Mercurial > hg
comparison mcabber/src/roster.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 | 353a4f8a3f61 |
children | 465d98d2f8e3 |
comparison
equal
deleted
inserted
replaced
209:353a4f8a3f61 | 210:f64818ba3503 |
---|---|
178 roster_usr = (roster*)sl_user->data; | 178 roster_usr = (roster*)sl_user->data; |
179 if (roster_usr->jid) | 179 if (roster_usr->jid) |
180 g_free((gchar*)roster_usr->jid); | 180 g_free((gchar*)roster_usr->jid); |
181 if (roster_usr->name) | 181 if (roster_usr->name) |
182 g_free((gchar*)roster_usr->name); | 182 g_free((gchar*)roster_usr->name); |
183 g_free(roster_usr); | |
183 | 184 |
184 // That's a little complex, we need to dereference twice | 185 // That's a little complex, we need to dereference twice |
185 sl_group = ((roster*)sl_user->data)->list; | 186 sl_group = ((roster*)sl_user->data)->list; |
186 sl_group_listptr = &((roster*)(sl_group->data))->list; | 187 sl_group_listptr = &((roster*)(sl_group->data))->list; |
187 *sl_group_listptr = g_slist_delete_link(*sl_group_listptr, sl_user); | 188 *sl_group_listptr = g_slist_delete_link(*sl_group_listptr, sl_user); |
188 | 189 |
189 // We need to rebuild the list | 190 // We need to rebuild the list |
190 if (current_buddy) | 191 if (current_buddy) |
191 buddylist_build(); | 192 buddylist_build(); |
192 // TODO What we should do, too, is to check if the deleted node is | 193 // TODO What we could do, too, is to check if the deleted node is |
193 // current_buddy, in which case we could move current_buddy to the | 194 // current_buddy, in which case we could move current_buddy to the |
194 // previous (or next) node. | 195 // previous (or next) node. |
195 } | 196 } |
196 | 197 |
197 // Free all roster data. Call buddylist_build() to free the buddylist. | 198 // Free all roster data and call buddylist_build() to free the buddylist. |
198 void roster_free(void) | 199 void roster_free(void) |
199 { | 200 { |
200 GSList *sl_grp = groups; | 201 GSList *sl_grp = groups; |
201 | 202 |
202 // Walk through groups | 203 // Walk through groups |
473 { | 474 { |
474 roster *roster_usr = rosterdata; | 475 roster *roster_usr = rosterdata; |
475 return roster_usr->jid; | 476 return roster_usr->jid; |
476 } | 477 } |
477 | 478 |
479 // buddy_setgroup() | |
480 // Change the group of current buddy | |
481 // | |
482 // Warning! This function changes current_buddy! | |
483 // Warning! Old buddy is deleted, so you can't acces to its jid/name after | |
484 // calling this function. | |
485 void buddy_setgroup(gpointer rosterdata, char *newgroupname) | |
486 { | |
487 roster *roster_usr = rosterdata; | |
488 GSList **sl_group; | |
489 GSList *sl_clone; | |
490 roster *roster_clone; | |
491 | |
492 // A group has no group :) | |
493 if (roster_usr->type & ROSTER_TYPE_GROUP) return; | |
494 | |
495 // Remove the buddy from current group | |
496 sl_group = &((roster*)((GSList*)roster_usr->list)->data)->list; | |
497 *sl_group = g_slist_remove(*sl_group, rosterdata); | |
498 | |
499 // Add the buddy to its new group; actually we "clone" this buddy... | |
500 sl_clone = roster_add_user(roster_usr->jid, roster_usr->name, | |
501 newgroupname, roster_usr->type); | |
502 roster_clone = (roster*)sl_clone->data; | |
503 roster_clone->status = roster_usr->status; | |
504 roster_clone->flags = roster_usr->flags; | |
505 | |
506 // Free old buddy | |
507 if (roster_usr->jid) g_free((gchar*)roster_usr->jid); | |
508 if (roster_usr->name) g_free((gchar*)roster_usr->name); | |
509 g_free(roster_usr); | |
510 | |
511 buddylist_build(); | |
512 current_buddy = g_list_find(buddylist, roster_clone); | |
513 } | |
514 | |
478 void buddy_setname(gpointer rosterdata, char *newname) | 515 void buddy_setname(gpointer rosterdata, char *newname) |
479 { | 516 { |
480 roster *roster_usr = rosterdata; | 517 roster *roster_usr = rosterdata; |
481 GSList **sl_group; | 518 GSList **sl_group; |
482 | 519 |