LibreOffice Module framework (master) 1
interaction.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#include <com/sun/star/document/XInteractionFilterSelect.hpp>
23#include <com/sun/star/document/NoSuchFilterRequest.hpp>
24#include <utility>
25
26using namespace ::com::sun::star;
27
28namespace framework{
29
30namespace {
31
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.
37
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.
43
44 @implements XInteractionFilterSelect
45
46 @base ImplInheritanceHelper
47 ContinuationBase
48
49 @devstatus ready to use
50 @threadsafe no (used on once position only!)
51*//*-*************************************************************************************************************/
52class ContinuationFilterSelect : public comphelper::OInteraction< css::document::XInteractionFilterSelect >
53{
54 // c++ interface
55 public:
56 ContinuationFilterSelect();
57
58 // uno interface
59 public:
60 virtual void SAL_CALL setFilter( const OUString& sFilter ) override;
61 virtual OUString SAL_CALL getFilter( ) override;
62
63 // member
64 private:
65 OUString m_sFilter;
66
67}; // class ContinuationFilterSelect
68
69}
70
71// initialize continuation with right start values
72
73ContinuationFilterSelect::ContinuationFilterSelect()
74{
75}
76
77// handler should use it after selection to set user specified filter for transport
78
79void SAL_CALL ContinuationFilterSelect::setFilter( const OUString& sFilter )
80{
81 m_sFilter = sFilter;
82}
83
84// read access to transported filter
85
86OUString SAL_CALL ContinuationFilterSelect::getFilter()
87{
88 return m_sFilter;
89}
90
91class RequestFilterSelect_Impl : public ::cppu::WeakImplHelper< css::task::XInteractionRequest >
92{
93public:
94 explicit RequestFilterSelect_Impl(const OUString& rURL);
95 bool isAbort () const;
96 OUString getFilter() const;
97
98public:
99 virtual css::uno::Any SAL_CALL getRequest() override;
100 virtual css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > SAL_CALL getContinuations() override;
101
102private:
103 css::uno::Any m_aRequest;
106};
107
108// initialize instance with all necessary information
109// We use it without any further checks on our member then ...!
110
112{
113 css::uno::Reference< css::uno::XInterface > temp2;
114 css::document::NoSuchFilterRequest aFilterRequest( OUString(),
115 temp2 ,
116 sURL );
117 m_aRequest <<= aFilterRequest;
118
120 m_xFilter = new ContinuationFilterSelect;
121}
122
123// return abort state of interaction
124// If it is true, return value of method "getFilter()" will be unspecified then!
125
127{
128 return m_xAbort->wasSelected();
129}
130
131// return user selected filter
132// Return value valid for non aborted interaction only. Please check "isAbort()" before you call these only!
133
135{
136 return m_xFilter->getFilter();
137}
138
139// handler call it to get type of request
140// Is hard coded to "please select filter" here. see ctor for further information.
141
143{
144 return m_aRequest;
145}
146
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.
151
152css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > SAL_CALL RequestFilterSelect_Impl::getContinuations()
153{
154 return { m_xAbort, m_xFilter };
155}
156
157RequestFilterSelect::RequestFilterSelect( const OUString& sURL )
158 : mxImpl(new RequestFilterSelect_Impl( sURL ))
159{
160}
161
162RequestFilterSelect::~RequestFilterSelect()
163{
164}
165
166// return abort state of interaction
167// If it is true, return value of method "getFilter()" will be unspecified then!
168
169bool RequestFilterSelect::isAbort() const
170{
171 return mxImpl->isAbort();
172}
173
174// return user selected filter
175// Return value valid for non aborted interaction only. Please check "isAbort()" before you call these only!
176
177OUString RequestFilterSelect::getFilter() const
178{
179 return mxImpl->getFilter();
180}
181
182uno::Reference < task::XInteractionRequest > RequestFilterSelect::GetRequest() const
183{
184 return mxImpl;
185}
186
187namespace {
188
189class InteractionRequest_Impl : public ::cppu::WeakImplHelper< css::task::XInteractionRequest >
190{
192 uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > m_lContinuations;
193
194public:
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)
198 {
199 }
200
201 virtual uno::Any SAL_CALL getRequest() override;
202 virtual uno::Sequence< uno::Reference< task::XInteractionContinuation > > SAL_CALL getContinuations() override;
203};
204
205}
206
207uno::Any SAL_CALL InteractionRequest_Impl::getRequest()
208{
209 return m_aRequest;
210}
211
212uno::Sequence< uno::Reference< task::XInteractionContinuation > > SAL_CALL InteractionRequest_Impl::getContinuations()
213{
214 return m_lContinuations;
215}
216
217uno::Reference < task::XInteractionRequest > InteractionRequest::CreateRequest(
218 const uno::Any& aRequest, const uno::Sequence< uno::Reference< task::XInteractionContinuation > >& lContinuations )
219{
220 return new InteractionRequest_Impl( aRequest, lContinuations );
221}
222
223} // namespace framework
224
225/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static css::uno::Reference< css::task::XInteractionRequest > CreateRequest(const css::uno::Any &aRequest, const css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > &lContinuations)
virtual css::uno::Any SAL_CALL getRequest() override
rtl::Reference< ContinuationFilterSelect > m_xFilter
rtl::Reference< comphelper::OInteractionAbort > m_xAbort
RequestFilterSelect_Impl(const OUString &rURL)
virtual css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > SAL_CALL getContinuations() override
void getContinuations(css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > const &rContinuations, css::uno::Reference< t1 > *pContinuation1, css::uno::Reference< t2 > *pContinuation2)
uno::Any m_aRequest
uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > m_lContinuations
OUString m_sFilter
Definition: interaction.cxx:65
OInteraction< css::task::XInteractionAbort > OInteractionAbort