Update ooo320-m1
[ooovba.git] / framework / source / dispatch / oxt_handler.cxx
blob0ac770a4f760b1344c15c2abb28116ea8a5c6adc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: oxt_handler.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
33 //_________________________________________________________________________________________________________________
34 // my own includes
35 //_________________________________________________________________________________________________________________
37 #ifndef __FRAMEWORK_DISPATCH_OXT_HANDLER_HXX_
38 #include <dispatch/oxt_handler.hxx>
39 #endif
41 #ifndef __FRAMEWORK_THREADHELP_TRANSACTIONGUARD_HXX_
42 #include <threadhelp/transactionguard.hxx>
43 #endif
45 #ifndef __FRAMEWORK_THREADHELP_WRITEGUARD_HXX_
46 #include <threadhelp/writeguard.hxx>
47 #endif
49 #ifndef __FRAMEWORK_THREADHELP_READGUARD_HXX_
50 #include <threadhelp/readguard.hxx>
51 #endif
53 #ifndef __FRAMEWORK_MACROS_DEBUG_HXX_
54 #include <macros/debug.hxx>
55 #endif
57 #ifndef __FRAMEWORK_SERVICES_H_
58 #include <services.h>
59 #endif
61 #ifndef __COMPHELPER_MEDIADESCRIPTOR_HXX_
62 #include <comphelper/mediadescriptor.hxx>
63 #endif
65 //_________________________________________________________________________________________________________________
66 // interface includes
67 //_________________________________________________________________________________________________________________
69 #include <com/sun/star/io/XInputStream.hpp>
70 #include <com/sun/star/frame/DispatchResultState.hpp>
71 #include <com/sun/star/task/XJobExecutor.hpp>
73 //_________________________________________________________________________________________________________________
74 // includes of other projects
75 //_________________________________________________________________________________________________________________
77 #ifndef _COMPHELPER_SEQUENCEASHASHMAP_HXX_
78 #include <comphelper/sequenceashashmap.hxx>
79 #endif
81 #ifndef _RTL_USTRBUF_HXX_
82 #include <rtl/ustrbuf.hxx>
83 #endif
85 //_________________________________________________________________________________________________________________
86 // namespace
87 //_________________________________________________________________________________________________________________
89 namespace framework{
91 //_________________________________________________________________________________________________________________
92 // non exported const
93 //_________________________________________________________________________________________________________________
95 //_________________________________________________________________________________________________________________
96 // non exported definitions
97 //_________________________________________________________________________________________________________________
99 #define UNISTRING(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
101 //_________________________________________________________________________________________________________________
102 // declarations
103 //_________________________________________________________________________________________________________________
105 //*****************************************************************************************************************
106 // XInterface, XTypeProvider, XServiceInfo
107 //*****************************************************************************************************************
108 DEFINE_XINTERFACE_5 ( Oxt_Handler ,
109 OWeakObject ,
110 DIRECT_INTERFACE( css::lang::XTypeProvider ),
111 DIRECT_INTERFACE( css::lang::XServiceInfo ),
112 DIRECT_INTERFACE( css::frame::XNotifyingDispatch ),
113 DIRECT_INTERFACE( css::frame::XDispatch ),
114 DIRECT_INTERFACE( css::document::XExtendedFilterDetection )
117 DEFINE_XTYPEPROVIDER_5 ( Oxt_Handler ,
118 css::lang::XTypeProvider ,
119 css::lang::XServiceInfo ,
120 css::frame::XNotifyingDispatch ,
121 css::frame::XDispatch ,
122 css::document::XExtendedFilterDetection
125 DEFINE_XSERVICEINFO_MULTISERVICE ( Oxt_Handler ,
126 ::cppu::OWeakObject ,
127 SERVICENAME_CONTENTHANDLER ,
128 IMPLEMENTATIONNAME_OXT_HANDLER
131 DEFINE_INIT_SERVICE ( Oxt_Handler,
136 /*-************************************************************************************************************//**
137 @short standard ctor
138 @descr These initialize a new instance of this class with needed informations for work.
140 @seealso using at owner
142 @param "xFactory", reference to service manager for creation of new services
143 @return -
145 @onerror Show an assertion and do nothing else.
146 @threadsafe yes
147 *//*-*************************************************************************************************************/
148 Oxt_Handler::Oxt_Handler( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory )
149 // Init baseclasses first
150 : ThreadHelpBase ( )
151 , ::cppu::OWeakObject ( )
152 // Init member
153 , m_xFactory ( xFactory )
157 /*-************************************************************************************************************//**
158 @short standard dtor
159 @descr -
161 @seealso -
163 @param -
164 @return -
166 @onerror -
167 @threadsafe -
168 *//*-*************************************************************************************************************/
169 Oxt_Handler::~Oxt_Handler()
171 if ( m_xListener.is() )
173 css::frame::DispatchResultEvent aEvent;
174 aEvent.State = css::frame::DispatchResultState::FAILURE;
175 m_xListener->dispatchFinished( aEvent );
176 m_xListener = css::uno::Reference< css::frame::XDispatchResultListener >();
180 /*-************************************************************************************************************//**
181 @interface ::com::sun::star::frame::XDispatch
183 @short try to load audio file
184 @descr This method try to load given audio file by URL and play it. We use vcl/Sound class to do that.
185 Playing of sound is asynchron everytime.
187 @attention We must hold us alive by ourself ... because we use async. vcl sound player ... but playing is started
188 in async interface call "dispatch()" too. And caller forget us imediatly. But then our uno ref count
189 will decreased to 0 and will die. The only solution is to use own reference to our implementation.
190 But we do it for realy started jobs only and release it during call back of vcl.
192 @seealso class vcl/Sound
193 @seealso method implts_PlayerNotify()
195 @param "aURL" , URL to dispatch.
196 @param "lArguments", list of optional arguments.
197 @return -
199 @onerror We do nothing.
200 @threadsafe yes
201 *//*-*************************************************************************************************************/
202 void SAL_CALL Oxt_Handler::dispatchWithNotification( const css::util::URL& aURL,
203 const css::uno::Sequence< css::beans::PropertyValue >& /*lArguments*/,
204 const css::uno::Reference< css::frame::XDispatchResultListener >& xListener )
205 throw( css::uno::RuntimeException )
207 // SAFE {
208 ResetableGuard aLock( m_aLock );
210 rtl::OUString sServiceName = UNISTRING( "com.sun.star.deployment.ui.PackageManagerDialog" );
211 css::uno::Sequence< css::uno::Any > lParams(1);
212 lParams[0] <<= aURL.Main;
214 css::uno::Reference< css::uno::XInterface > xService;
216 xService = m_xFactory->createInstanceWithArguments( sServiceName, lParams );
217 css::uno::Reference< css::task::XJobExecutor > xExecuteable( xService, css::uno::UNO_QUERY );
218 if ( xExecuteable.is() )
219 xExecuteable->trigger( rtl::OUString() );
221 if ( xListener.is() )
223 css::frame::DispatchResultEvent aEvent;
224 aEvent.State = css::frame::DispatchResultState::SUCCESS;
225 xListener->dispatchFinished( aEvent );
229 // Try to initialize player.
230 m_xListener = xListener;
231 if (m_aPlayer.SetSoundName(aURL.Complete))
233 // OK- we can start async playing ...
234 // Count this request and initialize self-holder against dieing by uno ref count ...
235 m_xSelfHold = css::uno::Reference< css::uno::XInterface >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY);
236 m_aPlayer.Play();
239 // } SAFE
240 aLock.unlock();
243 void SAL_CALL Oxt_Handler::dispatch( const css::util::URL& aURL ,
244 const css::uno::Sequence< css::beans::PropertyValue >& lArguments )
245 throw( css::uno::RuntimeException )
247 dispatchWithNotification( aURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >() );
250 /*-************************************************************************************************************//**
251 @interface ::com::sun::star::document::XExtendedFilterDetection
253 @short try to detect file (given as argument included in "lDescriptor")
254 @descr We try to detect, if given file could be handled by this class and is a well known one.
255 If it is - we return right internal type name - otherwise we return nothing!
256 So call can search for another detect service and ask him too.
258 @attention a) We don't need any mutex here ... because we don't use any member!
259 b) Dont' use internal player instance "m_pPlayer" to detect given sound file!
260 It's not neccessary to do that ... and we can use temp. variable to do the same.
261 This way is easy - we don't must synchronize it with currently played sounds!
262 Another reason to do so ... We are a listener on our internal ma_Player object.
263 If you would call "IsSoundFile()" on this instance, he would call us back and
264 we make some uneccssary things ...
266 @seealso -
268 @param "lDescriptor", description of file to detect
269 @return Internal type name which match this file ... or nothing if it is unknown.
271 @onerror We return nothing.
272 @threadsafe yes
273 *//*-*************************************************************************************************************/
274 ::rtl::OUString SAL_CALL Oxt_Handler::detect( css::uno::Sequence< css::beans::PropertyValue >& lDescriptor )
275 throw( css::uno::RuntimeException )
277 // Our default is "nothing". So we can return it, if detection failed or fily type is realy unknown.
278 ::rtl::OUString sTypeName;
280 // Analyze given descriptor to find filename or input stream or ...
281 ::comphelper::MediaDescriptor aDescriptor( lDescriptor );
282 ::rtl::OUString sURL = aDescriptor.getUnpackedValueOrDefault( ::comphelper::MediaDescriptor::PROP_URL(), ::rtl::OUString() );
284 long nLength = sURL.getLength();
285 if ( ( nLength > 4 ) && sURL.matchIgnoreAsciiCase( UNISTRING(".oxt"), nLength-4 ) )
287 // "IsSoundFile" idffer between different "wav" and "au" file versions ...
288 // couldn't return this information ... because: He use the OS to detect it!
289 // I think we can the following ones:
290 // a) look for given extension of url to map our type decision HARD CODED!!!
291 // b) return preferred type every time... it's easy :-)
292 sTypeName = ::rtl::OUString::createFromAscii("oxt_OpenOffice_Extension");
293 aDescriptor[::comphelper::MediaDescriptor::PROP_TYPENAME()] <<= sTypeName;
294 aDescriptor >> lDescriptor;
297 // Return our decision.
298 return sTypeName;
301 } // namespace framework