76
70
quoted_if_space(nick, resource->name) :
77
71
g_strconcat(nick, "/", resource->name, NULL));
77
get_jids(XMPP_SERVER_REC *server, const char *jid)
80
GList *list, *list_case, *offlist, *offlist_case;
81
XMPP_ROSTER_USER_REC *user;
84
list = list_case = offlist = offlist_case = NULL;
86
for (gl = server->roster; gl != NULL; gl = gl->next) {
87
for (ul = ((XMPP_ROSTER_GROUP_REC *)gl->data)->users;
88
ul != NULL ; ul = ul->next) {
89
user = (XMPP_ROSTER_USER_REC *)ul->data;
90
if (strncmp(user->jid, jid, len) == 0) {
91
if (user->resources != NULL)
92
g_list_append(list, user->jid);
94
g_list_append(offlist, user->jid);
95
} else if (g_strncasecmp(user->jid, jid, len) == 0) {
96
if (user->resources != NULL)
97
g_list_append(list_case, user->jid);
99
g_list_append(offlist_case, user->jid);
103
/* TODO: temporary list of jids */
104
list = g_list_concat(list, list_case);
105
list = g_list_concat(list, offlist);
106
list = g_list_concat(list, offlist_case);
94
g_return_val_if_fail(IS_XMPP_SERVER(server), NULL);
95
g_return_val_if_fail(nick != NULL, NULL);
97
121
len = strlen(nick);
99
122
/* resources completion */
100
123
resource = xmpp_extract_resource(nick);
101
124
if (resource != NULL) {
102
125
jid = xmpp_strip_resource(nick);
104
126
list = get_resources(server, jid, resource, quoted);
106
127
g_free(resource);
116
134
/* first complete with online contacts
117
135
* then complete with offline contacts */
118
136
for (gl = server->roster; gl != NULL; gl = gl->next) {
120
137
for (ul = ((XMPP_ROSTER_GROUP_REC *)gl->data)->users;
121
138
ul != NULL ; ul = ul->next) {
122
139
user = (XMPP_ROSTER_USER_REC *)ul->data;
124
140
if ((!pass2 && user->resources == NULL)
125
141
|| (pass2 && user->resources != NULL))
128
143
if (complete_names && user->name != NULL
129
144
&& g_strncasecmp(user->name, nick, len) == 0)
130
145
list = g_list_prepend(list, quoted ?
131
146
quoted_if_space(user->name, NULL) :
132
147
g_strdup(user->name));
134
148
if (g_strncasecmp(user->jid, nick, len) == 0)
135
149
list = g_list_prepend(list, quoted ?
136
150
quoted_if_space(user->jid, NULL) :
137
151
g_strdup(user->jid));
141
154
if ((pass2 = !pass2))
156
/* TODO: rewrite this function */
227
227
g_return_if_fail(window != NULL);
228
228
g_return_if_fail(word != NULL);
229
229
g_return_if_fail(args != NULL);
231
server = XMPP_SERVER(window->active_server);
230
if ((server = XMPP_SERVER(window->active_server)) == NULL)
235
232
len = strlen(word);
236
233
tmp = g_strsplit(args, " ", 2);
238
234
/* complete nicks */
239
235
if (tmp[0] == NULL)
240
236
*list = g_list_concat(*list, get_nicks(server, *word == '"' ?
241
237
word+1 : word , TRUE, FALSE));
244
sig_complete_command_presence(GList **list, WINDOW_REC *window,
245
const char *word, const char *args, int *want_space)
247
XMPP_SERVER_REC *server;
251
g_return_if_fail(list != NULL);
252
g_return_if_fail(window != NULL);
253
g_return_if_fail(word != NULL);
254
g_return_if_fail(args != NULL);
255
if ((server = XMPP_SERVER(window->active_server)) == NULL)
258
tmp = g_strsplit(args, " ", 2);
261
*list = g_list_concat(*list, get_jids(server, *word == '"' ?
245
264
if (*list != NULL)
254
XMPP_CHANNEL_REC *channel;
273
CHANNEL_REC *channel;
255
274
CHANNEL_SETUP_REC *channel_setup;
258
277
g_return_val_if_fail(IS_XMPP_SERVER(server), NULL);
259
278
g_return_val_if_fail(word != NULL, NULL);
261
279
len = strlen(word);
264
/* get joined channels */
265
281
for (tmp = server->channels; tmp != NULL; tmp = tmp->next) {
266
channel = XMPP_CHANNEL(tmp->data);
282
channel = CHANNEL(tmp->data);
268
283
if (channel != NULL &&
269
284
g_strncasecmp(channel->name, word, len) == 0)
270
285
list = g_list_append(list, g_strdup(channel->name));
273
/* get channels from setup */
274
287
for (tmp = setupchannels; tmp != NULL; tmp = tmp->next) {
275
288
channel_setup = tmp->data;
277
if ((IS_XMPP_CHANNEL_SETUP(channel_setup)
289
if ((PROTO_CHECK_CAST(channel_setup, CHANNEL_SETUP_REC,
290
chat_type, XMPP_PROTOCOL_NAME)
278
291
|| *channel_setup->name != '#')
279
292
&& g_strncasecmp(channel_setup->name, word, len) == 0
280
293
&& glist_find_string(list, channel_setup->name) == NULL)
281
294
list = g_list_append(list,
282
295
g_strdup(channel_setup->name));
340
346
g_return_if_fail(list != NULL);
341
347
g_return_if_fail(window != NULL);
342
348
g_return_if_fail(word != NULL);
344
349
server = XMPP_SERVER(window->active_server);
345
350
if (server == NULL)
348
352
len = strlen(word);
350
353
if (g_strncasecmp(word,
351
354
xmpp_presence_show[XMPP_PRESENCE_AWAY], len) == 0)
352
355
*list = g_list_append(*list,
353
356
g_strdup(xmpp_presence_show[XMPP_PRESENCE_AWAY]));
355
357
if (g_strncasecmp(word,
356
358
xmpp_presence_show[XMPP_PRESENCE_XA], len) == 0)
357
359
*list = g_list_append(*list,
358
360
g_strdup(xmpp_presence_show[XMPP_PRESENCE_XA]));
360
361
if (g_strncasecmp(word,
361
362
xmpp_presence_show[XMPP_PRESENCE_DND], len) == 0)
362
363
*list = g_list_append(*list,
363
364
g_strdup(xmpp_presence_show[XMPP_PRESENCE_DND]));
365
365
if (g_strncasecmp(word,
366
366
xmpp_presence_show[XMPP_PRESENCE_CHAT], len) == 0)
367
367
*list = g_list_append(*list,
368
368
g_strdup(xmpp_presence_show[XMPP_PRESENCE_CHAT]));
370
369
if (g_strncasecmp(word,
371
xmpp_presence_show[XMPP_PRESENCE_ONLINE_STR], len) == 0)
370
xmpp_presence_show[XMPP_PRESENCE_ONLINE], len) == 0)
372
371
*list = g_list_append(*list, g_strdup("online"));
378
376
xmpp_completion_init(void)
380
signal_add("complete word", (SIGNAL_FUNC)sig_complete_word);
378
signal_add("complete word", sig_complete_word);
381
379
signal_add("complete command roster group",
382
(SIGNAL_FUNC)sig_complete_command_roster_group);
380
sig_complete_command_roster_group);
383
381
signal_add("complete command roster add",
384
(SIGNAL_FUNC)sig_complete_command_roster_others);
382
sig_complete_command_roster_others);
385
383
signal_add("complete command roster remove",
386
(SIGNAL_FUNC)sig_complete_command_roster_others);
384
sig_complete_command_roster_others);
387
385
signal_add("complete command roster name",
388
(SIGNAL_FUNC)sig_complete_command_roster_others);
389
signal_add("complete command roster accept",
390
(SIGNAL_FUNC)sig_complete_command_roster_others);
391
signal_add("complete command roster deny",
392
(SIGNAL_FUNC)sig_complete_command_roster_others);
393
signal_add("complete command roster subscribe",
394
(SIGNAL_FUNC)sig_complete_command_roster_others);
395
signal_add("complete command roster unsubscribe",
396
(SIGNAL_FUNC)sig_complete_command_roster_others);
397
signal_add("complete command join",
398
(SIGNAL_FUNC)sig_complete_command_channels);
399
signal_add("complete command part",
400
(SIGNAL_FUNC)sig_complete_command_channels);
401
signal_add("complete command invite",
402
(SIGNAL_FUNC)sig_complete_command_invite);
403
signal_add("complete command away",
404
(SIGNAL_FUNC)sig_complete_command_away);
386
sig_complete_command_roster_others);
387
signal_add("complete command presence accept",
388
sig_complete_command_presence);
389
signal_add("complete command presence deny",
390
sig_complete_command_presence);
391
signal_add("complete command presence subscribe",
392
sig_complete_command_presence);
393
signal_add("complete command presence unsubscribe",
394
sig_complete_command_presence);
395
signal_add("complete command join", sig_complete_command_channels);
396
signal_add("complete command part", sig_complete_command_channels);
397
signal_add("complete command invite", sig_complete_command_invite);
398
signal_add("complete command away", sig_complete_command_away);
408
402
xmpp_completion_deinit(void)
410
signal_remove("complete word", (SIGNAL_FUNC)sig_complete_word);
404
signal_remove("complete word", sig_complete_word);
411
405
signal_remove("complete command roster group",
412
(SIGNAL_FUNC) sig_complete_command_roster_group);
406
sig_complete_command_roster_group);
413
407
signal_remove("complete command roster add",
414
(SIGNAL_FUNC)sig_complete_command_roster_others);
408
sig_complete_command_roster_others);
415
409
signal_remove("complete command roster remove",
416
(SIGNAL_FUNC)sig_complete_command_roster_others);
410
sig_complete_command_roster_others);
417
411
signal_remove("complete command roster name",
418
(SIGNAL_FUNC)sig_complete_command_roster_others);
419
signal_remove("complete command roster accept",
420
(SIGNAL_FUNC)sig_complete_command_roster_others);
421
signal_remove("complete command roster deny",
422
(SIGNAL_FUNC)sig_complete_command_roster_others);
423
signal_remove("complete command roster subscribe",
424
(SIGNAL_FUNC)sig_complete_command_roster_others);
425
signal_remove("complete command roster unsubscribe",
426
(SIGNAL_FUNC)sig_complete_command_roster_others);
427
signal_remove("complete command join",
428
(SIGNAL_FUNC)sig_complete_command_channels);
429
signal_remove("complete command part",
430
(SIGNAL_FUNC)sig_complete_command_channels);
431
signal_remove("complete command invite",
432
(SIGNAL_FUNC)sig_complete_command_invite);
433
signal_remove("complete command away",
434
(SIGNAL_FUNC)sig_complete_command_away);
412
sig_complete_command_roster_others);
413
signal_remove("complete command presence accept",
414
sig_complete_command_presence);
415
signal_remove("complete command presence deny",
416
sig_complete_command_presence);
417
signal_remove("complete command presence subscribe",
418
sig_complete_command_presence);
419
signal_remove("complete command presence unsubscribe",
420
sig_complete_command_presence);
421
signal_remove("complete command join", sig_complete_command_channels);
422
signal_remove("complete command part", sig_complete_command_channels);
423
signal_remove("complete command invite", sig_complete_command_invite);
424
signal_remove("complete command away", sig_complete_command_away);