bump product version to 4.1.6.2
[LibreOffice.git] / comphelper / source / misc / docpasswordrequest.cxx
bloba674f7246026d808630f68e34eb458239a8ac4a7
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>
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;
44 namespace comphelper {
46 // ============================================================================
48 class AbortContinuation : public ::cppu::WeakImplHelper1< XInteractionAbort >
50 public:
51 inline explicit AbortContinuation() : mbSelected( false ) {}
53 inline sal_Bool isSelected() const { return mbSelected; }
54 inline void reset() { mbSelected = false; }
56 virtual void SAL_CALL select() throw( RuntimeException ) { mbSelected = true; }
58 private:
59 sal_Bool mbSelected;
62 // ============================================================================
64 class PasswordContinuation : public ::cppu::WeakImplHelper1< XInteractionPassword2 >
66 public:
67 inline explicit PasswordContinuation() : mbReadOnly( sal_False ), mbSelected( sal_False ) {}
69 inline sal_Bool isSelected() const { return mbSelected; }
70 inline void reset() { mbSelected = sal_False; }
72 virtual void SAL_CALL select() throw( RuntimeException ) { mbSelected = sal_True; }
74 virtual void SAL_CALL setPassword( const OUString& rPass ) throw( RuntimeException ) { maPassword = rPass; }
75 virtual OUString SAL_CALL getPassword() throw( RuntimeException ) { return maPassword; }
77 virtual void SAL_CALL setPasswordToModify( const OUString& rPass ) throw( RuntimeException ) { maModifyPassword = rPass; }
78 virtual OUString SAL_CALL getPasswordToModify() throw( RuntimeException ) { return maModifyPassword; }
80 virtual void SAL_CALL setRecommendReadOnly( sal_Bool bReadOnly ) throw( RuntimeException ) { mbReadOnly = bReadOnly; }
81 virtual sal_Bool SAL_CALL getRecommendReadOnly() throw( RuntimeException ) { return mbReadOnly; }
83 private:
84 OUString maPassword;
85 OUString maModifyPassword;
86 sal_Bool mbReadOnly;
87 sal_Bool mbSelected;
90 // ============================================================================
92 SimplePasswordRequest::SimplePasswordRequest( PasswordRequestMode eMode )
93 : mpAbort( NULL )
94 , mpPassword( NULL )
96 PasswordRequest aRequest( OUString(), Reference< XInterface >(),
97 InteractionClassification_QUERY, eMode );
98 maRequest <<= aRequest;
100 maContinuations.realloc( 2 );
101 maContinuations[ 0 ].set( mpAbort = new AbortContinuation );
102 maContinuations[ 1 ].set( mpPassword = new PasswordContinuation );
105 SimplePasswordRequest::~SimplePasswordRequest()
109 /*uno::*/Any SAL_CALL SimplePasswordRequest::queryInterface( const /*uno::*/Type& rType ) throw (RuntimeException)
111 return ::cppu::queryInterface ( rType,
112 // OWeakObject interfaces
113 dynamic_cast< XInterface* > ( (XInteractionRequest *) this ),
114 static_cast< XWeak* > ( this ),
115 // my own interfaces
116 static_cast< XInteractionRequest* > ( this ) );
119 void SAL_CALL SimplePasswordRequest::acquire( ) throw ()
121 OWeakObject::acquire();
124 void SAL_CALL SimplePasswordRequest::release( ) throw ()
126 OWeakObject::release();
129 sal_Bool SimplePasswordRequest::isPassword() const
131 return mpPassword->isSelected();
134 OUString SimplePasswordRequest::getPassword() const
136 return mpPassword->getPassword();
139 Any SAL_CALL SimplePasswordRequest::getRequest() throw( RuntimeException )
141 return maRequest;
144 Sequence< Reference< XInteractionContinuation > > SAL_CALL SimplePasswordRequest::getContinuations() throw( RuntimeException )
146 return maContinuations;
149 // ============================================================================
151 DocPasswordRequest::DocPasswordRequest( DocPasswordRequestType eType,
152 PasswordRequestMode eMode, const OUString& rDocumentName, sal_Bool bPasswordToModify )
153 : mpAbort( NULL )
154 , mpPassword( NULL )
156 switch( eType )
158 case DocPasswordRequestType_STANDARD:
160 DocumentPasswordRequest2 aRequest( OUString(), Reference< XInterface >(),
161 InteractionClassification_QUERY, eMode, rDocumentName, bPasswordToModify );
162 maRequest <<= aRequest;
164 break;
165 case DocPasswordRequestType_MS:
167 DocumentMSPasswordRequest2 aRequest( OUString(), Reference< XInterface >(),
168 InteractionClassification_QUERY, eMode, rDocumentName, bPasswordToModify );
169 maRequest <<= aRequest;
171 break;
172 /* no 'default', so compilers will complain about missing
173 implementation of a new enum value. */
176 maContinuations.realloc( 2 );
177 maContinuations[ 0 ].set( mpAbort = new AbortContinuation );
178 maContinuations[ 1 ].set( mpPassword = new PasswordContinuation );
181 DocPasswordRequest::~DocPasswordRequest()
185 /*uno::*/Any SAL_CALL DocPasswordRequest::queryInterface( const /*uno::*/Type& rType ) throw (RuntimeException)
187 return ::cppu::queryInterface ( rType,
188 // OWeakObject interfaces
189 dynamic_cast< XInterface* > ( (XInteractionRequest *) this ),
190 static_cast< XWeak* > ( this ),
191 // my own interfaces
192 static_cast< XInteractionRequest* > ( this ) );
195 void SAL_CALL DocPasswordRequest::acquire( ) throw ()
197 OWeakObject::acquire();
200 void SAL_CALL DocPasswordRequest::release( ) throw ()
202 OWeakObject::release();
205 sal_Bool DocPasswordRequest::isPassword() const
207 return mpPassword->isSelected();
210 OUString DocPasswordRequest::getPassword() const
212 return mpPassword->getPassword();
215 OUString DocPasswordRequest::getPasswordToModify() const
217 return mpPassword->getPasswordToModify();
220 sal_Bool DocPasswordRequest::getRecommendReadOnly() const
222 return mpPassword->getRecommendReadOnly();
225 Any SAL_CALL DocPasswordRequest::getRequest() throw( RuntimeException )
227 return maRequest;
230 Sequence< Reference< XInteractionContinuation > > SAL_CALL DocPasswordRequest::getContinuations() throw( RuntimeException )
232 return maContinuations;
235 // ============================================================================
237 } // namespace comphelper
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */