diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-06-04 14:19:38 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-06-04 15:14:23 +0200 |
commit | b3f5ab776591f134e5f1692e745f62a2df599a67 (patch) | |
tree | 7f7e4e6f6ee045bf210c0e8c0bece4aa4912a6fd /extensions/source/abpilot | |
parent | b2117c98ed959e79079084a6e3e6e490573e7236 (diff) |
abpilot: embed the data source definition, if possible + requested
Change-Id: I0e70459e331995388b36c77c351bff89ece004a6
Diffstat (limited to 'extensions/source/abpilot')
-rw-r--r-- | extensions/source/abpilot/abspilot.cxx | 2 | ||||
-rw-r--r-- | extensions/source/abpilot/datasourcehandling.cxx | 52 | ||||
-rw-r--r-- | extensions/source/abpilot/datasourcehandling.hxx | 3 |
3 files changed, 52 insertions, 5 deletions
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 <boost/noncopyable.hpp> #include <com/sun/star/beans/XPropertySet.hpp> @@ -46,7 +47,28 @@ #include <unotools/confignode.hxx> #include <unotools/sharedunocomponent.hxx> #include <vcl/stdtext.hxx> +#include <sfx2/objsh.hxx> +#include <sfx2/docfile.hxx> +#include <sfx2/viewfrm.hxx> +#include <comphelper/propertysequence.hxx> +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<PropertyValue>()); + { + 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<PropertyValue>()); + } + 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<embed::XStorage> xStorage = pObjectShell->GetStorage(); + uno::Sequence<beans::PropertyValue> 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 <p>This class allows to access data sources without the need to compile the respective file with exception handling enabled (hopefully :).</p> @@ -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 ); |