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 "docinteraction.hxx"
22 :
23 : #include <com/sun/star/frame/XModel.hpp>
24 : #include <com/sun/star/task/InteractionHandler.hpp>
25 : #include <com/sun/star/task/DocumentPasswordRequest.hpp>
26 :
27 : #include <comphelper/componentcontext.hxx>
28 : #include <comphelper/namedvaluecollection.hxx>
29 : #include <comphelper/interaction.hxx>
30 : #include <rtl/ref.hxx>
31 : #include <tools/diagnose_ex.h>
32 :
33 : //........................................................................
34 : namespace dbmm
35 : {
36 : //........................................................................
37 :
38 : /** === begin UNO using === **/
39 : using ::com::sun::star::uno::Reference;
40 : using ::com::sun::star::uno::XInterface;
41 : using ::com::sun::star::uno::UNO_QUERY;
42 : using ::com::sun::star::uno::UNO_QUERY_THROW;
43 : using ::com::sun::star::uno::UNO_SET_THROW;
44 : using ::com::sun::star::uno::Exception;
45 : using ::com::sun::star::uno::RuntimeException;
46 : using ::com::sun::star::uno::Any;
47 : using ::com::sun::star::uno::makeAny;
48 : using ::com::sun::star::task::XInteractionHandler;
49 : using ::com::sun::star::frame::XModel;
50 : using ::com::sun::star::task::DocumentPasswordRequest;
51 : using ::com::sun::star::task::InteractionClassification_QUERY;
52 : using ::com::sun::star::task::PasswordRequestMode_PASSWORD_ENTER;
53 : using ::com::sun::star::task::PasswordRequestMode_PASSWORD_REENTER;
54 : /** === end UNO using === **/
55 :
56 : //====================================================================
57 : //= InteractionHandler_Data
58 : //====================================================================
59 0 : struct InteractionHandler_Data
60 : {
61 : Reference< XInteractionHandler > xHandler;
62 :
63 : InteractionHandler_Data( const Reference< XInteractionHandler >& _rxHandler )
64 : :xHandler( _rxHandler )
65 : {
66 : }
67 :
68 0 : InteractionHandler_Data( const ::comphelper::ComponentContext& _rContext )
69 0 : :xHandler( ::com::sun::star::task::InteractionHandler::createWithParent(_rContext.getUNOContext(), 0), UNO_QUERY )
70 : {
71 0 : }
72 : };
73 :
74 : //====================================================================
75 : //= InteractionHandler
76 : //====================================================================
77 : //--------------------------------------------------------------------
78 0 : InteractionHandler::InteractionHandler( const ::comphelper::ComponentContext& _rContext, const Reference< XModel >& _rxDocument )
79 0 : :m_pData( new InteractionHandler_Data( _rContext ) )
80 : {
81 : // check whether the doumentc has an own interaction handler set
82 0 : ::comphelper::NamedValueCollection aDocArgs( _rxDocument->getArgs() );
83 0 : m_pData->xHandler = aDocArgs.getOrDefault( "InteractionHandler", m_pData->xHandler );
84 0 : }
85 :
86 : //--------------------------------------------------------------------
87 0 : InteractionHandler::~InteractionHandler()
88 : {
89 0 : }
90 :
91 : //--------------------------------------------------------------------
92 0 : bool InteractionHandler::requestDocumentPassword( const ::rtl::OUString& _rDocumentName, ::rtl::OUString& _io_rPassword )
93 : {
94 : // create request
95 : DocumentPasswordRequest aRequest(
96 : ::rtl::OUString(), NULL,
97 : InteractionClassification_QUERY,
98 0 : _io_rPassword.isEmpty() ? PasswordRequestMode_PASSWORD_ENTER : PasswordRequestMode_PASSWORD_REENTER,
99 : _rDocumentName
100 0 : );
101 :
102 0 : ::rtl::Reference< ::comphelper::OInteractionRequest > pRequest( new ::comphelper::OInteractionRequest( makeAny( aRequest ) ) );
103 0 : ::rtl::Reference< ::comphelper::OInteractionPassword > pPassword( new ::comphelper::OInteractionPassword( _io_rPassword ) );
104 0 : ::rtl::Reference< ::comphelper::OInteractionAbort > pAbort( new ::comphelper::OInteractionAbort );
105 0 : pRequest->addContinuation( pPassword.get() );
106 0 : pRequest->addContinuation( pAbort.get() );
107 :
108 : // handle
109 0 : m_pData->xHandler->handle( pRequest.get() );
110 :
111 : // finish up
112 0 : if ( pAbort->wasSelected() )
113 0 : return false;
114 :
115 0 : _io_rPassword = pPassword->getPassword();
116 0 : return true;
117 : }
118 :
119 : //--------------------------------------------------------------------
120 0 : void InteractionHandler::reportError( const Any& _rError )
121 : {
122 0 : ::rtl::Reference< ::comphelper::OInteractionRequest > pRequest( new ::comphelper::OInteractionRequest( _rError ) );
123 0 : ::rtl::Reference< ::comphelper::OInteractionApprove > pApprove( new ::comphelper::OInteractionApprove );
124 0 : pRequest->addContinuation( pApprove.get() );
125 :
126 0 : m_pData->xHandler->handle( pRequest.get() );
127 0 : }
128 :
129 : //........................................................................
130 : } // namespace dbmm
131 : //........................................................................
132 :
133 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|