Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/commands.c @ 104:fe7257d251ac
[/trunk] Changeset 118 by mikael
* Commands are ready. Callback system in place.
* Implement /roster callback :)
* Completion is case-insensitive (good idea??)
author | mikael |
---|---|
date | Thu, 21 Apr 2005 20:22:35 +0000 |
parents | 93dcc4e15d4a |
children | 7fb72bc13732 |
comparison
equal
deleted
inserted
replaced
103:93dcc4e15d4a | 104:fe7257d251ac |
---|---|
27 #include "screen.h" | 27 #include "screen.h" |
28 #include "compl.h" | 28 #include "compl.h" |
29 #include "utf8.h" | 29 #include "utf8.h" |
30 #include "utils.h" | 30 #include "utils.h" |
31 | 31 |
32 | 32 // Commands callbacks |
33 void do_roster(char *arg); | |
34 | |
35 // Global variable for the commands list | |
33 static GSList *Commands; | 36 static GSList *Commands; |
37 | |
34 | 38 |
35 // cmd_add() | 39 // cmd_add() |
36 // Adds a command to the commands list and to the CMD completion list | 40 // Adds a command to the commands list and to the CMD completion list |
37 void cmd_add(const char *name, const char *help, | 41 void cmd_add(const char *name, const char *help, |
38 guint flags_row1, guint flags_row2, void *(*f)()) | 42 guint flags_row1, guint flags_row2, void (*f)()) |
39 { | 43 { |
40 cmd *n_cmd = g_new0(cmd, 1); | 44 cmd *n_cmd = g_new0(cmd, 1); |
41 strncpy(n_cmd->name, name, 32-1); | 45 strncpy(n_cmd->name, name, 32-1); |
42 n_cmd->help = help; | 46 n_cmd->help = help; |
43 n_cmd->completion_flags[0] = flags_row1; | 47 n_cmd->completion_flags[0] = flags_row1; |
60 //cmd_add("move"); | 64 //cmd_add("move"); |
61 //cmd_add("nick"); | 65 //cmd_add("nick"); |
62 cmd_add("quit", "Exit the software", 0, 0, NULL); | 66 cmd_add("quit", "Exit the software", 0, 0, NULL); |
63 //cmd_add("rename"); | 67 //cmd_add("rename"); |
64 //cmd_add("request_auth"); | 68 //cmd_add("request_auth"); |
65 cmd_add("roster", "Manipulate the roster/buddylist", COMPL_ROSTER, 0, NULL); | 69 cmd_add("roster", "Manipulate the roster/buddylist", COMPL_ROSTER, 0, &do_roster); |
66 cmd_add("say", "Say something to the selected buddy", 0, 0, NULL); | 70 cmd_add("say", "Say something to the selected buddy", 0, 0, NULL); |
67 //cmd_add("search"); | 71 //cmd_add("search"); |
68 //cmd_add("send_auth"); | 72 //cmd_add("send_auth"); |
69 cmd_add("status", "Show or set your status", COMPL_STATUS, 0, NULL); | 73 cmd_add("status", "Show or set your status", COMPL_STATUS, 0, NULL); |
70 | 74 |
147 // If this isn't a command, this is a message and it is sent to the | 151 // If this isn't a command, this is a message and it is sent to the |
148 // currently selected buddy. | 152 // currently selected buddy. |
149 int process_line(char *line) | 153 int process_line(char *line) |
150 { | 154 { |
151 char *p; | 155 char *p; |
156 cmd *curcmd; | |
157 | |
152 if (*line != '/') { | 158 if (*line != '/') { |
153 send_message(line); // FIXME: are we talking to a _buddy_? | 159 send_message(line); // FIXME: are we talking to a _buddy_? |
154 return 0; | 160 return 0; |
155 } | 161 } |
156 | 162 |
163 | 169 |
164 // Command "quit"? | 170 // Command "quit"? |
165 if (!strcasecmp(line, "/quit")) { | 171 if (!strcasecmp(line, "/quit")) { |
166 return 255; | 172 return 255; |
167 } | 173 } |
174 | |
168 // Commands handling | 175 // Commands handling |
169 // TODO | 176 curcmd = cmd_get(line); |
170 // say, send_raw... | 177 |
171 | 178 if (!curcmd) { |
172 scr_LogPrint("Unrecognised command, sorry."); | 179 scr_LogPrint("Unrecognized command, sorry."); |
180 return 0; | |
181 } | |
182 if (!curcmd->func) { | |
183 scr_LogPrint("Not yet implemented, sorry."); | |
184 return 0; | |
185 } | |
186 // Lets go to the command parameters | |
187 for (line++; *line && (*line != ' ') ; line++) | |
188 ; | |
189 // Skip spaces | |
190 while (*line && (*line == ' ')) | |
191 line++; | |
192 // Call command-specific function | |
193 (*curcmd->func)(line); | |
173 return 0; | 194 return 0; |
174 } | 195 } |
175 | 196 |
197 /* Commands callback functions */ | |
198 | |
199 void do_roster(char *arg) | |
200 { | |
201 if (!strcasecmp(arg, "top")) { | |
202 scr_RosterTop(); | |
203 scr_DrawRoster(); | |
204 } else if (!strcasecmp(arg, "bottom")) { | |
205 scr_RosterBottom(); | |
206 scr_DrawRoster(); | |
207 } else if (!strcasecmp(arg, "hide_offline")) { | |
208 buddylist_hide_offline_buddies(TRUE); | |
209 if (current_buddy) | |
210 buddylist_build(); | |
211 scr_DrawRoster(); | |
212 } else if (!strcasecmp(arg, "show_offline")) { | |
213 buddylist_hide_offline_buddies(FALSE); | |
214 if (current_buddy) | |
215 buddylist_build(); | |
216 scr_DrawRoster(); | |
217 } else | |
218 scr_LogPrint("Unrecognized parameter!"); | |
219 } |