47
|
1 /*
|
|
2 * commands.c -- user commands handling
|
|
3 *
|
|
4 * Copyright (C) 2005 Mikael Berthe <bmikael@lists.lilotux.net>
|
|
5 *
|
|
6 * This program 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, write to the Free Software
|
|
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
19 * USA
|
|
20 */
|
|
21
|
95
|
22 #include <string.h>
|
|
23
|
47
|
24 #include "commands.h"
|
|
25 #include "jabglue.h"
|
81
|
26 #include "roster.h"
|
47
|
27 #include "screen.h"
|
95
|
28 #include "compl.h"
|
113
|
29 #include "hooks.h"
|
191
|
30 #include "hbuf.h"
|
81
|
31 #include "utf8.h"
|
47
|
32 #include "utils.h"
|
|
33
|
104
|
34 // Commands callbacks
|
|
35 void do_roster(char *arg);
|
116
|
36 void do_status(char *arg);
|
124
|
37 void do_add(char *arg);
|
205
|
38 void do_del(char *arg);
|
128
|
39 void do_group(char *arg);
|
132
|
40 void do_say(char *arg);
|
238
|
41 void do_msay(char *arg);
|
187
|
42 void do_buffer(char *arg);
|
|
43 void do_clear(char *arg);
|
191
|
44 void do_info(char *arg);
|
208
|
45 void do_rename(char *arg);
|
210
|
46 void do_move(char *arg);
|
47
|
47
|
104
|
48 // Global variable for the commands list
|
95
|
49 static GSList *Commands;
|
|
50
|
104
|
51
|
95
|
52 // cmd_add()
|
|
53 // Adds a command to the commands list and to the CMD completion list
|
|
54 void cmd_add(const char *name, const char *help,
|
104
|
55 guint flags_row1, guint flags_row2, void (*f)())
|
95
|
56 {
|
|
57 cmd *n_cmd = g_new0(cmd, 1);
|
|
58 strncpy(n_cmd->name, name, 32-1);
|
|
59 n_cmd->help = help;
|
|
60 n_cmd->completion_flags[0] = flags_row1;
|
|
61 n_cmd->completion_flags[1] = flags_row2;
|
|
62 n_cmd->func = f;
|
102
|
63 Commands = g_slist_append(Commands, n_cmd);
|
95
|
64 // Add to completion CMD category
|
|
65 compl_add_category_word(COMPL_CMD, name);
|
|
66 }
|
|
67
|
|
68 // cmd_init()
|
|
69 // ...
|
|
70 void cmd_init(void)
|
|
71 {
|
124
|
72 cmd_add("add", "Add a jabber user", COMPL_JID, 0, &do_add);
|
187
|
73 cmd_add("buffer", "Manipulate current buddy's buffer (chat window)",
|
|
74 COMPL_BUFFER, 0, &do_buffer);
|
108
|
75 cmd_add("clear", "Clear the dialog window", 0, 0, &do_clear);
|
205
|
76 cmd_add("del", "Delete the current buddy", 0, 0, &do_del);
|
128
|
77 cmd_add("group", "Change group display settings", COMPL_GROUP, 0, &do_group);
|
127
|
78 cmd_add("help", "Display some help", COMPL_CMD, 0, NULL);
|
191
|
79 cmd_add("info", "Show basic infos on current buddy", 0, 0, &do_info);
|
225
|
80 cmd_add("move", "Move the current buddy to another group", COMPL_GROUPNAME,
|
|
81 0, &do_move);
|
238
|
82 cmd_add("msay", "Send a multi-lines message to the selected buddy",
|
|
83 COMPL_MULTILINE, 0, &do_msay);
|
95
|
84 //cmd_add("nick");
|
|
85 cmd_add("quit", "Exit the software", 0, 0, NULL);
|
208
|
86 cmd_add("rename", "Rename the current buddy", 0, 0, &do_rename);
|
95
|
87 //cmd_add("request_auth");
|
128
|
88 cmd_add("roster", "Manipulate the roster/buddylist", COMPL_ROSTER, 0,
|
|
89 &do_roster);
|
132
|
90 cmd_add("say", "Say something to the selected buddy", 0, 0, &do_say);
|
95
|
91 //cmd_add("search");
|
|
92 //cmd_add("send_auth");
|
116
|
93 cmd_add("status", "Show or set your status", COMPL_STATUS, 0, &do_status);
|
95
|
94
|
|
95 // Status category
|
|
96 compl_add_category_word(COMPL_STATUS, "online");
|
|
97 compl_add_category_word(COMPL_STATUS, "avail");
|
|
98 compl_add_category_word(COMPL_STATUS, "invisible");
|
|
99 compl_add_category_word(COMPL_STATUS, "free");
|
|
100 compl_add_category_word(COMPL_STATUS, "dnd");
|
|
101 compl_add_category_word(COMPL_STATUS, "busy");
|
|
102 compl_add_category_word(COMPL_STATUS, "notavail");
|
|
103 compl_add_category_word(COMPL_STATUS, "away");
|
103
|
104
|
|
105 // Roster category
|
|
106 compl_add_category_word(COMPL_ROSTER, "bottom");
|
|
107 compl_add_category_word(COMPL_ROSTER, "hide_offline");
|
|
108 compl_add_category_word(COMPL_ROSTER, "show_offline");
|
|
109 compl_add_category_word(COMPL_ROSTER, "top");
|
236
|
110 compl_add_category_word(COMPL_ROSTER, "unread_first");
|
|
111 compl_add_category_word(COMPL_ROSTER, "unread_next");
|
127
|
112
|
187
|
113 // Roster category
|
|
114 compl_add_category_word(COMPL_BUFFER, "bottom");
|
|
115 compl_add_category_word(COMPL_BUFFER, "clear");
|
|
116 compl_add_category_word(COMPL_BUFFER, "top");
|
|
117
|
127
|
118 // Group category
|
240
|
119 compl_add_category_word(COMPL_GROUP, "fold");
|
|
120 compl_add_category_word(COMPL_GROUP, "unfold");
|
130
|
121 compl_add_category_word(COMPL_GROUP, "toggle");
|
238
|
122
|
|
123 // Multi-line (msay) category
|
|
124 compl_add_category_word(COMPL_MULTILINE, "abort");
|
|
125 compl_add_category_word(COMPL_MULTILINE, "begin");
|
|
126 compl_add_category_word(COMPL_MULTILINE, "send");
|
95
|
127 }
|
94
|
128
|
102
|
129 // cmd_get
|
|
130 // Finds command in the command list structure.
|
|
131 // Returns a pointer to the cmd entry, or NULL if command not found.
|
238
|
132 cmd *cmd_get(const char *command)
|
102
|
133 {
|
238
|
134 const char *p1, *p2;
|
102
|
135 char *com;
|
|
136 GSList *sl_com;
|
|
137 // Ignore leading '/'
|
|
138 for (p1 = command ; *p1 == '/' ; p1++)
|
|
139 ;
|
|
140 // Locate the end of the command
|
|
141 for (p2 = p1 ; *p2 && (*p2 != ' ') ; p2++)
|
|
142 ;
|
|
143 // Copy the clean command
|
|
144 com = g_strndup(p1, p2-p1);
|
|
145
|
|
146 // Look for command in the list
|
|
147 for (sl_com=Commands; sl_com; sl_com = g_slist_next(sl_com)) {
|
|
148 if (!strcasecmp(com, ((cmd*)sl_com->data)->name))
|
|
149 break;
|
|
150 }
|
|
151 g_free(com);
|
|
152
|
|
153 if (sl_com) // Command has been found.
|
|
154 return (cmd*)sl_com->data;
|
|
155 return NULL;
|
|
156 }
|
|
157
|
47
|
158 // send_message(msg)
|
|
159 // Write the message in the buddy's window and send the message on
|
|
160 // the network.
|
238
|
161 void send_message(const char *msg)
|
47
|
162 {
|
81
|
163 const char *jid;
|
|
164
|
|
165 if (!current_buddy) {
|
|
166 scr_LogPrint("No buddy currently selected.");
|
|
167 return;
|
|
168 }
|
|
169
|
|
170 jid = CURRENT_JID;
|
|
171 if (!jid) {
|
|
172 scr_LogPrint("No buddy currently selected.");
|
|
173 return;
|
|
174 }
|
47
|
175
|
113
|
176 // local part (UI, logging, etc.)
|
|
177 hk_message_out(jid, 0, msg);
|
47
|
178
|
|
179 // Network part
|
213
|
180 jb_send_msg(jid, msg);
|
47
|
181 }
|
|
182
|
|
183 // process_line(line)
|
|
184 // Process a command/message line.
|
|
185 // If this isn't a command, this is a message and it is sent to the
|
|
186 // currently selected buddy.
|
|
187 int process_line(char *line)
|
|
188 {
|
101
|
189 char *p;
|
104
|
190 cmd *curcmd;
|
|
191
|
132
|
192 if (!*line) { // User only pressed enter
|
238
|
193 if (scr_get_multimode()) {
|
|
194 scr_append_multiline("");
|
|
195 return 0;
|
|
196 }
|
129
|
197 if (current_buddy) {
|
132
|
198 scr_set_chatmode(TRUE);
|
129
|
199 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE);
|
132
|
200 scr_ShowBuddyWindow();
|
|
201 }
|
|
202 return 0;
|
|
203 }
|
129
|
204
|
132
|
205 if (*line != '/') {
|
238
|
206 if (scr_get_multimode())
|
|
207 scr_append_multiline(line);
|
|
208 else
|
|
209 do_say(line);
|
47
|
210 return 0;
|
|
211 }
|
101
|
212
|
|
213 /* It is a command */
|
|
214 // Remove trailing spaces:
|
|
215 for (p=line ; *p ; p++)
|
|
216 ;
|
|
217 for (p-- ; p>line && (*p == ' ') ; p--)
|
|
218 *p = 0;
|
|
219
|
|
220 // Command "quit"?
|
116
|
221 if (!strncasecmp(line, "/quit", 5))
|
|
222 if (!line[5] || line[5] == ' ')
|
|
223 return 255;
|
104
|
224
|
47
|
225 // Commands handling
|
104
|
226 curcmd = cmd_get(line);
|
47
|
227
|
104
|
228 if (!curcmd) {
|
|
229 scr_LogPrint("Unrecognized command, sorry.");
|
|
230 return 0;
|
|
231 }
|
|
232 if (!curcmd->func) {
|
|
233 scr_LogPrint("Not yet implemented, sorry.");
|
|
234 return 0;
|
|
235 }
|
|
236 // Lets go to the command parameters
|
|
237 for (line++; *line && (*line != ' ') ; line++)
|
|
238 ;
|
|
239 // Skip spaces
|
|
240 while (*line && (*line == ' '))
|
|
241 line++;
|
|
242 // Call command-specific function
|
|
243 (*curcmd->func)(line);
|
47
|
244 return 0;
|
|
245 }
|
|
246
|
104
|
247 /* Commands callback functions */
|
|
248
|
|
249 void do_roster(char *arg)
|
|
250 {
|
|
251 if (!strcasecmp(arg, "top")) {
|
|
252 scr_RosterTop();
|
128
|
253 update_roster = TRUE;
|
104
|
254 } else if (!strcasecmp(arg, "bottom")) {
|
|
255 scr_RosterBottom();
|
128
|
256 update_roster = TRUE;
|
104
|
257 } else if (!strcasecmp(arg, "hide_offline")) {
|
120
|
258 buddylist_set_hide_offline_buddies(TRUE);
|
104
|
259 if (current_buddy)
|
|
260 buddylist_build();
|
128
|
261 update_roster = TRUE;
|
104
|
262 } else if (!strcasecmp(arg, "show_offline")) {
|
120
|
263 buddylist_set_hide_offline_buddies(FALSE);
|
124
|
264 buddylist_build();
|
128
|
265 update_roster = TRUE;
|
236
|
266 } else if (!strcasecmp(arg, "unread_first")) {
|
|
267 scr_RosterUnreadMessage(0);
|
|
268 } else if (!strcasecmp(arg, "unread_next")) {
|
|
269 scr_RosterUnreadMessage(1);
|
104
|
270 } else
|
|
271 scr_LogPrint("Unrecognized parameter!");
|
|
272 }
|
108
|
273
|
116
|
274 void do_status(char *arg)
|
|
275 {
|
|
276 enum imstatus st;
|
|
277
|
|
278 if (!arg || (*arg == 0)) {
|
|
279 scr_LogPrint("Your status is: %c", imstatus2char[jb_getstatus()]);
|
|
280 return;
|
|
281 }
|
|
282
|
130
|
283 if (!strcasecmp(arg, "offline")) st = offline;
|
|
284 else if (!strcasecmp(arg, "online")) st = available;
|
|
285 else if (!strcasecmp(arg, "avail")) st = available;
|
|
286 else if (!strcasecmp(arg, "away")) st = away;
|
|
287 else if (!strcasecmp(arg, "invisible")) st = invisible;
|
|
288 else if (!strcasecmp(arg, "dnd")) st = dontdisturb;
|
|
289 else if (!strcasecmp(arg, "busy")) st = occupied;
|
|
290 else if (!strcasecmp(arg, "notavail")) st = notavail;
|
|
291 else if (!strcasecmp(arg, "free")) st = freeforchat;
|
116
|
292 else {
|
|
293 scr_LogPrint("Unrecognized parameter!");
|
|
294 return;
|
|
295 }
|
|
296
|
|
297 // XXX special case if offline??
|
|
298 jb_setstatus(st, NULL); // TODO handle message (instead of NULL)
|
|
299 }
|
|
300
|
124
|
301 void do_add(char *arg)
|
|
302 {
|
244
|
303 char *id, *nick;
|
124
|
304 if (!arg || (*arg == 0)) {
|
|
305 scr_LogPrint("Wrong usage");
|
|
306 return;
|
|
307 }
|
|
308
|
244
|
309 id = g_strdup(arg);
|
|
310 nick = strchr(id, ' ');
|
|
311 if (nick) {
|
|
312 *nick++ = 0;
|
|
313 while (*nick && *nick == ' ')
|
|
314 nick++;
|
|
315 }
|
|
316
|
|
317 // FIXME check id =~ jabber id
|
|
318 // 2nd parameter = optional nickname
|
|
319 jb_addbuddy(id, nick, NULL);
|
|
320 scr_LogPrint("Sent presence notfication request to <%s>", id);
|
|
321 g_free(id);
|
124
|
322 }
|
128
|
323
|
206
|
324 void do_del(char *arg)
|
|
325 {
|
|
326 const char *jid;
|
|
327
|
|
328 if (arg && (*arg)) {
|
|
329 scr_LogPrint("Wrong usage");
|
|
330 return;
|
|
331 }
|
|
332
|
|
333 if (!current_buddy) return;
|
|
334 jid = buddy_getjid(BUDDATA(current_buddy));
|
|
335 if (!jid) return;
|
|
336
|
|
337 scr_LogPrint("Removing <%s>...", jid);
|
|
338 jb_delbuddy(jid);
|
|
339 }
|
|
340
|
128
|
341 void do_group(char *arg)
|
|
342 {
|
|
343 gpointer group;
|
166
|
344 guint leave_windowbuddy;
|
128
|
345
|
|
346 if (!arg || (*arg == 0)) {
|
|
347 scr_LogPrint("Missing parameter");
|
|
348 return;
|
|
349 }
|
|
350
|
166
|
351 if (!current_buddy) return;
|
128
|
352
|
166
|
353 group = buddy_getgroup(BUDDATA(current_buddy));
|
212
|
354 // We'll have to redraw the chat window if we're not currently on the group
|
|
355 // entry itself, because it means we'll have to leave the current buddy
|
|
356 // chat window.
|
166
|
357 leave_windowbuddy = (group != BUDDATA(current_buddy));
|
|
358
|
128
|
359 if (!(buddy_gettype(group) & ROSTER_TYPE_GROUP)) {
|
166
|
360 scr_LogPrint("You need to select a group");
|
128
|
361 return;
|
|
362 }
|
166
|
363
|
|
364 if (!strcasecmp(arg, "expand") || !strcasecmp(arg, "unfold")) {
|
128
|
365 buddy_setflags(group, ROSTER_FLAG_HIDE, FALSE);
|
166
|
366 } else if (!strcasecmp(arg, "shrink") || !strcasecmp(arg, "fold")) {
|
128
|
367 buddy_setflags(group, ROSTER_FLAG_HIDE, TRUE);
|
130
|
368 } else if (!strcasecmp(arg, "toggle")) {
|
|
369 buddy_setflags(group, ROSTER_FLAG_HIDE,
|
|
370 !(buddy_getflags(group) & ROSTER_FLAG_HIDE));
|
128
|
371 } else {
|
|
372 scr_LogPrint("Unrecognized parameter!");
|
|
373 return;
|
|
374 }
|
|
375
|
|
376 buddylist_build();
|
|
377 update_roster = TRUE;
|
166
|
378 if (leave_windowbuddy) scr_ShowBuddyWindow();
|
128
|
379 }
|
|
380
|
132
|
381 void do_say(char *arg)
|
|
382 {
|
164
|
383 gpointer bud;
|
132
|
384
|
|
385 scr_set_chatmode(TRUE);
|
164
|
386
|
|
387 if (!current_buddy) {
|
132
|
388 scr_LogPrint("Who are you talking to??");
|
164
|
389 return;
|
132
|
390 }
|
164
|
391
|
|
392 bud = BUDDATA(current_buddy);
|
|
393 if (!(buddy_gettype(bud) & ROSTER_TYPE_USER)) {
|
|
394 scr_LogPrint("This is not a user");
|
|
395 return;
|
|
396 }
|
|
397
|
|
398 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE);
|
|
399 send_message(arg);
|
132
|
400 }
|
|
401
|
238
|
402 void do_msay(char *arg)
|
|
403 {
|
|
404 /* begin abort send */
|
|
405 gpointer bud;
|
|
406
|
|
407 if (!strcasecmp(arg, "abort")) {
|
|
408 scr_set_multimode(FALSE);
|
|
409 return;
|
|
410 } else if (!strcasecmp(arg, "begin")) {
|
|
411 scr_set_multimode(TRUE);
|
|
412 scr_LogPrint("Entered multi-line message mode.");
|
|
413 scr_LogPrint("Select a buddy and use \"/msay send\" "
|
|
414 "when your message is ready.");
|
|
415 return;
|
|
416 } else if (*arg == 0) {
|
|
417 scr_LogPrint("Please read the manual before using the /msay command.");
|
|
418 scr_LogPrint("(Use /msay begin to enter multi-line mode...)");
|
|
419 return;
|
|
420 } else if (strcasecmp(arg, "send")) {
|
|
421 scr_LogPrint("Unrecognized parameter!");
|
|
422 return;
|
|
423 }
|
|
424
|
|
425 // send command
|
|
426
|
|
427 if (!scr_get_multimode()) {
|
|
428 scr_LogPrint("No message to send. Use \"/msay begin\" first.");
|
|
429 return;
|
|
430 }
|
|
431
|
|
432 scr_set_chatmode(TRUE);
|
|
433
|
|
434 if (!current_buddy) {
|
|
435 scr_LogPrint("Who are you talking to??");
|
|
436 return;
|
|
437 }
|
|
438
|
|
439 bud = BUDDATA(current_buddy);
|
|
440 if (!(buddy_gettype(bud) & ROSTER_TYPE_USER)) {
|
|
441 scr_LogPrint("This is not a user");
|
|
442 return;
|
|
443 }
|
|
444
|
|
445 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE);
|
|
446 send_message(scr_get_multiline());
|
|
447 scr_set_multimode(FALSE);
|
|
448 }
|
|
449
|
187
|
450 void do_buffer(char *arg)
|
|
451 {
|
|
452 if (!strcasecmp(arg, "top")) {
|
|
453 scr_BufferTop();
|
|
454 } else if (!strcasecmp(arg, "bottom")) {
|
|
455 scr_BufferBottom();
|
|
456 } else if (!strcasecmp(arg, "clear")) {
|
|
457 scr_Clear();
|
|
458 } else
|
|
459 scr_LogPrint("Unrecognized parameter!");
|
|
460 }
|
|
461
|
|
462 void do_clear(char *arg) // Alias for "/buffer clear"
|
|
463 {
|
|
464 do_buffer("clear");
|
|
465 }
|
|
466
|
191
|
467 void do_info(char *arg)
|
|
468 {
|
|
469 gpointer bud;
|
221
|
470 const char *jid, *name, *st_msg;
|
191
|
471 guint type;
|
|
472 enum imstatus status;
|
|
473 char *buffer;
|
|
474
|
|
475 if (!current_buddy) return;
|
|
476 bud = BUDDATA(current_buddy);
|
|
477
|
|
478 jid = buddy_getjid(bud);
|
|
479 name = buddy_getname(bud);
|
|
480 type = buddy_gettype(bud);
|
|
481 status = buddy_getstatus(bud);
|
221
|
482 st_msg = buddy_getstatusmsg(bud);
|
191
|
483
|
|
484 buffer = g_new(char, 128);
|
|
485
|
|
486 if (jid) {
|
|
487 char *typestr = "unknown";
|
|
488
|
|
489 snprintf(buffer, 127, "jid: <%s>", jid);
|
|
490 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO);
|
|
491 if (name) {
|
|
492 snprintf(buffer, 127, "Name: %s", name);
|
|
493 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO);
|
|
494 }
|
221
|
495 if (st_msg) {
|
|
496 snprintf(buffer, 127, "Status message: %s", st_msg);
|
|
497 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO);
|
|
498 }
|
191
|
499
|
|
500 if (type == ROSTER_TYPE_USER) typestr = "user";
|
|
501 else if (type == ROSTER_TYPE_AGENT) typestr = "agent";
|
|
502
|
|
503 snprintf(buffer, 127, "Type: %s", typestr);
|
|
504 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO);
|
|
505 } else {
|
|
506 if (name) scr_LogPrint("Name: %s", name);
|
|
507 scr_LogPrint("Type: %s",
|
|
508 ((type == ROSTER_TYPE_GROUP) ? "group" : "unknown"));
|
|
509 }
|
|
510
|
|
511 g_free(buffer);
|
|
512 }
|
|
513
|
208
|
514 void do_rename(char *arg)
|
|
515 {
|
|
516 gpointer bud;
|
|
517 const char *jid, *group;
|
|
518 guint type;
|
|
519 char *newname, *p;
|
|
520
|
|
521 if (!arg || (*arg == 0)) {
|
|
522 scr_LogPrint("Missing parameter");
|
|
523 return;
|
|
524 }
|
|
525
|
|
526 if (!current_buddy) return;
|
|
527 bud = BUDDATA(current_buddy);
|
|
528
|
|
529 jid = buddy_getjid(bud);
|
|
530 group = buddy_getgroupname(bud);
|
|
531 type = buddy_gettype(bud);
|
|
532
|
|
533 if (type & ROSTER_TYPE_GROUP) {
|
|
534 scr_LogPrint("You can't rename groups");
|
|
535 return;
|
|
536 }
|
|
537
|
|
538 newname = g_strdup(arg);
|
|
539 // Remove trailing space
|
|
540 for (p = newname; *p; p++) ;
|
|
541 while (p > newname && *p == ' ') *p = 0;
|
|
542
|
|
543 buddy_setname(bud, newname);
|
|
544 jb_updatebuddy(jid, newname, group);
|
|
545
|
|
546 g_free(newname);
|
|
547 update_roster = TRUE;
|
|
548 }
|
|
549
|
210
|
550 void do_move(char *arg)
|
|
551 {
|
|
552 gpointer bud;
|
|
553 const char *jid, *name;
|
|
554 guint type;
|
|
555 char *newgroupname, *p;
|
|
556
|
|
557 if (!current_buddy) return;
|
|
558 bud = BUDDATA(current_buddy);
|
|
559
|
|
560 jid = buddy_getjid(bud);
|
|
561 name = buddy_getname(bud);
|
|
562 type = buddy_gettype(bud);
|
|
563
|
|
564 if (type & ROSTER_TYPE_GROUP) {
|
|
565 scr_LogPrint("You can't move groups!");
|
|
566 return;
|
|
567 }
|
|
568
|
|
569 newgroupname = g_strdup(arg);
|
|
570 // Remove trailing space
|
|
571 for (p = newgroupname; *p; p++) ;
|
|
572 while (p > newgroupname && *p == ' ') *p = 0;
|
|
573
|
|
574 // Call to buddy_setgroup() should be at the end, as current implementation
|
|
575 // clones the buddy and deletes the old one (and thus, jid and name are
|
|
576 // freed)
|
|
577 jb_updatebuddy(jid, name, newgroupname);
|
|
578 buddy_setgroup(bud, newgroupname);
|
|
579
|
|
580 g_free(newgroupname);
|
|
581 update_roster = TRUE;
|
|
582 }
|
|
583
|