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

Generated by: LCOV version 1.10