tdf#146173: combine non-BMP characters' surrogates correctly
[LibreOffice.git] / include / ucbhelper / interactionrequest.hxx
blob78fc31f7a23bdd896dc98984fe9a630a7311adfe
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 #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>
35 #include <memory>
37 namespace rtl { template <class reference_type> class Reference; }
39 namespace ucbhelper {
41 class InteractionContinuation;
44 struct InteractionRequest_Impl;
46 /**
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;
70 protected:
71 void setRequest( const css::uno::Any & rRequest );
73 InteractionRequest();
74 virtual ~InteractionRequest() override;
76 public:
77 /**
78 * Constructor.
80 * @param rRequest is the exception describing the error.
82 InteractionRequest( const css::uno::Any & rRequest );
84 /**
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
116 * current selection.
118 void
119 setSelection(
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
131 * this class.
133 class UCBHELPER_DLLPUBLIC InteractionContinuation : public cppu::OWeakObject
135 InteractionRequest* m_pRequest;
137 protected:
139 * This method marks this continuation as "selected" at the request it
140 * belongs to.
142 * Derived classes must implement their XInteractionContinuation::select()
143 * method the way that they call this method.
145 void recordSelection();
146 virtual ~InteractionContinuation() override;
148 public:
149 InteractionContinuation( InteractionRequest * pRequest );
154 * This class implements a standard interaction continuation, namely the
155 * interface XInteractionAbort. Instances of this class can be passed
156 * along with an interaction request to indicate the possibility to abort
157 * the operation that caused the request.
159 class UCBHELPER_DLLPUBLIC InteractionAbort final : public InteractionContinuation,
160 public css::lang::XTypeProvider,
161 public css::task::XInteractionAbort
163 public:
164 InteractionAbort( InteractionRequest * pRequest )
165 : InteractionContinuation( pRequest ) {}
167 // XInterface
168 virtual css::uno::Any SAL_CALL
169 queryInterface( const css::uno::Type & rType ) override;
170 virtual void SAL_CALL acquire() noexcept override
171 { OWeakObject::acquire(); }
172 virtual void SAL_CALL release() noexcept override
173 { OWeakObject::release(); }
175 // XTypeProvider
176 virtual css::uno::Sequence< css::uno::Type > SAL_CALL
177 getTypes() override;
178 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
179 getImplementationId() override;
181 // XInteractionContinuation
182 virtual void SAL_CALL select() override;
187 * This class implements a standard interaction continuation, namely the
188 * interface XInteractionRetry. Instances of this class can be passed
189 * along with an interaction request to indicate the possibility to retry
190 * the operation that caused the request.
192 class UCBHELPER_DLLPUBLIC InteractionRetry final : public InteractionContinuation,
193 public css::lang::XTypeProvider,
194 public css::task::XInteractionRetry
196 public:
197 InteractionRetry( InteractionRequest * pRequest )
198 : InteractionContinuation( pRequest ) {}
200 // XInterface
201 virtual css::uno::Any SAL_CALL
202 queryInterface( const css::uno::Type & rType ) override;
203 virtual void SAL_CALL acquire() noexcept override
204 { OWeakObject::acquire(); }
205 virtual void SAL_CALL release() noexcept override
206 { OWeakObject::release(); }
208 // XTypeProvider
209 virtual css::uno::Sequence< css::uno::Type > SAL_CALL
210 getTypes() override;
211 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
212 getImplementationId() override;
214 // XInteractionContinuation
215 virtual void SAL_CALL select() override;
220 * This class implements a standard interaction continuation, namely the
221 * interface XInteractionApprove. Instances of this class can be passed
222 * along with an interaction request to indicate the possibility to approve
223 * the request.
225 class UNLESS_MERGELIBS(UCBHELPER_DLLPUBLIC) InteractionApprove final : public InteractionContinuation,
226 public css::lang::XTypeProvider,
227 public css::task::XInteractionApprove
229 public:
230 InteractionApprove( InteractionRequest * pRequest )
231 : InteractionContinuation( pRequest ) {}
233 // XInterface
234 virtual css::uno::Any SAL_CALL
235 queryInterface( const css::uno::Type & rType ) override;
236 virtual void SAL_CALL acquire() noexcept override
237 { OWeakObject::acquire(); }
238 virtual void SAL_CALL release() noexcept override
239 { OWeakObject::release(); }
241 // XTypeProvider
242 virtual css::uno::Sequence< css::uno::Type > SAL_CALL
243 getTypes() override;
244 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
245 getImplementationId() override;
247 // XInteractionContinuation
248 virtual void SAL_CALL select() override;
253 * This class implements a standard interaction continuation, namely the
254 * interface XInteractionDisapprove. Instances of this class can be passed
255 * along with an interaction request to indicate the possibility to disapprove
256 * the request.
258 class UNLESS_MERGELIBS(UCBHELPER_DLLPUBLIC) InteractionDisapprove final : public InteractionContinuation,
259 public css::lang::XTypeProvider,
260 public css::task::XInteractionDisapprove
262 public:
263 InteractionDisapprove( InteractionRequest * pRequest )
264 : InteractionContinuation( pRequest ) {}
266 // XInterface
267 virtual css::uno::Any SAL_CALL
268 queryInterface( const css::uno::Type & rType ) override;
269 virtual void SAL_CALL acquire() noexcept override
270 { OWeakObject::acquire(); }
271 virtual void SAL_CALL release() noexcept override
272 { OWeakObject::release(); }
274 // XTypeProvider
275 virtual css::uno::Sequence< css::uno::Type > SAL_CALL
276 getTypes() override;
277 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
278 getImplementationId() override;
280 // XInteractionContinuation
281 virtual void SAL_CALL select() override;
286 * This class implements a standard interaction continuation, namely the
287 * interface XInteractionSupplyAuthentication. Instances of this class can be
288 * passed along with an authentication interaction request to enable the
289 * interaction handler to supply the missing authentication data.
291 class UNLESS_MERGELIBS(UCBHELPER_DLLPUBLIC) InteractionSupplyAuthentication final :
292 public InteractionContinuation,
293 public css::lang::XTypeProvider,
294 public css::ucb::XInteractionSupplyAuthentication2
296 css::uno::Sequence< css::ucb::RememberAuthentication >
297 m_aRememberPasswordModes;
298 css::uno::Sequence< css::ucb::RememberAuthentication >
299 m_aRememberAccountModes;
300 OUString m_aRealm;
301 OUString m_aUserName;
302 OUString m_aPassword;
303 css::ucb::RememberAuthentication m_eRememberPasswordMode;
304 css::ucb::RememberAuthentication m_eDefaultRememberPasswordMode;
305 css::ucb::RememberAuthentication m_eDefaultRememberAccountMode;
306 bool m_bCanSetRealm : 1;
307 bool m_bCanSetUserName : 1;
308 bool m_bCanSetPassword : 1;
309 bool m_bCanSetAccount : 1;
310 bool m_bCanUseSystemCredentials : 1;
311 bool m_bUseSystemCredentials : 1;
313 public:
315 * Constructor.
317 * Note: The remember-authentication stuff is interesting only for
318 * clients implementing own password storage functionality.
320 * @param rxRequest is the interaction request that owns this continuation.
321 * @param bCanSetRealm indicates, whether the realm given with the
322 * authentication request is read-only.
323 * @param bCanSetUserName indicates, whether the username given with the
324 * authentication request is read-only.
325 * @param bCanSetPassword indicates, whether the password given with the
326 * authentication request is read-only.
327 * @param bCanSetAccount indicates, whether the account given with the
328 * authentication request is read-only.
329 * @param rRememberPasswordModes specifies the authentication-remember-
330 * modes for passwords supported by the requesting client.
331 * @param eDefaultRememberPasswordMode specifies the default
332 * authentication-remember-mode for passwords preferred by the
333 * requesting client.
334 * @param rRememberAccountModes specifies the authentication-remember-
335 * modes for accounts supported by the requesting client.
336 * @param eDefaultRememberAccountMode specifies the default
337 * authentication-remember-mode for accounts preferred by the
338 * requesting client.
339 * @param bCanUseSystemCredentials indicates whether issuer of the
340 * authentication request can obtain and use system credentials
341 * for authentication.
343 * @see css::ucb::AuthenticationRequest
344 * @see css::ucb::RememberAuthentication
346 inline InteractionSupplyAuthentication(
347 InteractionRequest * pRequest,
348 bool bCanSetRealm,
349 bool bCanSetUserName,
350 bool bCanSetPassword,
351 bool bCanSetAccount,
352 const css::uno::Sequence< css::ucb::RememberAuthentication > & rRememberPasswordModes,
353 const css::ucb::RememberAuthentication eDefaultRememberPasswordMode,
354 const css::uno::Sequence< css::ucb::RememberAuthentication > & rRememberAccountModes,
355 const css::ucb::RememberAuthentication eDefaultRememberAccountMode,
356 bool bCanUseSystemCredentials );
358 // XInterface
359 virtual css::uno::Any SAL_CALL
360 queryInterface( const css::uno::Type & rType ) override;
361 virtual void SAL_CALL acquire() noexcept override
362 { OWeakObject::acquire(); }
363 virtual void SAL_CALL release() noexcept override
364 { OWeakObject::release(); }
366 // XTypeProvider
367 virtual css::uno::Sequence< css::uno::Type > SAL_CALL
368 getTypes() override;
369 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
370 getImplementationId() override;
372 // XInteractionContinuation
373 virtual void SAL_CALL select() override;
375 // XInteractionSupplyAuthentication
376 virtual sal_Bool SAL_CALL
377 canSetRealm() override;
378 virtual void SAL_CALL
379 setRealm( const OUString& Realm ) override;
381 virtual sal_Bool SAL_CALL
382 canSetUserName() override;
383 virtual void SAL_CALL
384 setUserName( const OUString& UserName ) override;
386 virtual sal_Bool SAL_CALL
387 canSetPassword() override;
388 virtual void SAL_CALL
389 setPassword( const OUString& Password ) override;
391 virtual css::uno::Sequence<
392 css::ucb::RememberAuthentication > SAL_CALL
393 getRememberPasswordModes(
394 css::ucb::RememberAuthentication& Default ) override;
395 virtual void SAL_CALL
396 setRememberPassword( css::ucb::RememberAuthentication Remember ) override;
398 virtual sal_Bool SAL_CALL
399 canSetAccount() override;
400 virtual void SAL_CALL
401 setAccount( const OUString& Account ) override;
403 virtual css::uno::Sequence< css::ucb::RememberAuthentication > SAL_CALL
404 getRememberAccountModes(
405 css::ucb::RememberAuthentication& Default ) override;
406 virtual void SAL_CALL
407 setRememberAccount( css::ucb::RememberAuthentication Remember ) override;
409 // XInteractionSupplyAuthentication2
410 virtual sal_Bool SAL_CALL canUseSystemCredentials( sal_Bool& Default ) override;
411 virtual void SAL_CALL setUseSystemCredentials( sal_Bool UseSystemCredentials ) override;
413 // Non-interface methods.
416 * This method returns the realm that was supplied by the interaction
417 * handler.
419 * @return the realm.
421 const OUString & getRealm() const { return m_aRealm; }
424 * This method returns the username that was supplied by the interaction
425 * handler.
427 * @return the username.
429 const OUString & getUserName() const { return m_aUserName; }
432 * This method returns the password that was supplied by the interaction
433 * handler.
435 * @return the password.
437 const OUString & getPassword() const { return m_aPassword; }
440 * This method returns the authentication remember-mode for the password
441 * that was supplied by the interaction handler.
443 * @return the remember-mode for the password.
445 const css::ucb::RememberAuthentication &
446 getRememberPasswordMode() const { return m_eRememberPasswordMode; }
448 bool getUseSystemCredentials() const { return m_bUseSystemCredentials; }
453 inline InteractionSupplyAuthentication::InteractionSupplyAuthentication(
454 InteractionRequest * pRequest,
455 bool bCanSetRealm,
456 bool bCanSetUserName,
457 bool bCanSetPassword,
458 bool bCanSetAccount,
459 const css::uno::Sequence< css::ucb::RememberAuthentication > & rRememberPasswordModes,
460 const css::ucb::RememberAuthentication eDefaultRememberPasswordMode,
461 const css::uno::Sequence< css::ucb::RememberAuthentication > & rRememberAccountModes,
462 const css::ucb::RememberAuthentication eDefaultRememberAccountMode,
463 bool bCanUseSystemCredentials )
464 : InteractionContinuation( pRequest ),
465 m_aRememberPasswordModes( rRememberPasswordModes ),
466 m_aRememberAccountModes( rRememberAccountModes ),
467 m_eRememberPasswordMode( eDefaultRememberPasswordMode ),
468 m_eDefaultRememberPasswordMode( eDefaultRememberPasswordMode ),
469 m_eDefaultRememberAccountMode( eDefaultRememberAccountMode ),
470 m_bCanSetRealm( bCanSetRealm ),
471 m_bCanSetUserName( bCanSetUserName ),
472 m_bCanSetPassword( bCanSetPassword ),
473 m_bCanSetAccount( bCanSetAccount ),
474 m_bCanUseSystemCredentials( bCanUseSystemCredentials ),
475 m_bUseSystemCredentials( false )
481 * This class implements a standard interaction continuation, namely the
482 * interface XInteractionReplaceExistingData. Instances of this class can be
483 * passed along with an interaction request to indicate the possibility to
484 * replace existing data.
486 class InteractionReplaceExistingData final :
487 public InteractionContinuation,
488 public css::lang::XTypeProvider,
489 public css::ucb::XInteractionReplaceExistingData
491 public:
492 InteractionReplaceExistingData( InteractionRequest * pRequest )
493 : InteractionContinuation( pRequest ) {}
495 // XInterface
496 virtual css::uno::Any SAL_CALL
497 queryInterface( const css::uno::Type & rType ) override;
498 virtual void SAL_CALL acquire() noexcept override
499 { OWeakObject::acquire(); }
500 virtual void SAL_CALL release() noexcept override
501 { OWeakObject::release(); }
503 // XTypeProvider
504 virtual css::uno::Sequence< css::uno::Type > SAL_CALL
505 getTypes() override;
506 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
507 getImplementationId() override;
509 // XInteractionContinuation
510 virtual void SAL_CALL select() override;
513 class UCBHELPER_DLLPUBLIC InteractionAuthFallback final :
514 public InteractionContinuation,
515 public css::ucb::XInteractionAuthFallback
517 OUString m_aCode;
519 public:
520 InteractionAuthFallback( InteractionRequest * pRequest )
521 : InteractionContinuation( pRequest ) {}
523 // XInterface
524 virtual css::uno::Any SAL_CALL
525 queryInterface( const css::uno::Type & rType ) override;
526 virtual void SAL_CALL acquire() noexcept override
527 { OWeakObject::acquire(); }
528 virtual void SAL_CALL release() noexcept override
529 { OWeakObject::release(); }
531 // XInteractionContinuation
532 virtual void SAL_CALL select() override;
534 // XAuthFallback
535 virtual void SAL_CALL setCode( const OUString& code ) override;
536 /// @throws css::uno::RuntimeException
537 const OUString& getCode() const;
543 } // namespace ucbhelper
545 #endif /* ! INCLUDED_UCBHELPER_INTERACTIONREQUEST_HXX */
547 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */