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 
45 class AbortContinuation : public ::cppu::WeakImplHelper< XInteractionAbort >
46 {
47 public:
48  virtual void SAL_CALL select() override {}
49 };
50 
51 
52 class PasswordContinuation : public ::cppu::WeakImplHelper< XInteractionPassword2 >
53 {
54 public:
55  explicit PasswordContinuation() : mbReadOnly( false ), mbSelected( false ) {}
56 
57  bool isSelected() const { return mbSelected; }
58 
59  virtual void SAL_CALL select() override { mbSelected = true; }
60 
61  virtual void SAL_CALL setPassword( const OUString& rPass ) override { maPassword = rPass; }
62  virtual OUString SAL_CALL getPassword() override { return maPassword; }
63 
64  virtual void SAL_CALL setPasswordToModify( const OUString& rPass ) override { maModifyPassword = rPass; }
65  virtual OUString SAL_CALL getPasswordToModify() override { return maModifyPassword; }
66 
67  virtual void SAL_CALL setRecommendReadOnly( sal_Bool bReadOnly ) override { mbReadOnly = bReadOnly; }
68  virtual sal_Bool SAL_CALL getRecommendReadOnly() override { return mbReadOnly; }
69 
70 private:
71  OUString maPassword;
72  OUString maModifyPassword;
73  bool mbReadOnly;
74  bool mbSelected;
75 };
76 
77 
79 {
80  PasswordRequest aRequest( OUString(), Reference< XInterface >(),
81  InteractionClassification_QUERY, css::task::PasswordRequestMode_PASSWORD_CREATE );
82  maRequest <<= aRequest;
83 
86 }
87 
89 {
90 }
91 
93 {
94  return mxPassword->isSelected();
95 }
96 
98 {
99  return mxPassword->getPassword();
100 }
101 
103 {
104  return maRequest;
105 }
106 
107 Sequence< Reference< XInteractionContinuation > > SAL_CALL SimplePasswordRequest::getContinuations()
108 {
109  return { mxAbort.get(), mxPassword.get() };
110 }
111 
112 
114  PasswordRequestMode eMode, const OUString& rDocumentUrl, bool bPasswordToModify )
115 {
116  switch( eType )
117  {
119  {
120  DocumentPasswordRequest2 aRequest( OUString(), Reference< XInterface >(),
121  InteractionClassification_QUERY, eMode, rDocumentUrl, bPasswordToModify );
122  maRequest <<= aRequest;
123  }
124  break;
126  {
127  DocumentMSPasswordRequest2 aRequest( OUString(), Reference< XInterface >(),
128  InteractionClassification_QUERY, eMode, rDocumentUrl, bPasswordToModify );
129  maRequest <<= aRequest;
130  }
131  break;
132  /* no 'default', so compilers will complain about missing
133  implementation of a new enum value. */
134  }
135 
136  mxAbort = new AbortContinuation;
137  mxPassword = new PasswordContinuation;
138 }
139 
141 {
142 }
143 
145 {
146  return mxPassword->isSelected();
147 }
148 
150 {
151  return mxPassword->getPassword();
152 }
153 
155 {
156  return mxPassword->getPasswordToModify();
157 }
158 
160 {
161  return mxPassword->getRecommendReadOnly();
162 }
163 
165 {
166  return maRequest;
167 }
168 
169 Sequence< Reference< XInteractionContinuation > > SAL_CALL DocPasswordRequest::getContinuations()
170 {
171  return { mxAbort.get(), mxPassword.get() };
172 }
173 
174 
175 } // namespace comphelper
176 
177 /* 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
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