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: pages.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"
37 #include "migration.hxx"
38 #include <vcl/msgbox.hxx>
39 #include <vcl/mnemonic.hxx>
41 #include <rtl/ustring.hxx>
42 #include <osl/file.hxx>
43 #include <unotools/bootstrap.hxx>
44 #include <unotools/configmgr.hxx>
45 #include <svtools/regoptions.hxx>
46 #include <svtools/useroptions.hxx>
47 #include <sfx2/basedlgs.hxx>
48 #include <comphelper/processfactory.hxx>
49 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
50 #include <com/sun/star/lang/XInitialization.hpp>
51 #include <com/sun/star/frame/XDesktop.hpp>
52 #include <com/sun/star/beans/XMaterialHolder.hpp>
53 #include <com/sun/star/beans/NamedValue.hpp>
54 #include <com/sun/star/container/XNameReplace.hpp>
55 #include <com/sun/star/task/XJobExecutor.hpp>
56 #include <comphelper/configurationhelper.hxx>
57 #include <rtl/bootstrap.hxx>
58 #include <rtl/ustrbuf.hxx>
59 #include <osl/file.hxx>
60 #include <unotools/bootstrap.hxx>
61 #include <tools/config.hxx>
68 using namespace com::sun::star::frame
;
69 using namespace com::sun::star::lang
;
70 using namespace com::sun::star::util
;
71 using namespace com::sun::star::beans
;
72 using namespace com::sun::star::uno
;
73 using namespace com::sun::star::container
;
75 #define UNISTRING(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
79 static void _setBold(FixedText
& ft
)
81 Font f
= ft
.GetControlFont();
82 f
.SetWeight(WEIGHT_BOLD
);
86 WelcomePage::WelcomePage( svt::OWizardMachine
* parent
, const ResId
& resid
, sal_Bool bLicenseNeedsAcceptance
)
87 : OWizardPage(parent
, resid
)
88 , m_ftHead(this, WizardResId(FT_WELCOME_HEADER
))
89 , m_ftBody(this, WizardResId(FT_WELCOME_BODY
))
91 , m_bLicenseNeedsAcceptance( bLicenseNeedsAcceptance
)
92 , bIsEvalVersion(false)
100 // we need to choose the welcome text that is diplayed
101 // choices are the default text, default text+migradtion,
102 // OEM and extended OEM
106 // check for migration
107 if (Migration::checkMigration())
109 String
aText(WizardResId(STR_WELCOME_MIGRATION
));
110 // replace %OLDPRODUCT with found version name
111 aText
.SearchAndReplaceAll( UniString::CreateFromAscii("%OLD_VERSION"), Migration::getOldVersionName());
112 m_ftBody
.SetText( aText
);
115 if (bIsEvalVersion
&& (! bNoEvalText
))
117 String
aText(WizardResId(STR_WELCOME_EVAL
));
118 aText
.SearchAndReplaceAll( UniString::CreateFromAscii("%EVALDAYS"), UniString::CreateFromAscii("90"));
119 m_ftBody
.SetText( aText
);
122 if ( ! m_bLicenseNeedsAcceptance
)
124 String
aText(WizardResId(STR_WELCOME_WITHOUT_LICENSE
));
125 m_ftBody
.SetText( aText
);
129 m_ftBody
.SetText(String(WizardResId(STR_WELCOME_OEM
)));
132 m_ftBody
.SetText(String(WizardResId(STR_WELCOME_OEM_EXT
)));
139 void WelcomePage::checkEval()
141 Reference
< XMultiServiceFactory
> xFactory
= ::comphelper::getProcessServiceFactory();
142 Reference
< XMaterialHolder
> xHolder(xFactory
->createInstance(
143 OUString::createFromAscii("com.sun.star.tab.tabreg")), UNO_QUERY
);
145 Any aData
= xHolder
->getMaterial();
146 Sequence
< NamedValue
> aSeq
;
147 if (aData
>>= aSeq
) {
148 bIsEvalVersion
= true;
149 for (int i
=0; i
< aSeq
.getLength(); i
++) {
150 if (aSeq
[i
].Name
.equalsAscii("NoEvalText")) {
151 aSeq
[i
].Value
>>= bNoEvalText
;
159 void WelcomePage::ActivatePage()
161 OWizardPage::ActivatePage();
162 // this page has no controls, so forwarding to default
163 // button (next) won't work if we grap focus
167 LicensePage::LicensePage( svt::OWizardMachine
* parent
, const ResId
& resid
, const rtl::OUString
&rLicensePath
)
168 : OWizardPage(parent
, resid
)
170 , m_ftHead(this, WizardResId(FT_LICENSE_HEADER
))
171 , m_ftBody1(this, WizardResId(FT_LICENSE_BODY_1
))
172 , m_ftBody1Txt(this, WizardResId(FT_LICENSE_BODY_1_TXT
))
173 , m_ftBody2(this, WizardResId(FT_LICENSE_BODY_2
))
174 , m_ftBody2Txt(this, WizardResId(FT_LICENSE_BODY_2_TXT
))
175 , m_mlLicense(this, WizardResId(ML_LICENSE
))
176 , m_pbDown(this, WizardResId(PB_LICENSE_DOWN
))
177 , m_bLicenseRead(sal_False
)
183 m_mlLicense
.SetEndReachedHdl( LINK(this, LicensePage
, EndReachedHdl
) );
184 m_mlLicense
.SetScrolledHdl( LINK(this, LicensePage
, ScrolledHdl
) );
185 m_pbDown
.SetClickHdl( LINK(this, LicensePage
, PageDownHdl
) );
187 // We want a automatic repeating page down button
188 WinBits aStyle
= m_pbDown
.GetStyle();
190 m_pbDown
.SetStyle( aStyle
);
192 // replace %PAGEDOWN in text2 with button text
193 String aText
= m_ftBody1Txt
.GetText();
194 aText
.SearchAndReplaceAll( UniString::CreateFromAscii("%PAGEDOWN"),
195 MnemonicGenerator::EraseAllMnemonicChars(m_pbDown
.GetText()));
197 m_ftBody1Txt
.SetText( aText
);
200 File
aLicenseFile(rLicensePath
);
201 if ( aLicenseFile
.open(OpenFlag_Read
) == FileBase::E_None
)
204 DirectoryItem::get(rLicensePath
, d
);
205 FileStatus
fs(FileStatusMask_FileSize
);
207 sal_uInt64 nBytesRead
= 0;
208 sal_uInt64 nPosition
= 0;
209 sal_uInt32 nBytes
= (sal_uInt32
)fs
.getFileSize();
210 sal_Char
*pBuffer
= new sal_Char
[nBytes
];
211 // FileBase RC r = FileBase::E_None;
212 while (aLicenseFile
.read(pBuffer
+nPosition
, nBytes
-nPosition
, nBytesRead
) == FileBase::E_None
213 && nPosition
+ nBytesRead
< nBytes
)
215 nPosition
+= nBytesRead
;
217 OUString
aLicenseString(pBuffer
, nBytes
, RTL_TEXTENCODING_UTF8
,
218 OSTRING_TO_OUSTRING_CVTFLAGS
| RTL_TEXTTOUNICODE_FLAGS_GLOBAL_SIGNATURE
);
220 m_mlLicense
.SetText(aLicenseString
);
225 void LicensePage::ActivatePage()
227 OWizardPage::ActivatePage();
228 m_bLicenseRead
= m_mlLicense
.IsEndReached();
229 m_pbDown
.GrabFocus();
230 updateDialogTravelUI();
233 bool LicensePage::canAdvance() const
235 if (m_mlLicense
.IsEndReached())
236 const_cast< LicensePage
* >( this )->m_pbDown
.Disable();
238 const_cast< LicensePage
* >( this )->m_pbDown
.Enable();
240 return m_bLicenseRead
;
243 IMPL_LINK( LicensePage
, PageDownHdl
, PushButton
*, EMPTYARG
)
245 m_mlLicense
.ScrollDown( SCROLL_PAGEDOWN
);
249 IMPL_LINK( LicensePage
, EndReachedHdl
, LicenseView
*, EMPTYARG
)
251 m_bLicenseRead
= TRUE
;
252 updateDialogTravelUI();
256 IMPL_LINK( LicensePage
, ScrolledHdl
, LicenseView
*, EMPTYARG
)
258 updateDialogTravelUI();
263 LicenseView::LicenseView( Window
* pParent
, const ResId
& rResId
)
264 : MultiLineEdit( pParent
, rResId
)
267 mbEndReached
= IsEndReached();
268 StartListening( *GetTextEngine() );
271 LicenseView::~LicenseView()
273 maEndReachedHdl
= Link();
274 maScrolledHdl
= Link();
278 void LicenseView::ScrollDown( ScrollType eScroll
)
280 ScrollBar
* pScroll
= GetVScrollBar();
282 pScroll
->DoScrollAction( eScroll
);
285 BOOL
LicenseView::IsEndReached() const
289 ExtTextView
* pView
= GetTextView();
290 ExtTextEngine
* pEdit
= GetTextEngine();
291 ULONG nHeight
= pEdit
->GetTextHeight();
292 Size aOutSize
= pView
->GetWindow()->GetOutputSizePixel();
293 Point
aBottom( 0, aOutSize
.Height() );
295 if ( (ULONG
) pView
->GetDocPos( aBottom
).Y() >= nHeight
- 1 )
303 void LicenseView::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
305 if ( rHint
.IsA( TYPE(TextHint
) ) )
307 BOOL bLastVal
= EndReached();
308 ULONG nId
= ((const TextHint
&)rHint
).GetId();
310 if ( nId
== TEXT_HINT_PARAINSERTED
)
313 mbEndReached
= IsEndReached();
315 else if ( nId
== TEXT_HINT_VIEWSCROLLED
)
317 if ( ! mbEndReached
)
318 mbEndReached
= IsEndReached();
319 maScrolledHdl
.Call( this );
322 if ( EndReached() && !bLastVal
)
324 maEndReachedHdl
.Call( this );
331 // -------------------------------------------------------------------
333 MigrationPage::MigrationPage( svt::OWizardMachine
* parent
, const ResId
& resid
)
334 : OWizardPage(parent
, resid
)
335 , m_ftHead(this, WizardResId(FT_MIGRATION_HEADER
))
336 , m_ftBody(this, WizardResId(FT_MIGRATION_BODY
))
337 , m_cbMigration(this, WizardResId(CB_MIGRATION
))
338 , m_bMigrationDone(sal_False
)
343 // replace %OLDPRODUCT with found version name
344 String aText
= m_ftBody
.GetText();
345 aText
.SearchAndReplaceAll( UniString::CreateFromAscii("%OLDPRODUCT"), Migration::getOldVersionName());
346 m_ftBody
.SetText( aText
);
349 sal_Bool
MigrationPage::commitPage( CommitPageReason _eReason
)
351 if (_eReason
== eTravelForward
&& m_cbMigration
.IsChecked() && !m_bMigrationDone
)
354 Migration::doMigration();
356 m_bMigrationDone
= sal_True
;
359 Migration::cancelMigration();
363 void MigrationPage::ActivatePage()
365 OWizardPage::ActivatePage();
369 UserPage::UserPage( svt::OWizardMachine
* parent
, const ResId
& resid
)
370 : OWizardPage(parent
, resid
)
371 , m_ftHead(this, WizardResId(FT_USER_HEADER
))
372 , m_ftBody(this, WizardResId(FT_USER_BODY
))
373 , m_ftFirst(this, WizardResId(FT_USER_FIRST
))
374 , m_edFirst(this, WizardResId(ED_USER_FIRST
))
375 , m_ftLast(this, WizardResId(FT_USER_LAST
))
376 , m_edLast(this, WizardResId(ED_USER_LAST
))
377 , m_ftInitials(this, WizardResId(FT_USER_INITIALS
))
378 , m_edInitials(this, WizardResId(ED_USER_INITIALS
))
379 , m_ftFather(this, WizardResId(FT_USER_FATHER
))
380 , m_edFather(this, WizardResId(ED_USER_FATHER
))
381 , m_lang(Application::GetSettings().GetUILanguage())
386 // check whether this is a russian version. otherwise
387 // we'll hide the 'Fathers name' field
388 SvtUserOptions aUserOpt
;
389 m_edFirst
.SetText(aUserOpt
.GetFirstName());
390 m_edLast
.SetText(aUserOpt
.GetLastName());
391 m_edInitials
.SetText(aUserOpt
.GetID());
392 if (m_lang
== LANGUAGE_RUSSIAN
)
396 m_edFather
.SetText(aUserOpt
.GetFathersName());
400 sal_Bool
UserPage::commitPage( CommitPageReason
)
402 SvtUserOptions aUserOpt
;
403 aUserOpt
.SetFirstName(m_edFirst
.GetText());
404 aUserOpt
.SetLastName(m_edLast
.GetText());
405 aUserOpt
.SetID( m_edInitials
.GetText());
406 if (m_lang
== LANGUAGE_RUSSIAN
)
407 aUserOpt
.SetFathersName(m_edFather
.GetText());
412 void UserPage::ActivatePage()
414 OWizardPage::ActivatePage();
418 // -------------------------------------------------------------------
419 UpdateCheckPage::UpdateCheckPage( svt::OWizardMachine
* parent
, const ResId
& resid
)
420 : OWizardPage(parent
, resid
)
421 , m_ftHead(this, WizardResId(FT_UPDATE_CHECK_HEADER
))
422 , m_ftBody(this, WizardResId(FT_UPDATE_CHECK_BODY
))
423 , m_cbUpdateCheck(this, WizardResId(CB_UPDATE_CHECK
))
429 sal_Bool
UpdateCheckPage::commitPage( CommitPageReason _eReason
)
431 if ( _eReason
== eTravelForward
)
434 Reference
< XNameReplace
> xUpdateAccess
;
435 Reference
< XMultiServiceFactory
> xFactory( ::comphelper::getProcessServiceFactory() );
437 xUpdateAccess
= Reference
< XNameReplace
>(
438 xFactory
->createInstance( UNISTRING( "com.sun.star.setup.UpdateCheckConfig" ) ), UNO_QUERY_THROW
);
440 if ( !xUpdateAccess
.is() )
443 sal_Bool bAutoUpdChk
= m_cbUpdateCheck
.IsChecked();
444 xUpdateAccess
->replaceByName( UNISTRING("AutoCheckEnabled"), makeAny( bAutoUpdChk
) );
446 Reference
< XChangesBatch
> xChangesBatch( xUpdateAccess
, UNO_QUERY
);
447 if( xChangesBatch
.is() && xChangesBatch
->hasPendingChanges() )
448 xChangesBatch
->commitChanges();
449 } catch (RuntimeException
)
457 void UpdateCheckPage::ActivatePage()
459 OWizardPage::ActivatePage();
463 // -------------------------------------------------------------------
464 RegistrationPage::RegistrationPage( Window
* pParent
, const ResId
& rResid
)
465 : OWizardPage( pParent
, rResid
)
466 , m_ftHeader(this, WizardResId(FT_REGISTRATION_HEADER
))
467 , m_ftBody(this, WizardResId(FT_REGISTRATION_BODY
))
468 , m_rbNow(this, WizardResId(RB_REGISTRATION_NOW
))
469 , m_rbLater(this, WizardResId(RB_REGISTRATION_LATER
))
470 , m_rbNever(this, WizardResId(RB_REGISTRATION_NEVER
))
471 , m_flSeparator(this, WizardResId(FL_REGISTRATION
))
472 , m_ftEnd(this, WizardResId(FT_REGISTRATION_END
))
473 , m_bNeverVisible( sal_True
)
477 // another text for OOo
478 sal_Int32 nOpenSourceContext
= 0;
481 ::utl::ConfigManager::GetDirectConfigProperty(
482 ::utl::ConfigManager::OPENSOURCECONTEXT
) >>= nOpenSourceContext
;
486 DBG_ERRORFILE( "RegistrationPage::RegistrationPage(): error while getting open source context" );
489 if ( nOpenSourceContext
> 0 )
491 String
sBodyText( WizardResId( STR_REGISTRATION_OOO
) );
492 m_ftBody
.SetText( sBodyText
);
495 // calculate height of body text and rearrange the buttons
496 Size aSize
= m_ftBody
.GetSizePixel();
497 Size aMinSize
= m_ftBody
.CalcMinimumSize( aSize
.Width() );
498 long nTxtH
= aMinSize
.Height();
499 long nCtrlH
= aSize
.Height();
500 long nDelta
= ( nCtrlH
- nTxtH
);
501 aSize
.Height() -= nDelta
;
502 m_ftBody
.SetSizePixel( aSize
);
503 Window
* pWins
[] = { &m_rbNow
, &m_rbLater
, &m_rbNever
};
504 Window
** pCurrent
= pWins
;
505 for ( sal_uInt32 i
= 0; i
< sizeof( pWins
) / sizeof( pWins
[ 0 ] ); ++i
, ++pCurrent
)
507 Point aNewPos
= (*pCurrent
)->GetPosPixel();
508 aNewPos
.Y() -= nDelta
;
509 (*pCurrent
)->SetPosPixel( aNewPos
);
512 _setBold(m_ftHeader
);
513 impl_retrieveConfigurationData();
514 updateButtonStates();
517 bool RegistrationPage::canAdvance() const
522 void RegistrationPage::ActivatePage()
524 OWizardPage::ActivatePage();
528 void RegistrationPage::impl_retrieveConfigurationData()
530 static ::rtl::OUString PACKAGE
= ::rtl::OUString::createFromAscii("org.openoffice.FirstStartWizard");
531 static ::rtl::OUString PATH
= ::rtl::OUString::createFromAscii("TabPages/Registration/RegistrationOptions/NeverButton");
532 static ::rtl::OUString KEY
= ::rtl::OUString::createFromAscii("Visible");
534 ::com::sun::star::uno::Any aValue
;
537 aValue
= ::comphelper::ConfigurationHelper::readDirectKey(
538 ::comphelper::getProcessServiceFactory(),
542 ::comphelper::ConfigurationHelper::E_READONLY
);
544 catch(const ::com::sun::star::uno::Exception
&)
547 aValue
>>= m_bNeverVisible
;
550 void RegistrationPage::updateButtonStates()
552 m_rbNever
.Show( m_bNeverVisible
);
555 sal_Bool
RegistrationPage::commitPage( CommitPageReason _eReason
)
557 if ( _eReason
== eFinish
)
559 ::svt::RegOptions aOptions
;
560 rtl::OUString aEvent
;
562 if ( m_rbNow
.IsChecked())
564 aEvent
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RegistrationRequired" ) );
566 else if (m_rbLater
.IsChecked())
568 aOptions
.activateReminder(7);
569 // avtivate a reminder job...
571 // aOptions.markSessionDone();
575 // create the Desktop component which can load components
576 Reference
< XMultiServiceFactory
> xFactory
= ::comphelper::getProcessServiceFactory();
579 Reference
< com::sun::star::task::XJobExecutor
> xProductRegistration(
580 xFactory
->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.setup.ProductRegistration" ) ) ),
583 // tell it that the user wants to register
584 xProductRegistration
->trigger( aEvent
);
587 catch( const Exception
& )
594 RegistrationPage::RegistrationMode
RegistrationPage::getRegistrationMode() const
596 RegistrationPage::RegistrationMode eMode
= rmNow
;
597 if ( m_rbLater
.IsChecked() )
599 else if ( m_rbNever
.IsChecked() )
604 void RegistrationPage::prepareSingleMode()
606 // remove wizard text (hide and cut)
607 m_flSeparator
.Hide();
609 Size aNewSize
= GetSizePixel();
610 aNewSize
.Height() -= ( aNewSize
.Height() - m_flSeparator
.GetPosPixel().Y() );
611 SetSizePixel( aNewSize
);
614 bool RegistrationPage::hasReminderDateCome()
616 return ::svt::RegOptions().hasReminderDateCome();
619 void RegistrationPage::executeSingleMode()
621 // opens the page in a single tabdialog
622 SfxSingleTabDialog
aSingleDlg( NULL
, TP_REGISTRATION
);
623 RegistrationPage
* pPage
= new RegistrationPage( &aSingleDlg
, WizardResId( TP_REGISTRATION
) );
624 pPage
->prepareSingleMode();
625 aSingleDlg
.SetPage( pPage
);
626 aSingleDlg
.SetText( pPage
->getSingleModeTitle() );
627 aSingleDlg
.Execute();
628 // the registration modes "Now" and "Later" are handled by the page
629 RegistrationPage::RegistrationMode eMode
= pPage
->getRegistrationMode();
630 if ( eMode
== RegistrationPage::rmNow
|| eMode
== RegistrationPage::rmLater
)
631 pPage
->commitPage( IWizardPage::eFinish
);
632 if ( eMode
!= RegistrationPage::rmLater
)
633 ::svt::RegOptions().removeReminder();
636 // -----------------------------------------------------------------------
638 static char const OEM_PRELOAD_SECTION
[] = "Bootstrap";
639 static char const OEM_PRELOAD
[] = "Preload";
640 static char const STR_TRUE
[] = "1";
641 static char const STR_FALSE
[] = "0";
643 static sal_Bool
existsURL( OUString
const& _sURL
)
646 DirectoryItem aDirItem
;
648 if (_sURL
.getLength() != 0)
649 return ( DirectoryItem::get( _sURL
, aDirItem
) == DirectoryItem::E_None
);
655 // locate soffice.ini/.rc file
656 static OUString
locateIniFile()
658 OUString aUserDataPath
;
659 OUString aSofficeIniFileURL
;
661 // Retrieve the default file URL for the soffice.ini/rc
662 rtl::Bootstrap().getIniName( aSofficeIniFileURL
);
664 if ( utl::Bootstrap::locateUserData( aUserDataPath
) == utl::Bootstrap::PATH_EXISTS
)
666 const char CONFIG_DIR
[] = "/config";
668 sal_Int32 nIndex
= aSofficeIniFileURL
.lastIndexOf( '/');
671 OUString aUserSofficeIniFileURL
;
672 OUStringBuffer
aBuffer( aUserDataPath
);
673 aBuffer
.appendAscii( CONFIG_DIR
);
674 aBuffer
.append( aSofficeIniFileURL
.copy( nIndex
));
675 aUserSofficeIniFileURL
= aBuffer
.makeStringAndClear();
677 if ( existsURL( aUserSofficeIniFileURL
))
678 return aUserSofficeIniFileURL
;
681 // Fallback try to use the soffice.ini/rc from program folder
682 return aSofficeIniFileURL
;
685 // check whether the OEMPreload flag was set in soffice.ini/.rc
686 static sal_Int32
checkOEMPreloadFlag()
688 OUString aSofficeIniFileURL
;
689 aSofficeIniFileURL
= locateIniFile();
690 Config
aConfig(aSofficeIniFileURL
);
691 aConfig
.SetGroup( OEM_PRELOAD_SECTION
);
692 ByteString sResult
= aConfig
.ReadKey( OEM_PRELOAD
);
693 return sResult
.ToInt32();
695 if ( sResult == STR_TRUE )
702 WelcomePage::OEMType
WelcomePage::checkOEM()
704 sal_Int32 oemResult
= checkOEMPreloadFlag();
715 } // namespace desktop