[Libreoffice-commits] core.git: cui/source

Yusuf Keten (via logerrit) logerrit at kemper.freedesktop.org
Wed Aug 26 19:50:05 UTC 2020


 cui/source/dialogs/AdditionsDialog.cxx |   59 +++++++++++++++++++++++++++------
 cui/source/inc/AdditionsDialog.hxx     |    6 +++
 2 files changed, 55 insertions(+), 10 deletions(-)

New commits:
commit f1e6919a5072b3f4bc67dbf5d8fcde524b74ecf8
Author:     Yusuf Keten <ketenyusuf at gmail.com>
AuthorDate: Fri Aug 21 02:30:26 2020 +0300
Commit:     Muhammet Kara <muhammet.kara at collabora.com>
CommitDate: Wed Aug 26 21:49:22 2020 +0200

    tdf#135275: Additions: Sorting of extensions
    
    Change-Id: If10820786ebc1f97aef24a7cb71a9f8a67e4bb8d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101097
    Tested-by: Jenkins
    Reviewed-by: Muhammet Kara <muhammet.kara at collabora.com>

diff --git a/cui/source/dialogs/AdditionsDialog.cxx b/cui/source/dialogs/AdditionsDialog.cxx
index 7460fb576790..395198948dea 100644
--- a/cui/source/dialogs/AdditionsDialog.cxx
+++ b/cui/source/dialogs/AdditionsDialog.cxx
@@ -445,6 +445,8 @@ void SearchAndParseThread::execute()
     {
         std::string sResponse = curlGet(m_pAdditionsDialog->m_sURL);
         parseResponse(sResponse, m_pAdditionsDialog->m_aAllExtensionsVector);
+        std::sort(m_pAdditionsDialog->m_aAllExtensionsVector.begin(),
+                  m_pAdditionsDialog->m_aAllExtensionsVector.end(), AdditionsDialog::sortByRating);
         Search();
     }
     else // Searching
@@ -471,6 +473,9 @@ AdditionsDialog::AdditionsDialog(weld::Window* pParent, const OUString& sAdditio
     , m_xLabelProgress(m_xBuilder->weld_label("labelProgress"))
     , m_xGearBtn(m_xBuilder->weld_menu_button("buttonGear"))
 {
+    m_xGearBtn->connect_selected(LINK(this, AdditionsDialog, GearHdl));
+    m_xGearBtn->set_item_active("gear_sort_voting", true);
+
     m_aSearchDataTimer.SetInvokeHandler(LINK(this, AdditionsDialog, ImplUpdateDataHdl));
     m_aSearchDataTimer.SetDebugName("AdditionsDialog SearchDataTimer");
     m_aSearchDataTimer.SetTimeout(EDIT_UPDATEDATA_TIMEOUT);
@@ -579,6 +584,32 @@ void AdditionsDialog::ClearList()
     this->m_aAdditionsItems.clear();
 }
 
+void AdditionsDialog::RefreshUI()
+{
+    if (m_pSearchThread.is())
+        m_pSearchThread->StopExecution();
+    ClearList();
+    m_nCurrentListItemCount = 0;
+    m_nMaxItemCount = PAGE_SIZE;
+    m_pSearchThread = new SearchAndParseThread(this, false);
+    m_pSearchThread->launch();
+}
+
+bool AdditionsDialog::sortByRating(const AdditionInfo& a, const AdditionInfo& b)
+{
+    return a.sRating.toDouble() > b.sRating.toDouble();
+}
+
+bool AdditionsDialog::sortByComment(const AdditionInfo& a, const AdditionInfo& b)
+{
+    return a.sCommentNumber.toUInt32() > b.sCommentNumber.toUInt32();
+}
+
+bool AdditionsDialog::sortByDownload(const AdditionInfo& a, const AdditionInfo& b)
+{
+    return a.sDownloadNumber.toUInt32() > b.sDownloadNumber.toUInt32();
+}
+
 AdditionsItem::AdditionsItem(weld::Widget* pParent, AdditionsDialog* pParentDialog,
                              AdditionInfo& additionInfo)
     : m_xBuilder(Application::CreateBuilder(pParent, "cui/ui/additionsfragment.ui"))
@@ -700,16 +731,7 @@ bool AdditionsItem::getExtensionFile(OUString& sExtensionFile)
     return true;
 }
 
-IMPL_LINK_NOARG(AdditionsDialog, ImplUpdateDataHdl, Timer*, void)
-{
-    if (m_pSearchThread.is())
-        m_pSearchThread->StopExecution();
-    ClearList();
-    m_nCurrentListItemCount = 0;
-    m_nMaxItemCount = PAGE_SIZE;
-    m_pSearchThread = new SearchAndParseThread(this, false);
-    m_pSearchThread->launch();
-}
+IMPL_LINK_NOARG(AdditionsDialog, ImplUpdateDataHdl, Timer*, void) { RefreshUI(); }
 
 IMPL_LINK_NOARG(AdditionsDialog, SearchUpdateHdl, weld::Entry&, void)
 {
@@ -848,4 +870,21 @@ void TmpRepositoryCommandEnv::update(uno::Any const& /*Status */) {}
 
 void TmpRepositoryCommandEnv::pop() {}
 
+IMPL_LINK(AdditionsDialog, GearHdl, const OString&, rIdent, void)
+{
+    if (rIdent == "gear_sort_voting")
+    {
+        std::sort(m_aAllExtensionsVector.begin(), m_aAllExtensionsVector.end(), sortByRating);
+    }
+    else if (rIdent == "gear_sort_comments")
+    {
+        std::sort(m_aAllExtensionsVector.begin(), m_aAllExtensionsVector.end(), sortByComment);
+    }
+    else if (rIdent == "gear_sort_downloads")
+    {
+        std::sort(m_aAllExtensionsVector.begin(), m_aAllExtensionsVector.end(), sortByDownload);
+    }
+    // After the sorting, UI will be refreshed to update extension list.
+    RefreshUI();
+}
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/cui/source/inc/AdditionsDialog.hxx b/cui/source/inc/AdditionsDialog.hxx
index 9061b755a5be..9efaad017af7 100644
--- a/cui/source/inc/AdditionsDialog.hxx
+++ b/cui/source/inc/AdditionsDialog.hxx
@@ -68,6 +68,7 @@ class AdditionsDialog : public weld::GenericDialogController
 private:
     Timer m_aSearchDataTimer;
 
+    DECL_LINK(GearHdl, const OString&, void);
     DECL_LINK(SearchUpdateHdl, weld::Entry&, void);
     DECL_LINK(ImplUpdateDataHdl, Timer*, void);
     DECL_LINK(FocusOut_Impl, weld::Widget&, void);
@@ -102,6 +103,11 @@ public:
     getInstalledExtensions();
     void SetProgress(const OUString& rProgress);
     void ClearList();
+    void RefreshUI();
+
+    static bool sortByComment(const AdditionInfo& a, const AdditionInfo& b);
+    static bool sortByRating(const AdditionInfo& a, const AdditionInfo& b);
+    static bool sortByDownload(const AdditionInfo& a, const AdditionInfo& b);
 };
 
 class AdditionsItem


More information about the Libreoffice-commits mailing list