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

Generated by: LCOV version 1.10