changeset 225:d5ae42cbe1fa

[/trunk] Changeset 237 by mikael * Group names and JIDs completion
author mikael
date Sat, 04 Jun 2005 19:35:30 +0000
parents 3795729cee54
children bebefc0aa5a9
files mcabber/src/TODO mcabber/src/commands.c mcabber/src/compl.c mcabber/src/compl.h mcabber/src/roster.c mcabber/src/roster.h
diffstat 6 files changed, 51 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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);
--- 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 <string.h>
 
 #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;
 }
 
--- 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 <glib.h>
 
-#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);
--- 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;
+}
+
--- 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__ */