sw/inc/strings.hrc                     |    3 +
 sw/inc/view.hxx                        |    6 +++
 sw/source/ui/dbui/mailmergewizard.cxx  |    9 ++++
 sw/source/ui/dbui/mmdocselectpage.cxx  |   17 +++++++-
 sw/source/ui/dbui/mmdocselectpage.hxx  |    1 
 sw/source/uibase/uiview/view.cxx       |   65 ++++++++++++++++++++++++++++++++-
 sw/uiconfig/swriter/ui/mmselectpage.ui |   17 ++++++++
 7 files changed, 114 insertions(+), 4 deletions(-)

New commits:
commit 4d2db8230fa7412dd523cf78fd0efe3609b6cb31
Author:     Gülşah Köse <gulsah.k...@collabora.com>
AuthorDate: Wed Mar 31 22:48:03 2021 +0300
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Fri Apr 9 23:35:41 2021 +0200

    tdf#139906 Prevent to use the Mail Merge wizard without data source.
    
    When the file has a data source but that data source is not available in
    LibreOffice we shouldn't let user continue mail merging.
    
    Change-Id: Ic28101a12b2e33e78fd9b478fc41707786344e52
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113432
    Tested-by: Jenkins
    Reviewed-by: Gülşah Köse <gulsah.k...@collabora.com>

