fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / dispatch / oxt_handler.cxx
blobb3e9bb3c81f9e6fec0f53b1aec67ba30e0c23d92
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <dispatch/oxt_handler.hxx>
21 #include <threadhelp/transactionguard.hxx>
22 #include <services.h>
23 #include <unotools/mediadescriptor.hxx>
25 #include <com/sun/star/io/XInputStream.hpp>
26 #include <com/sun/star/frame/DispatchResultState.hpp>
27 #include <com/sun/star/task/XJobExecutor.hpp>
29 #include <comphelper/sequenceashashmap.hxx>
30 #include <rtl/ustrbuf.hxx>
32 namespace framework{
34 // XInterface, XTypeProvider, XServiceInfo
36 DEFINE_XSERVICEINFO_MULTISERVICE ( Oxt_Handler ,
37 ::cppu::OWeakObject ,
38 SERVICENAME_CONTENTHANDLER ,
39 IMPLEMENTATIONNAME_OXT_HANDLER
42 DEFINE_INIT_SERVICE ( Oxt_Handler,
47 /*-************************************************************************************************************
48 @short standard ctor
49 @descr These initialize a new instance of this class with needed information for work.
51 @seealso using at owner
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 Oxt_Handler::Oxt_Handler( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory )
58 : m_xFactory ( xFactory )
62 /*-************************************************************************************************************
63 @short standard dtor
64 *//*-*************************************************************************************************************/
65 Oxt_Handler::~Oxt_Handler()
67 if ( m_xListener.is() )
69 css::frame::DispatchResultEvent aEvent;
70 aEvent.State = css::frame::DispatchResultState::FAILURE;
71 m_xListener->dispatchFinished( aEvent );
72 m_xListener = css::uno::Reference< css::frame::XDispatchResultListener >();
76 /*-************************************************************************************************************
77 @interface ::com::sun::star::frame::XDispatch
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.
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.
88 @seealso class vcl/Sound
89 @seealso method implts_PlayerNotify()
91 @param "aURL" , URL to dispatch.
92 @param "lArguments", list of optional arguments.
93 @onerror We do nothing.
94 @threadsafe yes
95 *//*-*************************************************************************************************************/
96 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 )
101 osl::MutexGuard g(m_mutex);
103 OUString sServiceName = "com.sun.star.deployment.ui.PackageManagerDialog";
104 css::uno::Sequence< css::uno::Any > lParams(1);
105 lParams[0] <<= aURL.Main;
107 css::uno::Reference< css::uno::XInterface > xService;
109 xService = m_xFactory->createInstanceWithArguments( sServiceName, lParams );
110 css::uno::Reference< css::task::XJobExecutor > xExecuteable( xService, css::uno::UNO_QUERY );
111 if ( xExecuteable.is() )
112 xExecuteable->trigger( OUString() );
114 if ( xListener.is() )
116 css::frame::DispatchResultEvent aEvent;
117 aEvent.State = css::frame::DispatchResultState::SUCCESS;
118 xListener->dispatchFinished( aEvent );
122 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 )
126 dispatchWithNotification( aURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >() );
129 /*-************************************************************************************************************
130 @interface ::com::sun::star::document::XExtendedFilterDetection
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.
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.
147 @onerror We return nothing.
148 @threadsafe yes
149 *//*-*************************************************************************************************************/
150 OUString SAL_CALL Oxt_Handler::detect( css::uno::Sequence< css::beans::PropertyValue >& lDescriptor )
151 throw( css::uno::RuntimeException, std::exception )
153 // Our default is "nothing". So we can return it, if detection failed or fily type is really unknown.
154 OUString sTypeName;
156 // Analyze given descriptor to find filename or input stream or ...
157 utl::MediaDescriptor aDescriptor( lDescriptor );
158 OUString sURL = aDescriptor.getUnpackedValueOrDefault( utl::MediaDescriptor::PROP_URL(), OUString() );
160 long nLength = sURL.getLength();
161 if ( ( nLength > 4 ) && sURL.matchIgnoreAsciiCase( ".oxt", nLength-4 ) )
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 sTypeName = "oxt_OpenOffice_Extension";
169 aDescriptor[utl::MediaDescriptor::PROP_TYPENAME()] <<= sTypeName;
170 aDescriptor >> lDescriptor;
173 // Return our decision.
174 return sTypeName;
177 } // namespace framework
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */