Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / comphelper / source / misc / docpasswordrequest.cxx
blob6f644336e1e2d6c5f18242925837ca1297700e84
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 <comphelper/docpasswordrequest.hxx>
22 #include <com/sun/star/task/DocumentMSPasswordRequest2.hpp>
23 #include <com/sun/star/task/DocumentPasswordRequest2.hpp>
24 #include <com/sun/star/task/PasswordRequest.hpp>
25 #include <com/sun/star/task/XInteractionAbort.hpp>
26 #include <com/sun/star/task/XInteractionPassword2.hpp>
27 #include <cppuhelper/implbase.hxx>
29 using ::com::sun::star::uno::Any;
30 using ::com::sun::star::uno::Reference;
31 using ::com::sun::star::uno::Sequence;
32 using ::com::sun::star::uno::XInterface;
33 using ::com::sun::star::task::InteractionClassification_QUERY;
34 using ::com::sun::star::task::DocumentMSPasswordRequest2;
35 using ::com::sun::star::task::DocumentPasswordRequest2;
36 using ::com::sun::star::task::PasswordRequest;
37 using ::com::sun::star::task::PasswordRequestMode;
38 using ::com::sun::star::task::XInteractionAbort;
39 using ::com::sun::star::task::XInteractionContinuation;
40 using ::com::sun::star::task::XInteractionPassword2;
42 namespace comphelper {
44 namespace {
46 class AbortContinuation : public ::cppu::WeakImplHelper< XInteractionAbort >
48 public:
49 virtual void SAL_CALL select() override {}
54 class PasswordContinuation : public ::cppu::WeakImplHelper< XInteractionPassword2 >
56 public:
57 explicit PasswordContinuation() : mbReadOnly( false ), mbSelected( false ) {}
59 bool isSelected() const { return mbSelected; }
61 virtual void SAL_CALL select() override { mbSelected = true; }
63 virtual void SAL_CALL setPassword( const OUString& rPass ) override { maPassword = rPass; }
64 virtual OUString SAL_CALL getPassword() override { return maPassword; }
66 virtual void SAL_CALL setPasswordToModify( const OUString& rPass ) override { maModifyPassword = rPass; }
67 virtual OUString SAL_CALL getPasswordToModify() override { return maModifyPassword; }
69 virtual void SAL_CALL setRecommendReadOnly( sal_Bool bReadOnly ) override { mbReadOnly = bReadOnly; }
70 virtual sal_Bool SAL_CALL getRecommendReadOnly() override { return mbReadOnly; }
72 private:
73 OUString maPassword;
74 OUString maModifyPassword;
75 bool mbReadOnly;
76 bool mbSelected;
80 SimplePasswordRequest::SimplePasswordRequest()
82 PasswordRequest aRequest( OUString(), Reference< XInterface >(),
83 InteractionClassification_QUERY, css::task::PasswordRequestMode_PASSWORD_CREATE );
84 maRequest <<= aRequest;
86 mxAbort = new AbortContinuation;
87 mxPassword = new PasswordContinuation;
90 SimplePasswordRequest::~SimplePasswordRequest()
94 bool SimplePasswordRequest::isPassword() const
96 return mxPassword->isSelected();
99 OUString SimplePasswordRequest::getPassword() const
101 return mxPassword->getPassword();
104 Any SAL_CALL SimplePasswordRequest::getRequest()
106 return maRequest;
109 Sequence< Reference< XInteractionContinuation > > SAL_CALL SimplePasswordRequest::getContinuations()
111 return { mxAbort, mxPassword };
115 DocPasswordRequest::DocPasswordRequest( DocPasswordRequestType eType,
116 PasswordRequestMode eMode, const OUString& rDocumentUrl, bool bPasswordToModify )
118 switch( eType )
120 case DocPasswordRequestType::Standard:
122 DocumentPasswordRequest2 aRequest( OUString(), Reference< XInterface >(),
123 InteractionClassification_QUERY, eMode, rDocumentUrl, bPasswordToModify );
124 maRequest <<= aRequest;
126 break;
127 case DocPasswordRequestType::MS:
129 DocumentMSPasswordRequest2 aRequest( OUString(), Reference< XInterface >(),
130 InteractionClassification_QUERY, eMode, rDocumentUrl, bPasswordToModify );
131 maRequest <<= aRequest;
133 break;
134 /* no 'default', so compilers will complain about missing
135 implementation of a new enum value. */
138 mxAbort = new AbortContinuation;
139 mxPassword = new PasswordContinuation;
142 DocPasswordRequest::~DocPasswordRequest()
146 bool DocPasswordRequest::isPassword() const
148 return mxPassword->isSelected();
151 OUString DocPasswordRequest::getPassword() const
153 return mxPassword->getPassword();
156 OUString DocPasswordRequest::getPasswordToModify() const
158 return mxPassword->getPasswordToModify();
161 bool DocPasswordRequest::getRecommendReadOnly() const
163 return mxPassword->getRecommendReadOnly();
166 Any SAL_CALL DocPasswordRequest::getRequest()
168 return maRequest;
171 Sequence< Reference< XInteractionContinuation > > SAL_CALL DocPasswordRequest::getContinuations()
173 return { mxAbort, mxPassword };
177 } // namespace comphelper
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */