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