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

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