12722ceddSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
32722ceddSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
42722ceddSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
52722ceddSAndrew Rist  * distributed with this work for additional information
62722ceddSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
72722ceddSAndrew Rist  * to you under the Apache License, Version 2.0 (the
82722ceddSAndrew Rist  * "License"); you may not use this file except in compliance
92722ceddSAndrew Rist  * with the License.  You may obtain a copy of the License at
102722ceddSAndrew Rist  *
112722ceddSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
122722ceddSAndrew Rist  *
132722ceddSAndrew Rist  * Unless required by applicable law or agreed to in writing,
142722ceddSAndrew Rist  * software distributed under the License is distributed on an
152722ceddSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162722ceddSAndrew Rist  * KIND, either express or implied.  See the License for the
172722ceddSAndrew Rist  * specific language governing permissions and limitations
182722ceddSAndrew Rist  * under the License.
192722ceddSAndrew Rist  *
202722ceddSAndrew Rist  *************************************************************/
212722ceddSAndrew Rist 
222722ceddSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_desktop.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <migration.hxx>
28cdf0e10cSrcweir #include "wizard.hxx"
29cdf0e10cSrcweir #include "wizard.hrc"
30cdf0e10cSrcweir #include "pages.hxx"
31cdf0e10cSrcweir #include "app.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <rtl/ustring.hxx>
34cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
35cdf0e10cSrcweir #include <rtl/string.hxx>
36cdf0e10cSrcweir #include <rtl/strbuf.hxx>
37cdf0e10cSrcweir #include <rtl/bootstrap.hxx>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
40cdf0e10cSrcweir #include <tools/date.hxx>
41cdf0e10cSrcweir #include <tools/time.hxx>
42cdf0e10cSrcweir #include <tools/datetime.hxx>
43cdf0e10cSrcweir #include <osl/file.hxx>
44cdf0e10cSrcweir #include <osl/time.h>
45cdf0e10cSrcweir #include <osl/module.hxx>
46cdf0e10cSrcweir #include <unotools/bootstrap.hxx>
47cdf0e10cSrcweir #include <vcl/msgbox.hxx>
48cdf0e10cSrcweir 
49cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
50cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
51cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp>
52cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
53cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyState.hpp>
54cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp>
55cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
56cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
57cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
58cdf0e10cSrcweir #include <com/sun/star/util/XChangesBatch.hpp>
59cdf0e10cSrcweir #include <com/sun/star/container/XNameReplace.hpp>
60cdf0e10cSrcweir #include <com/sun/star/awt/WindowDescriptor.hpp>
61cdf0e10cSrcweir #include <com/sun/star/awt/WindowAttribute.hpp>
62cdf0e10cSrcweir 
63cdf0e10cSrcweir using namespace svt;
64cdf0e10cSrcweir using namespace rtl;
65cdf0e10cSrcweir using namespace osl;
66cdf0e10cSrcweir using namespace utl;
67cdf0e10cSrcweir using namespace com::sun::star;
68cdf0e10cSrcweir using namespace com::sun::star::uno;
69cdf0e10cSrcweir using namespace com::sun::star::lang;
70cdf0e10cSrcweir using namespace com::sun::star::beans;
71cdf0e10cSrcweir using namespace com::sun::star::util;
72cdf0e10cSrcweir using namespace com::sun::star::container;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir #define UNISTRING(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
75cdf0e10cSrcweir 
76cdf0e10cSrcweir namespace desktop
77cdf0e10cSrcweir {
78cdf0e10cSrcweir 
79cdf0e10cSrcweir const FirstStartWizard::WizardState FirstStartWizard::STATE_WELCOME      = 0;
80cdf0e10cSrcweir const FirstStartWizard::WizardState FirstStartWizard::STATE_LICENSE      = 1;
81cdf0e10cSrcweir const FirstStartWizard::WizardState FirstStartWizard::STATE_MIGRATION    = 2;
82cdf0e10cSrcweir const FirstStartWizard::WizardState FirstStartWizard::STATE_USER         = 3;
83cdf0e10cSrcweir const FirstStartWizard::WizardState FirstStartWizard::STATE_UPDATE_CHECK = 4;
84cdf0e10cSrcweir const FirstStartWizard::WizardState FirstStartWizard::STATE_REGISTRATION = 5;
85cdf0e10cSrcweir 
getBuildId()86cdf0e10cSrcweir static sal_Int32 getBuildId()
87cdf0e10cSrcweir {
88cdf0e10cSrcweir     ::rtl::OUString aDefault;
89cdf0e10cSrcweir     ::rtl::OUString aBuildIdData = utl::Bootstrap::getBuildIdData( aDefault );
90cdf0e10cSrcweir     sal_Int32 nBuildId( 0 );
91cdf0e10cSrcweir     sal_Int32 nIndex1 = aBuildIdData.indexOf(':');
92cdf0e10cSrcweir     sal_Int32 nIndex2 = aBuildIdData.indexOf(')');
93cdf0e10cSrcweir     if (( nIndex1 > 0 ) && ( nIndex2 > 0 ) && ( nIndex2-1 > nIndex1+1 ))
94cdf0e10cSrcweir     {
95cdf0e10cSrcweir         ::rtl::OUString aBuildId = aBuildIdData.copy( nIndex1+1, nIndex2-nIndex1-1 );
96cdf0e10cSrcweir         nBuildId = aBuildId.toInt32();
97cdf0e10cSrcweir     }
98cdf0e10cSrcweir     return nBuildId;
99cdf0e10cSrcweir }
100cdf0e10cSrcweir 
WizardResId(sal_uInt16 nId)101cdf0e10cSrcweir WizardResId::WizardResId( sal_uInt16 nId ) :
102cdf0e10cSrcweir 	ResId( nId, *FirstStartWizard::GetResManager() )
103cdf0e10cSrcweir {
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir ResMgr *FirstStartWizard::pResMgr = 0;
107cdf0e10cSrcweir 
GetResManager()108cdf0e10cSrcweir ResMgr *FirstStartWizard::GetResManager()
109cdf0e10cSrcweir {
110cdf0e10cSrcweir     if ( !FirstStartWizard::pResMgr )
111*24c56ab9SHerbert Dürr         FirstStartWizard::pResMgr = ResMgr::CreateResMgr( "dkt");
112cdf0e10cSrcweir     return FirstStartWizard::pResMgr;
113cdf0e10cSrcweir }
114cdf0e10cSrcweir 
FirstStartWizard(Window * pParent,sal_Bool bLicenseNeedsAcceptance,const rtl::OUString & rLicensePath)115cdf0e10cSrcweir FirstStartWizard::FirstStartWizard( Window* pParent, sal_Bool bLicenseNeedsAcceptance, const rtl::OUString &rLicensePath )
116281431dbSOliver-Rainer Wittmann     :RoadmapWizard( pParent,
117281431dbSOliver-Rainer Wittmann                     WizardResId(DLG_FIRSTSTART_WIZARD),
118281431dbSOliver-Rainer Wittmann                     WZB_NEXT|WZB_PREVIOUS|WZB_FINISH|WZB_CANCEL|WZB_HELP)
119cdf0e10cSrcweir     ,m_bOverride(sal_False)
120281431dbSOliver-Rainer Wittmann     , m_lastState( STATE_WELCOME )
121cdf0e10cSrcweir     ,m_aDefaultPath(0)
122cdf0e10cSrcweir 	,m_aMigrationPath(0)
123cdf0e10cSrcweir     ,m_bDone(sal_False)
124cdf0e10cSrcweir 	,m_bLicenseNeedsAcceptance( bLicenseNeedsAcceptance )
125cdf0e10cSrcweir     ,m_bLicenseWasAccepted(sal_False)
126cdf0e10cSrcweir     ,m_bAutomaticUpdChk(sal_True)
127cdf0e10cSrcweir     ,m_aThrobber(this, WizardResId(CTRL_THROBBER))
128cdf0e10cSrcweir     ,m_aLicensePath( rLicensePath )
129cdf0e10cSrcweir {
130cdf0e10cSrcweir     FreeResource();
131cdf0e10cSrcweir 
132cdf0e10cSrcweir     Size aTPSize(TP_WIDTH, TP_HEIGHT);
133cdf0e10cSrcweir     SetPageSizePixel(LogicToPixel(aTPSize, MAP_APPFONT));
134cdf0e10cSrcweir 
135cdf0e10cSrcweir     //set help id
136cdf0e10cSrcweir     m_pPrevPage->SetHelpId(HID_FIRSTSTART_PREV);
137cdf0e10cSrcweir     m_pNextPage->SetHelpId(HID_FIRSTSTART_NEXT);
138cdf0e10cSrcweir     m_pCancel->SetHelpId(HID_FIRSTSTART_CANCEL);
139cdf0e10cSrcweir     m_pFinish->SetHelpId(HID_FIRSTSTART_FINISH);
140cdf0e10cSrcweir     m_pHelp->Hide();
141cdf0e10cSrcweir     m_pHelp->Disable();
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     // save button lables
144cdf0e10cSrcweir     m_sNext = m_pNextPage->GetText();
145cdf0e10cSrcweir     m_sCancel = m_pCancel->GetText();
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     // save cancel click handler
148cdf0e10cSrcweir     m_lnkCancel = m_pCancel->GetClickHdl();
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     m_aDefaultPath = defineWizardPagesDependingFromContext();
151cdf0e10cSrcweir 	activatePath(m_aDefaultPath, sal_True);
152cdf0e10cSrcweir 
153cdf0e10cSrcweir     ActivatePage();
154cdf0e10cSrcweir 
155cdf0e10cSrcweir     // set text of finish putton:
156cdf0e10cSrcweir     m_pFinish->SetText(String(WizardResId(STR_FINISH)));
157cdf0e10cSrcweir     // disable "finish button"
158cdf0e10cSrcweir     enableButtons(WZB_FINISH, sal_False);
159cdf0e10cSrcweir     defaultButton(WZB_NEXT);
160cdf0e10cSrcweir }
161cdf0e10cSrcweir 
DisableButtonsWhileMigration()162cdf0e10cSrcweir void FirstStartWizard::DisableButtonsWhileMigration()
163cdf0e10cSrcweir {
164cdf0e10cSrcweir     enableButtons(0xff, sal_False);
165cdf0e10cSrcweir }
166cdf0e10cSrcweir 
defineWizardPagesDependingFromContext()167cdf0e10cSrcweir ::svt::RoadmapWizardTypes::PathId FirstStartWizard::defineWizardPagesDependingFromContext()
168cdf0e10cSrcweir {
169cdf0e10cSrcweir 	::svt::RoadmapWizardTypes::PathId aDefaultPath = 0;
170cdf0e10cSrcweir 
171cdf0e10cSrcweir     sal_Bool bPage_Migration    = sal_True;
172cdf0e10cSrcweir     sal_Bool bPage_UpdateCheck  = sal_True;
173cdf0e10cSrcweir 
174cdf0e10cSrcweir     bPage_Migration   = Migration::checkMigration();
175cdf0e10cSrcweir     bPage_UpdateCheck = showOnlineUpdatePage();
176cdf0e10cSrcweir 
177cdf0e10cSrcweir     WizardPath aPath;
178281431dbSOliver-Rainer Wittmann     aPath.push_back(STATE_WELCOME);
179cdf0e10cSrcweir     if (bPage_Migration)
180281431dbSOliver-Rainer Wittmann     {
181cdf0e10cSrcweir         aPath.push_back(STATE_MIGRATION);
182281431dbSOliver-Rainer Wittmann     }
183281431dbSOliver-Rainer Wittmann     aPath.push_back(STATE_USER);
184281431dbSOliver-Rainer Wittmann     m_lastState = STATE_USER;
185cdf0e10cSrcweir     if (bPage_UpdateCheck)
186281431dbSOliver-Rainer Wittmann     {
187cdf0e10cSrcweir         aPath.push_back(STATE_UPDATE_CHECK);
188281431dbSOliver-Rainer Wittmann         m_lastState = STATE_UPDATE_CHECK;
189281431dbSOliver-Rainer Wittmann     }
190cdf0e10cSrcweir 
191cdf0e10cSrcweir     declarePath(aDefaultPath, aPath);
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 	// a) If license must be accepted by the user, all direct links
194cdf0e10cSrcweir 	//    to wizard tab pages must be disabled. Because such pages
195cdf0e10cSrcweir 	//	  should be accessible only in case license was accepted !
196cdf0e10cSrcweir 	// b) But if no license should be shown at all ...
197cdf0e10cSrcweir 	//    such direct links can be enabled by default.
198288ab9e2SHerbert Dürr 	sal_Bool bAllowDirectLink = true;
199cdf0e10cSrcweir 
200281431dbSOliver-Rainer Wittmann     enableState(STATE_USER, bAllowDirectLink);
201cdf0e10cSrcweir     if (bPage_Migration)
202cdf0e10cSrcweir         enableState(STATE_MIGRATION, bAllowDirectLink);
203281431dbSOliver-Rainer Wittmann     if (bPage_UpdateCheck)
204281431dbSOliver-Rainer Wittmann         enableState(STATE_UPDATE_CHECK, bAllowDirectLink);
205cdf0e10cSrcweir 
206cdf0e10cSrcweir 	return aDefaultPath;
207cdf0e10cSrcweir }
208cdf0e10cSrcweir 
209cdf0e10cSrcweir // catch F1 and disable help
PreNotify(NotifyEvent & rNEvt)210cdf0e10cSrcweir long FirstStartWizard::PreNotify( NotifyEvent& rNEvt )
211cdf0e10cSrcweir {
212cdf0e10cSrcweir     if( rNEvt.GetType() == EVENT_KEYINPUT )
213cdf0e10cSrcweir     {
214cdf0e10cSrcweir         const KeyCode& rKey = rNEvt.GetKeyEvent()->GetKeyCode();
215cdf0e10cSrcweir         if( rKey.GetCode() == KEY_F1 && ! rKey.GetModifier() )
216cdf0e10cSrcweir             return sal_True;
217cdf0e10cSrcweir     }
218cdf0e10cSrcweir     return RoadmapWizard::PreNotify(rNEvt);
219cdf0e10cSrcweir }
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 
enterState(WizardState _nState)222cdf0e10cSrcweir void FirstStartWizard::enterState(WizardState _nState)
223cdf0e10cSrcweir {
224cdf0e10cSrcweir     RoadmapWizard::enterState(_nState);
225cdf0e10cSrcweir     // default state
226cdf0e10cSrcweir     // all on
227cdf0e10cSrcweir     enableButtons(0xff, sal_True);
228cdf0e10cSrcweir     // finish off
229cdf0e10cSrcweir     enableButtons(WZB_FINISH, sal_False);
230cdf0e10cSrcweir     // default text
231cdf0e10cSrcweir     m_pCancel->SetText(m_sCancel);
232cdf0e10cSrcweir     m_pCancel->SetClickHdl(m_lnkCancel);
233cdf0e10cSrcweir     m_pNextPage->SetText(m_sNext);
234cdf0e10cSrcweir 
235cdf0e10cSrcweir     // default
236cdf0e10cSrcweir     defaultButton(WZB_NEXT);
237cdf0e10cSrcweir 
238cdf0e10cSrcweir     // specialized state
239cdf0e10cSrcweir     switch (_nState)
240cdf0e10cSrcweir     {
241cdf0e10cSrcweir     case STATE_WELCOME:
242cdf0e10cSrcweir         enableButtons(WZB_PREVIOUS, sal_False);
243cdf0e10cSrcweir         break;
244cdf0e10cSrcweir     case STATE_LICENSE:
245cdf0e10cSrcweir         m_pCancel->SetText(String(WizardResId(STR_LICENSE_DECLINE)));
246cdf0e10cSrcweir         m_pNextPage->SetText(String(WizardResId(STR_LICENSE_ACCEPT)));
247cdf0e10cSrcweir         enableButtons(WZB_NEXT, sal_False);
248cdf0e10cSrcweir         // attach warning dialog to cancel/decline button
249cdf0e10cSrcweir         m_pCancel->SetClickHdl( LINK(this, FirstStartWizard, DeclineHdl) );
250cdf0e10cSrcweir         break;
251281431dbSOliver-Rainer Wittmann     }
252281431dbSOliver-Rainer Wittmann     if ( _nState == m_lastState )
253281431dbSOliver-Rainer Wittmann     {
254cdf0e10cSrcweir         enableButtons(WZB_NEXT, sal_False);
255cdf0e10cSrcweir         enableButtons(WZB_FINISH, sal_True);
256cdf0e10cSrcweir         defaultButton(WZB_FINISH);
257cdf0e10cSrcweir     }
258cdf0e10cSrcweir }
259cdf0e10cSrcweir 
IMPL_LINK(FirstStartWizard,DeclineHdl,PushButton *,EMPTYARG)260cdf0e10cSrcweir IMPL_LINK( FirstStartWizard, DeclineHdl, PushButton *, EMPTYARG )
261cdf0e10cSrcweir {
262cdf0e10cSrcweir     QueryBox aBox(this, WizardResId(QB_ASK_DECLINE));
263cdf0e10cSrcweir     sal_Int32 ret = aBox.Execute();
264cdf0e10cSrcweir     if ( ret == BUTTON_OK || ret == BUTTON_YES)
265cdf0e10cSrcweir     {
266cdf0e10cSrcweir         Close();
267cdf0e10cSrcweir         return sal_False;
268cdf0e10cSrcweir     }
269cdf0e10cSrcweir     else
270cdf0e10cSrcweir         return sal_True;
271cdf0e10cSrcweir }
272cdf0e10cSrcweir 
273cdf0e10cSrcweir 
createPage(WizardState _nState)274cdf0e10cSrcweir TabPage* FirstStartWizard::createPage(WizardState _nState)
275cdf0e10cSrcweir {
276cdf0e10cSrcweir     TabPage *pTabPage = 0;
277cdf0e10cSrcweir     switch (_nState)
278cdf0e10cSrcweir     {
279cdf0e10cSrcweir     case STATE_WELCOME:
280cdf0e10cSrcweir         pTabPage = new WelcomePage(this, WizardResId(TP_WELCOME), m_bLicenseNeedsAcceptance);
281cdf0e10cSrcweir         break;
282cdf0e10cSrcweir     case STATE_MIGRATION:
283cdf0e10cSrcweir         pTabPage = new MigrationPage(this, WizardResId(TP_MIGRATION), m_aThrobber);
284cdf0e10cSrcweir         break;
285cdf0e10cSrcweir     case STATE_USER:
286cdf0e10cSrcweir         pTabPage = new UserPage(this, WizardResId(TP_USER));
287cdf0e10cSrcweir         break;
288cdf0e10cSrcweir     case STATE_UPDATE_CHECK:
289cdf0e10cSrcweir         pTabPage = new UpdateCheckPage(this, WizardResId(TP_UPDATE_CHECK));
290cdf0e10cSrcweir         break;
291cdf0e10cSrcweir     }
292cdf0e10cSrcweir     pTabPage->Show();
293cdf0e10cSrcweir 
294cdf0e10cSrcweir     return pTabPage;
295cdf0e10cSrcweir }
296cdf0e10cSrcweir 
getStateDisplayName(WizardState _nState) const297cdf0e10cSrcweir String FirstStartWizard::getStateDisplayName( WizardState _nState ) const
298cdf0e10cSrcweir {
299cdf0e10cSrcweir     String sName;
300cdf0e10cSrcweir     switch(_nState)
301cdf0e10cSrcweir     {
302cdf0e10cSrcweir     case STATE_WELCOME:
303cdf0e10cSrcweir         sName = String(WizardResId(STR_STATE_WELCOME));
304cdf0e10cSrcweir         break;
305cdf0e10cSrcweir     case STATE_MIGRATION:
306cdf0e10cSrcweir         sName = String(WizardResId(STR_STATE_MIGRATION));
307cdf0e10cSrcweir         break;
308cdf0e10cSrcweir     case STATE_USER:
309cdf0e10cSrcweir         sName = String(WizardResId(STR_STATE_USER));
310cdf0e10cSrcweir         break;
311cdf0e10cSrcweir     case STATE_UPDATE_CHECK:
312cdf0e10cSrcweir         sName = String(WizardResId(STR_STATE_UPDATE_CHECK));
313cdf0e10cSrcweir         break;
314cdf0e10cSrcweir     }
315cdf0e10cSrcweir     return sName;
316cdf0e10cSrcweir }
317cdf0e10cSrcweir 
prepareLeaveCurrentState(CommitPageReason _eReason)318cdf0e10cSrcweir sal_Bool FirstStartWizard::prepareLeaveCurrentState( CommitPageReason _eReason )
319cdf0e10cSrcweir {
320cdf0e10cSrcweir     // the license acceptance is handled here, because it needs to change the state
321cdf0e10cSrcweir     // of the roadmap wizard which the page implementation does not know.
322cdf0e10cSrcweir     if (
323cdf0e10cSrcweir 		(_eReason              == eTravelForward) &&
324cdf0e10cSrcweir 		(getCurrentState()     == STATE_LICENSE ) &&
325cdf0e10cSrcweir 		(m_bLicenseWasAccepted == sal_False     )
326cdf0e10cSrcweir 	   )
327cdf0e10cSrcweir     {
328cdf0e10cSrcweir 		if (Migration::checkMigration())
329cdf0e10cSrcweir             enableState(FirstStartWizard::STATE_MIGRATION, sal_True);
330cdf0e10cSrcweir         if ( showOnlineUpdatePage() )
331cdf0e10cSrcweir             enableState(FirstStartWizard::STATE_UPDATE_CHECK, sal_True);
332cdf0e10cSrcweir 		enableState(FirstStartWizard::STATE_USER, sal_True);
333cdf0e10cSrcweir         enableState(FirstStartWizard::STATE_REGISTRATION, sal_True);
334cdf0e10cSrcweir 
335cdf0e10cSrcweir         storeAcceptDate();
336cdf0e10cSrcweir         m_bLicenseWasAccepted = sal_True;
337cdf0e10cSrcweir     }
338cdf0e10cSrcweir 
339cdf0e10cSrcweir     return svt::RoadmapWizard::prepareLeaveCurrentState(_eReason);
340cdf0e10cSrcweir }
341cdf0e10cSrcweir 
leaveState(WizardState)342cdf0e10cSrcweir sal_Bool FirstStartWizard::leaveState(WizardState)
343cdf0e10cSrcweir {
344cdf0e10cSrcweir     if (( getCurrentState() == STATE_MIGRATION ) && m_bLicenseWasAccepted )
345cdf0e10cSrcweir     {
346cdf0e10cSrcweir         // Store accept date and patch level now as it has been
347cdf0e10cSrcweir         // overwritten by the migration process!
348cdf0e10cSrcweir         storeAcceptDate();
349cdf0e10cSrcweir         setPatchLevel();
350cdf0e10cSrcweir     }
351cdf0e10cSrcweir 
352cdf0e10cSrcweir     return sal_True;
353cdf0e10cSrcweir }
354cdf0e10cSrcweir 
onFinish()355cdf0e10cSrcweir sal_Bool FirstStartWizard::onFinish()
356cdf0e10cSrcweir {
35719720aa2SHerbert Dürr     return svt::RoadmapWizard::onFinish();
358cdf0e10cSrcweir }
359cdf0e10cSrcweir 
Execute()360cdf0e10cSrcweir short FirstStartWizard::Execute()
361cdf0e10cSrcweir {
362cdf0e10cSrcweir     return svt::RoadmapWizard::Execute();
363cdf0e10cSrcweir }
364cdf0e10cSrcweir 
_makeDateTimeString(const DateTime & aDateTime,sal_Bool bUTC=sal_False)365cdf0e10cSrcweir static OUString _makeDateTimeString (const DateTime& aDateTime, sal_Bool bUTC = sal_False)
366cdf0e10cSrcweir {
367cdf0e10cSrcweir     OStringBuffer aDateTimeString;
368cdf0e10cSrcweir     aDateTimeString.append((sal_Int32)aDateTime.GetYear());
369cdf0e10cSrcweir     aDateTimeString.append("-");
370cdf0e10cSrcweir     if (aDateTime.GetMonth()<10) aDateTimeString.append("0");
371cdf0e10cSrcweir     aDateTimeString.append((sal_Int32)aDateTime.GetMonth());
372cdf0e10cSrcweir     aDateTimeString.append("-");
373cdf0e10cSrcweir     if (aDateTime.GetDay()<10) aDateTimeString.append("0");
374cdf0e10cSrcweir     aDateTimeString.append((sal_Int32)aDateTime.GetDay());
375cdf0e10cSrcweir     aDateTimeString.append("T");
376cdf0e10cSrcweir     if (aDateTime.GetHour()<10) aDateTimeString.append("0");
377cdf0e10cSrcweir     aDateTimeString.append((sal_Int32)aDateTime.GetHour());
378cdf0e10cSrcweir     aDateTimeString.append(":");
379cdf0e10cSrcweir     if (aDateTime.GetMin()<10) aDateTimeString.append("0");
380cdf0e10cSrcweir     aDateTimeString.append((sal_Int32)aDateTime.GetMin());
381cdf0e10cSrcweir     aDateTimeString.append(":");
382cdf0e10cSrcweir     if (aDateTime.GetSec()<10) aDateTimeString.append("0");
383cdf0e10cSrcweir     aDateTimeString.append((sal_Int32)aDateTime.GetSec());
384cdf0e10cSrcweir     if (bUTC) aDateTimeString.append("Z");
385cdf0e10cSrcweir 
386cdf0e10cSrcweir     return OStringToOUString(aDateTimeString.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US);
387cdf0e10cSrcweir }
388cdf0e10cSrcweir 
_getCurrentDateString()389cdf0e10cSrcweir static OUString _getCurrentDateString()
390cdf0e10cSrcweir {
391cdf0e10cSrcweir     OUString aString;
392cdf0e10cSrcweir     return _makeDateTimeString(DateTime());
393cdf0e10cSrcweir }
394cdf0e10cSrcweir 
395cdf0e10cSrcweir 
396cdf0e10cSrcweir static const OUString sConfigSrvc( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationProvider" ) );
397cdf0e10cSrcweir static const OUString sAccessSrvc( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationUpdateAccess" ) );
398cdf0e10cSrcweir static const OUString sReadSrvc  ( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationAccess" ) );
399cdf0e10cSrcweir 
storeAcceptDate()400cdf0e10cSrcweir void FirstStartWizard::storeAcceptDate()
401cdf0e10cSrcweir {
402cdf0e10cSrcweir 
403cdf0e10cSrcweir     try {
404cdf0e10cSrcweir         Reference < XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
405cdf0e10cSrcweir         // get configuration provider
406cdf0e10cSrcweir         Reference< XMultiServiceFactory > theConfigProvider = Reference< XMultiServiceFactory >(
407cdf0e10cSrcweir         xFactory->createInstance(sConfigSrvc), UNO_QUERY_THROW);
408cdf0e10cSrcweir         Sequence< Any > theArgs(1);
409cdf0e10cSrcweir         NamedValue v(OUString::createFromAscii("NodePath"),
410cdf0e10cSrcweir             makeAny(OUString::createFromAscii("org.openoffice.Setup/Office")));
411cdf0e10cSrcweir         theArgs[0] <<= v;
412cdf0e10cSrcweir         Reference< XPropertySet > pset = Reference< XPropertySet >(
413cdf0e10cSrcweir             theConfigProvider->createInstanceWithArguments(sAccessSrvc, theArgs), UNO_QUERY_THROW);
414cdf0e10cSrcweir         Any result = pset->getPropertyValue(OUString::createFromAscii("LicenseAcceptDate"));
415cdf0e10cSrcweir 
416cdf0e10cSrcweir         OUString aAcceptDate = _getCurrentDateString();
417cdf0e10cSrcweir         pset->setPropertyValue(OUString::createFromAscii("LicenseAcceptDate"), makeAny(aAcceptDate));
418cdf0e10cSrcweir         Reference< XChangesBatch >(pset, UNO_QUERY_THROW)->commitChanges();
419cdf0e10cSrcweir 
420cdf0e10cSrcweir 		// since the license is accepted the local user registry can be cleaned if required
421cdf0e10cSrcweir 		cleanOldOfficeRegKeys();
422cdf0e10cSrcweir     } catch (const Exception&)
423cdf0e10cSrcweir     {
424cdf0e10cSrcweir     }
425cdf0e10cSrcweir 
426cdf0e10cSrcweir }
427cdf0e10cSrcweir 
setPatchLevel()428cdf0e10cSrcweir void FirstStartWizard::setPatchLevel()
429cdf0e10cSrcweir {
430cdf0e10cSrcweir     try {
431cdf0e10cSrcweir         Reference < XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
432cdf0e10cSrcweir         // get configuration provider
433cdf0e10cSrcweir         Reference< XMultiServiceFactory > theConfigProvider = Reference< XMultiServiceFactory >(
434cdf0e10cSrcweir         xFactory->createInstance(sConfigSrvc), UNO_QUERY_THROW);
435cdf0e10cSrcweir         Sequence< Any > theArgs(1);
436cdf0e10cSrcweir         NamedValue v(OUString::createFromAscii("NodePath"),
437cdf0e10cSrcweir             makeAny(OUString::createFromAscii("org.openoffice.Office.Common/Help/Registration")));
438cdf0e10cSrcweir         theArgs[0] <<= v;
439cdf0e10cSrcweir         Reference< XPropertySet > pset = Reference< XPropertySet >(
440cdf0e10cSrcweir             theConfigProvider->createInstanceWithArguments(sAccessSrvc, theArgs), UNO_QUERY_THROW);
441cdf0e10cSrcweir         Any result = pset->getPropertyValue(OUString::createFromAscii("ReminderDate"));
442cdf0e10cSrcweir 
443cdf0e10cSrcweir         OUString aPatchLevel( RTL_CONSTASCII_USTRINGPARAM( "Patch" ));
444cdf0e10cSrcweir         aPatchLevel += OUString::valueOf( getBuildId(), 10 );
445cdf0e10cSrcweir         pset->setPropertyValue(OUString::createFromAscii("ReminderDate"), makeAny(aPatchLevel));
446cdf0e10cSrcweir         Reference< XChangesBatch >(pset, UNO_QUERY_THROW)->commitChanges();
447cdf0e10cSrcweir     } catch (const Exception&)
448cdf0e10cSrcweir     {
449cdf0e10cSrcweir     }
450cdf0e10cSrcweir }
451cdf0e10cSrcweir 
452cdf0e10cSrcweir #ifdef WNT
453cdf0e10cSrcweir typedef int ( __stdcall * CleanCurUserRegProc ) ( wchar_t* );
454cdf0e10cSrcweir #endif
455cdf0e10cSrcweir 
cleanOldOfficeRegKeys()456cdf0e10cSrcweir void FirstStartWizard::cleanOldOfficeRegKeys()
457cdf0e10cSrcweir {
458cdf0e10cSrcweir #ifdef WNT
459cdf0e10cSrcweir 	// after the wizard is completed clean OOo1.1.x entries in the current user registry if required
460cdf0e10cSrcweir 	// issue i47658
461cdf0e10cSrcweir 
462cdf0e10cSrcweir     OUString aBaseLocationPath;
463cdf0e10cSrcweir     OUString aSharedLocationPath;
464cdf0e10cSrcweir 	OUString aInstallMode;
465cdf0e10cSrcweir 
466cdf0e10cSrcweir 	::utl::Bootstrap::PathStatus aBaseLocateResult =
467cdf0e10cSrcweir         ::utl::Bootstrap::locateBaseInstallation( aBaseLocationPath );
468cdf0e10cSrcweir     ::utl::Bootstrap::PathStatus aSharedLocateResult =
469cdf0e10cSrcweir         ::utl::Bootstrap::locateSharedData( aSharedLocationPath );
470cdf0e10cSrcweir     aInstallMode = ::utl::Bootstrap::getAllUsersValue( ::rtl::OUString() );
471cdf0e10cSrcweir 
472cdf0e10cSrcweir 	// TODO: replace the checking for install mode
473cdf0e10cSrcweir     if ( aBaseLocateResult == ::utl::Bootstrap::PATH_EXISTS && aSharedLocateResult == ::utl::Bootstrap::PATH_EXISTS
474cdf0e10cSrcweir 	  && aInstallMode.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "1" ) ) ) )
475cdf0e10cSrcweir     {
476cdf0e10cSrcweir 		::rtl::OUString aDeregCompletePath =
477cdf0e10cSrcweir 					aBaseLocationPath + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/program/regcleanold.dll" ) );
478cdf0e10cSrcweir 		::rtl::OUString aExecCompletePath =
479cdf0e10cSrcweir 					aSharedLocationPath + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/regdeinstall/userdeinst.exe" ) );
480cdf0e10cSrcweir 
481cdf0e10cSrcweir 		osl::Module aCleanModule( aDeregCompletePath );
482cdf0e10cSrcweir 		CleanCurUserRegProc pNativeProc = ( CleanCurUserRegProc )(
483cdf0e10cSrcweir 					aCleanModule.getFunctionSymbol(
484cdf0e10cSrcweir 						::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CleanCurUserOldSystemRegistry" ) ) ) );
485cdf0e10cSrcweir 
486cdf0e10cSrcweir 		if( pNativeProc!=NULL )
487cdf0e10cSrcweir 		{
488cdf0e10cSrcweir 			::rtl::OUString aExecCompleteSysPath;
489cdf0e10cSrcweir 			if ( osl::File::getSystemPathFromFileURL( aExecCompletePath, aExecCompleteSysPath ) == FileBase::E_None
490cdf0e10cSrcweir 			  && aExecCompleteSysPath.getLength() )
491cdf0e10cSrcweir 			{
492cdf0e10cSrcweir 				( *pNativeProc )( (wchar_t*)( aExecCompleteSysPath.getStr() ) );
493cdf0e10cSrcweir 			}
494cdf0e10cSrcweir 		}
495cdf0e10cSrcweir 	}
496cdf0e10cSrcweir #endif
497cdf0e10cSrcweir }
498cdf0e10cSrcweir 
showOnlineUpdatePage()499cdf0e10cSrcweir sal_Bool FirstStartWizard::showOnlineUpdatePage()
500cdf0e10cSrcweir {
501cdf0e10cSrcweir     try {
502cdf0e10cSrcweir         Reference < XNameReplace > xUpdateAccess;
503cdf0e10cSrcweir         Reference < XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
504cdf0e10cSrcweir 
505cdf0e10cSrcweir         xUpdateAccess = Reference < XNameReplace >(
506cdf0e10cSrcweir             xFactory->createInstance( UNISTRING( "com.sun.star.setup.UpdateCheckConfig" ) ), UNO_QUERY_THROW );
507cdf0e10cSrcweir 
508cdf0e10cSrcweir         if ( xUpdateAccess.is() )
509cdf0e10cSrcweir         {
510cdf0e10cSrcweir             sal_Bool bAutoUpdChk = sal_False;
511cdf0e10cSrcweir             Any result = xUpdateAccess->getByName( UNISTRING( "AutoCheckEnabled" ) );
512cdf0e10cSrcweir             result >>= bAutoUpdChk;
513cdf0e10cSrcweir             if ( bAutoUpdChk == sal_False )
514cdf0e10cSrcweir                 return sal_True;
515cdf0e10cSrcweir             else
516cdf0e10cSrcweir                 return sal_False;
517cdf0e10cSrcweir         }
518cdf0e10cSrcweir     } catch (const Exception&)
519cdf0e10cSrcweir     {
520cdf0e10cSrcweir     }
521cdf0e10cSrcweir     return sal_False;
522cdf0e10cSrcweir }
523cdf0e10cSrcweir 
524cdf0e10cSrcweir }
525