changeset 208:8b08f34922c5

[/trunk] Changeset 220 by mikael * jabglue: add jb_updatebuddy() * commands: add /rename command * documentation: small changes and updates
author mikael
date Sat, 07 May 2005 20:09:15 +0000
parents 41fafa0ecfd8
children 353a4f8a3f61
files mcabber/doc/mcabber.1.txt mcabber/src/commands.c mcabber/src/jabglue.c mcabber/src/jabglue.h
diffstat 4 files changed, 73 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/doc/mcabber.1.txt	Sat May 07 20:04:29 2005 +0000
+++ b/mcabber/doc/mcabber.1.txt	Sat May 07 20:09:15 2005 +0000
@@ -15,7 +15,7 @@
 -----------
 `mcabber(1)` is a small Jabber console client. +
 For now it needs a configuration file to start, so please copy the sample
-mcabberrc file and update your connection options.
+mcabberrc file and adapt your connection settings.
 
 The `mcabber(1)` screen is divided into 4 regions.
 The 'roster', alias 'buddylist', is on the left.  The 'chat window', or chat
@@ -78,7 +78,7 @@
 
 /add jid::
         Add the 'jid' Jabber user to our roster, and send a notification
-        request to this buddy
+        request to this buddy.
 
 /buffer clear|top|bottom::
         The 'buffer' command manipulates the current buddy's buffer
@@ -103,10 +103,13 @@
         'toggle';; toggle the fold/unfold state of the current tree
 
 /info::
-        Display info on the selected entry (user, agent, group...)
+        Display info on the selected entry (user, agent, group...).
 
 /quit::
-        Disconnect and leave `mcabber(1)`
+        Disconnect and leave `mcabber(1)`.
+
+/rename nickname::
+        Rename current buddy to the given nickname.
 
 /roster hide_offline|show_offline|top|bottom::
         The 'roster' command manipulates the roster/buddylist.
--- a/mcabber/src/commands.c	Sat May 07 20:04:29 2005 +0000
+++ b/mcabber/src/commands.c	Sat May 07 20:09:15 2005 +0000
@@ -41,6 +41,7 @@
 void do_buffer(char *arg);
 void do_clear(char *arg);
 void do_info(char *arg);
+void do_rename(char *arg);
 
 // Global variable for the commands list
 static GSList *Commands;
@@ -77,7 +78,7 @@
   //cmd_add("move");
   //cmd_add("nick");
   cmd_add("quit", "Exit the software", 0, 0, NULL);
-  //cmd_add("rename");
+  cmd_add("rename", "Rename the current buddy", 0, 0, &do_rename);
   //cmd_add("request_auth");
   cmd_add("roster", "Manipulate the roster/buddylist", COMPL_ROSTER, 0,
           &do_roster);
@@ -423,3 +424,39 @@
   g_free(buffer);
 }
 
+void do_rename(char *arg)
+{
+  gpointer bud;
+  const char *jid, *group;
+  guint type;
+  char *newname, *p;
+
+  if (!arg || (*arg == 0)) {
+    scr_LogPrint("Missing parameter");
+    return;
+  }
+
+  if (!current_buddy) return;
+  bud = BUDDATA(current_buddy);
+
+  jid   = buddy_getjid(bud);
+  group = buddy_getgroupname(bud);
+  type  = buddy_gettype(bud);
+
+  if (type & ROSTER_TYPE_GROUP) {
+    scr_LogPrint("You can't rename groups");
+    return;
+  }
+
+  newname = g_strdup(arg);
+  // Remove trailing space
+  for (p = newname; *p; p++) ;
+  while (p > newname && *p == ' ') *p = 0;
+
+  buddy_setname(bud, newname);
+  jb_updatebuddy(jid, newname, group);
+
+  g_free(newname);
+  update_roster = TRUE;
+}
+
--- a/mcabber/src/jabglue.c	Sat May 07 20:04:29 2005 +0000
+++ b/mcabber/src/jabglue.c	Sat May 07 20:09:15 2005 +0000
@@ -301,7 +301,7 @@
   xmlnode x, y, z;
   char *cleanjid;
 
-  // XXX Check jid (but perhaps caller should do it)
+  if (!online) return;
 
   // We don't check if the jabber user already exists in the roster,
   // because it allows to re-ask for notification.
@@ -340,8 +340,6 @@
 
   if (!online) return;
 
-  // XXX Check jid (but perhaps caller should do it)
-
   cleanjid = jidtodisp(jid);
 
   // If the current buddy is an agent, unsubscribe from it
@@ -377,6 +375,32 @@
   update_roster = TRUE;
 }
 
+void jb_updatebuddy(const char *jid, const char *name, const char *group)
+{
+  xmlnode x, y;
+  char *cleanjid;
+
+  if (!online) return;
+
+  // XXX We should check name's and group's correctness
+
+  cleanjid = jidtodisp(jid);
+
+  x = jutil_iqnew(JPACKET__SET, NS_ROSTER);
+  y = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "item");
+  xmlnode_put_attrib(y, "jid", cleanjid);
+  xmlnode_put_attrib(y, "name", name);
+
+  if (group) {
+    y = xmlnode_insert_tag(y, "group");
+    xmlnode_insert_cdata(y, group, (unsigned) -1);
+  }
+
+  jab_send(jc, x);
+  xmlnode_free(x);
+  g_free(cleanjid);
+}
+
 void postlogin()
 {
   //int i;
--- a/mcabber/src/jabglue.h	Sat May 07 20:04:29 2005 +0000
+++ b/mcabber/src/jabglue.h	Sat May 07 20:09:15 2005 +0000
@@ -34,6 +34,7 @@
 void jb_main();
 void jb_addbuddy(const char *jid, const char *group);
 void jb_delbuddy(const char *jid);
+void jb_updatebuddy(const char *jid, const char *name, const char *group);
 inline enum imstatus jb_getstatus();
 void jb_setstatus(enum imstatus st, char *msg);
 void jb_send_msg(const char *, const char *);