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