Kaydet (Commit) 54bf49a2 authored tarafından Miklos Vajna's avatar Miklos Vajna

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
üst b499739c
...@@ -350,7 +350,7 @@ public: ...@@ -350,7 +350,7 @@ public:
the filename returned by a file picker and additional settings dialog. the filename returned by a file picker and additional settings dialog.
In case of success it returns the registered name, otherwise an empty string. 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. Loads a data source from file and registers it.
...@@ -360,7 +360,8 @@ public: ...@@ -360,7 +360,8 @@ public:
*/ */
static OUString LoadAndRegisterDataSource(const DBConnURITypes type, const ::com::sun::star::uno::Any &rUnoURI, 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 ::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. Loads a data source from file and registers it.
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include <unotools/pathoptions.hxx> #include <unotools/pathoptions.hxx>
#include <svl/urihelper.hxx> #include <svl/urihelper.hxx>
#include <dbui.hrc> #include <dbui.hrc>
#include <view.hxx>
#include <helpid.h> #include <helpid.h>
#include <unomid.h> #include <unomid.h>
...@@ -345,7 +346,14 @@ IMPL_LINK_NOARG(SwAddressListDialog, FilterHdl_Impl) ...@@ -345,7 +346,14 @@ IMPL_LINK_NOARG(SwAddressListDialog, FilterHdl_Impl)
IMPL_LINK_NOARG(SwAddressListDialog, LoadHdl_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()) if(!sNewSource.isEmpty())
{ {
SvTreeListEntry* pNewSource = m_pListLB->InsertEntry(sNewSource); SvTreeListEntry* pNewSource = m_pListLB->InsertEntry(sNewSource);
......
...@@ -141,6 +141,8 @@ ...@@ -141,6 +141,8 @@
#if ENABLE_CUPS && !defined(MACOSX) #if ENABLE_CUPS && !defined(MACOSX)
#include <vcl/printerinfomanager.hxx> #include <vcl/printerinfomanager.hxx>
#endif #endif
#include <comphelper/propertysequence.hxx>
#include <officecfg/Office/Common.hxx>
using namespace ::osl; using namespace ::osl;
...@@ -2397,7 +2399,7 @@ Sequence<OUString> SwDBManager::GetExistingDatabaseNames() ...@@ -2397,7 +2399,7 @@ Sequence<OUString> SwDBManager::GetExistingDatabaseNames()
return xDBContext->getElementNames(); return xDBContext->getElementNames();
} }
OUString SwDBManager::LoadAndRegisterDataSource() OUString SwDBManager::LoadAndRegisterDataSource(SwDocShell* pDocShell)
{ {
sfx2::FileDialogHelper aDlgHelper( TemplateDescription::FILEOPEN_SIMPLE, 0 ); sfx2::FileDialogHelper aDlgHelper( TemplateDescription::FILEOPEN_SIMPLE, 0 );
Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker(); Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker();
...@@ -2449,7 +2451,7 @@ OUString SwDBManager::LoadAndRegisterDataSource() ...@@ -2449,7 +2451,7 @@ OUString SwDBManager::LoadAndRegisterDataSource()
if( xSettingsDlg->execute() ) if( xSettingsDlg->execute() )
aSettings.set( uno::Reference < beans::XPropertySet >( xSettingsDlg, uno::UNO_QUERY_THROW ) ); 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; return sFind;
} }
...@@ -2511,8 +2513,26 @@ SwDBManager::DBConnURITypes SwDBManager::GetDBunoURI(const OUString &rURI, Any & ...@@ -2511,8 +2513,26 @@ SwDBManager::DBConnURITypes SwDBManager::GetDBunoURI(const OUString &rURI, Any &
return type; 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, 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 ); INetURLObject aURL( rURI );
OUString sExt( aURL.GetExtension() ); OUString sExt( aURL.GetExtension() );
...@@ -2597,14 +2617,33 @@ OUString SwDBManager::LoadAndRegisterDataSource(const DBConnURITypes type, const ...@@ -2597,14 +2617,33 @@ OUString SwDBManager::LoadAndRegisterDataSource(const DBConnURITypes type, const
Reference<XDocumentDataSource> xDS(xNewInstance, UNO_QUERY_THROW); Reference<XDocumentDataSource> xDS(xNewInstance, UNO_QUERY_THROW);
Reference<XStorable> xStore(xDS->getDatabaseDocument(), UNO_QUERY_THROW); Reference<XStorable> xStore(xDS->getDatabaseDocument(), UNO_QUERY_THROW);
OUString sOutputExt = ".odb"; OUString sOutputExt = ".odb";
OUString aOwnURL = lcl_getOwnURL(pDocShell);
OUString sTmpName; 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()); OUString sHomePath(SvtPathOptions().GetWorkPath());
utl::TempFile aTempFile(sNewName, true, &sOutputExt, pDestDir ? pDestDir : &sHomePath); utl::TempFile aTempFile(sNewName, true, &sOutputExt, pDestDir ? pDestDir : &sHomePath);
aTempFile.EnableKillingFile(true); aTempFile.EnableKillingFile(true);
sTmpName = aTempFile.GetURL(); 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 ); xDBContext->registerObject( sFind, xNewInstance );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment