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

Generated by: LCOV version 1.10