Mercurial > hg
diff mcabber/src/commands.c @ 210:f64818ba3503
[/trunk] Changeset 222 by mikael
* Add /move command
* roster: Add buddy_setgroup()
* roster.c: Fix a small memory leak
* Keep documentation up-to-date
author | mikael |
---|---|
date | Sun, 08 May 2005 07:02:11 +0000 |
parents | 8b08f34922c5 |
children | 465d98d2f8e3 |
line wrap: on
line diff
--- a/mcabber/src/commands.c Sat May 07 21:21:57 2005 +0000 +++ b/mcabber/src/commands.c Sun May 08 07:02:11 2005 +0000 @@ -42,6 +42,7 @@ void do_clear(char *arg); void do_info(char *arg); void do_rename(char *arg); +void do_move(char *arg); // Global variable for the commands list static GSList *Commands; @@ -75,7 +76,7 @@ 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"); + cmd_add("move", "Move the current buddy to another group", 0, 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); @@ -460,3 +461,37 @@ update_roster = TRUE; } +void do_move(char *arg) +{ + gpointer bud; + const char *jid, *name; + guint type; + char *newgroupname, *p; + + if (!current_buddy) return; + bud = BUDDATA(current_buddy); + + jid = buddy_getjid(bud); + name = buddy_getname(bud); + type = buddy_gettype(bud); + + if (type & ROSTER_TYPE_GROUP) { + scr_LogPrint("You can't move groups!"); + return; + } + + newgroupname = g_strdup(arg); + // Remove trailing space + for (p = newgroupname; *p; p++) ; + while (p > newgroupname && *p == ' ') *p = 0; + + // Call to buddy_setgroup() should be at the end, as current implementation + // clones the buddy and deletes the old one (and thus, jid and name are + // freed) + jb_updatebuddy(jid, name, newgroupname); + buddy_setgroup(bud, newgroupname); + + g_free(newgroupname); + update_roster = TRUE; +} +