Kaydet (Commit) 7f97b5e7 authored tarafından Noel Grandin's avatar Noel Grandin

convert CONTINUATION constants to typed_flags_set

Change-Id: I38333e5d229aa520fbe0a8ad72007c503853956e
üst 69c29c9f
...@@ -22,28 +22,31 @@ ...@@ -22,28 +22,31 @@
#include <ucbhelper/interactionrequest.hxx> #include <ucbhelper/interactionrequest.hxx>
#include <ucbhelper/ucbhelperdllapi.h> #include <ucbhelper/ucbhelperdllapi.h>
#include <o3tl/typed_flags_set.hxx>
namespace ucbhelper {
/** These are the constants that can be passed to the constructor of class /** These are the constants that can be passed to the constructor of class
* SimpleInteractionRequest and that are returned by method * SimpleInteractionRequest and that are returned by method
* SimpleInteractionRequest::getResponse(). * SimpleInteractionRequest::getResponse().
*/ */
/** The request was not (yet) handled by the interaction handler. */ enum class ContinuationFlags {
static const sal_Int32 CONTINUATION_UNKNOWN = 0; /** The request was not (yet) handled by the interaction handler. */
NONE = 0,
/** The interaction handler selected XInteractionAbort. */ /** The interaction handler selected XInteractionAbort. */
static const sal_Int32 CONTINUATION_ABORT = 1; Abort = 1,
/** The interaction handler selected XInteractionRetry. */
/** The interaction handler selected XInteractionRetry. */ Retry = 2,
static const sal_Int32 CONTINUATION_RETRY = 2; /** The interaction handler selected XInteractionApprove. */
Approve = 4,
/** The interaction handler selected XInteractionApprove. */ /** The interaction handler selected XInteractionDisapprove. */
static const sal_Int32 CONTINUATION_APPROVE = 4; Disapprove = 8,
};
namespace o3tl
{
template<> struct typed_flags<ContinuationFlags> : is_typed_flags<ContinuationFlags, 0x0f> {};
}
/** The interaction handler selected XInteractionDisapprove. */ namespace ucbhelper {
static const sal_Int32 CONTINUATION_DISAPPROVE = 8;
/** /**
* This class implements a simple interaction request. The user must not deal * This class implements a simple interaction request. The user must not deal
...@@ -71,16 +74,16 @@ public: ...@@ -71,16 +74,16 @@ public:
* listed above. * listed above.
*/ */
SimpleInteractionRequest( const css::uno::Any & rRequest, SimpleInteractionRequest( const css::uno::Any & rRequest,
const sal_Int32 nContinuations ); const ContinuationFlags nContinuations );
/** /**
* After passing this request to XInteractionHandler::handle, this method * After passing this request to XInteractionHandler::handle, this method
* returns the continuation that was chosen by the interaction handler. * returns the continuation that was chosen by the interaction handler.
* *
* @return the continuation chosen by an interaction handler or * @return the continuation chosen by an interaction handler or
* CONTINUATION_UNKNOWN, if the request was not (yet) handled. * ContinuationFlags::NONE, if the request was not (yet) handled.
*/ */
sal_Int32 getResponse() const; ContinuationFlags getResponse() const;
}; };
} // namespace ucbhelper } // namespace ucbhelper
......
...@@ -52,26 +52,14 @@ bool ScWarnPassword::WarningOnPassword( SfxMedium& rMedium ) ...@@ -52,26 +52,14 @@ bool ScWarnPassword::WarningOnPassword( SfxMedium& rMedium )
rtl::Reference< ucbhelper::SimpleInteractionRequest > xRequest rtl::Reference< ucbhelper::SimpleInteractionRequest > xRequest
= new ucbhelper::SimpleInteractionRequest( = new ucbhelper::SimpleInteractionRequest(
aException, aException,
ucbhelper::CONTINUATION_APPROVE ContinuationFlags::Approve | ContinuationFlags::Disapprove );
| ucbhelper::CONTINUATION_DISAPPROVE );
xHandler->handle( xRequest.get() ); xHandler->handle( xRequest.get() );
const sal_Int32 nResp = xRequest->getResponse(); const ContinuationFlags nResp = xRequest->getResponse();
switch ( nResp ) if ( nResp == ContinuationFlags::Disapprove )
{ bReturn = false;
case ucbhelper::CONTINUATION_UNKNOWN:
break;
case ucbhelper::CONTINUATION_APPROVE:
// Continue
break;
case ucbhelper::CONTINUATION_DISAPPROVE:
bReturn = false;
break;
}
} }
return bReturn; return bReturn;
} }
......
...@@ -2586,25 +2586,24 @@ void Content::insert( ...@@ -2586,25 +2586,24 @@ void Content::insert(
rtl::Reference< ucbhelper::SimpleInteractionRequest > xRequest rtl::Reference< ucbhelper::SimpleInteractionRequest > xRequest
= new ucbhelper::SimpleInteractionRequest( = new ucbhelper::SimpleInteractionRequest(
aExAsAny, aExAsAny,
ucbhelper::CONTINUATION_APPROVE ContinuationFlags::Approve | ContinuationFlags::Disapprove );
| ucbhelper::CONTINUATION_DISAPPROVE );
xIH->handle( xRequest.get() ); xIH->handle( xRequest.get() );
const sal_Int32 nResp = xRequest->getResponse(); const ContinuationFlags nResp = xRequest->getResponse();
switch ( nResp ) switch ( nResp )
{ {
case ucbhelper::CONTINUATION_UNKNOWN: case ContinuationFlags::NONE:
// Not handled; throw. // Not handled; throw.
throw aEx; throw aEx;
// break; // break;
case ucbhelper::CONTINUATION_APPROVE: case ContinuationFlags::Approve:
// Continue -> Overwrite. // Continue -> Overwrite.
bReplaceExisting = true; bReplaceExisting = true;
break; break;
case ucbhelper::CONTINUATION_DISAPPROVE: case ContinuationFlags::Disapprove:
// Abort. // Abort.
throw ucb::CommandFailedException( throw ucb::CommandFailedException(
OUString(), OUString(),
......
...@@ -2435,25 +2435,25 @@ void Content::insert( ...@@ -2435,25 +2435,25 @@ void Content::insert(
rtl::Reference< ucbhelper::SimpleInteractionRequest > xRequest rtl::Reference< ucbhelper::SimpleInteractionRequest > xRequest
= new ucbhelper::SimpleInteractionRequest( = new ucbhelper::SimpleInteractionRequest(
aExAsAny, aExAsAny,
ucbhelper::CONTINUATION_APPROVE ContinuationFlags::Approve
| ucbhelper::CONTINUATION_DISAPPROVE ); | ContinuationFlags::Disapprove );
xIH->handle( xRequest.get() ); xIH->handle( xRequest.get() );
const sal_Int32 nResp = xRequest->getResponse(); const sal_Int32 nResp = xRequest->getResponse();
switch ( nResp ) switch ( nResp )
{ {
case ucbhelper::CONTINUATION_UNKNOWN: case ContinuationFlags::NONE:
// Not handled; throw. // Not handled; throw.
throw aEx; throw aEx;
// break; // break;
case ucbhelper::CONTINUATION_APPROVE: case ContinuationFlags::Approve:
// Continue -> Overwrite. // Continue -> Overwrite.
bReplaceExisting = true; bReplaceExisting = true;
break; break;
case ucbhelper::CONTINUATION_DISAPPROVE: case ContinuationFlags::Disapprove:
// Abort. // Abort.
throw ucb::CommandFailedException( throw ucb::CommandFailedException(
OUString(), OUString(),
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
*/ */
#include <ucbhelper/simpleinteractionrequest.hxx> #include <ucbhelper/simpleinteractionrequest.hxx>
#include <comphelper/sequence.hxx>
#include <osl/diagnose.h> #include <osl/diagnose.h>
...@@ -27,69 +28,35 @@ using namespace ucbhelper; ...@@ -27,69 +28,35 @@ using namespace ucbhelper;
SimpleInteractionRequest::SimpleInteractionRequest( SimpleInteractionRequest::SimpleInteractionRequest(
const uno::Any & rRequest, const uno::Any & rRequest,
const sal_Int32 nContinuations ) const ContinuationFlags nContinuations )
: InteractionRequest( rRequest ) : InteractionRequest( rRequest )
{ {
// Set continuations. // Set continuations.
OSL_ENSURE( nContinuations != CONTINUATION_UNKNOWN, OSL_ENSURE( nContinuations != ContinuationFlags::NONE,
"SimpleInteractionRequest - No continuation!" ); "SimpleInteractionRequest - No continuation!" );
sal_Int32 nLength = 0; std::vector< uno::Reference< task::XInteractionContinuation > > aContinuations;
if ( nContinuations & ContinuationFlags::Abort )
uno::Reference< task::XInteractionContinuation > xAbort;
uno::Reference< task::XInteractionContinuation > xRetry;
uno::Reference< task::XInteractionContinuation > xApprove;
uno::Reference< task::XInteractionContinuation > xDisapprove;
if ( nContinuations & CONTINUATION_ABORT )
{ {
++nLength; aContinuations.push_back( new InteractionAbort( this ) );
xAbort = new InteractionAbort( this );
} }
if ( nContinuations & ContinuationFlags::Retry )
if ( nContinuations & CONTINUATION_RETRY )
{ {
++nLength; aContinuations.push_back( new InteractionRetry( this ) );
xRetry = new InteractionRetry( this );
} }
if ( nContinuations & ContinuationFlags::Approve )
if ( nContinuations & CONTINUATION_APPROVE )
{ {
++nLength; aContinuations.push_back( new InteractionApprove( this ) );
xApprove = new InteractionApprove( this );
} }
if ( nContinuations & ContinuationFlags::Disapprove )
if ( nContinuations & CONTINUATION_DISAPPROVE )
{ {
++nLength; aContinuations.push_back( new InteractionDisapprove( this ) );
xDisapprove = new InteractionDisapprove( this );
} }
setContinuations( comphelper::containerToSequence(aContinuations) );
OSL_ENSURE( nLength > 0,
"SimpleInteractionRequest - No continuation!" );
uno::Sequence< uno::Reference< task::XInteractionContinuation > >
aContinuations( nLength );
nLength = 0;
if ( xAbort.is() )
aContinuations[ nLength++ ] = xAbort;
if ( xRetry.is() )
aContinuations[ nLength++ ] = xRetry;
if ( xApprove.is() )
aContinuations[ nLength++ ] = xApprove;
if ( xDisapprove.is() )
aContinuations[ nLength++ ] = xDisapprove;
setContinuations( aContinuations );
} }
sal_Int32 SimpleInteractionRequest::getResponse() const ContinuationFlags SimpleInteractionRequest::getResponse() const
{ {
rtl::Reference< InteractionContinuation > xSelection = getSelection(); rtl::Reference< InteractionContinuation > xSelection = getSelection();
if ( xSelection.is() ) if ( xSelection.is() )
...@@ -99,26 +66,26 @@ sal_Int32 SimpleInteractionRequest::getResponse() const ...@@ -99,26 +66,26 @@ sal_Int32 SimpleInteractionRequest::getResponse() const
uno::Reference< task::XInteractionAbort > xAbort( uno::Reference< task::XInteractionAbort > xAbort(
pSelection, uno::UNO_QUERY ); pSelection, uno::UNO_QUERY );
if ( xAbort.is() ) if ( xAbort.is() )
return CONTINUATION_ABORT; return ContinuationFlags::Abort;
uno::Reference< task::XInteractionRetry > xRetry( uno::Reference< task::XInteractionRetry > xRetry(
pSelection, uno::UNO_QUERY ); pSelection, uno::UNO_QUERY );
if ( xRetry.is() ) if ( xRetry.is() )
return CONTINUATION_RETRY; return ContinuationFlags::Retry;
uno::Reference< task::XInteractionApprove > xApprove( uno::Reference< task::XInteractionApprove > xApprove(
pSelection, uno::UNO_QUERY ); pSelection, uno::UNO_QUERY );
if ( xApprove.is() ) if ( xApprove.is() )
return CONTINUATION_APPROVE; return ContinuationFlags::Approve;
uno::Reference< task::XInteractionDisapprove > xDisapprove( uno::Reference< task::XInteractionDisapprove > xDisapprove(
pSelection, uno::UNO_QUERY ); pSelection, uno::UNO_QUERY );
if ( xDisapprove.is() ) if ( xDisapprove.is() )
return CONTINUATION_DISAPPROVE; return ContinuationFlags::Disapprove;
OSL_FAIL( "SimpleInteractionRequest::getResponse - Unknown continuation!" ); OSL_FAIL( "SimpleInteractionRequest::getResponse - Unknown continuation!" );
} }
return CONTINUATION_UNKNOWN; return ContinuationFlags::NONE;
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment