merge the formfield patch from ooo-build
[ooovba.git] / extensions / source / oooimprovement / config.cxx
blob11dd7d67832eecbf83cc8f3996687a279ed1937a
1 /*************************************************************************
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3 *
4 * Copyright 2008 by Sun Microsystems, Inc.
6 * OpenOffice.org - a multi-platform office productivity suite
8 * $RCSfile: config.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
28 ************************************************************************/
30 // MARKER(update_precomp.py): autogen include statement, do not remove
31 #include "precompiled_extensions.hxx"
33 #include "config.hxx"
34 #include "myconfigurationhelper.hxx"
35 #include <rtl/ustrbuf.hxx>
38 using namespace ::com::sun::star::lang;
39 using namespace ::com::sun::star::uno;
40 using ::rtl::OUString;
41 using ::rtl::OUStringBuffer;
44 namespace
46 using namespace oooimprovement;
48 static const OUString CFG_COUNTERS = OUString::createFromAscii("Counters");
49 static const OUString CFG_ENABLINGALLOWED = OUString::createFromAscii("EnablingAllowed");
50 static const OUString CFG_EVENTSCOUNT = OUString::createFromAscii("LoggedEvents");
51 static const OUString CFG_EXTENSION = OUString::createFromAscii("ooSetupExtension");
52 static const OUString CFG_FAILEDATTEMPTS = OUString::createFromAscii("FailedAttempts");
53 static const OUString CFG_INVACCEPT = OUString::createFromAscii("InvitationAccepted");
54 static const OUString CFG_L10N = OUString::createFromAscii("L10N");
55 static const OUString CFG_LOCALE = OUString::createFromAscii("ooLocale");
56 static const OUString CFG_LOGGING = OUString::createFromAscii("/org.openoffice.Office.Logging");
57 static const OUString CFG_LOGPATH = OUString::createFromAscii("LogPath");
58 static const OUString CFG_NAME = OUString::createFromAscii("ooName");
59 static const OUString CFG_OFFICESTARTCOUNTDOWN = OUString::createFromAscii("OfficeStartCounterdown");
60 static const OUString CFG_OOOIMPROVEMENT = OUString::createFromAscii("OOoImprovement");
61 static const OUString CFG_OOOIMPROVEMENTPACK = OUString::createFromAscii("/org.openoffice.Office.OOoImprovement.Settings");
62 static const OUString CFG_PARTICIPATION = OUString::createFromAscii("Participation");
63 static const OUString CFG_PRODUCT = OUString::createFromAscii("Product");
64 static const OUString CFG_REPORTCOUNT = OUString::createFromAscii("UploadedReports");
65 static const OUString CFG_REPORTEREMAIL = OUString::createFromAscii("ReporterEmail");
66 static const OUString CFG_SETUP = OUString::createFromAscii("/org.openoffice.Setup");
67 static const OUString CFG_SHOWEDINV = OUString::createFromAscii("ShowedInvitation");
68 static const OUString CFG_SOAPIDADD = OUString::createFromAscii("SoapIdAdditions");
69 static const OUString CFG_SOAPURL = OUString::createFromAscii("SoapUrl");
70 static const OUString CFG_UPLOAD = OUString::createFromAscii("Upload");
71 static const OUString CFG_VERSION = OUString::createFromAscii("ooSetupVersion");
73 static const OUString SOAPID = OUString::createFromAscii("OpenOffice.org Improvement Report - Version 1\n");
75 static sal_Int32 incrementCfgValue(
76 const Reference<XMultiServiceFactory> sm,
77 const OUString& package,
78 const OUString& rel_path,
79 const OUString& key,
80 sal_Int32 increment_by)
82 sal_Int32 value;
83 Reference<XInterface> cfg =
84 MyConfigurationHelper::openConfig(
85 sm,
86 package, MyConfigurationHelper::E_STANDARD);
87 MyConfigurationHelper::readRelativeKey(
88 cfg,
89 rel_path, key) >>= value;
90 value += increment_by;
91 MyConfigurationHelper::writeRelativeKey(
92 cfg,
93 rel_path, key,
94 Any(value));
95 MyConfigurationHelper::flush(cfg);
96 return value;
100 namespace oooimprovement
102 Config::Config(const Reference<XMultiServiceFactory>& sf)
103 : m_ServiceFactory(sf)
106 OUString Config::getSoapUrl() const
108 OUString result;
109 MyConfigurationHelper::readDirectKey(
110 m_ServiceFactory,
111 CFG_OOOIMPROVEMENTPACK, CFG_UPLOAD, CFG_SOAPURL,
112 MyConfigurationHelper::E_READONLY) >>= result;
113 return result;
116 OUString Config::getSoapId() const
118 OUString value;
119 OUStringBuffer result = SOAPID;
120 MyConfigurationHelper::readDirectKey(
121 m_ServiceFactory,
122 CFG_OOOIMPROVEMENTPACK, CFG_UPLOAD, CFG_SOAPIDADD,
123 MyConfigurationHelper::E_READONLY) >>= value;
124 result.append(value);
125 return result.makeStringAndClear();
128 OUString Config::getReporterEmail() const
130 OUString result;
131 MyConfigurationHelper::readDirectKey(
132 m_ServiceFactory,
133 CFG_OOOIMPROVEMENTPACK, CFG_UPLOAD, CFG_REPORTEREMAIL,
134 MyConfigurationHelper::E_READONLY) >>= result;
135 return result;
138 OUString Config::getLogPath() const
140 OUString result;
141 MyConfigurationHelper::readDirectKey(
142 m_ServiceFactory,
143 CFG_LOGGING, CFG_OOOIMPROVEMENT, CFG_LOGPATH,
144 MyConfigurationHelper::E_READONLY) >>= result;
145 return result;
148 bool Config::getEnablingAllowed() const
150 bool result = false;
151 MyConfigurationHelper::readDirectKey(
152 m_ServiceFactory,
153 CFG_LOGGING, CFG_OOOIMPROVEMENT, CFG_ENABLINGALLOWED,
154 MyConfigurationHelper::E_READONLY) >>= result;
155 return result;
158 bool Config::getInvitationAccepted() const
160 bool result = false;
161 MyConfigurationHelper::readDirectKey(
162 m_ServiceFactory,
163 CFG_OOOIMPROVEMENTPACK, CFG_PARTICIPATION, CFG_INVACCEPT,
164 MyConfigurationHelper::E_READONLY) >>= result;
165 return result;
168 bool Config::getShowedInvitation() const
170 bool result = false;
171 MyConfigurationHelper::readDirectKey(
172 m_ServiceFactory,
173 CFG_OOOIMPROVEMENTPACK, CFG_PARTICIPATION, CFG_SHOWEDINV,
174 MyConfigurationHelper::E_READONLY) >>= result;
175 return result;
178 OUString Config::getCompleteProductname() const
180 OUStringBuffer result;
181 OUString value;
182 MyConfigurationHelper::readDirectKey(
183 m_ServiceFactory,
184 CFG_SETUP, CFG_PRODUCT, CFG_NAME,
185 MyConfigurationHelper::E_READONLY) >>= value;
186 result.append(value);
188 value = OUString::createFromAscii("");
189 MyConfigurationHelper::readDirectKey(
190 m_ServiceFactory,
191 CFG_SETUP, CFG_PRODUCT, CFG_VERSION,
192 MyConfigurationHelper::E_READONLY) >>= value;
193 if(value.getLength()) result.appendAscii(" ").append(value);
195 value = OUString::createFromAscii("");
196 MyConfigurationHelper::readDirectKey(
197 m_ServiceFactory,
198 CFG_SETUP, CFG_PRODUCT, CFG_EXTENSION,
199 MyConfigurationHelper::E_READONLY) >>= value;
200 if(value.getLength()) result.appendAscii(" ").append(value);
202 return result.makeStringAndClear();
205 OUString Config::getSetupLocale() const
207 OUString result;
208 MyConfigurationHelper::readDirectKey(
209 m_ServiceFactory,
210 CFG_SETUP, CFG_L10N, CFG_LOCALE,
211 MyConfigurationHelper::E_READONLY) >>= result;
212 return result;
215 sal_Int32 Config::getReportCount() const
217 sal_Int32 result = 0;
218 MyConfigurationHelper::readDirectKey(
219 m_ServiceFactory,
220 CFG_OOOIMPROVEMENTPACK, CFG_COUNTERS, CFG_REPORTCOUNT,
221 MyConfigurationHelper::E_READONLY) >>= result;
222 return result;
225 #ifdef FUTURE
226 sal_Int32 Config::getFailedAttempts() const
228 sal_Int32 result = 0;
229 MyConfigurationHelper::readDirectKey(
230 m_ServiceFactory,
231 CFG_OOOIMPROVEMENTPACK, CFG_COUNTERS, CFG_FAILEDATTEMPTS,
232 MyConfigurationHelper::E_READONLY) >>= result;
233 return result;
235 #endif
237 sal_Int32 Config::getOfficeStartCounterdown() const
239 sal_Int32 result = 0;
240 MyConfigurationHelper::readDirectKey(
241 m_ServiceFactory,
242 CFG_OOOIMPROVEMENTPACK, CFG_PARTICIPATION, CFG_OFFICESTARTCOUNTDOWN,
243 MyConfigurationHelper::E_READONLY) >>= result;
244 return result;
247 sal_Int32 Config::incrementReportCount(sal_Int32 by)
249 return incrementCfgValue(
250 m_ServiceFactory,
251 CFG_OOOIMPROVEMENTPACK, CFG_COUNTERS, CFG_REPORTCOUNT,
252 by);
255 sal_Int32 Config::incrementEventCount(sal_Int32 by)
257 return incrementCfgValue(
258 m_ServiceFactory,
259 CFG_OOOIMPROVEMENTPACK, CFG_COUNTERS, CFG_EVENTSCOUNT,
260 by);
263 sal_Int32 Config::incrementFailedAttempts(sal_Int32 by)
265 return incrementCfgValue(
266 m_ServiceFactory,
267 CFG_OOOIMPROVEMENTPACK, CFG_COUNTERS, CFG_FAILEDATTEMPTS,
268 by);
271 sal_Int32 Config::decrementOfficeStartCounterdown(sal_Int32 by)
273 return incrementCfgValue(
274 m_ServiceFactory,
275 CFG_OOOIMPROVEMENTPACK, CFG_PARTICIPATION, CFG_OFFICESTARTCOUNTDOWN,
276 -by);
279 void Config::resetFailedAttempts()
281 sal_Int32 zero = 0;
282 MyConfigurationHelper::writeDirectKey(
283 m_ServiceFactory,
284 CFG_OOOIMPROVEMENTPACK, CFG_COUNTERS, CFG_FAILEDATTEMPTS,
285 Any(zero),
286 MyConfigurationHelper::E_STANDARD);
289 void Config::giveupUploading()
291 sal_Bool f = false;
292 MyConfigurationHelper::writeDirectKey(
293 m_ServiceFactory,
294 CFG_OOOIMPROVEMENTPACK, CFG_PARTICIPATION, CFG_INVACCEPT,
295 Any(f),
296 MyConfigurationHelper::E_STANDARD);
297 resetFailedAttempts();