diff --git a/sw/source/ui/dbui/mailmergewizard.cxx 
b/sw/source/ui/dbui/mailmergewizard.cxx
index bb10a2a9a0da..87116262facf 100644
--- a/sw/source/ui/dbui/mailmergewizard.cxx
+++ b/sw/source/ui/dbui/mailmergewizard.cxx
@@ -142,7 +142,16 @@ void SwMailMergeWizard::enterState( WizardState _nState )
     switch(_nState)
     {
         case MM_DOCUMENTSELECTPAGE:
+        {
             bEnablePrev = false; // the first page
+
+            OUString sDataSourceName = GetSwView()->GetDataSourceName();
+            if(!sDataSourceName.isEmpty() &&
+               !SwView::IsDataSourceAvailable(sDataSourceName))
+            {
+                bEnableNext = false;
+            }
+        }
         break;
         case MM_ADDRESSBLOCKPAGE  :
             bEnableNext = m_xConfigItem->GetResultSet().is();
diff --git a/sw/source/ui/dbui/mmdocselectpage.cxx 
b/sw/source/ui/dbui/mmdocselectpage.cxx
index f19089126a03..a83a7e727f7b 100644
--- a/sw/source/ui/dbui/mmdocselectpage.cxx
+++ b/sw/source/ui/dbui/mmdocselectpage.cxx
@@ -49,6 +49,7 @@ 
SwMailMergeDocSelectPage::SwMailMergeDocSelectPage(weld::Container* pPage, SwMai
     , m_xBrowseDocPB(m_xBuilder->weld_button("browsedoc"))
     , m_xBrowseTemplatePB(m_xBuilder->weld_button("browsetemplate"))
     , m_xRecentDocLB(m_xBuilder->weld_combo_box("recentdoclb"))
+    , m_xDataSourceWarningFT(m_xBuilder->weld_label("datasourcewarning"))
 {
     m_xCurrentDocRB->set_active(true);
     DocSelectHdl(*m_xNewDocRB);
@@ -84,9 +85,21 @@ SwMailMergeDocSelectPage::~SwMailMergeDocSelectPage()
 IMPL_LINK_NOARG(SwMailMergeDocSelectPage, DocSelectHdl, weld::ToggleButton&, 
void)
 {
     m_xRecentDocLB->set_sensitive(m_xRecentDocRB->get_active());
-
     m_pWizard->UpdateRoadmap();
-    m_pWizard->enableButtons(WizardButtonFlags::NEXT, 
m_pWizard->isStateEnabled(MM_OUTPUTTYPETPAGE));
+    OUString sDataSourceName = m_pWizard->GetSwView()->GetDataSourceName();
+
+    if(m_xCurrentDocRB->get_active() &&
+       !sDataSourceName.isEmpty() &&
+       !SwView::IsDataSourceAvailable(sDataSourceName))
+    {
+        m_xDataSourceWarningFT->show();
+        m_pWizard->enableButtons(WizardButtonFlags::NEXT, false);
+    }
+    else
+    {
+        m_xDataSourceWarningFT->hide();
+        m_pWizard->enableButtons(WizardButtonFlags::NEXT, 
m_pWizard->isStateEnabled(MM_OUTPUTTYPETPAGE));
+    }
 }
 
 IMPL_LINK(SwMailMergeDocSelectPage, FileSelectHdl, weld::Button&, rButton, 
void)
diff --git a/sw/source/ui/dbui/mmdocselectpage.hxx 
b/sw/source/ui/dbui/mmdocselectpage.hxx
index 88ac9e40dc8d..67cea59b6450 100644
--- a/sw/source/ui/dbui/mmdocselectpage.hxx
+++ b/sw/source/ui/dbui/mmdocselectpage.hxx
@@ -39,6 +39,7 @@ class SwMailMergeDocSelectPage : public vcl::OWizardPage
     std::unique_ptr<weld::Button> m_xBrowseDocPB;
     std::unique_ptr<weld::Button> m_xBrowseTemplatePB;
     std::unique_ptr<weld::ComboBox> m_xRecentDocLB;
+    std::unique_ptr<weld::Label> m_xDataSourceWarningFT;
 
     DECL_LINK(DocSelectHdl, weld::ToggleButton&, void);
     DECL_LINK(FileSelectHdl, weld::Button&, void);
diff --git a/sw/uiconfig/swriter/ui/mmselectpage.ui 
b/sw/uiconfig/swriter/ui/mmselectpage.ui
index 124f91b38c99..dd2f71529348 100644
--- a/sw/uiconfig/swriter/ui/mmselectpage.ui
+++ b/sw/uiconfig/swriter/ui/mmselectpage.ui
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.36.0 -->
+<!-- Generated with glade 3.22.2 -->
 <interface domain="sw">
   <requires lib="gtk+" version="3.20"/>
   <object class="GtkBox" id="MMSelectPage">
@@ -192,6 +192,21 @@
                 </child>
               </object>
             </child>
+            <child>
+              <object class="GtkLabel" id="datasourcewarning">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">start</property>
+                <property name="label" translatable="yes" 
context="mmselectpage|extended_tip|datasourcewarning">Data source of the 
current document is not registered.</property>
+                <attributes>
+                  <attribute name="foreground" value="#cccc00000000"/>
+                </attributes>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">8</property>
+              </packing>
+            </child>
           </object>
         </child>
         <child type="label">
commit 330bfa09d825b4a5827f45d5cd3d19086ff2c692
Author:     Gülşah Köse <gulsah.k...@collabora.com>
AuthorDate: Mon Mar 29 11:52:05 2021 +0300
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Fri Apr 9 23:35:25 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.k...@collabora.com>

diff --git a/sw/inc/strings.hrc b/sw/inc/strings.hrc
index e5f20d867d2d..9a924698a82e 100644
--- a/sw/inc/strings.hrc
+++ b/sw/inc/strings.hrc
@@ -1384,6 +1384,9 @@
 #define STR_AUTOMARK_NO                         NC_("createautomarkdialog|no", 
"No")
 
 #define STR_WRAP_PANEL_CUSTOM_STR               NC_("sidebarwrap|customlabel", 
"Custom")
+#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
 
diff --git a/sw/inc/view.hxx b/sw/inc/view.hxx
index 7e3feca87883..0cf34eccc881 100644
--- a/sw/inc/view.hxx
+++ b/sw/inc/view.hxx
@@ -542,6 +542,8 @@ public:
     // form control has been activated
     DECL_LINK( FormControlActivated, LinkParamNone*, void );
 
+    DECL_LINK( ExchangeDatabaseHandler, weld::Button&, void);
+
     // edit links
     void            EditLinkDlg();
     void            AutoCaption(const sal_uInt16 nType, const SvGlobalName 
*pOleId = nullptr);
@@ -611,6 +613,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 3e10ab192e5a..9dd7b932de0b 100644
--- a/sw/source/uibase/uiview/view.cxx
+++ b/sw/source/uibase/uiview/view.cxx
@@ -34,6 +34,8 @@
 #include <sfx2/docfile.hxx>
 #include <sfx2/objface.hxx>
 #include <sfx2/request.hxx>
+#include <sfx2/event.hxx>
+#include <sfx2/infobar.hxx>
 #include <svx/ruler.hxx>
 #include <svx/srchdlg.hxx>
 #include <svx/fmshell.hxx>
@@ -66,6 +68,7 @@
 #include <gloshdl.hxx>
 #include <usrpref.hxx>
 #include <srcview.hxx>
+#include <strings.hrc>
 #include <doc.hxx>
 #include <IDocumentUndoRedo.hxx>
 #include <IDocumentSettingAccess.hxx>
@@ -84,6 +87,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 <sal/log.hxx>
 
@@ -105,6 +112,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
 
@@ -203,6 +212,11 @@ IMPL_LINK_NOARG(SwView, FormControlActivated, 
LinkParamNone*, void)
     }
 }
 
+IMPL_LINK_NOARG(SwView, ExchangeDatabaseHandler, weld::Button&, void)
+{
+    GetDispatcher().Execute(FN_CHANGE_DBFIELD);
+}
+
 namespace
 {
 uno::Reference<frame::XLayoutManager> getLayoutManager(const SfxViewFrame& 
rViewFrame)
@@ -1629,7 +1643,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
@@ -1710,7 +1742,6 @@ void SwView::Notify( SfxBroadcaster& rBC, const SfxHint& 
rHint )
                     GetViewFrame()->GetBindings().Invalidate(aSlotRedLine);
                 }
                 break;
-
             default: break;
         }
     }
@@ -1864,6 +1895,38 @@ void SwView::AddTransferable(SwTransferable& 
rTransferable)
     GetViewImpl()->AddTransferable(rTransferable);
 }
 
+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;
+
+    weld::Button& rBtn = pInfoBar->addButton();
+    rBtn.set_label(SwResId(STR_EXCHANGE_DATABASE));
+    rBtn.connect_clicked(LINK(this, SwView, ExchangeDatabaseHandler));
+}
+
 namespace sw {
 
 void InitPrintOptionsFromApplication(SwPrintData & o_rData, bool const bWeb)
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to