Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / dbaccess / source / ext / macromigration / macromigrationpages.cxx
blob9192eb6601a8018d0b19a95e4afa088663dc29f0
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::UNO_QUERY_THROW;
38 using ::com::sun::star::uno::Exception;
39 using ::com::sun::star::frame::XModel;
41 MacroMigrationPage::MacroMigrationPage(vcl::Window *pParent, const OString& rID, const OUString& rUIXMLDescription)
42 : MacroMigrationPage_Base(pParent, rID, rUIXMLDescription)
46 MacroMigrationDialog& MacroMigrationPage::getDialog()
48 return *dynamic_cast< MacroMigrationDialog* >( GetParentDialog() );
51 // PreparationPage
52 PreparationPage::PreparationPage(vcl::Window *pParent)
53 : MacroMigrationPage(pParent, "PreparePage" ,"dbaccess/ui/preparepage.ui")
55 get(m_pCloseDocError, "closedocerror");
58 PreparationPage::~PreparationPage()
60 disposeOnce();
63 void PreparationPage::dispose()
65 m_pCloseDocError.clear();
66 MacroMigrationPage::dispose();
69 void PreparationPage::showCloseDocsError( bool _bShow )
71 m_pCloseDocError->Show( _bShow );
74 VclPtr<TabPage> PreparationPage::Create( ::svt::RoadmapWizard& _rParentDialog )
76 return VclPtr<PreparationPage>::Create(&_rParentDialog);
79 // SaveDBDocPage
80 SaveDBDocPage::SaveDBDocPage(MacroMigrationDialog& _rParentDialog)
81 : MacroMigrationPage(&_rParentDialog, "BackupPage" ,"dbaccess/ui/backuppage.ui")
83 get(m_pStartMigration, "startmigrate");
84 get(m_pBrowseSaveAsLocation, "browse");
85 get(m_pSaveAsLocation, "location");
86 m_pLocationController = new svx::DatabaseLocationInputController(
87 _rParentDialog.getComponentContext(), *m_pSaveAsLocation, *m_pBrowseSaveAsLocation);
89 m_pSaveAsLocation->SetModifyHdl( LINK( this, SaveDBDocPage, OnLocationModified ) );
90 m_pSaveAsLocation->SetDropDownLineCount( 20 );
92 impl_updateLocationDependentItems();
95 SaveDBDocPage::~SaveDBDocPage()
97 disposeOnce();
100 void SaveDBDocPage::dispose()
102 delete m_pLocationController;
103 m_pSaveAsLocation.clear();
104 m_pBrowseSaveAsLocation.clear();
105 m_pStartMigration.clear();
106 MacroMigrationPage::dispose();
109 void SaveDBDocPage::impl_updateLocationDependentItems()
111 updateDialogTravelUI();
112 m_pStartMigration->Show(!m_pSaveAsLocation->GetText().isEmpty());
115 IMPL_LINK_NOARG_TYPED( SaveDBDocPage, OnLocationModified, Edit&, void )
117 impl_updateLocationDependentItems();
120 void SaveDBDocPage::initializePage()
122 OWizardPage::initializePage();
126 // get the document's current URL
127 Reference< XModel > xDocument( getDialog().getDocument(), UNO_QUERY_THROW );
128 INetURLObject aURLParser( xDocument->getURL() );
129 OSL_ENSURE( aURLParser.GetProtocol() != INetProtocol::NotValid, "SaveDBDocPage::initializePage: illegal document URL!" );
131 OUStringBuffer aBaseName( aURLParser.getBase() );
132 aBaseName.append( ".backup" );
133 aURLParser.setBase( aBaseName.makeStringAndClear() );
135 m_pLocationController->setURL( aURLParser.GetMainURL( INetURLObject::NO_DECODE ) );
136 impl_updateLocationDependentItems();
138 catch( const Exception& )
140 DBG_UNHANDLED_EXCEPTION();
144 bool SaveDBDocPage::canAdvance() const
146 if ( !MacroMigrationPage::canAdvance() )
147 return false;
149 return !m_pSaveAsLocation->GetText().isEmpty();
152 bool SaveDBDocPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
154 if ( !MacroMigrationPage::commitPage( _eReason ) )
155 return false;
157 if ( ::svt::WizardTypes::eTravelBackward == _eReason )
158 return true;
160 if ( !m_pLocationController->prepareCommit() )
161 return false;
163 return true;
166 VclPtr<TabPage> SaveDBDocPage::Create( ::svt::RoadmapWizard& _rParentDialog )
168 return VclPtr<SaveDBDocPage>::Create( dynamic_cast< MacroMigrationDialog& >( _rParentDialog ) );
171 // ProgressPage
172 ProgressPage::ProgressPage(vcl::Window* pParent)
173 : MacroMigrationPage(pParent, "MigratePage" ,"dbaccess/ui/migratepage.ui")
175 get(m_pObjectCount, "count");
176 get(m_pCurrentObject, "object");
177 get(m_pCurrentAction, "current");
178 m_aCurrentProgress.Set(get<ProgressBar>("currentprogress"));
179 get(m_pAllProgressText, "overall");
180 m_aAllProgress.Set(get<ProgressBar>("allprogress"));
181 get(m_pMigrationDone, "done");
184 ProgressPage::~ProgressPage()
186 disposeOnce();
189 void ProgressPage::dispose()
191 m_pObjectCount.clear();
192 m_pCurrentObject.clear();
193 m_pCurrentAction.clear();
194 m_pAllProgressText.clear();
195 m_pMigrationDone.clear();
196 MacroMigrationPage::dispose();
199 VclPtr<TabPage> ProgressPage::Create(::svt::RoadmapWizard& _rParentDialog)
201 return VclPtr<ProgressPage>::Create(&_rParentDialog);
204 void ProgressPage::setDocumentCounts( const sal_Int32 _nForms, const sal_Int32 _nReports )
206 OUString sText( m_pObjectCount->GetText() );
207 sText = sText.replaceFirst( "$forms$", OUString::number( _nForms ) );
208 sText = sText.replaceFirst( "$reports$", OUString::number( _nReports ) );
209 m_pObjectCount->SetText( sText );
212 void ProgressPage::onFinishedSuccessfully()
214 m_pMigrationDone->Show();
217 void ProgressPage::startObject( const OUString& _rObjectName, const OUString& _rCurrentAction, const sal_uInt32 _nRange )
219 m_pCurrentObject->SetText( _rObjectName );
220 m_pCurrentAction->SetText( _rCurrentAction );
221 m_aCurrentProgress.SetRange( _nRange );
222 m_aCurrentProgress.SetValue( (sal_uInt32)0 );
224 // since this is currently called from the main thread, which does not have the chance
225 // to re-schedule, we need to explicitly update the display
226 m_pCurrentObject->Update();
227 m_pCurrentAction->Update();
228 Update();
231 void ProgressPage::setObjectProgressText( const OUString& _rText )
233 m_pCurrentAction->SetText( _rText );
234 m_pCurrentAction->Update();
235 Update();
238 void ProgressPage::setObjectProgressValue( const sal_uInt32 _nValue )
240 m_aCurrentProgress.SetValue( _nValue );
241 Update();
244 void ProgressPage::endObject()
246 m_pCurrentAction->SetText( OUString() );
247 m_aCurrentProgress.SetValue( m_aCurrentProgress.GetRange() );
248 m_pCurrentAction->Update();
249 Update();
252 void ProgressPage::start( const sal_uInt32 _nOverallRange )
254 m_aAllProgress.SetRange( _nOverallRange );
255 Update();
258 void ProgressPage::setOverallProgressText( const OUString& _rText )
260 m_pAllProgressText->SetText( _rText );
261 Update();
264 void ProgressPage::setOverallProgressValue( const sal_uInt32 _nValue )
266 m_aAllProgress.SetValue( _nValue );
267 Update();
270 // ResultPage
271 ResultPage::ResultPage(vcl::Window* pParent)
272 : MacroMigrationPage(pParent, "SummaryPage" ,"dbaccess/ui/summarypage.ui")
274 get(m_pChanges, "textview");
275 m_pChanges->set_height_request(GetTextHeight() * 10);
276 m_pChanges->set_width_request(approximate_char_width() * 40);
277 get(m_pSuccessLabel, "success");
278 get(m_pFailureLabel, "failure");
281 ResultPage::~ResultPage()
283 disposeOnce();
286 void ResultPage::dispose()
288 m_pSuccessLabel.clear();
289 m_pFailureLabel.clear();
290 m_pChanges.clear();
291 MacroMigrationPage::dispose();
294 VclPtr<TabPage> ResultPage::Create(::svt::RoadmapWizard& _rParentDialog)
296 return VclPtr<ResultPage>::Create(&_rParentDialog);
299 void ResultPage::displayMigrationLog(const bool _bSuccessful, const OUString& _rSummary)
301 if (_bSuccessful)
302 m_pFailureLabel->Hide();
303 else
304 m_pSuccessLabel->Hide();
305 m_pChanges->SetText(_rSummary);
308 } // namespace dbmm
310 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */