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