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

Generated by: LCOV version 1.10