From c958dbab118e9618d975fa37e72159319bc633f4 Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Sat, 5 Sep 2015 10:06:41 +0000 Subject: MessageState: refactoring git-svn-id: http://svn.miranda-ng.org/main/trunk@15248 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MessageState/src/global.h | 3 ++- plugins/MessageState/src/main.cpp | 8 +++---- plugins/MessageState/src/messagestate.cpp | 40 ++++++++++++++++++------------- plugins/MessageState/src/stdafx.h | 1 + 4 files changed, 30 insertions(+), 22 deletions(-) (limited to 'plugins/MessageState') diff --git a/plugins/MessageState/src/global.h b/plugins/MessageState/src/global.h index 7a0ca5e446..463142be2f 100644 --- a/plugins/MessageState/src/global.h +++ b/plugins/MessageState/src/global.h @@ -22,9 +22,10 @@ enum SRMM_ICON_TYPE #define FLAG_CONTAINS(x,y) ((x & y) == y) #define DBKEY_MESSAGE_READ_TIME "LastMsgReadTime" +#define DBKEY_MESSAGE_READ_TIME_TYPE "LastMsgReadTimeType" int OnModulesLoaded(WPARAM, LPARAM); -INT_PTR DummyService(WPARAM, LPARAM); +INT_PTR UpdateService(WPARAM, LPARAM); #endif //_GLOBAL_H_ \ No newline at end of file diff --git a/plugins/MessageState/src/main.cpp b/plugins/MessageState/src/main.cpp index b2caea0d74..f9091a9722 100644 --- a/plugins/MessageState/src/main.cpp +++ b/plugins/MessageState/src/main.cpp @@ -2,7 +2,7 @@ int hLangpack; HINSTANCE g_hInst; -HANDLE hDummyService; +HANDLE hUpdateService; PLUGININFOEX pluginInfo = { @@ -36,15 +36,15 @@ extern "C" int __declspec(dllexport) Load(void) mir_getLP(&pluginInfo); HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); - hDummyService = CreateServiceFunction(MODULENAME "/DummyService", DummyService); + hUpdateService = CreateServiceFunction(MS_MESSAGESTATE_UPDATE, UpdateService); return 0; } extern "C" int __declspec(dllexport) Unload(void) { - if (hDummyService) - DestroyServiceFunction(hDummyService); + if (hUpdateService) + DestroyServiceFunction(hUpdateService); return 0; } \ No newline at end of file diff --git a/plugins/MessageState/src/messagestate.cpp b/plugins/MessageState/src/messagestate.cpp index d7ddd12d32..d1cd032e36 100644 --- a/plugins/MessageState/src/messagestate.cpp +++ b/plugins/MessageState/src/messagestate.cpp @@ -35,12 +35,20 @@ void SetSRMMIcon(MCONTACT hContact, SRMM_ICON_TYPE type, time_t time = 0) case ICON_READ: { sid.hIcon = IcoLib_GetIcon("read_icon"); - TCHAR ttime[64]; - _locale_t locale = _create_locale(LC_ALL, ""); - _tcsftime_l(ttime, _countof(ttime), _T("%X %x"), localtime(&time), locale); - _free_locale(locale); - CMString tooltip(FORMAT, L"%s %s", TranslateT("Last message read at"), ttime); - sid.tszTooltip = mir_tstrdup(tooltip.GetBuffer()); + CMString tooltip; + if (db_get_dw(hContact, MODULENAME, DBKEY_MESSAGE_READ_TIME_TYPE, -1) == MRD_TYPE_READTIME) + { + TCHAR ttime[64]; + _locale_t locale = _create_locale(LC_ALL, ""); + _tcsftime_l(ttime, _countof(ttime), _T("%X %x"), localtime(&time), locale); + _free_locale(locale); + tooltip.Format(L"%s %s", TranslateT("Last message read at"), ttime); + } + else + { + tooltip = TranslateT("Last message read (unknown time)"); + } + sid.tszTooltip = tooltip.Detach(); break; } case ICON_UNREAD: @@ -100,14 +108,6 @@ int OnProtoAck(WPARAM, LPARAM lParam) return 0; } -int OnContactSettingChanged(WPARAM hContact, LPARAM lParam) -{ - DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING*)lParam; - if (CheckProtoSupport(GetContactProto(hContact)) && cws && cws->szSetting && !mir_strcmpi(cws->szSetting, DBKEY_MESSAGE_READ_TIME)) - IconsUpdate(hContact, cws->value.dVal); - return 0; -} - int OnEventFilterAdd(WPARAM hContact, LPARAM lParam) { DBEVENTINFO *dbei = (DBEVENTINFO *)lParam; @@ -127,7 +127,7 @@ int OnSrmmWindowEvent(WPARAM, LPARAM lParam) if (CheckProtoSupport(szProto)) { arMonitoredWindows.insert((HANDLE)event->hContact); - IconsUpdate(event->hContact, db_get_dw(event->hContact, szProto, DBKEY_MESSAGE_READ_TIME, 0)); + IconsUpdate(event->hContact, db_get_dw(event->hContact, MODULENAME, DBKEY_MESSAGE_READ_TIME, 0)); } } else if (event->uType == MSG_WINDOW_EVT_CLOSE) @@ -136,12 +136,18 @@ int OnSrmmWindowEvent(WPARAM, LPARAM lParam) return 0; } -INT_PTR DummyService(WPARAM, LPARAM){ return 0; } +INT_PTR UpdateService(WPARAM hContact, LPARAM lParam) +{ + MessageReadData *mrd = (MessageReadData*)lParam; + db_set_dw(hContact, MODULENAME, DBKEY_MESSAGE_READ_TIME, mrd->dw_lastTime); + db_set_dw(hContact, MODULENAME, DBKEY_MESSAGE_READ_TIME_TYPE, mrd->iTimeType); + IconsUpdate(hContact, mrd->dw_lastTime); + return 0; +} int OnModulesLoaded(WPARAM, LPARAM) { HookEvent(ME_MSG_WINDOWEVENT, OnSrmmWindowEvent); - HookEvent(ME_DB_CONTACT_SETTINGCHANGED, OnContactSettingChanged); HookEvent(ME_PROTO_ACK, OnProtoAck); HookEvent(ME_DB_EVENT_FILTER_ADD, OnEventFilterAdd); diff --git a/plugins/MessageState/src/stdafx.h b/plugins/MessageState/src/stdafx.h index fab1d17e96..115d3c067c 100644 --- a/plugins/MessageState/src/stdafx.h +++ b/plugins/MessageState/src/stdafx.h @@ -4,6 +4,7 @@ #include #include +#include #include #include #include -- cgit v1.2.3