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

Generated by: LCOV version 1.11