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

Generated by: LCOV version 1.10