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