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