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 : :
21 : : #include <unotools/workingsetoptions.hxx>
22 : : #include <unotools/configmgr.hxx>
23 : : #include <unotools/configitem.hxx>
24 : : #include <tools/debug.hxx>
25 : : #include <com/sun/star/uno/Any.hxx>
26 : : #include <com/sun/star/uno/Sequence.hxx>
27 : :
28 : : #include <itemholder1.hxx>
29 : :
30 : : //_________________________________________________________________________________________________________________
31 : : // namespaces
32 : : //_________________________________________________________________________________________________________________
33 : :
34 : : using namespace ::utl ;
35 : : using namespace ::rtl ;
36 : : using namespace ::osl ;
37 : : using namespace ::com::sun::star::uno ;
38 : :
39 : : #define ROOTNODE_WORKINGSET OUString(RTL_CONSTASCII_USTRINGPARAM("Office.Common/WorkingSet"))
40 : : #define DEFAULT_WINDOWLIST Sequence< OUString >()
41 : :
42 : : #define PROPERTYNAME_WINDOWLIST OUString(RTL_CONSTASCII_USTRINGPARAM("WindowList" ))
43 : :
44 : : #define PROPERTYHANDLE_WINDOWLIST 0
45 : :
46 : : #define PROPERTYCOUNT 1
47 : :
48 : : //_________________________________________________________________________________________________________________
49 : : // private declarations!
50 : : //_________________________________________________________________________________________________________________
51 : :
52 : : class SvtWorkingSetOptions_Impl : public ConfigItem
53 : : {
54 : : //-------------------------------------------------------------------------------------------------------------
55 : : // public methods
56 : : //-------------------------------------------------------------------------------------------------------------
57 : :
58 : : public:
59 : :
60 : : //---------------------------------------------------------------------------------------------------------
61 : : // constructor / destructor
62 : : //---------------------------------------------------------------------------------------------------------
63 : :
64 : : SvtWorkingSetOptions_Impl();
65 : : ~SvtWorkingSetOptions_Impl();
66 : :
67 : : //---------------------------------------------------------------------------------------------------------
68 : : // overloaded methods of baseclass
69 : : //---------------------------------------------------------------------------------------------------------
70 : :
71 : : /*-****************************************************************************************************//**
72 : : @short called for notify of configmanager
73 : : @descr These method is called from the ConfigManager before application ends or from the
74 : : PropertyChangeListener if the sub tree broadcasts changes. You must update your
75 : : internal values.
76 : :
77 : : @seealso baseclass ConfigItem
78 : :
79 : : @param "seqPropertyNames" is the list of properties which should be updated.
80 : : @return -
81 : :
82 : : @onerror -
83 : : *//*-*****************************************************************************************************/
84 : :
85 : : virtual void Notify( const Sequence< OUString >& seqPropertyNames );
86 : :
87 : : /*-****************************************************************************************************//**
88 : : @short write changes to configuration
89 : : @descr These method writes the changed values into the sub tree
90 : : and should always called in our destructor to guarantee consistency of config data.
91 : :
92 : : @seealso baseclass ConfigItem
93 : :
94 : : @param -
95 : : @return -
96 : :
97 : : @onerror -
98 : : *//*-*****************************************************************************************************/
99 : :
100 : : virtual void Commit();
101 : :
102 : : //-------------------------------------------------------------------------------------------------------------
103 : : // private methods
104 : : //-------------------------------------------------------------------------------------------------------------
105 : :
106 : : private:
107 : :
108 : : /*-****************************************************************************************************//**
109 : : @short return list of key names of ouer configuration management which represent oue module tree
110 : : @descr These methods return a static const list of key names. We need it to get needed values from our
111 : : configuration management.
112 : :
113 : : @seealso -
114 : :
115 : : @param -
116 : : @return A list of needed configuration keys is returned.
117 : :
118 : : @onerror -
119 : : *//*-*****************************************************************************************************/
120 : :
121 : : static Sequence< OUString > GetPropertyNames();
122 : :
123 : : //-------------------------------------------------------------------------------------------------------------
124 : : // private member
125 : : //-------------------------------------------------------------------------------------------------------------
126 : :
127 : : private:
128 : :
129 : : Sequence< OUString > m_seqWindowList ;
130 : : };
131 : :
132 : : //*****************************************************************************************************************
133 : : // constructor
134 : : //*****************************************************************************************************************
135 : 0 : SvtWorkingSetOptions_Impl::SvtWorkingSetOptions_Impl()
136 : : // Init baseclasses first
137 : : : ConfigItem ( ROOTNODE_WORKINGSET )
138 : : // Init member then.
139 [ # # ][ # # ]: 0 : , m_seqWindowList ( DEFAULT_WINDOWLIST )
140 : : {
141 : : // Use our static list of configuration keys to get his values.
142 [ # # ]: 0 : Sequence< OUString > seqNames = GetPropertyNames ( );
143 [ # # ]: 0 : Sequence< Any > seqValues = GetProperties ( seqNames );
144 : :
145 : : // Safe impossible cases.
146 : : // We need values from ALL configuration keys.
147 : : // Follow assignment use order of values in relation to our list of key names!
148 : : DBG_ASSERT( !(seqNames.getLength()!=seqValues.getLength()), "SvtWorkingSetOptions_Impl::SvtWorkingSetOptions_Impl()\nI miss some values of configuration keys!\n" );
149 : :
150 : : // Copy values from list in right order to ouer internal member.
151 : 0 : sal_Int32 nPropertyCount = seqValues.getLength();
152 [ # # ]: 0 : for( sal_Int32 nProperty=0; nProperty<nPropertyCount; ++nProperty )
153 : : {
154 : : // Safe impossible cases.
155 : : // Check any for valid value.
156 : : DBG_ASSERT( !(seqValues[nProperty].hasValue()==sal_False), "SvtWorkingSetOptions_Impl::SvtWorkingSetOptions_Impl()\nInvalid property value detected!\n" );
157 [ # # ]: 0 : switch( nProperty )
158 : : {
159 : : case PROPERTYHANDLE_WINDOWLIST : {
160 : : DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_SEQUENCE), "SvtWorkingSetOptions_Impl::SvtWorkingSetOptions_Impl()\nWho has changed the value type of \"Office.Common\\WorkingSet\\WindowList\"?" );
161 [ # # ][ # # ]: 0 : seqValues[nProperty] >>= m_seqWindowList;
162 : : }
163 : 0 : break;
164 : : }
165 : : }
166 : :
167 : : // Enable notification mechanism of ouer baseclass.
168 : : // We need it to get information about changes outside these class on ouer used configuration keys!
169 [ # # ][ # # ]: 0 : EnableNotification( seqNames );
[ # # ]
170 : 0 : }
171 : :
172 : : //*****************************************************************************************************************
173 : : // destructor
174 : : //*****************************************************************************************************************
175 [ # # ]: 0 : SvtWorkingSetOptions_Impl::~SvtWorkingSetOptions_Impl()
176 : : {
177 : : // We must save our current values .. if user forget it!
178 [ # # ][ # # ]: 0 : if( IsModified() == sal_True )
179 : : {
180 [ # # ]: 0 : Commit();
181 : : }
182 [ # # ]: 0 : }
183 : :
184 : : //*****************************************************************************************************************
185 : : // public method
186 : : //*****************************************************************************************************************
187 : 0 : void SvtWorkingSetOptions_Impl::Notify( const Sequence< OUString >& seqPropertyNames )
188 : : {
189 : : // Use given list of updated properties to get his values from configuration directly!
190 [ # # ]: 0 : Sequence< Any > seqValues = GetProperties( seqPropertyNames );
191 : : // Safe impossible cases.
192 : : // We need values from ALL notified configuration keys.
193 : : DBG_ASSERT( !(seqPropertyNames.getLength()!=seqValues.getLength()), "SvtWorkingSetOptions_Impl::Notify()\nI miss some values of configuration keys!\n" );
194 : : // Step over list of property names and get right value from coreesponding value list to set it on internal members!
195 : 0 : sal_Int32 nCount = seqPropertyNames.getLength();
196 [ # # ]: 0 : for( sal_Int32 nProperty=0; nProperty<nCount; ++nProperty )
197 : : {
198 [ # # ][ # # ]: 0 : if( seqPropertyNames[nProperty] == PROPERTYNAME_WINDOWLIST )
199 : : {
200 : : DBG_ASSERT(!(seqValues[nProperty].getValueTypeClass()!=TypeClass_SEQUENCE), "SvtWorkingSetOptions_Impl::Notify()\nWho has changed the value type of \"Office.Common\\WorkingSet\\WindowList\"?" );
201 [ # # ][ # # ]: 0 : seqValues[nProperty] >>= m_seqWindowList;
202 : : }
203 : : #if OSL_DEBUG_LEVEL > 1
204 : : else DBG_ASSERT( sal_False, "SvtWorkingSetOptions_Impl::Notify()\nUnkown property detected ... I can't handle these!\n" );
205 : : #endif
206 [ # # ]: 0 : }
207 : 0 : }
208 : :
209 : : //*****************************************************************************************************************
210 : : // public method
211 : : //*****************************************************************************************************************
212 : 0 : void SvtWorkingSetOptions_Impl::Commit()
213 : : {
214 : : // Get names of supported properties, create a list for values and copy current values to it.
215 [ # # ]: 0 : Sequence< OUString > seqNames = GetPropertyNames ();
216 : 0 : sal_Int32 nCount = seqNames.getLength();
217 [ # # ]: 0 : Sequence< Any > seqValues ( nCount );
218 [ # # ]: 0 : for( sal_Int32 nProperty=0; nProperty<nCount; ++nProperty )
219 : : {
220 [ # # ]: 0 : switch( nProperty )
221 : : {
222 : : case PROPERTYHANDLE_WINDOWLIST : {
223 [ # # ][ # # ]: 0 : seqValues[nProperty] <<= m_seqWindowList;
224 : : }
225 : 0 : break;
226 : : }
227 : : }
228 : : // Set properties in configuration.
229 [ # # ][ # # ]: 0 : PutProperties( seqNames, seqValues );
[ # # ]
230 : 0 : }
231 : :
232 : : //*****************************************************************************************************************
233 : : // private method
234 : : //*****************************************************************************************************************
235 : 0 : Sequence< OUString > SvtWorkingSetOptions_Impl::GetPropertyNames()
236 : : {
237 : : // Build list of configuration key names.
238 : : const OUString pProperties[] =
239 : : {
240 : : PROPERTYNAME_WINDOWLIST ,
241 [ # # ]: 0 : };
[ # # # # ]
242 : : // Initialize return sequence with these list ...
243 [ # # ]: 0 : const Sequence< OUString > seqPropertyNames( pProperties, PROPERTYCOUNT );
244 : : // ... and return it.
245 [ # # ][ # # ]: 0 : return seqPropertyNames;
246 : : }
247 : :
248 : : //*****************************************************************************************************************
249 : : // initialize static member
250 : : // DON'T DO IT IN YOUR HEADER!
251 : : // see definition for further informations
252 : : //*****************************************************************************************************************
253 : : SvtWorkingSetOptions_Impl* SvtWorkingSetOptions::m_pDataContainer = NULL ;
254 : : sal_Int32 SvtWorkingSetOptions::m_nRefCount = 0 ;
255 : :
256 : : //*****************************************************************************************************************
257 : : // constructor
258 : : //*****************************************************************************************************************
259 : 0 : SvtWorkingSetOptions::SvtWorkingSetOptions()
260 : : {
261 : : // Global access, must be guarded (multithreading!).
262 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetOwnStaticMutex() );
263 : : // Increase ouer refcount ...
264 : 0 : ++m_nRefCount;
265 : : // ... and initialize ouer data container only if it not already exist!
266 [ # # ]: 0 : if( m_pDataContainer == NULL )
267 : : {
268 [ # # ][ # # ]: 0 : m_pDataContainer = new SvtWorkingSetOptions_Impl;
269 [ # # ]: 0 : ItemHolder1::holdConfigItem(E_WORKINGSETOPTIONS);
270 [ # # ]: 0 : }
271 : 0 : }
272 : :
273 : : //*****************************************************************************************************************
274 : : // destructor
275 : : //*****************************************************************************************************************
276 : 0 : SvtWorkingSetOptions::~SvtWorkingSetOptions()
277 : : {
278 : : // Global access, must be guarded (multithreading!)
279 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetOwnStaticMutex() );
280 : : // Decrease ouer refcount.
281 : 0 : --m_nRefCount;
282 : : // If last instance was deleted ...
283 : : // we must destroy ouer static data container!
284 [ # # ]: 0 : if( m_nRefCount <= 0 )
285 : : {
286 [ # # ][ # # ]: 0 : delete m_pDataContainer;
287 : 0 : m_pDataContainer = NULL;
288 [ # # ]: 0 : }
289 [ # # ]: 0 : }
290 : :
291 : : namespace
292 : : {
293 : : class theWorkingSetOptionsMutex : public rtl::Static<osl::Mutex, theWorkingSetOptionsMutex>{};
294 : : }
295 : :
296 : : //*****************************************************************************************************************
297 : : // private method
298 : : //*****************************************************************************************************************
299 : 0 : Mutex& SvtWorkingSetOptions::GetOwnStaticMutex()
300 : : {
301 : 0 : return theWorkingSetOptionsMutex::get();
302 : : }
303 : :
304 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|