Some clean up

Change-Id: Ia17a714b55da06bd38c7b5d60881f1b3838da992
This commit is contained in:
Stephan Bergmann
2012-09-29 13:43:20 +02:00
parent dec68c6684
commit f05d7abf93

View File

@@ -40,9 +40,10 @@
#include <com/sun/star/task/DocumentPasswordRequest.hpp> #include <com/sun/star/task/DocumentPasswordRequest.hpp>
#include <cppuhelper/exc_hlp.hxx> #include <cppuhelper/exc_hlp.hxx>
#include <cppuhelper/compbase2.hxx>
#include <cppuhelper/implbase1.hxx> #include <cppuhelper/implbase1.hxx>
#include <cppuhelper/basemutex.hxx> #include <cppuhelper/implbase2.hxx>
#include <osl/mutex.hxx>
#include <rtl/ref.hxx>
#include <tools/errcode.hxx> #include <tools/errcode.hxx>
using namespace com::sun::star; using namespace com::sun::star;
@@ -50,15 +51,14 @@ using namespace com::sun::star;
namespace namespace
{ {
typedef ::cppu::WeakComponentImplHelper2< class PDFPasswordRequest:
com::sun::star::task::XInteractionRequest, public cppu::WeakImplHelper2<
com::sun::star::task::XInteractionPassword > PDFPasswordRequestBase; task::XInteractionRequest, task::XInteractionPassword >,
private boost::noncopyable
class PDFPasswordRequest : private cppu::BaseMutex,
public PDFPasswordRequestBase
{ {
private: private:
task::DocumentPasswordRequest m_aRequest; mutable osl::Mutex m_aMutex;
uno::Any m_aRequest;
rtl::OUString m_aPassword; rtl::OUString m_aPassword;
bool m_bSelected; bool m_bSelected;
@@ -77,54 +77,51 @@ public:
virtual void SAL_CALL select() throw (uno::RuntimeException); virtual void SAL_CALL select() throw (uno::RuntimeException);
bool isSelected() const { osl::MutexGuard const guard( m_aMutex ); return m_bSelected; } bool isSelected() const { osl::MutexGuard const guard( m_aMutex ); return m_bSelected; }
private:
virtual ~PDFPasswordRequest() {}
}; };
PDFPasswordRequest::PDFPasswordRequest( bool bFirstTry, const rtl::OUString& rName ) : PDFPasswordRequest::PDFPasswordRequest( bool bFirstTry, const rtl::OUString& rName ) :
PDFPasswordRequestBase( m_aMutex ), m_aRequest(
m_aRequest(), uno::makeAny(
m_aPassword(), task::DocumentPasswordRequest(
OUString(), uno::Reference< uno::XInterface >(),
task::InteractionClassification_QUERY,
(bFirstTry
? task::PasswordRequestMode_PASSWORD_ENTER
: task::PasswordRequestMode_PASSWORD_REENTER),
rName))),
m_bSelected(false) m_bSelected(false)
{}
uno::Any PDFPasswordRequest::getRequest() throw (uno::RuntimeException)
{ {
m_aRequest.Mode = bFirstTry ? return m_aRequest;
task::PasswordRequestMode_PASSWORD_ENTER :
task::PasswordRequestMode_PASSWORD_REENTER;
m_aRequest.Classification = task::InteractionClassification_QUERY;
m_aRequest.Name = rName;
} }
uno::Any SAL_CALL PDFPasswordRequest::getRequest() throw (uno::RuntimeException) uno::Sequence< uno::Reference< task::XInteractionContinuation > > PDFPasswordRequest::getContinuations() throw (uno::RuntimeException)
{ {
osl::MutexGuard const guard( m_aMutex );
uno::Any aRet;
aRet <<= m_aRequest;
return aRet;
}
uno::Sequence< uno::Reference< task::XInteractionContinuation > > SAL_CALL PDFPasswordRequest::getContinuations() throw (uno::RuntimeException)
{
osl::MutexGuard const guard( m_aMutex );
uno::Sequence< uno::Reference< task::XInteractionContinuation > > aRet( 1 ); uno::Sequence< uno::Reference< task::XInteractionContinuation > > aRet( 1 );
aRet.getArray()[0] = static_cast<task::XInteractionContinuation*>(this); aRet[0] = this;
return aRet; return aRet;
} }
void SAL_CALL PDFPasswordRequest::setPassword( const rtl::OUString& rPwd ) throw (uno::RuntimeException) void PDFPasswordRequest::setPassword( const rtl::OUString& rPwd ) throw (uno::RuntimeException)
{ {
osl::MutexGuard const guard( m_aMutex ); osl::MutexGuard const guard( m_aMutex );
m_aPassword = rPwd; m_aPassword = rPwd;
} }
rtl::OUString SAL_CALL PDFPasswordRequest::getPassword() throw (uno::RuntimeException) rtl::OUString PDFPasswordRequest::getPassword() throw (uno::RuntimeException)
{ {
osl::MutexGuard const guard( m_aMutex ); osl::MutexGuard const guard( m_aMutex );
return m_aPassword; return m_aPassword;
} }
void SAL_CALL PDFPasswordRequest::select() throw (uno::RuntimeException) void PDFPasswordRequest::select() throw (uno::RuntimeException)
{ {
osl::MutexGuard const guard( m_aMutex ); osl::MutexGuard const guard( m_aMutex );
@@ -170,22 +167,21 @@ bool getPassword( const uno::Reference< task::XInteractionHandler >& xHandler,
{ {
bool bSuccess = false; bool bSuccess = false;
PDFPasswordRequest* pRequest; rtl::Reference< PDFPasswordRequest > xReq(
uno::Reference< task::XInteractionRequest > xReq( new PDFPasswordRequest( bFirstTry, rDocName ) );
pRequest = new PDFPasswordRequest( bFirstTry, rDocName ) );
try try
{ {
xHandler->handle( xReq ); xHandler->handle( xReq.get() );
} }
catch( uno::Exception& ) catch( uno::Exception& )
{ {
} }
OSL_TRACE( "request %s selected", pRequest->isSelected() ? "was" : "was not" ); OSL_TRACE( "request %s selected", xReq->isSelected() ? "was" : "was not" );
if( pRequest->isSelected() ) if( xReq->isSelected() )
{ {
bSuccess = true; bSuccess = true;
rOutPwd = pRequest->getPassword(); rOutPwd = xReq->getPassword();
} }
return bSuccess; return bSuccess;