xref: /AOO41X/main/ucb/source/ucp/tdoc/tdoc_passwordrequest.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_ucb.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "osl/mutex.hxx"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "com/sun/star/lang/XTypeProvider.hpp"
34*cdf0e10cSrcweir #include "com/sun/star/task/DocumentPasswordRequest.hpp"
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include "cppuhelper/typeprovider.hxx"
37*cdf0e10cSrcweir #include "ucbhelper/interactionrequest.hxx"
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include "tdoc_passwordrequest.hxx"
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir using namespace com::sun::star;
42*cdf0e10cSrcweir using namespace tdoc_ucp;
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir namespace tdoc_ucp
45*cdf0e10cSrcweir {
46*cdf0e10cSrcweir     class InteractionSupplyPassword :
47*cdf0e10cSrcweir                       public ucbhelper::InteractionContinuation,
48*cdf0e10cSrcweir                       public lang::XTypeProvider,
49*cdf0e10cSrcweir                       public task::XInteractionPassword
50*cdf0e10cSrcweir     {
51*cdf0e10cSrcweir     public:
52*cdf0e10cSrcweir         InteractionSupplyPassword( ucbhelper::InteractionRequest * pRequest )
53*cdf0e10cSrcweir         : InteractionContinuation( pRequest ) {}
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir         // XInterface
56*cdf0e10cSrcweir         virtual uno::Any SAL_CALL queryInterface( const uno::Type & rType )
57*cdf0e10cSrcweir             throw ( uno::RuntimeException );
58*cdf0e10cSrcweir         virtual void SAL_CALL acquire()
59*cdf0e10cSrcweir             throw ();
60*cdf0e10cSrcweir         virtual void SAL_CALL release()
61*cdf0e10cSrcweir             throw ();
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir         // XTypeProvider
64*cdf0e10cSrcweir         virtual uno::Sequence< uno::Type > SAL_CALL getTypes()
65*cdf0e10cSrcweir             throw ( uno::RuntimeException );
66*cdf0e10cSrcweir         virtual uno::Sequence< sal_Int8 > SAL_CALL getImplementationId()
67*cdf0e10cSrcweir             throw ( uno::RuntimeException );
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir         // XInteractionContinuation
70*cdf0e10cSrcweir         virtual void SAL_CALL select()
71*cdf0e10cSrcweir             throw ( uno::RuntimeException );
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir         // XInteractionPassword
74*cdf0e10cSrcweir         virtual void SAL_CALL setPassword( const rtl::OUString & aPasswd )
75*cdf0e10cSrcweir             throw ( uno::RuntimeException );
76*cdf0e10cSrcweir         virtual rtl::OUString SAL_CALL getPassword()
77*cdf0e10cSrcweir             throw ( uno::RuntimeException );
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir     private:
80*cdf0e10cSrcweir         osl::Mutex m_aMutex;
81*cdf0e10cSrcweir         rtl::OUString m_aPassword;
82*cdf0e10cSrcweir     };
83*cdf0e10cSrcweir } // namespace tdoc_ucp
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir //=========================================================================
86*cdf0e10cSrcweir //=========================================================================
87*cdf0e10cSrcweir //
88*cdf0e10cSrcweir // InteractionSupplyPassword Implementation.
89*cdf0e10cSrcweir //
90*cdf0e10cSrcweir //=========================================================================
91*cdf0e10cSrcweir //=========================================================================
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir //=========================================================================
94*cdf0e10cSrcweir //
95*cdf0e10cSrcweir // XInterface methods.
96*cdf0e10cSrcweir //
97*cdf0e10cSrcweir //=========================================================================
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir // virtual
100*cdf0e10cSrcweir void SAL_CALL InteractionSupplyPassword::acquire()
101*cdf0e10cSrcweir     throw()
102*cdf0e10cSrcweir {
103*cdf0e10cSrcweir     OWeakObject::acquire();
104*cdf0e10cSrcweir }
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir //=========================================================================
107*cdf0e10cSrcweir // virtual
108*cdf0e10cSrcweir void SAL_CALL InteractionSupplyPassword::release()
109*cdf0e10cSrcweir     throw()
110*cdf0e10cSrcweir {
111*cdf0e10cSrcweir     OWeakObject::release();
112*cdf0e10cSrcweir }
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir //=========================================================================
115*cdf0e10cSrcweir // virtual
116*cdf0e10cSrcweir uno::Any SAL_CALL
117*cdf0e10cSrcweir InteractionSupplyPassword::queryInterface( const uno::Type & rType )
118*cdf0e10cSrcweir     throw ( uno::RuntimeException )
119*cdf0e10cSrcweir {
120*cdf0e10cSrcweir     uno::Any aRet = cppu::queryInterface( rType,
121*cdf0e10cSrcweir                 static_cast< lang::XTypeProvider * >( this ),
122*cdf0e10cSrcweir                 static_cast< task::XInteractionContinuation * >( this ),
123*cdf0e10cSrcweir                 static_cast< task::XInteractionPassword * >( this ) );
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir     return aRet.hasValue()
126*cdf0e10cSrcweir             ? aRet : InteractionContinuation::queryInterface( rType );
127*cdf0e10cSrcweir }
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir //=========================================================================
130*cdf0e10cSrcweir //
131*cdf0e10cSrcweir // XTypeProvider methods.
132*cdf0e10cSrcweir //
133*cdf0e10cSrcweir //=========================================================================
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir // virtual
136*cdf0e10cSrcweir uno::Sequence< sal_Int8 > SAL_CALL
137*cdf0e10cSrcweir InteractionSupplyPassword::getImplementationId()
138*cdf0e10cSrcweir     throw( uno::RuntimeException )
139*cdf0e10cSrcweir {
140*cdf0e10cSrcweir     static cppu::OImplementationId * pId = 0;
141*cdf0e10cSrcweir     if ( !pId )
142*cdf0e10cSrcweir     {
143*cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
144*cdf0e10cSrcweir         if ( !pId )
145*cdf0e10cSrcweir         {
146*cdf0e10cSrcweir             static cppu::OImplementationId id( sal_False );
147*cdf0e10cSrcweir             pId = &id;
148*cdf0e10cSrcweir         }
149*cdf0e10cSrcweir     }
150*cdf0e10cSrcweir     return (*pId).getImplementationId();
151*cdf0e10cSrcweir }
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir //=========================================================================
154*cdf0e10cSrcweir // virtual
155*cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL InteractionSupplyPassword::getTypes()
156*cdf0e10cSrcweir     throw( uno::RuntimeException )
157*cdf0e10cSrcweir {
158*cdf0e10cSrcweir     static cppu::OTypeCollection * pCollection = 0;
159*cdf0e10cSrcweir     if ( !pCollection )
160*cdf0e10cSrcweir     {
161*cdf0e10cSrcweir         osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
162*cdf0e10cSrcweir         if ( !pCollection )
163*cdf0e10cSrcweir         {
164*cdf0e10cSrcweir             static cppu::OTypeCollection collection(
165*cdf0e10cSrcweir                 getCppuType( static_cast<
166*cdf0e10cSrcweir                     uno::Reference< lang::XTypeProvider > * >( 0 ) ),
167*cdf0e10cSrcweir                 getCppuType( static_cast<
168*cdf0e10cSrcweir                     uno::Reference< task::XInteractionPassword > * >( 0 ) ) );
169*cdf0e10cSrcweir             pCollection = &collection;
170*cdf0e10cSrcweir         }
171*cdf0e10cSrcweir     }
172*cdf0e10cSrcweir     return (*pCollection).getTypes();
173*cdf0e10cSrcweir }
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir //=========================================================================
176*cdf0e10cSrcweir //
177*cdf0e10cSrcweir // XInteractionContinuation methods.
178*cdf0e10cSrcweir //
179*cdf0e10cSrcweir //=========================================================================
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir // virtual
182*cdf0e10cSrcweir void SAL_CALL InteractionSupplyPassword::select()
183*cdf0e10cSrcweir     throw( uno::RuntimeException )
184*cdf0e10cSrcweir {
185*cdf0e10cSrcweir     recordSelection();
186*cdf0e10cSrcweir }
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir //=========================================================================
189*cdf0e10cSrcweir //
190*cdf0e10cSrcweir // XInteractionPassword methods.
191*cdf0e10cSrcweir //
192*cdf0e10cSrcweir //=========================================================================
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir // virtual
195*cdf0e10cSrcweir void SAL_CALL
196*cdf0e10cSrcweir InteractionSupplyPassword::setPassword( const ::rtl::OUString& aPasswd )
197*cdf0e10cSrcweir     throw ( uno::RuntimeException )
198*cdf0e10cSrcweir {
199*cdf0e10cSrcweir     osl::MutexGuard aGuard( m_aMutex );
200*cdf0e10cSrcweir     m_aPassword = aPasswd;
201*cdf0e10cSrcweir }
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir // virtual
204*cdf0e10cSrcweir rtl::OUString SAL_CALL InteractionSupplyPassword::getPassword()
205*cdf0e10cSrcweir     throw ( uno::RuntimeException )
206*cdf0e10cSrcweir {
207*cdf0e10cSrcweir     osl::MutexGuard aGuard( m_aMutex );
208*cdf0e10cSrcweir     return m_aPassword;
209*cdf0e10cSrcweir }
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir //=========================================================================
212*cdf0e10cSrcweir //=========================================================================
213*cdf0e10cSrcweir //
214*cdf0e10cSrcweir // DocumentPasswordRequest Implementation.
215*cdf0e10cSrcweir //
216*cdf0e10cSrcweir //=========================================================================
217*cdf0e10cSrcweir //=========================================================================
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir DocumentPasswordRequest::DocumentPasswordRequest(
220*cdf0e10cSrcweir     task::PasswordRequestMode eMode,
221*cdf0e10cSrcweir     const rtl::OUString & rDocumentName )
222*cdf0e10cSrcweir {
223*cdf0e10cSrcweir     // Fill request...
224*cdf0e10cSrcweir     task::DocumentPasswordRequest aRequest;
225*cdf0e10cSrcweir //    aRequest.Message        = // OUString
226*cdf0e10cSrcweir //    aRequest.Context        = // XInterface
227*cdf0e10cSrcweir     aRequest.Classification = task::InteractionClassification_ERROR;
228*cdf0e10cSrcweir     aRequest.Mode           = eMode;
229*cdf0e10cSrcweir     aRequest.Name           = rDocumentName;
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir     setRequest( uno::makeAny( aRequest ) );
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir     // Fill continuations...
234*cdf0e10cSrcweir     uno::Sequence<
235*cdf0e10cSrcweir         uno::Reference< task::XInteractionContinuation > > aContinuations( 3 );
236*cdf0e10cSrcweir     aContinuations[ 0 ] = new ucbhelper::InteractionAbort( this );
237*cdf0e10cSrcweir     aContinuations[ 1 ] = new ucbhelper::InteractionRetry( this );
238*cdf0e10cSrcweir     aContinuations[ 2 ] = new InteractionSupplyPassword( this );
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir     setContinuations( aContinuations );
241*cdf0e10cSrcweir }
242*cdf0e10cSrcweir 
243