xref: /AOO41X/main/comphelper/source/misc/docpasswordrequest.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_comphelper.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "comphelper/docpasswordrequest.hxx"
32*cdf0e10cSrcweir #include <com/sun/star/task/DocumentMSPasswordRequest2.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/task/DocumentPasswordRequest2.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/task/PasswordRequest.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/task/XInteractionAbort.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/task/XInteractionPassword2.hpp>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir using ::rtl::OUString;
39*cdf0e10cSrcweir using ::com::sun::star::uno::Any;
40*cdf0e10cSrcweir using ::com::sun::star::uno::Type;
41*cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
42*cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException;
43*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
44*cdf0e10cSrcweir using ::com::sun::star::uno::XInterface;
45*cdf0e10cSrcweir using ::com::sun::star::task::InteractionClassification_QUERY;
46*cdf0e10cSrcweir using ::com::sun::star::task::DocumentMSPasswordRequest2;
47*cdf0e10cSrcweir using ::com::sun::star::task::DocumentPasswordRequest2;
48*cdf0e10cSrcweir using ::com::sun::star::task::PasswordRequest;
49*cdf0e10cSrcweir using ::com::sun::star::task::PasswordRequestMode;
50*cdf0e10cSrcweir using ::com::sun::star::task::XInteractionAbort;
51*cdf0e10cSrcweir using ::com::sun::star::task::XInteractionContinuation;
52*cdf0e10cSrcweir using ::com::sun::star::task::XInteractionPassword2;
53*cdf0e10cSrcweir using ::com::sun::star::task::XInteractionRequest;
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir namespace comphelper {
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir // ============================================================================
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir class AbortContinuation : public ::cppu::WeakImplHelper1< XInteractionAbort >
60*cdf0e10cSrcweir {
61*cdf0e10cSrcweir public:
62*cdf0e10cSrcweir     inline explicit     AbortContinuation() : mbSelected( false ) {}
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir     inline sal_Bool     isSelected() const { return mbSelected; }
65*cdf0e10cSrcweir     inline void         reset() { mbSelected = false; }
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir     virtual void SAL_CALL select() throw( RuntimeException ) { mbSelected = true; }
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir private:
70*cdf0e10cSrcweir     sal_Bool            mbSelected;
71*cdf0e10cSrcweir };
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir // ============================================================================
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir class PasswordContinuation : public ::cppu::WeakImplHelper1< XInteractionPassword2 >
76*cdf0e10cSrcweir {
77*cdf0e10cSrcweir public:
78*cdf0e10cSrcweir     inline explicit     PasswordContinuation() : mbReadOnly( sal_False ), mbSelected( sal_False ) {}
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir     inline sal_Bool     isSelected() const { return mbSelected; }
81*cdf0e10cSrcweir     inline void         reset() { mbSelected = sal_False; }
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir     virtual void SAL_CALL select() throw( RuntimeException ) { mbSelected = sal_True; }
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir     virtual void SAL_CALL setPassword( const OUString& rPass ) throw( RuntimeException ) { maPassword = rPass; }
86*cdf0e10cSrcweir     virtual OUString SAL_CALL getPassword() throw( RuntimeException ) { return maPassword; }
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir     virtual void SAL_CALL setPasswordToModify( const OUString& rPass ) throw( RuntimeException ) { maModifyPassword = rPass; }
89*cdf0e10cSrcweir     virtual OUString SAL_CALL getPasswordToModify() throw( RuntimeException ) { return maModifyPassword; }
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir     virtual void SAL_CALL setRecommendReadOnly( sal_Bool bReadOnly ) throw( RuntimeException ) { mbReadOnly = bReadOnly; }
92*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL getRecommendReadOnly() throw( RuntimeException ) { return mbReadOnly; }
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir private:
95*cdf0e10cSrcweir     OUString            maPassword;
96*cdf0e10cSrcweir     OUString            maModifyPassword;
97*cdf0e10cSrcweir     sal_Bool            mbReadOnly;
98*cdf0e10cSrcweir     sal_Bool            mbSelected;
99*cdf0e10cSrcweir };
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir // ============================================================================
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir SimplePasswordRequest::SimplePasswordRequest( PasswordRequestMode eMode )
104*cdf0e10cSrcweir : mpAbort( NULL )
105*cdf0e10cSrcweir , mpPassword( NULL )
106*cdf0e10cSrcweir {
107*cdf0e10cSrcweir     PasswordRequest aRequest( OUString(), Reference< XInterface >(),
108*cdf0e10cSrcweir         InteractionClassification_QUERY, eMode );
109*cdf0e10cSrcweir     maRequest <<= aRequest;
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir     maContinuations.realloc( 2 );
112*cdf0e10cSrcweir     maContinuations[ 0 ].set( mpAbort = new AbortContinuation );
113*cdf0e10cSrcweir     maContinuations[ 1 ].set( mpPassword = new PasswordContinuation );
114*cdf0e10cSrcweir }
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir SimplePasswordRequest::~SimplePasswordRequest()
117*cdf0e10cSrcweir {
118*cdf0e10cSrcweir }
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir /*uno::*/Any SAL_CALL SimplePasswordRequest::queryInterface( const /*uno::*/Type& rType ) throw (RuntimeException)
121*cdf0e10cSrcweir {
122*cdf0e10cSrcweir     return ::cppu::queryInterface ( rType,
123*cdf0e10cSrcweir             // OWeakObject interfaces
124*cdf0e10cSrcweir             dynamic_cast< XInterface* > ( (XInteractionRequest *) this ),
125*cdf0e10cSrcweir             static_cast< XWeak* > ( this ),
126*cdf0e10cSrcweir             // my own interfaces
127*cdf0e10cSrcweir             static_cast< XInteractionRequest*  > ( this ) );
128*cdf0e10cSrcweir }
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir void SAL_CALL SimplePasswordRequest::acquire(  ) throw ()
131*cdf0e10cSrcweir {
132*cdf0e10cSrcweir     OWeakObject::acquire();
133*cdf0e10cSrcweir }
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir void SAL_CALL SimplePasswordRequest::release(  ) throw ()
136*cdf0e10cSrcweir {
137*cdf0e10cSrcweir     OWeakObject::release();
138*cdf0e10cSrcweir }
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir sal_Bool SimplePasswordRequest::isAbort() const
141*cdf0e10cSrcweir {
142*cdf0e10cSrcweir     return mpAbort->isSelected();
143*cdf0e10cSrcweir }
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir sal_Bool SimplePasswordRequest::isPassword() const
146*cdf0e10cSrcweir {
147*cdf0e10cSrcweir     return mpPassword->isSelected();
148*cdf0e10cSrcweir }
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir OUString SimplePasswordRequest::getPassword() const
151*cdf0e10cSrcweir {
152*cdf0e10cSrcweir     return mpPassword->getPassword();
153*cdf0e10cSrcweir }
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir Any SAL_CALL SimplePasswordRequest::getRequest() throw( RuntimeException )
156*cdf0e10cSrcweir {
157*cdf0e10cSrcweir     return maRequest;
158*cdf0e10cSrcweir }
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir Sequence< Reference< XInteractionContinuation > > SAL_CALL SimplePasswordRequest::getContinuations() throw( RuntimeException )
161*cdf0e10cSrcweir {
162*cdf0e10cSrcweir     return maContinuations;
163*cdf0e10cSrcweir }
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir // ============================================================================
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir DocPasswordRequest::DocPasswordRequest( DocPasswordRequestType eType,
168*cdf0e10cSrcweir         PasswordRequestMode eMode, const OUString& rDocumentName, sal_Bool bPasswordToModify )
169*cdf0e10cSrcweir : mpAbort( NULL )
170*cdf0e10cSrcweir , mpPassword( NULL )
171*cdf0e10cSrcweir {
172*cdf0e10cSrcweir     switch( eType )
173*cdf0e10cSrcweir     {
174*cdf0e10cSrcweir         case DocPasswordRequestType_STANDARD:
175*cdf0e10cSrcweir         {
176*cdf0e10cSrcweir             DocumentPasswordRequest2 aRequest( OUString(), Reference< XInterface >(),
177*cdf0e10cSrcweir                 InteractionClassification_QUERY, eMode, rDocumentName, bPasswordToModify );
178*cdf0e10cSrcweir             maRequest <<= aRequest;
179*cdf0e10cSrcweir         }
180*cdf0e10cSrcweir         break;
181*cdf0e10cSrcweir         case DocPasswordRequestType_MS:
182*cdf0e10cSrcweir         {
183*cdf0e10cSrcweir             DocumentMSPasswordRequest2 aRequest( OUString(), Reference< XInterface >(),
184*cdf0e10cSrcweir                 InteractionClassification_QUERY, eMode, rDocumentName, bPasswordToModify );
185*cdf0e10cSrcweir             maRequest <<= aRequest;
186*cdf0e10cSrcweir         }
187*cdf0e10cSrcweir         break;
188*cdf0e10cSrcweir         /*  no 'default', so compilers will complain about missing
189*cdf0e10cSrcweir             implementation of a new enum value. */
190*cdf0e10cSrcweir     }
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir     maContinuations.realloc( 2 );
193*cdf0e10cSrcweir     maContinuations[ 0 ].set( mpAbort = new AbortContinuation );
194*cdf0e10cSrcweir     maContinuations[ 1 ].set( mpPassword = new PasswordContinuation );
195*cdf0e10cSrcweir }
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir DocPasswordRequest::~DocPasswordRequest()
198*cdf0e10cSrcweir {
199*cdf0e10cSrcweir }
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir /*uno::*/Any SAL_CALL DocPasswordRequest::queryInterface( const /*uno::*/Type& rType ) throw (RuntimeException)
202*cdf0e10cSrcweir {
203*cdf0e10cSrcweir     return ::cppu::queryInterface ( rType,
204*cdf0e10cSrcweir             // OWeakObject interfaces
205*cdf0e10cSrcweir             dynamic_cast< XInterface* > ( (XInteractionRequest *) this ),
206*cdf0e10cSrcweir             static_cast< XWeak* > ( this ),
207*cdf0e10cSrcweir             // my own interfaces
208*cdf0e10cSrcweir             static_cast< XInteractionRequest*  > ( this ) );
209*cdf0e10cSrcweir }
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir void SAL_CALL DocPasswordRequest::acquire(  ) throw ()
212*cdf0e10cSrcweir {
213*cdf0e10cSrcweir     OWeakObject::acquire();
214*cdf0e10cSrcweir }
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir void SAL_CALL DocPasswordRequest::release(  ) throw ()
217*cdf0e10cSrcweir {
218*cdf0e10cSrcweir     OWeakObject::release();
219*cdf0e10cSrcweir }
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir sal_Bool DocPasswordRequest::isAbort() const
222*cdf0e10cSrcweir {
223*cdf0e10cSrcweir     return mpAbort->isSelected();
224*cdf0e10cSrcweir }
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir sal_Bool DocPasswordRequest::isPassword() const
227*cdf0e10cSrcweir {
228*cdf0e10cSrcweir     return mpPassword->isSelected();
229*cdf0e10cSrcweir }
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir OUString DocPasswordRequest::getPassword() const
232*cdf0e10cSrcweir {
233*cdf0e10cSrcweir     return mpPassword->getPassword();
234*cdf0e10cSrcweir }
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir OUString DocPasswordRequest::getPasswordToModify() const
237*cdf0e10cSrcweir {
238*cdf0e10cSrcweir     return mpPassword->getPasswordToModify();
239*cdf0e10cSrcweir }
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir sal_Bool DocPasswordRequest::getRecommendReadOnly() const
242*cdf0e10cSrcweir {
243*cdf0e10cSrcweir     return mpPassword->getRecommendReadOnly();
244*cdf0e10cSrcweir }
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir Any SAL_CALL DocPasswordRequest::getRequest() throw( RuntimeException )
247*cdf0e10cSrcweir {
248*cdf0e10cSrcweir     return maRequest;
249*cdf0e10cSrcweir }
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir Sequence< Reference< XInteractionContinuation > > SAL_CALL DocPasswordRequest::getContinuations() throw( RuntimeException )
252*cdf0e10cSrcweir {
253*cdf0e10cSrcweir     return maContinuations;
254*cdf0e10cSrcweir }
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir // ============================================================================
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir } // namespace comphelper
259*cdf0e10cSrcweir 
260