Debian Codegraph @

src/fe-text/xep/text-composing.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2007 Colin DIDIER
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18 #include <string.h>
19
20 #include "module.h"
21 #include "module-formats.h"
22 #include "signals.h"
23 #include "statusbar-item.h"
24 #include "window-items.h"
25
26 #include "xmpp-servers.h"
27 #include "xmpp-queries.h"
28
29 static void
30 item_xmpp_composing(struct SBAR_ITEM_REC *item, int get_size_only)
31 {
32 XMPP_SERVER_REC *server;
33 XMPP_QUERY_REC *query;
34 char *str = NULL;
35
36 server = XMPP_SERVER(active_win->active_server);
37 if (server == NULL || !IS_XMPP_SERVER(server))
38 goto out;
39 query = XMPP_QUERY(active_win->active);
40 if (query == NULL)
41 goto out;
42 if (query->composing_visible)
43 str = "{sb composing}";
44
45 out:
46 if (str == NULL) {
47 if (get_size_only)
48 statusbar_item_set_size(item, 0, 0);
49 return;
50 }
51 statusbar_item_default_handler(item, get_size_only,
52 str, "", FALSE);
53 }
54
55 static void
56 xmpp_composing_update(void)
57 {
58 statusbar_items_redraw("xmpp_composing");
59 }
60
61 static void
62 event_message_sent(XMPP_SERVER_REC *server, const char *message,
63 const char *full_jid, const char *ignore)
64 {
65 XMPP_QUERY_REC *query;
66
67 if (!IS_XMPP_SERVER(server))
68 return;
69 query = xmpp_query_find(server, full_jid);
70 if (query != NULL)
71 query->composing_visible = FALSE;
72 xmpp_composing_update();
73 }
74
75 void
76 text_composing_init(void)
77 {
78 statusbar_item_register("xmpp_composing", NULL, item_xmpp_composing);
79
80 signal_add("window changed", xmpp_composing_update);
81 signal_add_last("xmpp composing show", xmpp_composing_update);
82 signal_add_last("xmpp composing hide", xmpp_composing_update);
83 signal_add("message private", event_message_sent);
84 signal_add("message xmpp action", event_message_sent);
85 }
86
87 void
88 text_composing_deinit(void)
89 {
90 statusbar_item_unregister("xmpp_composing");
91
92 signal_remove("window changed", xmpp_composing_update);
93 signal_remove("xmpp composing show", xmpp_composing_update);
94 signal_remove("xmpp composing hide", xmpp_composing_update);
95 signal_remove("message private", event_message_sent);
96 signal_remove("message xmpp action", event_message_sent);
97 }