1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #ifndef INCLUDED_UCBHELPER_INTERACTIONREQUEST_HXX
21 #define INCLUDED_UCBHELPER_INTERACTIONREQUEST_HXX
23 #include <config_options.h>
24 #include <com/sun/star/lang/XTypeProvider.hpp>
25 #include <com/sun/star/task/XInteractionRequest.hpp>
26 #include <com/sun/star/task/XInteractionAbort.hpp>
27 #include <com/sun/star/task/XInteractionRetry.hpp>
28 #include <com/sun/star/task/XInteractionApprove.hpp>
29 #include <com/sun/star/task/XInteractionDisapprove.hpp>
30 #include <com/sun/star/ucb/XInteractionAuthFallback.hpp>
31 #include <com/sun/star/ucb/XInteractionReplaceExistingData.hpp>
32 #include <com/sun/star/ucb/XInteractionSupplyAuthentication2.hpp>
33 #include <cppuhelper/implbase.hxx>
34 #include <ucbhelper/ucbhelperdllapi.h>
37 namespace rtl
{ template <class reference_type
> class Reference
; }
41 class InteractionContinuation
;
44 struct InteractionRequest_Impl
;
47 * This class implements the interface XInteractionRequest. Instances can
48 * be passed directly to XInteractionHandler::handle(...). Each interaction
49 * request contains an exception describing the error and a number of
50 * interaction continuations describing the possible "answers" for the request.
51 * After the request was passed to XInteractionHandler::handle(...) the method
52 * getSelection() returns the continuation chosen by the interaction handler.
54 * The typical usage of this class would be:
56 * 1) Create exception object that shall be handled by the interaction handler.
57 * 2) Create InteractionRequest, supply exception as ctor parameter
58 * 3) Create continuations needed and add them to a sequence
59 * 4) Supply the continuations to the InteractionRequest by calling
60 * setContinuations(...)
62 * This class can also be used as base class for more specialized requests,
63 * like authentication requests.
65 class UCBHELPER_DLLPUBLIC InteractionRequest
:
66 public cppu::WeakImplHelper
<css::task::XInteractionRequest
>
68 std::unique_ptr
<InteractionRequest_Impl
> m_pImpl
;
71 void setRequest( const css::uno::Any
& rRequest
);
74 virtual ~InteractionRequest() override
;
80 * @param rRequest is the exception describing the error.
82 InteractionRequest( const css::uno::Any
& rRequest
);
85 * This method sets the continuations for the request.
87 * @param rContinuations contains the possible continuations.
89 void setContinuations(
90 const css::uno::Sequence
< css::uno::Reference
< css::task::XInteractionContinuation
> > & rContinuations
);
92 // XInteractionRequest
93 virtual css::uno::Any SAL_CALL
94 getRequest() override
;
95 virtual css::uno::Sequence
< css::uno::Reference
< css::task::XInteractionContinuation
> > SAL_CALL
96 getContinuations() override
;
98 // Non-interface methods.
101 * After passing this request to XInteractionHandler::handle, this method
102 * returns the continuation that was chosen by the interaction handler.
104 * @return the continuation chosen by an interaction handler or an empty
105 * reference, if the request was not (yet) handled.
107 rtl::Reference
< InteractionContinuation
> const & getSelection() const;
110 * This method sets a continuation for the request. It also can be used
111 * to reset the continuation set by a previous XInteractionHandler::handle
112 * call in order to use this request object more than once.
114 * @param rxSelection is the interaction continuation to activate for
115 * the request or an empty reference in order to reset the
120 const rtl::Reference
< InteractionContinuation
> & rxSelection
);
125 * This class is the base for implementations of the interface
126 * XInteractionContinuation. Classes derived from this bas class work together
127 * with class InteractionRequest.
129 * Derived classes must implement their XInteractionContinuation::select()
130 * method the way that they simply call recordSelection() which is provided by
133 class UNLESS_MERGELIBS(UCBHELPER_DLLPUBLIC
) InteractionContinuation
: public cppu::WeakImplHelper
<>
135 InteractionRequest
* m_pRequest
;
139 * This method marks this continuation as "selected" at the request it
142 * Derived classes must implement their XInteractionContinuation::select()
143 * method the way that they call this method.
145 void recordSelection();
146 virtual ~InteractionContinuation() override
;
149 InteractionContinuation( InteractionRequest
* pRequest
);
153 using InteractionAbort_BASE
= cppu::ImplInheritanceHelper
<InteractionContinuation
,
154 css::task::XInteractionAbort
>;
156 * This class implements a standard interaction continuation, namely the
157 * interface XInteractionAbort. Instances of this class can be passed
158 * along with an interaction request to indicate the possibility to abort
159 * the operation that caused the request.
161 class UNLESS_MERGELIBS(UCBHELPER_DLLPUBLIC
) InteractionAbort final
: public InteractionAbort_BASE
164 InteractionAbort( InteractionRequest
* pRequest
)
165 : InteractionAbort_BASE( pRequest
) {}
167 // XInteractionContinuation
168 virtual void SAL_CALL
select() override
;
172 using InteractionRetry_BASE
= cppu::ImplInheritanceHelper
<InteractionContinuation
,
173 css::task::XInteractionRetry
>;
175 * This class implements a standard interaction continuation, namely the
176 * interface XInteractionRetry. Instances of this class can be passed
177 * along with an interaction request to indicate the possibility to retry
178 * the operation that caused the request.
180 class UNLESS_MERGELIBS(UCBHELPER_DLLPUBLIC
) InteractionRetry final
: public InteractionRetry_BASE
183 InteractionRetry( InteractionRequest
* pRequest
)
184 : InteractionRetry_BASE( pRequest
) {}
186 // XInteractionContinuation
187 virtual void SAL_CALL
select() override
;
191 using InteractionApprove_BASE
= cppu::ImplInheritanceHelper
<InteractionContinuation
,
192 css::task::XInteractionApprove
>;
194 * This class implements a standard interaction continuation, namely the
195 * interface XInteractionApprove. Instances of this class can be passed
196 * along with an interaction request to indicate the possibility to approve
199 class UCBHELPER_DLLPUBLIC InteractionApprove final
: public InteractionApprove_BASE
202 InteractionApprove( InteractionRequest
* pRequest
)
203 : InteractionApprove_BASE( pRequest
) {}
205 // XInteractionContinuation
206 virtual void SAL_CALL
select() override
;
210 using InteractionDisapprove_BASE
= cppu::ImplInheritanceHelper
<InteractionContinuation
,
211 css::task::XInteractionDisapprove
>;
213 * This class implements a standard interaction continuation, namely the
214 * interface XInteractionDisapprove. Instances of this class can be passed
215 * along with an interaction request to indicate the possibility to disapprove
218 class UCBHELPER_DLLPUBLIC InteractionDisapprove final
: public InteractionDisapprove_BASE
221 InteractionDisapprove( InteractionRequest
* pRequest
)
222 : InteractionDisapprove_BASE( pRequest
) {}
224 // XInteractionContinuation
225 virtual void SAL_CALL
select() override
;
229 using InteractionSupplyAuthentication_BASE
= cppu::ImplInheritanceHelper
<InteractionContinuation
,
230 css::ucb::XInteractionSupplyAuthentication2
>;
232 * This class implements a standard interaction continuation, namely the
233 * interface XInteractionSupplyAuthentication. Instances of this class can be
234 * passed along with an authentication interaction request to enable the
235 * interaction handler to supply the missing authentication data.
237 class UCBHELPER_DLLPUBLIC InteractionSupplyAuthentication final
:
238 public InteractionSupplyAuthentication_BASE
240 css::uno::Sequence
< css::ucb::RememberAuthentication
>
241 m_aRememberPasswordModes
;
242 css::uno::Sequence
< css::ucb::RememberAuthentication
>
243 m_aRememberAccountModes
;
245 OUString m_aUserName
;
246 OUString m_aPassword
;
247 css::ucb::RememberAuthentication m_eRememberPasswordMode
;
248 css::ucb::RememberAuthentication m_eDefaultRememberPasswordMode
;
249 css::ucb::RememberAuthentication m_eDefaultRememberAccountMode
;
250 bool m_bCanSetRealm
: 1;
251 bool m_bCanSetUserName
: 1;
252 bool m_bCanSetPassword
: 1;
253 bool m_bCanSetAccount
: 1;
254 bool m_bCanUseSystemCredentials
: 1;
255 bool m_bUseSystemCredentials
: 1;
261 * Note: The remember-authentication stuff is interesting only for
262 * clients implementing own password storage functionality.
264 * @param rxRequest is the interaction request that owns this continuation.
265 * @param bCanSetRealm indicates, whether the realm given with the
266 * authentication request is read-only.
267 * @param bCanSetUserName indicates, whether the username given with the
268 * authentication request is read-only.
269 * @param bCanSetPassword indicates, whether the password given with the
270 * authentication request is read-only.
271 * @param bCanSetAccount indicates, whether the account given with the
272 * authentication request is read-only.
273 * @param rRememberPasswordModes specifies the authentication-remember-
274 * modes for passwords supported by the requesting client.
275 * @param eDefaultRememberPasswordMode specifies the default
276 * authentication-remember-mode for passwords preferred by the
278 * @param rRememberAccountModes specifies the authentication-remember-
279 * modes for accounts supported by the requesting client.
280 * @param eDefaultRememberAccountMode specifies the default
281 * authentication-remember-mode for accounts preferred by the
283 * @param bCanUseSystemCredentials indicates whether issuer of the
284 * authentication request can obtain and use system credentials
285 * for authentication.
287 * @see css::ucb::AuthenticationRequest
288 * @see css::ucb::RememberAuthentication
290 inline InteractionSupplyAuthentication(
291 InteractionRequest
* pRequest
,
293 bool bCanSetUserName
,
294 bool bCanSetPassword
,
296 const css::uno::Sequence
< css::ucb::RememberAuthentication
> & rRememberPasswordModes
,
297 const css::ucb::RememberAuthentication eDefaultRememberPasswordMode
,
298 const css::uno::Sequence
< css::ucb::RememberAuthentication
> & rRememberAccountModes
,
299 const css::ucb::RememberAuthentication eDefaultRememberAccountMode
,
300 bool bCanUseSystemCredentials
);
302 // XInteractionContinuation
303 virtual void SAL_CALL
select() override
;
305 // XInteractionSupplyAuthentication
306 virtual sal_Bool SAL_CALL
307 canSetRealm() override
;
308 virtual void SAL_CALL
309 setRealm( const OUString
& Realm
) override
;
311 virtual sal_Bool SAL_CALL
312 canSetUserName() override
;
313 virtual void SAL_CALL
314 setUserName( const OUString
& UserName
) override
;
316 virtual sal_Bool SAL_CALL
317 canSetPassword() override
;
318 virtual void SAL_CALL
319 setPassword( const OUString
& Password
) override
;
321 virtual css::uno::Sequence
<
322 css::ucb::RememberAuthentication
> SAL_CALL
323 getRememberPasswordModes(
324 css::ucb::RememberAuthentication
& Default
) override
;
325 virtual void SAL_CALL
326 setRememberPassword( css::ucb::RememberAuthentication Remember
) override
;
328 virtual sal_Bool SAL_CALL
329 canSetAccount() override
;
330 virtual void SAL_CALL
331 setAccount( const OUString
& Account
) override
;
333 virtual css::uno::Sequence
< css::ucb::RememberAuthentication
> SAL_CALL
334 getRememberAccountModes(
335 css::ucb::RememberAuthentication
& Default
) override
;
336 virtual void SAL_CALL
337 setRememberAccount( css::ucb::RememberAuthentication Remember
) override
;
339 // XInteractionSupplyAuthentication2
340 virtual sal_Bool SAL_CALL
canUseSystemCredentials( sal_Bool
& Default
) override
;
341 virtual void SAL_CALL
setUseSystemCredentials( sal_Bool UseSystemCredentials
) override
;
343 // Non-interface methods.
346 * This method returns the realm that was supplied by the interaction
351 const OUString
& getRealm() const { return m_aRealm
; }
354 * This method returns the username that was supplied by the interaction
357 * @return the username.
359 const OUString
& getUserName() const { return m_aUserName
; }
362 * This method returns the password that was supplied by the interaction
365 * @return the password.
367 const OUString
& getPassword() const { return m_aPassword
; }
370 * This method returns the authentication remember-mode for the password
371 * that was supplied by the interaction handler.
373 * @return the remember-mode for the password.
375 const css::ucb::RememberAuthentication
&
376 getRememberPasswordMode() const { return m_eRememberPasswordMode
; }
378 bool getUseSystemCredentials() const { return m_bUseSystemCredentials
; }
383 inline InteractionSupplyAuthentication::InteractionSupplyAuthentication(
384 InteractionRequest
* pRequest
,
386 bool bCanSetUserName
,
387 bool bCanSetPassword
,
389 const css::uno::Sequence
< css::ucb::RememberAuthentication
> & rRememberPasswordModes
,
390 const css::ucb::RememberAuthentication eDefaultRememberPasswordMode
,
391 const css::uno::Sequence
< css::ucb::RememberAuthentication
> & rRememberAccountModes
,
392 const css::ucb::RememberAuthentication eDefaultRememberAccountMode
,
393 bool bCanUseSystemCredentials
)
394 : InteractionSupplyAuthentication_BASE( pRequest
),
395 m_aRememberPasswordModes( rRememberPasswordModes
),
396 m_aRememberAccountModes( rRememberAccountModes
),
397 m_eRememberPasswordMode( eDefaultRememberPasswordMode
),
398 m_eDefaultRememberPasswordMode( eDefaultRememberPasswordMode
),
399 m_eDefaultRememberAccountMode( eDefaultRememberAccountMode
),
400 m_bCanSetRealm( bCanSetRealm
),
401 m_bCanSetUserName( bCanSetUserName
),
402 m_bCanSetPassword( bCanSetPassword
),
403 m_bCanSetAccount( bCanSetAccount
),
404 m_bCanUseSystemCredentials( bCanUseSystemCredentials
),
405 m_bUseSystemCredentials( false )
410 using InteractionReplaceExistingData_BASE
= cppu::ImplInheritanceHelper
<InteractionContinuation
,
411 css::ucb::XInteractionReplaceExistingData
>;
413 * This class implements a standard interaction continuation, namely the
414 * interface XInteractionReplaceExistingData. Instances of this class can be
415 * passed along with an interaction request to indicate the possibility to
416 * replace existing data.
418 class InteractionReplaceExistingData final
:
419 public InteractionReplaceExistingData_BASE
422 InteractionReplaceExistingData( InteractionRequest
* pRequest
)
423 : InteractionReplaceExistingData_BASE( pRequest
) {}
425 // XInteractionContinuation
426 virtual void SAL_CALL
select() override
;
429 using InteractionAuthFallback_BASE
= cppu::ImplInheritanceHelper
<InteractionContinuation
,
430 css::ucb::XInteractionAuthFallback
>;
431 class UCBHELPER_DLLPUBLIC InteractionAuthFallback final
:
432 public InteractionAuthFallback_BASE
437 InteractionAuthFallback( InteractionRequest
* pRequest
)
438 : InteractionAuthFallback_BASE( pRequest
) {}
440 // XInteractionContinuation
441 virtual void SAL_CALL
select() override
;
444 virtual void SAL_CALL
setCode( const OUString
& code
) override
;
445 /// @throws css::uno::RuntimeException
446 const OUString
& getCode() const;
450 } // namespace ucbhelper
452 #endif /* ! INCLUDED_UCBHELPER_INTERACTIONREQUEST_HXX */
454 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */