diff options
Diffstat (limited to 'plugins/MessageState/src/messagestate.cpp')
-rw-r--r-- | plugins/MessageState/src/messagestate.cpp | 137 |
1 files changed, 50 insertions, 87 deletions
diff --git a/plugins/MessageState/src/messagestate.cpp b/plugins/MessageState/src/messagestate.cpp index 8a0dca5b8b..56c9399024 100644 --- a/plugins/MessageState/src/messagestate.cpp +++ b/plugins/MessageState/src/messagestate.cpp @@ -1,74 +1,64 @@ #include "stdafx.h"
+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("Unread clist extra icon"), "clist_unread_icon", IDI_EXTRA },
+};
+
+const TCHAR* Tooltips[]
+{
+ LPGENT("Last message is not read"),
+ LPGENT("Last message read"),
+ LPGENT("Last message was not sent"),
+ LPGENT("Sending...")
+};
+
void SetSRMMIcon(MCONTACT hContact, SRMM_ICON_TYPE type, time_t time)
{
- if (hContact && arMonitoredWindows.getIndex((HANDLE)hContact) != -1)
- {
- StatusIconData sid = { sizeof(sid) };
- sid.szModule = MODULENAME;
- sid.dwId = 1;
- sid.flags = MBF_TCHAR;
+ StatusIconData sid = { sizeof(sid) };
+ sid.szModule = MODULENAME;
+ sid.dwId = 1;
+ sid.flags = MBF_TCHAR;
- CMString tszTooltip;
+ CMString tszTooltip;
+
+ if (type != ICON_HIDDEN)
+ {
+ sid.hIcon = IcoLib_GetIconByHandle(Icons[type].hIcolib);
- switch (type)
+ if (type == ICON_READ)
{
- case ICON_HIDDEN:
+ if (db_get_dw(hContact, MODULENAME, DBKEY_MESSAGE_READ_TIME_TYPE, -1) == MRD_TYPE_READTIME)
{
- sid.flags |= MBF_HIDDEN;
- break;
+ _tcsftime(tszTooltip.GetBuffer(64), 64, TranslateT("Last message read at %X %x"), localtime(&time));
+ tszTooltip.ReleaseBuffer();
}
- case ICON_READ:
+ else
{
- sid.hIcon = IcoLib_GetIcon("read_icon");
-
- 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);
- tszTooltip.Format(L"%s %s", TranslateT("Last message read at"), ttime);
- }
- else
- {
- tszTooltip = TranslateT("Last message read (unknown time)");
- }
- break;
+ tszTooltip = TranslateT("Last message read (unknown time)");
}
- case ICON_UNREAD:
- {
- sid.hIcon = IcoLib_GetIcon("unread_icon");
- tszTooltip = TranslateT("Last message is not read");
- break;
- }
- case ICON_FAILED:
- {
- sid.hIcon = IcoLib_GetIcon("fail_icon");
- tszTooltip = TranslateT("Last message was not sent.");
- break;
- }
- case ICON_NOSENT:
- {
- sid.hIcon = IcoLib_GetIcon("nosent_icon");
- tszTooltip = TranslateT("Sending...");
- break;
- }
- default:
- return;
}
+ else
+ tszTooltip = TranslateTS(Tooltips[type]);
sid.tszTooltip = tszTooltip.GetBuffer();
-
- Srmm_ModifyIcon(hContact, &sid);
}
+ else
+ {
+ sid.flags |= MBF_HIDDEN;
+ }
+
+ Srmm_ModifyIcon(hContact, &sid);
}
-int IconsUpdate(WPARAM hContact, LONGLONG readtime)
+int IconsUpdate(MCONTACT hContact)
{
- if (hContact == NULL) return 1;
-
- LONGLONG lasttime = GetLastSentMessageTime(hContact);
+ time_t readtime = db_get_dw(hContact, MODULENAME, DBKEY_MESSAGE_READ_TIME, 0);
+ time_t lasttime = GetLastSentMessageTime(hContact);
if (lasttime != -1 && readtime != 0)
{
SetSRMMIcon(hContact, HasUnread(hContact) ? ICON_UNREAD : ICON_READ , readtime);
@@ -88,15 +78,8 @@ int OnProtoAck(WPARAM, LPARAM lParam) ACKDATA *pAck = (ACKDATA *)lParam;
if (pAck && (pAck->type == ACKTYPE_MESSAGE || pAck->type == ACKTYPE_FILE) && CheckProtoSupport(pAck->szModule))
{
- if (pAck->result == ACKRESULT_SUCCESS)
- {
- SetSRMMIcon(pAck->hContact, ICON_UNREAD);
- ExtraIconsApply(pAck->hContact, 0);
- }
- else if (pAck->result == ACKRESULT_FAILED)
- {
- SetSRMMIcon(pAck->hContact, ICON_FAILED);
- }
+ if (pAck->result == ACKRESULT_SUCCESS) SetSRMMIcon(pAck->hContact, ICON_UNREAD);
+ else if (pAck->result == ACKRESULT_FAILED) SetSRMMIcon(pAck->hContact, ICON_FAILED);
}
return 0;
}
@@ -104,41 +87,18 @@ int OnProtoAck(WPARAM, LPARAM lParam) int OnEventFilterAdd(WPARAM hContact, LPARAM lParam)
{
DBEVENTINFO *dbei = (DBEVENTINFO *)lParam;
- if (FLAG_CONTAINS(dbei->flags, DBEF_SENT) && CheckProtoSupport(dbei->szModule) && db_get_b(hContact, "Tab_SRMsg", "no_ack", 0))
+ if ((dbei->flags & DBEF_SENT) && CheckProtoSupport(dbei->szModule) && db_get_b(hContact, "Tab_SRMsg", "no_ack", 0))
SetSRMMIcon(hContact, ICON_NOSENT);
ExtraIconsApply(hContact, 0);
return 0;
}
-int OnSrmmWindowEvent(WPARAM, LPARAM lParam)
-{
- MessageWindowEventData *event = (MessageWindowEventData *)lParam;
- if (event == NULL)
- return 0;
-
- if (event->uType == MSG_WINDOW_EVT_OPEN) {
- const char *szProto = GetContactProto(event->hContact);
- if (CheckProtoSupport(szProto))
- {
- arMonitoredWindows.insert((HANDLE)event->hContact);
- IconsUpdate(event->hContact, db_get_dw(event->hContact, MODULENAME, DBKEY_MESSAGE_READ_TIME, 0));
- }
- }
- else if (event->uType == MSG_WINDOW_EVT_CLOSE)
- arMonitoredWindows.remove(event->hContact);
-
- return 0;
-}
-
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);
+ Icon_Register(g_hInst, MODULENAME, Icons, _countof(Icons));
StatusIconData sid = { sizeof(sid) };
sid.szModule = MODULENAME;
@@ -148,5 +108,8 @@ int OnModulesLoaded(WPARAM, LPARAM) InitClistExtraIcon();
+ for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
+ IconsUpdate(hContact);
+
return 0;
}
\ No newline at end of file |