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

Generated by: LCOV version 1.10