LCOV - code coverage report
Current view: top level - unotools/source/config - moduleoptions.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 268 522 51.3 %
Date: 2015-06-13 12:38:46 Functions: 49 70 70.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             : #include <unotools/moduleoptions.hxx>
      21             : #include <comphelper/sequenceashashmap.hxx>
      22             : #include <unotools/configmgr.hxx>
      23             : #include <unotools/configitem.hxx>
      24             : #include <comphelper/processfactory.hxx>
      25             : #include <comphelper/sequence.hxx>
      26             : #include <osl/diagnose.h>
      27             : #include <o3tl/enumarray.hxx>
      28             : #include <rtl/ustrbuf.hxx>
      29             : #include <rtl/instance.hxx>
      30             : #include <com/sun/star/uno/Any.hxx>
      31             : #include <com/sun/star/uno/Sequence.hxx>
      32             : #include <com/sun/star/beans/PropertyValue.hpp>
      33             : #include <com/sun/star/container/XNameAccess.hpp>
      34             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      35             : #include <com/sun/star/lang/XServiceInfo.hpp>
      36             : #include <com/sun/star/document/XTypeDetection.hpp>
      37             : #include <com/sun/star/util/PathSubstitution.hpp>
      38             : #include <com/sun/star/util/XStringSubstitution.hpp>
      39             : 
      40             : #include "itemholder1.hxx"
      41             : 
      42             : /*-************************************************************************************************************
      43             :     @descr          These values are used to define necessary keys from our configuration management to support
      44             :                     all functionality of these implementation.
      45             :                     It's a fast way to make changes if some keys change his name or location!
      46             : 
      47             :                     Property handle are necessary to specify right position in return list of configuration
      48             :                     for asked values. We ask it with a list of properties to get his values. The returned list
      49             :                     has the same order like our given name list!
      50             :                     e.g.:
      51             :                             NAMELIST[ PROPERTYHANDLE_xxx ] => VALUELIST[ PROPERTYHANDLE_xxx ]
      52             : *//*-*************************************************************************************************************/
      53             : #define ROOTNODE_FACTORIES                  OUString("Setup/Office/Factories"        )
      54             : #define PATHSEPARATOR                       "/"
      55             : 
      56             : // Attention: The property "ooSetupFactoryEmptyDocumentURL" is read from configuration but not used! There is
      57             : //            special code that uses hard coded strings to return them.
      58             : #define PROPERTYNAME_SHORTNAME              "ooSetupFactoryShortName"
      59             : #define PROPERTYNAME_TEMPLATEFILE           "ooSetupFactoryTemplateFile"
      60             : #define PROPERTYNAME_WINDOWATTRIBUTES       "ooSetupFactoryWindowAttributes"
      61             : #define PROPERTYNAME_EMPTYDOCUMENTURL       "ooSetupFactoryEmptyDocumentURL"
      62             : #define PROPERTYNAME_DEFAULTFILTER          "ooSetupFactoryDefaultFilter"
      63             : #define PROPERTYNAME_ICON                   "ooSetupFactoryIcon"
      64             : 
      65             : #define PROPERTYHANDLE_SHORTNAME            0
      66             : #define PROPERTYHANDLE_TEMPLATEFILE         1
      67             : #define PROPERTYHANDLE_WINDOWATTRIBUTES     2
      68             : #define PROPERTYHANDLE_EMPTYDOCUMENTURL     3
      69             : #define PROPERTYHANDLE_DEFAULTFILTER        4
      70             : #define PROPERTYHANDLE_ICON                 5
      71             : 
      72             : #define PROPERTYCOUNT                       6
      73             : 
      74             : #define FACTORYNAME_WRITER                  "com.sun.star.text.TextDocument"
      75             : #define FACTORYNAME_WRITERWEB               "com.sun.star.text.WebDocument"
      76             : #define FACTORYNAME_WRITERGLOBAL            "com.sun.star.text.GlobalDocument"
      77             : #define FACTORYNAME_CALC                    "com.sun.star.sheet.SpreadsheetDocument"
      78             : #define FACTORYNAME_DRAW                    "com.sun.star.drawing.DrawingDocument"
      79             : #define FACTORYNAME_IMPRESS                 "com.sun.star.presentation.PresentationDocument"
      80             : #define FACTORYNAME_MATH                    "com.sun.star.formula.FormulaProperties"
      81             : #define FACTORYNAME_CHART                   "com.sun.star.chart2.ChartDocument"
      82             : #define FACTORYNAME_DATABASE                "com.sun.star.sdb.OfficeDatabaseDocument"
      83             : #define FACTORYNAME_STARTMODULE             "com.sun.star.frame.StartModule"
      84             : #define FACTORYNAME_BASIC                   "com.sun.star.script.BasicIDE"
      85             : 
      86             : #define FACTORYCOUNT                        11
      87             : 
      88             : /*-************************************************************************************************************
      89             :     @descr  This struct hold information about one factory. We declare a complete array which can hold infos
      90             :             for all well known factories. Values of enum "EFactory" (see header!) are directly used as index!
      91             :             So we can support a fast access on these information.
      92             : *//*-*************************************************************************************************************/
      93        1287 : struct FactoryInfo
      94             : {
      95             :     public:
      96             : 
      97             :         // initialize empty struct
      98        1309 :         FactoryInfo()
      99        1309 :         {
     100        1309 :             free();
     101        1309 :         }
     102             : 
     103             :         // easy way to reset struct member!
     104        3927 :         void free()
     105             :         {
     106        3927 :             bInstalled                  = false;
     107        3927 :             sFactory.clear();
     108        3927 :             sShortName.clear();
     109        3927 :             sTemplateFile.clear();
     110        3927 :             sWindowAttributes.clear();
     111        3927 :             sEmptyDocumentURL.clear();
     112        3927 :             sDefaultFilter.clear();
     113        3927 :             nIcon                       = 0;
     114        3927 :             bChangedTemplateFile        = false;
     115        3927 :             bChangedWindowAttributes    = false;
     116        3927 :             bChangedEmptyDocumentURL    = false;
     117        3927 :             bChangedDefaultFilter       = false;
     118        3927 :             bChangedIcon                = false;
     119        3927 :             bDefaultFilterReadonly      = false;
     120        3927 :         }
     121             : 
     122             :         // returns list of properties, which has changed only!
     123             :         // We use given value of sNodeBase to build full qualified paths ...
     124             :         // Last sign of it must be "/". because we use it directly, without any additional things!
     125           0 :         css::uno::Sequence< css::beans::PropertyValue > getChangedProperties( const OUString& sNodeBase )
     126             :         {
     127             :             // a) reserve memory for max. count of changed properties
     128             :             // b) add names and values of changed ones only and count it
     129             :             // c) resize return list by using count
     130           0 :             css::uno::Sequence< css::beans::PropertyValue > lProperties   ( 4 );
     131           0 :             sal_Int8                                        nRealyChanged = 0;
     132             : 
     133           0 :             if( bChangedTemplateFile )
     134             :             {
     135           0 :                 lProperties[nRealyChanged].Name = sNodeBase + PROPERTYNAME_TEMPLATEFILE;
     136             : 
     137           0 :                 if ( !sTemplateFile.isEmpty() )
     138             :                 {
     139           0 :                     lProperties[nRealyChanged].Value
     140           0 :                         <<= getStringSubstitution()
     141           0 :                             ->reSubstituteVariables( sTemplateFile );
     142             :                 }
     143             :                 else
     144             :                 {
     145           0 :                     lProperties[nRealyChanged].Value <<= sTemplateFile;
     146             :                 }
     147             : 
     148           0 :                 ++nRealyChanged;
     149             :             }
     150           0 :             if( bChangedWindowAttributes )
     151             :             {
     152           0 :                 lProperties[nRealyChanged].Name    = sNodeBase + PROPERTYNAME_WINDOWATTRIBUTES;
     153           0 :                 lProperties[nRealyChanged].Value <<= sWindowAttributes;
     154           0 :                 ++nRealyChanged;
     155             :             }
     156           0 :             if( bChangedEmptyDocumentURL )
     157             :             {
     158           0 :                 lProperties[nRealyChanged].Name    = sNodeBase + PROPERTYNAME_EMPTYDOCUMENTURL;
     159           0 :                 lProperties[nRealyChanged].Value <<= sEmptyDocumentURL;
     160           0 :                 ++nRealyChanged;
     161             :             }
     162           0 :             if( bChangedDefaultFilter )
     163             :             {
     164           0 :                 lProperties[nRealyChanged].Name    = sNodeBase + PROPERTYNAME_DEFAULTFILTER;
     165           0 :                 lProperties[nRealyChanged].Value <<= sDefaultFilter;
     166           0 :                 ++nRealyChanged;
     167             :             }
     168           0 :             if( bChangedIcon )
     169             :             {
     170           0 :                 lProperties[nRealyChanged].Name    = sNodeBase + PROPERTYNAME_ICON;
     171           0 :                 lProperties[nRealyChanged].Value <<= nIcon;
     172           0 :                 ++nRealyChanged;
     173             :             }
     174             : 
     175             :             // Don't forget to reset changed flags! Otherwise we save it again and again and ...
     176           0 :             bChangedTemplateFile        = false;
     177           0 :             bChangedWindowAttributes    = false;
     178           0 :             bChangedEmptyDocumentURL    = false;
     179           0 :             bChangedDefaultFilter       = false;
     180           0 :             bChangedIcon                = false;
     181             : 
     182           0 :             lProperties.realloc( nRealyChanged );
     183           0 :             return lProperties;
     184             :         }
     185             : 
     186             :         // We must support setting AND marking of changed values.
     187             :         // That's why we can't make our member public. We must use get/set/init methods
     188             :         // to control access on it!
     189       24107 :         bool            getInstalled        () const { return bInstalled;         };
     190          13 :         OUString     getFactory          () const { return sFactory;           };
     191         704 :         OUString     getTemplateFile     () const { return sTemplateFile;      };
     192          13 :         OUString     getDefaultFilter    () const { return sDefaultFilter;     };
     193           0 :         bool            isDefaultFilterReadonly() const { return bDefaultFilterReadonly; }
     194        3289 :         sal_Int32           getIcon             () const { return nIcon;              };
     195             : 
     196             :         // If you call set-methods - we check for changes of valkues and mark it.
     197             :         // But if you wish to set it without that ... you must initialize it!
     198        1309 :         void initInstalled        ( bool               bNewInstalled        ) { bInstalled        = bNewInstalled; }
     199        1309 :         void initFactory          ( const OUString& sNewFactory          ) { sFactory          = sNewFactory; }
     200        1309 :         void initShortName        ( const OUString& sNewShortName        ) { sShortName        = sNewShortName; }
     201        1072 :         void initWindowAttributes ( const OUString& sNewWindowAttributes ) { sWindowAttributes = sNewWindowAttributes; }
     202        1071 :         void initEmptyDocumentURL ( const OUString& sNewEmptyDocumentURL ) { sEmptyDocumentURL = sNewEmptyDocumentURL; }
     203        1071 :         void initDefaultFilter    ( const OUString& sNewDefaultFilter    ) { sDefaultFilter    = sNewDefaultFilter; }
     204           0 :         void setDefaultFilterReadonly( const bool bVal){bDefaultFilterReadonly = bVal;}
     205        1309 :         void initIcon             ( sal_Int32              nNewIcon             ) { nIcon             = nNewIcon; }
     206             : 
     207        1071 :         void initTemplateFile( const OUString& sNewTemplateFile )
     208             :         {
     209        1071 :             if ( !sNewTemplateFile.isEmpty() )
     210             :             {
     211             :                 sTemplateFile
     212           0 :                     = getStringSubstitution()
     213           0 :                         ->substituteVariables( sNewTemplateFile, sal_False );
     214             :             }
     215             :             else
     216             :             {
     217        1071 :                 sTemplateFile = sNewTemplateFile;
     218             :             }
     219        1071 :         }
     220             : 
     221           0 :         void setTemplateFile( const OUString& sNewTemplateFile )
     222             :         {
     223           0 :             if( sTemplateFile != sNewTemplateFile )
     224             :             {
     225           0 :                 sTemplateFile        = sNewTemplateFile;
     226           0 :                 bChangedTemplateFile = true;
     227             :             }
     228           0 :         };
     229             : 
     230           0 :         void setDefaultFilter( const OUString& sNewDefaultFilter )
     231             :         {
     232           0 :             if( sDefaultFilter != sNewDefaultFilter )
     233             :             {
     234           0 :                 sDefaultFilter       = sNewDefaultFilter;
     235           0 :                 bChangedDefaultFilter = true;
     236             :             }
     237           0 :         };
     238             : 
     239             :     private:
     240           0 :         css::uno::Reference< css::util::XStringSubstitution > getStringSubstitution()
     241             :         {
     242           0 :             if ( !xSubstVars.is() )
     243             :             {
     244           0 :                 xSubstVars.set( css::util::PathSubstitution::create(::comphelper::getProcessComponentContext()) );
     245             :             }
     246           0 :             return xSubstVars;
     247             :         }
     248             : 
     249             :         bool            bInstalled;
     250             :         OUString     sFactory;
     251             :         OUString     sShortName;
     252             :         OUString     sTemplateFile;
     253             :         OUString     sWindowAttributes;
     254             :         OUString     sEmptyDocumentURL;
     255             :         OUString     sDefaultFilter;
     256             :         sal_Int32           nIcon;
     257             : 
     258             :         bool            bChangedTemplateFile        :1;
     259             :         bool            bChangedWindowAttributes    :1;
     260             :         bool            bChangedEmptyDocumentURL    :1;
     261             :         bool            bChangedDefaultFilter       :1;
     262             :         bool            bChangedIcon                :1;
     263             :         bool            bDefaultFilterReadonly      :1;
     264             : 
     265             :         css::uno::Reference< css::util::XStringSubstitution >  xSubstVars;
     266             : };
     267             : 
     268             : /*-************************************************************************************************************
     269             :     @short          IMPL data container for wrapper class SvtModulOptions!
     270             :     @descr          These class is used as a static data container of class SvtModuleOptions. The hold it by using
     271             :                     a refcount and make it threadsafe by using an osl mutex. So we don't must do anything for that.
     272             :                     We can implement pure functionality to read/write configuration data only.
     273             :     @base           ConfigItem
     274             : 
     275             :     @devstatus      ready to use
     276             :     @threadsafe     no
     277             : *//*-*************************************************************************************************************/
     278             : class SvtModuleOptions_Impl : public ::utl::ConfigItem
     279             : {
     280             : 
     281             :     //  public methods
     282             : 
     283             :     public:
     284             : 
     285             :         //  constructor / destructor
     286             : 
     287             :          SvtModuleOptions_Impl();
     288             :         virtual ~SvtModuleOptions_Impl();
     289             : 
     290             :         //  override methods of baseclass
     291             : 
     292             :         virtual void Notify( const css::uno::Sequence< OUString >& lPropertyNames ) SAL_OVERRIDE;
     293             : 
     294             :         //  public interface
     295             : 
     296             :         bool            IsModuleInstalled         (       SvtModuleOptions::EModule     eModule    ) const;
     297             :         ::com::sun::star::uno::Sequence < OUString > GetAllServiceNames();
     298             :         OUString        GetFactoryName            (       SvtModuleOptions::EFactory    eFactory   ) const;
     299             :         OUString        GetFactoryStandardTemplate(       SvtModuleOptions::EFactory    eFactory   ) const;
     300             :         static OUString GetFactoryEmptyDocumentURL(       SvtModuleOptions::EFactory    eFactory   );
     301             :         OUString        GetFactoryDefaultFilter   (       SvtModuleOptions::EFactory    eFactory   ) const;
     302             :         bool            IsDefaultFilterReadonly(          SvtModuleOptions::EFactory eFactory      ) const;
     303             :         sal_Int32       GetFactoryIcon            (       SvtModuleOptions::EFactory    eFactory   ) const;
     304             :         static bool     ClassifyFactoryByName     ( const OUString&              sName      ,
     305             :                                                           SvtModuleOptions::EFactory&   eFactory   );
     306             :         void            SetFactoryStandardTemplate(       SvtModuleOptions::EFactory    eFactory   ,
     307             :                                                     const OUString&              sTemplate  );
     308             :         void            SetFactoryDefaultFilter   (       SvtModuleOptions::EFactory    eFactory   ,
     309             :                                                     const OUString&              sFilter    );
     310             :         void            MakeReadonlyStatesAvailable();
     311             : 
     312             :     //  private methods
     313             : 
     314             :     private:
     315             :         static css::uno::Sequence< OUString > impl_ExpandSetNames ( const css::uno::Sequence< OUString >& lSetNames   );
     316             :                void                                  impl_Read           ( const css::uno::Sequence< OUString >& lSetNames   );
     317             : 
     318             :         virtual void ImplCommit() SAL_OVERRIDE;
     319             : 
     320             :     //  private types
     321             : 
     322             :     private:
     323             : 
     324             :     //  private member
     325             : 
     326             :     private:
     327             :         o3tl::enumarray<SvtModuleOptions::EFactory, FactoryInfo> m_lFactories;
     328             :         bool            m_bReadOnlyStatesWellKnown;
     329             : };
     330             : 
     331             : /*-************************************************************************************************************
     332             :     @short      default ctor
     333             :     @descr      We open our configuration here and read all necessary values from it.
     334             :                 These values are cached till everyone call Commit(). Then we write changed ones back to cfg.
     335             : 
     336             :     @seealso    baseclass ConfigItem
     337             :     @seealso    method impl_Read()
     338             :     @threadsafe no
     339             : *//*-*************************************************************************************************************/
     340         119 : SvtModuleOptions_Impl::SvtModuleOptions_Impl()
     341             :     :   ::utl::ConfigItem( ROOTNODE_FACTORIES )
     342         119 :     ,   m_bReadOnlyStatesWellKnown( false )
     343             : {
     344             :     // First initialize list of factory infos! Otherwise we couldnt guarantee right working of these class.
     345        1428 :     for( auto & rFactory : m_lFactories )
     346        1309 :         rFactory.free();
     347             : 
     348             :     // Get name list of all existing set node names in configuration to read her properties in impl_Read().
     349             :     // These list is a list of long names of our factories.
     350         119 :     const css::uno::Sequence< OUString > lFactories = GetNodeNames( OUString() );
     351         119 :     impl_Read( lFactories );
     352             : 
     353             :     // Enable notification for changes by using configuration directly.
     354             :     // So we can update our internal values immediately.
     355         119 :     EnableNotification( lFactories );
     356         119 : }
     357             : 
     358         234 : SvtModuleOptions_Impl::~SvtModuleOptions_Impl()
     359             : {
     360             :     assert(!IsModified()); // should have been committed
     361         234 : }
     362             : 
     363             : /*-************************************************************************************************************
     364             :     @short      called for notify of configmanager
     365             :     @descr      These method is called from the ConfigManager before application ends or from the
     366             :                 PropertyChangeListener if the sub tree broadcasts changes. You must update our
     367             :                 internal values.
     368             : 
     369             :     @attention  We are registered for pure set node names only. So we can use our internal method "impl_Read()" to
     370             :                 update our info list. Because - these method expand given name list to full qualified property list
     371             :                 and use it to read the values. These values are filled into our internal member list m_lFactories
     372             :                 at right position.
     373             : 
     374             :     @seealso    method impl_Read()
     375             : 
     376             :     @param      "lNames" is the list of set node entries which should be updated.
     377             :     @threadsafe no
     378             : *//*-*************************************************************************************************************/
     379           0 : void SvtModuleOptions_Impl::Notify( const css::uno::Sequence< OUString >& )
     380             : {
     381             :     OSL_FAIL( "SvtModuleOptions_Impl::Notify()\nNot implemented yet!\n" );
     382           0 : }
     383             : 
     384             : /*-****************************************************************************************************
     385             :     @short      write changes to configuration
     386             :     @descr      These method writes the changed values into the sub tree
     387             :                 and should always called in our destructor to guarantee consistency of config data.
     388             : 
     389             :     @attention  We clear complete set in configuration first and write it completely new! So we don't must
     390             :                 distinguish between existing, added or removed elements. Our internal cached values
     391             :                 are the only and right ones.
     392             : 
     393             :     @seealso    baseclass ConfigItem
     394             :     @threadsafe no
     395             : *//*-*****************************************************************************************************/
     396           0 : void SvtModuleOptions_Impl::ImplCommit()
     397             : {
     398             :     // Reserve memory for ALL possible factory properties!
     399             :     // Step over all factories and get her really changed values only.
     400             :     // Build list of these ones and use it for commit.
     401           0 :     css::uno::Sequence< css::beans::PropertyValue > lCommitProperties( FACTORYCOUNT*PROPERTYCOUNT );
     402           0 :     sal_Int32                                       nRealCount       = 0;
     403           0 :     OUString                                 sBasePath;
     404           0 :     for( FactoryInfo & rInfo : m_lFactories )
     405             :     {
     406             :         // These path is used to build full qualified property names ....
     407             :         // See pInfo->getChangedProperties() for further information
     408           0 :         sBasePath  = PATHSEPARATOR + rInfo.getFactory() + PATHSEPARATOR;
     409             : 
     410           0 :         const css::uno::Sequence< css::beans::PropertyValue > lChangedProperties = rInfo.getChangedProperties ( sBasePath );
     411           0 :         const css::beans::PropertyValue*                      pChangedProperties = lChangedProperties.getConstArray();
     412           0 :         sal_Int32                                             nPropertyCount     = lChangedProperties.getLength();
     413           0 :         for( sal_Int32 nProperty=0; nProperty<nPropertyCount; ++nProperty )
     414             :         {
     415           0 :             lCommitProperties[nRealCount] = pChangedProperties[nProperty];
     416           0 :             ++nRealCount;
     417             :         }
     418           0 :     }
     419             :     // Resize commit list to real size.
     420             :     // If nothing to do - suppress calling of configuration ...
     421             :     // It could be to expensive :-)
     422           0 :     if( nRealCount > 0 )
     423             :     {
     424           0 :         lCommitProperties.realloc( nRealCount );
     425           0 :         SetSetProperties( OUString(), lCommitProperties );
     426           0 :     }
     427           0 : }
     428             : 
     429             : /*-****************************************************************************************************
     430             :     @short      access method to get internal values
     431             :     @descr      These methods implement easy access to our internal values.
     432             :                 You give us right enum value to specify which module interest you ... we return right information.
     433             : 
     434             :     @attention  Some people use any value as enum ... but we support in header specified values only!
     435             :                 We use it directly as index in our internal list. If enum value isn't right - we crash with an
     436             :                 "index out of range"!!! Please use me right - otherwise there is no guarantee.
     437             :     @param      "eModule"  , index in list - specify module
     438             :     @param      "eFactory" , index in list - specify factory
     439             :     @param      "sTemplate", set new standard template for these factory
     440             :     @return     Queried information.
     441             : 
     442             :     @onerror    We return default values. (mostly "not installed"!)
     443             :     @threadsafe no
     444             : *//*-*****************************************************************************************************/
     445       24107 : bool SvtModuleOptions_Impl::IsModuleInstalled( SvtModuleOptions::EModule eModule ) const
     446             : {
     447       24107 :     bool bInstalled = false;
     448       24107 :     switch( eModule )
     449             :     {
     450        1667 :         case SvtModuleOptions::EModule::WRITER    :   bInstalled = m_lFactories[SvtModuleOptions::EFactory::WRITER].getInstalled();
     451        1667 :                                                 break;
     452           0 :         case SvtModuleOptions::EModule::WEB       :   bInstalled = m_lFactories[SvtModuleOptions::EFactory::WRITERWEB].getInstalled();
     453           0 :                                                 break;
     454           0 :         case SvtModuleOptions::EModule::GLOBAL    :   bInstalled = m_lFactories[SvtModuleOptions::EFactory::WRITERGLOBAL].getInstalled();
     455           0 :                                                 break;
     456        4176 :         case SvtModuleOptions::EModule::CALC      :   bInstalled = m_lFactories[SvtModuleOptions::EFactory::CALC].getInstalled();
     457        4176 :                                                 break;
     458          64 :         case SvtModuleOptions::EModule::DRAW      :   bInstalled = m_lFactories[SvtModuleOptions::EFactory::DRAW].getInstalled();
     459          64 :                                                 break;
     460          64 :         case SvtModuleOptions::EModule::IMPRESS   :   bInstalled = m_lFactories[SvtModuleOptions::EFactory::IMPRESS].getInstalled();
     461          64 :                                                 break;
     462        5088 :         case SvtModuleOptions::EModule::MATH      :   bInstalled = m_lFactories[SvtModuleOptions::EFactory::MATH].getInstalled();
     463        5088 :                                                 break;
     464        5142 :         case SvtModuleOptions::EModule::CHART     :   bInstalled = m_lFactories[SvtModuleOptions::EFactory::CHART].getInstalled();
     465        5142 :                                                 break;
     466        6336 :         case SvtModuleOptions::EModule::STARTMODULE : bInstalled = m_lFactories[SvtModuleOptions::EFactory::STARTMODULE].getInstalled();
     467        6336 :                                                 break;
     468           0 :         case SvtModuleOptions::EModule::BASIC     :   bInstalled = true; // Couldn't be deselected by setup yet!
     469           0 :                                                 break;
     470        1570 :         case SvtModuleOptions::EModule::DATABASE  :   bInstalled = m_lFactories[SvtModuleOptions::EFactory::DATABASE].getInstalled();
     471        1570 :                                                 break;
     472             :     }
     473             : 
     474       24107 :     return bInstalled;
     475             : }
     476             : 
     477           0 : ::com::sun::star::uno::Sequence < OUString > SvtModuleOptions_Impl::GetAllServiceNames()
     478             : {
     479           0 :     std::vector<OUString> aVec;
     480             : 
     481           0 :     for( auto & rFactory : m_lFactories )
     482           0 :         if( rFactory.getInstalled() )
     483           0 :             aVec.push_back( rFactory.getFactory() );
     484             : 
     485           0 :     return comphelper::containerToSequence(aVec);
     486             : }
     487             : 
     488          13 : OUString SvtModuleOptions_Impl::GetFactoryName( SvtModuleOptions::EFactory eFactory ) const
     489             : {
     490          13 :     return m_lFactories[eFactory].getFactory();
     491             : }
     492             : 
     493      102628 : OUString SvtModuleOptions::GetFactoryShortName(SvtModuleOptions::EFactory eFactory)
     494             : {
     495             :     // Attention: Hard configured yet ... because it's not fine to make changes possible by xml file yet.
     496             :     //            But it's good to plan further possibilities!
     497             : 
     498             :     //return m_lFactories[eFactory].sShortName;
     499             : 
     500      102628 :     OUString sShortName;
     501      102628 :     switch( eFactory )
     502             :     {
     503       81124 :         case SvtModuleOptions::EFactory::WRITER   :  sShortName = "swriter";
     504       81124 :                                                        break;
     505          54 :         case SvtModuleOptions::EFactory::WRITERWEB:  sShortName = "swriter/web";
     506          54 :                                                        break;
     507           0 :         case SvtModuleOptions::EFactory::WRITERGLOBAL:  sShortName = "swriter/GlobalDocument";
     508           0 :                                                        break;
     509       18151 :         case SvtModuleOptions::EFactory::CALC     :  sShortName = "scalc";
     510       18151 :                                                        break;
     511        2160 :         case SvtModuleOptions::EFactory::DRAW     :  sShortName = "sdraw";
     512        2160 :                                                        break;
     513         884 :         case SvtModuleOptions::EFactory::IMPRESS  :  sShortName = "simpress";
     514         884 :                                                        break;
     515         255 :         case SvtModuleOptions::EFactory::MATH     :  sShortName = "smath";
     516         255 :                                                        break;
     517           0 :         case SvtModuleOptions::EFactory::CHART    :  sShortName = "schart";
     518           0 :                                                        break;
     519           0 :         case SvtModuleOptions::EFactory::BASIC    :  sShortName = "sbasic";
     520           0 :                                                        break;
     521           0 :         case SvtModuleOptions::EFactory::DATABASE :  sShortName = "sdatabase";
     522           0 :                                                        break;
     523             :         default:
     524             :             OSL_FAIL( "unknown factory" );
     525           0 :             break;
     526             :     }
     527             : 
     528      102628 :     return sShortName;
     529             : }
     530             : 
     531         704 : OUString SvtModuleOptions_Impl::GetFactoryStandardTemplate( SvtModuleOptions::EFactory eFactory ) const
     532             : {
     533         704 :     return m_lFactories[eFactory].getTemplateFile();
     534             : }
     535             : 
     536           7 : OUString SvtModuleOptions_Impl::GetFactoryEmptyDocumentURL( SvtModuleOptions::EFactory eFactory )
     537             : {
     538             :     // Attention: Hard configured yet ... because it's not fine to make changes possible by xml file yet.
     539             :     //            But it's good to plan further possibilities!
     540             : 
     541             :     //return m_lFactories[eFactory].getEmptyDocumentURL();
     542             : 
     543           7 :     OUString sURL;
     544           7 :     switch( eFactory )
     545             :     {
     546           0 :         case SvtModuleOptions::EFactory::WRITER        :  sURL = "private:factory/swriter";
     547           0 :                                                   break;
     548           0 :         case SvtModuleOptions::EFactory::WRITERWEB     :  sURL = "private:factory/swriter/web";
     549           0 :                                                   break;
     550           0 :         case SvtModuleOptions::EFactory::WRITERGLOBAL  :  sURL = "private:factory/swriter/GlobalDocument";
     551           0 :                                                   break;
     552           0 :         case SvtModuleOptions::EFactory::CALC          :  sURL = "private:factory/scalc";
     553           0 :                                                   break;
     554           0 :         case SvtModuleOptions::EFactory::DRAW          :  sURL = "private:factory/sdraw";
     555           0 :                                                   break;
     556           0 :         case SvtModuleOptions::EFactory::IMPRESS       :  sURL = "private:factory/simpress?slot=6686";
     557           0 :                                                   break;
     558           0 :         case SvtModuleOptions::EFactory::MATH          :  sURL = "private:factory/smath";
     559           0 :                                                   break;
     560           0 :         case SvtModuleOptions::EFactory::CHART         :  sURL = "private:factory/schart";
     561           0 :                                                   break;
     562           0 :         case SvtModuleOptions::EFactory::BASIC         :  sURL = "private:factory/sbasic";
     563           0 :                                                   break;
     564           7 :         case SvtModuleOptions::EFactory::DATABASE     :  sURL = "private:factory/sdatabase?Interactive";
     565           7 :                                                   break;
     566             :         default:
     567             :             OSL_FAIL( "unknown factory" );
     568           0 :             break;
     569             :     }
     570           7 :     return sURL;
     571             : }
     572             : 
     573          13 : OUString SvtModuleOptions_Impl::GetFactoryDefaultFilter( SvtModuleOptions::EFactory eFactory ) const
     574             : {
     575          13 :     return m_lFactories[eFactory].getDefaultFilter();
     576             : }
     577             : 
     578           0 : bool SvtModuleOptions_Impl::IsDefaultFilterReadonly( SvtModuleOptions::EFactory eFactory   ) const
     579             : {
     580           0 :     return m_lFactories[eFactory].isDefaultFilterReadonly();
     581             : }
     582             : 
     583        3289 : sal_Int32 SvtModuleOptions_Impl::GetFactoryIcon( SvtModuleOptions::EFactory eFactory ) const
     584             : {
     585        3289 :     return m_lFactories[eFactory].getIcon();
     586             : }
     587             : 
     588           0 : void SvtModuleOptions_Impl::SetFactoryStandardTemplate(       SvtModuleOptions::EFactory eFactory   ,
     589             :                                                         const OUString&           sTemplate  )
     590             : {
     591           0 :     m_lFactories[eFactory].setTemplateFile( sTemplate );
     592           0 :     SetModified();
     593           0 : }
     594             : 
     595           0 : void SvtModuleOptions_Impl::SetFactoryDefaultFilter(       SvtModuleOptions::EFactory eFactory,
     596             :                                                      const OUString&           sFilter )
     597             : {
     598           0 :     m_lFactories[eFactory].setDefaultFilter( sFilter );
     599           0 :     SetModified();
     600           0 : }
     601             : 
     602             : /*-************************************************************************************************************
     603             :     @short      return list of key names of our configuration management which represent our module tree
     604             :     @descr      You give use a list of current existing set node names .. and we expand it for all
     605             :                 well known properties which are necessary for this implementation.
     606             :                 These full expanded list should be used to get values of this properties.
     607             : 
     608             :     @seealso    ctor
     609             :     @return     List of all relative addressed properties of given set entry names.
     610             : 
     611             :     @onerror    List will be empty.
     612             :     @threadsafe no
     613             : *//*-*************************************************************************************************************/
     614         119 : css::uno::Sequence< OUString > SvtModuleOptions_Impl::impl_ExpandSetNames( const css::uno::Sequence< OUString >& lSetNames )
     615             : {
     616         119 :     sal_Int32                             nCount     = lSetNames.getLength();
     617         119 :     css::uno::Sequence< OUString > lPropNames ( nCount*PROPERTYCOUNT );
     618         119 :     OUString*                      pPropNames = lPropNames.getArray();
     619         119 :     sal_Int32                             nPropStart = 0;
     620             : 
     621        2618 :     for( sal_Int32 nName=0; nName<nCount; ++nName )
     622             :     {
     623        2499 :         pPropNames[nPropStart+PROPERTYHANDLE_SHORTNAME       ] = lSetNames[nName] + PATHSEPARATOR PROPERTYNAME_SHORTNAME;
     624        2499 :         pPropNames[nPropStart+PROPERTYHANDLE_TEMPLATEFILE    ] = lSetNames[nName] + PATHSEPARATOR PROPERTYNAME_TEMPLATEFILE;
     625        2499 :         pPropNames[nPropStart+PROPERTYHANDLE_WINDOWATTRIBUTES] = lSetNames[nName] + PATHSEPARATOR PROPERTYNAME_WINDOWATTRIBUTES;
     626        2499 :         pPropNames[nPropStart+PROPERTYHANDLE_EMPTYDOCUMENTURL] = lSetNames[nName] + PATHSEPARATOR PROPERTYNAME_EMPTYDOCUMENTURL;
     627        2499 :         pPropNames[nPropStart+PROPERTYHANDLE_DEFAULTFILTER   ] = lSetNames[nName] + PATHSEPARATOR PROPERTYNAME_DEFAULTFILTER;
     628        2499 :         pPropNames[nPropStart+PROPERTYHANDLE_ICON            ] = lSetNames[nName] + PATHSEPARATOR PROPERTYNAME_ICON;
     629        2499 :         nPropStart += PROPERTYCOUNT;
     630             :     }
     631             : 
     632         119 :     return lPropNames;
     633             : }
     634             : 
     635             : /*-************************************************************************************************************
     636             :     @short      helper to classify given factory by name
     637             :     @descr      Every factory has his own long and short name. So we can match right enum value for internal using.
     638             : 
     639             :     @attention  We change in/out parameter "eFactory" in every case! But you should use it only, if return value is sal_True!
     640             :                 Algorithm:  Set out-parameter to probably value ... and check the longname.
     641             :                             If it matches with these factory - break operation and return true AND right set parameter.
     642             :                             Otherwise try next one and so on. If no factory was found return false. Out parameter eFactory
     643             :                             is set to last tried value but shouldn't be used! Because our return value is false!
     644             :     @param      "sLongName" , long name of factory, which should be classified
     645             :     @return     "eFactory"  , right enum value, which match given long name
     646             :                 and true for successfully classification, false otherwise
     647             : 
     648             :     @onerror    We return false.
     649             :     @threadsafe no
     650             : *//*-*************************************************************************************************************/
     651        2499 : bool SvtModuleOptions_Impl::ClassifyFactoryByName( const OUString& sName, SvtModuleOptions::EFactory& eFactory )
     652             : {
     653             :     bool bState;
     654             : 
     655        2499 :     eFactory = SvtModuleOptions::EFactory::WRITER;
     656        2499 :     bState   = ( sName == FACTORYNAME_WRITER );
     657             : 
     658        2499 :     if( !bState )
     659             :     {
     660        2380 :         eFactory = SvtModuleOptions::EFactory::WRITERWEB;
     661        2380 :         bState   = ( sName == FACTORYNAME_WRITERWEB );
     662             :     }
     663             :     // no else!
     664        2499 :     if( !bState )
     665             :     {
     666        2261 :         eFactory = SvtModuleOptions::EFactory::WRITERGLOBAL;
     667        2261 :         bState   = ( sName == FACTORYNAME_WRITERGLOBAL );
     668             :     }
     669             :     // no else!
     670        2499 :     if( !bState )
     671             :     {
     672        2142 :         eFactory = SvtModuleOptions::EFactory::CALC;
     673        2142 :         bState   = ( sName == FACTORYNAME_CALC );
     674             :     }
     675             :     // no else!
     676        2499 :     if( !bState )
     677             :     {
     678        2023 :         eFactory = SvtModuleOptions::EFactory::DRAW;
     679        2023 :         bState   = ( sName == FACTORYNAME_DRAW );
     680             :     }
     681             :     // no else!
     682        2499 :     if( !bState )
     683             :     {
     684        1904 :         eFactory = SvtModuleOptions::EFactory::IMPRESS;
     685        1904 :         bState   = ( sName == FACTORYNAME_IMPRESS );
     686             :     }
     687             :     // no else!
     688        2499 :     if( !bState )
     689             :     {
     690        1785 :         eFactory = SvtModuleOptions::EFactory::MATH;
     691        1785 :         bState   = ( sName == FACTORYNAME_MATH );
     692             :     }
     693             :     // no else!
     694        2499 :     if( !bState )
     695             :     {
     696        1666 :         eFactory = SvtModuleOptions::EFactory::CHART;
     697        1666 :         bState   = ( sName == FACTORYNAME_CHART );
     698             :     }
     699             :     // no else!
     700        2499 :     if( !bState )
     701             :     {
     702        1547 :         eFactory = SvtModuleOptions::EFactory::DATABASE;
     703        1547 :         bState   = ( sName == FACTORYNAME_DATABASE );
     704             :     }
     705             :     // no else!
     706        2499 :     if( !bState )
     707             :     {
     708        1428 :         eFactory = SvtModuleOptions::EFactory::STARTMODULE;
     709        1428 :         bState   = ( sName == FACTORYNAME_STARTMODULE);
     710             :     }
     711             :     // no else!
     712        2499 :     if( !bState )
     713             :     {
     714        1309 :         eFactory = SvtModuleOptions::EFactory::BASIC;
     715        1309 :         bState   = ( sName == FACTORYNAME_BASIC);
     716             :     }
     717             : 
     718        2499 :     return bState;
     719             : }
     720             : 
     721             : /*-************************************************************************************************************
     722             :     @short      read factory configuration
     723             :     @descr      Give us a list of pure factory names (long names!) which can be used as
     724             :                 direct set node names ... and we read her property values and fill internal list.
     725             :                 These method can be used by initial reading at ctor and later updating by "Notify()".
     726             : 
     727             :     @seealso    ctor
     728             :     @seealso    method Notify()
     729             : 
     730             :     @param      "lFactories" is the list of set node entries which should be readed.
     731             :     @onerror    We do nothing.
     732             :     @threadsafe no
     733             : *//*-*************************************************************************************************************/
     734         119 : void SvtModuleOptions_Impl::impl_Read( const css::uno::Sequence< OUString >& lFactories )
     735             : {
     736             :     // Expand every set node name in lFactories to full qualified paths to his properties
     737             :     // and get right values from configuration.
     738         119 :     const css::uno::Sequence< OUString > lProperties = impl_ExpandSetNames( lFactories  );
     739         238 :     const css::uno::Sequence< css::uno::Any >   lValues     = GetProperties( lProperties );
     740             : 
     741             :     // Safe impossible cases.
     742             :     // We need values from ALL configuration keys.
     743             :     // Follow assignment use order of values in relation to our list of key names!
     744             :     OSL_ENSURE( !(lProperties.getLength()!=lValues.getLength()), "SvtModuleOptions_Impl::impl_Read()\nI miss some values of configuration keys!\n" );
     745             : 
     746             :     // Algorithm:   We step over all given factory names and classify it. These enum value can be used as direct index
     747             :     //              in our member list m_lFactories! VAriable nPropertyStart marks start position of every factory
     748             :     //              and her properties in expanded property/value list. The defines PROPERTHANDLE_xxx are used as offset values
     749             :     //              added to nPropertyStart. So we can address every property relative in these lists.
     750             :     //              If we found any valid values ... we reset all existing information for corresponding m_lFactories-entry and
     751             :     //              use a pointer to these struct in memory directly to set new values.
     752             :     //              But we set it only, if bInstalled is true. Otherwise all other values of a factory can be undeclared .. They
     753             :     //              shouldn't be used then.
     754             :     // Attention:   If a propertyset of a factory will be ignored we must step to next start position of next factory infos!
     755             :     //              see "nPropertyStart += PROPERTYCOUNT" ...
     756             : 
     757         119 :     sal_Int32                   nPropertyStart  = 0;
     758         119 :     sal_Int32                   nNodeCount      = lFactories.getLength();
     759         119 :     FactoryInfo*                pInfo           = NULL;
     760             :     SvtModuleOptions::EFactory  eFactory;
     761             : 
     762        2618 :     for( sal_Int32 nSetNode=0; nSetNode<nNodeCount; ++nSetNode )
     763             :     {
     764        2499 :         const OUString& sFactoryName = lFactories[nSetNode];
     765        2499 :         if( ClassifyFactoryByName( sFactoryName, eFactory ) )
     766             :         {
     767        1309 :             OUString sTemp;
     768        1309 :             sal_Int32       nTemp = 0;
     769             : 
     770        1309 :             pInfo = &(m_lFactories[eFactory]);
     771        1309 :             pInfo->free();
     772             : 
     773        1309 :             pInfo->initInstalled( true     );
     774        1309 :             pInfo->initFactory  ( sFactoryName );
     775             : 
     776        1309 :             if (lValues[nPropertyStart+PROPERTYHANDLE_SHORTNAME] >>= sTemp)
     777        1309 :                 pInfo->initShortName( sTemp );
     778        1309 :             if (lValues[nPropertyStart+PROPERTYHANDLE_TEMPLATEFILE] >>= sTemp)
     779        1071 :                 pInfo->initTemplateFile( sTemp );
     780        1309 :             if (lValues[nPropertyStart+PROPERTYHANDLE_WINDOWATTRIBUTES] >>= sTemp)
     781        1072 :                 pInfo->initWindowAttributes( sTemp );
     782        1309 :             if (lValues[nPropertyStart+PROPERTYHANDLE_EMPTYDOCUMENTURL] >>= sTemp)
     783        1071 :                 pInfo->initEmptyDocumentURL( sTemp );
     784        1309 :             if (lValues[nPropertyStart+PROPERTYHANDLE_DEFAULTFILTER   ] >>= sTemp)
     785        1071 :                 pInfo->initDefaultFilter( sTemp );
     786        1309 :             if (lValues[nPropertyStart+PROPERTYHANDLE_ICON] >>= nTemp)
     787        1309 :                 pInfo->initIcon( nTemp );
     788             :         }
     789        2499 :         nPropertyStart += PROPERTYCOUNT;
     790         119 :     }
     791         119 : }
     792             : 
     793           0 : void SvtModuleOptions_Impl::MakeReadonlyStatesAvailable()
     794             : {
     795           0 :     if (m_bReadOnlyStatesWellKnown)
     796           0 :         return;
     797             : 
     798           0 :     css::uno::Sequence< OUString > lFactories = GetNodeNames(OUString());
     799           0 :     sal_Int32 c = lFactories.getLength();
     800           0 :     sal_Int32 i = 0;
     801           0 :     for (i=0; i<c; ++i)
     802             :     {
     803           0 :         OUStringBuffer sPath(256);
     804           0 :         sPath.append(lFactories[i]             );
     805           0 :         sPath.append(PATHSEPARATOR             );
     806           0 :         sPath.append(PROPERTYNAME_DEFAULTFILTER);
     807             : 
     808           0 :         lFactories[i] = sPath.makeStringAndClear();
     809           0 :     }
     810             : 
     811           0 :     css::uno::Sequence< sal_Bool > lReadonlyStates = GetReadOnlyStates(lFactories);
     812           0 :     for (i=0; i<c; ++i)
     813             :     {
     814           0 :         OUString&            rFactoryName = lFactories[i];
     815             :         SvtModuleOptions::EFactory  eFactory;
     816             : 
     817           0 :         if (!ClassifyFactoryByName(rFactoryName, eFactory))
     818           0 :             continue;
     819             : 
     820           0 :         FactoryInfo& rInfo = m_lFactories[eFactory];
     821           0 :         rInfo.setDefaultFilterReadonly(lReadonlyStates[i]);
     822             :     }
     823             : 
     824           0 :     m_bReadOnlyStatesWellKnown = true;
     825             : }
     826             : 
     827             : //  initialize static member
     828             : //  DON'T DO IT IN YOUR HEADER!
     829             : //  see definition for further information
     830             : 
     831             : SvtModuleOptions_Impl*  SvtModuleOptions::m_pDataContainer  = NULL;
     832             : sal_Int32               SvtModuleOptions::m_nRefCount       = 0;
     833             : 
     834             : /*-************************************************************************************************************
     835             :     @short      standard constructor and destructor
     836             :     @descr      This will initialize an instance with default values. We initialize/deinitialize our static data
     837             :                 container and create a static mutex, which is used for threadsafe code in further time of this object.
     838             : 
     839             :     @seealso    method impl_GetOwnStaticMutex()
     840             :     @threadsafe yes
     841             : *//*-*************************************************************************************************************/
     842       27787 : SvtModuleOptions::SvtModuleOptions()
     843             : {
     844       27787 :     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
     845       27787 :     ++m_nRefCount;
     846       27787 :     if( m_nRefCount == 1 )
     847             :     {
     848         119 :         m_pDataContainer = new SvtModuleOptions_Impl();
     849             : 
     850         119 :         ItemHolder1::holdConfigItem(E_MODULEOPTIONS);
     851       27787 :     }
     852       27787 : }
     853             : 
     854       55687 : SvtModuleOptions::~SvtModuleOptions()
     855             : {
     856       27785 :     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
     857       27785 :     --m_nRefCount;
     858       27785 :     if( m_nRefCount == 0 )
     859             :     {
     860         117 :         delete m_pDataContainer;
     861         117 :         m_pDataContainer = NULL;
     862       27785 :     }
     863       27902 : }
     864             : 
     865             : /*-************************************************************************************************************
     866             :     @short      access to configuration data
     867             :     @descr      This methods allow read/write access to configuration values.
     868             :                 They are threadsafe. All calls are forwarded to impl-data-container. See there for further information!
     869             : 
     870             :     @seealso    method impl_GetOwnStaticMutex()
     871             :     @threadsafe yes
     872             : *//*-*************************************************************************************************************/
     873        9253 : bool SvtModuleOptions::IsModuleInstalled( EModule eModule ) const
     874             : {
     875        9253 :     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
     876        9253 :     return m_pDataContainer->IsModuleInstalled( eModule );
     877             : }
     878             : 
     879          13 : OUString SvtModuleOptions::GetFactoryName( EFactory eFactory ) const
     880             : {
     881          13 :     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
     882          13 :     return m_pDataContainer->GetFactoryName( eFactory );
     883             : }
     884             : 
     885         704 : OUString SvtModuleOptions::GetFactoryStandardTemplate( EFactory eFactory ) const
     886             : {
     887         704 :     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
     888         704 :     return m_pDataContainer->GetFactoryStandardTemplate( eFactory );
     889             : }
     890             : 
     891           7 : OUString SvtModuleOptions::GetFactoryEmptyDocumentURL( EFactory eFactory ) const
     892             : {
     893           7 :     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
     894           7 :     return SvtModuleOptions_Impl::GetFactoryEmptyDocumentURL( eFactory );
     895             : }
     896             : 
     897          13 : OUString SvtModuleOptions::GetFactoryDefaultFilter( EFactory eFactory ) const
     898             : {
     899          13 :     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
     900          13 :     return m_pDataContainer->GetFactoryDefaultFilter( eFactory );
     901             : }
     902             : 
     903           0 : bool SvtModuleOptions::IsDefaultFilterReadonly( EFactory eFactory   ) const
     904             : {
     905           0 :     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
     906           0 :     m_pDataContainer->MakeReadonlyStatesAvailable();
     907           0 :     return m_pDataContainer->IsDefaultFilterReadonly( eFactory );
     908             : }
     909             : 
     910        3289 : sal_Int32 SvtModuleOptions::GetFactoryIcon( EFactory eFactory ) const
     911             : {
     912        3289 :     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
     913        3289 :     return m_pDataContainer->GetFactoryIcon( eFactory );
     914             : }
     915             : 
     916           0 : bool SvtModuleOptions::ClassifyFactoryByName( const OUString& sName    ,
     917             :                                                         EFactory&        eFactory )
     918             : {
     919             :     // We don't need any mutex here ... because we don't use any member here!
     920           0 :     return SvtModuleOptions_Impl::ClassifyFactoryByName( sName, eFactory );
     921             : }
     922             : 
     923           0 : void SvtModuleOptions::SetFactoryStandardTemplate(       EFactory         eFactory   ,
     924             :                                                    const OUString& sTemplate  )
     925             : {
     926           0 :     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
     927           0 :     m_pDataContainer->SetFactoryStandardTemplate( eFactory, sTemplate );
     928           0 : }
     929             : 
     930           0 : void SvtModuleOptions::SetFactoryDefaultFilter(       EFactory         eFactory,
     931             :                                                 const OUString& sFilter )
     932             : {
     933           0 :     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
     934           0 :     m_pDataContainer->SetFactoryDefaultFilter( eFactory, sFilter );
     935           0 : }
     936             : 
     937        5087 : bool SvtModuleOptions::IsMath() const
     938             : {
     939        5087 :     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
     940        5087 :     return m_pDataContainer->IsModuleInstalled( EModule::MATH );
     941             : }
     942             : 
     943        5142 : bool SvtModuleOptions::IsChart() const
     944             : {
     945        5142 :     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
     946        5142 :     return m_pDataContainer->IsModuleInstalled( EModule::CHART );
     947             : }
     948             : 
     949        4175 : bool SvtModuleOptions::IsCalc() const
     950             : {
     951        4175 :     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
     952        4175 :     return m_pDataContainer->IsModuleInstalled( EModule::CALC );
     953             : }
     954             : 
     955          63 : bool SvtModuleOptions::IsDraw() const
     956             : {
     957          63 :     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
     958          63 :     return m_pDataContainer->IsModuleInstalled( EModule::DRAW );
     959             : }
     960             : 
     961         307 : bool SvtModuleOptions::IsWriter() const
     962             : {
     963         307 :     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
     964         307 :     return m_pDataContainer->IsModuleInstalled( EModule::WRITER );
     965             : }
     966             : 
     967          63 : bool SvtModuleOptions::IsImpress() const
     968             : {
     969          63 :     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
     970          63 :     return m_pDataContainer->IsModuleInstalled( EModule::IMPRESS );
     971             : }
     972             : 
     973           0 : bool SvtModuleOptions::IsDataBase() const
     974             : {
     975           0 :     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
     976           0 :     return m_pDataContainer->IsModuleInstalled( EModule::DATABASE );
     977             : }
     978             : 
     979             : namespace
     980             : {
     981             :     class theModuleOptionsMutex : public rtl::Static<osl::Mutex, theModuleOptionsMutex> {};
     982             : }
     983             : /*-****************************************************************************************************
     984             :     @short      return a reference to a static mutex
     985             :     @descr      These class is threadsafe.
     986             :                 We create a static mutex only for one time and use it to protect our refcount and container
     987             :                 member!
     988             :     @return     A reference to a static mutex member.
     989             :     @threadsafe yes
     990             : *//*-*****************************************************************************************************/
     991       83688 : ::osl::Mutex& SvtModuleOptions::impl_GetOwnStaticMutex()
     992             : {
     993       83688 :     return theModuleOptionsMutex::get();
     994             : }
     995             : 
     996           1 : OUString SvtModuleOptions::GetModuleName( EModule eModule ) const
     997             : {
     998           1 :     switch( eModule )
     999             :     {
    1000           1 :         case SvtModuleOptions::EModule::WRITER    :   { return OUString("Writer"); }
    1001           0 :         case SvtModuleOptions::EModule::WEB       :   { return OUString("Web"); }
    1002           0 :         case SvtModuleOptions::EModule::GLOBAL    :   { return OUString("Global"); }
    1003           0 :         case SvtModuleOptions::EModule::CALC      :   { return OUString("Calc"); }
    1004           0 :         case SvtModuleOptions::EModule::DRAW      :   { return OUString("Draw"); }
    1005           0 :         case SvtModuleOptions::EModule::IMPRESS   :   { return OUString("Impress"); }
    1006           0 :         case SvtModuleOptions::EModule::MATH      :   { return OUString("Math"); }
    1007           0 :         case SvtModuleOptions::EModule::CHART     :   { return OUString("Chart"); }
    1008           0 :         case SvtModuleOptions::EModule::BASIC     :   { return OUString("Basic"); }
    1009           0 :         case SvtModuleOptions::EModule::DATABASE  :   { return OUString("Database"); }
    1010             :         default:
    1011             :             OSL_FAIL( "unknown module" );
    1012           0 :             break;
    1013             :     }
    1014             : 
    1015           0 :     return OUString();
    1016             : }
    1017             : 
    1018           0 : SvtModuleOptions::EFactory SvtModuleOptions::ClassifyFactoryByShortName(const OUString& sName)
    1019             : {
    1020           0 :     if ( sName == "swriter" )
    1021           0 :         return EFactory::WRITER;
    1022           0 :     if (sName.equalsIgnoreAsciiCase("swriter/Web")) // sometimes they are registered for swriter/web :-(
    1023           0 :         return EFactory::WRITERWEB;
    1024           0 :     if (sName.equalsIgnoreAsciiCase("swriter/GlobalDocument")) // sometimes they are registered for swriter/globaldocument :-(
    1025           0 :         return EFactory::WRITERGLOBAL;
    1026           0 :     if ( sName == "scalc" )
    1027           0 :         return EFactory::CALC;
    1028           0 :     if ( sName == "sdraw" )
    1029           0 :         return EFactory::DRAW;
    1030           0 :     if ( sName == "simpress" )
    1031           0 :         return EFactory::IMPRESS;
    1032           0 :     if ( sName == "schart" )
    1033           0 :         return EFactory::CHART;
    1034           0 :     if ( sName == "smath" )
    1035           0 :         return EFactory::MATH;
    1036           0 :     if ( sName == "sbasic" )
    1037           0 :         return EFactory::BASIC;
    1038           0 :     if ( sName == "sdatabase" )
    1039           0 :         return EFactory::DATABASE;
    1040             : 
    1041           0 :     return EFactory::UNKNOWN_FACTORY;
    1042             : }
    1043             : 
    1044      116986 : SvtModuleOptions::EFactory SvtModuleOptions::ClassifyFactoryByServiceName(const OUString& sName)
    1045             : {
    1046      116986 :     if (sName == FACTORYNAME_WRITERGLOBAL)
    1047           0 :         return EFactory::WRITERGLOBAL;
    1048      116986 :     if (sName == FACTORYNAME_WRITERWEB)
    1049          57 :         return EFactory::WRITERWEB;
    1050      116929 :     if (sName == FACTORYNAME_WRITER)
    1051       84566 :         return EFactory::WRITER;
    1052       32363 :     if (sName == FACTORYNAME_CALC)
    1053       18795 :         return EFactory::CALC;
    1054       13568 :     if (sName == FACTORYNAME_DRAW)
    1055        2359 :         return EFactory::DRAW;
    1056       11209 :     if (sName == FACTORYNAME_IMPRESS)
    1057         967 :         return EFactory::IMPRESS;
    1058       10242 :     if (sName == FACTORYNAME_MATH)
    1059        1424 :         return EFactory::MATH;
    1060        8818 :     if (sName == FACTORYNAME_CHART)
    1061         824 :         return EFactory::CHART;
    1062        7994 :     if (sName == FACTORYNAME_DATABASE)
    1063         199 :         return EFactory::DATABASE;
    1064        7795 :     if (sName == FACTORYNAME_STARTMODULE)
    1065           0 :         return EFactory::STARTMODULE;
    1066        7795 :     if (sName == FACTORYNAME_BASIC)
    1067           0 :         return EFactory::BASIC;
    1068             : 
    1069        7795 :     return EFactory::UNKNOWN_FACTORY;
    1070             : }
    1071             : 
    1072           0 : SvtModuleOptions::EFactory SvtModuleOptions::ClassifyFactoryByURL(const OUString&                                 sURL            ,
    1073             :                                                                   const css::uno::Sequence< css::beans::PropertyValue >& lMediaDescriptor)
    1074             : {
    1075           0 :     css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
    1076             : 
    1077           0 :     css::uno::Reference< css::container::XNameAccess > xFilterCfg;
    1078           0 :     css::uno::Reference< css::container::XNameAccess > xTypeCfg;
    1079             :     try
    1080             :     {
    1081           0 :         xFilterCfg = css::uno::Reference< css::container::XNameAccess >(
    1082           0 :             xContext->getServiceManager()->createInstanceWithContext("com.sun.star.document.FilterFactory", xContext), css::uno::UNO_QUERY);
    1083           0 :         xTypeCfg = css::uno::Reference< css::container::XNameAccess >(
    1084           0 :             xContext->getServiceManager()->createInstanceWithContext("com.sun.star.document.TypeDetection", xContext), css::uno::UNO_QUERY);
    1085             :     }
    1086           0 :     catch(const css::uno::RuntimeException&)
    1087           0 :         { throw; }
    1088           0 :     catch(const css::uno::Exception&)
    1089           0 :         { return EFactory::UNKNOWN_FACTORY; }
    1090             : 
    1091           0 :     ::comphelper::SequenceAsHashMap stlDesc(lMediaDescriptor);
    1092             : 
    1093             :     // is there already a filter inside the descriptor?
    1094           0 :     OUString sFilterName = stlDesc.getUnpackedValueOrDefault("FilterName", OUString());
    1095           0 :     if (!sFilterName.isEmpty())
    1096             :     {
    1097             :         try
    1098             :         {
    1099           0 :             ::comphelper::SequenceAsHashMap stlFilterProps   (xFilterCfg->getByName(sFilterName));
    1100           0 :             OUString                 sDocumentService = stlFilterProps.getUnpackedValueOrDefault("DocumentService", OUString());
    1101           0 :             SvtModuleOptions::EFactory      eApp             = SvtModuleOptions::ClassifyFactoryByServiceName(sDocumentService);
    1102             : 
    1103           0 :             if (eApp != EFactory::UNKNOWN_FACTORY)
    1104           0 :                 return eApp;
    1105             :         }
    1106           0 :         catch(const css::uno::RuntimeException&)
    1107           0 :             { throw; }
    1108           0 :         catch(const css::uno::Exception&)
    1109             :             { /* do nothing here ... may the following code can help!*/ }
    1110             :     }
    1111             : 
    1112             :     // is there already a type inside the descriptor?
    1113           0 :     OUString sTypeName = stlDesc.getUnpackedValueOrDefault("TypeName", OUString());
    1114           0 :     if (sTypeName.isEmpty())
    1115             :     {
    1116             :         // no :-(
    1117             :         // start flat detection of URL
    1118           0 :         css::uno::Reference< css::document::XTypeDetection > xDetect(xTypeCfg, css::uno::UNO_QUERY);
    1119           0 :         sTypeName = xDetect->queryTypeByURL(sURL);
    1120             :     }
    1121             : 
    1122           0 :     if (sTypeName.isEmpty())
    1123           0 :         return EFactory::UNKNOWN_FACTORY;
    1124             : 
    1125             :     // yes - there is a type info
    1126             :     // Try to find the preferred filter.
    1127             :     try
    1128             :     {
    1129           0 :         ::comphelper::SequenceAsHashMap stlTypeProps     (xTypeCfg->getByName(sTypeName));
    1130           0 :         OUString                 sPreferredFilter = stlTypeProps.getUnpackedValueOrDefault("PreferredFilter", OUString());
    1131           0 :         ::comphelper::SequenceAsHashMap stlFilterProps   (xFilterCfg->getByName(sPreferredFilter));
    1132           0 :         OUString                 sDocumentService = stlFilterProps.getUnpackedValueOrDefault("DocumentService", OUString());
    1133           0 :         SvtModuleOptions::EFactory      eApp             = SvtModuleOptions::ClassifyFactoryByServiceName(sDocumentService);
    1134             : 
    1135           0 :         if (eApp != EFactory::UNKNOWN_FACTORY)
    1136           0 :             return eApp;
    1137             :     }
    1138           0 :     catch(const css::uno::RuntimeException&)
    1139           0 :         { throw; }
    1140           0 :     catch(const css::uno::Exception&)
    1141             :         { /* do nothing here ... may the following code can help!*/ }
    1142             : 
    1143             :     // no filter/no type/no detection result => no fun :-)
    1144           0 :     return EFactory::UNKNOWN_FACTORY;
    1145             : }
    1146             : 
    1147        5863 : SvtModuleOptions::EFactory SvtModuleOptions::ClassifyFactoryByModel(const css::uno::Reference< css::frame::XModel >& xModel)
    1148             : {
    1149        5863 :     css::uno::Reference< css::lang::XServiceInfo > xInfo(xModel, css::uno::UNO_QUERY);
    1150        5863 :     if (!xInfo.is())
    1151           0 :         return EFactory::UNKNOWN_FACTORY;
    1152             : 
    1153       11726 :     const css::uno::Sequence< OUString > lServices = xInfo->getSupportedServiceNames();
    1154        5863 :     const OUString*                      pServices = lServices.getConstArray();
    1155             : 
    1156       13658 :     for (sal_Int32 i=0; i<lServices.getLength(); ++i)
    1157             :     {
    1158       13658 :         SvtModuleOptions::EFactory eApp = SvtModuleOptions::ClassifyFactoryByServiceName(pServices[i]);
    1159       13658 :         if (eApp != EFactory::UNKNOWN_FACTORY)
    1160        5863 :             return eApp;
    1161             :     }
    1162             : 
    1163        5863 :     return EFactory::UNKNOWN_FACTORY;
    1164             : }
    1165             : 
    1166           0 : ::com::sun::star::uno::Sequence < OUString > SvtModuleOptions::GetAllServiceNames()
    1167             : {
    1168           0 :     ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
    1169           0 :     return m_pDataContainer->GetAllServiceNames();
    1170             : }
    1171             : 
    1172          17 : OUString SvtModuleOptions::GetDefaultModuleName()
    1173             : {
    1174          17 :     OUString aModule;
    1175          17 :     if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::EModule::WRITER))
    1176          17 :         aModule = GetFactoryShortName(SvtModuleOptions::EFactory::WRITER);
    1177           0 :     else if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::EModule::CALC))
    1178           0 :         aModule = GetFactoryShortName(SvtModuleOptions::EFactory::CALC);
    1179           0 :     else if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::EModule::IMPRESS))
    1180           0 :         aModule = GetFactoryShortName(SvtModuleOptions::EFactory::IMPRESS);
    1181           0 :     else if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::EModule::DATABASE))
    1182           0 :         aModule = GetFactoryShortName(SvtModuleOptions::EFactory::DATABASE);
    1183           0 :     else if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::EModule::DRAW))
    1184           0 :         aModule = GetFactoryShortName(SvtModuleOptions::EFactory::DRAW);
    1185           0 :     else if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::EModule::WEB))
    1186           0 :         aModule = GetFactoryShortName(SvtModuleOptions::EFactory::WRITERWEB);
    1187           0 :     else if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::EModule::GLOBAL))
    1188           0 :         aModule = GetFactoryShortName(SvtModuleOptions::EFactory::WRITERGLOBAL);
    1189           0 :     else if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::EModule::MATH))
    1190           0 :         aModule = GetFactoryShortName(SvtModuleOptions::EFactory::MATH);
    1191          17 :     return aModule;
    1192             : }
    1193             : 
    1194             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11