Bump version to 5.0-14
[LibreOffice.git] / dbaccess / source / ext / macromigration / macromigrationpages.cxx
blob6d101ca3382a01b710a7acb2d2ae1fece309250a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "dbaccess_helpid.hrc"
21 #include "dbmm_module.hxx"
22 #include "dbmm_global.hrc"
23 #include "macromigration.hrc"
24 #include "macromigrationpages.hxx"
25 #include "macromigrationdialog.hxx"
27 #include <com/sun/star/frame/XModel.hpp>
29 #include <tools/urlobj.hxx>
30 #include <tools/diagnose_ex.h>
31 #include <vcl/metric.hxx>
33 namespace dbmm
36 using ::com::sun::star::uno::Reference;
37 using ::com::sun::star::uno::XInterface;
38 using ::com::sun::star::uno::UNO_QUERY;
39 using ::com::sun::star::uno::UNO_QUERY_THROW;
40 using ::com::sun::star::uno::UNO_SET_THROW;
41 using ::com::sun::star::uno::Exception;
42 using ::com::sun::star::uno::RuntimeException;
43 using ::com::sun::star::uno::Any;
44 using ::com::sun::star::uno::makeAny;
45 using ::com::sun::star::uno::Sequence;
46 using ::com::sun::star::frame::XModel;
48 MacroMigrationPage::MacroMigrationPage(vcl::Window *pParent, const OString& rID, const OUString& rUIXMLDescription)
49 : MacroMigrationPage_Base(pParent, rID, rUIXMLDescription)
53 const MacroMigrationDialog& MacroMigrationPage::getDialog() const
55 return *dynamic_cast< const MacroMigrationDialog* >( GetParentDialog() );
58 MacroMigrationDialog& MacroMigrationPage::getDialog()
60 return *dynamic_cast< MacroMigrationDialog* >( GetParentDialog() );
63 // PreparationPage
64 PreparationPage::PreparationPage(vcl::Window *pParent)
65 : MacroMigrationPage(pParent, "PreparePage" ,"dbaccess/ui/preparepage.ui")
67 get(m_pCloseDocError, "closedocerror");
70 PreparationPage::~PreparationPage()
72 disposeOnce();
75 void PreparationPage::dispose()
77 m_pCloseDocError.clear();
78 MacroMigrationPage::dispose();
81 void PreparationPage::showCloseDocsError( bool _bShow )
83 m_pCloseDocError->Show( _bShow );
86 VclPtr<TabPage> PreparationPage::Create( ::svt::RoadmapWizard& _rParentDialog )
88 return VclPtr<PreparationPage>::Create(&_rParentDialog);
91 // SaveDBDocPage
92 SaveDBDocPage::SaveDBDocPage(MacroMigrationDialog& _rParentDialog)
93 : MacroMigrationPage(&_rParentDialog, "BackupPage" ,"dbaccess/ui/backuppage.ui")
95 get(m_pStartMigration, "startmigrate");
96 get(m_pBrowseSaveAsLocation, "browse");
97 get(m_pSaveAsLocation, "location");
98 m_pLocationController = new svx::DatabaseLocationInputController(
99 _rParentDialog.getComponentContext(), *m_pSaveAsLocation, *m_pBrowseSaveAsLocation);
101 m_pSaveAsLocation->SetModifyHdl( LINK( this, SaveDBDocPage, OnLocationModified ) );
102 m_pSaveAsLocation->SetDropDownLineCount( 20 );
104 impl_updateLocationDependentItems();
107 SaveDBDocPage::~SaveDBDocPage()
109 disposeOnce();
112 void SaveDBDocPage::dispose()
114 delete m_pLocationController;
115 m_pSaveAsLocation.clear();
116 m_pBrowseSaveAsLocation.clear();
117 m_pStartMigration.clear();
118 MacroMigrationPage::dispose();
121 void SaveDBDocPage::impl_updateLocationDependentItems()
123 updateDialogTravelUI();
124 m_pStartMigration->Show(!m_pSaveAsLocation->GetText().isEmpty());
127 IMPL_LINK( SaveDBDocPage, OnLocationModified, Edit*, /**/ )
129 impl_updateLocationDependentItems();
130 return 0L;
133 void SaveDBDocPage::initializePage()
135 OWizardPage::initializePage();
139 // get the document's current URL
140 Reference< XModel > xDocument( getDialog().getDocument(), UNO_QUERY_THROW );
141 INetURLObject aURLParser( xDocument->getURL() );
142 OSL_ENSURE( aURLParser.GetProtocol() != INetProtocol::NotValid, "SaveDBDocPage::initializePage: illegal document URL!" );
144 OUStringBuffer aBaseName( aURLParser.getBase() );
145 aBaseName.appendAscii( ".backup" );
146 aURLParser.setBase( aBaseName.makeStringAndClear() );
148 m_pLocationController->setURL( aURLParser.GetMainURL( INetURLObject::NO_DECODE ) );
149 impl_updateLocationDependentItems();
151 catch( const Exception& )
153 DBG_UNHANDLED_EXCEPTION();
157 bool SaveDBDocPage::canAdvance() const
159 if ( !MacroMigrationPage::canAdvance() )
160 return false;
162 return !m_pSaveAsLocation->GetText().isEmpty();
165 bool SaveDBDocPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
167 if ( !MacroMigrationPage::commitPage( _eReason ) )
168 return false;
170 if ( ::svt::WizardTypes::eTravelBackward == _eReason )
171 return true;
173 if ( !m_pLocationController->prepareCommit() )
174 return false;
176 return true;
179 VclPtr<TabPage> SaveDBDocPage::Create( ::svt::RoadmapWizard& _rParentDialog )
181 return VclPtr<SaveDBDocPage>::Create( dynamic_cast< MacroMigrationDialog& >( _rParentDialog ) );
184 // ProgressPage
185 ProgressPage::ProgressPage(vcl::Window* pParent)
186 : MacroMigrationPage(pParent, "MigratePage" ,"dbaccess/ui/migratepage.ui")
188 get(m_pObjectCount, "count");
189 get(m_pCurrentObject, "object");
190 get(m_pCurrentAction, "current");
191 m_aCurrentProgress.Set(get<ProgressBar>("currentprogress"));
192 get(m_pAllProgressText, "overall");
193 m_aAllProgress.Set(get<ProgressBar>("allprogress"));
194 get(m_pMigrationDone, "done");
197 ProgressPage::~ProgressPage()
199 disposeOnce();
202 void ProgressPage::dispose()
204 m_pObjectCount.clear();
205 m_pCurrentObject.clear();
206 m_pCurrentAction.clear();
207 m_pAllProgressText.clear();
208 m_pMigrationDone.clear();
209 MacroMigrationPage::dispose();
212 VclPtr<TabPage> ProgressPage::Create(::svt::RoadmapWizard& _rParentDialog)
214 return VclPtr<ProgressPage>::Create(&_rParentDialog);
217 void ProgressPage::setDocumentCounts( const sal_Int32 _nForms, const sal_Int32 _nReports )
219 OUString sText( m_pObjectCount->GetText() );
220 sText = sText.replaceFirst( "$forms$", OUString::number( _nForms ) );
221 sText = sText.replaceFirst( "$reports$", OUString::number( _nReports ) );
222 m_pObjectCount->SetText( sText );
225 void ProgressPage::onFinishedSuccessfully()
227 m_pMigrationDone->Show();
230 void ProgressPage::startObject( const OUString& _rObjectName, const OUString& _rCurrentAction, const sal_uInt32 _nRange )
232 m_pCurrentObject->SetText( _rObjectName );
233 m_pCurrentAction->SetText( _rCurrentAction );
234 m_aCurrentProgress.SetRange( _nRange );
235 m_aCurrentProgress.SetValue( (sal_uInt32)0 );
237 // since this is currently called from the main thread, which does not have the chance
238 // to re-schedule, we need to explicitly update the display
239 m_pCurrentObject->Update();
240 m_pCurrentAction->Update();
241 Update();
244 void ProgressPage::setObjectProgressText( const OUString& _rText )
246 m_pCurrentAction->SetText( _rText );
247 m_pCurrentAction->Update();
248 Update();
251 void ProgressPage::setObjectProgressValue( const sal_uInt32 _nValue )
253 m_aCurrentProgress.SetValue( _nValue );
254 Update();
257 void ProgressPage::endObject()
259 m_pCurrentAction->SetText( OUString() );
260 m_aCurrentProgress.SetValue( m_aCurrentProgress.GetRange() );
261 m_pCurrentAction->Update();
262 Update();
265 void ProgressPage::start( const sal_uInt32 _nOverallRange )
267 m_aAllProgress.SetRange( _nOverallRange );
268 Update();
271 void ProgressPage::setOverallProgressText( const OUString& _rText )
273 m_pAllProgressText->SetText( _rText );
274 Update();
277 void ProgressPage::setOverallProgressValue( const sal_uInt32 _nValue )
279 m_aAllProgress.SetValue( _nValue );
280 Update();
283 // ResultPage
284 ResultPage::ResultPage(vcl::Window* pParent)
285 : MacroMigrationPage(pParent, "SummaryPage" ,"dbaccess/ui/summarypage.ui")
287 get(m_pChanges, "textview");
288 m_pChanges->set_height_request(GetTextHeight() * 10);
289 m_pChanges->set_width_request(approximate_char_width() * 40);
290 get(m_pSuccessLabel, "success");
291 get(m_pFailureLabel, "failure");
294 ResultPage::~ResultPage()
296 disposeOnce();
299 void ResultPage::dispose()
301 m_pSuccessLabel.clear();
302 m_pFailureLabel.clear();
303 m_pChanges.clear();
304 MacroMigrationPage::dispose();
307 VclPtr<TabPage> ResultPage::Create(::svt::RoadmapWizard& _rParentDialog)
309 return VclPtr<ResultPage>::Create(&_rParentDialog);
312 void ResultPage::displayMigrationLog(const bool _bSuccessful, const OUString& _rSummary)
314 if (_bSuccessful)
315 m_pFailureLabel->Hide();
316 else
317 m_pSuccessLabel->Hide();
318 m_pChanges->SetText(_rSummary);
321 } // namespace dbmm
323 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */