LCOV - code coverage report
Current view: top level - framework/source/dispatch - oxt_handler.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 16 43 37.2 %
Date: 2012-08-25 Functions: 12 19 63.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 25 156 16.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <dispatch/oxt_handler.hxx>
      30                 :            : #include <threadhelp/transactionguard.hxx>
      31                 :            : #include <threadhelp/writeguard.hxx>
      32                 :            : #include <threadhelp/readguard.hxx>
      33                 :            : #include <macros/debug.hxx>
      34                 :            : #include <services.h>
      35                 :            : #include <comphelper/mediadescriptor.hxx>
      36                 :            : 
      37                 :            : #include <com/sun/star/io/XInputStream.hpp>
      38                 :            : #include <com/sun/star/frame/DispatchResultState.hpp>
      39                 :            : #include <com/sun/star/task/XJobExecutor.hpp>
      40                 :            : 
      41                 :            : #include <comphelper/sequenceashashmap.hxx>
      42                 :            : #include <rtl/ustrbuf.hxx>
      43                 :            : 
      44                 :            : namespace framework{
      45                 :            : 
      46                 :            : #define UNISTRING(s) rtl::OUString(s)
      47                 :            : 
      48                 :            : //*****************************************************************************************************************
      49                 :            : //  XInterface, XTypeProvider, XServiceInfo
      50                 :            : //*****************************************************************************************************************
      51 [ +  + ][ +  - ]:        138 : DEFINE_XINTERFACE_5                 (   Oxt_Handler                                                ,
      52                 :            :                                         OWeakObject                                                ,
      53                 :            :                                         DIRECT_INTERFACE( css::lang::XTypeProvider                ),
      54                 :            :                                         DIRECT_INTERFACE( css::lang::XServiceInfo                 ),
      55                 :            :                                         DIRECT_INTERFACE( css::frame::XNotifyingDispatch          ),
      56                 :            :                                         DIRECT_INTERFACE( css::frame::XDispatch                   ),
      57                 :            :                                         DIRECT_INTERFACE( css::document::XExtendedFilterDetection )
      58                 :            :                                     )
      59                 :            : 
      60 [ #  # ][ #  # ]:          0 : DEFINE_XTYPEPROVIDER_5              (   Oxt_Handler                                                ,
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      61                 :            :                                         css::lang::XTypeProvider                                   ,
      62                 :            :                                         css::lang::XServiceInfo                                    ,
      63                 :            :                                         css::frame::XNotifyingDispatch                             ,
      64                 :            :                                         css::frame::XDispatch                                      ,
      65                 :            :                                         css::document::XExtendedFilterDetection
      66                 :            :                                     )
      67                 :            : 
      68 [ +  - ][ +  - ]:         44 : DEFINE_XSERVICEINFO_MULTISERVICE    (   Oxt_Handler                                                ,
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ #  # ][ #  # ]
      69                 :            :                                         ::cppu::OWeakObject                                        ,
      70                 :            :                                         SERVICENAME_CONTENTHANDLER                                 ,
      71                 :            :                                         IMPLEMENTATIONNAME_OXT_HANDLER
      72                 :            :                                     )
      73                 :            : 
      74                 :         12 : DEFINE_INIT_SERVICE                 (   Oxt_Handler,
      75                 :            :                                         {
      76                 :            :                                         }
      77                 :            :                                     )
      78                 :            : 
      79                 :            : /*-************************************************************************************************************//**
      80                 :            :     @short      standard ctor
      81                 :            :     @descr      These initialize a new instance of this class with needed informations for work.
      82                 :            : 
      83                 :            :     @seealso    using at owner
      84                 :            : 
      85                 :            :     @param      "xFactory", reference to service manager for creation of new services
      86                 :            :     @return     -
      87                 :            : 
      88                 :            :     @onerror    Show an assertion and do nothing else.
      89                 :            :     @threadsafe yes
      90                 :            : *//*-*************************************************************************************************************/
      91                 :         12 : Oxt_Handler::Oxt_Handler( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory )
      92                 :            :         //  Init baseclasses first
      93                 :            :         :   ThreadHelpBase      (          )
      94                 :            :         ,   ::cppu::OWeakObject (          )
      95                 :            :         // Init member
      96         [ +  - ]:         12 :         ,   m_xFactory          ( xFactory )
      97                 :            : {
      98                 :         12 : }
      99                 :            : 
     100                 :            : /*-************************************************************************************************************//**
     101                 :            :     @short      standard dtor
     102                 :            :     @descr      -
     103                 :            : 
     104                 :            :     @seealso    -
     105                 :            : 
     106                 :            :     @param      -
     107                 :            :     @return     -
     108                 :            : 
     109                 :            :     @onerror    -
     110                 :            :     @threadsafe -
     111                 :            : *//*-*************************************************************************************************************/
     112 [ +  - ][ +  - ]:         12 : Oxt_Handler::~Oxt_Handler()
     113                 :            : {
     114         [ -  + ]:         12 :     if ( m_xListener.is() )
     115                 :            :     {
     116         [ #  # ]:          0 :         css::frame::DispatchResultEvent aEvent;
     117                 :          0 :         aEvent.State = css::frame::DispatchResultState::FAILURE;
     118 [ #  # ][ #  # ]:          0 :         m_xListener->dispatchFinished( aEvent );
     119 [ #  # ][ #  # ]:          0 :         m_xListener = css::uno::Reference< css::frame::XDispatchResultListener >();
     120                 :            :     }
     121         [ -  + ]:         24 : }
     122                 :            : 
     123                 :            : /*-************************************************************************************************************//**
     124                 :            :     @interface  ::com::sun::star::frame::XDispatch
     125                 :            : 
     126                 :            :     @short      try to load audio file
     127                 :            :     @descr      This method try to load given audio file by URL and play it. We use vcl/Sound class to do that.
     128                 :            :                 Playing of sound is asynchron everytime.
     129                 :            : 
     130                 :            :     @attention  We must hold us alive by ourself ... because we use async. vcl sound player ... but playing is started
     131                 :            :                 in async interface call "dispatch()" too. And caller forget us imediatly. But then our uno ref count
     132                 :            :                 will decreased to 0 and will die. The only solution is to use own reference to our implementation.
     133                 :            :                 But we do it for realy started jobs only and release it during call back of vcl.
     134                 :            : 
     135                 :            :     @seealso    class vcl/Sound
     136                 :            :     @seealso    method implts_PlayerNotify()
     137                 :            : 
     138                 :            :     @param      "aURL"      , URL to dispatch.
     139                 :            :     @param      "lArguments", list of optional arguments.
     140                 :            :     @return     -
     141                 :            : 
     142                 :            :     @onerror    We do nothing.
     143                 :            :     @threadsafe yes
     144                 :            : *//*-*************************************************************************************************************/
     145                 :          0 : void SAL_CALL Oxt_Handler::dispatchWithNotification( const css::util::URL& aURL,
     146                 :            :                                                      const css::uno::Sequence< css::beans::PropertyValue >&            /*lArguments*/,
     147                 :            :                                                      const css::uno::Reference< css::frame::XDispatchResultListener >& xListener )
     148                 :            :     throw( css::uno::RuntimeException )
     149                 :            : {
     150                 :            :     // SAFE {
     151         [ #  # ]:          0 :     ResetableGuard aLock( m_aLock );
     152                 :            : 
     153                 :          0 :     rtl::OUString sServiceName = UNISTRING( "com.sun.star.deployment.ui.PackageManagerDialog" );
     154         [ #  # ]:          0 :     css::uno::Sequence< css::uno::Any > lParams(1);
     155 [ #  # ][ #  # ]:          0 :     lParams[0] <<= aURL.Main;
     156                 :            : 
     157                 :          0 :     css::uno::Reference< css::uno::XInterface > xService;
     158                 :            : 
     159 [ #  # ][ #  # ]:          0 :     xService = m_xFactory->createInstanceWithArguments( sServiceName, lParams );
                 [ #  # ]
     160         [ #  # ]:          0 :     css::uno::Reference< css::task::XJobExecutor > xExecuteable( xService, css::uno::UNO_QUERY );
     161         [ #  # ]:          0 :     if ( xExecuteable.is() )
     162 [ #  # ][ #  # ]:          0 :         xExecuteable->trigger( rtl::OUString() );
     163                 :            : 
     164         [ #  # ]:          0 :     if ( xListener.is() )
     165                 :            :     {
     166         [ #  # ]:          0 :         css::frame::DispatchResultEvent aEvent;
     167                 :          0 :         aEvent.State = css::frame::DispatchResultState::SUCCESS;
     168 [ #  # ][ #  # ]:          0 :         xListener->dispatchFinished( aEvent );
                 [ #  # ]
     169                 :            :     }
     170                 :            : 
     171                 :            :     // } SAFE
     172 [ #  # ][ #  # ]:          0 :     aLock.unlock();
                 [ #  # ]
     173                 :          0 : }
     174                 :            : 
     175                 :          0 : void SAL_CALL Oxt_Handler::dispatch( const css::util::URL&                                  aURL       ,
     176                 :            :                                      const css::uno::Sequence< css::beans::PropertyValue >& lArguments )
     177                 :            :     throw( css::uno::RuntimeException )
     178                 :            : {
     179         [ #  # ]:          0 :     dispatchWithNotification( aURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >() );
     180                 :          0 : }
     181                 :            : 
     182                 :            : /*-************************************************************************************************************//**
     183                 :            :     @interface  ::com::sun::star::document::XExtendedFilterDetection
     184                 :            : 
     185                 :            :     @short      try to detect file (given as argument included in "lDescriptor")
     186                 :            :     @descr      We try to detect, if given file could be handled by this class and is a well known one.
     187                 :            :                 If it is - we return right internal type name - otherwise we return nothing!
     188                 :            :                 So call can search for another detect service and ask him too.
     189                 :            : 
     190                 :            :     @attention  a) We don't need any mutex here ... because we don't use any member!
     191                 :            :                 b) Dont' use internal player instance "m_pPlayer" to detect given sound file!
     192                 :            :                    It's not neccessary to do that ... and we can use temp. variable to do the same.
     193                 :            :                    This way is easy - we don't must synchronize it with currently played sounds!
     194                 :            :                    Another reason to do so ... We are a listener on our internal ma_Player object.
     195                 :            :                    If you would call "IsSoundFile()" on this instance, he would call us back and
     196                 :            :                    we make some uneccssary things ...
     197                 :            : 
     198                 :            :     @seealso    -
     199                 :            : 
     200                 :            :     @param      "lDescriptor", description of file to detect
     201                 :            :     @return     Internal type name which match this file ... or nothing if it is unknown.
     202                 :            : 
     203                 :            :     @onerror    We return nothing.
     204                 :            :     @threadsafe yes
     205                 :            : *//*-*************************************************************************************************************/
     206                 :         10 : ::rtl::OUString SAL_CALL Oxt_Handler::detect( css::uno::Sequence< css::beans::PropertyValue >& lDescriptor )
     207                 :            :     throw( css::uno::RuntimeException )
     208                 :            : {
     209                 :            :     // Our default is "nothing". So we can return it, if detection failed or fily type is realy unknown.
     210                 :         10 :     ::rtl::OUString sTypeName;
     211                 :            : 
     212                 :            :     // Analyze given descriptor to find filename or input stream or ...
     213         [ +  - ]:         10 :     ::comphelper::MediaDescriptor aDescriptor( lDescriptor );
     214 [ +  - ][ +  - ]:         10 :     ::rtl::OUString               sURL       = aDescriptor.getUnpackedValueOrDefault( ::comphelper::MediaDescriptor::PROP_URL(), ::rtl::OUString() );
     215                 :            : 
     216                 :         10 :     long nLength = sURL.getLength();
     217 [ -  + ][ +  - ]:         10 :     if ( ( nLength > 4 ) && sURL.matchIgnoreAsciiCase( UNISTRING(".oxt"), nLength-4 ) )
         [ +  - ][ -  + ]
                 [ +  - ]
     218                 :            :     {
     219                 :            :         // "IsSoundFile" idffer between different "wav" and "au" file versions ...
     220                 :            :         // couldn't return this information ... because: He use the OS to detect it!
     221                 :            :         // I think we can the following ones:
     222                 :            :         //  a) look for given extension of url to map our type decision HARD CODED!!!
     223                 :            :         //  b) return preferred type every time... it's easy :-)
     224                 :          0 :         sTypeName = ::rtl::OUString("oxt_OpenOffice_Extension");
     225 [ #  # ][ #  # ]:          0 :         aDescriptor[::comphelper::MediaDescriptor::PROP_TYPENAME()] <<= sTypeName;
                 [ #  # ]
     226         [ #  # ]:          0 :         aDescriptor >> lDescriptor;
     227                 :            :     }
     228                 :            : 
     229                 :            :     // Return our decision.
     230         [ +  - ]:         10 :     return sTypeName;
     231                 :            : }
     232                 :            : 
     233                 :            : } // namespace framework
     234                 :            : 
     235                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10