comparison src/list.c @ 4785:1e28e7d802a1

[gaim-migrate @ 5105] fix a few things, get rid of a few stale functions, and get rid of the compatibility functions. wee! committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sat, 15 Mar 2003 03:23:30 +0000
parents b6f33ba0a0c0
children 677d3cb193a1
comparison
equal deleted inserted replaced
4784:b1365291f002 4785:1e28e7d802a1
63 if (!node) 63 if (!node)
64 return NULL; 64 return NULL;
65 return gaim_blist_get_last_sibling(node->child); 65 return gaim_blist_get_last_sibling(node->child);
66 } 66 }
67 67
68 static void gaim_blist_print()
69 {
70 GaimBlistNode *group = gaimbuddylist->root;
71 GaimBlistNode *buddy;
72 if (!gaimbuddylist)
73 return;
74 while (group) {
75 debug_printf("+-%s %p\n", ((struct group*)group)->name, group);
76 buddy = group->child;
77 while (buddy) {
78 debug_printf("|--- %d %s\t\t%d\n", ((struct buddy*)buddy)->present, ((struct buddy*)buddy)->name, ((struct buddy*)buddy)->idle);
79 buddy = buddy->next;
80 }
81 group = group->next;
82 }
83 }
84
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 /***************************************************************************** 68 /*****************************************************************************
114 * Public API functions * 69 * Public API functions *
115 *****************************************************************************/ 70 *****************************************************************************/
116 71
117 struct gaim_buddy_list *gaim_blist_new() 72 struct gaim_buddy_list *gaim_blist_new()
311 } 266 }
312 267
313 void gaim_blist_add_group (struct group *group, GaimBlistNode *node) 268 void gaim_blist_add_group (struct group *group, GaimBlistNode *node)
314 { 269 {
315 struct gaim_blist_ui_ops *ops; 270 struct gaim_blist_ui_ops *ops;
316 gboolean save; 271 gboolean save = FALSE;
317 272
318 if (!gaimbuddylist) 273 if (!gaimbuddylist)
319 gaimbuddylist = gaim_blist_new(); 274 gaimbuddylist = gaim_blist_new();
320 ops = gaimbuddylist->ui_ops; 275 ops = gaimbuddylist->ui_ops;
321 276
322 if (!gaimbuddylist->root) { 277 if (!gaimbuddylist->root) {
323 gaimbuddylist->root = (GaimBlistNode*)group; 278 gaimbuddylist->root = (GaimBlistNode*)group;
324 return; 279 return;
325 } 280 }
326 281
327 282
328 if (!node) 283 if (!node)
329 node = gaim_blist_get_last_sibling(gaimbuddylist->root); 284 node = gaim_blist_get_last_sibling(gaimbuddylist->root);
330 285
331 if (gaim_find_group(group->name)) { 286 if (gaim_find_group(group->name)) {
332 /* This is just being moved */ 287 /* This is just being moved */
333 GaimBlistNode *node2 = ((GaimBlistNode*)group)->next; 288 GaimBlistNode *node2 = ((GaimBlistNode*)group)->next;
334 GaimBlistNode *node3 = ((GaimBlistNode*)group)->prev; 289 GaimBlistNode *node3 = ((GaimBlistNode*)group)->prev;
335 290
339 node2->prev = node3; 294 node2->prev = node3;
340 if (node3) 295 if (node3)
341 node3->next = node2; 296 node3->next = node2;
342 save = TRUE; 297 save = TRUE;
343 } 298 }
344 299
345 ((GaimBlistNode*)group)->next = node ? node->next : NULL; 300 ((GaimBlistNode*)group)->next = node ? node->next : NULL;
346 ((GaimBlistNode*)group)->prev = node; 301 ((GaimBlistNode*)group)->prev = node;
347 node->next = (GaimBlistNode*)group; 302 node->next = (GaimBlistNode*)group;
348 303
349 if (ops) 304 if (ops)
350 ops->update(gaimbuddylist, (GaimBlistNode*)group); 305 ops->update(gaimbuddylist, (GaimBlistNode*)group);
351 if (save) 306 if (save)
352 gaim_blist_save(); 307 gaim_blist_save();
353 } 308 }
354 309
355 void gaim_blist_remove_buddy (struct buddy *buddy) 310 void gaim_blist_remove_buddy (struct buddy *buddy)
356 { 311 {
832 g_string_free(buf, TRUE); 787 g_string_free(buf, TRUE);
833 } 788 }
834 } 789 }
835 790
836 gboolean gaim_group_on_account(struct group *g, struct gaim_account *account) { 791 gboolean gaim_group_on_account(struct group *g, struct gaim_account *account) {
837 GSList *buds = gaim_blist_members(g); 792 GaimBlistNode *bnode;
838 GSList *buds1 = buds; 793 for(bnode = g->node.child; bnode; bnode = bnode->next) {
839 while(buds1) { 794 struct buddy *b = (struct buddy *)bnode;
840 struct buddy *b = buds->data; 795 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode))
796 continue;
841 if((!account && b->account->gc) || b->account == account) 797 if((!account && b->account->gc) || b->account == account)
842 return TRUE; 798 return TRUE;
843 buds1 = buds1->next; 799 }
844 }
845 g_slist_free(buds);
846 return FALSE; 800 return FALSE;
847 } 801 }
848 802
849 static gboolean blist_safe_to_write = FALSE; 803 static gboolean blist_safe_to_write = FALSE;
850 804
1165 g_free(data_val); 1119 g_free(data_val);
1166 } 1120 }
1167 1121
1168 static void gaim_blist_write(FILE *file, struct gaim_account *exp_acct) { 1122 static void gaim_blist_write(FILE *file, struct gaim_account *exp_acct) {
1169 GSList *accounts, *buds; 1123 GSList *accounts, *buds;
1124 GaimBlistNode *gnode,*bnode;
1170 struct group *group; 1125 struct group *group;
1171 struct buddy *bud; 1126 struct buddy *bud;
1172 fprintf(file, "<?xml version='1.0' encoding='UTF-8' ?>\n"); 1127 fprintf(file, "<?xml version='1.0' encoding='UTF-8' ?>\n");
1173 fprintf(file, "<gaim version=\"1\">\n"); 1128 fprintf(file, "<gaim version=\"1\">\n");
1174 fprintf(file, "\t<blist>\n"); 1129 fprintf(file, "\t<blist>\n");
1175 1130
1176 for(group = (struct group*)gaimbuddylist->root; group; group = (struct group*)((GaimBlistNode*)group)->next) { 1131 for(gnode = gaimbuddylist->root; gnode; gnode = gnode->next) {
1132 if(!GAIM_BLIST_NODE_IS_GROUP(gnode))
1133 continue;
1134 group = (struct group *)gnode;
1177 if(!exp_acct || gaim_group_on_account(group, exp_acct)) { 1135 if(!exp_acct || gaim_group_on_account(group, exp_acct)) {
1178 char *group_name = g_markup_escape_text(group->name, -1); 1136 char *group_name = g_markup_escape_text(group->name, -1);
1179 GSList *buds1;
1180 fprintf(file, "\t\t<group name=\"%s\">\n", group_name); 1137 fprintf(file, "\t\t<group name=\"%s\">\n", group_name);
1181 buds = gaim_blist_members(group); 1138 for(bnode = gnode->child; bnode; bnode = bnode->next) {
1182 for(buds1 = buds; buds1; buds1 = buds1->next) { 1139 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode))
1183 bud = buds1->data; 1140 continue;
1141 bud = (struct buddy *)bnode;
1184 if(!exp_acct || bud->account == exp_acct) { 1142 if(!exp_acct || bud->account == exp_acct) {
1185 char *bud_name = g_markup_escape_text(bud->name, -1); 1143 char *bud_name = g_markup_escape_text(bud->name, -1);
1186 char *bud_alias = NULL; 1144 char *bud_alias = NULL;
1187 char *acct_name = g_markup_escape_text(bud->account->username, -1); 1145 char *acct_name = g_markup_escape_text(bud->account->username, -1);
1188 if(bud->alias) 1146 if(bud->alias)
1204 g_free(bud_name); 1162 g_free(bud_name);
1205 g_free(bud_alias); 1163 g_free(bud_alias);
1206 g_free(acct_name); 1164 g_free(acct_name);
1207 } 1165 }
1208 } 1166 }
1209 g_slist_free(buds);
1210 fprintf(file, "\t\t</group>\n"); 1167 fprintf(file, "\t\t</group>\n");
1211 g_free(group_name); 1168 g_free(group_name);
1212 } 1169 }
1213 } 1170 }
1214 1171