LCOV - code coverage report
Current view: top level - libreoffice/framework/source/fwe/interaction - preventduplicateinteraction.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 105 0.0 %
Date: 2012-12-27 Functions: 0 10 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 "framework/preventduplicateinteraction.hxx"
      21             : 
      22             : #include <com/sun/star/task/XInteractionAbort.hpp>
      23             : #include <com/sun/star/task/XInteractionRetry.hpp>
      24             : 
      25             : namespace framework{
      26             : 
      27             : #define IMPLEMENTATIONNAME_UIINTERACTIONHANDLER                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.uui.UUIInteractionHandler"))
      28             : 
      29           0 : PreventDuplicateInteraction::PreventDuplicateInteraction(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
      30             :     : ThreadHelpBase2()
      31           0 :     , m_xSMGR(xSMGR)
      32             : {
      33           0 : }
      34             : 
      35             : //_________________________________________________________________________________________________________________
      36             : 
      37           0 : PreventDuplicateInteraction::~PreventDuplicateInteraction()
      38             : {
      39           0 : }
      40             : 
      41             : //_________________________________________________________________________________________________________________
      42             : 
      43           0 : void PreventDuplicateInteraction::setHandler(const css::uno::Reference< css::task::XInteractionHandler >& xHandler)
      44             : {
      45             :     // SAFE ->
      46           0 :     ::osl::ResettableMutexGuard aLock(m_aLock);
      47           0 :     m_xHandler = xHandler;
      48           0 :     aLock.clear();
      49             :     // <- SAFE
      50           0 : }
      51             : 
      52             : //_________________________________________________________________________________________________________________
      53             : 
      54           0 : void PreventDuplicateInteraction::useDefaultUUIHandler()
      55             : {
      56             :     // SAFE ->
      57           0 :     ::osl::ResettableMutexGuard aLock(m_aLock);
      58           0 :     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
      59           0 :     aLock.clear();
      60             :     // <- SAFE
      61             : 
      62             :     css::uno::Reference< css::task::XInteractionHandler > xHandler(
      63           0 :                             xSMGR->createInstance(IMPLEMENTATIONNAME_UIINTERACTIONHANDLER),
      64           0 :                             css::uno::UNO_QUERY_THROW);
      65             : 
      66             :     // SAFE ->
      67           0 :     aLock.reset();
      68           0 :     m_xHandler = xHandler;
      69           0 :     aLock.clear();
      70             :     // <- SAFE
      71           0 : }
      72             : 
      73             : //_________________________________________________________________________________________________________________
      74           0 : css::uno::Any SAL_CALL PreventDuplicateInteraction::queryInterface( const css::uno::Type& aType )
      75             :     throw (css::uno::RuntimeException)
      76             : {
      77           0 :     if ( aType.equals( XInteractionHandler2::static_type() ) )
      78             :     {
      79           0 :         ::osl::ResettableMutexGuard aLock(m_aLock);
      80           0 :         css::uno::Reference< css::task::XInteractionHandler2 > xHandler( m_xHandler, css::uno::UNO_QUERY );
      81           0 :         if ( !xHandler.is() )
      82           0 :             return css::uno::Any();
      83             :     }
      84           0 :     return ::cppu::WeakImplHelper1< css::task::XInteractionHandler2 >::queryInterface( aType );
      85             : }
      86             : 
      87             : //_________________________________________________________________________________________________________________
      88             : 
      89           0 : void SAL_CALL PreventDuplicateInteraction::handle(const css::uno::Reference< css::task::XInteractionRequest >& xRequest)
      90             :     throw(css::uno::RuntimeException)
      91             : {
      92           0 :     css::uno::Any aRequest  = xRequest->getRequest();
      93           0 :     sal_Bool      bHandleIt = sal_True;
      94             : 
      95             :     // SAFE ->
      96           0 :     ::osl::ResettableMutexGuard aLock(m_aLock);
      97             : 
      98           0 :     InteractionList::iterator pIt;
      99           0 :     for (  pIt  = m_lInteractionRules.begin();
     100           0 :            pIt != m_lInteractionRules.end()  ;
     101             :          ++pIt                               )
     102             :     {
     103           0 :         InteractionInfo& rInfo = *pIt;
     104             : 
     105           0 :         if (aRequest.isExtractableTo(rInfo.m_aInteraction))
     106             :         {
     107           0 :             ++rInfo.m_nCallCount;
     108           0 :             rInfo.m_xRequest = xRequest;
     109           0 :             bHandleIt = (rInfo.m_nCallCount <= rInfo.m_nMaxCount);
     110           0 :             break;
     111             :         }
     112             :     }
     113             : 
     114           0 :     css::uno::Reference< css::task::XInteractionHandler > xHandler = m_xHandler;
     115             : 
     116           0 :     aLock.clear();
     117             :     // <- SAFE
     118             : 
     119           0 :     if (
     120             :         (bHandleIt    ) &&
     121           0 :         (xHandler.is())
     122             :        )
     123             :     {
     124           0 :         xHandler->handle(xRequest);
     125             :     }
     126             :     else
     127             :     {
     128           0 :         const css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > lContinuations = xRequest->getContinuations();
     129           0 :         sal_Int32 c = lContinuations.getLength();
     130           0 :         sal_Int32 i = 0;
     131           0 :         for (i=0; i<c; ++i)
     132             :         {
     133           0 :             css::uno::Reference< css::task::XInteractionAbort > xAbort(lContinuations[i], css::uno::UNO_QUERY);
     134           0 :             if (xAbort.is())
     135             :             {
     136           0 :                 xAbort->select();
     137             :                 break;
     138             :             }
     139           0 :         }
     140           0 :     }
     141           0 : }
     142             : 
     143             : //_________________________________________________________________________________________________________________
     144             : 
     145           0 : ::sal_Bool SAL_CALL PreventDuplicateInteraction::handleInteractionRequest( const css::uno::Reference< css::task::XInteractionRequest >& xRequest )
     146             :             throw (css::uno::RuntimeException)
     147             : {
     148           0 :     css::uno::Any aRequest  = xRequest->getRequest();
     149           0 :     sal_Bool      bHandleIt = sal_True;
     150             : 
     151             :     // SAFE ->
     152           0 :     ::osl::ResettableMutexGuard aLock(m_aLock);
     153             : 
     154           0 :     InteractionList::iterator pIt;
     155           0 :     for (  pIt  = m_lInteractionRules.begin();
     156           0 :            pIt != m_lInteractionRules.end()  ;
     157             :          ++pIt                               )
     158             :     {
     159           0 :         InteractionInfo& rInfo = *pIt;
     160             : 
     161           0 :         if (aRequest.isExtractableTo(rInfo.m_aInteraction))
     162             :         {
     163           0 :             ++rInfo.m_nCallCount;
     164           0 :             rInfo.m_xRequest = xRequest;
     165           0 :             bHandleIt = (rInfo.m_nCallCount <= rInfo.m_nMaxCount);
     166           0 :             break;
     167             :         }
     168             :     }
     169             : 
     170           0 :     css::uno::Reference< css::task::XInteractionHandler2 > xHandler( m_xHandler, css::uno::UNO_QUERY );
     171             :     OSL_ENSURE( xHandler.is() || !m_xHandler.is(),
     172             :         "PreventDuplicateInteraction::handleInteractionRequest: inconsistency!" );
     173             : 
     174           0 :     aLock.clear();
     175             :     // <- SAFE
     176             : 
     177           0 :     if (
     178             :         (bHandleIt    ) &&
     179           0 :         (xHandler.is())
     180             :        )
     181             :     {
     182           0 :         return xHandler->handleInteractionRequest(xRequest);
     183             :     }
     184             :     else
     185             :     {
     186           0 :         const css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > lContinuations = xRequest->getContinuations();
     187           0 :         sal_Int32 c = lContinuations.getLength();
     188           0 :         sal_Int32 i = 0;
     189           0 :         for (i=0; i<c; ++i)
     190             :         {
     191           0 :             css::uno::Reference< css::task::XInteractionAbort > xAbort(lContinuations[i], css::uno::UNO_QUERY);
     192           0 :             if (xAbort.is())
     193             :             {
     194           0 :                 xAbort->select();
     195             :                 break;
     196             :             }
     197           0 :         }
     198             :     }
     199           0 :     return false;
     200             : }
     201             : 
     202             : //_________________________________________________________________________________________________________________
     203             : 
     204           0 : void PreventDuplicateInteraction::addInteractionRule(const PreventDuplicateInteraction::InteractionInfo& aInteractionInfo)
     205             : {
     206             :     // SAFE ->
     207           0 :     ::osl::ResettableMutexGuard aLock(m_aLock);
     208             : 
     209           0 :     InteractionList::iterator pIt;
     210           0 :     for (  pIt  = m_lInteractionRules.begin();
     211           0 :            pIt != m_lInteractionRules.end()  ;
     212             :          ++pIt                               )
     213             :     {
     214           0 :         InteractionInfo& rInfo = *pIt;
     215           0 :         if (rInfo.m_aInteraction == aInteractionInfo.m_aInteraction)
     216             :         {
     217           0 :             rInfo.m_nMaxCount  = aInteractionInfo.m_nMaxCount ;
     218           0 :             rInfo.m_nCallCount = aInteractionInfo.m_nCallCount;
     219           0 :             return;
     220             :         }
     221             :     }
     222             : 
     223           0 :     m_lInteractionRules.push_back(aInteractionInfo);
     224             : 
     225           0 :     aLock.clear();
     226             :     // <- SAFE
     227             : }
     228             : 
     229             : //_________________________________________________________________________________________________________________
     230             : 
     231           0 : sal_Bool PreventDuplicateInteraction::getInteractionInfo(const css::uno::Type&                               aInteraction,
     232             :                                                                PreventDuplicateInteraction::InteractionInfo* pReturn     ) const
     233             : {
     234             :     // SAFE ->
     235           0 :     ::osl::ResettableMutexGuard aLock(m_aLock);
     236             : 
     237           0 :     PreventDuplicateInteraction::InteractionList::const_iterator pIt;
     238           0 :     for (  pIt  = m_lInteractionRules.begin();
     239           0 :            pIt != m_lInteractionRules.end()  ;
     240             :          ++pIt                               )
     241             :     {
     242           0 :         const PreventDuplicateInteraction::InteractionInfo& rInfo = *pIt;
     243           0 :         if (rInfo.m_aInteraction == aInteraction)
     244             :         {
     245           0 :             *pReturn = rInfo;
     246           0 :             return sal_True;
     247             :         }
     248             :     }
     249             : 
     250           0 :     aLock.clear();
     251             :     // <- SAFE
     252             : 
     253           0 :     return sal_False;
     254             : }
     255             : 
     256             : } // namespace framework
     257             : 
     258             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10