1827
|
1 /*
|
|
2 * Module "xttitle" -- Update X terminal tittle
|
|
3 *
|
|
4 * Copyright (C) 2010 Mikael Berthe <mikael@lilotux.net>
|
|
5 *
|
|
6 * This module is free software; you can redistribute it and/or modify
|
|
7 * it under the terms of the GNU General Public License as published by
|
|
8 * the Free Software Foundation; either version 2 of the License, or (at
|
|
9 * your option) any later version.
|
|
10 *
|
|
11 * This program is distributed in the hope that it will be useful, but
|
|
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
14 * General Public License for more details.
|
|
15 *
|
|
16 * You should have received a copy of the GNU General Public License
|
|
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
18 */
|
|
19
|
|
20 #include <stdlib.h>
|
|
21 #include <mcabber/modules.h>
|
|
22 #include <mcabber/settings.h>
|
|
23 #include <mcabber/hooks.h>
|
|
24 #include <mcabber/logprint.h>
|
|
25
|
|
26 static void xttitle_init(void);
|
|
27 static void xttitle_uninit(void);
|
|
28
|
|
29 /* Module description */
|
|
30 module_info_t info_xttitle = {
|
|
31 .branch = MCABBER_BRANCH,
|
|
32 .api = MCABBER_API_VERSION,
|
|
33 .version = MCABBER_VERSION,
|
|
34 .description = "Show unread message count in X terminal title",
|
|
35 .requires = NULL,
|
|
36 .init = xttitle_init,
|
|
37 .uninit = xttitle_uninit,
|
|
38 .next = NULL,
|
|
39 };
|
|
40
|
|
41 // Hook handler id
|
|
42 static guint unread_list_hid;
|
|
43
|
|
44 // Event handler for HOOK_UNREAD_LIST_CHANGE events
|
|
45 static guint unread_list_hh(const gchar *hookname, hk_arg_t *args,
|
|
46 gpointer userdata)
|
|
47 {
|
|
48 guint all_unread = 0;
|
|
49 guint muc_unread = 0;
|
|
50 guint muc_attention = 0;
|
|
51 guint unread; // private message count
|
|
52
|
|
53 // Note: We can add "attention" string later, but it isn't used
|
|
54 // yet in mcabber...
|
|
55 for ( ; args->name; args++) {
|
|
56 if (!g_strcmp0(args->name, "unread")) {
|
|
57 all_unread = atoi(args->value);
|
|
58 } else if (!g_strcmp0(args->name, "muc_unread")) {
|
|
59 muc_unread = atoi(args->value);
|
|
60 } else if (!g_strcmp0(args->name, "muc_attention")) {
|
|
61 muc_attention = atoi(args->value);
|
|
62 }
|
|
63 }
|
|
64
|
|
65 // Let's not count the MUC unread buffers that don't have the attention
|
|
66 // flag (that is, MUC buffer that have no highlighted messages).
|
|
67 unread = all_unread - (muc_unread - muc_attention);
|
|
68
|
|
69 // Update the terminal tittle
|
|
70 if (muc_unread) {
|
|
71 printf("\033]0;MCabber -- %d message%c (total:%d / MUC:%d)\007",
|
|
72 unread, (unread > 1 ? 's' : ' '), all_unread, muc_unread);
|
|
73 } else {
|
|
74 if (unread)
|
|
75 printf("\033]0;MCabber -- %d message%c\007", unread,
|
|
76 (unread > 1 ? 's' : ' '));
|
|
77 else
|
|
78 printf("\033]0;MCabber -- No message\007");
|
|
79 }
|
|
80
|
|
81 return HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
|
|
82 }
|
|
83
|
|
84 // Initialization
|
|
85 static void xttitle_init(void)
|
|
86 {
|
|
87 // Add hook handler for unread message data
|
|
88 unread_list_hid = hk_add_handler(unread_list_hh, HOOK_UNREAD_LIST_CHANGE,
|
|
89 G_PRIORITY_DEFAULT_IDLE, NULL);
|
|
90 }
|
|
91
|
|
92 // Uninitialization
|
|
93 static void xttitle_uninit(void)
|
|
94 {
|
|
95 // Unregister handler
|
|
96 hk_del_handler(HOOK_UNREAD_LIST_CHANGE, unread_list_hid);
|
|
97 }
|
|
98
|
|
99 /* vim: set et cindent cinoptions=>2\:2(0 ts=2 sw=2: For Vim users... */
|