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 <accelerators/moduleacceleratorconfiguration.hxx>
21 :
22 : #include <threadhelp/readguard.hxx>
23 : #include <threadhelp/writeguard.hxx>
24 : #include "helper/mischelper.hxx"
25 :
26 : #include <acceleratorconst.h>
27 : #include <services.h>
28 :
29 : #include <com/sun/star/beans/XPropertySet.hpp>
30 : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
31 : #include <com/sun/star/embed/ElementModes.hpp>
32 :
33 : #include <comphelper/sequenceashashmap.hxx>
34 : #include <vcl/svapp.hxx>
35 :
36 : #include <comphelper/configurationhelper.hxx>
37 :
38 : #include <com/sun/star/util/XChangesNotifier.hpp>
39 :
40 : #include <rtl/logfile.hxx>
41 :
42 : #include <rtl/logfile.h>
43 :
44 : #define SERVICENAME_MODULEACCELERATORCONFIGURATION DECLARE_ASCII("com.sun.star.ui.ModuleAcceleratorConfiguration")
45 : #define IMPLEMENTATIONNAME_MODULEACCELERATORCONFIGURATION DECLARE_ASCII("com.sun.star.comp.framework.ModuleAcceleratorConfiguration")
46 :
47 : namespace framework
48 : {
49 :
50 : //-----------------------------------------------
51 : // XInterface, XTypeProvider, XServiceInfo
52 86803 : DEFINE_XINTERFACE_2(ModuleAcceleratorConfiguration ,
53 : XCUBasedAcceleratorConfiguration ,
54 : DIRECT_INTERFACE(css::lang::XServiceInfo) ,
55 : DIRECT_INTERFACE(css::lang::XInitialization))
56 :
57 0 : DEFINE_XTYPEPROVIDER_2_WITH_BASECLASS(ModuleAcceleratorConfiguration,
58 : XCUBasedAcceleratorConfiguration ,
59 : css::lang::XServiceInfo ,
60 : css::lang::XInitialization )
61 :
62 1102 : DEFINE_XSERVICEINFO_MULTISERVICE_2(ModuleAcceleratorConfiguration ,
63 : ::cppu::OWeakObject ,
64 : SERVICENAME_MODULEACCELERATORCONFIGURATION ,
65 : IMPLEMENTATIONNAME_MODULEACCELERATORCONFIGURATION)
66 :
67 46 : DEFINE_INIT_SERVICE(ModuleAcceleratorConfiguration,
68 : {
69 : /*Attention
70 : I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
71 : to create a new instance of this class by our own supported service factory.
72 : see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further information!
73 : */
74 : }
75 : )
76 :
77 : //-----------------------------------------------
78 46 : ModuleAcceleratorConfiguration::ModuleAcceleratorConfiguration(const css::uno::Reference< css::uno::XComponentContext >& xContext)
79 46 : : XCUBasedAcceleratorConfiguration(xContext)
80 : {
81 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleAcceleratorConfiguration::ModuleAcceleratorConfiguration" );
82 46 : }
83 :
84 : //-----------------------------------------------
85 92 : ModuleAcceleratorConfiguration::~ModuleAcceleratorConfiguration()
86 : {
87 92 : }
88 :
89 : //-----------------------------------------------
90 46 : void SAL_CALL ModuleAcceleratorConfiguration::initialize(const css::uno::Sequence< css::uno::Any >& lArguments)
91 : throw(css::uno::Exception ,
92 : css::uno::RuntimeException)
93 : {
94 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleAcceleratorConfiguration::initialize" );
95 : // SAFE -> ----------------------------------
96 46 : WriteGuard aWriteLock(m_aLock);
97 :
98 92 : OUString sModule;
99 46 : if (lArguments.getLength() == 1 && (lArguments[0] >>= sModule))
100 : {
101 46 : m_sModule = sModule;
102 : } else
103 : {
104 0 : ::comphelper::SequenceAsHashMap lArgs(lArguments);
105 0 : m_sModule = lArgs.getUnpackedValueOrDefault("ModuleIdentifier", OUString());
106 0 : m_sLocale = lArgs.getUnpackedValueOrDefault("Locale", OUString("x-default"));
107 : }
108 :
109 46 : if (m_sModule.isEmpty())
110 : throw css::uno::RuntimeException(
111 : OUString("The module dependend accelerator configuration service was initialized with an empty module identifier!"),
112 0 : static_cast< ::cppu::OWeakObject* >(this));
113 :
114 46 : aWriteLock.unlock();
115 : // <- SAFE ----------------------------------
116 :
117 92 : impl_ts_fillCache();
118 46 : }
119 :
120 : //-----------------------------------------------
121 46 : void ModuleAcceleratorConfiguration::impl_ts_fillCache()
122 : {
123 : RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleAcceleratorConfiguration::impl_ts_fillCache" );
124 : // SAFE -> ----------------------------------
125 46 : ReadGuard aReadLock(m_aLock);
126 46 : m_sModuleCFG = m_sModule;
127 46 : aReadLock.unlock();
128 : // <- SAFE ----------------------------------
129 :
130 : #if 0
131 : // get current office locale ... but dont cache it.
132 : // Otherwise we must be listener on the configuration layer
133 : // which seems to superflous for this small implementation .-)
134 : // XXX: what is this good for? it was a comphelper::Locale but unused
135 : LanguageTag aLanguageTag(m_sLocale);
136 : #endif
137 :
138 : // May be the current app module does not have any
139 : // accelerator config? Handle it gracefully :-)
140 : try
141 : {
142 46 : m_sGlobalOrModules = CFG_ENTRY_MODULES;
143 46 : XCUBasedAcceleratorConfiguration::reload();
144 :
145 45 : css::uno::Reference< css::util::XChangesNotifier > xBroadcaster(m_xCfg, css::uno::UNO_QUERY_THROW);
146 45 : m_xCfgListener = new WeakChangesListener(this);
147 45 : xBroadcaster->addChangesListener(m_xCfgListener);
148 : }
149 0 : catch(const css::uno::RuntimeException&)
150 0 : { throw; }
151 1 : catch(const css::uno::Exception&)
152 46 : {}
153 46 : }
154 :
155 : //-----------------------------------------------
156 : //
157 : // XComponent.dispose(), #i120029#, to release the cyclic reference
158 : //
159 46 : void SAL_CALL ModuleAcceleratorConfiguration::dispose()
160 : throw(css::uno::RuntimeException)
161 : {
162 : try
163 : {
164 46 : css::uno::Reference< css::util::XChangesNotifier > xBroadcaster(m_xCfg, css::uno::UNO_QUERY_THROW);
165 46 : if ( xBroadcaster.is() )
166 46 : xBroadcaster->removeChangesListener(static_cast< css::util::XChangesListener* >(this));
167 : }
168 0 : catch(const css::uno::RuntimeException&)
169 0 : { throw; }
170 0 : catch(const css::uno::Exception&)
171 : {}
172 46 : }
173 :
174 402 : } // namespace framework
175 :
176 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|