LCOV - code coverage report
Current view: top level - sd/source/ui/tools - SlotStateListener.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 63 68 92.6 %
Date: 2015-06-13 12:38:46 Functions: 12 13 92.3 %
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 "tools/SlotStateListener.hxx"
      21             : #include <com/sun/star/frame/XStatusListener.hpp>
      22             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      23             : #include <com/sun/star/frame/XDispatch.hpp>
      24             : #include <com/sun/star/util/URLTransformer.hpp>
      25             : #include <com/sun/star/util/XURLTransformer.hpp>
      26             : #include <com/sun/star/beans/PropertyChangeEvent.hpp>
      27             : 
      28             : #include <comphelper/processfactory.hxx>
      29             : 
      30             : using namespace ::com::sun::star;
      31             : 
      32             : namespace sd { namespace tools {
      33             : 
      34          10 : SlotStateListener::SlotStateListener (
      35             :     Link<>& rCallback,
      36             :     const uno::Reference<frame::XDispatchProvider>& rxDispatchProvider,
      37             :     const OUString& rSlotName)
      38             :     : SlotStateListenerInterfaceBase(maMutex),
      39             :       maCallback(),
      40          10 :       mxDispatchProviderWeak(NULL)
      41             : {
      42          10 :     SetCallback(rCallback);
      43          10 :     ConnectToDispatchProvider(rxDispatchProvider);
      44          10 :     ObserveSlot(rSlotName);
      45          10 : }
      46             : 
      47          30 : SlotStateListener::~SlotStateListener()
      48             : {
      49          10 :     ReleaseListeners();
      50          20 : }
      51             : 
      52          10 : void SlotStateListener::SetCallback (const Link<>& rCallback)
      53             : {
      54          10 :     ThrowIfDisposed();
      55             : 
      56          10 :     maCallback = rCallback;
      57          10 : }
      58             : 
      59          10 : void SlotStateListener::ConnectToDispatchProvider (
      60             :     const uno::Reference<frame::XDispatchProvider>& rxDispatchProvider)
      61             : {
      62          10 :     ThrowIfDisposed();
      63             : 
      64             :     // When we are listening to state changes of slots of another frame then
      65             :     // release these listeners first.
      66          10 :     if ( ! maRegisteredURLList.empty())
      67           0 :         ReleaseListeners();
      68             : 
      69          10 :     mxDispatchProviderWeak = rxDispatchProvider;
      70          10 : }
      71             : 
      72          10 : void SlotStateListener::ObserveSlot (const OUString& rSlotName)
      73             : {
      74          10 :     ThrowIfDisposed();
      75             : 
      76          10 :     if (maCallback.IsSet())
      77             :     {
      78             :         // Connect the state change listener.
      79          10 :         util::URL aURL (MakeURL(rSlotName));
      80          20 :         uno::Reference<frame::XDispatch> xDispatch (GetDispatch(aURL));
      81          10 :         if (xDispatch.is())
      82             :         {
      83          10 :             maRegisteredURLList.push_back(aURL);
      84          10 :             xDispatch->addStatusListener(this,aURL);
      85          10 :         }
      86             :     }
      87          10 : }
      88             : 
      89          10 : void SlotStateListener::disposing()
      90             : {
      91          10 :     ReleaseListeners();
      92          10 :     mxDispatchProviderWeak = uno::WeakReference<frame::XDispatchProvider>(NULL);
      93          10 :     maCallback = Link<>();
      94          10 : }
      95             : 
      96          10 : util::URL SlotStateListener::MakeURL (const OUString& rSlotName)
      97             : {
      98          10 :     util::URL aURL;
      99          10 :     aURL.Complete = rSlotName;
     100             : 
     101          20 :     uno::Reference<util::XURLTransformer> xTransformer(util::URLTransformer::create(::comphelper::getProcessComponentContext()));
     102          10 :     xTransformer->parseStrict(aURL);
     103             : 
     104          20 :     return aURL;
     105             : }
     106             : 
     107             : uno::Reference<frame::XDispatch>
     108          30 :     SlotStateListener::GetDispatch (const util::URL& rURL) const
     109             : {
     110          30 :     uno::Reference<frame::XDispatch> xDispatch;
     111             : 
     112          60 :     uno::Reference<frame::XDispatchProvider> xDispatchProvider (mxDispatchProviderWeak);
     113          30 :     if (xDispatchProvider.is())
     114          20 :         xDispatch = xDispatchProvider->queryDispatch(rURL, OUString(), 0);
     115             : 
     116          60 :     return xDispatch;
     117             : }
     118             : 
     119          12 : void SlotStateListener::statusChanged (
     120             :     const frame::FeatureStateEvent& rState)
     121             :     throw (uno::RuntimeException, std::exception)
     122             : {
     123          12 :     ThrowIfDisposed();
     124          12 :     OUString sSlotName (rState.FeatureURL.Complete);
     125          12 :     if (maCallback.IsSet())
     126          12 :         maCallback.Call(&sSlotName);
     127          12 : }
     128             : 
     129          20 : void SlotStateListener::ReleaseListeners()
     130             : {
     131          20 :     if ( ! maRegisteredURLList.empty())
     132             :     {
     133          20 :         RegisteredURLList::iterator iURL (maRegisteredURLList.begin());
     134          20 :         RegisteredURLList::iterator iEnd (maRegisteredURLList.end());
     135          40 :         for (; iURL!=iEnd; ++iURL)
     136             :         {
     137          20 :             uno::Reference<frame::XDispatch> xDispatch (GetDispatch(*iURL));
     138          20 :             if (xDispatch.is())
     139             :             {
     140           0 :                 xDispatch->removeStatusListener(this,*iURL);
     141             :             }
     142          20 :         }
     143             :     }
     144          20 : }
     145             : 
     146             : //=====  lang::XEventListener  ================================================
     147             : 
     148           0 : void SAL_CALL SlotStateListener::disposing (
     149             :     const lang::EventObject& )
     150             :     throw (uno::RuntimeException, std::exception)
     151             : {
     152           0 : }
     153             : 
     154          42 : void SlotStateListener::ThrowIfDisposed()
     155             :     throw (lang::DisposedException)
     156             : {
     157          42 :     if (rBHelper.bDisposed || rBHelper.bInDispose)
     158             :     {
     159             :         throw lang::DisposedException ("SlideSorterController object has already been disposed",
     160           0 :             static_cast<uno::XWeak*>(this));
     161             :     }
     162          42 : }
     163             : 
     164             : } } // end of namespace ::sd::tools
     165             : 
     166             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11