tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / framework / source / fwe / dispatch / interaction.cxx
blobd0cf88e6f6f817bf6ceda45a3ff7baedf83fd2f4
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 <comphelper/interaction.hxx>
21 #include <framework/interaction.hxx>
22 #include <com/sun/star/document/XInteractionFilterSelect.hpp>
23 #include <com/sun/star/document/NoSuchFilterRequest.hpp>
24 #include <utility>
26 using namespace ::com::sun::star;
28 namespace framework{
30 namespace {
32 /*-************************************************************************************************************
33 @short declaration of special continuation for filter selection
34 @descr Sometimes filter detection during loading document failed. Then we need a possibility
35 to ask user for his decision. These continuation transport selected filter by user to
36 code user of interaction.
38 @attention This implementation could be used one times only. We don't support a resettable continuation yet!
39 Why? Normally interaction should show a filter selection dialog and ask user for his decision.
40 He can select any filter - then instances of these class will be called by handler... or user
41 close dialog without any selection. Then another continuation should be selected by handler to
42 abort continuations... Retrying isn't very useful here... I think.
44 @implements XInteractionFilterSelect
46 @base ImplInheritanceHelper
47 ContinuationBase
49 @devstatus ready to use
50 @threadsafe no (used on once position only!)
51 *//*-*************************************************************************************************************/
52 class ContinuationFilterSelect : public comphelper::OInteraction< css::document::XInteractionFilterSelect >
54 // c++ interface
55 public:
56 ContinuationFilterSelect();
58 // uno interface
59 public:
60 virtual void SAL_CALL setFilter( const OUString& sFilter ) override;
61 virtual OUString SAL_CALL getFilter( ) override;
63 // member
64 private:
65 OUString m_sFilter;
67 }; // class ContinuationFilterSelect
71 // initialize continuation with right start values
73 ContinuationFilterSelect::ContinuationFilterSelect()
77 // handler should use it after selection to set user specified filter for transport
79 void SAL_CALL ContinuationFilterSelect::setFilter( const OUString& sFilter )
81 m_sFilter = sFilter;
84 // read access to transported filter
86 OUString SAL_CALL ContinuationFilterSelect::getFilter()
88 return m_sFilter;
91 class RequestFilterSelect_Impl : public ::cppu::WeakImplHelper< css::task::XInteractionRequest >
93 public:
94 explicit RequestFilterSelect_Impl(const OUString& rURL);
95 bool isAbort () const;
96 OUString getFilter() const;
98 public:
99 virtual css::uno::Any SAL_CALL getRequest() override;
100 virtual css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > SAL_CALL getContinuations() override;
102 private:
103 css::uno::Any m_aRequest;
104 rtl::Reference<comphelper::OInteractionAbort> m_xAbort;
105 rtl::Reference<ContinuationFilterSelect> m_xFilter;
108 // initialize instance with all necessary information
109 // We use it without any further checks on our member then ...!
111 RequestFilterSelect_Impl::RequestFilterSelect_Impl( const OUString& sURL )
113 css::uno::Reference< css::uno::XInterface > temp2;
114 css::document::NoSuchFilterRequest aFilterRequest( OUString(),
115 temp2 ,
116 sURL );
117 m_aRequest <<= aFilterRequest;
119 m_xAbort = new comphelper::OInteractionAbort;
120 m_xFilter = new ContinuationFilterSelect;
123 // return abort state of interaction
124 // If it is true, return value of method "getFilter()" will be unspecified then!
126 bool RequestFilterSelect_Impl::isAbort() const
128 return m_xAbort->wasSelected();
131 // return user selected filter
132 // Return value valid for non aborted interaction only. Please check "isAbort()" before you call these only!
134 OUString RequestFilterSelect_Impl::getFilter() const
136 return m_xFilter->getFilter();
139 // handler call it to get type of request
140 // Is hard coded to "please select filter" here. see ctor for further information.
142 css::uno::Any SAL_CALL RequestFilterSelect_Impl::getRequest()
144 return m_aRequest;
147 // handler call it to get possible continuations
148 // We support "abort/select_filter" only here.
149 // After interaction we support read access on these continuations on our c++ interface to
150 // return user decision.
152 css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > SAL_CALL RequestFilterSelect_Impl::getContinuations()
154 return { m_xAbort, m_xFilter };
157 RequestFilterSelect::RequestFilterSelect( const OUString& sURL )
158 : mxImpl(new RequestFilterSelect_Impl( sURL ))
162 RequestFilterSelect::~RequestFilterSelect()
166 // return abort state of interaction
167 // If it is true, return value of method "getFilter()" will be unspecified then!
169 bool RequestFilterSelect::isAbort() const
171 return mxImpl->isAbort();
174 // return user selected filter
175 // Return value valid for non aborted interaction only. Please check "isAbort()" before you call these only!
177 OUString RequestFilterSelect::getFilter() const
179 return mxImpl->getFilter();
182 uno::Reference < task::XInteractionRequest > RequestFilterSelect::GetRequest() const
184 return mxImpl;
187 namespace {
189 class InteractionRequest_Impl : public ::cppu::WeakImplHelper< css::task::XInteractionRequest >
191 uno::Any m_aRequest;
192 uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > m_lContinuations;
194 public:
195 InteractionRequest_Impl( css::uno::Any aRequest,
196 const css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > >& lContinuations )
197 : m_aRequest(std::move(aRequest)), m_lContinuations(lContinuations)
201 virtual uno::Any SAL_CALL getRequest() override;
202 virtual uno::Sequence< uno::Reference< task::XInteractionContinuation > > SAL_CALL getContinuations() override;
207 uno::Any SAL_CALL InteractionRequest_Impl::getRequest()
209 return m_aRequest;
212 uno::Sequence< uno::Reference< task::XInteractionContinuation > > SAL_CALL InteractionRequest_Impl::getContinuations()
214 return m_lContinuations;
217 uno::Reference < task::XInteractionRequest > InteractionRequest::CreateRequest(
218 const uno::Any& aRequest, const uno::Sequence< uno::Reference< task::XInteractionContinuation > >& lContinuations )
220 return new InteractionRequest_Impl( aRequest, lContinuations );
223 } // namespace framework
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */