# HG changeset patch # User mikael # Date 1114114955 0 # Node ID fe7257d251acd849daa9321d4e5cc194974ac30e # Parent 93dcc4e15d4ac75cedfa6d7163946521b04c8b44 [/trunk] Changeset 118 by mikael * Commands are ready. Callback system in place. * Implement /roster callback :) * Completion is case-insensitive (good idea??) diff -r 93dcc4e15d4a -r fe7257d251ac mcabber/src/commands.c --- a/mcabber/src/commands.c Thu Apr 21 19:38:23 2005 +0000 +++ b/mcabber/src/commands.c Thu Apr 21 20:22:35 2005 +0000 @@ -29,13 +29,17 @@ #include "utf8.h" #include "utils.h" +// Commands callbacks +void do_roster(char *arg); +// Global variable for the commands list static GSList *Commands; + // cmd_add() // Adds a command to the commands list and to the CMD completion list void cmd_add(const char *name, const char *help, - guint flags_row1, guint flags_row2, void *(*f)()) + guint flags_row1, guint flags_row2, void (*f)()) { cmd *n_cmd = g_new0(cmd, 1); strncpy(n_cmd->name, name, 32-1); @@ -62,7 +66,7 @@ cmd_add("quit", "Exit the software", 0, 0, NULL); //cmd_add("rename"); //cmd_add("request_auth"); - cmd_add("roster", "Manipulate the roster/buddylist", COMPL_ROSTER, 0, NULL); + cmd_add("roster", "Manipulate the roster/buddylist", COMPL_ROSTER, 0, &do_roster); cmd_add("say", "Say something to the selected buddy", 0, 0, NULL); //cmd_add("search"); //cmd_add("send_auth"); @@ -149,6 +153,8 @@ int process_line(char *line) { char *p; + cmd *curcmd; + if (*line != '/') { send_message(line); // FIXME: are we talking to a _buddy_? return 0; @@ -165,11 +171,49 @@ if (!strcasecmp(line, "/quit")) { return 255; } + // Commands handling - // TODO - // say, send_raw... + curcmd = cmd_get(line); - scr_LogPrint("Unrecognised command, sorry."); + if (!curcmd) { + scr_LogPrint("Unrecognized command, sorry."); + return 0; + } + if (!curcmd->func) { + scr_LogPrint("Not yet implemented, sorry."); + return 0; + } + // Lets go to the command parameters + for (line++; *line && (*line != ' ') ; line++) + ; + // Skip spaces + while (*line && (*line == ' ')) + line++; + // Call command-specific function + (*curcmd->func)(line); return 0; } +/* Commands callback functions */ + +void do_roster(char *arg) +{ + if (!strcasecmp(arg, "top")) { + scr_RosterTop(); + scr_DrawRoster(); + } else if (!strcasecmp(arg, "bottom")) { + scr_RosterBottom(); + scr_DrawRoster(); + } else if (!strcasecmp(arg, "hide_offline")) { + buddylist_hide_offline_buddies(TRUE); + if (current_buddy) + buddylist_build(); + scr_DrawRoster(); + } else if (!strcasecmp(arg, "show_offline")) { + buddylist_hide_offline_buddies(FALSE); + if (current_buddy) + buddylist_build(); + scr_DrawRoster(); + } else + scr_LogPrint("Unrecognized parameter!"); +} diff -r 93dcc4e15d4a -r fe7257d251ac mcabber/src/commands.h --- a/mcabber/src/commands.h Thu Apr 21 19:38:23 2005 +0000 +++ b/mcabber/src/commands.h Thu Apr 21 20:22:35 2005 +0000 @@ -8,7 +8,7 @@ char name[32]; const char *help; guint completion_flags[2]; - void *(*func)(); + void (*func)(); } cmd; void cmd_init(void); diff -r 93dcc4e15d4a -r fe7257d251ac mcabber/src/compl.c --- a/mcabber/src/compl.c Thu Apr 21 19:38:23 2005 +0000 +++ b/mcabber/src/compl.c Thu Apr 21 20:22:35 2005 +0000 @@ -78,7 +78,7 @@ // Build the list of matches for (sl_cat=compl_cat; sl_cat; sl_cat = g_slist_next(sl_cat)) { char *word = sl_cat->data; - if (!strncmp(prefix, word, len)) { + if (!strncasecmp(prefix, word, len)) { if (strlen(word) != len) c->list = g_slist_append(c->list, g_strdup(word+len)); // TODO sort } diff -r 93dcc4e15d4a -r fe7257d251ac mcabber/src/screen.c --- a/mcabber/src/screen.c Thu Apr 21 19:38:23 2005 +0000 +++ b/mcabber/src/screen.c Thu Apr 21 20:22:35 2005 +0000 @@ -535,6 +535,22 @@ return inputWnd; } +void scr_RosterTop() +{ + current_buddy = buddylist; + // XXX We should rebuild the buddylist but perhaps not everytime? + if (chatmode) + scr_ShowBuddyWindow(); +} + +void scr_RosterBottom() +{ + current_buddy = g_list_last(buddylist); + // XXX We should rebuild the buddylist but perhaps not everytime? + if (chatmode) + scr_ShowBuddyWindow(); +} + void scr_RosterUp() { if (current_buddy) { @@ -544,6 +560,9 @@ } } // XXX We should rebuild the buddylist but perhaps not everytime? + + if (chatmode) + scr_ShowBuddyWindow(); } void scr_RosterDown() @@ -555,6 +574,9 @@ } } // XXX We should rebuild the buddylist but perhaps not everytime? + + if (chatmode) + scr_ShowBuddyWindow(); } // scr_LogPrint(...) @@ -787,13 +809,9 @@ break; case KEY_UP: scr_RosterUp(); - if (chatmode) - scr_ShowBuddyWindow(); break; case KEY_DOWN: scr_RosterDown(); - if (chatmode) - scr_ShowBuddyWindow(); break; case KEY_PPAGE: scr_LogPrint("PageUp??"); diff -r 93dcc4e15d4a -r fe7257d251ac mcabber/src/screen.h --- a/mcabber/src/screen.h Thu Apr 21 19:38:23 2005 +0000 +++ b/mcabber/src/screen.h Thu Apr 21 20:22:35 2005 +0000 @@ -33,4 +33,8 @@ int process_key(int); +// For commands... +void scr_RosterTop(); +void scr_RosterBottom(); + #endif