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 .
21 #include <comphelper/docpasswordrequest.hxx>
22 #include <com/sun/star/task/DocumentMSPasswordRequest2.hpp>
23 #include <com/sun/star/task/DocumentPasswordRequest2.hpp>
24 #include <com/sun/star/task/PasswordRequest.hpp>
25 #include <com/sun/star/task/XInteractionAbort.hpp>
26 #include <com/sun/star/task/XInteractionPassword2.hpp>
28 using ::com::sun::star::uno::Any
;
29 using ::com::sun::star::uno::Type
;
30 using ::com::sun::star::uno::Reference
;
31 using ::com::sun::star::uno::RuntimeException
;
32 using ::com::sun::star::uno::Sequence
;
33 using ::com::sun::star::uno::XInterface
;
34 using ::com::sun::star::task::InteractionClassification_QUERY
;
35 using ::com::sun::star::task::DocumentMSPasswordRequest2
;
36 using ::com::sun::star::task::DocumentPasswordRequest2
;
37 using ::com::sun::star::task::PasswordRequest
;
38 using ::com::sun::star::task::PasswordRequestMode
;
39 using ::com::sun::star::task::XInteractionAbort
;
40 using ::com::sun::star::task::XInteractionContinuation
;
41 using ::com::sun::star::task::XInteractionPassword2
;
42 using ::com::sun::star::task::XInteractionRequest
;
44 namespace comphelper
{
48 class AbortContinuation
: public ::cppu::WeakImplHelper1
< XInteractionAbort
>
51 virtual void SAL_CALL
select() throw( RuntimeException
, std::exception
) SAL_OVERRIDE
{}
56 class PasswordContinuation
: public ::cppu::WeakImplHelper1
< XInteractionPassword2
>
59 inline explicit PasswordContinuation() : mbReadOnly( false ), mbSelected( false ) {}
61 inline bool isSelected() const { return mbSelected
; }
63 virtual void SAL_CALL
select() throw( RuntimeException
, std::exception
) SAL_OVERRIDE
{ mbSelected
= true; }
65 virtual void SAL_CALL
setPassword( const OUString
& rPass
) throw( RuntimeException
, std::exception
) SAL_OVERRIDE
{ maPassword
= rPass
; }
66 virtual OUString SAL_CALL
getPassword() throw( RuntimeException
, std::exception
) SAL_OVERRIDE
{ return maPassword
; }
68 virtual void SAL_CALL
setPasswordToModify( const OUString
& rPass
) throw( RuntimeException
, std::exception
) SAL_OVERRIDE
{ maModifyPassword
= rPass
; }
69 virtual OUString SAL_CALL
getPasswordToModify() throw( RuntimeException
, std::exception
) SAL_OVERRIDE
{ return maModifyPassword
; }
71 virtual void SAL_CALL
setRecommendReadOnly( sal_Bool bReadOnly
) throw( RuntimeException
, std::exception
) SAL_OVERRIDE
{ mbReadOnly
= bReadOnly
; }
72 virtual sal_Bool SAL_CALL
getRecommendReadOnly() throw( RuntimeException
, std::exception
) SAL_OVERRIDE
{ return mbReadOnly
; }
76 OUString maModifyPassword
;
83 SimplePasswordRequest::SimplePasswordRequest( PasswordRequestMode eMode
)
85 PasswordRequest
aRequest( OUString(), Reference
< XInterface
>(),
86 InteractionClassification_QUERY
, eMode
);
87 maRequest
<<= aRequest
;
89 maContinuations
.realloc( 2 );
90 maContinuations
[ 0 ].set( new AbortContinuation
);
91 mpPassword
= new PasswordContinuation
;
92 maContinuations
[ 1 ].set( mpPassword
);
95 SimplePasswordRequest::~SimplePasswordRequest()
99 bool SimplePasswordRequest::isPassword() const
101 return mpPassword
->isSelected();
104 OUString
SimplePasswordRequest::getPassword() const
106 return mpPassword
->getPassword();
109 Any SAL_CALL
SimplePasswordRequest::getRequest() throw( RuntimeException
, std::exception
)
114 Sequence
< Reference
< XInteractionContinuation
> > SAL_CALL
SimplePasswordRequest::getContinuations() throw( RuntimeException
, std::exception
)
116 return maContinuations
;
121 DocPasswordRequest::DocPasswordRequest( DocPasswordRequestType eType
,
122 PasswordRequestMode eMode
, const OUString
& rDocumentName
, bool bPasswordToModify
)
126 case DocPasswordRequestType_STANDARD
:
128 DocumentPasswordRequest2
aRequest( OUString(), Reference
< XInterface
>(),
129 InteractionClassification_QUERY
, eMode
, rDocumentName
, bPasswordToModify
);
130 maRequest
<<= aRequest
;
133 case DocPasswordRequestType_MS
:
135 DocumentMSPasswordRequest2
aRequest( OUString(), Reference
< XInterface
>(),
136 InteractionClassification_QUERY
, eMode
, rDocumentName
, bPasswordToModify
);
137 maRequest
<<= aRequest
;
140 /* no 'default', so compilers will complain about missing
141 implementation of a new enum value. */
144 maContinuations
.realloc( 2 );
145 maContinuations
[ 0 ].set( new AbortContinuation
);
146 mpPassword
= new PasswordContinuation
;
147 maContinuations
[ 1 ].set( mpPassword
);
150 DocPasswordRequest::~DocPasswordRequest()
154 bool DocPasswordRequest::isPassword() const
156 return mpPassword
->isSelected();
159 OUString
DocPasswordRequest::getPassword() const
161 return mpPassword
->getPassword();
164 OUString
DocPasswordRequest::getPasswordToModify() const
166 return mpPassword
->getPasswordToModify();
169 bool DocPasswordRequest::getRecommendReadOnly() const
171 return mpPassword
->getRecommendReadOnly();
174 Any SAL_CALL
DocPasswordRequest::getRequest() throw( RuntimeException
, std::exception
)
179 Sequence
< Reference
< XInteractionContinuation
> > SAL_CALL
DocPasswordRequest::getContinuations() throw( RuntimeException
, std::exception
)
181 return maContinuations
;
186 } // namespace comphelper
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */