Mercurial > pidgin
annotate src/blist.c @ 6843:549a0bbbf73d
[gaim-migrate @ 7388]
pre-compute the priority contact so we don't waste much effort looking it up
committer: Tailor Script <tailor@pidgin.im>
| author | Nathan Walp <nwalp@pidgin.im> |
|---|---|
| date | Sun, 14 Sep 2003 22:17:55 +0000 |
| parents | f76e26a0e6a9 |
| children | 8ab95f4c9800 |
| rev | line source |
|---|---|
| 5228 | 1 /* |
| 2 * gaim | |
| 3 * | |
| 4 * Copyright (C) 2003, Sean Egan <sean.egan@binghamton.edu> | |
| 5 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
| 6 * | |
| 7 * This program is free software; you can redistribute it and/or modify | |
| 8 * it under the terms of the GNU General Public License as published by | |
| 9 * the Free Software Foundation; either version 2 of the License, or | |
| 10 * (at your option) any later version. | |
| 11 * | |
| 12 * This program is distributed in the hope that it will be useful, | |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 * GNU General Public License for more details. | |
| 16 * | |
| 17 * You should have received a copy of the GNU General Public License | |
| 18 * along with this program; if not, write to the Free Software | |
| 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 20 * | |
| 21 */ | |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
22 #include "internal.h" |
| 5228 | 23 #include "blist.h" |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
24 #include "conversation.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
25 #include "debug.h" |
| 6034 | 26 #include "multi.h" |
|
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
27 #include "notify.h" |
|
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
28 #include "prefs.h" |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
29 #include "privacy.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
30 #include "prpl.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
31 #include "server.h" |
|
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
32 #include "signals.h" |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
33 #include "util.h" |
| 5228 | 34 |
| 35 #define PATHSIZE 1024 | |
| 36 | |
| 37 struct gaim_buddy_list *gaimbuddylist = NULL; | |
| 38 static struct gaim_blist_ui_ops *blist_ui_ops = NULL; | |
| 39 | |
| 40 /***************************************************************************** | |
| 41 * Private Utility functions * | |
| 42 *****************************************************************************/ | |
| 43 static GaimBlistNode *gaim_blist_get_last_sibling(GaimBlistNode *node) | |
| 44 { | |
| 45 GaimBlistNode *n = node; | |
| 46 if (!n) | |
| 47 return NULL; | |
| 48 while (n->next) | |
| 49 n = n->next; | |
| 50 return n; | |
| 51 } | |
| 6695 | 52 |
| 5228 | 53 static GaimBlistNode *gaim_blist_get_last_child(GaimBlistNode *node) |
| 54 { | |
| 55 if (!node) | |
| 56 return NULL; | |
| 57 return gaim_blist_get_last_sibling(node->child); | |
| 58 } | |
| 59 | |
| 5247 | 60 struct _gaim_hbuddy { |
| 61 char *name; | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
62 GaimAccount *account; |
| 5758 | 63 GaimBlistNode *group; |
| 5247 | 64 }; |
| 65 | |
| 66 static guint _gaim_blist_hbuddy_hash (struct _gaim_hbuddy *hb) | |
| 67 { | |
| 68 return g_str_hash(hb->name); | |
| 69 } | |
| 70 | |
| 71 static guint _gaim_blist_hbuddy_equal (struct _gaim_hbuddy *hb1, struct _gaim_hbuddy *hb2) | |
| 72 { | |
| 5758 | 73 return ((!strcmp(hb1->name, hb2->name)) && hb1->account == hb2->account && hb1->group == hb2->group); |
| 5247 | 74 } |
| 75 | |
| 6742 | 76 static void _gaim_blist_hbuddy_free_key(struct _gaim_hbuddy *hb) |
| 77 { | |
| 78 g_free(hb->name); | |
| 79 g_free(hb); | |
| 80 } | |
| 81 | |
| 6006 | 82 static void blist_pref_cb(const char *name, GaimPrefType typ, gpointer value, gpointer data) |
| 83 { | |
| 6012 | 84 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; |
| 6695 | 85 GaimBlistNode *gnode, *cnode, *bnode; |
| 6012 | 86 |
| 87 if (!ops) | |
| 88 return; | |
| 89 | |
| 6695 | 90 for(gnode = gaimbuddylist->root; gnode; gnode = gnode->next) { |
| 91 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
| 6012 | 92 continue; |
| 6695 | 93 for(cnode = gnode->child; cnode; cnode = cnode->next) { |
| 94 if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
| 95 for(bnode = cnode->child; bnode; bnode = bnode->next) { | |
| 96 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
| 97 continue; | |
| 98 ops->update(gaimbuddylist, bnode); | |
| 99 } | |
| 100 } else if(GAIM_BLIST_NODE_IS_CHAT(cnode)) { | |
| 101 ops->update(gaimbuddylist, cnode); | |
| 102 } | |
| 6012 | 103 } |
| 104 } | |
| 6006 | 105 } |
| 106 | |
| 6843 | 107 static GaimContact *gaim_buddy_get_contact(GaimBuddy *buddy) |
| 108 { | |
| 109 return (GaimContact*)((GaimBlistNode*)buddy)->parent; | |
| 110 } | |
| 111 | |
| 112 static void gaim_contact_compute_priority_buddy(GaimContact *contact) { | |
| 113 GaimBlistNode *bnode; | |
| 114 | |
| 115 for(bnode = ((GaimBlistNode*)contact)->child; bnode; bnode = bnode->next) { | |
| 116 GaimBuddy *buddy; | |
| 117 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
| 118 continue; | |
| 119 buddy = (GaimBuddy*)bnode; | |
| 120 if(!gaim_account_is_connected(buddy->account)) | |
| 121 continue; | |
| 122 | |
| 123 if(!contact->priority) { | |
| 124 contact->priority = buddy; | |
| 125 } else if(GAIM_BUDDY_IS_ONLINE(buddy)) { | |
| 126 if(!GAIM_BUDDY_IS_ONLINE(contact->priority)) { | |
| 127 contact->priority = buddy; | |
| 128 } else if(!(buddy->uc & UC_UNAVAILABLE) && !buddy->idle && | |
| 129 (contact->priority->uc & UC_UNAVAILABLE || | |
| 130 contact->priority->idle)) { | |
| 131 contact->priority = buddy; | |
| 132 } else if(!buddy->idle && contact->priority->idle) { | |
| 133 contact->priority = buddy; | |
| 134 } else if(contact->priority->uc & UC_UNAVAILABLE && | |
| 135 contact->priority->idle && (!(buddy->uc & UC_UNAVAILABLE) || | |
| 136 !buddy->idle)) { | |
| 137 contact->priority = buddy; | |
| 138 } | |
| 139 } | |
| 140 } | |
| 141 } | |
| 142 | |
| 143 | |
| 5228 | 144 /***************************************************************************** |
| 145 * Public API functions * | |
| 146 *****************************************************************************/ | |
| 147 | |
| 148 struct gaim_buddy_list *gaim_blist_new() | |
| 149 { | |
| 150 struct gaim_buddy_list *gbl = g_new0(struct gaim_buddy_list, 1); | |
| 151 | |
| 152 gbl->ui_ops = gaim_get_blist_ui_ops(); | |
| 153 | |
| 6742 | 154 gbl->buddies = g_hash_table_new_full((GHashFunc)_gaim_blist_hbuddy_hash, |
| 155 (GEqualFunc)_gaim_blist_hbuddy_equal, | |
| 156 (GDestroyNotify)_gaim_blist_hbuddy_free_key, NULL); | |
| 5247 | 157 |
| 5228 | 158 if (gbl->ui_ops != NULL && gbl->ui_ops->new_list != NULL) |
| 159 gbl->ui_ops->new_list(gbl); | |
| 160 | |
|
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
161 gaim_prefs_connect_callback("/core/buddies/use_server_alias", |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
162 blist_pref_cb, NULL); |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
163 |
| 6006 | 164 |
| 5228 | 165 return gbl; |
| 166 } | |
| 167 | |
| 168 void | |
| 169 gaim_set_blist(struct gaim_buddy_list *list) | |
| 170 { | |
| 171 gaimbuddylist = list; | |
| 172 } | |
| 173 | |
| 174 struct gaim_buddy_list * | |
| 175 gaim_get_blist(void) | |
| 176 { | |
| 177 return gaimbuddylist; | |
| 178 } | |
| 179 | |
| 6695 | 180 void gaim_blist_show () |
| 5228 | 181 { |
| 182 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 183 if (ops) | |
| 184 ops->show(gaimbuddylist); | |
| 185 } | |
| 186 | |
| 187 void gaim_blist_destroy() | |
| 188 { | |
| 189 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 190 if (ops) | |
| 191 ops->destroy(gaimbuddylist); | |
| 192 } | |
| 193 | |
| 194 void gaim_blist_set_visible (gboolean show) | |
| 195 { | |
| 196 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 197 if (ops) | |
| 198 ops->set_visible(gaimbuddylist, show); | |
| 199 } | |
| 200 | |
| 6695 | 201 void gaim_blist_update_buddy_status (GaimBuddy *buddy, int status) |
| 5228 | 202 { |
|
5266
b3a03b86b09b
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
203 struct gaim_blist_ui_ops *ops; |
|
b3a03b86b09b
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
204 |
|
b3a03b86b09b
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
205 if (buddy->uc == status) |
|
b3a03b86b09b
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
206 return; |
|
b3a03b86b09b
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
207 |
|
b3a03b86b09b
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
208 ops = gaimbuddylist->ui_ops; |
| 5228 | 209 |
| 5305 | 210 if((status & UC_UNAVAILABLE) != (buddy->uc & UC_UNAVAILABLE)) { |
| 211 if(status & UC_UNAVAILABLE) | |
|
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
212 gaim_signal_emit(gaim_blist_get_handle(), "buddy-away", buddy); |
| 5305 | 213 else |
|
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
214 gaim_signal_emit(gaim_blist_get_handle(), "buddy-back", buddy); |
| 5305 | 215 } |
| 5228 | 216 |
| 5305 | 217 buddy->uc = status; |
| 6843 | 218 gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy)); |
| 5228 | 219 if (ops) |
| 220 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 221 } | |
| 222 | |
| 6695 | 223 static gboolean presence_update_timeout_cb(GaimBuddy *buddy) { |
| 5228 | 224 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; |
|
6640
314111e7b601
[gaim-migrate @ 7165]
Christian Hammond <chipx86@chipx86.com>
parents:
6564
diff
changeset
|
225 GaimConversation *conv; |
|
314111e7b601
[gaim-migrate @ 7165]
Christian Hammond <chipx86@chipx86.com>
parents:
6564
diff
changeset
|
226 |
|
314111e7b601
[gaim-migrate @ 7165]
Christian Hammond <chipx86@chipx86.com>
parents:
6564
diff
changeset
|
227 conv = gaim_find_conversation_with_account(buddy->name, buddy->account); |
| 5228 | 228 |
| 229 if(buddy->present == GAIM_BUDDY_SIGNING_ON) { | |
| 230 buddy->present = GAIM_BUDDY_ONLINE; | |
| 231 } else if(buddy->present == GAIM_BUDDY_SIGNING_OFF) { | |
| 232 buddy->present = GAIM_BUDDY_OFFLINE; | |
| 233 } | |
| 234 | |
| 235 buddy->timer = 0; | |
| 6843 | 236 gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy)); |
| 5228 | 237 |
| 238 if (ops) | |
| 239 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 240 | |
|
6392
e9974608b319
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
241 if (conv) { |
|
e9974608b319
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
242 if (buddy->present == GAIM_BUDDY_ONLINE) |
|
e9974608b319
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
243 gaim_conversation_update(conv, GAIM_CONV_ACCOUNT_ONLINE); |
|
e9974608b319
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
244 else if (buddy->present == GAIM_BUDDY_OFFLINE) |
|
e9974608b319
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
245 gaim_conversation_update(conv, GAIM_CONV_ACCOUNT_OFFLINE); |
|
e9974608b319
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
246 } |
|
e9974608b319
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
247 |
| 5228 | 248 return FALSE; |
| 249 } | |
| 250 | |
| 6695 | 251 void gaim_blist_update_buddy_presence(GaimBuddy *buddy, int presence) { |
| 5228 | 252 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; |
| 253 gboolean do_timer = FALSE; | |
| 254 | |
| 255 if (!GAIM_BUDDY_IS_ONLINE(buddy) && presence) { | |
| 256 buddy->present = GAIM_BUDDY_SIGNING_ON; | |
|
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
257 gaim_signal_emit(gaim_blist_get_handle(), "buddy-signed-on", buddy); |
| 5228 | 258 do_timer = TRUE; |
| 6695 | 259 ((GaimContact*)((GaimBlistNode*)buddy)->parent)->online++; |
| 260 if(((GaimContact*)((GaimBlistNode*)buddy)->parent)->online == 1) | |
| 261 ((GaimGroup *)((GaimBlistNode *)buddy)->parent->parent)->online++; | |
| 5228 | 262 } else if(GAIM_BUDDY_IS_ONLINE(buddy) && !presence) { |
| 263 buddy->present = GAIM_BUDDY_SIGNING_OFF; | |
|
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
264 gaim_signal_emit(gaim_blist_get_handle(), "buddy-signed-off", buddy); |
| 5228 | 265 do_timer = TRUE; |
| 6695 | 266 ((GaimContact*)((GaimBlistNode*)buddy)->parent)->online--; |
| 267 if(((GaimContact*)((GaimBlistNode*)buddy)->parent)->online == 0) | |
| 268 ((GaimGroup *)((GaimBlistNode *)buddy)->parent->parent)->online--; | |
| 5228 | 269 } |
| 270 | |
| 271 if(do_timer) { | |
| 272 if(buddy->timer > 0) | |
| 273 g_source_remove(buddy->timer); | |
| 274 buddy->timer = g_timeout_add(10000, (GSourceFunc)presence_update_timeout_cb, buddy); | |
| 275 } | |
| 276 | |
| 6843 | 277 gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy)); |
| 5228 | 278 if (ops) |
| 279 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 280 } | |
| 281 | |
| 282 | |
| 6695 | 283 void gaim_blist_update_buddy_idle (GaimBuddy *buddy, int idle) |
| 5228 | 284 { |
| 285 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 286 buddy->idle = idle; | |
| 6843 | 287 gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy)); |
| 5228 | 288 if (ops) |
| 289 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 290 } | |
| 6695 | 291 |
| 292 void gaim_blist_update_buddy_evil (GaimBuddy *buddy, int warning) | |
| 5228 | 293 { |
| 294 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 295 buddy->evil = warning; | |
| 296 if (ops) | |
| 297 ops->update(gaimbuddylist,(GaimBlistNode*)buddy); | |
| 298 } | |
| 6695 | 299 |
| 300 void gaim_blist_update_buddy_icon(GaimBuddy *buddy) { | |
| 5228 | 301 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; |
| 302 if(ops) | |
| 303 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 304 } | |
| 6695 | 305 |
| 306 void gaim_blist_rename_buddy (GaimBuddy *buddy, const char *name) | |
| 5228 | 307 { |
| 308 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 5634 | 309 g_free(buddy->name); |
| 5228 | 310 buddy->name = g_strdup(name); |
| 311 if (ops) | |
| 312 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 313 } | |
| 5234 | 314 |
| 6695 | 315 void gaim_blist_alias_chat(GaimBlistChat *chat, const char *alias) |
| 5234 | 316 { |
| 317 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 318 | |
| 5237 | 319 g_free(chat->alias); |
| 5234 | 320 |
| 5237 | 321 if(alias && strlen(alias)) |
| 322 chat->alias = g_strdup(alias); | |
| 323 else | |
| 324 chat->alias = NULL; | |
| 325 | |
| 5234 | 326 if(ops) |
| 327 ops->update(gaimbuddylist, (GaimBlistNode*)chat); | |
| 328 } | |
| 329 | |
| 6695 | 330 void gaim_blist_alias_buddy (GaimBuddy *buddy, const char *alias) |
| 5228 | 331 { |
| 332 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
|
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5634
diff
changeset
|
333 GaimConversation *conv; |
| 5228 | 334 |
| 335 g_free(buddy->alias); | |
| 336 | |
| 337 if(alias && strlen(alias)) | |
| 338 buddy->alias = g_strdup(alias); | |
| 339 else | |
| 340 buddy->alias = NULL; | |
| 341 | |
| 342 if (ops) | |
| 343 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 344 | |
| 345 conv = gaim_find_conversation_with_account(buddy->name, buddy->account); | |
| 346 | |
| 347 if (conv) | |
| 348 gaim_conversation_autoset_title(conv); | |
| 349 } | |
| 350 | |
| 6695 | 351 void gaim_blist_server_alias_buddy (GaimBuddy *buddy, const char *alias) |
| 6058 | 352 { |
| 353 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 354 GaimConversation *conv; | |
| 355 | |
| 356 g_free(buddy->server_alias); | |
| 357 | |
| 358 if(alias && strlen(alias) && g_utf8_validate(alias, -1, NULL)) | |
| 359 buddy->server_alias = g_strdup(alias); | |
| 360 else | |
| 361 buddy->server_alias = NULL; | |
| 362 | |
| 363 if (ops) | |
| 364 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 365 | |
| 366 conv = gaim_find_conversation_with_account(buddy->name, buddy->account); | |
| 367 | |
| 368 if (conv) | |
| 369 gaim_conversation_autoset_title(conv); | |
| 370 } | |
| 371 | |
| 6695 | 372 void gaim_blist_rename_group(GaimGroup *group, const char *name) |
| 5228 | 373 { |
| 374 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 6695 | 375 GaimGroup *dest_group; |
| 5346 | 376 GaimBlistNode *prev, *child, *next; |
| 377 GSList *accts; | |
| 378 | |
| 379 if(!name || !strlen(name) || !strcmp(name, group->name)) { | |
| 380 /* nothing to do here */ | |
| 381 return; | |
| 382 } else if((dest_group = gaim_find_group(name))) { | |
| 383 /* here we're merging two groups */ | |
| 384 prev = gaim_blist_get_last_child((GaimBlistNode*)dest_group); | |
| 385 child = ((GaimBlistNode*)group)->child; | |
| 386 | |
| 387 while(child) | |
| 388 { | |
| 389 next = child->next; | |
| 6695 | 390 if(GAIM_BLIST_NODE_IS_CONTACT(child)) { |
| 391 GaimBlistNode *bnode; | |
| 392 gaim_blist_add_contact((GaimContact *)child, dest_group, prev); | |
| 393 for(bnode = child->child; bnode; bnode = bnode->next) | |
| 394 gaim_blist_add_buddy((GaimBuddy*)bnode, (GaimContact*)child, | |
| 395 NULL, bnode->prev); | |
| 5346 | 396 prev = child; |
| 397 } else if(GAIM_BLIST_NODE_IS_CHAT(child)) { | |
| 6695 | 398 gaim_blist_add_chat((GaimBlistChat *)child, dest_group, prev); |
| 5346 | 399 prev = child; |
| 400 } else { | |
| 401 gaim_debug(GAIM_DEBUG_ERROR, "blist", | |
| 402 "Unknown child type in group %s\n", group->name); | |
| 403 } | |
| 404 child = next; | |
| 405 } | |
| 406 for (accts = gaim_group_get_accounts(group); accts; accts = g_slist_remove(accts, accts->data)) { | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
407 GaimAccount *account = accts->data; |
| 5346 | 408 serv_rename_group(account->gc, group, name); |
| 409 } | |
| 410 gaim_blist_remove_group(group); | |
| 411 } else { | |
| 412 /* a simple rename */ | |
| 413 for (accts = gaim_group_get_accounts(group); accts; accts = g_slist_remove(accts, accts->data)) { | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
414 GaimAccount *account = accts->data; |
| 5346 | 415 serv_rename_group(account->gc, group, name); |
| 416 } | |
| 417 g_free(group->name); | |
| 418 group->name = g_strdup(name); | |
| 419 if (ops) | |
| 420 ops->update(gaimbuddylist, (GaimBlistNode*)group); | |
| 421 } | |
| 5228 | 422 } |
| 5234 | 423 |
| 6695 | 424 GaimBlistChat *gaim_blist_chat_new(GaimAccount *account, const char *alias, GHashTable *components) |
| 5234 | 425 { |
| 6695 | 426 GaimBlistChat *chat; |
| 5234 | 427 struct gaim_blist_ui_ops *ops; |
| 428 | |
| 5237 | 429 if(!components) |
| 5234 | 430 return NULL; |
| 431 | |
| 6695 | 432 chat = g_new0(GaimBlistChat, 1); |
| 5234 | 433 chat->account = account; |
| 5237 | 434 if(alias && strlen(alias)) |
| 435 chat->alias = g_strdup(alias); | |
| 5234 | 436 chat->components = components; |
| 5906 | 437 chat->settings = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 438 g_free, g_free); | |
| 5234 | 439 |
| 440 ((GaimBlistNode*)chat)->type = GAIM_BLIST_CHAT_NODE; | |
| 441 | |
| 442 ops = gaim_get_blist_ui_ops(); | |
| 443 | |
| 444 if (ops != NULL && ops->new_node != NULL) | |
| 445 ops->new_node((GaimBlistNode *)chat); | |
| 446 | |
| 447 return chat; | |
| 448 } | |
| 449 | |
| 6695 | 450 char *gaim_blist_chat_get_display_name(GaimBlistChat *chat) |
| 6034 | 451 { |
| 452 char *name; | |
| 453 | |
| 454 if(chat->alias){ | |
| 455 name = g_strdup(chat->alias); | |
| 456 } | |
| 457 else{ | |
| 458 GList *parts; | |
| 459 GaimPlugin *prpl; | |
| 460 GaimPluginProtocolInfo *prpl_info; | |
| 461 struct proto_chat_entry *pce; | |
| 462 | |
| 463 prpl = gaim_find_prpl(gaim_account_get_protocol(chat->account)); | |
| 464 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
| 465 | |
| 466 parts = prpl_info->chat_info(chat->account->gc); | |
| 467 | |
| 468 pce = parts->data; | |
| 469 name = g_markup_escape_text(g_hash_table_lookup(chat->components, | |
| 470 pce->identifier), -1); | |
| 471 g_list_free(parts); | |
| 472 } | |
| 473 | |
| 474 return name; | |
| 475 } | |
| 476 | |
| 6695 | 477 GaimBuddy *gaim_buddy_new(GaimAccount *account, const char *screenname, const char *alias) |
| 5228 | 478 { |
| 6695 | 479 GaimBuddy *b; |
| 5228 | 480 struct gaim_blist_ui_ops *ops; |
| 481 | |
| 6695 | 482 b = g_new0(GaimBuddy, 1); |
| 5228 | 483 b->account = account; |
| 484 b->name = g_strdup(screenname); | |
| 485 b->alias = g_strdup(alias); | |
| 486 b->settings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
| 487 ((GaimBlistNode*)b)->type = GAIM_BLIST_BUDDY_NODE; | |
| 488 | |
| 489 ops = gaim_get_blist_ui_ops(); | |
| 490 | |
| 491 if (ops != NULL && ops->new_node != NULL) | |
| 492 ops->new_node((GaimBlistNode *)b); | |
| 493 | |
| 494 return b; | |
| 495 } | |
| 5634 | 496 |
| 6695 | 497 void gaim_blist_add_chat(GaimBlistChat *chat, GaimGroup *group, GaimBlistNode *node) |
| 5234 | 498 { |
| 499 GaimBlistNode *n = node, *cnode = (GaimBlistNode*)chat; | |
| 6695 | 500 GaimGroup *g = group; |
| 5234 | 501 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; |
| 502 gboolean save = FALSE; | |
| 503 | |
| 6774 | 504 |
| 505 g_return_if_fail(chat != NULL); | |
| 506 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT((GaimBlistNode*)chat)); | |
| 507 | |
| 5234 | 508 if (!n) { |
| 509 if (!g) { | |
| 510 g = gaim_group_new(_("Chats")); | |
| 5634 | 511 gaim_blist_add_group(g, |
| 512 gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
| 5234 | 513 } |
| 514 } else { | |
| 6695 | 515 g = (GaimGroup*)n->parent; |
| 5234 | 516 } |
| 517 | |
| 518 /* if we're moving to overtop of ourselves, do nothing */ | |
| 519 if(cnode == n) | |
| 520 return; | |
| 521 | |
| 522 if (cnode->parent) { | |
| 523 /* This chat was already in the list and is | |
| 524 * being moved. | |
| 525 */ | |
| 6695 | 526 ((GaimGroup *)cnode->parent)->totalsize--; |
| 5855 | 527 if (gaim_account_is_connected(chat->account)) { |
| 6695 | 528 ((GaimGroup *)cnode->parent)->online--; |
| 529 ((GaimGroup *)cnode->parent)->currentsize--; | |
| 5287 | 530 } |
| 5234 | 531 if(cnode->next) |
| 532 cnode->next->prev = cnode->prev; | |
| 533 if(cnode->prev) | |
| 534 cnode->prev->next = cnode->next; | |
| 535 if(cnode->parent->child == cnode) | |
| 536 cnode->parent->child = cnode->next; | |
| 537 | |
| 538 ops->remove(gaimbuddylist, cnode); | |
| 539 | |
| 540 save = TRUE; | |
| 541 } | |
| 542 | |
| 543 if (n) { | |
| 544 if(n->next) | |
| 545 n->next->prev = cnode; | |
| 546 cnode->next = n->next; | |
| 547 cnode->prev = n; | |
| 548 cnode->parent = n->parent; | |
| 549 n->next = cnode; | |
| 6695 | 550 ((GaimGroup *)n->parent)->totalsize++; |
| 5855 | 551 if (gaim_account_is_connected(chat->account)) { |
| 6695 | 552 ((GaimGroup *)n->parent)->online++; |
| 553 ((GaimGroup *)n->parent)->currentsize++; | |
| 5287 | 554 } |
| 5234 | 555 } else { |
| 5634 | 556 if(((GaimBlistNode*)g)->child) |
| 557 ((GaimBlistNode*)g)->child->prev = cnode; | |
| 558 cnode->next = ((GaimBlistNode*)g)->child; | |
| 559 cnode->prev = NULL; | |
| 5234 | 560 ((GaimBlistNode*)g)->child = cnode; |
| 561 cnode->parent = (GaimBlistNode*)g; | |
| 5277 | 562 g->totalsize++; |
| 5855 | 563 if (gaim_account_is_connected(chat->account)) { |
| 5287 | 564 g->online++; |
| 5277 | 565 g->currentsize++; |
| 5287 | 566 } |
| 5234 | 567 } |
| 568 | |
| 569 if (ops) | |
| 570 ops->update(gaimbuddylist, (GaimBlistNode*)cnode); | |
| 571 if (save) | |
| 572 gaim_blist_save(); | |
| 573 } | |
| 574 | |
| 6695 | 575 void gaim_blist_add_buddy (GaimBuddy *buddy, GaimContact *contact, GaimGroup *group, GaimBlistNode *node) |
| 5228 | 576 { |
| 6695 | 577 GaimBlistNode *cnode, *bnode; |
| 578 GaimGroup *g; | |
| 579 GaimContact *c; | |
| 5228 | 580 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; |
| 6695 | 581 gboolean save = FALSE; |
| 5247 | 582 struct _gaim_hbuddy *hb; |
| 6695 | 583 |
| 584 g_return_if_fail(buddy != NULL); | |
| 6774 | 585 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY((GaimBlistNode*)buddy)); |
| 6695 | 586 |
| 587 bnode = (GaimBlistNode *)buddy; | |
| 5228 | 588 |
| 6695 | 589 /* if we're moving to overtop of ourselves, do nothing */ |
| 590 if(bnode == node || (!node && bnode->parent && | |
| 591 contact && bnode->parent == (GaimBlistNode*)contact | |
| 592 && bnode == bnode->parent->child)) | |
| 593 return; | |
| 594 | |
| 595 if(node && GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
| 596 c = (GaimContact*)node->parent; | |
| 597 g = (GaimGroup*)node->parent->parent; | |
| 598 } else if(contact) { | |
| 599 c = contact; | |
| 600 g = (GaimGroup*)((GaimBlistNode*)c)->parent; | |
| 601 } else { | |
| 602 if(group) { | |
| 603 g = group; | |
| 604 } else { | |
| 5228 | 605 g = gaim_group_new(_("Buddies")); |
| 5634 | 606 gaim_blist_add_group(g, |
| 607 gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
| 5228 | 608 } |
| 6695 | 609 c = gaim_contact_new(); |
| 610 gaim_blist_add_contact(c, g, | |
| 611 gaim_blist_get_last_child((GaimBlistNode*)g)); | |
| 5228 | 612 } |
| 613 | |
| 6695 | 614 cnode = (GaimBlistNode *)c; |
| 5228 | 615 |
| 6695 | 616 if(bnode->parent) { |
| 617 if(GAIM_BUDDY_IS_ONLINE(buddy)) { | |
| 618 ((GaimContact*)bnode->parent)->online--; | |
| 619 if(((GaimContact*)bnode->parent)->online == 0) | |
| 620 ((GaimGroup*)bnode->parent->parent)->online--; | |
| 621 } | |
| 622 if(gaim_account_is_connected(buddy->account)) { | |
| 623 ((GaimContact*)bnode->parent)->currentsize--; | |
| 624 if(((GaimContact*)bnode->parent)->currentsize == 0) | |
| 625 ((GaimGroup*)bnode->parent->parent)->currentsize--; | |
| 626 } | |
| 627 ((GaimContact*)bnode->parent)->totalsize--; | |
| 628 /* the group totalsize will be taken care of by remove_contact below */ | |
| 629 | |
| 630 if(bnode->parent->parent != (GaimBlistNode*)g) | |
| 631 serv_move_buddy(buddy, (GaimGroup *)bnode->parent->parent, g); | |
| 5277 | 632 |
| 5228 | 633 if(bnode->next) |
| 634 bnode->next->prev = bnode->prev; | |
| 635 if(bnode->prev) | |
| 636 bnode->prev->next = bnode->next; | |
| 6794 | 637 if(bnode->parent->child == bnode) |
| 5228 | 638 bnode->parent->child = bnode->next; |
| 639 | |
| 640 ops->remove(gaimbuddylist, bnode); | |
| 641 | |
| 642 save = TRUE; | |
| 6742 | 643 |
| 644 if(bnode->parent->parent != (GaimBlistNode*)g) { | |
| 645 hb = g_new(struct _gaim_hbuddy, 1); | |
| 646 hb->name = normalize(buddy->name); | |
| 647 hb->account = buddy->account; | |
| 648 hb->group = bnode->parent->parent; | |
| 6775 | 649 g_hash_table_remove(gaimbuddylist->buddies, hb); |
| 6742 | 650 g_free(hb); |
| 651 } | |
| 6794 | 652 |
| 653 if(!bnode->parent->child) | |
| 654 gaim_blist_remove_contact((GaimContact*)bnode->parent); | |
| 655 | |
| 5228 | 656 } |
| 657 | |
| 6695 | 658 if(node && GAIM_BLIST_NODE_IS_BUDDY(node)) { |
| 659 if(node->next) | |
| 660 node->next->prev = bnode; | |
| 661 bnode->next = node->next; | |
| 662 bnode->prev = node; | |
| 663 bnode->parent = node->parent; | |
| 664 node->next = bnode; | |
| 5228 | 665 } else { |
| 6695 | 666 if(cnode->child) |
| 667 cnode->child->prev = bnode; | |
| 668 bnode->prev = NULL; | |
| 669 bnode->next = cnode->child; | |
| 670 cnode->child = bnode; | |
| 671 bnode->parent = cnode; | |
| 5228 | 672 } |
| 673 | |
| 6695 | 674 if(GAIM_BUDDY_IS_ONLINE(buddy)) { |
| 675 ((GaimContact*)bnode->parent)->online++; | |
| 676 if(((GaimContact*)bnode->parent)->online == 1) | |
| 677 ((GaimGroup*)bnode->parent->parent)->online++; | |
| 678 } | |
| 679 if(gaim_account_is_connected(buddy->account)) { | |
| 680 ((GaimContact*)bnode->parent)->currentsize++; | |
| 681 if(((GaimContact*)bnode->parent)->currentsize == 1) | |
| 682 ((GaimGroup*)bnode->parent->parent)->currentsize++; | |
| 683 } | |
| 684 ((GaimContact*)bnode->parent)->totalsize++; | |
| 685 | |
| 686 | |
| 6742 | 687 hb = g_new(struct _gaim_hbuddy, 1); |
| 5247 | 688 hb->name = g_strdup(normalize(buddy->name)); |
| 689 hb->account = buddy->account; | |
| 6695 | 690 hb->group = ((GaimBlistNode*)buddy)->parent->parent; |
| 5247 | 691 |
| 6742 | 692 g_hash_table_replace(gaimbuddylist->buddies, hb, buddy); |
| 5247 | 693 |
| 6843 | 694 gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy)); |
| 5228 | 695 if (ops) |
| 696 ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 697 if (save) | |
| 698 gaim_blist_save(); | |
| 699 } | |
| 700 | |
| 6695 | 701 GaimContact *gaim_contact_new() |
| 5228 | 702 { |
| 6695 | 703 struct gaim_blist_ui_ops *ops; |
| 704 GaimContact *c = g_new0(GaimContact, 1); | |
| 705 ((GaimBlistNode*)c)->type = GAIM_BLIST_CONTACT_NODE; | |
| 706 | |
| 707 c->totalsize = c->currentsize = c->online = 0; | |
| 708 | |
| 709 ops = gaim_get_blist_ui_ops(); | |
| 710 if (ops != NULL && ops->new_node != NULL) | |
| 711 ops->new_node((GaimBlistNode *)c); | |
| 712 | |
| 713 return c; | |
| 714 } | |
| 715 | |
| 6755 | 716 void gaim_contact_set_alias(GaimContact* contact, const char *alias) |
| 717 { | |
| 718 g_return_if_fail(contact != NULL); | |
| 719 | |
| 720 if(contact->alias) | |
| 721 g_free(contact->alias); | |
| 722 | |
| 723 contact->alias = g_strdup(alias); | |
| 724 } | |
| 725 | |
| 726 const char *gaim_contact_get_alias(GaimContact* contact) | |
| 727 { | |
| 728 return contact ? contact->alias : NULL; | |
| 729 } | |
| 730 | |
| 6695 | 731 GaimGroup *gaim_group_new(const char *name) |
| 732 { | |
| 733 GaimGroup *g = gaim_find_group(name); | |
| 5228 | 734 |
| 735 if (!g) { | |
| 736 struct gaim_blist_ui_ops *ops; | |
| 6695 | 737 g= g_new0(GaimGroup, 1); |
| 5228 | 738 g->name = g_strdup(name); |
| 5277 | 739 g->totalsize = 0; |
| 740 g->currentsize = 0; | |
| 741 g->online = 0; | |
| 5228 | 742 g->settings = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 743 g_free, g_free); | |
| 744 ((GaimBlistNode*)g)->type = GAIM_BLIST_GROUP_NODE; | |
| 745 | |
| 746 ops = gaim_get_blist_ui_ops(); | |
| 747 | |
| 748 if (ops != NULL && ops->new_node != NULL) | |
| 749 ops->new_node((GaimBlistNode *)g); | |
| 750 | |
| 751 } | |
| 752 return g; | |
| 753 } | |
| 754 | |
| 6695 | 755 void gaim_blist_add_contact(GaimContact *contact, GaimGroup *group, GaimBlistNode *node) |
| 756 { | |
| 757 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 758 GaimGroup *g; | |
| 6742 | 759 GaimBlistNode *gnode, *cnode, *bnode; |
| 6695 | 760 gboolean save = FALSE; |
| 761 | |
| 6774 | 762 g_return_if_fail(contact != NULL); |
| 763 g_return_if_fail(GAIM_BLIST_NODE_IS_CONTACT((GaimBlistNode*)contact)); | |
| 6695 | 764 |
| 765 if(node && (GAIM_BLIST_NODE_IS_CONTACT(node) || | |
| 766 GAIM_BLIST_NODE_IS_CHAT(node))) | |
| 767 g = (GaimGroup*)node->parent; | |
| 768 else if(group) | |
| 769 g = group; | |
| 770 else { | |
| 771 g = gaim_group_new(_("Buddies")); | |
| 772 gaim_blist_add_group(g, | |
| 773 gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
| 774 } | |
| 775 | |
| 776 gnode = (GaimBlistNode*)g; | |
| 777 cnode = (GaimBlistNode*)contact; | |
| 778 | |
| 779 if(cnode->parent) { | |
| 6731 | 780 if(cnode->parent->child == cnode) |
| 781 cnode->parent->child = cnode->next; | |
| 6695 | 782 if(cnode->prev) |
| 783 cnode->prev->next = cnode->next; | |
| 784 if(cnode->next) | |
| 785 cnode->next->prev = cnode->prev; | |
| 786 | |
| 787 | |
| 788 if(contact->online > 0) | |
| 789 ((GaimGroup*)cnode->parent)->online--; | |
| 790 if(contact->currentsize > 0) | |
| 791 ((GaimGroup*)cnode->parent)->currentsize--; | |
| 792 ((GaimGroup*)cnode->parent)->totalsize--; | |
| 793 | |
| 6731 | 794 ops->remove(gaimbuddylist, cnode); |
| 795 | |
| 6695 | 796 save = TRUE; |
| 6742 | 797 |
| 798 if(cnode->parent != gnode) { | |
| 799 for(bnode = cnode->child; bnode; bnode = bnode->next) { | |
| 800 GaimBuddy *b = (GaimBuddy*)bnode; | |
| 801 | |
| 802 struct _gaim_hbuddy *hb = g_new(struct _gaim_hbuddy, 1); | |
| 803 hb->name = g_strdup(normalize(b->name)); | |
| 804 hb->account = b->account; | |
| 805 hb->group = cnode->parent; | |
| 806 | |
| 6776 | 807 g_hash_table_remove(gaimbuddylist->buddies, hb); |
| 6742 | 808 |
| 809 hb->group = gnode; | |
| 810 g_hash_table_replace(gaimbuddylist->buddies, hb, b); | |
| 811 | |
| 812 if(b->account->gc) | |
| 813 serv_move_buddy(b, (GaimGroup*)cnode->parent, g); | |
| 814 } | |
| 815 } | |
| 6695 | 816 } |
| 817 | |
| 6775 | 818 |
| 6695 | 819 if(node && (GAIM_BLIST_NODE_IS_CONTACT(node) || |
| 820 GAIM_BLIST_NODE_IS_CHAT(node))) { | |
| 821 if(node->next) | |
| 822 node->next->prev = cnode; | |
| 823 cnode->next = node->next; | |
| 824 cnode->prev = node; | |
| 825 cnode->parent = node->parent; | |
| 826 node->next = cnode; | |
| 827 } else { | |
| 828 if(gnode->child) | |
| 829 gnode->child->prev = cnode; | |
| 830 cnode->prev = NULL; | |
| 831 cnode->next = gnode->child; | |
| 832 gnode->child = cnode; | |
| 833 cnode->parent = gnode; | |
| 834 } | |
| 835 | |
| 836 if(contact->online > 0) | |
| 837 g->online++; | |
| 838 if(contact->currentsize > 0) | |
| 839 g->currentsize++; | |
| 840 g->totalsize++; | |
| 841 | |
| 842 if(ops && cnode->child) | |
| 843 ops->update(gaimbuddylist, cnode); | |
| 6775 | 844 |
| 845 for(bnode = cnode->child; bnode; bnode = bnode->next) | |
| 846 ops->update(gaimbuddylist, bnode); | |
| 847 | |
| 6695 | 848 if (save) |
| 849 gaim_blist_save(); | |
| 850 } | |
| 851 | |
| 852 void gaim_blist_add_group (GaimGroup *group, GaimBlistNode *node) | |
| 5228 | 853 { |
| 854 struct gaim_blist_ui_ops *ops; | |
| 855 GaimBlistNode *gnode = (GaimBlistNode*)group; | |
| 856 gboolean save = FALSE; | |
| 857 | |
| 6774 | 858 g_return_if_fail(group != NULL); |
| 859 g_return_if_fail(GAIM_BLIST_NODE_IS_GROUP((GaimBlistNode*)group)); | |
| 860 | |
| 5228 | 861 if (!gaimbuddylist) |
| 862 gaimbuddylist = gaim_blist_new(); | |
| 863 ops = gaimbuddylist->ui_ops; | |
| 864 | |
| 865 if (!gaimbuddylist->root) { | |
| 866 gaimbuddylist->root = gnode; | |
| 867 return; | |
| 868 } | |
| 869 | |
| 870 /* if we're moving to overtop of ourselves, do nothing */ | |
| 871 if(gnode == node) | |
| 872 return; | |
| 873 | |
| 874 if (gaim_find_group(group->name)) { | |
| 875 /* This is just being moved */ | |
| 876 | |
| 877 ops->remove(gaimbuddylist, (GaimBlistNode*)group); | |
| 878 | |
| 879 if(gnode == gaimbuddylist->root) | |
| 880 gaimbuddylist->root = gnode->next; | |
| 881 if(gnode->prev) | |
| 882 gnode->prev->next = gnode->next; | |
| 883 if(gnode->next) | |
| 884 gnode->next->prev = gnode->prev; | |
| 885 | |
| 886 save = TRUE; | |
| 887 } | |
| 888 | |
| 6695 | 889 if (node && GAIM_BLIST_NODE_IS_GROUP(node)) { |
| 5634 | 890 gnode->next = node->next; |
| 891 gnode->prev = node; | |
| 892 if(node->next) | |
| 893 node->next->prev = gnode; | |
| 894 node->next = gnode; | |
| 895 } else { | |
| 6807 | 896 if(gaimbuddylist->root) |
| 897 gaimbuddylist->root->prev = gnode; | |
| 5634 | 898 gnode->next = gaimbuddylist->root; |
| 899 gnode->prev = NULL; | |
| 900 gaimbuddylist->root = gnode; | |
| 901 } | |
| 902 | |
| 5228 | 903 |
| 904 if (ops) { | |
| 905 ops->update(gaimbuddylist, gnode); | |
| 906 for(node = gnode->child; node; node = node->next) | |
| 907 ops->update(gaimbuddylist, node); | |
| 908 } | |
| 909 if (save) | |
| 910 gaim_blist_save(); | |
| 911 } | |
| 912 | |
| 6695 | 913 void gaim_blist_remove_contact(GaimContact* contact) |
| 5228 | 914 { |
| 915 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 916 | |
| 6695 | 917 GaimBlistNode *gnode, *cnode = (GaimBlistNode*)contact; |
| 918 | |
| 919 gnode = cnode->parent; | |
| 920 | |
| 921 if(cnode->child) { | |
| 922 while(cnode->child) { | |
| 923 gaim_blist_remove_buddy((GaimBuddy*)cnode->child); | |
| 924 } | |
| 925 } else { | |
| 926 if(ops) | |
| 927 ops->remove(gaimbuddylist, cnode); | |
| 928 | |
| 929 if(gnode->child == cnode) | |
| 930 gnode->child = cnode->next; | |
| 931 if(cnode->prev) | |
| 932 cnode->prev->next = cnode->next; | |
| 933 if(cnode->next) | |
| 934 cnode->next->prev = cnode->prev; | |
| 935 | |
| 936 g_free(contact); | |
| 937 } | |
| 938 } | |
| 939 | |
| 6742 | 940 void gaim_blist_remove_buddy (GaimBuddy *buddy) |
| 6695 | 941 { |
| 942 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 943 | |
| 944 GaimBlistNode *cnode, *node = (GaimBlistNode*)buddy; | |
| 945 GaimGroup *group; | |
| 6742 | 946 struct _gaim_hbuddy hb; |
| 5228 | 947 |
| 6695 | 948 cnode = node->parent; |
| 949 group = (GaimGroup *)cnode->parent; | |
| 5228 | 950 |
| 6695 | 951 if(GAIM_BUDDY_IS_ONLINE(buddy)) { |
| 952 ((GaimContact*)cnode)->online--; | |
| 953 if(((GaimContact*)cnode)->online == 0) | |
| 954 group->online--; | |
| 955 } | |
| 956 if(gaim_account_is_connected(buddy->account)) { | |
| 957 ((GaimContact*)cnode)->currentsize--; | |
| 958 if(((GaimContact*)cnode)->currentsize == 0) | |
| 959 group->currentsize--; | |
| 960 } | |
| 961 ((GaimContact*)cnode)->totalsize--; | |
| 962 | |
| 5228 | 963 if (node->prev) |
| 964 node->prev->next = node->next; | |
| 965 if (node->next) | |
| 966 node->next->prev = node->prev; | |
| 6695 | 967 if(cnode->child == node) { |
| 968 cnode->child = node->next; | |
| 969 } | |
| 5228 | 970 |
| 6755 | 971 |
| 5247 | 972 hb.name = normalize(buddy->name); |
| 973 hb.account = buddy->account; | |
| 6695 | 974 hb.group = ((GaimBlistNode*)buddy)->parent->parent; |
| 6742 | 975 g_hash_table_remove(gaimbuddylist->buddies, &hb); |
| 5247 | 976 |
| 5292 | 977 if(buddy->timer > 0) |
| 978 g_source_remove(buddy->timer); | |
| 979 | |
| 5228 | 980 ops->remove(gaimbuddylist, node); |
| 981 g_hash_table_destroy(buddy->settings); | |
| 982 g_free(buddy->name); | |
| 983 g_free(buddy->alias); | |
| 984 g_free(buddy); | |
| 6755 | 985 |
| 986 if(!cnode->child) | |
| 987 gaim_blist_remove_contact((GaimContact*)cnode); | |
| 5228 | 988 } |
| 989 | |
| 6695 | 990 void gaim_blist_remove_chat (GaimBlistChat *chat) |
| 5234 | 991 { |
| 992 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 993 | |
| 994 GaimBlistNode *gnode, *node = (GaimBlistNode*)chat; | |
| 6695 | 995 GaimGroup *group; |
| 5234 | 996 |
| 997 gnode = node->parent; | |
| 6695 | 998 group = (GaimGroup *)gnode; |
| 5234 | 999 |
| 1000 if(gnode->child == node) | |
| 1001 gnode->child = node->next; | |
| 1002 if (node->prev) | |
| 1003 node->prev->next = node->next; | |
| 1004 if (node->next) | |
| 1005 node->next->prev = node->prev; | |
| 5277 | 1006 group->totalsize--; |
| 5855 | 1007 if (gaim_account_is_connected(chat->account)) { |
| 5277 | 1008 group->currentsize--; |
| 5394 | 1009 group->online--; |
| 1010 } | |
| 5234 | 1011 |
| 1012 ops->remove(gaimbuddylist, node); | |
| 1013 g_hash_table_destroy(chat->components); | |
| 1014 g_free(chat->alias); | |
| 1015 g_free(chat); | |
| 1016 } | |
| 1017 | |
| 6695 | 1018 void gaim_blist_remove_group (GaimGroup *group) |
| 5228 | 1019 { |
| 1020 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 1021 GaimBlistNode *node = (GaimBlistNode*)group; | |
| 1022 | |
| 1023 if(node->child) { | |
| 1024 char *buf; | |
| 1025 int count = 0; | |
| 1026 GaimBlistNode *child = node->child; | |
| 1027 | |
| 1028 while(child) { | |
| 1029 count++; | |
| 1030 child = child->next; | |
| 1031 } | |
| 1032 | |
| 6308 | 1033 buf = g_strdup_printf(ngettext("%d buddy from group %s was not removed " |
| 1034 "because its account was not logged in." | |
| 1035 " This buddy and the group were not " | |
| 1036 "removed.\n", | |
| 1037 "%d buddies from group %s were not " | |
| 1038 "removed because their accounts were " | |
| 6336 | 1039 "not logged in. These buddies and " |
| 1040 "the group were not removed.\n", count), | |
| 6308 | 1041 count, group->name); |
|
5541
aee0ee458974
[gaim-migrate @ 5941]
Christian Hammond <chipx86@chipx86.com>
parents:
5436
diff
changeset
|
1042 gaim_notify_error(NULL, NULL, _("Group not removed"), buf); |
| 5228 | 1043 g_free(buf); |
| 1044 return; | |
| 1045 } | |
| 1046 | |
| 1047 if(gaimbuddylist->root == node) | |
| 1048 gaimbuddylist->root = node->next; | |
| 1049 if (node->prev) | |
| 1050 node->prev->next = node->next; | |
| 1051 if (node->next) | |
| 1052 node->next->prev = node->prev; | |
| 1053 | |
| 1054 ops->remove(gaimbuddylist, node); | |
| 1055 g_free(group->name); | |
| 1056 g_free(group); | |
| 1057 } | |
| 1058 | |
| 6695 | 1059 GaimBuddy *gaim_contact_get_priority_buddy(GaimContact *contact) { |
| 6843 | 1060 return contact->priority; |
| 6695 | 1061 } |
| 1062 | |
| 1063 const char *gaim_get_buddy_alias_only(GaimBuddy *b) { | |
|
5545
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
1064 if(!b) |
|
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
1065 return NULL; |
|
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
1066 |
|
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
1067 if(b->alias && b->alias[0]) { |
|
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
1068 return b->alias; |
|
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
1069 } |
|
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
1070 else if (b->server_alias != NULL && |
|
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
1071 gaim_prefs_get_bool("/core/buddies/use_server_alias")) { |
|
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
1072 |
|
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
1073 return b->server_alias; |
|
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
1074 } |
|
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
1075 |
|
7a64114641c3
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
1076 return NULL; |
| 5228 | 1077 } |
| 1078 | |
| 6695 | 1079 const char * gaim_get_buddy_alias (GaimBuddy *buddy) |
| 5228 | 1080 { |
| 6755 | 1081 GaimContact *contact; |
| 1082 const char *ret; | |
| 1083 | |
| 1084 if(!buddy) | |
| 1085 return _("Unknown"); | |
| 5228 | 1086 |
| 6755 | 1087 contact = (GaimContact*)((GaimBlistNode*)buddy)->parent; |
| 6036 | 1088 |
| 6755 | 1089 if(contact && contact->alias) |
| 1090 return contact->alias; | |
| 1091 | |
| 1092 ret= gaim_get_buddy_alias_only(buddy); | |
| 1093 | |
| 1094 return ret ? ret : buddy->name; | |
| 5228 | 1095 } |
| 1096 | |
| 6744 | 1097 const char *gaim_blist_chat_get_name(GaimBlistChat *chat) |
| 1098 { | |
| 1099 if(chat->alias && *chat->alias) { | |
| 1100 return chat->alias; | |
| 1101 } else { | |
| 1102 struct proto_chat_entry *pce; | |
| 1103 GList *parts, *tmp; | |
| 1104 char *ret; | |
| 1105 | |
| 1106 parts = GAIM_PLUGIN_PROTOCOL_INFO(chat->account->gc->prpl)->chat_info(chat->account->gc); | |
| 1107 pce = parts->data; | |
| 1108 ret = g_hash_table_lookup(chat->components, pce->identifier); | |
| 1109 for(tmp = parts; tmp; tmp = tmp->next) | |
| 1110 g_free(tmp->data); | |
| 1111 g_list_free(parts); | |
| 1112 | |
| 1113 return ret; | |
| 1114 } | |
| 1115 } | |
| 1116 | |
| 6695 | 1117 GaimBuddy *gaim_find_buddy(GaimAccount *account, const char *name) |
| 5228 | 1118 { |
| 6695 | 1119 GaimBuddy *buddy; |
| 5247 | 1120 struct _gaim_hbuddy hb; |
| 5758 | 1121 GaimBlistNode *group; |
| 5228 | 1122 |
| 1123 if (!gaimbuddylist) | |
| 1124 return NULL; | |
| 6245 | 1125 |
| 1126 if (!name) | |
|
5985
60d9cbfb6bf8
[gaim-migrate @ 6433]
Christian Hammond <chipx86@chipx86.com>
parents:
5947
diff
changeset
|
1127 return NULL; |
| 5228 | 1128 |
| 6245 | 1129 hb.name = normalize(name); |
| 1130 hb.account = account; | |
| 5247 | 1131 |
| 6245 | 1132 for(group = gaimbuddylist->root; group; group = group->next) { |
| 5758 | 1133 hb.group = group; |
| 5776 | 1134 if ((buddy = g_hash_table_lookup(gaimbuddylist->buddies, &hb)) != NULL) |
| 5758 | 1135 return buddy; |
| 1136 } | |
| 6245 | 1137 |
| 5758 | 1138 return NULL; |
| 5228 | 1139 } |
| 1140 | |
| 6245 | 1141 GSList *gaim_find_buddies(GaimAccount *account, const char *name) |
| 1142 { | |
| 1143 struct buddy *buddy; | |
| 1144 struct _gaim_hbuddy hb; | |
| 1145 GaimBlistNode *group; | |
| 1146 GSList *ret = NULL; | |
| 1147 | |
| 1148 if (!gaimbuddylist) | |
| 1149 return NULL; | |
| 1150 | |
| 1151 if (!name) | |
| 1152 return NULL; | |
| 1153 | |
| 1154 hb.name = normalize(name); | |
| 1155 hb.account = account; | |
| 1156 | |
| 1157 for(group = gaimbuddylist->root; group; group = group->next) { | |
| 1158 hb.group = group; | |
| 1159 if ((buddy = g_hash_table_lookup(gaimbuddylist->buddies, &hb)) != NULL) | |
| 1160 ret = g_slist_append(ret, buddy); | |
| 1161 } | |
| 1162 | |
| 1163 return ret; | |
| 1164 } | |
| 1165 | |
| 6695 | 1166 GaimGroup *gaim_find_group(const char *name) |
| 5228 | 1167 { |
| 1168 GaimBlistNode *node; | |
| 1169 if (!gaimbuddylist) | |
| 1170 return NULL; | |
| 1171 node = gaimbuddylist->root; | |
| 1172 while(node) { | |
| 6695 | 1173 if (!strcmp(((GaimGroup *)node)->name, name)) |
| 1174 return (GaimGroup *)node; | |
| 5228 | 1175 node = node->next; |
| 1176 } | |
| 1177 return NULL; | |
| 1178 } | |
|
6456
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1179 |
| 6695 | 1180 GaimBlistChat * |
|
6456
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1181 gaim_blist_find_chat(GaimAccount *account, const char *name) |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1182 { |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1183 char *chat_name; |
| 6695 | 1184 GaimBlistChat *chat; |
|
6456
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1185 GaimPlugin *prpl; |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1186 GaimPluginProtocolInfo *prpl_info = NULL; |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1187 struct proto_chat_entry *pce; |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1188 GaimBlistNode *node, *group; |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1189 GList *parts; |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1190 |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1191 g_return_val_if_fail(gaim_get_blist() != NULL, NULL); |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1192 g_return_val_if_fail(name != NULL, NULL); |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1193 |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1194 for (group = gaimbuddylist->root; group != NULL; group = group->next) { |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1195 for (node = group->child; node != NULL; node = node->next) { |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1196 if (GAIM_BLIST_NODE_IS_CHAT(node)) { |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1197 |
| 6695 | 1198 chat = (GaimBlistChat*)node; |
|
6456
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1199 |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1200 prpl = gaim_find_prpl(gaim_account_get_protocol(chat->account)); |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1201 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1202 |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1203 parts = prpl_info->chat_info( |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1204 gaim_account_get_connection(chat->account)); |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1205 |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1206 pce = parts->data; |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1207 chat_name = g_hash_table_lookup(chat->components, |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1208 pce->identifier); |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1209 |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1210 if (chat->account == account && |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1211 name != NULL && !strcmp(chat_name, name)) { |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1212 |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1213 return chat; |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1214 } |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1215 } |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1216 } |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1217 } |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1218 |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1219 return NULL; |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1220 } |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1221 |
| 6695 | 1222 GaimGroup * |
| 1223 gaim_blist_chat_get_group(GaimBlistChat *chat) | |
|
6456
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1224 { |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1225 g_return_val_if_fail(chat != NULL, NULL); |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1226 |
| 6695 | 1227 return (GaimGroup *)(((GaimBlistNode *)chat)->parent); |
|
6456
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1228 } |
|
ccfdf9f2cdd1
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1229 |
| 6695 | 1230 GaimGroup *gaim_find_buddys_group(GaimBuddy *buddy) |
| 5228 | 1231 { |
| 1232 if (!buddy) | |
| 1233 return NULL; | |
|
6706
854a435d2cc3
[gaim-migrate @ 7232]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
1234 |
|
854a435d2cc3
[gaim-migrate @ 7232]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
1235 if (((GaimBlistNode *)buddy)->parent == NULL) |
|
854a435d2cc3
[gaim-migrate @ 7232]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
1236 return NULL; |
|
854a435d2cc3
[gaim-migrate @ 7232]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
1237 |
| 6695 | 1238 return (GaimGroup *)(((GaimBlistNode*)buddy)->parent->parent); |
| 5228 | 1239 } |
| 1240 | |
| 6695 | 1241 GSList *gaim_group_get_accounts(GaimGroup *g) |
| 5228 | 1242 { |
| 1243 GSList *l = NULL; | |
| 6695 | 1244 GaimBlistNode *gnode, *cnode, *bnode; |
| 1245 | |
| 1246 gnode = (GaimBlistNode *)g; | |
| 5228 | 1247 |
| 6695 | 1248 for(cnode = gnode->child; cnode; cnode = cnode->next) { |
| 1249 if (GAIM_BLIST_NODE_IS_CHAT(cnode)) { | |
| 1250 if(!g_slist_find(l, ((GaimBlistChat *)cnode)->account)) | |
| 1251 l = g_slist_append(l, ((GaimBlistChat *)cnode)->account); | |
| 1252 } else if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
| 1253 for(bnode = cnode->child; bnode; bnode = bnode->next) { | |
| 1254 if(GAIM_BLIST_NODE_IS_BUDDY(bnode)) { | |
| 1255 if(!g_slist_find(l, ((GaimBuddy *)bnode)->account)) | |
| 1256 l = g_slist_append(l, ((GaimBuddy *)bnode)->account); | |
| 1257 } | |
| 1258 } | |
| 1259 } | |
| 5228 | 1260 } |
| 6695 | 1261 |
| 5228 | 1262 return l; |
| 1263 } | |
| 1264 | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1265 void gaim_blist_add_account(GaimAccount *account) |
| 5234 | 1266 { |
| 1267 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 6695 | 1268 GaimBlistNode *gnode, *cnode, *bnode; |
| 5234 | 1269 |
| 1270 if(!gaimbuddylist) | |
| 1271 return; | |
| 1272 | |
| 6695 | 1273 if(!ops) |
| 1274 return; | |
| 1275 | |
| 1276 for(gnode = gaimbuddylist->root; gnode; gnode = gnode->next) { | |
| 1277 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
| 5234 | 1278 continue; |
| 6695 | 1279 for(cnode = gnode->child; cnode; cnode = cnode->next) { |
| 1280 if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
| 1281 for(bnode = cnode->child; bnode; bnode = bnode->next) { | |
| 1282 if(GAIM_BLIST_NODE_IS_BUDDY(bnode) && | |
| 1283 ((GaimBuddy*)bnode)->account == account) { | |
| 1284 ((GaimContact*)cnode)->currentsize++; | |
| 1285 if(((GaimContact*)cnode)->currentsize == 1) | |
| 1286 ((GaimGroup*)gnode)->currentsize++; | |
| 1287 if(GAIM_BUDDY_IS_ONLINE((GaimBuddy*)bnode)) { | |
| 1288 ((GaimContact*)cnode)->online++; | |
| 1289 if(((GaimContact*)cnode)->online == 1) | |
| 1290 ((GaimGroup*)gnode)->online++; | |
| 1291 } | |
| 1292 ops->update(gaimbuddylist, bnode); | |
| 1293 } | |
| 1294 } | |
| 6843 | 1295 gaim_contact_compute_priority_buddy((GaimContact*)cnode); |
| 6695 | 1296 ops->update(gaimbuddylist, cnode); |
| 1297 } else if(GAIM_BLIST_NODE_IS_CHAT(cnode) && | |
| 1298 ((GaimBlistChat*)cnode)->account == account) { | |
| 1299 ((GaimGroup *)gnode)->online++; | |
| 1300 ((GaimGroup *)gnode)->currentsize++; | |
| 1301 ops->update(gaimbuddylist, cnode); | |
| 5234 | 1302 } |
| 1303 } | |
| 6695 | 1304 ops->update(gaimbuddylist, gnode); |
| 5234 | 1305 } |
| 1306 } | |
| 1307 | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1308 void gaim_blist_remove_account(GaimAccount *account) |
| 5228 | 1309 { |
| 1310 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 6695 | 1311 GaimBlistNode *gnode, *cnode, *bnode; |
| 5234 | 1312 |
| 5228 | 1313 if (!gaimbuddylist) |
| 1314 return; | |
| 5234 | 1315 |
| 6695 | 1316 for(gnode = gaimbuddylist->root; gnode; gnode = gnode->next) { |
| 1317 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
| 5234 | 1318 continue; |
| 6695 | 1319 for(cnode = gnode->child; cnode; cnode = cnode->next) { |
| 1320 if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
| 1321 for(bnode = cnode->child; bnode; bnode = bnode->next) { | |
| 1322 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
| 1323 continue; | |
| 1324 if(account == ((GaimBuddy *)bnode)->account) { | |
| 1325 if(((GaimBuddy*)bnode)->present == GAIM_BUDDY_ONLINE || | |
| 1326 ((GaimBuddy*)bnode)->present == GAIM_BUDDY_SIGNING_ON) { | |
| 1327 ((GaimContact*)cnode)->online--; | |
| 1328 if(((GaimContact*)cnode)->online == 0) | |
| 1329 ((GaimGroup*)gnode)->online--; | |
| 1330 } | |
| 1331 ((GaimContact*)cnode)->currentsize--; | |
| 1332 if(((GaimContact*)cnode)->currentsize == 0) | |
| 1333 ((GaimGroup*)gnode)->currentsize--; | |
| 1334 | |
| 1335 ((GaimBuddy*)bnode)->present = GAIM_BUDDY_OFFLINE; | |
| 1336 | |
| 6803 | 1337 ((GaimBuddy*)bnode)->uc = 0; |
| 1338 ((GaimBuddy*)bnode)->idle = 0; | |
| 1339 ((GaimBuddy*)bnode)->evil = 0; | |
| 1340 | |
| 6695 | 1341 if(ops) |
| 1342 ops->remove(gaimbuddylist, bnode); | |
| 1343 } | |
| 5234 | 1344 } |
| 6843 | 1345 gaim_contact_compute_priority_buddy((GaimContact*)cnode); |
| 6695 | 1346 } else if(GAIM_BLIST_NODE_IS_CHAT(cnode) && |
| 1347 ((GaimBlistChat*)cnode)->account == account) { | |
| 1348 ((GaimGroup*)gnode)->currentsize--; | |
| 1349 ((GaimGroup*)gnode)->online--; | |
| 1350 if(ops) | |
| 1351 ops->remove(gaimbuddylist, cnode); | |
| 5228 | 1352 } |
| 1353 } | |
| 1354 } | |
| 1355 } | |
| 1356 | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1357 void parse_toc_buddy_list(GaimAccount *account, char *config) |
| 5228 | 1358 { |
| 1359 char *c; | |
| 1360 char current[256]; | |
| 1361 GList *bud = NULL; | |
| 1362 | |
| 1363 | |
| 1364 if (config != NULL) { | |
| 1365 | |
| 1366 /* skip "CONFIG:" (if it exists) */ | |
| 1367 c = strncmp(config + 6 /* sizeof(struct sflap_hdr) */ , "CONFIG:", strlen("CONFIG:")) ? | |
| 1368 strtok(config, "\n") : | |
| 1369 strtok(config + 6 /* sizeof(struct sflap_hdr) */ + strlen("CONFIG:"), "\n"); | |
| 1370 do { | |
| 1371 if (c == NULL) | |
| 1372 break; | |
| 1373 if (*c == 'g') { | |
| 1374 char *utf8 = NULL; | |
| 1375 utf8 = gaim_try_conv_to_utf8(c + 2); | |
| 1376 if (utf8 == NULL) { | |
| 1377 g_strlcpy(current, _("Invalid Groupname"), sizeof(current)); | |
| 1378 } else { | |
| 1379 g_strlcpy(current, utf8, sizeof(current)); | |
| 1380 g_free(utf8); | |
| 1381 } | |
| 1382 if (!gaim_find_group(current)) { | |
| 6695 | 1383 GaimGroup *g = gaim_group_new(current); |
| 5634 | 1384 gaim_blist_add_group(g, |
| 1385 gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
| 5228 | 1386 } |
| 1387 } else if (*c == 'b') { /*&& !gaim_find_buddy(user, c + 2)) {*/ | |
| 1388 char nm[80], sw[388], *a, *utf8 = NULL; | |
| 1389 | |
| 1390 if ((a = strchr(c + 2, ':')) != NULL) { | |
| 1391 *a++ = '\0'; /* nul the : */ | |
| 1392 } | |
| 1393 | |
| 1394 g_strlcpy(nm, c + 2, sizeof(nm)); | |
| 1395 if (a) { | |
| 1396 utf8 = gaim_try_conv_to_utf8(a); | |
| 1397 if (utf8 == NULL) { | |
| 1398 gaim_debug(GAIM_DEBUG_ERROR, "toc blist", | |
| 1399 "Failed to convert alias for " | |
| 1400 "'%s' to UTF-8\n", nm); | |
| 1401 } | |
| 1402 } | |
| 1403 if (utf8 == NULL) { | |
| 1404 sw[0] = '\0'; | |
| 1405 } else { | |
| 1406 /* This can leave a partial sequence at the end, | |
| 1407 * but who cares? */ | |
| 1408 g_strlcpy(sw, utf8, sizeof(sw)); | |
| 1409 g_free(utf8); | |
| 1410 } | |
| 1411 | |
| 1412 if (!gaim_find_buddy(account, nm)) { | |
| 6695 | 1413 GaimBuddy *b = gaim_buddy_new(account, nm, sw); |
| 1414 GaimGroup *g = gaim_find_group(current); | |
| 1415 gaim_blist_add_buddy(b, NULL, g, | |
| 5634 | 1416 gaim_blist_get_last_child((GaimBlistNode*)g)); |
| 5228 | 1417 bud = g_list_append(bud, g_strdup(nm)); |
| 1418 } | |
| 1419 } else if (*c == 'p') { | |
|
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
1420 gaim_privacy_permit_add(account, c + 2, TRUE); |
| 5228 | 1421 } else if (*c == 'd') { |
|
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
1422 gaim_privacy_deny_add(account, c + 2, TRUE); |
| 5228 | 1423 } else if (!strncmp("toc", c, 3)) { |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1424 sscanf(c + strlen(c) - 1, "%d", &account->perm_deny); |
| 5228 | 1425 gaim_debug(GAIM_DEBUG_MISC, "toc blist", |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1426 "permdeny: %d\n", account->perm_deny); |
|
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1427 if (account->perm_deny == 0) |
|
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1428 account->perm_deny = 1; |
| 5228 | 1429 } else if (*c == 'm') { |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1430 sscanf(c + 2, "%d", &account->perm_deny); |
| 5228 | 1431 gaim_debug(GAIM_DEBUG_MISC, "toc blist", |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1432 "permdeny: %d\n", account->perm_deny); |
|
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1433 if (account->perm_deny == 0) |
|
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1434 account->perm_deny = 1; |
| 5228 | 1435 } |
| 1436 } while ((c = strtok(NULL, "\n"))); | |
| 1437 | |
| 1438 if(account->gc) { | |
| 1439 if(bud) { | |
| 1440 GList *node = bud; | |
| 1441 serv_add_buddies(account->gc, bud); | |
| 1442 while(node) { | |
| 1443 g_free(node->data); | |
| 1444 node = node->next; | |
| 1445 } | |
| 1446 } | |
| 1447 serv_set_permit_deny(account->gc); | |
| 1448 } | |
| 1449 g_list_free(bud); | |
| 1450 } | |
| 1451 } | |
| 1452 | |
| 1453 #if 0 | |
| 1454 /* translate an AIM 3 buddylist (*.lst) to a Gaim buddylist */ | |
| 1455 static GString *translate_lst(FILE *src_fp) | |
| 1456 { | |
| 1457 char line[BUF_LEN], *line2; | |
| 1458 char *name; | |
| 1459 int i; | |
| 1460 | |
| 1461 GString *dest = g_string_new("m 1\n"); | |
| 1462 | |
| 1463 while (fgets(line, BUF_LEN, src_fp)) { | |
| 1464 line2 = g_strchug(line); | |
| 1465 if (strstr(line2, "group") == line2) { | |
| 1466 name = strpbrk(line2, " \t\n\r\f") + 1; | |
| 1467 dest = g_string_append(dest, "g "); | |
| 1468 for (i = 0; i < strcspn(name, "\n\r"); i++) | |
| 1469 if (name[i] != '\"') | |
| 1470 dest = g_string_append_c(dest, name[i]); | |
| 1471 dest = g_string_append_c(dest, '\n'); | |
| 1472 } | |
| 1473 if (strstr(line2, "buddy") == line2) { | |
| 1474 name = strpbrk(line2, " \t\n\r\f") + 1; | |
| 1475 dest = g_string_append(dest, "b "); | |
| 1476 for (i = 0; i < strcspn(name, "\n\r"); i++) | |
| 1477 if (name[i] != '\"') | |
| 1478 dest = g_string_append_c(dest, name[i]); | |
| 1479 dest = g_string_append_c(dest, '\n'); | |
| 1480 } | |
| 1481 } | |
| 1482 | |
| 1483 return dest; | |
| 1484 } | |
| 1485 | |
| 1486 | |
| 1487 /* translate an AIM 4 buddylist (*.blt) to Gaim format */ | |
| 1488 static GString *translate_blt(FILE *src_fp) | |
| 1489 { | |
| 1490 int i; | |
| 1491 char line[BUF_LEN]; | |
| 1492 char *buddy; | |
| 1493 | |
| 1494 GString *dest = g_string_new("m 1\n"); | |
| 1495 | |
| 1496 while (strstr(fgets(line, BUF_LEN, src_fp), "Buddy") == NULL); | |
| 1497 while (strstr(fgets(line, BUF_LEN, src_fp), "list") == NULL); | |
| 1498 | |
| 1499 while (1) { | |
| 1500 fgets(line, BUF_LEN, src_fp); g_strchomp(line); | |
| 1501 if (strchr(line, '}') != NULL) | |
| 1502 break; | |
| 1503 | |
| 1504 if (strchr(line, '{') != NULL) { | |
| 1505 /* Syntax starting with "<group> {" */ | |
| 1506 | |
| 1507 dest = g_string_append(dest, "g "); | |
| 1508 buddy = g_strchug(strtok(line, "{")); | |
| 1509 for (i = 0; i < strlen(buddy); i++) | |
| 1510 if (buddy[i] != '\"') | |
| 1511 dest = g_string_append_c(dest, buddy[i]); | |
| 1512 dest = g_string_append_c(dest, '\n'); | |
| 1513 while (strchr(fgets(line, BUF_LEN, src_fp), '}') == NULL) { | |
| 1514 gboolean pounce = FALSE; | |
| 1515 char *e; | |
| 1516 g_strchomp(line); | |
| 1517 buddy = g_strchug(line); | |
| 1518 gaim_debug(GAIM_DEBUG_MISC, "AIM 4 blt import", | |
| 1519 "buddy: \"%s\"\n", buddy); | |
| 1520 dest = g_string_append(dest, "b "); | |
| 1521 if (strchr(buddy, '{') != NULL) { | |
| 1522 /* buddy pounce, etc */ | |
| 1523 char *pos = strchr(buddy, '{') - 1; | |
| 1524 *pos = 0; | |
| 1525 pounce = TRUE; | |
| 1526 } | |
| 1527 if ((e = strchr(buddy, '\"')) != NULL) { | |
| 1528 *e = '\0'; | |
| 1529 buddy++; | |
| 1530 } | |
| 1531 dest = g_string_append(dest, buddy); | |
| 1532 dest = g_string_append_c(dest, '\n'); | |
| 1533 if (pounce) | |
| 1534 do | |
| 1535 fgets(line, BUF_LEN, src_fp); | |
| 1536 while (!strchr(line, '}')); | |
| 1537 } | |
| 1538 } else { | |
| 1539 | |
| 1540 /* Syntax "group buddy buddy ..." */ | |
| 1541 buddy = g_strchug(strtok(line, " \n")); | |
| 1542 dest = g_string_append(dest, "g "); | |
| 1543 if (strchr(buddy, '\"') != NULL) { | |
| 1544 dest = g_string_append(dest, &buddy[1]); | |
| 1545 dest = g_string_append_c(dest, ' '); | |
| 1546 buddy = g_strchug(strtok(NULL, " \n")); | |
| 1547 while (strchr(buddy, '\"') == NULL) { | |
| 1548 dest = g_string_append(dest, buddy); | |
| 1549 dest = g_string_append_c(dest, ' '); | |
| 1550 buddy = g_strchug(strtok(NULL, " \n")); | |
| 1551 } | |
| 1552 buddy[strlen(buddy) - 1] = '\0'; | |
| 1553 dest = g_string_append(dest, buddy); | |
| 1554 } else { | |
| 1555 dest = g_string_append(dest, buddy); | |
| 1556 } | |
| 1557 dest = g_string_append_c(dest, '\n'); | |
| 1558 while ((buddy = g_strchug(strtok(NULL, " \n"))) != NULL) { | |
| 1559 dest = g_string_append(dest, "b "); | |
| 1560 if (strchr(buddy, '\"') != NULL) { | |
| 1561 dest = g_string_append(dest, &buddy[1]); | |
| 1562 dest = g_string_append_c(dest, ' '); | |
| 1563 buddy = g_strchug(strtok(NULL, " \n")); | |
| 1564 while (strchr(buddy, '\"') == NULL) { | |
| 1565 dest = g_string_append(dest, buddy); | |
| 1566 dest = g_string_append_c(dest, ' '); | |
| 1567 buddy = g_strchug(strtok(NULL, " \n")); | |
| 1568 } | |
| 1569 buddy[strlen(buddy) - 1] = '\0'; | |
| 1570 dest = g_string_append(dest, buddy); | |
| 1571 } else { | |
| 1572 dest = g_string_append(dest, buddy); | |
| 1573 } | |
| 1574 dest = g_string_append_c(dest, '\n'); | |
| 1575 } | |
| 1576 } | |
| 1577 } | |
| 1578 | |
| 1579 return dest; | |
| 1580 } | |
| 1581 | |
| 1582 static GString *translate_gnomeicu(FILE *src_fp) | |
| 1583 { | |
| 1584 char line[BUF_LEN]; | |
| 1585 GString *dest = g_string_new("m 1\ng Buddies\n"); | |
| 1586 | |
| 1587 while (strstr(fgets(line, BUF_LEN, src_fp), "NewContacts") == NULL); | |
| 1588 | |
| 1589 while (fgets(line, BUF_LEN, src_fp)) { | |
| 1590 char *eq; | |
| 1591 g_strchomp(line); | |
| 1592 if (line[0] == '\n' || line[0] == '[') | |
| 1593 break; | |
| 1594 eq = strchr(line, '='); | |
| 1595 if (!eq) | |
| 1596 break; | |
| 1597 *eq = ':'; | |
| 1598 eq = strchr(eq, ','); | |
| 1599 if (eq) | |
| 1600 *eq = '\0'; | |
| 1601 dest = g_string_append(dest, "b "); | |
| 1602 dest = g_string_append(dest, line); | |
| 1603 dest = g_string_append_c(dest, '\n'); | |
| 1604 } | |
| 1605 | |
| 1606 return dest; | |
| 1607 } | |
| 1608 #endif | |
| 1609 | |
| 1610 static gchar *get_screenname_filename(const char *name) | |
| 1611 { | |
| 1612 gchar **split; | |
| 1613 gchar *good; | |
| 1614 gchar *ret; | |
| 1615 | |
| 1616 split = g_strsplit(name, G_DIR_SEPARATOR_S, -1); | |
| 1617 good = g_strjoinv(NULL, split); | |
| 1618 g_strfreev(split); | |
| 1619 | |
| 1620 ret = g_utf8_strup(good, -1); | |
| 1621 | |
| 1622 g_free(good); | |
| 1623 | |
| 1624 return ret; | |
| 1625 } | |
| 1626 | |
| 1627 static gboolean gaim_blist_read(const char *filename); | |
| 1628 | |
| 1629 | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1630 static void do_import(GaimAccount *account, const char *filename) |
| 5228 | 1631 { |
| 1632 GString *buf = NULL; | |
| 1633 char first[64]; | |
| 1634 char path[PATHSIZE]; | |
| 1635 int len; | |
| 1636 FILE *f; | |
| 1637 struct stat st; | |
| 1638 | |
| 1639 if (filename) { | |
| 1640 g_snprintf(path, sizeof(path), "%s", filename); | |
| 1641 } else { | |
| 1642 char *g_screenname = get_screenname_filename(account->username); | |
|
5943
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1643 const char *username; |
| 5228 | 1644 char *file = gaim_user_dir(); |
|
5943
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1645 GaimProtocol prpl_num; |
|
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1646 int protocol; |
| 6695 | 1647 |
|
5943
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1648 prpl_num = gaim_account_get_protocol(account); |
|
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1649 |
|
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1650 protocol = prpl_num; |
|
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1651 |
|
6450
e7b87c8e8c0a
[gaim-migrate @ 6959]
Christian Hammond <chipx86@chipx86.com>
parents:
6392
diff
changeset
|
1652 /* TODO Somehow move this checking into prpls */ |
|
5943
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1653 if (prpl_num == GAIM_PROTO_OSCAR) { |
|
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1654 if ((username = gaim_account_get_username(account)) != NULL) { |
|
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1655 protocol = (isalpha(*username) |
|
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1656 ? GAIM_PROTO_TOC : GAIM_PROTO_ICQ); |
|
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1657 } |
|
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1658 } |
| 5228 | 1659 |
| 1660 if (file != (char *)NULL) { | |
| 5435 | 1661 snprintf(path, PATHSIZE, "%s" G_DIR_SEPARATOR_S "%s.%d.blist", file, g_screenname, protocol); |
| 5228 | 1662 g_free(g_screenname); |
| 1663 } else { | |
| 1664 g_free(g_screenname); | |
| 1665 return; | |
| 1666 } | |
| 1667 } | |
| 1668 | |
| 1669 if (stat(path, &st)) { | |
| 1670 gaim_debug(GAIM_DEBUG_ERROR, "blist import", "Unable to stat %s.\n", | |
| 1671 path); | |
| 1672 return; | |
| 1673 } | |
| 1674 | |
| 1675 if (!(f = fopen(path, "r"))) { | |
| 1676 gaim_debug(GAIM_DEBUG_ERROR, "blist import", "Unable to open %s.\n", | |
| 1677 path); | |
| 1678 return; | |
| 1679 } | |
| 1680 | |
| 1681 fgets(first, 64, f); | |
| 1682 | |
| 1683 if ((first[0] == '\n') || (first[0] == '\r' && first[1] == '\n')) | |
| 1684 fgets(first, 64, f); | |
| 1685 | |
| 1686 #if 0 | |
| 1687 if (!g_strncasecmp(first, "<xml", strlen("<xml"))) { | |
| 1688 /* new gaim XML buddy list */ | |
| 1689 gaim_blist_read(path); | |
| 1690 | |
| 1691 /* We really don't need to bother doing stuf like translating AIM 3 buddy lists anymore */ | |
| 1692 | |
| 1693 } else if (!g_strncasecmp(first, "Config {", strlen("Config {"))) { | |
| 1694 /* AIM 4 buddy list */ | |
| 1695 gaim_debug(GAIM_DEBUG_MISC, "blist import", "aim 4\n"); | |
| 1696 rewind(f); | |
| 1697 buf = translate_blt(f); | |
| 1698 } else if (strstr(first, "group") != NULL) { | |
| 1699 /* AIM 3 buddy list */ | |
| 1700 gaim_debug(GAIM_DEBUG_MISC, "blist import", "aim 3\n"); | |
| 1701 rewind(f); | |
| 1702 buf = translate_lst(f); | |
| 1703 } else if (!g_strncasecmp(first, "[User]", strlen("[User]"))) { | |
| 1704 /* GnomeICU (hopefully) */ | |
| 1705 gaim_debug(GAIM_DEBUG_MISC, "blist import", "gnomeicu\n"); | |
| 1706 rewind(f); | |
| 1707 buf = translate_gnomeicu(f); | |
| 1708 | |
| 1709 } else | |
| 1710 #endif | |
| 1711 if (first[0] == 'm') { | |
| 1712 /* Gaim buddy list - no translation */ | |
| 1713 char buf2[BUF_LONG * 2]; | |
| 1714 buf = g_string_new(""); | |
| 1715 rewind(f); | |
| 1716 while (1) { | |
| 1717 len = fread(buf2, 1, BUF_LONG * 2 - 1, f); | |
| 1718 if (len <= 0) | |
| 1719 break; | |
| 1720 buf2[len] = '\0'; | |
| 1721 buf = g_string_append(buf, buf2); | |
| 1722 if (len != BUF_LONG * 2 - 1) | |
| 1723 break; | |
| 1724 } | |
| 1725 } | |
| 1726 | |
| 1727 fclose(f); | |
| 1728 | |
| 1729 if (buf) { | |
| 1730 buf = g_string_prepend(buf, "toc_set_config {"); | |
| 1731 buf = g_string_append(buf, "}\n"); | |
| 1732 parse_toc_buddy_list(account, buf->str); | |
| 1733 g_string_free(buf, TRUE); | |
| 1734 } | |
| 1735 } | |
| 1736 | |
| 6695 | 1737 gboolean gaim_group_on_account(GaimGroup *g, GaimAccount *account) { |
| 1738 GaimBlistNode *cnode, *bnode; | |
| 1739 for(cnode = ((GaimBlistNode *)g)->child; cnode; cnode = cnode->next) { | |
| 1740 if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
| 1741 for(bnode = cnode->child; bnode; bnode = bnode->next) { | |
| 1742 if(GAIM_BLIST_NODE_IS_BUDDY(bnode)) { | |
| 1743 GaimBuddy *buddy = (GaimBuddy *)bnode; | |
| 1744 if((!account && gaim_account_is_connected(buddy->account)) | |
| 1745 || buddy->account == account) | |
| 1746 return TRUE; | |
| 1747 } | |
| 1748 } | |
| 1749 } else if(GAIM_BLIST_NODE_IS_CHAT(cnode)) { | |
| 1750 GaimBlistChat *chat = (GaimBlistChat *)cnode; | |
| 1751 if((!account && gaim_account_is_connected(chat->account)) | |
| 1752 || chat->account == account) | |
| 1753 return TRUE; | |
| 1754 } | |
| 5228 | 1755 } |
| 1756 return FALSE; | |
| 1757 } | |
| 1758 | |
| 1759 static gboolean blist_safe_to_write = FALSE; | |
| 1760 | |
| 6695 | 1761 GaimGroup *blist_parser_group = NULL; |
| 1762 GaimContact *blist_parser_contact = NULL; | |
| 5228 | 1763 static char *blist_parser_account_name = NULL; |
| 1764 static int blist_parser_account_protocol = 0; | |
| 5234 | 1765 static char *blist_parser_chat_alias = NULL; |
| 1766 static char *blist_parser_component_name = NULL; | |
| 1767 static char *blist_parser_component_value = NULL; | |
| 5228 | 1768 static char *blist_parser_buddy_name = NULL; |
| 1769 static char *blist_parser_buddy_alias = NULL; | |
| 1770 static char *blist_parser_setting_name = NULL; | |
| 1771 static char *blist_parser_setting_value = NULL; | |
| 1772 static GHashTable *blist_parser_buddy_settings = NULL; | |
| 5906 | 1773 static GHashTable *blist_parser_chat_settings = NULL; |
| 5228 | 1774 static GHashTable *blist_parser_group_settings = NULL; |
| 5234 | 1775 static GHashTable *blist_parser_chat_components = NULL; |
| 5228 | 1776 static int blist_parser_privacy_mode = 0; |
| 1777 static GList *tag_stack = NULL; | |
| 1778 enum { | |
| 1779 BLIST_TAG_GAIM, | |
| 1780 BLIST_TAG_BLIST, | |
| 1781 BLIST_TAG_GROUP, | |
| 5234 | 1782 BLIST_TAG_CHAT, |
| 1783 BLIST_TAG_COMPONENT, | |
| 6695 | 1784 BLIST_TAG_CONTACT, |
| 5228 | 1785 BLIST_TAG_BUDDY, |
| 1786 BLIST_TAG_NAME, | |
| 1787 BLIST_TAG_ALIAS, | |
| 1788 BLIST_TAG_SETTING, | |
| 1789 BLIST_TAG_PRIVACY, | |
| 1790 BLIST_TAG_ACCOUNT, | |
| 1791 BLIST_TAG_PERMIT, | |
| 1792 BLIST_TAG_BLOCK, | |
| 1793 BLIST_TAG_IGNORE | |
| 1794 }; | |
| 1795 static gboolean blist_parser_error_occurred = FALSE; | |
| 1796 | |
| 1797 static void blist_start_element_handler (GMarkupParseContext *context, | |
| 1798 const gchar *element_name, | |
| 1799 const gchar **attribute_names, | |
| 1800 const gchar **attribute_values, | |
| 1801 gpointer user_data, | |
| 1802 GError **error) { | |
| 1803 int i; | |
| 1804 | |
| 1805 if(!strcmp(element_name, "gaim")) { | |
| 1806 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_GAIM)); | |
| 1807 } else if(!strcmp(element_name, "blist")) { | |
| 1808 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_BLIST)); | |
| 1809 } else if(!strcmp(element_name, "group")) { | |
| 6803 | 1810 const char *name = NULL; |
| 5228 | 1811 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_GROUP)); |
| 1812 for(i=0; attribute_names[i]; i++) { | |
| 1813 if(!strcmp(attribute_names[i], "name")) { | |
| 6778 | 1814 name = attribute_values[i]; |
| 5228 | 1815 } |
| 1816 } | |
| 6778 | 1817 if(name) { |
| 1818 blist_parser_group = gaim_group_new(name); | |
| 6695 | 1819 gaim_blist_add_group(blist_parser_group, |
| 5634 | 1820 gaim_blist_get_last_sibling(gaimbuddylist->root)); |
| 5228 | 1821 } |
| 6695 | 1822 } else if(!strcmp(element_name, "contact")) { |
| 6755 | 1823 char *alias = NULL; |
| 6695 | 1824 tag_stack = g_list_prepend(tag_stack, |
| 1825 GINT_TO_POINTER(BLIST_TAG_CONTACT)); | |
| 1826 | |
| 6755 | 1827 for(i=0; attribute_names[i]; i++) { |
| 1828 if(!strcmp(attribute_names[i], "alias")) { | |
| 1829 g_free(alias); | |
| 1830 alias = g_strdup(attribute_values[i]); | |
| 1831 } | |
| 1832 } | |
| 1833 | |
| 6695 | 1834 blist_parser_contact = gaim_contact_new(); |
| 1835 gaim_blist_add_contact(blist_parser_contact, blist_parser_group, | |
| 1836 gaim_blist_get_last_sibling(((GaimBlistNode*)blist_parser_group)->child)); | |
| 6755 | 1837 |
| 1838 if(alias) { | |
| 1839 gaim_contact_set_alias(blist_parser_contact, alias); | |
| 1840 g_free(alias); | |
| 1841 } | |
| 5234 | 1842 } else if(!strcmp(element_name, "chat")) { |
| 1843 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_CHAT)); | |
| 1844 for(i=0; attribute_names[i]; i++) { | |
| 1845 if(!strcmp(attribute_names[i], "account")) { | |
| 1846 g_free(blist_parser_account_name); | |
| 1847 blist_parser_account_name = g_strdup(attribute_values[i]); | |
| 1848 } else if(!strcmp(attribute_names[i], "protocol")) { | |
| 1849 blist_parser_account_protocol = atoi(attribute_values[i]); | |
| 1850 } | |
| 1851 } | |
| 5228 | 1852 } else if(!strcmp(element_name, "buddy")) { |
| 1853 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_BUDDY)); | |
| 1854 for(i=0; attribute_names[i]; i++) { | |
| 1855 if(!strcmp(attribute_names[i], "account")) { | |
| 1856 g_free(blist_parser_account_name); | |
| 1857 blist_parser_account_name = g_strdup(attribute_values[i]); | |
| 1858 } else if(!strcmp(attribute_names[i], "protocol")) { | |
| 1859 blist_parser_account_protocol = atoi(attribute_values[i]); | |
| 1860 } | |
| 1861 } | |
| 1862 } else if(!strcmp(element_name, "name")) { | |
| 1863 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_NAME)); | |
| 1864 } else if(!strcmp(element_name, "alias")) { | |
| 1865 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_ALIAS)); | |
| 1866 } else if(!strcmp(element_name, "setting")) { | |
| 1867 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_SETTING)); | |
| 1868 for(i=0; attribute_names[i]; i++) { | |
| 1869 if(!strcmp(attribute_names[i], "name")) { | |
| 1870 g_free(blist_parser_setting_name); | |
| 1871 blist_parser_setting_name = g_strdup(attribute_values[i]); | |
| 1872 } | |
| 1873 } | |
| 5234 | 1874 } else if(!strcmp(element_name, "component")) { |
| 1875 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_COMPONENT)); | |
| 1876 for(i=0; attribute_names[i]; i++) { | |
| 1877 if(!strcmp(attribute_names[i], "name")) { | |
| 1878 g_free(blist_parser_component_name); | |
| 1879 blist_parser_component_name = g_strdup(attribute_values[i]); | |
| 1880 } | |
| 1881 } | |
| 1882 | |
| 5228 | 1883 } else if(!strcmp(element_name, "privacy")) { |
| 1884 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_PRIVACY)); | |
| 1885 } else if(!strcmp(element_name, "account")) { | |
| 1886 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_ACCOUNT)); | |
| 1887 for(i=0; attribute_names[i]; i++) { | |
| 1888 if(!strcmp(attribute_names[i], "protocol")) | |
| 1889 blist_parser_account_protocol = atoi(attribute_values[i]); | |
| 1890 else if(!strcmp(attribute_names[i], "mode")) | |
| 1891 blist_parser_privacy_mode = atoi(attribute_values[i]); | |
| 1892 else if(!strcmp(attribute_names[i], "name")) { | |
| 1893 g_free(blist_parser_account_name); | |
| 1894 blist_parser_account_name = g_strdup(attribute_values[i]); | |
| 1895 } | |
| 1896 } | |
| 1897 } else if(!strcmp(element_name, "permit")) { | |
| 1898 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_PERMIT)); | |
| 1899 } else if(!strcmp(element_name, "block")) { | |
| 1900 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_BLOCK)); | |
| 1901 } else if(!strcmp(element_name, "ignore")) { | |
| 1902 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_IGNORE)); | |
| 1903 } | |
| 1904 } | |
| 1905 | |
| 1906 static void blist_end_element_handler(GMarkupParseContext *context, | |
| 1907 const gchar *element_name, gpointer user_data, GError **error) { | |
| 1908 if(!strcmp(element_name, "gaim")) { | |
| 1909 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1910 } else if(!strcmp(element_name, "blist")) { | |
| 1911 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1912 } else if(!strcmp(element_name, "group")) { | |
| 1913 if(blist_parser_group_settings) { | |
| 6778 | 1914 g_hash_table_destroy(blist_parser_group->settings); |
| 1915 blist_parser_group->settings = blist_parser_group_settings; | |
| 5228 | 1916 } |
| 1917 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1918 blist_parser_group_settings = NULL; | |
| 6695 | 1919 blist_parser_group = NULL; |
| 5234 | 1920 } else if(!strcmp(element_name, "chat")) { |
|
5874
964e4f94fc56
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1921 GaimAccount *account = gaim_accounts_find(blist_parser_account_name, |
| 5234 | 1922 blist_parser_account_protocol); |
| 5237 | 1923 if(account) { |
| 6695 | 1924 GaimBlistChat *chat = gaim_blist_chat_new(account, |
| 1925 blist_parser_chat_alias, blist_parser_chat_components); | |
| 6778 | 1926 gaim_blist_add_chat(chat,blist_parser_group, |
| 1927 gaim_blist_get_last_child((GaimBlistNode*)blist_parser_group)); | |
| 5906 | 1928 if(blist_parser_chat_settings) { |
| 1929 g_hash_table_destroy(chat->settings); | |
| 1930 chat->settings = blist_parser_chat_settings; | |
| 1931 } | |
| 5234 | 1932 } |
| 1933 g_free(blist_parser_chat_alias); | |
| 1934 blist_parser_chat_alias = NULL; | |
| 1935 g_free(blist_parser_account_name); | |
| 1936 blist_parser_account_name = NULL; | |
| 1937 blist_parser_chat_components = NULL; | |
| 5906 | 1938 blist_parser_chat_settings = NULL; |
| 5234 | 1939 tag_stack = g_list_delete_link(tag_stack, tag_stack); |
| 6695 | 1940 } else if(!strcmp(element_name, "contact")) { |
| 1941 if(blist_parser_contact && !blist_parser_contact->node.child) | |
| 1942 gaim_blist_remove_contact(blist_parser_contact); | |
| 1943 blist_parser_contact = NULL; | |
| 5228 | 1944 tag_stack = g_list_delete_link(tag_stack, tag_stack); |
| 1945 } else if(!strcmp(element_name, "buddy")) { | |
|
5874
964e4f94fc56
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1946 GaimAccount *account = gaim_accounts_find(blist_parser_account_name, |
| 5228 | 1947 blist_parser_account_protocol); |
| 1948 if(account) { | |
| 6695 | 1949 GaimBuddy *b = gaim_buddy_new(account, blist_parser_buddy_name, blist_parser_buddy_alias); |
| 1950 gaim_blist_add_buddy(b,blist_parser_contact, blist_parser_group, | |
| 1951 gaim_blist_get_last_child((GaimBlistNode*)blist_parser_contact)); | |
| 5228 | 1952 if(blist_parser_buddy_settings) { |
| 1953 g_hash_table_destroy(b->settings); | |
| 1954 b->settings = blist_parser_buddy_settings; | |
| 1955 } | |
| 1956 } | |
| 1957 g_free(blist_parser_buddy_name); | |
| 1958 blist_parser_buddy_name = NULL; | |
| 1959 g_free(blist_parser_buddy_alias); | |
| 1960 blist_parser_buddy_alias = NULL; | |
| 1961 g_free(blist_parser_account_name); | |
| 1962 blist_parser_account_name = NULL; | |
| 1963 blist_parser_buddy_settings = NULL; | |
| 1964 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1965 } else if(!strcmp(element_name, "name")) { | |
| 1966 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1967 } else if(!strcmp(element_name, "alias")) { | |
| 1968 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 5234 | 1969 } else if(!strcmp(element_name, "component")) { |
| 1970 if(!blist_parser_chat_components) | |
| 1971 blist_parser_chat_components = g_hash_table_new_full(g_str_hash, | |
| 1972 g_str_equal, g_free, g_free); | |
| 1973 if(blist_parser_component_name && blist_parser_component_value) { | |
| 1974 g_hash_table_replace(blist_parser_chat_components, | |
| 1975 g_strdup(blist_parser_component_name), | |
| 1976 g_strdup(blist_parser_component_value)); | |
| 1977 } | |
| 1978 g_free(blist_parser_component_name); | |
| 1979 g_free(blist_parser_component_value); | |
| 1980 blist_parser_component_name = NULL; | |
| 1981 blist_parser_component_value = NULL; | |
| 1982 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 5228 | 1983 } else if(!strcmp(element_name, "setting")) { |
| 1984 if(GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_BUDDY) { | |
| 1985 if(!blist_parser_buddy_settings) | |
| 1986 blist_parser_buddy_settings = g_hash_table_new_full(g_str_hash, | |
| 1987 g_str_equal, g_free, g_free); | |
| 1988 if(blist_parser_setting_name && blist_parser_setting_value) { | |
| 1989 g_hash_table_replace(blist_parser_buddy_settings, | |
| 1990 g_strdup(blist_parser_setting_name), | |
| 1991 g_strdup(blist_parser_setting_value)); | |
| 1992 } | |
| 5906 | 1993 } else if(GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_CHAT) { |
| 1994 if(!blist_parser_chat_settings) | |
| 1995 blist_parser_chat_settings = g_hash_table_new_full(g_str_hash, | |
| 1996 g_str_equal, g_free, g_free); | |
| 1997 if(blist_parser_setting_name && blist_parser_setting_value) { | |
| 6307 | 1998 g_hash_table_replace(blist_parser_chat_settings, |
| 5906 | 1999 g_strdup(blist_parser_setting_name), |
| 2000 g_strdup(blist_parser_setting_value)); | |
| 2001 } | |
| 5228 | 2002 } else if(GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_GROUP) { |
| 2003 if(!blist_parser_group_settings) | |
| 2004 blist_parser_group_settings = g_hash_table_new_full(g_str_hash, | |
| 2005 g_str_equal, g_free, g_free); | |
| 2006 if(blist_parser_setting_name && blist_parser_setting_value) { | |
| 2007 g_hash_table_replace(blist_parser_group_settings, | |
| 2008 g_strdup(blist_parser_setting_name), | |
| 2009 g_strdup(blist_parser_setting_value)); | |
| 2010 } | |
| 2011 } | |
| 2012 g_free(blist_parser_setting_name); | |
| 2013 g_free(blist_parser_setting_value); | |
| 2014 blist_parser_setting_name = NULL; | |
| 2015 blist_parser_setting_value = NULL; | |
| 2016 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 2017 } else if(!strcmp(element_name, "privacy")) { | |
| 2018 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 2019 } else if(!strcmp(element_name, "account")) { | |
|
5874
964e4f94fc56
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
2020 GaimAccount *account = gaim_accounts_find(blist_parser_account_name, |
| 5228 | 2021 blist_parser_account_protocol); |
| 2022 if(account) { | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
2023 account->perm_deny = blist_parser_privacy_mode; |
| 5228 | 2024 } |
| 2025 g_free(blist_parser_account_name); | |
| 2026 blist_parser_account_name = NULL; | |
| 2027 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 2028 } else if(!strcmp(element_name, "permit")) { | |
|
5874
964e4f94fc56
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
2029 GaimAccount *account = gaim_accounts_find(blist_parser_account_name, |
| 5228 | 2030 blist_parser_account_protocol); |
| 2031 if(account) { | |
|
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
2032 gaim_privacy_permit_add(account, blist_parser_buddy_name, TRUE); |
| 5228 | 2033 } |
| 2034 g_free(blist_parser_buddy_name); | |
| 2035 blist_parser_buddy_name = NULL; | |
| 2036 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 2037 } else if(!strcmp(element_name, "block")) { | |
|
5874
964e4f94fc56
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
2038 GaimAccount *account = gaim_accounts_find(blist_parser_account_name, |
| 5228 | 2039 blist_parser_account_protocol); |
| 2040 if(account) { | |
|
6378
01289157fc37
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
2041 gaim_privacy_deny_add(account, blist_parser_buddy_name, TRUE); |
| 5228 | 2042 } |
| 2043 g_free(blist_parser_buddy_name); | |
| 2044 blist_parser_buddy_name = NULL; | |
| 2045 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 2046 } else if(!strcmp(element_name, "ignore")) { | |
| 2047 /* we'll apparently do something with this later */ | |
| 2048 tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 2049 } | |
| 2050 } | |
| 2051 | |
| 2052 static void blist_text_handler(GMarkupParseContext *context, const gchar *text, | |
| 2053 gsize text_len, gpointer user_data, GError **error) { | |
| 2054 switch(GPOINTER_TO_INT(tag_stack->data)) { | |
| 2055 case BLIST_TAG_NAME: | |
| 2056 blist_parser_buddy_name = g_strndup(text, text_len); | |
| 2057 break; | |
| 2058 case BLIST_TAG_ALIAS: | |
| 5234 | 2059 if(tag_stack->next && |
| 2060 GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_BUDDY) | |
| 2061 blist_parser_buddy_alias = g_strndup(text, text_len); | |
| 2062 else if(tag_stack->next && | |
| 2063 GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_CHAT) | |
| 2064 blist_parser_chat_alias = g_strndup(text, text_len); | |
| 5228 | 2065 break; |
| 2066 case BLIST_TAG_PERMIT: | |
| 2067 case BLIST_TAG_BLOCK: | |
| 2068 case BLIST_TAG_IGNORE: | |
| 2069 blist_parser_buddy_name = g_strndup(text, text_len); | |
| 2070 break; | |
| 5234 | 2071 case BLIST_TAG_COMPONENT: |
| 2072 blist_parser_component_value = g_strndup(text, text_len); | |
| 2073 break; | |
| 5228 | 2074 case BLIST_TAG_SETTING: |
| 2075 blist_parser_setting_value = g_strndup(text, text_len); | |
| 2076 break; | |
| 2077 default: | |
| 2078 break; | |
| 2079 } | |
| 2080 } | |
| 2081 | |
| 2082 static void blist_error_handler(GMarkupParseContext *context, GError *error, | |
| 2083 gpointer user_data) { | |
| 2084 blist_parser_error_occurred = TRUE; | |
| 2085 gaim_debug(GAIM_DEBUG_ERROR, "blist import", | |
| 2086 "Error parsing blist.xml: %s\n", error->message); | |
| 2087 } | |
| 2088 | |
| 2089 static GMarkupParser blist_parser = { | |
| 2090 blist_start_element_handler, | |
| 2091 blist_end_element_handler, | |
| 2092 blist_text_handler, | |
| 2093 NULL, | |
| 2094 blist_error_handler | |
| 2095 }; | |
| 2096 | |
| 2097 static gboolean gaim_blist_read(const char *filename) { | |
| 2098 gchar *contents = NULL; | |
| 2099 gsize length; | |
| 2100 GMarkupParseContext *context; | |
| 2101 GError *error = NULL; | |
| 2102 | |
| 2103 gaim_debug(GAIM_DEBUG_INFO, "blist import", | |
| 2104 "Reading %s\n", filename); | |
| 2105 if(!g_file_get_contents(filename, &contents, &length, &error)) { | |
| 2106 gaim_debug(GAIM_DEBUG_ERROR, "blist import", | |
| 2107 "Error reading blist: %s\n", error->message); | |
| 2108 g_error_free(error); | |
| 2109 return FALSE; | |
| 2110 } | |
| 2111 | |
| 2112 context = g_markup_parse_context_new(&blist_parser, 0, NULL, NULL); | |
| 2113 | |
| 2114 if(!g_markup_parse_context_parse(context, contents, length, NULL)) { | |
| 2115 g_markup_parse_context_free(context); | |
| 2116 g_free(contents); | |
| 2117 return FALSE; | |
| 2118 } | |
| 2119 | |
| 2120 if(!g_markup_parse_context_end_parse(context, NULL)) { | |
| 2121 gaim_debug(GAIM_DEBUG_ERROR, "blist import", | |
| 2122 "Error parsing %s\n", filename); | |
| 2123 g_markup_parse_context_free(context); | |
| 2124 g_free(contents); | |
| 2125 return FALSE; | |
| 2126 } | |
| 2127 | |
| 2128 g_markup_parse_context_free(context); | |
| 2129 g_free(contents); | |
| 2130 | |
| 2131 if(blist_parser_error_occurred) | |
| 2132 return FALSE; | |
| 2133 | |
| 2134 gaim_debug(GAIM_DEBUG_INFO, "blist import", "Finished reading %s\n", | |
| 2135 filename); | |
| 2136 | |
| 2137 return TRUE; | |
| 2138 } | |
| 2139 | |
| 2140 void gaim_blist_load() { | |
|
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
2141 GList *accts; |
| 5228 | 2142 char *user_dir = gaim_user_dir(); |
| 2143 char *filename; | |
| 2144 char *msg; | |
| 2145 | |
| 2146 blist_safe_to_write = TRUE; | |
| 2147 | |
| 2148 if(!user_dir) | |
| 2149 return; | |
| 2150 | |
| 2151 filename = g_build_filename(user_dir, "blist.xml", NULL); | |
| 2152 | |
| 2153 if(g_file_test(filename, G_FILE_TEST_EXISTS)) { | |
| 2154 if(!gaim_blist_read(filename)) { | |
| 2155 msg = g_strdup_printf(_("An error was encountered parsing your " | |
| 2156 "buddy list. It has not been loaded.")); | |
|
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
2157 gaim_notify_error(NULL, NULL, _("Buddy List Error"), msg); |
| 5228 | 2158 g_free(msg); |
| 2159 } | |
|
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
2160 } else if(g_list_length(gaim_accounts_get_all())) { |
| 5228 | 2161 /* read in the old lists, then save to the new format */ |
|
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
2162 for(accts = gaim_accounts_get_all(); accts; accts = accts->next) { |
| 5228 | 2163 do_import(accts->data, NULL); |
| 2164 } | |
| 2165 gaim_blist_save(); | |
| 2166 } | |
| 2167 | |
| 2168 g_free(filename); | |
| 2169 } | |
| 2170 | |
| 2171 static void blist_print_group_settings(gpointer key, gpointer data, | |
| 2172 gpointer user_data) { | |
| 2173 char *key_val; | |
| 2174 char *data_val; | |
| 2175 FILE *file = user_data; | |
| 2176 | |
| 2177 if(!key || !data) | |
| 2178 return; | |
| 2179 | |
| 2180 key_val = g_markup_escape_text(key, -1); | |
| 2181 data_val = g_markup_escape_text(data, -1); | |
| 2182 | |
| 2183 fprintf(file, "\t\t\t<setting name=\"%s\">%s</setting>\n", key_val, | |
| 2184 data_val); | |
| 2185 g_free(key_val); | |
| 2186 g_free(data_val); | |
| 2187 } | |
| 2188 | |
| 2189 static void blist_print_buddy_settings(gpointer key, gpointer data, | |
| 2190 gpointer user_data) { | |
| 2191 char *key_val; | |
| 2192 char *data_val; | |
| 2193 FILE *file = user_data; | |
| 2194 | |
| 2195 if(!key || !data) | |
| 2196 return; | |
| 2197 | |
| 2198 key_val = g_markup_escape_text(key, -1); | |
| 2199 data_val = g_markup_escape_text(data, -1); | |
| 2200 | |
| 2201 fprintf(file, "\t\t\t\t\t<setting name=\"%s\">%s</setting>\n", key_val, | |
| 2202 data_val); | |
| 2203 g_free(key_val); | |
| 2204 g_free(data_val); | |
| 2205 } | |
| 2206 | |
| 6695 | 2207 static void blist_print_cnode_settings(gpointer key, gpointer data, |
| 2208 gpointer user_data) { | |
| 2209 char *key_val; | |
| 2210 char *data_val; | |
| 2211 FILE *file = user_data; | |
| 2212 | |
| 2213 if(!key || !data) | |
| 2214 return; | |
| 2215 | |
| 2216 key_val = g_markup_escape_text(key, -1); | |
| 2217 data_val = g_markup_escape_text(data, -1); | |
| 2218 | |
| 2219 fprintf(file, "\t\t\t\t<setting name=\"%s\">%s</setting>\n", key_val, | |
| 2220 data_val); | |
| 2221 g_free(key_val); | |
| 2222 g_free(data_val); | |
| 2223 } | |
| 2224 | |
| 5234 | 2225 static void blist_print_chat_components(gpointer key, gpointer data, |
| 2226 gpointer user_data) { | |
| 2227 char *key_val; | |
| 2228 char *data_val; | |
| 2229 FILE *file = user_data; | |
| 2230 | |
| 2231 if(!key || !data) | |
| 2232 return; | |
| 2233 | |
| 2234 key_val = g_markup_escape_text(key, -1); | |
| 2235 data_val = g_markup_escape_text(data, -1); | |
| 2236 | |
| 2237 fprintf(file, "\t\t\t\t<component name=\"%s\">%s</component>\n", key_val, | |
| 2238 data_val); | |
| 2239 g_free(key_val); | |
| 2240 g_free(data_val); | |
| 2241 } | |
| 2242 | |
| 6695 | 2243 static void print_buddy(FILE *file, GaimBuddy *buddy) { |
| 2244 char *bud_name = g_markup_escape_text(buddy->name, -1); | |
| 2245 char *bud_alias = NULL; | |
| 2246 char *acct_name = g_markup_escape_text(buddy->account->username, -1); | |
| 2247 if(buddy->alias) | |
| 2248 bud_alias= g_markup_escape_text(buddy->alias, -1); | |
| 2249 fprintf(file, "\t\t\t\t<buddy protocol=\"%d\" " | |
| 2250 "account=\"%s\">\n", | |
| 2251 gaim_account_get_protocol(buddy->account), | |
| 2252 acct_name); | |
| 2253 fprintf(file, "\t\t\t\t\t<name>%s</name>\n", bud_name); | |
| 2254 if(bud_alias) { | |
| 2255 fprintf(file, "\t\t\t\t\t<alias>%s</alias>\n", bud_alias); | |
| 2256 } | |
| 2257 g_hash_table_foreach(buddy->settings, blist_print_buddy_settings, file); | |
| 2258 fprintf(file, "\t\t\t\t</buddy>\n"); | |
| 2259 g_free(bud_name); | |
| 2260 g_free(bud_alias); | |
| 2261 g_free(acct_name); | |
| 2262 } | |
| 2263 | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
2264 static void gaim_blist_write(FILE *file, GaimAccount *exp_acct) { |
|
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
2265 GList *accounts; |
|
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
2266 GSList *buds; |
| 6695 | 2267 GaimBlistNode *gnode, *cnode, *bnode; |
| 5228 | 2268 fprintf(file, "<?xml version='1.0' encoding='UTF-8' ?>\n"); |
| 2269 fprintf(file, "<gaim version=\"1\">\n"); | |
| 2270 fprintf(file, "\t<blist>\n"); | |
| 2271 | |
| 2272 for(gnode = gaimbuddylist->root; gnode; gnode = gnode->next) { | |
| 6695 | 2273 GaimGroup *group; |
| 2274 | |
| 5228 | 2275 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) |
| 2276 continue; | |
| 6695 | 2277 |
| 2278 group = (GaimGroup *)gnode; | |
| 5228 | 2279 if(!exp_acct || gaim_group_on_account(group, exp_acct)) { |
| 2280 char *group_name = g_markup_escape_text(group->name, -1); | |
| 2281 fprintf(file, "\t\t<group name=\"%s\">\n", group_name); | |
| 2282 g_hash_table_foreach(group->settings, blist_print_group_settings, file); | |
| 6695 | 2283 for(cnode = gnode->child; cnode; cnode = cnode->next) { |
| 2284 if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
| 6755 | 2285 GaimContact *contact = (GaimContact*)cnode; |
| 2286 fprintf(file, "\t\t\t<contact"); | |
| 2287 if(contact->alias) { | |
| 2288 char *alias = g_markup_escape_text(contact->alias, -1); | |
| 2289 fprintf(file, " alias=\"%s\"", alias); | |
| 2290 g_free(alias); | |
| 2291 } | |
| 2292 fprintf(file, ">\n"); | |
| 6695 | 2293 |
| 2294 for(bnode = cnode->child; bnode; bnode = bnode->next) { | |
| 2295 if(GAIM_BLIST_NODE_IS_BUDDY(bnode)) { | |
| 2296 GaimBuddy *buddy = (GaimBuddy *)bnode; | |
| 2297 if(!exp_acct || buddy->account == exp_acct) { | |
| 2298 print_buddy(file, buddy); | |
| 2299 } | |
| 5234 | 2300 } |
| 5228 | 2301 } |
| 6695 | 2302 |
| 2303 fprintf(file, "\t\t\t</contact>\n"); | |
| 2304 } else if(GAIM_BLIST_NODE_IS_CHAT(cnode)) { | |
| 2305 GaimBlistChat *chat = (GaimBlistChat *)cnode; | |
| 5234 | 2306 if(!exp_acct || chat->account == exp_acct) { |
| 2307 char *acct_name = g_markup_escape_text(chat->account->username, -1); | |
|
5943
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
2308 fprintf(file, "\t\t\t<chat protocol=\"%d\" account=\"%s\">\n", |
|
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
2309 gaim_account_get_protocol(chat->account), |
|
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
2310 acct_name); |
| 5237 | 2311 if(chat->alias) { |
| 2312 char *chat_alias = g_markup_escape_text(chat->alias, -1); | |
| 2313 fprintf(file, "\t\t\t\t<alias>%s</alias>\n", chat_alias); | |
| 2314 g_free(chat_alias); | |
| 2315 } | |
| 5234 | 2316 g_hash_table_foreach(chat->components, |
| 2317 blist_print_chat_components, file); | |
| 5906 | 2318 g_hash_table_foreach(chat->settings, |
| 6695 | 2319 blist_print_cnode_settings, file); |
| 5234 | 2320 fprintf(file, "\t\t\t</chat>\n"); |
| 5237 | 2321 g_free(acct_name); |
| 5234 | 2322 } |
| 5228 | 2323 } |
| 2324 } | |
| 2325 fprintf(file, "\t\t</group>\n"); | |
| 2326 g_free(group_name); | |
| 2327 } | |
| 2328 } | |
| 2329 | |
| 2330 fprintf(file, "\t</blist>\n"); | |
| 2331 fprintf(file, "\t<privacy>\n"); | |
| 2332 | |
|
5580
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
2333 for(accounts = gaim_accounts_get_all(); |
|
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
2334 accounts != NULL; |
|
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
2335 accounts = accounts->next) { |
|
86456ec3ca25
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
2336 |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
2337 GaimAccount *account = accounts->data; |
| 5228 | 2338 char *acct_name = g_markup_escape_text(account->username, -1); |
| 2339 if(!exp_acct || account == exp_acct) { | |
| 2340 fprintf(file, "\t\t<account protocol=\"%d\" name=\"%s\" " | |
|
5943
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
2341 "mode=\"%d\">\n", gaim_account_get_protocol(account), |
|
a4f2aba0848d
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
2342 acct_name, account->perm_deny); |
| 5228 | 2343 for(buds = account->permit; buds; buds = buds->next) { |
| 2344 char *bud_name = g_markup_escape_text(buds->data, -1); | |
| 2345 fprintf(file, "\t\t\t<permit>%s</permit>\n", bud_name); | |
| 2346 g_free(bud_name); | |
| 2347 } | |
| 2348 for(buds = account->deny; buds; buds = buds->next) { | |
| 2349 char *bud_name = g_markup_escape_text(buds->data, -1); | |
| 2350 fprintf(file, "\t\t\t<block>%s</block>\n", bud_name); | |
| 2351 g_free(bud_name); | |
| 2352 } | |
| 2353 fprintf(file, "\t\t</account>\n"); | |
| 2354 } | |
| 2355 g_free(acct_name); | |
| 2356 } | |
| 2357 | |
| 2358 fprintf(file, "\t</privacy>\n"); | |
| 2359 fprintf(file, "</gaim>\n"); | |
| 2360 } | |
| 2361 | |
| 2362 void gaim_blist_save() { | |
| 2363 FILE *file; | |
| 2364 char *user_dir = gaim_user_dir(); | |
| 2365 char *filename; | |
| 2366 char *filename_real; | |
| 2367 | |
| 2368 if(!user_dir) | |
| 2369 return; | |
| 2370 if(!blist_safe_to_write) { | |
| 2371 gaim_debug(GAIM_DEBUG_WARNING, "blist save", | |
| 2372 "AHH!! Tried to write the blist before we read it!\n"); | |
| 2373 return; | |
| 2374 } | |
| 2375 | |
| 2376 file = fopen(user_dir, "r"); | |
| 2377 if(!file) | |
| 2378 mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
| 2379 else | |
| 2380 fclose(file); | |
| 2381 | |
| 2382 filename = g_build_filename(user_dir, "blist.xml.save", NULL); | |
| 2383 | |
| 2384 if((file = fopen(filename, "w"))) { | |
| 2385 gaim_blist_write(file, NULL); | |
| 2386 fclose(file); | |
| 2387 chmod(filename, S_IRUSR | S_IWUSR); | |
| 2388 } else { | |
| 2389 gaim_debug(GAIM_DEBUG_ERROR, "blist save", "Unable to write %s\n", | |
| 2390 filename); | |
| 2391 } | |
| 2392 | |
| 2393 filename_real = g_build_filename(user_dir, "blist.xml", NULL); | |
| 2394 | |
| 2395 if(rename(filename, filename_real) < 0) | |
| 2396 gaim_debug(GAIM_DEBUG_ERROR, "blist save", | |
| 2397 "Error renaming %s to %s\n", filename, filename_real); | |
| 2398 | |
| 2399 | |
| 2400 g_free(filename); | |
| 2401 g_free(filename_real); | |
| 2402 } | |
| 2403 | |
| 6695 | 2404 void gaim_group_set_setting(GaimGroup *g, const char *key, |
| 5228 | 2405 const char *value) { |
| 2406 if(!g) | |
| 2407 return; | |
| 2408 g_hash_table_replace(g->settings, g_strdup(key), g_strdup(value)); | |
| 2409 } | |
| 2410 | |
| 6695 | 2411 char *gaim_group_get_setting(GaimGroup *g, const char *key) { |
| 5228 | 2412 if(!g) |
| 2413 return NULL; | |
| 2414 return g_strdup(g_hash_table_lookup(g->settings, key)); | |
| 2415 } | |
| 2416 | |
| 6695 | 2417 void gaim_blist_chat_set_setting(GaimBlistChat *c, const char *key, |
| 5906 | 2418 const char *value) |
| 2419 { | |
| 2420 if(!c) | |
| 2421 return; | |
| 2422 g_hash_table_replace(c->settings, g_strdup(key), g_strdup(value)); | |
| 2423 } | |
| 2424 | |
| 6695 | 2425 char *gaim_blist_chat_get_setting(GaimBlistChat *c, const char *key) |
| 5906 | 2426 { |
| 2427 if(!c) | |
| 2428 return NULL; | |
| 2429 return g_strdup(g_hash_table_lookup(c->settings, key)); | |
| 2430 } | |
| 2431 | |
| 6695 | 2432 void gaim_buddy_set_setting(GaimBuddy *b, const char *key, |
| 5228 | 2433 const char *value) { |
| 2434 if(!b) | |
| 2435 return; | |
| 2436 g_hash_table_replace(b->settings, g_strdup(key), g_strdup(value)); | |
| 2437 } | |
| 2438 | |
| 6695 | 2439 char *gaim_buddy_get_setting(GaimBuddy *b, const char *key) { |
| 5228 | 2440 if(!b) |
| 2441 return NULL; | |
| 2442 return g_strdup(g_hash_table_lookup(b->settings, key)); | |
| 2443 } | |
| 2444 | |
| 2445 void gaim_set_blist_ui_ops(struct gaim_blist_ui_ops *ops) | |
| 2446 { | |
| 2447 blist_ui_ops = ops; | |
| 2448 } | |
| 2449 | |
| 2450 struct gaim_blist_ui_ops * | |
| 2451 gaim_get_blist_ui_ops(void) | |
| 2452 { | |
| 2453 return blist_ui_ops; | |
| 2454 } | |
| 2455 | |
| 6695 | 2456 int gaim_blist_get_group_size(GaimGroup *group, gboolean offline) { |
| 5228 | 2457 if(!group) |
| 2458 return 0; | |
| 2459 | |
| 5277 | 2460 return offline ? group->totalsize : group->currentsize; |
| 5228 | 2461 } |
| 2462 | |
| 6695 | 2463 int gaim_blist_get_group_online_count(GaimGroup *group) { |
| 5228 | 2464 if(!group) |
| 2465 return 0; | |
| 2466 | |
| 5277 | 2467 return group->online; |
| 5228 | 2468 } |
| 2469 | |
|
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2470 void * |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2471 gaim_blist_get_handle(void) |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2472 { |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2473 static int handle; |
| 5228 | 2474 |
|
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2475 return &handle; |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2476 } |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2477 |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2478 void |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2479 gaim_blist_init(void) |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2480 { |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2481 void *handle = gaim_blist_get_handle(); |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2482 |
|
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2483 gaim_signal_register(handle, "buddy-away", |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2484 gaim_marshal_VOID__POINTER, NULL, 1, |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2485 gaim_value_new(GAIM_TYPE_SUBTYPE, |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2486 GAIM_SUBTYPE_BLIST_BUDDY)); |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2487 |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2488 gaim_signal_register(handle, "buddy-back", |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2489 gaim_marshal_VOID__POINTER, NULL, 1, |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2490 gaim_value_new(GAIM_TYPE_SUBTYPE, |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2491 GAIM_SUBTYPE_BLIST_BUDDY)); |
|
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2492 |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2493 gaim_signal_register(handle, "buddy-idle", |
|
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2494 gaim_marshal_VOID__POINTER, NULL, 1, |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2495 gaim_value_new(GAIM_TYPE_SUBTYPE, |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2496 GAIM_SUBTYPE_BLIST_BUDDY)); |
|
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2497 gaim_signal_register(handle, "buddy-unidle", |
|
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2498 gaim_marshal_VOID__POINTER, NULL, 1, |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2499 gaim_value_new(GAIM_TYPE_SUBTYPE, |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2500 GAIM_SUBTYPE_BLIST_BUDDY)); |
|
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2501 |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2502 gaim_signal_register(handle, "buddy-signed-on", |
|
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2503 gaim_marshal_VOID__POINTER, NULL, 1, |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2504 gaim_value_new(GAIM_TYPE_SUBTYPE, |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2505 GAIM_SUBTYPE_BLIST_BUDDY)); |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2506 |
|
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2507 gaim_signal_register(handle, "buddy-signed-off", |
|
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2508 gaim_marshal_VOID__POINTER, NULL, 1, |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2509 gaim_value_new(GAIM_TYPE_SUBTYPE, |
|
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2510 GAIM_SUBTYPE_BLIST_BUDDY)); |
|
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2511 |
|
6564
800ef4a51096
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2512 gaim_signal_register(handle, "update-idle", gaim_marshal_VOID, NULL, 0); |
|
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2513 } |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2514 |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2515 void |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2516 gaim_blist_uninit(void) |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2517 { |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2518 gaim_signals_unregister_by_instance(gaim_blist_get_handle()); |
|
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2519 } |
