Blame SOURCES/0197-LOK-CALLBACK_SEARCH_RESULT_COUNT-is-redundant.patch

135360
From 764878984eaaf6099dc2eb7dced5f6faa775bb8a Mon Sep 17 00:00:00 2001
135360
From: Miklos Vajna <vmiklos@collabora.co.uk>
135360
Date: Fri, 9 Oct 2015 08:08:48 +0200
135360
Subject: [PATCH 197/398] LOK: CALLBACK_SEARCH_RESULT_COUNT is redundant
135360
135360
1) The size of the searchResultSelection array in
135360
LOK_CALLBACK_SEARCH_RESULT_SELECTION provides the same information.
135360
135360
2) None of the clients except lokdocview used it.
135360
135360
3) Only sw provided this callback, not sc/sd.
135360
135360
Change-Id: I9da639b6693f24634f298f9bc4773f705e944359
135360
(cherry picked from commit f0e3fe840b6f103c589f044bbde18b2faa345279)
135360
---
135360
 include/LibreOfficeKit/LibreOfficeKitEnums.h   |  6 ------
135360
 libreofficekit/source/gtk/lokdocview.cxx       | 14 ++++++--------
135360
 sw/qa/extras/tiledrendering/tiledrendering.cxx | 12 +-----------
135360
 sw/source/uibase/uiview/viewsrch.cxx           | 14 +++++---------
135360
 4 files changed, 12 insertions(+), 34 deletions(-)
135360
135360
diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h
135360
index b87f69a39989..0da87699b1b5 100644
135360
--- a/include/LibreOfficeKit/LibreOfficeKitEnums.h
135360
+++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h
135360
@@ -158,12 +158,6 @@ typedef enum
135360
     LOK_CALLBACK_SET_PART,
135360
 
