diff options
author | Mataes <mataes2007@gmail.com> | 2020-05-03 19:47:33 +0300 |
---|---|---|
committer | Mataes <mataes2007@gmail.com> | 2020-05-03 19:47:33 +0300 |
commit | f7b27f2c7e35c41141498fc2e472948f1dd1f140 (patch) | |
tree | 8fbd8ca98c69f3762866273fe13daf31558955e6 /plugins/NewStory | |
parent | 2848d4f4bf6a0065e45728144ba75084a6aa6968 (diff) |
NewStory: add items in time tree
Diffstat (limited to 'plugins/NewStory')
-rw-r--r-- | plugins/NewStory/src/history.cpp | 66 | ||||
-rw-r--r-- | plugins/NewStory/src/stdafx.h | 3 |
2 files changed, 68 insertions, 1 deletions
diff --git a/plugins/NewStory/src/history.cpp b/plugins/NewStory/src/history.cpp index 340f1e4180..6f17847f45 100644 --- a/plugins/NewStory/src/history.cpp +++ b/plugins/NewStory/src/history.cpp @@ -336,6 +336,70 @@ class CHistoryDlg : public CDlgBase SetWindowText(m_hwnd, TranslateT("System history")); } + 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, hCurMonth, hCurDay; + 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 (!db_event_get(hDbEvent, &dbei)) { + struct tm ts = { 0 }; + time_t timestamp = dbei.timestamp; + errno_t err = localtime_s(&ts, ×tamp); /* 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.hInsertAfter = TVI_SORT; + tvi.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE; + if (CurYear != PrevYear) + { + _itow(CurYear, buf, 10); + tvi.item.pszText = buf; + hCurYear = TreeView_InsertItem(m_timeTree.GetHwnd(), &tvi); + PrevYear = CurYear; + } + if (CurMonth != PrevMonth) + { + tvi.hParent = hCurYear; + tvi.item.pszText = TranslateW(months[CurMonth - 1]); + hCurMonth = TreeView_InsertItem(m_timeTree.GetHwnd(), &tvi); + PrevMonth = CurMonth; + } + if (CurDay != PrevDay) + { + _itow(CurDay, buf, 10); + tvi.hParent = hCurMonth; + tvi.item.pszText = buf; + hCurDay = TreeView_InsertItem(m_timeTree.GetHwnd(), &tvi); + PrevDay = CurDay; + } + if (dbei.pBlob) + mir_free(dbei.pBlob); + } + hDbEvent = db_event_next(m_hContact, hDbEvent); + } + } + } + CCtrlBase m_histControl; CCtrlEdit edtSearchText; CCtrlMButton btnUserInfo, btnSendMsg, btnUserMenu, btnCopy, btnOptions, btnFilter; @@ -520,6 +584,7 @@ public: SetFocus(m_histControl.GetHwnd()); ShowHideControls(); + TimeTreeBuild(); return true; } @@ -566,6 +631,7 @@ public: ShowHideControls(); LayoutHistoryWnd(); + TimeTreeBuild(); } void onClick_Export(CCtrlButton *) diff --git a/plugins/NewStory/src/stdafx.h b/plugins/NewStory/src/stdafx.h index ad0a5d62fd..52d19c9a3d 100644 --- a/plugins/NewStory/src/stdafx.h +++ b/plugins/NewStory/src/stdafx.h @@ -87,4 +87,5 @@ struct CMPlugin : public PLUGIN<CMPlugin> int Unload() override; }; -extern CMOption<bool> g_bOptGrouping;
\ No newline at end of file +extern CMOption<bool> g_bOptGrouping; +extern wchar_t* months[12];
\ No newline at end of file |