1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_framework.hxx"
26 #include <accelerators/moduleacceleratorconfiguration.hxx>
27
28 //_______________________________________________
29 // own includes
30 #include <threadhelp/readguard.hxx>
31 #include <threadhelp/writeguard.hxx>
32
33 #ifndef __FRAMEWORK_ACCELERATORCONST_H_
34 #include <acceleratorconst.h>
35 #endif
36 #include <services.h>
37
38 //_______________________________________________
39 // interface includes
40 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
42 #include <com/sun/star/embed/ElementModes.hpp>
43
44 //_______________________________________________
45 // other includes
46
47 #ifndef _COMPHELPER_SEQUENCEASHASHMAP_HXX
48 #include <comphelper/sequenceashashmap.hxx>
49 #endif
50 #include <vcl/svapp.hxx>
51
52 #ifndef _COMPHELPER_CONFIGURATIONHELPER_HXX_
53 #include <comphelper/configurationhelper.hxx>
54 #endif
55
56 #ifndef _COM_SUN_STAR_UTIL_XCHANGESNOTIFIER_HPP_
57 #include <com/sun/star/util/XChangesNotifier.hpp>
58 #endif
59
60 #ifndef _RTL_LOGFILE_HXX_
61 #include <rtl/logfile.hxx>
62 #endif
63
64 #ifndef _RTL_LOGFILE_HXX_
65 #include <rtl/logfile.h>
66 #endif
67
68 //_______________________________________________
69 // const
70
71 namespace framework
72 {
73
74 //-----------------------------------------------
75 // XInterface, XTypeProvider, XServiceInfo
DEFINE_XINTERFACE_2(ModuleAcceleratorConfiguration,XCUBasedAcceleratorConfiguration,DIRECT_INTERFACE (css::lang::XServiceInfo),DIRECT_INTERFACE (css::lang::XInitialization))76 DEFINE_XINTERFACE_2(ModuleAcceleratorConfiguration ,
77 XCUBasedAcceleratorConfiguration ,
78 DIRECT_INTERFACE(css::lang::XServiceInfo) ,
79 DIRECT_INTERFACE(css::lang::XInitialization))
80
81 DEFINE_XTYPEPROVIDER_2_WITH_BASECLASS(ModuleAcceleratorConfiguration,
82 XCUBasedAcceleratorConfiguration ,
83 css::lang::XServiceInfo ,
84 css::lang::XInitialization )
85
86 DEFINE_XSERVICEINFO_MULTISERVICE(ModuleAcceleratorConfiguration ,
87 ::cppu::OWeakObject ,
88 SERVICENAME_MODULEACCELERATORCONFIGURATION ,
89 IMPLEMENTATIONNAME_MODULEACCELERATORCONFIGURATION)
90
91 DEFINE_INIT_SERVICE(ModuleAcceleratorConfiguration,
92 {
93 /*Attention
94 I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
95 to create a new instance of this class by our own supported service factory.
96 see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further informations!
97 */
98 }
99 )
100
101 //-----------------------------------------------
102 ModuleAcceleratorConfiguration::ModuleAcceleratorConfiguration(const css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR)
103 : XCUBasedAcceleratorConfiguration(xSMGR)
104 {
105 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleAcceleratorConfiguration::ModuleAcceleratorConfiguration" );
106 }
107
108 //-----------------------------------------------
~ModuleAcceleratorConfiguration()109 ModuleAcceleratorConfiguration::~ModuleAcceleratorConfiguration()
110 {
111 // m_aPresetHandler.removeStorageListener(this);
112 }
113
114 //-----------------------------------------------
initialize(const css::uno::Sequence<css::uno::Any> & lArguments)115 void SAL_CALL ModuleAcceleratorConfiguration::initialize(const css::uno::Sequence< css::uno::Any >& lArguments)
116 throw(css::uno::Exception ,
117 css::uno::RuntimeException)
118 {
119 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleAcceleratorConfiguration::initialize" );
120 // SAFE -> ----------------------------------
121 WriteGuard aWriteLock(m_aLock);
122
123 ::comphelper::SequenceAsHashMap lArgs(lArguments);
124 m_sModule = lArgs.getUnpackedValueOrDefault(::rtl::OUString::createFromAscii("ModuleIdentifier"), ::rtl::OUString());
125 m_sLocale = lArgs.getUnpackedValueOrDefault(::rtl::OUString::createFromAscii("Locale") , ::rtl::OUString::createFromAscii("x-default"));
126
127 if (!m_sModule.getLength())
128 throw css::uno::RuntimeException(
129 ::rtl::OUString::createFromAscii("The module dependend accelerator configuration service was initialized with an empty module identifier!"),
130 static_cast< ::cppu::OWeakObject* >(this));
131
132 aWriteLock.unlock();
133 // <- SAFE ----------------------------------
134
135 impl_ts_fillCache();
136 }
137
138 //-----------------------------------------------
impl_ts_fillCache()139 void ModuleAcceleratorConfiguration::impl_ts_fillCache()
140 {
141 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleAcceleratorConfiguration::impl_ts_fillCache" );
142 // SAFE -> ----------------------------------
143 ReadGuard aReadLock(m_aLock);
144 ::rtl::OUString sModule = m_sModule;
145 m_sModuleCFG = m_sModule;
146 aReadLock.unlock();
147 // <- SAFE ----------------------------------
148
149 // get current office locale ... but dont cache it.
150 // Otherwise we must be listener on the configuration layer
151 // which seems to superflous for this small implementation .-)
152 ::comphelper::Locale aLocale = ::comphelper::Locale(m_sLocale);
153
154 // May be the current app module does not have any
155 // accelerator config? Handle it gracefully :-)
156 try
157 {
158 m_sGlobalOrModules = CFG_ENTRY_MODULES;
159 XCUBasedAcceleratorConfiguration::reload();
160
161 css::uno::Reference< css::util::XChangesNotifier > xBroadcaster(m_xCfg, css::uno::UNO_QUERY_THROW);
162 xBroadcaster->addChangesListener(static_cast< css::util::XChangesListener* >(this));
163 }
164 catch(const css::uno::RuntimeException& exRun)
165 { throw exRun; }
166 catch(const css::uno::Exception&)
167 {}
168 }
169
170 //-----------------------------------------------
171 //
172 // XComponent.dispose(), #120029#, to release the cyclic reference
173 //
dispose()174 void SAL_CALL ModuleAcceleratorConfiguration::dispose()
175 throw(css::uno::RuntimeException)
176 {
177 try
178 {
179 css::uno::Reference< css::util::XChangesNotifier > xBroadcaster(m_xCfg, css::uno::UNO_QUERY_THROW);
180 if ( xBroadcaster.is() )
181 xBroadcaster->removeChangesListener(static_cast< css::util::XChangesListener* >(this));
182 }
183 catch(const css::uno::RuntimeException& exRun)
184 { throw exRun; }
185 catch(const css::uno::Exception&)
186 {}
187 }
188
189 } // namespace framework
190
191