New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Thanks to Viacheslav for the suggestion and sample patch.
--- a/mcabber/contrib/events/eventcmd Fri Feb 29 14:55:55 2008 +0100
+++ b/mcabber/contrib/events/eventcmd Sun Mar 02 11:14:42 2008 +0100
@@ -43,5 +43,7 @@
elif [ $event = "STATUS" ]; then
# Buddy $arg2 status is $arg1 (_, O, I, F, D, N, A)
echo > /dev/null
+elif [ $event = "UNREAD" ]; then
+ # $arg1 is the number of unread buffers
+ echo > /dev/null
fi
-
--- a/mcabber/mcabberrc.example Fri Feb 29 14:55:55 2008 +0100
+++ b/mcabber/mcabberrc.example Sun Mar 02 11:14:42 2008 +0100
@@ -191,6 +191,7 @@
# $events_command MSG OUT jabber@id (when sending a message)
# $events_command MSG MUC room_id [file] (when receiving a MUC message)
# $events_command STATUS X jabber@id (new buddy status is X)
+# $events_command UNREAD N (number of unread buddy buffers)
# See sample script in contrib/ directory.
#set events_command = ~/.mcabber/eventcmd
#
--- a/mcabber/src/hooks.c Fri Feb 29 14:55:55 2008 +0100
+++ b/mcabber/src/hooks.c Sun Mar 02 11:14:42 2008 +0100
@@ -405,23 +405,24 @@
char *arg_data = NULL;
char status_str[2];
char *datafname = NULL;
+ char unread_str[16];
if (!extcmd) return;
// Prepare arg_* (external command parameters)
switch (type) {
- case 'M':
+ case 'M': /* Normal message */
arg_type = "MSG";
if (info == 'R')
arg_info = "IN";
else if (info == 'S')
arg_info = "OUT";
break;
- case 'G':
+ case 'G': /* Groupchat message */
arg_type = "MSG";
arg_info = "MUC";
break;
- case 'S':
+ case 'S': /* Status change */
arg_type = "STATUS";
if (strchr(imstatus2char, tolower(info))) {
status_str[0] = toupper(info);
@@ -429,6 +430,11 @@
arg_info = status_str;
}
break;
+ case 'U': /* Unread buffer count */
+ arg_type = "UNREAD";
+ g_snprintf(unread_str, sizeof unread_str, "%d", info);
+ arg_info = unread_str; /* number of remaining unread bjids */
+ break;
default:
return;
}
--- a/mcabber/src/roster.c Fri Feb 29 14:55:55 2008 +0100
+++ b/mcabber/src/roster.c Sun Mar 02 11:14:42 2008 +0100
@@ -23,6 +23,7 @@
#include "roster.h"
#include "utils.h"
+#include "hooks.h"
extern void hlog_save_state(void);
@@ -666,8 +667,12 @@
if (buddylist && (new_roster_item || !g_list_find(buddylist, roster_usr)))
buddylist_build();
- if (unread_list_modified)
+ if (unread_list_modified) {
hlog_save_state();
+ guint unread_count = g_slist_length(unread_list);
+ /* Call external command */
+ hk_ext_cmd("", 'U', (guchar)MIN(255, unread_count), NULL);
+ }
}
const char *roster_getname(const char *jid)