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