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
, std::exception
) SAL_OVERRIDE
;
48 virtual void SAL_CALL
acquire()
49 throw () SAL_OVERRIDE
;
50 virtual void SAL_CALL
release()
51 throw () SAL_OVERRIDE
;
54 virtual uno::Sequence
< uno::Type
> SAL_CALL
getTypes()
55 throw ( uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
56 virtual uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId()
57 throw ( uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
59 // XInteractionContinuation
60 virtual void SAL_CALL
select()
61 throw ( uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
63 // XInteractionPassword
64 virtual void SAL_CALL
setPassword( const OUString
& aPasswd
)
65 throw ( uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
66 virtual OUString SAL_CALL
getPassword()
67 throw ( uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
73 } // namespace tdoc_ucp
78 // InteractionSupplyPassword Implementation.
85 // XInterface methods.
90 void SAL_CALL
InteractionSupplyPassword::acquire()
93 OWeakObject::acquire();
98 void SAL_CALL
InteractionSupplyPassword::release()
101 OWeakObject::release();
107 InteractionSupplyPassword::queryInterface( const uno::Type
& rType
)
108 throw ( uno::RuntimeException
, std::exception
)
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
);
121 // XTypeProvider methods.
126 uno::Sequence
< sal_Int8
> SAL_CALL
127 InteractionSupplyPassword::getImplementationId()
128 throw( uno::RuntimeException
, std::exception
)
130 return css::uno::Sequence
<sal_Int8
>();
135 uno::Sequence
< uno::Type
> SAL_CALL
InteractionSupplyPassword::getTypes()
136 throw( uno::RuntimeException
, std::exception
)
138 static cppu::OTypeCollection
* pCollection
= 0;
141 osl::Guard
< osl::Mutex
> aGuard( osl::Mutex::getGlobalMutex() );
144 static cppu::OTypeCollection
collection(
145 getCppuType( static_cast<
146 uno::Reference
< lang::XTypeProvider
> * >( 0 ) ),
147 getCppuType( static_cast<
148 uno::Reference
< task::XInteractionPassword
> * >( 0 ) ) );
149 pCollection
= &collection
;
152 return (*pCollection
).getTypes();
157 // XInteractionContinuation methods.
162 void SAL_CALL
InteractionSupplyPassword::select()
163 throw( uno::RuntimeException
, std::exception
)
170 // XInteractionPassword methods.
176 InteractionSupplyPassword::setPassword( const OUString
& aPasswd
)
177 throw ( uno::RuntimeException
, std::exception
)
179 osl::MutexGuard
aGuard( m_aMutex
);
180 m_aPassword
= aPasswd
;
184 OUString SAL_CALL
InteractionSupplyPassword::getPassword()
185 throw ( uno::RuntimeException
, std::exception
)
187 osl::MutexGuard
aGuard( m_aMutex
);
194 // DocumentPasswordRequest Implementation.
199 DocumentPasswordRequest::DocumentPasswordRequest(
200 task::PasswordRequestMode eMode
,
201 const OUString
& rDocumentName
)
204 task::DocumentPasswordRequest aRequest
;
205 // aRequest.Message = // OUString
206 // aRequest.Context = // XInterface
207 aRequest
.Classification
= task::InteractionClassification_ERROR
;
208 aRequest
.Mode
= eMode
;
209 aRequest
.Name
= rDocumentName
;
211 setRequest( uno::makeAny( aRequest
) );
213 // Fill continuations...
215 uno::Reference
< task::XInteractionContinuation
> > aContinuations( 3 );
216 aContinuations
[ 0 ] = new ucbhelper::InteractionAbort( this );
217 aContinuations
[ 1 ] = new ucbhelper::InteractionRetry( this );
218 aContinuations
[ 2 ] = new InteractionSupplyPassword( this );
220 setContinuations( aContinuations
);
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */