[Libreoffice-commits] core.git: Branch 'libreoffice-5-0' - sw/source

Bjoern Michaelsen bjoern.michaelsen at canonical.com
Mon Jul 6 05:58:33 PDT 2015


 sw/source/ui/dbui/mailmergewizard.cxx  |    1 
 sw/source/uibase/dbui/mmconfigitem.cxx |   70 +++++++++++----------------------
 sw/source/uibase/inc/mmconfigitem.hxx  |    6 +-
 3 files changed, 30 insertions(+), 47 deletions(-)

New commits:
commit faf32bcd27b4a1e53cccb03de51a691152a75c6d
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Sat Jul 4 23:22:53 2015 +0200

    tdf#90377: fix exclude recipient in mail merge
    
    - first, actually use the selection in MergeNew()
    - secoond, bring back GetSelection() for that
    - third, throw away lots of the old (dead) code that mostly just
      stumbled over itself
      - e.g. ExcludeRecord() wouldnt work on the last element due to a
        off-by-one error
    
    Change-Id: I07d07e086b748b393f2ada7cb22fdb2ce285ad65
    Reviewed-on: https://gerrit.libreoffice.org/16762
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/sw/source/ui/dbui/mailmergewizard.cxx b/sw/source/ui/dbui/mailmergewizard.cxx
index 341bede..04bd7f8 100644
--- a/sw/source/ui/dbui/mailmergewizard.cxx
+++ b/sw/source/ui/dbui/mailmergewizard.cxx
@@ -276,6 +276,7 @@ void SwMailMergeWizard::CreateTargetDocument()
     aDescriptor[ svx::daCursor ]      <<= m_rConfigItem.GetResultSet();
     aDescriptor[ svx::daCommand ]     <<= m_rConfigItem.GetCurrentDBData().sCommand;
     aDescriptor[ svx::daCommandType ] <<= m_rConfigItem.GetCurrentDBData().nCommandType;
+    aDescriptor[ svx::daSelection ]   <<= m_rConfigItem.GetSelection();
 
     SwMergeDescriptor aMergeDesc( DBMGR_MERGE_SHELL, GetSwView()->GetWrtShell(),
         aDescriptor);
diff --git a/sw/source/uibase/dbui/mmconfigitem.cxx b/sw/source/uibase/dbui/mmconfigitem.cxx
index cec51c7..85f6735 100644
--- a/sw/source/uibase/dbui/mmconfigitem.cxx
+++ b/sw/source/uibase/dbui/mmconfigitem.cxx
@@ -17,7 +17,9 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+
 #include <mmconfigitem.hxx>
+#include <vector>
 #include <swtypes.hxx>
 #include <osl/diagnose.h>
 #include <com/sun/star/uno/Any.hxx>
@@ -34,6 +36,7 @@
 #include <comphelper/processfactory.hxx>
 #include <comphelper/types.hxx>
 #include <com/sun/star/sdb/CommandType.hpp>
+#include <comphelper/sequence.hxx>
 #include <rtl/instance.hxx>
 #include <unotools/configitem.hxx>
 #include <mailmergehelper.hxx>
@@ -1021,57 +1024,34 @@ sal_Int32 SwMailMergeConfigItem::GetResultSetPosition() const
     return m_pImpl->nResultSetCursorPos;
 }
 
