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