1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <sal/config.h>
24 #include <com/sun/star/beans/NamedValue.hpp>
25 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
26 #include <com/sun/star/configuration/theDefaultProvider.hpp>
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <com/sun/star/uno/Any.hxx>
29 #include <com/sun/star/uno/Reference.hxx>
30 #include <com/sun/star/uno/Sequence.hxx>
31 #include <osl/diagnose.h>
32 #include <rtl/instance.hxx>
33 #include <rtl/ustring.h>
34 #include <rtl/ustring.hxx>
35 #include <unotools/configitem.hxx>
36 #include <unotools/configmgr.hxx>
37 #include <comphelper/processfactory.hxx>
41 class RegisterConfigItemHelper
{
43 RegisterConfigItemHelper(
44 utl::ConfigManager
& manager
, utl::ConfigItem
& item
):
45 manager_(manager
), item_(&item
)
47 manager
.registerConfigItem(item_
);
50 ~RegisterConfigItemHelper() {
52 manager_
.removeConfigItem(*item_
);
56 void keep() { item_
= 0; }
59 utl::ConfigManager
& manager_
;
60 utl::ConfigItem
* item_
;
62 RegisterConfigItemHelper(const RegisterConfigItemHelper
&) SAL_DELETED_FUNCTION
;
63 RegisterConfigItemHelper
& operator=(const RegisterConfigItemHelper
&) SAL_DELETED_FUNCTION
;
66 css::uno::Reference
< css::lang::XMultiServiceFactory
>
67 getConfigurationProvider() {
68 return css::configuration::theDefaultProvider::get( comphelper::getProcessComponentContext() );
71 OUString
getConfigurationString(OUString
const & module
, OUString
const & path
)
73 css::uno::Sequence
< css::uno::Any
> args(1);
74 args
[0] <<= css::beans::NamedValue(
76 css::uno::makeAny(module
));
78 css::uno::Reference
< css::container::XHierarchicalNameAccess
>(
79 getConfigurationProvider()->createInstanceWithArguments(
80 OUString("com.sun.star.configuration.ConfigurationAccess"),
82 css::uno::UNO_QUERY_THROW
)->
83 getByHierarchicalName(path
).get
< OUString
>();
86 struct theConfigManager
:
87 public rtl::Static
< utl::ConfigManager
, theConfigManager
>
92 OUString
utl::ConfigManager::getAboutBoxProductVersion() {
93 return getConfigurationString(
94 OUString("/org.openoffice.Setup"),
95 OUString("Product/ooSetupVersionAboutBox"));
98 OUString
utl::ConfigManager::getAboutBoxProductVersionSuffix() {
99 return getConfigurationString(
100 OUString("/org.openoffice.Setup"),
101 OUString("Product/ooSetupVersionAboutBoxSuffix"));
104 OUString
utl::ConfigManager::getDefaultCurrency() {
105 return getConfigurationString(
106 OUString("/org.openoffice.Setup"),
107 OUString("L10N/ooSetupCurrency"));
110 OUString
utl::ConfigManager::getLocale() {
111 return getConfigurationString(
112 OUString("/org.openoffice.Setup"),
113 OUString("L10N/ooLocale"));
116 OUString
utl::ConfigManager::getProductExtension() {
117 return getConfigurationString(
118 OUString("/org.openoffice.Setup"),
119 OUString("Product/ooSetupExtension"));
122 OUString
utl::ConfigManager::getProductName() {
123 return getConfigurationString(
124 OUString("/org.openoffice.Setup"),
125 OUString("Product/ooName"));
128 OUString
utl::ConfigManager::getProductVersion() {
129 return getConfigurationString(
130 OUString("/org.openoffice.Setup"),
131 OUString("Product/ooSetupVersion"));
134 OUString
utl::ConfigManager::getVendor() {
135 return getConfigurationString(
136 OUString("/org.openoffice.Setup"),
137 OUString("Product/ooVendor"));
140 void utl::ConfigManager::storeConfigItems() {
141 getConfigManager().doStoreConfigItems();
144 utl::ConfigManager
& utl::ConfigManager::getConfigManager() {
145 return theConfigManager::get();
148 css::uno::Reference
< css::container::XHierarchicalNameAccess
>
149 utl::ConfigManager::acquireTree(utl::ConfigItem
& item
) {
150 css::uno::Sequence
< css::uno::Any
> args(1);
151 args
[0] <<= css::beans::NamedValue(
152 OUString("nodepath"),
153 css::uno::makeAny("/org.openoffice." + item
.GetSubTreeName()));
154 if (item
.GetMode() & ConfigItemMode::AllLocales
) {
156 args
[1] <<= css::beans::NamedValue(OUString("locale"), css::uno::makeAny(OUString("*")));
158 return css::uno::Reference
< css::container::XHierarchicalNameAccess
>(
159 getConfigurationProvider()->createInstanceWithArguments(
160 OUString("com.sun.star.configuration.ConfigurationUpdateAccess"),
162 css::uno::UNO_QUERY_THROW
);
165 utl::ConfigManager::ConfigManager() {}
167 utl::ConfigManager::~ConfigManager() {
168 OSL_ASSERT(items_
.empty());
171 css::uno::Reference
< css::container::XHierarchicalNameAccess
>
172 utl::ConfigManager::addConfigItem(utl::ConfigItem
& item
) {
173 RegisterConfigItemHelper
reg(*this, item
);
174 css::uno::Reference
< css::container::XHierarchicalNameAccess
> tree(
180 void utl::ConfigManager::removeConfigItem(utl::ConfigItem
& item
) {
181 for (std::list
< ConfigItem
* >::iterator
i(items_
.begin());
182 i
!= items_
.end(); ++i
)
191 void utl::ConfigManager::registerConfigItem(utl::ConfigItem
* item
) {
192 OSL_ASSERT(item
!= 0);
193 items_
.push_back(item
);
196 void utl::ConfigManager::doStoreConfigItems() {
197 for (std::list
< ConfigItem
* >::iterator
i(items_
.begin());
198 i
!= items_
.end(); ++i
)
200 if ((*i
)->IsModified()) {
202 (*i
)->ClearModified();
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */