[Libreoffice-commits] core.git: 2 commits - dbaccess/source sw/inc sw/source
Miklos Vajna
vmiklos at collabora.co.uk
Mon Jun 1 03:31:03 PDT 2015
dbaccess/source/core/dataaccess/databasedocument.cxx | 30 +++++++++++-
sw/inc/dbmgr.hxx | 5 +-
sw/source/ui/dbui/addresslistdialog.cxx | 10 +++-
sw/source/uibase/dbui/dbmgr.cxx | 47 +++++++++++++++++--
4 files changed, 84 insertions(+), 8 deletions(-)
New commits:
commit 54bf49a2be3a7bc370c7043011c6080918224ffa
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Mon Jun 1 12:13:44 2015 +0200
SwDBManager: embed data source definition if possible
In the past SwDBManager (used by the MM wizard) created a smaller .odb
file in the home directory by default in case the data source was
something external (.ods file, etc).
If the document is saved already (and experimental mode is enabled, as
this is still a work in progress), then stop saving these small .odb
files to the home directory, instead embed the data source definition
into the currently active .odt file.
Previously created such separate .odb files are still fully supported,
of course.
Change-Id: I7c1776e5ed57cdde05c0adfc5f7d1dc485363f03
diff --git a/sw/inc/dbmgr.hxx b/sw/inc/dbmgr.hxx
index 5bf5432..27c86a7 100644
--- a/sw/inc/dbmgr.hxx
+++ b/sw/inc/dbmgr.hxx
@@ -350,7 +350,7 @@ public:
the filename returned by a file picker and additional settings dialog.
In case of success it returns the registered name, otherwise an empty string.
*/
- static OUString LoadAndRegisterDataSource();
+ static OUString LoadAndRegisterDataSource(SwDocShell* pDocShell = 0);
/**
Loads a data source from file and registers it.
@@ -360,7 +360,8 @@ public:
*/
static OUString LoadAndRegisterDataSource(const DBConnURITypes type, const ::com::sun::star::uno::Any &rUnoURI,
const ::com::sun::star::uno::Reference < ::com::sun::star::beans::XPropertySet > *pSettings,
- const OUString &rURI, const OUString *pPrefix = 0, const OUString *pDestDir = 0);
+ const OUString &rURI, const OUString *pPrefix = 0, const OUString *pDestDir = 0,
+ SwDocShell* pDocShell = 0);
/**
Loads a data source from file and registers it.
diff --git a/sw/source/ui/dbui/addresslistdialog.cxx b/sw/source/ui/dbui/addresslistdialog.cxx
index 9f989d0..16a55a7 100644
--- a/sw/source/ui/dbui/addresslistdialog.cxx
+++ b/sw/source/ui/dbui/addresslistdialog.cxx
@@ -56,6 +56,7 @@
#include <unotools/pathoptions.hxx>
#include <svl/urihelper.hxx>
#include <dbui.hrc>
+#include <view.hxx>
#include <helpid.h>
#include <unomid.h>
@@ -345,7 +346,14 @@ IMPL_LINK_NOARG(SwAddressListDialog, FilterHdl_Impl)
IMPL_LINK_NOARG(SwAddressListDialog, LoadHdl_Impl)
{
- const OUString sNewSource = SwDBManager::LoadAndRegisterDataSource();
+ SwMailMergeWizard* pWizard = 0;
+ if (GetParent() && GetParent()->GetParent())
+ pWizard = dynamic_cast<SwMailMergeWizard*>(GetParent()->GetParent());
+ SwView* pView = 0;
+ if (pWizard)
+ pView = pWizard->GetSwView();
+
+ const OUString sNewSource = SwDBManager::LoadAndRegisterDataSource(pView ? pView->GetDocShell() : 0);
if(!sNewSource.isEmpty())
{
SvTreeListEntry* pNewSource = m_pListLB->InsertEntry(sNewSource);
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index 942f58b..5f5c703 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -141,6 +141,8 @@
#if ENABLE_CUPS && !defined(MACOSX)
#include <vcl/printerinfomanager.hxx>
#endif
+#include <comphelper/propertysequence.hxx>
+#include <officecfg/Office/Common.hxx>
using namespace ::osl;
@@ -2397,7 +2399,7 @@ Sequence<OUString> SwDBManager::GetExistingDatabaseNames()
return xDBContext->getElementNames();
}
-OUString SwDBManager::LoadAndRegisterDataSource()
+OUString SwDBManager::LoadAndRegisterDataSource(SwDocShell* pDocShell)
{
sfx2::FileDialogHelper aDlgHelper( TemplateDescription::FILEOPEN_SIMPLE, 0 );
Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker();
@@ -2449,7 +2451,7 @@ OUString SwDBManager::LoadAndRegisterDataSource()
if( xSettingsDlg->execute() )
aSettings.set( uno::Reference < beans::XPropertySet >( xSettingsDlg, uno::UNO_QUERY_THROW ) );
}
- sFind = LoadAndRegisterDataSource( type, aURLAny, DBCONN_FLAT == type ? &aSettings : 0, aURI );
+ sFind = LoadAndRegisterDataSource( type, aURLAny, DBCONN_FLAT == type ? &aSettings : 0, aURI, 0, 0, pDocShell );
}
return sFind;
}
@@ -2511,8 +2513,26 @@ SwDBManager::DBConnURITypes SwDBManager::GetDBunoURI(const OUString &rURI, Any &
return type;
}
+/// Returns the URL of this SwDoc.
+OUString lcl_getOwnURL(SwDocShell* pDocShell)
+{
+ OUString aRet;
+
+ // Experimental till load/store of embedded data source definition is not fully implemented.
+ static bool bEmbed = officecfg::Office::Common::Misc::ExperimentalMode::get();
+ if (!bEmbed)
+ return aRet;
+
+ if (!pDocShell)
+ return aRet;
+
+ const INetURLObject& rURLObject = pDocShell->GetMedium()->GetURLObject();
+ aRet = rURLObject.GetMainURL(INetURLObject::DECODE_WITH_CHARSET);
+ return aRet;
+}
+
OUString SwDBManager::LoadAndRegisterDataSource(const DBConnURITypes type, const Any &aURLAny, const uno::Reference< beans::XPropertySet > *pSettings,
- const OUString &rURI, const OUString *pPrefix, const OUString *pDestDir)
+ const OUString &rURI, const OUString *pPrefix, const OUString *pDestDir, SwDocShell* pDocShell)
{
INetURLObject aURL( rURI );
OUString sExt( aURL.GetExtension() );
@@ -2597,14 +2617,33 @@ OUString SwDBManager::LoadAndRegisterDataSource(const DBConnURITypes type, const
Reference<XDocumentDataSource> xDS(xNewInstance, UNO_QUERY_THROW);
Reference<XStorable> xStore(xDS->getDatabaseDocument(), UNO_QUERY_THROW);
OUString sOutputExt = ".odb";
+ OUString aOwnURL = lcl_getOwnURL(pDocShell);
OUString sTmpName;
+ uno::Sequence<beans::PropertyValue> aSequence;
+ if (aOwnURL.isEmpty())
{
+ // Cannot embed, as embedded data source would need the URL of the parent document.
OUString sHomePath(SvtPathOptions().GetWorkPath());
utl::TempFile aTempFile(sNewName, true, &sOutputExt, pDestDir ? pDestDir : &sHomePath);
aTempFile.EnableKillingFile(true);
sTmpName = aTempFile.GetURL();
}
- xStore->storeAsURL(sTmpName, Sequence< PropertyValue >());
+ else
+ {
+ // Embed: construct vnd.sun.star.pkg:// URL for later loading, and TargetStorage/StreamRelPath for storing.
+ OUString aStreamRelPath = "EmbeddedDatabase";
+ sTmpName = "vnd.sun.star.pkg://";
+ sTmpName += INetURLObject::encode(aOwnURL, INetURLObject::PART_AUTHORITY, INetURLObject::ENCODE_ALL);
+ sTmpName += "/" + aStreamRelPath;
+ uno::Reference<embed::XStorage> xStorage = pDocShell->GetStorage();
+
+ aSequence = comphelper::InitPropertySequence(
+ {
+ {"TargetStorage", uno::makeAny(xStorage)},
+ {"StreamRelPath", uno::makeAny(aStreamRelPath)}
+ });
+ }
+ xStore->storeAsURL(sTmpName, aSequence);
}
xDBContext->registerObject( sFind, xNewInstance );
}
commit b499739c438d58c29125cb2777f019c84394786d
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Mon Jun 1 11:36:10 2015 +0200
dbaccess: add support for storing ODatabaseDocument to a sub-storage
When Writer creates an embedded data source definition, it should be
stored on the storage of the Writer document, so Writer sets the
TargetStorage and StreamRelPath parameters of the storeAsURL() call.
Let ODatabaseDocument::impl_storeAs_throw() and
ODatabaseDocument::impl_writeStorage_throw() respect these, so the save
actually succeeds.
Change-Id: I4568ef96204a219b813142d7b5eebe9f1ec5e22e
diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx
index 1f801b7..84a592e 100644
--- a/dbaccess/source/core/dataaccess/databasedocument.cxx
+++ b/dbaccess/source/core/dataaccess/databasedocument.cxx
@@ -91,6 +91,7 @@
#include <list>
#include <svtools/grfmgr.hxx>
+#include <tools/urlobj.hxx>
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
@@ -487,6 +488,8 @@ namespace
{ OUString("BaseURI"), 0, ::cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID, 0 },
{ OUString("StreamName"), 0, ::cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID, 0 },
{ OUString("UsePrettyPrinting"), 0, ::cppu::UnoType<sal_Bool>::get(), beans::PropertyAttribute::MAYBEVOID, 0},
+ {OUString("TargetStorage"), 0, cppu::UnoType<embed::XStorage>::get(), beans::PropertyAttribute::MAYBEVOID, 0},
+ {OUString("StreamRelPath"), 0, cppu::UnoType<OUString>::get(), beans::PropertyAttribute::MAYBEVOID, 0},
{ OUString(), 0, css::uno::Type(), 0, 0 }
};
}
@@ -1074,7 +1077,15 @@ void ODatabaseDocument::impl_storeAs_throw( const OUString& _rURL, const ::comph
if ( bLocationChanged )
{
// create storage for target URL
- Reference< XStorage > xTargetStorage( impl_createStorageFor_throw( _rURL ) );
+ uno::Reference<embed::XStorage> xTargetStorage;
+ _rArguments.get("TargetStorage") >>= xTargetStorage;
+ if (!xTargetStorage.is())
+ xTargetStorage = impl_createStorageFor_throw(_rURL);
+
+ // In case we got a StreamRelPath, then xTargetStorage should reference that sub-storage.
+ OUString sStreamRelPath = _rArguments.getOrDefault("StreamRelPath", OUString());
+ if (!sStreamRelPath.isEmpty())
+ xTargetStorage = xTargetStorage->openStorageElement(sStreamRelPath, embed::ElementModes::READWRITE);
if ( m_pImpl->isEmbeddedDatabase() )
m_pImpl->clearConnections();
@@ -1649,6 +1660,23 @@ void ODatabaseDocument::impl_writeStorage_throw( const Reference< XStorage >& _r
if ( aSaveOpt.IsSaveRelFSys() )
xInfoSet->setPropertyValue("BaseURI", uno::makeAny(_rMediaDescriptor.getOrDefault("URL",OUString())));
+ // Set TargetStorage, so it doesn't have to be re-constructed based on possibly empty URL.
+ xInfoSet->setPropertyValue("TargetStorage", uno::makeAny(m_pImpl->getRootStorage()));
+
+ // Set StreamRelPath, in case this document is an embedded one.
+ OUString sStreamRelPath;
+ OUString sURL = _rMediaDescriptor.getOrDefault("URL", OUString());
+ if (sURL.startsWithIgnoreAsciiCase("vnd.sun.star.pkg:"))
+ {
+ // In this case the host contains the real path, and the the path is the embedded stream name.
+ INetURLObject aURL(sURL);
+ sStreamRelPath = aURL.GetURLPath(INetURLObject::DECODE_WITH_CHARSET);
+ if (sStreamRelPath.startsWith("/"))
+ sStreamRelPath = sStreamRelPath.copy(1);
+ }
+ if (!sStreamRelPath.isEmpty())
+ xInfoSet->setPropertyValue("StreamRelPath", uno::makeAny(sStreamRelPath));
+
sal_Int32 nArgsLen = aDelegatorArguments.getLength();
aDelegatorArguments.realloc(nArgsLen+1);
aDelegatorArguments[nArgsLen++] <<= xInfoSet;
More information about the Libreoffice-commits
mailing list