tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / framework / source / dispatch / oxt_handler.cxx
blob7d38224e43293c796986882b96a88c2cb7dabea3
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 <unotools/mediadescriptor.hxx>
23 #include <com/sun/star/frame/DispatchResultState.hpp>
24 #include <com/sun/star/task/XJobExecutor.hpp>
25 #include <cppuhelper/supportsservice.hxx>
26 #include <tools/long.hxx>
27 #include <utility>
29 namespace framework{
31 // XInterface, XTypeProvider, XServiceInfo
33 OUString SAL_CALL Oxt_Handler::getImplementationName()
35 return u"com.sun.star.comp.framework.OXTFileHandler"_ustr;
38 sal_Bool SAL_CALL Oxt_Handler::supportsService( const OUString& sServiceName )
40 return cppu::supportsService(this, sServiceName);
43 css::uno::Sequence< OUString > SAL_CALL Oxt_Handler::getSupportedServiceNames()
45 return { u"com.sun.star.frame.ContentHandler"_ustr };
49 /*-************************************************************************************************************
50 @short standard ctor
51 @descr These initialize a new instance of this class with needed information for work.
53 @seealso using at owner
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 *//*-*************************************************************************************************************/
59 Oxt_Handler::Oxt_Handler( css::uno::Reference< css::uno::XComponentContext > xContext )
60 : m_xContext (std::move( xContext ))
64 /*-************************************************************************************************************
65 @short standard dtor
66 *//*-*************************************************************************************************************/
67 Oxt_Handler::~Oxt_Handler()
71 /*-************************************************************************************************************
72 @interface css::frame::XDispatch
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.
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.
83 @seealso class vcl/Sound
84 @seealso method implts_PlayerNotify()
86 @param "aURL" , URL to dispatch.
87 @param "lArguments", list of optional arguments.
88 @onerror We do nothing.
89 @threadsafe yes
90 *//*-*************************************************************************************************************/
91 void 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 )
95 std::unique_lock g(m_mutex);
97 css::uno::Sequence< css::uno::Any > lParams{ css::uno::Any(aURL.Main) };
99 css::uno::Reference< css::uno::XInterface > xService = m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext( u"com.sun.star.deployment.ui.PackageManagerDialog"_ustr, lParams, m_xContext );
100 css::uno::Reference< css::task::XJobExecutor > xExecutable( xService, css::uno::UNO_QUERY );
101 if ( xExecutable.is() )
102 xExecutable->trigger( OUString() );
104 if ( xListener.is() )
106 css::frame::DispatchResultEvent aEvent;
107 aEvent.State = css::frame::DispatchResultState::SUCCESS;
108 xListener->dispatchFinished( aEvent );
112 void SAL_CALL Oxt_Handler::dispatch( const css::util::URL& aURL ,
113 const css::uno::Sequence< css::beans::PropertyValue >& lArguments )
115 dispatchWithNotification( aURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >() );
118 /*-************************************************************************************************************
119 @interface css::document::XExtendedFilterDetection
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.
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.
136 @onerror We return nothing.
137 @threadsafe yes
138 *//*-*************************************************************************************************************/
139 OUString SAL_CALL Oxt_Handler::detect( css::uno::Sequence< css::beans::PropertyValue >& lDescriptor )
141 // Our default is "nothing". So we can return it, if detection failed or file type is really unknown.
142 OUString sTypeName;
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() );
148 tools::Long nLength = sURL.getLength();
149 if ( ( nLength > 4 ) && sURL.matchIgnoreAsciiCase( ".oxt", nLength-4 ) )
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;
161 // Return our decision.
162 return sTypeName;
165 } // namespace framework
168 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
169 framework_Oxt_Handler_get_implementation(
170 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& )
172 return cppu::acquire(new framework::Oxt_Handler(context));
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */