LCOV - code coverage report
Current view: top level - libreoffice/sd/source/ui/tools - SlotStateListener.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 68 0.0 %
Date: 2012-12-27 Functions: 0 13 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 "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           0 : SlotStateListener::SlotStateListener (
      38             :     Link& rCallback,
      39             :     const uno::Reference<frame::XDispatchProvider>& rxDispatchProvider,
      40             :     const ::rtl::OUString& rSlotName)
      41             :     : SlotStateListenerInterfaceBase(maMutex),
      42             :       maCallback(),
      43           0 :       mxDispatchProviderWeak(NULL)
      44             : {
      45           0 :     SetCallback(rCallback);
      46           0 :     ConnectToDispatchProvider(rxDispatchProvider);
      47           0 :     ObserveSlot(rSlotName);
      48           0 : }
      49             : 
      50             : 
      51             : 
      52             : 
      53           0 : SlotStateListener::~SlotStateListener (void)
      54             : {
      55           0 :     ReleaseListeners();
      56           0 : }
      57             : 
      58             : 
      59             : 
      60             : 
      61           0 : void SlotStateListener::SetCallback (const Link& rCallback)
      62             : {
      63           0 :     ThrowIfDisposed();
      64             : 
      65           0 :     maCallback = rCallback;
      66           0 : }
      67             : 
      68             : 
      69             : 
      70             : 
      71           0 : void SlotStateListener::ConnectToDispatchProvider (
      72             :     const uno::Reference<frame::XDispatchProvider>& rxDispatchProvider)
      73             : {
      74           0 :     ThrowIfDisposed();
      75             : 
      76             :     // When we are listening to state changes of slots of another frame then
      77             :     // release these listeners first.
      78           0 :     if ( ! maRegisteredURLList.empty())
      79           0 :         ReleaseListeners();
      80             : 
      81           0 :     mxDispatchProviderWeak = rxDispatchProvider;
      82           0 : }
      83             : 
      84             : 
      85             : 
      86             : 
      87           0 : void SlotStateListener::ObserveSlot (const ::rtl::OUString& rSlotName)
      88             : {
      89           0 :     ThrowIfDisposed();
      90             : 
      91           0 :     if (maCallback.IsSet())
      92             :     {
      93             :         // Connect the state change listener.
      94           0 :         util::URL aURL (MakeURL(rSlotName));
      95           0 :         uno::Reference<frame::XDispatch> xDispatch (GetDispatch(aURL));
      96           0 :         if (xDispatch.is())
      97             :         {
      98           0 :             maRegisteredURLList.push_back(aURL);
      99           0 :             xDispatch->addStatusListener(this,aURL);
     100           0 :         }
     101             :     }
     102           0 : }
     103             : 
     104             : 
     105             : 
     106             : 
     107           0 : void SlotStateListener::disposing (void)
     108             : {
     109           0 :     ReleaseListeners();
     110           0 :     mxDispatchProviderWeak = uno::WeakReference<frame::XDispatchProvider>(NULL);
     111           0 :     maCallback = Link();
     112           0 : }
     113             : 
     114             : 
     115             : 
     116             : 
     117           0 : util::URL SlotStateListener::MakeURL (const OUString& rSlotName) const
     118             : {
     119           0 :     util::URL aURL;
     120           0 :     aURL.Complete = rSlotName;
     121             : 
     122           0 :     uno::Reference<util::XURLTransformer> xTransformer(util::URLTransformer::create(::comphelper::getProcessComponentContext()));
     123           0 :     xTransformer->parseStrict(aURL);
     124             : 
     125           0 :     return aURL;
     126             : }
     127             : 
     128             : 
     129             : 
     130             : 
     131             : uno::Reference<frame::XDispatch>
     132           0 :     SlotStateListener::GetDispatch (const util::URL& rURL) const
     133             : {
     134           0 :     uno::Reference<frame::XDispatch> xDispatch;
     135             : 
     136           0 :     uno::Reference<frame::XDispatchProvider> xDispatchProvider (mxDispatchProviderWeak);
     137           0 :     if (xDispatchProvider.is())
     138           0 :         xDispatch = xDispatchProvider->queryDispatch(rURL, OUString(), 0);
     139             : 
     140           0 :     return xDispatch;
     141             : }
     142             : 
     143             : 
     144             : 
     145             : 
     146           0 : void SlotStateListener::statusChanged (
     147             :     const frame::FeatureStateEvent& rState)
     148             :     throw (uno::RuntimeException)
     149             : {
     150           0 :     ThrowIfDisposed();
     151           0 :     OUString sSlotName (rState.FeatureURL.Complete);
     152           0 :     if (maCallback.IsSet())
     153           0 :         maCallback.Call(&sSlotName);
     154           0 : }
     155             : 
     156             : 
     157             : 
     158             : 
     159           0 : void SlotStateListener::ReleaseListeners (void)
     160             : {
     161           0 :     if ( ! maRegisteredURLList.empty())
     162             :     {
     163           0 :         RegisteredURLList::iterator iURL (maRegisteredURLList.begin());
     164           0 :         RegisteredURLList::iterator iEnd (maRegisteredURLList.end());
     165           0 :         for (; iURL!=iEnd; ++iURL)
     166             :         {
     167           0 :             uno::Reference<frame::XDispatch> xDispatch (GetDispatch(*iURL));
     168           0 :             if (xDispatch.is())
     169             :             {
     170           0 :                 xDispatch->removeStatusListener(this,*iURL);
     171             :             }
     172           0 :         }
     173             :     }
     174           0 : }
     175             : 
     176             : 
     177             : 
     178             : 
     179             : //=====  lang::XEventListener  ================================================
     180             : 
     181           0 : void SAL_CALL SlotStateListener::disposing (
     182             :     const lang::EventObject& )
     183             :     throw (uno::RuntimeException)
     184             : {
     185           0 : }
     186             : 
     187             : 
     188             : 
     189             : 
     190           0 : void SlotStateListener::ThrowIfDisposed (void)
     191             :     throw (lang::DisposedException)
     192             : {
     193           0 :     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           0 : }
     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