LCOV - code coverage report
Current view: top level - svx/source/unodraw - recoveryui.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 2 148 1.4 %
Date: 2012-08-25 Functions: 1 22 4.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 201 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "recoveryui.hxx"
      30                 :            : #include "docrecovery.hxx"
      31                 :            : #include <com/sun/star/lang/XInitialization.hpp>
      32                 :            : #include <com/sun/star/frame/XFramesSupplier.hpp>
      33                 :            : #include <com/sun/star/beans/NamedValue.hpp>
      34                 :            : #include <osl/file.hxx>
      35                 :            : #include <rtl/bootstrap.hxx>
      36                 :            : #include <comphelper/configurationhelper.hxx>
      37                 :            : 
      38                 :            : #include <vcl/svapp.hxx>
      39                 :            : 
      40                 :            : #include <boost/scoped_ptr.hpp>
      41                 :            : 
      42                 :            : 
      43                 :            : #define IMPLEMENTATIONNAME_RECOVERYUI       ::rtl::OUString("com.sun.star.comp.svx.RecoveryUI")
      44                 :            : #define SERVICENAME_RECOVERYUI              ::rtl::OUString("com.sun.star.dialog.RecoveryUI")
      45                 :            : 
      46                 :            : 
      47                 :            : namespace svx
      48                 :            : {
      49                 :            : 
      50                 :            : namespace css   = ::com::sun::star;
      51                 :            : namespace svxdr = ::svx::DocRecovery;
      52                 :            : 
      53                 :            : using namespace ::rtl;
      54                 :            : using namespace ::osl;
      55                 :            : 
      56                 :            : //===============================================
      57                 :          0 : RecoveryUI::RecoveryUI(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
      58                 :            :     : m_xSMGR        (xSMGR                    )
      59                 :            :     , m_pParentWindow(0                        )
      60                 :          0 :     , m_eJob         (RecoveryUI::E_JOB_UNKNOWN)
      61                 :            : {
      62                 :          0 : }
      63                 :            : 
      64                 :            : //===============================================
      65                 :          0 : RecoveryUI::~RecoveryUI()
      66                 :            : {
      67         [ #  # ]:          0 : }
      68                 :            : 
      69                 :            : //===============================================
      70                 :          0 : ::rtl::OUString SAL_CALL RecoveryUI::getImplementationName()
      71                 :            :     throw(css::uno::RuntimeException)
      72                 :            : {
      73                 :          0 :     return RecoveryUI::st_getImplementationName();
      74                 :            : }
      75                 :            : 
      76                 :            : //===============================================
      77                 :          0 : sal_Bool SAL_CALL RecoveryUI::supportsService(const ::rtl::OUString& sServiceName)
      78                 :            :     throw(css::uno::RuntimeException)
      79                 :            : {
      80         [ #  # ]:          0 :     const css::uno::Sequence< ::rtl::OUString > lServices = RecoveryUI::st_getSupportedServiceNames();
      81                 :          0 :           sal_Int32                             c         = lServices.getLength();
      82                 :          0 :           sal_Int32                             i         = 0;
      83         [ #  # ]:          0 :     for (i=0; i<c; ++i)
      84                 :            :     {
      85                 :          0 :         const ::rtl::OUString& sSupportedService = lServices[i];
      86         [ #  # ]:          0 :         if (sSupportedService.equals(sServiceName))
      87                 :          0 :             return sal_True;
      88                 :            :     }
      89         [ #  # ]:          0 :     return sal_False;
      90                 :            : }
      91                 :            : 
      92                 :            : //===============================================
      93                 :          0 : css::uno::Sequence< ::rtl::OUString > SAL_CALL RecoveryUI::getSupportedServiceNames()
      94                 :            :     throw(css::uno::RuntimeException)
      95                 :            : {
      96                 :          0 :     return RecoveryUI::st_getSupportedServiceNames();
      97                 :            : }
      98                 :            : 
      99                 :            : //===============================================
     100                 :          0 : css::uno::Any SAL_CALL RecoveryUI::dispatchWithReturnValue(const css::util::URL& aURL,
     101                 :            :                                                    const css::uno::Sequence< css::beans::PropertyValue >& )
     102                 :            :     throw(css::uno::RuntimeException)
     103                 :            : {
     104                 :            :     // Internaly we use VCL ... every call into vcl based code must
     105                 :            :     // be guarded by locking the global solar mutex.
     106         [ #  # ]:          0 :     ::SolarMutexGuard aSolarLock;
     107                 :            : 
     108                 :          0 :     css::uno::Any aRet;
     109         [ #  # ]:          0 :     RecoveryUI::EJob eJob = impl_classifyJob(aURL);
     110                 :            :     // TODO think about outside arguments
     111                 :            : 
     112   [ #  #  #  # ]:          0 :     switch(eJob)
     113                 :            :     {
     114                 :            :         case RecoveryUI::E_DO_EMERGENCY_SAVE :
     115                 :            :         {
     116         [ #  # ]:          0 :             sal_Bool bRet = impl_doEmergencySave();
     117         [ #  # ]:          0 :             aRet <<= bRet;
     118                 :            :             break;
     119                 :            :         }
     120                 :            : 
     121                 :            :         case RecoveryUI::E_DO_RECOVERY :
     122         [ #  # ]:          0 :             impl_doRecovery();
     123                 :          0 :             break;
     124                 :            : 
     125                 :            :         case RecoveryUI::E_DO_CRASHREPORT :
     126         [ #  # ]:          0 :             impl_doCrashReport();
     127                 :          0 :             break;
     128                 :            : 
     129                 :            :         default :
     130                 :          0 :             break;
     131                 :            :     }
     132                 :            : 
     133         [ #  # ]:          0 :     return aRet;
     134                 :            : }
     135                 :            : 
     136                 :            : //===============================================
     137                 :          0 : void SAL_CALL RecoveryUI::dispatch(const css::util::URL&                                  aURL      ,
     138                 :            :                                    const css::uno::Sequence< css::beans::PropertyValue >& lArguments)
     139                 :            :     throw(css::uno::RuntimeException)
     140                 :            : {
     141                 :            :     // recycle this method :-)
     142                 :          0 :     dispatchWithReturnValue(aURL, lArguments);
     143                 :          0 : }
     144                 :            : 
     145                 :            : //===============================================
     146                 :          0 : void SAL_CALL RecoveryUI::addStatusListener(const css::uno::Reference< css::frame::XStatusListener >&, const css::util::URL& ) throw(css::uno::RuntimeException)
     147                 :            : {
     148                 :            :     // TODO
     149                 :            :     OSL_FAIL("RecoveryUI::addStatusListener()\nNot implemented yet!");
     150                 :          0 : }
     151                 :            : 
     152                 :            : //===============================================
     153                 :          0 : void SAL_CALL RecoveryUI::removeStatusListener(const css::uno::Reference< css::frame::XStatusListener >&, const css::util::URL& )
     154                 :            :     throw(css::uno::RuntimeException)
     155                 :            : {
     156                 :            :     // TODO
     157                 :            :     OSL_FAIL("RecoveryUI::removeStatusListener()\nNot implemented yet!");
     158                 :          0 : }
     159                 :            : 
     160                 :            : //===============================================
     161                 :         70 : ::rtl::OUString RecoveryUI::st_getImplementationName()
     162                 :            : {
     163                 :         70 :     return ::rtl::OUString(IMPLEMENTATIONNAME_RECOVERYUI);
     164                 :            : }
     165                 :            : 
     166                 :            : //===============================================
     167                 :          0 : css::uno::Sequence< ::rtl::OUString > RecoveryUI::st_getSupportedServiceNames()
     168                 :            : {
     169         [ #  # ]:          0 :     css::uno::Sequence< ::rtl::OUString > lServiceNames(1);    lServiceNames.getArray() [0] = SERVICENAME_RECOVERYUI;
     170                 :          0 :     return lServiceNames;
     171                 :            : }
     172                 :            : 
     173                 :            : //===============================================
     174                 :          0 : css::uno::Reference< css::uno::XInterface > SAL_CALL RecoveryUI::st_createInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
     175                 :            : {
     176         [ #  # ]:          0 :     RecoveryUI* pNew = new RecoveryUI(xSMGR);
     177         [ #  # ]:          0 :     return css::uno::Reference< css::uno::XInterface >(static_cast< css::lang::XServiceInfo* >(pNew));
     178                 :            : }
     179                 :            : 
     180                 :            : //===============================================
     181                 :            : 
     182                 :          0 : static OUString GetCrashConfigDir()
     183                 :            : {
     184                 :            : 
     185                 :            : #if defined(WNT)
     186                 :            :     OUString    ustrValue = OUString("${$BRAND_BASE_DIR/program/bootstrap.ini:UserInstallation}");
     187                 :            : #elif defined(MACOSX)
     188                 :            :     OUString    ustrValue = OUString("~");
     189                 :            : #else
     190                 :          0 :     OUString    ustrValue = OUString("$SYSUSERCONFIG");
     191                 :            : #endif
     192                 :          0 :     Bootstrap::expandMacros( ustrValue );
     193                 :            : 
     194                 :            : #if defined(WNT)
     195                 :            :     ustrValue += OUString("/user/crashdata");
     196                 :            : #endif
     197                 :          0 :     return ustrValue;
     198                 :            : }
     199                 :            : 
     200                 :            : //===============================================
     201                 :            : 
     202                 :            : #if defined(WNT)
     203                 :            : #define LCKFILE "crashdat.lck"
     204                 :            : #else
     205                 :            : #define LCKFILE ".crash_report_unsent"
     206                 :            : #endif
     207                 :            : 
     208                 :            : 
     209                 :          0 : static OUString GetUnsentURL()
     210                 :            : {
     211                 :          0 :     OUString    aURL = GetCrashConfigDir();
     212                 :            : 
     213                 :          0 :     aURL += OUString(  "/"  );
     214                 :          0 :     aURL += OUString(  LCKFILE  );
     215                 :            : 
     216                 :          0 :     return aURL;
     217                 :            : }
     218                 :            : 
     219                 :            : //===============================================
     220                 :            : 
     221                 :          0 : static bool new_crash_pending()
     222                 :            : {
     223         [ #  # ]:          0 :     OUString    aUnsentURL = GetUnsentURL();
     224                 :          0 :     File    aFile( aUnsentURL );
     225                 :            : 
     226 [ #  # ][ #  # ]:          0 :     if ( FileBase::E_None == aFile.open( osl_File_OpenFlag_Read ) )
     227                 :            :     {
     228         [ #  # ]:          0 :         aFile.close();
     229                 :          0 :         return true;
     230                 :            :     }
     231                 :            : 
     232         [ #  # ]:          0 :     return false;
     233                 :            : }
     234                 :            : //===============================================
     235                 :            : 
     236                 :          0 : static bool delete_pending_crash()
     237                 :            : {
     238         [ #  # ]:          0 :     OUString    aUnsentURL = GetUnsentURL();
     239         [ #  # ]:          0 :     return ( FileBase::E_None == File::remove( aUnsentURL ) );
     240                 :            : }
     241                 :            : 
     242                 :          0 : RecoveryUI::EJob RecoveryUI::impl_classifyJob(const css::util::URL& aURL)
     243                 :            : {
     244                 :          0 :     m_eJob = RecoveryUI::E_JOB_UNKNOWN;
     245         [ #  # ]:          0 :     if (aURL.Protocol.equals(RECOVERY_CMDPART_PROTOCOL))
     246                 :            :     {
     247         [ #  # ]:          0 :         if (aURL.Path.equals(RECOVERY_CMDPART_DO_EMERGENCY_SAVE))
     248                 :          0 :             m_eJob = RecoveryUI::E_DO_EMERGENCY_SAVE;
     249                 :            :         else
     250         [ #  # ]:          0 :         if (aURL.Path.equals(RECOVERY_CMDPART_DO_RECOVERY))
     251                 :          0 :             m_eJob = RecoveryUI::E_DO_RECOVERY;
     252                 :            :         else
     253         [ #  # ]:          0 :         if (aURL.Path.equals(RECOVERY_CMDPART_DO_CRASHREPORT))
     254                 :          0 :             m_eJob = RecoveryUI::E_DO_CRASHREPORT;
     255                 :            :     }
     256                 :            : 
     257                 :          0 :     return m_eJob;
     258                 :            : }
     259                 :            : 
     260                 :            : //===============================================
     261                 :          0 : sal_Bool RecoveryUI::impl_doEmergencySave()
     262                 :            : {
     263                 :            :     // create core service, which implements the real "emergency save" algorithm.
     264         [ #  # ]:          0 :     svxdr::RecoveryCore* pCore = new svxdr::RecoveryCore(m_xSMGR, sal_True);
     265 [ #  # ][ #  # ]:          0 :     css::uno::Reference< css::frame::XStatusListener > xCore(pCore);
     266                 :            : 
     267                 :            :     // create all needed dialogs for this operation
     268                 :            :     // and bind it to the used core service
     269 [ #  # ][ #  # ]:          0 :     svxdr::TabDialog4Recovery* pWizard = new svxdr::TabDialog4Recovery(m_pParentWindow);
     270 [ #  # ][ #  # ]:          0 :     svxdr::IExtendedTabPage*   pPage1  = new svxdr::SaveDialog        (pWizard, pCore );
     271         [ #  # ]:          0 :     pWizard->addTabPage(pPage1);
     272                 :            : 
     273                 :            :     // start the wizard
     274         [ #  # ]:          0 :     short nRet = pWizard->Execute();
     275                 :            : 
     276 [ #  # ][ #  # ]:          0 :     delete pPage1 ;
     277 [ #  # ][ #  # ]:          0 :     delete pWizard;
     278                 :            : 
     279                 :          0 :     return (nRet==DLG_RET_OK_AUTOLUNCH);
     280                 :            : }
     281                 :            : 
     282                 :            : //===============================================
     283                 :          0 : void RecoveryUI::impl_doRecovery()
     284                 :            : {
     285                 :          0 :     sal_Bool bRecoveryOnly( sal_False );
     286                 :            : 
     287                 :          0 :     ::rtl::OUString CFG_PACKAGE_RECOVERY( "org.openoffice.Office.Recovery/");
     288                 :          0 :     ::rtl::OUString CFG_PATH_CRASHREPORTER(  "CrashReporter" );
     289                 :          0 :     ::rtl::OUString CFG_ENTRY_ENABLED( "Enabled" );
     290                 :            : 
     291                 :          0 :     sal_Bool bCrashRepEnabled(sal_False);
     292                 :            :     css::uno::Any aVal = ::comphelper::ConfigurationHelper::readDirectKey(
     293                 :            :                                 m_xSMGR,
     294                 :            :                                 CFG_PACKAGE_RECOVERY,
     295                 :            :                                 CFG_PATH_CRASHREPORTER,
     296                 :            :                                 CFG_ENTRY_ENABLED,
     297         [ #  # ]:          0 :                                 ::comphelper::ConfigurationHelper::E_READONLY);
     298                 :          0 :     aVal >>= bCrashRepEnabled;
     299                 :          0 :     bRecoveryOnly = !bCrashRepEnabled;
     300                 :            : 
     301                 :            :     // create core service, which implements the real "emergency save" algorithm.
     302         [ #  # ]:          0 :     svxdr::RecoveryCore* pCore = new svxdr::RecoveryCore(m_xSMGR, sal_False);
     303 [ #  # ][ #  # ]:          0 :     css::uno::Reference< css::frame::XStatusListener > xCore(pCore);
     304                 :            : 
     305                 :            :     // create all needed dialogs for this operation
     306                 :            :     // and bind it to the used core service
     307 [ #  # ][ #  # ]:          0 :     boost::scoped_ptr<svxdr::TabDialog4Recovery> xWizard(new svxdr::TabDialog4Recovery(m_pParentWindow));
     308 [ #  # ][ #  # ]:          0 :     svxdr::IExtendedTabPage*   pPage1  = new svxdr::RecoveryDialog(xWizard.get(), pCore );
     309                 :          0 :     svxdr::IExtendedTabPage*   pPage2  = 0;
     310                 :          0 :     svxdr::IExtendedTabPage*   pPage3  = 0;
     311                 :            : 
     312         [ #  # ]:          0 :     xWizard->addTabPage(pPage1);
     313 [ #  # ][ #  # ]:          0 :     if ( !bRecoveryOnly && new_crash_pending() )
         [ #  # ][ #  # ]
     314                 :            :     {
     315 [ #  # ][ #  # ]:          0 :         pPage2 = new svxdr::ErrorRepWelcomeDialog(xWizard.get());
     316 [ #  # ][ #  # ]:          0 :         pPage3 = new svxdr::ErrorRepSendDialog(xWizard.get());
     317         [ #  # ]:          0 :         xWizard->addTabPage(pPage2);
     318         [ #  # ]:          0 :         xWizard->addTabPage(pPage3);
     319                 :            :     }
     320                 :            : 
     321                 :            :     // start the wizard
     322         [ #  # ]:          0 :     xWizard->Execute();
     323                 :            : 
     324         [ #  # ]:          0 :     impl_showAllRecoveredDocs();
     325                 :            : 
     326 [ #  # ][ #  # ]:          0 :     delete pPage3 ;
     327 [ #  # ][ #  # ]:          0 :     delete pPage2 ;
     328 [ #  # ][ #  # ]:          0 :     delete pPage1 ;
     329                 :            : 
     330 [ #  # ][ #  # ]:          0 :     delete_pending_crash();
     331                 :          0 : }
     332                 :            : 
     333                 :            : //===============================================
     334                 :            : 
     335                 :          0 : void RecoveryUI::impl_doCrashReport()
     336                 :            : {
     337         [ #  # ]:          0 :     if ( new_crash_pending() )
     338                 :            :     {
     339         [ #  # ]:          0 :         svxdr::TabDialog4Recovery* pWizard = new svxdr::TabDialog4Recovery   (m_pParentWindow   );
     340         [ #  # ]:          0 :         svxdr::IExtendedTabPage*   pPage1  = new svxdr::ErrorRepWelcomeDialog(pWizard, sal_False);
     341         [ #  # ]:          0 :         svxdr::IExtendedTabPage*   pPage2  = new svxdr::ErrorRepSendDialog   (pWizard           );
     342                 :          0 :         pWizard->addTabPage(pPage1);
     343                 :          0 :         pWizard->addTabPage(pPage2);
     344                 :            : 
     345                 :            :         // start the wizard
     346                 :          0 :         pWizard->Execute();
     347                 :            : 
     348         [ #  # ]:          0 :         delete pPage2 ;
     349         [ #  # ]:          0 :         delete pPage1 ;
     350         [ #  # ]:          0 :         delete pWizard;
     351                 :            : 
     352                 :          0 :         delete_pending_crash();
     353                 :            :     }
     354                 :          0 : }
     355                 :            : 
     356                 :            : //===============================================
     357                 :          0 : void RecoveryUI::impl_showAllRecoveredDocs()
     358                 :            : {
     359                 :            :     css::uno::Reference< css::frame::XFramesSupplier > xDesktop(
     360         [ #  # ]:          0 :         m_xSMGR->createInstance(SERVICENAME_DESKTOP),
     361 [ #  # ][ #  # ]:          0 :         css::uno::UNO_QUERY_THROW);
                 [ #  # ]
     362                 :            : 
     363                 :            :     css::uno::Reference< css::container::XIndexAccess > xTaskContainer(
     364         [ #  # ]:          0 :         xDesktop->getFrames(),
     365 [ #  # ][ #  # ]:          0 :         css::uno::UNO_QUERY_THROW);
     366                 :            : 
     367 [ #  # ][ #  # ]:          0 :     sal_Int32 c = xTaskContainer->getCount();
     368                 :          0 :     sal_Int32 i = 0;
     369         [ #  # ]:          0 :     for (i=0; i<c; ++i)
     370                 :            :     {
     371                 :            :         try
     372                 :            :         {
     373                 :          0 :             css::uno::Reference< css::frame::XFrame > xTask;
     374 [ #  # ][ #  # ]:          0 :             xTaskContainer->getByIndex(i) >>= xTask;
                 [ #  # ]
     375         [ #  # ]:          0 :             if (!xTask.is())
     376                 :          0 :                 continue;
     377                 :            : 
     378 [ #  # ][ #  # ]:          0 :             css::uno::Reference< css::awt::XWindow > xWindow = xTask->getContainerWindow();
     379         [ #  # ]:          0 :             if (!xWindow.is())
     380                 :          0 :                 continue;
     381                 :            : 
     382 [ #  # ][ #  # ]:          0 :             xWindow->setVisible(sal_True);
         [ #  # ][ #  # ]
     383                 :            :         }
     384      [ #  #  # ]:          0 :         catch(const css::uno::RuntimeException&)
     385                 :          0 :             { throw; }
     386         [ #  # ]:          0 :         catch(const css::uno::Exception&)
     387                 :          0 :             { continue; }
     388                 :          0 :     }
     389                 :          0 : }
     390                 :            : 
     391                 :            : } // namespace svx
     392                 :            : 
     393                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10