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