LCOV - code coverage report
Current view: top level - dbaccess/source/ext/macromigration - docinteraction.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 30 0.0 %
Date: 2014-04-14 Functions: 0 6 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10