1 /*************************************************************************
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * Copyright 2000, 2010 Oracle and/or its affiliates.
6 * OpenOffice.org - a multi-platform office productivity suite
8 * This file is part of OpenOffice.org.
10 * OpenOffice.org is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License version 3
12 * only, as published by the Free Software Foundation.
14 * OpenOffice.org is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License version 3 for more details
18 * (a copy is included in the LICENSE file that accompanied this code).
20 * You should have received a copy of the GNU Lesser General Public License
21 * version 3 along with OpenOffice.org. If not, see
22 * <http://www.openoffice.org/license.html>
23 * for a copy of the LGPLv3 License.
25 ************************************************************************/
27 // MARKER(update_precomp.py): autogen include statement, do not remove
28 #include "precompiled_extensions.hxx"
31 #include "myconfigurationhelper.hxx"
32 #include <rtl/ustrbuf.hxx>
35 using namespace ::com::sun::star::lang
;
36 using namespace ::com::sun::star::uno
;
37 using ::rtl::OUString
;
38 using ::rtl::OUStringBuffer
;
43 using namespace oooimprovement
;
45 static const OUString CFG_COUNTERS
= OUString::createFromAscii("Counters");
46 static const OUString CFG_ENABLINGALLOWED
= OUString::createFromAscii("EnablingAllowed");
47 static const OUString CFG_EVENTSCOUNT
= OUString::createFromAscii("LoggedEvents");
48 static const OUString CFG_EXTENSION
= OUString::createFromAscii("ooSetupExtension");
49 static const OUString CFG_FAILEDATTEMPTS
= OUString::createFromAscii("FailedAttempts");
50 static const OUString CFG_INVACCEPT
= OUString::createFromAscii("InvitationAccepted");
51 static const OUString CFG_L10N
= OUString::createFromAscii("L10N");
52 static const OUString CFG_LOCALE
= OUString::createFromAscii("ooLocale");
53 static const OUString CFG_LOGGING
= OUString::createFromAscii("/org.openoffice.Office.Logging");
54 static const OUString CFG_LOGPATH
= OUString::createFromAscii("LogPath");
55 static const OUString CFG_NAME
= OUString::createFromAscii("ooName");
56 static const OUString CFG_OFFICESTARTCOUNTDOWN
= OUString::createFromAscii("OfficeStartCounterdown");
57 static const OUString CFG_OOOIMPROVEMENT
= OUString::createFromAscii("OOoImprovement");
58 static const OUString CFG_OOOIMPROVEMENTPACK
= OUString::createFromAscii("/org.openoffice.Office.OOoImprovement.Settings");
59 static const OUString CFG_PARTICIPATION
= OUString::createFromAscii("Participation");
60 static const OUString CFG_PRODUCT
= OUString::createFromAscii("Product");
61 static const OUString CFG_REPORTCOUNT
= OUString::createFromAscii("UploadedReports");
62 static const OUString CFG_REPORTEREMAIL
= OUString::createFromAscii("ReporterEmail");
63 static const OUString CFG_SETUP
= OUString::createFromAscii("/org.openoffice.Setup");
64 static const OUString CFG_SHOWEDINV
= OUString::createFromAscii("ShowedInvitation");
65 static const OUString CFG_SOAPIDADD
= OUString::createFromAscii("SoapIdAdditions");
66 static const OUString CFG_SOAPURL
= OUString::createFromAscii("SoapUrl");
67 static const OUString CFG_UPLOAD
= OUString::createFromAscii("Upload");
68 static const OUString CFG_VERSION
= OUString::createFromAscii("ooSetupVersion");
70 static const OUString SOAPID
= OUString::createFromAscii("OpenOffice.org Improvement Report - Version 1\n");
72 static sal_Int32
incrementCfgValue(
73 const Reference
<XMultiServiceFactory
> sm
,
74 const OUString
& package
,
75 const OUString
& rel_path
,
77 sal_Int32 increment_by
)
80 Reference
<XInterface
> cfg
=
81 MyConfigurationHelper::openConfig(
83 package
, MyConfigurationHelper::E_STANDARD
);
84 MyConfigurationHelper::readRelativeKey(
86 rel_path
, key
) >>= value
;
87 value
+= increment_by
;
88 MyConfigurationHelper::writeRelativeKey(
92 MyConfigurationHelper::flush(cfg
);
97 namespace oooimprovement
99 Config::Config(const Reference
<XMultiServiceFactory
>& sf
)
100 : m_ServiceFactory(sf
)
103 OUString
Config::getSoapUrl() const
106 MyConfigurationHelper::readDirectKey(
108 CFG_OOOIMPROVEMENTPACK
, CFG_UPLOAD
, CFG_SOAPURL
,
109 MyConfigurationHelper::E_READONLY
) >>= result
;
113 OUString
Config::getSoapId() const
116 OUStringBuffer result
= SOAPID
;
117 MyConfigurationHelper::readDirectKey(
119 CFG_OOOIMPROVEMENTPACK
, CFG_UPLOAD
, CFG_SOAPIDADD
,
120 MyConfigurationHelper::E_READONLY
) >>= value
;
121 result
.append(value
);
122 return result
.makeStringAndClear();
125 OUString
Config::getReporterEmail() const
128 MyConfigurationHelper::readDirectKey(
130 CFG_OOOIMPROVEMENTPACK
, CFG_UPLOAD
, CFG_REPORTEREMAIL
,
131 MyConfigurationHelper::E_READONLY
) >>= result
;
135 OUString
Config::getLogPath() const
138 MyConfigurationHelper::readDirectKey(
140 CFG_LOGGING
, CFG_OOOIMPROVEMENT
, CFG_LOGPATH
,
141 MyConfigurationHelper::E_READONLY
) >>= result
;
145 bool Config::getEnablingAllowed() const
148 MyConfigurationHelper::readDirectKey(
150 CFG_LOGGING
, CFG_OOOIMPROVEMENT
, CFG_ENABLINGALLOWED
,
151 MyConfigurationHelper::E_READONLY
) >>= result
;
155 bool Config::getInvitationAccepted() const
158 MyConfigurationHelper::readDirectKey(
160 CFG_OOOIMPROVEMENTPACK
, CFG_PARTICIPATION
, CFG_INVACCEPT
,
161 MyConfigurationHelper::E_READONLY
) >>= result
;
165 bool Config::getShowedInvitation() const
168 MyConfigurationHelper::readDirectKey(
170 CFG_OOOIMPROVEMENTPACK
, CFG_PARTICIPATION
, CFG_SHOWEDINV
,
171 MyConfigurationHelper::E_READONLY
) >>= result
;
175 OUString
Config::getCompleteProductname() const
177 OUStringBuffer result
;
179 MyConfigurationHelper::readDirectKey(
181 CFG_SETUP
, CFG_PRODUCT
, CFG_NAME
,
182 MyConfigurationHelper::E_READONLY
) >>= value
;
183 result
.append(value
);
185 value
= OUString::createFromAscii("");
186 MyConfigurationHelper::readDirectKey(
188 CFG_SETUP
, CFG_PRODUCT
, CFG_VERSION
,
189 MyConfigurationHelper::E_READONLY
) >>= value
;
190 if(value
.getLength()) result
.appendAscii(" ").append(value
);
192 value
= OUString::createFromAscii("");
193 MyConfigurationHelper::readDirectKey(
195 CFG_SETUP
, CFG_PRODUCT
, CFG_EXTENSION
,
196 MyConfigurationHelper::E_READONLY
) >>= value
;
197 if(value
.getLength()) result
.appendAscii(" ").append(value
);
199 return result
.makeStringAndClear();
202 OUString
Config::getSetupLocale() const
205 MyConfigurationHelper::readDirectKey(
207 CFG_SETUP
, CFG_L10N
, CFG_LOCALE
,
208 MyConfigurationHelper::E_READONLY
) >>= result
;
212 sal_Int32
Config::getReportCount() const
214 sal_Int32 result
= 0;
215 MyConfigurationHelper::readDirectKey(
217 CFG_OOOIMPROVEMENTPACK
, CFG_COUNTERS
, CFG_REPORTCOUNT
,
218 MyConfigurationHelper::E_READONLY
) >>= result
;
223 sal_Int32
Config::getFailedAttempts() const
225 sal_Int32 result
= 0;
226 MyConfigurationHelper::readDirectKey(
228 CFG_OOOIMPROVEMENTPACK
, CFG_COUNTERS
, CFG_FAILEDATTEMPTS
,
229 MyConfigurationHelper::E_READONLY
) >>= result
;
234 sal_Int32
Config::getOfficeStartCounterdown() const
236 sal_Int32 result
= 0;
237 MyConfigurationHelper::readDirectKey(
239 CFG_OOOIMPROVEMENTPACK
, CFG_PARTICIPATION
, CFG_OFFICESTARTCOUNTDOWN
,
240 MyConfigurationHelper::E_READONLY
) >>= result
;
244 sal_Int32
Config::incrementReportCount(sal_Int32 by
)
246 return incrementCfgValue(
248 CFG_OOOIMPROVEMENTPACK
, CFG_COUNTERS
, CFG_REPORTCOUNT
,
252 sal_Int32
Config::incrementEventCount(sal_Int32 by
)
254 return incrementCfgValue(
256 CFG_OOOIMPROVEMENTPACK
, CFG_COUNTERS
, CFG_EVENTSCOUNT
,
260 sal_Int32
Config::incrementFailedAttempts(sal_Int32 by
)
262 return incrementCfgValue(
264 CFG_OOOIMPROVEMENTPACK
, CFG_COUNTERS
, CFG_FAILEDATTEMPTS
,
268 sal_Int32
Config::decrementOfficeStartCounterdown(sal_Int32 by
)
270 return incrementCfgValue(
272 CFG_OOOIMPROVEMENTPACK
, CFG_PARTICIPATION
, CFG_OFFICESTARTCOUNTDOWN
,
276 void Config::resetFailedAttempts()
279 MyConfigurationHelper::writeDirectKey(
281 CFG_OOOIMPROVEMENTPACK
, CFG_COUNTERS
, CFG_FAILEDATTEMPTS
,
283 MyConfigurationHelper::E_STANDARD
);
286 void Config::giveupUploading()
289 MyConfigurationHelper::writeDirectKey(
291 CFG_OOOIMPROVEMENTPACK
, CFG_PARTICIPATION
, CFG_INVACCEPT
,
293 MyConfigurationHelper::E_STANDARD
);
294 resetFailedAttempts();