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