1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_framework.hxx"
30 #include <accelerators/moduleacceleratorconfiguration.hxx>
31 
32 //_______________________________________________
33 // own includes
34 #include <threadhelp/readguard.hxx>
35 #include <threadhelp/writeguard.hxx>
36 
37 #ifndef __FRAMEWORK_ACCELERATORCONST_H_
38 #include <acceleratorconst.h>
39 #endif
40 #include <services.h>
41 
42 //_______________________________________________
43 // interface includes
44 #include <com/sun/star/beans/XPropertySet.hpp>
45 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
46 #include <com/sun/star/embed/ElementModes.hpp>
47 
48 //_______________________________________________
49 // other includes
50 
51 #ifndef _COMPHELPER_SEQUENCEASHASHMAP_HXX
52 #include <comphelper/sequenceashashmap.hxx>
53 #endif
54 #include <vcl/svapp.hxx>
55 
56 #ifndef _COMPHELPER_CONFIGURATIONHELPER_HXX_
57 #include <comphelper/configurationhelper.hxx>
58 #endif
59 
60 #ifndef _COM_SUN_STAR_UTIL_XCHANGESNOTIFIER_HPP_
61 #include <com/sun/star/util/XChangesNotifier.hpp>
62 #endif
63 
64 #ifndef _RTL_LOGFILE_HXX_
65 #include <rtl/logfile.hxx>
66 #endif
67 
68 #ifndef _RTL_LOGFILE_HXX_
69 #include <rtl/logfile.h>
70 #endif
71 
72 //_______________________________________________
73 // const
74 
75 namespace framework
76 {
77 
78 //-----------------------------------------------
79 // XInterface, XTypeProvider, XServiceInfo
80 DEFINE_XINTERFACE_2(ModuleAcceleratorConfiguration              ,
81                     XCUBasedAcceleratorConfiguration                    ,
82                     DIRECT_INTERFACE(css::lang::XServiceInfo)   ,
83                     DIRECT_INTERFACE(css::lang::XInitialization))
84 
85 DEFINE_XTYPEPROVIDER_2_WITH_BASECLASS(ModuleAcceleratorConfiguration,
86                                       XCUBasedAcceleratorConfiguration      ,
87                                       css::lang::XServiceInfo       ,
88                                       css::lang::XInitialization    )
89 
90 DEFINE_XSERVICEINFO_MULTISERVICE(ModuleAcceleratorConfiguration                   ,
91                                  ::cppu::OWeakObject                              ,
92                                  SERVICENAME_MODULEACCELERATORCONFIGURATION       ,
93                                  IMPLEMENTATIONNAME_MODULEACCELERATORCONFIGURATION)
94 
95 DEFINE_INIT_SERVICE(ModuleAcceleratorConfiguration,
96                     {
97                         /*Attention
98                         I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
99                         to create a new instance of this class by our own supported service factory.
100                         see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further informations!
101                         */
102                     }
103                    )
104 
105 //-----------------------------------------------
106 ModuleAcceleratorConfiguration::ModuleAcceleratorConfiguration(const css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR)
107     : XCUBasedAcceleratorConfiguration(xSMGR)
108 {
109     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleAcceleratorConfiguration::ModuleAcceleratorConfiguration" );
110 }
111 
112 //-----------------------------------------------
113 ModuleAcceleratorConfiguration::~ModuleAcceleratorConfiguration()
114 {
115    // m_aPresetHandler.removeStorageListener(this);
116 }
117 
118 //-----------------------------------------------
119 void SAL_CALL ModuleAcceleratorConfiguration::initialize(const css::uno::Sequence< css::uno::Any >& lArguments)
120     throw(css::uno::Exception       ,
121           css::uno::RuntimeException)
122 {
123     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleAcceleratorConfiguration::initialize" );
124     // SAFE -> ----------------------------------
125     WriteGuard aWriteLock(m_aLock);
126 
127 	::comphelper::SequenceAsHashMap lArgs(lArguments);
128     m_sModule = lArgs.getUnpackedValueOrDefault(::rtl::OUString::createFromAscii("ModuleIdentifier"), ::rtl::OUString());
129 	m_sLocale = lArgs.getUnpackedValueOrDefault(::rtl::OUString::createFromAscii("Locale")          , ::rtl::OUString::createFromAscii("x-default"));
130 
131     if (!m_sModule.getLength())
132         throw css::uno::RuntimeException(
133                 ::rtl::OUString::createFromAscii("The module dependend accelerator configuration service was initialized with an empty module identifier!"),
134                 static_cast< ::cppu::OWeakObject* >(this));
135 
136     aWriteLock.unlock();
137     // <- SAFE ----------------------------------
138 
139     impl_ts_fillCache();
140 }
141 
142 //-----------------------------------------------
143 void ModuleAcceleratorConfiguration::impl_ts_fillCache()
144 {
145     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleAcceleratorConfiguration::impl_ts_fillCache" );
146     // SAFE -> ----------------------------------
147     ReadGuard aReadLock(m_aLock);
148     ::rtl::OUString sModule = m_sModule;
149 	m_sModuleCFG = m_sModule;
150     aReadLock.unlock();
151     // <- SAFE ----------------------------------
152 
153     // get current office locale ... but dont cache it.
154     // Otherwise we must be listener on the configuration layer
155     // which seems to superflous for this small implementation .-)
156 	::comphelper::Locale aLocale = ::comphelper::Locale(m_sLocale);
157 
158     // May be the current app module does not have any
159     // accelerator config? Handle it gracefully :-)
160     try
161     {
162         m_sGlobalOrModules = CFG_ENTRY_MODULES;
163 		XCUBasedAcceleratorConfiguration::reload();
164 
165 		css::uno::Reference< css::util::XChangesNotifier > xBroadcaster(m_xCfg, css::uno::UNO_QUERY_THROW);
166 		xBroadcaster->addChangesListener(static_cast< css::util::XChangesListener* >(this));
167 	}
168     catch(const css::uno::RuntimeException& exRun)
169         { throw exRun; }
170     catch(const css::uno::Exception&)
171         {}
172 }
173 
174 } // namespace framework
175 
176