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