1 /*************************************************************************
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * Copyright 2008 by Sun Microsystems, Inc.
6 * OpenOffice.org - a multi-platform office productivity suite
8 * $RCSfile: config.cxx,v $
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"
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
;
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
,
80 sal_Int32 increment_by
)
83 Reference
<XInterface
> cfg
=
84 MyConfigurationHelper::openConfig(
86 package
, MyConfigurationHelper::E_STANDARD
);
87 MyConfigurationHelper::readRelativeKey(
89 rel_path
, key
) >>= value
;
90 value
+= increment_by
;
91 MyConfigurationHelper::writeRelativeKey(
95 MyConfigurationHelper::flush(cfg
);
100 namespace oooimprovement
102 Config::Config(const Reference
<XMultiServiceFactory
>& sf
)
103 : m_ServiceFactory(sf
)
106 OUString
Config::getSoapUrl() const
109 MyConfigurationHelper::readDirectKey(
111 CFG_OOOIMPROVEMENTPACK
, CFG_UPLOAD
, CFG_SOAPURL
,
112 MyConfigurationHelper::E_READONLY
) >>= result
;
116 OUString
Config::getSoapId() const
119 OUStringBuffer result
= SOAPID
;
120 MyConfigurationHelper::readDirectKey(
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
131 MyConfigurationHelper::readDirectKey(
133 CFG_OOOIMPROVEMENTPACK
, CFG_UPLOAD
, CFG_REPORTEREMAIL
,
134 MyConfigurationHelper::E_READONLY
) >>= result
;
138 OUString
Config::getLogPath() const
141 MyConfigurationHelper::readDirectKey(
143 CFG_LOGGING
, CFG_OOOIMPROVEMENT
, CFG_LOGPATH
,
144 MyConfigurationHelper::E_READONLY
) >>= result
;
148 bool Config::getEnablingAllowed() const
151 MyConfigurationHelper::readDirectKey(
153 CFG_LOGGING
, CFG_OOOIMPROVEMENT
, CFG_ENABLINGALLOWED
,
154 MyConfigurationHelper::E_READONLY
) >>= result
;
158 bool Config::getInvitationAccepted() const
161 MyConfigurationHelper::readDirectKey(
163 CFG_OOOIMPROVEMENTPACK
, CFG_PARTICIPATION
, CFG_INVACCEPT
,
164 MyConfigurationHelper::E_READONLY
) >>= result
;
168 bool Config::getShowedInvitation() const
171 MyConfigurationHelper::readDirectKey(
173 CFG_OOOIMPROVEMENTPACK
, CFG_PARTICIPATION
, CFG_SHOWEDINV
,
174 MyConfigurationHelper::E_READONLY
) >>= result
;
178 OUString
Config::getCompleteProductname() const
180 OUStringBuffer result
;
182 MyConfigurationHelper::readDirectKey(
184 CFG_SETUP
, CFG_PRODUCT
, CFG_NAME
,
185 MyConfigurationHelper::E_READONLY
) >>= value
;
186 result
.append(value
);
188 value
= OUString::createFromAscii("");
189 MyConfigurationHelper::readDirectKey(
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(
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
208 MyConfigurationHelper::readDirectKey(
210 CFG_SETUP
, CFG_L10N
, CFG_LOCALE
,
211 MyConfigurationHelper::E_READONLY
) >>= result
;
215 sal_Int32
Config::getReportCount() const
217 sal_Int32 result
= 0;
218 MyConfigurationHelper::readDirectKey(
220 CFG_OOOIMPROVEMENTPACK
, CFG_COUNTERS
, CFG_REPORTCOUNT
,
221 MyConfigurationHelper::E_READONLY
) >>= result
;
226 sal_Int32
Config::getFailedAttempts() const
228 sal_Int32 result
= 0;
229 MyConfigurationHelper::readDirectKey(
231 CFG_OOOIMPROVEMENTPACK
, CFG_COUNTERS
, CFG_FAILEDATTEMPTS
,
232 MyConfigurationHelper::E_READONLY
) >>= result
;
237 sal_Int32
Config::getOfficeStartCounterdown() const
239 sal_Int32 result
= 0;
240 MyConfigurationHelper::readDirectKey(
242 CFG_OOOIMPROVEMENTPACK
, CFG_PARTICIPATION
, CFG_OFFICESTARTCOUNTDOWN
,
243 MyConfigurationHelper::E_READONLY
) >>= result
;
247 sal_Int32
Config::incrementReportCount(sal_Int32 by
)
249 return incrementCfgValue(
251 CFG_OOOIMPROVEMENTPACK
, CFG_COUNTERS
, CFG_REPORTCOUNT
,
255 sal_Int32
Config::incrementEventCount(sal_Int32 by
)
257 return incrementCfgValue(
259 CFG_OOOIMPROVEMENTPACK
, CFG_COUNTERS
, CFG_EVENTSCOUNT
,
263 sal_Int32
Config::incrementFailedAttempts(sal_Int32 by
)
265 return incrementCfgValue(
267 CFG_OOOIMPROVEMENTPACK
, CFG_COUNTERS
, CFG_FAILEDATTEMPTS
,
271 sal_Int32
Config::decrementOfficeStartCounterdown(sal_Int32 by
)
273 return incrementCfgValue(
275 CFG_OOOIMPROVEMENTPACK
, CFG_PARTICIPATION
, CFG_OFFICESTARTCOUNTDOWN
,
279 void Config::resetFailedAttempts()
282 MyConfigurationHelper::writeDirectKey(
284 CFG_OOOIMPROVEMENTPACK
, CFG_COUNTERS
, CFG_FAILEDATTEMPTS
,
286 MyConfigurationHelper::E_STANDARD
);
289 void Config::giveupUploading()
292 MyConfigurationHelper::writeDirectKey(
294 CFG_OOOIMPROVEMENTPACK
, CFG_PARTICIPATION
, CFG_INVACCEPT
,
296 MyConfigurationHelper::E_STANDARD
);
297 resetFailedAttempts();