# HG changeset patch # User Mikael Berthe # Date 1269686149 -3600 # Node ID a2642e56e0de17292912e4610cbf0464de3bc53b # Parent 1aa89ccfb62672d40eb8a3f6486b13fdbccdfe87 Add xttitle module diff -r 1aa89ccfb626 -r a2642e56e0de mcabber/configure.ac --- a/mcabber/configure.ac Sat Mar 27 11:08:19 2010 +0100 +++ b/mcabber/configure.ac Sat Mar 27 11:35:49 2010 +0100 @@ -267,6 +267,7 @@ AC_CONFIG_FILES([mcabber/Makefile modules/Makefile modules/beep/Makefile + modules/xttitle/Makefile doc/Makefile doc/guide/Makefile doc/help/Makefile diff -r 1aa89ccfb626 -r a2642e56e0de mcabber/modules/Makefile.am --- a/mcabber/modules/Makefile.am Sat Mar 27 11:08:19 2010 +0100 +++ b/mcabber/modules/Makefile.am Sat Mar 27 11:35:49 2010 +0100 @@ -1,1 +1,1 @@ -SUBDIRS = beep +SUBDIRS = beep xttitle diff -r 1aa89ccfb626 -r a2642e56e0de mcabber/modules/xttitle/Makefile.am --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mcabber/modules/xttitle/Makefile.am Sat Mar 27 11:35:49 2010 +0100 @@ -0,0 +1,12 @@ + +if INSTALL_HEADERS + +pkglib_LTLIBRARIES = libxttitle.la +libxttitle_la_SOURCES = xttitle.c +libxttitle_la_LDFLAGS = -module -avoid-version -shared + +LDADD = $(GLIB_LIBS) +AM_CPPFLAGS = -I$(top_srcdir) $(GLIB_CFLAGS) $(LOUDMOUTH_CFLAGS) \ + $(GPGME_CFLAGS) $(LIBOTR_CFLAGS) $(ENCHANT_CFLAGS) + +endif diff -r 1aa89ccfb626 -r a2642e56e0de mcabber/modules/xttitle/xttitle.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mcabber/modules/xttitle/xttitle.c Sat Mar 27 11:35:49 2010 +0100 @@ -0,0 +1,99 @@ +/* + * Module "xttitle" -- Update X terminal tittle + * + * Copyright (C) 2010 Mikael Berthe + * + * This module is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include + +static void xttitle_init(void); +static void xttitle_uninit(void); + +/* Module description */ +module_info_t info_xttitle = { + .branch = MCABBER_BRANCH, + .api = MCABBER_API_VERSION, + .version = MCABBER_VERSION, + .description = "Show unread message count in X terminal title", + .requires = NULL, + .init = xttitle_init, + .uninit = xttitle_uninit, + .next = NULL, +}; + +// Hook handler id +static guint unread_list_hid; + +// Event handler for HOOK_UNREAD_LIST_CHANGE events +static guint unread_list_hh(const gchar *hookname, hk_arg_t *args, + gpointer userdata) +{ + guint all_unread = 0; + guint muc_unread = 0; + guint muc_attention = 0; + guint unread; // private message count + + // Note: We can add "attention" string later, but it isn't used + // yet in mcabber... + for ( ; args->name; args++) { + if (!g_strcmp0(args->name, "unread")) { + all_unread = atoi(args->value); + } else if (!g_strcmp0(args->name, "muc_unread")) { + muc_unread = atoi(args->value); + } else if (!g_strcmp0(args->name, "muc_attention")) { + muc_attention = atoi(args->value); + } + } + + // Let's not count the MUC unread buffers that don't have the attention + // flag (that is, MUC buffer that have no highlighted messages). + unread = all_unread - (muc_unread - muc_attention); + + // Update the terminal tittle + if (muc_unread) { + printf("\033]0;MCabber -- %d message%c (total:%d / MUC:%d)\007", + unread, (unread > 1 ? 's' : ' '), all_unread, muc_unread); + } else { + if (unread) + printf("\033]0;MCabber -- %d message%c\007", unread, + (unread > 1 ? 's' : ' ')); + else + printf("\033]0;MCabber -- No message\007"); + } + + return HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS; +} + +// Initialization +static void xttitle_init(void) +{ + // Add hook handler for unread message data + unread_list_hid = hk_add_handler(unread_list_hh, HOOK_UNREAD_LIST_CHANGE, + G_PRIORITY_DEFAULT_IDLE, NULL); +} + +// Uninitialization +static void xttitle_uninit(void) +{ + // Unregister handler + hk_del_handler(HOOK_UNREAD_LIST_CHANGE, unread_list_hid); +} + +/* vim: set et cindent cinoptions=>2\:2(0 ts=2 sw=2: For Vim users... */