CWS-TOOLING: integrate CWS os146
[LibreOffice.git] / comphelper / source / misc / docpasswordrequest.cxx
blob15c2e09ba0f341cf9e16d0bb9eb84831d33ba969
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_comphelper.hxx"
31 #include "comphelper/docpasswordrequest.hxx"
32 #include <com/sun/star/task/DocumentMSPasswordRequest2.hpp>
33 #include <com/sun/star/task/DocumentPasswordRequest2.hpp>
34 #include <com/sun/star/task/PasswordRequest.hpp>
35 #include <com/sun/star/task/XInteractionAbort.hpp>
36 #include <com/sun/star/task/XInteractionPassword2.hpp>
38 using ::rtl::OUString;
39 using ::com::sun::star::uno::Any;
40 using ::com::sun::star::uno::Type;
41 using ::com::sun::star::uno::Reference;
42 using ::com::sun::star::uno::RuntimeException;
43 using ::com::sun::star::uno::Sequence;
44 using ::com::sun::star::uno::XInterface;
45 using ::com::sun::star::task::InteractionClassification_QUERY;
46 using ::com::sun::star::task::DocumentMSPasswordRequest2;
47 using ::com::sun::star::task::DocumentPasswordRequest2;
48 using ::com::sun::star::task::PasswordRequest;
49 using ::com::sun::star::task::PasswordRequestMode;
50 using ::com::sun::star::task::XInteractionAbort;
51 using ::com::sun::star::task::XInteractionContinuation;
52 using ::com::sun::star::task::XInteractionPassword2;
53 using ::com::sun::star::task::XInteractionRequest;
55 namespace comphelper {
57 // ============================================================================
59 class AbortContinuation : public ::cppu::WeakImplHelper1< XInteractionAbort >
61 public:
62 inline explicit AbortContinuation() : mbSelected( false ) {}
64 inline sal_Bool isSelected() const { return mbSelected; }
65 inline void reset() { mbSelected = false; }
67 virtual void SAL_CALL select() throw( RuntimeException ) { mbSelected = true; }
69 private:
70 sal_Bool mbSelected;
73 // ============================================================================
75 class PasswordContinuation : public ::cppu::WeakImplHelper1< XInteractionPassword2 >
77 public:
78 inline explicit PasswordContinuation() : mbReadOnly( sal_False ), mbSelected( sal_False ) {}
80 inline sal_Bool isSelected() const { return mbSelected; }
81 inline void reset() { mbSelected = sal_False; }
83 virtual void SAL_CALL select() throw( RuntimeException ) { mbSelected = sal_True; }
85 virtual void SAL_CALL setPassword( const OUString& rPass ) throw( RuntimeException ) { maPassword = rPass; }
86 virtual OUString SAL_CALL getPassword() throw( RuntimeException ) { return maPassword; }
88 virtual void SAL_CALL setPasswordToModify( const OUString& rPass ) throw( RuntimeException ) { maModifyPassword = rPass; }
89 virtual OUString SAL_CALL getPasswordToModify() throw( RuntimeException ) { return maModifyPassword; }
91 virtual void SAL_CALL setRecommendReadOnly( sal_Bool bReadOnly ) throw( RuntimeException ) { mbReadOnly = bReadOnly; }
92 virtual sal_Bool SAL_CALL getRecommendReadOnly() throw( RuntimeException ) { return mbReadOnly; }
94 private:
95 OUString maPassword;
96 OUString maModifyPassword;
97 sal_Bool mbReadOnly;
98 sal_Bool mbSelected;
101 // ============================================================================
103 SimplePasswordRequest::SimplePasswordRequest( PasswordRequestMode eMode )
104 : mpAbort( NULL )
105 , mpPassword( NULL )
107 PasswordRequest aRequest( OUString(), Reference< XInterface >(),
108 InteractionClassification_QUERY, eMode );
109 maRequest <<= aRequest;
111 maContinuations.realloc( 2 );
112 maContinuations[ 0 ].set( mpAbort = new AbortContinuation );
113 maContinuations[ 1 ].set( mpPassword = new PasswordContinuation );
116 SimplePasswordRequest::~SimplePasswordRequest()
120 /*uno::*/Any SAL_CALL SimplePasswordRequest::queryInterface( const /*uno::*/Type& rType ) throw (RuntimeException)
122 return ::cppu::queryInterface ( rType,
123 // OWeakObject interfaces
124 dynamic_cast< XInterface* > ( (XInteractionRequest *) this ),
125 static_cast< XWeak* > ( this ),
126 // my own interfaces
127 static_cast< XInteractionRequest* > ( this ) );
130 void SAL_CALL SimplePasswordRequest::acquire( ) throw ()
132 OWeakObject::acquire();
135 void SAL_CALL SimplePasswordRequest::release( ) throw ()
137 OWeakObject::release();
140 sal_Bool SimplePasswordRequest::isAbort() const
142 return mpAbort->isSelected();
145 sal_Bool SimplePasswordRequest::isPassword() const
147 return mpPassword->isSelected();
150 OUString SimplePasswordRequest::getPassword() const
152 return mpPassword->getPassword();
155 Any SAL_CALL SimplePasswordRequest::getRequest() throw( RuntimeException )
157 return maRequest;
160 Sequence< Reference< XInteractionContinuation > > SAL_CALL SimplePasswordRequest::getContinuations() throw( RuntimeException )
162 return maContinuations;
165 // ============================================================================
167 DocPasswordRequest::DocPasswordRequest( DocPasswordRequestType eType,
168 PasswordRequestMode eMode, const OUString& rDocumentName, sal_Bool bPasswordToModify )
169 : mpAbort( NULL )
170 , mpPassword( NULL )
172 switch( eType )
174 case DocPasswordRequestType_STANDARD:
176 DocumentPasswordRequest2 aRequest( OUString(), Reference< XInterface >(),
177 InteractionClassification_QUERY, eMode, rDocumentName, bPasswordToModify );
178 maRequest <<= aRequest;
180 break;
181 case DocPasswordRequestType_MS:
183 DocumentMSPasswordRequest2 aRequest( OUString(), Reference< XInterface >(),
184 InteractionClassification_QUERY, eMode, rDocumentName, bPasswordToModify );
185 maRequest <<= aRequest;
187 break;
188 /* no 'default', so compilers will complain about missing
189 implementation of a new enum value. */
192 maContinuations.realloc( 2 );
193 maContinuations[ 0 ].set( mpAbort = new AbortContinuation );
194 maContinuations[ 1 ].set( mpPassword = new PasswordContinuation );
197 DocPasswordRequest::~DocPasswordRequest()
201 /*uno::*/Any SAL_CALL DocPasswordRequest::queryInterface( const /*uno::*/Type& rType ) throw (RuntimeException)
203 return ::cppu::queryInterface ( rType,
204 // OWeakObject interfaces
205 dynamic_cast< XInterface* > ( (XInteractionRequest *) this ),
206 static_cast< XWeak* > ( this ),
207 // my own interfaces
208 static_cast< XInteractionRequest* > ( this ) );
211 void SAL_CALL DocPasswordRequest::acquire( ) throw ()
213 OWeakObject::acquire();
216 void SAL_CALL DocPasswordRequest::release( ) throw ()
218 OWeakObject::release();
221 sal_Bool DocPasswordRequest::isAbort() const
223 return mpAbort->isSelected();
226 sal_Bool DocPasswordRequest::isPassword() const
228 return mpPassword->isSelected();
231 OUString DocPasswordRequest::getPassword() const
233 return mpPassword->getPassword();
236 OUString DocPasswordRequest::getPasswordToModify() const
238 return mpPassword->getPasswordToModify();
241 sal_Bool DocPasswordRequest::getRecommendReadOnly() const
243 return mpPassword->getRecommendReadOnly();
246 Any SAL_CALL DocPasswordRequest::getRequest() throw( RuntimeException )
248 return maRequest;
251 Sequence< Reference< XInteractionContinuation > > SAL_CALL DocPasswordRequest::getContinuations() throw( RuntimeException )
253 return maContinuations;
256 // ============================================================================
258 } // namespace comphelper