Bump for 3.6-28
[LibreOffice.git] / ucb / source / ucp / tdoc / tdoc_passwordrequest.cxx
blobfbae96bbc5430e96f143591d01c0c375272f5157
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "osl/mutex.hxx"
32 #include "com/sun/star/lang/XTypeProvider.hpp"
33 #include "com/sun/star/task/DocumentPasswordRequest.hpp"
35 #include "cppuhelper/typeprovider.hxx"
36 #include "ucbhelper/interactionrequest.hxx"
38 #include "tdoc_passwordrequest.hxx"
40 using namespace com::sun::star;
41 using namespace tdoc_ucp;
43 namespace tdoc_ucp
45 class InteractionSupplyPassword :
46 public ucbhelper::InteractionContinuation,
47 public lang::XTypeProvider,
48 public task::XInteractionPassword
50 public:
51 InteractionSupplyPassword( ucbhelper::InteractionRequest * pRequest )
52 : InteractionContinuation( pRequest ) {}
54 // XInterface
55 virtual uno::Any SAL_CALL queryInterface( const uno::Type & rType )
56 throw ( uno::RuntimeException );
57 virtual void SAL_CALL acquire()
58 throw ();
59 virtual void SAL_CALL release()
60 throw ();
62 // XTypeProvider
63 virtual uno::Sequence< uno::Type > SAL_CALL getTypes()
64 throw ( uno::RuntimeException );
65 virtual uno::Sequence< sal_Int8 > SAL_CALL getImplementationId()
66 throw ( uno::RuntimeException );
68 // XInteractionContinuation
69 virtual void SAL_CALL select()
70 throw ( uno::RuntimeException );
72 // XInteractionPassword
73 virtual void SAL_CALL setPassword( const rtl::OUString & aPasswd )
74 throw ( uno::RuntimeException );
75 virtual rtl::OUString SAL_CALL getPassword()
76 throw ( uno::RuntimeException );
78 private:
79 osl::Mutex m_aMutex;
80 rtl::OUString m_aPassword;
82 } // namespace tdoc_ucp
84 //=========================================================================
85 //=========================================================================
87 // InteractionSupplyPassword Implementation.
89 //=========================================================================
90 //=========================================================================
92 //=========================================================================
94 // XInterface methods.
96 //=========================================================================
98 // virtual
99 void SAL_CALL InteractionSupplyPassword::acquire()
100 throw()
102 OWeakObject::acquire();
105 //=========================================================================
106 // virtual
107 void SAL_CALL InteractionSupplyPassword::release()
108 throw()
110 OWeakObject::release();
113 //=========================================================================
114 // virtual
115 uno::Any SAL_CALL
116 InteractionSupplyPassword::queryInterface( const uno::Type & rType )
117 throw ( uno::RuntimeException )
119 uno::Any aRet = cppu::queryInterface( rType,
120 static_cast< lang::XTypeProvider * >( this ),
121 static_cast< task::XInteractionContinuation * >( this ),
122 static_cast< task::XInteractionPassword * >( this ) );
124 return aRet.hasValue()
125 ? aRet : InteractionContinuation::queryInterface( rType );
128 //=========================================================================
130 // XTypeProvider methods.
132 //=========================================================================
134 // virtual
135 uno::Sequence< sal_Int8 > SAL_CALL
136 InteractionSupplyPassword::getImplementationId()
137 throw( uno::RuntimeException )
139 static cppu::OImplementationId * pId = 0;
140 if ( !pId )
142 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
143 if ( !pId )
145 static cppu::OImplementationId id( sal_False );
146 pId = &id;
149 return (*pId).getImplementationId();
152 //=========================================================================
153 // virtual
154 uno::Sequence< uno::Type > SAL_CALL InteractionSupplyPassword::getTypes()
155 throw( uno::RuntimeException )
157 static cppu::OTypeCollection * pCollection = 0;
158 if ( !pCollection )
160 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
161 if ( !pCollection )
163 static cppu::OTypeCollection collection(
164 getCppuType( static_cast<
165 uno::Reference< lang::XTypeProvider > * >( 0 ) ),
166 getCppuType( static_cast<
167 uno::Reference< task::XInteractionPassword > * >( 0 ) ) );
168 pCollection = &collection;
171 return (*pCollection).getTypes();
174 //=========================================================================
176 // XInteractionContinuation methods.
178 //=========================================================================
180 // virtual
181 void SAL_CALL InteractionSupplyPassword::select()
182 throw( uno::RuntimeException )
184 recordSelection();
187 //=========================================================================
189 // XInteractionPassword methods.
191 //=========================================================================
193 // virtual
194 void SAL_CALL
195 InteractionSupplyPassword::setPassword( const ::rtl::OUString& aPasswd )
196 throw ( uno::RuntimeException )
198 osl::MutexGuard aGuard( m_aMutex );
199 m_aPassword = aPasswd;
202 // virtual
203 rtl::OUString SAL_CALL InteractionSupplyPassword::getPassword()
204 throw ( uno::RuntimeException )
206 osl::MutexGuard aGuard( m_aMutex );
207 return m_aPassword;
210 //=========================================================================
211 //=========================================================================
213 // DocumentPasswordRequest Implementation.
215 //=========================================================================
216 //=========================================================================
218 DocumentPasswordRequest::DocumentPasswordRequest(
219 task::PasswordRequestMode eMode,
220 const rtl::OUString & rDocumentName )
222 // Fill request...
223 task::DocumentPasswordRequest aRequest;
224 // aRequest.Message = // OUString
225 // aRequest.Context = // XInterface
226 aRequest.Classification = task::InteractionClassification_ERROR;
227 aRequest.Mode = eMode;
228 aRequest.Name = rDocumentName;
230 setRequest( uno::makeAny( aRequest ) );
232 // Fill continuations...
233 uno::Sequence<
234 uno::Reference< task::XInteractionContinuation > > aContinuations( 3 );
235 aContinuations[ 0 ] = new ucbhelper::InteractionAbort( this );
236 aContinuations[ 1 ] = new ucbhelper::InteractionRetry( this );
237 aContinuations[ 2 ] = new InteractionSupplyPassword( this );
239 setContinuations( aContinuations );
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */