comparison src/list.c @ 4770:c4c28874ecd3

[gaim-migrate @ 5088] I want to go to sleep. This is drag-n-drop moving of buddies in the list. I think it works, but I didn't actually test it... I really should have though; I can't imagine it working fine as-is. ;) I'm holding off on the rest of my Edit Buddy List stuff for tomorrow... I love last minute things, don't I? Note: I created gaim_blist_members and gaim_blist_groups to reproduce the effects of the old groups GSList and the members GSList of the group struct that I removed. This is really sub-optimal and should be replaced to iterate the Buddy List directly. If someone wants to do that, please do. Even if you don't want to do that, just review the changes I made and make sure I didn't do anything stupid. It is past 6am and I'm a bit tired and prone to mistake making. Thanks. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Fri, 14 Mar 2003 11:38:21 +0000
parents c4ebe1a8484b
children b6f33ba0a0c0
comparison
equal deleted inserted replaced
4769:e0afac5f85bd 4770:c4c28874ecd3
81 group = group->next; 81 group = group->next;
82 } 82 }
83 } 83 }
84 84
85 /***************************************************************************** 85 /*****************************************************************************
86 * Public Utility Functions *
87 *****************************************************************************/
88
89 GSList *gaim_blist_members(struct group *g)
90 {
91 GaimBlistNode *group = (GaimBlistNode*)g;
92 GSList *list = NULL;
93 GaimBlistNode *child = group->child;
94 while (child) {
95 list = g_slist_append(list, child);
96 child = child->next;
97 }
98 return list;
99 }
100
101 GSList *gaim_blist_groups()
102 {
103 struct gaim_buddy_list *gaimbuddylist = gaim_get_blist();
104 GSList *list = NULL;
105 GaimBlistNode *g = gaimbuddylist->root;
106 while (g) {
107 list = g_slist_append(list, g);
108 g = g->next;
109 }
110 return list;
111 }
112
113 /*****************************************************************************
86 * Public API functions * 114 * Public API functions *
87 *****************************************************************************/ 115 *****************************************************************************/
88 116
89 struct gaim_buddy_list *gaim_blist_new() 117 struct gaim_buddy_list *gaim_blist_new()
90 { 118 {
215 void gaim_blist_add_buddy (struct buddy *buddy, struct group *group, GaimBlistNode *node) 243 void gaim_blist_add_buddy (struct buddy *buddy, struct group *group, GaimBlistNode *node)
216 { 244 {
217 GaimBlistNode *n = node, *node2, *node3; 245 GaimBlistNode *n = node, *node2, *node3;
218 struct group *g = group; 246 struct group *g = group;
219 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; 247 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops;
248 gboolean save = FALSE;
220 if (!n) { 249 if (!n) {
221 if (!g) { 250 if (!g) {
222 g = gaim_group_new(_("Buddies")); 251 g = gaim_group_new(_("Buddies"));
223 gaim_blist_add_group(g, NULL); 252 gaim_blist_add_group(g, NULL);
224 } 253 }
225 n = gaim_blist_get_last_child((GaimBlistNode*)g); 254 n = gaim_blist_get_last_child((GaimBlistNode*)g);
226 } 255 }
227 256
228 node2 = ((GaimBlistNode*)buddy)->next; 257 if (((GaimBlistNode*)buddy)->parent) {
229 node3 = ((GaimBlistNode*)buddy)->prev; 258 /* This buddy was already in the list and is
230 259 * being moved.
231 if (node2) 260 */
232 node2->prev = node3; 261 ops->remove(gaimbuddylist, (GaimBlistNode*)buddy);
233 if (node3) 262 node2 = ((GaimBlistNode*)buddy)->next;
234 node3->next = node2; 263 node3 = ((GaimBlistNode*)buddy)->prev;
264
265 if (node2)
266 node2->prev = node3;
267 if (node3)
268 node3->next = node2;
269
270 if (((GaimBlistNode*)buddy)->parent != n->parent)
271 serv_move_buddy(buddy, (struct group*)((GaimBlistNode*)buddy)->parent,
272 (struct group*)n->parent);
273 save = TRUE;
274 }
235 275
236 if (n) { 276 if (n) {
237 ((GaimBlistNode*)buddy)->next = n->next; 277 ((GaimBlistNode*)buddy)->next = n->next;
238 ((GaimBlistNode*)buddy)->prev = n; 278 ((GaimBlistNode*)buddy)->prev = n;
239 ((GaimBlistNode*)buddy)->parent = n->parent; 279 ((GaimBlistNode*)buddy)->parent = n->parent;
243 ((GaimBlistNode*)buddy)->next = NULL; 283 ((GaimBlistNode*)buddy)->next = NULL;
244 ((GaimBlistNode*)buddy)->prev = NULL; 284 ((GaimBlistNode*)buddy)->prev = NULL;
245 ((GaimBlistNode*)buddy)->parent = (GaimBlistNode*)g; 285 ((GaimBlistNode*)buddy)->parent = (GaimBlistNode*)g;
246 } 286 }
247 287
248 g->members = g_slist_append(g->members, buddy);
249
250 if (ops) 288 if (ops)
251 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); 289 ops->update(gaimbuddylist, (GaimBlistNode*)buddy);
290 if (save)
291 gaim_blist_save();
252 } 292 }
253 293
254 struct group *gaim_group_new(const char *name) 294 struct group *gaim_group_new(const char *name)
255 { 295 {
256 struct group *g = gaim_find_group(name); 296 struct group *g = gaim_find_group(name);
311 gnode->child = node->next; 351 gnode->child = node->next;
312 if (node->prev) 352 if (node->prev)
313 node->prev->next = node->next; 353 node->prev->next = node->next;
314 if (node->next) 354 if (node->next)
315 node->next->prev = node->prev; 355 node->next->prev = node->prev;
316
317 group->members = g_slist_remove(group->members, buddy);
318 356
319 ops->remove(gaimbuddylist, node); 357 ops->remove(gaimbuddylist, node);
320 g_free(buddy->name); 358 g_free(buddy->name);
321 g_free(buddy->alias); 359 g_free(buddy->alias);
322 g_free(buddy); 360 g_free(buddy);
779 g_string_free(buf, TRUE); 817 g_string_free(buf, TRUE);
780 } 818 }
781 } 819 }
782 820
783 gboolean gaim_group_on_account(struct group *g, struct gaim_account *account) { 821 gboolean gaim_group_on_account(struct group *g, struct gaim_account *account) {
784 GSList *buds = g->members; 822 GSList *buds = gaim_blist_members(g);
785 while(buds) { 823 GSList *buds1 = buds;
824 while(buds1) {
786 struct buddy *b = buds->data; 825 struct buddy *b = buds->data;
787 if((!account && b->account->gc) || b->account == account) 826 if((!account && b->account->gc) || b->account == account)
788 return TRUE; 827 return TRUE;
789 buds = buds->next; 828 buds1 = buds1->next;
790 } 829 }
830 g_slist_free(buds);
791 return FALSE; 831 return FALSE;
792 } 832 }
793 833
794 static gboolean blist_safe_to_write = FALSE; 834 static gboolean blist_safe_to_write = FALSE;
795 835
1119 fprintf(file, "\t<blist>\n"); 1159 fprintf(file, "\t<blist>\n");
1120 1160
1121 for(group = (struct group*)gaimbuddylist->root; group; group = (struct group*)((GaimBlistNode*)group)->next) { 1161 for(group = (struct group*)gaimbuddylist->root; group; group = (struct group*)((GaimBlistNode*)group)->next) {
1122 if(!exp_acct || gaim_group_on_account(group, exp_acct)) { 1162 if(!exp_acct || gaim_group_on_account(group, exp_acct)) {
1123 char *group_name = g_markup_escape_text(group->name, -1); 1163 char *group_name = g_markup_escape_text(group->name, -1);
1164 GSList *buds1;
1124 fprintf(file, "\t\t<group name=\"%s\">\n", group_name); 1165 fprintf(file, "\t\t<group name=\"%s\">\n", group_name);
1125 for(buds = group->members; buds; buds = buds->next) { 1166 buds = gaim_blist_members(group);
1126 bud = buds->data; 1167 for(buds1 = buds; buds1; buds1 = buds1->next) {
1168 bud = buds1->data;
1127 if(!exp_acct || bud->account == exp_acct) { 1169 if(!exp_acct || bud->account == exp_acct) {
1128 char *bud_name = g_markup_escape_text(bud->name, -1); 1170 char *bud_name = g_markup_escape_text(bud->name, -1);
1129 char *bud_alias = NULL; 1171 char *bud_alias = NULL;
1130 char *acct_name = g_markup_escape_text(bud->account->username, -1); 1172 char *acct_name = g_markup_escape_text(bud->account->username, -1);
1131 if(bud->alias) 1173 if(bud->alias)
1147 g_free(bud_name); 1189 g_free(bud_name);
1148 g_free(bud_alias); 1190 g_free(bud_alias);
1149 g_free(acct_name); 1191 g_free(acct_name);
1150 } 1192 }
1151 } 1193 }
1194 g_slist_free(buds);
1152 fprintf(file, "\t\t</group>\n"); 1195 fprintf(file, "\t\t</group>\n");
1153 g_free(group_name); 1196 g_free(group_name);
1154 } 1197 }
1155 } 1198 }
1156 1199
1187 char *user_dir = gaim_user_dir(); 1230 char *user_dir = gaim_user_dir();
1188 char *filename; 1231 char *filename;
1189 1232
1190 if(!user_dir) 1233 if(!user_dir)
1191 return; 1234 return;
1192
1193 if(!blist_safe_to_write) { 1235 if(!blist_safe_to_write) {
1194 debug_printf("AHH!! tried to write the blist before we read it!\n"); 1236 debug_printf("AHH!! tried to write the blist before we read it!\n");
1195 return; 1237 return;
1196 } 1238 }
1197 1239