From e2135de541615dbae15e5f714d7658130334656c Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 27 Feb 2019 20:01:15 +0300 Subject: fixes #1701 (Clist modern: add contact sorting by last online time) --- plugins/Clist_modern/src/modern_clcitems.cpp | 1 + plugins/Clist_modern/src/modern_clcopts.cpp | 12 ++++++------ plugins/Clist_modern/src/modern_clist.h | 2 +- plugins/Clist_modern/src/modern_clistsettings.cpp | 1 + plugins/Clist_modern/src/modern_contact.cpp | 4 ++++ plugins/Clist_modern/src/stdafx.h | 1 + 6 files changed, 14 insertions(+), 7 deletions(-) (limited to 'plugins/Clist_modern/src') diff --git a/plugins/Clist_modern/src/modern_clcitems.cpp b/plugins/Clist_modern/src/modern_clcitems.cpp index 6f40ab2925..9fd277cb48 100644 --- a/plugins/Clist_modern/src/modern_clcitems.cpp +++ b/plugins/Clist_modern/src/modern_clcitems.cpp @@ -333,6 +333,7 @@ ClcCacheEntry* cliCreateCacheItem(MCONTACT hContact) pdnce->ApparentMode = db_get_w(hContact, pdnce->szProto, "ApparentMode", 0); pdnce->NotOnList = g_plugin.getByte(hContact, "NotOnList"); pdnce->IsExpanded = g_plugin.getByte(hContact, "Expanded"); + pdnce->dwLastOnlineTime = db_get_dw(hContact, pdnce->szProto, "LastSeen", 0); pdnce->dwLastMsgTime = -1; return pdnce; } diff --git a/plugins/Clist_modern/src/modern_clcopts.cpp b/plugins/Clist_modern/src/modern_clcopts.cpp index 9058bf6e4c..3181688df1 100644 --- a/plugins/Clist_modern/src/modern_clcopts.cpp +++ b/plugins/Clist_modern/src/modern_clcopts.cpp @@ -482,8 +482,9 @@ static int _GetNetVisibleProtoCount() return netProtoCount; } -wchar_t *sortby[] = { LPGENW("Name"), LPGENW("Name (use locale settings)"), LPGENW("Status"), LPGENW("Last message time"), LPGENW("Account name"), LPGENW("Rate"), LPGENW("-Nothing-") }; -int sortbyValue[] = { SORTBY_NAME, SORTBY_NAME_LOCALE, SORTBY_STATUS, SORTBY_LASTMSG, SORTBY_PROTO, SORTBY_RATE, SORTBY_NOTHING }; +static wchar_t* sortby[] = { LPGENW("Name"), LPGENW("Name (use locale settings)"), LPGENW("Status"), LPGENW("Last message time"), LPGENW("Account name"), LPGENW("Rate"), LPGENW("Last online"), LPGENW("-Nothing-") }; +static int sortbyValue[] = { SORTBY_NAME, SORTBY_NAME_LOCALE, SORTBY_STATUS, SORTBY_LASTMSG, SORTBY_PROTO, SORTBY_RATE, SORTBY_LAST_ONLINE, SORTBY_NOTHING }; + static INT_PTR CALLBACK DlgProcClistOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { @@ -501,7 +502,6 @@ static INT_PTR CALLBACK DlgProcClistOpts(HWND hwndDlg, UINT msg, WPARAM wParam, CheckDlgButton(hwndDlg, IDC_HILIGHTMODE2, db_get_b(0, "CLC", "HiLightMode", SETTING_HILIGHTMODE_DEFAULT) == 2 ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg, IDC_HILIGHTMODE3, db_get_b(0, "CLC", "HiLightMode", SETTING_HILIGHTMODE_DEFAULT) == 3 ? BST_CHECKED : BST_UNCHECKED); { - int s1, s2, s3; for (auto &it : sortby) { int item = SendDlgItemMessage(hwndDlg, IDC_CLSORT1, CB_ADDSTRING, 0, (LPARAM)TranslateW(it)); SendDlgItemMessage(hwndDlg, IDC_CLSORT1, CB_SETITEMDATA, item, 0); @@ -511,9 +511,9 @@ static INT_PTR CALLBACK DlgProcClistOpts(HWND hwndDlg, UINT msg, WPARAM wParam, SendDlgItemMessage(hwndDlg, IDC_CLSORT3, CB_SETITEMDATA, item, 0); } - s1 = g_plugin.getByte("SortBy1", SETTING_SORTBY1_DEFAULT); - s2 = g_plugin.getByte("SortBy2", SETTING_SORTBY2_DEFAULT); - s3 = g_plugin.getByte("SortBy3", SETTING_SORTBY3_DEFAULT); + int s1 = g_plugin.getByte("SortBy1", SETTING_SORTBY1_DEFAULT); + int s2 = g_plugin.getByte("SortBy2", SETTING_SORTBY2_DEFAULT); + int s3 = g_plugin.getByte("SortBy3", SETTING_SORTBY3_DEFAULT); for (int i = 0; i < _countof(sortby); i++) { if (s1 == sortbyValue[i]) diff --git a/plugins/Clist_modern/src/modern_clist.h b/plugins/Clist_modern/src/modern_clist.h index 4cded86992..a03ff43bca 100644 --- a/plugins/Clist_modern/src/modern_clist.h +++ b/plugins/Clist_modern/src/modern_clist.h @@ -92,7 +92,7 @@ struct ClcCacheEntry : public ClcCacheEntryBase CSmileyString ssThirdLine; HANDLE hTimeZone; - DWORD dwLastMsgTime; + DWORD dwLastMsgTime, dwLastOnlineTime; int __forceinline getStatus() const { return m_iStatus; diff --git a/plugins/Clist_modern/src/modern_clistsettings.cpp b/plugins/Clist_modern/src/modern_clistsettings.cpp index ee3efc9b7a..e5cb54cb52 100644 --- a/plugins/Clist_modern/src/modern_clistsettings.cpp +++ b/plugins/Clist_modern/src/modern_clistsettings.cpp @@ -128,6 +128,7 @@ int ContactSettingChanged(WPARAM hContact, LPARAM lParam) if (!strcmp(cws->szModule, pdnce->szProto)) { if (!strcmp(cws->szSetting, "Status")) { pdnce->m_iStatus = cws->value.wVal; + pdnce->dwLastOnlineTime = time(0); if (pdnce->bIsHidden) return 0; diff --git a/plugins/Clist_modern/src/modern_contact.cpp b/plugins/Clist_modern/src/modern_contact.cpp index dda0a7fba0..a6558e095c 100644 --- a/plugins/Clist_modern/src/modern_contact.cpp +++ b/plugins/Clist_modern/src/modern_contact.cpp @@ -130,6 +130,10 @@ int cliCompareContacts(const ClcContact *contact1, const ClcContact *contact2) r = GetProtoIndex(contact1->pce->szProto) - GetProtoIndex(contact2->pce->szProto); break; + case SORTBY_LAST_ONLINE: + r = int(c2->dwLastOnlineTime) - int(c1->dwLastOnlineTime); // reverse order + break; + case SORTBY_RATE: r = contact2->bContactRate - contact1->bContactRate; // reverse order break; diff --git a/plugins/Clist_modern/src/stdafx.h b/plugins/Clist_modern/src/stdafx.h index 2c0977b17f..58c5c7cded 100644 --- a/plugins/Clist_modern/src/stdafx.h +++ b/plugins/Clist_modern/src/stdafx.h @@ -228,6 +228,7 @@ enum #define SORTBY_PROTO 3 #define SORTBY_RATE 4 #define SORTBY_NAME_LOCALE 5 +#define SORTBY_LAST_ONLINE 6 #define SORTBY_NOTHING 10 #define DT_FORCENATIVERENDER 0x10000000 -- cgit v1.2.3