LCOV - code coverage report
Current view: top level - dbaccess/source/ext/macromigration - macromigrationdialog.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 224 0.0 %
Date: 2012-08-25 Functions: 0 22 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     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/XContent.hpp>
      38                 :            : #include <com/sun/star/ucb/XContentProvider.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 <ucbhelper/contentbroker.hxx>
      48                 :            : #include <vcl/msgbox.hxx>
      49                 :            : 
      50                 :            : #include <list>
      51                 :            : 
      52                 :            : //........................................................................
      53                 :            : namespace dbmm
      54                 :            : {
      55                 :            : //........................................................................
      56                 :            : 
      57                 :            : #define STATE_CLOSE_SUB_DOCS    0
      58                 :            : #define STATE_BACKUP_DBDOC      1
      59                 :            : #define STATE_MIGRATE           2
      60                 :            : #define STATE_SUMMARY           3
      61                 :            : 
      62                 :            : #define PATH_DEFAULT            1
      63                 :            : 
      64                 :            :     /** === begin UNO using === **/
      65                 :            :     using ::com::sun::star::uno::Reference;
      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::XCommandEnvironment;
      92                 :            :     using ::com::sun::star::ucb::XContent;
      93                 :            :     using ::com::sun::star::ucb::XContentIdentifier;
      94                 :            :     using ::com::sun::star::ucb::XContentProvider;
      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( const ::rtl::OUString& _lhs, const ::rtl::OUString _rhs )
     400                 :            :         {
     401                 :            :             // the cheap situation: the URLs are equal
     402                 :          0 :             if ( _lhs == _rhs )
     403                 :          0 :                 return true;
     404                 :            : 
     405                 :          0 :             bool bEqual = true;
     406                 :            :             try
     407                 :            :             {
     408                 :          0 :                 ::ucbhelper::Content aContentLHS = ::ucbhelper::Content( _lhs, Reference< XCommandEnvironment >() );
     409                 :          0 :                 ::ucbhelper::Content aContentRHS = ::ucbhelper::Content( _rhs, Reference< XCommandEnvironment >() );
     410                 :          0 :                 Reference< XContent > xContentLHS( aContentLHS.get(), UNO_SET_THROW );
     411                 :          0 :                 Reference< XContent > xContentRHS( aContentRHS.get(), UNO_SET_THROW );
     412                 :          0 :                 Reference< XContentIdentifier > xID1( xContentLHS->getIdentifier(), UNO_SET_THROW );
     413                 :          0 :                 Reference< XContentIdentifier > xID2( xContentRHS->getIdentifier(), UNO_SET_THROW );
     414                 :            : 
     415                 :          0 :                 ::ucbhelper::ContentBroker* pBroker = ::ucbhelper::ContentBroker::get();
     416                 :            :                 Reference< XContentProvider > xProvider(
     417                 :          0 :                     pBroker ? pBroker->getContentProviderInterface() : Reference< XContentProvider >(), UNO_SET_THROW );
     418                 :            : 
     419                 :          0 :                 bEqual = ( 0 == xProvider->compareContentIds( xID1, xID2 ) );
     420                 :            :             }
     421                 :          0 :             catch( const Exception& )
     422                 :            :             {
     423                 :            :                 DBG_UNHANDLED_EXCEPTION();
     424                 :            :             }
     425                 :          0 :             return bEqual;
     426                 :            :         }
     427                 :            :     }
     428                 :            : 
     429                 :            :     //--------------------------------------------------------------------
     430                 :          0 :     bool MacroMigrationDialog::impl_backupDocument_nothrow() const
     431                 :            :     {
     432                 :          0 :         if ( !m_pData->xDocumentModel.is() )
     433                 :            :             // should never happen, but has been reported as assertion before
     434                 :          0 :             return false;
     435                 :            : 
     436                 :          0 :         SaveDBDocPage& rBackupPage = dynamic_cast< SaveDBDocPage& >( *GetPage( STATE_BACKUP_DBDOC ) );
     437                 :          0 :         ::rtl::OUString sBackupLocation( rBackupPage.getBackupLocation() );
     438                 :            : 
     439                 :          0 :         Any aError;
     440                 :            :         try
     441                 :            :         {
     442                 :            :             // check that the backup location isn't the same as the document itself
     443                 :          0 :             if ( lcl_equalURLs_nothrow( sBackupLocation, m_pData->xDocumentModel->getURL() ) )
     444                 :            :             {
     445                 :          0 :                 ErrorBox aErrorBox( const_cast< MacroMigrationDialog* >( this ), MacroMigrationResId( ERR_INVALID_BACKUP_LOCATION ) );
     446                 :          0 :                 aErrorBox.Execute();
     447                 :          0 :                 rBackupPage.grabLocationFocus();
     448                 :          0 :                 return false;
     449                 :            :             }
     450                 :            : 
     451                 :            :             // store to the backup location
     452                 :          0 :             const Reference< XStorable > xDocument( getDocument(), UNO_QUERY_THROW );
     453                 :          0 :             xDocument->storeToURL( sBackupLocation, Sequence< PropertyValue >() );
     454                 :          0 :             m_pData->sSuccessfulBackupLocation = sBackupLocation;
     455                 :            :         }
     456                 :          0 :         catch( const Exception& )
     457                 :            :         {
     458                 :          0 :             aError = ::cppu::getCaughtException();
     459                 :            :         }
     460                 :          0 :         if ( !aError.hasValue() )
     461                 :            :         {
     462                 :          0 :             ::svt::OFileNotation aFileNotation( sBackupLocation );
     463                 :          0 :             m_pData->aLogger.backedUpDocument( aFileNotation.get( ::svt::OFileNotation::N_SYSTEM ) );
     464                 :          0 :             return true;
     465                 :            :         }
     466                 :            : 
     467                 :            :         // display the error to the user
     468                 :          0 :         InteractionHandler aHandler( m_pData->aContext, m_pData->xDocumentModel.get() );
     469                 :          0 :         aHandler.reportError( aError );
     470                 :            : 
     471                 :          0 :         m_pData->aLogger.logFailure( MigrationError(
     472                 :            :             ERR_DOCUMENT_BACKUP_FAILED,
     473                 :            :             sBackupLocation,
     474                 :            :             aError
     475                 :          0 :         ) );
     476                 :            : 
     477                 :          0 :         return false;
     478                 :            :     }
     479                 :            : 
     480                 :            :     //--------------------------------------------------------------------
     481                 :          0 :     void MacroMigrationDialog::impl_reloadDocument_nothrow( bool _bMigrationSuccess )
     482                 :            :     {
     483                 :            :         typedef ::std::pair< Reference< XFrame >, ::rtl::OUString > ViewDescriptor;
     484                 :          0 :         ::std::list< ViewDescriptor > aViews;
     485                 :            : 
     486                 :            :         try
     487                 :            :         {
     488                 :            :             // the information which is necessary to reload the document
     489                 :          0 :             ::rtl::OUString                     sDocumentURL ( m_pData->xDocumentModel->getURL()  );
     490                 :          0 :             ::comphelper::NamedValueCollection  aDocumentArgs( m_pData->xDocumentModel->getArgs() );
     491                 :          0 :             if ( !_bMigrationSuccess )
     492                 :            :             {
     493                 :            :                 // if the migration was not successful, then reload from the backup
     494                 :          0 :                 aDocumentArgs.put( "SalvagedFile", m_pData->sSuccessfulBackupLocation );
     495                 :            :                 // reset the modified flag of the document, so the controller can be suspended later
     496                 :          0 :                 Reference< XModifiable > xModify( m_pData->xDocument, UNO_QUERY_THROW );
     497                 :          0 :                 xModify->setModified( sal_False );
     498                 :            :                 // after this reload, don't show the migration warning, again
     499                 :          0 :                 aDocumentArgs.put( "SuppressMigrationWarning", sal_Bool(sal_True) );
     500                 :            :             }
     501                 :            : 
     502                 :            :             // remove anything from the args which might refer to the old document
     503                 :          0 :             aDocumentArgs.remove( "Model" );
     504                 :          0 :             aDocumentArgs.remove( "Stream" );
     505                 :          0 :             aDocumentArgs.remove( "InputStream" );
     506                 :          0 :             aDocumentArgs.remove( "FileName" );
     507                 :          0 :             aDocumentArgs.remove( "URL" );
     508                 :            : 
     509                 :            :             // collect all controllers of our document
     510                 :          0 :             ::std::list< Reference< XController2 > > aControllers;
     511                 :          0 :             lcl_getControllers_throw( m_pData->xDocumentModel, aControllers );
     512                 :            : 
     513                 :            :             // close all those controllers
     514                 :          0 :             while ( !aControllers.empty() )
     515                 :            :             {
     516                 :          0 :                 Reference< XController2 > xController( aControllers.front(), UNO_SET_THROW );
     517                 :          0 :                 aControllers.pop_front();
     518                 :            : 
     519                 :          0 :                 Reference< XFrame > xFrame( xController->getFrame(), UNO_SET_THROW );
     520                 :          0 :                 ::rtl::OUString sViewName( xController->getViewControllerName() );
     521                 :            : 
     522                 :          0 :                 if ( !xController->suspend( sal_True ) )
     523                 :            :                 {   // ouch. There shouldn't be any modal dialogs and such, so there
     524                 :            :                     // really is no reason why suspending shouldn't work.
     525                 :            :                     OSL_FAIL( "MacroMigrationDialog::impl_reloadDocument_nothrow: could not suspend a controller!" );
     526                 :            :                     // ignoring this would be at the cost of a crash (potentially)
     527                 :            :                     // so, we cannot continue here.
     528                 :          0 :                     throw CloseVetoException();
     529                 :            :                 }
     530                 :            : 
     531                 :          0 :                 aViews.push_back( ViewDescriptor( xFrame, sViewName ) );
     532                 :          0 :                 xFrame->setComponent( NULL, NULL );
     533                 :          0 :                 xController->dispose();
     534                 :          0 :             }
     535                 :            : 
     536                 :            :             // Note the document is closed now - disconnecting the last controller
     537                 :            :             // closes it automatically.
     538                 :            : 
     539                 :          0 :             Reference< XOfficeDatabaseDocument > xNewDocument;
     540                 :            : 
     541                 :            :             // re-create the views
     542                 :          0 :             while ( !aViews.empty() )
     543                 :            :             {
     544                 :          0 :                 ViewDescriptor aView( aViews.front() );
     545                 :          0 :                 aViews.pop_front();
     546                 :            : 
     547                 :            :                 // load the document into this frame
     548                 :          0 :                 Reference< XComponentLoader > xLoader( aView.first, UNO_QUERY_THROW );
     549                 :          0 :                 aDocumentArgs.put( "ViewName", aView.second );
     550                 :          0 :                 Reference< XInterface > xReloaded( xLoader->loadComponentFromURL(
     551                 :            :                     sDocumentURL,
     552                 :            :                     ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_self" ) ),
     553                 :            :                     0,
     554                 :            :                     aDocumentArgs.getPropertyValues()
     555                 :          0 :                 ) );
     556                 :            : 
     557                 :            :                 OSL_ENSURE( xReloaded != m_pData->xDocumentModel,
     558                 :            :                     "MacroMigrationDialog::impl_reloadDocument_nothrow: this should have been a new instance!" );
     559                 :            :                     // this would be unexpected, but recoverable: The loader should at least have done
     560                 :            :                     // this: really *load* the document, even if it loaded it into the old document instance
     561                 :          0 :                 if ( !xNewDocument.is() )
     562                 :            :                 {
     563                 :          0 :                     xNewDocument.set( xReloaded, UNO_QUERY_THROW );
     564                 :            :                     // for subsequent loads, into different frames, put the document into the load args
     565                 :          0 :                     aDocumentArgs.put( "Model", xNewDocument );
     566                 :            :                 }
     567                 :            :                 #if OSL_DEBUG_LEVEL > 0
     568                 :            :                 else
     569                 :            :                 {
     570                 :            :                     OSL_ENSURE( xNewDocument == xReloaded,
     571                 :            :                         "MacroMigrationDialog::impl_reloadDocument_nothrow: unexpected: subsequent load attempt returned a wrong document!" );
     572                 :            :                 }
     573                 :            :                 #endif
     574                 :          0 :             }
     575                 :            : 
     576                 :          0 :             m_pData->xDocument = xNewDocument;
     577                 :          0 :             m_pData->xDocumentModel.set( xNewDocument, UNO_QUERY );
     578                 :            : 
     579                 :            :             // finally, now that the document has been reloaded - if the migration was not successful,
     580                 :            :             // then it was reloaded from the backup, but the real document still is broken. So, save
     581                 :            :             // the document once, which will write the content loaded from the backup to the real docfile.
     582                 :          0 :             if ( !_bMigrationSuccess )
     583                 :            :             {
     584                 :          0 :                 Reference< XModifiable > xModify( m_pData->xDocument, UNO_QUERY_THROW );
     585                 :          0 :                 xModify->setModified( sal_True );
     586                 :            :                     // this is just parnoia - in case saving the doc fails, perhaps the user is tempted to do so
     587                 :          0 :                 Reference< XStorable > xStor( m_pData->xDocument, UNO_QUERY_THROW );
     588                 :          0 :                 xStor->store();
     589                 :          0 :             }
     590                 :            :         }
     591                 :          0 :         catch( const Exception& )
     592                 :            :         {
     593                 :            :             DBG_UNHANDLED_EXCEPTION();
     594                 :            :         }
     595                 :            : 
     596                 :            :         // close all frames from aViews - the respective controllers have been closed, but
     597                 :            :         // reloading didn't work, so the frames are zombies now.
     598                 :          0 :         while ( !aViews.empty() )
     599                 :            :         {
     600                 :          0 :             ViewDescriptor aView( aViews.front() );
     601                 :          0 :             aViews.pop_front();
     602                 :            :             try
     603                 :            :             {
     604                 :          0 :                 Reference< XCloseable > xFrameClose( aView.first, UNO_QUERY_THROW );
     605                 :          0 :                 xFrameClose->close( sal_True );
     606                 :            :             }
     607                 :          0 :             catch( const Exception& )
     608                 :            :             {
     609                 :            :                 DBG_UNHANDLED_EXCEPTION();
     610                 :            :             }
     611                 :          0 :         }
     612                 :          0 :     }
     613                 :            : 
     614                 :            : //........................................................................
     615                 :            : } // namespace dbmm
     616                 :            : //........................................................................
     617                 :            : 
     618                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10