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

Generated by: LCOV version 1.10