135360
     /**
135360
-     * Number of search results followed by the original searched phrase.
135360
-     * count;phrase
135360
-     */
135360
-    LOK_CALLBACK_SEARCH_RESULT_COUNT,
135360
-
135360
-    /**
135360
      * Selection rectangles of the search result when find all is performed.
135360
      *
135360
      * Payload format example, in case of two matches:
135360
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
135360
index a40496eb7357..3f1d5815d05d 100644
135360
--- a/libreofficekit/source/gtk/lokdocview.cxx
135360
+++ b/libreofficekit/source/gtk/lokdocview.cxx
135360
@@ -12,6 +12,7 @@
135360
 #include <string.h>
135360
 #include <vector>
135360
 #include <string>
135360
+#include <boost/property_tree/json_parser.hpp>
135360
 
135360
 #include <com/sun/star/awt/Key.hpp>
135360
 #define LOK_USE_UNSTABLE_API
135360
@@ -227,8 +228,6 @@ callbackTypeToString (int nType)
135360
         return "LOK_CALLBACK_STATUS_INDICATOR_FINISH";
135360
     case LOK_CALLBACK_SEARCH_NOT_FOUND:
135360
         return "LOK_CALLBACK_SEARCH_NOT_FOUND";
135360
-    case LOK_CALLBACK_SEARCH_RESULT_COUNT:
135360
-        return "LOK_CALLBACK_SEARCH_RESULT_COUNT";
135360
     case LOK_CALLBACK_DOCUMENT_SIZE_CHANGED:
135360
         return "LOK_CALLBACK_DOCUMENT_SIZE_CHANGED";
135360
     case LOK_CALLBACK_SET_PART:
135360
@@ -661,12 +660,6 @@ callback (gpointer pData)
135360
         searchNotFound(pDocView, pCallback->m_aPayload);
135360
     }
135360
     break;
135360
-    case LOK_CALLBACK_SEARCH_RESULT_COUNT:
135360
-    {
135360
-        size_t nPos = pCallback->m_aPayload.find_first_of(";");
135360
-        searchResultCount(pDocView, pCallback->m_aPayload.substr(0, nPos));
135360
-    }
135360
-    break;
135360
     case LOK_CALLBACK_DOCUMENT_SIZE_CHANGED:
135360
     {
135360
         payloadToSize(pCallback->m_aPayload.c_str(), priv->m_nDocumentWidthTwips, priv->m_nDocumentHeightTwips);
135360
@@ -684,6 +677,11 @@ callback (gpointer pData)
135360
     break;
135360
     case LOK_CALLBACK_SEARCH_RESULT_SELECTION:
135360
     {
135360
+        boost::property_tree::ptree aTree;
135360
+        std::stringstream aStream(pCallback->m_aPayload);
135360
+        boost::property_tree::read_json(aStream, aTree);
135360
+        int nCount = aTree.get_child("searchResultSelection").size();
135360
+        searchResultCount(pDocView, std::to_string(nCount));
135360
     }
135360
     break;
135360
     default:
135360
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
135360
index 1eb57dea109e..eb59b62b9208 100644
135360
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
135360
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
135360
@@ -72,13 +72,11 @@ private:
135360
     Size m_aDocumentSize;
135360
     OString m_aTextSelection;
135360
     bool m_bFound;
135360
-    sal_Int32 m_nSearchResultCount;
135360
     std::vector<OString> m_aSearchResultSelection;
135360
 };
135360
 
135360
 SwTiledRenderingTest::SwTiledRenderingTest()
135360
-    : m_bFound(true),
135360
-      m_nSearchResultCount(0)
135360
+    : m_bFound(true)
135360
 {
135360
 }
135360
 
135360
@@ -134,12 +132,6 @@ void SwTiledRenderingTest::callbackImpl(int nType, const char* pPayload)
135360
         m_bFound = false;
135360
     }
135360
     break;
135360
-    case LOK_CALLBACK_SEARCH_RESULT_COUNT:
135360
-    {
135360
-        std::string aStrPayload(pPayload);
135360
-        m_nSearchResultCount = std::stoi(aStrPayload.substr(0, aStrPayload.find_first_of(";")));
135360
-    }
135360
-    break;
135360
     case LOK_CALLBACK_SEARCH_RESULT_SELECTION:
135360
     {
135360
         m_aSearchResultSelection.clear();
135360
@@ -485,8 +477,6 @@ void SwTiledRenderingTest::testSearchAll()
135360
     }));
135360
     comphelper::dispatchCommand(".uno:ExecuteSearch", aPropertyValues);
135360
     // This was 0; should be 2 results in the body text.
135360
-    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), m_nSearchResultCount);
135360
-    // Make sure that we get exactly as many rectangle lists as matches.
135360
     CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), m_aSearchResultSelection.size());
135360
 
135360
     comphelper::LibreOfficeKit::setActive(false);
135360
diff --git a/sw/source/uibase/uiview/viewsrch.cxx b/sw/source/uibase/uiview/viewsrch.cxx
135360
index c8d3e7a571ea..7f1addcc3f6b 100644
135360
--- a/sw/source/uibase/uiview/viewsrch.cxx
135360
+++ b/sw/source/uibase/uiview/viewsrch.cxx
135360
@@ -103,11 +103,8 @@ static void lcl_addContainerToJson(boost::property_tree::ptree& rTree, const OSt
135360
 }
135360
 
135360
 /// Emits LOK callbacks (count, selection) for search results.
135360
-static void lcl_emitSearchResultCallbacks(sal_uInt16 nFound, SvxSearchItem* pSearchItem, SwWrtShell* pWrtShell)
135360
+static void lcl_emitSearchResultCallbacks(SvxSearchItem* pSearchItem, SwWrtShell* pWrtShell)
135360
 {
135360
-    OString aPayload = OString::number(nFound) + ";" + pSearchItem->GetSearchString().toUtf8();
135360
-    pWrtShell->libreOfficeKitCallback(LOK_CALLBACK_SEARCH_RESULT_COUNT, aPayload.getStr());
135360
-
135360
     // Emit a callback also about the selection rectangles, grouped by matches.
135360
     if (SwPaM* pPaM = pWrtShell->GetCrsr())
135360
     {
135360
@@ -141,7 +138,7 @@ static void lcl_emitSearchResultCallbacks(sal_uInt16 nFound, SvxSearchItem* pSea
135360
 
135360
         std::stringstream aStream;
135360
         boost::property_tree::write_json(aStream, aTree);
135360
-        aPayload = aStream.str().c_str();
135360
+        OString aPayload = aStream.str().c_str();
135360
 
135360
         pWrtShell->libreOfficeKitCallback(LOK_CALLBACK_SEARCH_RESULT_SELECTION, aPayload.getStr());
135360
     }
135360
@@ -256,7 +253,7 @@ void SwView::ExecSearch(SfxRequest& rReq, bool bNoMessage)
135360
                 {
135360
                     Scroll(m_pWrtShell->GetCharRect().SVRect());
135360
                     if (comphelper::LibreOfficeKit::isActive())
135360
-                        lcl_emitSearchResultCallbacks(1, m_pSrchItem, m_pWrtShell);
135360
+                        lcl_emitSearchResultCallbacks(m_pSrchItem, m_pWrtShell);
135360
                 }
135360
                 rReq.SetReturnValue(SfxBoolItem(nSlot, bRet));
135360
 #if HAVE_FEATURE_DESKTOP
135360
@@ -275,8 +272,7 @@ void SwView::ExecSearch(SfxRequest& rReq, bool bNoMessage)
135360
             break;
135360
             case SvxSearchCmd::FIND_ALL:
135360
             {
135360
-                sal_uInt16 nFound = 0;
135360
-                bool bRet = SearchAll(&nFound);
135360
+                bool bRet = SearchAll();
135360
                 if( !bRet )
135360
                 {
135360
 #if HAVE_FEATURE_DESKTOP
135360
@@ -290,7 +286,7 @@ void SwView::ExecSearch(SfxRequest& rReq, bool bNoMessage)
135360
                     m_bFound = false;
135360
                 }
135360
                 else if (comphelper::LibreOfficeKit::isActive())
135360
-                    lcl_emitSearchResultCallbacks(nFound, m_pSrchItem, m_pWrtShell);
135360
+                    lcl_emitSearchResultCallbacks(m_pSrchItem, m_pWrtShell);
135360
                 rReq.SetReturnValue(SfxBoolItem(nSlot, bRet));
135360
 #if HAVE_FEATURE_DESKTOP
135360
                 {
135360
-- 
135360
2.12.0
135360