1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_desktop.hxx" 30 31 #include "pages.hxx" 32 #include "wizard.hrc" 33 #include "wizard.hxx" 34 #include "migration.hxx" 35 #include <vcl/msgbox.hxx> 36 #include <vcl/mnemonic.hxx> 37 #include <vos/security.hxx> 38 #include <app.hxx> 39 #include <rtl/ustring.hxx> 40 #include <osl/file.hxx> 41 #include <unotools/bootstrap.hxx> 42 #include <unotools/configmgr.hxx> 43 #include <unotools/regoptions.hxx> 44 #include <unotools/useroptions.hxx> 45 #include <sfx2/basedlgs.hxx> 46 #include <comphelper/processfactory.hxx> 47 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 48 #include <com/sun/star/lang/XInitialization.hpp> 49 #include <com/sun/star/frame/XDesktop.hpp> 50 #include <com/sun/star/beans/XMaterialHolder.hpp> 51 #include <com/sun/star/beans/NamedValue.hpp> 52 #include <com/sun/star/container/XNameReplace.hpp> 53 #include <com/sun/star/task/XJobExecutor.hpp> 54 #include <comphelper/configurationhelper.hxx> 55 #include <rtl/bootstrap.hxx> 56 #include <rtl/ustrbuf.hxx> 57 #include <osl/file.hxx> 58 #include <osl/thread.hxx> 59 #include <unotools/bootstrap.hxx> 60 #include <tools/config.hxx> 61 62 using namespace rtl; 63 using namespace osl; 64 using namespace utl; 65 using namespace svt; 66 using namespace com::sun::star; 67 using namespace com::sun::star::frame; 68 using namespace com::sun::star::lang; 69 using namespace com::sun::star::util; 70 using namespace com::sun::star::beans; 71 using namespace com::sun::star::uno; 72 using namespace com::sun::star::container; 73 74 #define UNISTRING(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s)) 75 76 namespace desktop { 77 78 static void _setBold(FixedText& ft) 79 { 80 Font f = ft.GetControlFont(); 81 f.SetWeight(WEIGHT_BOLD); 82 ft.SetControlFont(f); 83 } 84 85 WelcomePage::WelcomePage( svt::OWizardMachine* parent, const ResId& resid, sal_Bool bLicenseNeedsAcceptance ) 86 : OWizardPage(parent, resid) 87 , m_ftHead(this, WizardResId(FT_WELCOME_HEADER)) 88 , m_ftBody(this, WizardResId(FT_WELCOME_BODY)) 89 , m_pParent(parent) 90 , m_bLicenseNeedsAcceptance( bLicenseNeedsAcceptance ) 91 , bIsEvalVersion(false) 92 , bNoEvalText(false) 93 { 94 FreeResource(); 95 96 _setBold(m_ftHead); 97 98 checkEval(); 99 100 // check for migration 101 if (Migration::checkMigration()) 102 { 103 String aText(WizardResId(STR_WELCOME_MIGRATION)); 104 // replace %OLDPRODUCT with found version name 105 aText.SearchAndReplaceAll( UniString::CreateFromAscii("%OLD_VERSION"), Migration::getOldVersionName()); 106 m_ftBody.SetText( aText ); 107 } 108 else if ( ! m_bLicenseNeedsAcceptance ) 109 { 110 String aText(WizardResId(STR_WELCOME_WITHOUT_LICENSE)); 111 m_ftBody.SetText( aText ); 112 } 113 } 114 115 116 void WelcomePage::checkEval() 117 { 118 Reference< XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory(); 119 Reference< XMaterialHolder > xHolder(xFactory->createInstance( 120 OUString::createFromAscii("com.sun.star.tab.tabreg")), UNO_QUERY); 121 if (xHolder.is()) { 122 Any aData = xHolder->getMaterial(); 123 Sequence < NamedValue > aSeq; 124 if (aData >>= aSeq) { 125 bIsEvalVersion = true; 126 for (int i=0; i< aSeq.getLength(); i++) { 127 if (aSeq[i].Name.equalsAscii("NoEvalText")) { 128 aSeq[i].Value >>= bNoEvalText; 129 } 130 } 131 } 132 } 133 } 134 135 136 void WelcomePage::ActivatePage() 137 { 138 OWizardPage::ActivatePage(); 139 // this page has no controls, so forwarding to default 140 // button (next) won't work if we grap focus 141 // GrabFocus(); 142 } 143 144 // ------------------------------------------------------------------- 145 146 class MigrationThread : public ::osl::Thread 147 { 148 public: 149 MigrationThread(); 150 151 virtual void SAL_CALL run(); 152 virtual void SAL_CALL onTerminated(); 153 }; 154 155 MigrationThread::MigrationThread() 156 { 157 } 158 159 void MigrationThread::run() 160 { 161 try 162 { 163 Migration::doMigration(); 164 } 165 catch ( uno::Exception& ) 166 { 167 } 168 } 169 170 void MigrationThread::onTerminated() 171 { 172 } 173 174 // ------------------------------------------------------------------- 175 176 MigrationPage::MigrationPage( 177 svt::OWizardMachine* parent, 178 const ResId& resid, Throbber& i_throbber ) 179 : OWizardPage(parent, resid) 180 , m_ftHead(this, WizardResId(FT_MIGRATION_HEADER)) 181 , m_ftBody(this, WizardResId(FT_MIGRATION_BODY)) 182 , m_cbMigration(this, WizardResId(CB_MIGRATION)) 183 , m_rThrobber(i_throbber) 184 , m_bMigrationDone(sal_False) 185 { 186 FreeResource(); 187 _setBold(m_ftHead); 188 189 // replace %OLDPRODUCT with found version name 190 String aText = m_ftBody.GetText(); 191 aText.SearchAndReplaceAll( UniString::CreateFromAscii("%OLDPRODUCT"), Migration::getOldVersionName()); 192 m_ftBody.SetText( aText ); 193 } 194 195 sal_Bool MigrationPage::commitPage( svt::WizardTypes::CommitPageReason _eReason ) 196 { 197 if (_eReason == svt::WizardTypes::eTravelForward && m_cbMigration.IsChecked() && !m_bMigrationDone) 198 { 199 GetParent()->EnterWait(); 200 FirstStartWizard* pWizard = dynamic_cast< FirstStartWizard* >( GetParent() ); 201 if ( pWizard ) 202 pWizard->DisableButtonsWhileMigration(); 203 204 m_rThrobber.Show(); 205 m_rThrobber.start(); 206 MigrationThread* pMigThread = new MigrationThread(); 207 pMigThread->create(); 208 209 while ( pMigThread->isRunning() ) 210 { 211 Application::Reschedule(); 212 } 213 214 m_rThrobber.stop(); 215 GetParent()->LeaveWait(); 216 // Next state will enable buttons - so no EnableButtons necessary! 217 m_rThrobber.Hide(); 218 pMigThread->join(); 219 delete pMigThread; 220 m_bMigrationDone = sal_True; 221 } 222 else 223 Migration::cancelMigration(); 224 return sal_True; 225 } 226 227 void MigrationPage::ActivatePage() 228 { 229 OWizardPage::ActivatePage(); 230 GrabFocus(); 231 } 232 233 UserPage::UserPage( svt::OWizardMachine* parent, const ResId& resid) 234 : OWizardPage(parent, resid) 235 , m_ftHead(this, WizardResId(FT_USER_HEADER)) 236 , m_ftBody(this, WizardResId(FT_USER_BODY)) 237 , m_ftFirst(this, WizardResId(FT_USER_FIRST)) 238 , m_edFirst(this, WizardResId(ED_USER_FIRST)) 239 , m_ftLast(this, WizardResId(FT_USER_LAST)) 240 , m_edLast(this, WizardResId(ED_USER_LAST)) 241 , m_ftInitials(this, WizardResId(FT_USER_INITIALS)) 242 , m_edInitials(this, WizardResId(ED_USER_INITIALS)) 243 , m_ftFather(this, WizardResId(FT_USER_FATHER)) 244 , m_edFather(this, WizardResId(ED_USER_FATHER)) 245 , m_lang(Application::GetSettings().GetUILanguage()) 246 { 247 FreeResource(); 248 _setBold(m_ftHead); 249 250 // check whether this is a russian version. otherwise 251 // we'll hide the 'Fathers name' field 252 SvtUserOptions aUserOpt; 253 m_edFirst.SetText(aUserOpt.GetFirstName()); 254 m_edLast.SetText(aUserOpt.GetLastName()); 255 #if 0 256 rtl::OUString aUserName; 257 vos::OSecurity().getUserName( aUserName ); 258 aUserOpt.SetID( aUserName ); 259 #endif 260 261 m_edInitials.SetText(aUserOpt.GetID()); 262 if (m_lang == LANGUAGE_RUSSIAN) 263 { 264 m_ftFather.Show(); 265 m_edFather.Show(); 266 m_edFather.SetText(aUserOpt.GetFathersName()); 267 } 268 } 269 270 sal_Bool UserPage::commitPage( svt::WizardTypes::CommitPageReason ) 271 { 272 SvtUserOptions aUserOpt; 273 aUserOpt.SetFirstName(m_edFirst.GetText()); 274 aUserOpt.SetLastName(m_edLast.GetText()); 275 aUserOpt.SetID( m_edInitials.GetText()); 276 277 if (m_lang == LANGUAGE_RUSSIAN) 278 aUserOpt.SetFathersName(m_edFather.GetText()); 279 280 return sal_True; 281 } 282 283 void UserPage::ActivatePage() 284 { 285 OWizardPage::ActivatePage(); 286 GrabFocus(); 287 } 288 289 // ------------------------------------------------------------------- 290 UpdateCheckPage::UpdateCheckPage( svt::OWizardMachine* parent, const ResId& resid) 291 : OWizardPage(parent, resid) 292 , m_ftHead(this, WizardResId(FT_UPDATE_CHECK_HEADER)) 293 , m_ftBody(this, WizardResId(FT_UPDATE_CHECK_BODY)) 294 , m_cbUpdateCheck(this, WizardResId(CB_UPDATE_CHECK)) 295 { 296 FreeResource(); 297 _setBold(m_ftHead); 298 } 299 300 sal_Bool UpdateCheckPage::commitPage( svt::WizardTypes::CommitPageReason _eReason ) 301 { 302 if ( _eReason == svt::WizardTypes::eTravelForward ) 303 { 304 try { 305 Reference < XNameReplace > xUpdateAccess; 306 Reference < XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() ); 307 308 xUpdateAccess = Reference < XNameReplace >( 309 xFactory->createInstance( UNISTRING( "com.sun.star.setup.UpdateCheckConfig" ) ), UNO_QUERY_THROW ); 310 311 if ( !xUpdateAccess.is() ) 312 return sal_False; 313 314 sal_Bool bAutoUpdChk = m_cbUpdateCheck.IsChecked(); 315 xUpdateAccess->replaceByName( UNISTRING("AutoCheckEnabled"), makeAny( bAutoUpdChk ) ); 316 317 Reference< XChangesBatch > xChangesBatch( xUpdateAccess, UNO_QUERY); 318 if( xChangesBatch.is() && xChangesBatch->hasPendingChanges() ) 319 xChangesBatch->commitChanges(); 320 } catch (RuntimeException) 321 { 322 } 323 } 324 325 return sal_True; 326 } 327 328 void UpdateCheckPage::ActivatePage() 329 { 330 OWizardPage::ActivatePage(); 331 GrabFocus(); 332 } 333 334 } // namespace desktop 335 336