LCOV - code coverage report
Current view: top level - dbaccess/source/ui/uno - dbinteraction.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 157 0.0 %
Date: 2014-04-14 Functions: 0 24 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 "dbinteraction.hxx"
      21             : #include "dbu_reghelper.hxx"
      22             : #include <tools/diagnose_ex.h>
      23             : #include <osl/diagnose.h>
      24             : #include <vcl/msgbox.hxx>
      25             : #include <connectivity/dbexception.hxx>
      26             : #include "sqlmessage.hxx"
      27             : #include <com/sun/star/task/InteractionHandler.hpp>
      28             : #include <com/sun/star/task/XInteractionApprove.hpp>
      29             : #include <com/sun/star/task/XInteractionDisapprove.hpp>
      30             : #include <com/sun/star/task/XInteractionRetry.hpp>
      31             : #include <com/sun/star/task/XInteractionAbort.hpp>
      32             : #include <com/sun/star/sdb/XInteractionSupplyParameters.hpp>
      33             : #include <com/sun/star/sdb/XInteractionDocumentSave.hpp>
      34             : #include <sfx2/QuerySaveDocument.hxx>
      35             : #include "dbu_uno.hrc"
      36             : #include "paramdialog.hxx"
      37             : #include <vcl/svapp.hxx>
      38             : #include <osl/mutex.hxx>
      39             : #include "CollectionView.hxx"
      40             : #include "UITools.hxx"
      41             : #include <comphelper/processfactory.hxx>
      42             : 
      43           0 : extern "C" void SAL_CALL createRegistryInfo_OInteractionHandler()
      44             : {
      45           0 :     static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::SQLExceptionInteractionHandler > aSQLExceptionInteractionHandler_AutoRegistration;
      46           0 :     static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::LegacyInteractionHandler > aLegacyInteractionHandler_AutoRegistration;
      47           0 : }
      48             : 
      49             : namespace dbaui
      50             : {
      51             :     using namespace ::com::sun::star::uno;
      52             :     using namespace ::com::sun::star::ucb;
      53             :     using namespace ::com::sun::star::sdb;
      54             :     using namespace ::com::sun::star::lang;
      55             :     using namespace ::com::sun::star::task;
      56             :     using namespace ::com::sun::star::beans;
      57             :     using namespace ::dbtools;
      58             : 
      59             :     // BasicInteractionHandler
      60           0 :     BasicInteractionHandler::BasicInteractionHandler( const Reference< XComponentContext >& rxContext, const bool i_bFallbackToGeneric )
      61             :         :m_xContext( rxContext )
      62           0 :         ,m_bFallbackToGeneric( i_bFallbackToGeneric )
      63             :     {
      64             :         OSL_ENSURE( !m_bFallbackToGeneric,
      65             :             "BasicInteractionHandler::BasicInteractionHandler: enabling legacy behavior, there should be no clients of this anymore!" );
      66           0 :     }
      67             : 
      68           0 :     sal_Bool SAL_CALL BasicInteractionHandler::handleInteractionRequest( const Reference< XInteractionRequest >& i_rRequest ) throw (RuntimeException, std::exception)
      69             :     {
      70           0 :         return impl_handle_throw( i_rRequest );
      71             :     }
      72             : 
      73           0 :     void SAL_CALL BasicInteractionHandler::handle( const Reference< XInteractionRequest >& i_rRequest ) throw(RuntimeException, std::exception)
      74             :     {
      75           0 :         impl_handle_throw( i_rRequest );
      76           0 :     }
      77             : 
      78           0 :     sal_Bool BasicInteractionHandler::impl_handle_throw( const Reference< XInteractionRequest >& i_Request )
      79             :     {
      80           0 :         Any aRequest( i_Request->getRequest() );
      81             :         OSL_ENSURE(aRequest.hasValue(), "BasicInteractionHandler::handle: invalid request!");
      82           0 :         if ( !aRequest.hasValue() )
      83             :             // no request -> no handling
      84           0 :             return sal_False;
      85             : 
      86           0 :         Sequence< Reference< XInteractionContinuation > > aContinuations( i_Request->getContinuations() );
      87             : 
      88             :         // try to extract an SQLException (or one of it's derived members
      89           0 :         SQLExceptionInfo aInfo( aRequest );
      90           0 :         if ( aInfo.isValid() )
      91             :         {
      92           0 :             implHandle( aInfo, aContinuations );
      93           0 :             return sal_True;
      94             :         }
      95             : 
      96           0 :         ParametersRequest aParamRequest;
      97           0 :         if ( aRequest >>= aParamRequest )
      98             :         {
      99           0 :             implHandle( aParamRequest, aContinuations );
     100           0 :             return sal_True;
     101             :         }
     102             : 
     103           0 :         DocumentSaveRequest aDocuRequest;
     104           0 :         if ( aRequest >>= aDocuRequest )
     105             :         {
     106           0 :             implHandle( aDocuRequest, aContinuations );
     107           0 :             return sal_True;
     108             :         }
     109             : 
     110           0 :         if ( m_bFallbackToGeneric )
     111           0 :             return implHandleUnknown( i_Request );
     112             : 
     113           0 :         return sal_False;
     114             :     }
     115             : 
     116           0 :     void BasicInteractionHandler::implHandle(const ParametersRequest& _rParamRequest, const Sequence< Reference< XInteractionContinuation > >& _rContinuations)
     117             :     {
     118           0 :         SolarMutexGuard aGuard;
     119             :         // want to open a dialog...
     120             : 
     121           0 :         sal_Int32 nAbortPos = getContinuation(ABORT, _rContinuations);
     122           0 :         sal_Int32 nParamPos = getContinuation(SUPPLY_PARAMETERS, _rContinuations);
     123             : 
     124           0 :         Reference< XInteractionSupplyParameters > xParamCallback;
     125           0 :         if (-1 != nParamPos)
     126           0 :             xParamCallback = Reference< XInteractionSupplyParameters >(_rContinuations[nParamPos], UNO_QUERY);
     127             :         OSL_ENSURE(xParamCallback.is(), "BasicInteractionHandler::implHandle(ParametersRequest): can't set the parameters without an appropriate interaction handler!s");
     128             : 
     129           0 :         OParameterDialog aDlg(NULL, _rParamRequest.Parameters, _rParamRequest.Connection, m_xContext);
     130           0 :         sal_Int16 nResult = aDlg.Execute();
     131             :         try
     132             :         {
     133           0 :             switch (nResult)
     134             :             {
     135             :                 case RET_OK:
     136           0 :                     if (xParamCallback.is())
     137             :                     {
     138           0 :                         xParamCallback->setParameters(aDlg.getValues());
     139           0 :                         xParamCallback->select();
     140             :                     }
     141           0 :                     break;
     142             :                 default:
     143           0 :                     if (-1 != nAbortPos)
     144           0 :                         _rContinuations[nAbortPos]->select();
     145           0 :                     break;
     146             :             }
     147             :         }
     148           0 :         catch( const Exception& )
     149             :         {
     150             :             DBG_UNHANDLED_EXCEPTION();
     151           0 :         }
     152           0 :     }
     153             : 
     154           0 :     void BasicInteractionHandler::implHandle(const SQLExceptionInfo& _rSqlInfo, const Sequence< Reference< XInteractionContinuation > >& _rContinuations)
     155             :     {
     156           0 :         SolarMutexGuard aGuard;
     157             :         // want to open a dialog...
     158             : 
     159           0 :         sal_Int32 nApprovePos = getContinuation(APPROVE, _rContinuations);
     160           0 :         sal_Int32 nDisapprovePos = getContinuation(DISAPPROVE, _rContinuations);
     161           0 :         sal_Int32 nAbortPos = getContinuation(ABORT, _rContinuations);
     162           0 :         sal_Int32 nRetryPos = getContinuation(RETRY, _rContinuations);
     163             : 
     164             :         // determine the style of the dialog, dependent on the present continuation types
     165           0 :         WinBits nDialogStyle = 0;
     166           0 :         bool bHaveCancel = nAbortPos != -1;
     167             :         // "approve" means "Yes", "disapprove" means "No"
     168             :         // VCL only supports having both (which makes sense ...)
     169           0 :         if ( ( nApprovePos != -1 ) || ( nDisapprovePos != -1 ) )
     170           0 :             nDialogStyle = ( bHaveCancel ? WB_YES_NO_CANCEL : WB_YES_NO ) | WB_DEF_YES;
     171             :         else
     172             :         {
     173             :             // if there's no yes/no, then use a default OK button
     174           0 :             nDialogStyle = ( bHaveCancel ? WB_OK_CANCEL : WB_OK ) | WB_DEF_OK;
     175             :         }
     176             : 
     177             :         // If there's a "Retry" continuation, have a "Retry" button
     178           0 :         if ( nRetryPos != -1 )
     179             :         {
     180           0 :             nDialogStyle = WB_RETRY_CANCEL | WB_DEF_RETRY;
     181             :         }
     182             : 
     183             :         // execute the dialog
     184           0 :         OSQLMessageBox aDialog(NULL, _rSqlInfo, nDialogStyle);
     185             :         // TODO: need a way to specify the parent window
     186           0 :         sal_Int16 nResult = aDialog.Execute();
     187             :         try
     188             :         {
     189           0 :             switch (nResult)
     190             :             {
     191             :                 case RET_YES:
     192             :                 case RET_OK:
     193           0 :                     if ( nApprovePos != -1 )
     194           0 :                         _rContinuations[ nApprovePos ]->select();
     195             :                     else
     196             :                         OSL_ENSURE( nResult != RET_YES, "BasicInteractionHandler::implHandle: no handler for YES!" );
     197           0 :                     break;
     198             : 
     199             :                 case RET_NO:
     200           0 :                     if ( nDisapprovePos != -1 )
     201           0 :                         _rContinuations[ nDisapprovePos ]->select();
     202             :                     else
     203             :                         OSL_FAIL( "BasicInteractionHandler::implHandle: no handler for NO!" );
     204           0 :                     break;
     205             : 
     206             :                 case RET_CANCEL:
     207           0 :                     if ( nAbortPos != -1 )
     208           0 :                         _rContinuations[ nAbortPos ]->select();
     209           0 :                     else if ( nDisapprovePos != -1 )
     210           0 :                         _rContinuations[ nDisapprovePos ]->select();
     211             :                     else
     212             :                         OSL_FAIL( "BasicInteractionHandler::implHandle: no handler for CANCEL!" );
     213           0 :                     break;
     214             :                 case RET_RETRY:
     215           0 :                     if ( nRetryPos != -1 )
     216           0 :                         _rContinuations[ nRetryPos ]->select();
     217             :                     else
     218             :                         OSL_FAIL( "BasicInteractionHandler::implHandle: where does the RETRY come from?" );
     219           0 :                     break;
     220             :             }
     221             :         }
     222           0 :         catch( const Exception& )
     223             :         {
     224             :             DBG_UNHANDLED_EXCEPTION();
     225           0 :         }
     226           0 :     }
     227           0 :     void BasicInteractionHandler::implHandle(const DocumentSaveRequest& _rDocuRequest, const Sequence< Reference< XInteractionContinuation > >& _rContinuations)
     228             :     {
     229           0 :         SolarMutexGuard aGuard;
     230             :         // want to open a dialog ....
     231             : 
     232           0 :         sal_Int32 nApprovePos = getContinuation(APPROVE, _rContinuations);
     233           0 :         sal_Int32 nDisApprovePos = getContinuation(DISAPPROVE, _rContinuations);
     234           0 :         sal_Int32 nAbortPos = getContinuation(ABORT, _rContinuations);
     235             : 
     236           0 :         short nRet = RET_YES;
     237           0 :         if ( -1 != nApprovePos )
     238             :         {
     239             :             // ask whether it should be saved
     240           0 :             nRet = ExecuteQuerySaveDocument(NULL,_rDocuRequest.Name);
     241             :         }
     242             : 
     243           0 :         if ( RET_CANCEL == nRet )
     244             :         {
     245           0 :             if (-1 != nAbortPos)
     246           0 :                 _rContinuations[nAbortPos]->select();
     247           0 :             return;
     248             :         }
     249           0 :         else if ( RET_YES == nRet )
     250             :         {
     251           0 :             sal_Int32 nDocuPos = getContinuation(SUPPLY_DOCUMENTSAVE, _rContinuations);
     252             : 
     253           0 :             if (-1 != nDocuPos)
     254             :             {
     255           0 :                 Reference< XInteractionDocumentSave > xCallback(_rContinuations[nDocuPos], UNO_QUERY);
     256             :                 OSL_ENSURE(xCallback.is(), "BasicInteractionHandler::implHandle(DocumentSaveRequest): can't save document without an appropriate interaction handler!s");
     257             : 
     258           0 :                 OCollectionView aDlg(NULL, _rDocuRequest.Content, _rDocuRequest.Name, m_xContext);
     259           0 :                 sal_Int16 nResult = aDlg.Execute();
     260             :                 try
     261             :                 {
     262           0 :                     switch (nResult)
     263             :                     {
     264             :                         case RET_OK:
     265           0 :                             if (xCallback.is())
     266             :                             {
     267           0 :                                 xCallback->setName(aDlg.getName(),aDlg.getSelectedFolder());
     268           0 :                                 xCallback->select();
     269             :                             }
     270           0 :                             break;
     271             :                         default:
     272           0 :                             if (-1 != nAbortPos)
     273           0 :                                 _rContinuations[nAbortPos]->select();
     274           0 :                             break;
     275             :                     }
     276             :                 }
     277           0 :                 catch( const Exception& )
     278             :                 {
     279             :                     DBG_UNHANDLED_EXCEPTION();
     280           0 :                 }
     281             :             }
     282           0 :             else if ( -1 != nApprovePos )
     283           0 :                 _rContinuations[nApprovePos]->select();
     284             :         }
     285           0 :         else if ( -1 != nDisApprovePos )
     286           0 :                 _rContinuations[nDisApprovePos]->select();
     287             :     }
     288             : 
     289           0 :     bool BasicInteractionHandler::implHandleUnknown( const Reference< XInteractionRequest >& _rxRequest )
     290             :     {
     291           0 :         if ( m_xContext.is() )
     292             :         {
     293             :             Reference< XInteractionHandler2 > xFallbackHandler(
     294           0 :                 InteractionHandler::createWithParent(m_xContext, 0) );
     295           0 :             xFallbackHandler->handle( _rxRequest );
     296           0 :             return true;
     297             :         }
     298           0 :         return false;
     299             :     }
     300             : 
     301           0 :     sal_Int32 BasicInteractionHandler::getContinuation(Continuation _eCont, const Sequence< Reference< XInteractionContinuation > >& _rContinuations)
     302             :     {
     303           0 :         const Reference< XInteractionContinuation >* pContinuations = _rContinuations.getConstArray();
     304           0 :         for (sal_Int32 i=0; i<_rContinuations.getLength(); ++i, ++pContinuations)
     305             :         {
     306           0 :             switch (_eCont)
     307             :             {
     308             :                 case APPROVE:
     309           0 :                     if (Reference< XInteractionApprove >(*pContinuations, UNO_QUERY).is())
     310           0 :                         return i;
     311           0 :                     break;
     312             :                 case DISAPPROVE:
     313           0 :                     if (Reference< XInteractionDisapprove >(*pContinuations, UNO_QUERY).is())
     314           0 :                         return i;
     315           0 :                     break;
     316             :                 case RETRY:
     317           0 :                     if (Reference< XInteractionRetry >(*pContinuations, UNO_QUERY).is())
     318           0 :                         return i;
     319           0 :                     break;
     320             :                 case ABORT:
     321           0 :                     if (Reference< XInteractionAbort >(*pContinuations, UNO_QUERY).is())
     322           0 :                         return i;
     323           0 :                     break;
     324             :                 case SUPPLY_PARAMETERS:
     325           0 :                     if (Reference< XInteractionSupplyParameters >(*pContinuations, UNO_QUERY).is())
     326           0 :                         return i;
     327           0 :                     break;
     328             :                 case SUPPLY_DOCUMENTSAVE:
     329           0 :                     if (Reference< XInteractionDocumentSave >(*pContinuations, UNO_QUERY).is())
     330           0 :                         return i;
     331           0 :                     break;
     332             :             }
     333             :         }
     334             : 
     335           0 :         return -1;
     336             :     }
     337             : 
     338             :     // SQLExceptionInteractionHandler
     339           0 :     IMPLEMENT_SERVICE_INFO_IMPLNAME_STATIC(SQLExceptionInteractionHandler, "com.sun.star.comp.dbaccess.DatabaseInteractionHandler")
     340           0 :     IMPLEMENT_SERVICE_INFO_SUPPORTS(SQLExceptionInteractionHandler)
     341           0 :     IMPLEMENT_SERVICE_INFO_GETSUPPORTED1_STATIC(SQLExceptionInteractionHandler, "com.sun.star.sdb.DatabaseInteractionHandler")
     342             : 
     343             :     Reference< XInterface >
     344           0 :         SAL_CALL SQLExceptionInteractionHandler::Create(const Reference< XMultiServiceFactory >& _rxORB)
     345             :     {
     346           0 :         return static_cast< XServiceInfo* >(new SQLExceptionInteractionHandler(comphelper::getComponentContext(_rxORB)));
     347             :     }
     348             : 
     349             :     // LegacyInteractionHandler
     350           0 :     IMPLEMENT_SERVICE_INFO_IMPLNAME_STATIC(LegacyInteractionHandler, "com.sun.star.comp.dbaccess.LegacyInteractionHandler")
     351           0 :     IMPLEMENT_SERVICE_INFO_SUPPORTS(LegacyInteractionHandler)
     352           0 :     IMPLEMENT_SERVICE_INFO_GETSUPPORTED1_STATIC(LegacyInteractionHandler, "com.sun.star.sdb.LegacyInteractionHandler")
     353             : 
     354             :     Reference< XInterface >
     355           0 :         SAL_CALL LegacyInteractionHandler::Create(const Reference< XMultiServiceFactory >& _rxORB)
     356             :     {
     357           0 :         return static_cast< XServiceInfo* >(new LegacyInteractionHandler(comphelper::getComponentContext(_rxORB)));
     358             :     }
     359             : 
     360           0 : }   // namespace dbaui
     361             : 
     362             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10