1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: startoptions.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
36 //_________________________________________________________________________________________________________________
38 //_________________________________________________________________________________________________________________
40 #include <svtools/startoptions.hxx>
41 #include <unotools/configmgr.hxx>
42 #include <unotools/configitem.hxx>
43 #include <tools/debug.hxx>
44 #include <com/sun/star/uno/Any.hxx>
45 #include <com/sun/star/uno/Sequence.hxx>
47 #include <rtl/logfile.hxx>
48 #include "itemholder1.hxx"
49 //_________________________________________________________________________________________________________________
51 //_________________________________________________________________________________________________________________
53 using namespace ::utl
;
54 using namespace ::rtl
;
55 using namespace ::osl
;
56 using namespace ::com::sun::star::uno
;
58 //_________________________________________________________________________________________________________________
60 //_________________________________________________________________________________________________________________
62 #define DEFAULT_SHOWINTRO sal_True
63 #define DEFAULT_CONNECTIONURL OUString()
65 #define ROOTNODE_START OUString(RTL_CONSTASCII_USTRINGPARAM("Setup/Office" ))
66 #define PROPERTYNAME_SHOWINTRO OUString(RTL_CONSTASCII_USTRINGPARAM("ooSetupShowIntro" ))
67 #define PROPERTYNAME_CONNECTIONURL OUString(RTL_CONSTASCII_USTRINGPARAM("ooSetupConnectionURL" ))
69 #define PROPERTYHANDLE_SHOWINTRO 0
70 #define PROPERTYHANDLE_CONNECTIONURL 1
72 #define PROPERTYCOUNT 2
74 //_________________________________________________________________________________________________________________
75 // private declarations!
76 //_________________________________________________________________________________________________________________
78 class SvtStartOptions_Impl
: public ConfigItem
80 //-------------------------------------------------------------------------------------------------------------
82 //-------------------------------------------------------------------------------------------------------------
86 //---------------------------------------------------------------------------------------------------------
87 // constructor / destructor
88 //---------------------------------------------------------------------------------------------------------
90 SvtStartOptions_Impl();
91 ~SvtStartOptions_Impl();
93 //---------------------------------------------------------------------------------------------------------
94 // overloaded methods of baseclass
95 //---------------------------------------------------------------------------------------------------------
97 /*-****************************************************************************************************//**
98 @short called for notify of configmanager
99 @descr These method is called from the ConfigManager before application ends or from the
100 PropertyChangeListener if the sub tree broadcasts changes. You must update your
103 @ATTENTION We don't implement these method - because we support readonly values at runtime only!
105 @seealso baseclass ConfigItem
107 @param "seqPropertyNames" is the list of properties which should be updated.
111 *//*-*****************************************************************************************************/
113 virtual void Notify( const Sequence
< OUString
>& seqPropertyNames
);
115 /*-****************************************************************************************************//**
116 @short write changes to configuration
117 @descr These method writes the changed values into the sub tree
118 and should always called in our destructor to guarantee consistency of config data.
120 @ATTENTION We don't implement these method - because we support readonly values at runtime only!
122 @seealso baseclass ConfigItem
128 *//*-*****************************************************************************************************/
130 virtual void Commit();
132 //---------------------------------------------------------------------------------------------------------
134 //---------------------------------------------------------------------------------------------------------
136 /*-****************************************************************************************************//**
137 @short access method to get internal values
138 @descr These method give us a chance to regulate acces to ouer internal values.
139 It's not used in the moment - but it's possible for the feature!
147 *//*-*****************************************************************************************************/
149 sal_Bool
IsIntroEnabled ( ) const ;
150 void EnableIntro ( sal_Bool bState
) ;
151 OUString
GetConnectionURL( ) const ;
152 void SetConnectionURL( const OUString
& sURL
) ;
154 //-------------------------------------------------------------------------------------------------------------
156 //-------------------------------------------------------------------------------------------------------------
160 /*-****************************************************************************************************//**
161 @short return list of fix key names of ouer configuration management which represent oue module tree
162 @descr These methods return a static const list of key names. We need it to get needed values from our
163 configuration management. We return well known key names only - because the "UserData" node
164 is handled in a special way!
169 @return A list of needed configuration keys is returned.
172 *//*-*****************************************************************************************************/
174 static Sequence
< OUString
> impl_GetPropertyNames();
176 //-------------------------------------------------------------------------------------------------------------
178 //-------------------------------------------------------------------------------------------------------------
182 sal_Bool m_bShowIntro
; /// cache "ShowIntro" of Start section
183 OUString m_sConnectionURL
; /// cache "Connection" of Start section
186 //_________________________________________________________________________________________________________________
188 //_________________________________________________________________________________________________________________
190 //*****************************************************************************************************************
192 //*****************************************************************************************************************
193 SvtStartOptions_Impl::SvtStartOptions_Impl()
194 // Init baseclasses first
195 : ConfigItem ( ROOTNODE_START
)
197 , m_bShowIntro ( DEFAULT_SHOWINTRO
)
199 // Use our static list of configuration keys to get his values.
200 Sequence
< OUString
> seqNames
= impl_GetPropertyNames();
201 Sequence
< Any
> seqValues
= GetProperties( seqNames
) ;
203 // Safe impossible cases.
204 // We need values from ALL configuration keys.
205 // Follow assignment use order of values in relation to our list of key names!
206 DBG_ASSERT( !(seqNames
.getLength()!=seqValues
.getLength()), "SvtStartOptions_Impl::SvtStartOptions_Impl()\nI miss some values of configuration keys!\n" );
208 // Copy values from list in right order to ouer internal member.
209 sal_Int32 nPropertyCount
= seqValues
.getLength() ;
210 sal_Int32 nProperty
= 0 ;
211 for( nProperty
=0; nProperty
<nPropertyCount
; ++nProperty
)
213 // Safe impossible cases.
214 // Check any for valid value.
215 DBG_ASSERT( !(seqValues
[nProperty
].hasValue()==sal_False
), "SvtStartOptions_Impl::SvtStartOptions_Impl()\nInvalid property value for property detected!\n" );
218 case PROPERTYHANDLE_SHOWINTRO
: {
219 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_BOOLEAN
), "SvtStartOptions_Impl::SvtStartOptions_Impl()\nWho has changed the value type of \"Office.Common\\Start\\ShowIntro\"?" );
220 seqValues
[nProperty
] >>= m_bShowIntro
;
224 case PROPERTYHANDLE_CONNECTIONURL
: {
225 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_STRING
), "SvtStartOptions_Impl::SvtStartOptions_Impl()\nWho has changed the value type of \"Office.Common\\Start\\Connection\"?" );
226 seqValues
[nProperty
] >>= m_sConnectionURL
;
232 // Don't enable notification mechanism of ouer baseclass!
233 // We support readonly variables in the moment.
236 //*****************************************************************************************************************
238 //*****************************************************************************************************************
239 SvtStartOptions_Impl::~SvtStartOptions_Impl()
241 // We must save our current values .. if user forget it!
242 if( IsModified() == sal_True
)
248 //*****************************************************************************************************************
250 //*****************************************************************************************************************
251 void SvtStartOptions_Impl::Notify( const Sequence
< OUString
>& seqPropertyNames
)
253 // Use given list of updated properties to get his values from configuration directly!
254 Sequence
< Any
> seqValues
= GetProperties( seqPropertyNames
);
255 // Safe impossible cases.
256 // We need values from ALL notified configuration keys.
257 DBG_ASSERT( !(seqPropertyNames
.getLength()!=seqValues
.getLength()), "SvtStartOptions_Impl::Notify()\nI miss some values of configuration keys!\n" );
258 // Step over list of property names and get right value from coreesponding value list to set it on internal members!
259 sal_Int32 nCount
= seqPropertyNames
.getLength();
260 for( sal_Int32 nProperty
=0; nProperty
<nCount
; ++nProperty
)
262 if( seqPropertyNames
[nProperty
] == PROPERTYNAME_SHOWINTRO
)
264 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_BOOLEAN
), "SvtStartOptions_Impl::Notify()\nWho has changed the value type of \"Office.Common\\Start\\ShowIntro\"?" );
265 seqValues
[nProperty
] >>= m_bShowIntro
;
268 if( seqPropertyNames
[nProperty
] == PROPERTYNAME_CONNECTIONURL
)
270 DBG_ASSERT(!(seqValues
[nProperty
].getValueTypeClass()!=TypeClass_STRING
), "SvtStartOptions_Impl::Notify()\nWho has changed the value type of \"Office.Common\\Start\\Connection\"?" );
271 seqValues
[nProperty
] >>= m_sConnectionURL
;
273 #if OSL_DEBUG_LEVEL > 1
274 else DBG_ASSERT( sal_False
, "SvtStartOptions_Impl::Notify()\nUnkown property detected ... I can't handle these!\n" );
279 //*****************************************************************************************************************
281 //*****************************************************************************************************************
282 void SvtStartOptions_Impl::Commit()
284 // Get names of supported properties, create a list for values and copy current values to it.
285 Sequence
< OUString
> seqNames
= impl_GetPropertyNames();
286 sal_Int32 nCount
= seqNames
.getLength();
287 Sequence
< Any
> seqValues ( nCount
);
288 for( sal_Int32 nProperty
=0; nProperty
<nCount
; ++nProperty
)
292 case PROPERTYHANDLE_SHOWINTRO
: {
293 seqValues
[nProperty
] <<= m_bShowIntro
;
296 case PROPERTYHANDLE_CONNECTIONURL
: {
297 seqValues
[nProperty
] <<= m_sConnectionURL
;
302 // Set properties in configuration.
303 PutProperties( seqNames
, seqValues
);
306 //*****************************************************************************************************************
308 //*****************************************************************************************************************
309 sal_Bool
SvtStartOptions_Impl::IsIntroEnabled() const
314 //*****************************************************************************************************************
316 //*****************************************************************************************************************
317 void SvtStartOptions_Impl::EnableIntro( sal_Bool bState
)
319 m_bShowIntro
= bState
;
323 //*****************************************************************************************************************
325 //*****************************************************************************************************************
326 OUString
SvtStartOptions_Impl::GetConnectionURL() const
328 return m_sConnectionURL
;
331 //*****************************************************************************************************************
333 //*****************************************************************************************************************
334 void SvtStartOptions_Impl::SetConnectionURL( const OUString
& sURL
)
336 m_sConnectionURL
= sURL
;
340 //*****************************************************************************************************************
342 //*****************************************************************************************************************
343 Sequence
< OUString
> SvtStartOptions_Impl::impl_GetPropertyNames()
345 // Build static list of configuration key names.
346 static const OUString pProperties
[] =
348 PROPERTYNAME_SHOWINTRO
,
349 PROPERTYNAME_CONNECTIONURL
,
351 // Initialize return sequence with these list ...
352 static const Sequence
< OUString
> seqPropertyNames( pProperties
, PROPERTYCOUNT
);
353 // ... and return it.
354 return seqPropertyNames
;
357 //*****************************************************************************************************************
358 // initialize static member
359 // DON'T DO IT IN YOUR HEADER!
360 // see definition for further informations
361 //*****************************************************************************************************************
362 SvtStartOptions_Impl
* SvtStartOptions::m_pDataContainer
= NULL
;
363 sal_Int32
SvtStartOptions::m_nRefCount
= 0 ;
365 //*****************************************************************************************************************
367 //*****************************************************************************************************************
368 SvtStartOptions::SvtStartOptions()
370 // Global access, must be guarded (multithreading!).
371 MutexGuard
aGuard( GetOwnStaticMutex() );
372 // Increase ouer refcount ...
374 // ... and initialize ouer data container only if it not already!
375 if( m_pDataContainer
== NULL
)
377 RTL_LOGFILE_CONTEXT(aLog
, "svtools ( ??? ) ::SvtStartOptions_Impl::ctor()");
378 m_pDataContainer
= new SvtStartOptions_Impl();
380 ItemHolder1::holdConfigItem(E_STARTOPTIONS
);
384 //*****************************************************************************************************************
386 //*****************************************************************************************************************
387 SvtStartOptions::~SvtStartOptions()
389 // Global access, must be guarded (multithreading!)
390 MutexGuard
aGuard( GetOwnStaticMutex() );
391 // Decrease ouer refcount.
393 // If last instance was deleted ...
394 // we must destroy ouer static data container!
395 if( m_nRefCount
<= 0 )
397 delete m_pDataContainer
;
398 m_pDataContainer
= NULL
;
402 //*****************************************************************************************************************
404 //*****************************************************************************************************************
405 sal_Bool
SvtStartOptions::IsIntroEnabled() const
407 MutexGuard
aGuard( GetOwnStaticMutex() );
408 return m_pDataContainer
->IsIntroEnabled();
411 //*****************************************************************************************************************
413 //*****************************************************************************************************************
414 void SvtStartOptions::EnableIntro( sal_Bool bState
)
416 MutexGuard
aGuard( GetOwnStaticMutex() );
417 m_pDataContainer
->EnableIntro( bState
);
420 //*****************************************************************************************************************
422 //*****************************************************************************************************************
423 OUString
SvtStartOptions::GetConnectionURL() const
425 MutexGuard
aGuard( GetOwnStaticMutex() );
426 return m_pDataContainer
->GetConnectionURL();
429 //*****************************************************************************************************************
431 //*****************************************************************************************************************
432 void SvtStartOptions::SetConnectionURL( const OUString
& sURL
)
434 MutexGuard
aGuard( GetOwnStaticMutex() );
435 m_pDataContainer
->SetConnectionURL( sURL
);
438 //*****************************************************************************************************************
440 //*****************************************************************************************************************
441 Mutex
& SvtStartOptions::GetOwnStaticMutex()
443 // Initialize static mutex only for one time!
444 static Mutex
* pMutex
= NULL
;
445 // If these method first called (Mutex not already exist!) ...
448 // ... we must create a new one. Protect follow code with the global mutex -
449 // It must be - we create a static variable!
450 MutexGuard
aGuard( Mutex::getGlobalMutex() );
451 // We must check our pointer again - because it can be that another instance of ouer class will be fastr then these!
454 // Create the new mutex and set it for return on static variable.
459 // Return new created or already existing mutex object.