LCOV - code coverage report
Current view: top level - framework/source/fwe/dispatch - interaction.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 12 54 22.2 %
Date: 2014-11-03 Functions: 6 23 26.1 %
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 <comphelper/interaction.hxx>
      21             : #include <framework/interaction.hxx>
      22             : #include <general.h>
      23             : 
      24             : using namespace ::com::sun::star;
      25             : 
      26             : namespace framework{
      27             : 
      28             : /*-************************************************************************************************************
      29             :     @short          declaration of special continuation for filter selection
      30             :     @descr          Sometimes filter detection during loading document failed. Then we need a possibility
      31             :                     to ask user for his decision. These continuation transport selected filter by user to
      32             :                     code user of interaction.
      33             : 
      34             :     @attention      This implementation could be used one times only. We don't support a resetable continuation yet!
      35             :                     Why? Normally interaction should show a filter selection dialog and ask user for his decision.
      36             :                     He can select any filter - then instances of these class will be called by handler ... or user
      37             :                     close dialog without any selection. Then another continuation should be slected by handler to
      38             :                     abort continuations ... Retrying isn't very useful here ... I think.
      39             : 
      40             :     @implements     XInteractionFilterSelect
      41             : 
      42             :     @base           ImplInheritanceHelper1
      43             :                     ContinuationBase
      44             : 
      45             :     @devstatus      ready to use
      46             :     @threadsafe     no (used on once position only!)
      47             : *//*-*************************************************************************************************************/
      48           0 : class ContinuationFilterSelect : public comphelper::OInteraction< ::com::sun::star::document::XInteractionFilterSelect >
      49             : {
      50             :     // c++ interface
      51             :     public:
      52             :         ContinuationFilterSelect();
      53             : 
      54             :     // uno interface
      55             :     public:
      56             :         virtual void            SAL_CALL setFilter( const OUString& sFilter ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
      57             :         virtual OUString SAL_CALL getFilter(                                ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
      58             : 
      59             :     // member
      60             :     private:
      61             :         OUString m_sFilter;
      62             : 
      63             : };  // class ContinuationFilterSelect
      64             : 
      65             : // initialize continuation with right start values
      66             : 
      67           0 : ContinuationFilterSelect::ContinuationFilterSelect()
      68           0 :     : m_sFilter( OUString() )
      69             : {
      70           0 : }
      71             : 
      72             : // handler should use it after selection to set user specified filter for transport
      73             : 
      74           0 : void SAL_CALL ContinuationFilterSelect::setFilter( const OUString& sFilter ) throw( css::uno::RuntimeException, std::exception )
      75             : {
      76           0 :     m_sFilter = sFilter;
      77           0 : }
      78             : 
      79             : // read access to transported filter
      80             : 
      81           0 : OUString SAL_CALL ContinuationFilterSelect::getFilter() throw( css::uno::RuntimeException, std::exception )
      82             : {
      83           0 :     return m_sFilter;
      84             : }
      85             : 
      86           0 : class RequestFilterSelect_Impl : public ::cppu::WeakImplHelper1< ::com::sun::star::task::XInteractionRequest >
      87             : {
      88             : public:
      89             :     RequestFilterSelect_Impl( const OUString& sURL );
      90             :     bool     isAbort  () const;
      91             :     OUString getFilter() const;
      92             : 
      93             : public:
      94             :     virtual ::com::sun::star::uno::Any SAL_CALL getRequest() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
      95             :     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > > SAL_CALL getContinuations() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
      96             : 
      97             : private:
      98             :     ::com::sun::star::uno::Any                                                                                                 m_aRequest;
      99             :     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > >    m_lContinuations;
     100             :     comphelper::OInteractionAbort* m_pAbort;
     101             :     ContinuationFilterSelect* m_pFilter;
     102             : };
     103             : 
     104             : // initialize instance with all necessary information
     105             : // We use it without any further checks on our member then ...!
     106             : 
     107           0 : RequestFilterSelect_Impl::RequestFilterSelect_Impl( const OUString& sURL )
     108             : {
     109           0 :     OUString temp;
     110           0 :     css::uno::Reference< css::uno::XInterface > temp2;
     111             :     css::document::NoSuchFilterRequest aFilterRequest( temp                             ,
     112             :                                                        temp2                            ,
     113           0 :                                                        sURL                                          );
     114           0 :     m_aRequest <<= aFilterRequest;
     115             : 
     116           0 :     m_pAbort  = new comphelper::OInteractionAbort;
     117           0 :     m_pFilter = new ContinuationFilterSelect;
     118             : 
     119           0 :     m_lContinuations.realloc( 2 );
     120           0 :     m_lContinuations[0] = css::uno::Reference< css::task::XInteractionContinuation >( m_pAbort  );
     121           0 :     m_lContinuations[1] = css::uno::Reference< css::task::XInteractionContinuation >( m_pFilter );
     122           0 : }
     123             : 
     124             : // return abort state of interaction
     125             : // If it is true, return value of method "getFilter()" will be unspecified then!
     126             : 
     127           0 : bool RequestFilterSelect_Impl::isAbort() const
     128             : {
     129           0 :     return m_pAbort->wasSelected();
     130             : }
     131             : 
     132             : // return user selected filter
     133             : // Return value valid for non aborted interaction only. Please check "isAbort()" before you call these ony!
     134             : 
     135           0 : OUString RequestFilterSelect_Impl::getFilter() const
     136             : {
     137           0 :     return m_pFilter->getFilter();
     138             : }
     139             : 
     140             : // handler call it to get type of request
     141             : // Is hard coded to "please select filter" here. see ctor for further information.
     142             : 
     143           0 : css::uno::Any SAL_CALL RequestFilterSelect_Impl::getRequest() throw( css::uno::RuntimeException, std::exception )
     144             : {
     145           0 :     return m_aRequest;
     146             : }
     147             : 
     148             : // handler call it to get possible continuations
     149             : // We support "abort/select_filter" only here.
     150             : // After interaction we support read access on these continuations on our c++ interface to
     151             : // return user decision.
     152             : 
     153           0 : css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > SAL_CALL RequestFilterSelect_Impl::getContinuations() throw( css::uno::RuntimeException, std::exception )
     154             : {
     155           0 :     return m_lContinuations;
     156             : }
     157             : 
     158           0 : RequestFilterSelect::RequestFilterSelect( const OUString& sURL )
     159             : {
     160           0 :     pImp = new RequestFilterSelect_Impl( sURL );
     161           0 :     pImp->acquire();
     162           0 : }
     163             : 
     164           0 : RequestFilterSelect::~RequestFilterSelect()
     165             : {
     166           0 :     pImp->release();
     167           0 : }
     168             : 
     169             : // return abort state of interaction
     170             : // If it is true, return value of method "getFilter()" will be unspecified then!
     171             : 
     172           0 : bool RequestFilterSelect::isAbort() const
     173             : {
     174           0 :     return pImp->isAbort();
     175             : }
     176             : 
     177             : // return user selected filter
     178             : // Return value valid for non aborted interaction only. Please check "isAbort()" before you call these ony!
     179             : 
     180           0 : OUString RequestFilterSelect::getFilter() const
     181             : {
     182           0 :     return pImp->getFilter();
     183             : }
     184             : 
     185           0 : uno::Reference < task::XInteractionRequest > RequestFilterSelect::GetRequest()
     186             : {
     187           0 :     return uno::Reference < task::XInteractionRequest > (pImp);
     188             : }
     189             : 
     190         504 : class InteractionRequest_Impl : public ::cppu::WeakImplHelper1< ::com::sun::star::task::XInteractionRequest >
     191             : {
     192             :     uno::Any m_aRequest;
     193             :     uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > > m_lContinuations;
     194             : 
     195             : public:
     196         252 :     InteractionRequest_Impl( const ::com::sun::star::uno::Any& aRequest,
     197             :         const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > >& lContinuations )
     198         252 :     {
     199         252 :         m_aRequest = aRequest;
     200         252 :         m_lContinuations = lContinuations;
     201         252 :     }
     202             : 
     203             :     virtual uno::Any SAL_CALL getRequest() throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     204             :     virtual uno::Sequence< uno::Reference< task::XInteractionContinuation > > SAL_CALL getContinuations()
     205             :             throw( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     206             : };
     207             : 
     208         252 : uno::Any SAL_CALL InteractionRequest_Impl::getRequest() throw( uno::RuntimeException, std::exception )
     209             : {
     210         252 :     return m_aRequest;
     211             : }
     212             : 
     213         252 : uno::Sequence< uno::Reference< task::XInteractionContinuation > > SAL_CALL InteractionRequest_Impl::getContinuations()
     214             :     throw( uno::RuntimeException, std::exception )
     215             : {
     216         252 :     return m_lContinuations;
     217             : }
     218             : 
     219         252 : uno::Reference < task::XInteractionRequest > InteractionRequest::CreateRequest(
     220             :     const uno::Any& aRequest, const uno::Sequence< uno::Reference< task::XInteractionContinuation > >& lContinuations )
     221             : {
     222         252 :     return new InteractionRequest_Impl( aRequest, lContinuations );
     223             : }
     224             : 
     225             : }       //  namespace framework
     226             : 
     227             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10