LCOV - code coverage report
Current view: top level - framework/source/inc/accelerators - presethandler.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 4 0.0 %
Date: 2014-04-14 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_FRAMEWORK_SOURCE_INC_ACCELERATORS_PRESETHANDLER_HXX
      21             : #define INCLUDED_FRAMEWORK_SOURCE_INC_ACCELERATORS_PRESETHANDLER_HXX
      22             : 
      23             : #include <accelerators/storageholder.hxx>
      24             : #include <general.h>
      25             : #include <stdtypes.h>
      26             : 
      27             : #include <com/sun/star/embed/XStorage.hpp>
      28             : 
      29             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      30             : 
      31             : #include <comphelper/processfactory.hxx>
      32             : #include <salhelper/singletonref.hxx>
      33             : #include <i18nlangtag/languagetag.hxx>
      34             : 
      35             : namespace framework
      36             : {
      37             : /**
      38             :     TODO document me
      39             : 
      40             :         <layer>/global/<resourcetype>/<preset>.xml
      41             :         <layer>/modules/<moduleid>/<resourcetype>/<preset>.xml
      42             : 
      43             :         RESOURCETYPE        PRESET        TARGET
      44             :                             (share)       (user)
      45             :         "accelerator"       "default"     "current"
      46             :                             "word"
      47             :                             "excel"
      48             : 
      49             :         "menubar"           "default"     "menubar"
      50             : 
      51             :  */
      52             : class PresetHandler
      53             : {
      54             : 
      55             :     public:
      56             : 
      57             :         static OUString PRESET_DEFAULT();
      58             :         static OUString TARGET_CURRENT();
      59             : 
      60             :         static OUString RESOURCETYPE_MENUBAR();
      61             :         static OUString RESOURCETYPE_TOOLBAR();
      62             :         static OUString RESOURCETYPE_ACCELERATOR();
      63             :         static OUString RESOURCETYPE_STATUSBAR();
      64             : 
      65             :     // types
      66             : 
      67             :     public:
      68             : 
      69             :         /** @short  this handler can provide different
      70             :                     types of configuration.
      71             : 
      72             :             @descr  Means: a global or a module dependend
      73             :                     or ... configuration.
      74             :          */
      75             :         enum EConfigType
      76             :         {
      77             :             E_GLOBAL,
      78             :             E_MODULES,
      79             :             E_DOCUMENT
      80             :         };
      81             : 
      82             :     private:
      83             : 
      84             :         /** @short  because a concurrent access to the same storage from different implementations
      85             :                     isnt supported, we have to share it with others.
      86             : 
      87             :             @descr  This struct makes it possible to use any shared storage
      88             :                     in combination with a SingletonRef<> template ...
      89             : 
      90             :                     This struct is allegedly shared and must be used within a
      91             :                     synchronized section. But it isn't.
      92             :          */
      93             :         struct TSharedStorages
      94             :         {
      95             :             public:
      96             : 
      97             :                 StorageHolder m_lStoragesShare;
      98             :                 StorageHolder m_lStoragesUser;
      99             : 
     100           0 :                 TSharedStorages()
     101             :                     : m_lStoragesShare()
     102           0 :                     , m_lStoragesUser ()
     103           0 :                 {};
     104             : 
     105           0 :                 virtual ~TSharedStorages() {};
     106             :         };
     107             : 
     108             :     // member
     109             : 
     110             :     private:
     111             : 
     112             :         /** @short  can be used to create on needed uno resources. */
     113             :         css::uno::Reference< css::uno::XComponentContext > m_xContext;
     114             : 
     115             :         /** @short  knows the type of provided configuration.
     116             : 
     117             :             @descr  e.g. global, modules, ...
     118             :          */
     119             :         EConfigType m_eConfigType;
     120             : 
     121             :         /** @short  specify the type of resource, which configuration sets
     122             :                     must be provided here.
     123             : 
     124             :             @descr  e.g. menubars, toolbars, accelerators
     125             :          */
     126             :         OUString m_sResourceType;
     127             : 
     128             :         /** @short  specify the application module for a module
     129             :                     dependend configuration.
     130             : 
     131             :             @descr  Will be used only, if m_sResourceType is set to
     132             :                     "module". Further it must be a valid module identifier
     133             :                     then ...
     134             :          */
     135             :         OUString m_sModule;
     136             : 
     137             :         /** @short  provides access to the:
     138             :                     a) shared root storages
     139             :                     b) shared "inbetween" storages
     140             :                     of the share and user layer. */
     141             :         ::salhelper::SingletonRef< TSharedStorages > m_aSharedStorages;
     142             : 
     143             :         /** @short  if we run in document mode, we cant use the global root storages!
     144             :                     We have to use a special document storage explicitly. */
     145             :         StorageHolder m_lDocumentStorages;
     146             : 
     147             :         /** @short  holds the folder storage of the share layer alive,
     148             :                     where the current configuration set exists.
     149             : 
     150             :             @descr  Note: If this preset handler works in document mode
     151             :                     this member is meaned relative to the document root ...
     152             :                     not to the share layer root!
     153             : 
     154             :                     Further is defined, that m_xWorkingStorageUser
     155             :                     is equals to m_xWorkingStorageShare then!
     156             :          */
     157             :         css::uno::Reference< css::embed::XStorage > m_xWorkingStorageShare;
     158             : 
     159             :         /** @short  global language-independent storage
     160             :          */
     161             :         css::uno::Reference< css::embed::XStorage > m_xWorkingStorageNoLang;
     162             : 
     163             :         /** @short  holds the folder storage of the user layer alive,
     164             :                     where the current configuration set exists.
     165             : 
     166             :             @descr  Note: If this preset handler works in document mode
     167             :                     this member is meaned relative to the document root ...
     168             :                     not to the user layer root!
     169             : 
     170             :                     Further is defined, that m_xWorkingStorageUser
     171             :                     is equals to m_xWorkingStorageShare then!
     172             :          */
     173             :         css::uno::Reference< css::embed::XStorage > m_xWorkingStorageUser;
     174             : 
     175             :         /** @short  knows the names of all presets inside the current
     176             :                     working storage of the share layer. */
     177             :         OUStringList m_lPresets;
     178             : 
     179             :         /** @short  knows the names of all targets inside the current
     180             :                     working storage of the user layer. */
     181             :         OUStringList m_lTargets;
     182             : 
     183             :         /** @short  its the current office locale and will be used
     184             :                     to handle localized presets.
     185             : 
     186             :             @descr  Default is "x-no-translate" which disable any
     187             :                     localized handling inside this class! */
     188             :         LanguageTag m_aLanguageTag;
     189             : 
     190             :         /** @short  knows the relative path from the root. */
     191             :         OUString m_sRelPathShare;
     192             :         OUString m_sRelPathNoLang;
     193             :         OUString m_sRelPathUser;
     194             : 
     195             :     // native interface
     196             : 
     197             :     public:
     198             : 
     199             :         /** @short  does nothing real.
     200             : 
     201             :             @descr  Because this class should be useable in combination
     202             :                     with ::salhelper::SingletonRef template this ctor
     203             :                     cant have any special parameters!
     204             : 
     205             :             @param  xContext
     206             :                     points to an uno service manager, which is used internally
     207             :                     to create own needed uno resources.
     208             :          */
     209             :         PresetHandler(const css::uno::Reference< css::uno::XComponentContext >& xContext);
     210             : 
     211             :         /** @short  copy ctor */
     212             :         PresetHandler(const PresetHandler& rCopy);
     213             : 
     214             :         /** @short  closes all open storages ... if user forgot that .-) */
     215             :         virtual ~PresetHandler();
     216             : 
     217             :         /** @short  free all currently cache(!) storages. */
     218             :         void forgetCachedStorages();
     219             : 
     220             :         /** @short  return access to the internally used and cached root storage.
     221             : 
     222             :             @descr  These root storages are the base of all further opened
     223             :                     presets and targets. They are provided here only, to support
     224             :                     older implementations, which base on them ...
     225             : 
     226             :                     getOrCreate...() - What does it mean?
     227             :                     Such root storage will be created one times only and
     228             :                     cached then internally till the last instance of such PresetHandler
     229             :                     dies.
     230             : 
     231             :             @return com::sun::star::embed::XStorage
     232             :                     which represent a root storage.
     233             :          */
     234             :         css::uno::Reference< css::embed::XStorage > getOrCreateRootStorageShare();
     235             :         css::uno::Reference< css::embed::XStorage > getOrCreateRootStorageUser();
     236             : 
     237             :         /** @short  provides access to the current working storages.
     238             : 
     239             :             @descr  Working storages are the "lowest" storages, where the
     240             :                     preset and target files exists.
     241             : 
     242             :             @return com::sun::star::embed::XStorage
     243             :                     which the current working storage.
     244             :          */
     245             :         css::uno::Reference< css::embed::XStorage > getWorkingStorageShare();
     246             :         css::uno::Reference< css::embed::XStorage > getWorkingStorageUser();
     247             : 
     248             :         /** @short  check if there is a parent storage well known for
     249             :                     the specified child storage and return it.
     250             : 
     251             :             @param  xChild
     252             :                     the child storage where a paranet storage should be searched for.
     253             : 
     254             :             @return com::sun::star::embed::XStorage
     255             :                     A valid storage if a paranet exists. NULL otherwise.
     256             :          */
     257             :         css::uno::Reference< css::embed::XStorage > getParentStorageShare(const css::uno::Reference< css::embed::XStorage >& xChild);
     258             :         css::uno::Reference< css::embed::XStorage > getParentStorageUser (const css::uno::Reference< css::embed::XStorage >& xChild);
     259             : 
     260             :         /** @short  free all internal structures and let this handler
     261             :                     work on a new type of configuration sets.
     262             : 
     263             :             @param  eConfigType
     264             :                     differ between global or module dependend configuration.
     265             : 
     266             :             @param  sResourceType
     267             :                     differ between menubar/toolbar/accelerator/... configuration.
     268             : 
     269             :             @param  sModule
     270             :                     if sResourceType is set to a module dependend configuration,
     271             :                     it address the current application module.
     272             : 
     273             :             @param  xDocumentRoot
     274             :                     if sResourceType is set to E_DOCUMENT, this value points to the
     275             :                     root storage inside the document, where we can save our
     276             :                     configuration files. Note: Thats not the real root of the document ...
     277             :                     its only a sub storage. But we interpret it as our root storage.
     278             : 
     279             :             @param  rLanguageTag
     280             :                     in case this configuration supports localized entries,
     281             :                     the current locale must be set.
     282             : 
     283             :                     Localzation will be represented as directory structure
     284             :                     of provided presets. Means: you call us with a preset name "default";
     285             :                     and we use e.g. "/en-US/default.xml" internally.
     286             : 
     287             :                     If no localization exists for this preset set, this class
     288             :                     will work in default mode - means "no locale" - automaticly.
     289             :                     e.g. "/default.xml"
     290             : 
     291             :             @throw  com::sun::star::uno::RuntimeException(!)
     292             :                     if the specified resource couldn't be located.
     293             :          */
     294             :         void connectToResource(      EConfigType                                  eConfigType   ,
     295             :                                const OUString&                             sResourceType ,
     296             :                                const OUString&                             sModule       ,
     297             :                                const css::uno::Reference< css::embed::XStorage >& xDocumentRoot ,
     298             :                                const LanguageTag&                                 rLanguageTag  = LanguageTag(LANGUAGE_USER_PRIV_NOTRANSLATE));
     299             : 
     300             :         /** @short  try to copy the specified preset from the share
     301             :                     layer to the user layer and establish it as the
     302             :                     specified target.
     303             : 
     304             :             @descr  Means: copy share/.../<preset>.xml user/.../<target>.xml
     305             :                     Note: The target will be overwritten completely or
     306             :                     created as new by this operation!
     307             : 
     308             :             @param  sPreset
     309             :                     the ALIAS name of an existing preset.
     310             : 
     311             :             @param  sTarget
     312             :                     the ALIAS name of the target.
     313             : 
     314             :             @throw  com::sun::star::container::NoSuchElementException
     315             :                     if the specified preset does not exists.
     316             : 
     317             :             @throw  com::sun::star::io::IOException
     318             :                     if copying failed.
     319             :          */
     320             :         void copyPresetToTarget(const OUString& sPreset,
     321             :                                 const OUString& sTarget);
     322             : 
     323             :         /** @short  open the specified preset as stream object
     324             :                     and return it.
     325             : 
     326             :             @descr  Note: Because presets resist inside the share
     327             :                     layer, they will be opened readonly every time.
     328             : 
     329             :             @param  sPreset
     330             :                     the ALIAS name of an existing preset.
     331             : 
     332             :             @param  bNoLangGlobal
     333             :                     access the global language-independent storage instead of the preset storage
     334             : 
     335             :             @return The opened preset stream ... or NULL if the preset does not exists.
     336             :          */
     337             :         css::uno::Reference< css::io::XStream > openPreset(const OUString& sPreset,
     338             :                                                            bool bUseNoLangGlobal = false);
     339             : 
     340             :         /** @short  open the specified target as stream object
     341             :                     and return it.
     342             : 
     343             :             @descr  Note: Targets resist inside the user
     344             :                     layer. Normaly they are opened in read/write mode.
     345             :                     But it will be opened readonly automaticly if that isnt possible
     346             :                     (may be the file is write protected on the system ...).
     347             : 
     348             :             @param  sTarget
     349             :                     the ALIAS name of the target.
     350             : 
     351             :             @param  bCreateIfMissing
     352             :                     create target file, if it does not still exists.
     353             :                     Note: That does not means reseting of an existing file!
     354             : 
     355             :             @return The opened target stream ... or NULL if the target does not exists
     356             :                     or couldnt be created as new one.
     357             :          */
     358             :         css::uno::Reference< css::io::XStream > openTarget(const OUString& sTarget         ,
     359             :                                                                  bool         bCreateIfMissing);
     360             : 
     361             :         /** @short  do anything which is necessary to flush all changes
     362             :                     back to disk.
     363             : 
     364             :             @descr  We have to call commit on all cached sub storages on the
     365             :                     path from the root storage upside down to the working storage
     366             :                     (which are not really used, but required to be holded alive!).
     367             :          */
     368             :         void commitUserChanges();
     369             : 
     370             :         /** TODO */
     371             :         void addStorageListener(IStorageListener* pListener);
     372             :         void removeStorageListener(IStorageListener* pListener);
     373             : 
     374             :     // helper
     375             : 
     376             :     private:
     377             : 
     378             :         /** @short  open a config path ignoring errors (catching exceptions).
     379             : 
     380             :             @descr  We catch only normal exceptions here - no runtime exceptions.
     381             : 
     382             :             @param  sPath
     383             :                     the configuration path, which should be opened.
     384             : 
     385             :             @param  eMode
     386             :                     the open mode (READ/READWRITE)
     387             : 
     388             :             @param  bShare
     389             :                     force using of the share layer instead of the user layer.
     390             : 
     391             :             @return An opened storage in case method was successfully - null otherwise.
     392             :          */
     393             :         css::uno::Reference< css::embed::XStorage > impl_openPathIgnoringErrors(const OUString& sPath ,
     394             :                                                                                       sal_Int32        eMode ,
     395             :                                                                                       bool         bShare);
     396             : 
     397             :         /** @short  try to find the specified locale inside list of possible ones.
     398             : 
     399             :             @descr  The lits of possible locale values was e.g. retrieved from the system
     400             :                     (configuration, directory listing etcpp). The locale normaly represent
     401             :                     the current office locale. This method search for a suitable item by using
     402             :                     different algorithm.
     403             :                     a) exact search
     404             :                     b) search with using fallbacks
     405             : 
     406             :             @param  lLocalizedValues
     407             :                     list of BCP47 language tags / locale codes
     408             : 
     409             :             @param  rLanguageTag
     410             :                     [IN ] the current office locale, which should be searched inside lLocalizedValues.
     411             :                     [OUT] in case fallbacks was allowed, it contains afterwards the fallback locale.
     412             : 
     413             :             @param  bAllowFallbacks
     414             :                     enable/disable using of fallbacks
     415             : 
     416             :             @return An iterator, which points directly into lLocalizedValue list.
     417             :                     As a negative result the special iterator lLocalizedValues.end() will be returned.
     418             :          */
     419             :         ::std::vector< OUString >::const_iterator impl_findMatchingLocalizedValue(const ::std::vector< OUString >& lLocalizedValues,
     420             :                                                                                                OUString&             rLanguageTag         ,
     421             :                                                                                                bool                          bAllowFallbacks );
     422             : 
     423             :         /** @short  open a config path ignoring errors (catching exceptions).
     424             : 
     425             :             @descr  We catch only normal exceptions here - no runtime exceptions.
     426             :                     Further the path itself is tries in different versions (using locale
     427             :                     specific attributes).
     428             :                     e.g. "path/e-US" => "path/en" => "path/de"
     429             : 
     430             :             @param  sPath
     431             :                     the configuration path, which should be opened.
     432             :                     Its further used as out parameter too, so we can return the localized
     433             :                     path to the calli!
     434             : 
     435             :             @param  eMode
     436             :                     the open mode (READ/READWRITE)
     437             : 
     438             :             @param  bShare
     439             :                     force using of the share layer instead of the user layer.
     440             : 
     441             :             @param  rLanguageTag
     442             :                     [IN ] contains the start locale for searching localized sub dirs.
     443             :                     [OUT] contains the locale of a found localized sub dir
     444             : 
     445             :             @param  bAllowFallback
     446             :                     enable/disable fallback handling for locales
     447             : 
     448             :             @return An opened storage in case method was successfully - null otherwise.
     449             :          */
     450             :         css::uno::Reference< css::embed::XStorage > impl_openLocalizedPathIgnoringErrors(OUString&      sPath         ,
     451             :                                                                                          sal_Int32             eMode         ,
     452             :                                                                                          bool              bShare        ,
     453             :                                                                                          OUString&             rLanguageTag  ,
     454             :                                                                                          bool              bAllowFallback);
     455             : 
     456             :         /** @short  returns the names of all sub storages of specified storage.
     457             : 
     458             :             @param  xFolder
     459             :                     the base storage for this operation.
     460             : 
     461             :             @return [vector< string >]
     462             :                     a list of folder names.
     463             :          */
     464             :         ::std::vector< OUString > impl_getSubFolderNames(const css::uno::Reference< css::embed::XStorage >& xFolder);
     465             : };
     466             : 
     467             : } // namespace framework
     468             : 
     469             : #endif // INCLUDED_FRAMEWORK_SOURCE_INC_ACCELERATORS_PRESETHANDLER_HXX
     470             : 
     471             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10