From 36825f49853431433297fbcd23488c7fd1dbfc85 Mon Sep 17 00:00:00 2001 From: Gülşah Köse Date: Mon, 29 Mar 2021 11:52:05 +0300 Subject: tdf#139906 Show warning message when data source is not avaible. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CurrentDatabaseDataSource config item holds a database name for a specific file. When document has CurrentDatabaseDataSource config item but LibreOffice doesn't have in registered databases we should notify the user at load time and put a button to fix the problem. Change-Id: Ia0a6fd53985fc2fb82ce37d3962b3f479c20a647 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113296 Tested-by: Jenkins Reviewed-by: Gülşah Köse Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113701 Tested-by: Jenkins CollaboraOffice Reviewed-by: Jan Holesovsky --- sw/inc/strings.hrc | 3 ++ sw/inc/view.hxx | 7 +++++ sw/source/uibase/uiview/view.cxx | 67 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 76 insertions(+), 1 deletion(-) diff --git a/sw/inc/strings.hrc b/sw/inc/strings.hrc index c2b15f563c68..4fabab278917 100644 --- a/sw/inc/strings.hrc +++ b/sw/inc/strings.hrc @@ -1383,6 +1383,9 @@ #define STR_AUTOMARK_YES NC_("createautomarkdialog|yes", "Yes") #define STR_AUTOMARK_NO NC_("createautomarkdialog|no", "No") +#define STR_DATASOURCE_NOT_AVAILABLE NC_("STR_DATASOURCE_NOT_AVAILABLE", "Data source is not available. Mail merge wizard will not work properly.") +#define STR_EXCHANGE_DATABASE NC_("STR_EXCHANGE_DATABASE", "Exchange Database") + #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/inc/view.hxx b/sw/inc/view.hxx index 6c42497efeb6..fc855b426d85 100644 --- a/sw/inc/view.hxx +++ b/sw/inc/view.hxx @@ -20,6 +20,7 @@ #define INCLUDED_SW_INC_VIEW_HXX #include +#include #include #include #include @@ -542,6 +543,8 @@ public: // form control has been activated DECL_LINK( FormControlActivated, LinkParamNone*, void ); + DECL_LINK( ExchangeDatabaseHandler, Button*, void); + // edit links void EditLinkDlg(); void AutoCaption(const sal_uInt16 nType, const SvGlobalName *pOleId = nullptr); @@ -611,6 +614,10 @@ public: std::shared_ptr const & GetMailMergeConfigItem() const; std::shared_ptr EnsureMailMergeConfigItem(const SfxItemSet* pArgs = nullptr); + OUString GetDataSourceName() const; + static bool IsDataSourceAvailable(const OUString sDataSourceName); + void AppendDataSourceInfobar(); + void ExecFormatPaintbrush(SfxRequest const &); void StateFormatPaintbrush(SfxItemSet &); diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx index b06fa1a38457..23127155d4f6 100644 --- a/sw/source/uibase/uiview/view.cxx +++ b/sw/source/uibase/uiview/view.cxx @@ -38,6 +38,8 @@ #include #include #include +#include +#include #include #include #include @@ -75,6 +77,7 @@ #include #include #include +#include #include #include #include @@ -98,6 +101,10 @@ #include #include #include +#include +#include +#include +#include #include #include #include @@ -125,6 +132,8 @@ using namespace ::com::sun::star; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::scanner; +using namespace ::com::sun::star::sdb; +using namespace ::com::sun::star::sdbc; #define SWVIEWFLAGS SfxViewShellFlags::HAS_PRINTOPTIONS @@ -223,6 +232,11 @@ IMPL_LINK_NOARG(SwView, FormControlActivated, LinkParamNone*, void) } } +IMPL_LINK_NOARG(SwView, ExchangeDatabaseHandler, Button*, void) +{ + GetDispatcher().Execute(FN_CHANGE_DBFIELD); +} + namespace { uno::Reference getLayoutManager(const SfxViewFrame& rViewFrame) @@ -1645,7 +1659,25 @@ void SwView::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) } else { + if (auto pSfxEventHint = dynamic_cast(&rHint)) + { + switch( pSfxEventHint->GetEventId() ) + { + case SfxEventHintId::CreateDoc: + case SfxEventHintId::OpenDoc: + { + OUString sDataSourceName = GetDataSourceName(); + if ( !sDataSourceName.isEmpty() && !IsDataSourceAvailable(sDataSourceName)) + AppendDataSourceInfobar(); + } + break; + default: + break; + } + } + SfxHintId nId = rHint.GetId(); + switch ( nId ) { // sub shells will be destroyed by the @@ -1726,7 +1758,6 @@ void SwView::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) GetViewFrame()->GetBindings().Invalidate(aSlotRedLine); } break; - default: break; } } @@ -1889,6 +1920,40 @@ tools::Rectangle SwView::getLOKVisibleArea() const return tools::Rectangle(); } +OUString SwView::GetDataSourceName() const +{ + uno::Reference xFactory(GetDocShell()->GetModel(), uno::UNO_QUERY); + uno::Reference xSettings( + xFactory->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY); + OUString sDataSourceName = ""; + xSettings->getPropertyValue("CurrentDatabaseDataSource") >>= sDataSourceName; + + return sDataSourceName; +} + +bool SwView::IsDataSourceAvailable(const OUString sDataSourceName) +{ + uno::Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() ); + Reference< XDatabaseContext> xDatabaseContext = DatabaseContext::create(xContext); + + return xDatabaseContext->hasByName(sDataSourceName); +} + +void SwView::AppendDataSourceInfobar() +{ + auto pInfoBar = GetViewFrame()->AppendInfoBar("datasource", "", + SwResId(STR_DATASOURCE_NOT_AVAILABLE), + InfobarType::WARNING); + if (!pInfoBar) + return; + + VclPtrInstance xBtn(GetWindow()); + xBtn->SetText(SwResId(STR_EXCHANGE_DATABASE)); + xBtn->SetSizePixel(xBtn->GetOptimalSize()); + xBtn->SetClickHdl(LINK(this, SwView, ExchangeDatabaseHandler)); + pInfoBar->addButton(xBtn); +} + namespace sw { void InitPrintOptionsFromApplication(SwPrintData & o_rData, bool const bWeb) -- cgit