LCOV - code coverage report
Current view: top level - svx/source/unodraw - recoveryui.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 81 1.2 %
Date: 2015-06-13 12:38:46 Functions: 2 17 11.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <config_folders.h>
      21             : 
      22             : #include <docrecovery.hxx>
      23             : #include <com/sun/star/beans/NamedValue.hpp>
      24             : #include <com/sun/star/frame/Desktop.hpp>
      25             : #include <com/sun/star/frame/XFramesSupplier.hpp>
      26             : #include <com/sun/star/frame/XSynchronousDispatch.hpp>
      27             : #include <com/sun/star/lang/XServiceInfo.hpp>
      28             : #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
      29             : #include <cppuhelper/implbase2.hxx>
      30             : #include <osl/file.hxx>
      31             : #include <rtl/bootstrap.hxx>
      32             : #include <rtl/ref.hxx>
      33             : #include <comphelper/processfactory.hxx>
      34             : #include <cppuhelper/supportsservice.hxx>
      35             : 
      36             : #include <vcl/svapp.hxx>
      37             : #include <vcl/window.hxx>
      38             : 
      39             : #include <boost/scoped_ptr.hpp>
      40             : #include <officecfg/Office/Recovery.hxx>
      41             : 
      42             : namespace svxdr = svx::DocRecovery;
      43             : using namespace ::osl;
      44             : 
      45             : namespace {
      46             : 
      47             : class RecoveryUI : public ::cppu::WeakImplHelper2< css::lang::XServiceInfo        ,
      48             :                                                    css::frame::XSynchronousDispatch > // => XDispatch!
      49             : {
      50             : 
      51             :     // const, types, etcpp.
      52             :     private:
      53             : 
      54             :         /** @short TODO */
      55             :         enum EJob
      56             :         {
      57             :             E_JOB_UNKNOWN,
      58             :             E_DO_EMERGENCY_SAVE,
      59             :             E_DO_RECOVERY,
      60             :         };
      61             : 
      62             : 
      63             :     // member
      64             :     private:
      65             : 
      66             :         /** @short TODO */
      67             :         css::uno::Reference< css::uno::XComponentContext > m_xContext;
      68             : 
      69             :         /** @short TODO */
      70             :         VclPtr<vcl::Window> m_pParentWindow;
      71             : 
      72             :         /** @short TODO */
      73             :         RecoveryUI::EJob m_eJob;
      74             : 
      75             :         /** @short TODO */
      76             :         css::uno::Reference< css::task::XStatusIndicatorFactory > m_xProgressFactory;
      77             : 
      78             : 
      79             :     // interface
      80             :     public:
      81             : 
      82             : 
      83             :         /** @short  TODO */
      84             :         explicit RecoveryUI(const css::uno::Reference< css::uno::XComponentContext >& xContext);
      85             : 
      86             : 
      87             :         /** @short  TODO */
      88             :         virtual ~RecoveryUI();
      89             : 
      90             : 
      91             :         // css.lang.XServiceInfo
      92             : 
      93             :         virtual OUString SAL_CALL getImplementationName()
      94             :             throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      95             : 
      96             :         virtual sal_Bool SAL_CALL supportsService(const OUString& sServiceName)
      97             :             throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      98             : 
      99             :         virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
     100             :             throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     101             : 
     102             : 
     103             :         virtual com::sun::star::uno::Any SAL_CALL dispatchWithReturnValue(const css::util::URL& aURL,
     104             :                                             const css::uno::Sequence< css::beans::PropertyValue >& lArguments )
     105             :             throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     106             : 
     107             : 
     108             :     // helper
     109             :     private:
     110             : 
     111             :         EJob impl_classifyJob(const css::util::URL& aURL);
     112             : 
     113             :         bool impl_doEmergencySave();
     114             : 
     115             :         void impl_doRecovery();
     116             : 
     117             :         void impl_showAllRecoveredDocs();
     118             : 
     119             : };
     120             : 
     121           0 : RecoveryUI::RecoveryUI(const css::uno::Reference< css::uno::XComponentContext >& xContext)
     122             :     : m_xContext     (xContext                 )
     123             :     , m_pParentWindow(0                        )
     124           0 :     , m_eJob         (RecoveryUI::E_JOB_UNKNOWN)
     125             : {
     126           0 : }
     127             : 
     128           0 : RecoveryUI::~RecoveryUI()
     129             : {
     130           0 : }
     131             : 
     132           0 : OUString SAL_CALL RecoveryUI::getImplementationName()
     133             :     throw(css::uno::RuntimeException, std::exception)
     134             : {
     135           0 :     return OUString("com.sun.star.comp.svx.RecoveryUI");
     136             : }
     137             : 
     138           0 : sal_Bool SAL_CALL RecoveryUI::supportsService(const OUString& sServiceName)
     139             :     throw(css::uno::RuntimeException, std::exception)
     140             : {
     141           0 :     return cppu::supportsService(this, sServiceName);
     142             : }
     143             : 
     144           0 : css::uno::Sequence< OUString > SAL_CALL RecoveryUI::getSupportedServiceNames()
     145             :     throw(css::uno::RuntimeException, std::exception)
     146             : {
     147           0 :     css::uno::Sequence< OUString > lServiceNames(1);
     148           0 :     lServiceNames[0] = "com.sun.star.dialog.RecoveryUI";
     149           0 :     return lServiceNames;
     150             : }
     151             : 
     152           0 : css::uno::Any SAL_CALL RecoveryUI::dispatchWithReturnValue(const css::util::URL& aURL,
     153             :                                                    const css::uno::Sequence< css::beans::PropertyValue >& )
     154             :     throw(css::uno::RuntimeException, std::exception)
     155             : {
     156             :     // Internally we use VCL ... every call into vcl based code must
     157             :     // be guarded by locking the global solar mutex.
     158           0 :     ::SolarMutexGuard aSolarLock;
     159             : 
     160           0 :     css::uno::Any aRet;
     161           0 :     RecoveryUI::EJob eJob = impl_classifyJob(aURL);
     162             :     // TODO think about outside arguments
     163             : 
     164           0 :     switch(eJob)
     165             :     {
     166             :         case RecoveryUI::E_DO_EMERGENCY_SAVE :
     167             :         {
     168           0 :             bool bRet = impl_doEmergencySave();
     169           0 :             aRet <<= bRet;
     170           0 :             break;
     171             :         }
     172             : 
     173             :         case RecoveryUI::E_DO_RECOVERY :
     174           0 :             impl_doRecovery();
     175           0 :             break;
     176             : 
     177             :         default :
     178           0 :             break;
     179             :     }
     180             : 
     181           0 :     return aRet;
     182             : }
     183             : 
     184             : 
     185             : 
     186           0 : static OUString GetCrashConfigDir()
     187             : {
     188             : 
     189             : #if defined(WNT)
     190             :     OUString    ustrValue = "${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/bootstrap.ini:UserInstallation}";
     191             : #elif defined(MACOSX)
     192             :     OUString    ustrValue = "~";
     193             : #else
     194           0 :     OUString    ustrValue = "$SYSUSERCONFIG";
     195             : #endif
     196           0 :     rtl::Bootstrap::expandMacros( ustrValue );
     197             : 
     198             : #if defined(WNT)
     199             :     ustrValue += "/user/crashdata";
     200             : #endif
     201           0 :     return ustrValue;
     202             : }
     203             : 
     204             : 
     205             : 
     206             : #if defined(WNT)
     207             : #define LCKFILE "crashdat.lck"
     208             : #else
     209             : #define LCKFILE ".crash_report_unsent"
     210             : #endif
     211             : 
     212             : 
     213           0 : static OUString GetUnsentURL()
     214             : {
     215           0 :     OUString aURL = GetCrashConfigDir() + "/" LCKFILE;
     216           0 :     return aURL;
     217             : }
     218             : 
     219             : 
     220             : 
     221           0 : static bool delete_pending_crash()
     222             : {
     223           0 :     OUString    aUnsentURL = GetUnsentURL();
     224           0 :     return ( FileBase::E_None == File::remove( aUnsentURL ) );
     225             : }
     226             : 
     227           0 : RecoveryUI::EJob RecoveryUI::impl_classifyJob(const css::util::URL& aURL)
     228             : {
     229           0 :     m_eJob = RecoveryUI::E_JOB_UNKNOWN;
     230           0 :     if (aURL.Protocol == RECOVERY_CMDPART_PROTOCOL)
     231             :     {
     232           0 :         if (aURL.Path == RECOVERY_CMDPART_DO_EMERGENCY_SAVE)
     233           0 :             m_eJob = RecoveryUI::E_DO_EMERGENCY_SAVE;
     234           0 :         else if (aURL.Path == RECOVERY_CMDPART_DO_RECOVERY)
     235           0 :             m_eJob = RecoveryUI::E_DO_RECOVERY;
     236             :     }
     237             : 
     238           0 :     return m_eJob;
     239             : }
     240             : 
     241           0 : bool RecoveryUI::impl_doEmergencySave()
     242             : {
     243             :     // create core service, which implements the real "emergency save" algorithm.
     244           0 :     svxdr::RecoveryCore* pCore = new svxdr::RecoveryCore(m_xContext, true);
     245           0 :     css::uno::Reference< css::frame::XStatusListener > xCore(pCore);
     246             : 
     247             :     // create dialog for this operation and bind it to the used core service
     248           0 :     ScopedVclPtrInstance<svxdr::SaveDialog> xDialog(m_pParentWindow, pCore);
     249             : 
     250             :     // start the dialog
     251           0 :     short nRet = xDialog->Execute();
     252           0 :     return (nRet==DLG_RET_OK_AUTOLUNCH);
     253             : }
     254             : 
     255           0 : void RecoveryUI::impl_doRecovery()
     256             : {
     257             :     // create core service, which implements the real "emergency save" algorithm.
     258           0 :     svxdr::RecoveryCore* pCore = new svxdr::RecoveryCore(m_xContext, false);
     259           0 :     css::uno::Reference< css::frame::XStatusListener > xCore(pCore);
     260             : 
     261             :     // create all needed dialogs for this operation
     262             :     // and bind it to the used core service
     263           0 :     ScopedVclPtrInstance<svxdr::RecoveryDialog> xDialog(m_pParentWindow, pCore);
     264             : 
     265             :     // start the dialog
     266           0 :     xDialog->Execute();
     267             : 
     268           0 :     impl_showAllRecoveredDocs();
     269             : 
     270           0 :     delete_pending_crash();
     271           0 : }
     272             : 
     273           0 : void RecoveryUI::impl_showAllRecoveredDocs()
     274             : {
     275           0 :     css::uno::Reference< css::frame::XDesktop2 > xDesktop = css::frame::Desktop::create( m_xContext );
     276             : 
     277             :     css::uno::Reference< css::container::XIndexAccess > xTaskContainer(
     278           0 :         xDesktop->getFrames(),
     279           0 :         css::uno::UNO_QUERY_THROW);
     280             : 
     281           0 :     sal_Int32 c = xTaskContainer->getCount();
     282           0 :     sal_Int32 i = 0;
     283           0 :     for (i=0; i<c; ++i)
     284             :     {
     285             :         try
     286             :         {
     287           0 :             css::uno::Reference< css::frame::XFrame > xTask;
     288           0 :             xTaskContainer->getByIndex(i) >>= xTask;
     289           0 :             if (!xTask.is())
     290           0 :                 continue;
     291             : 
     292           0 :             css::uno::Reference< css::awt::XWindow > xWindow = xTask->getContainerWindow();
     293           0 :             if (!xWindow.is())
     294           0 :                 continue;
     295             : 
     296           0 :             xWindow->setVisible(sal_True);
     297             :         }
     298           0 :         catch(const css::uno::RuntimeException&)
     299           0 :             { throw; }
     300           0 :         catch(const css::uno::Exception&)
     301           0 :             { continue; }
     302           0 :     }
     303           0 : }
     304             : 
     305             : }
     306             : 
     307             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     308           0 : com_sun_star_comp_svx_RecoveryUI_get_implementation(
     309             :     css::uno::XComponentContext *context,
     310             :     css::uno::Sequence<css::uno::Any> const &)
     311             : {
     312           0 :     return cppu::acquire(new RecoveryUI(context));
     313         390 : }
     314             : 
     315             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11