-bool SwMailMergeConfigItem::IsRecordExcluded(sal_Int32 nRecord)
-{
-    bool bRet = false;
-    if(nRecord > 0 && nRecord < m_aSelection.getLength())
-    {
-        sal_Int32 nTemp = 0;
-        m_aSelection[nRecord - 1] >>= nTemp;
-        bRet = nTemp < 1;
-    }
-    return bRet;
-}
+bool SwMailMergeConfigItem::IsRecordExcluded(sal_Int32 nRecord) const
+    { return m_aExcludedRecords.find(nRecord) != m_aExcludedRecords.end(); }
 
 void SwMailMergeConfigItem::ExcludeRecord(sal_Int32 nRecord, bool bExclude)
 {
-    //nRecord is based on 1
-    //the selection array contains Anys for all records
-    //excluded records  contain a '-1'
-    if(!m_aSelection.getLength() || nRecord > m_aSelection.getLength())
-    {
-        if(bExclude)
-        {
-            //if no selection array is available we need to create one containing the
-            //entries for all available records
-            if(!m_pImpl->xResultSet.is())
-                GetResultSet();
-            if(m_pImpl->xResultSet.is())
-            {
-                m_pImpl->xResultSet->last();
-                sal_Int32 nEnd = m_pImpl->xResultSet->getRow();
-                sal_Int32 nStart = m_aSelection.getLength();
-                m_aSelection.realloc(nEnd);
-                Any* pSelection = m_aSelection.getArray();
-                for(sal_Int32 nIndex = nStart; nIndex < nEnd; ++nIndex)
-                {
-                    if((nRecord - 1) != nIndex)
-                        pSelection[nIndex] <<= nIndex + 1;
-                    else
-                        pSelection[nIndex] <<= (sal_Int32) -1;
-                }
-            }
-        }
-    }
+    if(bExclude)
+        m_aExcludedRecords.insert(nRecord);
     else
-    {
-        if(nRecord > 0 && m_aSelection.getLength() > nRecord)
-        {
-            m_aSelection[nRecord - 1] <<= bExclude ? -1 : nRecord;
-        }
-    }
+        m_aExcludedRecords.erase(nRecord);
 }
 
+uno::Sequence<uno::Any> SwMailMergeConfigItem::GetSelection() const
+{
+    if(!m_pImpl->xResultSet.is())
+        GetResultSet();
+    if(!m_pImpl->xResultSet.is())
+        return {};
+    m_pImpl->xResultSet->last();
+    sal_Int32 nResultSetSize = m_pImpl->xResultSet->getRow()+1;
+    std::vector<uno::Any> vResult;
+    vResult.reserve(nResultSetSize);
+    for(sal_Int32 nIdx=1; nIdx<nResultSetSize;++nIdx)
+        if(!IsRecordExcluded(nIdx))
+            vResult.push_back(uno::makeAny<sal_Int32>(nIdx));
+    return comphelper::containerToSequence(vResult);
+}
+
+
 const uno::Sequence< OUString>&
                     SwMailMergeConfigItem::GetSavedDocuments() const
 {
diff --git a/sw/source/uibase/inc/mmconfigitem.hxx b/sw/source/uibase/inc/mmconfigitem.hxx
index 7b4115e..07f216c 100644
--- a/sw/source/uibase/inc/mmconfigitem.hxx
+++ b/sw/source/uibase/inc/mmconfigitem.hxx
@@ -22,6 +22,7 @@
 #include <com/sun/star/uno/Sequence.hxx>
 #include <com/sun/star/uno/Reference.hxx>
 #include <tools/resary.hxx>
+#include <set>
 #include <swdbdata.hxx>
 #include "swdllapi.h"
 #include "sharedconnection.hxx"
@@ -56,7 +57,7 @@ class SW_DLLPUBLIC SwMailMergeConfigItem
     bool                                                        m_bGreetingInserted;
     sal_Int32                                                   m_nGreetingMoves;
     OUString                                             m_rAddressBlockFrame;
-    ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any> m_aSelection;
+    std::set<sal_Int32> m_aExcludedRecords;
 
     sal_uInt16                                                      m_nStartPrint;
     sal_uInt16                                                      m_nEndPrint;
@@ -112,8 +113,9 @@ public:
     sal_Int32           GetResultSetPosition()const;
     bool                IsResultSetFirstLast(bool& bIsFirst, bool& bIsLast);
 
-    bool                IsRecordExcluded(sal_Int32 nRecord);
+    bool                IsRecordExcluded(sal_Int32 nRecord) const;
     void                ExcludeRecord(sal_Int32 nRecord, bool bExclude);
+    css::uno::Sequence< css::uno::Any> GetSelection() const;
 
     const com::sun::star::uno::Sequence< OUString>&
                         GetSavedDocuments() const;


More information about the Libreoffice-commits mailing list