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