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 <com/sun/star/lang/XTypeProvider.hpp>
24 #include <com/sun/star/task/XInteractionRequest.hpp>
25 #include <com/sun/star/task/XInteractionAbort.hpp>
26 #include <com/sun/star/task/XInteractionRetry.hpp>
27 #include <com/sun/star/task/XInteractionApprove.hpp>
28 #include <com/sun/star/task/XInteractionDisapprove.hpp>
29 #include <com/sun/star/ucb/XInteractionAuthFallback.hpp>
30 #include <com/sun/star/ucb/XInteractionReplaceExistingData.hpp>
31 #include <com/sun/star/ucb/XInteractionSupplyAuthentication2.hpp>
32 #include <rtl/ref.hxx>
33 #include <cppuhelper/weak.hxx>
34 #include <ucbhelper/ucbhelperdllapi.h>
39 class InteractionContinuation
;
42 struct InteractionRequest_Impl
;
45 * This class implements the interface XInteractionRequest. Instances can
46 * be passed directly to XInteractionHandler::handle(...). Each interaction
47 * request contains an exception describing the error and a number of
48 * interaction continuations describing the possible "answers" for the request.
49 * After the request was passed to XInteractionHandler::handle(...) the method
50 * getSelection() returns the continuation chosen by the interaction handler.
52 * The typical usage of this class would be:
54 * 1) Create exception object that shall be handled by the interaction handler.
55 * 2) Create InteractionRequest, supply exception as ctor parameter
56 * 3) Create continuations needed and add them to a sequence
57 * 4) Supply the continuations to the InteractionRequest by calling
58 * setContinuations(...)
60 * This class can also be used as base class for more specialized requests,
61 * like authentication requests.
63 class UCBHELPER_DLLPUBLIC InteractionRequest
: public cppu::OWeakObject
,
64 public css::lang::XTypeProvider
,
65 public css::task::XInteractionRequest
67 std::unique_ptr
<InteractionRequest_Impl
> m_pImpl
;
70 void setRequest( const css::uno::Any
& rRequest
);
73 virtual ~InteractionRequest() override
;
79 * @param rRequest is the exception describing the error.
81 InteractionRequest( const css::uno::Any
& rRequest
);
84 * This method sets the continuations for the request.
86 * @param rContinuations contains the possible continuations.
88 void setContinuations(
89 const css::uno::Sequence
< css::uno::Reference
< css::task::XInteractionContinuation
> > & rContinuations
);
92 virtual css::uno::Any SAL_CALL
93 queryInterface( const css::uno::Type
& rType
) override
;
94 virtual void SAL_CALL
acquire()
96 virtual void SAL_CALL
release()
100 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
102 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
103 getImplementationId() override
;
105 // XInteractionRequest
106 virtual css::uno::Any SAL_CALL
107 getRequest() override
;
108 virtual css::uno::Sequence
< css::uno::Reference
< css::task::XInteractionContinuation
> > SAL_CALL
109 getContinuations() override
;
111 // Non-interface methods.
114 * After passing this request to XInteractionHandler::handle, this method
115 * returns the continuation that was chosen by the interaction handler.
117 * @return the continuation chosen by an interaction handler or an empty
118 * reference, if the request was not (yet) handled.
120 rtl::Reference
< InteractionContinuation
> const & getSelection() const;
123 * This method sets a continuation for the request. It also can be used
124 * to reset the continuation set by a previous XInteractionHandler::handle
125 * call in order to use this request object more than once.
127 * @param rxSelection is the interaction continuation to activate for
128 * the request or an empty reference in order to reset the
133 const rtl::Reference
< InteractionContinuation
> & rxSelection
);
138 * This class is the base for implementations of the interface
139 * XInteractionContinuation. Classes derived from this bas class work together
140 * with class InteractionRequest.
142 * Derived classes must implement their XInteractionContinuation::select()
143 * method the way that they simply call recordSelection() which is provided by
146 class UCBHELPER_DLLPUBLIC InteractionContinuation
: public cppu::OWeakObject
148 InteractionRequest
* m_pRequest
;
152 * This method marks this continuation as "selected" at the request it
155 * Derived classes must implement their XInteractionContinuation::select()
156 * method the way that they call this method.
158 void recordSelection();
159 virtual ~InteractionContinuation() override
;
162 InteractionContinuation( InteractionRequest
* pRequest
);
167 * This class implements a standard interaction continuation, namely the
168 * interface XInteractionAbort. Instances of this class can be passed
169 * along with an interaction request to indicate the possibility to abort
170 * the operation that caused the request.
172 class UCBHELPER_DLLPUBLIC InteractionAbort
: public InteractionContinuation
,
173 public css::lang::XTypeProvider
,
174 public css::task::XInteractionAbort
177 InteractionAbort( InteractionRequest
* pRequest
)
178 : InteractionContinuation( pRequest
) {}
181 virtual css::uno::Any SAL_CALL
182 queryInterface( const css::uno::Type
& rType
) override
;
183 virtual void SAL_CALL
acquire()
185 virtual void SAL_CALL
release()
189 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
191 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
192 getImplementationId() override
;
194 // XInteractionContinuation
195 virtual void SAL_CALL
select() override
;
200 * This class implements a standard interaction continuation, namely the
201 * interface XInteractionRetry. Instances of this class can be passed
202 * along with an interaction request to indicate the possibility to retry
203 * the operation that caused the request.
205 class UCBHELPER_DLLPUBLIC InteractionRetry
: public InteractionContinuation
,
206 public css::lang::XTypeProvider
,
207 public css::task::XInteractionRetry
210 InteractionRetry( InteractionRequest
* pRequest
)
211 : InteractionContinuation( pRequest
) {}
214 virtual css::uno::Any SAL_CALL
215 queryInterface( const css::uno::Type
& rType
) override
;
216 virtual void SAL_CALL
acquire()
218 virtual void SAL_CALL
release()
222 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
224 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
225 getImplementationId() override
;
227 // XInteractionContinuation
228 virtual void SAL_CALL
select() override
;
233 * This class implements a standard interaction continuation, namely the
234 * interface XInteractionApprove. Instances of this class can be passed
235 * along with an interaction request to indicate the possibility to approve
238 class UCBHELPER_DLLPUBLIC InteractionApprove
: public InteractionContinuation
,
239 public css::lang::XTypeProvider
,
240 public css::task::XInteractionApprove
243 InteractionApprove( InteractionRequest
* pRequest
)
244 : InteractionContinuation( pRequest
) {}
247 virtual css::uno::Any SAL_CALL
248 queryInterface( const css::uno::Type
& rType
) override
;
249 virtual void SAL_CALL
acquire()
251 virtual void SAL_CALL
release()
255 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
257 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
258 getImplementationId() override
;
260 // XInteractionContinuation
261 virtual void SAL_CALL
select() override
;
266 * This class implements a standard interaction continuation, namely the
267 * interface XInteractionDisapprove. Instances of this class can be passed
268 * along with an interaction request to indicate the possibility to disapprove
271 class UCBHELPER_DLLPUBLIC InteractionDisapprove
: public InteractionContinuation
,
272 public css::lang::XTypeProvider
,
273 public css::task::XInteractionDisapprove
276 InteractionDisapprove( InteractionRequest
* pRequest
)
277 : InteractionContinuation( pRequest
) {}
280 virtual css::uno::Any SAL_CALL
281 queryInterface( const css::uno::Type
& rType
) override
;
282 virtual void SAL_CALL
acquire()
284 virtual void SAL_CALL
release()
288 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
290 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
291 getImplementationId() override
;
293 // XInteractionContinuation
294 virtual void SAL_CALL
select() override
;
299 * This class implements a standard interaction continuation, namely the
300 * interface XInteractionSupplyAuthentication. Instances of this class can be
301 * passed along with an authentication interaction request to enable the
302 * interaction handler to supply the missing authentication data.
304 class UCBHELPER_DLLPUBLIC InteractionSupplyAuthentication
:
305 public InteractionContinuation
,
306 public css::lang::XTypeProvider
,
307 public css::ucb::XInteractionSupplyAuthentication2
309 css::uno::Sequence
< css::ucb::RememberAuthentication
>
310 m_aRememberPasswordModes
;
311 css::uno::Sequence
< css::ucb::RememberAuthentication
>
312 m_aRememberAccountModes
;
314 OUString m_aUserName
;
315 OUString m_aPassword
;
317 css::ucb::RememberAuthentication m_eRememberPasswordMode
;
318 css::ucb::RememberAuthentication m_eDefaultRememberPasswordMode
;
319 css::ucb::RememberAuthentication m_eRememberAccountMode
;
320 css::ucb::RememberAuthentication m_eDefaultRememberAccountMode
;
321 bool m_bCanSetRealm
: 1;
322 bool m_bCanSetUserName
: 1;
323 bool m_bCanSetPassword
: 1;
324 bool m_bCanSetAccount
: 1;
325 bool m_bCanUseSystemCredentials
: 1;
326 bool m_bUseSystemCredentials
: 1;
332 * Note: The remember-authentication stuff is interesting only for
333 * clients implementing own password storage functionality.
335 * @param rxRequest is the interaction request that owns this continuation.
336 * @param bCanSetRealm indicates, whether the realm given with the
337 * authentication request is read-only.
338 * @param bCanSetUserName indicates, whether the username given with the
339 * authentication request is read-only.
340 * @param bCanSetPassword indicates, whether the password given with the
341 * authentication request is read-only.
342 * @param bCanSetAccount indicates, whether the account given with the
343 * authentication request is read-only.
344 * @param rRememberPasswordModes specifies the authentication-remember-
345 * modes for passwords supported by the requesting client.
346 * @param eDefaultRememberPasswordMode specifies the default
347 * authentication-remember-mode for passwords preferred by the
349 * @param rRememberAccountModes specifies the authentication-remember-
350 * modes for accounts supported by the requesting client.
351 * @param eDefaultRememberAccountMode specifies the default
352 * authentication-remember-mode for accounts preferred by the
354 * @param bCanUseSystemCredentials indicates whether issuer of the
355 * authentication request can obtain and use system credentials
356 * for authentication.
358 * @see css::ucb::AuthenticationRequest
359 * @see css::ucb::RememberAuthentication
361 inline InteractionSupplyAuthentication(
362 InteractionRequest
* pRequest
,
364 bool bCanSetUserName
,
365 bool bCanSetPassword
,
367 const css::uno::Sequence
< css::ucb::RememberAuthentication
> & rRememberPasswordModes
,
368 const css::ucb::RememberAuthentication eDefaultRememberPasswordMode
,
369 const css::uno::Sequence
< css::ucb::RememberAuthentication
> & rRememberAccountModes
,
370 const css::ucb::RememberAuthentication eDefaultRememberAccountMode
,
371 bool bCanUseSystemCredentials
);
374 virtual css::uno::Any SAL_CALL
375 queryInterface( const css::uno::Type
& rType
) override
;
376 virtual void SAL_CALL
acquire()
378 virtual void SAL_CALL
release()
382 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
384 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
385 getImplementationId() override
;
387 // XInteractionContinuation
388 virtual void SAL_CALL
select() override
;
390 // XInteractionSupplyAuthentication
391 virtual sal_Bool SAL_CALL
392 canSetRealm() override
;
393 virtual void SAL_CALL
394 setRealm( const OUString
& Realm
) override
;
396 virtual sal_Bool SAL_CALL
397 canSetUserName() override
;
398 virtual void SAL_CALL
399 setUserName( const OUString
& UserName
) override
;
401 virtual sal_Bool SAL_CALL
402 canSetPassword() override
;
403 virtual void SAL_CALL
404 setPassword( const OUString
& Password
) override
;
406 virtual css::uno::Sequence
<
407 css::ucb::RememberAuthentication
> SAL_CALL
408 getRememberPasswordModes(
409 css::ucb::RememberAuthentication
& Default
) override
;
410 virtual void SAL_CALL
411 setRememberPassword( css::ucb::RememberAuthentication Remember
) override
;
413 virtual sal_Bool SAL_CALL
414 canSetAccount() override
;
415 virtual void SAL_CALL
416 setAccount( const OUString
& Account
) override
;
418 virtual css::uno::Sequence
< css::ucb::RememberAuthentication
> SAL_CALL
419 getRememberAccountModes(
420 css::ucb::RememberAuthentication
& Default
) override
;
421 virtual void SAL_CALL
422 setRememberAccount( css::ucb::RememberAuthentication Remember
) override
;
424 // XInteractionSupplyAuthentication2
425 virtual sal_Bool SAL_CALL
canUseSystemCredentials( sal_Bool
& Default
) override
;
426 virtual void SAL_CALL
setUseSystemCredentials( sal_Bool UseSystemCredentials
) override
;
428 // Non-interface methods.
431 * This method returns the realm that was supplied by the interaction
436 const OUString
& getRealm() const { return m_aRealm
; }
439 * This method returns the username that was supplied by the interaction
442 * @return the username.
444 const OUString
& getUserName() const { return m_aUserName
; }
447 * This method returns the password that was supplied by the interaction
450 * @return the password.
452 const OUString
& getPassword() const { return m_aPassword
; }
455 * This method returns the authentication remember-mode for the password
456 * that was supplied by the interaction handler.
458 * @return the remember-mode for the password.
460 const css::ucb::RememberAuthentication
&
461 getRememberPasswordMode() const { return m_eRememberPasswordMode
; }
463 bool getUseSystemCredentials() const { return m_bUseSystemCredentials
; }
468 inline InteractionSupplyAuthentication::InteractionSupplyAuthentication(
469 InteractionRequest
* pRequest
,
471 bool bCanSetUserName
,
472 bool bCanSetPassword
,
474 const css::uno::Sequence
< css::ucb::RememberAuthentication
> & rRememberPasswordModes
,
475 const css::ucb::RememberAuthentication eDefaultRememberPasswordMode
,
476 const css::uno::Sequence
< css::ucb::RememberAuthentication
> & rRememberAccountModes
,
477 const css::ucb::RememberAuthentication eDefaultRememberAccountMode
,
478 bool bCanUseSystemCredentials
)
479 : InteractionContinuation( pRequest
),
480 m_aRememberPasswordModes( rRememberPasswordModes
),
481 m_aRememberAccountModes( rRememberAccountModes
),
482 m_eRememberPasswordMode( eDefaultRememberPasswordMode
),
483 m_eDefaultRememberPasswordMode( eDefaultRememberPasswordMode
),
484 m_eRememberAccountMode( eDefaultRememberAccountMode
),
485 m_eDefaultRememberAccountMode( eDefaultRememberAccountMode
),
486 m_bCanSetRealm( bCanSetRealm
),
487 m_bCanSetUserName( bCanSetUserName
),
488 m_bCanSetPassword( bCanSetPassword
),
489 m_bCanSetAccount( bCanSetAccount
),
490 m_bCanUseSystemCredentials( bCanUseSystemCredentials
),
491 m_bUseSystemCredentials( false )
497 * This class implements a standard interaction continuation, namely the
498 * interface XInteractionReplaceExistingData. Instances of this class can be
499 * passed along with an interaction request to indicate the possibility to
500 * replace existing data.
502 class InteractionReplaceExistingData
:
503 public InteractionContinuation
,
504 public css::lang::XTypeProvider
,
505 public css::ucb::XInteractionReplaceExistingData
508 InteractionReplaceExistingData( InteractionRequest
* pRequest
)
509 : InteractionContinuation( pRequest
) {}
512 virtual css::uno::Any SAL_CALL
513 queryInterface( const css::uno::Type
& rType
) override
;
514 virtual void SAL_CALL
acquire()
516 virtual void SAL_CALL
release()
520 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
522 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
523 getImplementationId() override
;
525 // XInteractionContinuation
526 virtual void SAL_CALL
select() override
;
529 class UCBHELPER_DLLPUBLIC InteractionAuthFallback
:
530 public InteractionContinuation
,
531 public css::ucb::XInteractionAuthFallback
536 InteractionAuthFallback( InteractionRequest
* pRequest
)
537 : InteractionContinuation( pRequest
) {}
540 virtual css::uno::Any SAL_CALL
541 queryInterface( const css::uno::Type
& rType
) override
;
542 virtual void SAL_CALL
acquire()
544 virtual void SAL_CALL
release()
547 // XInteractionContinuation
548 virtual void SAL_CALL
select() override
;
551 virtual void SAL_CALL
setCode( const OUString
& code
) override
;
552 /// @throws css::uno::RuntimeException
553 const OUString
& SAL_CALL
getCode();
559 } // namespace ucbhelper
561 #endif /* ! INCLUDED_UCBHELPER_INTERACTIONREQUEST_HXX */
563 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */