summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/dbmgr.hxx5
-rw-r--r--sw/source/ui/dbui/addresslistdialog.cxx10
-rw-r--r--sw/source/uibase/dbui/dbmgr.cxx47
3 files changed, 55 insertions, 7 deletions
diff --git a/sw/inc/dbmgr.hxx b/sw/inc/dbmgr.hxx
index 5bf5432fdc0e..27c86a7268f0 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 9f989d054776..16a55a717ef7 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 942f58b43ade..5f5c703723dd 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 );
}