summaryrefslogtreecommitdiff
path: root/plugins/NewStory
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2020-05-04 14:42:38 +0300
committerGeorge Hazan <ghazan@miranda.im>2020-05-04 14:42:38 +0300
commit055bae23041ae6817c9595714b80a0e0fdd77867 (patch)
tree113cf4ceddb8703f1fd542e686dd672a20bc1a8d /plugins/NewStory
parent6e5c2ba80ec20f94540ad4b374c5f225172d0a56 (diff)
NewStory: time tree to share array with history control, instead of running its own cycle
Diffstat (limited to 'plugins/NewStory')
-rw-r--r--plugins/NewStory/src/history.cpp112
-rw-r--r--plugins/NewStory/src/history_control.cpp3
-rw-r--r--plugins/NewStory/src/history_control.h1
3 files changed, 54 insertions, 62 deletions
diff --git a/plugins/NewStory/src/history.cpp b/plugins/NewStory/src/history.cpp
index b3230295c9..f6b26a08ff 100644
--- a/plugins/NewStory/src/history.cpp
+++ b/plugins/NewStory/src/history.cpp
@@ -338,71 +338,59 @@ class CHistoryDlg : public CDlgBase
void TimeTreeBuild()
{
- if (m_dwOptions & WND_OPT_TIMETREE)
- {
- MEVENT hDbEvent = db_event_first(m_hContact);
- int CurYear = 0, CurMonth = 0, CurDay = 0, PrevYear = -1, PrevMonth = -1, PrevDay = -1;
- HTREEITEM hCurYear = 0, hCurMonth = 0, hCurDay = 0;
- while (hDbEvent != NULL) {
- DBEVENTINFO dbei = {};
- int nSize = db_event_getBlobSize(hDbEvent);
- if (nSize > 0) {
- dbei.cbBlob = nSize;
- dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob + 2);
- dbei.pBlob[dbei.cbBlob] = 0;
- dbei.pBlob[dbei.cbBlob + 1] = 0;
- // Double null terminate, this should prevent most errors
- // where the blob received has an invalid format
- }
+ if (!(m_dwOptions & WND_OPT_TIMETREE))
+ return;
- if (!db_event_get(hDbEvent, &dbei)) {
- struct tm ts = { 0 };
- time_t timestamp = dbei.timestamp;
- errno_t err = localtime_s(&ts, &timestamp); /* statically alloced, local time correction */
- if (err != 0)
- return;
-
- CurYear = ts.tm_year + 1900;
- CurMonth = ts.tm_mon + 1;
- CurDay = ts.tm_mday;
- wchar_t buf[50];
- TVINSERTSTRUCT tvi;
- tvi.hParent = nullptr;
- tvi.item.mask = TVIF_TEXT | TVIF_PARAM;
- if (CurYear != PrevYear)
- {
- _itow(CurYear, buf, 10);
- tvi.item.pszText = buf;
- tvi.item.lParam = 0;
- hCurYear = TreeView_InsertItem(m_timeTree.GetHwnd(), &tvi);
- PrevYear = CurYear;
- }
- if (CurMonth != PrevMonth)
- {
- tvi.hParent = hCurYear;
- tvi.item.pszText = TranslateW(months[CurMonth - 1]);
- tvi.item.lParam = CurMonth;
- hCurMonth = TreeView_InsertItem(m_timeTree.GetHwnd(), &tvi);
- PrevMonth = CurMonth;
- }
- if (CurDay != PrevDay)
- {
- _itow(CurDay, buf, 10);
- tvi.hParent = hCurMonth;
- tvi.item.pszText = buf;
- tvi.item.lParam = 0;
- hCurDay = TreeView_InsertItem(m_timeTree.GetHwnd(), &tvi);
- PrevDay = CurDay;
- }
- if (dbei.pBlob)
- mir_free(dbei.pBlob);
- }
- hDbEvent = db_event_next(m_hContact, hDbEvent);
+ auto *pArray = (HistoryArray *)m_histControl.SendMsg(NSM_GETARRAY, 0, 0);
+ int numItems = pArray->getCount();
+
+ int CurYear = 0, CurMonth = 0, CurDay = 0, PrevYear = -1, PrevMonth = -1, PrevDay = -1;
+ HTREEITEM hCurYear = 0, hCurMonth = 0, hCurDay = 0;
+ for (int i=0; i < numItems; i++) {
+ auto *pItem = pArray->get(i, true);
+
+ struct tm ts = { 0 };
+ time_t timestamp = pItem->dbe.timestamp;
+ errno_t err = localtime_s(&ts, &timestamp); /* statically alloced, local time correction */
+ if (err != 0)
+ return;
+
+ CurYear = ts.tm_year + 1900;
+ CurMonth = ts.tm_mon + 1;
+ CurDay = ts.tm_mday;
+ wchar_t buf[50];
+ TVINSERTSTRUCT tvi;
+ tvi.hParent = nullptr;
+ tvi.item.mask = TVIF_TEXT | TVIF_PARAM;
+ if (CurYear != PrevYear)
+ {
+ _itow(CurYear, buf, 10);
+ tvi.item.pszText = buf;
+ tvi.item.lParam = 0;
+ hCurYear = TreeView_InsertItem(m_timeTree.GetHwnd(), &tvi);
+ PrevYear = CurYear;
+ }
+ if (CurMonth != PrevMonth)
+ {
+ tvi.hParent = hCurYear;
+ tvi.item.pszText = TranslateW(months[CurMonth - 1]);
+ tvi.item.lParam = CurMonth;
+ hCurMonth = TreeView_InsertItem(m_timeTree.GetHwnd(), &tvi);
+ PrevMonth = CurMonth;
+ }
+ if (CurDay != PrevDay)
+ {
+ _itow(CurDay, buf, 10);
+ tvi.hParent = hCurMonth;
+ tvi.item.pszText = buf;
+ tvi.item.lParam = 0;
+ hCurDay = TreeView_InsertItem(m_timeTree.GetHwnd(), &tvi);
+ PrevDay = CurDay;
}
- disableTimeTreeChange = true;
- HTREEITEM root = m_timeTree.GetRoot();
- m_timeTree.SelectItem(root);
}
+ disableTimeTreeChange = true;
+ HTREEITEM root = m_timeTree.GetRoot();
+ m_timeTree.SelectItem(root);
}
CCtrlBase m_histControl;
diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp
index 7aa6416f75..6e1f2dbd83 100644
--- a/plugins/NewStory/src/history_control.cpp
+++ b/plugins/NewStory/src/history_control.cpp
@@ -506,6 +506,9 @@ LRESULT CALLBACK NewstoryListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
data->redrawTimer.Start(100);
break;
+ case NSM_GETARRAY:
+ return (LRESULT)&data->items;
+
case NSM_GETCOUNT:
return data->items.getCount();
diff --git a/plugins/NewStory/src/history_control.h b/plugins/NewStory/src/history_control.h
index 0483ac9112..c1ed6be620 100644
--- a/plugins/NewStory/src/history_control.h
+++ b/plugins/NewStory/src/history_control.h
@@ -68,6 +68,7 @@ enum
//
NSM_GETCOUNT,
+ NSM_GETARRAY,
//
NSM_SEEKEND,