1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "osl/mutex.hxx"
23 #include "com/sun/star/lang/XTypeProvider.hpp"
24 #include "com/sun/star/task/DocumentPasswordRequest.hpp"
26 #include "cppuhelper/typeprovider.hxx"
27 #include "ucbhelper/interactionrequest.hxx"
29 #include "tdoc_passwordrequest.hxx"
31 using namespace com::sun::star
;
32 using namespace tdoc_ucp
;
36 class InteractionSupplyPassword
:
37 public ucbhelper::InteractionContinuation
,
38 public lang::XTypeProvider
,
39 public task::XInteractionPassword
42 InteractionSupplyPassword( ucbhelper::InteractionRequest
* pRequest
)
43 : InteractionContinuation( pRequest
) {}
46 virtual uno::Any SAL_CALL
queryInterface( const uno::Type
& rType
)
47 throw ( uno::RuntimeException
);
48 virtual void SAL_CALL
acquire()
50 virtual void SAL_CALL
release()
54 virtual uno::Sequence
< uno::Type
> SAL_CALL
getTypes()
55 throw ( uno::RuntimeException
);
56 virtual uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId()
57 throw ( uno::RuntimeException
);
59 // XInteractionContinuation
60 virtual void SAL_CALL
select()
61 throw ( uno::RuntimeException
);
63 // XInteractionPassword
64 virtual void SAL_CALL
setPassword( const rtl::OUString
& aPasswd
)
65 throw ( uno::RuntimeException
);
66 virtual rtl::OUString SAL_CALL
getPassword()
67 throw ( uno::RuntimeException
);
71 rtl::OUString m_aPassword
;
73 } // namespace tdoc_ucp
75 //=========================================================================
76 //=========================================================================
78 // InteractionSupplyPassword Implementation.
80 //=========================================================================
81 //=========================================================================
83 //=========================================================================
85 // XInterface methods.
87 //=========================================================================
90 void SAL_CALL
InteractionSupplyPassword::acquire()
93 OWeakObject::acquire();
96 //=========================================================================
98 void SAL_CALL
InteractionSupplyPassword::release()
101 OWeakObject::release();
104 //=========================================================================
107 InteractionSupplyPassword::queryInterface( const uno::Type
& rType
)
108 throw ( uno::RuntimeException
)
110 uno::Any aRet
= cppu::queryInterface( rType
,
111 static_cast< lang::XTypeProvider
* >( this ),
112 static_cast< task::XInteractionContinuation
* >( this ),
113 static_cast< task::XInteractionPassword
* >( this ) );
115 return aRet
.hasValue()
116 ? aRet
: InteractionContinuation::queryInterface( rType
);
119 //=========================================================================
121 // XTypeProvider methods.
123 //=========================================================================
126 uno::Sequence
< sal_Int8
> SAL_CALL
127 InteractionSupplyPassword::getImplementationId()
128 throw( uno::RuntimeException
)
130 static cppu::OImplementationId
* pId
= 0;
133 osl::Guard
< osl::Mutex
> aGuard( osl::Mutex::getGlobalMutex() );
136 static cppu::OImplementationId
id( sal_False
);
140 return (*pId
).getImplementationId();
143 //=========================================================================
145 uno::Sequence
< uno::Type
> SAL_CALL
InteractionSupplyPassword::getTypes()
146 throw( uno::RuntimeException
)
148 static cppu::OTypeCollection
* pCollection
= 0;
151 osl::Guard
< osl::Mutex
> aGuard( osl::Mutex::getGlobalMutex() );
154 static cppu::OTypeCollection
collection(
155 getCppuType( static_cast<
156 uno::Reference
< lang::XTypeProvider
> * >( 0 ) ),
157 getCppuType( static_cast<
158 uno::Reference
< task::XInteractionPassword
> * >( 0 ) ) );
159 pCollection
= &collection
;
162 return (*pCollection
).getTypes();
165 //=========================================================================
167 // XInteractionContinuation methods.
169 //=========================================================================
172 void SAL_CALL
InteractionSupplyPassword::select()
173 throw( uno::RuntimeException
)
178 //=========================================================================
180 // XInteractionPassword methods.
182 //=========================================================================
186 InteractionSupplyPassword::setPassword( const ::rtl::OUString
& aPasswd
)
187 throw ( uno::RuntimeException
)
189 osl::MutexGuard
aGuard( m_aMutex
);
190 m_aPassword
= aPasswd
;
194 rtl::OUString SAL_CALL
InteractionSupplyPassword::getPassword()
195 throw ( uno::RuntimeException
)
197 osl::MutexGuard
aGuard( m_aMutex
);
201 //=========================================================================
202 //=========================================================================
204 // DocumentPasswordRequest Implementation.
206 //=========================================================================
207 //=========================================================================
209 DocumentPasswordRequest::DocumentPasswordRequest(
210 task::PasswordRequestMode eMode
,
211 const rtl::OUString
& rDocumentName
)
214 task::DocumentPasswordRequest aRequest
;
215 // aRequest.Message = // OUString
216 // aRequest.Context = // XInterface
217 aRequest
.Classification
= task::InteractionClassification_ERROR
;
218 aRequest
.Mode
= eMode
;
219 aRequest
.Name
= rDocumentName
;
221 setRequest( uno::makeAny( aRequest
) );
223 // Fill continuations...
225 uno::Reference
< task::XInteractionContinuation
> > aContinuations( 3 );
226 aContinuations
[ 0 ] = new ucbhelper::InteractionAbort( this );
227 aContinuations
[ 1 ] = new ucbhelper::InteractionRetry( this );
228 aContinuations
[ 2 ] = new InteractionSupplyPassword( this );
230 setContinuations( aContinuations
);
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */