merge the formfield patch from ooo-build
[ooovba.git] / desktop / source / migration / wizard.cxx
blobded4b8b7a7f2bde35d100d2a338ddbeb67ed1026
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: wizard.cxx,v $
10 * $Revision: 1.22 $
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.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_desktop.hxx"
34 #include <migration.hxx>
35 #include "wizard.hxx"
36 #include "wizard.hrc"
37 #include "pages.hxx"
38 #include "app.hxx"
40 #include <rtl/ustring.hxx>
41 #include <rtl/ustrbuf.hxx>
42 #include <rtl/string.hxx>
43 #include <rtl/strbuf.hxx>
44 #include <rtl/bootstrap.hxx>
46 #include <comphelper/processfactory.hxx>
47 #include <tools/date.hxx>
48 #include <tools/time.hxx>
49 #include <tools/datetime.hxx>
50 #include <osl/file.hxx>
51 #include <osl/time.h>
52 #include <osl/module.hxx>
53 #include <unotools/bootstrap.hxx>
54 #include <vcl/msgbox.hxx>
56 #include <com/sun/star/uno/Any.hxx>
57 #include <com/sun/star/uno/Sequence.hxx>
58 #include <com/sun/star/beans/NamedValue.hpp>
59 #include <com/sun/star/beans/XPropertySet.hpp>
60 #include <com/sun/star/beans/XPropertyState.hpp>
61 #include <com/sun/star/frame/XDesktop.hpp>
62 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
63 #include <com/sun/star/lang/XInitialization.hpp>
64 #include <com/sun/star/lang/XComponent.hpp>
65 #include <com/sun/star/util/XChangesBatch.hpp>
66 #include <com/sun/star/container/XNameReplace.hpp>
68 using namespace svt;
69 using namespace rtl;
70 using namespace osl;
71 using namespace utl;
72 using namespace com::sun::star::uno;
73 using namespace com::sun::star::lang;
74 using namespace com::sun::star::beans;
75 using namespace com::sun::star::util;
76 using namespace com::sun::star::container;
78 #define UNISTRING(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
80 namespace desktop
83 const FirstStartWizard::WizardState FirstStartWizard::STATE_WELCOME = 0;
84 const FirstStartWizard::WizardState FirstStartWizard::STATE_LICENSE = 1;
85 const FirstStartWizard::WizardState FirstStartWizard::STATE_MIGRATION = 2;
86 const FirstStartWizard::WizardState FirstStartWizard::STATE_USER = 3;
87 const FirstStartWizard::WizardState FirstStartWizard::STATE_UPDATE_CHECK = 4;
88 const FirstStartWizard::WizardState FirstStartWizard::STATE_REGISTRATION = 5;
90 WizardResId::WizardResId( USHORT nId ) :
91 ResId( nId, *FirstStartWizard::GetResManager() )
95 ResMgr *FirstStartWizard::pResMgr = 0;
97 ResMgr *FirstStartWizard::GetResManager()
99 if ( !FirstStartWizard::pResMgr )
101 String aMgrName = String::CreateFromAscii( "dkt" );
102 FirstStartWizard::pResMgr = ResMgr::CreateResMgr( OUStringToOString( aMgrName, RTL_TEXTENCODING_UTF8 ));
104 return FirstStartWizard::pResMgr;
107 FirstStartWizard::FirstStartWizard( Window* pParent, sal_Bool bLicenseNeedsAcceptance, const rtl::OUString &rLicensePath )
108 :RoadmapWizard( pParent, WizardResId(DLG_FIRSTSTART_WIZARD),
109 WZB_NEXT|WZB_PREVIOUS|WZB_FINISH|WZB_CANCEL|WZB_HELP)
110 ,m_bOverride(sal_False)
111 ,m_aDefaultPath(0)
112 ,m_aMigrationPath(0)
113 ,m_bDone(sal_False)
114 ,m_bLicenseNeedsAcceptance( bLicenseNeedsAcceptance )
115 ,m_bLicenseWasAccepted(sal_False)
116 ,m_bAutomaticUpdChk(sal_True)
117 ,m_aLicensePath( rLicensePath )
119 return;
121 // ---
122 // FreeResource();
123 // enableState(STATE_USER, sal_False);
124 // enableState(STATE_REGISTRATION, sal_False);
126 ShowButtonFixedLine(sal_True);
127 Size aTPSize(TP_WIDTH, TP_HEIGHT);
128 SetPageSizePixel(LogicToPixel(aTPSize, MAP_APPFONT));
130 //set help id
131 m_pPrevPage->SetHelpId(HID_FIRSTSTART_PREV);
132 m_pNextPage->SetHelpId(HID_FIRSTSTART_NEXT);
133 m_pCancel->SetHelpId(HID_FIRSTSTART_CANCEL);
134 m_pFinish->SetHelpId(HID_FIRSTSTART_FINISH);
135 // m_pHelp->SetUniqueId(UID_FIRSTSTART_HELP);
136 m_pHelp->Hide();
137 m_pHelp->Disable();
139 // save button lables
140 m_sNext = m_pNextPage->GetText();
141 m_sCancel = m_pCancel->GetText();
143 // save cancel click handler
144 m_lnkCancel = m_pCancel->GetClickHdl();
146 m_aDefaultPath = defineWizardPagesDependingFromContext();
147 activatePath(m_aDefaultPath, sal_True);
149 enterState(STATE_WELCOME);
150 ActivatePage();
152 // set text of finish putton:
153 m_pFinish->SetText(String(WizardResId(STR_FINISH)));
154 // disable "finish button"
155 enableButtons(WZB_FINISH, sal_False);
156 defaultButton(WZB_NEXT);
159 ::svt::RoadmapWizardTypes::PathId FirstStartWizard::defineWizardPagesDependingFromContext()
161 ::svt::RoadmapWizardTypes::PathId aDefaultPath = 0;
163 sal_Bool bPage_Welcome = sal_True;
164 sal_Bool bPage_License = sal_True;
165 sal_Bool bPage_Migration = sal_True;
166 sal_Bool bPage_User = sal_True;
167 sal_Bool bPage_UpdateCheck = sal_True;
168 sal_Bool bPage_Registration = sal_True;
170 bPage_License = m_bLicenseNeedsAcceptance;
171 bPage_Migration = Migration::checkMigration();
172 bPage_UpdateCheck = showOnlineUpdatePage();
174 WizardPath aPath;
175 if (bPage_Welcome)
176 aPath.push_back(STATE_WELCOME);
177 if (bPage_License)
178 aPath.push_back(STATE_LICENSE);
179 if (bPage_Migration)
180 aPath.push_back(STATE_MIGRATION);
181 if (bPage_User)
182 aPath.push_back(STATE_USER);
183 if (bPage_UpdateCheck)
184 aPath.push_back(STATE_UPDATE_CHECK);
185 if (bPage_Registration)
186 aPath.push_back(STATE_REGISTRATION);
188 declarePath(aDefaultPath, aPath);
190 // a) If license must be accepted by the user, all direct links
191 // to wizard tab pages must be disabled. Because such pages
192 // should be accessible only in case license was accepted !
193 // b) But if no license should be shown at all ...
194 // such direct links can be enabled by default.
195 sal_Bool bAllowDirectLink = ( ! bPage_License);
197 if (bPage_User)
198 enableState(STATE_USER, bAllowDirectLink);
199 if (bPage_UpdateCheck)
200 enableState(STATE_UPDATE_CHECK, bAllowDirectLink);
201 if (bPage_Migration)
202 enableState(STATE_MIGRATION, bAllowDirectLink);
203 if (bPage_Registration)
204 enableState(STATE_REGISTRATION, bAllowDirectLink);
206 return aDefaultPath;
209 // catch F1 and disable help
210 long FirstStartWizard::PreNotify( NotifyEvent& rNEvt )
212 if( rNEvt.GetType() == EVENT_KEYINPUT )
214 const KeyCode& rKey = rNEvt.GetKeyEvent()->GetKeyCode();
215 if( rKey.GetCode() == KEY_F1 && ! rKey.GetModifier() )
216 return TRUE;
218 return RoadmapWizard::PreNotify(rNEvt);
222 void FirstStartWizard::enterState(WizardState _nState)
224 RoadmapWizard::enterState(_nState);
225 // default state
226 // all on
227 enableButtons(0xff, sal_True);
228 // finish off
229 enableButtons(WZB_FINISH, sal_False);
230 // default text
231 m_pCancel->SetText(m_sCancel);
232 m_pCancel->SetClickHdl(m_lnkCancel);
233 m_pNextPage->SetText(m_sNext);
235 // default
236 defaultButton(WZB_NEXT);
238 // specialized state
239 switch (_nState)
241 case STATE_WELCOME:
242 enableButtons(WZB_PREVIOUS, sal_False);
243 break;
244 case STATE_LICENSE:
245 m_pCancel->SetText(String(WizardResId(STR_LICENSE_DECLINE)));
246 m_pNextPage->SetText(String(WizardResId(STR_LICENSE_ACCEPT)));
247 enableButtons(WZB_NEXT, sal_False);
248 // attach warning dialog to cancel/decline button
249 m_pCancel->SetClickHdl( LINK(this, FirstStartWizard, DeclineHdl) );
250 break;
251 case STATE_REGISTRATION:
252 enableButtons(WZB_NEXT, sal_False);
253 enableButtons(WZB_FINISH, sal_True);
254 defaultButton(WZB_FINISH);
255 break;
258 // focus
262 IMPL_LINK( FirstStartWizard, DeclineHdl, PushButton *, EMPTYARG )
264 QueryBox aBox(this, WizardResId(QB_ASK_DECLINE));
265 sal_Int32 ret = aBox.Execute();
266 if ( ret == BUTTON_OK || ret == BUTTON_YES)
268 Close();
269 return sal_False;
271 else
272 return sal_True;
276 TabPage* FirstStartWizard::createPage(WizardState _nState)
278 TabPage *pTabPage = 0;
279 switch (_nState)
281 case STATE_WELCOME:
282 pTabPage = new WelcomePage(this, WizardResId(TP_WELCOME), m_bLicenseNeedsAcceptance);
283 break;
284 case STATE_LICENSE:
285 pTabPage = new LicensePage(this, WizardResId(TP_LICENSE), m_aLicensePath);
286 break;
287 case STATE_MIGRATION:
288 pTabPage = new MigrationPage(this, WizardResId(TP_MIGRATION));
289 break;
290 case STATE_USER:
291 pTabPage = new UserPage(this, WizardResId(TP_USER));
292 break;
293 case STATE_UPDATE_CHECK:
294 pTabPage = new UpdateCheckPage(this, WizardResId(TP_UPDATE_CHECK));
295 break;
296 case STATE_REGISTRATION:
297 pTabPage = new RegistrationPage(this, WizardResId(TP_REGISTRATION));
298 break;
300 pTabPage->Show();
302 return pTabPage;
305 String FirstStartWizard::getStateDisplayName( WizardState _nState ) const
307 String sName;
308 switch(_nState)
310 case STATE_WELCOME:
311 sName = String(WizardResId(STR_STATE_WELCOME));
312 break;
313 case STATE_LICENSE:
314 sName = String(WizardResId(STR_STATE_LICENSE));
315 break;
316 case STATE_MIGRATION:
317 sName = String(WizardResId(STR_STATE_MIGRATION));
318 break;
319 case STATE_USER:
320 sName = String(WizardResId(STR_STATE_USER));
321 break;
322 case STATE_UPDATE_CHECK:
323 sName = String(WizardResId(STR_STATE_UPDATE_CHECK));
324 break;
325 case STATE_REGISTRATION:
326 sName = String(WizardResId(STR_STATE_REGISTRATION));
327 break;
329 return sName;
332 sal_Bool FirstStartWizard::prepareLeaveCurrentState( CommitPageReason _eReason )
334 // the license acceptance is handled here, because it needs to change the state
335 // of the roadmap wizard which the page implementation does not know.
336 if (
337 (_eReason == eTravelForward) &&
338 (getCurrentState() == STATE_LICENSE ) &&
339 (m_bLicenseWasAccepted == sal_False )
342 if (Migration::checkMigration())
343 enableState(FirstStartWizard::STATE_MIGRATION, sal_True);
344 if ( showOnlineUpdatePage() )
345 enableState(FirstStartWizard::STATE_UPDATE_CHECK, sal_True);
346 enableState(FirstStartWizard::STATE_USER, sal_True);
347 enableState(FirstStartWizard::STATE_REGISTRATION, sal_True);
349 storeAcceptDate();
350 m_bLicenseWasAccepted = sal_True;
353 return svt::RoadmapWizard::prepareLeaveCurrentState(_eReason);
356 sal_Bool FirstStartWizard::leaveState(WizardState)
358 return sal_True;
361 sal_Bool FirstStartWizard::onFinish(sal_Int32 _nResult)
363 // return sal_True;
364 if (svt::RoadmapWizard::onFinish(_nResult))
366 #ifndef OS2 // cannot enable quickstart on first startup, see shutdownicon.cxx comments.
367 enableQuickstart();
368 #endif
369 disableWizard();
370 return sal_True;
372 else
373 return sal_False;
376 short FirstStartWizard::Execute()
378 disableWizard();
379 if ( Migration::checkMigration() )
380 Migration::doMigration();
382 return sal_True;
385 static OUString _makeDateTimeString (const DateTime& aDateTime, sal_Bool bUTC = sal_False)
387 OStringBuffer aDateTimeString;
388 aDateTimeString.append((sal_Int32)aDateTime.GetYear());
389 aDateTimeString.append("-");
390 if (aDateTime.GetMonth()<10) aDateTimeString.append("0");
391 aDateTimeString.append((sal_Int32)aDateTime.GetMonth());
392 aDateTimeString.append("-");
393 if (aDateTime.GetDay()<10) aDateTimeString.append("0");
394 aDateTimeString.append((sal_Int32)aDateTime.GetDay());
395 aDateTimeString.append("T");
396 if (aDateTime.GetHour()<10) aDateTimeString.append("0");
397 aDateTimeString.append((sal_Int32)aDateTime.GetHour());
398 aDateTimeString.append(":");
399 if (aDateTime.GetMin()<10) aDateTimeString.append("0");
400 aDateTimeString.append((sal_Int32)aDateTime.GetMin());
401 aDateTimeString.append(":");
402 if (aDateTime.GetSec()<10) aDateTimeString.append("0");
403 aDateTimeString.append((sal_Int32)aDateTime.GetSec());
404 if (bUTC) aDateTimeString.append("Z");
406 return OStringToOUString(aDateTimeString.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US);
409 static OUString _getCurrentDateString()
411 OUString aString;
412 return _makeDateTimeString(DateTime());
416 static const OUString sConfigSrvc( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationProvider" ) );
417 static const OUString sAccessSrvc( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationUpdateAccess" ) );
418 static const OUString sReadSrvc ( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationAccess" ) );
420 void FirstStartWizard::storeAcceptDate()
423 try {
424 Reference < XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
425 // get configuration provider
426 Reference< XMultiServiceFactory > theConfigProvider = Reference< XMultiServiceFactory >(
427 xFactory->createInstance(sConfigSrvc), UNO_QUERY_THROW);
428 Sequence< Any > theArgs(1);
429 NamedValue v(OUString::createFromAscii("NodePath"),
430 makeAny(OUString::createFromAscii("org.openoffice.Setup/Office")));
431 theArgs[0] <<= v;
432 Reference< XPropertySet > pset = Reference< XPropertySet >(
433 theConfigProvider->createInstanceWithArguments(sAccessSrvc, theArgs), UNO_QUERY_THROW);
434 Any result = pset->getPropertyValue(OUString::createFromAscii("LicenseAcceptDate"));
436 OUString aAcceptDate = _getCurrentDateString();
437 pset->setPropertyValue(OUString::createFromAscii("LicenseAcceptDate"), makeAny(aAcceptDate));
438 Reference< XChangesBatch >(pset, UNO_QUERY_THROW)->commitChanges();
440 // since the license is accepted the local user registry can be cleaned if required
441 cleanOldOfficeRegKeys();
442 } catch (const Exception&)
448 #ifdef WNT
449 typedef int ( __stdcall * CleanCurUserRegProc ) ( wchar_t* );
450 #endif
452 void FirstStartWizard::cleanOldOfficeRegKeys()
454 #ifdef WNT
455 // after the wizard is completed clean OOo1.1.x entries in the current user registry if required
456 // issue i47658
458 OUString aBaseLocationPath;
459 OUString aSharedLocationPath;
460 OUString aInstallMode;
462 ::utl::Bootstrap::PathStatus aBaseLocateResult =
463 ::utl::Bootstrap::locateBaseInstallation( aBaseLocationPath );
464 ::utl::Bootstrap::PathStatus aSharedLocateResult =
465 ::utl::Bootstrap::locateSharedData( aSharedLocationPath );
466 aInstallMode = ::utl::Bootstrap::getAllUsersValue( ::rtl::OUString() );
468 // TODO: replace the checking for install mode
469 if ( aBaseLocateResult == ::utl::Bootstrap::PATH_EXISTS && aSharedLocateResult == ::utl::Bootstrap::PATH_EXISTS
470 && aInstallMode.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "1" ) ) ) )
472 ::rtl::OUString aDeregCompletePath =
473 aBaseLocationPath + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/program/regcleanold.dll" ) );
474 ::rtl::OUString aExecCompletePath =
475 aSharedLocationPath + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/regdeinstall/userdeinst.exe" ) );
477 osl::Module aCleanModule( aDeregCompletePath );
478 CleanCurUserRegProc pNativeProc = ( CleanCurUserRegProc )(
479 aCleanModule.getFunctionSymbol(
480 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CleanCurUserOldSystemRegistry" ) ) ) );
482 if( pNativeProc!=NULL )
484 ::rtl::OUString aExecCompleteSysPath;
485 if ( osl::File::getSystemPathFromFileURL( aExecCompletePath, aExecCompleteSysPath ) == FileBase::E_None
486 && aExecCompleteSysPath.getLength() )
488 ( *pNativeProc )( (wchar_t*)( aExecCompleteSysPath.getStr() ) );
492 #endif
495 void FirstStartWizard::disableWizard()
498 try {
499 Reference < XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
500 // get configuration provider
501 Reference< XMultiServiceFactory > theConfigProvider = Reference< XMultiServiceFactory >(
502 xFactory->createInstance(sConfigSrvc), UNO_QUERY_THROW);
503 Sequence< Any > theArgs(1);
504 NamedValue v(OUString::createFromAscii("NodePath"),
505 makeAny(OUString::createFromAscii("org.openoffice.Setup/Office")));
506 theArgs[0] <<= v;
507 Reference< XPropertySet > pset = Reference< XPropertySet >(
508 theConfigProvider->createInstanceWithArguments(sAccessSrvc, theArgs), UNO_QUERY_THROW);
509 pset->setPropertyValue(OUString::createFromAscii("FirstStartWizardCompleted"), makeAny(sal_True));
510 Reference< XChangesBatch >(pset, UNO_QUERY_THROW)->commitChanges();
511 } catch (const Exception&)
518 void FirstStartWizard::enableQuickstart()
520 sal_Bool bQuickstart( sal_True );
521 sal_Bool bAutostart( sal_True );
522 Sequence< Any > aSeq( 2 );
523 aSeq[0] <<= bQuickstart;
524 aSeq[1] <<= bAutostart;
526 Reference < XInitialization > xQuickstart( ::comphelper::getProcessServiceFactory()->createInstance(
527 OUString::createFromAscii( "com.sun.star.office.Quickstart" )),UNO_QUERY );
528 if ( xQuickstart.is() )
529 xQuickstart->initialize( aSeq );
533 sal_Bool FirstStartWizard::showOnlineUpdatePage()
535 try {
536 Reference < XNameReplace > xUpdateAccess;
537 Reference < XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
539 xUpdateAccess = Reference < XNameReplace >(
540 xFactory->createInstance( UNISTRING( "com.sun.star.setup.UpdateCheckConfig" ) ), UNO_QUERY_THROW );
542 if ( xUpdateAccess.is() )
544 sal_Bool bAutoUpdChk = sal_False;
545 Any result = xUpdateAccess->getByName( UNISTRING( "AutoCheckEnabled" ) );
546 result >>= bAutoUpdChk;
547 if ( bAutoUpdChk == sal_False )
548 return sal_True;
549 else
550 return sal_False;
552 } catch (const Exception&)
555 return sal_False;