LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/dbaccess/source/ui/browser - dbexchange.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 101 1.0 %
Date: 2013-07-09 Functions: 2 12 16.7 %
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 "dbexchange.hxx"
      22             : #include <sot/formats.hxx>
      23             : #include <sot/storage.hxx>
      24             : #include <osl/diagnose.h>
      25             : #include <com/sun/star/sdb/CommandType.hpp>
      26             : #include <com/sun/star/sdb/XResultSetAccess.hpp>
      27             : #include "TokenWriter.hxx"
      28             : #include "dbustrings.hrc"
      29             : #include <comphelper/uno3.hxx>
      30             : #include <svx/dataaccessdescriptor.hxx>
      31             : #include "UITools.hxx"
      32             : #include <comphelper/processfactory.hxx>
      33             : 
      34             : 
      35             : namespace dbaui
      36             : {
      37             :     using namespace ::com::sun::star::uno;
      38             :     using namespace ::com::sun::star::beans;
      39             :     using namespace ::com::sun::star::sdb;
      40             :     using namespace ::com::sun::star::lang;
      41             :     using namespace ::com::sun::star::util;
      42             :     using namespace ::com::sun::star::sdbc;
      43             :     using namespace ::com::sun::star::datatransfer;
      44             :     using namespace ::svx;
      45             : 
      46             :     namespace
      47             :     {
      48           0 :         template<class T > void lcl_setListener(const Reference<T>& _xComponent, const Reference< XEventListener >& i_rListener, const bool i_bAdd )
      49             :         {
      50           0 :             if ( !_xComponent.is() )
      51           0 :                 return;
      52             : 
      53           0 :             Reference< XComponent> xCom( _xComponent, UNO_QUERY );
      54             :             OSL_ENSURE( xCom.is(), "lcl_setListener: no component!" );
      55           0 :             if ( !xCom.is() )
      56           0 :                 return;
      57             : 
      58           0 :             i_bAdd ? xCom->addEventListener( i_rListener ) : xCom->removeEventListener( i_rListener );
      59             :         }
      60             :     }
      61             : 
      62             :     // -----------------------------------------------------------------------------
      63           0 :     ODataClipboard::ODataClipboard(
      64             :                     const OUString&  _rDatasource,
      65             :                     const sal_Int32         _nCommandType,
      66             :                     const OUString&  _rCommand,
      67             :                     const Reference< XConnection >& _rxConnection,
      68             :                     const Reference< XNumberFormatter >& _rxFormatter,
      69             :                     const Reference< XComponentContext >& _rxORB)
      70             :                     :ODataAccessObjectTransferable( _rDatasource,OUString(), _nCommandType, _rCommand, _rxConnection )
      71             :         ,m_pHtml(NULL)
      72           0 :         ,m_pRtf(NULL)
      73             :     {
      74           0 :         osl_atomic_increment( &m_refCount );
      75           0 :         lcl_setListener( _rxConnection, this, true );
      76             : 
      77           0 :         m_pHtml.set( new OHTMLImportExport( getDescriptor(), _rxORB, _rxFormatter ) );
      78           0 :         m_pRtf.set( new ORTFImportExport( getDescriptor(), _rxORB, _rxFormatter ) );
      79             : 
      80           0 :         osl_atomic_decrement( &m_refCount );
      81           0 :     }
      82             : 
      83             :     // -----------------------------------------------------------------------------
      84           0 :     ODataClipboard::ODataClipboard(
      85             :                     const OUString&  _rDatasource,
      86             :                     const sal_Int32         _nCommandType,
      87             :                     const OUString&  _rCommand,
      88             :                     const Reference< XNumberFormatter >& _rxFormatter,
      89             :                     const Reference< XComponentContext >& _rxORB)
      90             :         :ODataAccessObjectTransferable( _rDatasource, OUString(),_nCommandType, _rCommand)
      91             :         ,m_pHtml(NULL)
      92           0 :         ,m_pRtf(NULL)
      93             :     {
      94           0 :         m_pHtml.set( new OHTMLImportExport( getDescriptor(),_rxORB, _rxFormatter ) );
      95           0 :         m_pRtf.set( new ORTFImportExport( getDescriptor(),_rxORB, _rxFormatter ) );
      96           0 :     }
      97             : 
      98             :     // -----------------------------------------------------------------------------
      99           0 :     ODataClipboard::ODataClipboard( const Reference< XPropertySet >& i_rAliveForm,
     100             :                                     const Sequence< Any >& i_rSelectedRows,
     101             :                                     const sal_Bool i_bBookmarkSelection,
     102             :                                     const Reference< XComponentContext >& i_rORB )
     103             :         :ODataAccessObjectTransferable( i_rAliveForm )
     104             :         ,m_pHtml(NULL)
     105           0 :         ,m_pRtf(NULL)
     106             :     {
     107             :         OSL_PRECOND( i_rORB.is(), "ODataClipboard::ODataClipboard: having no factory is not good ..." );
     108             : 
     109           0 :         osl_atomic_increment( &m_refCount );
     110             : 
     111           0 :         Reference<XConnection> xConnection;
     112           0 :         getDescriptor()[ daConnection ] >>= xConnection;
     113           0 :         lcl_setListener( xConnection, this, true );
     114             : 
     115             :         // do not pass the form itself as source result set, since the client might operate on the form, which
     116             :         // might lead to undesired effects. Instead, use a clone.
     117           0 :         Reference< XResultSet > xResultSetClone;
     118           0 :         Reference< XResultSetAccess > xResultSetAccess( i_rAliveForm, UNO_QUERY );
     119           0 :         if ( xResultSetAccess.is() )
     120           0 :             xResultSetClone = xResultSetAccess->createResultSet();
     121             :         OSL_ENSURE( xResultSetClone.is(), "ODataClipboard::ODataClipboard: could not clone the form's result set" );
     122           0 :         lcl_setListener( xResultSetClone, this, true );
     123             : 
     124           0 :         getDescriptor()[daCursor]           <<= xResultSetClone;
     125           0 :         getDescriptor()[daSelection]        <<= i_rSelectedRows;
     126           0 :         getDescriptor()[daBookmarkSelection]<<= i_bBookmarkSelection;
     127           0 :         addCompatibleSelectionDescription( i_rSelectedRows );
     128             : 
     129           0 :         if ( xConnection.is() && i_rORB.is() )
     130             :         {
     131           0 :             Reference< XNumberFormatter > xFormatter( getNumberFormatter( xConnection, i_rORB ) );
     132           0 :             if ( xFormatter.is() )
     133             :             {
     134           0 :                 m_pHtml.set( new OHTMLImportExport( getDescriptor(), i_rORB, xFormatter ) );
     135           0 :                 m_pRtf.set( new ORTFImportExport( getDescriptor(), i_rORB, xFormatter ) );
     136           0 :             }
     137             :         }
     138             : 
     139           0 :         osl_atomic_decrement( &m_refCount );
     140           0 :     }
     141             : 
     142             :     // -----------------------------------------------------------------------------
     143           0 :     sal_Bool ODataClipboard::WriteObject( SotStorageStreamRef& rxOStm, void* pUserObject, sal_uInt32 nUserObjectId, const ::com::sun::star::datatransfer::DataFlavor& /*rFlavor*/ )
     144             :     {
     145           0 :         if (nUserObjectId == SOT_FORMAT_RTF || nUserObjectId == SOT_FORMATSTR_ID_HTML )
     146             :         {
     147           0 :             ODatabaseImportExport* pExport = reinterpret_cast<ODatabaseImportExport*>(pUserObject);
     148           0 :             if ( pExport && rxOStm.Is() )
     149             :             {
     150           0 :                 pExport->setStream(&rxOStm);
     151           0 :                 return pExport->Write();
     152             :             }
     153             :         }
     154           0 :         return sal_False;
     155             :     }
     156             : 
     157             :     // -----------------------------------------------------------------------------
     158           0 :     void ODataClipboard::AddSupportedFormats()
     159             :     {
     160           0 :         if ( m_pRtf.is() )
     161           0 :             AddFormat( SOT_FORMAT_RTF );
     162             : 
     163           0 :         if ( m_pHtml.is() )
     164           0 :             AddFormat( SOT_FORMATSTR_ID_HTML );
     165             : 
     166           0 :         ODataAccessObjectTransferable::AddSupportedFormats();
     167           0 :     }
     168             : 
     169             :     // -----------------------------------------------------------------------------
     170           0 :     sal_Bool ODataClipboard::GetData( const DataFlavor& rFlavor )
     171             :     {
     172           0 :         const sal_uLong nFormat = SotExchange::GetFormat(rFlavor);
     173           0 :         switch (nFormat)
     174             :         {
     175             :             case SOT_FORMAT_RTF:
     176           0 :                 if ( m_pRtf.is() )
     177           0 :                     m_pRtf->initialize(getDescriptor());
     178           0 :                 return m_pRtf.is() && SetObject( m_pRtf.get(), SOT_FORMAT_RTF, rFlavor );
     179             : 
     180             :             case SOT_FORMATSTR_ID_HTML:
     181           0 :                 if ( m_pHtml.is() )
     182           0 :                     m_pHtml->initialize(getDescriptor());
     183           0 :                 return m_pHtml.is() && SetObject( m_pHtml.get(), SOT_FORMATSTR_ID_HTML, rFlavor );
     184             :         }
     185             : 
     186           0 :         return ODataAccessObjectTransferable::GetData( rFlavor );
     187             :     }
     188             : 
     189             :     // -----------------------------------------------------------------------------
     190           0 :     void ODataClipboard::ObjectReleased()
     191             :     {
     192           0 :         if ( m_pHtml.is() )
     193             :         {
     194           0 :             m_pHtml->dispose();
     195           0 :             m_pHtml.clear();
     196             :         }
     197             : 
     198           0 :         if ( m_pRtf.is() )
     199             :         {
     200           0 :             m_pRtf->dispose();
     201           0 :             m_pRtf.clear();
     202             :         }
     203             : 
     204           0 :         if ( getDescriptor().has( daConnection ) )
     205             :         {
     206           0 :             Reference<XConnection> xConnection( getDescriptor()[daConnection], UNO_QUERY );
     207           0 :             lcl_setListener( xConnection, this, false );
     208             :         }
     209             : 
     210           0 :         if ( getDescriptor().has( daCursor ) )
     211             :         {
     212           0 :             Reference< XResultSet > xResultSet( getDescriptor()[ daCursor ], UNO_QUERY );
     213           0 :             lcl_setListener( xResultSet, this, false );
     214             :         }
     215             : 
     216           0 :         ODataAccessObjectTransferable::ObjectReleased( );
     217           0 :     }
     218             : 
     219             :     // -----------------------------------------------------------------------------
     220           0 :     void SAL_CALL ODataClipboard::disposing( const ::com::sun::star::lang::EventObject& i_rSource ) throw (::com::sun::star::uno::RuntimeException)
     221             :     {
     222           0 :         ODataAccessDescriptor& rDescriptor( getDescriptor() );
     223             : 
     224           0 :         if ( rDescriptor.has( daConnection ) )
     225             :         {
     226           0 :             Reference< XConnection > xConnection( rDescriptor[daConnection], UNO_QUERY );
     227           0 :             if ( xConnection == i_rSource.Source )
     228             :             {
     229           0 :                 rDescriptor.erase( daConnection );
     230           0 :             }
     231             :         }
     232             : 
     233           0 :         if ( rDescriptor.has( daCursor ) )
     234             :         {
     235           0 :             Reference< XResultSet > xResultSet( rDescriptor[ daCursor ], UNO_QUERY );
     236           0 :             if ( xResultSet == i_rSource.Source )
     237             :             {
     238           0 :                 rDescriptor.erase( daCursor );
     239             :                 // Selection and BookmarkSelection are meaningless without a result set
     240           0 :                 if ( rDescriptor.has( daSelection ) )
     241           0 :                     rDescriptor.erase( daSelection );
     242           0 :                 if ( rDescriptor.has( daBookmarkSelection ) )
     243           0 :                     rDescriptor.erase( daBookmarkSelection );
     244           0 :             }
     245             :         }
     246             : 
     247             :         // no matter whether it was the source connection or the source result set which died,
     248             :         // we cannot provide the data anymore.
     249           0 :         ClearFormats();
     250           0 :     }
     251          12 : }
     252             : 
     253             : 
     254             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10