LibreOffice Module comphelper (master) 1
docpasswordrequest.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
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>
28
29using ::com::sun::star::uno::Any;
30using ::com::sun::star::uno::Reference;
31using ::com::sun::star::uno::Sequence;
32using ::com::sun::star::uno::XInterface;
33using ::com::sun::star::task::InteractionClassification_QUERY;
34using ::com::sun::star::task::DocumentMSPasswordRequest2;
35using ::com::sun::star::task::DocumentPasswordRequest2;
36using ::com::sun::star::task::PasswordRequest;
37using ::com::sun::star::task::PasswordRequestMode;
38using ::com::sun::star::task::XInteractionAbort;
39using ::com::sun::star::task::XInteractionContinuation;
40using ::com::sun::star::task::XInteractionPassword2;
41
42namespace comphelper {
43
44namespace {
45
46class AbortContinuation : public ::cppu::WeakImplHelper< XInteractionAbort >
47{
48public:
49 virtual void SAL_CALL select() override {}
50};
51
52}
53
54class PasswordContinuation : public ::cppu::WeakImplHelper< XInteractionPassword2 >
55{
56public:
57 explicit PasswordContinuation() : mbReadOnly( false ), mbSelected( false ) {}
58
59 bool isSelected() const { return mbSelected; }
60
61 virtual void SAL_CALL select() override { mbSelected = true; }
62
63 virtual void SAL_CALL setPassword( const OUString& rPass ) override { maPassword = rPass; }
64 virtual OUString SAL_CALL getPassword() override { return maPassword; }
65
66 virtual void SAL_CALL setPasswordToModify( const OUString& rPass ) override { maModifyPassword = rPass; }
67 virtual OUString SAL_CALL getPasswordToModify() override { return maModifyPassword; }
68
69 virtual void SAL_CALL setRecommendReadOnly( sal_Bool bReadOnly ) override { mbReadOnly = bReadOnly; }
70 virtual sal_Bool SAL_CALL getRecommendReadOnly() override { return mbReadOnly; }
71
72private:
73 OUString maPassword;
77};
78
79
81{
82 PasswordRequest aRequest( OUString(), Reference< XInterface >(),
83 InteractionClassification_QUERY, css::task::PasswordRequestMode_PASSWORD_CREATE );
84 maRequest <<= aRequest;
85
86 mxAbort = new AbortContinuation;
88}
89
91{
92}
93
95{
96 return mxPassword->isSelected();
97}
98
100{
101 return mxPassword->getPassword();
102}
103
105{
106 return maRequest;
107}
108
109Sequence< Reference< XInteractionContinuation > > SAL_CALL SimplePasswordRequest::getContinuations()
110{
111 return { mxAbort, mxPassword };
112}
113
114
116 PasswordRequestMode eMode, const OUString& rDocumentUrl, bool bPasswordToModify )
117{
118 switch( eType )
119 {
121 {
122 DocumentPasswordRequest2 aRequest( OUString(), Reference< XInterface >(),
123 InteractionClassification_QUERY, eMode, rDocumentUrl, bPasswordToModify );
124 maRequest <<= aRequest;
125 }
126 break;
128 {
129 DocumentMSPasswordRequest2 aRequest( OUString(), Reference< XInterface >(),
130 InteractionClassification_QUERY, eMode, rDocumentUrl, bPasswordToModify );
131 maRequest <<= aRequest;
132 }
133 break;
134 /* no 'default', so compilers will complain about missing
135 implementation of a new enum value. */
136 }
137
138 mxAbort = new AbortContinuation;
139 mxPassword = new PasswordContinuation;
140}
141
143{
144}
145
147{
148 return mxPassword->isSelected();
149}
150
152{
153 return mxPassword->getPassword();
154}
155
157{
158 return mxPassword->getPasswordToModify();
159}
160
162{
163 return mxPassword->getRecommendReadOnly();
164}
165
167{
168 return maRequest;
169}
170
171Sequence< Reference< XInteractionContinuation > > SAL_CALL DocPasswordRequest::getContinuations()
172{
173 return { mxAbort, mxPassword };
174}
175
176
177} // namespace comphelper
178
179/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > SAL_CALL getContinuations() override
css::uno::Reference< css::task::XInteractionAbort > mxAbort
DocPasswordRequest(DocPasswordRequestType eType, css::task::PasswordRequestMode eMode, const OUString &rDocumentUrl, bool bPasswordToModify=false)
rtl::Reference< PasswordContinuation > mxPassword
virtual css::uno::Any SAL_CALL getRequest() override
virtual void SAL_CALL setPasswordToModify(const OUString &rPass) override
virtual void SAL_CALL setPassword(const OUString &rPass) override
virtual OUString SAL_CALL getPassword() override
virtual sal_Bool SAL_CALL getRecommendReadOnly() override
virtual OUString SAL_CALL getPasswordToModify() override
virtual void SAL_CALL setRecommendReadOnly(sal_Bool bReadOnly) override
virtual void SAL_CALL select() override
rtl::Reference< PasswordContinuation > mxPassword
virtual css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > SAL_CALL getContinuations() override
css::uno::Reference< css::task::XInteractionAbort > mxAbort
virtual css::uno::Any SAL_CALL getRequest() override
bool bReadOnly
DocPasswordRequestType
Selects which UNO document password request type to use.
@ MS
Uses the standard com.sun.star.task.DocumentPasswordRequest request.
unsigned char sal_Bool