Line data Source code
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 :
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 :
28 : using ::com::sun::star::uno::Any;
29 : using ::com::sun::star::uno::Type;
30 : using ::com::sun::star::uno::Reference;
31 : using ::com::sun::star::uno::RuntimeException;
32 : using ::com::sun::star::uno::Sequence;
33 : using ::com::sun::star::uno::XInterface;
34 : using ::com::sun::star::task::InteractionClassification_QUERY;
35 : using ::com::sun::star::task::DocumentMSPasswordRequest2;
36 : using ::com::sun::star::task::DocumentPasswordRequest2;
37 : using ::com::sun::star::task::PasswordRequest;
38 : using ::com::sun::star::task::PasswordRequestMode;
39 : using ::com::sun::star::task::XInteractionAbort;
40 : using ::com::sun::star::task::XInteractionContinuation;
41 : using ::com::sun::star::task::XInteractionPassword2;
42 : using ::com::sun::star::task::XInteractionRequest;
43 :
44 : namespace comphelper {
45 :
46 : // ============================================================================
47 :
48 0 : class AbortContinuation : public ::cppu::WeakImplHelper1< XInteractionAbort >
49 : {
50 : public:
51 0 : inline explicit AbortContinuation() : mbSelected( false ) {}
52 :
53 : inline sal_Bool isSelected() const { return mbSelected; }
54 : inline void reset() { mbSelected = false; }
55 :
56 0 : virtual void SAL_CALL select() throw( RuntimeException ) { mbSelected = true; }
57 :
58 : private:
59 : sal_Bool mbSelected;
60 : };
61 :
62 : // ============================================================================
63 :
64 0 : class PasswordContinuation : public ::cppu::WeakImplHelper1< XInteractionPassword2 >
65 : {
66 : public:
67 0 : inline explicit PasswordContinuation() : mbReadOnly( sal_False ), mbSelected( sal_False ) {}
68 :
69 0 : inline sal_Bool isSelected() const { return mbSelected; }
70 : inline void reset() { mbSelected = sal_False; }
71 :
72 0 : virtual void SAL_CALL select() throw( RuntimeException ) { mbSelected = sal_True; }
73 :
74 0 : virtual void SAL_CALL setPassword( const OUString& rPass ) throw( RuntimeException ) { maPassword = rPass; }
75 0 : virtual OUString SAL_CALL getPassword() throw( RuntimeException ) { return maPassword; }
76 :
77 0 : virtual void SAL_CALL setPasswordToModify( const OUString& rPass ) throw( RuntimeException ) { maModifyPassword = rPass; }
78 0 : virtual OUString SAL_CALL getPasswordToModify() throw( RuntimeException ) { return maModifyPassword; }
79 :
80 0 : virtual void SAL_CALL setRecommendReadOnly( sal_Bool bReadOnly ) throw( RuntimeException ) { mbReadOnly = bReadOnly; }
81 0 : virtual sal_Bool SAL_CALL getRecommendReadOnly() throw( RuntimeException ) { return mbReadOnly; }
82 :
83 : private:
84 : OUString maPassword;
85 : OUString maModifyPassword;
86 : sal_Bool mbReadOnly;
87 : sal_Bool mbSelected;
88 : };
89 :
90 : // ============================================================================
91 :
92 0 : SimplePasswordRequest::SimplePasswordRequest( PasswordRequestMode eMode )
93 : : mpAbort( NULL )
94 0 : , mpPassword( NULL )
95 : {
96 : PasswordRequest aRequest( OUString(), Reference< XInterface >(),
97 0 : InteractionClassification_QUERY, eMode );
98 0 : maRequest <<= aRequest;
99 :
100 0 : maContinuations.realloc( 2 );
101 0 : maContinuations[ 0 ].set( mpAbort = new AbortContinuation );
102 0 : maContinuations[ 1 ].set( mpPassword = new PasswordContinuation );
103 0 : }
104 :
105 0 : SimplePasswordRequest::~SimplePasswordRequest()
106 : {
107 0 : }
108 :
109 0 : /*uno::*/Any SAL_CALL SimplePasswordRequest::queryInterface( const /*uno::*/Type& rType ) throw (RuntimeException)
110 : {
111 : return ::cppu::queryInterface ( rType,
112 : // OWeakObject interfaces
113 : dynamic_cast< XInterface* > ( (XInteractionRequest *) this ),
114 : static_cast< XWeak* > ( this ),
115 : // my own interfaces
116 0 : static_cast< XInteractionRequest* > ( this ) );
117 : }
118 :
119 0 : void SAL_CALL SimplePasswordRequest::acquire( ) throw ()
120 : {
121 0 : OWeakObject::acquire();
122 0 : }
123 :
124 0 : void SAL_CALL SimplePasswordRequest::release( ) throw ()
125 : {
126 0 : OWeakObject::release();
127 0 : }
128 :
129 0 : sal_Bool SimplePasswordRequest::isPassword() const
130 : {
131 0 : return mpPassword->isSelected();
132 : }
133 :
134 0 : OUString SimplePasswordRequest::getPassword() const
135 : {
136 0 : return mpPassword->getPassword();
137 : }
138 :
139 0 : Any SAL_CALL SimplePasswordRequest::getRequest() throw( RuntimeException )
140 : {
141 0 : return maRequest;
142 : }
143 :
144 0 : Sequence< Reference< XInteractionContinuation > > SAL_CALL SimplePasswordRequest::getContinuations() throw( RuntimeException )
145 : {
146 0 : return maContinuations;
147 : }
148 :
149 : // ============================================================================
150 :
151 0 : DocPasswordRequest::DocPasswordRequest( DocPasswordRequestType eType,
152 : PasswordRequestMode eMode, const OUString& rDocumentName, sal_Bool bPasswordToModify )
153 : : mpAbort( NULL )
154 0 : , mpPassword( NULL )
155 : {
156 0 : switch( eType )
157 : {
158 : case DocPasswordRequestType_STANDARD:
159 : {
160 : DocumentPasswordRequest2 aRequest( OUString(), Reference< XInterface >(),
161 0 : InteractionClassification_QUERY, eMode, rDocumentName, bPasswordToModify );
162 0 : maRequest <<= aRequest;
163 : }
164 0 : break;
165 : case DocPasswordRequestType_MS:
166 : {
167 : DocumentMSPasswordRequest2 aRequest( OUString(), Reference< XInterface >(),
168 0 : InteractionClassification_QUERY, eMode, rDocumentName, bPasswordToModify );
169 0 : maRequest <<= aRequest;
170 : }
171 0 : break;
172 : /* no 'default', so compilers will complain about missing
173 : implementation of a new enum value. */
174 : }
175 :
176 0 : maContinuations.realloc( 2 );
177 0 : maContinuations[ 0 ].set( mpAbort = new AbortContinuation );
178 0 : maContinuations[ 1 ].set( mpPassword = new PasswordContinuation );
179 0 : }
180 :
181 0 : DocPasswordRequest::~DocPasswordRequest()
182 : {
183 0 : }
184 :
185 0 : /*uno::*/Any SAL_CALL DocPasswordRequest::queryInterface( const /*uno::*/Type& rType ) throw (RuntimeException)
186 : {
187 : return ::cppu::queryInterface ( rType,
188 : // OWeakObject interfaces
189 : dynamic_cast< XInterface* > ( (XInteractionRequest *) this ),
190 : static_cast< XWeak* > ( this ),
191 : // my own interfaces
192 0 : static_cast< XInteractionRequest* > ( this ) );
193 : }
194 :
195 0 : void SAL_CALL DocPasswordRequest::acquire( ) throw ()
196 : {
197 0 : OWeakObject::acquire();
198 0 : }
199 :
200 0 : void SAL_CALL DocPasswordRequest::release( ) throw ()
201 : {
202 0 : OWeakObject::release();
203 0 : }
204 :
205 0 : sal_Bool DocPasswordRequest::isPassword() const
206 : {
207 0 : return mpPassword->isSelected();
208 : }
209 :
210 0 : OUString DocPasswordRequest::getPassword() const
211 : {
212 0 : return mpPassword->getPassword();
213 : }
214 :
215 0 : OUString DocPasswordRequest::getPasswordToModify() const
216 : {
217 0 : return mpPassword->getPasswordToModify();
218 : }
219 :
220 0 : sal_Bool DocPasswordRequest::getRecommendReadOnly() const
221 : {
222 0 : return mpPassword->getRecommendReadOnly();
223 : }
224 :
225 0 : Any SAL_CALL DocPasswordRequest::getRequest() throw( RuntimeException )
226 : {
227 0 : return maRequest;
228 : }
229 :
230 0 : Sequence< Reference< XInteractionContinuation > > SAL_CALL DocPasswordRequest::getContinuations() throw( RuntimeException )
231 : {
232 0 : return maContinuations;
233 : }
234 :
235 : // ============================================================================
236 :
237 : } // namespace comphelper
238 :
239 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|