LibreOffice Module framework (master) 1
moduleacceleratorconfiguration.cxx
Go to the documentation of this file.
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
21#include <helper/mischelper.hxx>
22
23#include <com/sun/star/lang/XServiceInfo.hpp>
24
27#include <vcl/svapp.hxx>
28
29#include <com/sun/star/util/XChangesNotifier.hpp>
30
32
33using namespace framework;
34
35namespace {
36
41typedef ::cppu::ImplInheritanceHelper<
43 css::lang::XServiceInfo > ModuleAcceleratorConfiguration_BASE;
44
45class ModuleAcceleratorConfiguration : public ModuleAcceleratorConfiguration_BASE
46{
47private:
50 OUString m_sModule;
51
52public:
53
59 ModuleAcceleratorConfiguration(
60 const css::uno::Reference< css::uno::XComponentContext >& xContext,
61 const css::uno::Sequence< css::uno::Any >& lArguments);
62
63 virtual OUString SAL_CALL getImplementationName() override
64 {
65 return "com.sun.star.comp.framework.ModuleAcceleratorConfiguration";
66 }
67
68 virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
69 {
70 return cppu::supportsService(this, ServiceName);
71 }
72
73 virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
74 {
75 return {"com.sun.star.ui.ModuleAcceleratorConfiguration"};
76 }
77
79 void fillCache();
80
81private:
83 css::uno::Reference< css::util::XChangesListener > m_xCfgListener;
84};
85
86ModuleAcceleratorConfiguration::ModuleAcceleratorConfiguration(
87 const css::uno::Reference< css::uno::XComponentContext >& xContext,
88 const css::uno::Sequence< css::uno::Any >& lArguments)
89 : ModuleAcceleratorConfiguration_BASE(xContext)
90{
92
93 OUString sModule;
94 if (lArguments.getLength() == 1 && (lArguments[0] >>= sModule))
95 {
96 m_sModule = sModule;
97 } else
98 {
99 ::comphelper::SequenceAsHashMap lArgs(lArguments);
100 m_sModule = lArgs.getUnpackedValueOrDefault("ModuleIdentifier", OUString());
101 // OUString sLocale = lArgs.getUnpackedValueOrDefault("Locale", OUString("x-default"));
102 }
103
104 if (m_sModule.isEmpty())
105 throw css::uno::RuntimeException(
106 "The module dependent accelerator configuration service was initialized with an empty module identifier!",
107 static_cast< ::cppu::OWeakObject* >(this));
108}
109
110void ModuleAcceleratorConfiguration::fillCache()
111{
112 {
114 m_sModuleCFG = m_sModule;
115 }
116
117#if 0
118 // get current office locale ... but don't cache it.
119 // Otherwise we must be listener on the configuration layer
120 // which seems to superfluous for this small implementation .-)
121 // XXX: what is this good for? it was a comphelper::Locale but unused
122 LanguageTag aLanguageTag(m_sLocale);
123#endif
124
125 // May be the current app module does not have any
126 // accelerator config? Handle it gracefully :-)
127 try
128 {
129 m_sGlobalOrModules = CFG_ENTRY_MODULES;
130 XCUBasedAcceleratorConfiguration::reload();
131
132 css::uno::Reference< css::util::XChangesNotifier > xBroadcaster(m_xCfg, css::uno::UNO_QUERY_THROW);
133 m_xCfgListener = new WeakChangesListener(this);
134 xBroadcaster->addChangesListener(m_xCfgListener);
135 }
136 catch(const css::uno::RuntimeException&)
137 { throw; }
138 catch(const css::uno::Exception&)
139 {}
140}
141
142}
143
144extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
146 css::uno::XComponentContext *context,
147 css::uno::Sequence<css::uno::Any> const &arguments)
148{
149 rtl::Reference<ModuleAcceleratorConfiguration> inst = new ModuleAcceleratorConfiguration(context, arguments);
150 css::uno::XInterface *acquired_inst = cppu::acquire(inst.get());
151
152 inst->fillCache();
153
154 return acquired_inst;
155}
156
157/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_framework_ModuleAcceleratorConfiguration_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &arguments)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
constexpr OUStringLiteral CFG_ENTRY_MODULES
unsigned char sal_Bool