1*dde7d3faSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*dde7d3faSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*dde7d3faSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*dde7d3faSAndrew Rist * distributed with this work for additional information
6*dde7d3faSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*dde7d3faSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*dde7d3faSAndrew Rist * "License"); you may not use this file except in compliance
9*dde7d3faSAndrew Rist * with the License. You may obtain a copy of the License at
10*dde7d3faSAndrew Rist *
11*dde7d3faSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*dde7d3faSAndrew Rist *
13*dde7d3faSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*dde7d3faSAndrew Rist * software distributed under the License is distributed on an
15*dde7d3faSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*dde7d3faSAndrew Rist * KIND, either express or implied. See the License for the
17*dde7d3faSAndrew Rist * specific language governing permissions and limitations
18*dde7d3faSAndrew Rist * under the License.
19*dde7d3faSAndrew Rist *
20*dde7d3faSAndrew Rist *************************************************************/
21*dde7d3faSAndrew Rist
22*dde7d3faSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_comphelper.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "comphelper/docpasswordrequest.hxx"
28cdf0e10cSrcweir #include <com/sun/star/task/DocumentMSPasswordRequest2.hpp>
29cdf0e10cSrcweir #include <com/sun/star/task/DocumentPasswordRequest2.hpp>
30cdf0e10cSrcweir #include <com/sun/star/task/PasswordRequest.hpp>
31cdf0e10cSrcweir #include <com/sun/star/task/XInteractionAbort.hpp>
32cdf0e10cSrcweir #include <com/sun/star/task/XInteractionPassword2.hpp>
33cdf0e10cSrcweir
34cdf0e10cSrcweir using ::rtl::OUString;
35cdf0e10cSrcweir using ::com::sun::star::uno::Any;
36cdf0e10cSrcweir using ::com::sun::star::uno::Type;
37cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
38cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException;
39cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
40cdf0e10cSrcweir using ::com::sun::star::uno::XInterface;
41cdf0e10cSrcweir using ::com::sun::star::task::InteractionClassification_QUERY;
42cdf0e10cSrcweir using ::com::sun::star::task::DocumentMSPasswordRequest2;
43cdf0e10cSrcweir using ::com::sun::star::task::DocumentPasswordRequest2;
44cdf0e10cSrcweir using ::com::sun::star::task::PasswordRequest;
45cdf0e10cSrcweir using ::com::sun::star::task::PasswordRequestMode;
46cdf0e10cSrcweir using ::com::sun::star::task::XInteractionAbort;
47cdf0e10cSrcweir using ::com::sun::star::task::XInteractionContinuation;
48cdf0e10cSrcweir using ::com::sun::star::task::XInteractionPassword2;
49cdf0e10cSrcweir using ::com::sun::star::task::XInteractionRequest;
50cdf0e10cSrcweir
51cdf0e10cSrcweir namespace comphelper {
52cdf0e10cSrcweir
53cdf0e10cSrcweir // ============================================================================
54cdf0e10cSrcweir
55cdf0e10cSrcweir class AbortContinuation : public ::cppu::WeakImplHelper1< XInteractionAbort >
56cdf0e10cSrcweir {
57cdf0e10cSrcweir public:
AbortContinuation()58cdf0e10cSrcweir inline explicit AbortContinuation() : mbSelected( false ) {}
59cdf0e10cSrcweir
isSelected() const60cdf0e10cSrcweir inline sal_Bool isSelected() const { return mbSelected; }
reset()61cdf0e10cSrcweir inline void reset() { mbSelected = false; }
62cdf0e10cSrcweir
select()63cdf0e10cSrcweir virtual void SAL_CALL select() throw( RuntimeException ) { mbSelected = true; }
64cdf0e10cSrcweir
65cdf0e10cSrcweir private:
66cdf0e10cSrcweir sal_Bool mbSelected;
67cdf0e10cSrcweir };
68cdf0e10cSrcweir
69cdf0e10cSrcweir // ============================================================================
70cdf0e10cSrcweir
71cdf0e10cSrcweir class PasswordContinuation : public ::cppu::WeakImplHelper1< XInteractionPassword2 >
72cdf0e10cSrcweir {
73cdf0e10cSrcweir public:
PasswordContinuation()74cdf0e10cSrcweir inline explicit PasswordContinuation() : mbReadOnly( sal_False ), mbSelected( sal_False ) {}
75cdf0e10cSrcweir
isSelected() const76cdf0e10cSrcweir inline sal_Bool isSelected() const { return mbSelected; }
reset()77cdf0e10cSrcweir inline void reset() { mbSelected = sal_False; }
78cdf0e10cSrcweir
select()79cdf0e10cSrcweir virtual void SAL_CALL select() throw( RuntimeException ) { mbSelected = sal_True; }
80cdf0e10cSrcweir
setPassword(const OUString & rPass)81cdf0e10cSrcweir virtual void SAL_CALL setPassword( const OUString& rPass ) throw( RuntimeException ) { maPassword = rPass; }
getPassword()82cdf0e10cSrcweir virtual OUString SAL_CALL getPassword() throw( RuntimeException ) { return maPassword; }
83cdf0e10cSrcweir
setPasswordToModify(const OUString & rPass)84cdf0e10cSrcweir virtual void SAL_CALL setPasswordToModify( const OUString& rPass ) throw( RuntimeException ) { maModifyPassword = rPass; }
getPasswordToModify()85cdf0e10cSrcweir virtual OUString SAL_CALL getPasswordToModify() throw( RuntimeException ) { return maModifyPassword; }
86cdf0e10cSrcweir
setRecommendReadOnly(sal_Bool bReadOnly)87cdf0e10cSrcweir virtual void SAL_CALL setRecommendReadOnly( sal_Bool bReadOnly ) throw( RuntimeException ) { mbReadOnly = bReadOnly; }
getRecommendReadOnly()88cdf0e10cSrcweir virtual sal_Bool SAL_CALL getRecommendReadOnly() throw( RuntimeException ) { return mbReadOnly; }
89cdf0e10cSrcweir
90cdf0e10cSrcweir private:
91cdf0e10cSrcweir OUString maPassword;
92cdf0e10cSrcweir OUString maModifyPassword;
93cdf0e10cSrcweir sal_Bool mbReadOnly;
94cdf0e10cSrcweir sal_Bool mbSelected;
95cdf0e10cSrcweir };
96cdf0e10cSrcweir
97cdf0e10cSrcweir // ============================================================================
98cdf0e10cSrcweir
SimplePasswordRequest(PasswordRequestMode eMode)99cdf0e10cSrcweir SimplePasswordRequest::SimplePasswordRequest( PasswordRequestMode eMode )
100cdf0e10cSrcweir : mpAbort( NULL )
101cdf0e10cSrcweir , mpPassword( NULL )
102cdf0e10cSrcweir {
103cdf0e10cSrcweir PasswordRequest aRequest( OUString(), Reference< XInterface >(),
104cdf0e10cSrcweir InteractionClassification_QUERY, eMode );
105cdf0e10cSrcweir maRequest <<= aRequest;
106cdf0e10cSrcweir
107cdf0e10cSrcweir maContinuations.realloc( 2 );
108cdf0e10cSrcweir maContinuations[ 0 ].set( mpAbort = new AbortContinuation );
109cdf0e10cSrcweir maContinuations[ 1 ].set( mpPassword = new PasswordContinuation );
110cdf0e10cSrcweir }
111cdf0e10cSrcweir
~SimplePasswordRequest()112cdf0e10cSrcweir SimplePasswordRequest::~SimplePasswordRequest()
113cdf0e10cSrcweir {
114cdf0e10cSrcweir }
115cdf0e10cSrcweir
queryInterface(const Type & rType)116cdf0e10cSrcweir /*uno::*/Any SAL_CALL SimplePasswordRequest::queryInterface( const /*uno::*/Type& rType ) throw (RuntimeException)
117cdf0e10cSrcweir {
118cdf0e10cSrcweir return ::cppu::queryInterface ( rType,
119cdf0e10cSrcweir // OWeakObject interfaces
120cdf0e10cSrcweir dynamic_cast< XInterface* > ( (XInteractionRequest *) this ),
121cdf0e10cSrcweir static_cast< XWeak* > ( this ),
122cdf0e10cSrcweir // my own interfaces
123cdf0e10cSrcweir static_cast< XInteractionRequest* > ( this ) );
124cdf0e10cSrcweir }
125cdf0e10cSrcweir
acquire()126cdf0e10cSrcweir void SAL_CALL SimplePasswordRequest::acquire( ) throw ()
127cdf0e10cSrcweir {
128cdf0e10cSrcweir OWeakObject::acquire();
129cdf0e10cSrcweir }
130cdf0e10cSrcweir
release()131cdf0e10cSrcweir void SAL_CALL SimplePasswordRequest::release( ) throw ()
132cdf0e10cSrcweir {
133cdf0e10cSrcweir OWeakObject::release();
134cdf0e10cSrcweir }
135cdf0e10cSrcweir
isAbort() const136cdf0e10cSrcweir sal_Bool SimplePasswordRequest::isAbort() const
137cdf0e10cSrcweir {
138cdf0e10cSrcweir return mpAbort->isSelected();
139cdf0e10cSrcweir }
140cdf0e10cSrcweir
isPassword() const141cdf0e10cSrcweir sal_Bool SimplePasswordRequest::isPassword() const
142cdf0e10cSrcweir {
143cdf0e10cSrcweir return mpPassword->isSelected();
144cdf0e10cSrcweir }
145cdf0e10cSrcweir
getPassword() const146cdf0e10cSrcweir OUString SimplePasswordRequest::getPassword() const
147cdf0e10cSrcweir {
148cdf0e10cSrcweir return mpPassword->getPassword();
149cdf0e10cSrcweir }
150cdf0e10cSrcweir
getRequest()151cdf0e10cSrcweir Any SAL_CALL SimplePasswordRequest::getRequest() throw( RuntimeException )
152cdf0e10cSrcweir {
153cdf0e10cSrcweir return maRequest;
154cdf0e10cSrcweir }
155cdf0e10cSrcweir
getContinuations()156cdf0e10cSrcweir Sequence< Reference< XInteractionContinuation > > SAL_CALL SimplePasswordRequest::getContinuations() throw( RuntimeException )
157cdf0e10cSrcweir {
158cdf0e10cSrcweir return maContinuations;
159cdf0e10cSrcweir }
160cdf0e10cSrcweir
161cdf0e10cSrcweir // ============================================================================
162cdf0e10cSrcweir
DocPasswordRequest(DocPasswordRequestType eType,PasswordRequestMode eMode,const OUString & rDocumentName,sal_Bool bPasswordToModify)163cdf0e10cSrcweir DocPasswordRequest::DocPasswordRequest( DocPasswordRequestType eType,
164cdf0e10cSrcweir PasswordRequestMode eMode, const OUString& rDocumentName, sal_Bool bPasswordToModify )
165cdf0e10cSrcweir : mpAbort( NULL )
166cdf0e10cSrcweir , mpPassword( NULL )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir switch( eType )
169cdf0e10cSrcweir {
170cdf0e10cSrcweir case DocPasswordRequestType_STANDARD:
171cdf0e10cSrcweir {
172cdf0e10cSrcweir DocumentPasswordRequest2 aRequest( OUString(), Reference< XInterface >(),
173cdf0e10cSrcweir InteractionClassification_QUERY, eMode, rDocumentName, bPasswordToModify );
174cdf0e10cSrcweir maRequest <<= aRequest;
175cdf0e10cSrcweir }
176cdf0e10cSrcweir break;
177cdf0e10cSrcweir case DocPasswordRequestType_MS:
178cdf0e10cSrcweir {
179cdf0e10cSrcweir DocumentMSPasswordRequest2 aRequest( OUString(), Reference< XInterface >(),
180cdf0e10cSrcweir InteractionClassification_QUERY, eMode, rDocumentName, bPasswordToModify );
181cdf0e10cSrcweir maRequest <<= aRequest;
182cdf0e10cSrcweir }
183cdf0e10cSrcweir break;
184cdf0e10cSrcweir /* no 'default', so compilers will complain about missing
185cdf0e10cSrcweir implementation of a new enum value. */
186cdf0e10cSrcweir }
187cdf0e10cSrcweir
188cdf0e10cSrcweir maContinuations.realloc( 2 );
189cdf0e10cSrcweir maContinuations[ 0 ].set( mpAbort = new AbortContinuation );
190cdf0e10cSrcweir maContinuations[ 1 ].set( mpPassword = new PasswordContinuation );
191cdf0e10cSrcweir }
192cdf0e10cSrcweir
~DocPasswordRequest()193cdf0e10cSrcweir DocPasswordRequest::~DocPasswordRequest()
194cdf0e10cSrcweir {
195cdf0e10cSrcweir }
196cdf0e10cSrcweir
queryInterface(const Type & rType)197cdf0e10cSrcweir /*uno::*/Any SAL_CALL DocPasswordRequest::queryInterface( const /*uno::*/Type& rType ) throw (RuntimeException)
198cdf0e10cSrcweir {
199cdf0e10cSrcweir return ::cppu::queryInterface ( rType,
200cdf0e10cSrcweir // OWeakObject interfaces
201cdf0e10cSrcweir dynamic_cast< XInterface* > ( (XInteractionRequest *) this ),
202cdf0e10cSrcweir static_cast< XWeak* > ( this ),
203cdf0e10cSrcweir // my own interfaces
204cdf0e10cSrcweir static_cast< XInteractionRequest* > ( this ) );
205cdf0e10cSrcweir }
206cdf0e10cSrcweir
acquire()207cdf0e10cSrcweir void SAL_CALL DocPasswordRequest::acquire( ) throw ()
208cdf0e10cSrcweir {
209cdf0e10cSrcweir OWeakObject::acquire();
210cdf0e10cSrcweir }
211cdf0e10cSrcweir
release()212cdf0e10cSrcweir void SAL_CALL DocPasswordRequest::release( ) throw ()
213cdf0e10cSrcweir {
214cdf0e10cSrcweir OWeakObject::release();
215cdf0e10cSrcweir }
216cdf0e10cSrcweir
isAbort() const217cdf0e10cSrcweir sal_Bool DocPasswordRequest::isAbort() const
218cdf0e10cSrcweir {
219cdf0e10cSrcweir return mpAbort->isSelected();
220cdf0e10cSrcweir }
221cdf0e10cSrcweir
isPassword() const222cdf0e10cSrcweir sal_Bool DocPasswordRequest::isPassword() const
223cdf0e10cSrcweir {
224cdf0e10cSrcweir return mpPassword->isSelected();
225cdf0e10cSrcweir }
226cdf0e10cSrcweir
getPassword() const227cdf0e10cSrcweir OUString DocPasswordRequest::getPassword() const
228cdf0e10cSrcweir {
229cdf0e10cSrcweir return mpPassword->getPassword();
230cdf0e10cSrcweir }
231cdf0e10cSrcweir
getPasswordToModify() const232cdf0e10cSrcweir OUString DocPasswordRequest::getPasswordToModify() const
233cdf0e10cSrcweir {
234cdf0e10cSrcweir return mpPassword->getPasswordToModify();
235cdf0e10cSrcweir }
236cdf0e10cSrcweir
getRecommendReadOnly() const237cdf0e10cSrcweir sal_Bool DocPasswordRequest::getRecommendReadOnly() const
238cdf0e10cSrcweir {
239cdf0e10cSrcweir return mpPassword->getRecommendReadOnly();
240cdf0e10cSrcweir }
241cdf0e10cSrcweir
getRequest()242cdf0e10cSrcweir Any SAL_CALL DocPasswordRequest::getRequest() throw( RuntimeException )
243cdf0e10cSrcweir {
244cdf0e10cSrcweir return maRequest;
245cdf0e10cSrcweir }
246cdf0e10cSrcweir
getContinuations()247cdf0e10cSrcweir Sequence< Reference< XInteractionContinuation > > SAL_CALL DocPasswordRequest::getContinuations() throw( RuntimeException )
248cdf0e10cSrcweir {
249cdf0e10cSrcweir return maContinuations;
250cdf0e10cSrcweir }
251cdf0e10cSrcweir
252cdf0e10cSrcweir // ============================================================================
253cdf0e10cSrcweir
254cdf0e10cSrcweir } // namespace comphelper
255cdf0e10cSrcweir
256