summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-08-04 21:45:15 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-08-04 21:45:15 +0300
commitc2f9a67162701ea0c3dcce7867887ffb4ba92ed2 (patch)
treeb26b1ead4598893addb3eb679ec5c7f6efd076d1
parent5a8d4daed9badd45ceb3f882aa28df60c0fa7c8e (diff)
NewStory: global search results to be added in the sorted order
-rw-r--r--plugins/NewStory/src/history_array.cpp13
-rw-r--r--plugins/NewStory/src/history_array.h14
-rw-r--r--plugins/NewStory/src/history_control.cpp8
-rw-r--r--plugins/NewStory/src/history_control.h1
-rw-r--r--plugins/NewStory/src/history_dlg.cpp20
5 files changed, 52 insertions, 4 deletions
diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp
index 0a68338f2a..6bdd4a74f2 100644
--- a/plugins/NewStory/src/history_array.cpp
+++ b/plugins/NewStory/src/history_array.cpp
@@ -353,6 +353,19 @@ bool HistoryArray::addEvent(MCONTACT hContact, MEVENT hEvent, int count)
return true;
}
+void HistoryArray::addResults(OBJLIST<SearchResult> *pArray)
+{
+ int numItems = getCount();
+ auto *pPrev = (numItems == 0) ? nullptr : get(numItems - 1);
+
+ for (auto &it : *pArray) {
+ auto &p = allocateItem();
+ p.hContact = it->hContact;
+ p.hEvent = it->hEvent;
+ p.pPrev = pPrev; pPrev = &p;
+ }
+}
+
ItemData& HistoryArray::allocateItem()
{
if (iLastPageCounter == HIST_BLOCK_SIZE) {
diff --git a/plugins/NewStory/src/history_array.h b/plugins/NewStory/src/history_array.h
index fea6f21e66..f274c5181a 100644
--- a/plugins/NewStory/src/history_array.h
+++ b/plugins/NewStory/src/history_array.h
@@ -117,6 +117,19 @@ struct ItemBlock : public MZeroedObject
ItemData data[HIST_BLOCK_SIZE];
};
+struct SearchResult
+{
+ SearchResult(MCONTACT _1, MEVENT _2, uint32_t _3) :
+ hContact(_1),
+ hEvent(_2),
+ ts(_3)
+ {}
+
+ MCONTACT hContact;
+ MEVENT hEvent;
+ uint32_t ts;
+};
+
class HistoryArray
{
LIST<wchar_t> strings;
@@ -131,6 +144,7 @@ public:
bool addEvent(MCONTACT hContact, MEVENT hEvent, int count);
void addChatEvent(SESSION_INFO *si, LOGINFO *pEvent);
+ void addResults(OBJLIST<SearchResult> *pArray);
void clear();
int find(MEVENT hEvent);
int getCount() const;
diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp
index b380374ee4..b4e82e77a1 100644
--- a/plugins/NewStory/src/history_control.cpp
+++ b/plugins/NewStory/src/history_control.cpp
@@ -565,6 +565,14 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
data->ScheduleDraw();
break;
+ case NSM_ADDRESULTS:
+ if (auto *pResults = (OBJLIST<SearchResult>*)wParam) {
+ data->items.addResults(pResults);
+ data->totalCount = data->items.getCount();
+ data->ScheduleDraw();
+ }
+ break;
+
case NSM_CLEAR:
data->items.clear();
data->totalCount = 0;
diff --git a/plugins/NewStory/src/history_control.h b/plugins/NewStory/src/history_control.h
index 4d2b8418e7..e6ec51cdeb 100644
--- a/plugins/NewStory/src/history_control.h
+++ b/plugins/NewStory/src/history_control.h
@@ -22,6 +22,7 @@ enum
// add one or more events
NSM_ADDEVENTS,
NSM_ADDCHATEVENT,
+ NSM_ADDRESULTS,
// clear log
NSM_CLEAR,
diff --git a/plugins/NewStory/src/history_dlg.cpp b/plugins/NewStory/src/history_dlg.cpp
index 0e23196044..124b78bc5b 100644
--- a/plugins/NewStory/src/history_dlg.cpp
+++ b/plugins/NewStory/src/history_dlg.cpp
@@ -113,6 +113,13 @@ class CHistoryDlg : public CDlgBase
HWND m_hwndDateFrom, m_hwndDateTo;
InfoBarEvents ibMessages, ibFiles, ibUrls, ibTotal;
+ OBJLIST<SearchResult> m_arResults;
+
+ static int stubSortResults(const void *p1, const void *p2)
+ {
+ return int((*(SearchResult **)p1)->ts) - int((*(SearchResult **)p2)->ts);
+ }
+
void DoGlobalSearch()
{
ptrW wszPattern(edtSearchText.GetText());
@@ -126,6 +133,12 @@ class CHistoryDlg : public CDlgBase
DoSearchContact(0, wszPattern);
for (auto &hContact : Contacts())
DoSearchContact(hContact, wszPattern);
+
+ qsort(m_arResults.getArray(), m_arResults.getCount(), sizeof(void *), stubSortResults);
+ m_histControl.SendMsg(NSM_ADDRESULTS, WPARAM(&m_arResults), 0);
+ m_arResults.destroy();
+
+ TimeTreeBuild();
}
void DoSearchContact(MCONTACT hContact, const wchar_t *pwszPattern)
@@ -141,10 +154,8 @@ class CHistoryDlg : public CDlgBase
continue;
CharLowerW(pwszText);
- if (wcsstr(pwszText, pwszPattern)) {
- ADDEVENTS tmp = { hContact, hDbEvent, 1 };
- m_histControl.SendMsg(NSM_ADDEVENTS, WPARAM(&tmp), 0);
- }
+ if (wcsstr(pwszText, pwszPattern))
+ m_arResults.insert(new SearchResult(hContact, hDbEvent, dbei.timestamp));
}
}
@@ -275,6 +286,7 @@ class CHistoryDlg : public CDlgBase
public:
CHistoryDlg(MCONTACT _hContact) :
CDlgBase(g_plugin, IDD_HISTORY),
+ m_arResults(10000),
m_hContact(_hContact),
m_timeTree(this, IDC_TIMETREEVIEW),
m_histControl(this, IDC_HISTORYCONTROL),