Wed, 13 Aug 2003 16:31:57 +0000
[gaim-migrate @ 6959]
MMaking a comment about a check that, imho, is a bit ugly. We don't want to
have protocol-specific checks in core code if we can help it.
| 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" |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5855
diff
changeset
|
32 | #include "util.h" |
| 5228 | 33 | |
| 34 | #define PATHSIZE 1024 | |
| 35 | ||
| 36 | struct gaim_buddy_list *gaimbuddylist = NULL; | |
| 37 | static struct gaim_blist_ui_ops *blist_ui_ops = NULL; | |
| 38 | ||
| 39 | /***************************************************************************** | |
| 40 | * Private Utility functions * | |
| 41 | *****************************************************************************/ | |
| 42 | static GaimBlistNode *gaim_blist_get_last_sibling(GaimBlistNode *node) | |
| 43 | { | |
| 44 | GaimBlistNode *n = node; | |
| 45 | if (!n) | |
| 46 | return NULL; | |
| 47 | while (n->next) | |
| 48 | n = n->next; | |
| 49 | return n; | |
| 50 | } | |
| 51 | static GaimBlistNode *gaim_blist_get_last_child(GaimBlistNode *node) | |
| 52 | { | |
| 53 | if (!node) | |
| 54 | return NULL; | |
| 55 | return gaim_blist_get_last_sibling(node->child); | |
| 56 | } | |
| 57 | ||
| 5247 | 58 | struct _gaim_hbuddy { |
| 59 | char *name; | |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
60 | GaimAccount *account; |
| 5758 | 61 | GaimBlistNode *group; |
| 5247 | 62 | }; |
| 63 | ||
| 64 | static guint _gaim_blist_hbuddy_hash (struct _gaim_hbuddy *hb) | |
| 65 | { | |
| 66 | return g_str_hash(hb->name); | |
| 67 | } | |
| 68 | ||
| 69 | static guint _gaim_blist_hbuddy_equal (struct _gaim_hbuddy *hb1, struct _gaim_hbuddy *hb2) | |
| 70 | { | |
| 5758 | 71 | return ((!strcmp(hb1->name, hb2->name)) && hb1->account == hb2->account && hb1->group == hb2->group); |
| 5247 | 72 | } |
| 73 | ||
|
6006
d862aa2f47ca
[gaim-migrate @ 6454]
Mark Doliner <markdoliner@pidgin.im>
parents:
5985
diff
changeset
|
74 | 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
|
75 | { |
| 6012 | 76 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; |
| 77 | GaimBlistNode *group, *buddy; | |
| 78 | ||
| 79 | if (!ops) | |
| 80 | return; | |
| 81 | ||
| 82 | for(group = gaimbuddylist->root; group; group = group->next) { | |
| 83 | if(!GAIM_BLIST_NODE_IS_GROUP(group)) | |
| 84 | continue; | |
| 85 | for(buddy = group->child; buddy; buddy = buddy->next) { | |
| 86 | if(!GAIM_BLIST_NODE_IS_BUDDY(buddy)) | |
| 87 | continue; | |
| 88 | ops->update(gaimbuddylist, buddy); | |
| 89 | } | |
| 90 | } | |
|
6006
d862aa2f47ca
[gaim-migrate @ 6454]
Mark Doliner <markdoliner@pidgin.im>
parents:
5985
diff
changeset
|
91 | } |
|
d862aa2f47ca
[gaim-migrate @ 6454]
Mark Doliner <markdoliner@pidgin.im>
parents:
5985
diff
changeset
|
92 | |
| 5228 | 93 | /***************************************************************************** |
| 94 | * Public API functions * | |
| 95 | *****************************************************************************/ | |
| 96 | ||
| 97 | struct gaim_buddy_list *gaim_blist_new() | |
| 98 | { | |
| 99 | struct gaim_buddy_list *gbl = g_new0(struct gaim_buddy_list, 1); | |
| 100 | ||
| 101 | gbl->ui_ops = gaim_get_blist_ui_ops(); | |
| 102 | ||
| 5247 | 103 | gbl->buddies = g_hash_table_new ((GHashFunc)_gaim_blist_hbuddy_hash, |
| 104 | (GEqualFunc)_gaim_blist_hbuddy_equal); | |
| 105 | ||
| 5228 | 106 | if (gbl->ui_ops != NULL && gbl->ui_ops->new_list != NULL) |
| 107 | gbl->ui_ops->new_list(gbl); | |
| 108 | ||
|
6006
d862aa2f47ca
[gaim-migrate @ 6454]
Mark Doliner <markdoliner@pidgin.im>
parents:
5985
diff
changeset
|
109 | gaim_prefs_connect_callback("/core/buddies/use_server_alias", blist_pref_cb, NULL); |
|
d862aa2f47ca
[gaim-migrate @ 6454]
Mark Doliner <markdoliner@pidgin.im>
parents:
5985
diff
changeset
|
110 | |
| 5228 | 111 | return gbl; |
| 112 | } | |
| 113 | ||
| 114 | void | |
| 115 | gaim_set_blist(struct gaim_buddy_list *list) | |
| 116 | { | |
| 117 | gaimbuddylist = list; | |
| 118 | } | |
| 119 | ||
| 120 | struct gaim_buddy_list * | |
| 121 | gaim_get_blist(void) | |
| 122 | { | |
| 123 | return gaimbuddylist; | |
| 124 | } | |
| 125 | ||
| 126 | void gaim_blist_show () | |
| 127 | { | |
| 128 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 129 | if (ops) | |
| 130 | ops->show(gaimbuddylist); | |
| 131 | } | |
| 132 | ||
| 133 | void gaim_blist_destroy() | |
| 134 | { | |
| 135 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 136 | if (ops) | |
| 137 | ops->destroy(gaimbuddylist); | |
| 138 | } | |
| 139 | ||
| 140 | void gaim_blist_set_visible (gboolean show) | |
| 141 | { | |
| 142 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 143 | if (ops) | |
| 144 | ops->set_visible(gaimbuddylist, show); | |
| 145 | } | |
| 146 | ||
| 147 | void gaim_blist_update_buddy_status (struct buddy *buddy, int status) | |
| 148 | { | |
|
5266
cb6fe050ff33
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
149 | struct gaim_blist_ui_ops *ops; |
|
cb6fe050ff33
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
150 | |
|
cb6fe050ff33
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
151 | if (buddy->uc == status) |
|
cb6fe050ff33
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
152 | return; |
|
cb6fe050ff33
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
153 | |
|
cb6fe050ff33
[gaim-migrate @ 5638]
Christian Hammond <chipx86@chipx86.com>
parents:
5259
diff
changeset
|
154 | ops = gaimbuddylist->ui_ops; |
| 5228 | 155 | |
|
5305
5a6fc3d321d9
[gaim-migrate @ 5677]
David J. Brigada <brigada@prism.net>
parents:
5292
diff
changeset
|
156 | if((status & UC_UNAVAILABLE) != (buddy->uc & UC_UNAVAILABLE)) { |
|
5a6fc3d321d9
[gaim-migrate @ 5677]
David J. Brigada <brigada@prism.net>
parents:
5292
diff
changeset
|
157 | if(status & UC_UNAVAILABLE) |
|
5a6fc3d321d9
[gaim-migrate @ 5677]
David J. Brigada <brigada@prism.net>
parents:
5292
diff
changeset
|
158 | gaim_event_broadcast(event_buddy_away, buddy->account->gc, buddy->name); |
|
5a6fc3d321d9
[gaim-migrate @ 5677]
David J. Brigada <brigada@prism.net>
parents:
5292
diff
changeset
|
159 | else |
|
5a6fc3d321d9
[gaim-migrate @ 5677]
David J. Brigada <brigada@prism.net>
parents:
5292
diff
changeset
|
160 | gaim_event_broadcast(event_buddy_back, buddy->account->gc, buddy->name); |
|
5a6fc3d321d9
[gaim-migrate @ 5677]
David J. Brigada <brigada@prism.net>
parents:
5292
diff
changeset
|
161 | } |
| 5228 | 162 | |
|
5305
5a6fc3d321d9
[gaim-migrate @ 5677]
David J. Brigada <brigada@prism.net>
parents:
5292
diff
changeset
|
163 | buddy->uc = status; |
| 5228 | 164 | if (ops) |
| 165 | ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 166 | } | |
| 167 | ||
| 168 | static gboolean presence_update_timeout_cb(struct buddy *buddy) { | |
| 169 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
|
6392
3db2b3c7b5aa
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
170 | GaimConversation *conv = gaim_find_conversation(buddy->name); |
| 5228 | 171 | |
| 172 | if(buddy->present == GAIM_BUDDY_SIGNING_ON) { | |
| 173 | buddy->present = GAIM_BUDDY_ONLINE; | |
| 174 | } else if(buddy->present == GAIM_BUDDY_SIGNING_OFF) { | |
| 175 | buddy->present = GAIM_BUDDY_OFFLINE; | |
| 176 | } | |
| 177 | ||
| 178 | buddy->timer = 0; | |
| 179 | ||
| 180 | if (ops) | |
| 181 | ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 182 | ||
|
6392
3db2b3c7b5aa
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
183 | if (conv) { |
|
3db2b3c7b5aa
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
184 | if (buddy->present == GAIM_BUDDY_ONLINE) |
|
3db2b3c7b5aa
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
185 | gaim_conversation_update(conv, GAIM_CONV_ACCOUNT_ONLINE); |
|
3db2b3c7b5aa
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
186 | else if (buddy->present == GAIM_BUDDY_OFFLINE) |
|
3db2b3c7b5aa
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
187 | gaim_conversation_update(conv, GAIM_CONV_ACCOUNT_OFFLINE); |
|
3db2b3c7b5aa
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
188 | } |
|
3db2b3c7b5aa
[gaim-migrate @ 6897]
Christian Hammond <chipx86@chipx86.com>
parents:
6378
diff
changeset
|
189 | |
| 5228 | 190 | return FALSE; |
| 191 | } | |
| 192 | ||
| 193 | void gaim_blist_update_buddy_presence(struct buddy *buddy, int presence) { | |
| 194 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 195 | gboolean do_timer = FALSE; | |
| 196 | ||
| 197 | if (!GAIM_BUDDY_IS_ONLINE(buddy) && presence) { | |
| 198 | buddy->present = GAIM_BUDDY_SIGNING_ON; | |
| 199 | gaim_event_broadcast(event_buddy_signon, buddy->account->gc, buddy->name); | |
| 200 | do_timer = TRUE; | |
| 5277 | 201 | ((struct group *)((GaimBlistNode *)buddy)->parent)->online++; |
| 5228 | 202 | } else if(GAIM_BUDDY_IS_ONLINE(buddy) && !presence) { |
| 203 | buddy->present = GAIM_BUDDY_SIGNING_OFF; | |
| 204 | gaim_event_broadcast(event_buddy_signoff, buddy->account->gc, buddy->name); | |
| 205 | do_timer = TRUE; | |
| 5394 | 206 | ((struct group *)((GaimBlistNode *)buddy)->parent)->online--; |
| 5228 | 207 | } |
| 208 | ||
| 209 | if(do_timer) { | |
| 210 | if(buddy->timer > 0) | |
| 211 | g_source_remove(buddy->timer); | |
| 212 | buddy->timer = g_timeout_add(10000, (GSourceFunc)presence_update_timeout_cb, buddy); | |
| 213 | } | |
| 214 | ||
| 215 | if (ops) | |
| 216 | ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 217 | } | |
| 218 | ||
| 219 | ||
| 220 | void gaim_blist_update_buddy_idle (struct buddy *buddy, int idle) | |
| 221 | { | |
| 222 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 223 | buddy->idle = idle; | |
| 224 | if (ops) | |
| 225 | ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 226 | } | |
| 227 | void gaim_blist_update_buddy_evil (struct buddy *buddy, int warning) | |
| 228 | { | |
| 229 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 230 | buddy->evil = warning; | |
| 231 | if (ops) | |
| 232 | ops->update(gaimbuddylist,(GaimBlistNode*)buddy); | |
| 233 | } | |
| 234 | void gaim_blist_update_buddy_icon(struct buddy *buddy) { | |
| 235 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 236 | if(ops) | |
| 237 | ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 238 | } | |
| 239 | void gaim_blist_rename_buddy (struct buddy *buddy, const char *name) | |
| 240 | { | |
| 241 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 5634 | 242 | g_free(buddy->name); |
| 5228 | 243 | buddy->name = g_strdup(name); |
| 244 | if (ops) | |
| 245 | ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 246 | } | |
| 5234 | 247 | |
| 248 | void gaim_blist_alias_chat(struct chat *chat, const char *alias) | |
| 249 | { | |
| 250 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 251 | ||
| 5237 | 252 | g_free(chat->alias); |
| 5234 | 253 | |
| 5237 | 254 | if(alias && strlen(alias)) |
| 255 | chat->alias = g_strdup(alias); | |
| 256 | else | |
| 257 | chat->alias = NULL; | |
| 258 | ||
| 5234 | 259 | if(ops) |
| 260 | ops->update(gaimbuddylist, (GaimBlistNode*)chat); | |
| 261 | } | |
| 262 | ||
| 5228 | 263 | void gaim_blist_alias_buddy (struct buddy *buddy, const char *alias) |
| 264 | { | |
| 265 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
|
5676
d3c2fdaf4821
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5634
diff
changeset
|
266 | GaimConversation *conv; |
| 5228 | 267 | |
| 268 | g_free(buddy->alias); | |
| 269 | ||
| 270 | if(alias && strlen(alias)) | |
| 271 | buddy->alias = g_strdup(alias); | |
| 272 | else | |
| 273 | buddy->alias = NULL; | |
| 274 | ||
| 275 | if (ops) | |
| 276 | ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 277 | ||
| 278 | conv = gaim_find_conversation_with_account(buddy->name, buddy->account); | |
| 279 | ||
| 280 | if (conv) | |
| 281 | gaim_conversation_autoset_title(conv); | |
| 282 | } | |
| 283 | ||
|
6058
0d5c66a5da5d
[gaim-migrate @ 6508]
Mark Doliner <markdoliner@pidgin.im>
parents:
6036
diff
changeset
|
284 | void gaim_blist_server_alias_buddy (struct buddy *buddy, const char *alias) |
|
0d5c66a5da5d
[gaim-migrate @ 6508]
Mark Doliner <markdoliner@pidgin.im>
parents:
6036
diff
changeset
|
285 | { |
|
0d5c66a5da5d
[gaim-migrate @ 6508]
Mark Doliner <markdoliner@pidgin.im>
parents:
6036
diff
changeset
|
286 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; |
|
0d5c66a5da5d
[gaim-migrate @ 6508]
Mark Doliner <markdoliner@pidgin.im>
parents:
6036
diff
changeset
|
287 | GaimConversation *conv; |
|
0d5c66a5da5d
[gaim-migrate @ 6508]
Mark Doliner <markdoliner@pidgin.im>
parents:
6036
diff
changeset
|
288 | |
|
0d5c66a5da5d
[gaim-migrate @ 6508]
Mark Doliner <markdoliner@pidgin.im>
parents:
6036
diff
changeset
|
289 | g_free(buddy->server_alias); |
|
0d5c66a5da5d
[gaim-migrate @ 6508]
Mark Doliner <markdoliner@pidgin.im>
parents:
6036
diff
changeset
|
290 | |
|
0d5c66a5da5d
[gaim-migrate @ 6508]
Mark Doliner <markdoliner@pidgin.im>
parents:
6036
diff
changeset
|
291 | if(alias && strlen(alias) && g_utf8_validate(alias, -1, NULL)) |
|
0d5c66a5da5d
[gaim-migrate @ 6508]
Mark Doliner <markdoliner@pidgin.im>
parents:
6036
diff
changeset
|
292 | buddy->server_alias = g_strdup(alias); |
|
0d5c66a5da5d
[gaim-migrate @ 6508]
Mark Doliner <markdoliner@pidgin.im>
parents:
6036
diff
changeset
|
293 | else |
|
0d5c66a5da5d
[gaim-migrate @ 6508]
Mark Doliner <markdoliner@pidgin.im>
parents:
6036
diff
changeset
|
294 | buddy->server_alias = NULL; |
|
0d5c66a5da5d
[gaim-migrate @ 6508]
Mark Doliner <markdoliner@pidgin.im>
parents:
6036
diff
changeset
|
295 | |
|
0d5c66a5da5d
[gaim-migrate @ 6508]
Mark Doliner <markdoliner@pidgin.im>
parents:
6036
diff
changeset
|
296 | if (ops) |
|
0d5c66a5da5d
[gaim-migrate @ 6508]
Mark Doliner <markdoliner@pidgin.im>
parents:
6036
diff
changeset
|
297 | ops->update(gaimbuddylist, (GaimBlistNode*)buddy); |
|
0d5c66a5da5d
[gaim-migrate @ 6508]
Mark Doliner <markdoliner@pidgin.im>
parents:
6036
diff
changeset
|
298 | |
|
0d5c66a5da5d
[gaim-migrate @ 6508]
Mark Doliner <markdoliner@pidgin.im>
parents:
6036
diff
changeset
|
299 | conv = gaim_find_conversation_with_account(buddy->name, buddy->account); |
|
0d5c66a5da5d
[gaim-migrate @ 6508]
Mark Doliner <markdoliner@pidgin.im>
parents:
6036
diff
changeset
|
300 | |
|
0d5c66a5da5d
[gaim-migrate @ 6508]
Mark Doliner <markdoliner@pidgin.im>
parents:
6036
diff
changeset
|
301 | if (conv) |
|
0d5c66a5da5d
[gaim-migrate @ 6508]
Mark Doliner <markdoliner@pidgin.im>
parents:
6036
diff
changeset
|
302 | gaim_conversation_autoset_title(conv); |
|
0d5c66a5da5d
[gaim-migrate @ 6508]
Mark Doliner <markdoliner@pidgin.im>
parents:
6036
diff
changeset
|
303 | } |
|
0d5c66a5da5d
[gaim-migrate @ 6508]
Mark Doliner <markdoliner@pidgin.im>
parents:
6036
diff
changeset
|
304 | |
| 5228 | 305 | void gaim_blist_rename_group(struct group *group, const char *name) |
| 306 | { | |
| 307 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 5346 | 308 | struct group *dest_group; |
| 309 | GaimBlistNode *prev, *child, *next; | |
| 310 | GSList *accts; | |
| 311 | ||
| 312 | if(!name || !strlen(name) || !strcmp(name, group->name)) { | |
| 313 | /* nothing to do here */ | |
| 314 | return; | |
| 315 | } else if((dest_group = gaim_find_group(name))) { | |
| 316 | /* here we're merging two groups */ | |
| 317 | prev = gaim_blist_get_last_child((GaimBlistNode*)dest_group); | |
| 318 | child = ((GaimBlistNode*)group)->child; | |
| 319 | ||
| 320 | while(child) | |
| 321 | { | |
| 322 | next = child->next; | |
| 323 | if(GAIM_BLIST_NODE_IS_BUDDY(child)) { | |
| 324 | gaim_blist_add_buddy((struct buddy *)child, dest_group, prev); | |
| 325 | prev = child; | |
| 326 | } else if(GAIM_BLIST_NODE_IS_CHAT(child)) { | |
| 327 | gaim_blist_add_chat((struct chat *)child, dest_group, prev); | |
| 328 | prev = child; | |
| 329 | } else { | |
| 330 | gaim_debug(GAIM_DEBUG_ERROR, "blist", | |
| 331 | "Unknown child type in group %s\n", group->name); | |
| 332 | } | |
| 333 | child = next; | |
| 334 | } | |
| 335 | 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
|
336 | GaimAccount *account = accts->data; |
| 5346 | 337 | serv_rename_group(account->gc, group, name); |
| 338 | } | |
| 339 | gaim_blist_remove_group(group); | |
| 340 | } else { | |
| 341 | /* a simple rename */ | |
| 342 | 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
|
343 | GaimAccount *account = accts->data; |
| 5346 | 344 | serv_rename_group(account->gc, group, name); |
| 345 | } | |
| 346 | g_free(group->name); | |
| 347 | group->name = g_strdup(name); | |
| 348 | if (ops) | |
| 349 | ops->update(gaimbuddylist, (GaimBlistNode*)group); | |
| 350 | } | |
| 5228 | 351 | } |
| 5234 | 352 | |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
353 | struct chat *gaim_chat_new(GaimAccount *account, const char *alias, GHashTable *components) |
| 5234 | 354 | { |
| 355 | struct chat *chat; | |
| 356 | struct gaim_blist_ui_ops *ops; | |
| 357 | ||
| 5237 | 358 | if(!components) |
| 5234 | 359 | return NULL; |
| 360 | ||
| 361 | chat = g_new0(struct chat, 1); | |
| 362 | chat->account = account; | |
| 5237 | 363 | if(alias && strlen(alias)) |
| 364 | chat->alias = g_strdup(alias); | |
| 5234 | 365 | chat->components = components; |
| 5906 | 366 | chat->settings = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 367 | g_free, g_free); | |
| 5234 | 368 | |
| 369 | ((GaimBlistNode*)chat)->type = GAIM_BLIST_CHAT_NODE; | |
| 370 | ||
| 371 | ops = gaim_get_blist_ui_ops(); | |
| 372 | ||
| 373 | if (ops != NULL && ops->new_node != NULL) | |
| 374 | ops->new_node((GaimBlistNode *)chat); | |
| 375 | ||
| 376 | return chat; | |
| 377 | } | |
| 378 | ||
|
6036
285e48913c72
[gaim-migrate @ 6486]
Mark Doliner <markdoliner@pidgin.im>
parents:
6034
diff
changeset
|
379 | char *gaim_chat_get_display_name(struct chat *chat) |
| 6034 | 380 | { |
| 381 | char *name; | |
| 382 | ||
| 383 | if(chat->alias){ | |
| 384 | name = g_strdup(chat->alias); | |
| 385 | } | |
| 386 | else{ | |
| 387 | GList *parts; | |
| 388 | GaimPlugin *prpl; | |
| 389 | GaimPluginProtocolInfo *prpl_info; | |
| 390 | struct proto_chat_entry *pce; | |
| 391 | ||
| 392 | prpl = gaim_find_prpl(gaim_account_get_protocol(chat->account)); | |
| 393 | prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
| 394 | ||
| 395 | parts = prpl_info->chat_info(chat->account->gc); | |
| 396 | ||
| 397 | pce = parts->data; | |
| 398 | name = g_markup_escape_text(g_hash_table_lookup(chat->components, | |
| 399 | pce->identifier), -1); | |
| 400 | g_list_free(parts); | |
| 401 | } | |
| 402 | ||
| 403 | return name; | |
| 404 | } | |
| 405 | ||
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
406 | struct buddy *gaim_buddy_new(GaimAccount *account, const char *screenname, const char *alias) |
| 5228 | 407 | { |
| 408 | struct buddy *b; | |
| 409 | struct gaim_blist_ui_ops *ops; | |
| 410 | ||
| 411 | b = g_new0(struct buddy, 1); | |
| 412 | b->account = account; | |
| 413 | b->name = g_strdup(screenname); | |
| 414 | b->alias = g_strdup(alias); | |
| 415 | b->settings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
| 416 | ((GaimBlistNode*)b)->type = GAIM_BLIST_BUDDY_NODE; | |
| 417 | ||
| 418 | ops = gaim_get_blist_ui_ops(); | |
| 419 | ||
| 420 | if (ops != NULL && ops->new_node != NULL) | |
| 421 | ops->new_node((GaimBlistNode *)b); | |
| 422 | ||
| 423 | return b; | |
| 424 | } | |
| 5634 | 425 | |
| 5234 | 426 | void gaim_blist_add_chat(struct chat *chat, struct group *group, GaimBlistNode *node) |
| 427 | { | |
| 428 | GaimBlistNode *n = node, *cnode = (GaimBlistNode*)chat; | |
| 429 | struct group *g = group; | |
| 430 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 431 | gboolean save = FALSE; | |
| 432 | ||
| 433 | if (!n) { | |
| 434 | if (!g) { | |
| 435 | g = gaim_group_new(_("Chats")); | |
| 5634 | 436 | gaim_blist_add_group(g, |
| 437 | gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
| 5234 | 438 | } |
| 439 | } else { | |
| 440 | g = (struct group*)n->parent; | |
| 441 | } | |
| 442 | ||
| 443 | /* if we're moving to overtop of ourselves, do nothing */ | |
| 444 | if(cnode == n) | |
| 445 | return; | |
| 446 | ||
| 447 | if (cnode->parent) { | |
| 448 | /* This chat was already in the list and is | |
| 449 | * being moved. | |
| 450 | */ | |
| 5277 | 451 | ((struct group *)cnode->parent)->totalsize--; |
| 5855 | 452 | if (gaim_account_is_connected(chat->account)) { |
| 5287 | 453 | ((struct group *)cnode->parent)->online--; |
| 5277 | 454 | ((struct group *)cnode->parent)->currentsize--; |
| 5287 | 455 | } |
| 5234 | 456 | if(cnode->next) |
| 457 | cnode->next->prev = cnode->prev; | |
| 458 | if(cnode->prev) | |
| 459 | cnode->prev->next = cnode->next; | |
| 460 | if(cnode->parent->child == cnode) | |
| 461 | cnode->parent->child = cnode->next; | |
| 462 | ||
| 463 | ops->remove(gaimbuddylist, cnode); | |
| 464 | ||
| 465 | save = TRUE; | |
| 466 | } | |
| 467 | ||
| 468 | if (n) { | |
| 469 | if(n->next) | |
| 470 | n->next->prev = cnode; | |
| 471 | cnode->next = n->next; | |
| 472 | cnode->prev = n; | |
| 473 | cnode->parent = n->parent; | |
| 474 | n->next = cnode; | |
| 5277 | 475 | ((struct group *)n->parent)->totalsize++; |
| 5855 | 476 | if (gaim_account_is_connected(chat->account)) { |
| 5287 | 477 | ((struct group *)n->parent)->online++; |
| 5277 | 478 | ((struct group *)n->parent)->currentsize++; |
| 5287 | 479 | } |
| 5234 | 480 | } else { |
| 5634 | 481 | if(((GaimBlistNode*)g)->child) |
| 482 | ((GaimBlistNode*)g)->child->prev = cnode; | |
| 483 | cnode->next = ((GaimBlistNode*)g)->child; | |
| 484 | cnode->prev = NULL; | |
| 5234 | 485 | ((GaimBlistNode*)g)->child = cnode; |
| 486 | cnode->parent = (GaimBlistNode*)g; | |
| 5277 | 487 | g->totalsize++; |
| 5855 | 488 | if (gaim_account_is_connected(chat->account)) { |
| 5287 | 489 | g->online++; |
| 5277 | 490 | g->currentsize++; |
| 5287 | 491 | } |
| 5234 | 492 | } |
| 493 | ||
| 494 | if (ops) | |
| 495 | ops->update(gaimbuddylist, (GaimBlistNode*)cnode); | |
| 496 | if (save) | |
| 497 | gaim_blist_save(); | |
| 498 | } | |
| 499 | ||
| 5228 | 500 | void gaim_blist_add_buddy (struct buddy *buddy, struct group *group, GaimBlistNode *node) |
| 501 | { | |
| 502 | GaimBlistNode *n = node, *bnode = (GaimBlistNode*)buddy; | |
| 503 | struct group *g = group; | |
| 504 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 5247 | 505 | struct _gaim_hbuddy *hb; |
| 5228 | 506 | gboolean save = FALSE; |
| 507 | ||
| 508 | if (!n) { | |
| 509 | if (!g) { | |
| 510 | g = gaim_group_new(_("Buddies")); | |
| 5634 | 511 | gaim_blist_add_group(g, |
| 512 | gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
| 5228 | 513 | } |
| 514 | } else { | |
| 515 | g = (struct group*)n->parent; | |
| 516 | } | |
| 517 | ||
| 518 | /* if we're moving to overtop of ourselves, do nothing */ | |
| 519 | if(bnode == n) | |
| 520 | return; | |
| 521 | ||
| 522 | if (bnode->parent) { | |
| 523 | /* This buddy was already in the list and is | |
| 524 | * being moved. | |
| 525 | */ | |
| 5394 | 526 | ((struct group *)bnode->parent)->totalsize--; |
| 5855 | 527 | if (gaim_account_is_connected(buddy->account)) |
| 5277 | 528 | ((struct group *)bnode->parent)->currentsize--; |
| 5394 | 529 | if (GAIM_BUDDY_IS_ONLINE(buddy)) |
| 5313 | 530 | ((struct group *)bnode->parent)->online--; |
| 5277 | 531 | |
| 5228 | 532 | if(bnode->next) |
| 533 | bnode->next->prev = bnode->prev; | |
| 534 | if(bnode->prev) | |
| 535 | bnode->prev->next = bnode->next; | |
| 536 | if(bnode->parent->child == bnode) | |
| 537 | bnode->parent->child = bnode->next; | |
| 538 | ||
| 539 | ops->remove(gaimbuddylist, bnode); | |
| 540 | ||
| 5277 | 541 | if (bnode->parent != ((GaimBlistNode*)g)) { |
| 5228 | 542 | serv_move_buddy(buddy, (struct group*)bnode->parent, g); |
| 5277 | 543 | } |
| 5228 | 544 | save = TRUE; |
| 545 | } | |
| 546 | ||
| 547 | if (n) { | |
| 548 | if(n->next) | |
| 549 | n->next->prev = (GaimBlistNode*)buddy; | |
| 550 | ((GaimBlistNode*)buddy)->next = n->next; | |
| 551 | ((GaimBlistNode*)buddy)->prev = n; | |
| 552 | ((GaimBlistNode*)buddy)->parent = n->parent; | |
| 553 | n->next = (GaimBlistNode*)buddy; | |
| 5277 | 554 | ((struct group *)n->parent)->totalsize++; |
| 5855 | 555 | if (gaim_account_is_connected(buddy->account)) |
| 5277 | 556 | ((struct group *)n->parent)->currentsize++; |
| 5394 | 557 | if (GAIM_BUDDY_IS_ONLINE(buddy)) |
| 5313 | 558 | ((struct group *)n->parent)->online++; |
| 5228 | 559 | } else { |
| 5634 | 560 | if(((GaimBlistNode*)g)->child) |
| 561 | ((GaimBlistNode*)g)->child->prev = (GaimBlistNode*)buddy; | |
| 562 | ((GaimBlistNode*)buddy)->prev = NULL; | |
| 563 | ((GaimBlistNode*)buddy)->next = ((GaimBlistNode*)g)->child; | |
| 5228 | 564 | ((GaimBlistNode*)g)->child = (GaimBlistNode*)buddy; |
| 565 | ((GaimBlistNode*)buddy)->parent = (GaimBlistNode*)g; | |
| 5277 | 566 | g->totalsize++; |
| 5855 | 567 | if (gaim_account_is_connected(buddy->account)) |
| 5277 | 568 | g->currentsize++; |
| 5394 | 569 | if (GAIM_BUDDY_IS_ONLINE(buddy)) |
| 5313 | 570 | g->online++; |
| 5228 | 571 | } |
| 572 | ||
| 5247 | 573 | hb = g_malloc(sizeof(struct _gaim_hbuddy)); |
| 574 | hb->name = g_strdup(normalize(buddy->name)); | |
| 575 | hb->account = buddy->account; | |
| 5758 | 576 | hb->group = ((GaimBlistNode*)buddy)->parent; |
| 5247 | 577 | |
| 578 | if (g_hash_table_lookup(gaimbuddylist->buddies, (gpointer)hb)) { | |
| 579 | /* This guy already exists */ | |
| 580 | g_free(hb->name); | |
| 581 | g_free(hb); | |
| 582 | } else { | |
| 583 | g_hash_table_insert(gaimbuddylist->buddies, (gpointer)hb, (gpointer)buddy); | |
| 584 | } | |
| 585 | ||
| 5228 | 586 | if (ops) |
| 587 | ops->update(gaimbuddylist, (GaimBlistNode*)buddy); | |
| 588 | if (save) | |
| 589 | gaim_blist_save(); | |
| 590 | } | |
| 591 | ||
| 592 | struct group *gaim_group_new(const char *name) | |
| 593 | { | |
| 594 | struct group *g = gaim_find_group(name); | |
| 595 | ||
| 596 | if (!g) { | |
| 597 | struct gaim_blist_ui_ops *ops; | |
| 598 | g= g_new0(struct group, 1); | |
| 599 | g->name = g_strdup(name); | |
| 5277 | 600 | g->totalsize = 0; |
| 601 | g->currentsize = 0; | |
| 602 | g->online = 0; | |
| 5228 | 603 | g->settings = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 604 | g_free, g_free); | |
| 605 | ((GaimBlistNode*)g)->type = GAIM_BLIST_GROUP_NODE; | |
| 606 | ||
| 607 | ops = gaim_get_blist_ui_ops(); | |
| 608 | ||
| 609 | if (ops != NULL && ops->new_node != NULL) | |
| 610 | ops->new_node((GaimBlistNode *)g); | |
| 611 | ||
| 612 | } | |
| 613 | return g; | |
| 614 | } | |
| 615 | ||
| 616 | void gaim_blist_add_group (struct group *group, GaimBlistNode *node) | |
| 617 | { | |
| 618 | struct gaim_blist_ui_ops *ops; | |
| 619 | GaimBlistNode *gnode = (GaimBlistNode*)group; | |
| 620 | gboolean save = FALSE; | |
| 621 | ||
| 622 | if (!gaimbuddylist) | |
| 623 | gaimbuddylist = gaim_blist_new(); | |
| 624 | ops = gaimbuddylist->ui_ops; | |
| 625 | ||
| 626 | if (!gaimbuddylist->root) { | |
| 627 | gaimbuddylist->root = gnode; | |
| 628 | return; | |
| 629 | } | |
| 630 | ||
| 631 | /* if we're moving to overtop of ourselves, do nothing */ | |
| 632 | if(gnode == node) | |
| 633 | return; | |
| 634 | ||
| 635 | if (gaim_find_group(group->name)) { | |
| 636 | /* This is just being moved */ | |
| 637 | ||
| 638 | ops->remove(gaimbuddylist, (GaimBlistNode*)group); | |
| 639 | ||
| 640 | if(gnode == gaimbuddylist->root) | |
| 641 | gaimbuddylist->root = gnode->next; | |
| 642 | if(gnode->prev) | |
| 643 | gnode->prev->next = gnode->next; | |
| 644 | if(gnode->next) | |
| 645 | gnode->next->prev = gnode->prev; | |
| 646 | ||
| 647 | save = TRUE; | |
| 648 | } | |
| 649 | ||
| 5634 | 650 | if (node) { |
| 651 | gnode->next = node->next; | |
| 652 | gnode->prev = node; | |
| 653 | if(node->next) | |
| 654 | node->next->prev = gnode; | |
| 655 | node->next = gnode; | |
| 656 | } else { | |
| 657 | gaimbuddylist->root->prev = gnode; | |
| 658 | gnode->next = gaimbuddylist->root; | |
| 659 | gnode->prev = NULL; | |
| 660 | gaimbuddylist->root = gnode; | |
| 661 | } | |
| 662 | ||
| 5228 | 663 | |
| 664 | if (ops) { | |
| 665 | ops->update(gaimbuddylist, gnode); | |
| 666 | for(node = gnode->child; node; node = node->next) | |
| 667 | ops->update(gaimbuddylist, node); | |
| 668 | } | |
| 669 | if (save) | |
| 670 | gaim_blist_save(); | |
| 671 | } | |
| 672 | ||
| 673 | void gaim_blist_remove_buddy (struct buddy *buddy) | |
| 674 | { | |
| 675 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 676 | ||
| 677 | GaimBlistNode *gnode, *node = (GaimBlistNode*)buddy; | |
| 678 | struct group *group; | |
| 5247 | 679 | struct _gaim_hbuddy hb, *key; |
| 680 | struct buddy *val; | |
| 5228 | 681 | |
| 682 | gnode = node->parent; | |
| 683 | group = (struct group *)gnode; | |
| 684 | ||
| 685 | if(gnode->child == node) | |
| 686 | gnode->child = node->next; | |
| 687 | if (node->prev) | |
| 688 | node->prev->next = node->next; | |
| 689 | if (node->next) | |
| 690 | node->next->prev = node->prev; | |
| 5394 | 691 | group->totalsize--; |
| 5855 | 692 | if (gaim_account_is_connected(buddy->account)) |
| 5277 | 693 | group->currentsize--; |
| 5394 | 694 | if (GAIM_BUDDY_IS_ONLINE(buddy)) |
| 695 | group->online--; | |
| 5228 | 696 | |
| 5247 | 697 | hb.name = normalize(buddy->name); |
| 698 | hb.account = buddy->account; | |
| 5758 | 699 | hb.group = ((GaimBlistNode*)buddy)->parent; |
| 5247 | 700 | if (g_hash_table_lookup_extended(gaimbuddylist->buddies, &hb, (gpointer *)&key, (gpointer *)&val)) { |
| 701 | g_hash_table_remove(gaimbuddylist->buddies, &hb); | |
| 702 | g_free(key->name); | |
| 703 | g_free(key); | |
| 704 | } | |
| 705 | ||
| 5292 | 706 | if(buddy->timer > 0) |
| 707 | g_source_remove(buddy->timer); | |
| 708 | ||
| 5228 | 709 | ops->remove(gaimbuddylist, node); |
| 710 | g_hash_table_destroy(buddy->settings); | |
| 711 | g_free(buddy->name); | |
| 712 | g_free(buddy->alias); | |
| 713 | g_free(buddy); | |
| 714 | } | |
| 715 | ||
| 5234 | 716 | void gaim_blist_remove_chat (struct chat *chat) |
| 717 | { | |
| 718 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 719 | ||
| 720 | GaimBlistNode *gnode, *node = (GaimBlistNode*)chat; | |
| 721 | struct group *group; | |
| 722 | ||
| 723 | gnode = node->parent; | |
| 724 | group = (struct group *)gnode; | |
| 725 | ||
| 726 | if(gnode->child == node) | |
| 727 | gnode->child = node->next; | |
| 728 | if (node->prev) | |
| 729 | node->prev->next = node->next; | |
| 730 | if (node->next) | |
| 731 | node->next->prev = node->prev; | |
| 5277 | 732 | group->totalsize--; |
| 5855 | 733 | if (gaim_account_is_connected(chat->account)) { |
| 5277 | 734 | group->currentsize--; |
| 5394 | 735 | group->online--; |
| 736 | } | |
| 5234 | 737 | |
| 738 | ops->remove(gaimbuddylist, node); | |
| 739 | g_hash_table_destroy(chat->components); | |
| 740 | g_free(chat->alias); | |
| 741 | g_free(chat); | |
| 742 | } | |
| 743 | ||
| 5228 | 744 | void gaim_blist_remove_group (struct group *group) |
| 745 | { | |
| 746 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 747 | GaimBlistNode *node = (GaimBlistNode*)group; | |
| 748 | ||
| 749 | if(node->child) { | |
| 750 | char *buf; | |
| 751 | int count = 0; | |
| 752 | GaimBlistNode *child = node->child; | |
| 753 | ||
| 754 | while(child) { | |
| 755 | count++; | |
| 756 | child = child->next; | |
| 757 | } | |
| 758 | ||
|
6308
12d48b4e80db
[gaim-migrate @ 6807]
Mark Doliner <markdoliner@pidgin.im>
parents:
6307
diff
changeset
|
759 | 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
|
760 | "because its account was not logged in." |
|
12d48b4e80db
[gaim-migrate @ 6807]
Mark Doliner <markdoliner@pidgin.im>
parents:
6307
diff
changeset
|
761 | " This buddy and the group were not " |
|
12d48b4e80db
[gaim-migrate @ 6807]
Mark Doliner <markdoliner@pidgin.im>
parents:
6307
diff
changeset
|
762 | "removed.\n", |
|
12d48b4e80db
[gaim-migrate @ 6807]
Mark Doliner <markdoliner@pidgin.im>
parents:
6307
diff
changeset
|
763 | "%d buddies from group %s were not " |
|
12d48b4e80db
[gaim-migrate @ 6807]
Mark Doliner <markdoliner@pidgin.im>
parents:
6307
diff
changeset
|
764 | "removed because their accounts were " |
|
6336
7c62a14b3486
[gaim-migrate @ 6835]
Mark Doliner <markdoliner@pidgin.im>
parents:
6322
diff
changeset
|
765 | "not logged in. These buddies and " |
|
7c62a14b3486
[gaim-migrate @ 6835]
Mark Doliner <markdoliner@pidgin.im>
parents:
6322
diff
changeset
|
766 | "the group were not removed.\n", count), |
|
6308
12d48b4e80db
[gaim-migrate @ 6807]
Mark Doliner <markdoliner@pidgin.im>
parents:
6307
diff
changeset
|
767 | count, group->name); |
|
5541
d4840f195f45
[gaim-migrate @ 5941]
Christian Hammond <chipx86@chipx86.com>
parents:
5436
diff
changeset
|
768 | gaim_notify_error(NULL, NULL, _("Group not removed"), buf); |
| 5228 | 769 | g_free(buf); |
| 770 | return; | |
| 771 | } | |
| 772 | ||
| 773 | if(gaimbuddylist->root == node) | |
| 774 | gaimbuddylist->root = node->next; | |
| 775 | if (node->prev) | |
| 776 | node->prev->next = node->next; | |
| 777 | if (node->next) | |
| 778 | node->next->prev = node->prev; | |
| 779 | ||
| 780 | ops->remove(gaimbuddylist, node); | |
| 781 | g_free(group->name); | |
| 782 | g_free(group); | |
| 783 | } | |
| 784 | ||
| 785 | char *gaim_get_buddy_alias_only(struct buddy *b) { | |
|
5545
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
786 | if(!b) |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
787 | return NULL; |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
788 | |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
789 | if(b->alias && b->alias[0]) { |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
790 | return b->alias; |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
791 | } |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
792 | else if (b->server_alias != NULL && |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
793 | gaim_prefs_get_bool("/core/buddies/use_server_alias")) { |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
794 | |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
795 | return b->server_alias; |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
796 | } |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
797 | |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
798 | return NULL; |
| 5228 | 799 | } |
| 800 | ||
| 801 | char * gaim_get_buddy_alias (struct buddy *buddy) | |
| 802 | { | |
| 803 | char *ret = gaim_get_buddy_alias_only(buddy); | |
| 804 | ||
|
6036
285e48913c72
[gaim-migrate @ 6486]
Mark Doliner <markdoliner@pidgin.im>
parents:
6034
diff
changeset
|
805 | if(!ret) |
|
285e48913c72
[gaim-migrate @ 6486]
Mark Doliner <markdoliner@pidgin.im>
parents:
6034
diff
changeset
|
806 | return buddy ? buddy->name : _("Unknown"); |
|
285e48913c72
[gaim-migrate @ 6486]
Mark Doliner <markdoliner@pidgin.im>
parents:
6034
diff
changeset
|
807 | |
|
285e48913c72
[gaim-migrate @ 6486]
Mark Doliner <markdoliner@pidgin.im>
parents:
6034
diff
changeset
|
808 | return ret; |
| 5228 | 809 | } |
| 810 | ||
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
811 | struct buddy *gaim_find_buddy(GaimAccount *account, const char *name) |
| 5228 | 812 | { |
| 6245 | 813 | struct buddy *buddy; |
| 5247 | 814 | struct _gaim_hbuddy hb; |
| 5758 | 815 | GaimBlistNode *group; |
| 5228 | 816 | |
| 817 | if (!gaimbuddylist) | |
| 818 | return NULL; | |
| 6245 | 819 | |
| 820 | if (!name) | |
|
5985
69ab892a8fab
[gaim-migrate @ 6433]
Christian Hammond <chipx86@chipx86.com>
parents:
5947
diff
changeset
|
821 | return NULL; |
| 5228 | 822 | |
| 6245 | 823 | hb.name = normalize(name); |
| 824 | hb.account = account; | |
| 5247 | 825 | |
| 6245 | 826 | for(group = gaimbuddylist->root; group; group = group->next) { |
| 5758 | 827 | hb.group = group; |
| 5776 | 828 | if ((buddy = g_hash_table_lookup(gaimbuddylist->buddies, &hb)) != NULL) |
| 5758 | 829 | return buddy; |
| 830 | } | |
| 6245 | 831 | |
| 5758 | 832 | return NULL; |
| 5228 | 833 | } |
| 834 | ||
| 6245 | 835 | GSList *gaim_find_buddies(GaimAccount *account, const char *name) |
| 836 | { | |
| 837 | struct buddy *buddy; | |
| 838 | struct _gaim_hbuddy hb; | |
| 839 | GaimBlistNode *group; | |
| 840 | GSList *ret = NULL; | |
| 841 | ||
| 842 | if (!gaimbuddylist) | |
| 843 | return NULL; | |
| 844 | ||
| 845 | if (!name) | |
| 846 | return NULL; | |
| 847 | ||
| 848 | hb.name = normalize(name); | |
| 849 | hb.account = account; | |
| 850 | ||
| 851 | for(group = gaimbuddylist->root; group; group = group->next) { | |
| 852 | hb.group = group; | |
| 853 | if ((buddy = g_hash_table_lookup(gaimbuddylist->buddies, &hb)) != NULL) | |
| 854 | ret = g_slist_append(ret, buddy); | |
| 855 | } | |
| 856 | ||
| 857 | return ret; | |
| 858 | } | |
| 859 | ||
| 5228 | 860 | struct group *gaim_find_group(const char *name) |
| 861 | { | |
| 862 | GaimBlistNode *node; | |
| 863 | if (!gaimbuddylist) | |
| 864 | return NULL; | |
| 865 | node = gaimbuddylist->root; | |
| 866 | while(node) { | |
| 867 | if (!strcmp(((struct group*)node)->name, name)) | |
| 868 | return (struct group*)node; | |
| 869 | node = node->next; | |
| 870 | } | |
| 871 | return NULL; | |
| 872 | } | |
| 873 | struct group *gaim_find_buddys_group(struct buddy *buddy) | |
| 874 | { | |
| 875 | if (!buddy) | |
| 876 | return NULL; | |
| 877 | return (struct group*)(((GaimBlistNode*)buddy)->parent); | |
| 878 | } | |
| 879 | ||
| 880 | GSList *gaim_group_get_accounts(struct group *g) | |
| 881 | { | |
| 882 | GSList *l = NULL; | |
| 883 | GaimBlistNode *child = ((GaimBlistNode *)g)->child; | |
| 884 | ||
| 885 | while (child) { | |
|
6322
35fdae8a156f
[gaim-migrate @ 6821]
Mark Doliner <markdoliner@pidgin.im>
parents:
6308
diff
changeset
|
886 | GaimAccount *account = NULL; |
|
35fdae8a156f
[gaim-migrate @ 6821]
Mark Doliner <markdoliner@pidgin.im>
parents:
6308
diff
changeset
|
887 | if (GAIM_BLIST_NODE_IS_BUDDY(child)) |
|
35fdae8a156f
[gaim-migrate @ 6821]
Mark Doliner <markdoliner@pidgin.im>
parents:
6308
diff
changeset
|
888 | account = ((struct buddy *)child)->account; |
|
35fdae8a156f
[gaim-migrate @ 6821]
Mark Doliner <markdoliner@pidgin.im>
parents:
6308
diff
changeset
|
889 | else if (GAIM_BLIST_NODE_IS_CHAT(child)) |
|
35fdae8a156f
[gaim-migrate @ 6821]
Mark Doliner <markdoliner@pidgin.im>
parents:
6308
diff
changeset
|
890 | account = ((struct chat *)child)->account; |
|
35fdae8a156f
[gaim-migrate @ 6821]
Mark Doliner <markdoliner@pidgin.im>
parents:
6308
diff
changeset
|
891 | if (!g_slist_find(l, account)) |
|
35fdae8a156f
[gaim-migrate @ 6821]
Mark Doliner <markdoliner@pidgin.im>
parents:
6308
diff
changeset
|
892 | l = g_slist_append(l, account); |
| 5228 | 893 | child = child->next; |
| 894 | } | |
| 895 | return l; | |
| 896 | } | |
| 897 | ||
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
898 | void gaim_blist_add_account(GaimAccount *account) |
| 5234 | 899 | { |
| 900 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 901 | GaimBlistNode *group, *buddy; | |
| 902 | ||
| 903 | if(!gaimbuddylist) | |
| 904 | return; | |
| 905 | ||
| 906 | for(group = gaimbuddylist->root; group; group = group->next) { | |
| 907 | if(!GAIM_BLIST_NODE_IS_GROUP(group)) | |
| 908 | continue; | |
| 909 | for(buddy = group->child; buddy; buddy = buddy->next) { | |
| 910 | if(GAIM_BLIST_NODE_IS_BUDDY(buddy)) { | |
| 911 | if (account == ((struct buddy*)buddy)->account) { | |
| 5277 | 912 | ((struct group *)group)->currentsize++; |
| 5234 | 913 | if(ops) |
| 914 | ops->update(gaimbuddylist, buddy); | |
| 915 | } | |
| 916 | } else if(GAIM_BLIST_NODE_IS_CHAT(buddy)) { | |
| 917 | if (account == ((struct chat*)buddy)->account) { | |
| 5287 | 918 | ((struct group *)group)->online++; |
| 5277 | 919 | ((struct group *)group)->currentsize++; |
| 5234 | 920 | if(ops) |
| 921 | ops->update(gaimbuddylist, buddy); | |
| 922 | } | |
| 923 | } | |
| 924 | } | |
| 925 | } | |
| 926 | } | |
| 927 | ||
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
928 | void gaim_blist_remove_account(GaimAccount *account) |
| 5228 | 929 | { |
| 930 | struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | |
| 5234 | 931 | GaimBlistNode *group, *buddy; |
| 932 | ||
| 5228 | 933 | if (!gaimbuddylist) |
| 934 | return; | |
| 5234 | 935 | |
| 936 | for(group = gaimbuddylist->root; group; group = group->next) { | |
| 937 | if(!GAIM_BLIST_NODE_IS_GROUP(group)) | |
| 938 | continue; | |
| 939 | for(buddy = group->child; buddy; buddy = buddy->next) { | |
| 940 | if(GAIM_BLIST_NODE_IS_BUDDY(buddy)) { | |
| 941 | if (account == ((struct buddy*)buddy)->account) { | |
| 5394 | 942 | if (GAIM_BUDDY_IS_ONLINE((struct buddy*)buddy)) |
| 5277 | 943 | ((struct group *)group)->online--; |
| 5234 | 944 | ((struct buddy*)buddy)->present = GAIM_BUDDY_OFFLINE; |
| 5394 | 945 | ((struct group *)group)->currentsize--; |
| 5234 | 946 | if(ops) |
| 947 | ops->remove(gaimbuddylist, buddy); | |
| 948 | } | |
| 949 | } else if(GAIM_BLIST_NODE_IS_CHAT(buddy)) { | |
| 950 | if (account == ((struct chat*)buddy)->account) { | |
| 5277 | 951 | ((struct group *)group)->online--; |
| 952 | ((struct group *)group)->currentsize--; | |
| 5234 | 953 | if(ops) |
| 954 | ops->remove(gaimbuddylist, buddy); | |
| 955 | } | |
| 5228 | 956 | } |
| 957 | } | |
| 958 | } | |
| 959 | } | |
| 960 | ||
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
961 | void parse_toc_buddy_list(GaimAccount *account, char *config) |
| 5228 | 962 | { |
| 963 | char *c; | |
| 964 | char current[256]; | |
| 965 | GList *bud = NULL; | |
| 966 | ||
| 967 | ||
| 968 | if (config != NULL) { | |
| 969 | ||
| 970 | /* skip "CONFIG:" (if it exists) */ | |
| 971 | c = strncmp(config + 6 /* sizeof(struct sflap_hdr) */ , "CONFIG:", strlen("CONFIG:")) ? | |
| 972 | strtok(config, "\n") : | |
| 973 | strtok(config + 6 /* sizeof(struct sflap_hdr) */ + strlen("CONFIG:"), "\n"); | |
| 974 | do { | |
| 975 | if (c == NULL) | |
| 976 | break; | |
| 977 | if (*c == 'g') { | |
| 978 | char *utf8 = NULL; | |
| 979 | utf8 = gaim_try_conv_to_utf8(c + 2); | |
| 980 | if (utf8 == NULL) { | |
| 981 | g_strlcpy(current, _("Invalid Groupname"), sizeof(current)); | |
| 982 | } else { | |
| 983 | g_strlcpy(current, utf8, sizeof(current)); | |
| 984 | g_free(utf8); | |
| 985 | } | |
| 986 | if (!gaim_find_group(current)) { | |
| 987 | struct group *g = gaim_group_new(current); | |
| 5634 | 988 | gaim_blist_add_group(g, |
| 989 | gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
| 5228 | 990 | } |
| 991 | } else if (*c == 'b') { /*&& !gaim_find_buddy(user, c + 2)) {*/ | |
| 992 | char nm[80], sw[388], *a, *utf8 = NULL; | |
| 993 | ||
| 994 | if ((a = strchr(c + 2, ':')) != NULL) { | |
| 995 | *a++ = '\0'; /* nul the : */ | |
| 996 | } | |
| 997 | ||
| 998 | g_strlcpy(nm, c + 2, sizeof(nm)); | |
| 999 | if (a) { | |
| 1000 | utf8 = gaim_try_conv_to_utf8(a); | |
| 1001 | if (utf8 == NULL) { | |
| 1002 | gaim_debug(GAIM_DEBUG_ERROR, "toc blist", | |
| 1003 | "Failed to convert alias for " | |
| 1004 | "'%s' to UTF-8\n", nm); | |
| 1005 | } | |
| 1006 | } | |
| 1007 | if (utf8 == NULL) { | |
| 1008 | sw[0] = '\0'; | |
| 1009 | } else { | |
| 1010 | /* This can leave a partial sequence at the end, | |
| 1011 | * but who cares? */ | |
| 1012 | g_strlcpy(sw, utf8, sizeof(sw)); | |
| 1013 | g_free(utf8); | |
| 1014 | } | |
| 1015 | ||
| 1016 | if (!gaim_find_buddy(account, nm)) { | |
| 1017 | struct buddy *b = gaim_buddy_new(account, nm, sw); | |
| 1018 | struct group *g = gaim_find_group(current); | |
| 5634 | 1019 | gaim_blist_add_buddy(b, g, |
| 1020 | gaim_blist_get_last_child((GaimBlistNode*)g)); | |
| 5228 | 1021 | bud = g_list_append(bud, g_strdup(nm)); |
| 1022 | } | |
| 1023 | } else if (*c == 'p') { | |
|
6378
233d1294508f
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
1024 | gaim_privacy_permit_add(account, c + 2, TRUE); |
| 5228 | 1025 | } else if (*c == 'd') { |
|
6378
233d1294508f
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
1026 | gaim_privacy_deny_add(account, c + 2, TRUE); |
| 5228 | 1027 | } else if (!strncmp("toc", c, 3)) { |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1028 | sscanf(c + strlen(c) - 1, "%d", &account->perm_deny); |
| 5228 | 1029 | gaim_debug(GAIM_DEBUG_MISC, "toc blist", |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1030 | "permdeny: %d\n", account->perm_deny); |
|
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1031 | if (account->perm_deny == 0) |
|
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1032 | account->perm_deny = 1; |
| 5228 | 1033 | } else if (*c == 'm') { |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1034 | sscanf(c + 2, "%d", &account->perm_deny); |
| 5228 | 1035 | gaim_debug(GAIM_DEBUG_MISC, "toc blist", |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1036 | "permdeny: %d\n", account->perm_deny); |
|
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1037 | if (account->perm_deny == 0) |
|
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1038 | account->perm_deny = 1; |
| 5228 | 1039 | } |
| 1040 | } while ((c = strtok(NULL, "\n"))); | |
| 1041 | ||
| 1042 | if(account->gc) { | |
| 1043 | if(bud) { | |
| 1044 | GList *node = bud; | |
| 1045 | serv_add_buddies(account->gc, bud); | |
| 1046 | while(node) { | |
| 1047 | g_free(node->data); | |
| 1048 | node = node->next; | |
| 1049 | } | |
| 1050 | } | |
| 1051 | serv_set_permit_deny(account->gc); | |
| 1052 | } | |
| 1053 | g_list_free(bud); | |
| 1054 | } | |
| 1055 | } | |
| 1056 | ||
| 1057 | #if 0 | |
| 1058 | /* translate an AIM 3 buddylist (*.lst) to a Gaim buddylist */ | |
| 1059 | static GString *translate_lst(FILE *src_fp) | |
| 1060 | { | |
| 1061 | char line[BUF_LEN], *line2; | |
| 1062 | char *name; | |
| 1063 | int i; | |
| 1064 | ||
| 1065 | GString *dest = g_string_new("m 1\n"); | |
| 1066 | ||
| 1067 | while (fgets(line, BUF_LEN, src_fp)) { | |
| 1068 | line2 = g_strchug(line); | |
| 1069 | if (strstr(line2, "group") == line2) { | |
| 1070 | name = strpbrk(line2, " \t\n\r\f") + 1; | |
| 1071 | dest = g_string_append(dest, "g "); | |
| 1072 | for (i = 0; i < strcspn(name, "\n\r"); i++) | |
| 1073 | if (name[i] != '\"') | |
| 1074 | dest = g_string_append_c(dest, name[i]); | |
| 1075 | dest = g_string_append_c(dest, '\n'); | |
| 1076 | } | |
| 1077 | if (strstr(line2, "buddy") == line2) { | |
| 1078 | name = strpbrk(line2, " \t\n\r\f") + 1; | |
| 1079 | dest = g_string_append(dest, "b "); | |
| 1080 | for (i = 0; i < strcspn(name, "\n\r"); i++) | |
| 1081 | if (name[i] != '\"') | |
| 1082 | dest = g_string_append_c(dest, name[i]); | |
| 1083 | dest = g_string_append_c(dest, '\n'); | |
| 1084 | } | |
| 1085 | } | |
| 1086 | ||
| 1087 | return dest; | |
| 1088 | } | |
| 1089 | ||
| 1090 | ||
| 1091 | /* translate an AIM 4 buddylist (*.blt) to Gaim format */ | |
| 1092 | static GString *translate_blt(FILE *src_fp) | |
| 1093 | { | |
| 1094 | int i; | |
| 1095 | char line[BUF_LEN]; | |
| 1096 | char *buddy; | |
| 1097 | ||
| 1098 | GString *dest = g_string_new("m 1\n"); | |
| 1099 | ||
| 1100 | while (strstr(fgets(line, BUF_LEN, src_fp), "Buddy") == NULL); | |
| 1101 | while (strstr(fgets(line, BUF_LEN, src_fp), "list") == NULL); | |
| 1102 | ||
| 1103 | while (1) { | |
| 1104 | fgets(line, BUF_LEN, src_fp); g_strchomp(line); | |
| 1105 | if (strchr(line, '}') != NULL) | |
| 1106 | break; | |
| 1107 | ||
| 1108 | if (strchr(line, '{') != NULL) { | |
| 1109 | /* Syntax starting with "<group> {" */ | |
| 1110 | ||
| 1111 | dest = g_string_append(dest, "g "); | |
| 1112 | buddy = g_strchug(strtok(line, "{")); | |
| 1113 | for (i = 0; i < strlen(buddy); i++) | |
| 1114 | if (buddy[i] != '\"') | |
| 1115 | dest = g_string_append_c(dest, buddy[i]); | |
| 1116 | dest = g_string_append_c(dest, '\n'); | |
| 1117 | while (strchr(fgets(line, BUF_LEN, src_fp), '}') == NULL) { | |
| 1118 | gboolean pounce = FALSE; | |
| 1119 | char *e; | |
| 1120 | g_strchomp(line); | |
| 1121 | buddy = g_strchug(line); | |
| 1122 | gaim_debug(GAIM_DEBUG_MISC, "AIM 4 blt import", | |
| 1123 | "buddy: \"%s\"\n", buddy); | |
| 1124 | dest = g_string_append(dest, "b "); | |
| 1125 | if (strchr(buddy, '{') != NULL) { | |
| 1126 | /* buddy pounce, etc */ | |
| 1127 | char *pos = strchr(buddy, '{') - 1; | |
| 1128 | *pos = 0; | |
| 1129 | pounce = TRUE; | |
| 1130 | } | |
| 1131 | if ((e = strchr(buddy, '\"')) != NULL) { | |
| 1132 | *e = '\0'; | |
| 1133 | buddy++; | |
| 1134 | } | |
| 1135 | dest = g_string_append(dest, buddy); | |
| 1136 | dest = g_string_append_c(dest, '\n'); | |
| 1137 | if (pounce) | |
| 1138 | do | |
| 1139 | fgets(line, BUF_LEN, src_fp); | |
| 1140 | while (!strchr(line, '}')); | |
| 1141 | } | |
| 1142 | } else { | |
| 1143 | ||
| 1144 | /* Syntax "group buddy buddy ..." */ | |
| 1145 | buddy = g_strchug(strtok(line, " \n")); | |
| 1146 | dest = g_string_append(dest, "g "); | |
| 1147 | if (strchr(buddy, '\"') != NULL) { | |
| 1148 | dest = g_string_append(dest, &buddy[1]); | |
| 1149 | dest = g_string_append_c(dest, ' '); | |
| 1150 | buddy = g_strchug(strtok(NULL, " \n")); | |
| 1151 | while (strchr(buddy, '\"') == NULL) { | |
| 1152 | dest = g_string_append(dest, buddy); | |
| 1153 | dest = g_string_append_c(dest, ' '); | |
| 1154 | buddy = g_strchug(strtok(NULL, " \n")); | |
| 1155 | } | |
| 1156 | buddy[strlen(buddy) - 1] = '\0'; | |
| 1157 | dest = g_string_append(dest, buddy); | |
| 1158 | } else { | |
| 1159 | dest = g_string_append(dest, buddy); | |
| 1160 | } | |
| 1161 | dest = g_string_append_c(dest, '\n'); | |
| 1162 | while ((buddy = g_strchug(strtok(NULL, " \n"))) != NULL) { | |
| 1163 | dest = g_string_append(dest, "b "); | |
| 1164 | if (strchr(buddy, '\"') != NULL) { | |
| 1165 | dest = g_string_append(dest, &buddy[1]); | |
| 1166 | dest = g_string_append_c(dest, ' '); | |
| 1167 | buddy = g_strchug(strtok(NULL, " \n")); | |
| 1168 | while (strchr(buddy, '\"') == NULL) { | |
| 1169 | dest = g_string_append(dest, buddy); | |
| 1170 | dest = g_string_append_c(dest, ' '); | |
| 1171 | buddy = g_strchug(strtok(NULL, " \n")); | |
| 1172 | } | |
| 1173 | buddy[strlen(buddy) - 1] = '\0'; | |
| 1174 | dest = g_string_append(dest, buddy); | |
| 1175 | } else { | |
| 1176 | dest = g_string_append(dest, buddy); | |
| 1177 | } | |
| 1178 | dest = g_string_append_c(dest, '\n'); | |
| 1179 | } | |
| 1180 | } | |
| 1181 | } | |
| 1182 | ||
| 1183 | return dest; | |
| 1184 | } | |
| 1185 | ||
| 1186 | static GString *translate_gnomeicu(FILE *src_fp) | |
| 1187 | { | |
| 1188 | char line[BUF_LEN]; | |
| 1189 | GString *dest = g_string_new("m 1\ng Buddies\n"); | |
| 1190 | ||
| 1191 | while (strstr(fgets(line, BUF_LEN, src_fp), "NewContacts") == NULL); | |
| 1192 | ||
| 1193 | while (fgets(line, BUF_LEN, src_fp)) { | |
| 1194 | char *eq; | |
| 1195 | g_strchomp(line); | |
| 1196 | if (line[0] == '\n' || line[0] == '[') | |
| 1197 | break; | |
| 1198 | eq = strchr(line, '='); | |
| 1199 | if (!eq) | |
| 1200 | break; | |
| 1201 | *eq = ':'; | |
| 1202 | eq = strchr(eq, ','); | |
| 1203 | if (eq) | |
| 1204 | *eq = '\0'; | |
| 1205 | dest = g_string_append(dest, "b "); | |
| 1206 | dest = g_string_append(dest, line); | |
| 1207 | dest = g_string_append_c(dest, '\n'); | |
| 1208 | } | |
| 1209 | ||
| 1210 | return dest; | |
| 1211 | } | |
| 1212 | #endif | |
| 1213 | ||
| 1214 | static gchar *get_screenname_filename(const char *name) | |
| 1215 | { | |
| 1216 | gchar **split; | |
| 1217 | gchar *good; | |
| 1218 | gchar *ret; | |
| 1219 | ||
| 1220 | split = g_strsplit(name, G_DIR_SEPARATOR_S, -1); | |
| 1221 | good = g_strjoinv(NULL, split); | |
| 1222 | g_strfreev(split); | |
| 1223 | ||
| 1224 | ret = g_utf8_strup(good, -1); | |
| 1225 | ||
| 1226 | g_free(good); | |
| 1227 | ||
| 1228 | return ret; | |
| 1229 | } | |
| 1230 | ||
| 1231 | static gboolean gaim_blist_read(const char *filename); | |
| 1232 | ||
| 1233 | ||
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1234 | static void do_import(GaimAccount *account, const char *filename) |
| 5228 | 1235 | { |
| 1236 | GString *buf = NULL; | |
| 1237 | char first[64]; | |
| 1238 | char path[PATHSIZE]; | |
| 1239 | int len; | |
| 1240 | FILE *f; | |
| 1241 | struct stat st; | |
| 1242 | ||
| 1243 | if (filename) { | |
| 1244 | g_snprintf(path, sizeof(path), "%s", filename); | |
| 1245 | } else { | |
| 1246 | char *g_screenname = get_screenname_filename(account->username); | |
|
5943
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1247 | const char *username; |
| 5228 | 1248 | char *file = gaim_user_dir(); |
|
5943
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1249 | GaimProtocol prpl_num; |
|
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1250 | int protocol; |
|
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1251 | |
|
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1252 | prpl_num = gaim_account_get_protocol(account); |
|
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1253 | |
|
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1254 | protocol = prpl_num; |
|
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1255 | |
|
6450
4c2364a4b6a4
[gaim-migrate @ 6959]
Christian Hammond <chipx86@chipx86.com>
parents:
6392
diff
changeset
|
1256 | /* TODO Somehow move this checking into prpls */ |
|
5943
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1257 | if (prpl_num == GAIM_PROTO_OSCAR) { |
|
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1258 | if ((username = gaim_account_get_username(account)) != NULL) { |
|
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1259 | protocol = (isalpha(*username) |
|
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1260 | ? GAIM_PROTO_TOC : GAIM_PROTO_ICQ); |
|
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1261 | } |
|
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1262 | } |
| 5228 | 1263 | |
| 1264 | if (file != (char *)NULL) { | |
|
5435
990c340ecb6d
[gaim-migrate @ 5817]
Mark Doliner <markdoliner@pidgin.im>
parents:
5394
diff
changeset
|
1265 | snprintf(path, PATHSIZE, "%s" G_DIR_SEPARATOR_S "%s.%d.blist", file, g_screenname, protocol); |
| 5228 | 1266 | g_free(g_screenname); |
| 1267 | } else { | |
| 1268 | g_free(g_screenname); | |
| 1269 | return; | |
| 1270 | } | |
| 1271 | } | |
| 1272 | ||
| 1273 | if (stat(path, &st)) { | |
| 1274 | gaim_debug(GAIM_DEBUG_ERROR, "blist import", "Unable to stat %s.\n", | |
| 1275 | path); | |
| 1276 | return; | |
| 1277 | } | |
| 1278 | ||
| 1279 | if (!(f = fopen(path, "r"))) { | |
| 1280 | gaim_debug(GAIM_DEBUG_ERROR, "blist import", "Unable to open %s.\n", | |
| 1281 | path); | |
| 1282 | return; | |
| 1283 | } | |
| 1284 | ||
| 1285 | fgets(first, 64, f); | |
| 1286 | ||
| 1287 | if ((first[0] == '\n') || (first[0] == '\r' && first[1] == '\n')) | |
| 1288 | fgets(first, 64, f); | |
| 1289 | ||
| 1290 | #if 0 | |
| 1291 | if (!g_strncasecmp(first, "<xml", strlen("<xml"))) { | |
| 1292 | /* new gaim XML buddy list */ | |
| 1293 | gaim_blist_read(path); | |
| 1294 | ||
| 1295 | /* We really don't need to bother doing stuf like translating AIM 3 buddy lists anymore */ | |
| 1296 | ||
| 1297 | } else if (!g_strncasecmp(first, "Config {", strlen("Config {"))) { | |
| 1298 | /* AIM 4 buddy list */ | |
| 1299 | gaim_debug(GAIM_DEBUG_MISC, "blist import", "aim 4\n"); | |
| 1300 | rewind(f); | |
| 1301 | buf = translate_blt(f); | |
| 1302 | } else if (strstr(first, "group") != NULL) { | |
| 1303 | /* AIM 3 buddy list */ | |
| 1304 | gaim_debug(GAIM_DEBUG_MISC, "blist import", "aim 3\n"); | |
| 1305 | rewind(f); | |
| 1306 | buf = translate_lst(f); | |
| 1307 | } else if (!g_strncasecmp(first, "[User]", strlen("[User]"))) { | |
| 1308 | /* GnomeICU (hopefully) */ | |
| 1309 | gaim_debug(GAIM_DEBUG_MISC, "blist import", "gnomeicu\n"); | |
| 1310 | rewind(f); | |
| 1311 | buf = translate_gnomeicu(f); | |
| 1312 | ||
| 1313 | } else | |
| 1314 | #endif | |
| 1315 | if (first[0] == 'm') { | |
| 1316 | /* Gaim buddy list - no translation */ | |
| 1317 | char buf2[BUF_LONG * 2]; | |
| 1318 | buf = g_string_new(""); | |
| 1319 | rewind(f); | |
| 1320 | while (1) { | |
| 1321 | len = fread(buf2, 1, BUF_LONG * 2 - 1, f); | |
| 1322 | if (len <= 0) | |
| 1323 | break; | |
| 1324 | buf2[len] = '\0'; | |
| 1325 | buf = g_string_append(buf, buf2); | |
| 1326 | if (len != BUF_LONG * 2 - 1) | |
| 1327 | break; | |
| 1328 | } | |
| 1329 | } | |
| 1330 | ||
| 1331 | fclose(f); | |
| 1332 | ||
| 1333 | if (buf) { | |
| 1334 | buf = g_string_prepend(buf, "toc_set_config {"); | |
| 1335 | buf = g_string_append(buf, "}\n"); | |
| 1336 | parse_toc_buddy_list(account, buf->str); | |
| 1337 | g_string_free(buf, TRUE); | |
| 1338 | } | |
| 1339 | } | |
| 1340 | ||
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1341 | gboolean gaim_group_on_account(struct group *g, GaimAccount *account) { |
| 5228 | 1342 | GaimBlistNode *bnode; |
| 1343 | for(bnode = g->node.child; bnode; bnode = bnode->next) { | |
| 1344 | struct buddy *b = (struct buddy *)bnode; | |
| 1345 | if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
| 1346 | continue; | |
| 5855 | 1347 | if((!account && gaim_account_is_connected(b->account)) |
| 1348 | || b->account == account) | |
| 5228 | 1349 | return TRUE; |
| 1350 | } | |
| 1351 | return FALSE; | |
| 1352 | } | |
| 1353 | ||
| 1354 | static gboolean blist_safe_to_write = FALSE; | |
| 1355 | ||
| 1356 | static char *blist_parser_group_name = NULL; | |
| 1357 | static char *blist_parser_person_name = NULL; | |
| 1358 | static char *blist_parser_account_name = NULL; | |
| 1359 | static int blist_parser_account_protocol = 0; | |
| 5234 | 1360 | static char *blist_parser_chat_alias = NULL; |
| 1361 | static char *blist_parser_component_name = NULL; | |
| 1362 | static char *blist_parser_component_value = NULL; | |
| 5228 | 1363 | static char *blist_parser_buddy_name = NULL; |
| 1364 | static char *blist_parser_buddy_alias = NULL; | |
| 1365 | static char *blist_parser_setting_name = NULL; | |
| 1366 | static char *blist_parser_setting_value = NULL; | |
| 1367 | static GHashTable *blist_parser_buddy_settings = NULL; | |
| 5906 | 1368 | static GHashTable *blist_parser_chat_settings = NULL; |
| 5228 | 1369 | static GHashTable *blist_parser_group_settings = NULL; |
| 5234 | 1370 | static GHashTable *blist_parser_chat_components = NULL; |
| 5228 | 1371 | static int blist_parser_privacy_mode = 0; |
| 1372 | static GList *tag_stack = NULL; | |
| 1373 | enum { | |
| 1374 | BLIST_TAG_GAIM, | |
| 1375 | BLIST_TAG_BLIST, | |
| 1376 | BLIST_TAG_GROUP, | |
| 5234 | 1377 | BLIST_TAG_CHAT, |
| 1378 | BLIST_TAG_COMPONENT, | |
| 5228 | 1379 | BLIST_TAG_PERSON, |
| 1380 | BLIST_TAG_BUDDY, | |
| 1381 | BLIST_TAG_NAME, | |
| 1382 | BLIST_TAG_ALIAS, | |
| 1383 | BLIST_TAG_SETTING, | |
| 1384 | BLIST_TAG_PRIVACY, | |
| 1385 | BLIST_TAG_ACCOUNT, | |
| 1386 | BLIST_TAG_PERMIT, | |
| 1387 | BLIST_TAG_BLOCK, | |
| 1388 | BLIST_TAG_IGNORE | |
| 1389 | }; | |
| 1390 | static gboolean blist_parser_error_occurred = FALSE; | |
| 1391 | ||
| 1392 | static void blist_start_element_handler (GMarkupParseContext *context, | |
| 1393 | const gchar *element_name, | |
| 1394 | const gchar **attribute_names, | |
| 1395 | const gchar **attribute_values, | |
| 1396 | gpointer user_data, | |
| 1397 | GError **error) { | |
| 1398 | int i; | |
| 1399 | ||
| 1400 | if(!strcmp(element_name, "gaim")) { | |
| 1401 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_GAIM)); | |
| 1402 | } else if(!strcmp(element_name, "blist")) { | |
| 1403 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_BLIST)); | |
| 1404 | } else if(!strcmp(element_name, "group")) { | |
| 1405 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_GROUP)); | |
| 1406 | for(i=0; attribute_names[i]; i++) { | |
| 1407 | if(!strcmp(attribute_names[i], "name")) { | |
| 1408 | g_free(blist_parser_group_name); | |
| 1409 | blist_parser_group_name = g_strdup(attribute_values[i]); | |
| 1410 | } | |
| 1411 | } | |
| 1412 | if(blist_parser_group_name) { | |
| 1413 | struct group *g = gaim_group_new(blist_parser_group_name); | |
| 5634 | 1414 | gaim_blist_add_group(g, |
| 1415 | gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
| 5228 | 1416 | } |
| 5234 | 1417 | } else if(!strcmp(element_name, "chat")) { |
| 1418 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_CHAT)); | |
| 1419 | for(i=0; attribute_names[i]; i++) { | |
| 1420 | if(!strcmp(attribute_names[i], "account")) { | |
| 1421 | g_free(blist_parser_account_name); | |
| 1422 | blist_parser_account_name = g_strdup(attribute_values[i]); | |
| 1423 | } else if(!strcmp(attribute_names[i], "protocol")) { | |
| 1424 | blist_parser_account_protocol = atoi(attribute_values[i]); | |
| 1425 | } | |
| 1426 | } | |
| 5228 | 1427 | } else if(!strcmp(element_name, "person")) { |
| 1428 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_PERSON)); | |
| 1429 | for(i=0; attribute_names[i]; i++) { | |
| 1430 | if(!strcmp(attribute_names[i], "name")) { | |
| 1431 | g_free(blist_parser_person_name); | |
| 1432 | blist_parser_person_name = g_strdup(attribute_values[i]); | |
| 1433 | } | |
| 1434 | } | |
| 1435 | } else if(!strcmp(element_name, "buddy")) { | |
| 1436 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_BUDDY)); | |
| 1437 | for(i=0; attribute_names[i]; i++) { | |
| 1438 | if(!strcmp(attribute_names[i], "account")) { | |
| 1439 | g_free(blist_parser_account_name); | |
| 1440 | blist_parser_account_name = g_strdup(attribute_values[i]); | |
| 1441 | } else if(!strcmp(attribute_names[i], "protocol")) { | |
| 1442 | blist_parser_account_protocol = atoi(attribute_values[i]); | |
| 1443 | } | |
| 1444 | } | |
| 1445 | } else if(!strcmp(element_name, "name")) { | |
| 1446 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_NAME)); | |
| 1447 | } else if(!strcmp(element_name, "alias")) { | |
| 1448 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_ALIAS)); | |
| 1449 | } else if(!strcmp(element_name, "setting")) { | |
| 1450 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_SETTING)); | |
| 1451 | for(i=0; attribute_names[i]; i++) { | |
| 1452 | if(!strcmp(attribute_names[i], "name")) { | |
| 1453 | g_free(blist_parser_setting_name); | |
| 1454 | blist_parser_setting_name = g_strdup(attribute_values[i]); | |
| 1455 | } | |
| 1456 | } | |
| 5234 | 1457 | } else if(!strcmp(element_name, "component")) { |
| 1458 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_COMPONENT)); | |
| 1459 | for(i=0; attribute_names[i]; i++) { | |
| 1460 | if(!strcmp(attribute_names[i], "name")) { | |
| 1461 | g_free(blist_parser_component_name); | |
| 1462 | blist_parser_component_name = g_strdup(attribute_values[i]); | |
| 1463 | } | |
| 1464 | } | |
| 1465 | ||
| 5228 | 1466 | } else if(!strcmp(element_name, "privacy")) { |
| 1467 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_PRIVACY)); | |
| 1468 | } else if(!strcmp(element_name, "account")) { | |
| 1469 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_ACCOUNT)); | |
| 1470 | for(i=0; attribute_names[i]; i++) { | |
| 1471 | if(!strcmp(attribute_names[i], "protocol")) | |
| 1472 | blist_parser_account_protocol = atoi(attribute_values[i]); | |
| 1473 | else if(!strcmp(attribute_names[i], "mode")) | |
| 1474 | blist_parser_privacy_mode = atoi(attribute_values[i]); | |
| 1475 | else if(!strcmp(attribute_names[i], "name")) { | |
| 1476 | g_free(blist_parser_account_name); | |
| 1477 | blist_parser_account_name = g_strdup(attribute_values[i]); | |
| 1478 | } | |
| 1479 | } | |
| 1480 | } else if(!strcmp(element_name, "permit")) { | |
| 1481 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_PERMIT)); | |
| 1482 | } else if(!strcmp(element_name, "block")) { | |
| 1483 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_BLOCK)); | |
| 1484 | } else if(!strcmp(element_name, "ignore")) { | |
| 1485 | tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_IGNORE)); | |
| 1486 | } | |
| 1487 | } | |
| 1488 | ||
| 1489 | static void blist_end_element_handler(GMarkupParseContext *context, | |
| 1490 | const gchar *element_name, gpointer user_data, GError **error) { | |
| 1491 | if(!strcmp(element_name, "gaim")) { | |
| 1492 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1493 | } else if(!strcmp(element_name, "blist")) { | |
| 1494 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1495 | } else if(!strcmp(element_name, "group")) { | |
| 1496 | if(blist_parser_group_settings) { | |
| 1497 | struct group *g = gaim_find_group(blist_parser_group_name); | |
| 1498 | g_hash_table_destroy(g->settings); | |
| 1499 | g->settings = blist_parser_group_settings; | |
| 1500 | } | |
| 1501 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1502 | blist_parser_group_settings = NULL; | |
| 5234 | 1503 | } else if(!strcmp(element_name, "chat")) { |
|
5874
5e19273d3c6f
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1504 | GaimAccount *account = gaim_accounts_find(blist_parser_account_name, |
| 5234 | 1505 | blist_parser_account_protocol); |
| 5237 | 1506 | if(account) { |
| 5234 | 1507 | struct chat *chat = gaim_chat_new(account, blist_parser_chat_alias, blist_parser_chat_components); |
| 1508 | struct group *g = gaim_find_group(blist_parser_group_name); | |
| 5634 | 1509 | gaim_blist_add_chat(chat,g, |
| 1510 | gaim_blist_get_last_child((GaimBlistNode*)g)); | |
| 5906 | 1511 | if(blist_parser_chat_settings) { |
| 1512 | g_hash_table_destroy(chat->settings); | |
| 1513 | chat->settings = blist_parser_chat_settings; | |
| 1514 | } | |
| 5234 | 1515 | } |
| 1516 | g_free(blist_parser_chat_alias); | |
| 1517 | blist_parser_chat_alias = NULL; | |
| 1518 | g_free(blist_parser_account_name); | |
| 1519 | blist_parser_account_name = NULL; | |
| 1520 | blist_parser_chat_components = NULL; | |
| 5906 | 1521 | blist_parser_chat_settings = NULL; |
| 5234 | 1522 | tag_stack = g_list_delete_link(tag_stack, tag_stack); |
| 5228 | 1523 | } else if(!strcmp(element_name, "person")) { |
| 1524 | g_free(blist_parser_person_name); | |
| 1525 | blist_parser_person_name = NULL; | |
| 1526 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1527 | } else if(!strcmp(element_name, "buddy")) { | |
|
5874
5e19273d3c6f
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1528 | GaimAccount *account = gaim_accounts_find(blist_parser_account_name, |
| 5228 | 1529 | blist_parser_account_protocol); |
| 1530 | if(account) { | |
| 1531 | struct buddy *b = gaim_buddy_new(account, blist_parser_buddy_name, blist_parser_buddy_alias); | |
| 1532 | struct group *g = gaim_find_group(blist_parser_group_name); | |
| 5634 | 1533 | gaim_blist_add_buddy(b,g, |
| 1534 | gaim_blist_get_last_child((GaimBlistNode*)g)); | |
| 5228 | 1535 | if(blist_parser_buddy_settings) { |
| 1536 | g_hash_table_destroy(b->settings); | |
| 1537 | b->settings = blist_parser_buddy_settings; | |
| 1538 | } | |
| 1539 | } | |
| 1540 | g_free(blist_parser_buddy_name); | |
| 1541 | blist_parser_buddy_name = NULL; | |
| 1542 | g_free(blist_parser_buddy_alias); | |
| 1543 | blist_parser_buddy_alias = NULL; | |
| 1544 | g_free(blist_parser_account_name); | |
| 1545 | blist_parser_account_name = NULL; | |
| 1546 | blist_parser_buddy_settings = NULL; | |
| 1547 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1548 | } else if(!strcmp(element_name, "name")) { | |
| 1549 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1550 | } else if(!strcmp(element_name, "alias")) { | |
| 1551 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 5234 | 1552 | } else if(!strcmp(element_name, "component")) { |
| 1553 | if(!blist_parser_chat_components) | |
| 1554 | blist_parser_chat_components = g_hash_table_new_full(g_str_hash, | |
| 1555 | g_str_equal, g_free, g_free); | |
| 1556 | if(blist_parser_component_name && blist_parser_component_value) { | |
| 1557 | g_hash_table_replace(blist_parser_chat_components, | |
| 1558 | g_strdup(blist_parser_component_name), | |
| 1559 | g_strdup(blist_parser_component_value)); | |
| 1560 | } | |
| 1561 | g_free(blist_parser_component_name); | |
| 1562 | g_free(blist_parser_component_value); | |
| 1563 | blist_parser_component_name = NULL; | |
| 1564 | blist_parser_component_value = NULL; | |
| 1565 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 5228 | 1566 | } else if(!strcmp(element_name, "setting")) { |
| 1567 | if(GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_BUDDY) { | |
| 1568 | if(!blist_parser_buddy_settings) | |
| 1569 | blist_parser_buddy_settings = g_hash_table_new_full(g_str_hash, | |
| 1570 | g_str_equal, g_free, g_free); | |
| 1571 | if(blist_parser_setting_name && blist_parser_setting_value) { | |
| 1572 | g_hash_table_replace(blist_parser_buddy_settings, | |
| 1573 | g_strdup(blist_parser_setting_name), | |
| 1574 | g_strdup(blist_parser_setting_value)); | |
| 1575 | } | |
| 5906 | 1576 | } else if(GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_CHAT) { |
| 1577 | if(!blist_parser_chat_settings) | |
| 1578 | blist_parser_chat_settings = g_hash_table_new_full(g_str_hash, | |
| 1579 | g_str_equal, g_free, g_free); | |
| 1580 | if(blist_parser_setting_name && blist_parser_setting_value) { | |
|
6307
08774a6785ac
[gaim-migrate @ 6806]
Mark Doliner <markdoliner@pidgin.im>
parents:
6245
diff
changeset
|
1581 | g_hash_table_replace(blist_parser_chat_settings, |
| 5906 | 1582 | g_strdup(blist_parser_setting_name), |
| 1583 | g_strdup(blist_parser_setting_value)); | |
| 1584 | } | |
| 5228 | 1585 | } else if(GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_GROUP) { |
| 1586 | if(!blist_parser_group_settings) | |
| 1587 | blist_parser_group_settings = g_hash_table_new_full(g_str_hash, | |
| 1588 | g_str_equal, g_free, g_free); | |
| 1589 | if(blist_parser_setting_name && blist_parser_setting_value) { | |
| 1590 | g_hash_table_replace(blist_parser_group_settings, | |
| 1591 | g_strdup(blist_parser_setting_name), | |
| 1592 | g_strdup(blist_parser_setting_value)); | |
| 1593 | } | |
| 1594 | } | |
| 1595 | g_free(blist_parser_setting_name); | |
| 1596 | g_free(blist_parser_setting_value); | |
| 1597 | blist_parser_setting_name = NULL; | |
| 1598 | blist_parser_setting_value = NULL; | |
| 1599 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1600 | } else if(!strcmp(element_name, "privacy")) { | |
| 1601 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1602 | } else if(!strcmp(element_name, "account")) { | |
|
5874
5e19273d3c6f
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1603 | GaimAccount *account = gaim_accounts_find(blist_parser_account_name, |
| 5228 | 1604 | blist_parser_account_protocol); |
| 1605 | if(account) { | |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1606 | account->perm_deny = blist_parser_privacy_mode; |
| 5228 | 1607 | } |
| 1608 | g_free(blist_parser_account_name); | |
| 1609 | blist_parser_account_name = NULL; | |
| 1610 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1611 | } else if(!strcmp(element_name, "permit")) { | |
|
5874
5e19273d3c6f
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1612 | GaimAccount *account = gaim_accounts_find(blist_parser_account_name, |
| 5228 | 1613 | blist_parser_account_protocol); |
| 1614 | if(account) { | |
|
6378
233d1294508f
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
1615 | gaim_privacy_permit_add(account, blist_parser_buddy_name, TRUE); |
| 5228 | 1616 | } |
| 1617 | g_free(blist_parser_buddy_name); | |
| 1618 | blist_parser_buddy_name = NULL; | |
| 1619 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1620 | } else if(!strcmp(element_name, "block")) { | |
|
5874
5e19273d3c6f
[gaim-migrate @ 6306]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1621 | GaimAccount *account = gaim_accounts_find(blist_parser_account_name, |
| 5228 | 1622 | blist_parser_account_protocol); |
| 1623 | if(account) { | |
|
6378
233d1294508f
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
1624 | gaim_privacy_deny_add(account, blist_parser_buddy_name, TRUE); |
| 5228 | 1625 | } |
| 1626 | g_free(blist_parser_buddy_name); | |
| 1627 | blist_parser_buddy_name = NULL; | |
| 1628 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1629 | } else if(!strcmp(element_name, "ignore")) { | |
| 1630 | /* we'll apparently do something with this later */ | |
| 1631 | tag_stack = g_list_delete_link(tag_stack, tag_stack); | |
| 1632 | } | |
| 1633 | } | |
| 1634 | ||
| 1635 | static void blist_text_handler(GMarkupParseContext *context, const gchar *text, | |
| 1636 | gsize text_len, gpointer user_data, GError **error) { | |
| 1637 | switch(GPOINTER_TO_INT(tag_stack->data)) { | |
| 1638 | case BLIST_TAG_NAME: | |
| 1639 | blist_parser_buddy_name = g_strndup(text, text_len); | |
| 1640 | break; | |
| 1641 | case BLIST_TAG_ALIAS: | |
| 5234 | 1642 | if(tag_stack->next && |
| 1643 | GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_BUDDY) | |
| 1644 | blist_parser_buddy_alias = g_strndup(text, text_len); | |
| 1645 | else if(tag_stack->next && | |
| 1646 | GPOINTER_TO_INT(tag_stack->next->data) == BLIST_TAG_CHAT) | |
| 1647 | blist_parser_chat_alias = g_strndup(text, text_len); | |
| 5228 | 1648 | break; |
| 1649 | case BLIST_TAG_PERMIT: | |
| 1650 | case BLIST_TAG_BLOCK: | |
| 1651 | case BLIST_TAG_IGNORE: | |
| 1652 | blist_parser_buddy_name = g_strndup(text, text_len); | |
| 1653 | break; | |
| 5234 | 1654 | case BLIST_TAG_COMPONENT: |
| 1655 | blist_parser_component_value = g_strndup(text, text_len); | |
| 1656 | break; | |
| 5228 | 1657 | case BLIST_TAG_SETTING: |
| 1658 | blist_parser_setting_value = g_strndup(text, text_len); | |
| 1659 | break; | |
| 1660 | default: | |
| 1661 | break; | |
| 1662 | } | |
| 1663 | } | |
| 1664 | ||
| 1665 | static void blist_error_handler(GMarkupParseContext *context, GError *error, | |
| 1666 | gpointer user_data) { | |
| 1667 | blist_parser_error_occurred = TRUE; | |
| 1668 | gaim_debug(GAIM_DEBUG_ERROR, "blist import", | |
| 1669 | "Error parsing blist.xml: %s\n", error->message); | |
| 1670 | } | |
| 1671 | ||
| 1672 | static GMarkupParser blist_parser = { | |
| 1673 | blist_start_element_handler, | |
| 1674 | blist_end_element_handler, | |
| 1675 | blist_text_handler, | |
| 1676 | NULL, | |
| 1677 | blist_error_handler | |
| 1678 | }; | |
| 1679 | ||
| 1680 | static gboolean gaim_blist_read(const char *filename) { | |
| 1681 | gchar *contents = NULL; | |
| 1682 | gsize length; | |
| 1683 | GMarkupParseContext *context; | |
| 1684 | GError *error = NULL; | |
| 1685 | ||
| 1686 | gaim_debug(GAIM_DEBUG_INFO, "blist import", | |
| 1687 | "Reading %s\n", filename); | |
| 1688 | if(!g_file_get_contents(filename, &contents, &length, &error)) { | |
| 1689 | gaim_debug(GAIM_DEBUG_ERROR, "blist import", | |
| 1690 | "Error reading blist: %s\n", error->message); | |
| 1691 | g_error_free(error); | |
| 1692 | return FALSE; | |
| 1693 | } | |
| 1694 | ||
| 1695 | context = g_markup_parse_context_new(&blist_parser, 0, NULL, NULL); | |
| 1696 | ||
| 1697 | if(!g_markup_parse_context_parse(context, contents, length, NULL)) { | |
| 1698 | g_markup_parse_context_free(context); | |
| 1699 | g_free(contents); | |
| 1700 | return FALSE; | |
| 1701 | } | |
| 1702 | ||
| 1703 | if(!g_markup_parse_context_end_parse(context, NULL)) { | |
| 1704 | gaim_debug(GAIM_DEBUG_ERROR, "blist import", | |
| 1705 | "Error parsing %s\n", filename); | |
| 1706 | g_markup_parse_context_free(context); | |
| 1707 | g_free(contents); | |
| 1708 | return FALSE; | |
| 1709 | } | |
| 1710 | ||
| 1711 | g_markup_parse_context_free(context); | |
| 1712 | g_free(contents); | |
| 1713 | ||
| 1714 | if(blist_parser_error_occurred) | |
| 1715 | return FALSE; | |
| 1716 | ||
| 1717 | gaim_debug(GAIM_DEBUG_INFO, "blist import", "Finished reading %s\n", | |
| 1718 | filename); | |
| 1719 | ||
| 1720 | return TRUE; | |
| 1721 | } | |
| 1722 | ||
| 1723 | void gaim_blist_load() { | |
|
5580
a5a3e6dfb409
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1724 | GList *accts; |
| 5228 | 1725 | char *user_dir = gaim_user_dir(); |
| 1726 | char *filename; | |
| 1727 | char *msg; | |
| 1728 | ||
| 1729 | blist_safe_to_write = TRUE; | |
| 1730 | ||
| 1731 | if(!user_dir) | |
| 1732 | return; | |
| 1733 | ||
| 1734 | filename = g_build_filename(user_dir, "blist.xml", NULL); | |
| 1735 | ||
| 1736 | if(g_file_test(filename, G_FILE_TEST_EXISTS)) { | |
| 1737 | if(!gaim_blist_read(filename)) { | |
| 1738 | msg = g_strdup_printf(_("An error was encountered parsing your " | |
| 1739 | "buddy list. It has not been loaded.")); | |
|
5436
a0e0bacaa196
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
1740 | gaim_notify_error(NULL, NULL, _("Buddy List Error"), msg); |
| 5228 | 1741 | g_free(msg); |
| 1742 | } | |
|
5580
a5a3e6dfb409
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1743 | } else if(g_list_length(gaim_accounts_get_all())) { |
|
5947
2f57285b03f3
[gaim-migrate @ 6388]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
1744 | GMainContext *ctx; |
|
2f57285b03f3
[gaim-migrate @ 6388]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
1745 | |
| 5228 | 1746 | /* rob wants to inform the user that their buddy lists are |
| 1747 | * being converted */ | |
| 1748 | msg = g_strdup_printf(_("Gaim is converting your old buddy lists " | |
| 1749 | "to a new format, which will now be located at %s"), | |
| 1750 | filename); | |
|
5436
a0e0bacaa196
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
1751 | gaim_notify_info(NULL, NULL, _("Converting Buddy List"), msg); |
| 5228 | 1752 | g_free(msg); |
| 1753 | ||
| 1754 | /* now, let gtk actually display the dialog before we start anything */ | |
|
5947
2f57285b03f3
[gaim-migrate @ 6388]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
1755 | ctx = g_main_context_default(); |
|
2f57285b03f3
[gaim-migrate @ 6388]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
1756 | |
|
2f57285b03f3
[gaim-migrate @ 6388]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
1757 | while(g_main_context_pending(ctx)) |
|
2f57285b03f3
[gaim-migrate @ 6388]
Christian Hammond <chipx86@chipx86.com>
parents:
5943
diff
changeset
|
1758 | g_main_context_iteration(ctx, FALSE); |
| 5228 | 1759 | |
| 1760 | /* 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
|
1761 | for(accts = gaim_accounts_get_all(); accts; accts = accts->next) { |
| 5228 | 1762 | do_import(accts->data, NULL); |
| 1763 | } | |
| 1764 | gaim_blist_save(); | |
| 1765 | } | |
| 1766 | ||
| 1767 | g_free(filename); | |
| 1768 | } | |
| 1769 | ||
| 1770 | static void blist_print_group_settings(gpointer key, gpointer data, | |
| 1771 | gpointer user_data) { | |
| 1772 | char *key_val; | |
| 1773 | char *data_val; | |
| 1774 | FILE *file = user_data; | |
| 1775 | ||
| 1776 | if(!key || !data) | |
| 1777 | return; | |
| 1778 | ||
| 1779 | key_val = g_markup_escape_text(key, -1); | |
| 1780 | data_val = g_markup_escape_text(data, -1); | |
| 1781 | ||
| 1782 | fprintf(file, "\t\t\t<setting name=\"%s\">%s</setting>\n", key_val, | |
| 1783 | data_val); | |
| 1784 | g_free(key_val); | |
| 1785 | g_free(data_val); | |
| 1786 | } | |
| 1787 | ||
| 1788 | static void blist_print_buddy_settings(gpointer key, gpointer data, | |
| 1789 | gpointer user_data) { | |
| 1790 | char *key_val; | |
| 1791 | char *data_val; | |
| 1792 | FILE *file = user_data; | |
| 1793 | ||
| 1794 | if(!key || !data) | |
| 1795 | return; | |
| 1796 | ||
| 1797 | key_val = g_markup_escape_text(key, -1); | |
| 1798 | data_val = g_markup_escape_text(data, -1); | |
| 1799 | ||
| 1800 | fprintf(file, "\t\t\t\t\t<setting name=\"%s\">%s</setting>\n", key_val, | |
| 1801 | data_val); | |
| 1802 | g_free(key_val); | |
| 1803 | g_free(data_val); | |
| 1804 | } | |
| 1805 | ||
| 5234 | 1806 | static void blist_print_chat_components(gpointer key, gpointer data, |
| 1807 | gpointer user_data) { | |
| 1808 | char *key_val; | |
| 1809 | char *data_val; | |
| 1810 | FILE *file = user_data; | |
| 1811 | ||
| 1812 | if(!key || !data) | |
| 1813 | return; | |
| 1814 | ||
| 1815 | key_val = g_markup_escape_text(key, -1); | |
| 1816 | data_val = g_markup_escape_text(data, -1); | |
| 1817 | ||
| 1818 | fprintf(file, "\t\t\t\t<component name=\"%s\">%s</component>\n", key_val, | |
| 1819 | data_val); | |
| 1820 | g_free(key_val); | |
| 1821 | g_free(data_val); | |
| 1822 | } | |
| 1823 | ||
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1824 | static void gaim_blist_write(FILE *file, GaimAccount *exp_acct) { |
|
5580
a5a3e6dfb409
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1825 | GList *accounts; |
|
a5a3e6dfb409
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1826 | GSList *buds; |
| 5228 | 1827 | GaimBlistNode *gnode,*bnode; |
| 1828 | struct group *group; | |
| 1829 | struct buddy *bud; | |
| 1830 | fprintf(file, "<?xml version='1.0' encoding='UTF-8' ?>\n"); | |
| 1831 | fprintf(file, "<gaim version=\"1\">\n"); | |
| 1832 | fprintf(file, "\t<blist>\n"); | |
| 1833 | ||
| 1834 | for(gnode = gaimbuddylist->root; gnode; gnode = gnode->next) { | |
| 1835 | if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
| 1836 | continue; | |
| 1837 | group = (struct group *)gnode; | |
| 1838 | if(!exp_acct || gaim_group_on_account(group, exp_acct)) { | |
| 1839 | char *group_name = g_markup_escape_text(group->name, -1); | |
| 1840 | fprintf(file, "\t\t<group name=\"%s\">\n", group_name); | |
| 1841 | g_hash_table_foreach(group->settings, blist_print_group_settings, file); | |
| 1842 | for(bnode = gnode->child; bnode; bnode = bnode->next) { | |
| 5234 | 1843 | if(GAIM_BLIST_NODE_IS_BUDDY(bnode)) { |
| 1844 | bud = (struct buddy *)bnode; | |
| 1845 | if(!exp_acct || bud->account == exp_acct) { | |
| 1846 | char *bud_name = g_markup_escape_text(bud->name, -1); | |
| 1847 | char *bud_alias = NULL; | |
| 1848 | char *acct_name = g_markup_escape_text(bud->account->username, -1); | |
| 1849 | if(bud->alias) | |
| 1850 | bud_alias= g_markup_escape_text(bud->alias, -1); | |
| 1851 | fprintf(file, "\t\t\t<person name=\"%s\">\n", | |
| 1852 | bud_alias ? bud_alias : bud_name); | |
| 1853 | fprintf(file, "\t\t\t\t<buddy protocol=\"%d\" " | |
|
5943
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1854 | "account=\"%s\">\n", |
|
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1855 | gaim_account_get_protocol(bud->account), |
| 5234 | 1856 | acct_name); |
| 1857 | fprintf(file, "\t\t\t\t\t<name>%s</name>\n", bud_name); | |
| 1858 | if(bud_alias) { | |
| 1859 | fprintf(file, "\t\t\t\t\t<alias>%s</alias>\n", | |
| 1860 | bud_alias); | |
| 1861 | } | |
| 1862 | g_hash_table_foreach(bud->settings, | |
| 1863 | blist_print_buddy_settings, file); | |
| 1864 | fprintf(file, "\t\t\t\t</buddy>\n"); | |
| 1865 | fprintf(file, "\t\t\t</person>\n"); | |
| 1866 | g_free(bud_name); | |
| 1867 | g_free(bud_alias); | |
| 1868 | g_free(acct_name); | |
| 5228 | 1869 | } |
| 5234 | 1870 | } else if(GAIM_BLIST_NODE_IS_CHAT(bnode)) { |
| 1871 | struct chat *chat = (struct chat *)bnode; | |
| 1872 | if(!exp_acct || chat->account == exp_acct) { | |
| 1873 | 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
|
1874 | fprintf(file, "\t\t\t<chat protocol=\"%d\" account=\"%s\">\n", |
|
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1875 | gaim_account_get_protocol(chat->account), |
|
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1876 | acct_name); |
| 5237 | 1877 | if(chat->alias) { |
| 1878 | char *chat_alias = g_markup_escape_text(chat->alias, -1); | |
| 1879 | fprintf(file, "\t\t\t\t<alias>%s</alias>\n", chat_alias); | |
| 1880 | g_free(chat_alias); | |
| 1881 | } | |
| 5234 | 1882 | g_hash_table_foreach(chat->components, |
| 1883 | blist_print_chat_components, file); | |
| 5906 | 1884 | /* works for chats too, I don't feel like renaming */ |
| 1885 | g_hash_table_foreach(chat->settings, | |
| 1886 | blist_print_buddy_settings, file); | |
| 5234 | 1887 | fprintf(file, "\t\t\t</chat>\n"); |
| 5237 | 1888 | g_free(acct_name); |
| 5234 | 1889 | } |
| 5228 | 1890 | } |
| 1891 | } | |
| 1892 | fprintf(file, "\t\t</group>\n"); | |
| 1893 | g_free(group_name); | |
| 1894 | } | |
| 1895 | } | |
| 1896 | ||
| 1897 | fprintf(file, "\t</blist>\n"); | |
| 1898 | fprintf(file, "\t<privacy>\n"); | |
| 1899 | ||
|
5580
a5a3e6dfb409
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1900 | for(accounts = gaim_accounts_get_all(); |
|
a5a3e6dfb409
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1901 | accounts != NULL; |
|
a5a3e6dfb409
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1902 | accounts = accounts->next) { |
|
a5a3e6dfb409
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
1903 | |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1904 | GaimAccount *account = accounts->data; |
| 5228 | 1905 | char *acct_name = g_markup_escape_text(account->username, -1); |
| 1906 | if(!exp_acct || account == exp_acct) { | |
| 1907 | fprintf(file, "\t\t<account protocol=\"%d\" name=\"%s\" " | |
|
5943
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1908 | "mode=\"%d\">\n", gaim_account_get_protocol(account), |
|
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1909 | acct_name, account->perm_deny); |
| 5228 | 1910 | for(buds = account->permit; buds; buds = buds->next) { |
| 1911 | char *bud_name = g_markup_escape_text(buds->data, -1); | |
| 1912 | fprintf(file, "\t\t\t<permit>%s</permit>\n", bud_name); | |
| 1913 | g_free(bud_name); | |
| 1914 | } | |
| 1915 | for(buds = account->deny; buds; buds = buds->next) { | |
| 1916 | char *bud_name = g_markup_escape_text(buds->data, -1); | |
| 1917 | fprintf(file, "\t\t\t<block>%s</block>\n", bud_name); | |
| 1918 | g_free(bud_name); | |
| 1919 | } | |
| 1920 | fprintf(file, "\t\t</account>\n"); | |
| 1921 | } | |
| 1922 | g_free(acct_name); | |
| 1923 | } | |
| 1924 | ||
| 1925 | fprintf(file, "\t</privacy>\n"); | |
| 1926 | fprintf(file, "</gaim>\n"); | |
| 1927 | } | |
| 1928 | ||
| 1929 | void gaim_blist_save() { | |
| 1930 | FILE *file; | |
| 1931 | char *user_dir = gaim_user_dir(); | |
| 1932 | char *filename; | |
| 1933 | char *filename_real; | |
| 1934 | ||
| 1935 | if(!user_dir) | |
| 1936 | return; | |
| 1937 | if(!blist_safe_to_write) { | |
| 1938 | gaim_debug(GAIM_DEBUG_WARNING, "blist save", | |
| 1939 | "AHH!! Tried to write the blist before we read it!\n"); | |
| 1940 | return; | |
| 1941 | } | |
| 1942 | ||
| 1943 | file = fopen(user_dir, "r"); | |
| 1944 | if(!file) | |
| 1945 | mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
| 1946 | else | |
| 1947 | fclose(file); | |
| 1948 | ||
| 1949 | filename = g_build_filename(user_dir, "blist.xml.save", NULL); | |
| 1950 | ||
| 1951 | if((file = fopen(filename, "w"))) { | |
| 1952 | gaim_blist_write(file, NULL); | |
| 1953 | fclose(file); | |
| 1954 | chmod(filename, S_IRUSR | S_IWUSR); | |
| 1955 | } else { | |
| 1956 | gaim_debug(GAIM_DEBUG_ERROR, "blist save", "Unable to write %s\n", | |
| 1957 | filename); | |
| 1958 | } | |
| 1959 | ||
| 1960 | filename_real = g_build_filename(user_dir, "blist.xml", NULL); | |
| 1961 | ||
| 1962 | if(rename(filename, filename_real) < 0) | |
| 1963 | gaim_debug(GAIM_DEBUG_ERROR, "blist save", | |
| 1964 | "Error renaming %s to %s\n", filename, filename_real); | |
| 1965 | ||
| 1966 | ||
| 1967 | g_free(filename); | |
| 1968 | g_free(filename_real); | |
| 1969 | } | |
| 1970 | ||
| 1971 | void gaim_group_set_setting(struct group *g, const char *key, | |
| 1972 | const char *value) { | |
| 1973 | if(!g) | |
| 1974 | return; | |
| 1975 | g_hash_table_replace(g->settings, g_strdup(key), g_strdup(value)); | |
| 1976 | } | |
| 1977 | ||
| 1978 | char *gaim_group_get_setting(struct group *g, const char *key) { | |
| 1979 | if(!g) | |
| 1980 | return NULL; | |
| 1981 | return g_strdup(g_hash_table_lookup(g->settings, key)); | |
| 1982 | } | |
| 1983 | ||
| 5906 | 1984 | void gaim_chat_set_setting(struct chat *c, const char *key, |
| 1985 | const char *value) | |
| 1986 | { | |
| 1987 | if(!c) | |
| 1988 | return; | |
| 1989 | g_hash_table_replace(c->settings, g_strdup(key), g_strdup(value)); | |
| 1990 | } | |
| 1991 | ||
| 1992 | char *gaim_chat_get_setting(struct chat *c, const char *key) | |
| 1993 | { | |
| 1994 | if(!c) | |
| 1995 | return NULL; | |
| 1996 | return g_strdup(g_hash_table_lookup(c->settings, key)); | |
| 1997 | } | |
| 1998 | ||
| 5228 | 1999 | void gaim_buddy_set_setting(struct buddy *b, const char *key, |
| 2000 | const char *value) { | |
| 2001 | if(!b) | |
| 2002 | return; | |
| 2003 | g_hash_table_replace(b->settings, g_strdup(key), g_strdup(value)); | |
| 2004 | } | |
| 2005 | ||
| 2006 | char *gaim_buddy_get_setting(struct buddy *b, const char *key) { | |
| 2007 | if(!b) | |
| 2008 | return NULL; | |
| 2009 | return g_strdup(g_hash_table_lookup(b->settings, key)); | |
| 2010 | } | |
| 2011 | ||
| 2012 | void gaim_set_blist_ui_ops(struct gaim_blist_ui_ops *ops) | |
| 2013 | { | |
| 2014 | blist_ui_ops = ops; | |
| 2015 | } | |
| 2016 | ||
| 2017 | struct gaim_blist_ui_ops * | |
| 2018 | gaim_get_blist_ui_ops(void) | |
| 2019 | { | |
| 2020 | return blist_ui_ops; | |
| 2021 | } | |
| 2022 | ||
| 2023 | int gaim_blist_get_group_size(struct group *group, gboolean offline) { | |
| 2024 | if(!group) | |
| 2025 | return 0; | |
| 2026 | ||
| 5277 | 2027 | return offline ? group->totalsize : group->currentsize; |
| 5228 | 2028 | } |
| 2029 | ||
| 2030 | int gaim_blist_get_group_online_count(struct group *group) { | |
| 2031 | if(!group) | |
| 2032 | return 0; | |
| 2033 | ||
| 5277 | 2034 | return group->online; |
| 5228 | 2035 | } |
| 2036 | ||
| 2037 |