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 "boost/noncopyable.hpp"
25 #include "com/sun/star/beans/NamedValue.hpp"
26 #include "com/sun/star/container/XHierarchicalNameAccess.hpp"
27 #include "com/sun/star/configuration/theDefaultProvider.hpp"
28 #include "com/sun/star/lang/XMultiServiceFactory.hpp"
29 #include "com/sun/star/uno/Any.hxx"
30 #include "com/sun/star/uno/Reference.hxx"
31 #include "com/sun/star/uno/Sequence.hxx"
32 #include "osl/diagnose.h"
33 #include "rtl/instance.hxx"
34 #include "rtl/ustring.h"
35 #include "rtl/ustring.hxx"
36 #include "unotools/configitem.hxx"
37 #include "unotools/configmgr.hxx"
38 #include "comphelper/processfactory.hxx"
42 class RegisterConfigItemHelper
: private boost::noncopyable
{
44 RegisterConfigItemHelper(
45 utl::ConfigManager
& manager
, utl::ConfigItem
& item
):
46 manager_(manager
), item_(&item
)
48 manager
.registerConfigItem(item_
);
51 ~RegisterConfigItemHelper() {
53 manager_
.removeConfigItem(*item_
);
57 void keep() { item_
= 0; }
60 utl::ConfigManager
& manager_
;
61 utl::ConfigItem
* item_
;
64 css::uno::Reference
< css::lang::XMultiServiceFactory
>
65 getConfigurationProvider() {
66 return css::configuration::theDefaultProvider::get( comphelper::getProcessComponentContext() );
69 OUString
getConfigurationString(OUString
const & module
, OUString
const & path
)
71 css::uno::Sequence
< css::uno::Any
> args(1);
72 args
[0] <<= css::beans::NamedValue(
74 css::uno::makeAny(module
));
76 css::uno::Reference
< css::container::XHierarchicalNameAccess
>(
77 getConfigurationProvider()->createInstanceWithArguments(
78 OUString("com.sun.star.configuration.ConfigurationAccess"),
80 css::uno::UNO_QUERY_THROW
)->
81 getByHierarchicalName(path
).get
< OUString
>();
84 struct theConfigManager
:
85 public rtl::Static
< utl::ConfigManager
, theConfigManager
>
90 OUString
utl::ConfigManager::getAboutBoxProductVersion() {
91 return getConfigurationString(
92 OUString("/org.openoffice.Setup"),
93 OUString("Product/ooSetupVersionAboutBox"));
96 OUString
utl::ConfigManager::getAboutBoxProductVersionSuffix() {
97 return getConfigurationString(
98 OUString("/org.openoffice.Setup"),
99 OUString("Product/ooSetupVersionAboutBoxSuffix"));
102 OUString
utl::ConfigManager::getDefaultCurrency() {
103 return getConfigurationString(
104 OUString("/org.openoffice.Setup"),
105 OUString("L10N/ooSetupCurrency"));
108 OUString
utl::ConfigManager::getLocale() {
109 return getConfigurationString(
110 OUString("/org.openoffice.Setup"),
111 OUString("L10N/ooLocale"));
114 OUString
utl::ConfigManager::getProductExtension() {
115 return getConfigurationString(
116 OUString("/org.openoffice.Setup"),
117 OUString("Product/ooSetupExtension"));
120 OUString
utl::ConfigManager::getProductName() {
121 return getConfigurationString(
122 OUString("/org.openoffice.Setup"),
123 OUString("Product/ooName"));
126 OUString
utl::ConfigManager::getProductVersion() {
127 return getConfigurationString(
128 OUString("/org.openoffice.Setup"),
129 OUString("Product/ooSetupVersion"));
132 OUString
utl::ConfigManager::getProductXmlFileFormat() {
133 return getConfigurationString(
134 OUString("/org.openoffice.Setup"),
135 OUString("Product/ooXMLFileFormatName"));
138 OUString
utl::ConfigManager::getProductXmlFileFormatVersion() {
139 return getConfigurationString(
140 OUString("/org.openoffice.Setup"),
141 OUString("Product/ooXMLFileFormatVersion"));
144 OUString
utl::ConfigManager::getVendor() {
145 return getConfigurationString(
146 OUString("/org.openoffice.Setup"),
147 OUString("Product/ooVendor"));
150 OUString
utl::ConfigManager::getWriterCompatibilityVersionOOo_1_1() {
151 return getConfigurationString(
152 OUString("/org.openoffice.Office.Compatibility"),
153 OUString("WriterCompatibilityVersion/OOo11"));
156 void utl::ConfigManager::storeConfigItems() {
157 getConfigManager().doStoreConfigItems();
160 utl::ConfigManager
& utl::ConfigManager::getConfigManager() {
161 return theConfigManager::get();
164 css::uno::Reference
< css::container::XHierarchicalNameAccess
>
165 utl::ConfigManager::acquireTree(utl::ConfigItem
& item
) {
166 css::uno::Sequence
< css::uno::Any
> args(1);
167 args
[0] <<= css::beans::NamedValue(
168 OUString("nodepath"),
170 OUString("/org.openoffice.") + item
.GetSubTreeName()));
171 if ((item
.GetMode() & CONFIG_MODE_ALL_LOCALES
) != 0) {
173 args
[1] <<= css::beans::NamedValue(OUString("locale"), css::uno::makeAny(OUString("*")));
175 return css::uno::Reference
< css::container::XHierarchicalNameAccess
>(
176 getConfigurationProvider()->createInstanceWithArguments(
177 OUString("com.sun.star.configuration.ConfigurationUpdateAccess"),
179 css::uno::UNO_QUERY_THROW
);
182 utl::ConfigManager::ConfigManager() {}
184 utl::ConfigManager::~ConfigManager() {
185 OSL_ASSERT(items_
.empty());
188 css::uno::Reference
< css::container::XHierarchicalNameAccess
>
189 utl::ConfigManager::addConfigItem(utl::ConfigItem
& item
) {
190 RegisterConfigItemHelper
reg(*this, item
);
191 css::uno::Reference
< css::container::XHierarchicalNameAccess
> tree(
197 void utl::ConfigManager::removeConfigItem(utl::ConfigItem
& item
) {
198 for (std::list
< ConfigItem
* >::iterator
i(items_
.begin());
199 i
!= items_
.end(); ++i
)
208 void utl::ConfigManager::registerConfigItem(utl::ConfigItem
* item
) {
209 OSL_ASSERT(item
!= 0);
210 items_
.push_back(item
);
213 void utl::ConfigManager::doStoreConfigItems() {
214 for (std::list
< ConfigItem
* >::iterator
i(items_
.begin());
215 i
!= items_
.end(); ++i
)
217 if ((*i
)->IsModified()) {
219 (*i
)->ClearModified();
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */