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