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