Branch data 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/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"
38 : :
39 : : namespace {
40 : :
41 : : namespace css = com::sun::star;
42 : :
43 : : class RegisterConfigItemHelper: private boost::noncopyable {
44 : : public:
45 : 17060 : RegisterConfigItemHelper(
46 : : utl::ConfigManager & manager, utl::ConfigItem & item):
47 : 17060 : manager_(manager), item_(&item)
48 : : {
49 [ + - ]: 17060 : manager.registerConfigItem(item_);
50 : 17060 : }
51 : :
52 : 17060 : ~RegisterConfigItemHelper() {
53 [ - + ]: 17060 : if (item_ != 0) {
54 [ # # ]: 0 : manager_.removeConfigItem(*item_);
55 : : }
56 : 17060 : }
57 : :
58 : 17060 : void keep() { item_ = 0; }
59 : :
60 : : private:
61 : : utl::ConfigManager & manager_;
62 : : utl::ConfigItem * item_;
63 : : };
64 : :
65 : : css::uno::Reference< css::lang::XMultiServiceFactory >
66 : 60178 : getConfigurationProvider() {
67 : : return css::uno::Reference< css::lang::XMultiServiceFactory >(
68 : : (css::uno::Reference< css::lang::XMultiServiceFactory >(
69 [ + - ][ + - ]: 120356 : comphelper::getProcessServiceFactory(), css::uno::UNO_SET_THROW)->
70 : : createInstance(
71 : : rtl::OUString(
72 : : RTL_CONSTASCII_USTRINGPARAM(
73 : 60178 : "com.sun.star.configuration.ConfigurationProvider")))),
74 [ + - ][ + - ]: 120356 : css::uno::UNO_QUERY_THROW);
[ + - ]
75 : : }
76 : :
77 : 42025 : rtl::OUString getConfigurationString(
78 : : rtl::OUString const & module, rtl::OUString const & path)
79 : : {
80 [ + - ]: 42025 : css::uno::Sequence< css::uno::Any > args(1);
81 [ + - ]: 42025 : args[0] <<= css::beans::NamedValue(
82 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("nodepath")),
83 [ + - ][ + - ]: 84050 : css::uno::makeAny(module));
[ + - ]
84 : : return
85 : : css::uno::Reference< css::container::XHierarchicalNameAccess >(
86 [ + - ][ + - ]: 84050 : getConfigurationProvider()->createInstanceWithArguments(
87 : : rtl::OUString(
88 : : RTL_CONSTASCII_USTRINGPARAM(
89 : : "com.sun.star.configuration.ConfigurationAccess")),
90 : 42025 : args),
91 [ + - ][ + - ]: 84050 : css::uno::UNO_QUERY_THROW)->
[ + - ][ + - ]
92 [ + - ][ + - ]: 84050 : getByHierarchicalName(path).get< rtl::OUString >();
[ + - ]
93 : : }
94 : :
95 : : struct theConfigManager:
96 : : public rtl::Static< utl::ConfigManager, theConfigManager >
97 : : {};
98 : :
99 : : }
100 : :
101 : 1384 : rtl::OUString utl::ConfigManager::getAboutBoxProductVersion() {
102 : : return getConfigurationString(
103 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
104 : : rtl::OUString(
105 [ + - ][ + - ]: 1384 : RTL_CONSTASCII_USTRINGPARAM("Product/ooSetupVersionAboutBox")));
106 : : }
107 : :
108 : 1384 : rtl::OUString utl::ConfigManager::getAboutBoxProductVersionSuffix() {
109 : : return getConfigurationString(
110 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
111 : : rtl::OUString(
112 [ + - ][ + - ]: 1384 : RTL_CONSTASCII_USTRINGPARAM("Product/ooSetupVersionAboutBoxSuffix")));
113 : : }
114 : :
115 : 29 : rtl::OUString utl::ConfigManager::getDefaultCurrency() {
116 : : return getConfigurationString(
117 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
118 [ + - ][ + - ]: 29 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("L10N/ooSetupCurrency")));
119 : : }
120 : :
121 : 1023 : rtl::OUString utl::ConfigManager::getLocale() {
122 : : return getConfigurationString(
123 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
124 [ + - ][ + - ]: 1023 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("L10N/ooLocale")));
125 : : }
126 : :
127 : 9170 : rtl::OUString utl::ConfigManager::getProductExtension() {
128 : : return getConfigurationString(
129 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
130 [ + - ][ + - ]: 9170 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Product/ooSetupExtension")));
131 : : }
132 : :
133 : 23304 : rtl::OUString utl::ConfigManager::getProductName() {
134 : : return getConfigurationString(
135 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
136 [ + - ][ + - ]: 23304 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Product/ooName")));
137 : : }
138 : :
139 : 2963 : rtl::OUString utl::ConfigManager::getProductVersion() {
140 : : return getConfigurationString(
141 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
142 [ + - ][ + - ]: 2963 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Product/ooSetupVersion")));
143 : : }
144 : :
145 : 1384 : rtl::OUString utl::ConfigManager::getProductXmlFileFormat() {
146 : : return getConfigurationString(
147 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
148 : : rtl::OUString(
149 [ + - ][ + - ]: 1384 : RTL_CONSTASCII_USTRINGPARAM("Product/ooXMLFileFormatName")));
150 : : }
151 : :
152 : 1384 : rtl::OUString utl::ConfigManager::getProductXmlFileFormatVersion() {
153 : : return getConfigurationString(
154 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
155 : : rtl::OUString(
156 [ + - ][ + - ]: 1384 : RTL_CONSTASCII_USTRINGPARAM("Product/ooXMLFileFormatVersion")));
157 : : }
158 : :
159 : 0 : rtl::OUString utl::ConfigManager::getVendor() {
160 : : return getConfigurationString(
161 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
162 [ # # ][ # # ]: 0 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Product/ooVendor")));
163 : : }
164 : :
165 : 0 : rtl::OUString utl::ConfigManager::getWriterCompatibilityVersionOOo_1_1() {
166 : : return getConfigurationString(
167 : : rtl::OUString(
168 : : RTL_CONSTASCII_USTRINGPARAM(
169 : : "/org.openoffice.Office.Compatibility")),
170 : : rtl::OUString(
171 [ # # ][ # # ]: 0 : RTL_CONSTASCII_USTRINGPARAM("WriterCompatibilityVersion/OOo11")));
172 : : }
173 : :
174 : 316 : void utl::ConfigManager::storeConfigItems() {
175 : 316 : getConfigManager().doStoreConfigItems();
176 : 316 : }
177 : :
178 : 17376 : utl::ConfigManager & utl::ConfigManager::getConfigManager() {
179 : 17376 : return theConfigManager::get();
180 : : }
181 : :
182 : : css::uno::Reference< css::container::XHierarchicalNameAccess >
183 : 18153 : utl::ConfigManager::acquireTree(utl::ConfigItem & item) {
184 [ + - ]: 18153 : css::uno::Sequence< css::uno::Any > args(1);
185 [ + - ]: 18153 : args[0] <<= css::beans::NamedValue(
186 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("nodepath")),
187 : : css::uno::makeAny(
188 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.")) +
189 [ + - ][ + - ]: 36306 : item.GetSubTreeName()));
[ + - ][ + - ]
190 [ + + ][ + - ]: 18153 : if ((item.GetMode() & CONFIG_MODE_ALL_LOCALES) != 0) {
191 [ + - ]: 24 : args.realloc(2);
192 [ + - ]: 24 : args[1] <<= css::beans::NamedValue(
193 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("locale")),
194 [ + - ][ + - ]: 48 : css::uno::makeAny(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("*"))));
[ + - ][ + - ]
195 : : }
196 : : return css::uno::Reference< css::container::XHierarchicalNameAccess >(
197 [ + - ][ + - ]: 36306 : getConfigurationProvider()->createInstanceWithArguments(
198 : : rtl::OUString(
199 : : RTL_CONSTASCII_USTRINGPARAM(
200 : : "com.sun.star.configuration.ConfigurationUpdateAccess")),
201 : 18153 : args),
202 [ + - ][ + - ]: 36306 : css::uno::UNO_QUERY_THROW);
[ + - ][ + - ]
203 : : }
204 : :
205 [ + - ]: 266 : utl::ConfigManager::ConfigManager() {}
206 : :
207 : 266 : utl::ConfigManager::~ConfigManager() {
208 : : OSL_ASSERT(items_.empty());
209 : 266 : }
210 : :
211 : : css::uno::Reference< css::container::XHierarchicalNameAccess >
212 : 17060 : utl::ConfigManager::addConfigItem(utl::ConfigItem & item) {
213 [ + - ]: 17060 : RegisterConfigItemHelper reg(*this, item);
214 : : css::uno::Reference< css::container::XHierarchicalNameAccess > tree(
215 [ + - ]: 17060 : acquireTree(item));
216 : 17060 : reg.keep();
217 [ + - ]: 17060 : return tree;
218 : : }
219 : :
220 : 15225 : void utl::ConfigManager::removeConfigItem(utl::ConfigItem & item) {
221 [ + - + - ]: 1008914 : for (std::list< ConfigItem * >::iterator i(items_.begin());
[ + - ]
222 : 504457 : i != items_.end(); ++i)
223 : : {
224 [ + - ][ + + ]: 504457 : if (*i == &item) {
225 [ + - ]: 15225 : items_.erase(i);
226 : 15225 : break;
227 : : }
228 : : }
229 : 15225 : }
230 : :
231 : 17060 : void utl::ConfigManager::registerConfigItem(utl::ConfigItem * item) {
232 : : OSL_ASSERT(item != 0);
233 : 17060 : items_.push_back(item);
234 : 17060 : }
235 : :
236 : 316 : void utl::ConfigManager::doStoreConfigItems() {
237 [ + - + - ]: 14948 : for (std::list< ConfigItem * >::iterator i(items_.begin());
[ + + ]
238 : 7474 : i != items_.end(); ++i)
239 : : {
240 [ + - ][ + - ]: 7158 : if ((*i)->IsModified()) {
[ + + ]
241 [ + - ][ + - ]: 691 : (*i)->Commit();
242 [ + - ][ + - ]: 691 : (*i)->ClearModified();
243 : : }
244 : : }
245 : 316 : }
246 : :
247 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|