bump product version to 7.2.5.1
[LibreOffice.git] / ucb / source / ucp / tdoc / tdoc_passwordrequest.cxx
bloba5a8f742b41d46effafd59816cfd5d6f8dd89b37
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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;
36 namespace tdoc_ucp
38 namespace {
40 class InteractionSupplyPassword :
41 public ucbhelper::InteractionContinuation,
42 public lang::XTypeProvider,
43 public task::XInteractionPassword
45 public:
46 explicit InteractionSupplyPassword( ucbhelper::InteractionRequest * pRequest )
47 : InteractionContinuation( pRequest ) {}
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;
56 // XTypeProvider
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;
67 private:
68 osl::Mutex m_aMutex;
69 OUString m_aPassword;
73 } // namespace tdoc_ucp
76 // InteractionSupplyPassword Implementation.
79 // XInterface methods.
82 // virtual
83 void SAL_CALL InteractionSupplyPassword::acquire()
84 noexcept
86 OWeakObject::acquire();
90 // virtual
91 void SAL_CALL InteractionSupplyPassword::release()
92 noexcept
94 OWeakObject::release();
98 // virtual
99 uno::Any SAL_CALL
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.
115 // virtual
116 uno::Sequence< sal_Int8 > SAL_CALL
117 InteractionSupplyPassword::getImplementationId()
119 return css::uno::Sequence<sal_Int8>();
123 // virtual
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.
137 // virtual
138 void SAL_CALL InteractionSupplyPassword::select()
140 recordSelection();
144 // XInteractionPassword methods.
147 // virtual
148 void SAL_CALL
149 InteractionSupplyPassword::setPassword( const OUString& aPasswd )
151 osl::MutexGuard aGuard( m_aMutex );
152 m_aPassword = aPasswd;
155 // virtual
156 OUString SAL_CALL InteractionSupplyPassword::getPassword()
158 osl::MutexGuard aGuard( m_aMutex );
159 return m_aPassword;
163 // DocumentPasswordRequest Implementation.
166 DocumentPasswordRequest::DocumentPasswordRequest(
167 task::PasswordRequestMode eMode,
168 const OUString & rDocumentName )
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;
178 setRequest( uno::makeAny( aRequest ) );
180 // Fill continuations...
181 uno::Sequence<
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: */