LCOV - code coverage report
Current view: top level - unotools/source/config - defaultoptions.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 96 0.0 %
Date: 2014-04-14 Functions: 0 11 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <unotools/defaultoptions.hxx>
      21             : #include <unotools/pathoptions.hxx>
      22             : #include <unotools/configitem.hxx>
      23             : #include <unotools/configmgr.hxx>
      24             : #include <tools/debug.hxx>
      25             : #include <com/sun/star/uno/Any.hxx>
      26             : #include <com/sun/star/uno/Sequence.hxx>
      27             : #include <osl/mutex.hxx>
      28             : 
      29             : #include <unotools/localfilehelper.hxx>
      30             : #include <rtl/instance.hxx>
      31             : 
      32             : #include <itemholder1.hxx>
      33             : 
      34             : using namespace osl;
      35             : using namespace utl;
      36             : using namespace com::sun::star::uno;
      37             : 
      38             : // define ----------------------------------------------------------------
      39             : 
      40             : #define DEFAULTPATH__ADDIN          0
      41             : #define DEFAULTPATH__AUTOCORRECT    1
      42             : #define DEFAULTPATH__AUTOTEXT       2
      43             : #define DEFAULTPATH__BACKUP         3
      44             : #define DEFAULTPATH__BASIC          4
      45             : #define DEFAULTPATH__BITMAP         5
      46             : #define DEFAULTPATH__CONFIG         6
      47             : #define DEFAULTPATH__DICTIONARY     7
      48             : #define DEFAULTPATH__FAVORITES      8
      49             : #define DEFAULTPATH__FILTER         9
      50             : #define DEFAULTPATH__GALLERY        10
      51             : #define DEFAULTPATH__GRAPHIC        11
      52             : #define DEFAULTPATH__HELP           12
      53             : #define DEFAULTPATH__LINGUISTIC     13
      54             : #define DEFAULTPATH__MODULE         14
      55             : #define DEFAULTPATH__PALETTE        15
      56             : #define DEFAULTPATH__PLUGIN         16
      57             : #define DEFAULTPATH__TEMP           17
      58             : #define DEFAULTPATH__TEMPLATE       18
      59             : #define DEFAULTPATH__USERCONFIG     19
      60             : #define DEFAULTPATH__WORK           20
      61             : #define DEFAULTPATH__USERDICTIONARY 21
      62             : 
      63             : // class SvtDefaultOptions_Impl ------------------------------------------
      64             : 
      65           0 : class SvtDefaultOptions_Impl : public utl::ConfigItem
      66             : {
      67             : public:
      68             :     OUString         m_aAddinPath;
      69             :     OUString         m_aAutoCorrectPath;
      70             :     OUString         m_aAutoTextPath;
      71             :     OUString         m_aBackupPath;
      72             :     OUString         m_aBasicPath;
      73             :     OUString         m_aBitmapPath;
      74             :     OUString         m_aConfigPath;
      75             :     OUString         m_aDictionaryPath;
      76             :     OUString         m_aFavoritesPath;
      77             :     OUString         m_aFilterPath;
      78             :     OUString         m_aGalleryPath;
      79             :     OUString         m_aGraphicPath;
      80             :     OUString         m_aHelpPath;
      81             :     OUString         m_aLinguisticPath;
      82             :     OUString         m_aModulePath;
      83             :     OUString         m_aPalettePath;
      84             :     OUString         m_aPluginPath;
      85             :     OUString         m_aTempPath;
      86             :     OUString         m_aTemplatePath;
      87             :     OUString         m_aUserConfigPath;
      88             :     OUString         m_aWorkPath;
      89             :     OUString         m_aUserDictionaryPath;
      90             : 
      91             :                     SvtDefaultOptions_Impl();
      92             : 
      93             :     OUString         GetDefaultPath( sal_uInt16 nId ) const;
      94             :     virtual void    Commit() SAL_OVERRIDE;
      95             :     virtual void    Notify( const com::sun::star::uno::Sequence<OUString>& aPropertyNames) SAL_OVERRIDE;
      96             : };
      97             : 
      98             : // global ----------------------------------------------------------------
      99             : 
     100             : static SvtDefaultOptions_Impl*  pOptions = NULL;
     101             : static sal_Int32                nRefCount = 0;
     102             : 
     103             : typedef OUString SvtDefaultOptions_Impl:: *PathStrPtr;
     104             : 
     105             : struct PathToDefaultMapping_Impl
     106             : {
     107             :     SvtPathOptions::Paths   _ePath;
     108             :     PathStrPtr              _pDefaultPath;
     109             : };
     110             : 
     111             : static PathToDefaultMapping_Impl const PathMap_Impl[] =
     112             : {
     113             :     { SvtPathOptions::PATH_ADDIN,           &SvtDefaultOptions_Impl::m_aAddinPath },
     114             :     { SvtPathOptions::PATH_AUTOCORRECT,     &SvtDefaultOptions_Impl::m_aAutoCorrectPath },
     115             :     { SvtPathOptions::PATH_AUTOTEXT,        &SvtDefaultOptions_Impl::m_aAutoTextPath },
     116             :     { SvtPathOptions::PATH_BACKUP,          &SvtDefaultOptions_Impl::m_aBackupPath },
     117             :     { SvtPathOptions::PATH_BASIC,           &SvtDefaultOptions_Impl::m_aBasicPath },
     118             :     { SvtPathOptions::PATH_BITMAP,          &SvtDefaultOptions_Impl::m_aBitmapPath },
     119             :     { SvtPathOptions::PATH_CONFIG,          &SvtDefaultOptions_Impl::m_aConfigPath },
     120             :     { SvtPathOptions::PATH_DICTIONARY,      &SvtDefaultOptions_Impl::m_aDictionaryPath },
     121             :     { SvtPathOptions::PATH_FAVORITES,       &SvtDefaultOptions_Impl::m_aFavoritesPath },
     122             :     { SvtPathOptions::PATH_FILTER,          &SvtDefaultOptions_Impl::m_aFilterPath },
     123             :     { SvtPathOptions::PATH_GALLERY,         &SvtDefaultOptions_Impl::m_aGalleryPath },
     124             :     { SvtPathOptions::PATH_GRAPHIC,         &SvtDefaultOptions_Impl::m_aGraphicPath },
     125             :     { SvtPathOptions::PATH_HELP,            &SvtDefaultOptions_Impl::m_aHelpPath },
     126             :     { SvtPathOptions::PATH_LINGUISTIC,      &SvtDefaultOptions_Impl::m_aLinguisticPath },
     127             :     { SvtPathOptions::PATH_MODULE,          &SvtDefaultOptions_Impl::m_aModulePath },
     128             :     { SvtPathOptions::PATH_PALETTE,         &SvtDefaultOptions_Impl::m_aPalettePath },
     129             :     { SvtPathOptions::PATH_PLUGIN,          &SvtDefaultOptions_Impl::m_aPluginPath },
     130             :     { SvtPathOptions::PATH_TEMP,            &SvtDefaultOptions_Impl::m_aTempPath },
     131             :     { SvtPathOptions::PATH_TEMPLATE,        &SvtDefaultOptions_Impl::m_aTemplatePath },
     132             :     { SvtPathOptions::PATH_USERCONFIG,      &SvtDefaultOptions_Impl::m_aUserConfigPath },
     133             :     { SvtPathOptions::PATH_WORK,            &SvtDefaultOptions_Impl::m_aWorkPath }
     134             : };
     135             : 
     136             : // functions -------------------------------------------------------------
     137             : 
     138           0 : Sequence< OUString > GetDefaultPropertyNames()
     139             : {
     140             :     static const char* aPropNames[] =
     141             :     {
     142             :         "Addin",            // PATH_ADDIN
     143             :         "AutoCorrect",      // PATH_AUTOCORRECT
     144             :         "AutoText",         // PATH_AUTOTEXT
     145             :         "Backup",           // PATH_BACKUP
     146             :         "Basic",            // PATH_BASIC
     147             :         "Bitmap",           // PATH_BITMAP
     148             :         "Config",           // PATH_CONFIG
     149             :         "Dictionary",       // PATH_DICTIONARY
     150             :         "Favorite",         // PATH_FAVORITES
     151             :         "Filter",           // PATH_FILTER
     152             :         "Gallery",          // PATH_GALLERY
     153             :         "Graphic",          // PATH_GRAPHIC
     154             :         "Help",             // PATH_HELP
     155             :         "Linguistic",       // PATH_LINGUISTIC
     156             :         "Module",           // PATH_MODULE
     157             :         "Palette",          // PATH_PALETTE
     158             :         "Plugin",           // PATH_PLUGIN
     159             :         "Temp",             // PATH_TEMP
     160             :         "Template",         // PATH_TEMPLATE
     161             :         "UserConfig",       // PATH_USERCONFIG
     162             :         "Work"              // PATH_WORK
     163             :     };
     164             : 
     165           0 :     const int nCount = sizeof( aPropNames ) / sizeof( const char* );
     166           0 :     Sequence< OUString > aNames( nCount );
     167           0 :     OUString* pNames = aNames.getArray();
     168           0 :     for ( int i = 0; i < nCount; i++ )
     169           0 :         pNames[i] = OUString::createFromAscii( aPropNames[i] );
     170             : 
     171           0 :     return aNames;
     172             : }
     173             : 
     174           0 : void SvtDefaultOptions_Impl::Notify( const Sequence< OUString >&  )
     175             : {
     176             :     // no notification, will never be changed
     177           0 : }
     178             : 
     179           0 : void SvtDefaultOptions_Impl::Commit()
     180             : {
     181             :     // will never be changed
     182           0 : }
     183             : 
     184             : // class SvtDefaultOptions_Impl ------------------------------------------
     185             : 
     186           0 : OUString SvtDefaultOptions_Impl::GetDefaultPath( sal_uInt16 nId ) const
     187             : {
     188           0 :     OUString aRet;
     189           0 :     sal_uInt16 nIdx = 0;
     190             : 
     191           0 :     while ( PathMap_Impl[nIdx]._ePath <= SvtPathOptions::PATH_WORK )
     192             :     {
     193           0 :         if ( nId == PathMap_Impl[nIdx]._ePath && PathMap_Impl[nIdx]._pDefaultPath )
     194             :         {
     195           0 :             aRet = this->*(PathMap_Impl[nIdx]._pDefaultPath);
     196           0 :             if ( nId == SvtPathOptions::PATH_ADDIN ||
     197           0 :                  nId == SvtPathOptions::PATH_FILTER ||
     198           0 :                  nId == SvtPathOptions::PATH_HELP ||
     199           0 :                  nId == SvtPathOptions::PATH_MODULE ||
     200             :                  nId == SvtPathOptions::PATH_PLUGIN )
     201             :             {
     202           0 :                 OUString aTmp;
     203           0 :                 ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aRet, aTmp );
     204           0 :                 aRet = aTmp;
     205             :             }
     206             : 
     207           0 :             break;
     208             :         }
     209           0 :         ++nIdx;
     210             :     }
     211             : 
     212           0 :     return aRet;
     213             : }
     214             : 
     215           0 : SvtDefaultOptions_Impl::SvtDefaultOptions_Impl() : ConfigItem( "Office.Common/Path/Default" )
     216             : {
     217           0 :     Sequence< OUString > aNames = GetDefaultPropertyNames();
     218           0 :     Sequence< Any > aValues = GetProperties( aNames );
     219           0 :     EnableNotification( aNames );
     220           0 :     const Any* pValues = aValues.getConstArray();
     221             :     DBG_ASSERT( aValues.getLength() == aNames.getLength(), "GetProperties failed" );
     222           0 :     if ( aValues.getLength() == aNames.getLength() )
     223             :     {
     224           0 :         SvtPathOptions aPathOpt;
     225           0 :         OUString aTempStr, aFullPath;
     226             : 
     227           0 :         for ( int nProp = 0; nProp < aNames.getLength(); nProp++ )
     228             :         {
     229           0 :             if ( pValues[nProp].hasValue() )
     230             :             {
     231           0 :                 switch ( pValues[nProp].getValueTypeClass() )
     232             :                 {
     233             :                     case ::com::sun::star::uno::TypeClass_STRING :
     234             :                     {
     235             :                         // multi paths
     236           0 :                         if ( pValues[nProp] >>= aTempStr )
     237           0 :                             aFullPath = aPathOpt.SubstituteVariable( aTempStr );
     238             :                         else
     239             :                         {
     240             :                             SAL_WARN( "unotools.config", "any operator >>= failed" );
     241             :                         }
     242           0 :                         break;
     243             :                     }
     244             : 
     245             :                     case ::com::sun::star::uno::TypeClass_SEQUENCE :
     246             :                     {
     247             :                         // single paths
     248           0 :                         aFullPath = OUString();
     249           0 :                         Sequence < OUString > aList;
     250           0 :                         if ( pValues[nProp] >>= aList )
     251             :                         {
     252           0 :                             sal_Int32 nCount = aList.getLength();
     253           0 :                             for ( sal_Int32 nPosition = 0; nPosition < nCount; ++nPosition )
     254             :                             {
     255           0 :                                 aTempStr = aPathOpt.SubstituteVariable( aList[ nPosition ] );
     256           0 :                                 aFullPath += aTempStr;
     257           0 :                                 if ( nPosition < nCount-1 )
     258           0 :                                     aFullPath += ";";
     259             :                             }
     260             :                         }
     261             :                         else
     262             :                         {
     263             :                             SAL_WARN( "unotools.config", "any operator >>= failed" );
     264             :                         }
     265           0 :                         break;
     266             :                     }
     267             : 
     268             :                     default:
     269             :                     {
     270             :                         SAL_WARN( "unotools.config", "Wrong any type" );
     271             :                     }
     272             :                 }
     273             : 
     274           0 :                 switch ( nProp )
     275             :                 {
     276           0 :                     case DEFAULTPATH__ADDIN:            m_aAddinPath = aFullPath;         break;
     277           0 :                     case DEFAULTPATH__AUTOCORRECT:      m_aAutoCorrectPath = aFullPath;   break;
     278           0 :                     case DEFAULTPATH__AUTOTEXT:         m_aAutoTextPath = aFullPath;      break;
     279           0 :                     case DEFAULTPATH__BACKUP:           m_aBackupPath = aFullPath;        break;
     280           0 :                     case DEFAULTPATH__BASIC:            m_aBasicPath = aFullPath;         break;
     281           0 :                     case DEFAULTPATH__BITMAP:           m_aBitmapPath = aFullPath;        break;
     282           0 :                     case DEFAULTPATH__CONFIG:           m_aConfigPath = aFullPath;        break;
     283           0 :                     case DEFAULTPATH__DICTIONARY:       m_aDictionaryPath = aFullPath;    break;
     284           0 :                     case DEFAULTPATH__FAVORITES:        m_aFavoritesPath = aFullPath;     break;
     285           0 :                     case DEFAULTPATH__FILTER:           m_aFilterPath = aFullPath;        break;
     286           0 :                     case DEFAULTPATH__GALLERY:          m_aGalleryPath = aFullPath;       break;
     287           0 :                     case DEFAULTPATH__GRAPHIC:          m_aGraphicPath = aFullPath;       break;
     288           0 :                     case DEFAULTPATH__HELP:             m_aHelpPath = aFullPath;          break;
     289           0 :                     case DEFAULTPATH__LINGUISTIC:       m_aLinguisticPath = aFullPath;    break;
     290           0 :                     case DEFAULTPATH__MODULE:           m_aModulePath = aFullPath;        break;
     291           0 :                     case DEFAULTPATH__PALETTE:          m_aPalettePath = aFullPath;       break;
     292           0 :                     case DEFAULTPATH__PLUGIN:           m_aPluginPath = aFullPath;        break;
     293           0 :                     case DEFAULTPATH__TEMP:             m_aTempPath = aFullPath;          break;
     294           0 :                     case DEFAULTPATH__TEMPLATE:         m_aTemplatePath = aFullPath;      break;
     295           0 :                     case DEFAULTPATH__USERCONFIG:       m_aUserConfigPath = aFullPath;    break;
     296           0 :                     case DEFAULTPATH__WORK:             m_aWorkPath = aFullPath;          break;
     297           0 :                     case DEFAULTPATH__USERDICTIONARY:   m_aUserDictionaryPath = aFullPath;break;
     298             : 
     299             :                     default:
     300             :                         SAL_WARN( "unotools.config", "invalid index to load a default path" );
     301             :                 }
     302             :             }
     303           0 :         }
     304           0 :     }
     305           0 : }
     306             : 
     307             : // class SvtDefaultOptions -----------------------------------------------
     308             : namespace { struct lclMutex : public rtl::Static< ::osl::Mutex, lclMutex > {}; }
     309             : 
     310           0 : SvtDefaultOptions::SvtDefaultOptions()
     311             : {
     312             :     // Global access, must be guarded (multithreading)
     313           0 :     ::osl::MutexGuard aGuard( lclMutex::get() );
     314           0 :     if ( !pOptions )
     315             :     {
     316           0 :         pOptions = new SvtDefaultOptions_Impl;
     317           0 :         ItemHolder1::holdConfigItem(E_DEFAULTOPTIONS);
     318             :     }
     319           0 :     ++nRefCount;
     320           0 :     pImp = pOptions;
     321           0 : }
     322             : 
     323           0 : SvtDefaultOptions::~SvtDefaultOptions()
     324             : {
     325             :     // Global access, must be guarded (multithreading)
     326           0 :     ::osl::MutexGuard aGuard( lclMutex::get() );
     327           0 :     if ( !--nRefCount )
     328             :     {
     329           0 :         if ( pOptions->IsModified() )
     330           0 :             pOptions->Commit();
     331           0 :         DELETEZ( pOptions );
     332           0 :     }
     333           0 : }
     334             : 
     335           0 : OUString SvtDefaultOptions::GetDefaultPath( sal_uInt16 nId ) const
     336             : {
     337           0 :     return pImp->GetDefaultPath( nId );
     338             : }
     339             : 
     340             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10