1 /************************************************************************* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * 4 * Copyright 2000, 2010 Oracle and/or its affiliates. 5 * 6 * OpenOffice.org - a multi-platform office productivity suite 7 * 8 * This file is part of OpenOffice.org. 9 * 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. 13 * 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). 19 * 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. 24 * 25 ************************************************************************/ 26 27 // MARKER(update_precomp.py): autogen include statement, do not remove 28 #include "precompiled_extensions.hxx" 29 30 #include "config.hxx" 31 #include "myconfigurationhelper.hxx" 32 #include <rtl/ustrbuf.hxx> 33 34 35 using namespace ::com::sun::star::lang; 36 using namespace ::com::sun::star::uno; 37 using ::rtl::OUString; 38 using ::rtl::OUStringBuffer; 39 40 41 namespace 42 { 43 using namespace oooimprovement; 44 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"); 69 70 static const OUString SOAPID = OUString::createFromAscii("OpenOffice.org Improvement Report - Version 1\n"); 71 72 static sal_Int32 incrementCfgValue( 73 const Reference<XMultiServiceFactory> sm, 74 const OUString& package, 75 const OUString& rel_path, 76 const OUString& key, 77 sal_Int32 increment_by) 78 { 79 sal_Int32 value; 80 Reference<XInterface> cfg = 81 MyConfigurationHelper::openConfig( 82 sm, 83 package, MyConfigurationHelper::E_STANDARD); 84 MyConfigurationHelper::readRelativeKey( 85 cfg, 86 rel_path, key) >>= value; 87 value += increment_by; 88 MyConfigurationHelper::writeRelativeKey( 89 cfg, 90 rel_path, key, 91 Any(value)); 92 MyConfigurationHelper::flush(cfg); 93 return value; 94 }; 95 } 96 97 namespace oooimprovement 98 { 99 Config::Config(const Reference<XMultiServiceFactory>& sf) 100 : m_ServiceFactory(sf) 101 {} 102 103 OUString Config::getSoapUrl() const 104 { 105 OUString result; 106 MyConfigurationHelper::readDirectKey( 107 m_ServiceFactory, 108 CFG_OOOIMPROVEMENTPACK, CFG_UPLOAD, CFG_SOAPURL, 109 MyConfigurationHelper::E_READONLY) >>= result; 110 return result; 111 } 112 113 OUString Config::getSoapId() const 114 { 115 OUString value; 116 OUStringBuffer result = SOAPID; 117 MyConfigurationHelper::readDirectKey( 118 m_ServiceFactory, 119 CFG_OOOIMPROVEMENTPACK, CFG_UPLOAD, CFG_SOAPIDADD, 120 MyConfigurationHelper::E_READONLY) >>= value; 121 result.append(value); 122 return result.makeStringAndClear(); 123 } 124 125 OUString Config::getReporterEmail() const 126 { 127 OUString result; 128 MyConfigurationHelper::readDirectKey( 129 m_ServiceFactory, 130 CFG_OOOIMPROVEMENTPACK, CFG_UPLOAD, CFG_REPORTEREMAIL, 131 MyConfigurationHelper::E_READONLY) >>= result; 132 return result; 133 } 134 135 OUString Config::getLogPath() const 136 { 137 OUString result; 138 MyConfigurationHelper::readDirectKey( 139 m_ServiceFactory, 140 CFG_LOGGING, CFG_OOOIMPROVEMENT, CFG_LOGPATH, 141 MyConfigurationHelper::E_READONLY) >>= result; 142 return result; 143 } 144 145 bool Config::getEnablingAllowed() const 146 { 147 bool result = false; 148 MyConfigurationHelper::readDirectKey( 149 m_ServiceFactory, 150 CFG_LOGGING, CFG_OOOIMPROVEMENT, CFG_ENABLINGALLOWED, 151 MyConfigurationHelper::E_READONLY) >>= result; 152 return result; 153 } 154 155 bool Config::getInvitationAccepted() const 156 { 157 bool result = false; 158 MyConfigurationHelper::readDirectKey( 159 m_ServiceFactory, 160 CFG_OOOIMPROVEMENTPACK, CFG_PARTICIPATION, CFG_INVACCEPT, 161 MyConfigurationHelper::E_READONLY) >>= result; 162 return result; 163 }; 164 165 bool Config::getShowedInvitation() const 166 { 167 bool result = false; 168 MyConfigurationHelper::readDirectKey( 169 m_ServiceFactory, 170 CFG_OOOIMPROVEMENTPACK, CFG_PARTICIPATION, CFG_SHOWEDINV, 171 MyConfigurationHelper::E_READONLY) >>= result; 172 return result; 173 }; 174 175 OUString Config::getCompleteProductname() const 176 { 177 OUStringBuffer result; 178 OUString value; 179 MyConfigurationHelper::readDirectKey( 180 m_ServiceFactory, 181 CFG_SETUP, CFG_PRODUCT, CFG_NAME, 182 MyConfigurationHelper::E_READONLY) >>= value; 183 result.append(value); 184 185 value = OUString::createFromAscii(""); 186 MyConfigurationHelper::readDirectKey( 187 m_ServiceFactory, 188 CFG_SETUP, CFG_PRODUCT, CFG_VERSION, 189 MyConfigurationHelper::E_READONLY) >>= value; 190 if(value.getLength()) result.appendAscii(" ").append(value); 191 192 value = OUString::createFromAscii(""); 193 MyConfigurationHelper::readDirectKey( 194 m_ServiceFactory, 195 CFG_SETUP, CFG_PRODUCT, CFG_EXTENSION, 196 MyConfigurationHelper::E_READONLY) >>= value; 197 if(value.getLength()) result.appendAscii(" ").append(value); 198 199 return result.makeStringAndClear(); 200 } 201 202 OUString Config::getSetupLocale() const 203 { 204 OUString result; 205 MyConfigurationHelper::readDirectKey( 206 m_ServiceFactory, 207 CFG_SETUP, CFG_L10N, CFG_LOCALE, 208 MyConfigurationHelper::E_READONLY) >>= result; 209 return result; 210 } 211 212 sal_Int32 Config::getReportCount() const 213 { 214 sal_Int32 result = 0; 215 MyConfigurationHelper::readDirectKey( 216 m_ServiceFactory, 217 CFG_OOOIMPROVEMENTPACK, CFG_COUNTERS, CFG_REPORTCOUNT, 218 MyConfigurationHelper::E_READONLY) >>= result; 219 return result; 220 } 221 222 #ifdef FUTURE 223 sal_Int32 Config::getFailedAttempts() const 224 { 225 sal_Int32 result = 0; 226 MyConfigurationHelper::readDirectKey( 227 m_ServiceFactory, 228 CFG_OOOIMPROVEMENTPACK, CFG_COUNTERS, CFG_FAILEDATTEMPTS, 229 MyConfigurationHelper::E_READONLY) >>= result; 230 return result; 231 } 232 #endif 233 234 sal_Int32 Config::getOfficeStartCounterdown() const 235 { 236 sal_Int32 result = 0; 237 MyConfigurationHelper::readDirectKey( 238 m_ServiceFactory, 239 CFG_OOOIMPROVEMENTPACK, CFG_PARTICIPATION, CFG_OFFICESTARTCOUNTDOWN, 240 MyConfigurationHelper::E_READONLY) >>= result; 241 return result; 242 } 243 244 sal_Int32 Config::incrementReportCount(sal_Int32 by) 245 { 246 return incrementCfgValue( 247 m_ServiceFactory, 248 CFG_OOOIMPROVEMENTPACK, CFG_COUNTERS, CFG_REPORTCOUNT, 249 by); 250 } 251 252 sal_Int32 Config::incrementEventCount(sal_Int32 by) 253 { 254 return incrementCfgValue( 255 m_ServiceFactory, 256 CFG_OOOIMPROVEMENTPACK, CFG_COUNTERS, CFG_EVENTSCOUNT, 257 by); 258 } 259 260 sal_Int32 Config::incrementFailedAttempts(sal_Int32 by) 261 { 262 return incrementCfgValue( 263 m_ServiceFactory, 264 CFG_OOOIMPROVEMENTPACK, CFG_COUNTERS, CFG_FAILEDATTEMPTS, 265 by); 266 } 267 268 sal_Int32 Config::decrementOfficeStartCounterdown(sal_Int32 by) 269 { 270 return incrementCfgValue( 271 m_ServiceFactory, 272 CFG_OOOIMPROVEMENTPACK, CFG_PARTICIPATION, CFG_OFFICESTARTCOUNTDOWN, 273 -by); 274 } 275 276 void Config::resetFailedAttempts() 277 { 278 sal_Int32 zero = 0; 279 MyConfigurationHelper::writeDirectKey( 280 m_ServiceFactory, 281 CFG_OOOIMPROVEMENTPACK, CFG_COUNTERS, CFG_FAILEDATTEMPTS, 282 Any(zero), 283 MyConfigurationHelper::E_STANDARD); 284 } 285 286 void Config::giveupUploading() 287 { 288 sal_Bool f = false; 289 MyConfigurationHelper::writeDirectKey( 290 m_ServiceFactory, 291 CFG_OOOIMPROVEMENTPACK, CFG_PARTICIPATION, CFG_INVACCEPT, 292 Any(f), 293 MyConfigurationHelper::E_STANDARD); 294 resetFailedAttempts(); 295 } 296 } 297