From b3f5ab776591f134e5f1692e745f62a2df599a67 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Thu, 4 Jun 2015 14:19:38 +0200 Subject: abpilot: embed the data source definition, if possible + requested Change-Id: I0e70459e331995388b36c77c351bff89ece004a6 --- extensions/source/abpilot/abspilot.cxx | 2 +- extensions/source/abpilot/datasourcehandling.cxx | 52 ++++++++++++++++++++++-- extensions/source/abpilot/datasourcehandling.hxx | 3 +- 3 files changed, 52 insertions(+), 5 deletions(-) (limited to 'extensions') diff --git a/extensions/source/abpilot/abspilot.cxx b/extensions/source/abpilot/abspilot.cxx index 459f321ad136..1ef0ebe0331c 100644 --- a/extensions/source/abpilot/abspilot.cxx +++ b/extensions/source/abpilot/abspilot.cxx @@ -158,7 +158,7 @@ namespace abp m_aNewDataSource.rename( m_aSettings.sDataSourceName ); // 1. the data source - m_aNewDataSource.store(); + m_aNewDataSource.store(m_aSettings); // 2. check if we need to register the data source if ( m_aSettings.bRegisterDataSource ) diff --git a/extensions/source/abpilot/datasourcehandling.cxx b/extensions/source/abpilot/datasourcehandling.cxx index 38952680239a..f3d6268b1e7a 100644 --- a/extensions/source/abpilot/datasourcehandling.cxx +++ b/extensions/source/abpilot/datasourcehandling.cxx @@ -22,6 +22,7 @@ #include "abptypes.hxx" #include "componentmodule.hxx" #include "datasourcehandling.hxx" +#include "addresssettings.hxx" #include #include @@ -46,7 +47,28 @@ #include #include #include +#include +#include +#include +#include +namespace +{ + +/// Returns the URL of this object shell. +OUString lcl_getOwnURL(SfxObjectShell* pObjectShell) +{ + OUString aRet; + + if (!pObjectShell) + return aRet; + + const INetURLObject& rURLObject = pObjectShell->GetMedium()->GetURLObject(); + aRet = rURLObject.GetMainURL(INetURLObject::DECODE_WITH_CHARSET); + return aRet; +} + +} namespace abp { @@ -54,6 +76,7 @@ namespace abp using namespace ::utl; using namespace ::comphelper; + using namespace ::com::sun::star; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::sdb; @@ -347,8 +370,7 @@ namespace abp delete m_pImpl; } - - void ODataSource::store() + void ODataSource::store(const AddressSettings& rSettings) { if (!isValid()) // nothing to do @@ -361,7 +383,31 @@ namespace abp xStorable.set(xDocAccess->getDatabaseDocument(), css::uno::UNO_QUERY); OSL_ENSURE( xStorable.is(),"DataSource is no XStorable!" ); if ( xStorable.is() ) - xStorable->storeAsURL(m_pImpl->sName,Sequence()); + { + SfxObjectShell* pObjectShell = SfxViewFrame::Current()->GetObjectShell(); + OUString aOwnURL = lcl_getOwnURL(pObjectShell); + if (aOwnURL.isEmpty() || !rSettings.bEmbedDataSource) + { + // Cannot or should not embed. + xStorable->storeAsURL(m_pImpl->sName,Sequence()); + } + else + { + // Embed. + OUString aStreamRelPath = "EmbeddedDatabase"; + OUString sTmpName = "vnd.sun.star.pkg://"; + sTmpName += INetURLObject::encode(aOwnURL, INetURLObject::PART_AUTHORITY, INetURLObject::ENCODE_ALL); + sTmpName += "/" + aStreamRelPath; + uno::Reference xStorage = pObjectShell->GetStorage(); + uno::Sequence aSequence = comphelper::InitPropertySequence( + { + {"TargetStorage", uno::makeAny(xStorage)}, + {"StreamRelPath", uno::makeAny(aStreamRelPath)} + }); + xStorable->storeAsURL(sTmpName, aSequence); + m_pImpl->sName = sTmpName; + } + } } catch(const Exception&) { diff --git a/extensions/source/abpilot/datasourcehandling.hxx b/extensions/source/abpilot/datasourcehandling.hxx index fd4a75fa5632..0d96f1dd61ab 100644 --- a/extensions/source/abpilot/datasourcehandling.hxx +++ b/extensions/source/abpilot/datasourcehandling.hxx @@ -95,6 +95,7 @@ namespace abp struct ODataSourceImpl; struct PackageAccessControl; + struct AddressSettings; /** a non-UNO wrapper for a data source

This class allows to access data sources without the need to compile the respective file with exception handling enabled (hopefully :).

@@ -159,7 +160,7 @@ namespace abp void disconnect( ); /// stores the database file - void store(); + void store(const AddressSettings& rSettings); /// register the data source under the given name in the configuration void registerDataSource( const OUString& _sRegisteredDataSourceName ); -- cgit