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