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