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