LibreOffice Module ucb (master) 1
tdoc_passwordrequest.cxx
Go to the documentation of this file.
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
28
30
31#include <mutex>
32
33using namespace com::sun::star;
34using namespace tdoc_ucp;
35
36namespace tdoc_ucp
37{
38 namespace {
39
40 class InteractionSupplyPassword :
42 public lang::XTypeProvider,
43 public task::XInteractionPassword
44 {
45 public:
46 explicit InteractionSupplyPassword( ucbhelper::InteractionRequest * pRequest )
47 : InteractionContinuation( pRequest ) {}
48
49 // XInterface
50 virtual uno::Any SAL_CALL queryInterface( const uno::Type & rType ) override;
51 virtual void SAL_CALL acquire()
52 noexcept override;
53 virtual void SAL_CALL release()
54 noexcept override;
55
56 // XTypeProvider
57 virtual uno::Sequence< uno::Type > SAL_CALL getTypes() override;
58 virtual uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
59
60 // XInteractionContinuation
61 virtual void SAL_CALL select() override;
62
63 // XInteractionPassword
64 virtual void SAL_CALL setPassword( const OUString & aPasswd ) override;
65 virtual OUString SAL_CALL getPassword() override;
66
67 private:
68 std::mutex m_aMutex;
69 OUString m_aPassword;
70 };
71
72 }
73} // namespace tdoc_ucp
74
75
76// InteractionSupplyPassword Implementation.
77
78
79// XInterface methods.
80
81
82// virtual
83void SAL_CALL InteractionSupplyPassword::acquire()
84 noexcept
85{
86 OWeakObject::acquire();
87}
88
89
90// virtual
91void SAL_CALL InteractionSupplyPassword::release()
92 noexcept
93{
94 OWeakObject::release();
95}
96
97
98// virtual
99uno::Any SAL_CALL
100InteractionSupplyPassword::queryInterface( const uno::Type & rType )
101{
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 ) );
106
107 return aRet.hasValue()
108 ? aRet : InteractionContinuation::queryInterface( rType );
109}
110
111
112// XTypeProvider methods.
113
114
115// virtual
116uno::Sequence< sal_Int8 > SAL_CALL
117InteractionSupplyPassword::getImplementationId()
118{
119 return css::uno::Sequence<sal_Int8>();
120}
121
122
123// virtual
124uno::Sequence< uno::Type > SAL_CALL InteractionSupplyPassword::getTypes()
125{
126 static cppu::OTypeCollection s_aCollection(
129
130 return s_aCollection.getTypes();
131}
132
133
134// XInteractionContinuation methods.
135
136
137// virtual
138void SAL_CALL InteractionSupplyPassword::select()
139{
140 recordSelection();
141}
142
143
144// XInteractionPassword methods.
145
146
147// virtual
148void SAL_CALL
149InteractionSupplyPassword::setPassword( const OUString& aPasswd )
150{
151 std::scoped_lock aGuard( m_aMutex );
152 m_aPassword = aPasswd;
153}
154
155// virtual
156OUString SAL_CALL InteractionSupplyPassword::getPassword()
157{
158 std::scoped_lock aGuard( m_aMutex );
159 return m_aPassword;
160}
161
162
163// DocumentPasswordRequest Implementation.
164
165
167 task::PasswordRequestMode eMode,
168 const OUString & rDocumentName )
169{
170 // Fill request...
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;
177
178 setRequest( uno::Any( aRequest ) );
179
180 // Fill continuations...
181 uno::Sequence<
182 uno::Reference< task::XInteractionContinuation > > aContinuations{
183 new ucbhelper::InteractionAbort( this ),
184 new ucbhelper::InteractionRetry( this ),
185 new InteractionSupplyPassword( this )
186 };
187
188 setContinuations( aContinuations );
189}
190
191/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
DocumentPasswordRequest(css::task::PasswordRequestMode eMode, const OUString &rDocumentName)
Mode eMode
Type
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
bool hasValue()
OUString m_aPassword
std::mutex m_aMutex
signed char sal_Int8