summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/MessageState/src/clist_extra.cpp11
-rw-r--r--plugins/MessageState/src/global.h7
-rw-r--r--plugins/MessageState/src/main.cpp7
-rw-r--r--plugins/MessageState/src/messagestate.cpp51
-rw-r--r--plugins/MessageState/src/services.cpp27
-rw-r--r--plugins/MessageState/src/utils.cpp24
6 files changed, 76 insertions, 51 deletions
diff --git a/plugins/MessageState/src/clist_extra.cpp b/plugins/MessageState/src/clist_extra.cpp
index 40fcc0d9f0..031c273ea4 100644
--- a/plugins/MessageState/src/clist_extra.cpp
+++ b/plugins/MessageState/src/clist_extra.cpp
@@ -2,17 +2,6 @@
HANDLE hExtraIcon = NULL;
-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;
-}
-
int ExtraIconsApply(WPARAM hContact, LPARAM)
{
if (hContact == NULL) return 0;
diff --git a/plugins/MessageState/src/global.h b/plugins/MessageState/src/global.h
index f9927d77d3..5734fba61d 100644
--- a/plugins/MessageState/src/global.h
+++ b/plugins/MessageState/src/global.h
@@ -22,6 +22,7 @@ enum SRMM_ICON_TYPE
};
#define FLAG_CONTAINS(x,y) ((x & y) == y)
+
#define DBKEY_MESSAGE_READ_TIME "LastMsgReadTime"
#define DBKEY_MESSAGE_READ_TIME_TYPE "LastMsgReadTimeType"
@@ -29,10 +30,14 @@ __forceinline bool CheckProtoSupport(const char *szProto)
{ return ((szProto != NULL) ? FLAG_CONTAINS(CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_4, 0), PF4_READNOTIFY) : false);
}
+void InitServices();
+void DestroyServices();
+INT_PTR UpdateService(WPARAM, LPARAM);
+
+int IconsUpdate(WPARAM hContact, LONGLONG readtime);
void SetSRMMIcon(MCONTACT hContact, SRMM_ICON_TYPE type, time_t time = 0);
LONGLONG GetLastSentMessageTime(MCONTACT hContact);
int OnModulesLoaded(WPARAM, LPARAM);
-INT_PTR UpdateService(WPARAM, LPARAM);
bool HasUnread(MCONTACT hContact);
int ExtraIconsApply(WPARAM hContact, LPARAM);
void InitClistExtraIcon();
diff --git a/plugins/MessageState/src/main.cpp b/plugins/MessageState/src/main.cpp
index f9091a9722..ce6b830092 100644
--- a/plugins/MessageState/src/main.cpp
+++ b/plugins/MessageState/src/main.cpp
@@ -35,16 +35,13 @@ extern "C" int __declspec(dllexport) Load(void)
{
mir_getLP(&pluginInfo);
HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);
-
- hUpdateService = CreateServiceFunction(MS_MESSAGESTATE_UPDATE, UpdateService);
-
+ InitServices();
return 0;
}
extern "C" int __declspec(dllexport) Unload(void)
{
- if (hUpdateService)
- DestroyServiceFunction(hUpdateService);
+ DestroyServices();
return 0;
} \ No newline at end of file
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);
diff --git a/plugins/MessageState/src/services.cpp b/plugins/MessageState/src/services.cpp
new file mode 100644
index 0000000000..11beec6d04
--- /dev/null
+++ b/plugins/MessageState/src/services.cpp
@@ -0,0 +1,27 @@
+#include "stdafx.h"
+
+extern 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;
+ 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;
+} \ No newline at end of file
diff --git a/plugins/MessageState/src/utils.cpp b/plugins/MessageState/src/utils.cpp
new file mode 100644
index 0000000000..27040cf3c2
--- /dev/null
+++ b/plugins/MessageState/src/utils.cpp
@@ -0,0 +1,24 @@
+#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;
+}
+
+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;
+}