Debian Codegraph @

src/fe-common/fe-xmpp-queries.c

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
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 "module.h"
19 #include "levels.h"
20 #include "module-formats.h"
21 #include "printtext.h"
22 #include "signals.h"
23 #include "window-items.h"
24
25 #include "xmpp-queries.h"
26 #include "rosters-tools.h"
27 #include "fe-xmpp-status.h"
28
29 int query_type;
30 int chatnet_type;
31
32 static void
33 sig_presence_changed(XMPP_SERVER_REC *server, const char *full_jid,
34 int show, const char *status)
35 {
36 XMPP_QUERY_REC *rec;
37 XMPP_ROSTER_USER_REC *user;
38 const char *msg;
39 char *name;
40
41 g_return_if_fail(server != NULL);
42 g_return_if_fail(full_jid != NULL);
43 g_return_if_fail(0 <= show && show < XMPP_PRESENCE_SHOW_LEN);
44 if ((rec = xmpp_query_find(server, full_jid)) == NULL)
45 return;
46 msg = fe_xmpp_presence_show[show];
47 user = rosters_find_user(server->roster, full_jid, NULL, NULL);
48 name = user != NULL && user->name != NULL ?
49 format_get_text(MODULE_NAME, NULL, server, NULL,
50 XMPPTXT_FORMAT_NAME, user->name, full_jid) :
51 format_get_text(MODULE_NAME, NULL, server, NULL,
52 XMPPTXT_FORMAT_JID, full_jid);
53 if (status != NULL)
54 printformat_module(MODULE_NAME, server, full_jid, MSGLEVEL_CRAP | MSGLEVEL_MODES,
55 XMPPTXT_PRESENCE_CHANGE_REASON, name, msg, status);
56 else
57 printformat_module(MODULE_NAME, server, full_jid, MSGLEVEL_CRAP | MSGLEVEL_MODES,
58 XMPPTXT_PRESENCE_CHANGE, name, msg);
59 }
60
61 static void
62 sig_query_raise(XMPP_SERVER_REC *server, QUERY_REC *query)
63 {
64 WINDOW_REC *window;
65
66 g_return_if_fail(query != NULL);
67 window = window_item_window(query);
68 if (window != active_win)
69 window_set_active(window);
70 window_item_set_active(active_win, (WI_ITEM_REC *)query);
71 }
72
73 static void
74 sig_query_created(XMPP_QUERY_REC *query, int automatic)
75 {
76 XMPP_ROSTER_USER_REC *user;
77
78 if (!IS_XMPP_QUERY(query))
79 return;
80 user = rosters_find_user(query->server->roster, query->name, NULL,
81 NULL);
82 if (user == NULL || user->name == NULL)
83 return;
84 printformat_module(MODULE_NAME, query->server, query->name,
85 MSGLEVEL_CRAP, XMPPTXT_QUERY_AKA, user->jid, user->name);
86 }
87
88 static void
89 sig_window_bound_query(SERVER_REC *gserver)
90 {
91 XMPP_SERVER_REC *server;
92 g_return_if_fail(gserver != NULL);
93
94 if ((server = XMPP_SERVER(gserver)) == NULL)
95 return;
96
97 #if defined(IRSSI_ABI_VERSION) && IRSSI_ABI_VERSION >= 20
98 GSList *tmp, *tmp2, *bounds;
99 for (tmp = windows; tmp != NULL; tmp = tmp->next) {
100 WINDOW_REC *win = tmp->data;
101 bounds = g_slist_copy(win->bound_items);
102
103 for (tmp2 = bounds; tmp2 != NULL; tmp2 = tmp2->next) {
104 WINDOW_BIND_REC *bound = tmp2->data;
105
106 if (bound->type == query_type) {
107 if (server->chat_type == chatnet_type &&
108 g_strcmp0(server->tag, bound->servertag) == 0) {
109 xmpp_query_create(bound->servertag, bound->name, TRUE);
110 }
111 }
112 }
113
114 g_slist_free(bounds);
115 }
116 #endif
117 }
118
119 void
120 fe_xmpp_queries_init(void)
121 {
122 query_type = module_get_uniq_id_str("WINDOW ITEM TYPE", "QUERY");
123 chatnet_type = XMPP_PROTOCOL;
124
125 signal_add("xmpp query raise", sig_query_raise);
126 signal_add("xmpp presence changed", sig_presence_changed);
127 signal_add("server connected", sig_window_bound_query);
128 signal_add_last("query created", sig_query_created);
129 }
130
131 void
132 fe_xmpp_queries_deinit(void)
133 {
134 signal_remove("xmpp query raise", sig_query_raise);
135 signal_remove("xmpp presence changed", sig_presence_changed);
136 signal_remove("server connected", sig_window_bound_query);
137 signal_remove("query created", sig_query_created);
138 }