LCOV - code coverage report
Current view: top level - svx/source/unodraw - recoveryui.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 94 0.0 %
Date: 2014-04-14 Functions: 0 18 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <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             :         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             :         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             :         // css.frame.XDispatch
     109             : 
     110             :         virtual void SAL_CALL dispatch(const css::util::URL&                                  aURL      ,
     111             :                                        const css::uno::Sequence< css::beans::PropertyValue >& lArguments)
     112             :             throw(css::uno::RuntimeException);
     113             : 
     114             :         virtual void SAL_CALL addStatusListener(const css::uno::Reference< css::frame::XStatusListener >& xListener,
     115             :                                                 const css::util::URL&                                     aURL     )
     116             :             throw(css::uno::RuntimeException);
     117             :         virtual void SAL_CALL removeStatusListener(const css::uno::Reference< css::frame::XStatusListener >& xListener,
     118             :                                                    const css::util::URL&                                     aURL     )
     119             :             throw(css::uno::RuntimeException);
     120             : 
     121             : 
     122             :     // helper
     123             :     private:
     124             : 
     125             :         EJob impl_classifyJob(const css::util::URL& aURL);
     126             : 
     127             :         sal_Bool impl_doEmergencySave();
     128             : 
     129             :         void impl_doRecovery();
     130             : 
     131             :         void impl_showAllRecoveredDocs();
     132             : 
     133             : };
     134             : 
     135           0 : RecoveryUI::RecoveryUI(const css::uno::Reference< css::uno::XComponentContext >& xContext)
     136             :     : m_xContext     (xContext                 )
     137             :     , m_pParentWindow(0                        )
     138           0 :     , m_eJob         (RecoveryUI::E_JOB_UNKNOWN)
     139             : {
     140           0 : }
     141             : 
     142           0 : RecoveryUI::~RecoveryUI()
     143             : {
     144           0 : }
     145             : 
     146           0 : OUString SAL_CALL RecoveryUI::getImplementationName()
     147             :     throw(css::uno::RuntimeException, std::exception)
     148             : {
     149           0 :     return OUString("com.sun.star.comp.svx.RecoveryUI");
     150             : }
     151             : 
     152           0 : sal_Bool SAL_CALL RecoveryUI::supportsService(const OUString& sServiceName)
     153             :     throw(css::uno::RuntimeException, std::exception)
     154             : {
     155           0 :     return cppu::supportsService(this, sServiceName);
     156             : }
     157             : 
     158           0 : css::uno::Sequence< OUString > SAL_CALL RecoveryUI::getSupportedServiceNames()
     159             :     throw(css::uno::RuntimeException, std::exception)
     160             : {
     161           0 :     css::uno::Sequence< OUString > lServiceNames(1);
     162           0 :     lServiceNames[0] = "com.sun.star.dialog.RecoveryUI";
     163           0 :     return lServiceNames;
     164             : }
     165             : 
     166           0 : css::uno::Any SAL_CALL RecoveryUI::dispatchWithReturnValue(const css::util::URL& aURL,
     167             :                                                    const css::uno::Sequence< css::beans::PropertyValue >& )
     168             :     throw(css::uno::RuntimeException, std::exception)
     169             : {
     170             :     // Internally we use VCL ... every call into vcl based code must
     171             :     // be guarded by locking the global solar mutex.
     172           0 :     ::SolarMutexGuard aSolarLock;
     173             : 
     174           0 :     css::uno::Any aRet;
     175           0 :     RecoveryUI::EJob eJob = impl_classifyJob(aURL);
     176             :     // TODO think about outside arguments
     177             : 
     178           0 :     switch(eJob)
     179             :     {
     180             :         case RecoveryUI::E_DO_EMERGENCY_SAVE :
     181             :         {
     182           0 :             sal_Bool bRet = impl_doEmergencySave();
     183           0 :             aRet <<= bRet;
     184           0 :             break;
     185             :         }
     186             : 
     187             :         case RecoveryUI::E_DO_RECOVERY :
     188           0 :             impl_doRecovery();
     189           0 :             break;
     190             : 
     191             :         default :
     192           0 :             break;
     193             :     }
     194             : 
     195           0 :     return aRet;
     196             : }
     197             : 
     198             : 
     199           0 : void SAL_CALL RecoveryUI::dispatch(const css::util::URL&                                  aURL      ,
     200             :                                    const css::uno::Sequence< css::beans::PropertyValue >& lArguments)
     201             :     throw(css::uno::RuntimeException)
     202             : {
     203             :     // recycle this method :-)
     204           0 :     dispatchWithReturnValue(aURL, lArguments);
     205           0 : }
     206             : 
     207             : 
     208           0 : void SAL_CALL RecoveryUI::addStatusListener(const css::uno::Reference< css::frame::XStatusListener >&, const css::util::URL& ) throw(css::uno::RuntimeException)
     209             : {
     210             :     // TODO
     211             :     OSL_FAIL("RecoveryUI::addStatusListener()\nNot implemented yet!");
     212           0 : }
     213             : 
     214             : 
     215           0 : void SAL_CALL RecoveryUI::removeStatusListener(const css::uno::Reference< css::frame::XStatusListener >&, const css::util::URL& )
     216             :     throw(css::uno::RuntimeException)
     217             : {
     218             :     // TODO
     219             :     OSL_FAIL("RecoveryUI::removeStatusListener()\nNot implemented yet!");
     220           0 : }
     221             : 
     222           0 : static OUString GetCrashConfigDir()
     223             : {
     224             : 
     225             : #if defined(WNT)
     226             :     OUString    ustrValue = "${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/bootstrap.ini:UserInstallation}";
     227             : #elif defined(MACOSX)
     228             :     OUString    ustrValue = "~";
     229             : #else
     230           0 :     OUString    ustrValue = "$SYSUSERCONFIG";
     231             : #endif
     232           0 :     rtl::Bootstrap::expandMacros( ustrValue );
     233             : 
     234             : #if defined(WNT)
     235             :     ustrValue += "/user/crashdata";
     236             : #endif
     237           0 :     return ustrValue;
     238             : }
     239             : 
     240             : 
     241             : 
     242             : #if defined(WNT)
     243             : #define LCKFILE "crashdat.lck"
     244             : #else
     245             : #define LCKFILE ".crash_report_unsent"
     246             : #endif
     247             : 
     248             : 
     249           0 : static OUString GetUnsentURL()
     250             : {
     251           0 :     OUString aURL = GetCrashConfigDir() + "/" + LCKFILE;
     252           0 :     return aURL;
     253             : }
     254             : 
     255             : 
     256             : 
     257           0 : static bool delete_pending_crash()
     258             : {
     259           0 :     OUString    aUnsentURL = GetUnsentURL();
     260           0 :     return ( FileBase::E_None == File::remove( aUnsentURL ) );
     261             : }
     262             : 
     263           0 : RecoveryUI::EJob RecoveryUI::impl_classifyJob(const css::util::URL& aURL)
     264             : {
     265           0 :     m_eJob = RecoveryUI::E_JOB_UNKNOWN;
     266           0 :     if (aURL.Protocol.equals(RECOVERY_CMDPART_PROTOCOL))
     267             :     {
     268           0 :         if (aURL.Path.equals(RECOVERY_CMDPART_DO_EMERGENCY_SAVE))
     269           0 :             m_eJob = RecoveryUI::E_DO_EMERGENCY_SAVE;
     270           0 :         else if (aURL.Path.equals(RECOVERY_CMDPART_DO_RECOVERY))
     271           0 :             m_eJob = RecoveryUI::E_DO_RECOVERY;
     272             :     }
     273             : 
     274           0 :     return m_eJob;
     275             : }
     276             : 
     277             : 
     278           0 : sal_Bool RecoveryUI::impl_doEmergencySave()
     279             : {
     280             :     // create core service, which implements the real "emergency save" algorithm.
     281           0 :     svxdr::RecoveryCore* pCore = new svxdr::RecoveryCore(m_xContext, true);
     282           0 :     css::uno::Reference< css::frame::XStatusListener > xCore(pCore);
     283             : 
     284             :     // create all needed dialogs for this operation
     285             :     // and bind it to the used core service
     286           0 :     svxdr::TabDialog4Recovery* pWizard = new svxdr::TabDialog4Recovery(m_pParentWindow);
     287           0 :     svxdr::IExtendedTabPage*   pPage1  = new svxdr::SaveDialog        (pWizard, pCore );
     288           0 :     pWizard->addTabPage(pPage1);
     289             : 
     290             :     // start the wizard
     291           0 :     short nRet = pWizard->Execute();
     292             : 
     293           0 :     delete pPage1 ;
     294           0 :     delete pWizard;
     295             : 
     296           0 :     return (nRet==DLG_RET_OK_AUTOLUNCH);
     297             : }
     298             : 
     299             : 
     300           0 : void RecoveryUI::impl_doRecovery()
     301             : {
     302             :     // create core service, which implements the real "emergency save" algorithm.
     303           0 :     svxdr::RecoveryCore* pCore = new svxdr::RecoveryCore(m_xContext, false);
     304           0 :     css::uno::Reference< css::frame::XStatusListener > xCore(pCore);
     305             : 
     306             :     // create all needed dialogs for this operation
     307             :     // and bind it to the used core service
     308           0 :     boost::scoped_ptr<svxdr::TabDialog4Recovery> xWizard(new svxdr::TabDialog4Recovery(m_pParentWindow));
     309           0 :     svxdr::IExtendedTabPage*   pPage1  = new svxdr::RecoveryDialog(xWizard.get(), pCore );
     310             : 
     311           0 :     xWizard->addTabPage(pPage1);
     312             : 
     313             :     // start the wizard
     314           0 :     xWizard->Execute();
     315             : 
     316           0 :     impl_showAllRecoveredDocs();
     317             : 
     318           0 :     delete pPage1 ;
     319             : 
     320           0 :     delete_pending_crash();
     321           0 : }
     322             : 
     323             : 
     324             : 
     325           0 : void RecoveryUI::impl_showAllRecoveredDocs()
     326             : {
     327           0 :     css::uno::Reference< css::frame::XDesktop2 > xDesktop = css::frame::Desktop::create( m_xContext );
     328             : 
     329             :     css::uno::Reference< css::container::XIndexAccess > xTaskContainer(
     330           0 :         xDesktop->getFrames(),
     331           0 :         css::uno::UNO_QUERY_THROW);
     332             : 
     333           0 :     sal_Int32 c = xTaskContainer->getCount();
     334           0 :     sal_Int32 i = 0;
     335           0 :     for (i=0; i<c; ++i)
     336             :     {
     337             :         try
     338             :         {
     339           0 :             css::uno::Reference< css::frame::XFrame > xTask;
     340           0 :             xTaskContainer->getByIndex(i) >>= xTask;
     341           0 :             if (!xTask.is())
     342           0 :                 continue;
     343             : 
     344           0 :             css::uno::Reference< css::awt::XWindow > xWindow = xTask->getContainerWindow();
     345           0 :             if (!xWindow.is())
     346           0 :                 continue;
     347             : 
     348           0 :             xWindow->setVisible(sal_True);
     349             :         }
     350           0 :         catch(const css::uno::RuntimeException&)
     351           0 :             { throw; }
     352           0 :         catch(const css::uno::Exception&)
     353           0 :             { continue; }
     354           0 :     }
     355           0 : }
     356             : 
     357             : }
     358             : 
     359             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     360           0 : com_sun_star_comp_svx_RecoveryUI_get_implementation(
     361             :     css::uno::XComponentContext *context,
     362             :     css::uno::Sequence<css::uno::Any> const &)
     363             : {
     364           0 :     return cppu::acquire(new RecoveryUI(context));
     365             : }
     366             : 
     367             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10