fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / comphelper / source / misc / configuration.cxx
blob69885b98163f82905033b98df2770f7de9686d23
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/.
8 */
10 #include "sal/config.h"
12 #include <cassert>
14 #include "boost/shared_ptr.hpp"
15 #include "com/sun/star/configuration/ReadOnlyAccess.hpp"
16 #include "com/sun/star/configuration/ReadWriteAccess.hpp"
17 #include "com/sun/star/configuration/XReadWriteAccess.hpp"
18 #include "com/sun/star/configuration/theDefaultProvider.hpp"
19 #include "com/sun/star/container/XHierarchicalNameAccess.hpp"
20 #include "com/sun/star/container/XHierarchicalNameReplace.hpp"
21 #include "com/sun/star/container/XNameAccess.hpp"
22 #include "com/sun/star/container/XNameContainer.hpp"
23 #include "com/sun/star/lang/Locale.hpp"
24 #include "com/sun/star/lang/XLocalizable.hpp"
25 #include "com/sun/star/uno/Any.hxx"
26 #include "com/sun/star/uno/Reference.hxx"
27 #include "com/sun/star/uno/XComponentContext.hpp"
28 #include "comphelper/configuration.hxx"
29 #include "rtl/instance.hxx"
30 #include "rtl/ustrbuf.hxx"
31 #include "rtl/ustring.hxx"
32 #include "i18nlangtag/languagetag.hxx"
34 namespace {
36 struct TheConfigurationWrapper:
37 public rtl::StaticWithArg<
38 comphelper::detail::ConfigurationWrapper,
39 css::uno::Reference< css::uno::XComponentContext >,
40 TheConfigurationWrapper >
41 {};
43 OUString getDefaultLocale(
44 css::uno::Reference< css::uno::XComponentContext > const & context)
46 return LanguageTag(
47 css::uno::Reference< css::lang::XLocalizable >(
48 css::configuration::theDefaultProvider::get(context),
49 css::uno::UNO_QUERY_THROW)->
50 getLocale()).getBcp47();
53 OUString extendLocalizedPath(OUString const & path, OUString const & locale) {
54 OUStringBuffer buf(path);
55 buf.append("/['*");
56 SAL_WARN_IF(
57 locale.match("*"), "comphelper",
58 "Locale \"" << locale << "\" starts with \"*\"");
59 assert(locale.indexOf('&') == -1);
60 assert(locale.indexOf('"') == -1);
61 assert(locale.indexOf('\'') == -1);
62 buf.append(locale);
63 buf.append("']");
64 return buf.makeStringAndClear();
69 boost::shared_ptr< comphelper::ConfigurationChanges >
70 comphelper::ConfigurationChanges::create(
71 css::uno::Reference< css::uno::XComponentContext > const & context)
73 return TheConfigurationWrapper::get(context).createChanges();
77 comphelper::ConfigurationChanges::~ConfigurationChanges() {}
79 void comphelper::ConfigurationChanges::commit() const {
80 access_->commitChanges();
83 comphelper::ConfigurationChanges::ConfigurationChanges(
84 css::uno::Reference< css::uno::XComponentContext > const & context):
85 access_(
86 css::configuration::ReadWriteAccess::create(
87 context, getDefaultLocale(context)))
90 void comphelper::ConfigurationChanges::setPropertyValue(
91 OUString const & path, css::uno::Any const & value) const
93 access_->replaceByHierarchicalName(path, value);
96 css::uno::Reference< css::container::XHierarchicalNameReplace >
97 comphelper::ConfigurationChanges::getGroup(OUString const & path) const
99 return css::uno::Reference< css::container::XHierarchicalNameReplace >(
100 access_->getByHierarchicalName(path), css::uno::UNO_QUERY_THROW);
103 css::uno::Reference< css::container::XNameContainer >
104 comphelper::ConfigurationChanges::getSet(OUString const & path) const
106 return css::uno::Reference< css::container::XNameContainer >(
107 access_->getByHierarchicalName(path), css::uno::UNO_QUERY_THROW);
110 comphelper::detail::ConfigurationWrapper const &
111 comphelper::detail::ConfigurationWrapper::get(
112 css::uno::Reference< css::uno::XComponentContext > const & context)
114 return TheConfigurationWrapper::get(context);
117 comphelper::detail::ConfigurationWrapper::ConfigurationWrapper(
118 css::uno::Reference< css::uno::XComponentContext > const & context):
119 context_(context),
120 access_(css::configuration::ReadOnlyAccess::create(context, "*"))
123 comphelper::detail::ConfigurationWrapper::~ConfigurationWrapper() {}
125 css::uno::Any comphelper::detail::ConfigurationWrapper::getPropertyValue(
126 OUString const & path) const
128 return access_->getByHierarchicalName(path);
131 void comphelper::detail::ConfigurationWrapper::setPropertyValue(
132 boost::shared_ptr< ConfigurationChanges > const & batch,
133 OUString const & path, com::sun::star::uno::Any const & value) const
135 assert(batch.get() != 0);
136 batch->setPropertyValue(path, value);
139 css::uno::Any
140 comphelper::detail::ConfigurationWrapper::getLocalizedPropertyValue(
141 OUString const & path) const
143 return access_->getByHierarchicalName(
144 extendLocalizedPath(path, getDefaultLocale(context_)));
147 void comphelper::detail::ConfigurationWrapper::setLocalizedPropertyValue(
148 boost::shared_ptr< ConfigurationChanges > const & batch,
149 OUString const & path, com::sun::star::uno::Any const & value) const
151 assert(batch.get() != 0);
152 batch->setPropertyValue(path, value);
155 css::uno::Reference< css::container::XHierarchicalNameAccess >
156 comphelper::detail::ConfigurationWrapper::getGroupReadOnly(
157 OUString const & path) const
159 return css::uno::Reference< css::container::XHierarchicalNameAccess >(
160 (css::configuration::ReadOnlyAccess::create(
161 context_, getDefaultLocale(context_))->
162 getByHierarchicalName(path)),
163 css::uno::UNO_QUERY_THROW);
166 css::uno::Reference< css::container::XHierarchicalNameReplace >
167 comphelper::detail::ConfigurationWrapper::getGroupReadWrite(
168 boost::shared_ptr< ConfigurationChanges > const & batch,
169 OUString const & path) const
171 assert(batch.get() != 0);
172 return batch->getGroup(path);
175 css::uno::Reference< css::container::XNameAccess >
176 comphelper::detail::ConfigurationWrapper::getSetReadOnly(
177 OUString const & path) const
179 return css::uno::Reference< css::container::XNameAccess >(
180 (css::configuration::ReadOnlyAccess::create(
181 context_, getDefaultLocale(context_))->
182 getByHierarchicalName(path)),
183 css::uno::UNO_QUERY_THROW);
186 css::uno::Reference< css::container::XNameContainer >
187 comphelper::detail::ConfigurationWrapper::getSetReadWrite(
188 boost::shared_ptr< ConfigurationChanges > const & batch,
189 OUString const & path) const
191 assert(batch.get() != 0);
192 return batch->getSet(path);
195 boost::shared_ptr< comphelper::ConfigurationChanges >
196 comphelper::detail::ConfigurationWrapper::createChanges() const {
197 return boost::shared_ptr< ConfigurationChanges >(
198 new ConfigurationChanges(context_));
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */