1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
#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 wchar_t* Tooltips[] =
{
LPGENW("Last message is not read"),
LPGENW("Last message read"),
LPGENW("Last message was not sent"),
LPGENW("Sending...")
};
void SetSRMMIcon(MCONTACT hContact, SRMM_ICON_TYPE type, time_t time)
{
StatusIconData sid = {};
sid.szModule = MODULENAME;
sid.dwId = 1;
sid.flags = MBF_UNICODE;
CMStringW tszTooltip;
if (type != ICON_HIDDEN) {
sid.hIcon = IcoLib_GetIconByHandle(Icons[type].hIcolib);
if (type == ICON_READ) {
if (g_plugin.getDword(hContact, DBKEY_MESSAGE_READ_TIME_TYPE, -1) == MRD_TYPE_READTIME) {
wcsftime(tszTooltip.GetBuffer(64), 64, TranslateT("Last message read at %X %x"), localtime(&time));
tszTooltip.ReleaseBuffer();
}
else tszTooltip = TranslateT("Last message read (unknown time)");
}
else tszTooltip = TranslateW(Tooltips[type]);
sid.tszTooltip = tszTooltip.GetBuffer();
}
else sid.flags |= MBF_HIDDEN;
Srmm_ModifyIcon(hContact, &sid);
}
int IconsUpdate(MCONTACT hContact)
{
time_t readtime = g_plugin.getDword(hContact, DBKEY_MESSAGE_READ_TIME, 0);
time_t lasttime = GetLastSentMessageTime(hContact);
if (lasttime != -1 && readtime != 0) {
SetSRMMIcon(hContact, HasUnread(hContact) ? ICON_UNREAD : ICON_READ, readtime);
}
else {
SetSRMMIcon(hContact, ICON_HIDDEN);
}
ExtraIconsApply(hContact, 0);
return 0;
}
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);
else if (pAck->result == ACKRESULT_FAILED) SetSRMMIcon(pAck->hContact, ICON_FAILED);
ExtraIconsApply(pAck->hContact, 0);
}
return 0;
}
int OnEventFilterAdd(WPARAM hContact, LPARAM lParam)
{
DBEVENTINFO *dbei = (DBEVENTINFO *)lParam;
if ((dbei->flags & DBEF_SENT) && CheckProtoSupport(dbei->szModule) && db_get_b(hContact, "Tab_SRMsg", "no_ack", 0))
SetSRMMIcon(hContact, ICON_NOSENT);
return 0;
}
int OnModulesLoaded(WPARAM, LPARAM)
{
HookEvent(ME_PROTO_ACK, OnProtoAck);
HookEvent(ME_DB_EVENT_FILTER_ADD, OnEventFilterAdd);
g_plugin.registerIcon(MODULENAME, Icons);
StatusIconData sid = {};
sid.szModule = MODULENAME;
sid.flags = MBF_HIDDEN;
sid.dwId = 1;
Srmm_AddIcon(&sid, &g_plugin);
InitClistExtraIcon();
for (auto &hContact : Contacts())
IconsUpdate(hContact);
return 0;
}
|