| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 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/. |
| 8 |
* |
| 9 |
* This file incorporates work covered by the following license notice: |
| 10 |
* |
| 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 . |
| 18 |
*/ |
| 19 |
|
| 20 |
|
| 21 |
#include <com/sun/star/lang/XTypeProvider.hpp> |
| 22 |
#include <com/sun/star/task/DocumentPasswordRequest.hpp> |
| 23 |
#include <com/sun/star/task/XInteractionPassword.hpp> |
| 24 |
|
| 25 |
#include <cppuhelper/queryinterface.hxx> |
| 26 |
#include <cppuhelper/typeprovider.hxx> |
| 27 |
#include <ucbhelper/interactionrequest.hxx> |
| 28 |
|
| 29 |
#include "tdoc_passwordrequest.hxx" |
| 30 |
|
| 31 |
#include <mutex> |
| 32 |
|
| 33 |
using namespace com::sun::star; |
| 34 |
using namespace tdoc_ucp; |
| 35 |
|
| 36 |
namespace tdoc_ucp |
| 37 |
{ |
| 38 |
namespace { |
| 39 |
|
| 40 |
using InteractionSupplyPassword_BASE = cppu::ImplInheritanceHelper<ucbhelper::InteractionContinuation, |
| 41 |
task::XInteractionPassword>; |
| 42 |
class InteractionSupplyPassword : public InteractionSupplyPassword_BASE |
| 43 |
{ |
| 44 |
public: |
| 45 |
explicit InteractionSupplyPassword( ucbhelper::InteractionRequest * pRequest ) |
| 46 |
: InteractionSupplyPassword_BASE( pRequest ) {} |
| 47 |
|
| 48 |
// XInteractionContinuation |
| 49 |
virtual void SAL_CALL select() override; |
| 50 |
|
| 51 |
// XInteractionPassword |
| 52 |
virtual void SAL_CALL setPassword( const OUString & aPasswd ) override; |
| 53 |
virtual OUString SAL_CALL getPassword() override; |
| 54 |
|
| 55 |
private: |
| 56 |
std::mutex m_aMutex; |
| 57 |
OUString m_aPassword; |
| 58 |
}; |
| 59 |
|
| 60 |
} |
| 61 |
} // namespace tdoc_ucp |
| 62 |
|
| 63 |
|
| 64 |
// InteractionSupplyPassword Implementation. |
| 65 |
|
| 66 |
|
| 67 |
// XInteractionContinuation methods. |
| 68 |
|
| 69 |
|
| 70 |
// virtual |
| 71 |
void SAL_CALL InteractionSupplyPassword::select() |
| 72 |
{ |
| 73 |
recordSelection(); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
// XInteractionPassword methods. |
| 78 |
|
| 79 |
|
| 80 |
// virtual |
| 81 |
void SAL_CALL |
| 82 |
InteractionSupplyPassword::setPassword( const OUString& aPasswd ) |
| 83 |
{ |
| 84 |
std::scoped_lock aGuard( m_aMutex ); |
| 85 |
m_aPassword = aPasswd; |
| 86 |
} |
| 87 |
|
| 88 |
// virtual |
| 89 |
OUString SAL_CALL InteractionSupplyPassword::getPassword() |
| 90 |
{ |
| 91 |
std::scoped_lock aGuard( m_aMutex ); |
| 92 |
return m_aPassword; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
// DocumentPasswordRequest Implementation. |
| 97 |
|
| 98 |
|
| 99 |
DocumentPasswordRequest::DocumentPasswordRequest( |
| 100 |
task::PasswordRequestMode eMode, |
| 101 |
const OUString & rDocumentName ) |
| 102 |
{ |
| 103 |
// Fill request... |
| 104 |
task::DocumentPasswordRequest aRequest; |
| 105 |
// aRequest.Message = // OUString |
| 106 |
// aRequest.Context = // XInterface |
| 107 |
aRequest.Classification = task::InteractionClassification_ERROR; |
| 108 |
aRequest.Mode = eMode; |
| 109 |
aRequest.Name = rDocumentName; |
| 110 |
|
| 111 |
setRequest( uno::Any( aRequest ) ); |
| 112 |
|
| 113 |
// Fill continuations... |
| 114 |
uno::Sequence< |
| 115 |
uno::Reference< task::XInteractionContinuation > > aContinuations{ |
| 116 |
new ucbhelper::InteractionAbort( this ), |
| 117 |
new ucbhelper::InteractionRetry( this ), |
| 118 |
new InteractionSupplyPassword( this ) |
| 119 |
}; |
| 120 |
|
| 121 |
setContinuations( aContinuations ); |
| 122 |
} |
| 123 |
|
| 124 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |