1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: wizard.cxx,v $
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>
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>
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>
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))
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
)
114 ,m_bLicenseNeedsAcceptance( bLicenseNeedsAcceptance
)
115 ,m_bLicenseWasAccepted(sal_False
)
116 ,m_bAutomaticUpdChk(sal_True
)
117 ,m_aLicensePath( rLicensePath
)
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
));
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);
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
);
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();
176 aPath
.push_back(STATE_WELCOME
);
178 aPath
.push_back(STATE_LICENSE
);
180 aPath
.push_back(STATE_MIGRATION
);
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
);
198 enableState(STATE_USER
, bAllowDirectLink
);
199 if (bPage_UpdateCheck
)
200 enableState(STATE_UPDATE_CHECK
, bAllowDirectLink
);
202 enableState(STATE_MIGRATION
, bAllowDirectLink
);
203 if (bPage_Registration
)
204 enableState(STATE_REGISTRATION
, bAllowDirectLink
);
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() )
218 return RoadmapWizard::PreNotify(rNEvt
);
222 void FirstStartWizard::enterState(WizardState _nState
)
224 RoadmapWizard::enterState(_nState
);
227 enableButtons(0xff, sal_True
);
229 enableButtons(WZB_FINISH
, sal_False
);
231 m_pCancel
->SetText(m_sCancel
);
232 m_pCancel
->SetClickHdl(m_lnkCancel
);
233 m_pNextPage
->SetText(m_sNext
);
236 defaultButton(WZB_NEXT
);
242 enableButtons(WZB_PREVIOUS
, sal_False
);
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
) );
251 case STATE_REGISTRATION
:
252 enableButtons(WZB_NEXT
, sal_False
);
253 enableButtons(WZB_FINISH
, sal_True
);
254 defaultButton(WZB_FINISH
);
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
)
276 TabPage
* FirstStartWizard::createPage(WizardState _nState
)
278 TabPage
*pTabPage
= 0;
282 pTabPage
= new WelcomePage(this, WizardResId(TP_WELCOME
), m_bLicenseNeedsAcceptance
);
285 pTabPage
= new LicensePage(this, WizardResId(TP_LICENSE
), m_aLicensePath
);
287 case STATE_MIGRATION
:
288 pTabPage
= new MigrationPage(this, WizardResId(TP_MIGRATION
));
291 pTabPage
= new UserPage(this, WizardResId(TP_USER
));
293 case STATE_UPDATE_CHECK
:
294 pTabPage
= new UpdateCheckPage(this, WizardResId(TP_UPDATE_CHECK
));
296 case STATE_REGISTRATION
:
297 pTabPage
= new RegistrationPage(this, WizardResId(TP_REGISTRATION
));
305 String
FirstStartWizard::getStateDisplayName( WizardState _nState
) const
311 sName
= String(WizardResId(STR_STATE_WELCOME
));
314 sName
= String(WizardResId(STR_STATE_LICENSE
));
316 case STATE_MIGRATION
:
317 sName
= String(WizardResId(STR_STATE_MIGRATION
));
320 sName
= String(WizardResId(STR_STATE_USER
));
322 case STATE_UPDATE_CHECK
:
323 sName
= String(WizardResId(STR_STATE_UPDATE_CHECK
));
325 case STATE_REGISTRATION
:
326 sName
= String(WizardResId(STR_STATE_REGISTRATION
));
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.
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
);
350 m_bLicenseWasAccepted
= sal_True
;
353 return svt::RoadmapWizard::prepareLeaveCurrentState(_eReason
);
356 sal_Bool
FirstStartWizard::leaveState(WizardState
)
361 sal_Bool
FirstStartWizard::onFinish(sal_Int32 _nResult
)
364 if (svt::RoadmapWizard::onFinish(_nResult
))
366 #ifndef OS2 // cannot enable quickstart on first startup, see shutdownicon.cxx comments.
376 short FirstStartWizard::Execute()
379 if ( Migration::checkMigration() )
380 Migration::doMigration();
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()
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()
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")));
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
&)
449 typedef int ( __stdcall
* CleanCurUserRegProc
) ( wchar_t* );
452 void FirstStartWizard::cleanOldOfficeRegKeys()
455 // after the wizard is completed clean OOo1.1.x entries in the current user registry if required
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() ) );
495 void FirstStartWizard::disableWizard()
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")));
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()
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
)
552 } catch (const Exception
&)