Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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"
26 :
27 : #include <com/sun/star/frame/XModel.hpp>
28 :
29 : #include <tools/urlobj.hxx>
30 : #include <tools/diagnose_ex.h>
31 : #include <vcl/metric.hxx>
32 :
33 : namespace dbmm
34 : {
35 :
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;
47 :
48 0 : MacroMigrationPage::MacroMigrationPage(vcl::Window *pParent, const OString& rID, const OUString& rUIXMLDescription)
49 0 : : MacroMigrationPage_Base(pParent, rID, rUIXMLDescription)
50 : {
51 0 : }
52 :
53 0 : const MacroMigrationDialog& MacroMigrationPage::getDialog() const
54 : {
55 0 : return *dynamic_cast< const MacroMigrationDialog* >( GetParentDialog() );
56 : }
57 :
58 0 : MacroMigrationDialog& MacroMigrationPage::getDialog()
59 : {
60 0 : return *dynamic_cast< MacroMigrationDialog* >( GetParentDialog() );
61 : }
62 :
63 : // PreparationPage
64 0 : PreparationPage::PreparationPage(vcl::Window *pParent)
65 0 : : MacroMigrationPage(pParent, "PreparePage" ,"dbaccess/ui/preparepage.ui")
66 : {
67 0 : get(m_pCloseDocError, "closedocerror");
68 0 : }
69 :
70 0 : void PreparationPage::showCloseDocsError( bool _bShow )
71 : {
72 0 : m_pCloseDocError->Show( _bShow );
73 0 : }
74 :
75 0 : TabPage* PreparationPage::Create( ::svt::RoadmapWizard& _rParentDialog )
76 : {
77 0 : return new PreparationPage(&_rParentDialog);
78 : }
79 :
80 : // SaveDBDocPage
81 0 : SaveDBDocPage::SaveDBDocPage(MacroMigrationDialog& _rParentDialog)
82 0 : : MacroMigrationPage(&_rParentDialog, "BackupPage" ,"dbaccess/ui/backuppage.ui")
83 : {
84 0 : get(m_pStartMigration, "startmigrate");
85 0 : get(m_pBrowseSaveAsLocation, "browse");
86 0 : get(m_pSaveAsLocation, "location");
87 : m_pLocationController = new ::svx::DatabaseLocationInputController(
88 0 : _rParentDialog.getComponentContext(), *m_pSaveAsLocation, *m_pBrowseSaveAsLocation);
89 :
90 0 : m_pSaveAsLocation->SetModifyHdl( LINK( this, SaveDBDocPage, OnLocationModified ) );
91 0 : m_pSaveAsLocation->SetDropDownLineCount( 20 );
92 :
93 0 : impl_updateLocationDependentItems();
94 0 : }
95 :
96 0 : SaveDBDocPage::~SaveDBDocPage()
97 : {
98 0 : delete m_pLocationController;
99 0 : }
100 :
101 0 : void SaveDBDocPage::impl_updateLocationDependentItems()
102 : {
103 0 : updateDialogTravelUI();
104 0 : m_pStartMigration->Show(!m_pSaveAsLocation->GetText().isEmpty());
105 0 : }
106 :
107 0 : IMPL_LINK( SaveDBDocPage, OnLocationModified, Edit*, /**/ )
108 : {
109 0 : impl_updateLocationDependentItems();
110 0 : return 0L;
111 : }
112 :
113 0 : void SaveDBDocPage::initializePage()
114 : {
115 0 : OWizardPage::initializePage();
116 :
117 : try
118 : {
119 : // get the document's current URL
120 0 : Reference< XModel > xDocument( getDialog().getDocument(), UNO_QUERY_THROW );
121 0 : INetURLObject aURLParser( xDocument->getURL() );
122 : OSL_ENSURE( aURLParser.GetProtocol() != INET_PROT_NOT_VALID, "SaveDBDocPage::initializePage: illegal document URL!" );
123 :
124 0 : OUStringBuffer aBaseName( aURLParser.getBase() );
125 0 : aBaseName.appendAscii( ".backup" );
126 0 : aURLParser.setBase( aBaseName.makeStringAndClear() );
127 :
128 0 : m_pLocationController->setURL( aURLParser.GetMainURL( INetURLObject::NO_DECODE ) );
129 0 : impl_updateLocationDependentItems();
130 : }
131 0 : catch( const Exception& )
132 : {
133 : DBG_UNHANDLED_EXCEPTION();
134 : }
135 0 : }
136 :
137 0 : bool SaveDBDocPage::canAdvance() const
138 : {
139 0 : if ( !MacroMigrationPage::canAdvance() )
140 0 : return false;
141 :
142 0 : return !m_pSaveAsLocation->GetText().isEmpty();
143 : }
144 :
145 0 : bool SaveDBDocPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
146 : {
147 0 : if ( !MacroMigrationPage::commitPage( _eReason ) )
148 0 : return false;
149 :
150 0 : if ( ::svt::WizardTypes::eTravelBackward == _eReason )
151 0 : return true;
152 :
153 0 : if ( !m_pLocationController->prepareCommit() )
154 0 : return false;
155 :
156 0 : return true;
157 : }
158 :
159 0 : TabPage* SaveDBDocPage::Create( ::svt::RoadmapWizard& _rParentDialog )
160 : {
161 0 : return new SaveDBDocPage( dynamic_cast< MacroMigrationDialog& >( _rParentDialog ) );
162 : }
163 :
164 : // ProgressPage
165 0 : ProgressPage::ProgressPage(vcl::Window* pParent)
166 0 : : MacroMigrationPage(pParent, "MigratePage" ,"dbaccess/ui/migratepage.ui")
167 : {
168 0 : get(m_pObjectCount, "count");
169 0 : get(m_pCurrentObject, "object");
170 0 : get(m_pCurrentAction, "current");
171 0 : m_aCurrentProgress.Set(get<ProgressBar>("currentprogress"));
172 0 : get(m_pAllProgressText, "overall");
173 0 : m_aAllProgress.Set(get<ProgressBar>("allprogress"));
174 0 : get(m_pMigrationDone, "done");
175 0 : }
176 :
177 0 : TabPage* ProgressPage::Create(::svt::RoadmapWizard& _rParentDialog)
178 : {
179 0 : return new ProgressPage(&_rParentDialog);
180 : }
181 :
182 0 : void ProgressPage::setDocumentCounts( const sal_Int32 _nForms, const sal_Int32 _nReports )
183 : {
184 0 : OUString sText( m_pObjectCount->GetText() );
185 0 : sText = sText.replaceFirst( "$forms$", OUString::number( _nForms ) );
186 0 : sText = sText.replaceFirst( "$reports$", OUString::number( _nReports ) );
187 0 : m_pObjectCount->SetText( sText );
188 0 : }
189 :
190 0 : void ProgressPage::onFinishedSuccessfully()
191 : {
192 0 : m_pMigrationDone->Show();
193 0 : }
194 :
195 0 : void ProgressPage::startObject( const OUString& _rObjectName, const OUString& _rCurrentAction, const sal_uInt32 _nRange )
196 : {
197 0 : m_pCurrentObject->SetText( _rObjectName );
198 0 : m_pCurrentAction->SetText( _rCurrentAction );
199 0 : m_aCurrentProgress.SetRange( _nRange );
200 0 : m_aCurrentProgress.SetValue( (sal_uInt32)0 );
201 :
202 : // since this is currently called from the main thread, which does not have the chance
203 : // to re-schedule, we need to explicitly update the display
204 0 : m_pCurrentObject->Update();
205 0 : m_pCurrentAction->Update();
206 0 : Update();
207 0 : }
208 :
209 0 : void ProgressPage::setObjectProgressText( const OUString& _rText )
210 : {
211 0 : m_pCurrentAction->SetText( _rText );
212 0 : m_pCurrentAction->Update();
213 0 : Update();
214 0 : }
215 :
216 0 : void ProgressPage::setObjectProgressValue( const sal_uInt32 _nValue )
217 : {
218 0 : m_aCurrentProgress.SetValue( _nValue );
219 0 : Update();
220 0 : }
221 :
222 0 : void ProgressPage::endObject()
223 : {
224 0 : m_pCurrentAction->SetText( OUString() );
225 0 : m_aCurrentProgress.SetValue( m_aCurrentProgress.GetRange() );
226 0 : m_pCurrentAction->Update();
227 0 : Update();
228 0 : }
229 :
230 0 : void ProgressPage::start( const sal_uInt32 _nOverallRange )
231 : {
232 0 : m_aAllProgress.SetRange( _nOverallRange );
233 0 : Update();
234 0 : }
235 :
236 0 : void ProgressPage::setOverallProgressText( const OUString& _rText )
237 : {
238 0 : m_pAllProgressText->SetText( _rText );
239 0 : Update();
240 0 : }
241 :
242 0 : void ProgressPage::setOverallProgressValue( const sal_uInt32 _nValue )
243 : {
244 0 : m_aAllProgress.SetValue( _nValue );
245 0 : Update();
246 0 : }
247 :
248 : // ResultPage
249 0 : ResultPage::ResultPage(vcl::Window* pParent)
250 0 : : MacroMigrationPage(pParent, "SummaryPage" ,"dbaccess/ui/summarypage.ui")
251 : {
252 0 : get(m_pChanges, "textview");
253 0 : m_pChanges->set_height_request(GetTextHeight() * 10);
254 0 : m_pChanges->set_width_request(approximate_char_width() * 40);
255 0 : get(m_pSuccessLabel, "success");
256 0 : get(m_pFailureLabel, "failure");
257 0 : }
258 :
259 0 : TabPage* ResultPage::Create(::svt::RoadmapWizard& _rParentDialog)
260 : {
261 0 : return new ResultPage(&_rParentDialog);
262 : }
263 :
264 0 : void ResultPage::displayMigrationLog(const bool _bSuccessful, const OUString& _rSummary)
265 : {
266 0 : if (_bSuccessful)
267 0 : m_pFailureLabel->Hide();
268 : else
269 0 : m_pSuccessLabel->Hide();
270 0 : m_pChanges->SetText(_rSummary);
271 0 : }
272 :
273 0 : } // namespace dbmm
274 :
275 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|