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

Generated by: LCOV version 1.10