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