summaryrefslogtreecommitdiff
path: root/plugins/NewStory/src/history_dlg.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/NewStory/src/history_dlg.cpp')
-rw-r--r--plugins/NewStory/src/history_dlg.cpp126
1 files changed, 50 insertions, 76 deletions
diff --git a/plugins/NewStory/src/history_dlg.cpp b/plugins/NewStory/src/history_dlg.cpp
index eb239d100e..85dcd9ea5d 100644
--- a/plugins/NewStory/src/history_dlg.cpp
+++ b/plugins/NewStory/src/history_dlg.cpp
@@ -1,6 +1,6 @@
/*
Copyright (c) 2005 Victor Pavlychko (nullbyte@sotline.net.ua)
-Copyright (C) 2012-24 Miranda NG team (https://miranda-ng.org)
+Copyright (C) 2012-25 Miranda NG team (https://miranda-ng.org)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -165,7 +165,7 @@ class CHistoryDlg : public CDlgBase
CharLowerW(pwszText);
if (wcsstr(pwszText, pwszPattern))
- m_arResults.insert(new SearchResult(hContact, hDbEvent, dbei.timestamp));
+ m_arResults.insert(new SearchResult(hContact, hDbEvent, dbei.getUnixtime()));
}
}
@@ -295,25 +295,25 @@ class CHistoryDlg : public CDlgBase
auto &pArray = m_histCtrl->items;
int numItems = pArray.getCount();
- int CurYear = 0, CurMonth = 0, CurDay = 0, PrevYear = -1, PrevMonth = -1, PrevDay = -1;
+ int 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, false);
if (!pItem->fetch())
continue;
- if (pItem->dbe.timestamp == 0)
+ if (pItem->dbe.iTimestamp == 0)
continue;
struct tm ts = { 0 };
- time_t timestamp = pItem->dbe.timestamp;
+ time_t timestamp = pItem->dbe.getUnixtime();
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;
+ int CurYear = ts.tm_year + 1900;
+ int CurMonth = ts.tm_mon + 1;
+ int CurDay = ts.tm_mday;
wchar_t buf[50];
TVINSERTSTRUCT tvi;
tvi.hParent = nullptr;
@@ -321,14 +321,14 @@ class CHistoryDlg : public CDlgBase
if (CurYear != PrevYear) {
_itow(CurYear, buf, 10);
tvi.item.pszText = buf;
- tvi.item.lParam = CurYear;
+ tvi.item.lParam = CurYear * 100 * 100;
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;
+ tvi.item.lParam = (CurYear * 100 + CurMonth) * 100;
hCurMonth = TreeView_InsertItem(m_timeTree.GetHwnd(), &tvi);
PrevMonth = CurMonth;
}
@@ -336,11 +336,12 @@ class CHistoryDlg : public CDlgBase
_itow(CurDay, buf, 10);
tvi.hParent = hCurMonth;
tvi.item.pszText = buf;
- tvi.item.lParam = CurDay;
+ tvi.item.lParam = (CurYear * 100 + CurMonth) * 100 + CurDay;
hCurDay = TreeView_InsertItem(m_timeTree.GetHwnd(), &tvi);
PrevDay = CurDay;
}
}
+
disableTimeTreeChange = true;
HTREEITEM root = m_timeTree.GetRoot();
m_timeTree.SelectItem(root);
@@ -349,9 +350,6 @@ class CHistoryDlg : public CDlgBase
HTREEITEM FindSibling(HTREEITEM root, int value)
{
if (root) {
- if (value < 1000)
- root = m_timeTree.GetChild(root);
-
for (HTREEITEM hti = root; hti; hti = m_timeTree.GetNextSibling(hti)) {
TVITEMEX tvi;
tvi.mask = TVIF_PARAM;
@@ -372,9 +370,13 @@ class CHistoryDlg : public CDlgBase
if (err != 0)
return;
- HTREEITEM hti = FindSibling(m_timeTree.GetRoot(), ts.tm_year + 1900);
- hti = FindSibling(hti, ts.tm_mon + 1);
- hti = FindSibling(hti, ts.tm_mday);
+ int iValue = (ts.tm_year + 1900) * 100 * 100;
+ HTREEITEM hti = FindSibling(m_timeTree.GetRoot(), iValue);
+
+ iValue += (ts.tm_mon + 1) * 100;
+ hti = FindSibling(m_timeTree.GetChild(hti), iValue);
+
+ hti = FindSibling(m_timeTree.GetChild(hti), iValue + ts.tm_mday);
if (hti) {
disableTimeTreeChange = true;
m_timeTree.SelectItem(hti);
@@ -433,7 +435,7 @@ public:
m_toolbar.push_back(Button(btnTimeTree));
m_toolbar.push_back(Button(btnBookmarks));
m_toolbar.push_back(Button(btnSearch));
- m_toolbar.push_back(Button(btnFilter));
+ // m_toolbar.push_back(Button(btnFilter));
m_toolbar.push_back(Button(btnCalendar, Button::SPACED));
m_toolbar.push_back(Button(btnCopy));
m_toolbar.push_back(Button(btnDelete));
@@ -489,6 +491,7 @@ public:
// filterbar
btnFilter.MakePush();
+ btnFilter.Hide();
btnTimeTree.MakePush();
if (m_dwOptions & WND_OPT_TIMETREE)
@@ -568,8 +571,6 @@ public:
// Ask for layout
PostMessage(m_hwnd, WM_SIZE, 0, 0);
- WindowList_Add(g_hNewstoryWindows, m_hwnd, m_hContact);
-
ShowHideControls();
UpdateTitle();
@@ -584,6 +585,11 @@ public:
if (m_hContact != INVALID_CONTACT_ID) {
Utils_RestoreWindowPosition(m_hwnd, m_hContact, MODULENAME, "wnd_");
+ WindowList_Add(g_hNewstoryWindows, m_hwnd, m_hContact);
+
+ m_histCtrl->m_hContact = m_hContact;
+ WindowList_Add(g_hNewstoryHistLogs, m_histCtrl->m_hwnd, m_hContact);
+
m_histCtrl->AddEvent(m_hContact, 0, -1);
BuildTimeTree();
@@ -594,7 +600,6 @@ public:
OnResize();
BuildBookmarksList();
- m_histCtrl->SetContact(m_hContact);
m_histCtrl->ScrollBottom();
Window_SetIcon_IcoLib(m_hwnd, g_plugin.getIconHandle(IDI_NEWSTORY));
@@ -798,6 +803,7 @@ public:
Window_FreeIcon_IcoLib(m_hwnd);
WindowList_Remove(g_hNewstoryWindows, m_hwnd);
+ WindowList_Remove(g_hNewstoryHistLogs, m_histCtrl->m_hwnd);
if (m_hwndStatus != nullptr) {
DestroyWindow(m_hwndStatus);
@@ -1153,7 +1159,12 @@ public:
case UM_LOCATETIME:
if (m_dwOptions & WND_OPT_TIMETREE)
if (auto *pItem = m_histCtrl->GetItem(wParam))
- LocateDateTime(pItem->dbe.timestamp);
+ LocateDateTime(pItem->dbe.getUnixtime());
+ break;
+
+ case UM_UPDATE_WINDOW:
+ UpdateTitle();
+ BuildTimeTree();
break;
}
@@ -1180,62 +1191,25 @@ public:
void onSelChanged_TimeTree(CCtrlTreeView::TEventInfo *)
{
- wchar_t *val1, *val2, *val3;
- int yearsel = 0, monthsel = 0, daysel = 1;
- bool monthfound = false;
- if (disableTimeTreeChange)
+ if (disableTimeTreeChange) {
disableTimeTreeChange = false;
- else {
- HTREEITEM hti1 = m_timeTree.GetSelection();
- TVITEMEX tvi = { 0 };
- tvi.hItem = hti1;
- tvi.mask = TVIF_HANDLE | TVIF_TEXT | TVIF_PARAM;
- tvi.cchTextMax = MAX_PATH;
- tvi.lParam = 0;
- tvi.pszText = (wchar_t *)_alloca(MAX_PATH * sizeof(wchar_t));
-
- m_timeTree.GetItem(&tvi);
- val1 = tvi.pszText;
- if (tvi.lParam) {
- monthsel = tvi.lParam;
- monthfound = true;
- }
- HTREEITEM hti2 = m_timeTree.GetParent(hti1);
- if ((!monthfound) && (!hti2))
- yearsel = _wtoi(val1);
- if ((!monthfound) && (hti2))
- daysel = _wtoi(val1);
- if (hti2) {
- tvi.hItem = hti2;
- tvi.lParam = 0;
- m_timeTree.GetItem(&tvi);
- val2 = tvi.pszText;
- if (tvi.lParam) {
- monthsel = tvi.lParam;
- monthfound = true;
- }
- else
- yearsel = _wtoi(val2);
- HTREEITEM hti3 = m_timeTree.GetParent(hti2);
- if (hti3) {
- tvi.hItem = hti3;
- tvi.lParam = 0;
- m_timeTree.GetItem(&tvi);
- val3 = tvi.pszText;
- yearsel = _wtoi(val3);
- }
- }
- struct tm tm_sel;
- tm_sel.tm_hour = tm_sel.tm_min = tm_sel.tm_sec = 0;
- tm_sel.tm_isdst = 1;
- tm_sel.tm_mday = daysel;
- if (monthsel)
- tm_sel.tm_mon = monthsel - 1;
- else
- tm_sel.tm_mon = 0;
- tm_sel.tm_year = yearsel - 1900;
- PostMessage(m_hwnd, WM_USER + 0x600, mktime(&tm_sel), 0);
+ return;
}
+
+ HTREEITEM hti1 = m_timeTree.GetSelection();
+ TVITEMEX tvi = {};
+ tvi.hItem = hti1;
+ tvi.mask = TVIF_HANDLE | TVIF_PARAM;
+ m_timeTree.GetItem(&tvi);
+
+ struct tm tm_sel = {};
+ tm_sel.tm_isdst = 1;
+ tm_sel.tm_mday = tvi.lParam % 100; tvi.lParam /= 100;
+ tm_sel.tm_mon = tvi.lParam % 100;
+ if (tm_sel.tm_mon)
+ tm_sel.tm_mon--;
+ tm_sel.tm_year = tvi.lParam / 100 - 1900;
+ PostMessage(m_hwnd, WM_USER + 0x600, mktime(&tm_sel), 0);
}
};