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>
25 #include <com/sun/star/task/XInteractionPassword.hpp>
27 #include <cppuhelper/queryinterface.hxx>
28 #include <cppuhelper/typeprovider.hxx>
29 #include <ucbhelper/interactionrequest.hxx>
31 #include "tdoc_passwordrequest.hxx"
33 using namespace com::sun::star
;
34 using namespace tdoc_ucp
;
40 class InteractionSupplyPassword
:
41 public ucbhelper::InteractionContinuation
,
42 public lang::XTypeProvider
,
43 public task::XInteractionPassword
46 explicit InteractionSupplyPassword( ucbhelper::InteractionRequest
* pRequest
)
47 : InteractionContinuation( pRequest
) {}
50 virtual uno::Any SAL_CALL
queryInterface( const uno::Type
& rType
) override
;
51 virtual void SAL_CALL
acquire()
53 virtual void SAL_CALL
release()
57 virtual uno::Sequence
< uno::Type
> SAL_CALL
getTypes() override
;
58 virtual uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId() override
;
60 // XInteractionContinuation
61 virtual void SAL_CALL
select() override
;
63 // XInteractionPassword
64 virtual void SAL_CALL
setPassword( const OUString
& aPasswd
) override
;
65 virtual OUString SAL_CALL
getPassword() override
;
73 } // namespace tdoc_ucp
76 // InteractionSupplyPassword Implementation.
79 // XInterface methods.
83 void SAL_CALL
InteractionSupplyPassword::acquire()
86 OWeakObject::acquire();
91 void SAL_CALL
InteractionSupplyPassword::release()
94 OWeakObject::release();
100 InteractionSupplyPassword::queryInterface( const uno::Type
& rType
)
102 uno::Any aRet
= cppu::queryInterface( rType
,
103 static_cast< lang::XTypeProvider
* >( this ),
104 static_cast< task::XInteractionContinuation
* >( this ),
105 static_cast< task::XInteractionPassword
* >( this ) );
107 return aRet
.hasValue()
108 ? aRet
: InteractionContinuation::queryInterface( rType
);
112 // XTypeProvider methods.
116 uno::Sequence
< sal_Int8
> SAL_CALL
117 InteractionSupplyPassword::getImplementationId()
119 return css::uno::Sequence
<sal_Int8
>();
124 uno::Sequence
< uno::Type
> SAL_CALL
InteractionSupplyPassword::getTypes()
126 static cppu::OTypeCollection
s_aCollection(
127 cppu::UnoType
<lang::XTypeProvider
>::get(),
128 cppu::UnoType
<task::XInteractionPassword
>::get() );
130 return s_aCollection
.getTypes();
134 // XInteractionContinuation methods.
138 void SAL_CALL
InteractionSupplyPassword::select()
144 // XInteractionPassword methods.
149 InteractionSupplyPassword::setPassword( const OUString
& aPasswd
)
151 osl::MutexGuard
aGuard( m_aMutex
);
152 m_aPassword
= aPasswd
;
156 OUString SAL_CALL
InteractionSupplyPassword::getPassword()
158 osl::MutexGuard
aGuard( m_aMutex
);
163 // DocumentPasswordRequest Implementation.
166 DocumentPasswordRequest::DocumentPasswordRequest(
167 task::PasswordRequestMode eMode
,
168 const OUString
& rDocumentName
)
171 task::DocumentPasswordRequest aRequest
;
172 // aRequest.Message = // OUString
173 // aRequest.Context = // XInterface
174 aRequest
.Classification
= task::InteractionClassification_ERROR
;
175 aRequest
.Mode
= eMode
;
176 aRequest
.Name
= rDocumentName
;
178 setRequest( uno::makeAny( aRequest
) );
180 // Fill continuations...
182 uno::Reference
< task::XInteractionContinuation
> > aContinuations( 3 );
183 aContinuations
[ 0 ] = new ucbhelper::InteractionAbort( this );
184 aContinuations
[ 1 ] = new ucbhelper::InteractionRetry( this );
185 aContinuations
[ 2 ] = new InteractionSupplyPassword( this );
187 setContinuations( aContinuations
);
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */