update credits
[LibreOffice.git] / framework / source / accelerators / moduleacceleratorconfiguration.cxx
blob382df163b2b578d32e37462a77bb379b2c19974c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <accelerators/moduleacceleratorconfiguration.hxx>
22 #include <threadhelp/readguard.hxx>
23 #include <threadhelp/writeguard.hxx>
24 #include "helper/mischelper.hxx"
26 #include <acceleratorconst.h>
27 #include <services.h>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
31 #include <com/sun/star/embed/ElementModes.hpp>
33 #include <comphelper/sequenceashashmap.hxx>
34 #include <vcl/svapp.hxx>
36 #include <comphelper/configurationhelper.hxx>
38 #include <com/sun/star/util/XChangesNotifier.hpp>
40 #include <rtl/logfile.hxx>
42 #include <rtl/logfile.h>
45 namespace framework
48 //-----------------------------------------------
49 // XInterface, XTypeProvider, XServiceInfo
50 DEFINE_XINTERFACE_2(ModuleAcceleratorConfiguration ,
51 XCUBasedAcceleratorConfiguration ,
52 DIRECT_INTERFACE(css::lang::XServiceInfo) ,
53 DIRECT_INTERFACE(css::lang::XInitialization))
55 DEFINE_XTYPEPROVIDER_2_WITH_BASECLASS(ModuleAcceleratorConfiguration,
56 XCUBasedAcceleratorConfiguration ,
57 css::lang::XServiceInfo ,
58 css::lang::XInitialization )
60 DEFINE_XSERVICEINFO_MULTISERVICE(ModuleAcceleratorConfiguration ,
61 ::cppu::OWeakObject ,
62 SERVICENAME_MODULEACCELERATORCONFIGURATION ,
63 IMPLEMENTATIONNAME_MODULEACCELERATORCONFIGURATION)
65 DEFINE_INIT_SERVICE(ModuleAcceleratorConfiguration,
67 /*Attention
68 I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
69 to create a new instance of this class by our own supported service factory.
70 see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further information!
75 //-----------------------------------------------
76 ModuleAcceleratorConfiguration::ModuleAcceleratorConfiguration(const css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR)
77 : XCUBasedAcceleratorConfiguration(xSMGR)
79 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleAcceleratorConfiguration::ModuleAcceleratorConfiguration" );
82 //-----------------------------------------------
83 ModuleAcceleratorConfiguration::~ModuleAcceleratorConfiguration()
87 //-----------------------------------------------
88 void SAL_CALL ModuleAcceleratorConfiguration::initialize(const css::uno::Sequence< css::uno::Any >& lArguments)
89 throw(css::uno::Exception ,
90 css::uno::RuntimeException)
92 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleAcceleratorConfiguration::initialize" );
93 // SAFE -> ----------------------------------
94 WriteGuard aWriteLock(m_aLock);
96 ::comphelper::SequenceAsHashMap lArgs(lArguments);
97 m_sModule = lArgs.getUnpackedValueOrDefault(OUString("ModuleIdentifier"), OUString());
98 m_sLocale = lArgs.getUnpackedValueOrDefault(OUString("Locale") , OUString("x-default"));
100 if (m_sModule.isEmpty())
101 throw css::uno::RuntimeException(
102 OUString("The module dependend accelerator configuration service was initialized with an empty module identifier!"),
103 static_cast< ::cppu::OWeakObject* >(this));
105 aWriteLock.unlock();
106 // <- SAFE ----------------------------------
108 impl_ts_fillCache();
111 //-----------------------------------------------
112 void ModuleAcceleratorConfiguration::impl_ts_fillCache()
114 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen@sun.com", "ModuleAcceleratorConfiguration::impl_ts_fillCache" );
115 // SAFE -> ----------------------------------
116 ReadGuard aReadLock(m_aLock);
117 m_sModuleCFG = m_sModule;
118 aReadLock.unlock();
119 // <- SAFE ----------------------------------
121 #if 0
122 // get current office locale ... but dont cache it.
123 // Otherwise we must be listener on the configuration layer
124 // which seems to superflous for this small implementation .-)
125 // XXX: what is this good for? it was a comphelper::Locale but unused
126 LanguageTag aLanguageTag(m_sLocale);
127 #endif
129 // May be the current app module does not have any
130 // accelerator config? Handle it gracefully :-)
133 m_sGlobalOrModules = CFG_ENTRY_MODULES;
134 XCUBasedAcceleratorConfiguration::reload();
136 css::uno::Reference< css::util::XChangesNotifier > xBroadcaster(m_xCfg, css::uno::UNO_QUERY_THROW);
137 m_xCfgListener = new WeakChangesListener(this);
138 xBroadcaster->addChangesListener(m_xCfgListener);
140 catch(const css::uno::RuntimeException&)
141 { throw; }
142 catch(const css::uno::Exception&)
146 //-----------------------------------------------
148 // XComponent.dispose(), #i120029#, to release the cyclic reference
150 void SAL_CALL ModuleAcceleratorConfiguration::dispose()
151 throw(css::uno::RuntimeException)
155 css::uno::Reference< css::util::XChangesNotifier > xBroadcaster(m_xCfg, css::uno::UNO_QUERY_THROW);
156 if ( xBroadcaster.is() )
157 xBroadcaster->removeChangesListener(static_cast< css::util::XChangesListener* >(this));
159 catch(const css::uno::RuntimeException&)
160 { throw; }
161 catch(const css::uno::Exception&)
165 } // namespace framework
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */