diff options
Diffstat (limited to 'message_notify/messagenotify.cpp')
-rw-r--r-- | message_notify/messagenotify.cpp | 126 |
1 files changed, 80 insertions, 46 deletions
diff --git a/message_notify/messagenotify.cpp b/message_notify/messagenotify.cpp index 7cde52e..03d88a4 100644 --- a/message_notify/messagenotify.cpp +++ b/message_notify/messagenotify.cpp @@ -9,6 +9,11 @@ #include "popups.h"
#include <time.h>
+#include "collection.h"
+#include "m_speak.h"
+
+Map<HANDLE, HWND> open_msg_windows;
+
HINSTANCE hInst;
PLUGINLINK *pluginLink;
@@ -20,14 +25,12 @@ bool thread_api = false; int code_page = CP_ACP;
-HANDLE popupWindowList;
-
DWORD focusTimerId = 0;
PLUGININFOEX pluginInfo={
sizeof(PLUGININFOEX),
"Message Notify",
- PLUGIN_MAKE_VERSION(0,3,1,0),
+ PLUGIN_MAKE_VERSION(0, 4, 0, 0),
"Show a popup when a message is received",
"Scott Ellis",
"mail@scottellis.com.au",
@@ -89,9 +92,11 @@ bool window_focussed(HWND hwnd, HANDLE hContact) { mwd.cbSize = sizeof(mwd);
if(!CallService(MS_MSG_GETWINDOWDATA, (WPARAM)&mwid, (LPARAM)&mwd)) {
- if((mwd.uState & MSG_WINDOW_STATE_VISIBLE) != 0) {
+ //if((mwd.uState & MSG_WINDOW_STATE_VISIBLE) != 0) {
+ // return true;
+ //}
+ if(IsWindowVisible(mwd.hwndWindow))
return true;
- }
} else
return true;
@@ -105,6 +110,7 @@ bool window_focussed(HWND hwnd, HANDLE hContact) { void __stdcall FocusTimerProc(struct HWND__ *,unsigned int,unsigned int,unsigned long) {
if(options.notify_when != NOTIFY_NFORE) return;
+ /*
HANDLE hContact = (HANDLE) CallService(MS_DB_CONTACT_FINDFIRST, 0, 0);
while (hContact) {
HWND hwnd;
@@ -116,6 +122,14 @@ void __stdcall FocusTimerProc(struct HWND__ *,unsigned int,unsigned int,unsigned }
hContact = (HANDLE) CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM) hContact, 0);
}
+ */
+ for(Map<HANDLE, HWND>::Iterator i = open_msg_windows.start(); i.has_val(); i.next()) {
+ if(!EmptyList(i.val().first)) {
+ if(window_focussed(i.val().second, i.val().first))
+ PostMessageWindowList(WMU_CLOSEPOPUP, (WPARAM)i.val().first, 0); // close popups
+ }
+ }
+
}
void StartFocusTimer() {
@@ -176,7 +190,7 @@ unsigned int __stdcall sttCheckWindowProc( VOID *dwParam ) { //if(debug) PUShowMessage("start of notify thread", SM_NOTIFY);
- HWND hwnd = (HWND)DBGetContactSettingDword(cd->hContact, MODULE, "WindowHandle", 0);
+ HWND hwnd = open_msg_windows[cd->hContact];//(HWND)DBGetContactSettingDword(cd->hContact, MODULE, "WindowHandle", 0);
bool window_open = (hwnd != 0);
bool window_has_focus = window_open && window_focussed(hwnd, cd->hContact);
@@ -184,6 +198,7 @@ unsigned int __stdcall sttCheckWindowProc( VOID *dwParam ) { || (options.notify_when == NOTIFY_NFORE && !window_has_focus)
|| (options.notify_when == NOTIFY_CLOSED && !window_open))
{
+ // show a popup
if(IsUnicodePopupsEnabled()) {
//if(debug) PUShowMessage("showing popup (unicode)", SM_NOTIFY);
// get contact display name from clist
@@ -200,12 +215,13 @@ unsigned int __stdcall sttCheckWindowProc( VOID *dwParam ) { }
}
- if(cd->blobsize) {
+ if(cd->blobsize && options.show_msg) {
// does blob contain unicode message?
int msglen = strlen((char *)cd->blob) + 1;
if(msglen != cd->blobsize && wcslen((wchar_t *)(&cd->blob[msglen]))) {
// yes
- ShowPopupW(cd->hContact, swzContactDisplayName, (wchar_t *)(&cd->blob[msglen]));
+ if(options.flags & MNNF_POPUP) ShowPopupW(cd->hContact, swzContactDisplayName, options.show_msg ? (wchar_t *)(&cd->blob[msglen]) : 0);
+ if(options.flags & MNNF_SPEAK) Speak_SayExW("messages", cd->hContact, (wchar_t *)(&cd->blob[msglen]));
} else {
// no, convert to unciode
wchar_t msg[MAX_SECONDLINE];
@@ -213,23 +229,30 @@ unsigned int __stdcall sttCheckWindowProc( VOID *dwParam ) { MultiByteToWideChar(CP_UTF8, 0, (char *) cd->blob, -1, msg, MAX_SECONDLINE);
else
MultiByteToWideChar(code_page, 0, (char *) cd->blob, -1, msg, MAX_SECONDLINE);
- ShowPopupW(cd->hContact, swzContactDisplayName, msg);
+ if(options.flags & MNNF_POPUP) {
+ if(options.show_msg) {
+ ShowPopupW(cd->hContact, swzContactDisplayName, msg);
+ } else
+ ShowPopupW(cd->hContact, swzContactDisplayName, 0);
+ }
+ if(options.flags & MNNF_SPEAK) Speak_SayExW("messages", cd->hContact, msg);
}
} else {
// no message
- ShowPopupW(cd->hContact, swzContactDisplayName, 0);
+ if(options.flags & MNNF_POPUP) ShowPopupW(cd->hContact, swzContactDisplayName, 0);
+ if(options.flags & MNNF_SPEAK) Speak_SayExW("messages", cd->hContact, L"empty message");
}
} else {
//if(debug) PUShowMessage("showing popup (ansi)", SM_NOTIFY);
char *szCDN = (char *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)cd->hContact, 0);
if(szCDN && szCDN[0]) {
if(cd->blobsize) {
- char msg[MAX_SECONDLINE];
- strncpy(msg, (char *)cd->blob, MAX_SECONDLINE - 1);
- msg[MAX_SECONDLINE - 1] = 0;
- ShowPopup(cd->hContact, szCDN, (char *)msg);
- } else
- ShowPopup(cd->hContact, szCDN, 0);
+ if((options.flags & MNNF_POPUP) && options.show_msg) ShowPopup(cd->hContact, szCDN, (char *)cd->blob);
+ if(options.flags & MNNF_SPEAK) Speak_SayExA("messages", cd->hContact, (char *)cd->blob);
+ } else {
+ if(options.flags & MNNF_POPUP) ShowPopup(cd->hContact, szCDN, 0);
+ if(options.flags & MNNF_SPEAK) Speak_SayExA("messages", cd->hContact, "empty message");
+ }
}
}
} else {
@@ -249,6 +272,12 @@ int OnDatabaseEventAdded(WPARAM wParam, LPARAM lParam) { //bool debug = (DBGetContactSettingByte(0, MODULE, "Debug", 0) != 0);
// safety checks
+ int status = CallService(MS_CLIST_GETSTATUSMODE, 0, 0);
+ if(status >= ID_STATUS_ONLINE && status <= ID_STATUS_OUTTOLUNCH && options.disable_status[status - ID_STATUS_ONLINE]) {
+ //if(debug) PUShowMessage("ignoring event (disabled for this status)", SM_NOTIFY);
+ return 0;
+ }
+
// messages from this contact ignored
if(CallService(MS_IGNORE_ISIGNORED, (WPARAM)hContact, (LPARAM)IGNOREEVENT_MESSAGE)) {
//if(debug) PUShowMessage("ignoring event (contact ignored)", SM_NOTIFY);
@@ -265,43 +294,32 @@ int OnDatabaseEventAdded(WPARAM wParam, LPARAM lParam) { DBEVENTINFO dbei = {0};
dbei.cbSize = sizeof(dbei);
- if((dbei.cbBlob = (DWORD)CallService(MS_DB_EVENT_GETBLOBSIZE, (WPARAM)hDbEvent, 0)) == (DWORD)-1)
- //if(debug) PUShowMessage("invalid event", SM_NOTIFY);
- return 0;
+ if(options.show_msg || (options.flags & MNNF_SPEAK)) {
+ if((dbei.cbBlob = (DWORD)CallService(MS_DB_EVENT_GETBLOBSIZE, (WPARAM)hDbEvent, 0)) == (DWORD)-1) {
+ //if(debug) PUShowMessage("invalid event", SM_NOTIFY);
+ return 0;
+ }
+ if(dbei.cbBlob > 0) dbei.pBlob = new BYTE[dbei.cbBlob];
+ } else
+ dbei.cbBlob = 0;
- if(dbei.cbBlob > 0) dbei.pBlob = new BYTE[dbei.cbBlob];
if(CallService(MS_DB_EVENT_GET, (WPARAM)hDbEvent, (LPARAM)&dbei)) {
//if(debug) PUShowMessage("get event failed", SM_NOTIFY);
+ if(dbei.pBlob) delete[] dbei.pBlob;
return 0;
}
if ((dbei.flags & DBEF_SENT) || (dbei.eventType != EVENTTYPE_MESSAGE) || (dbei.flags & DBEF_READ)) {
//if(debug) PUShowMessage("ignoring event (read, sent, or type != message)", SM_NOTIFY);
+ if(dbei.pBlob) delete[] dbei.pBlob;
return 0;
}
- int status = CallService(MS_CLIST_GETSTATUSMODE, 0, 0);
- if(status >= ID_STATUS_ONLINE && status <= ID_STATUS_OUTTOLUNCH && options.disable_status[status - ID_STATUS_ONLINE]) {
- //if(debug) PUShowMessage("ignoring event (disabled for this status)", SM_NOTIFY);
- return 0;
- }
-
- if(dbei.cbBlob == 0 || dbei.pBlob == 0) {
- //if(debug) PUShowMessage("ignoring event (no text)", SM_NOTIFY);
- return 0; // just to be safe
- }
-
CheckWindowData *cd = new CheckWindowData;
cd->hContact = hContact;
- if(options.show_msg) {
- // send blob data
- cd->blobsize = dbei.cbBlob;
- cd->blob = dbei.pBlob;
- cd->flags = dbei.flags;
- } else {
- cd->blobsize = 0;
- delete dbei.pBlob;
- }
+ cd->blobsize = dbei.cbBlob;
+ cd->flags = dbei.flags;
+ cd->blob = dbei.pBlob;
// spawn a thread to deal with the data
if(thread_api) {
@@ -321,19 +339,33 @@ int OnDatabaseEventAdded(WPARAM wParam, LPARAM lParam) { return 0;
}
+/*
+void __cdecl windowData(void *param) {
+ Sleep(500);
+
+ HWND hWnd = (HWND)param;
+ char msg[512];
+ mir_snprintf(msg, 512, "window: %x, parent: %x, foreground: %x", hWnd, GetParent(hWnd), GetForegroundWindow());
+ PUShowMessage(msg, SM_NOTIFY);
+}
+*/
+
int OnWindowEvent(WPARAM wParam, LPARAM lParam) {
MessageWindowEventData *mwed = (MessageWindowEventData *)lParam;
switch(mwed->uType) {
- case MSG_WINDOW_EVT_OPENING:
+ //case MSG_WINDOW_EVT_OPENING:
case MSG_WINDOW_EVT_OPEN:
- DBWriteContactSettingDword(mwed->hContact, MODULE, "WindowHandle", (DWORD)mwed->hwndWindow);
+ //DBWriteContactSettingDword(mwed->hContact, MODULE, "WindowHandle", (DWORD)mwed->hwndWindow);
+ open_msg_windows[mwed->hContact] = mwed->hwndWindow;
if(options.notify_when == NOTIFY_CLOSED)
PostMessageWindowList(WMU_CLOSEPOPUP, (WPARAM)mwed->hContact, 0);
+ //mir_forkthread(windowData, (void *)mwed->hwndWindow);
break;
- case MSG_WINDOW_EVT_CLOSING:
+ //case MSG_WINDOW_EVT_CLOSING:
case MSG_WINDOW_EVT_CLOSE:
- DBWriteContactSettingDword(mwed->hContact, MODULE, "WindowHandle", 0);
+ //DBWriteContactSettingDword(mwed->hContact, MODULE, "WindowHandle", 0);
+ open_msg_windows.remove(mwed->hContact);
break;
default:
//ShowWarning("Window custom");
@@ -368,9 +400,11 @@ int OnModulesLoaded(WPARAM wParam, LPARAM lParam) { CallService(MS_UPDATE_REGISTER, 0, (WPARAM)&update);
}
+ // register with speak plugin (see m_speak.h)
+ Speak_Register(MODULE, "messages", "Messages", "core_main_1");
+
metacontacts_installed = (ServiceExists(MS_MC_GETMETACONTACT) != 0);
- hEventDbEventAdded = HookEvent(ME_DB_EVENT_ADDED, OnDatabaseEventAdded);
hIdle = HookEvent(ME_IDLE_CHANGED, OnIdleChanged);
hWindowEvent = HookEvent(ME_MSG_WINDOWEVENT, OnWindowEvent);
@@ -426,7 +460,7 @@ extern "C" int __declspec(dllexport) Load(PLUGINLINK *link) HookEvent(ME_SYSTEM_PRESHUTDOWN, OnPreShutdown);
HookEvent(ME_OPT_INITIALISE, OptInit);
- popupWindowList = (HANDLE)CallService(MS_UTILS_ALLOCWINDOWLIST, 0, 0);
+ hEventDbEventAdded = HookEvent(ME_DB_EVENT_ADDED, OnDatabaseEventAdded); // hooked early so SRMM can't mark it read too soon
return 0;
}
|