diff options
author | MikalaiR <nikolay.romanovich@narod.ru> | 2015-09-09 12:51:17 +0000 |
---|---|---|
committer | MikalaiR <nikolay.romanovich@narod.ru> | 2015-09-09 12:51:17 +0000 |
commit | eff5259d6dac303fafa0e661a181428680197584 (patch) | |
tree | 73a89e1d6636b2b154a9e7f24c98a60ed27fa2d6 /plugins/MessageState/src/messagestate.cpp | |
parent | 2ce8833450aa05cdc598abd2f7ca1b68afa3ae5d (diff) |
MessageState: code optimization; leaks fixes
git-svn-id: http://svn.miranda-ng.org/main/trunk@15314 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MessageState/src/messagestate.cpp')
-rw-r--r-- | plugins/MessageState/src/messagestate.cpp | 51 |
1 files changed, 17 insertions, 34 deletions
diff --git a/plugins/MessageState/src/messagestate.cpp b/plugins/MessageState/src/messagestate.cpp index 998d4a5083..e0b0ccb148 100644 --- a/plugins/MessageState/src/messagestate.cpp +++ b/plugins/MessageState/src/messagestate.cpp @@ -1,17 +1,5 @@ #include "stdafx.h"
-LONGLONG GetLastSentMessageTime(MCONTACT hContact)
-{
- for (MEVENT hDbEvent = db_event_last(hContact); hDbEvent; hDbEvent = db_event_prev(hContact, hDbEvent))
- {
- DBEVENTINFO dbei = { sizeof(dbei) };
- db_event_get(hDbEvent, &dbei);
- if (FLAG_CONTAINS(dbei.flags, DBEF_SENT))
- return dbei.timestamp;
- }
- return -1;
-}
-
void SetSRMMIcon(MCONTACT hContact, SRMM_ICON_TYPE type, time_t time)
{
if (hContact && arMonitoredWindows.getIndex((HANDLE)hContact) != -1)
@@ -21,6 +9,8 @@ void SetSRMMIcon(MCONTACT hContact, SRMM_ICON_TYPE type, time_t time) sid.dwId = 1;
sid.flags = MBF_TCHAR;
+ CMString tszTooltip;
+
switch (type)
{
case ICON_HIDDEN:
@@ -31,44 +21,45 @@ void SetSRMMIcon(MCONTACT hContact, SRMM_ICON_TYPE type, time_t time) case ICON_READ:
{
sid.hIcon = IcoLib_GetIcon("read_icon");
- 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);
+ tszTooltip.Format(L"%s %s", TranslateT("Last message read at"), ttime);
}
else
{
- tooltip = TranslateT("Last message read (unknown time)");
+ tszTooltip = TranslateT("Last message read (unknown time)");
}
- sid.tszTooltip = tooltip.Detach();
break;
}
case ICON_UNREAD:
{
sid.hIcon = IcoLib_GetIcon("unread_icon");
- sid.tszTooltip = TranslateT("Last message is not read");
+ tszTooltip = TranslateT("Last message is not read");
break;
}
case ICON_FAILED:
{
sid.hIcon = IcoLib_GetIcon("fail_icon");
- sid.tszTooltip = TranslateT("Last message was not sent.");
+ tszTooltip = TranslateT("Last message was not sent.");
break;
}
case ICON_NOSENT:
{
sid.hIcon = IcoLib_GetIcon("nosent_icon");
- sid.tszTooltip = TranslateT("Sending...");
+ tszTooltip = TranslateT("Sending...");
break;
}
default:
return;
}
+ sid.tszTooltip = tszTooltip.GetBuffer();
+
Srmm_ModifyIcon(hContact, &sid);
}
}
@@ -80,10 +71,15 @@ int IconsUpdate(WPARAM hContact, LONGLONG readtime) LONGLONG lasttime = GetLastSentMessageTime(hContact);
if (lasttime != -1 && readtime != 0)
{
- SetSRMMIcon(hContact, (readtime >= lasttime) ? ICON_READ : ICON_UNREAD, readtime);
+ SetSRMMIcon(hContact, HasUnread(hContact) ? ICON_UNREAD : ICON_READ , readtime);
}
- else
+ else
+ {
SetSRMMIcon(hContact, ICON_HIDDEN);
+ }
+
+ ExtraIconsApply(hContact, 0);
+
return 0;
}
@@ -134,19 +130,6 @@ int OnSrmmWindowEvent(WPARAM, LPARAM lParam) return 0;
}
-INT_PTR UpdateService(WPARAM hContact, LPARAM lParam)
-{
- MessageReadData *mrd = (MessageReadData*)lParam;
- if (mrd->dw_lastTime > db_get_dw(hContact, MODULENAME, DBKEY_MESSAGE_READ_TIME, 0))
- {
- 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;
-}
-
int OnModulesLoaded(WPARAM, LPARAM)
{
HookEvent(ME_MSG_WINDOWEVENT, OnSrmmWindowEvent);
|