bump product version to 4.1.6.2
[LibreOffice.git] / unotools / source / config / moduleoptions.cxx
blob8e5cfc69e8750587dac0e259d99a0239fd20d523
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
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>
41 #include "itemholder1.hxx"
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!
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 OUString("Setup/Office/Factories" )
55 #define PATHSEPARATOR OUString("/" )
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 OUString("ooSetupFactoryShortName" )
60 #define PROPERTYNAME_TEMPLATEFILE OUString("ooSetupFactoryTemplateFile" )
61 #define PROPERTYNAME_WINDOWATTRIBUTES OUString("ooSetupFactoryWindowAttributes")
62 #define PROPERTYNAME_EMPTYDOCUMENTURL OUString("ooSetupFactoryEmptyDocumentURL")
63 #define PROPERTYNAME_DEFAULTFILTER OUString("ooSetupFactoryDefaultFilter" )
64 #define PROPERTYNAME_ICON OUString("ooSetupFactoryIcon" )
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
73 #define PROPERTYCOUNT 6
75 #define FACTORYNAME_WRITER OUString("com.sun.star.text.TextDocument" )
76 #define FACTORYNAME_WRITERWEB OUString("com.sun.star.text.WebDocument" )
77 #define FACTORYNAME_WRITERGLOBAL OUString("com.sun.star.text.GlobalDocument" )
78 #define FACTORYNAME_CALC OUString("com.sun.star.sheet.SpreadsheetDocument" )
79 #define FACTORYNAME_DRAW OUString("com.sun.star.drawing.DrawingDocument" )
80 #define FACTORYNAME_IMPRESS OUString("com.sun.star.presentation.PresentationDocument")
81 #define FACTORYNAME_MATH OUString("com.sun.star.formula.FormulaProperties" )
82 #define FACTORYNAME_CHART OUString("com.sun.star.chart2.ChartDocument" )
83 #define FACTORYNAME_DATABASE OUString("com.sun.star.sdb.OfficeDatabaseDocument" )
84 #define FACTORYNAME_STARTMODULE OUString("com.sun.star.frame.StartModule" )
86 #define FACTORYCOUNT 10
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 information.
92 *//*-*************************************************************************************************************/
93 struct FactoryInfo
95 public:
96 //---------------------------------------------------------------------------------------------------------
97 // initialize empty struct
98 FactoryInfo()
100 free();
103 //---------------------------------------------------------------------------------------------------------
104 // easy way to reset struct member!
105 void free()
107 bInstalled = sal_False;
108 sFactory = "";
109 sShortName = "";
110 sTemplateFile = "";
111 sWindowAttributes = "";
112 sEmptyDocumentURL = "";
113 sDefaultFilter = "";
114 nIcon = 0;
115 bChangedTemplateFile = sal_False;
116 bChangedWindowAttributes = sal_False;
117 bChangedEmptyDocumentURL = sal_False;
118 bChangedDefaultFilter = sal_False;
119 bChangedIcon = sal_False;
120 bDefaultFilterReadonly = sal_False;
123 //---------------------------------------------------------------------------------------------------------
124 // returns list of properties, which has changed only!
125 // We use given value of sNodeBase to build full qualified paths ...
126 // Last sign of it must be "/". because we use it directly, without any additional things!
127 css::uno::Sequence< css::beans::PropertyValue > getChangedProperties( const OUString& sNodeBase )
129 // a) reserve memory for max. count of changed properties
130 // b) add names and values of changed ones only and count it
131 // c) resize return list by using count
132 css::uno::Sequence< css::beans::PropertyValue > lProperties ( 4 );
133 sal_Int8 nRealyChanged = 0 ;
135 if( bChangedTemplateFile == sal_True )
137 lProperties[nRealyChanged].Name = sNodeBase + PROPERTYNAME_TEMPLATEFILE;
139 if ( !sTemplateFile.isEmpty() )
141 lProperties[nRealyChanged].Value
142 <<= getStringSubstitution()
143 ->reSubstituteVariables( sTemplateFile );
145 else
147 lProperties[nRealyChanged].Value <<= sTemplateFile;
150 ++nRealyChanged;
152 if( bChangedWindowAttributes == sal_True )
154 lProperties[nRealyChanged].Name = sNodeBase + PROPERTYNAME_WINDOWATTRIBUTES;
155 lProperties[nRealyChanged].Value <<= sWindowAttributes;
156 ++nRealyChanged;
158 if( bChangedEmptyDocumentURL == sal_True )
160 lProperties[nRealyChanged].Name = sNodeBase + PROPERTYNAME_EMPTYDOCUMENTURL;
161 lProperties[nRealyChanged].Value <<= sEmptyDocumentURL;
162 ++nRealyChanged;
164 if( bChangedDefaultFilter == sal_True )
166 lProperties[nRealyChanged].Name = sNodeBase + PROPERTYNAME_DEFAULTFILTER;
167 lProperties[nRealyChanged].Value <<= sDefaultFilter;
168 ++nRealyChanged;
170 if( bChangedIcon == sal_True )
172 lProperties[nRealyChanged].Name = sNodeBase + PROPERTYNAME_ICON;
173 lProperties[nRealyChanged].Value <<= nIcon;
174 ++nRealyChanged;
177 // Don't forget to reset changed flags! Otherwise we save it again and again and ...
178 bChangedTemplateFile = sal_False ;
179 bChangedWindowAttributes = sal_False ;
180 bChangedEmptyDocumentURL = sal_False ;
181 bChangedDefaultFilter = sal_False ;
182 bChangedIcon = sal_False ;
184 lProperties.realloc( nRealyChanged );
185 return lProperties;
188 //---------------------------------------------------------------------------------------------------------
189 // We must support setting AND marking of changed values.
190 // That's why we can't make our member public. We must use get/set/init methods
191 // to control access on it!
192 sal_Bool getInstalled () const { return bInstalled; };
193 OUString getFactory () const { return sFactory; };
194 OUString getShortName () const { return sShortName; };
195 OUString getTemplateFile () const { return sTemplateFile; };
196 OUString getWindowAttributes () const { return sWindowAttributes; };
197 OUString getDefaultFilter () const { return sDefaultFilter; };
198 sal_Bool isDefaultFilterReadonly() const { return bDefaultFilterReadonly; }
199 sal_Int32 getIcon () const { return nIcon; };
201 //---------------------------------------------------------------------------------------------------------
202 // If you call set-methods - we check for changes of valkues and mark it.
203 // But if you whish to set it without that ... you must initialize it!
204 void initInstalled ( sal_Bool bNewInstalled ) { bInstalled = bNewInstalled ; }
205 void initFactory ( const OUString& sNewFactory ) { sFactory = sNewFactory ; }
206 void initShortName ( const OUString& sNewShortName ) { sShortName = sNewShortName ; }
207 void initWindowAttributes ( const OUString& sNewWindowAttributes ) { sWindowAttributes = sNewWindowAttributes ; }
208 void initEmptyDocumentURL ( const OUString& sNewEmptyDocumentURL ) { sEmptyDocumentURL = sNewEmptyDocumentURL ; }
209 void initDefaultFilter ( const OUString& sNewDefaultFilter ) { sDefaultFilter = sNewDefaultFilter ; }
210 void setDefaultFilterReadonly( const sal_Bool bVal){bDefaultFilterReadonly = bVal;}
211 void initIcon ( sal_Int32 nNewIcon ) { nIcon = nNewIcon ; }
213 //---------------------------------------------------------------------------------------------------------
214 void initTemplateFile( const OUString& sNewTemplateFile )
216 if ( !sNewTemplateFile.isEmpty() )
218 sTemplateFile
219 = getStringSubstitution()
220 ->substituteVariables( sNewTemplateFile, sal_False );
222 else
224 sTemplateFile = sNewTemplateFile;
228 //---------------------------------------------------------------------------------------------------------
229 void setTemplateFile( const OUString& sNewTemplateFile )
231 if( sTemplateFile != sNewTemplateFile )
233 sTemplateFile = sNewTemplateFile;
234 bChangedTemplateFile = sal_True ;
238 //---------------------------------------------------------------------------------------------------------
239 void setWindowAttributes( const OUString& sNewWindowAttributes )
241 if( sWindowAttributes != sNewWindowAttributes )
243 sWindowAttributes = sNewWindowAttributes;
244 bChangedWindowAttributes = sal_True ;
248 //---------------------------------------------------------------------------------------------------------
249 void setDefaultFilter( const OUString& sNewDefaultFilter )
251 if( sDefaultFilter != sNewDefaultFilter )
253 sDefaultFilter = sNewDefaultFilter;
254 bChangedDefaultFilter = sal_True ;
258 private:
259 css::uno::Reference< css::util::XStringSubstitution > getStringSubstitution()
261 if ( !xSubstVars.is() )
263 xSubstVars.set( css::util::PathSubstitution::create(::comphelper::getProcessComponentContext()) );
265 return xSubstVars;
268 sal_Bool bInstalled ;
269 OUString sFactory ;
270 OUString sShortName ;
271 OUString sTemplateFile ;
272 OUString sWindowAttributes ;
273 OUString sEmptyDocumentURL ;
274 OUString sDefaultFilter ;
275 sal_Int32 nIcon ;
277 sal_Bool bChangedTemplateFile :1 ;
278 sal_Bool bChangedWindowAttributes :1 ;
279 sal_Bool bChangedEmptyDocumentURL :1 ;
280 sal_Bool bChangedDefaultFilter :1 ;
281 sal_Bool bChangedIcon :1 ;
282 sal_Bool bDefaultFilterReadonly :1 ;
284 css::uno::Reference< css::util::XStringSubstitution > xSubstVars;
287 typedef FactoryInfo FactoryInfoList[FACTORYCOUNT];
289 /*-************************************************************************************************************//**
290 @short IMPL data container for wrapper class SvtModulOptions!
291 @descr These class is used as a static data container of class SvtModuleOptions. The hold it by using
292 a refcount and make it threadsafe by using an osl mutex. So we don't must do anything for that.
293 We can implement pure functionality to read/write configuration data only.
295 @implements -
296 @base ConfigItem
298 @devstatus ready to use
299 @threadsafe no
300 *//*-*************************************************************************************************************/
301 class SvtModuleOptions_Impl : public ::utl::ConfigItem
303 //-------------------------------------------------------------------------------------------------------------
304 // public methods
305 //-------------------------------------------------------------------------------------------------------------
306 public:
307 //---------------------------------------------------------------------------------------------------------
308 // constructor / destructor
309 //---------------------------------------------------------------------------------------------------------
310 SvtModuleOptions_Impl();
311 ~SvtModuleOptions_Impl();
313 //---------------------------------------------------------------------------------------------------------
314 // overloaded methods of baseclass
315 //---------------------------------------------------------------------------------------------------------
316 virtual void Notify( const css::uno::Sequence< OUString >& lPropertyNames );
317 virtual void Commit( );
319 //---------------------------------------------------------------------------------------------------------
320 // public interface
321 //---------------------------------------------------------------------------------------------------------
322 sal_Bool IsModuleInstalled ( SvtModuleOptions::EModule eModule ) const;
323 ::com::sun::star::uno::Sequence < OUString > GetAllServiceNames();
324 OUString GetFactoryName ( SvtModuleOptions::EFactory eFactory ) const;
325 OUString GetFactoryShortName ( SvtModuleOptions::EFactory eFactory ) const;
326 OUString GetFactoryStandardTemplate( SvtModuleOptions::EFactory eFactory ) const;
327 OUString GetFactoryEmptyDocumentURL( SvtModuleOptions::EFactory eFactory ) const;
328 OUString GetFactoryDefaultFilter ( SvtModuleOptions::EFactory eFactory ) const;
329 sal_Bool IsDefaultFilterReadonly( SvtModuleOptions::EFactory eFactory ) const;
330 sal_Int32 GetFactoryIcon ( SvtModuleOptions::EFactory eFactory ) const;
331 static sal_Bool ClassifyFactoryByName ( const OUString& sName ,
332 SvtModuleOptions::EFactory& eFactory );
333 void SetFactoryStandardTemplate( SvtModuleOptions::EFactory eFactory ,
334 const OUString& sTemplate );
335 void SetFactoryDefaultFilter ( SvtModuleOptions::EFactory eFactory ,
336 const OUString& sFilter );
337 void MakeReadonlyStatesAvailable();
339 //-------------------------------------------------------------------------------------------------------------
340 // private methods
341 //-------------------------------------------------------------------------------------------------------------
342 private:
343 static css::uno::Sequence< OUString > impl_ExpandSetNames ( const css::uno::Sequence< OUString >& lSetNames );
344 void impl_Read ( const css::uno::Sequence< OUString >& lSetNames );
346 //-------------------------------------------------------------------------------------------------------------
347 // private types
348 //-------------------------------------------------------------------------------------------------------------
349 private:
351 //-------------------------------------------------------------------------------------------------------------
352 // private member
353 //-------------------------------------------------------------------------------------------------------------
354 private:
355 FactoryInfoList m_lFactories;
356 sal_Bool m_bReadOnlyStatesWellKnown;
359 /*-************************************************************************************************************//**
360 @short default ctor
361 @descr We open our configuration here and read all neccessary values from it.
362 These values are cached till everyone call Commit(). Then we write changed ones back to cfg.
364 @seealso baseclass ConfigItem
365 @seealso method impl_Read()
367 @param -
368 @return -
370 @onerror -
371 @threadsafe no
372 *//*-*************************************************************************************************************/
373 SvtModuleOptions_Impl::SvtModuleOptions_Impl()
374 : ::utl::ConfigItem( ROOTNODE_FACTORIES )
375 , m_bReadOnlyStatesWellKnown( sal_False )
377 // First initialize list of factory infos! Otherwise we couldnt gurantee right working of these class.
378 for( sal_Int32 nFactory=0; nFactory<FACTORYCOUNT; ++nFactory )
379 m_lFactories[nFactory].free();
381 // Get name list of all existing set node names in configuration to read her properties in impl_Read().
382 // These list is a list of long names of our factories.
383 const css::uno::Sequence< OUString > lFactories = GetNodeNames( OUString() );
384 impl_Read( lFactories );
386 // Enable notification for changes by using configuration directly.
387 // So we can update our internal values immediately.
388 EnableNotification( lFactories );
391 /*-************************************************************************************************************//**
392 @short default dtor
393 @descr If any values of our cache was modified we should write it back to configuration.
395 @attention Don't forget to call "SetModified()" method of base class ConfigItem if any interface method
396 of this class modify internal member list m_lFactories! Otherwise Commit() will never be called!!!
398 @seealso baseclass ConfigItem
400 @param -
401 @return -
403 @onerror -
404 @threadsafe no
405 *//*-*************************************************************************************************************/
406 SvtModuleOptions_Impl::~SvtModuleOptions_Impl()
408 if( IsModified() == sal_True )
410 Commit();
414 /*-************************************************************************************************************//**
415 @short called for notify of configmanager
416 @descr These method is called from the ConfigManager before application ends or from the
417 PropertyChangeListener if the sub tree broadcasts changes. You must update our
418 internal values.
420 @attention We are registered for pure set node names only. So we can use our internal method "impl_Read()" to
421 update our info list. Because - these method expand given name list to full qualified property list
422 and use it to read the values. These values are filled into our internal member list m_lFactories
423 at right position.
425 @seealso method impl_Read()
427 @param "lNames" is the list of set node entries which should be updated.
428 @return -
430 @onerror -
431 @threadsafe no
432 *//*-*************************************************************************************************************/
433 void SvtModuleOptions_Impl::Notify( const css::uno::Sequence< OUString >& )
435 OSL_FAIL( "SvtModuleOptions_Impl::Notify()\nNot implemented yet!\n" );
438 /*-****************************************************************************************************//**
439 @short write changes to configuration
440 @descr These method writes the changed values into the sub tree
441 and should always called in our destructor to guarantee consistency of config data.
443 @attention We clear complete set in configuration first and write it completely new! So we don't must
444 distinguish between existing, added or removed elements. Our internal cached values
445 are the only and right ones.
447 @seealso baseclass ConfigItem
449 @param -
450 @return -
452 @onerror -
453 @threadsafe no
454 *//*-*****************************************************************************************************/
455 void SvtModuleOptions_Impl::Commit()
457 // Reserve memory for ALL possible factory properties!
458 // Step over all factories and get her realy changed values only.
459 // Build list of these ones and use it for commit.
460 css::uno::Sequence< css::beans::PropertyValue > lCommitProperties( FACTORYCOUNT*PROPERTYCOUNT );
461 FactoryInfo* pInfo = NULL ;
462 sal_Int32 nRealCount = 0 ;
463 OUString sBasePath ;
464 for( sal_Int32 nFactory=0; nFactory<FACTORYCOUNT; ++nFactory )
466 pInfo = &(m_lFactories[nFactory]);
468 // These path is used to build full qualified property names ....
469 // See pInfo->getChangedProperties() for further information
470 sBasePath = PATHSEPARATOR + pInfo->getFactory() + PATHSEPARATOR;
472 const css::uno::Sequence< css::beans::PropertyValue > lChangedProperties = pInfo->getChangedProperties ( sBasePath );
473 const css::beans::PropertyValue* pChangedProperties = lChangedProperties.getConstArray();
474 sal_Int32 nPropertyCount = lChangedProperties.getLength();
475 for( sal_Int32 nProperty=0; nProperty<nPropertyCount; ++nProperty )
477 lCommitProperties[nRealCount] = pChangedProperties[nProperty];
478 ++nRealCount;
481 // Resize commit list to real size.
482 // If nothing to do - suppress calling of configuration ...
483 // It could be to expensive :-)
484 if( nRealCount > 0 )
486 lCommitProperties.realloc( nRealCount );
487 SetSetProperties( OUString(), lCommitProperties );
491 /*-****************************************************************************************************//**
492 @short access method to get internal values
493 @descr These methods implement easy access to our internal values.
494 You give us right enum value to specify which module interest you ... we return right information.
496 @attention Some people use any value as enum ... but we support in header specified values only!
497 We use it directly as index in our internal list. If enum value isn't right - we crash with an
498 "index out of range"!!! Please use me right - otherwise there is no guarantee.
500 @seealso -
502 @param "eModule" , index in list - specify module
503 @param "eFactory" , index in list - specify factory
504 @param "sTemplate", set new standard template for these factory
505 @return Queried information.
507 @onerror We return default values. (mostly "not installed"!)
508 @threadsafe no
509 *//*-*****************************************************************************************************/
510 sal_Bool SvtModuleOptions_Impl::IsModuleInstalled( SvtModuleOptions::EModule eModule ) const
512 sal_Bool bInstalled = sal_False;
513 switch( eModule )
515 case SvtModuleOptions::E_SWRITER : bInstalled = m_lFactories[SvtModuleOptions::E_WRITER].getInstalled();
516 break;
517 case SvtModuleOptions::E_SWEB : bInstalled = m_lFactories[SvtModuleOptions::E_WRITERWEB].getInstalled();
518 break;
519 case SvtModuleOptions::E_SGLOBAL : bInstalled = m_lFactories[SvtModuleOptions::E_WRITERGLOBAL].getInstalled();
520 break;
521 case SvtModuleOptions::E_SCALC : bInstalled = m_lFactories[SvtModuleOptions::E_CALC].getInstalled();
522 break;
523 case SvtModuleOptions::E_SDRAW : bInstalled = m_lFactories[SvtModuleOptions::E_DRAW].getInstalled();
524 break;
525 case SvtModuleOptions::E_SIMPRESS : bInstalled = m_lFactories[SvtModuleOptions::E_IMPRESS].getInstalled();
526 break;
527 case SvtModuleOptions::E_SMATH : bInstalled = m_lFactories[SvtModuleOptions::E_MATH].getInstalled();
528 break;
529 case SvtModuleOptions::E_SCHART : bInstalled = m_lFactories[SvtModuleOptions::E_CHART].getInstalled();
530 break;
531 case SvtModuleOptions::E_SSTARTMODULE : bInstalled = m_lFactories[SvtModuleOptions::E_STARTMODULE].getInstalled();
532 break;
533 case SvtModuleOptions::E_SBASIC : bInstalled = sal_True; // Couldn't be deselected by setup yet!
534 break;
535 case SvtModuleOptions::E_SDATABASE : bInstalled = m_lFactories[SvtModuleOptions::E_DATABASE].getInstalled();
536 break;
539 return bInstalled;
542 ::com::sun::star::uno::Sequence < OUString > SvtModuleOptions_Impl::GetAllServiceNames()
544 sal_uInt32 nCount=0;
545 if( m_lFactories[SvtModuleOptions::E_WRITER].getInstalled() )
546 nCount++;
547 if ( m_lFactories[SvtModuleOptions::E_WRITERWEB].getInstalled() )
548 nCount++;
549 if ( m_lFactories[SvtModuleOptions::E_WRITERGLOBAL].getInstalled() )
550 nCount++;
551 if( m_lFactories[SvtModuleOptions::E_SCALC].getInstalled() )
552 nCount++;
553 if( m_lFactories[SvtModuleOptions::E_SDRAW].getInstalled() )
554 nCount++;
555 if( m_lFactories[SvtModuleOptions::E_SIMPRESS].getInstalled() )
556 nCount++;
557 if( m_lFactories[SvtModuleOptions::E_SCHART].getInstalled() )
558 nCount++;
559 if( m_lFactories[SvtModuleOptions::E_SMATH].getInstalled() )
560 nCount++;
561 if( m_lFactories[SvtModuleOptions::E_SBASIC].getInstalled() )
562 nCount++;
563 if( m_lFactories[SvtModuleOptions::E_SDATABASE].getInstalled() )
564 nCount++;
566 css::uno::Sequence < OUString > aRet( nCount );
567 sal_Int32 n=0;
568 if( m_lFactories[SvtModuleOptions::E_WRITER].getInstalled() )
569 aRet[n++] = m_lFactories[SvtModuleOptions::E_WRITER].getFactory();
570 if ( m_lFactories[SvtModuleOptions::E_WRITERWEB].getInstalled() )
571 aRet[n++] = m_lFactories[SvtModuleOptions::E_WRITERWEB].getFactory();
572 if ( m_lFactories[SvtModuleOptions::E_WRITERGLOBAL].getInstalled() )
573 aRet[n++] = m_lFactories[SvtModuleOptions::E_WRITERGLOBAL].getFactory();
574 if( m_lFactories[SvtModuleOptions::E_SCALC].getInstalled() )
575 aRet[n++] = m_lFactories[SvtModuleOptions::E_SCALC].getFactory();
576 if( m_lFactories[SvtModuleOptions::E_SDRAW].getInstalled() )
577 aRet[n++] = m_lFactories[SvtModuleOptions::E_SDRAW].getFactory();
578 if( m_lFactories[SvtModuleOptions::E_SIMPRESS].getInstalled() )
579 aRet[n++] = m_lFactories[SvtModuleOptions::E_SIMPRESS].getFactory();
580 if( m_lFactories[SvtModuleOptions::E_SCHART].getInstalled() )
581 aRet[n++] = m_lFactories[SvtModuleOptions::E_SCHART].getFactory();
582 if( m_lFactories[SvtModuleOptions::E_SMATH].getInstalled() )
583 aRet[n++] = m_lFactories[SvtModuleOptions::E_SMATH].getFactory();
584 if( m_lFactories[SvtModuleOptions::E_SBASIC].getInstalled() )
585 aRet[n++] = m_lFactories[SvtModuleOptions::E_SBASIC].getFactory();
586 if( m_lFactories[SvtModuleOptions::E_SDATABASE].getInstalled() )
587 aRet[n++] = m_lFactories[SvtModuleOptions::E_SDATABASE].getFactory();
589 return aRet;
592 //*****************************************************************************************************************
593 OUString SvtModuleOptions_Impl::GetFactoryName( SvtModuleOptions::EFactory eFactory ) const
595 OUString sName;
597 if( eFactory>=0 && eFactory<FACTORYCOUNT )
599 sName = m_lFactories[eFactory].getFactory();
602 return sName;
605 //*****************************************************************************************************************
606 OUString SvtModuleOptions_Impl::GetFactoryShortName( SvtModuleOptions::EFactory eFactory ) const
608 // Attention: Hard configured yet ... because it's not fine to make changes possible by xml file yet.
609 // But it's good to plan further possibilities!
611 //return m_lFactories[eFactory].sShortName;
613 OUString sShortName;
614 switch( eFactory )
616 case SvtModuleOptions::E_WRITER : sShortName = "swriter";
617 break;
618 case SvtModuleOptions::E_WRITERWEB : sShortName = "swriter/web";
619 break;
620 case SvtModuleOptions::E_WRITERGLOBAL : sShortName = "swriter/GlobalDocument";
621 break;
622 case SvtModuleOptions::E_CALC : sShortName = "scalc";
623 break;
624 case SvtModuleOptions::E_DRAW : sShortName = "sdraw";
625 break;
626 case SvtModuleOptions::E_IMPRESS : sShortName = "simpress";
627 break;
628 case SvtModuleOptions::E_MATH : sShortName = "smath";
629 break;
630 case SvtModuleOptions::E_CHART : sShortName = "schart";
631 break;
632 case SvtModuleOptions::E_BASIC : sShortName = "sbasic";
633 break;
634 case SvtModuleOptions::E_DATABASE : sShortName = "sdatabase";
635 break;
636 default:
637 OSL_FAIL( "unknown factory" );
638 break;
641 return sShortName;
644 //*****************************************************************************************************************
645 OUString SvtModuleOptions_Impl::GetFactoryStandardTemplate( SvtModuleOptions::EFactory eFactory ) const
647 OUString sFile;
649 if( eFactory>=0 && eFactory<FACTORYCOUNT )
651 sFile = m_lFactories[eFactory].getTemplateFile();
654 return sFile;
657 //*****************************************************************************************************************
658 OUString SvtModuleOptions_Impl::GetFactoryEmptyDocumentURL( SvtModuleOptions::EFactory eFactory ) const
660 // Attention: Hard configured yet ... because it's not fine to make changes possible by xml file yet.
661 // But it's good to plan further possibilities!
663 //return m_lFactories[eFactory].getEmptyDocumentURL();
665 OUString sURL;
666 switch( eFactory )
668 case SvtModuleOptions::E_WRITER : sURL = "private:factory/swriter";
669 break;
670 case SvtModuleOptions::E_WRITERWEB : sURL = "private:factory/swriter/web";
671 break;
672 case SvtModuleOptions::E_WRITERGLOBAL : sURL = "private:factory/swriter/GlobalDocument";
673 break;
674 case SvtModuleOptions::E_CALC : sURL = "private:factory/scalc";
675 break;
676 case SvtModuleOptions::E_DRAW : sURL = "private:factory/sdraw";
677 break;
678 case SvtModuleOptions::E_IMPRESS : sURL = "private:factory/simpress?slot=6686";
679 break;
680 case SvtModuleOptions::E_MATH : sURL = "private:factory/smath";
681 break;
682 case SvtModuleOptions::E_CHART : sURL = "private:factory/schart";
683 break;
684 case SvtModuleOptions::E_BASIC : sURL = "private:factory/sbasic";
685 break;
686 case SvtModuleOptions::E_DATABASE : sURL = "private:factory/sdatabase?Interactive";
687 break;
688 default:
689 OSL_FAIL( "unknown factory" );
690 break;
692 return sURL;
695 //*****************************************************************************************************************
696 OUString SvtModuleOptions_Impl::GetFactoryDefaultFilter( SvtModuleOptions::EFactory eFactory ) const
698 OUString sDefaultFilter;
700 if( eFactory>=0 && eFactory<FACTORYCOUNT )
702 sDefaultFilter = m_lFactories[eFactory].getDefaultFilter();
704 return sDefaultFilter;
706 //*****************************************************************************************************************
707 sal_Bool SvtModuleOptions_Impl::IsDefaultFilterReadonly( SvtModuleOptions::EFactory eFactory ) const
709 sal_Bool bRet = sal_False;
710 if( eFactory>=0 && eFactory<FACTORYCOUNT )
712 bRet = m_lFactories[eFactory].isDefaultFilterReadonly();
714 return bRet;
717 //*****************************************************************************************************************
718 sal_Int32 SvtModuleOptions_Impl::GetFactoryIcon( SvtModuleOptions::EFactory eFactory ) const
720 sal_Int32 nIcon = 0;
722 if( eFactory>=0 && eFactory<FACTORYCOUNT )
724 nIcon = m_lFactories[eFactory].getIcon();
727 return nIcon;
730 //*****************************************************************************************************************
731 void SvtModuleOptions_Impl::SetFactoryStandardTemplate( SvtModuleOptions::EFactory eFactory ,
732 const OUString& sTemplate )
734 if( eFactory>=0 && eFactory<FACTORYCOUNT )
736 m_lFactories[eFactory].setTemplateFile( sTemplate );
737 SetModified();
741 //*****************************************************************************************************************
742 void SvtModuleOptions_Impl::SetFactoryDefaultFilter( SvtModuleOptions::EFactory eFactory,
743 const OUString& sFilter )
745 if( eFactory>=0 && eFactory<FACTORYCOUNT )
747 m_lFactories[eFactory].setDefaultFilter( sFilter );
748 SetModified();
752 /*-************************************************************************************************************//**
753 @short return list of key names of ouer configuration management which represent our module tree
754 @descr You give use a list of current existing set node names .. and we expand it for all
755 well known properties which are neccessary for this implementation.
756 These full expanded list should be used to get values of this properties.
758 @seealso ctor
760 @param -
761 @return List of all relative addressed properties of given set entry names.
763 @onerror List will be empty.
764 @threadsafe no
765 *//*-*************************************************************************************************************/
766 css::uno::Sequence< OUString > SvtModuleOptions_Impl::impl_ExpandSetNames( const css::uno::Sequence< OUString >& lSetNames )
768 sal_Int32 nCount = lSetNames.getLength() ;
769 css::uno::Sequence< OUString > lPropNames ( nCount*PROPERTYCOUNT );
770 OUString* pPropNames = lPropNames.getArray() ;
771 sal_Int32 nPropStart = 0 ;
773 for( sal_Int32 nName=0; nName<nCount; ++nName )
775 pPropNames[nPropStart+PROPERTYHANDLE_SHORTNAME ] = lSetNames[nName] + PATHSEPARATOR + PROPERTYNAME_SHORTNAME ;
776 pPropNames[nPropStart+PROPERTYHANDLE_TEMPLATEFILE ] = lSetNames[nName] + PATHSEPARATOR + PROPERTYNAME_TEMPLATEFILE ;
777 pPropNames[nPropStart+PROPERTYHANDLE_WINDOWATTRIBUTES] = lSetNames[nName] + PATHSEPARATOR + PROPERTYNAME_WINDOWATTRIBUTES;
778 pPropNames[nPropStart+PROPERTYHANDLE_EMPTYDOCUMENTURL] = lSetNames[nName] + PATHSEPARATOR + PROPERTYNAME_EMPTYDOCUMENTURL;
779 pPropNames[nPropStart+PROPERTYHANDLE_DEFAULTFILTER ] = lSetNames[nName] + PATHSEPARATOR + PROPERTYNAME_DEFAULTFILTER ;
780 pPropNames[nPropStart+PROPERTYHANDLE_ICON ] = lSetNames[nName] + PATHSEPARATOR + PROPERTYNAME_ICON ;
781 nPropStart += PROPERTYCOUNT;
784 return lPropNames;
787 /*-************************************************************************************************************//**
788 @short helper to classify given factory by name
789 @descr Every factory has his own long and short name. So we can match right enum value for internal using.
791 @attention We change in/out parameter "eFactory" in every case! But you should use it only, if return value is sal_True!
792 Algorithm: Set out-parameter to propably value ... and check the longname.
793 If it match with these factory - break operation and return true AND right set parameter.
794 Otherwise try next one and so on. If no factory was found return false. Out parameter eFactory
795 is set to last tried value but shouldn't be used! Because our return value is false!
797 @seealso -
799 @param "sLongName" , long name of factory, which should be classified
800 @return "eFactory" , right enum value, which match given long name
801 and true for successfully classification, false otherwise
803 @onerror We return false.
804 @threadsafe no
805 *//*-*************************************************************************************************************/
806 sal_Bool SvtModuleOptions_Impl::ClassifyFactoryByName( const OUString& sName, SvtModuleOptions::EFactory& eFactory )
808 sal_Bool bState;
810 eFactory = SvtModuleOptions::E_WRITER ;
811 bState = ( sName == FACTORYNAME_WRITER );
813 if( bState == sal_False )
815 eFactory = SvtModuleOptions::E_WRITERWEB ;
816 bState = ( sName == FACTORYNAME_WRITERWEB );
818 // no else!
819 if( bState == sal_False )
821 eFactory = SvtModuleOptions::E_WRITERGLOBAL ;
822 bState = ( sName == FACTORYNAME_WRITERGLOBAL );
824 // no else!
825 if( bState == sal_False )
827 eFactory = SvtModuleOptions::E_CALC ;
828 bState = ( sName == FACTORYNAME_CALC );
830 // no else!
831 if( bState == sal_False )
833 eFactory = SvtModuleOptions::E_DRAW ;
834 bState = ( sName == FACTORYNAME_DRAW );
836 // no else!
837 if( bState == sal_False )
839 eFactory = SvtModuleOptions::E_IMPRESS ;
840 bState = ( sName == FACTORYNAME_IMPRESS );
842 // no else!
843 if( bState == sal_False )
845 eFactory = SvtModuleOptions::E_MATH ;
846 bState = ( sName == FACTORYNAME_MATH );
848 // no else!
849 if( bState == sal_False )
851 eFactory = SvtModuleOptions::E_CHART ;
852 bState = ( sName == FACTORYNAME_CHART );
854 // no else!
855 if( bState == sal_False )
857 eFactory = SvtModuleOptions::E_DATABASE ;
858 bState = ( sName == FACTORYNAME_DATABASE );
860 // no else!
861 if( bState == sal_False )
863 eFactory = SvtModuleOptions::E_STARTMODULE ;
864 bState = ( sName == FACTORYNAME_STARTMODULE);
867 return bState;
870 /*-************************************************************************************************************//**
871 @short read factory configuration
872 @descr Give us a list of pure factory names (long names!) which can be used as
873 direct set node names ... and we read her property values and fill internal list.
874 These method can be used by initial reading at ctor and later updating by "Notify()".
876 @seealso ctor
877 @seealso method Notify()
879 @param "lFactories" is the list of set node entries which should be readed.
880 @return -
882 @onerror We do nothing.
883 @threadsafe no
884 *//*-*************************************************************************************************************/
885 void SvtModuleOptions_Impl::impl_Read( const css::uno::Sequence< OUString >& lFactories )
887 // Expand every set node name in lFactories to full qualified paths to his properties
888 // and get right values from configuration.
889 const css::uno::Sequence< OUString > lProperties = impl_ExpandSetNames( lFactories );
890 const css::uno::Sequence< css::uno::Any > lValues = GetProperties( lProperties );
892 // Safe impossible cases.
893 // We need values from ALL configuration keys.
894 // Follow assignment use order of values in relation to our list of key names!
895 OSL_ENSURE( !(lProperties.getLength()!=lValues.getLength()), "SvtModuleOptions_Impl::impl_Read()\nI miss some values of configuration keys!\n" );
897 // Algorithm: We step over all given factory names and classify it. These enum value can be used as direct index
898 // in our member list m_lFactories! VAriable nPropertyStart marks start position of every factory
899 // and her properties in expanded property/value list. The defines PROPERTHANDLE_xxx are used as offset values
900 // added to nPropertyStart. So we can address every property relative in these lists.
901 // If we found any valid values ... we reset all existing information for corresponding m_lFactories-entry and
902 // use a pointer to these struct in memory directly to set new values.
903 // But we set it only, if bInstalled is true. Otherwise all other values of a factory can be undeclared .. They
904 // shouldn't be used then.
905 // Attention: If a propertyset of a factory will be ignored we must step to next start position of next factory infos!
906 // see "nPropertyStart += PROPERTYCOUNT" ...
908 sal_Int32 nPropertyStart = 0 ;
909 sal_Int32 nNodeCount = lFactories.getLength();
910 FactoryInfo* pInfo = NULL ;
911 SvtModuleOptions::EFactory eFactory ;
913 for( sal_Int32 nSetNode=0; nSetNode<nNodeCount; ++nSetNode )
915 const OUString& sFactoryName = lFactories[nSetNode];
916 if( ClassifyFactoryByName( sFactoryName, eFactory ) == sal_True )
918 OUString sTemp;
919 sal_Int32 nTemp = 0;
921 pInfo = &(m_lFactories[eFactory]);
922 pInfo->free();
924 pInfo->initInstalled( sal_True );
925 pInfo->initFactory ( sFactoryName );
927 if (lValues[nPropertyStart+PROPERTYHANDLE_SHORTNAME] >>= sTemp)
928 pInfo->initShortName( sTemp );
929 if (lValues[nPropertyStart+PROPERTYHANDLE_TEMPLATEFILE] >>= sTemp)
930 pInfo->initTemplateFile( sTemp );
931 if (lValues[nPropertyStart+PROPERTYHANDLE_WINDOWATTRIBUTES] >>= sTemp)
932 pInfo->initWindowAttributes( sTemp );
933 if (lValues[nPropertyStart+PROPERTYHANDLE_EMPTYDOCUMENTURL] >>= sTemp)
934 pInfo->initEmptyDocumentURL( sTemp );
935 if (lValues[nPropertyStart+PROPERTYHANDLE_DEFAULTFILTER ] >>= sTemp)
936 pInfo->initDefaultFilter( sTemp );
937 if (lValues[nPropertyStart+PROPERTYHANDLE_ICON] >>= nTemp)
938 pInfo->initIcon( nTemp );
940 nPropertyStart += PROPERTYCOUNT;
944 //*****************************************************************************************************************
945 void SvtModuleOptions_Impl::MakeReadonlyStatesAvailable()
947 if (m_bReadOnlyStatesWellKnown)
948 return;
950 css::uno::Sequence< OUString > lFactories = GetNodeNames(OUString());
951 sal_Int32 c = lFactories.getLength();
952 sal_Int32 i = 0;
953 for (i=0; i<c; ++i)
955 OUStringBuffer sPath(256);
956 sPath.append(lFactories[i] );
957 sPath.append(PATHSEPARATOR );
958 sPath.append(PROPERTYNAME_DEFAULTFILTER);
960 lFactories[i] = sPath.makeStringAndClear();
963 css::uno::Sequence< sal_Bool > lReadonlyStates = GetReadOnlyStates(lFactories);
964 for (i=0; i<c; ++i)
966 OUString& rFactoryName = lFactories[i];
967 SvtModuleOptions::EFactory eFactory ;
969 if (!ClassifyFactoryByName(rFactoryName, eFactory))
970 continue;
972 FactoryInfo& rInfo = m_lFactories[eFactory];
973 rInfo.setDefaultFilterReadonly(lReadonlyStates[i]);
976 m_bReadOnlyStatesWellKnown = sal_True;
979 //*****************************************************************************************************************
980 // initialize static member
981 // DON'T DO IT IN YOUR HEADER!
982 // see definition for further information
983 //*****************************************************************************************************************
984 SvtModuleOptions_Impl* SvtModuleOptions::m_pDataContainer = NULL ;
985 sal_Int32 SvtModuleOptions::m_nRefCount = 0 ;
987 /*-************************************************************************************************************//**
988 @short standard constructor and destructor
989 @descr This will initialize an instance with default values. We initialize/deinitialize our static data
990 container and create a static mutex, which is used for threadsafe code in further time of this object.
992 @seealso method impl_GetOwnStaticMutex()
994 @param -
995 @return -
997 @onerror -
998 @threadsafe yes
999 *//*-*************************************************************************************************************/
1000 SvtModuleOptions::SvtModuleOptions()
1002 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1003 ++m_nRefCount;
1004 if( m_nRefCount == 1 )
1006 RTL_LOGFILE_CONTEXT(aLog, "unotools ( ??? ) ::SvtModuleOptions_Impl::ctor()");
1007 m_pDataContainer = new SvtModuleOptions_Impl();
1009 ItemHolder1::holdConfigItem(E_MODULEOPTIONS);
1013 //*****************************************************************************************************************
1014 SvtModuleOptions::~SvtModuleOptions()
1016 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1017 --m_nRefCount;
1018 if( m_nRefCount == 0 )
1020 delete m_pDataContainer;
1021 m_pDataContainer = NULL;
1025 /*-************************************************************************************************************//**
1026 @short access to configuration data
1027 @descr This methods allow read/write access to configuration values.
1028 They are threadsafe. All calls are forwarded to impl-data-container. See there for further information!
1030 @seealso method impl_GetOwnStaticMutex()
1032 @param -
1033 @return -
1035 @onerror -
1036 @threadsafe yes
1037 *//*-*************************************************************************************************************/
1038 sal_Bool SvtModuleOptions::IsModuleInstalled( EModule eModule ) const
1040 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1041 return m_pDataContainer->IsModuleInstalled( eModule );
1044 //*****************************************************************************************************************
1045 OUString SvtModuleOptions::GetFactoryName( EFactory eFactory ) const
1047 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1048 return m_pDataContainer->GetFactoryName( eFactory );
1051 //*****************************************************************************************************************
1052 OUString SvtModuleOptions::GetFactoryStandardTemplate( EFactory eFactory ) const
1054 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1055 return m_pDataContainer->GetFactoryStandardTemplate( eFactory );
1058 //*****************************************************************************************************************
1059 OUString SvtModuleOptions::GetFactoryEmptyDocumentURL( EFactory eFactory ) const
1061 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1062 return m_pDataContainer->GetFactoryEmptyDocumentURL( eFactory );
1065 //*****************************************************************************************************************
1066 OUString SvtModuleOptions::GetFactoryDefaultFilter( EFactory eFactory ) const
1068 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1069 return m_pDataContainer->GetFactoryDefaultFilter( eFactory );
1071 //*****************************************************************************************************************
1072 sal_Bool SvtModuleOptions::IsDefaultFilterReadonly( EFactory eFactory ) const
1074 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1075 m_pDataContainer->MakeReadonlyStatesAvailable();
1076 return m_pDataContainer->IsDefaultFilterReadonly( eFactory );
1078 //*****************************************************************************************************************
1079 sal_Int32 SvtModuleOptions::GetFactoryIcon( EFactory eFactory ) const
1081 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1082 return m_pDataContainer->GetFactoryIcon( eFactory );
1085 //*****************************************************************************************************************
1086 sal_Bool SvtModuleOptions::ClassifyFactoryByName( const OUString& sName ,
1087 EFactory& eFactory )
1089 // We don't need any mutex here ... because we don't use any member here!
1090 return SvtModuleOptions_Impl::ClassifyFactoryByName( sName, eFactory );
1093 //*****************************************************************************************************************
1094 void SvtModuleOptions::SetFactoryStandardTemplate( EFactory eFactory ,
1095 const OUString& sTemplate )
1097 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1098 m_pDataContainer->SetFactoryStandardTemplate( eFactory, sTemplate );
1101 //*****************************************************************************************************************
1102 void SvtModuleOptions::SetFactoryDefaultFilter( EFactory eFactory,
1103 const OUString& sFilter )
1105 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1106 m_pDataContainer->SetFactoryDefaultFilter( eFactory, sFilter );
1109 //*****************************************************************************************************************
1110 sal_Bool SvtModuleOptions::IsMath() const
1112 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1113 return m_pDataContainer->IsModuleInstalled( E_SMATH );
1116 //*****************************************************************************************************************
1117 sal_Bool SvtModuleOptions::IsChart() const
1119 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1120 return m_pDataContainer->IsModuleInstalled( E_SCHART );
1123 //*****************************************************************************************************************
1124 sal_Bool SvtModuleOptions::IsCalc() const
1126 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1127 return m_pDataContainer->IsModuleInstalled( E_SCALC );
1130 //*****************************************************************************************************************
1131 sal_Bool SvtModuleOptions::IsDraw() const
1133 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1134 return m_pDataContainer->IsModuleInstalled( E_SDRAW );
1137 //*****************************************************************************************************************
1138 sal_Bool SvtModuleOptions::IsWriter() const
1140 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1141 return m_pDataContainer->IsModuleInstalled( E_SWRITER );
1144 //*****************************************************************************************************************
1145 sal_Bool SvtModuleOptions::IsImpress() const
1147 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1148 return m_pDataContainer->IsModuleInstalled( E_SIMPRESS );
1151 //*****************************************************************************************************************
1152 sal_Bool SvtModuleOptions::IsBasicIDE() const
1154 return sal_True;
1156 //*****************************************************************************************************************
1157 sal_Bool SvtModuleOptions::IsDataBase() const
1159 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1160 return m_pDataContainer->IsModuleInstalled( E_SDATABASE );
1163 namespace
1165 class theModuleOptionsMutex : public rtl::Static<osl::Mutex, theModuleOptionsMutex> {};
1167 /*-****************************************************************************************************//**
1168 @short return a reference to a static mutex
1169 @descr These class is threadsafe.
1170 We create a static mutex only for one time and use it to protect our refcount and container
1171 member!
1173 @seealso -
1175 @param -
1176 @return A reference to a static mutex member.
1178 @onerror -
1179 @threadsafe yes
1180 *//*-*****************************************************************************************************/
1181 ::osl::Mutex& SvtModuleOptions::impl_GetOwnStaticMutex()
1183 return theModuleOptionsMutex::get();
1186 OUString SvtModuleOptions::GetModuleName( EModule eModule ) const
1188 switch( eModule )
1190 case SvtModuleOptions::E_SWRITER : { return OUString("Writer"); }
1191 case SvtModuleOptions::E_SWEB : { return OUString("Web"); }
1192 case SvtModuleOptions::E_SGLOBAL : { return OUString("Global"); }
1193 case SvtModuleOptions::E_SCALC : { return OUString("Calc"); }
1194 case SvtModuleOptions::E_SDRAW : { return OUString("Draw"); }
1195 case SvtModuleOptions::E_SIMPRESS : { return OUString("Impress"); }
1196 case SvtModuleOptions::E_SMATH : { return OUString("Math"); }
1197 case SvtModuleOptions::E_SCHART : { return OUString("Chart"); }
1198 case SvtModuleOptions::E_SBASIC : { return OUString("Basic"); }
1199 case SvtModuleOptions::E_SDATABASE : { return OUString("Database"); }
1200 default:
1201 OSL_FAIL( "unknown module" );
1202 break;
1205 return OUString();
1208 SvtModuleOptions::EFactory SvtModuleOptions::ClassifyFactoryByShortName(const OUString& sName)
1210 if ( sName == "swriter" )
1211 return E_WRITER;
1212 if (sName.equalsIgnoreAsciiCase("swriter/Web")) // sometimes they are registerd for swriter/web :-(
1213 return E_WRITERWEB;
1214 if (sName.equalsIgnoreAsciiCase("swriter/GlobalDocument")) // sometimes they are registerd for swriter/globaldocument :-(
1215 return E_WRITERGLOBAL;
1216 if ( sName == "scalc" )
1217 return E_CALC;
1218 if ( sName == "sdraw" )
1219 return E_DRAW;
1220 if ( sName == "simpress" )
1221 return E_IMPRESS;
1222 if ( sName == "schart" )
1223 return E_CHART;
1224 if ( sName == "smath" )
1225 return E_MATH;
1226 if ( sName == "sbasic" )
1227 return E_BASIC;
1228 if ( sName == "sdatabase" )
1229 return E_DATABASE;
1231 return E_UNKNOWN_FACTORY;
1234 SvtModuleOptions::EFactory SvtModuleOptions::ClassifyFactoryByServiceName(const OUString& sName)
1236 if (sName.equals(FACTORYNAME_WRITERGLOBAL))
1237 return E_WRITERGLOBAL;
1238 if (sName.equals(FACTORYNAME_WRITERWEB))
1239 return E_WRITERWEB;
1240 if (sName.equals(FACTORYNAME_WRITER))
1241 return E_WRITER;
1242 if (sName.equals(FACTORYNAME_CALC))
1243 return E_CALC;
1244 if (sName.equals(FACTORYNAME_DRAW))
1245 return E_DRAW;
1246 if (sName.equals(FACTORYNAME_IMPRESS))
1247 return E_IMPRESS;
1248 if (sName.equals(FACTORYNAME_MATH))
1249 return E_MATH;
1250 if (sName.equals(FACTORYNAME_CHART))
1251 return E_CHART;
1252 if (sName.equals(FACTORYNAME_DATABASE))
1253 return E_DATABASE;
1255 return E_UNKNOWN_FACTORY;
1258 SvtModuleOptions::EFactory SvtModuleOptions::ClassifyFactoryByURL(const OUString& sURL ,
1259 const css::uno::Sequence< css::beans::PropertyValue >& lMediaDescriptor)
1261 css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
1263 css::uno::Reference< css::container::XNameAccess > xFilterCfg;
1264 css::uno::Reference< css::container::XNameAccess > xTypeCfg ;
1267 xFilterCfg = css::uno::Reference< css::container::XNameAccess >(
1268 xContext->getServiceManager()->createInstanceWithContext("com.sun.star.document.FilterFactory", xContext), css::uno::UNO_QUERY);
1269 xTypeCfg = css::uno::Reference< css::container::XNameAccess >(
1270 xContext->getServiceManager()->createInstanceWithContext("com.sun.star.document.TypeDetection", xContext), css::uno::UNO_QUERY);
1272 catch(const css::uno::RuntimeException&)
1273 { throw; }
1274 catch(const css::uno::Exception&)
1275 { return E_UNKNOWN_FACTORY; }
1277 ::comphelper::SequenceAsHashMap stlDesc(lMediaDescriptor);
1279 // is there already a filter inside the descriptor?
1280 OUString sFilterName = stlDesc.getUnpackedValueOrDefault(OUString("FilterName"), OUString());
1281 if (!sFilterName.isEmpty())
1285 ::comphelper::SequenceAsHashMap stlFilterProps (xFilterCfg->getByName(sFilterName));
1286 OUString sDocumentService = stlFilterProps.getUnpackedValueOrDefault(OUString("DocumentService"), OUString());
1287 SvtModuleOptions::EFactory eApp = SvtModuleOptions::ClassifyFactoryByServiceName(sDocumentService);
1289 if (eApp != E_UNKNOWN_FACTORY)
1290 return eApp;
1292 catch(const css::uno::RuntimeException&)
1293 { throw; }
1294 catch(const css::uno::Exception&)
1295 { /* do nothing here ... may the following code can help!*/ }
1298 // is there already a type inside the descriptor?
1299 OUString sTypeName = stlDesc.getUnpackedValueOrDefault(OUString("TypeName"), OUString());
1300 if (sTypeName.isEmpty())
1302 // no :-(
1303 // start flat detection of URL
1304 css::uno::Reference< css::document::XTypeDetection > xDetect(xTypeCfg, css::uno::UNO_QUERY);
1305 sTypeName = xDetect->queryTypeByURL(sURL);
1308 if (sTypeName.isEmpty())
1309 return E_UNKNOWN_FACTORY;
1311 // yes - there is a type info
1312 // Try to find the preferred filter.
1315 ::comphelper::SequenceAsHashMap stlTypeProps (xTypeCfg->getByName(sTypeName));
1316 OUString sPreferredFilter = stlTypeProps.getUnpackedValueOrDefault(OUString("PreferredFilter"), OUString());
1317 ::comphelper::SequenceAsHashMap stlFilterProps (xFilterCfg->getByName(sPreferredFilter));
1318 OUString sDocumentService = stlFilterProps.getUnpackedValueOrDefault(OUString("DocumentService"), OUString());
1319 SvtModuleOptions::EFactory eApp = SvtModuleOptions::ClassifyFactoryByServiceName(sDocumentService);
1321 if (eApp != E_UNKNOWN_FACTORY)
1322 return eApp;
1324 catch(const css::uno::RuntimeException&)
1325 { throw; }
1326 catch(const css::uno::Exception&)
1327 { /* do nothing here ... may the following code can help!*/ }
1329 // no filter/no type/no detection result => no fun :-)
1330 return E_UNKNOWN_FACTORY;
1333 SvtModuleOptions::EFactory SvtModuleOptions::ClassifyFactoryByModel(const css::uno::Reference< css::frame::XModel >& xModel)
1335 css::uno::Reference< css::lang::XServiceInfo > xInfo(xModel, css::uno::UNO_QUERY);
1336 if (!xInfo.is())
1337 return E_UNKNOWN_FACTORY;
1339 const css::uno::Sequence< OUString > lServices = xInfo->getSupportedServiceNames();
1340 const OUString* pServices = lServices.getConstArray();
1342 for (sal_Int32 i=0; i<lServices.getLength() ; ++i)
1344 SvtModuleOptions::EFactory eApp = SvtModuleOptions::ClassifyFactoryByServiceName(pServices[i]);
1345 if (eApp != E_UNKNOWN_FACTORY)
1346 return eApp;
1349 return E_UNKNOWN_FACTORY;
1352 ::com::sun::star::uno::Sequence < OUString > SvtModuleOptions::GetAllServiceNames()
1354 ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
1355 return m_pDataContainer->GetAllServiceNames();
1358 OUString SvtModuleOptions::GetDefaultModuleName()
1360 OUString aModule;
1361 if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::E_SWRITER))
1362 aModule = m_pDataContainer->GetFactoryShortName(SvtModuleOptions::E_WRITER);
1363 else if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::E_SCALC))
1364 aModule = m_pDataContainer->GetFactoryShortName(SvtModuleOptions::E_CALC);
1365 else if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::E_SIMPRESS))
1366 aModule = m_pDataContainer->GetFactoryShortName(SvtModuleOptions::E_IMPRESS);
1367 else if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::E_SDATABASE))
1368 aModule = m_pDataContainer->GetFactoryShortName(SvtModuleOptions::E_DATABASE);
1369 else if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::E_SDRAW))
1370 aModule = m_pDataContainer->GetFactoryShortName(SvtModuleOptions::E_DRAW);
1371 else if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::E_SWEB))
1372 aModule = m_pDataContainer->GetFactoryShortName(SvtModuleOptions::E_WRITERWEB);
1373 else if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::E_SGLOBAL))
1374 aModule = m_pDataContainer->GetFactoryShortName(SvtModuleOptions::E_WRITERGLOBAL);
1375 else if (m_pDataContainer->IsModuleInstalled(SvtModuleOptions::E_SMATH))
1376 aModule = m_pDataContainer->GetFactoryShortName(SvtModuleOptions::E_MATH);
1377 return aModule;
1380 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */