[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - sw/inc sw/source

Gülşah Köse (via logerrit) logerrit at kemper.freedesktop.org
Thu Apr 8 07:00:21 UTC 2021


 sw/inc/strings.hrc               |    3 +
 sw/inc/view.hxx                  |    7 ++++
 sw/source/uibase/uiview/view.cxx |   67 ++++++++++++++++++++++++++++++++++++++-
 3 files changed, 76 insertions(+), 1 deletion(-)

New commits:
commit 36825f49853431433297fbcd23488c7fd1dbfc85
Author:     Gülşah Köse <gulsah.kose at collabora.com>
AuthorDate: Mon Mar 29 11:52:05 2021 +0300
Commit:     Jan Holesovsky <kendy at collabora.com>
CommitDate: Thu Apr 8 08:59:46 2021 +0200

    tdf#139906 Show warning message when data source is not avaible.
    
    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 <gulsah.kose at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113701
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>

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 <vcl/timer.hxx>
+#include <vcl/weld.hxx>
 #include <sfx2/viewsh.hxx>
 #include <sfx2/objsh.hxx>
 #include <editeng/svxenum.hxx>
@@ -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<SwMailMergeConfigItem> const & GetMailMergeConfigItem() const;
     std::shared_ptr<SwMailMergeConfigItem> 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 <sfx2/objface.hxx>
 #include <sfx2/printer.hxx>
 #include <sfx2/request.hxx>
+#include <sfx2/event.hxx>
+#include <sfx2/infobar.hxx>
 #include <svx/ruler.hxx>
 #include <svx/srchdlg.hxx>
 #include <editeng/protitem.hxx>
@@ -75,6 +77,7 @@
 #include <gloshdl.hxx>
 #include <usrpref.hxx>
 #include <srcview.hxx>
+#include <strings.hrc>
 #include <doc.hxx>
 #include <IDocumentUndoRedo.hxx>
 #include <IDocumentSettingAccess.hxx>
@@ -98,6 +101,10 @@
 #include <com/sun/star/frame/XLayoutManager.hpp>
 #include <com/sun/star/scanner/ScannerContext.hpp>
 #include <com/sun/star/scanner/XScannerManager2.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/sdb/XDatabaseContext.hpp>
+#include <com/sun/star/sdb/DatabaseContext.hpp>
+#include <com/sun/star/sdbc/XDataSource.hpp>
 #include <toolkit/helper/vclunohelper.hxx>
 #include <rtl/ustrbuf.hxx>
 #include <sal/log.hxx>
@@ -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<frame::XLayoutManager> getLayoutManager(const SfxViewFrame& rViewFrame)
@@ -1645,7 +1659,25 @@ void SwView::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
     }
     else
     {
+        if (auto pSfxEventHint = dynamic_cast<const SfxEventHint*>(&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<lang::XMultiServiceFactory> xFactory(GetDocShell()->GetModel(), uno::UNO_QUERY);
+    uno::Reference<beans::XPropertySet> 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<PushButton> 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)


More information about the Libreoffice-commits mailing list