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>
27 #include <cppuhelper/implbase.hxx>
28 
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;
41 
42 namespace comphelper {
43 
44 namespace {
45 
46 class AbortContinuation : public ::cppu::WeakImplHelper< XInteractionAbort >
47 {
48 public:
49  virtual void SAL_CALL select() override {}
50 };
51 
52 }
53 
54 class PasswordContinuation : public ::cppu::WeakImplHelper< XInteractionPassword2 >
55 {
56 public:
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 
72 private:
73  OUString maPassword;
74  OUString maModifyPassword;
75  bool mbReadOnly;
76  bool mbSelected;
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 
109 Sequence< Reference< XInteractionContinuation > > SAL_CALL SimplePasswordRequest::getContinuations()
110 {
111  return { mxAbort.get(), mxPassword.get() };
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 
171 Sequence< Reference< XInteractionContinuation > > SAL_CALL DocPasswordRequest::getContinuations()
172 {
173  return { mxAbort.get(), mxPassword.get() };
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
virtual OUString SAL_CALL getPassword() override
virtual void SAL_CALL select() override
DocPasswordRequest(DocPasswordRequestType eType, css::task::PasswordRequestMode eMode, const OUString &rDocumentUrl, bool bPasswordToModify=false)
virtual void SAL_CALL setPassword(const OUString &rPass) override
virtual sal_Bool SAL_CALL getRecommendReadOnly() override
rtl::Reference< PasswordContinuation > mxPassword
virtual css::uno::Any SAL_CALL getRequest() override
unsigned char sal_Bool
css::uno::Reference< css::task::XInteractionAbort > mxAbort
DocPasswordRequestType
Selects which UNO document password request type to use.
css::uno::Reference< css::task::XInteractionAbort > mxAbort
virtual void SAL_CALL setRecommendReadOnly(sal_Bool bReadOnly) override
virtual css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > SAL_CALL getContinuations() override
virtual void SAL_CALL setPasswordToModify(const OUString &rPass) override
virtual css::uno::Any SAL_CALL getRequest() override
Uses the standard com.sun.star.task.DocumentPasswordRequest request.
virtual OUString SAL_CALL getPasswordToModify() override
rtl::Reference< PasswordContinuation > mxPassword