From 7ff2f6455e4461af8a2735fee591a3114fea1903 Mon Sep 17 00:00:00 2001 From: MikalaiR Date: Sat, 5 Sep 2015 18:48:33 +0000 Subject: MessageState: clist extra icons feature git-svn-id: http://svn.miranda-ng.org/main/trunk@15279 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MessageState/res/resource.rc | 1 + plugins/MessageState/res/unread_clist.ico | Bin 0 -> 1150 bytes plugins/MessageState/src/clist_extra.cpp | 35 ++++++++++++++++++++++++++++++ plugins/MessageState/src/global.h | 13 +++++++++-- plugins/MessageState/src/messagestate.cpp | 11 +++++----- plugins/MessageState/src/resource.h | 3 ++- 6 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 plugins/MessageState/res/unread_clist.ico create mode 100644 plugins/MessageState/src/clist_extra.cpp (limited to 'plugins') diff --git a/plugins/MessageState/res/resource.rc b/plugins/MessageState/res/resource.rc index 639fe66254..07780162ad 100644 --- a/plugins/MessageState/res/resource.rc +++ b/plugins/MessageState/res/resource.rc @@ -30,6 +30,7 @@ IDI_READ ICON "read.ico" IDI_UNREAD ICON "unread.ico" IDI_FAIL ICON "fail.ico" IDI_NOSENT ICON "nosent.ico" +IDI_EXTRA ICON "unread_clist.ico" #ifdef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// diff --git a/plugins/MessageState/res/unread_clist.ico b/plugins/MessageState/res/unread_clist.ico new file mode 100644 index 0000000000..0f6ce97952 Binary files /dev/null and b/plugins/MessageState/res/unread_clist.ico differ diff --git a/plugins/MessageState/src/clist_extra.cpp b/plugins/MessageState/src/clist_extra.cpp new file mode 100644 index 0000000000..40fcc0d9f0 --- /dev/null +++ b/plugins/MessageState/src/clist_extra.cpp @@ -0,0 +1,35 @@ +#include "stdafx.h" + +HANDLE hExtraIcon = NULL; + +bool HasUnread(MCONTACT hContact) +{ + const char *szProto = GetContactProto(hContact); + if (CheckProtoSupport(szProto)) + { + return ((GetLastSentMessageTime(hContact) > db_get_dw(hContact, MODULENAME, DBKEY_MESSAGE_READ_TIME, 0)) && db_get_dw(hContact, MODULENAME, DBKEY_MESSAGE_READ_TIME, 0) != 0); + } + + return false; +} + +int ExtraIconsApply(WPARAM hContact, LPARAM) +{ + if (hContact == NULL) return 0; + + if (HasUnread(hContact)) + ExtraIcon_SetIconByName(hExtraIcon, hContact, "clist_unread_icon"); + else + ExtraIcon_Clear(hExtraIcon, hContact); + + return 0; +} + +void InitClistExtraIcon() +{ + hExtraIcon = ExtraIcon_RegisterIcolib("messagestate_unread", LPGEN("MessageState unread extra icon"), "clist_unread_icon"); + HookEvent(ME_CLIST_EXTRA_IMAGE_APPLY, ExtraIconsApply); + + for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) + ExtraIconsApply(hContact, 0); +} \ No newline at end of file diff --git a/plugins/MessageState/src/global.h b/plugins/MessageState/src/global.h index 463142be2f..f9927d77d3 100644 --- a/plugins/MessageState/src/global.h +++ b/plugins/MessageState/src/global.h @@ -8,7 +8,8 @@ static IconItem Icons[] = { LPGEN("Unread message icon"), "unread_icon", IDI_UNREAD }, { LPGEN("Read message icon"), "read_icon", IDI_READ }, { LPGEN("Failed sending icon"), "fail_icon", IDI_FAIL }, - { LPGEN("Sending message icon"), "nosent_icon", IDI_NOSENT } + { LPGEN("Sending message icon"), "nosent_icon", IDI_NOSENT }, + { LPGEN("Unread clist extra icon"), "clist_unread_icon", IDI_EXTRA }, }; enum SRMM_ICON_TYPE @@ -24,8 +25,16 @@ enum SRMM_ICON_TYPE #define DBKEY_MESSAGE_READ_TIME "LastMsgReadTime" #define DBKEY_MESSAGE_READ_TIME_TYPE "LastMsgReadTimeType" +__forceinline bool CheckProtoSupport(const char *szProto) +{ return ((szProto != NULL) ? FLAG_CONTAINS(CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_4, 0), PF4_READNOTIFY) : false); +} + +void SetSRMMIcon(MCONTACT hContact, SRMM_ICON_TYPE type, time_t time = 0); +LONGLONG GetLastSentMessageTime(MCONTACT hContact); int OnModulesLoaded(WPARAM, LPARAM); INT_PTR UpdateService(WPARAM, LPARAM); - +bool HasUnread(MCONTACT hContact); +int ExtraIconsApply(WPARAM hContact, LPARAM); +void InitClistExtraIcon(); #endif //_GLOBAL_H_ \ No newline at end of file diff --git a/plugins/MessageState/src/messagestate.cpp b/plugins/MessageState/src/messagestate.cpp index 57dd44824e..1176fd7c3c 100644 --- a/plugins/MessageState/src/messagestate.cpp +++ b/plugins/MessageState/src/messagestate.cpp @@ -12,11 +12,7 @@ LONGLONG GetLastSentMessageTime(MCONTACT hContact) return -1; } -__forceinline bool CheckProtoSupport(const char *szProto) -{ return ((szProto != NULL) ? FLAG_CONTAINS(CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_4, 0), PF4_READNOTIFY) : false); -} - -void SetSRMMIcon(MCONTACT hContact, SRMM_ICON_TYPE type, time_t time = 0) +void SetSRMMIcon(MCONTACT hContact, SRMM_ICON_TYPE type, time_t time) { if (hContact && arMonitoredWindows.getIndex((HANDLE)hContact) != -1) { @@ -144,6 +140,7 @@ INT_PTR UpdateService(WPARAM hContact, LPARAM 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); + ExtraIconsApply(hContact, 0); } return 0; } @@ -153,7 +150,7 @@ int OnModulesLoaded(WPARAM, LPARAM) HookEvent(ME_MSG_WINDOWEVENT, OnSrmmWindowEvent); HookEvent(ME_PROTO_ACK, OnProtoAck); HookEvent(ME_DB_EVENT_FILTER_ADD, OnEventFilterAdd); - + // IcoLib support for (size_t i = 0; i < _countof(Icons); i++) Icon_Register(g_hInst, MODULENAME, &Icons[i], 1); @@ -164,5 +161,7 @@ int OnModulesLoaded(WPARAM, LPARAM) sid.dwId = 1; Srmm_AddIcon(&sid); + InitClistExtraIcon(); + return 0; } \ No newline at end of file diff --git a/plugins/MessageState/src/resource.h b/plugins/MessageState/src/resource.h index a668a8157c..acf5a45079 100644 --- a/plugins/MessageState/src/resource.h +++ b/plugins/MessageState/src/resource.h @@ -6,12 +6,13 @@ #define IDI_UNREAD 106 #define IDI_FAIL 107 #define IDI_NOSENT 108 +#define IDI_EXTRA 109 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 109 +#define _APS_NEXT_RESOURCE_VALUE 110 #define _APS_NEXT_COMMAND_VALUE 40001 #define _APS_NEXT_CONTROL_VALUE 1010 #define _APS_NEXT_SYMED_VALUE 101 -- cgit v1.2.3