LibreOffice Module framework (master) 1
mailtodispatcher.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
21#include <services.h>
22
23#include <com/sun/star/lang/IllegalArgumentException.hpp>
24#include <com/sun/star/system/SystemShellExecute.hpp>
25#include <com/sun/star/system/SystemShellExecuteException.hpp>
26#include <com/sun/star/system/SystemShellExecuteFlags.hpp>
27#include <com/sun/star/frame/DispatchResultState.hpp>
29#include <utility>
30
31namespace framework{
32
33// XInterface, XTypeProvider, XServiceInfo
34
36{
37 return "com.sun.star.comp.framework.MailToDispatcher";
38}
39
40sal_Bool SAL_CALL MailToDispatcher::supportsService( const OUString& sServiceName )
41{
43}
44
45css::uno::Sequence< OUString > SAL_CALL MailToDispatcher::getSupportedServiceNames()
46{
48}
49
50
58MailToDispatcher::MailToDispatcher( css::uno::Reference< css::uno::XComponentContext > xContext )
59 : m_xContext (std::move( xContext ))
60{
61}
62
67{
68}
69
79css::uno::Reference< css::frame::XDispatch > SAL_CALL MailToDispatcher::queryDispatch( const css::util::URL& aURL ,
80 const OUString& /*sTarget*/ ,
81 sal_Int32 /*nFlags*/ )
82{
83 css::uno::Reference< css::frame::XDispatch > xDispatcher;
84 if (aURL.Complete.startsWith("mailto:"))
85 xDispatcher = this;
86 return xDispatcher;
87}
88
92css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL MailToDispatcher::queryDispatches( const css::uno::Sequence< css::frame::DispatchDescriptor >& lDescriptor )
93{
94 sal_Int32 nCount = lDescriptor.getLength();
95 css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > lDispatcher( nCount );
96 auto lDispatcherRange = asNonConstRange(lDispatcher);
97 for( sal_Int32 i=0; i<nCount; ++i )
98 {
99 lDispatcherRange[i] = queryDispatch(
100 lDescriptor[i].FeatureURL,
101 lDescriptor[i].FrameName,
102 lDescriptor[i].SearchFlags);
103 }
104 return lDispatcher;
105}
106
118void SAL_CALL MailToDispatcher::dispatch( const css::util::URL& aURL ,
119 const css::uno::Sequence< css::beans::PropertyValue >& /*lArguments*/ )
120{
121 // dispatch() is an [oneway] call ... and may our user release his reference to us immediately.
122 // So we should hold us self alive till this call ends.
123 css::uno::Reference< css::frame::XNotifyingDispatch > xSelfHold(this);
125 // No notification for status listener!
126}
127
140void SAL_CALL MailToDispatcher::dispatchWithNotification( const css::util::URL& aURL ,
141 const css::uno::Sequence< css::beans::PropertyValue >& /*lArguments*/,
142 const css::uno::Reference< css::frame::XDispatchResultListener >& xListener )
143{
144 // This class was designed to die by reference. And if user release his reference to us immediately after calling this method
145 // we can run into some problems. So we hold us self alive till this method ends.
146 // Another reason: We can use this reference as source of sending event at the end too.
147 css::uno::Reference< css::frame::XNotifyingDispatch > xThis(this);
148
149 bool bState = implts_dispatch(aURL);
150 if (xListener.is())
151 {
152 css::frame::DispatchResultEvent aEvent;
153 if (bState)
154 aEvent.State = css::frame::DispatchResultState::SUCCESS;
155 else
156 aEvent.State = css::frame::DispatchResultState::FAILURE;
157 aEvent.Source = xThis;
158
159 xListener->dispatchFinished( aEvent );
160 }
161}
162
177bool MailToDispatcher::implts_dispatch( const css::util::URL& aURL )
178{
179 bool bSuccess = false;
180
181 css::uno::Reference< css::system::XSystemShellExecute > xSystemShellExecute = css::system::SystemShellExecute::create( m_xContext );
182
183 try
184 {
185 // start mail client
186 // Because there is no notification about success - we use case of
187 // no detected exception as SUCCESS - FAILED otherwise.
188 xSystemShellExecute->execute( aURL.Complete, OUString(), css::system::SystemShellExecuteFlags::URIS_ONLY );
189 bSuccess = true;
190 }
191 catch (const css::lang::IllegalArgumentException&)
192 {
193 }
194 catch (const css::system::SystemShellExecuteException&)
195 {
196 }
197
198 return bSuccess;
199}
200
212void SAL_CALL MailToDispatcher::addStatusListener( const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/ ,
213 const css::util::URL& /*aURL*/ )
214{
215 // not supported yet
216}
217
218void SAL_CALL MailToDispatcher::removeStatusListener( const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/ ,
219 const css::util::URL& /*aURL*/ )
220{
221 // not supported yet
222}
223
224} // namespace framework
225
226extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
228 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& )
229{
230 return cppu::acquire(new framework::MailToDispatcher(context));
231}
232
233/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr OUStringLiteral sServiceName
AnyEventRef aEvent
protocol handler for "mailto:" URLs @descr It's a special dispatch object which is used registered fo...
MailToDispatcher(css::uno::Reference< css::uno::XComponentContext > xContext)
standard ctor @descr This initializes a new instance of this class with needed information for work.
virtual void SAL_CALL removeStatusListener(const css::uno::Reference< css::frame::XStatusListener > &xListener, const css::util::URL &aURL) override
virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch(const css::util::URL &aURL, const OUString &sTarget, sal_Int32 nFlags) override
decide if this dispatch implementation can be used for requested URL or not @descr A protocol handler...
bool implts_dispatch(const css::util::URL &aURL)
threadsafe helper for dispatch calls @descr We support two interfaces for the same process - dispatch...
virtual void SAL_CALL addStatusListener(const css::uno::Reference< css::frame::XStatusListener > &xListener, const css::util::URL &aURL) override
add/remove listener for state events @descr Because we use an external process to forward such mail U...
virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches(const css::uno::Sequence< css::frame::DispatchDescriptor > &lDescriptor) override
do the same like dispatch() but for multiple requests at the same time
css::uno::Reference< css::uno::XComponentContext > m_xContext
reference to global uno service manager which had created us
virtual void SAL_CALL dispatch(const css::util::URL &aURL, const css::uno::Sequence< css::beans::PropertyValue > &lArguments) override
dispatch URL with arguments @descr We use threadsafe internal method to do so.
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
dispatch with guaranteed notifications about success @descr We use threadsafe internal method to do s...
virtual ~MailToDispatcher() override
standard dtor
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual sal_Bool SAL_CALL supportsService(const OUString &sServiceName) override
virtual OUString SAL_CALL getImplementationName() override
int nCount
URL aURL
css::uno::Reference< css::uno::XComponentContext > m_xContext
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * framework_MailToDispatcher_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
constexpr OUStringLiteral SERVICENAME_PROTOCOLHANDLER
Definition: services.h:32
int i
unsigned char sal_Bool