2010-10-14 08:27:31 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-29 14:02:24 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2009-09-07 14:41:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include "comphelper/docpasswordrequest.hxx"
|
2010-03-30 16:47:18 +02:00
|
|
|
#include <com/sun/star/task/DocumentMSPasswordRequest2.hpp>
|
|
|
|
#include <com/sun/star/task/DocumentPasswordRequest2.hpp>
|
2010-09-06 10:02:33 +02:00
|
|
|
#include <com/sun/star/task/PasswordRequest.hpp>
|
2009-09-07 14:41:16 +00:00
|
|
|
#include <com/sun/star/task/XInteractionAbort.hpp>
|
2010-03-30 16:47:18 +02:00
|
|
|
#include <com/sun/star/task/XInteractionPassword2.hpp>
|
2009-09-07 14:41:16 +00:00
|
|
|
|
|
|
|
using ::com::sun::star::uno::Any;
|
2010-05-07 10:40:12 +02:00
|
|
|
using ::com::sun::star::uno::Type;
|
2009-09-07 14:41:16 +00:00
|
|
|
using ::com::sun::star::uno::Reference;
|
|
|
|
using ::com::sun::star::uno::RuntimeException;
|
|
|
|
using ::com::sun::star::uno::Sequence;
|
|
|
|
using ::com::sun::star::uno::XInterface;
|
|
|
|
using ::com::sun::star::task::InteractionClassification_QUERY;
|
2010-03-30 16:47:18 +02:00
|
|
|
using ::com::sun::star::task::DocumentMSPasswordRequest2;
|
|
|
|
using ::com::sun::star::task::DocumentPasswordRequest2;
|
2010-09-06 10:02:33 +02:00
|
|
|
using ::com::sun::star::task::PasswordRequest;
|
2009-09-07 14:41:16 +00:00
|
|
|
using ::com::sun::star::task::PasswordRequestMode;
|
|
|
|
using ::com::sun::star::task::XInteractionAbort;
|
|
|
|
using ::com::sun::star::task::XInteractionContinuation;
|
2010-03-30 16:47:18 +02:00
|
|
|
using ::com::sun::star::task::XInteractionPassword2;
|
2010-05-07 10:40:12 +02:00
|
|
|
using ::com::sun::star::task::XInteractionRequest;
|
2009-09-07 14:41:16 +00:00
|
|
|
|
|
|
|
namespace comphelper {
|
|
|
|
|
2014-02-25 17:52:30 +01:00
|
|
|
|
2009-09-07 14:41:16 +00:00
|
|
|
|
|
|
|
class AbortContinuation : public ::cppu::WeakImplHelper1< XInteractionAbort >
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
inline explicit AbortContinuation() : mbSelected( false ) {}
|
|
|
|
|
2014-02-16 22:51:15 +01:00
|
|
|
inline bool isSelected() const { return mbSelected; }
|
2009-09-07 14:41:16 +00:00
|
|
|
inline void reset() { mbSelected = false; }
|
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
virtual void SAL_CALL select() throw( RuntimeException, std::exception ) { mbSelected = true; }
|
2009-09-07 14:41:16 +00:00
|
|
|
|
|
|
|
private:
|
2014-02-16 22:51:15 +01:00
|
|
|
bool mbSelected;
|
2009-09-07 14:41:16 +00:00
|
|
|
};
|
|
|
|
|
2014-02-25 17:52:30 +01:00
|
|
|
|
2009-09-07 14:41:16 +00:00
|
|
|
|
2010-03-30 16:47:18 +02:00
|
|
|
class PasswordContinuation : public ::cppu::WeakImplHelper1< XInteractionPassword2 >
|
2009-09-07 14:41:16 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-02-16 22:51:15 +01:00
|
|
|
inline explicit PasswordContinuation() : mbReadOnly( false ), mbSelected( false ) {}
|
2009-09-07 14:41:16 +00:00
|
|
|
|
2014-02-16 22:51:15 +01:00
|
|
|
inline bool isSelected() const { return mbSelected; }
|
|
|
|
inline void reset() { mbSelected = false; }
|
2010-03-30 16:47:18 +02:00
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
virtual void SAL_CALL select() throw( RuntimeException, std::exception ) { mbSelected = true; }
|
2009-09-07 14:41:16 +00:00
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
virtual void SAL_CALL setPassword( const OUString& rPass ) throw( RuntimeException, std::exception ) { maPassword = rPass; }
|
|
|
|
virtual OUString SAL_CALL getPassword() throw( RuntimeException, std::exception ) { return maPassword; }
|
2009-09-07 14:41:16 +00:00
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
virtual void SAL_CALL setPasswordToModify( const OUString& rPass ) throw( RuntimeException, std::exception ) { maModifyPassword = rPass; }
|
|
|
|
virtual OUString SAL_CALL getPasswordToModify() throw( RuntimeException, std::exception ) { return maModifyPassword; }
|
2010-03-30 16:47:18 +02:00
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
virtual void SAL_CALL setRecommendReadOnly( sal_Bool bReadOnly ) throw( RuntimeException, std::exception ) { mbReadOnly = bReadOnly; }
|
|
|
|
virtual sal_Bool SAL_CALL getRecommendReadOnly() throw( RuntimeException, std::exception ) { return mbReadOnly; }
|
2010-03-30 16:47:18 +02:00
|
|
|
|
2009-09-07 14:41:16 +00:00
|
|
|
private:
|
|
|
|
OUString maPassword;
|
2010-03-30 16:47:18 +02:00
|
|
|
OUString maModifyPassword;
|
2014-02-16 22:51:15 +01:00
|
|
|
bool mbReadOnly;
|
|
|
|
bool mbSelected;
|
2009-09-07 14:41:16 +00:00
|
|
|
};
|
|
|
|
|
2014-02-25 17:52:30 +01:00
|
|
|
|
2009-09-07 14:41:16 +00:00
|
|
|
|
2010-09-06 10:02:33 +02:00
|
|
|
SimplePasswordRequest::SimplePasswordRequest( PasswordRequestMode eMode )
|
|
|
|
: mpAbort( NULL )
|
|
|
|
, mpPassword( NULL )
|
|
|
|
{
|
|
|
|
PasswordRequest aRequest( OUString(), Reference< XInterface >(),
|
|
|
|
InteractionClassification_QUERY, eMode );
|
|
|
|
maRequest <<= aRequest;
|
|
|
|
|
|
|
|
maContinuations.realloc( 2 );
|
|
|
|
maContinuations[ 0 ].set( mpAbort = new AbortContinuation );
|
|
|
|
maContinuations[ 1 ].set( mpPassword = new PasswordContinuation );
|
|
|
|
}
|
|
|
|
|
|
|
|
SimplePasswordRequest::~SimplePasswordRequest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-16 22:51:15 +01:00
|
|
|
bool SimplePasswordRequest::isPassword() const
|
2010-09-06 10:02:33 +02:00
|
|
|
{
|
|
|
|
return mpPassword->isSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString SimplePasswordRequest::getPassword() const
|
|
|
|
{
|
|
|
|
return mpPassword->getPassword();
|
|
|
|
}
|
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
Any SAL_CALL SimplePasswordRequest::getRequest() throw( RuntimeException, std::exception )
|
2010-09-06 10:02:33 +02:00
|
|
|
{
|
|
|
|
return maRequest;
|
|
|
|
}
|
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
Sequence< Reference< XInteractionContinuation > > SAL_CALL SimplePasswordRequest::getContinuations() throw( RuntimeException, std::exception )
|
2010-09-06 10:02:33 +02:00
|
|
|
{
|
|
|
|
return maContinuations;
|
|
|
|
}
|
|
|
|
|
2014-02-25 17:52:30 +01:00
|
|
|
|
2010-09-06 10:02:33 +02:00
|
|
|
|
2009-09-07 14:41:16 +00:00
|
|
|
DocPasswordRequest::DocPasswordRequest( DocPasswordRequestType eType,
|
2014-02-16 22:51:15 +01:00
|
|
|
PasswordRequestMode eMode, const OUString& rDocumentName, bool bPasswordToModify )
|
2010-03-30 16:47:18 +02:00
|
|
|
: mpAbort( NULL )
|
|
|
|
, mpPassword( NULL )
|
2009-09-07 14:41:16 +00:00
|
|
|
{
|
|
|
|
switch( eType )
|
|
|
|
{
|
|
|
|
case DocPasswordRequestType_STANDARD:
|
|
|
|
{
|
2010-03-30 16:47:18 +02:00
|
|
|
DocumentPasswordRequest2 aRequest( OUString(), Reference< XInterface >(),
|
|
|
|
InteractionClassification_QUERY, eMode, rDocumentName, bPasswordToModify );
|
2009-09-07 14:41:16 +00:00
|
|
|
maRequest <<= aRequest;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DocPasswordRequestType_MS:
|
|
|
|
{
|
2010-03-30 16:47:18 +02:00
|
|
|
DocumentMSPasswordRequest2 aRequest( OUString(), Reference< XInterface >(),
|
|
|
|
InteractionClassification_QUERY, eMode, rDocumentName, bPasswordToModify );
|
2009-09-07 14:41:16 +00:00
|
|
|
maRequest <<= aRequest;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
/* no 'default', so compilers will complain about missing
|
|
|
|
implementation of a new enum value. */
|
|
|
|
}
|
|
|
|
|
|
|
|
maContinuations.realloc( 2 );
|
|
|
|
maContinuations[ 0 ].set( mpAbort = new AbortContinuation );
|
|
|
|
maContinuations[ 1 ].set( mpPassword = new PasswordContinuation );
|
|
|
|
}
|
|
|
|
|
|
|
|
DocPasswordRequest::~DocPasswordRequest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-16 22:51:15 +01:00
|
|
|
bool DocPasswordRequest::isPassword() const
|
2009-09-07 14:41:16 +00:00
|
|
|
{
|
|
|
|
return mpPassword->isSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString DocPasswordRequest::getPassword() const
|
|
|
|
{
|
|
|
|
return mpPassword->getPassword();
|
|
|
|
}
|
|
|
|
|
2010-03-30 16:47:18 +02:00
|
|
|
OUString DocPasswordRequest::getPasswordToModify() const
|
|
|
|
{
|
|
|
|
return mpPassword->getPasswordToModify();
|
|
|
|
}
|
|
|
|
|
2014-02-16 22:51:15 +01:00
|
|
|
bool DocPasswordRequest::getRecommendReadOnly() const
|
2010-03-30 16:47:18 +02:00
|
|
|
{
|
|
|
|
return mpPassword->getRecommendReadOnly();
|
|
|
|
}
|
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
Any SAL_CALL DocPasswordRequest::getRequest() throw( RuntimeException, std::exception )
|
2009-09-07 14:41:16 +00:00
|
|
|
{
|
|
|
|
return maRequest;
|
|
|
|
}
|
|
|
|
|
2014-02-25 21:31:58 +01:00
|
|
|
Sequence< Reference< XInteractionContinuation > > SAL_CALL DocPasswordRequest::getContinuations() throw( RuntimeException, std::exception )
|
2009-09-07 14:41:16 +00:00
|
|
|
{
|
|
|
|
return maContinuations;
|
|
|
|
}
|
|
|
|
|
2014-02-25 17:52:30 +01:00
|
|
|
|
2009-09-07 14:41:16 +00:00
|
|
|
|
|
|
|
} // namespace comphelper
|
|
|
|
|
2010-10-14 08:27:31 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|