1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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!
52 NAMELIST[ PROPERTYHANDLE_xxx ] => VALUELIST[ PROPERTYHANDLE_xxx ]
53 *//*-*************************************************************************************************************/
54 #define ROOTNODE_FACTORIES ::rtl::OUString("Setup/Office/Factories" )
55 #define PATHSEPERATOR ::rtl::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 ::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" )
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 ::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" )
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 informations.
92 *//*-*************************************************************************************************************/
96 //---------------------------------------------------------------------------------------------------------
97 // initialize empty struct
101 // @@@ should be supplied from outside!
102 xSMgr
= ::comphelper::getProcessServiceFactory();
105 //---------------------------------------------------------------------------------------------------------
106 // easy way to reset struct member!
109 bInstalled
= sal_False
;
110 sFactory
= ::rtl::OUString() ;
111 sShortName
= ::rtl::OUString() ;
112 sTemplateFile
= ::rtl::OUString() ;
113 sWindowAttributes
= ::rtl::OUString() ;
114 sEmptyDocumentURL
= ::rtl::OUString() ;
115 sDefaultFilter
= ::rtl::OUString() ;
117 bChangedTemplateFile
= sal_False
;
118 bChangedWindowAttributes
= sal_False
;
119 bChangedEmptyDocumentURL
= sal_False
;
120 bChangedDefaultFilter
= sal_False
;
121 bChangedIcon
= sal_False
;
122 bDefaultFilterReadonly
= sal_False
;
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 css::uno::Sequence
< css::beans::PropertyValue
> getChangedProperties( const ::rtl::OUString
& sNodeBase
)
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 css::uno::Sequence
< css::beans::PropertyValue
> lProperties ( 4 );
135 sal_Int8 nRealyChanged
= 0 ;
137 if( bChangedTemplateFile
== sal_True
)
139 lProperties
[nRealyChanged
].Name
= sNodeBase
+ PROPERTYNAME_TEMPLATEFILE
;
141 if ( !sTemplateFile
.isEmpty() )
143 lProperties
[nRealyChanged
].Value
144 <<= getStringSubstitution()
145 ->reSubstituteVariables( sTemplateFile
);
149 lProperties
[nRealyChanged
].Value
<<= sTemplateFile
;
154 if( bChangedWindowAttributes
== sal_True
)
156 lProperties
[nRealyChanged
].Name
= sNodeBase
+ PROPERTYNAME_WINDOWATTRIBUTES
;
157 lProperties
[nRealyChanged
].Value
<<= sWindowAttributes
;
160 if( bChangedEmptyDocumentURL
== sal_True
)
162 lProperties
[nRealyChanged
].Name
= sNodeBase
+ PROPERTYNAME_EMPTYDOCUMENTURL
;
163 lProperties
[nRealyChanged
].Value
<<= sEmptyDocumentURL
;
166 if( bChangedDefaultFilter
== sal_True
)
168 lProperties
[nRealyChanged
].Name
= sNodeBase
+ PROPERTYNAME_DEFAULTFILTER
;
169 lProperties
[nRealyChanged
].Value
<<= sDefaultFilter
;
172 if( bChangedIcon
== sal_True
)
174 lProperties
[nRealyChanged
].Name
= sNodeBase
+ PROPERTYNAME_ICON
;
175 lProperties
[nRealyChanged
].Value
<<= nIcon
;
179 // Don't forget to reset changed flags! Otherwise we save it again and again and ...
180 bChangedTemplateFile
= sal_False
;
181 bChangedWindowAttributes
= sal_False
;
182 bChangedEmptyDocumentURL
= sal_False
;
183 bChangedDefaultFilter
= sal_False
;
184 bChangedIcon
= sal_False
;
186 lProperties
.realloc( nRealyChanged
);
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 sal_Bool
getInstalled () const { return bInstalled
; };
195 ::rtl::OUString
getFactory () const { return sFactory
; };
196 ::rtl::OUString
getShortName () const { return sShortName
; };
197 ::rtl::OUString
getTemplateFile () const { return sTemplateFile
; };
198 ::rtl::OUString
getWindowAttributes () const { return sWindowAttributes
; };
199 ::rtl::OUString
getDefaultFilter () const { return sDefaultFilter
; };
200 sal_Bool
isDefaultFilterReadonly() const { return bDefaultFilterReadonly
; }
201 sal_Int32
getIcon () const { return nIcon
; };
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 void initInstalled ( sal_Bool bNewInstalled
) { bInstalled
= bNewInstalled
; }
207 void initFactory ( const ::rtl::OUString
& sNewFactory
) { sFactory
= sNewFactory
; }
208 void initShortName ( const ::rtl::OUString
& sNewShortName
) { sShortName
= sNewShortName
; }
209 void initWindowAttributes ( const ::rtl::OUString
& sNewWindowAttributes
) { sWindowAttributes
= sNewWindowAttributes
; }
210 void initEmptyDocumentURL ( const ::rtl::OUString
& sNewEmptyDocumentURL
) { sEmptyDocumentURL
= sNewEmptyDocumentURL
; }
211 void initDefaultFilter ( const ::rtl::OUString
& sNewDefaultFilter
) { sDefaultFilter
= sNewDefaultFilter
; }
212 void setDefaultFilterReadonly( const sal_Bool bVal
){bDefaultFilterReadonly
= bVal
;}
213 void initIcon ( sal_Int32 nNewIcon
) { nIcon
= nNewIcon
; }
215 //---------------------------------------------------------------------------------------------------------
216 void initTemplateFile( const ::rtl::OUString
& sNewTemplateFile
)
218 if ( !sNewTemplateFile
.isEmpty() )
221 = getStringSubstitution()
222 ->substituteVariables( sNewTemplateFile
, sal_False
);
226 sTemplateFile
= sNewTemplateFile
;
230 //---------------------------------------------------------------------------------------------------------
231 void setTemplateFile( const ::rtl::OUString
& sNewTemplateFile
)
233 if( sTemplateFile
!= sNewTemplateFile
)
235 sTemplateFile
= sNewTemplateFile
;
236 bChangedTemplateFile
= sal_True
;
240 //---------------------------------------------------------------------------------------------------------
241 void setWindowAttributes( const ::rtl::OUString
& sNewWindowAttributes
)
243 if( sWindowAttributes
!= sNewWindowAttributes
)
245 sWindowAttributes
= sNewWindowAttributes
;
246 bChangedWindowAttributes
= sal_True
;
250 //---------------------------------------------------------------------------------------------------------
251 void setDefaultFilter( const ::rtl::OUString
& sNewDefaultFilter
)
253 if( sDefaultFilter
!= sNewDefaultFilter
)
255 sDefaultFilter
= sNewDefaultFilter
;
256 bChangedDefaultFilter
= sal_True
;
261 css::uno::Reference
< css::util::XStringSubstitution
> getStringSubstitution()
263 if ( !xSubstVars
.is() )
265 css::uno::Reference
< css::uno::XComponentContext
> xContext( comphelper::getComponentContext(xSMgr
) );
267 = css::uno::Reference
< css::util::XStringSubstitution
>(
268 css::util::PathSubstitution::create(xContext
) );
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
;
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 ;
289 css::uno::Reference
< css::lang::XMultiServiceFactory
> xSMgr
;
290 css::uno::Reference
< css::util::XStringSubstitution
> xSubstVars
;
293 typedef FactoryInfo FactoryInfoList
[FACTORYCOUNT
];
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.
304 @devstatus ready to use
306 *//*-*************************************************************************************************************/
307 class SvtModuleOptions_Impl
: public ::utl::ConfigItem
309 //-------------------------------------------------------------------------------------------------------------
311 //-------------------------------------------------------------------------------------------------------------
313 //---------------------------------------------------------------------------------------------------------
314 // constructor / destructor
315 //---------------------------------------------------------------------------------------------------------
316 SvtModuleOptions_Impl();
317 ~SvtModuleOptions_Impl();
319 //---------------------------------------------------------------------------------------------------------
320 // overloaded methods of baseclass
321 //---------------------------------------------------------------------------------------------------------
322 virtual void Notify( const css::uno::Sequence
< ::rtl::OUString
>& lPropertyNames
);
323 virtual void Commit( );
325 //---------------------------------------------------------------------------------------------------------
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();
345 //-------------------------------------------------------------------------------------------------------------
347 //-------------------------------------------------------------------------------------------------------------
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
);
352 //-------------------------------------------------------------------------------------------------------------
354 //-------------------------------------------------------------------------------------------------------------
357 //-------------------------------------------------------------------------------------------------------------
359 //-------------------------------------------------------------------------------------------------------------
361 FactoryInfoList m_lFactories
;
362 sal_Bool m_bReadOnlyStatesWellKnown
;
365 /*-************************************************************************************************************//**
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.
370 @seealso baseclass ConfigItem
371 @seealso method impl_Read()
378 *//*-*************************************************************************************************************/
379 SvtModuleOptions_Impl::SvtModuleOptions_Impl()
380 : ::utl::ConfigItem( ROOTNODE_FACTORIES
)
381 , m_bReadOnlyStatesWellKnown( sal_False
)
383 // First initialize list of factory infos! Otherwise we couldnt gurantee right working of these class.
384 for( sal_Int32 nFactory
=0; nFactory
<FACTORYCOUNT
; ++nFactory
)
385 m_lFactories
[nFactory
].free();
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 const css::uno::Sequence
< ::rtl::OUString
> lFactories
= GetNodeNames( ::rtl::OUString() );
390 impl_Read( lFactories
);
392 // Enable notification for changes by using configuration directly.
393 // So we can update our internal values immediatly.
394 EnableNotification( lFactories
);
397 /*-************************************************************************************************************//**
399 @descr If any values of our cache was modified we should write it back to configuration.
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!!!
404 @seealso baseclass ConfigItem
411 *//*-*************************************************************************************************************/
412 SvtModuleOptions_Impl::~SvtModuleOptions_Impl()
414 if( IsModified() == sal_True
)
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
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
431 @seealso method impl_Read()
433 @param "lNames" is the list of set node entries which should be updated.
438 *//*-*************************************************************************************************************/
439 void SvtModuleOptions_Impl::Notify( const css::uno::Sequence
< ::rtl::OUString
>& )
441 OSL_FAIL( "SvtModuleOptions_Impl::Notify()\nNot implemented yet!\n" );
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.
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.
453 @seealso baseclass ConfigItem
460 *//*-*****************************************************************************************************/
461 void SvtModuleOptions_Impl::Commit()
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 css::uno::Sequence
< css::beans::PropertyValue
> lCommitProperties( FACTORYCOUNT
*PROPERTYCOUNT
);
467 FactoryInfo
* pInfo
= NULL
;
468 sal_Int32 nRealCount
= 0 ;
469 ::rtl::OUString sBasePath
;
470 for( sal_Int32 nFactory
=0; nFactory
<FACTORYCOUNT
; ++nFactory
)
472 pInfo
= &(m_lFactories
[nFactory
]);
474 // These path is used to build full qualified property names ....
475 // See pInfo->getChangedProperties() for further informations
476 sBasePath
= PATHSEPERATOR
+ pInfo
->getFactory() + PATHSEPERATOR
;
478 const css::uno::Sequence
< css::beans::PropertyValue
> lChangedProperties
= pInfo
->getChangedProperties ( sBasePath
);
479 const css::beans::PropertyValue
* pChangedProperties
= lChangedProperties
.getConstArray();
480 sal_Int32 nPropertyCount
= lChangedProperties
.getLength();
481 for( sal_Int32 nProperty
=0; nProperty
<nPropertyCount
; ++nProperty
)
483 lCommitProperties
[nRealCount
] = pChangedProperties
[nProperty
];
487 // Resize commit list to real size.
488 // If nothing to do - suppress calling of configuration ...
489 // It could be to expensive :-)
492 lCommitProperties
.realloc( nRealCount
);
493 SetSetProperties( ::rtl::OUString(), lCommitProperties
);
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.
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.
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.
513 @onerror We return default values. (mostly "not installed"!)
515 *//*-*****************************************************************************************************/
516 sal_Bool
SvtModuleOptions_Impl::IsModuleInstalled( SvtModuleOptions::EModule eModule
) const
518 sal_Bool bInstalled
= sal_False
;
521 case SvtModuleOptions::E_SWRITER
: bInstalled
= m_lFactories
[SvtModuleOptions::E_WRITER
].getInstalled();
523 case SvtModuleOptions::E_SWEB
: bInstalled
= m_lFactories
[SvtModuleOptions::E_WRITERWEB
].getInstalled();
525 case SvtModuleOptions::E_SGLOBAL
: bInstalled
= m_lFactories
[SvtModuleOptions::E_WRITERGLOBAL
].getInstalled();
527 case SvtModuleOptions::E_SCALC
: bInstalled
= m_lFactories
[SvtModuleOptions::E_CALC
].getInstalled();
529 case SvtModuleOptions::E_SDRAW
: bInstalled
= m_lFactories
[SvtModuleOptions::E_DRAW
].getInstalled();
531 case SvtModuleOptions::E_SIMPRESS
: bInstalled
= m_lFactories
[SvtModuleOptions::E_IMPRESS
].getInstalled();
533 case SvtModuleOptions::E_SMATH
: bInstalled
= m_lFactories
[SvtModuleOptions::E_MATH
].getInstalled();
535 case SvtModuleOptions::E_SCHART
: bInstalled
= m_lFactories
[SvtModuleOptions::E_CHART
].getInstalled();
537 case SvtModuleOptions::E_SSTARTMODULE
: bInstalled
= m_lFactories
[SvtModuleOptions::E_STARTMODULE
].getInstalled();
539 case SvtModuleOptions::E_SBASIC
: bInstalled
= sal_True
; // Couldn't be deselected by setup yet!
541 case SvtModuleOptions::E_SDATABASE
: bInstalled
= m_lFactories
[SvtModuleOptions::E_DATABASE
].getInstalled();
548 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SvtModuleOptions_Impl::GetAllServiceNames()
551 if( m_lFactories
[SvtModuleOptions::E_WRITER
].getInstalled() )
553 if ( m_lFactories
[SvtModuleOptions::E_WRITERWEB
].getInstalled() )
555 if ( m_lFactories
[SvtModuleOptions::E_WRITERGLOBAL
].getInstalled() )
557 if( m_lFactories
[SvtModuleOptions::E_SCALC
].getInstalled() )
559 if( m_lFactories
[SvtModuleOptions::E_SDRAW
].getInstalled() )
561 if( m_lFactories
[SvtModuleOptions::E_SIMPRESS
].getInstalled() )
563 if( m_lFactories
[SvtModuleOptions::E_SCHART
].getInstalled() )
565 if( m_lFactories
[SvtModuleOptions::E_SMATH
].getInstalled() )
567 if( m_lFactories
[SvtModuleOptions::E_SBASIC
].getInstalled() )
569 if( m_lFactories
[SvtModuleOptions::E_SDATABASE
].getInstalled() )
572 css::uno::Sequence
< ::rtl::OUString
> aRet( nCount
);
574 if( m_lFactories
[SvtModuleOptions::E_WRITER
].getInstalled() )
575 aRet
[n
++] = m_lFactories
[SvtModuleOptions::E_WRITER
].getFactory();
576 if ( m_lFactories
[SvtModuleOptions::E_WRITERWEB
].getInstalled() )
577 aRet
[n
++] = m_lFactories
[SvtModuleOptions::E_WRITERWEB
].getFactory();
578 if ( m_lFactories
[SvtModuleOptions::E_WRITERGLOBAL
].getInstalled() )
579 aRet
[n
++] = m_lFactories
[SvtModuleOptions::E_WRITERGLOBAL
].getFactory();
580 if( m_lFactories
[SvtModuleOptions::E_SCALC
].getInstalled() )
581 aRet
[n
++] = m_lFactories
[SvtModuleOptions::E_SCALC
].getFactory();
582 if( m_lFactories
[SvtModuleOptions::E_SDRAW
].getInstalled() )
583 aRet
[n
++] = m_lFactories
[SvtModuleOptions::E_SDRAW
].getFactory();
584 if( m_lFactories
[SvtModuleOptions::E_SIMPRESS
].getInstalled() )
585 aRet
[n
++] = m_lFactories
[SvtModuleOptions::E_SIMPRESS
].getFactory();
586 if( m_lFactories
[SvtModuleOptions::E_SCHART
].getInstalled() )
587 aRet
[n
++] = m_lFactories
[SvtModuleOptions::E_SCHART
].getFactory();
588 if( m_lFactories
[SvtModuleOptions::E_SMATH
].getInstalled() )
589 aRet
[n
++] = m_lFactories
[SvtModuleOptions::E_SMATH
].getFactory();
590 if( m_lFactories
[SvtModuleOptions::E_SBASIC
].getInstalled() )
591 aRet
[n
++] = m_lFactories
[SvtModuleOptions::E_SBASIC
].getFactory();
592 if( m_lFactories
[SvtModuleOptions::E_SDATABASE
].getInstalled() )
593 aRet
[n
++] = m_lFactories
[SvtModuleOptions::E_SDATABASE
].getFactory();
598 //*****************************************************************************************************************
599 ::rtl::OUString
SvtModuleOptions_Impl::GetFactoryName( SvtModuleOptions::EFactory eFactory
) const
601 ::rtl::OUString sName
;
603 if( eFactory
>=0 && eFactory
<FACTORYCOUNT
)
605 sName
= m_lFactories
[eFactory
].getFactory();
611 //*****************************************************************************************************************
612 ::rtl::OUString
SvtModuleOptions_Impl::GetFactoryShortName( SvtModuleOptions::EFactory eFactory
) const
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!
617 //return m_lFactories[eFactory].sShortName;
619 ::rtl::OUString sShortName
;
622 case SvtModuleOptions::E_WRITER
: sShortName
= ::rtl::OUString("swriter");
624 case SvtModuleOptions::E_WRITERWEB
: sShortName
= ::rtl::OUString("swriter/web");
626 case SvtModuleOptions::E_WRITERGLOBAL
: sShortName
= ::rtl::OUString("swriter/GlobalDocument");
628 case SvtModuleOptions::E_CALC
: sShortName
= ::rtl::OUString("scalc");
630 case SvtModuleOptions::E_DRAW
: sShortName
= ::rtl::OUString("sdraw");
632 case SvtModuleOptions::E_IMPRESS
: sShortName
= ::rtl::OUString("simpress");
634 case SvtModuleOptions::E_MATH
: sShortName
= ::rtl::OUString("smath");
636 case SvtModuleOptions::E_CHART
: sShortName
= ::rtl::OUString("schart");
638 case SvtModuleOptions::E_BASIC
: sShortName
= ::rtl::OUString("sbasic");
640 case SvtModuleOptions::E_DATABASE
: sShortName
= ::rtl::OUString("sdatabase");
643 OSL_FAIL( "unknown factory" );
650 //*****************************************************************************************************************
651 ::rtl::OUString
SvtModuleOptions_Impl::GetFactoryStandardTemplate( SvtModuleOptions::EFactory eFactory
) const
653 ::rtl::OUString sFile
;
655 if( eFactory
>=0 && eFactory
<FACTORYCOUNT
)
657 sFile
= m_lFactories
[eFactory
].getTemplateFile();
663 //*****************************************************************************************************************
664 ::rtl::OUString
SvtModuleOptions_Impl::GetFactoryEmptyDocumentURL( SvtModuleOptions::EFactory eFactory
) const
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!
669 //return m_lFactories[eFactory].getEmptyDocumentURL();
671 ::rtl::OUString sURL
;
674 case SvtModuleOptions::E_WRITER
: sURL
= ::rtl::OUString("private:factory/swriter");
676 case SvtModuleOptions::E_WRITERWEB
: sURL
= ::rtl::OUString("private:factory/swriter/web");
678 case SvtModuleOptions::E_WRITERGLOBAL
: sURL
= ::rtl::OUString("private:factory/swriter/GlobalDocument");
680 case SvtModuleOptions::E_CALC
: sURL
= ::rtl::OUString("private:factory/scalc");
682 case SvtModuleOptions::E_DRAW
: sURL
= ::rtl::OUString("private:factory/sdraw");
684 case SvtModuleOptions::E_IMPRESS
: sURL
= ::rtl::OUString("private:factory/simpress?slot=6686");
686 case SvtModuleOptions::E_MATH
: sURL
= ::rtl::OUString("private:factory/smath");
688 case SvtModuleOptions::E_CHART
: sURL
= ::rtl::OUString("private:factory/schart");
690 case SvtModuleOptions::E_BASIC
: sURL
= ::rtl::OUString("private:factory/sbasic");
692 case SvtModuleOptions::E_DATABASE
: sURL
= ::rtl::OUString("private:factory/sdatabase?Interactive");
695 OSL_FAIL( "unknown factory" );
701 //*****************************************************************************************************************
702 ::rtl::OUString
SvtModuleOptions_Impl::GetFactoryDefaultFilter( SvtModuleOptions::EFactory eFactory
) const
704 ::rtl::OUString sDefaultFilter
;
706 if( eFactory
>=0 && eFactory
<FACTORYCOUNT
)
708 sDefaultFilter
= m_lFactories
[eFactory
].getDefaultFilter();
710 return sDefaultFilter
;
712 //*****************************************************************************************************************
713 sal_Bool
SvtModuleOptions_Impl::IsDefaultFilterReadonly( SvtModuleOptions::EFactory eFactory
) const
715 sal_Bool bRet
= sal_False
;
716 if( eFactory
>=0 && eFactory
<FACTORYCOUNT
)
718 bRet
= m_lFactories
[eFactory
].isDefaultFilterReadonly();
723 //*****************************************************************************************************************
724 sal_Int32
SvtModuleOptions_Impl::GetFactoryIcon( SvtModuleOptions::EFactory eFactory
) const
728 if( eFactory
>=0 && eFactory
<FACTORYCOUNT
)
730 nIcon
= m_lFactories
[eFactory
].getIcon();
736 //*****************************************************************************************************************
737 void SvtModuleOptions_Impl::SetFactoryStandardTemplate( SvtModuleOptions::EFactory eFactory
,
738 const ::rtl::OUString
& sTemplate
)
740 if( eFactory
>=0 && eFactory
<FACTORYCOUNT
)
742 m_lFactories
[eFactory
].setTemplateFile( sTemplate
);
747 //*****************************************************************************************************************
748 void SvtModuleOptions_Impl::SetFactoryDefaultFilter( SvtModuleOptions::EFactory eFactory
,
749 const ::rtl::OUString
& sFilter
)
751 if( eFactory
>=0 && eFactory
<FACTORYCOUNT
)
753 m_lFactories
[eFactory
].setDefaultFilter( sFilter
);
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.
767 @return List of all relative addressed properties of given set entry names.
769 @onerror List will be empty.
771 *//*-*************************************************************************************************************/
772 css::uno::Sequence
< ::rtl::OUString
> SvtModuleOptions_Impl::impl_ExpandSetNames( const css::uno::Sequence
< ::rtl::OUString
>& lSetNames
)
774 sal_Int32 nCount
= lSetNames
.getLength() ;
775 css::uno::Sequence
< ::rtl::OUString
> lPropNames ( nCount
*PROPERTYCOUNT
);
776 ::rtl::OUString
* pPropNames
= lPropNames
.getArray() ;
777 sal_Int32 nPropStart
= 0 ;
779 for( sal_Int32 nName
=0; nName
<nCount
; ++nName
)
781 pPropNames
[nPropStart
+PROPERTYHANDLE_SHORTNAME
] = lSetNames
[nName
] + PATHSEPERATOR
+ PROPERTYNAME_SHORTNAME
;
782 pPropNames
[nPropStart
+PROPERTYHANDLE_TEMPLATEFILE
] = lSetNames
[nName
] + PATHSEPERATOR
+ PROPERTYNAME_TEMPLATEFILE
;
783 pPropNames
[nPropStart
+PROPERTYHANDLE_WINDOWATTRIBUTES
] = lSetNames
[nName
] + PATHSEPERATOR
+ PROPERTYNAME_WINDOWATTRIBUTES
;
784 pPropNames
[nPropStart
+PROPERTYHANDLE_EMPTYDOCUMENTURL
] = lSetNames
[nName
] + PATHSEPERATOR
+ PROPERTYNAME_EMPTYDOCUMENTURL
;
785 pPropNames
[nPropStart
+PROPERTYHANDLE_DEFAULTFILTER
] = lSetNames
[nName
] + PATHSEPERATOR
+ PROPERTYNAME_DEFAULTFILTER
;
786 pPropNames
[nPropStart
+PROPERTYHANDLE_ICON
] = lSetNames
[nName
] + PATHSEPERATOR
+ PROPERTYNAME_ICON
;
787 nPropStart
+= PROPERTYCOUNT
;
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.
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!
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
809 @onerror We return false.
811 *//*-*************************************************************************************************************/
812 sal_Bool
SvtModuleOptions_Impl::ClassifyFactoryByName( const ::rtl::OUString
& sName
, SvtModuleOptions::EFactory
& eFactory
)
816 eFactory
= SvtModuleOptions::E_WRITER
;
817 bState
= ( sName
== FACTORYNAME_WRITER
);
819 if( bState
== sal_False
)
821 eFactory
= SvtModuleOptions::E_WRITERWEB
;
822 bState
= ( sName
== FACTORYNAME_WRITERWEB
);
825 if( bState
== sal_False
)
827 eFactory
= SvtModuleOptions::E_WRITERGLOBAL
;
828 bState
= ( sName
== FACTORYNAME_WRITERGLOBAL
);
831 if( bState
== sal_False
)
833 eFactory
= SvtModuleOptions::E_CALC
;
834 bState
= ( sName
== FACTORYNAME_CALC
);
837 if( bState
== sal_False
)
839 eFactory
= SvtModuleOptions::E_DRAW
;
840 bState
= ( sName
== FACTORYNAME_DRAW
);
843 if( bState
== sal_False
)
845 eFactory
= SvtModuleOptions::E_IMPRESS
;
846 bState
= ( sName
== FACTORYNAME_IMPRESS
);
849 if( bState
== sal_False
)
851 eFactory
= SvtModuleOptions::E_MATH
;
852 bState
= ( sName
== FACTORYNAME_MATH
);
855 if( bState
== sal_False
)
857 eFactory
= SvtModuleOptions::E_CHART
;
858 bState
= ( sName
== FACTORYNAME_CHART
);
861 if( bState
== sal_False
)
863 eFactory
= SvtModuleOptions::E_DATABASE
;
864 bState
= ( sName
== FACTORYNAME_DATABASE
);
867 if( bState
== sal_False
)
869 eFactory
= SvtModuleOptions::E_STARTMODULE
;
870 bState
= ( sName
== FACTORYNAME_STARTMODULE
);
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()".
883 @seealso method Notify()
885 @param "lFactories" is the list of set node entries which should be readed.
888 @onerror We do nothing.
890 *//*-*************************************************************************************************************/
891 void SvtModuleOptions_Impl::impl_Read( const css::uno::Sequence
< ::rtl::OUString
>& lFactories
)
893 // Expand every set node name in lFactories to full qualified paths to his properties
894 // and get right values from configuration.
895 const css::uno::Sequence
< ::rtl::OUString
> lProperties
= impl_ExpandSetNames( lFactories
);
896 const css::uno::Sequence
< css::uno::Any
> lValues
= GetProperties( lProperties
);
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" );
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" ...
914 sal_Int32 nPropertyStart
= 0 ;
915 sal_Int32 nNodeCount
= lFactories
.getLength();
916 FactoryInfo
* pInfo
= NULL
;
917 SvtModuleOptions::EFactory eFactory
;
919 for( sal_Int32 nSetNode
=0; nSetNode
<nNodeCount
; ++nSetNode
)
921 const ::rtl::OUString
& sFactoryName
= lFactories
[nSetNode
];
922 if( ClassifyFactoryByName( sFactoryName
, eFactory
) == sal_True
)
924 ::rtl::OUString sTemp
;
927 pInfo
= &(m_lFactories
[eFactory
]);
930 pInfo
->initInstalled( sal_True
);
931 pInfo
->initFactory ( sFactoryName
);
933 if (lValues
[nPropertyStart
+PROPERTYHANDLE_SHORTNAME
] >>= sTemp
)
934 pInfo
->initShortName( sTemp
);
935 if (lValues
[nPropertyStart
+PROPERTYHANDLE_TEMPLATEFILE
] >>= sTemp
)
936 pInfo
->initTemplateFile( sTemp
);
937 if (lValues
[nPropertyStart
+PROPERTYHANDLE_WINDOWATTRIBUTES
] >>= sTemp
)
938 pInfo
->initWindowAttributes( sTemp
);
939 if (lValues
[nPropertyStart
+PROPERTYHANDLE_EMPTYDOCUMENTURL
] >>= sTemp
)
940 pInfo
->initEmptyDocumentURL( sTemp
);
941 if (lValues
[nPropertyStart
+PROPERTYHANDLE_DEFAULTFILTER
] >>= sTemp
)
942 pInfo
->initDefaultFilter( sTemp
);
943 if (lValues
[nPropertyStart
+PROPERTYHANDLE_ICON
] >>= nTemp
)
944 pInfo
->initIcon( nTemp
);
946 nPropertyStart
+= PROPERTYCOUNT
;
950 //*****************************************************************************************************************
951 void SvtModuleOptions_Impl::MakeReadonlyStatesAvailable()
953 if (m_bReadOnlyStatesWellKnown
)
956 css::uno::Sequence
< ::rtl::OUString
> lFactories
= GetNodeNames(::rtl::OUString());
957 sal_Int32 c
= lFactories
.getLength();
961 ::rtl::OUStringBuffer
sPath(256);
962 sPath
.append(lFactories
[i
] );
963 sPath
.append(PATHSEPERATOR
);
964 sPath
.append(PROPERTYNAME_DEFAULTFILTER
);
966 lFactories
[i
] = sPath
.makeStringAndClear();
969 css::uno::Sequence
< sal_Bool
> lReadonlyStates
= GetReadOnlyStates(lFactories
);
972 ::rtl::OUString
& rFactoryName
= lFactories
[i
];
973 SvtModuleOptions::EFactory eFactory
;
975 if (!ClassifyFactoryByName(rFactoryName
, eFactory
))
978 FactoryInfo
& rInfo
= m_lFactories
[eFactory
];
979 rInfo
.setDefaultFilterReadonly(lReadonlyStates
[i
]);
982 m_bReadOnlyStatesWellKnown
= sal_True
;
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 ;
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.
998 @seealso method impl_GetOwnStaticMutex()
1005 *//*-*************************************************************************************************************/
1006 SvtModuleOptions::SvtModuleOptions()
1008 ::osl::MutexGuard
aGuard( impl_GetOwnStaticMutex() );
1010 if( m_nRefCount
== 1 )
1012 RTL_LOGFILE_CONTEXT(aLog
, "unotools ( ??? ) ::SvtModuleOptions_Impl::ctor()");
1013 m_pDataContainer
= new SvtModuleOptions_Impl();
1015 ItemHolder1::holdConfigItem(E_MODULEOPTIONS
);
1019 //*****************************************************************************************************************
1020 SvtModuleOptions::~SvtModuleOptions()
1022 ::osl::MutexGuard
aGuard( impl_GetOwnStaticMutex() );
1024 if( m_nRefCount
== 0 )
1026 delete m_pDataContainer
;
1027 m_pDataContainer
= NULL
;
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!
1036 @seealso method impl_GetOwnStaticMutex()
1043 *//*-*************************************************************************************************************/
1044 sal_Bool
SvtModuleOptions::IsModuleInstalled( EModule eModule
) const
1046 ::osl::MutexGuard
aGuard( impl_GetOwnStaticMutex() );
1047 return m_pDataContainer
->IsModuleInstalled( eModule
);
1050 //*****************************************************************************************************************
1051 ::rtl::OUString
SvtModuleOptions::GetFactoryName( EFactory eFactory
) const
1053 ::osl::MutexGuard
aGuard( impl_GetOwnStaticMutex() );
1054 return m_pDataContainer
->GetFactoryName( eFactory
);
1057 //*****************************************************************************************************************
1058 ::rtl::OUString
SvtModuleOptions::GetFactoryShortName( EFactory eFactory
) const
1060 ::osl::MutexGuard
aGuard( impl_GetOwnStaticMutex() );
1061 return m_pDataContainer
->GetFactoryShortName( eFactory
);
1064 //*****************************************************************************************************************
1065 ::rtl::OUString
SvtModuleOptions::GetFactoryStandardTemplate( EFactory eFactory
) const
1067 ::osl::MutexGuard
aGuard( impl_GetOwnStaticMutex() );
1068 return m_pDataContainer
->GetFactoryStandardTemplate( eFactory
);
1071 //*****************************************************************************************************************
1072 ::rtl::OUString
SvtModuleOptions::GetFactoryEmptyDocumentURL( EFactory eFactory
) const
1074 ::osl::MutexGuard
aGuard( impl_GetOwnStaticMutex() );
1075 return m_pDataContainer
->GetFactoryEmptyDocumentURL( eFactory
);
1078 //*****************************************************************************************************************
1079 ::rtl::OUString
SvtModuleOptions::GetFactoryDefaultFilter( EFactory eFactory
) const
1081 ::osl::MutexGuard
aGuard( impl_GetOwnStaticMutex() );
1082 return m_pDataContainer
->GetFactoryDefaultFilter( eFactory
);
1084 //*****************************************************************************************************************
1085 sal_Bool
SvtModuleOptions::IsDefaultFilterReadonly( EFactory eFactory
) const
1087 ::osl::MutexGuard
aGuard( impl_GetOwnStaticMutex() );
1088 m_pDataContainer
->MakeReadonlyStatesAvailable();
1089 return m_pDataContainer
->IsDefaultFilterReadonly( eFactory
);
1091 //*****************************************************************************************************************
1092 sal_Int32
SvtModuleOptions::GetFactoryIcon( EFactory eFactory
) const
1094 ::osl::MutexGuard
aGuard( impl_GetOwnStaticMutex() );
1095 return m_pDataContainer
->GetFactoryIcon( eFactory
);
1098 //*****************************************************************************************************************
1099 sal_Bool
SvtModuleOptions::ClassifyFactoryByName( const ::rtl::OUString
& sName
,
1100 EFactory
& eFactory
)
1102 // We don't need any mutex here ... because we don't use any member here!
1103 return SvtModuleOptions_Impl::ClassifyFactoryByName( sName
, eFactory
);
1106 //*****************************************************************************************************************
1107 void SvtModuleOptions::SetFactoryStandardTemplate( EFactory eFactory
,
1108 const ::rtl::OUString
& sTemplate
)
1110 ::osl::MutexGuard
aGuard( impl_GetOwnStaticMutex() );
1111 m_pDataContainer
->SetFactoryStandardTemplate( eFactory
, sTemplate
);
1114 //*****************************************************************************************************************
1115 void SvtModuleOptions::SetFactoryDefaultFilter( EFactory eFactory
,
1116 const ::rtl::OUString
& sFilter
)
1118 ::osl::MutexGuard
aGuard( impl_GetOwnStaticMutex() );
1119 m_pDataContainer
->SetFactoryDefaultFilter( eFactory
, sFilter
);
1122 //*****************************************************************************************************************
1123 sal_Bool
SvtModuleOptions::IsMath() const
1125 ::osl::MutexGuard
aGuard( impl_GetOwnStaticMutex() );
1126 return m_pDataContainer
->IsModuleInstalled( E_SMATH
);
1129 //*****************************************************************************************************************
1130 sal_Bool
SvtModuleOptions::IsChart() const
1132 ::osl::MutexGuard
aGuard( impl_GetOwnStaticMutex() );
1133 return m_pDataContainer
->IsModuleInstalled( E_SCHART
);
1136 //*****************************************************************************************************************
1137 sal_Bool
SvtModuleOptions::IsCalc() const
1139 ::osl::MutexGuard
aGuard( impl_GetOwnStaticMutex() );
1140 return m_pDataContainer
->IsModuleInstalled( E_SCALC
);
1143 //*****************************************************************************************************************
1144 sal_Bool
SvtModuleOptions::IsDraw() const
1146 ::osl::MutexGuard
aGuard( impl_GetOwnStaticMutex() );
1147 return m_pDataContainer
->IsModuleInstalled( E_SDRAW
);
1150 //*****************************************************************************************************************
1151 sal_Bool
SvtModuleOptions::IsWriter() const
1153 ::osl::MutexGuard
aGuard( impl_GetOwnStaticMutex() );
1154 return m_pDataContainer
->IsModuleInstalled( E_SWRITER
);
1157 //*****************************************************************************************************************
1158 sal_Bool
SvtModuleOptions::IsImpress() const
1160 ::osl::MutexGuard
aGuard( impl_GetOwnStaticMutex() );
1161 return m_pDataContainer
->IsModuleInstalled( E_SIMPRESS
);
1164 //*****************************************************************************************************************
1165 sal_Bool
SvtModuleOptions::IsBasicIDE() const
1169 //*****************************************************************************************************************
1170 sal_Bool
SvtModuleOptions::IsDataBase() const
1172 ::osl::MutexGuard
aGuard( impl_GetOwnStaticMutex() );
1173 return m_pDataContainer
->IsModuleInstalled( E_SDATABASE
);
1178 class theModuleOptionsMutex
: public rtl::Static
<osl::Mutex
, theModuleOptionsMutex
> {};
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
1189 @return A reference to a static mutex member.
1193 *//*-*****************************************************************************************************/
1194 ::osl::Mutex
& SvtModuleOptions::impl_GetOwnStaticMutex()
1196 return theModuleOptionsMutex::get();
1199 ::rtl::OUString
SvtModuleOptions::GetModuleName( EModule eModule
) const
1203 case SvtModuleOptions::E_SWRITER
: { return ::rtl::OUString("Writer"); }
1204 case SvtModuleOptions::E_SWEB
: { return ::rtl::OUString("Web"); }
1205 case SvtModuleOptions::E_SGLOBAL
: { return ::rtl::OUString("Global"); }
1206 case SvtModuleOptions::E_SCALC
: { return ::rtl::OUString("Calc"); }
1207 case SvtModuleOptions::E_SDRAW
: { return ::rtl::OUString("Draw"); }
1208 case SvtModuleOptions::E_SIMPRESS
: { return ::rtl::OUString("Impress"); }
1209 case SvtModuleOptions::E_SMATH
: { return ::rtl::OUString("Math"); }
1210 case SvtModuleOptions::E_SCHART
: { return ::rtl::OUString("Chart"); }
1211 case SvtModuleOptions::E_SBASIC
: { return ::rtl::OUString("Basic"); }
1212 case SvtModuleOptions::E_SDATABASE
: { return ::rtl::OUString("Database"); }
1214 OSL_FAIL( "unknown module" );
1218 return ::rtl::OUString();
1221 SvtModuleOptions::EFactory
SvtModuleOptions::ClassifyFactoryByShortName(const ::rtl::OUString
& sName
)
1223 if ( sName
== "swriter" )
1225 if (sName
.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("swriter/Web"))) // sometimes they are registerd for swriter/web :-(
1227 if (sName
.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("swriter/GlobalDocument"))) // sometimes they are registerd for swriter/globaldocument :-(
1228 return E_WRITERGLOBAL
;
1229 if ( sName
== "scalc" )
1231 if ( sName
== "sdraw" )
1233 if ( sName
== "simpress" )
1235 if ( sName
== "schart" )
1237 if ( sName
== "smath" )
1239 if ( sName
== "sbasic" )
1241 if ( sName
== "sdatabase" )
1244 return E_UNKNOWN_FACTORY
;
1247 SvtModuleOptions::EFactory
SvtModuleOptions::ClassifyFactoryByServiceName(const ::rtl::OUString
& sName
)
1249 if (sName
.equals(FACTORYNAME_WRITERGLOBAL
))
1250 return E_WRITERGLOBAL
;
1251 if (sName
.equals(FACTORYNAME_WRITERWEB
))
1253 if (sName
.equals(FACTORYNAME_WRITER
))
1255 if (sName
.equals(FACTORYNAME_CALC
))
1257 if (sName
.equals(FACTORYNAME_DRAW
))
1259 if (sName
.equals(FACTORYNAME_IMPRESS
))
1261 if (sName
.equals(FACTORYNAME_MATH
))
1263 if (sName
.equals(FACTORYNAME_CHART
))
1265 if (sName
.equals(FACTORYNAME_DATABASE
))
1268 return E_UNKNOWN_FACTORY
;
1271 SvtModuleOptions::EFactory
SvtModuleOptions::ClassifyFactoryByURL(const ::rtl::OUString
& sURL
,
1272 const css::uno::Sequence
< css::beans::PropertyValue
>& lMediaDescriptor
)
1274 css::uno::Reference
< css::lang::XMultiServiceFactory
> xSMGR
= ::comphelper::getProcessServiceFactory();
1276 return E_UNKNOWN_FACTORY
;
1278 css::uno::Reference
< css::container::XNameAccess
> xFilterCfg
;
1279 css::uno::Reference
< css::container::XNameAccess
> xTypeCfg
;
1282 xFilterCfg
= css::uno::Reference
< css::container::XNameAccess
>(
1283 xSMGR
->createInstance(::rtl::OUString("com.sun.star.document.FilterFactory")), css::uno::UNO_QUERY
);
1284 xTypeCfg
= css::uno::Reference
< css::container::XNameAccess
>(
1285 xSMGR
->createInstance(::rtl::OUString("com.sun.star.document.TypeDetection")), css::uno::UNO_QUERY
);
1287 catch(const css::uno::RuntimeException
&)
1289 catch(const css::uno::Exception
&)
1290 { return E_UNKNOWN_FACTORY
; }
1292 ::comphelper::SequenceAsHashMap
stlDesc(lMediaDescriptor
);
1294 // is there already a filter inside the descriptor?
1295 ::rtl::OUString sFilterName
= stlDesc
.getUnpackedValueOrDefault(::rtl::OUString("FilterName"), ::rtl::OUString());
1296 if (!sFilterName
.isEmpty())
1300 ::comphelper::SequenceAsHashMap
stlFilterProps (xFilterCfg
->getByName(sFilterName
));
1301 ::rtl::OUString sDocumentService
= stlFilterProps
.getUnpackedValueOrDefault(::rtl::OUString("DocumentService"), ::rtl::OUString());
1302 SvtModuleOptions::EFactory eApp
= SvtModuleOptions::ClassifyFactoryByServiceName(sDocumentService
);
1304 if (eApp
!= E_UNKNOWN_FACTORY
)
1307 catch(const css::uno::RuntimeException
&)
1309 catch(const css::uno::Exception
&)
1310 { /* do nothing here ... may the following code can help!*/ }
1313 // is there already a type inside the descriptor?
1314 ::rtl::OUString sTypeName
= stlDesc
.getUnpackedValueOrDefault(::rtl::OUString("TypeName"), ::rtl::OUString());
1315 if (sTypeName
.isEmpty())
1318 // start flat detection of URL
1319 css::uno::Reference
< css::document::XTypeDetection
> xDetect(xTypeCfg
, css::uno::UNO_QUERY
);
1320 sTypeName
= xDetect
->queryTypeByURL(sURL
);
1323 if (sTypeName
.isEmpty())
1324 return E_UNKNOWN_FACTORY
;
1326 // yes - there is a type info
1327 // Try to find the preferred filter.
1330 ::comphelper::SequenceAsHashMap
stlTypeProps (xTypeCfg
->getByName(sTypeName
));
1331 ::rtl::OUString sPreferredFilter
= stlTypeProps
.getUnpackedValueOrDefault(::rtl::OUString("PreferredFilter"), ::rtl::OUString());
1332 ::comphelper::SequenceAsHashMap
stlFilterProps (xFilterCfg
->getByName(sPreferredFilter
));
1333 ::rtl::OUString sDocumentService
= stlFilterProps
.getUnpackedValueOrDefault(::rtl::OUString("DocumentService"), ::rtl::OUString());
1334 SvtModuleOptions::EFactory eApp
= SvtModuleOptions::ClassifyFactoryByServiceName(sDocumentService
);
1336 if (eApp
!= E_UNKNOWN_FACTORY
)
1339 catch(const css::uno::RuntimeException
&)
1341 catch(const css::uno::Exception
&)
1342 { /* do nothing here ... may the following code can help!*/ }
1344 // no filter/no type/no detection result => no fun :-)
1345 return E_UNKNOWN_FACTORY
;
1348 SvtModuleOptions::EFactory
SvtModuleOptions::ClassifyFactoryByModel(const css::uno::Reference
< css::frame::XModel
>& xModel
)
1350 css::uno::Reference
< css::lang::XServiceInfo
> xInfo(xModel
, css::uno::UNO_QUERY
);
1352 return E_UNKNOWN_FACTORY
;
1354 const css::uno::Sequence
< ::rtl::OUString
> lServices
= xInfo
->getSupportedServiceNames();
1355 const ::rtl::OUString
* pServices
= lServices
.getConstArray();
1357 for (sal_Int32 i
=0; i
<lServices
.getLength() ; ++i
)
1359 SvtModuleOptions::EFactory eApp
= SvtModuleOptions::ClassifyFactoryByServiceName(pServices
[i
]);
1360 if (eApp
!= E_UNKNOWN_FACTORY
)
1364 return E_UNKNOWN_FACTORY
;
1367 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SvtModuleOptions::GetAllServiceNames()
1369 ::osl::MutexGuard
aGuard( impl_GetOwnStaticMutex() );
1370 return m_pDataContainer
->GetAllServiceNames();
1373 ::rtl::OUString
SvtModuleOptions::GetDefaultModuleName()
1375 ::rtl::OUString aModule
;
1376 if (m_pDataContainer
->IsModuleInstalled(SvtModuleOptions::E_SWRITER
))
1377 aModule
= m_pDataContainer
->GetFactoryShortName(SvtModuleOptions::E_WRITER
);
1379 if (m_pDataContainer
->IsModuleInstalled(SvtModuleOptions::E_SCALC
))
1380 aModule
= m_pDataContainer
->GetFactoryShortName(SvtModuleOptions::E_CALC
);
1382 if (m_pDataContainer
->IsModuleInstalled(SvtModuleOptions::E_SIMPRESS
))
1383 aModule
= m_pDataContainer
->GetFactoryShortName(SvtModuleOptions::E_IMPRESS
);
1385 if (m_pDataContainer
->IsModuleInstalled(SvtModuleOptions::E_SDATABASE
))
1386 aModule
= m_pDataContainer
->GetFactoryShortName(SvtModuleOptions::E_DATABASE
);
1388 if (m_pDataContainer
->IsModuleInstalled(SvtModuleOptions::E_SDRAW
))
1389 aModule
= m_pDataContainer
->GetFactoryShortName(SvtModuleOptions::E_DRAW
);
1391 if (m_pDataContainer
->IsModuleInstalled(SvtModuleOptions::E_SWEB
))
1392 aModule
= m_pDataContainer
->GetFactoryShortName(SvtModuleOptions::E_WRITERWEB
);
1394 if (m_pDataContainer
->IsModuleInstalled(SvtModuleOptions::E_SGLOBAL
))
1395 aModule
= m_pDataContainer
->GetFactoryShortName(SvtModuleOptions::E_WRITERGLOBAL
);
1397 if (m_pDataContainer
->IsModuleInstalled(SvtModuleOptions::E_SMATH
))
1398 aModule
= m_pDataContainer
->GetFactoryShortName(SvtModuleOptions::E_MATH
);
1402 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */