1*96de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*96de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*96de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*96de5490SAndrew Rist  * distributed with this work for additional information
6*96de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*96de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*96de5490SAndrew Rist  * "License"); you may not use this file except in compliance
9*96de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*96de5490SAndrew Rist  *
11*96de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*96de5490SAndrew Rist  *
13*96de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*96de5490SAndrew Rist  * software distributed under the License is distributed on an
15*96de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*96de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
17*96de5490SAndrew Rist  * specific language governing permissions and limitations
18*96de5490SAndrew Rist  * under the License.
19*96de5490SAndrew Rist  *
20*96de5490SAndrew Rist  *************************************************************/
21*96de5490SAndrew Rist 
22*96de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "docinteraction.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir /** === begin UNO includes === **/
30cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
31cdf0e10cSrcweir #include <com/sun/star/task/DocumentPasswordRequest.hpp>
32cdf0e10cSrcweir /** === end UNO includes === **/
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <comphelper/componentcontext.hxx>
35cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx>
36cdf0e10cSrcweir #include <comphelper/interaction.hxx>
37cdf0e10cSrcweir #include <rtl/ref.hxx>
38cdf0e10cSrcweir #include <tools/diagnose_ex.h>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir //........................................................................
41cdf0e10cSrcweir namespace dbmm
42cdf0e10cSrcweir {
43cdf0e10cSrcweir //........................................................................
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 	/** === begin UNO using === **/
46cdf0e10cSrcweir 	using ::com::sun::star::uno::Reference;
47cdf0e10cSrcweir 	using ::com::sun::star::uno::XInterface;
48cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_QUERY;
49cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_QUERY_THROW;
50cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_SET_THROW;
51cdf0e10cSrcweir 	using ::com::sun::star::uno::Exception;
52cdf0e10cSrcweir 	using ::com::sun::star::uno::RuntimeException;
53cdf0e10cSrcweir 	using ::com::sun::star::uno::Any;
54cdf0e10cSrcweir 	using ::com::sun::star::uno::makeAny;
55cdf0e10cSrcweir     using ::com::sun::star::task::XInteractionHandler;
56cdf0e10cSrcweir     using ::com::sun::star::frame::XModel;
57cdf0e10cSrcweir     using ::com::sun::star::task::DocumentPasswordRequest;
58cdf0e10cSrcweir     using ::com::sun::star::task::InteractionClassification_QUERY;
59cdf0e10cSrcweir     using ::com::sun::star::task::PasswordRequestMode_PASSWORD_ENTER;
60cdf0e10cSrcweir     using ::com::sun::star::task::PasswordRequestMode_PASSWORD_REENTER;
61cdf0e10cSrcweir 	/** === end UNO using === **/
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 	//====================================================================
64cdf0e10cSrcweir 	//= InteractionHandler_Data
65cdf0e10cSrcweir 	//====================================================================
66cdf0e10cSrcweir     struct InteractionHandler_Data
67cdf0e10cSrcweir     {
68cdf0e10cSrcweir         Reference< XInteractionHandler >    xHandler;
69cdf0e10cSrcweir 
InteractionHandler_Datadbmm::InteractionHandler_Data70cdf0e10cSrcweir         InteractionHandler_Data( const Reference< XInteractionHandler >& _rxHandler )
71cdf0e10cSrcweir             :xHandler( _rxHandler )
72cdf0e10cSrcweir         {
73cdf0e10cSrcweir         }
74cdf0e10cSrcweir 
InteractionHandler_Datadbmm::InteractionHandler_Data75cdf0e10cSrcweir         InteractionHandler_Data( const ::comphelper::ComponentContext& _rContext )
76cdf0e10cSrcweir             :xHandler( _rContext.createComponent( "com.sun.star.task.InteractionHandler" ), UNO_QUERY_THROW )
77cdf0e10cSrcweir         {
78cdf0e10cSrcweir         }
79cdf0e10cSrcweir     };
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 	//====================================================================
82cdf0e10cSrcweir 	//= InteractionHandler
83cdf0e10cSrcweir 	//====================================================================
84cdf0e10cSrcweir 	//--------------------------------------------------------------------
InteractionHandler(const::comphelper::ComponentContext & _rContext,const Reference<XModel> & _rxDocument)85cdf0e10cSrcweir     InteractionHandler::InteractionHandler( const ::comphelper::ComponentContext& _rContext, const Reference< XModel >& _rxDocument )
86cdf0e10cSrcweir         :m_pData( new InteractionHandler_Data( _rContext ) )
87cdf0e10cSrcweir     {
88cdf0e10cSrcweir         // check whether the doumentc has an own interaction handler set
89cdf0e10cSrcweir         ::comphelper::NamedValueCollection aDocArgs( _rxDocument->getArgs() );
90cdf0e10cSrcweir         m_pData->xHandler = aDocArgs.getOrDefault( "InteractionHandler", m_pData->xHandler );
91cdf0e10cSrcweir     }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 	//--------------------------------------------------------------------
~InteractionHandler()94cdf0e10cSrcweir     InteractionHandler::~InteractionHandler()
95cdf0e10cSrcweir     {
96cdf0e10cSrcweir     }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 	//--------------------------------------------------------------------
requestDocumentPassword(const::rtl::OUString & _rDocumentName,::rtl::OUString & _io_rPassword)99cdf0e10cSrcweir     bool InteractionHandler::requestDocumentPassword( const ::rtl::OUString& _rDocumentName, ::rtl::OUString& _io_rPassword )
100cdf0e10cSrcweir     {
101cdf0e10cSrcweir         // create request
102cdf0e10cSrcweir         DocumentPasswordRequest aRequest(
103cdf0e10cSrcweir             ::rtl::OUString(), NULL,
104cdf0e10cSrcweir             InteractionClassification_QUERY,
105cdf0e10cSrcweir             _io_rPassword.getLength() ? PasswordRequestMode_PASSWORD_REENTER : PasswordRequestMode_PASSWORD_ENTER,
106cdf0e10cSrcweir             _rDocumentName
107cdf0e10cSrcweir         );
108cdf0e10cSrcweir 
109cdf0e10cSrcweir         ::rtl::Reference< ::comphelper::OInteractionRequest > pRequest( new ::comphelper::OInteractionRequest( makeAny( aRequest ) ) );
110cdf0e10cSrcweir         ::rtl::Reference< ::comphelper::OInteractionPassword > pPassword( new ::comphelper::OInteractionPassword( _io_rPassword ) );
111cdf0e10cSrcweir         ::rtl::Reference< ::comphelper::OInteractionAbort > pAbort( new ::comphelper::OInteractionAbort );
112cdf0e10cSrcweir         pRequest->addContinuation( pPassword.get() );
113cdf0e10cSrcweir         pRequest->addContinuation( pAbort.get() );
114cdf0e10cSrcweir 
115cdf0e10cSrcweir         // handle
116cdf0e10cSrcweir         m_pData->xHandler->handle( pRequest.get() );
117cdf0e10cSrcweir 
118cdf0e10cSrcweir         // finish up
119cdf0e10cSrcweir         if ( pAbort->wasSelected() )
120cdf0e10cSrcweir             return false;
121cdf0e10cSrcweir 
122cdf0e10cSrcweir         _io_rPassword = pPassword->getPassword();
123cdf0e10cSrcweir         return true;
124cdf0e10cSrcweir     }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 	//--------------------------------------------------------------------
reportError(const Any & _rError)127cdf0e10cSrcweir     void InteractionHandler::reportError( const Any& _rError )
128cdf0e10cSrcweir     {
129cdf0e10cSrcweir         ::rtl::Reference< ::comphelper::OInteractionRequest > pRequest( new ::comphelper::OInteractionRequest( _rError ) );
130cdf0e10cSrcweir         ::rtl::Reference< ::comphelper::OInteractionApprove > pApprove( new ::comphelper::OInteractionApprove );
131cdf0e10cSrcweir         pRequest->addContinuation( pApprove.get() );
132cdf0e10cSrcweir 
133cdf0e10cSrcweir         m_pData->xHandler->handle( pRequest.get() );
134cdf0e10cSrcweir     }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir //........................................................................
137cdf0e10cSrcweir } // namespace dbmm
138cdf0e10cSrcweir //........................................................................
139