1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_dbaccess.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "dbmm_global.hrc" 32*cdf0e10cSrcweir #include "dbmm_module.hxx" 33*cdf0e10cSrcweir #include "docinteraction.hxx" 34*cdf0e10cSrcweir #include "macromigration.hrc" 35*cdf0e10cSrcweir #include "macromigrationdialog.hxx" 36*cdf0e10cSrcweir #include "macromigrationpages.hxx" 37*cdf0e10cSrcweir #include "migrationengine.hxx" 38*cdf0e10cSrcweir #include "migrationerror.hxx" 39*cdf0e10cSrcweir #include "migrationlog.hxx" 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir /** === begin UNO includes === **/ 42*cdf0e10cSrcweir #include <com/sun/star/sdb/application/XDatabaseDocumentUI.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/frame/XModel2.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/util/XCloseable.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/ucb/XContent.hpp> 49*cdf0e10cSrcweir #include <com/sun/star/ucb/XContentProvider.hpp> 50*cdf0e10cSrcweir /** === end UNO includes === **/ 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx> 53*cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx> 54*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 55*cdf0e10cSrcweir #include <rtl/ref.hxx> 56*cdf0e10cSrcweir #include <svl/filenotation.hxx> 57*cdf0e10cSrcweir #include <tools/diagnose_ex.h> 58*cdf0e10cSrcweir #include <ucbhelper/content.hxx> 59*cdf0e10cSrcweir #include <ucbhelper/contentbroker.hxx> 60*cdf0e10cSrcweir #include <vcl/msgbox.hxx> 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir #include <list> 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir //........................................................................ 65*cdf0e10cSrcweir namespace dbmm 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir //........................................................................ 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir #define STATE_CLOSE_SUB_DOCS 0 70*cdf0e10cSrcweir #define STATE_BACKUP_DBDOC 1 71*cdf0e10cSrcweir #define STATE_MIGRATE 2 72*cdf0e10cSrcweir #define STATE_SUMMARY 3 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir #define PATH_DEFAULT 1 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir /** === begin UNO using === **/ 77*cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 78*cdf0e10cSrcweir using ::com::sun::star::uno::XInterface; 79*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY; 80*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW; 81*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_SET_THROW; 82*cdf0e10cSrcweir using ::com::sun::star::uno::Exception; 83*cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException; 84*cdf0e10cSrcweir using ::com::sun::star::uno::Any; 85*cdf0e10cSrcweir using ::com::sun::star::uno::makeAny; 86*cdf0e10cSrcweir using ::com::sun::star::sdb::application::XDatabaseDocumentUI; 87*cdf0e10cSrcweir using ::com::sun::star::sdb::XOfficeDatabaseDocument; 88*cdf0e10cSrcweir using ::com::sun::star::frame::XModel2; 89*cdf0e10cSrcweir using ::com::sun::star::frame::XController; 90*cdf0e10cSrcweir using ::com::sun::star::frame::XController2; 91*cdf0e10cSrcweir using ::com::sun::star::container::XEnumeration; 92*cdf0e10cSrcweir using ::com::sun::star::frame::XStorable; 93*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 94*cdf0e10cSrcweir using ::com::sun::star::beans::PropertyValue; 95*cdf0e10cSrcweir using ::com::sun::star::frame::XFrame; 96*cdf0e10cSrcweir using ::com::sun::star::awt::XWindow; 97*cdf0e10cSrcweir using ::com::sun::star::util::XCloseable; 98*cdf0e10cSrcweir using ::com::sun::star::util::XCloseListener; 99*cdf0e10cSrcweir using ::com::sun::star::util::CloseVetoException; 100*cdf0e10cSrcweir using ::com::sun::star::lang::EventObject; 101*cdf0e10cSrcweir using ::com::sun::star::frame::XComponentLoader; 102*cdf0e10cSrcweir using ::com::sun::star::util::XModifiable; 103*cdf0e10cSrcweir using ::com::sun::star::ucb::XCommandEnvironment; 104*cdf0e10cSrcweir using ::com::sun::star::ucb::XContent; 105*cdf0e10cSrcweir using ::com::sun::star::ucb::XContentIdentifier; 106*cdf0e10cSrcweir using ::com::sun::star::ucb::XContentProvider; 107*cdf0e10cSrcweir /** === end UNO using === **/ 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir //==================================================================== 110*cdf0e10cSrcweir //= helper 111*cdf0e10cSrcweir //==================================================================== 112*cdf0e10cSrcweir //-------------------------------------------------------------------- 113*cdf0e10cSrcweir static void lcl_getControllers_throw( const Reference< XModel2 >& _rxDocument, 114*cdf0e10cSrcweir ::std::list< Reference< XController2 > >& _out_rControllers ) 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir _out_rControllers.clear(); 117*cdf0e10cSrcweir Reference< XEnumeration > xControllerEnum( _rxDocument->getControllers(), UNO_SET_THROW ); 118*cdf0e10cSrcweir while ( xControllerEnum->hasMoreElements() ) 119*cdf0e10cSrcweir _out_rControllers.push_back( Reference< XController2 >( xControllerEnum->nextElement(), UNO_QUERY_THROW ) ); 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir //==================================================================== 123*cdf0e10cSrcweir //= MacroMigrationDialog_Data 124*cdf0e10cSrcweir //==================================================================== 125*cdf0e10cSrcweir struct MacroMigrationDialog_Data 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir ::comphelper::ComponentContext aContext; 128*cdf0e10cSrcweir MigrationLog aLogger; 129*cdf0e10cSrcweir Reference< XOfficeDatabaseDocument > xDocument; 130*cdf0e10cSrcweir Reference< XModel2 > xDocumentModel; 131*cdf0e10cSrcweir ::rtl::OUString sSuccessfulBackupLocation; 132*cdf0e10cSrcweir bool bMigrationIsRunning; 133*cdf0e10cSrcweir bool bMigrationFailure; 134*cdf0e10cSrcweir bool bMigrationSuccess; 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir MacroMigrationDialog_Data( 137*cdf0e10cSrcweir const ::comphelper::ComponentContext& _rContext, 138*cdf0e10cSrcweir const Reference< XOfficeDatabaseDocument >& _rxDocument ) 139*cdf0e10cSrcweir :aContext( _rContext ) 140*cdf0e10cSrcweir ,aLogger() 141*cdf0e10cSrcweir ,xDocument( _rxDocument ) 142*cdf0e10cSrcweir ,xDocumentModel( _rxDocument, UNO_QUERY ) 143*cdf0e10cSrcweir ,bMigrationIsRunning( false ) 144*cdf0e10cSrcweir ,bMigrationFailure( false ) 145*cdf0e10cSrcweir ,bMigrationSuccess( false ) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir }; 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir //==================================================================== 151*cdf0e10cSrcweir //= MacroMigrationDialog 152*cdf0e10cSrcweir //==================================================================== 153*cdf0e10cSrcweir //-------------------------------------------------------------------- 154*cdf0e10cSrcweir MacroMigrationDialog::MacroMigrationDialog( Window* _pParent, const ::comphelper::ComponentContext& _rContext, 155*cdf0e10cSrcweir const Reference< XOfficeDatabaseDocument >& _rxDocument ) 156*cdf0e10cSrcweir :MacroMigrationDialog_Base( _pParent, MacroMigrationResId( DLG_MACRO_MIGRATION ) ) 157*cdf0e10cSrcweir ,m_pData( new MacroMigrationDialog_Data( _rContext, _rxDocument ) ) 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir String sTitlePrepare( MacroMigrationResId( STR_STATE_CLOSE_SUB_DOCS ) ); 160*cdf0e10cSrcweir String sTitleStoreAs( MacroMigrationResId( STR_STATE_BACKUP_DBDOC ) ); 161*cdf0e10cSrcweir String sTitleMigrate( MacroMigrationResId( STR_STATE_MIGRATE ) ); 162*cdf0e10cSrcweir String sTitleSummary( MacroMigrationResId( STR_STATE_SUMMARY ) ); 163*cdf0e10cSrcweir FreeResource(); 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir describeState( STATE_CLOSE_SUB_DOCS, sTitlePrepare, &PreparationPage::Create ); 166*cdf0e10cSrcweir describeState( STATE_BACKUP_DBDOC, sTitleStoreAs, &SaveDBDocPage::Create ); 167*cdf0e10cSrcweir describeState( STATE_MIGRATE, sTitleMigrate, &ProgressPage::Create ); 168*cdf0e10cSrcweir describeState( STATE_SUMMARY, sTitleSummary, &ResultPage::Create ); 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir declarePath( PATH_DEFAULT, STATE_CLOSE_SUB_DOCS, STATE_BACKUP_DBDOC, STATE_MIGRATE, STATE_SUMMARY, WZS_INVALID_STATE ); 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir SetPageSizePixel( LogicToPixel( ::Size( TAB_PAGE_WIDTH, TAB_PAGE_HEIGHT ), MAP_APPFONT ) ); 173*cdf0e10cSrcweir ShowButtonFixedLine( true ); 174*cdf0e10cSrcweir SetRoadmapInteractive( true ); 175*cdf0e10cSrcweir enableAutomaticNextButtonState(); 176*cdf0e10cSrcweir defaultButton( WZB_NEXT ); 177*cdf0e10cSrcweir enableButtons( WZB_FINISH, true ); 178*cdf0e10cSrcweir ActivatePage(); 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir OSL_PRECOND( m_pData->xDocumentModel.is(), "MacroMigrationDialog::MacroMigrationDialog: illegal document!" ); 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir //-------------------------------------------------------------------- 184*cdf0e10cSrcweir MacroMigrationDialog::~MacroMigrationDialog() 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir //-------------------------------------------------------------------- 189*cdf0e10cSrcweir const ::comphelper::ComponentContext& MacroMigrationDialog::getComponentContext() const 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir return m_pData->aContext; 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir //-------------------------------------------------------------------- 195*cdf0e10cSrcweir const Reference< XOfficeDatabaseDocument >& MacroMigrationDialog::getDocument() const 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir return m_pData->xDocument; 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir //-------------------------------------------------------------------- 201*cdf0e10cSrcweir short MacroMigrationDialog::Execute() 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir short nResult = MacroMigrationDialog_Base::Execute(); 204*cdf0e10cSrcweir if ( !m_pData->bMigrationFailure && !m_pData->bMigrationSuccess ) 205*cdf0e10cSrcweir // migration did not even start 206*cdf0e10cSrcweir return nResult; 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir OSL_ENSURE( !m_pData->bMigrationFailure || !m_pData->bMigrationSuccess, 209*cdf0e10cSrcweir "MacroMigrationDialog::Execute: success *and* failure at the same time?!" ); 210*cdf0e10cSrcweir impl_reloadDocument_nothrow( m_pData->bMigrationSuccess ); 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir return nResult; 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir //-------------------------------------------------------------------- 216*cdf0e10cSrcweir sal_Bool MacroMigrationDialog::Close() 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir if ( m_pData->bMigrationIsRunning ) 219*cdf0e10cSrcweir return sal_False; 220*cdf0e10cSrcweir return MacroMigrationDialog_Base::Close(); 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir //-------------------------------------------------------------------- 224*cdf0e10cSrcweir void MacroMigrationDialog::enterState( WizardState _nState ) 225*cdf0e10cSrcweir { 226*cdf0e10cSrcweir MacroMigrationDialog_Base::enterState( _nState ); 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir switch ( _nState ) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir case STATE_CLOSE_SUB_DOCS: 231*cdf0e10cSrcweir enableButtons( WZB_FINISH, false ); 232*cdf0e10cSrcweir enableState( STATE_MIGRATE, false ); 233*cdf0e10cSrcweir enableState( STATE_SUMMARY, false ); 234*cdf0e10cSrcweir break; 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir case STATE_BACKUP_DBDOC: 237*cdf0e10cSrcweir enableState( STATE_MIGRATE, true ); 238*cdf0e10cSrcweir // Note that the state is automatically disabled if the current page 239*cdf0e10cSrcweir // (SaveDBDocPage) returns false in its canAdvance, not caring that 240*cdf0e10cSrcweir // we enabled it here. 241*cdf0e10cSrcweir break; 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir case STATE_MIGRATE: 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir // disable everything. The process we will start here cannot be cancelled, the user 246*cdf0e10cSrcweir // needs to wait 'til it's finished. 247*cdf0e10cSrcweir enableState( STATE_CLOSE_SUB_DOCS, false ); 248*cdf0e10cSrcweir enableState( STATE_BACKUP_DBDOC, false ); 249*cdf0e10cSrcweir enableState( STATE_SUMMARY, false ); 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir enableButtons( WZB_FINISH | WZB_CANCEL | WZB_PREVIOUS | WZB_NEXT, false ); 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir // start the migration asynchronously 254*cdf0e10cSrcweir PostUserEvent( LINK( this, MacroMigrationDialog, OnStartMigration ) ); 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir break; 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir case STATE_SUMMARY: 259*cdf0e10cSrcweir // disable the previous step - we can't return to the actual migration, it already happened (or failed) 260*cdf0e10cSrcweir enableState( STATE_MIGRATE, false ); 261*cdf0e10cSrcweir updateTravelUI(); 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir // display the results 264*cdf0e10cSrcweir dynamic_cast< ResultPage& >( *GetPage( STATE_SUMMARY ) ).displayMigrationLog( 265*cdf0e10cSrcweir m_pData->bMigrationSuccess, m_pData->aLogger.getCompleteLog() ); 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir enableButtons( WZB_FINISH, m_pData->bMigrationSuccess ); 268*cdf0e10cSrcweir enableButtons( WZB_CANCEL, m_pData->bMigrationFailure ); 269*cdf0e10cSrcweir defaultButton( m_pData->bMigrationSuccess ? WZB_FINISH : WZB_CANCEL ); 270*cdf0e10cSrcweir break; 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir default: 273*cdf0e10cSrcweir OSL_ENSURE( false, "MacroMigrationDialog::enterState: unhandled state!" ); 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir } 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir //-------------------------------------------------------------------- 278*cdf0e10cSrcweir sal_Bool MacroMigrationDialog::prepareLeaveCurrentState( CommitPageReason _eReason ) 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir if ( !MacroMigrationDialog_Base::prepareLeaveCurrentState( _eReason ) ) 281*cdf0e10cSrcweir return sal_False; 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir switch ( getCurrentState() ) 284*cdf0e10cSrcweir { 285*cdf0e10cSrcweir case STATE_CLOSE_SUB_DOCS: 286*cdf0e10cSrcweir if ( !impl_closeSubDocs_nothrow() ) 287*cdf0e10cSrcweir return sal_False; 288*cdf0e10cSrcweir break; 289*cdf0e10cSrcweir case STATE_BACKUP_DBDOC: 290*cdf0e10cSrcweir if ( !impl_backupDocument_nothrow() ) 291*cdf0e10cSrcweir return sal_False; 292*cdf0e10cSrcweir break; 293*cdf0e10cSrcweir case STATE_MIGRATE: 294*cdf0e10cSrcweir break; 295*cdf0e10cSrcweir case STATE_SUMMARY: 296*cdf0e10cSrcweir break; 297*cdf0e10cSrcweir default: 298*cdf0e10cSrcweir OSL_ENSURE( false, "MacroMigrationDialog::prepareLeaveCurrentState: unhandled state!" ); 299*cdf0e10cSrcweir } 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir return sal_True; 302*cdf0e10cSrcweir } 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir //-------------------------------------------------------------------- 305*cdf0e10cSrcweir sal_Bool MacroMigrationDialog::leaveState( WizardState _nState ) 306*cdf0e10cSrcweir { 307*cdf0e10cSrcweir return MacroMigrationDialog_Base::leaveState( _nState ); 308*cdf0e10cSrcweir } 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir //-------------------------------------------------------------------- 311*cdf0e10cSrcweir MacroMigrationDialog::WizardState MacroMigrationDialog::determineNextState( WizardState _nCurrentState ) const 312*cdf0e10cSrcweir { 313*cdf0e10cSrcweir return MacroMigrationDialog_Base::determineNextState( _nCurrentState ); 314*cdf0e10cSrcweir } 315*cdf0e10cSrcweir 316*cdf0e10cSrcweir //-------------------------------------------------------------------- 317*cdf0e10cSrcweir sal_Bool MacroMigrationDialog::onFinish() 318*cdf0e10cSrcweir { 319*cdf0e10cSrcweir return MacroMigrationDialog_Base::onFinish(); 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir //-------------------------------------------------------------------- 323*cdf0e10cSrcweir IMPL_LINK( MacroMigrationDialog, OnStartMigration, void*, /*_pNotInterestedIn*/ ) 324*cdf0e10cSrcweir { 325*cdf0e10cSrcweir // prevent closing 326*cdf0e10cSrcweir m_pData->bMigrationIsRunning = true; 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir // initialize migration engine and progress 329*cdf0e10cSrcweir ProgressPage& rProgressPage( dynamic_cast< ProgressPage& >( *GetPage( STATE_MIGRATE ) ) ); 330*cdf0e10cSrcweir MigrationEngine aEngine( m_pData->aContext, m_pData->xDocument, rProgressPage, m_pData->aLogger ); 331*cdf0e10cSrcweir rProgressPage.setDocumentCounts( aEngine.getFormCount(), aEngine.getReportCount() ); 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir // do the migration 334*cdf0e10cSrcweir m_pData->bMigrationSuccess = aEngine.migrateAll(); 335*cdf0e10cSrcweir m_pData->bMigrationFailure = !m_pData->bMigrationSuccess; 336*cdf0e10cSrcweir 337*cdf0e10cSrcweir // re-enable the UI 338*cdf0e10cSrcweir enableButtons( WZB_FINISH | WZB_NEXT, true ); 339*cdf0e10cSrcweir enableState( STATE_SUMMARY, true ); 340*cdf0e10cSrcweir updateTravelUI(); 341*cdf0e10cSrcweir 342*cdf0e10cSrcweir m_pData->bMigrationIsRunning = false; 343*cdf0e10cSrcweir 344*cdf0e10cSrcweir if ( m_pData->bMigrationSuccess ) 345*cdf0e10cSrcweir { 346*cdf0e10cSrcweir rProgressPage.onFinishedSuccessfully(); 347*cdf0e10cSrcweir } 348*cdf0e10cSrcweir else 349*cdf0e10cSrcweir { // if there was an error, show the summary automatically 350*cdf0e10cSrcweir travelNext(); 351*cdf0e10cSrcweir } 352*cdf0e10cSrcweir 353*cdf0e10cSrcweir // outta here 354*cdf0e10cSrcweir return 0L; 355*cdf0e10cSrcweir } 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir //-------------------------------------------------------------------- 358*cdf0e10cSrcweir void MacroMigrationDialog::impl_showCloseDocsError( bool _bShow ) 359*cdf0e10cSrcweir { 360*cdf0e10cSrcweir PreparationPage* pPreparationPage = dynamic_cast< PreparationPage* >( GetPage( STATE_CLOSE_SUB_DOCS ) ); 361*cdf0e10cSrcweir OSL_ENSURE( pPreparationPage, "MacroMigrationDialog::impl_showCloseDocsError: did not find the page!" ); 362*cdf0e10cSrcweir if ( pPreparationPage ) 363*cdf0e10cSrcweir pPreparationPage->showCloseDocsError( _bShow ); 364*cdf0e10cSrcweir } 365*cdf0e10cSrcweir 366*cdf0e10cSrcweir //-------------------------------------------------------------------- 367*cdf0e10cSrcweir bool MacroMigrationDialog::impl_closeSubDocs_nothrow() 368*cdf0e10cSrcweir { 369*cdf0e10cSrcweir OSL_PRECOND( m_pData->xDocument.is(), "MacroMigrationDialog::impl_closeSubDocs_nothrow: no document!" ); 370*cdf0e10cSrcweir if ( !m_pData->xDocument.is() ) 371*cdf0e10cSrcweir return false; 372*cdf0e10cSrcweir 373*cdf0e10cSrcweir impl_showCloseDocsError( false ); 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir bool bSuccess = true; 376*cdf0e10cSrcweir try 377*cdf0e10cSrcweir { 378*cdf0e10cSrcweir // collect all controllers of our document 379*cdf0e10cSrcweir ::std::list< Reference< XController2 > > aControllers; 380*cdf0e10cSrcweir lcl_getControllers_throw( m_pData->xDocumentModel, aControllers ); 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir // close all sub documents of all controllers 383*cdf0e10cSrcweir for ( ::std::list< Reference< XController2 > >::const_iterator pos = aControllers.begin(); 384*cdf0e10cSrcweir pos != aControllers.end() && bSuccess; 385*cdf0e10cSrcweir ++pos 386*cdf0e10cSrcweir ) 387*cdf0e10cSrcweir { 388*cdf0e10cSrcweir Reference< XDatabaseDocumentUI > xController( *pos, UNO_QUERY ); 389*cdf0e10cSrcweir OSL_ENSURE( xController.is(), "MacroMigrationDialog::impl_closeSubDocs_nothrow: unexpected: controller is missing an important interface!" ); 390*cdf0e10cSrcweir // at the moment, only one implementation for a DBDoc's controller exists, which should 391*cdf0e10cSrcweir // support this interface 392*cdf0e10cSrcweir if ( !xController.is() ) 393*cdf0e10cSrcweir continue; 394*cdf0e10cSrcweir 395*cdf0e10cSrcweir bSuccess = xController->closeSubComponents(); 396*cdf0e10cSrcweir } 397*cdf0e10cSrcweir } 398*cdf0e10cSrcweir catch( const Exception& ) 399*cdf0e10cSrcweir { 400*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 401*cdf0e10cSrcweir bSuccess = false; 402*cdf0e10cSrcweir } 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir impl_showCloseDocsError( !bSuccess ); 405*cdf0e10cSrcweir return bSuccess; 406*cdf0e10cSrcweir } 407*cdf0e10cSrcweir 408*cdf0e10cSrcweir //-------------------------------------------------------------------- 409*cdf0e10cSrcweir namespace 410*cdf0e10cSrcweir { 411*cdf0e10cSrcweir bool lcl_equalURLs_nothrow( const ::rtl::OUString& _lhs, const ::rtl::OUString _rhs ) 412*cdf0e10cSrcweir { 413*cdf0e10cSrcweir // the cheap situation: the URLs are equal 414*cdf0e10cSrcweir if ( _lhs == _rhs ) 415*cdf0e10cSrcweir return true; 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir bool bEqual = true; 418*cdf0e10cSrcweir try 419*cdf0e10cSrcweir { 420*cdf0e10cSrcweir ::ucbhelper::Content aContentLHS = ::ucbhelper::Content( _lhs, Reference< XCommandEnvironment >() ); 421*cdf0e10cSrcweir ::ucbhelper::Content aContentRHS = ::ucbhelper::Content( _rhs, Reference< XCommandEnvironment >() ); 422*cdf0e10cSrcweir Reference< XContent > xContentLHS( aContentLHS.get(), UNO_SET_THROW ); 423*cdf0e10cSrcweir Reference< XContent > xContentRHS( aContentRHS.get(), UNO_SET_THROW ); 424*cdf0e10cSrcweir Reference< XContentIdentifier > xID1( xContentLHS->getIdentifier(), UNO_SET_THROW ); 425*cdf0e10cSrcweir Reference< XContentIdentifier > xID2( xContentRHS->getIdentifier(), UNO_SET_THROW ); 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir ::ucbhelper::ContentBroker* pBroker = ::ucbhelper::ContentBroker::get(); 428*cdf0e10cSrcweir Reference< XContentProvider > xProvider( 429*cdf0e10cSrcweir pBroker ? pBroker->getContentProviderInterface() : Reference< XContentProvider >(), UNO_SET_THROW ); 430*cdf0e10cSrcweir 431*cdf0e10cSrcweir bEqual = ( 0 == xProvider->compareContentIds( xID1, xID2 ) ); 432*cdf0e10cSrcweir } 433*cdf0e10cSrcweir catch( const Exception& ) 434*cdf0e10cSrcweir { 435*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 436*cdf0e10cSrcweir } 437*cdf0e10cSrcweir return bEqual; 438*cdf0e10cSrcweir } 439*cdf0e10cSrcweir } 440*cdf0e10cSrcweir 441*cdf0e10cSrcweir //-------------------------------------------------------------------- 442*cdf0e10cSrcweir bool MacroMigrationDialog::impl_backupDocument_nothrow() const 443*cdf0e10cSrcweir { 444*cdf0e10cSrcweir if ( !m_pData->xDocumentModel.is() ) 445*cdf0e10cSrcweir // should never happen, but has been reported as assertion before 446*cdf0e10cSrcweir return false; 447*cdf0e10cSrcweir 448*cdf0e10cSrcweir SaveDBDocPage& rBackupPage = dynamic_cast< SaveDBDocPage& >( *GetPage( STATE_BACKUP_DBDOC ) ); 449*cdf0e10cSrcweir ::rtl::OUString sBackupLocation( rBackupPage.getBackupLocation() ); 450*cdf0e10cSrcweir 451*cdf0e10cSrcweir Any aError; 452*cdf0e10cSrcweir try 453*cdf0e10cSrcweir { 454*cdf0e10cSrcweir // check that the backup location isn't the same as the document itself 455*cdf0e10cSrcweir if ( lcl_equalURLs_nothrow( sBackupLocation, m_pData->xDocumentModel->getURL() ) ) 456*cdf0e10cSrcweir { 457*cdf0e10cSrcweir ErrorBox aErrorBox( const_cast< MacroMigrationDialog* >( this ), MacroMigrationResId( ERR_INVALID_BACKUP_LOCATION ) ); 458*cdf0e10cSrcweir aErrorBox.Execute(); 459*cdf0e10cSrcweir rBackupPage.grabLocationFocus(); 460*cdf0e10cSrcweir return false; 461*cdf0e10cSrcweir } 462*cdf0e10cSrcweir 463*cdf0e10cSrcweir // store to the backup location 464*cdf0e10cSrcweir const Reference< XStorable > xDocument( getDocument(), UNO_QUERY_THROW ); 465*cdf0e10cSrcweir xDocument->storeToURL( sBackupLocation, Sequence< PropertyValue >() ); 466*cdf0e10cSrcweir m_pData->sSuccessfulBackupLocation = sBackupLocation; 467*cdf0e10cSrcweir } 468*cdf0e10cSrcweir catch( const Exception& ) 469*cdf0e10cSrcweir { 470*cdf0e10cSrcweir aError = ::cppu::getCaughtException(); 471*cdf0e10cSrcweir } 472*cdf0e10cSrcweir if ( !aError.hasValue() ) 473*cdf0e10cSrcweir { 474*cdf0e10cSrcweir ::svt::OFileNotation aFileNotation( sBackupLocation ); 475*cdf0e10cSrcweir m_pData->aLogger.backedUpDocument( aFileNotation.get( ::svt::OFileNotation::N_SYSTEM ) ); 476*cdf0e10cSrcweir return true; 477*cdf0e10cSrcweir } 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir // display the error to the user 480*cdf0e10cSrcweir InteractionHandler aHandler( m_pData->aContext, m_pData->xDocumentModel.get() ); 481*cdf0e10cSrcweir aHandler.reportError( aError ); 482*cdf0e10cSrcweir 483*cdf0e10cSrcweir m_pData->aLogger.logFailure( MigrationError( 484*cdf0e10cSrcweir ERR_DOCUMENT_BACKUP_FAILED, 485*cdf0e10cSrcweir sBackupLocation, 486*cdf0e10cSrcweir aError 487*cdf0e10cSrcweir ) ); 488*cdf0e10cSrcweir 489*cdf0e10cSrcweir return false; 490*cdf0e10cSrcweir } 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir //-------------------------------------------------------------------- 493*cdf0e10cSrcweir void MacroMigrationDialog::impl_reloadDocument_nothrow( bool _bMigrationSuccess ) 494*cdf0e10cSrcweir { 495*cdf0e10cSrcweir typedef ::std::pair< Reference< XFrame >, ::rtl::OUString > ViewDescriptor; 496*cdf0e10cSrcweir ::std::list< ViewDescriptor > aViews; 497*cdf0e10cSrcweir 498*cdf0e10cSrcweir try 499*cdf0e10cSrcweir { 500*cdf0e10cSrcweir // the information which is necessary to reload the document 501*cdf0e10cSrcweir ::rtl::OUString sDocumentURL ( m_pData->xDocumentModel->getURL() ); 502*cdf0e10cSrcweir ::comphelper::NamedValueCollection aDocumentArgs( m_pData->xDocumentModel->getArgs() ); 503*cdf0e10cSrcweir if ( !_bMigrationSuccess ) 504*cdf0e10cSrcweir { 505*cdf0e10cSrcweir // if the migration was not successful, then reload from the backup 506*cdf0e10cSrcweir aDocumentArgs.put( "SalvagedFile", m_pData->sSuccessfulBackupLocation ); 507*cdf0e10cSrcweir // reset the modified flag of the document, so the controller can be suspended later 508*cdf0e10cSrcweir Reference< XModifiable > xModify( m_pData->xDocument, UNO_QUERY_THROW ); 509*cdf0e10cSrcweir xModify->setModified( sal_False ); 510*cdf0e10cSrcweir // after this reload, don't show the migration warning, again 511*cdf0e10cSrcweir aDocumentArgs.put( "SuppressMigrationWarning", sal_Bool(sal_True) ); 512*cdf0e10cSrcweir } 513*cdf0e10cSrcweir 514*cdf0e10cSrcweir // remove anything from the args which might refer to the old document 515*cdf0e10cSrcweir aDocumentArgs.remove( "Model" ); 516*cdf0e10cSrcweir aDocumentArgs.remove( "Stream" ); 517*cdf0e10cSrcweir aDocumentArgs.remove( "InputStream" ); 518*cdf0e10cSrcweir aDocumentArgs.remove( "FileName" ); 519*cdf0e10cSrcweir aDocumentArgs.remove( "URL" ); 520*cdf0e10cSrcweir 521*cdf0e10cSrcweir // collect all controllers of our document 522*cdf0e10cSrcweir ::std::list< Reference< XController2 > > aControllers; 523*cdf0e10cSrcweir lcl_getControllers_throw( m_pData->xDocumentModel, aControllers ); 524*cdf0e10cSrcweir 525*cdf0e10cSrcweir // close all those controllers 526*cdf0e10cSrcweir while ( !aControllers.empty() ) 527*cdf0e10cSrcweir { 528*cdf0e10cSrcweir Reference< XController2 > xController( aControllers.front(), UNO_SET_THROW ); 529*cdf0e10cSrcweir aControllers.pop_front(); 530*cdf0e10cSrcweir 531*cdf0e10cSrcweir Reference< XFrame > xFrame( xController->getFrame(), UNO_SET_THROW ); 532*cdf0e10cSrcweir ::rtl::OUString sViewName( xController->getViewControllerName() ); 533*cdf0e10cSrcweir 534*cdf0e10cSrcweir if ( !xController->suspend( sal_True ) ) 535*cdf0e10cSrcweir { // ouch. There shouldn't be any modal dialogs and such, so there 536*cdf0e10cSrcweir // really is no reason why suspending shouldn't work. 537*cdf0e10cSrcweir OSL_ENSURE( false, "MacroMigrationDialog::impl_reloadDocument_nothrow: could not suspend a controller!" ); 538*cdf0e10cSrcweir // ignoring this would be at the cost of a crash (potentially) 539*cdf0e10cSrcweir // so, we cannot continue here. 540*cdf0e10cSrcweir throw CloseVetoException(); 541*cdf0e10cSrcweir } 542*cdf0e10cSrcweir 543*cdf0e10cSrcweir aViews.push_back( ViewDescriptor( xFrame, sViewName ) ); 544*cdf0e10cSrcweir xFrame->setComponent( NULL, NULL ); 545*cdf0e10cSrcweir xController->dispose(); 546*cdf0e10cSrcweir } 547*cdf0e10cSrcweir 548*cdf0e10cSrcweir // Note the document is closed now - disconnecting the last controller 549*cdf0e10cSrcweir // closes it automatically. 550*cdf0e10cSrcweir 551*cdf0e10cSrcweir Reference< XOfficeDatabaseDocument > xNewDocument; 552*cdf0e10cSrcweir 553*cdf0e10cSrcweir // re-create the views 554*cdf0e10cSrcweir while ( !aViews.empty() ) 555*cdf0e10cSrcweir { 556*cdf0e10cSrcweir ViewDescriptor aView( aViews.front() ); 557*cdf0e10cSrcweir aViews.pop_front(); 558*cdf0e10cSrcweir 559*cdf0e10cSrcweir // load the document into this frame 560*cdf0e10cSrcweir Reference< XComponentLoader > xLoader( aView.first, UNO_QUERY_THROW ); 561*cdf0e10cSrcweir aDocumentArgs.put( "ViewName", aView.second ); 562*cdf0e10cSrcweir Reference< XInterface > xReloaded( xLoader->loadComponentFromURL( 563*cdf0e10cSrcweir sDocumentURL, 564*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_self" ) ), 565*cdf0e10cSrcweir 0, 566*cdf0e10cSrcweir aDocumentArgs.getPropertyValues() 567*cdf0e10cSrcweir ) ); 568*cdf0e10cSrcweir 569*cdf0e10cSrcweir OSL_ENSURE( xReloaded != m_pData->xDocumentModel, 570*cdf0e10cSrcweir "MacroMigrationDialog::impl_reloadDocument_nothrow: this should have been a new instance!" ); 571*cdf0e10cSrcweir // this would be unexpected, but recoverable: The loader should at least have done 572*cdf0e10cSrcweir // this: really *load* the document, even if it loaded it into the old document instance 573*cdf0e10cSrcweir if ( !xNewDocument.is() ) 574*cdf0e10cSrcweir { 575*cdf0e10cSrcweir xNewDocument.set( xReloaded, UNO_QUERY_THROW ); 576*cdf0e10cSrcweir // for subsequent loads, into different frames, put the document into the load args 577*cdf0e10cSrcweir aDocumentArgs.put( "Model", xNewDocument ); 578*cdf0e10cSrcweir } 579*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 580*cdf0e10cSrcweir else 581*cdf0e10cSrcweir { 582*cdf0e10cSrcweir OSL_ENSURE( xNewDocument == xReloaded, 583*cdf0e10cSrcweir "MacroMigrationDialog::impl_reloadDocument_nothrow: unexpected: subsequent load attempt returned a wrong document!" ); 584*cdf0e10cSrcweir } 585*cdf0e10cSrcweir #endif 586*cdf0e10cSrcweir } 587*cdf0e10cSrcweir 588*cdf0e10cSrcweir m_pData->xDocument = xNewDocument; 589*cdf0e10cSrcweir m_pData->xDocumentModel.set( xNewDocument, UNO_QUERY ); 590*cdf0e10cSrcweir 591*cdf0e10cSrcweir // finally, now that the document has been reloaded - if the migration was not successful, 592*cdf0e10cSrcweir // then it was reloaded from the backup, but the real document still is broken. So, save 593*cdf0e10cSrcweir // the document once, which will write the content loaded from the backup to the real docfile. 594*cdf0e10cSrcweir if ( !_bMigrationSuccess ) 595*cdf0e10cSrcweir { 596*cdf0e10cSrcweir Reference< XModifiable > xModify( m_pData->xDocument, UNO_QUERY_THROW ); 597*cdf0e10cSrcweir xModify->setModified( sal_True ); 598*cdf0e10cSrcweir // this is just parnoia - in case saving the doc fails, perhaps the user is tempted to do so 599*cdf0e10cSrcweir Reference< XStorable > xStor( m_pData->xDocument, UNO_QUERY_THROW ); 600*cdf0e10cSrcweir xStor->store(); 601*cdf0e10cSrcweir } 602*cdf0e10cSrcweir } 603*cdf0e10cSrcweir catch( const Exception& ) 604*cdf0e10cSrcweir { 605*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 606*cdf0e10cSrcweir } 607*cdf0e10cSrcweir 608*cdf0e10cSrcweir // close all frames from aViews - the respective controllers have been closed, but 609*cdf0e10cSrcweir // reloading didn't work, so the frames are zombies now. 610*cdf0e10cSrcweir while ( !aViews.empty() ) 611*cdf0e10cSrcweir { 612*cdf0e10cSrcweir ViewDescriptor aView( aViews.front() ); 613*cdf0e10cSrcweir aViews.pop_front(); 614*cdf0e10cSrcweir try 615*cdf0e10cSrcweir { 616*cdf0e10cSrcweir Reference< XCloseable > xFrameClose( aView.first, UNO_QUERY_THROW ); 617*cdf0e10cSrcweir xFrameClose->close( sal_True ); 618*cdf0e10cSrcweir } 619*cdf0e10cSrcweir catch( const Exception& ) 620*cdf0e10cSrcweir { 621*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 622*cdf0e10cSrcweir } 623*cdf0e10cSrcweir } 624*cdf0e10cSrcweir } 625*cdf0e10cSrcweir 626*cdf0e10cSrcweir //........................................................................ 627*cdf0e10cSrcweir } // namespace dbmm 628*cdf0e10cSrcweir //........................................................................ 629