Mercurial > hg
annotate mcabber/src/commands.c @ 265:49e9e02dd6d0
Add "/roster search" command
author | mikael@frmp8452 |
---|---|
date | Sat, 02 Jul 2005 19:23:45 +0100 |
parents | ab6f83a82811 |
children | 4d7040cff8ee |
rev | line source |
---|---|
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); |
262
ab6f83a82811
Do not add /help to command completion, as it isn't implemented yet.
mikael@frmp8452
parents:
260
diff
changeset
|
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"); | |
265 | 107 compl_add_category_word(COMPL_ROSTER, "top"); |
103 | 108 compl_add_category_word(COMPL_ROSTER, "hide_offline"); |
109 compl_add_category_word(COMPL_ROSTER, "show_offline"); | |
265 | 110 compl_add_category_word(COMPL_ROSTER, "search"); |
236 | 111 compl_add_category_word(COMPL_ROSTER, "unread_first"); |
112 compl_add_category_word(COMPL_ROSTER, "unread_next"); | |
127 | 113 |
187 | 114 // Roster category |
115 compl_add_category_word(COMPL_BUFFER, "bottom"); | |
116 compl_add_category_word(COMPL_BUFFER, "clear"); | |
117 compl_add_category_word(COMPL_BUFFER, "top"); | |
118 | |
127 | 119 // Group category |
240 | 120 compl_add_category_word(COMPL_GROUP, "fold"); |
121 compl_add_category_word(COMPL_GROUP, "unfold"); | |
130 | 122 compl_add_category_word(COMPL_GROUP, "toggle"); |
238 | 123 |
124 // Multi-line (msay) category | |
125 compl_add_category_word(COMPL_MULTILINE, "abort"); | |
126 compl_add_category_word(COMPL_MULTILINE, "begin"); | |
127 compl_add_category_word(COMPL_MULTILINE, "send"); | |
260
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
128 compl_add_category_word(COMPL_MULTILINE, "verbatim"); |
95 | 129 } |
94 | 130 |
102 | 131 // cmd_get |
132 // Finds command in the command list structure. | |
133 // Returns a pointer to the cmd entry, or NULL if command not found. | |
238 | 134 cmd *cmd_get(const char *command) |
102 | 135 { |
238 | 136 const char *p1, *p2; |
102 | 137 char *com; |
138 GSList *sl_com; | |
139 // Ignore leading '/' | |
140 for (p1 = command ; *p1 == '/' ; p1++) | |
141 ; | |
142 // Locate the end of the command | |
143 for (p2 = p1 ; *p2 && (*p2 != ' ') ; p2++) | |
144 ; | |
145 // Copy the clean command | |
146 com = g_strndup(p1, p2-p1); | |
147 | |
148 // Look for command in the list | |
149 for (sl_com=Commands; sl_com; sl_com = g_slist_next(sl_com)) { | |
150 if (!strcasecmp(com, ((cmd*)sl_com->data)->name)) | |
151 break; | |
152 } | |
153 g_free(com); | |
154 | |
155 if (sl_com) // Command has been found. | |
156 return (cmd*)sl_com->data; | |
157 return NULL; | |
158 } | |
159 | |
47 | 160 // send_message(msg) |
161 // Write the message in the buddy's window and send the message on | |
162 // the network. | |
238 | 163 void send_message(const char *msg) |
47 | 164 { |
81 | 165 const char *jid; |
166 | |
167 if (!current_buddy) { | |
168 scr_LogPrint("No buddy currently selected."); | |
169 return; | |
170 } | |
171 | |
172 jid = CURRENT_JID; | |
173 if (!jid) { | |
174 scr_LogPrint("No buddy currently selected."); | |
175 return; | |
176 } | |
47 | 177 |
113 | 178 // local part (UI, logging, etc.) |
179 hk_message_out(jid, 0, msg); | |
47 | 180 |
181 // Network part | |
213 | 182 jb_send_msg(jid, msg); |
47 | 183 } |
184 | |
185 // process_line(line) | |
186 // Process a command/message line. | |
187 // If this isn't a command, this is a message and it is sent to the | |
188 // currently selected buddy. | |
189 int process_line(char *line) | |
190 { | |
101 | 191 char *p; |
104 | 192 cmd *curcmd; |
193 | |
132 | 194 if (!*line) { // User only pressed enter |
238 | 195 if (scr_get_multimode()) { |
196 scr_append_multiline(""); | |
197 return 0; | |
198 } | |
129 | 199 if (current_buddy) { |
132 | 200 scr_set_chatmode(TRUE); |
129 | 201 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE); |
132 | 202 scr_ShowBuddyWindow(); |
203 } | |
204 return 0; | |
205 } | |
129 | 206 |
132 | 207 if (*line != '/') { |
260
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
208 // This isn't a command |
238 | 209 if (scr_get_multimode()) |
210 scr_append_multiline(line); | |
211 else | |
212 do_say(line); | |
47 | 213 return 0; |
214 } | |
101 | 215 |
216 /* It is a command */ | |
217 // Remove trailing spaces: | |
218 for (p=line ; *p ; p++) | |
219 ; | |
220 for (p-- ; p>line && (*p == ' ') ; p--) | |
221 *p = 0; | |
222 | |
223 // Command "quit"? | |
260
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
224 if ((!strncasecmp(line, "/quit", 5)) && (scr_get_multimode() != 2) ) |
116 | 225 if (!line[5] || line[5] == ' ') |
226 return 255; | |
104 | 227 |
260
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
228 // If verbatim multi-line mode, we check if another /msay command is typed |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
229 if ((scr_get_multimode() == 2) && (strncasecmp(line, "/msay ", 6))) { |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
230 // It isn't an /msay command |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
231 scr_append_multiline(line); |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
232 return 0; |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
233 } |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
234 |
47 | 235 // Commands handling |
104 | 236 curcmd = cmd_get(line); |
47 | 237 |
104 | 238 if (!curcmd) { |
239 scr_LogPrint("Unrecognized command, sorry."); | |
240 return 0; | |
241 } | |
242 if (!curcmd->func) { | |
243 scr_LogPrint("Not yet implemented, sorry."); | |
244 return 0; | |
245 } | |
246 // Lets go to the command parameters | |
247 for (line++; *line && (*line != ' ') ; line++) | |
248 ; | |
249 // Skip spaces | |
250 while (*line && (*line == ' ')) | |
251 line++; | |
252 // Call command-specific function | |
253 (*curcmd->func)(line); | |
47 | 254 return 0; |
255 } | |
256 | |
104 | 257 /* Commands callback functions */ |
258 | |
259 void do_roster(char *arg) | |
260 { | |
261 if (!strcasecmp(arg, "top")) { | |
262 scr_RosterTop(); | |
128 | 263 update_roster = TRUE; |
104 | 264 } else if (!strcasecmp(arg, "bottom")) { |
265 scr_RosterBottom(); | |
128 | 266 update_roster = TRUE; |
104 | 267 } else if (!strcasecmp(arg, "hide_offline")) { |
120 | 268 buddylist_set_hide_offline_buddies(TRUE); |
104 | 269 if (current_buddy) |
270 buddylist_build(); | |
128 | 271 update_roster = TRUE; |
104 | 272 } else if (!strcasecmp(arg, "show_offline")) { |
120 | 273 buddylist_set_hide_offline_buddies(FALSE); |
124 | 274 buddylist_build(); |
128 | 275 update_roster = TRUE; |
236 | 276 } else if (!strcasecmp(arg, "unread_first")) { |
277 scr_RosterUnreadMessage(0); | |
278 } else if (!strcasecmp(arg, "unread_next")) { | |
279 scr_RosterUnreadMessage(1); | |
265 | 280 } else if (!strncasecmp(arg, "search", 6)) { |
281 char *string = arg+6; | |
282 if (*string && (*string != ' ')) { | |
283 scr_LogPrint("Unrecognized parameter!"); | |
284 return; | |
285 } | |
286 while (*string == ' ') | |
287 string++; | |
288 if (!*string) { | |
289 scr_LogPrint("What name or jid are you looking for?"); | |
290 return; | |
291 } | |
292 scr_RosterSearch(string); | |
293 update_roster = TRUE; | |
104 | 294 } else |
295 scr_LogPrint("Unrecognized parameter!"); | |
296 } | |
108 | 297 |
116 | 298 void do_status(char *arg) |
299 { | |
300 enum imstatus st; | |
301 | |
302 if (!arg || (*arg == 0)) { | |
303 scr_LogPrint("Your status is: %c", imstatus2char[jb_getstatus()]); | |
304 return; | |
305 } | |
306 | |
130 | 307 if (!strcasecmp(arg, "offline")) st = offline; |
308 else if (!strcasecmp(arg, "online")) st = available; | |
309 else if (!strcasecmp(arg, "avail")) st = available; | |
310 else if (!strcasecmp(arg, "away")) st = away; | |
311 else if (!strcasecmp(arg, "invisible")) st = invisible; | |
312 else if (!strcasecmp(arg, "dnd")) st = dontdisturb; | |
313 else if (!strcasecmp(arg, "busy")) st = occupied; | |
314 else if (!strcasecmp(arg, "notavail")) st = notavail; | |
315 else if (!strcasecmp(arg, "free")) st = freeforchat; | |
116 | 316 else { |
317 scr_LogPrint("Unrecognized parameter!"); | |
318 return; | |
319 } | |
320 | |
321 // XXX special case if offline?? | |
322 jb_setstatus(st, NULL); // TODO handle message (instead of NULL) | |
323 } | |
324 | |
124 | 325 void do_add(char *arg) |
326 { | |
244 | 327 char *id, *nick; |
124 | 328 if (!arg || (*arg == 0)) { |
329 scr_LogPrint("Wrong usage"); | |
330 return; | |
331 } | |
332 | |
244 | 333 id = g_strdup(arg); |
334 nick = strchr(id, ' '); | |
335 if (nick) { | |
336 *nick++ = 0; | |
337 while (*nick && *nick == ' ') | |
338 nick++; | |
339 } | |
340 | |
341 // FIXME check id =~ jabber id | |
342 // 2nd parameter = optional nickname | |
343 jb_addbuddy(id, nick, NULL); | |
344 scr_LogPrint("Sent presence notfication request to <%s>", id); | |
345 g_free(id); | |
124 | 346 } |
128 | 347 |
206 | 348 void do_del(char *arg) |
349 { | |
350 const char *jid; | |
351 | |
352 if (arg && (*arg)) { | |
353 scr_LogPrint("Wrong usage"); | |
354 return; | |
355 } | |
356 | |
357 if (!current_buddy) return; | |
358 jid = buddy_getjid(BUDDATA(current_buddy)); | |
359 if (!jid) return; | |
360 | |
361 scr_LogPrint("Removing <%s>...", jid); | |
362 jb_delbuddy(jid); | |
363 } | |
364 | |
128 | 365 void do_group(char *arg) |
366 { | |
367 gpointer group; | |
166 | 368 guint leave_windowbuddy; |
128 | 369 |
370 if (!arg || (*arg == 0)) { | |
371 scr_LogPrint("Missing parameter"); | |
372 return; | |
373 } | |
374 | |
166 | 375 if (!current_buddy) return; |
128 | 376 |
166 | 377 group = buddy_getgroup(BUDDATA(current_buddy)); |
212 | 378 // We'll have to redraw the chat window if we're not currently on the group |
379 // entry itself, because it means we'll have to leave the current buddy | |
380 // chat window. | |
166 | 381 leave_windowbuddy = (group != BUDDATA(current_buddy)); |
382 | |
128 | 383 if (!(buddy_gettype(group) & ROSTER_TYPE_GROUP)) { |
166 | 384 scr_LogPrint("You need to select a group"); |
128 | 385 return; |
386 } | |
166 | 387 |
388 if (!strcasecmp(arg, "expand") || !strcasecmp(arg, "unfold")) { | |
128 | 389 buddy_setflags(group, ROSTER_FLAG_HIDE, FALSE); |
166 | 390 } else if (!strcasecmp(arg, "shrink") || !strcasecmp(arg, "fold")) { |
128 | 391 buddy_setflags(group, ROSTER_FLAG_HIDE, TRUE); |
130 | 392 } else if (!strcasecmp(arg, "toggle")) { |
393 buddy_setflags(group, ROSTER_FLAG_HIDE, | |
394 !(buddy_getflags(group) & ROSTER_FLAG_HIDE)); | |
128 | 395 } else { |
396 scr_LogPrint("Unrecognized parameter!"); | |
397 return; | |
398 } | |
399 | |
400 buddylist_build(); | |
401 update_roster = TRUE; | |
166 | 402 if (leave_windowbuddy) scr_ShowBuddyWindow(); |
128 | 403 } |
404 | |
132 | 405 void do_say(char *arg) |
406 { | |
164 | 407 gpointer bud; |
132 | 408 |
409 scr_set_chatmode(TRUE); | |
164 | 410 |
411 if (!current_buddy) { | |
132 | 412 scr_LogPrint("Who are you talking to??"); |
164 | 413 return; |
132 | 414 } |
164 | 415 |
416 bud = BUDDATA(current_buddy); | |
417 if (!(buddy_gettype(bud) & ROSTER_TYPE_USER)) { | |
418 scr_LogPrint("This is not a user"); | |
419 return; | |
420 } | |
421 | |
422 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE); | |
423 send_message(arg); | |
132 | 424 } |
425 | |
238 | 426 void do_msay(char *arg) |
427 { | |
260
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
428 /* Parameters: begin verbatim abort send */ |
238 | 429 gpointer bud; |
430 | |
431 if (!strcasecmp(arg, "abort")) { | |
432 scr_set_multimode(FALSE); | |
433 return; | |
260
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
434 } else if ((!strcasecmp(arg, "begin")) || (!strcasecmp(arg, "verbatim"))) { |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
435 if (!strcasecmp(arg, "verbatim")) |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
436 scr_set_multimode(2); |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
437 else |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
438 scr_set_multimode(1); |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
439 |
238 | 440 scr_LogPrint("Entered multi-line message mode."); |
441 scr_LogPrint("Select a buddy and use \"/msay send\" " | |
442 "when your message is ready."); | |
443 return; | |
444 } else if (*arg == 0) { | |
445 scr_LogPrint("Please read the manual before using the /msay command."); | |
446 scr_LogPrint("(Use /msay begin to enter multi-line mode...)"); | |
447 return; | |
448 } else if (strcasecmp(arg, "send")) { | |
449 scr_LogPrint("Unrecognized parameter!"); | |
450 return; | |
451 } | |
452 | |
453 // send command | |
454 | |
455 if (!scr_get_multimode()) { | |
456 scr_LogPrint("No message to send. Use \"/msay begin\" first."); | |
457 return; | |
458 } | |
459 | |
460 scr_set_chatmode(TRUE); | |
461 | |
462 if (!current_buddy) { | |
463 scr_LogPrint("Who are you talking to??"); | |
464 return; | |
465 } | |
466 | |
467 bud = BUDDATA(current_buddy); | |
468 if (!(buddy_gettype(bud) & ROSTER_TYPE_USER)) { | |
469 scr_LogPrint("This is not a user"); | |
470 return; | |
471 } | |
472 | |
473 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE); | |
474 send_message(scr_get_multiline()); | |
475 scr_set_multimode(FALSE); | |
476 } | |
477 | |
187 | 478 void do_buffer(char *arg) |
479 { | |
480 if (!strcasecmp(arg, "top")) { | |
481 scr_BufferTop(); | |
482 } else if (!strcasecmp(arg, "bottom")) { | |
483 scr_BufferBottom(); | |
484 } else if (!strcasecmp(arg, "clear")) { | |
485 scr_Clear(); | |
486 } else | |
487 scr_LogPrint("Unrecognized parameter!"); | |
488 } | |
489 | |
490 void do_clear(char *arg) // Alias for "/buffer clear" | |
491 { | |
492 do_buffer("clear"); | |
493 } | |
494 | |
191 | 495 void do_info(char *arg) |
496 { | |
497 gpointer bud; | |
221 | 498 const char *jid, *name, *st_msg; |
191 | 499 guint type; |
500 enum imstatus status; | |
501 char *buffer; | |
502 | |
503 if (!current_buddy) return; | |
504 bud = BUDDATA(current_buddy); | |
505 | |
506 jid = buddy_getjid(bud); | |
507 name = buddy_getname(bud); | |
508 type = buddy_gettype(bud); | |
509 status = buddy_getstatus(bud); | |
221 | 510 st_msg = buddy_getstatusmsg(bud); |
191 | 511 |
512 buffer = g_new(char, 128); | |
513 | |
514 if (jid) { | |
515 char *typestr = "unknown"; | |
516 | |
517 snprintf(buffer, 127, "jid: <%s>", jid); | |
518 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); | |
519 if (name) { | |
520 snprintf(buffer, 127, "Name: %s", name); | |
521 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); | |
522 } | |
221 | 523 if (st_msg) { |
524 snprintf(buffer, 127, "Status message: %s", st_msg); | |
525 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); | |
526 } | |
191 | 527 |
528 if (type == ROSTER_TYPE_USER) typestr = "user"; | |
529 else if (type == ROSTER_TYPE_AGENT) typestr = "agent"; | |
530 | |
531 snprintf(buffer, 127, "Type: %s", typestr); | |
532 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); | |
533 } else { | |
534 if (name) scr_LogPrint("Name: %s", name); | |
535 scr_LogPrint("Type: %s", | |
536 ((type == ROSTER_TYPE_GROUP) ? "group" : "unknown")); | |
537 } | |
538 | |
539 g_free(buffer); | |
540 } | |
541 | |
208 | 542 void do_rename(char *arg) |
543 { | |
544 gpointer bud; | |
545 const char *jid, *group; | |
546 guint type; | |
547 char *newname, *p; | |
548 | |
549 if (!arg || (*arg == 0)) { | |
550 scr_LogPrint("Missing parameter"); | |
551 return; | |
552 } | |
553 | |
554 if (!current_buddy) return; | |
555 bud = BUDDATA(current_buddy); | |
556 | |
557 jid = buddy_getjid(bud); | |
558 group = buddy_getgroupname(bud); | |
559 type = buddy_gettype(bud); | |
560 | |
561 if (type & ROSTER_TYPE_GROUP) { | |
562 scr_LogPrint("You can't rename groups"); | |
563 return; | |
564 } | |
565 | |
566 newname = g_strdup(arg); | |
567 // Remove trailing space | |
568 for (p = newname; *p; p++) ; | |
569 while (p > newname && *p == ' ') *p = 0; | |
570 | |
571 buddy_setname(bud, newname); | |
572 jb_updatebuddy(jid, newname, group); | |
573 | |
574 g_free(newname); | |
575 update_roster = TRUE; | |
576 } | |
577 | |
210 | 578 void do_move(char *arg) |
579 { | |
580 gpointer bud; | |
581 const char *jid, *name; | |
582 guint type; | |
583 char *newgroupname, *p; | |
584 | |
585 if (!current_buddy) return; | |
586 bud = BUDDATA(current_buddy); | |
587 | |
588 jid = buddy_getjid(bud); | |
589 name = buddy_getname(bud); | |
590 type = buddy_gettype(bud); | |
591 | |
592 if (type & ROSTER_TYPE_GROUP) { | |
593 scr_LogPrint("You can't move groups!"); | |
594 return; | |
595 } | |
596 | |
597 newgroupname = g_strdup(arg); | |
598 // Remove trailing space | |
599 for (p = newgroupname; *p; p++) ; | |
600 while (p > newgroupname && *p == ' ') *p = 0; | |
601 | |
602 // Call to buddy_setgroup() should be at the end, as current implementation | |
603 // clones the buddy and deletes the old one (and thus, jid and name are | |
604 // freed) | |
605 jb_updatebuddy(jid, name, newgroupname); | |
606 buddy_setgroup(bud, newgroupname); | |
607 | |
608 g_free(newgroupname); | |
609 update_roster = TRUE; | |
610 } | |
611 |