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

Generated by: LCOV version 1.10