# HG changeset patch # User mikael # Date 1117913730 0 # Node ID d5ae42cbe1fab2482d1fac43ce076119b87be43d # Parent 3795729cee5428e20e62ce64ad0ebd4807a57ab4 [/trunk] Changeset 237 by mikael * Group names and JIDs completion diff -r 3795729cee54 -r d5ae42cbe1fa mcabber/src/TODO --- a/mcabber/src/TODO Sat Jun 04 17:34:15 2005 +0000 +++ b/mcabber/src/TODO Sat Jun 04 19:35:30 2005 +0000 @@ -20,7 +20,6 @@ * Buddy buffer in full width (handy for cut'n paste!) (i.e. hide roster window) * Create .mcabber and .mcabber/histo dirs if needed. -* Add completion for group names * Search for a user * Get info about a user * Publish personal information diff -r 3795729cee54 -r d5ae42cbe1fa mcabber/src/commands.c --- a/mcabber/src/commands.c Sat Jun 04 17:34:15 2005 +0000 +++ b/mcabber/src/commands.c Sat Jun 04 19:35:30 2005 +0000 @@ -76,7 +76,8 @@ cmd_add("group", "Change group display settings", COMPL_GROUP, 0, &do_group); cmd_add("help", "Display some help", COMPL_CMD, 0, NULL); cmd_add("info", "Show basic infos on current buddy", 0, 0, &do_info); - cmd_add("move", "Move the current buddy to another group", 0, 0, &do_move); + cmd_add("move", "Move the current buddy to another group", COMPL_GROUPNAME, + 0, &do_move); //cmd_add("nick"); cmd_add("quit", "Exit the software", 0, 0, NULL); cmd_add("rename", "Rename the current buddy", 0, 0, &do_rename); diff -r 3795729cee54 -r d5ae42cbe1fa mcabber/src/compl.c --- a/mcabber/src/compl.c Sat Jun 04 17:34:15 2005 +0000 +++ b/mcabber/src/compl.c Sat Jun 04 19:35:30 2005 +0000 @@ -32,6 +32,7 @@ #include #include "compl.h" +#include "roster.h" // Completion structure typedef struct { @@ -50,20 +51,11 @@ static GSList *Categories; static compl *InputCompl; -// XXX Should not be there (?) -// jid_list(type) -// Returns a list of jid's. If type is COMPL_URLJID, urls are surrounded with -// '<' and '>'. -GSList *jid_list(guint type) // bool urlstyle? -{ -} - // new_completion(prefix, compl_cat) // . prefix = beginning of the word, typed by the user // . compl_cat = pointer to a completion category list (list of *char) // Returns a pointer to an allocated compl structure. This structure should // be freed by the caller when not used anymore. -//compl *new_completion(char *prefix, GSList *compl_cat) void new_completion(char *prefix, GSList *compl_cat) { compl *c; @@ -179,7 +171,14 @@ if (sl_cat) // Category was found, easy... return ((category*)sl_cat->data)->words; - // TODO handle dynamic SLists :) + // Handle dynamic SLists + if (cat_flags == COMPL_GROUPNAME) { + return compl_list(ROSTER_TYPE_GROUP); + } + if (cat_flags == COMPL_JID) { + return compl_list(ROSTER_TYPE_USER); + } + return NULL; } diff -r 3795729cee54 -r d5ae42cbe1fa mcabber/src/compl.h --- a/mcabber/src/compl.h Sat Jun 04 17:34:15 2005 +0000 +++ b/mcabber/src/compl.h Sat Jun 04 19:35:30 2005 +0000 @@ -3,15 +3,16 @@ #include -#define COMPL_CMD 1 -#define COMPL_JID 2 // Not implemented yet -#define COMPL_URLJID 4 // Not implemented yet -#define COMPL_NAME 8 // Not implemented yet -#define COMPL_STATUS 16 -#define COMPL_FILENAME 32 // Not implemented yet -#define COMPL_ROSTER 64 -#define COMPL_BUFFER 128 -#define COMPL_GROUP 256 +#define COMPL_CMD 1 +#define COMPL_JID 2 +#define COMPL_URLJID 4 // Not implemented yet +#define COMPL_NAME 8 // Not implemented yet +#define COMPL_STATUS 16 +#define COMPL_FILENAME 32 // Not implemented yet +#define COMPL_ROSTER 64 +#define COMPL_BUFFER 128 +#define COMPL_GROUP 256 +#define COMPL_GROUPNAME 512 void compl_add_category_word(guint, const char *command); GSList *compl_get_category_list(guint cat_flags); diff -r 3795729cee54 -r d5ae42cbe1fa mcabber/src/roster.c --- a/mcabber/src/roster.c Sat Jun 04 17:34:15 2005 +0000 +++ b/mcabber/src/roster.c Sat Jun 04 19:35:30 2005 +0000 @@ -617,3 +617,31 @@ return roster_usr->flags; } +// compl_list(type) +// Returns a list of jid's or groups. (For commands completion) +// type: ROSTER_TYPE_USER (jid's) or ROSTER_TYPE_GROUP (group names) +// The list should be freed by the caller after use. +GSList *compl_list(guint type) +{ + GSList *list = NULL; + GList *buddy = buddylist; + + for ( ; buddy ; buddy = g_list_next(buddy)) { + guint btype = buddy_gettype(BUDDATA(buddy)); + + if (type == ROSTER_TYPE_GROUP) { // (group names) + if (btype == ROSTER_TYPE_GROUP) { + const char *bname = buddy_getname(BUDDATA(buddy)); + if ((bname) && (*bname)) + list = g_slist_append(list, g_strdup(bname)); + } + } else { // ROSTER_TYPE_USER (jid) + const char *bjid = buddy_getjid(BUDDATA(buddy)); + if (bjid) + list = g_slist_append(list, g_strdup(bjid)); + } + } + + return list; +} + diff -r 3795729cee54 -r d5ae42cbe1fa mcabber/src/roster.h --- a/mcabber/src/roster.h Sat Jun 04 17:34:15 2005 +0000 +++ b/mcabber/src/roster.h Sat Jun 04 19:35:30 2005 +0000 @@ -61,4 +61,6 @@ void buddy_setflags(gpointer rosterdata, guint flags, guint value); guint buddy_getflags(gpointer rosterdata); +GSList *compl_list(guint type); + #endif /* __ROSTER_H__ */