tdf#133026: Tight integration of extensions - Add the search functions

The search function added. However, I added a case for check-in (UI change occurs when "2" is written) because the API is not ready at the moment. The finalURL variable will be activated when the API is ready.

Change-Id: I23c83e28d6ad8dea6c52813b4c98d219299fa9f1
diff --git a/cui/source/dialogs/AdditionsDialog.cxx b/cui/source/dialogs/AdditionsDialog.cxx
index ba49e07..73b0247 100644
--- a/cui/source/dialogs/AdditionsDialog.cxx
+++ b/cui/source/dialogs/AdditionsDialog.cxx
@@ -416,12 +416,20 @@ void SearchAndParseThread::execute()

AdditionsDialog::AdditionsDialog(weld::Window* pParent)
    : GenericDialogController(pParent, "cui/ui/additionsdialog.ui", "AdditionsDialog")
    , m_aSearchDataTimer("SearchDataTimer")
    , m_xEntrySearch(m_xBuilder->weld_entry("entrySearch"))
    , m_xMenuButtonSettings(m_xBuilder->weld_menu_button("buttonGear"))
    , m_xContentWindow(m_xBuilder->weld_scrolled_window("contentWindow"))
    , m_xContentGrid(m_xBuilder->weld_container("contentGrid"))
    , m_xLabelProgress(m_xBuilder->weld_label("labelProgress"))
{
    m_aSearchDataTimer.SetInvokeHandler(LINK(this, AdditionsDialog, ImplUpdateDataHdl));
    m_aSearchDataTimer.SetDebugName("AdditionsDialog SearchDataTimer");
    m_aSearchDataTimer.SetTimeout(EDIT_UPDATEDATA_TIMEOUT);

    m_xEntrySearch->connect_changed(LINK(this, AdditionsDialog, SearchUpdateHdl));
    m_xEntrySearch->connect_focus_out(LINK(this, AdditionsDialog, FocusOut_Impl));

    // TODO - Temporary URL
    OString rURL = "https://yusufketen.com/extensionTest.json";

@@ -456,4 +464,56 @@ void AdditionsDialog::SetProgress(const OUString& rProgress)
    }
}

void AdditionsDialog::ClearList()
{
    // for VCL to be able to destroy bitmaps
    SolarMutexGuard aGuard;

    for (auto& item : this->m_aAdditionsItems)
    {
        item.m_xContainer->hide();
    }
    this->m_aAdditionsItems.clear();
}

IMPL_LINK_NOARG(AdditionsDialog, ImplUpdateDataHdl, Timer*, void)
{
    this->ClearList();
    OUString aSearchTerm(m_xEntrySearch->get_text());
    /* OPTIONAL
    if (aSearchTerm.isEmpty())
        return;
    */
    if (m_pSearchThread.is())
        m_pSearchThread->StopExecution();

    OString rURL = "https://yusufketen.com/extensionTest.json"; // + q=aSearchTerm
    OUString finalURL = OStringToOUString(rURL + "?q=", RTL_TEXTENCODING_UTF8) + aSearchTerm;

    // Search Test
    if (aSearchTerm == "2")
    {
        rURL = "https://yusufketen.com/extensionTest2.json";
    }

    this->SetProgress(finalURL);
    m_pSearchThread
        = new SearchAndParseThread(this, OStringToOUString(rURL, RTL_TEXTENCODING_UTF8), false);
    m_pSearchThread->launch();
}

IMPL_LINK_NOARG(AdditionsDialog, SearchUpdateHdl, weld::Entry&, void)
{
    m_aSearchDataTimer.Start();
}

IMPL_LINK_NOARG(AdditionsDialog, FocusOut_Impl, weld::Widget&, void)
{
    if (m_aSearchDataTimer.IsActive())
    {
        m_aSearchDataTimer.Stop();
        m_aSearchDataTimer.Invoke();
    }
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/cui/source/inc/AdditionsDialog.hxx b/cui/source/inc/AdditionsDialog.hxx
index 8b3211b..7983c1a 100644
--- a/cui/source/inc/AdditionsDialog.hxx
+++ b/cui/source/inc/AdditionsDialog.hxx
@@ -13,6 +13,7 @@
#include <vcl/svapp.hxx>
#include <salhelper/thread.hxx>
#include <rtl/ref.hxx>
#include <vcl/timer.hxx>
#include <vcl/weld.hxx>

struct AdditionsItem
@@ -57,7 +58,11 @@ class SearchAndParseThread;
class AdditionsDialog : public weld::GenericDialogController
{
private:
    // void fillGrid();
    Timer m_aSearchDataTimer;

    DECL_LINK(SearchUpdateHdl, weld::Entry&, void);
    DECL_LINK(ImplUpdateDataHdl, Timer*, void);
    DECL_LINK(FocusOut_Impl, weld::Widget&, void);

public:
    std::unique_ptr<weld::Entry> m_xEntrySearch;
@@ -74,6 +79,7 @@ public:
    ~AdditionsDialog() override;

    void SetProgress(const OUString& rProgress);
    void ClearList();
};

class SearchAndParseThread : public salhelper::Thread