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 rtl::OUString
getConfigurationString(
70 rtl::OUString
const & module
, rtl::OUString
const & path
)
72 css::uno::Sequence
< css::uno::Any
> args(1);
73 args
[0] <<= css::beans::NamedValue(
74 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("nodepath")),
75 css::uno::makeAny(module
));
77 css::uno::Reference
< css::container::XHierarchicalNameAccess
>(
78 getConfigurationProvider()->createInstanceWithArguments(
80 RTL_CONSTASCII_USTRINGPARAM(
81 "com.sun.star.configuration.ConfigurationAccess")),
83 css::uno::UNO_QUERY_THROW
)->
84 getByHierarchicalName(path
).get
< rtl::OUString
>();
87 struct theConfigManager
:
88 public rtl::Static
< utl::ConfigManager
, theConfigManager
>
93 rtl::OUString
utl::ConfigManager::getAboutBoxProductVersion() {
94 return getConfigurationString(
95 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
97 RTL_CONSTASCII_USTRINGPARAM("Product/ooSetupVersionAboutBox")));
100 rtl::OUString
utl::ConfigManager::getAboutBoxProductVersionSuffix() {
101 return getConfigurationString(
102 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
104 RTL_CONSTASCII_USTRINGPARAM("Product/ooSetupVersionAboutBoxSuffix")));
107 rtl::OUString
utl::ConfigManager::getDefaultCurrency() {
108 return getConfigurationString(
109 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
110 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("L10N/ooSetupCurrency")));
113 rtl::OUString
utl::ConfigManager::getLocale() {
114 return getConfigurationString(
115 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
116 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("L10N/ooLocale")));
119 rtl::OUString
utl::ConfigManager::getProductExtension() {
120 return getConfigurationString(
121 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
122 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Product/ooSetupExtension")));
125 rtl::OUString
utl::ConfigManager::getProductName() {
126 return getConfigurationString(
127 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
128 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Product/ooName")));
131 rtl::OUString
utl::ConfigManager::getProductVersion() {
132 return getConfigurationString(
133 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
134 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Product/ooSetupVersion")));
137 rtl::OUString
utl::ConfigManager::getProductXmlFileFormat() {
138 return getConfigurationString(
139 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
141 RTL_CONSTASCII_USTRINGPARAM("Product/ooXMLFileFormatName")));
144 rtl::OUString
utl::ConfigManager::getProductXmlFileFormatVersion() {
145 return getConfigurationString(
146 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
148 RTL_CONSTASCII_USTRINGPARAM("Product/ooXMLFileFormatVersion")));
151 rtl::OUString
utl::ConfigManager::getVendor() {
152 return getConfigurationString(
153 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
154 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Product/ooVendor")));
157 rtl::OUString
utl::ConfigManager::getWriterCompatibilityVersionOOo_1_1() {
158 return getConfigurationString(
160 RTL_CONSTASCII_USTRINGPARAM(
161 "/org.openoffice.Office.Compatibility")),
163 RTL_CONSTASCII_USTRINGPARAM("WriterCompatibilityVersion/OOo11")));
166 void utl::ConfigManager::storeConfigItems() {
167 getConfigManager().doStoreConfigItems();
170 utl::ConfigManager
& utl::ConfigManager::getConfigManager() {
171 return theConfigManager::get();
174 css::uno::Reference
< css::container::XHierarchicalNameAccess
>
175 utl::ConfigManager::acquireTree(utl::ConfigItem
& item
) {
176 css::uno::Sequence
< css::uno::Any
> args(1);
177 args
[0] <<= css::beans::NamedValue(
178 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("nodepath")),
180 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.")) +
181 item
.GetSubTreeName()));
182 if ((item
.GetMode() & CONFIG_MODE_ALL_LOCALES
) != 0) {
184 args
[1] <<= css::beans::NamedValue(
185 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("locale")),
186 css::uno::makeAny(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("*"))));
188 return css::uno::Reference
< css::container::XHierarchicalNameAccess
>(
189 getConfigurationProvider()->createInstanceWithArguments(
191 RTL_CONSTASCII_USTRINGPARAM(
192 "com.sun.star.configuration.ConfigurationUpdateAccess")),
194 css::uno::UNO_QUERY_THROW
);
197 utl::ConfigManager::ConfigManager() {}
199 utl::ConfigManager::~ConfigManager() {
200 OSL_ASSERT(items_
.empty());
203 css::uno::Reference
< css::container::XHierarchicalNameAccess
>
204 utl::ConfigManager::addConfigItem(utl::ConfigItem
& item
) {
205 RegisterConfigItemHelper
reg(*this, item
);
206 css::uno::Reference
< css::container::XHierarchicalNameAccess
> tree(
212 void utl::ConfigManager::removeConfigItem(utl::ConfigItem
& item
) {
213 for (std::list
< ConfigItem
* >::iterator
i(items_
.begin());
214 i
!= items_
.end(); ++i
)
223 void utl::ConfigManager::registerConfigItem(utl::ConfigItem
* item
) {
224 OSL_ASSERT(item
!= 0);
225 items_
.push_back(item
);
228 void utl::ConfigManager::doStoreConfigItems() {
229 for (std::list
< ConfigItem
* >::iterator
i(items_
.begin());
230 i
!= items_
.end(); ++i
)
232 if ((*i
)->IsModified()) {
234 (*i
)->ClearModified();
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */