# HG changeset patch # User Mikael Berthe # Date 1269181368 -3600 # Node ID 9daf6b3f30d63783d3b30a89c0c67895ecc142da # Parent 48e47198a9dbcd74faa7906ae7a64c3ef0eebf05 Add hook-unread-list-change diff -r 48e47198a9db -r 9daf6b3f30d6 mcabber/mcabber/api.h --- a/mcabber/mcabber/api.h Sun Mar 21 15:18:40 2010 +0100 +++ b/mcabber/mcabber/api.h Sun Mar 21 15:22:48 2010 +0100 @@ -3,8 +3,8 @@ #include // For MCABBER_BRANCH -#define MCABBER_API_VERSION 9 -#define MCABBER_API_MIN 8 +#define MCABBER_API_VERSION 10 +#define MCABBER_API_MIN 9 extern const gchar *mcabber_branch; extern const guint mcabber_api_version; diff -r 48e47198a9db -r 9daf6b3f30d6 mcabber/mcabber/hooks.h --- a/mcabber/mcabber/hooks.h Sun Mar 21 15:18:40 2010 +0100 +++ b/mcabber/mcabber/hooks.h Sun Mar 21 15:22:48 2010 +0100 @@ -21,6 +21,7 @@ #define HOOK_MY_STATUS_CHANGE "hook-my-status-change" #define HOOK_POST_CONNECT "hook-post-connect" #define HOOK_PRE_DISCONNECT "hook-pre-disconnect" +#define HOOK_UNREAD_LIST_CHANGE "hook-unread-list-change" typedef enum { HOOK_HANDLER_RESULT_ALLOW_MORE_HOOKS = 0, diff -r 48e47198a9db -r 9daf6b3f30d6 mcabber/mcabber/roster.c --- a/mcabber/mcabber/roster.c Sun Mar 21 15:18:40 2010 +0100 +++ b/mcabber/mcabber/roster.c Sun Mar 21 15:22:48 2010 +0100 @@ -687,8 +687,57 @@ roster_msg_setflag_return: if (unread_list_modified) { - guint unread_count = g_slist_length(unread_list); + guint unread_count; hlog_save_state(); + +#ifdef MODULES_ENABLE + { + gpointer unread_ptr, first_unread; + guint muc_unread = 0, muc_attention = 0; + guint attention_count = 0; + unread_count = 0; + + unread_ptr = first_unread = unread_msg(NULL); + if (first_unread) { + do { + guint type = buddy_gettype(unread_ptr); + unread_count++; + + if (type & ROSTER_TYPE_ROOM) { + muc_unread++; + if (buddy_getuiprio(unread_ptr) >= ROSTER_UI_PRIO_MUC_HL_MESSAGE) + muc_attention++; + } else { + if (buddy_getuiprio(unread_ptr) >= ROSTER_UI_PRIO_ATTENTION_MESSAGE) + attention_count++; + } + unread_ptr = unread_msg(unread_ptr); + } while (unread_ptr && unread_ptr != first_unread); + } + + { + gchar *str_unread = g_strdup_printf("%u", unread_count); + gchar *str_attention = g_strdup_printf("%u", attention_count); + gchar *str_muc_unread = g_strdup_printf("%u", muc_unread); + gchar *str_muc_attention = g_strdup_printf("%u", muc_attention); + hk_arg_t args[] = { + { "unread", str_unread }, // All unread + { "attention", str_attention }, // Attention (private) + { "muc_unread", str_muc_unread }, // MUC unread + { "muc_attention", str_muc_attention }, // MUC attention (highlight) + { NULL, NULL }, + }; + hk_run_handlers(HOOK_UNREAD_LIST_CHANGE, args); + g_free(str_unread); + g_free(str_attention); + g_free(str_muc_unread); + g_free(str_muc_attention); + } + } +#else + unread_count = g_slist_length(unread_list); +#endif + /* Call external command */ hk_ext_cmd("", 'U', (guchar)MIN(255, unread_count), NULL); }