Mercurial > hg
annotate mcabber/src/commands.c @ 374:bd5638c21834
Improve logging system (traces)
There are now two trace logging levels:
* tracelog_level = 1:
Most messages from the log window are written to disk (LPRINT_LOG)
* tracelog_level =2:
LPRINT_LOG & LPRINT_DEBUG messages are written to disk
The trace file name is set with the "tracelog_file" option.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Mon, 25 Jul 2005 21:46:35 +0100 |
parents | bc54af8ed048 |
children | 00809e3e327e |
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) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
218 scr_LogPrint(LPRINT_NORMAL, "No buddy currently selected."); |
81 | 219 return; |
220 } | |
221 | |
222 jid = CURRENT_JID; | |
223 if (!jid) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
224 scr_LogPrint(LPRINT_NORMAL, "No buddy currently selected."); |
81 | 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) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
272 scr_LogPrint(LPRINT_NORMAL, "Unrecognized command, sorry."); |
285 | 273 if (xpline != line) g_free(xpline); |
104 | 274 return 0; |
275 } | |
276 if (!curcmd->func) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
277 scr_LogPrint(LPRINT_NORMAL, "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 != ' ')) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
358 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
265 | 359 return; |
360 } | |
361 while (*string == ' ') | |
362 string++; | |
363 if (!*string) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
364 scr_LogPrint(LPRINT_NORMAL, "What name or jid are you looking for?"); |
265 | 365 return; |
366 } | |
367 scr_RosterSearch(string); | |
368 update_roster = TRUE; | |
104 | 369 } else |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
370 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
104 | 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)) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
380 scr_LogPrint(LPRINT_NORMAL, "Your status is: %c", |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
381 imstatus2char[jb_getstatus()]); |
116 | 382 return; |
383 } | |
384 | |
318
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
385 msg = strchr(arg, ' '); |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
386 if (!msg) |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
387 len = strlen(arg); |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
388 else |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
389 len = msg - arg; |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
390 |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
391 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
|
392 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
|
393 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
|
394 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
|
395 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
|
396 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
|
397 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
|
398 else if (!strncasecmp(arg, "free", len)) st = freeforchat; |
116 | 399 else { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
400 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
116 | 401 return; |
402 } | |
403 | |
318
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
404 if (msg && st != offline && st != invisible) { |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
405 for (msg++ ; *msg && *msg == ' ' ; msg++) ; |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
406 if (!*msg) msg = NULL; |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
407 } else |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
408 msg = NULL; |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
409 |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
410 jb_setstatus(st, msg); |
116 | 411 } |
412 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
413 static void do_add(char *arg) |
124 | 414 { |
244 | 415 char *id, *nick; |
124 | 416 if (!arg || (*arg == 0)) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
417 scr_LogPrint(LPRINT_NORMAL, "Wrong usage"); |
124 | 418 return; |
419 } | |
420 | |
244 | 421 id = g_strdup(arg); |
422 nick = strchr(id, ' '); | |
423 if (nick) { | |
424 *nick++ = 0; | |
425 while (*nick && *nick == ' ') | |
426 nick++; | |
427 } | |
428 | |
429 // FIXME check id =~ jabber id | |
430 // 2nd parameter = optional nickname | |
431 jb_addbuddy(id, nick, NULL); | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
432 scr_LogPrint(LPRINT_LOGNORM, "Sent presence notfication request to <%s>", id); |
244 | 433 g_free(id); |
124 | 434 } |
128 | 435 |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
436 static void do_del(char *arg) |
206 | 437 { |
438 const char *jid; | |
439 | |
440 if (arg && (*arg)) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
441 scr_LogPrint(LPRINT_NORMAL, "Wrong usage"); |
206 | 442 return; |
443 } | |
444 | |
445 if (!current_buddy) return; | |
446 jid = buddy_getjid(BUDDATA(current_buddy)); | |
447 if (!jid) return; | |
448 | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
449 scr_LogPrint(LPRINT_LOGNORM, "Removing <%s>...", jid); |
206 | 450 jb_delbuddy(jid); |
451 } | |
452 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
453 static void do_group(char *arg) |
128 | 454 { |
455 gpointer group; | |
166 | 456 guint leave_windowbuddy; |
128 | 457 |
458 if (!arg || (*arg == 0)) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
459 scr_LogPrint(LPRINT_NORMAL, "Missing parameter"); |
128 | 460 return; |
461 } | |
462 | |
166 | 463 if (!current_buddy) return; |
128 | 464 |
166 | 465 group = buddy_getgroup(BUDDATA(current_buddy)); |
212 | 466 // We'll have to redraw the chat window if we're not currently on the group |
467 // entry itself, because it means we'll have to leave the current buddy | |
468 // chat window. | |
166 | 469 leave_windowbuddy = (group != BUDDATA(current_buddy)); |
470 | |
128 | 471 if (!(buddy_gettype(group) & ROSTER_TYPE_GROUP)) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
472 scr_LogPrint(LPRINT_NORMAL, "You need to select a group"); |
128 | 473 return; |
474 } | |
166 | 475 |
476 if (!strcasecmp(arg, "expand") || !strcasecmp(arg, "unfold")) { | |
128 | 477 buddy_setflags(group, ROSTER_FLAG_HIDE, FALSE); |
166 | 478 } else if (!strcasecmp(arg, "shrink") || !strcasecmp(arg, "fold")) { |
128 | 479 buddy_setflags(group, ROSTER_FLAG_HIDE, TRUE); |
130 | 480 } else if (!strcasecmp(arg, "toggle")) { |
481 buddy_setflags(group, ROSTER_FLAG_HIDE, | |
482 !(buddy_getflags(group) & ROSTER_FLAG_HIDE)); | |
128 | 483 } else { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
484 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
128 | 485 return; |
486 } | |
487 | |
488 buddylist_build(); | |
489 update_roster = TRUE; | |
166 | 490 if (leave_windowbuddy) scr_ShowBuddyWindow(); |
128 | 491 } |
492 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
493 static void do_say(char *arg) |
132 | 494 { |
164 | 495 gpointer bud; |
132 | 496 |
497 scr_set_chatmode(TRUE); | |
164 | 498 |
499 if (!current_buddy) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
500 scr_LogPrint(LPRINT_NORMAL, "Who are you talking to??"); |
164 | 501 return; |
132 | 502 } |
164 | 503 |
504 bud = BUDDATA(current_buddy); | |
505 if (!(buddy_gettype(bud) & ROSTER_TYPE_USER)) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
506 scr_LogPrint(LPRINT_NORMAL, "This is not a user"); |
164 | 507 return; |
508 } | |
509 | |
510 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE); | |
511 send_message(arg); | |
132 | 512 } |
513 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
514 static void do_msay(char *arg) |
238 | 515 { |
260
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
516 /* Parameters: begin verbatim abort send */ |
238 | 517 gpointer bud; |
518 | |
519 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
|
520 if (scr_get_multimode()) |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
521 scr_LogPrint(LPRINT_NORMAL, "Leaving multi-line message mode"); |
238 | 522 scr_set_multimode(FALSE); |
523 return; | |
260
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
524 } else if ((!strcasecmp(arg, "begin")) || (!strcasecmp(arg, "verbatim"))) { |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
525 if (!strcasecmp(arg, "verbatim")) |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
526 scr_set_multimode(2); |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
527 else |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
528 scr_set_multimode(1); |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
529 |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
530 scr_LogPrint(LPRINT_NORMAL, "Entered multi-line message mode."); |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
531 scr_LogPrint(LPRINT_NORMAL, "Select a buddy and use \"/msay send\" " |
238 | 532 "when your message is ready."); |
533 return; | |
534 } else if (*arg == 0) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
535 scr_LogPrint(LPRINT_NORMAL, "Please read the manual before using " |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
536 "the /msay command."); |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
537 scr_LogPrint(LPRINT_NORMAL, "(Use \"/msay begin\" to enter " |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
538 "multi-line mode...)"); |
238 | 539 return; |
540 } else if (strcasecmp(arg, "send")) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
541 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
238 | 542 return; |
543 } | |
544 | |
545 // send command | |
546 | |
547 if (!scr_get_multimode()) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
548 scr_LogPrint(LPRINT_NORMAL, "No message to send. " |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
549 "Use \"/msay begin\" first."); |
238 | 550 return; |
551 } | |
552 | |
553 scr_set_chatmode(TRUE); | |
554 | |
555 if (!current_buddy) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
556 scr_LogPrint(LPRINT_NORMAL, "Who are you talking to??"); |
238 | 557 return; |
558 } | |
559 | |
560 bud = BUDDATA(current_buddy); | |
561 if (!(buddy_gettype(bud) & ROSTER_TYPE_USER)) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
562 scr_LogPrint(LPRINT_NORMAL, "This is not a user"); |
238 | 563 return; |
564 } | |
565 | |
566 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE); | |
567 send_message(scr_get_multiline()); | |
568 scr_set_multimode(FALSE); | |
569 } | |
570 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
571 static void do_buffer(char *arg) |
187 | 572 { |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
573 int search_dir = 0; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
574 |
187 | 575 if (!strcasecmp(arg, "top")) { |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
336
diff
changeset
|
576 scr_BufferTopBottom(-1); |
187 | 577 } else if (!strcasecmp(arg, "bottom")) { |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
336
diff
changeset
|
578 scr_BufferTopBottom(1); |
187 | 579 } else if (!strcasecmp(arg, "clear")) { |
369
499170ed71c9
Rename some buffer commands, for homogeneity
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
580 scr_BufferClear(); |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
581 } else if (!strncasecmp(arg, "search_backward", 15)) { |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
582 arg += 15; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
583 if (*arg++ == ' ') |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
584 search_dir = -1; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
585 else |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
586 scr_LogPrint(LPRINT_NORMAL, "Missing parameter"); |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
587 } else if (!strncasecmp(arg, "search_forward", 14)) { |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
588 arg += 14; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
589 if (*arg++ == ' ') |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
590 search_dir = 1; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
591 else |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
592 scr_LogPrint(LPRINT_NORMAL, "Missing parameter"); |
187 | 593 } else |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
594 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
595 |
371
bc54af8ed048
/buffer search_*: skip leading spaces (if any) in string parameter
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
596 if (search_dir) { // It is a string search command |
bc54af8ed048
/buffer search_*: skip leading spaces (if any) in string parameter
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
597 for ( ; *arg && *arg == ' ' ; arg++) |
bc54af8ed048
/buffer search_*: skip leading spaces (if any) in string parameter
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
598 ; |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
599 scr_BufferSearch(search_dir, arg); |
371
bc54af8ed048
/buffer search_*: skip leading spaces (if any) in string parameter
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
600 } |
187 | 601 } |
602 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
603 static void do_clear(char *arg) // Alias for "/buffer clear" |
187 | 604 { |
605 do_buffer("clear"); | |
606 } | |
607 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
608 static void do_info(char *arg) |
191 | 609 { |
610 gpointer bud; | |
221 | 611 const char *jid, *name, *st_msg; |
191 | 612 guint type; |
613 enum imstatus status; | |
614 char *buffer; | |
615 | |
616 if (!current_buddy) return; | |
617 bud = BUDDATA(current_buddy); | |
618 | |
619 jid = buddy_getjid(bud); | |
620 name = buddy_getname(bud); | |
621 type = buddy_gettype(bud); | |
622 status = buddy_getstatus(bud); | |
221 | 623 st_msg = buddy_getstatusmsg(bud); |
191 | 624 |
625 buffer = g_new(char, 128); | |
626 | |
627 if (jid) { | |
628 char *typestr = "unknown"; | |
629 | |
630 snprintf(buffer, 127, "jid: <%s>", jid); | |
631 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); | |
632 if (name) { | |
633 snprintf(buffer, 127, "Name: %s", name); | |
634 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); | |
635 } | |
221 | 636 if (st_msg) { |
637 snprintf(buffer, 127, "Status message: %s", st_msg); | |
638 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); | |
639 } | |
191 | 640 |
641 if (type == ROSTER_TYPE_USER) typestr = "user"; | |
642 else if (type == ROSTER_TYPE_AGENT) typestr = "agent"; | |
643 | |
644 snprintf(buffer, 127, "Type: %s", typestr); | |
645 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); | |
646 } else { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
647 if (name) scr_LogPrint(LPRINT_NORMAL, "Name: %s", name); |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
648 scr_LogPrint(LPRINT_NORMAL, "Type: %s", |
191 | 649 ((type == ROSTER_TYPE_GROUP) ? "group" : "unknown")); |
650 } | |
651 | |
652 g_free(buffer); | |
653 } | |
654 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
655 static void do_rename(char *arg) |
208 | 656 { |
657 gpointer bud; | |
658 const char *jid, *group; | |
659 guint type; | |
660 char *newname, *p; | |
661 | |
662 if (!arg || (*arg == 0)) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
663 scr_LogPrint(LPRINT_NORMAL, "Missing parameter"); |
208 | 664 return; |
665 } | |
666 | |
667 if (!current_buddy) return; | |
668 bud = BUDDATA(current_buddy); | |
669 | |
670 jid = buddy_getjid(bud); | |
671 group = buddy_getgroupname(bud); | |
672 type = buddy_gettype(bud); | |
673 | |
674 if (type & ROSTER_TYPE_GROUP) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
675 scr_LogPrint(LPRINT_NORMAL, "You can't rename groups"); |
208 | 676 return; |
677 } | |
678 | |
679 newname = g_strdup(arg); | |
680 // Remove trailing space | |
681 for (p = newname; *p; p++) ; | |
682 while (p > newname && *p == ' ') *p = 0; | |
683 | |
684 buddy_setname(bud, newname); | |
685 jb_updatebuddy(jid, newname, group); | |
686 | |
687 g_free(newname); | |
688 update_roster = TRUE; | |
689 } | |
690 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
691 static void do_move(char *arg) |
210 | 692 { |
693 gpointer bud; | |
694 const char *jid, *name; | |
695 guint type; | |
696 char *newgroupname, *p; | |
697 | |
698 if (!current_buddy) return; | |
699 bud = BUDDATA(current_buddy); | |
700 | |
701 jid = buddy_getjid(bud); | |
702 name = buddy_getname(bud); | |
703 type = buddy_gettype(bud); | |
704 | |
705 if (type & ROSTER_TYPE_GROUP) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
706 scr_LogPrint(LPRINT_NORMAL, "You can't move groups!"); |
210 | 707 return; |
708 } | |
709 | |
710 newgroupname = g_strdup(arg); | |
711 // Remove trailing space | |
712 for (p = newgroupname; *p; p++) ; | |
713 while (p > newgroupname && *p == ' ') *p = 0; | |
714 | |
715 // Call to buddy_setgroup() should be at the end, as current implementation | |
716 // clones the buddy and deletes the old one (and thus, jid and name are | |
717 // freed) | |
718 jb_updatebuddy(jid, name, newgroupname); | |
719 buddy_setgroup(bud, newgroupname); | |
720 | |
721 g_free(newgroupname); | |
722 update_roster = TRUE; | |
723 } | |
724 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
725 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
|
726 { |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
727 guint assign; |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
728 const gchar *option, *value; |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
729 |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
730 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
|
731 if (!option) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
732 scr_LogPrint(LPRINT_NORMAL, "Huh?"); |
283
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
733 return; |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
734 } |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
735 if (!assign) { |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
736 // This is a query |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
737 value = settings_opt_get(option); |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
738 if (value) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
739 scr_LogPrint(LPRINT_NORMAL, "%s = [%s]", option, value); |
283
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
740 } else |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
741 scr_LogPrint(LPRINT_NORMAL, "Option %s is not set", option); |
283
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
742 return; |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
743 } |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
744 // Update the option |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
745 // 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
|
746 // (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
|
747 // (hide_offline_buddies for ex.) |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
748 if (!value) { |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
749 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
|
750 } else { |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
751 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
|
752 } |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
753 } |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
754 |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
755 static void do_alias(char *arg) |
285 | 756 { |
757 guint assign; | |
758 const gchar *alias, *value; | |
759 | |
760 assign = parse_assigment(arg, &alias, &value); | |
761 if (!alias) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
762 scr_LogPrint(LPRINT_NORMAL, "Huh?"); |
285 | 763 return; |
764 } | |
765 if (!assign) { | |
766 // This is a query | |
767 value = settings_get(SETTINGS_TYPE_ALIAS, alias); | |
768 if (value) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
769 scr_LogPrint(LPRINT_NORMAL, "%s = %s", alias, value); |
285 | 770 } else |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
771 scr_LogPrint(LPRINT_NORMAL, "Alias '%s' does not exist", alias); |
285 | 772 return; |
773 } | |
774 // Check the alias does not conflict with a registered command | |
775 if (cmd_get(alias)) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
776 scr_LogPrint(LPRINT_NORMAL, "'%s' is a reserved word!", alias); |
285 | 777 return; |
778 } | |
779 // Update the alias | |
780 if (!value) { | |
781 if (settings_get(SETTINGS_TYPE_ALIAS, alias)) { | |
782 settings_del(SETTINGS_TYPE_ALIAS, alias); | |
783 // Remove alias from the completion list | |
784 compl_del_category_word(COMPL_CMD, alias); | |
785 } | |
786 } else { | |
787 // Add alias to the completion list, if not already in | |
788 if (!settings_get(SETTINGS_TYPE_ALIAS, alias)) | |
789 compl_add_category_word(COMPL_CMD, alias); | |
790 settings_set(SETTINGS_TYPE_ALIAS, alias, value); | |
791 } | |
792 } | |
793 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
794 static void do_bind(char *arg) |
288 | 795 { |
796 guint assign; | |
797 const gchar *keycode, *value; | |
798 | |
799 assign = parse_assigment(arg, &keycode, &value); | |
800 if (!keycode) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
801 scr_LogPrint(LPRINT_NORMAL, "Huh?"); |
288 | 802 return; |
803 } | |
804 if (!assign) { | |
805 // This is a query | |
806 value = settings_get(SETTINGS_TYPE_BINDING, keycode); | |
807 if (value) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
808 scr_LogPrint(LPRINT_NORMAL, "Key %s is bound to: %s", keycode, value); |
288 | 809 } else |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
810 scr_LogPrint(LPRINT_NORMAL, "Key %s is not bound", keycode); |
288 | 811 return; |
812 } | |
813 // Update the key binding | |
814 if (!value) | |
815 settings_del(SETTINGS_TYPE_BINDING, keycode); | |
816 else | |
817 settings_set(SETTINGS_TYPE_BINDING, keycode, value); | |
818 } | |
819 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
820 static void do_connect(char *arg) |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
290
diff
changeset
|
821 { |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
290
diff
changeset
|
822 mcabber_connect(); |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
290
diff
changeset
|
823 } |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
290
diff
changeset
|
824 |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
825 static void do_disconnect(char *arg) |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
290
diff
changeset
|
826 { |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
290
diff
changeset
|
827 jb_disconnect(); |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
290
diff
changeset
|
828 } |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
290
diff
changeset
|
829 |