update dev300-m58
[ooovba.git] / ucb / source / ucp / tdoc / tdoc_passwordrequest.cxx
blobd0c438543ce7dfcf16e26ce53e278c4bf07d17a9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tdoc_passwordrequest.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucb.hxx"
34 #include "osl/mutex.hxx"
36 #include "com/sun/star/lang/XTypeProvider.hpp"
37 #include "com/sun/star/task/DocumentPasswordRequest.hpp"
39 #include "cppuhelper/typeprovider.hxx"
40 #include "ucbhelper/interactionrequest.hxx"
42 #include "tdoc_passwordrequest.hxx"
44 using namespace com::sun::star;
45 using namespace tdoc_ucp;
47 namespace tdoc_ucp
49 class InteractionSupplyPassword :
50 public ucbhelper::InteractionContinuation,
51 public lang::XTypeProvider,
52 public task::XInteractionPassword
54 public:
55 InteractionSupplyPassword( ucbhelper::InteractionRequest * pRequest )
56 : InteractionContinuation( pRequest ) {}
58 // XInterface
59 virtual uno::Any SAL_CALL queryInterface( const uno::Type & rType )
60 throw ( uno::RuntimeException );
61 virtual void SAL_CALL acquire()
62 throw ();
63 virtual void SAL_CALL release()
64 throw ();
66 // XTypeProvider
67 virtual uno::Sequence< uno::Type > SAL_CALL getTypes()
68 throw ( uno::RuntimeException );
69 virtual uno::Sequence< sal_Int8 > SAL_CALL getImplementationId()
70 throw ( uno::RuntimeException );
72 // XInteractionContinuation
73 virtual void SAL_CALL select()
74 throw ( uno::RuntimeException );
76 // XInteractionPassword
77 virtual void SAL_CALL setPassword( const rtl::OUString & aPasswd )
78 throw ( uno::RuntimeException );
79 virtual rtl::OUString SAL_CALL getPassword()
80 throw ( uno::RuntimeException );
82 private:
83 osl::Mutex m_aMutex;
84 rtl::OUString m_aPassword;
86 } // namespace tdoc_ucp
88 //=========================================================================
89 //=========================================================================
91 // InteractionSupplyPassword Implementation.
93 //=========================================================================
94 //=========================================================================
96 //=========================================================================
98 // XInterface methods.
100 //=========================================================================
102 // virtual
103 void SAL_CALL InteractionSupplyPassword::acquire()
104 throw()
106 OWeakObject::acquire();
109 //=========================================================================
110 // virtual
111 void SAL_CALL InteractionSupplyPassword::release()
112 throw()
114 OWeakObject::release();
117 //=========================================================================
118 // virtual
119 uno::Any SAL_CALL
120 InteractionSupplyPassword::queryInterface( const uno::Type & rType )
121 throw ( uno::RuntimeException )
123 uno::Any aRet = cppu::queryInterface( rType,
124 static_cast< lang::XTypeProvider * >( this ),
125 static_cast< task::XInteractionContinuation * >( this ),
126 static_cast< task::XInteractionPassword * >( this ) );
128 return aRet.hasValue()
129 ? aRet : InteractionContinuation::queryInterface( rType );
132 //=========================================================================
134 // XTypeProvider methods.
136 //=========================================================================
138 // virtual
139 uno::Sequence< sal_Int8 > SAL_CALL
140 InteractionSupplyPassword::getImplementationId()
141 throw( uno::RuntimeException )
143 static cppu::OImplementationId * pId = 0;
144 if ( !pId )
146 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
147 if ( !pId )
149 static cppu::OImplementationId id( sal_False );
150 pId = &id;
153 return (*pId).getImplementationId();
156 //=========================================================================
157 // virtual
158 uno::Sequence< uno::Type > SAL_CALL InteractionSupplyPassword::getTypes()
159 throw( uno::RuntimeException )
161 static cppu::OTypeCollection * pCollection = 0;
162 if ( !pCollection )
164 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
165 if ( !pCollection )
167 static cppu::OTypeCollection collection(
168 getCppuType( static_cast<
169 uno::Reference< lang::XTypeProvider > * >( 0 ) ),
170 getCppuType( static_cast<
171 uno::Reference< task::XInteractionPassword > * >( 0 ) ) );
172 pCollection = &collection;
175 return (*pCollection).getTypes();
178 //=========================================================================
180 // XInteractionContinuation methods.
182 //=========================================================================
184 // virtual
185 void SAL_CALL InteractionSupplyPassword::select()
186 throw( uno::RuntimeException )
188 recordSelection();
191 //=========================================================================
193 // XInteractionPassword methods.
195 //=========================================================================
197 // virtual
198 void SAL_CALL
199 InteractionSupplyPassword::setPassword( const ::rtl::OUString& aPasswd )
200 throw ( uno::RuntimeException )
202 osl::MutexGuard aGuard( m_aMutex );
203 m_aPassword = aPasswd;
206 // virtual
207 rtl::OUString SAL_CALL InteractionSupplyPassword::getPassword()
208 throw ( uno::RuntimeException )
210 osl::MutexGuard aGuard( m_aMutex );
211 return m_aPassword;
214 //=========================================================================
215 //=========================================================================
217 // DocumentPasswordRequest Implementation.
219 //=========================================================================
220 //=========================================================================
222 DocumentPasswordRequest::DocumentPasswordRequest(
223 task::PasswordRequestMode eMode,
224 const rtl::OUString & rDocumentName )
226 // Fill request...
227 task::DocumentPasswordRequest aRequest;
228 // aRequest.Message = // OUString
229 // aRequest.Context = // XInterface
230 aRequest.Classification = task::InteractionClassification_ERROR;
231 aRequest.Mode = eMode;
232 aRequest.Name = rDocumentName;
234 setRequest( uno::makeAny( aRequest ) );
236 // Fill continuations...
237 uno::Sequence<
238 uno::Reference< task::XInteractionContinuation > > aContinuations( 3 );
239 aContinuations[ 0 ] = new ucbhelper::InteractionAbort( this );
240 aContinuations[ 1 ] = new ucbhelper::InteractionRetry( this );
241 aContinuations[ 2 ] = new InteractionSupplyPassword( this );
243 setContinuations( aContinuations );