LCOV - code coverage report
Current view: top level - libreoffice/framework/source/dispatch - startmoduledispatcher.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 63 0.0 %
Date: 2012-12-27 Functions: 0 17 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include <dispatch/startmoduledispatcher.hxx>
      22             : 
      23             : #include <pattern/frame.hxx>
      24             : #include <threadhelp/readguard.hxx>
      25             : #include <threadhelp/writeguard.hxx>
      26             : #include <framework/framelistanalyzer.hxx>
      27             : #include <dispatchcommands.h>
      28             : #include <targets.h>
      29             : #include <services.h>
      30             : #include <general.h>
      31             : 
      32             : #include <com/sun/star/frame/Desktop.hpp>
      33             : #include <com/sun/star/frame/XController.hpp>
      34             : #include <com/sun/star/frame/CommandGroup.hpp>
      35             : #include <com/sun/star/awt/XTopWindow.hpp>
      36             : #include "com/sun/star/beans/XFastPropertySet.hpp"
      37             : #include <com/sun/star/frame/XModuleManager.hpp>
      38             : 
      39             : #include <toolkit/helper/vclunohelper.hxx>
      40             : #include <vcl/window.hxx>
      41             : #include <vcl/svapp.hxx>
      42             : #include <osl/mutex.hxx>
      43             : #include <unotools/moduleoptions.hxx>
      44             : #include <comphelper/processfactory.hxx>
      45             : 
      46             : 
      47             : namespace framework{
      48             : 
      49             : #ifdef fpf
      50             :     #error "Who uses \"fpf\" as define. It will overwrite my namespace alias ..."
      51             : #endif
      52             : namespace fpf = ::framework::pattern::frame;
      53             : 
      54             : 
      55           0 : DEFINE_XINTERFACE_4(StartModuleDispatcher                                     ,
      56             :                     OWeakObject                                               ,
      57             :                     DIRECT_INTERFACE(css::lang::XTypeProvider                ),
      58             :                     DIRECT_INTERFACE(css::frame::XNotifyingDispatch          ),
      59             :                     DIRECT_INTERFACE(css::frame::XDispatch                   ),
      60             :                     DIRECT_INTERFACE(css::frame::XDispatchInformationProvider))
      61             : 
      62             : // Note: XStatusListener is an implementation detail. Hide it for scripting!
      63           0 : DEFINE_XTYPEPROVIDER_4(StartModuleDispatcher                   ,
      64             :                        css::lang::XTypeProvider                ,
      65             :                        css::frame::XDispatchInformationProvider,
      66             :                        css::frame::XNotifyingDispatch          ,
      67             :                        css::frame::XDispatch                   )
      68             : 
      69             : //-----------------------------------------------
      70           0 : StartModuleDispatcher::StartModuleDispatcher(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR  ,
      71             :                                              const css::uno::Reference< css::frame::XFrame >&              xFrame ,
      72             :                                              const ::rtl::OUString&                                        sTarget)
      73           0 :     : ThreadHelpBase     (&Application::GetSolarMutex() )
      74             :     , ::cppu::OWeakObject(                              )
      75             :     , m_xSMGR            (xSMGR                         )
      76             :     , m_xOwner           (xFrame                        )
      77             :     , m_sDispatchTarget  (sTarget                       )
      78           0 :     , m_lStatusListener  (m_aLock.getShareableOslMutex())
      79             : {
      80           0 : }
      81             : 
      82             : //-----------------------------------------------
      83           0 : StartModuleDispatcher::~StartModuleDispatcher()
      84             : {
      85           0 : }
      86             : 
      87             : //-----------------------------------------------
      88           0 : void SAL_CALL StartModuleDispatcher::dispatch(const css::util::URL&                                  aURL      ,
      89             :                                               const css::uno::Sequence< css::beans::PropertyValue >& lArguments)
      90             :     throw(css::uno::RuntimeException)
      91             : {
      92           0 :     dispatchWithNotification(aURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >());
      93           0 : }
      94             : 
      95             : //-----------------------------------------------
      96           0 : void SAL_CALL StartModuleDispatcher::dispatchWithNotification(const css::util::URL&                                             aURL      ,
      97             :                                                               const css::uno::Sequence< css::beans::PropertyValue >&            /*lArguments*/,
      98             :                                                               const css::uno::Reference< css::frame::XDispatchResultListener >& xListener )
      99             :     throw(css::uno::RuntimeException)
     100             : {
     101           0 :     ::sal_Int16 nResult = css::frame::DispatchResultState::DONTKNOW;
     102           0 :     if ( aURL.Complete == CMD_UNO_SHOWSTARTMODULE )
     103             :     {
     104           0 :         nResult = css::frame::DispatchResultState::FAILURE;
     105           0 :         if (implts_isBackingModePossible ())
     106             :         {
     107           0 :             if (implts_establishBackingMode ())
     108           0 :                 nResult = css::frame::DispatchResultState::SUCCESS;
     109             :         }
     110             :     }
     111             : 
     112           0 :     implts_notifyResultListener(xListener, nResult, css::uno::Any());
     113           0 : }
     114             : 
     115             : //-----------------------------------------------
     116           0 : css::uno::Sequence< ::sal_Int16 > SAL_CALL StartModuleDispatcher::getSupportedCommandGroups()
     117             :     throw(css::uno::RuntimeException)
     118             : {
     119           0 :     return css::uno::Sequence< ::sal_Int16 >();
     120             : }
     121             : 
     122             : //-----------------------------------------------
     123           0 : css::uno::Sequence< css::frame::DispatchInformation > SAL_CALL StartModuleDispatcher::getConfigurableDispatchInformation(::sal_Int16 /*nCommandGroup*/)
     124             :     throw(css::uno::RuntimeException)
     125             : {
     126           0 :     return css::uno::Sequence< css::frame::DispatchInformation >();
     127             : }
     128             : 
     129             : //-----------------------------------------------
     130           0 : void SAL_CALL StartModuleDispatcher::addStatusListener(const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/,
     131             :                                                        const css::util::URL&                                     /*aURL*/     )
     132             :     throw(css::uno::RuntimeException)
     133             : {
     134           0 : }
     135             : 
     136             : //-----------------------------------------------
     137           0 : void SAL_CALL StartModuleDispatcher::removeStatusListener(const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/,
     138             :                                                           const css::util::URL&                                     /*aURL*/     )
     139             :     throw(css::uno::RuntimeException)
     140             : {
     141           0 : }
     142             : 
     143             : //-----------------------------------------------
     144           0 : ::sal_Bool StartModuleDispatcher::implts_isBackingModePossible ()
     145             : {
     146           0 :     if ( ! SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SSTARTMODULE))
     147           0 :         return sal_False;
     148             : 
     149             :     // SAFE -> ----------------------------------
     150           0 :     ReadGuard aReadLock(m_aLock);
     151           0 :     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
     152           0 :     aReadLock.unlock();
     153             :     // <- SAFE ----------------------------------
     154             : 
     155             :     css::uno::Reference< css::frame::XFramesSupplier > xDesktop(
     156           0 :         css::frame::Desktop::create( comphelper::getComponentContext(xSMGR) ), css::uno::UNO_QUERY);
     157             : 
     158             :     FrameListAnalyzer aCheck(
     159             :         xDesktop,
     160             :         css::uno::Reference< css::frame::XFrame >(),
     161           0 :         FrameListAnalyzer::E_HELP | FrameListAnalyzer::E_BACKINGCOMPONENT);
     162             : 
     163           0 :     ::sal_Bool  bIsPossible    = sal_False;
     164           0 :     ::sal_Int32 nVisibleFrames = aCheck.m_lOtherVisibleFrames.getLength ();
     165             : 
     166           0 :     if (
     167           0 :         ( ! aCheck.m_xBackingComponent.is ()) &&
     168             :         (   nVisibleFrames < 1              )
     169             :        )
     170             :     {
     171           0 :         bIsPossible = sal_True;
     172             :     }
     173             : 
     174           0 :     return bIsPossible;
     175             : }
     176             : 
     177             : //-----------------------------------------------
     178           0 : ::sal_Bool StartModuleDispatcher::implts_establishBackingMode()
     179             : {
     180             :     // SAFE -> ----------------------------------
     181           0 :     ReadGuard aReadLock(m_aLock);
     182           0 :     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR  = m_xSMGR;
     183           0 :     aReadLock.unlock();
     184             :     // <- SAFE ----------------------------------
     185             : 
     186           0 :     css::uno::Reference< css::frame::XDesktop2> xDesktop       = css::frame::Desktop::create( comphelper::getComponentContext(xSMGR) );
     187           0 :     css::uno::Reference< css::frame::XFrame > xFrame           = xDesktop->findFrame (SPECIALTARGET_BLANK, 0);
     188           0 :     css::uno::Reference< css::awt::XWindow  > xContainerWindow = xFrame->getContainerWindow ();
     189             : 
     190           0 :     css::uno::Sequence< css::uno::Any > lArgs(1);
     191           0 :     lArgs[0] <<= xContainerWindow;
     192             : 
     193             :     css::uno::Reference< css::frame::XController > xStartModule(
     194           0 :         xSMGR->createInstanceWithArguments(SERVICENAME_STARTMODULE, lArgs),
     195           0 :         css::uno::UNO_QUERY_THROW);
     196             : 
     197           0 :     css::uno::Reference< css::awt::XWindow > xComponentWindow(xStartModule, css::uno::UNO_QUERY);
     198           0 :     xFrame->setComponent(xComponentWindow, xStartModule);
     199           0 :     xStartModule->attachFrame(xFrame);
     200           0 :     xContainerWindow->setVisible(sal_True);
     201             : 
     202           0 :     return sal_True;
     203             : }
     204             : 
     205             : //-----------------------------------------------
     206           0 : void StartModuleDispatcher::implts_notifyResultListener(const css::uno::Reference< css::frame::XDispatchResultListener >& xListener,
     207             :                                                               ::sal_Int16                                                 nState   ,
     208             :                                                         const css::uno::Any&                                              aResult  )
     209             : {
     210           0 :     if ( ! xListener.is())
     211           0 :         return;
     212             : 
     213             :     css::frame::DispatchResultEvent aEvent(
     214             :         css::uno::Reference< css::uno::XInterface >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY),
     215             :         nState,
     216           0 :         aResult);
     217             : 
     218           0 :     xListener->dispatchFinished(aEvent);
     219             : }
     220             : 
     221             : } // namespace framework
     222             : 
     223             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10