diff options
Diffstat (limited to 'dbaccess/source/ui/misc/TableCopyHelper.cxx')
-rw-r--r-- | dbaccess/source/ui/misc/TableCopyHelper.cxx | 64 |
1 files changed, 27 insertions, 37 deletions
diff --git a/dbaccess/source/ui/misc/TableCopyHelper.cxx b/dbaccess/source/ui/misc/TableCopyHelper.cxx index 596aa7335771..5d22c90468c8 100644 --- a/dbaccess/source/ui/misc/TableCopyHelper.cxx +++ b/dbaccess/source/ui/misc/TableCopyHelper.cxx @@ -35,7 +35,7 @@ #include <svx/dbaexchange.hxx> #include <unotools/ucbhelper.hxx> #include <tools/urlobj.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <sal/log.hxx> #include <toolkit/helper/vclunohelper.hxx> #include <unotools/tempfile.hxx> @@ -48,23 +48,21 @@ using namespace ::svx; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::task; using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::lang; using namespace ::com::sun::star::container; using namespace ::com::sun::star::sdb; using namespace ::com::sun::star::sdb::application; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::ucb; -OTableCopyHelper::OTableCopyHelper(OGenericUnoController* _pControler) - :m_pController(_pControler) +OTableCopyHelper::OTableCopyHelper(OGenericUnoController* _pController) + :m_pController(_pController) { } -void OTableCopyHelper::insertTable( const OUString& i_rSourceDataSource, const Reference<XConnection>& i_rSourceConnection, +void OTableCopyHelper::insertTable( std::u16string_view i_rSourceDataSource, const Reference<XConnection>& i_rSourceConnection, const OUString& i_rCommand, const sal_Int32 i_nCommandType, const Reference< XResultSet >& i_rSourceRows, const Sequence< Any >& i_rSelection, const bool i_bBookmarkSelection, - const OUString& i_rDestDataSource, const Reference<XConnection>& i_rDestConnection) + std::u16string_view i_rDestDataSource, const Reference<XConnection>& i_rDestConnection) { if ( CommandType::QUERY != i_nCommandType && CommandType::TABLE != i_nCommandType ) { @@ -89,15 +87,15 @@ void OTableCopyHelper::insertTable( const OUString& i_rSourceDataSource, const R Reference< XDataAccessDescriptorFactory > xFactory( DataAccessDescriptorFactory::get( aContext ) ); Reference< XPropertySet > xSource( xFactory->createDataAccessDescriptor(), UNO_SET_THROW ); - xSource->setPropertyValue( PROPERTY_COMMAND_TYPE, makeAny( i_nCommandType ) ); - xSource->setPropertyValue( PROPERTY_COMMAND, makeAny( i_rCommand ) ); - xSource->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, makeAny( xSrcConnection ) ); - xSource->setPropertyValue( PROPERTY_RESULT_SET, makeAny( i_rSourceRows ) ); - xSource->setPropertyValue( PROPERTY_SELECTION, makeAny( i_rSelection ) ); - xSource->setPropertyValue( PROPERTY_BOOKMARK_SELECTION, makeAny( i_bBookmarkSelection ) ); + xSource->setPropertyValue( PROPERTY_COMMAND_TYPE, Any( i_nCommandType ) ); + xSource->setPropertyValue( PROPERTY_COMMAND, Any( i_rCommand ) ); + xSource->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, Any( xSrcConnection ) ); + xSource->setPropertyValue( PROPERTY_RESULT_SET, Any( i_rSourceRows ) ); + xSource->setPropertyValue( PROPERTY_SELECTION, Any( i_rSelection ) ); + xSource->setPropertyValue( PROPERTY_BOOKMARK_SELECTION, Any( i_bBookmarkSelection ) ); Reference< XPropertySet > xDest( xFactory->createDataAccessDescriptor(), UNO_SET_THROW ); - xDest->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, makeAny( i_rDestConnection ) ); + xDest->setPropertyValue( PROPERTY_ACTIVE_CONNECTION, Any( i_rDestConnection ) ); auto xInteractionHandler = InteractionHandler::createWithParent(aContext, VCLUnoHelper::GetInterface(m_pController->getView())); @@ -121,7 +119,7 @@ void OTableCopyHelper::insertTable( const OUString& i_rSourceDataSource, const R } } -void OTableCopyHelper::pasteTable( const svx::ODataAccessDescriptor& _rPasteData, const OUString& i_rDestDataSourceName, +void OTableCopyHelper::pasteTable( const svx::ODataAccessDescriptor& _rPasteData, std::u16string_view i_rDestDataSourceName, const SharedConnection& i_rDestConnection ) { OUString sSrcDataSourceName = _rPasteData.getDataSource(); @@ -166,7 +164,7 @@ void OTableCopyHelper::pasteTable( const svx::ODataAccessDescriptor& _rPasteData void OTableCopyHelper::pasteTable( SotClipboardFormatId _nFormatId ,const TransferableDataHelper& _rTransData - ,const OUString& i_rDestDataSource + ,std::u16string_view i_rDestDataSource ,const SharedConnection& _xConnection) { if ( _nFormatId == SotClipboardFormatId::DBACCESS_TABLE || _nFormatId == SotClipboardFormatId::DBACCESS_QUERY ) @@ -182,16 +180,15 @@ void OTableCopyHelper::pasteTable( SotClipboardFormatId _nFormatId try { DropDescriptor aTrans; - bool bOk; if ( _nFormatId != SotClipboardFormatId::RTF ) - bOk = const_cast<TransferableDataHelper&>(_rTransData).GetSotStorageStream(SotClipboardFormatId::HTML ,aTrans.aHtmlRtfStorage); + aTrans.aHtmlRtfStorage = _rTransData.GetSotStorageStream(SotClipboardFormatId::HTML); else - bOk = const_cast<TransferableDataHelper&>(_rTransData).GetSotStorageStream(SotClipboardFormatId::RTF,aTrans.aHtmlRtfStorage); + aTrans.aHtmlRtfStorage = _rTransData.GetSotStorageStream(SotClipboardFormatId::RTF); aTrans.nType = E_TABLE; aTrans.bHtml = SotClipboardFormatId::HTML == _nFormatId; aTrans.sDefaultTableName = GetTableNameForAppend(); - if ( !bOk || !copyTagTable(aTrans,false,_xConnection) ) + if ( !aTrans.aHtmlRtfStorage || !copyTagTable(aTrans,false,_xConnection) ) m_pController->showError(SQLException(DBA_RES(STR_NO_TABLE_FORMAT_INSIDE), *m_pController, "S1000", 0, Any())); } catch(const SQLException&) @@ -208,7 +205,7 @@ void OTableCopyHelper::pasteTable( SotClipboardFormatId _nFormatId } void OTableCopyHelper::pasteTable( const TransferableDataHelper& _rTransData - ,const OUString& i_rDestDataSource + ,std::u16string_view i_rDestDataSource ,const SharedConnection& _xConnection) { if ( _rTransData.HasFormat(SotClipboardFormatId::DBACCESS_TABLE) || _rTransData.HasFormat(SotClipboardFormatId::DBACCESS_QUERY) ) @@ -221,14 +218,12 @@ void OTableCopyHelper::pasteTable( const TransferableDataHelper& _rTransData bool OTableCopyHelper::copyTagTable(OTableCopyHelper::DropDescriptor const & _rDesc, bool _bCheck, const SharedConnection& _xConnection) { - Reference<XEventListener> xEvt; - ODatabaseImportExport* pImport = nullptr; + rtl::Reference<ODatabaseImportExport> pImport; if ( _rDesc.bHtml ) pImport = new OHTMLImportExport(_xConnection,getNumberFormatter(_xConnection, m_pController->getORB()),m_pController->getORB()); else pImport = new ORTFImportExport(_xConnection,getNumberFormatter(_xConnection, m_pController->getORB()),m_pController->getORB()); - xEvt = pImport; SvStream* pStream = _rDesc.aHtmlRtfStorage.get(); if ( _bCheck ) pImport->enableCheckOnly(); @@ -258,26 +253,21 @@ bool OTableCopyHelper::copyTagTable(const TransferableDataHelper& _aDroppedData bool bHtml = _aDroppedData.HasFormat(SotClipboardFormatId::HTML); if ( bHtml || _aDroppedData.HasFormat(SotClipboardFormatId::RTF) ) { - bool bOk; - if ( bHtml ) - bOk = const_cast<TransferableDataHelper&>(_aDroppedData).GetSotStorageStream(SotClipboardFormatId::HTML ,_rAsyncDrop.aHtmlRtfStorage); - else - bOk = const_cast<TransferableDataHelper&>(_aDroppedData).GetSotStorageStream(SotClipboardFormatId::RTF,_rAsyncDrop.aHtmlRtfStorage); + _rAsyncDrop.aHtmlRtfStorage = _aDroppedData.GetSotStorageStream(bHtml ? SotClipboardFormatId::HTML : SotClipboardFormatId::RTF); _rAsyncDrop.bHtml = bHtml; _rAsyncDrop.bError = !copyTagTable(_rAsyncDrop,true,_xConnection); - bRet = ( !_rAsyncDrop.bError && bOk && _rAsyncDrop.aHtmlRtfStorage.is() ); + bRet = ( !_rAsyncDrop.bError && _rAsyncDrop.aHtmlRtfStorage ); if ( bRet ) { // now we need to copy the stream - ::utl::TempFile aTmp; + ::utl::TempFileNamed aTmp; _rAsyncDrop.aUrl = aTmp.GetURL(); - ::tools::SvRef<SotStorageStream> aNew = new SotStorageStream( aTmp.GetFileName() ); + std::unique_ptr<SvStream> aNew = SotTempStream::Create( aTmp.GetFileName() ); _rAsyncDrop.aHtmlRtfStorage->Seek(STREAM_SEEK_TO_BEGIN); - _rAsyncDrop.aHtmlRtfStorage->CopyTo( aNew.get() ); - aNew->Commit(); - _rAsyncDrop.aHtmlRtfStorage = aNew; + aNew->WriteStream(*_rAsyncDrop.aHtmlRtfStorage); + _rAsyncDrop.aHtmlRtfStorage = std::move(aNew); } else _rAsyncDrop.aHtmlRtfStorage = nullptr; @@ -286,10 +276,10 @@ bool OTableCopyHelper::copyTagTable(const TransferableDataHelper& _aDroppedData } void OTableCopyHelper::asyncCopyTagTable( DropDescriptor& _rDesc - ,const OUString& i_rDestDataSource + ,std::u16string_view i_rDestDataSource ,const SharedConnection& _xConnection) { - if ( _rDesc.aHtmlRtfStorage.is() ) + if ( _rDesc.aHtmlRtfStorage ) { copyTagTable(_rDesc,false,_xConnection); _rDesc.aHtmlRtfStorage = nullptr; |