Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "uiconfiguration/globalsettings.hxx"
30 : : #include <threadhelp/resetableguard.hxx>
31 : : #include "services.h"
32 : :
33 : : #include <com/sun/star/beans/PropertyValue.hpp>
34 : : #include <com/sun/star/beans/XPropertySet.hpp>
35 : : #include <com/sun/star/container/XNameAccess.hpp>
36 : : #include <com/sun/star/container/XNameContainer.hpp>
37 : : #include <com/sun/star/container/XContainer.hpp>
38 : : #include <com/sun/star/lang/XComponent.hpp>
39 : : #include <com/sun/star/lang/XEventListener.hpp>
40 : :
41 : : #include <rtl/ustrbuf.hxx>
42 : : #include <rtl/instance.hxx>
43 : : #include <cppuhelper/weak.hxx>
44 : :
45 : : //_________________________________________________________________________________________________________________
46 : : // Defines
47 : : //_________________________________________________________________________________________________________________
48 : :
49 : : using namespace ::com::sun::star;
50 : :
51 : : using ::rtl::OUString;
52 : :
53 : : //_________________________________________________________________________________________________________________
54 : : // Namespace
55 : : //_________________________________________________________________________________________________________________
56 : :
57 : : static const char GLOBALSETTINGS_ROOT_ACCESS[] = "/org.openoffice.Office.UI.GlobalSettings/Toolbars";
58 : :
59 : : static const char GLOBALSETTINGS_NODEREF_STATES[] = "States";
60 : : static const char GLOBALSETTINGS_PROPERTY_LOCKED[] = "Locked";
61 : : static const char GLOBALSETTINGS_PROPERTY_DOCKED[] = "Docked";
62 : : static const char GLOBALSETTINGS_PROPERTY_STATESENABLED[] = "StatesEnabled";
63 : :
64 : : namespace framework
65 : : {
66 : :
67 : : //*****************************************************************************************************************
68 : : // Configuration access class for WindowState supplier implementation
69 : : //*****************************************************************************************************************
70 : :
71 : : class GlobalSettings_Access : public ::com::sun::star::lang::XComponent ,
72 : : public ::com::sun::star::lang::XEventListener ,
73 : : private ThreadHelpBase , // Struct for right initalization of mutex member! Must be first of baseclasses.
74 : : public ::cppu::OWeakObject
75 : : {
76 : : public:
77 : : GlobalSettings_Access( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager );
78 : : virtual ~GlobalSettings_Access();
79 : :
80 : : // XInterface, XTypeProvider, XServiceInfo
81 : : FWK_DECLARE_XINTERFACE
82 : :
83 : : // XComponent
84 : : virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException);
85 : : virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
86 : : virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
87 : :
88 : : // XEventListener
89 : : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
90 : :
91 : : // settings access
92 : : sal_Bool HasStatesInfo( GlobalSettings::UIElementType eElementType );
93 : : sal_Bool GetStateInfo( GlobalSettings::UIElementType eElementType, GlobalSettings::StateInfo eStateInfo, ::com::sun::star::uno::Any& aValue );
94 : :
95 : : private:
96 : : sal_Bool impl_initConfigAccess();
97 : :
98 : : sal_Bool m_bDisposed : 1,
99 : : m_bConfigRead : 1;
100 : : rtl::OUString m_aConfigSettingsAccess;
101 : : rtl::OUString m_aNodeRefStates;
102 : : rtl::OUString m_aPropStatesEnabled;
103 : : rtl::OUString m_aPropLocked;
104 : : rtl::OUString m_aPropDocked;
105 : : ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > m_xConfigAccess;
106 : : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager;
107 : : };
108 : :
109 : :
110 : : //*****************************************************************************************************************
111 : : // XInterface
112 : : //*****************************************************************************************************************
113 [ - + ][ # # ]: 904 : DEFINE_XINTERFACE_2 ( GlobalSettings_Access ,
114 : : OWeakObject ,
115 : : DIRECT_INTERFACE ( css::lang::XComponent ),
116 : : DIRECT_INTERFACE ( css::lang::XEventListener )
117 : : )
118 : :
119 : 113 : GlobalSettings_Access::GlobalSettings_Access( const css::uno::Reference< css::lang::XMultiServiceFactory >& rServiceManager ) :
120 : : ThreadHelpBase(),
121 : : m_bDisposed( sal_False ),
122 : : m_bConfigRead( sal_False ),
123 : : m_aConfigSettingsAccess( RTL_CONSTASCII_USTRINGPARAM( GLOBALSETTINGS_ROOT_ACCESS )),
124 : : m_aNodeRefStates( RTL_CONSTASCII_USTRINGPARAM( GLOBALSETTINGS_NODEREF_STATES )),
125 : : m_aPropStatesEnabled( RTL_CONSTASCII_USTRINGPARAM( GLOBALSETTINGS_PROPERTY_STATESENABLED )),
126 : : m_aPropLocked( RTL_CONSTASCII_USTRINGPARAM( GLOBALSETTINGS_PROPERTY_LOCKED )),
127 : : m_aPropDocked( RTL_CONSTASCII_USTRINGPARAM( GLOBALSETTINGS_PROPERTY_DOCKED )),
128 [ + - ][ + - ]: 113 : m_xServiceManager( rServiceManager )
[ + - ][ + - ]
[ + - ][ + - ]
129 : : {
130 : 113 : }
131 : :
132 [ + - ][ + - ]: 113 : GlobalSettings_Access::~GlobalSettings_Access()
133 : : {
134 [ - + ]: 226 : }
135 : :
136 : : // XComponent
137 : 0 : void SAL_CALL GlobalSettings_Access::dispose()
138 : : throw ( css::uno::RuntimeException )
139 : : {
140 : : // SAFE
141 [ # # ]: 0 : ResetableGuard aLock( m_aLock );
142 : :
143 : 0 : m_xConfigAccess.clear();
144 [ # # ]: 0 : m_bDisposed = sal_True;
145 : 0 : }
146 : :
147 : 0 : void SAL_CALL GlobalSettings_Access::addEventListener( const css::uno::Reference< css::lang::XEventListener >& )
148 : : throw (css::uno::RuntimeException)
149 : : {
150 : 0 : }
151 : :
152 : 0 : void SAL_CALL GlobalSettings_Access::removeEventListener( const css::uno::Reference< css::lang::XEventListener >& )
153 : : throw (css::uno::RuntimeException)
154 : : {
155 : 0 : }
156 : :
157 : : // XEventListener
158 : 113 : void SAL_CALL GlobalSettings_Access::disposing( const css::lang::EventObject& )
159 : : throw (css::uno::RuntimeException)
160 : : {
161 : : // SAFE
162 [ + - ]: 113 : ResetableGuard aLock( m_aLock );
163 [ + - ]: 113 : m_xConfigAccess.clear();
164 : 113 : }
165 : :
166 : : // settings access
167 : 3472 : sal_Bool GlobalSettings_Access::HasStatesInfo( GlobalSettings::UIElementType eElementType )
168 : : {
169 [ + - ]: 3472 : ResetableGuard aLock( m_aLock );
170 [ - + ]: 3472 : if ( eElementType == GlobalSettings::UIELEMENT_TYPE_DOCKWINDOW )
171 : 0 : return sal_False;
172 [ - + ]: 3472 : else if ( eElementType == GlobalSettings::UIELEMENT_TYPE_STATUSBAR )
173 : 0 : return sal_False;
174 : :
175 [ - + ]: 3472 : if ( m_bDisposed )
176 : 0 : return sal_False;
177 : :
178 [ + + ]: 3472 : if ( !m_bConfigRead )
179 : : {
180 : 113 : m_bConfigRead = sal_True;
181 [ + - ]: 113 : impl_initConfigAccess();
182 : : }
183 : :
184 [ + - ]: 3472 : if ( m_xConfigAccess.is() )
185 : : {
186 : : try
187 : : {
188 : 3472 : css::uno::Any a;
189 : 3472 : sal_Bool bValue = sal_Bool();
190 [ + - ][ + - ]: 3472 : a = m_xConfigAccess->getByName( m_aPropStatesEnabled );
191 [ - + ]: 3472 : if ( a >>= bValue )
192 [ + - ]: 3472 : return bValue;
[ # # # ]
193 : : }
194 [ # # ]: 0 : catch ( const css::container::NoSuchElementException& )
195 : : {
196 : : }
197 [ # # ]: 0 : catch ( const css::uno::Exception& )
198 : : {
199 : : }
200 : : }
201 : :
202 [ + - ]: 3472 : return sal_False;
203 : : }
204 : :
205 : 0 : sal_Bool GlobalSettings_Access::GetStateInfo( GlobalSettings::UIElementType eElementType, GlobalSettings::StateInfo eStateInfo, ::com::sun::star::uno::Any& aValue )
206 : : {
207 [ # # ]: 0 : ResetableGuard aLock( m_aLock );
208 [ # # ]: 0 : if ( eElementType == GlobalSettings::UIELEMENT_TYPE_DOCKWINDOW )
209 : 0 : return sal_False;
210 [ # # ]: 0 : else if ( eElementType == GlobalSettings::UIELEMENT_TYPE_STATUSBAR )
211 : 0 : return sal_False;
212 : :
213 [ # # ]: 0 : if ( m_bDisposed )
214 : 0 : return sal_False;
215 : :
216 [ # # ]: 0 : if ( !m_bConfigRead )
217 : : {
218 : 0 : m_bConfigRead = sal_True;
219 [ # # ]: 0 : impl_initConfigAccess();
220 : : }
221 : :
222 [ # # ]: 0 : if ( m_xConfigAccess.is() )
223 : : {
224 : : try
225 : : {
226 : 0 : css::uno::Any a;
227 [ # # ][ # # ]: 0 : a = m_xConfigAccess->getByName( m_aNodeRefStates );
228 : 0 : css::uno::Reference< css::container::XNameAccess > xNameAccess;
229 [ # # ][ # # ]: 0 : if ( a >>= xNameAccess )
230 : : {
231 [ # # ]: 0 : if ( eStateInfo == GlobalSettings::STATEINFO_LOCKED )
232 [ # # ][ # # ]: 0 : a = xNameAccess->getByName( m_aPropLocked );
233 [ # # ]: 0 : else if ( eStateInfo == GlobalSettings::STATEINFO_DOCKED )
234 [ # # ][ # # ]: 0 : a = xNameAccess->getByName( m_aPropDocked );
235 : :
236 : 0 : aValue = a;
237 : 0 : return sal_True;
238 [ # # ][ # # ]: 0 : }
[ # # # ]
239 : : }
240 [ # # ]: 0 : catch ( const css::container::NoSuchElementException& )
241 : : {
242 : : }
243 [ # # ]: 0 : catch ( const css::uno::Exception& )
244 : : {
245 : : }
246 : : }
247 : :
248 [ # # ]: 0 : return sal_False;
249 : : }
250 : :
251 : 113 : sal_Bool GlobalSettings_Access::impl_initConfigAccess()
252 : : {
253 [ + - ]: 113 : css::uno::Sequence< css::uno::Any > aArgs( 2 );
254 : 113 : css::beans::PropertyValue aPropValue;
255 : :
256 : : try
257 : : {
258 : 113 : css::uno::Reference< css::lang::XMultiServiceFactory > xConfigProvider;
259 [ + - ]: 113 : if ( m_xServiceManager.is() )
260 : : xConfigProvider = css::uno::Reference< css::lang::XMultiServiceFactory >(
261 [ + - ]: 113 : m_xServiceManager->createInstance( SERVICENAME_CFGPROVIDER ),
262 [ + - ][ + - ]: 113 : css::uno::UNO_QUERY );
[ + - ][ + - ]
263 : :
264 [ + - ]: 113 : if ( xConfigProvider.is() )
265 : : {
266 [ + - ]: 113 : aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ));
267 [ + - ][ + - ]: 113 : aPropValue.Value = css::uno::makeAny( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( GLOBALSETTINGS_ROOT_ACCESS )));
268 [ + - ][ + - ]: 113 : aArgs[0] = css::uno::makeAny( aPropValue );
269 [ + - ]: 113 : aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "lazywrite" ));
270 [ + - ]: 113 : aPropValue.Value = css::uno::makeAny( sal_True );
271 [ + - ][ + - ]: 113 : aArgs[1] = css::uno::makeAny( aPropValue );
272 : :
273 : : m_xConfigAccess = css::uno::Reference< css::container::XNameAccess >(
274 [ + - ]: 113 : xConfigProvider->createInstanceWithArguments(
275 : 113 : SERVICENAME_CFGREADACCESS, aArgs ),
276 [ + - ][ + - ]: 113 : css::uno::UNO_QUERY );
[ + - ][ + - ]
277 : :
278 [ + - ]: 113 : css::uno::Reference< css::lang::XComponent > xComponent( xConfigProvider, css::uno::UNO_QUERY );
279 [ + - ]: 113 : if ( xComponent.is() )
280 [ + - ]: 113 : xComponent->addEventListener(
281 : : css::uno::Reference< css::lang::XEventListener >(
282 : : static_cast< cppu::OWeakObject* >( this ),
283 [ + - ][ + - ]: 113 : css::uno::UNO_QUERY ));
284 : : }
285 : :
286 [ # # # ]: 113 : return m_xConfigAccess.is();
287 : : }
288 [ # # ]: 0 : catch ( const css::lang::WrappedTargetException& )
289 : : {
290 : : }
291 [ # # ]: 0 : catch ( const css::uno::Exception& )
292 : : {
293 : : }
294 : :
295 [ + - ]: 113 : return sal_False;
296 : : }
297 : :
298 : : //*****************************************************************************************************************
299 : : // global class
300 : : //*****************************************************************************************************************
301 : :
302 : : struct mutexGlobalSettings : public rtl::Static< osl::Mutex, mutexGlobalSettings > {};
303 : : static GlobalSettings_Access* pStaticSettings = 0;
304 : :
305 : 3472 : static GlobalSettings_Access* GetGlobalSettings( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rSrvMgr )
306 : : {
307 [ + - ][ + - ]: 3472 : osl::MutexGuard aGuard(mutexGlobalSettings::get());
308 [ + + ]: 3472 : if ( !pStaticSettings )
309 [ + - ]: 113 : pStaticSettings = new GlobalSettings_Access( rSrvMgr );
310 [ + - ]: 3472 : return pStaticSettings;
311 : : }
312 : :
313 : 3472 : GlobalSettings::GlobalSettings( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rSrvMgr ) :
314 : 3472 : m_xSrvMgr( rSrvMgr )
315 : : {
316 : 3472 : }
317 : :
318 : 3290 : GlobalSettings::~GlobalSettings()
319 : : {
320 : 3290 : }
321 : :
322 : : // settings access
323 : 3472 : sal_Bool GlobalSettings::HasStatesInfo( UIElementType eElementType )
324 : : {
325 : 3472 : GlobalSettings_Access* pSettings( GetGlobalSettings( m_xSrvMgr ));
326 : :
327 [ + - ]: 3472 : if ( pSettings )
328 : 3472 : return pSettings->HasStatesInfo( eElementType );
329 : : else
330 : 3472 : return sal_False;
331 : : }
332 : :
333 : 0 : sal_Bool GlobalSettings::GetStateInfo( UIElementType eElementType, StateInfo eStateInfo, ::com::sun::star::uno::Any& aValue )
334 : : {
335 : 0 : GlobalSettings_Access* pSettings( GetGlobalSettings( m_xSrvMgr ));
336 : :
337 [ # # ]: 0 : if ( pSettings )
338 : 0 : return pSettings->GetStateInfo( eElementType, eStateInfo, aValue );
339 : : else
340 : 0 : return sal_False;
341 : : }
342 : :
343 : : } // namespace framework
344 : :
345 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|