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