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
104
105
106
107
108
109
110
111
112
113
114
115
|
#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)
{
StatusIconData sid = { sizeof(sid) };
sid.szModule = MODULENAME;
sid.dwId = 1;
sid.flags = MBF_TCHAR;
CMString tszTooltip;
if (type != ICON_HIDDEN)
{
sid.hIcon = IcoLib_GetIconByHandle(Icons[type].hIcolib);
if (type == ICON_READ)
{
if (db_get_dw(hContact, MODULENAME, DBKEY_MESSAGE_READ_TIME_TYPE, -1) == MRD_TYPE_READTIME)
{
_tcsftime(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 = TranslateTS(Tooltips[type]);
sid.tszTooltip = tszTooltip.GetBuffer();
}
else
{
sid.flags |= MBF_HIDDEN;
}
Srmm_ModifyIcon(hContact, &sid);
}
int IconsUpdate(MCONTACT 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);
}
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);
}
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);
ExtraIconsApply(hContact, 0);
return 0;
}
int OnModulesLoaded(WPARAM, LPARAM)
{
HookEvent(ME_PROTO_ACK, OnProtoAck);
HookEvent(ME_DB_EVENT_FILTER_ADD, OnEventFilterAdd);
Icon_Register(g_hInst, MODULENAME, Icons, _countof(Icons));
StatusIconData sid = { sizeof(sid) };
sid.szModule = MODULENAME;
sid.flags = MBF_HIDDEN;
sid.dwId = 1;
Srmm_AddIcon(&sid);
InitClistExtraIcon();
for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact))
IconsUpdate(hContact);
return 0;
}
|