diff options
author | MikalaiR <nikolay.romanovich@narod.ru> | 2016-04-22 16:53:14 +0000 |
---|---|---|
committer | MikalaiR <nikolay.romanovich@narod.ru> | 2016-04-22 16:53:14 +0000 |
commit | 17da1798498188c1f221e738866107e69d6af066 (patch) | |
tree | 64da750c77dcf7ab12654d3fe22d2abeb8f8f3e9 /plugins/MessageState | |
parent | 2db93e0b278176b4dd68e8565ddab139d86c6e7b (diff) |
MessageState: code cleanup
git-svn-id: http://svn.miranda-ng.org/main/trunk@16747 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MessageState')
-rw-r--r-- | plugins/MessageState/src/clist_extra.cpp | 5 | ||||
-rw-r--r-- | plugins/MessageState/src/global.h | 27 | ||||
-rw-r--r-- | plugins/MessageState/src/main.cpp | 3 | ||||
-rw-r--r-- | plugins/MessageState/src/messagestate.cpp | 137 | ||||
-rw-r--r-- | plugins/MessageState/src/services.cpp | 11 | ||||
-rw-r--r-- | plugins/MessageState/src/stdafx.h | 2 | ||||
-rw-r--r-- | plugins/MessageState/src/utils.cpp | 12 |
7 files changed, 64 insertions, 133 deletions
diff --git a/plugins/MessageState/src/clist_extra.cpp b/plugins/MessageState/src/clist_extra.cpp index 031c273ea4..b10b825112 100644 --- a/plugins/MessageState/src/clist_extra.cpp +++ b/plugins/MessageState/src/clist_extra.cpp @@ -7,7 +7,7 @@ int ExtraIconsApply(WPARAM hContact, LPARAM) if (hContact == NULL) return 0;
if (HasUnread(hContact))
- ExtraIcon_SetIconByName(hExtraIcon, hContact, "clist_unread_icon");
+ ExtraIcon_SetIcon(hExtraIcon, hContact, Icons[ICON_EXTRA].hIcolib);
else
ExtraIcon_Clear(hExtraIcon, hContact);
@@ -18,7 +18,4 @@ 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 5734fba61d..9260116846 100644 --- a/plugins/MessageState/src/global.h +++ b/plugins/MessageState/src/global.h @@ -1,42 +1,29 @@ #ifndef _GLOBAL_H_
#define _GLOBAL_H_
-static LIST<void> arMonitoredWindows(3, PtrKeySortT);
-
-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("Unread clist extra icon"), "clist_unread_icon", IDI_EXTRA },
-};
-
enum SRMM_ICON_TYPE
{
- ICON_HIDDEN,
- ICON_READ,
+ ICON_HIDDEN = -1,
ICON_UNREAD,
+ ICON_READ,
ICON_FAILED,
- ICON_NOSENT
+ ICON_NOSENT,
+ ICON_EXTRA,
};
-#define FLAG_CONTAINS(x,y) ((x & y) == y)
-
#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);
+{ return (CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_READNOTIFY) != 0;
}
void InitServices();
-void DestroyServices();
INT_PTR UpdateService(WPARAM, LPARAM);
-int IconsUpdate(WPARAM hContact, LONGLONG readtime);
+int IconsUpdate(MCONTACT);
void SetSRMMIcon(MCONTACT hContact, SRMM_ICON_TYPE type, time_t time = 0);
-LONGLONG GetLastSentMessageTime(MCONTACT hContact);
+time_t GetLastSentMessageTime(MCONTACT hContact);
int OnModulesLoaded(WPARAM, LPARAM);
bool HasUnread(MCONTACT hContact);
int ExtraIconsApply(WPARAM hContact, LPARAM);
diff --git a/plugins/MessageState/src/main.cpp b/plugins/MessageState/src/main.cpp index ce6b830092..38b83bf5ec 100644 --- a/plugins/MessageState/src/main.cpp +++ b/plugins/MessageState/src/main.cpp @@ -2,7 +2,6 @@ int hLangpack;
HINSTANCE g_hInst;
-HANDLE hUpdateService;
PLUGININFOEX pluginInfo =
{
@@ -41,7 +40,5 @@ extern "C" int __declspec(dllexport) Load(void) extern "C" int __declspec(dllexport) Unload(void)
{
- DestroyServices();
-
return 0;
}
\ No newline at end of file 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 diff --git a/plugins/MessageState/src/services.cpp b/plugins/MessageState/src/services.cpp index 11beec6d04..362354e118 100644 --- a/plugins/MessageState/src/services.cpp +++ b/plugins/MessageState/src/services.cpp @@ -1,18 +1,12 @@ #include "stdafx.h"
-extern HANDLE hUpdateService;
+HANDLE hUpdateService;
void InitServices()
{
hUpdateService = CreateServiceFunction(MS_MESSAGESTATE_UPDATE, UpdateService);
}
-void DestroyServices()
-{
- if (hUpdateService)
- DestroyServiceFunction(hUpdateService);
-}
-
INT_PTR UpdateService(WPARAM hContact, LPARAM lParam)
{
MessageReadData *mrd = (MessageReadData*)lParam;
@@ -20,8 +14,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);
+ IconsUpdate(hContact);
}
return 0;
}
\ No newline at end of file diff --git a/plugins/MessageState/src/stdafx.h b/plugins/MessageState/src/stdafx.h index 115d3c067c..8d47d0212c 100644 --- a/plugins/MessageState/src/stdafx.h +++ b/plugins/MessageState/src/stdafx.h @@ -13,7 +13,6 @@ #include <m_icolib.h>
#include <m_extraicons.h>
#include <m_message.h>
-#include <m_timezones.h>
#include "resource.h"
#include "Version.h"
@@ -22,3 +21,4 @@ #define MODULENAME "MessageState"
extern HINSTANCE g_hInst;
+extern IconItem Icons[];
\ No newline at end of file diff --git a/plugins/MessageState/src/utils.cpp b/plugins/MessageState/src/utils.cpp index 27040cf3c2..7c285b42c7 100644 --- a/plugins/MessageState/src/utils.cpp +++ b/plugins/MessageState/src/utils.cpp @@ -1,12 +1,12 @@ #include "stdafx.h"
-LONGLONG GetLastSentMessageTime(MCONTACT hContact)
+time_t 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))
+ if (dbei.flags & DBEF_SENT)
return dbei.timestamp;
}
return -1;
@@ -14,11 +14,5 @@ LONGLONG GetLastSentMessageTime(MCONTACT hContact) 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;
+ return (CheckProtoSupport(GetContactProto(hContact))) && ((GetLastSentMessageTime(hContact) > db_get_dw(hContact, MODULENAME, DBKEY_MESSAGE_READ_TIME, 0)) && db_get_dw(hContact, MODULENAME, DBKEY_MESSAGE_READ_TIME, 0) != 0);
}
|