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