Line data Source code
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 :
20 : #include "sal/config.h"
21 :
22 : #include <list>
23 :
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"
39 :
40 : namespace {
41 :
42 : class RegisterConfigItemHelper: private boost::noncopyable {
43 : public:
44 10400 : RegisterConfigItemHelper(
45 : utl::ConfigManager & manager, utl::ConfigItem & item):
46 10400 : manager_(manager), item_(&item)
47 : {
48 10400 : manager.registerConfigItem(item_);
49 10400 : }
50 :
51 20800 : ~RegisterConfigItemHelper() {
52 10400 : if (item_ != 0) {
53 0 : manager_.removeConfigItem(*item_);
54 : }
55 10400 : }
56 :
57 10400 : void keep() { item_ = 0; }
58 :
59 : private:
60 : utl::ConfigManager & manager_;
61 : utl::ConfigItem * item_;
62 : };
63 :
64 : css::uno::Reference< css::lang::XMultiServiceFactory >
65 31439 : getConfigurationProvider() {
66 31439 : return css::configuration::theDefaultProvider::get( comphelper::getProcessComponentContext() );
67 : }
68 :
69 20518 : OUString getConfigurationString(OUString const & module, OUString const & path)
70 : {
71 20518 : css::uno::Sequence< css::uno::Any > args(1);
72 41036 : args[0] <<= css::beans::NamedValue(
73 : OUString("nodepath"),
74 20518 : css::uno::makeAny(module));
75 : return
76 : css::uno::Reference< css::container::XHierarchicalNameAccess >(
77 41036 : getConfigurationProvider()->createInstanceWithArguments(
78 : OUString("com.sun.star.configuration.ConfigurationAccess"),
79 20518 : args),
80 41036 : css::uno::UNO_QUERY_THROW)->
81 41036 : getByHierarchicalName(path).get< OUString >();
82 : }
83 :
84 : struct theConfigManager:
85 : public rtl::Static< utl::ConfigManager, theConfigManager >
86 : {};
87 :
88 : }
89 :
90 760 : OUString utl::ConfigManager::getAboutBoxProductVersion() {
91 : return getConfigurationString(
92 : OUString("/org.openoffice.Setup"),
93 760 : OUString("Product/ooSetupVersionAboutBox"));
94 : }
95 :
96 760 : OUString utl::ConfigManager::getAboutBoxProductVersionSuffix() {
97 : return getConfigurationString(
98 : OUString("/org.openoffice.Setup"),
99 760 : OUString("Product/ooSetupVersionAboutBoxSuffix"));
100 : }
101 :
102 15 : OUString utl::ConfigManager::getDefaultCurrency() {
103 : return getConfigurationString(
104 : OUString("/org.openoffice.Setup"),
105 15 : OUString("L10N/ooSetupCurrency"));
106 : }
107 :
108 569 : OUString utl::ConfigManager::getLocale() {
109 : return getConfigurationString(
110 : OUString("/org.openoffice.Setup"),
111 569 : OUString("L10N/ooLocale"));
112 : }
113 :
114 1104 : OUString utl::ConfigManager::getProductExtension() {
115 : return getConfigurationString(
116 : OUString("/org.openoffice.Setup"),
117 1104 : OUString("Product/ooSetupExtension"));
118 : }
119 :
120 13911 : OUString utl::ConfigManager::getProductName() {
121 : return getConfigurationString(
122 : OUString("/org.openoffice.Setup"),
123 13911 : OUString("Product/ooName"));
124 : }
125 :
126 1879 : OUString utl::ConfigManager::getProductVersion() {
127 : return getConfigurationString(
128 : OUString("/org.openoffice.Setup"),
129 1879 : OUString("Product/ooSetupVersion"));
130 : }
131 :
132 760 : OUString utl::ConfigManager::getProductXmlFileFormat() {
133 : return getConfigurationString(
134 : OUString("/org.openoffice.Setup"),
135 760 : OUString("Product/ooXMLFileFormatName"));
136 : }
137 :
138 760 : OUString utl::ConfigManager::getProductXmlFileFormatVersion() {
139 : return getConfigurationString(
140 : OUString("/org.openoffice.Setup"),
141 760 : OUString("Product/ooXMLFileFormatVersion"));
142 : }
143 :
144 0 : OUString utl::ConfigManager::getVendor() {
145 : return getConfigurationString(
146 : OUString("/org.openoffice.Setup"),
147 0 : OUString("Product/ooVendor"));
148 : }
149 :
150 0 : OUString utl::ConfigManager::getWriterCompatibilityVersionOOo_1_1() {
151 : return getConfigurationString(
152 : OUString("/org.openoffice.Office.Compatibility"),
153 0 : OUString("WriterCompatibilityVersion/OOo11"));
154 : }
155 :
156 166 : void utl::ConfigManager::storeConfigItems() {
157 166 : getConfigManager().doStoreConfigItems();
158 166 : }
159 :
160 10566 : utl::ConfigManager & utl::ConfigManager::getConfigManager() {
161 10566 : return theConfigManager::get();
162 : }
163 :
164 : css::uno::Reference< css::container::XHierarchicalNameAccess >
165 10921 : utl::ConfigManager::acquireTree(utl::ConfigItem & item) {
166 10921 : css::uno::Sequence< css::uno::Any > args(1);
167 21842 : args[0] <<= css::beans::NamedValue(
168 : OUString("nodepath"),
169 : css::uno::makeAny(
170 32763 : OUString("/org.openoffice.") + item.GetSubTreeName()));
171 10921 : if ((item.GetMode() & CONFIG_MODE_ALL_LOCALES) != 0) {
172 23 : args.realloc(2);
173 23 : args[1] <<= css::beans::NamedValue(OUString("locale"), css::uno::makeAny(OUString("*")));
174 : }
175 : return css::uno::Reference< css::container::XHierarchicalNameAccess >(
176 21842 : getConfigurationProvider()->createInstanceWithArguments(
177 : OUString("com.sun.star.configuration.ConfigurationUpdateAccess"),
178 10921 : args),
179 21842 : css::uno::UNO_QUERY_THROW);
180 : }
181 :
182 152 : utl::ConfigManager::ConfigManager() {}
183 :
184 152 : utl::ConfigManager::~ConfigManager() {
185 : OSL_ASSERT(items_.empty());
186 152 : }
187 :
188 : css::uno::Reference< css::container::XHierarchicalNameAccess >
189 10400 : utl::ConfigManager::addConfigItem(utl::ConfigItem & item) {
190 10400 : RegisterConfigItemHelper reg(*this, item);
191 : css::uno::Reference< css::container::XHierarchicalNameAccess > tree(
192 10400 : acquireTree(item));
193 10400 : reg.keep();
194 10400 : return tree;
195 : }
196 :
197 9522 : void utl::ConfigManager::removeConfigItem(utl::ConfigItem & item) {
198 920241 : for (std::list< ConfigItem * >::iterator i(items_.begin());
199 613494 : i != items_.end(); ++i)
200 : {
201 306747 : if (*i == &item) {
202 9522 : items_.erase(i);
203 9522 : break;
204 : }
205 : }
206 9522 : }
207 :
208 10400 : void utl::ConfigManager::registerConfigItem(utl::ConfigItem * item) {
209 : OSL_ASSERT(item != 0);
210 10400 : items_.push_back(item);
211 10400 : }
212 :
213 166 : void utl::ConfigManager::doStoreConfigItems() {
214 10488 : for (std::list< ConfigItem * >::iterator i(items_.begin());
215 6992 : i != items_.end(); ++i)
216 : {
217 3330 : if ((*i)->IsModified()) {
218 200 : (*i)->Commit();
219 200 : (*i)->ClearModified();
220 : }
221 : }
222 166 : }
223 :
224 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|