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