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