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