Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #include <unotools/startoptions.hxx>
21 : : #include <unotools/configmgr.hxx>
22 : : #include <unotools/configitem.hxx>
23 : : #include <tools/debug.hxx>
24 : : #include <com/sun/star/uno/Any.hxx>
25 : : #include <com/sun/star/uno/Sequence.hxx>
26 : :
27 : : #include <rtl/logfile.hxx>
28 : : #include "itemholder1.hxx"
29 : :
30 : : using namespace ::utl ;
31 : : using namespace ::rtl ;
32 : : using namespace ::osl ;
33 : : using namespace ::com::sun::star::uno ;
34 : :
35 : : #define DEFAULT_SHOWINTRO sal_True
36 : :
37 : : #define ROOTNODE_START OUString(RTL_CONSTASCII_USTRINGPARAM("Setup/Office" ))
38 : : #define PROPERTYNAME_SHOWINTRO OUString(RTL_CONSTASCII_USTRINGPARAM("ooSetupShowIntro" ))
39 : : #define PROPERTYNAME_CONNECTIONURL OUString(RTL_CONSTASCII_USTRINGPARAM("ooSetupConnectionURL" ))
40 : :
41 : : #define PROPERTYHANDLE_SHOWINTRO 0
42 : : #define PROPERTYHANDLE_CONNECTIONURL 1
43 : :
44 : : #define PROPERTYCOUNT 2
45 : :
46 : : class SvtStartOptions_Impl : public ConfigItem
47 : : {
48 : : public:
49 : :
50 : : SvtStartOptions_Impl();
51 : : ~SvtStartOptions_Impl();
52 : :
53 : : /*-****************************************************************************************************//**
54 : : @short called for notify of configmanager
55 : : @descr These method is called from the ConfigManager before application ends or from the
56 : : PropertyChangeListener if the sub tree broadcasts changes. You must update your
57 : : internal values.
58 : :
59 : : @ATTENTION We don't implement these method - because we support readonly values at runtime only!
60 : :
61 : : @seealso baseclass ConfigItem
62 : :
63 : : @param "seqPropertyNames" is the list of properties which should be updated.
64 : : @return -
65 : :
66 : : @onerror -
67 : : *//*-*****************************************************************************************************/
68 : :
69 : : virtual void Notify( const Sequence< OUString >& seqPropertyNames );
70 : :
71 : : /*-****************************************************************************************************//**
72 : : @short write changes to configuration
73 : : @descr These method writes the changed values into the sub tree
74 : : and should always called in our destructor to guarantee consistency of config data.
75 : :
76 : : @ATTENTION We don't implement these method - because we support readonly values at runtime only!
77 : :
78 : : @seealso baseclass ConfigItem
79 : :
80 : : @param -
81 : : @return -
82 : :
83 : : @onerror -
84 : : *//*-*****************************************************************************************************/
85 : :
86 : : virtual void Commit();
87 : :
88 : : /*-****************************************************************************************************//**
89 : : @short access method to get internal values
90 : : @descr These method give us a chance to regulate acces to ouer internal values.
91 : : It's not used in the moment - but it's possible for the feature!
92 : :
93 : : @seealso -
94 : :
95 : : @param -
96 : : @return -
97 : :
98 : : @onerror -
99 : : *//*-*****************************************************************************************************/
100 : :
101 : : OUString GetConnectionURL( ) const ;
102 : :
103 : : private:
104 : :
105 : : /*-****************************************************************************************************//**
106 : : @short return list of fix key names of ouer configuration management which represent oue module tree
107 : : @descr These methods return a static const list of key names. We need it to get needed values from our
108 : : configuration management. We return well known key names only - because the "UserData" node
109 : : is handled in a special way!
110 : :
111 : : @seealso -
112 : :
113 : : @param -
114 : : @return A list of needed configuration keys is returned.
115 : :
116 : : @onerror -
117 : : *//*-*****************************************************************************************************/
118 : :
119 : : static Sequence< OUString > impl_GetPropertyNames();
120 : :
121 : : private:
122 : :
123 : : sal_Bool m_bShowIntro ; /// cache "ShowIntro" of Start section
124 : : OUString m_sConnectionURL ; /// cache "Connection" of Start section
125 : : };
126 : :
127 : : //*****************************************************************************************************************
128 : : // constructor
129 : : //*****************************************************************************************************************
130 : 158 : SvtStartOptions_Impl::SvtStartOptions_Impl()
131 : : // Init baseclasses first
132 : : : ConfigItem ( ROOTNODE_START )
133 : : // Init member then.
134 [ + - ]: 158 : , m_bShowIntro ( DEFAULT_SHOWINTRO )
135 : : {
136 : : // Use our static list of configuration keys to get his values.
137 [ + - ]: 158 : Sequence< OUString > seqNames = impl_GetPropertyNames();
138 [ + - ]: 158 : Sequence< Any > seqValues = GetProperties( seqNames ) ;
139 : :
140 : : // Safe impossible cases.
141 : : // We need values from ALL configuration keys.
142 : : // Follow assignment use order of values in relation to our list of key names!
143 : : DBG_ASSERT( !(seqNames.getLength()!=seqValues.getLength()), "SvtStartOptions_Impl::SvtStartOptions_Impl()\nI miss some values of configuration keys!\n" );
144 : :
145 : : // Copy values from list in right order to ouer internal member.
146 : 158 : sal_Int32 nPropertyCount = seqValues.getLength() ;
147 : 158 : sal_Int32 nProperty = 0 ;
148 [ + + ]: 474 : for( nProperty=0; nProperty<nPropertyCount; ++nProperty )
149 : : {
150 : : // Safe impossible cases.
151 : : // Check any for valid value.
152 : : DBG_ASSERT( !(seqValues[nProperty].hasValue()==sal_False), "SvtStartOptions_Impl::SvtStartOptions_Impl()\nInvalid property value for property detected!\n" );
153 [ + + - ]: 316 : switch( nProperty )
154 : : {
155 : : case PROPERTYHANDLE_SHOWINTRO : {
156 : : DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtStartOptions_Impl::SvtStartOptions_Impl()\nWho has changed the value type of \"Office.Common\\Start\\ShowIntro\"?" );
157 [ + - ]: 158 : seqValues[nProperty] >>= m_bShowIntro;
158 : : }
159 : 158 : break;
160 : :
161 : : case PROPERTYHANDLE_CONNECTIONURL : {
162 : : DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_STRING), "SvtStartOptions_Impl::SvtStartOptions_Impl()\nWho has changed the value type of \"Office.Common\\Start\\Connection\"?" );
163 [ + - ]: 158 : seqValues[nProperty] >>= m_sConnectionURL;
164 : : }
165 : 158 : break;
166 : : }
167 [ + - ][ + - ]: 158 : }
168 : :
169 : : // Don't enable notification mechanism of ouer baseclass!
170 : : // We support readonly variables in the moment.
171 : 158 : }
172 : :
173 : : //*****************************************************************************************************************
174 : : // destructor
175 : : //*****************************************************************************************************************
176 : 158 : SvtStartOptions_Impl::~SvtStartOptions_Impl()
177 : : {
178 : : // We must save our current values .. if user forget it!
179 [ + - ][ - + ]: 158 : if( IsModified() == sal_True )
180 : : {
181 [ # # ]: 0 : Commit();
182 : : }
183 [ - + ]: 316 : }
184 : :
185 : : //*****************************************************************************************************************
186 : : // public method
187 : : //*****************************************************************************************************************
188 : 0 : void SvtStartOptions_Impl::Notify( const Sequence< OUString >& seqPropertyNames )
189 : : {
190 : : // Use given list of updated properties to get his values from configuration directly!
191 [ # # ]: 0 : Sequence< Any > seqValues = GetProperties( seqPropertyNames );
192 : : // Safe impossible cases.
193 : : // We need values from ALL notified configuration keys.
194 : : DBG_ASSERT( !(seqPropertyNames.getLength()!=seqValues.getLength()), "SvtStartOptions_Impl::Notify()\nI miss some values of configuration keys!\n" );
195 : : // Step over list of property names and get right value from coreesponding value list to set it on internal members!
196 : 0 : sal_Int32 nCount = seqPropertyNames.getLength();
197 [ # # ]: 0 : for( sal_Int32 nProperty=0; nProperty<nCount; ++nProperty )
198 : : {
199 [ # # ][ # # ]: 0 : if( seqPropertyNames[nProperty] == PROPERTYNAME_SHOWINTRO )
200 : : {
201 : : DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_BOOLEAN), "SvtStartOptions_Impl::Notify()\nWho has changed the value type of \"Office.Common\\Start\\ShowIntro\"?" );
202 [ # # ]: 0 : seqValues[nProperty] >>= m_bShowIntro;
203 : : }
204 : : else
205 [ # # ][ # # ]: 0 : if( seqPropertyNames[nProperty] == PROPERTYNAME_CONNECTIONURL )
206 : : {
207 : : DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_STRING), "SvtStartOptions_Impl::Notify()\nWho has changed the value type of \"Office.Common\\Start\\Connection\"?" );
208 [ # # ]: 0 : seqValues[nProperty] >>= m_sConnectionURL;
209 : : }
210 : : #if OSL_DEBUG_LEVEL > 1
211 : : else DBG_ASSERT( sal_False, "SvtStartOptions_Impl::Notify()\nUnkown property detected ... I can't handle these!\n" );
212 : : #endif
213 [ # # ]: 0 : }
214 : 0 : }
215 : :
216 : : //*****************************************************************************************************************
217 : : // public method
218 : : //*****************************************************************************************************************
219 : 0 : void SvtStartOptions_Impl::Commit()
220 : : {
221 : : // Get names of supported properties, create a list for values and copy current values to it.
222 [ # # ]: 0 : Sequence< OUString > seqNames = impl_GetPropertyNames();
223 : 0 : sal_Int32 nCount = seqNames.getLength();
224 [ # # ]: 0 : Sequence< Any > seqValues ( nCount );
225 [ # # ]: 0 : for( sal_Int32 nProperty=0; nProperty<nCount; ++nProperty )
226 : : {
227 [ # # # ]: 0 : switch( nProperty )
228 : : {
229 : : case PROPERTYHANDLE_SHOWINTRO : {
230 [ # # ][ # # ]: 0 : seqValues[nProperty] <<= m_bShowIntro;
231 : : }
232 : 0 : break;
233 : : case PROPERTYHANDLE_CONNECTIONURL : {
234 [ # # ][ # # ]: 0 : seqValues[nProperty] <<= m_sConnectionURL;
235 : : }
236 : 0 : break;
237 : : }
238 : : }
239 : : // Set properties in configuration.
240 [ # # ][ # # ]: 0 : PutProperties( seqNames, seqValues );
[ # # ]
241 : 0 : }
242 : :
243 : : //*****************************************************************************************************************
244 : : // public method
245 : : //*****************************************************************************************************************
246 : 158 : OUString SvtStartOptions_Impl::GetConnectionURL() const
247 : : {
248 : 158 : return m_sConnectionURL;
249 : : }
250 : :
251 : : //*****************************************************************************************************************
252 : : // private method
253 : : //*****************************************************************************************************************
254 : 158 : Sequence< OUString > SvtStartOptions_Impl::impl_GetPropertyNames()
255 : : {
256 : : // Build list of configuration key names.
257 : : const OUString pProperties[] =
258 : : {
259 : : PROPERTYNAME_SHOWINTRO ,
260 : : PROPERTYNAME_CONNECTIONURL ,
261 [ + - ][ + - ]: 474 : };
[ # # # # ]
262 : : // Initialize return sequence with these list ...
263 [ + - ]: 158 : const Sequence< OUString > seqPropertyNames( pProperties, PROPERTYCOUNT );
264 : : // ... and return it.
265 [ + + ][ # # ]: 474 : return seqPropertyNames;
266 : : }
267 : :
268 : : //*****************************************************************************************************************
269 : : // initialize static member
270 : : // DON'T DO IT IN YOUR HEADER!
271 : : // see definition for further informations
272 : : //*****************************************************************************************************************
273 : : SvtStartOptions_Impl* SvtStartOptions::m_pDataContainer = NULL ;
274 : : sal_Int32 SvtStartOptions::m_nRefCount = 0 ;
275 : :
276 : : //*****************************************************************************************************************
277 : : // constructor
278 : : //*****************************************************************************************************************
279 : 316 : SvtStartOptions::SvtStartOptions()
280 : : {
281 : : // Global access, must be guarded (multithreading!).
282 [ + - ][ + - ]: 316 : MutexGuard aGuard( GetOwnStaticMutex() );
283 : : // Increase ouer refcount ...
284 : 316 : ++m_nRefCount;
285 : : // ... and initialize ouer data container only if it not already!
286 [ + + ]: 316 : if( m_pDataContainer == NULL )
287 : : {
288 : : RTL_LOGFILE_CONTEXT(aLog, "unotools ( ??? ) ::SvtStartOptions_Impl::ctor()");
289 [ + - ][ + - ]: 158 : m_pDataContainer = new SvtStartOptions_Impl();
290 : :
291 [ + - ]: 158 : ItemHolder1::holdConfigItem(E_STARTOPTIONS);
292 [ + - ]: 316 : }
293 : 316 : }
294 : :
295 : : //*****************************************************************************************************************
296 : : // destructor
297 : : //*****************************************************************************************************************
298 : 316 : SvtStartOptions::~SvtStartOptions()
299 : : {
300 : : // Global access, must be guarded (multithreading!)
301 [ + - ][ + - ]: 316 : MutexGuard aGuard( GetOwnStaticMutex() );
302 : : // Decrease ouer refcount.
303 : 316 : --m_nRefCount;
304 : : // If last instance was deleted ...
305 : : // we must destroy ouer static data container!
306 [ + + ]: 316 : if( m_nRefCount <= 0 )
307 : : {
308 [ + - ][ + - ]: 158 : delete m_pDataContainer;
309 : 158 : m_pDataContainer = NULL;
310 [ + - ]: 316 : }
311 [ - + ]: 474 : }
312 : :
313 : : //*****************************************************************************************************************
314 : : // public method
315 : : //*****************************************************************************************************************
316 : 158 : OUString SvtStartOptions::GetConnectionURL() const
317 : : {
318 [ + - ][ + - ]: 158 : MutexGuard aGuard( GetOwnStaticMutex() );
319 [ + - ]: 158 : return m_pDataContainer->GetConnectionURL();
320 : : }
321 : :
322 : : namespace
323 : : {
324 : : class theStartOptionsMutex : public rtl::Static<osl::Mutex, theStartOptionsMutex>{};
325 : : }
326 : :
327 : : //*****************************************************************************************************************
328 : : // private method
329 : : //*****************************************************************************************************************
330 : 790 : Mutex& SvtStartOptions::GetOwnStaticMutex()
331 : : {
332 : 790 : return theStartOptionsMutex::get();
333 : : }
334 : :
335 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|