LCOV - code coverage report
Current view: top level - dbaccess/source/ext/macromigration - macromigrationdialog.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 219 0.0 %
Date: 2014-11-03 Functions: 0 22 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10