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