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