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

Szymon Kłos szymon.klos at collabora.com
Tue Sep 12 12:58:32 UTC 2017


 sw/inc/dbmgr.hxx                |    9 +++++++++
 sw/source/uibase/app/apphdl.cxx |    8 ++++++++
 sw/source/uibase/dbui/dbmgr.cxx |   28 ++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+)

New commits:
commit cba9bce6936c31aa836763a4dd147ac3db2013bc
Author: Szymon Kłos <szymon.klos at collabora.com>
Date:   Tue Sep 5 17:24:05 2017 +0200

    tdf#108572 revoke connection if mail-merge is cancelled
    
    Change-Id: Idca4969af8043f7dbc54f4a63b99e92155ef1585
    Reviewed-on: https://gerrit.libreoffice.org/41949
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Szymon Kłos <szymon.klos at collabora.com>
    (cherry picked from commit ba368643e6a0c5ac7a7b7ea8d72899d60b2a8331)
    Reviewed-on: https://gerrit.libreoffice.org/42044
    Reviewed-by: Andras Timar <andras.timar at collabora.com>
    Tested-by: Andras Timar <andras.timar at collabora.com>

diff --git a/sw/inc/dbmgr.hxx b/sw/inc/dbmgr.hxx
index 09a077200454..d4797b303e23 100644
--- a/sw/inc/dbmgr.hxx
+++ b/sw/inc/dbmgr.hxx
@@ -258,6 +258,9 @@ friend class SwConnectionDisposedListener_Impl;
     /// Name of the embedded database that's included in the current document.
     OUString     m_sEmbeddedName;
 
+    /// Store last registrations to revoke or commit
+    static std::vector<OUString> m_aUncommitedRegistrations;
+
     /// The document that owns this manager.
     SwDoc* m_pDoc;
 
@@ -478,6 +481,12 @@ public:
     SwDoc* getDoc() const;
     /// Stop reacting to removed database registrations.
     void releaseRevokeListener();
+
+    /// Revoke not commited registrations in case of mail merge cancel
+    void RevokeLastRegistrations();
+
+    /// Accept not commited registrations
+    static void CommitLastRegistrations();
 };
 
 #endif
diff --git a/sw/source/uibase/app/apphdl.cxx b/sw/source/uibase/app/apphdl.cxx
index 5abd1de7c9fa..0b029e6e5a04 100644
--- a/sw/source/uibase/app/apphdl.cxx
+++ b/sw/source/uibase/app/apphdl.cxx
@@ -489,6 +489,8 @@ void SwMailMergeWizardExecutor::ExecutionFinished()
     if (xMMConfig)
         xMMConfig->Commit();
 
+    SwDBManager::CommitLastRegistrations();
+
     // release/destroy asynchronously
     Application::PostUserEvent( LINK( this, SwMailMergeWizardExecutor, DestroyDialogHdl ) );
 }
@@ -661,6 +663,12 @@ IMPL_LINK_NOARG(SwMailMergeWizardExecutor, CancelHdl, void*, void)
         xMMConfig->Commit();
     }
 
+    // Revoke created connections
+    SwDoc* pDoc = m_pView->GetDocShell()->GetDoc();
+    SwDBManager* pDbManager = pDoc->GetDBManager();
+    if (pDbManager)
+        pDbManager->RevokeLastRegistrations();
+
     m_pWizard.disposeAndClear();
     release();
 }
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index 876f4c22166a..410fb02e6ade 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -165,6 +165,8 @@ void lcl_emitEvent(sal_uInt16 nEventId, sal_Int32 nStrId, SfxObjectShell* pDocSh
 
 }
 
+std::vector<OUString> SwDBManager::m_aUncommitedRegistrations;
+
 enum class SwDBNextRecord { NEXT, FIRST };
 static bool lcl_ToNextRecord( SwDSParam* pParam, const SwDBNextRecord action = SwDBNextRecord::NEXT );
 
@@ -2624,6 +2626,8 @@ OUString SwDBManager::LoadAndRegisterDataSource(SwDocShell* pDocShell)
                 aSettings.set( uno::Reference < beans::XPropertySet >( xSettingsDlg, uno::UNO_QUERY_THROW ) );
         }
         sFind = LoadAndRegisterDataSource( type, aURLAny, DBCONN_FLAT == type ? &aSettings : nullptr, aURI, nullptr, nullptr, pDocShell );
+
+        m_aUncommitedRegistrations.push_back(sFind);
     }
     return sFind;
 }
@@ -3200,4 +3204,28 @@ std::shared_ptr<SwMailMergeConfigItem> SwDBManager::PerformMailMerge(SwView* pVi
     return xConfigItem;
 }
 
+void SwDBManager::RevokeLastRegistrations()
+{
+    if (m_aUncommitedRegistrations.size())
+    {
+        SwView* pView = m_pDoc->GetDocShell()->GetView();
+        std::shared_ptr<SwMailMergeConfigItem> xConfigItem = pView->GetMailMergeConfigItem();
+        if (xConfigItem)
+        {
+            xConfigItem->DisposeResultSet();
+            xConfigItem->DocumentReloaded();
+        }
+
+        for (const OUString& rName : m_aUncommitedRegistrations)
+            RevokeDataSource(rName);
+
+        m_aUncommitedRegistrations.clear();
+    }
+}
+
+void SwDBManager::CommitLastRegistrations()
+{
+    m_aUncommitedRegistrations.clear();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list