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