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