Wed, 03 Dec 2003 15:53:54 +0000
[gaim-migrate @ 8372]
(10:49:40) faceprint: no no no no no
(10:49:51) LSchiere2: what did i get wrong faceprint?
(10:50:05) faceprint: server aliases
(10:50:11) LSchiere2: what about them?
(10:50:18) Paco-Paco: they don't belong in blist.xml
(10:50:24) faceprint: bingo
(10:50:25) LSchiere2: i asked sean
(10:50:36) SeanEgan: He did
(10:50:38) Paco-Paco: yeah that bugged me but I wasn't going to get involved
(10:51:04) SeanEgan: but I'd listen to faceprint.
(10:51:08) LSchiere2: it makes sense, both winicq and winaim use them even after the person goes offline
(10:51:20) faceprint: and so does the oscar prpl
(10:51:28) faceprint: but the core didn't
(10:51:33) faceprint: and everyone was happy
(10:51:37) datallah: whats wrong w/ saving them as long as they are refreshed when appropriate?
(10:51:58) faceprint: datallah: doing it in the core assumes certain things about how they're handled in all prpls
(10:51:58) LSchiere2: so the correct fix would be to change the protocols instead of the blist?
(10:52:22) faceprint: right. the prpls know what's going on, so they should store it as a setting like oscar does
committer: Luke Schierer <lschiere@pidgin.im>
| 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; | |
| 6870 | 130 | contact->priority = NULL; |
| 7420 | 131 | contact->score = INT_MAX; |
| 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 | ||
| 152 | if (score < contact->score) { | |
| 6843 | 153 | contact->priority = buddy; |
| 7420 | 154 | contact->score = score; |
| 155 | } | |
| 156 | if (gaim_prefs_get_bool("/core/contact/last_match")) | |
| 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; | |
| 7420 | 768 | c->score = INT_MAX; |
| 7693 | 769 | gaim_blist_node_initialize_settings((GaimBlistNode*)c); |
| 6695 | 770 | |
|
7035
76bca80cd91d
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
771 | ops = gaim_blist_get_ui_ops(); |
| 6695 | 772 | if (ops != NULL && ops->new_node != NULL) |
| 773 | ops->new_node((GaimBlistNode *)c); | |
| 774 | ||
| 775 | return c; | |
| 776 | } | |
| 777 | ||
| 6755 | 778 | void gaim_contact_set_alias(GaimContact* contact, const char *alias) |
| 779 | { | |
| 7245 | 780 | GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
| 781 | ||
| 6755 | 782 | g_return_if_fail(contact != NULL); |
| 783 | ||
| 784 | if(contact->alias) | |
| 785 | g_free(contact->alias); | |
| 786 | ||
| 7245 | 787 | if(alias && *alias) |
| 788 | contact->alias = g_strdup(alias); | |
| 789 | else | |
| 790 | contact->alias = NULL; | |
| 791 | ||
| 792 | if (ops) | |
| 793 | ops->update(gaimbuddylist, (GaimBlistNode*)contact); | |
| 6755 | 794 | } |
| 795 | ||
| 796 | const char *gaim_contact_get_alias(GaimContact* contact) | |
| 797 | { | |
| 7312 | 798 | if(!contact) |
| 799 | return NULL; | |
| 800 | ||
| 801 | if(contact->alias) | |
| 802 | return contact->alias; | |
| 803 | ||
| 804 | return gaim_get_buddy_alias(contact->priority); | |
| 6755 | 805 | } |
| 806 | ||
| 6695 | 807 | GaimGroup *gaim_group_new(const char *name) |
| 808 | { | |
| 809 | GaimGroup *g = gaim_find_group(name); | |
| 5228 | 810 | |
| 811 | if (!g) { | |
|
7098
22eabd4f5ed4
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
812 | GaimBlistUiOps *ops; |
| 6695 | 813 | g= g_new0(GaimGroup, 1); |
| 5228 | 814 | g->name = g_strdup(name); |
| 5277 | 815 | g->totalsize = 0; |
| 816 | g->currentsize = 0; | |
| 817 | g->online = 0; | |
| 7693 | 818 | gaim_blist_node_initialize_settings((GaimBlistNode*)g); |
| 5228 | 819 | ((GaimBlistNode*)g)->type = GAIM_BLIST_GROUP_NODE; |
| 820 | ||
|
7035
76bca80cd91d
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
821 | ops = gaim_blist_get_ui_ops(); |
| 5228 | 822 | |
| 823 | if (ops != NULL && ops->new_node != NULL) | |
| 824 | ops->new_node((GaimBlistNode *)g); | |
| 825 | ||
| 826 | } | |
| 827 | return g; | |
| 828 | } | |
| 829 | ||
| 6695 | 830 | void gaim_blist_add_contact(GaimContact *contact, GaimGroup *group, GaimBlistNode *node) |
| 831 | { | |
|
7098
22eabd4f5ed4
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
832 | GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
| 6695 | 833 | GaimGroup *g; |
| 6742 | 834 | GaimBlistNode *gnode, *cnode, *bnode; |
| 6695 | 835 | gboolean save = FALSE; |
| 836 | ||
| 6774 | 837 | g_return_if_fail(contact != NULL); |
| 838 | g_return_if_fail(GAIM_BLIST_NODE_IS_CONTACT((GaimBlistNode*)contact)); | |
| 6695 | 839 | |
| 6975 | 840 | if((GaimBlistNode*)contact == node) |
| 841 | return; | |
| 842 | ||
| 6695 | 843 | if(node && (GAIM_BLIST_NODE_IS_CONTACT(node) || |
| 844 | GAIM_BLIST_NODE_IS_CHAT(node))) | |
| 845 | g = (GaimGroup*)node->parent; | |
| 846 | else if(group) | |
| 847 | g = group; | |
| 848 | else { | |
| 849 | g = gaim_group_new(_("Buddies")); | |
| 850 | gaim_blist_add_group(g, | |
| 851 | gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
| 852 | } | |
| 853 | ||
| 854 | gnode = (GaimBlistNode*)g; | |
| 855 | cnode = (GaimBlistNode*)contact; | |
| 856 | ||
| 857 | if(cnode->parent) { | |
| 6731 | 858 | if(cnode->parent->child == cnode) |
| 859 | cnode->parent->child = cnode->next; | |
| 6695 | 860 | if(cnode->prev) |
| 861 | cnode->prev->next = cnode->next; | |
| 862 | if(cnode->next) | |
| 863 | cnode->next->prev = cnode->prev; | |
| 864 | ||
| 865 | ||
| 866 | if(contact->online > 0) | |
| 867 | ((GaimGroup*)cnode->parent)->online--; | |
| 868 | if(contact->currentsize > 0) | |
| 869 | ((GaimGroup*)cnode->parent)->currentsize--; | |
| 870 | ((GaimGroup*)cnode->parent)->totalsize--; | |
| 871 | ||
| 6731 | 872 | ops->remove(gaimbuddylist, cnode); |
| 873 | ||
| 6695 | 874 | save = TRUE; |
| 6742 | 875 | |
| 876 | if(cnode->parent != gnode) { | |
| 877 | for(bnode = cnode->child; bnode; bnode = bnode->next) { | |
| 878 | GaimBuddy *b = (GaimBuddy*)bnode; | |
| 879 | ||
| 880 | struct _gaim_hbuddy *hb = g_new(struct _gaim_hbuddy, 1); | |
| 7261 | 881 | hb->name = g_strdup(gaim_normalize(b->account, b->name)); |
| 6742 | 882 | hb->account = b->account; |
| 883 | hb->group = cnode->parent; | |
| 884 | ||
| 6776 | 885 | g_hash_table_remove(gaimbuddylist->buddies, hb); |
| 6742 | 886 | |
| 887 | hb->group = gnode; | |
| 888 | g_hash_table_replace(gaimbuddylist->buddies, hb, b); | |
| 889 | ||
| 890 | if(b->account->gc) | |
| 891 | serv_move_buddy(b, (GaimGroup*)cnode->parent, g); | |
| 892 | } | |
| 893 | } | |
| 6695 | 894 | } |
| 895 | ||
| 6775 | 896 | |
| 6695 | 897 | if(node && (GAIM_BLIST_NODE_IS_CONTACT(node) || |
| 898 | GAIM_BLIST_NODE_IS_CHAT(node))) { | |
| 899 | if(node->next) | |
| 900 | node->next->prev = cnode; | |
| 901 | cnode->next = node->next; | |
| 902 | cnode->prev = node; | |
| 903 | cnode->parent = node->parent; | |
| 904 | node->next = cnode; | |
| 905 | } else { | |
| 906 | if(gnode->child) | |
| 907 | gnode->child->prev = cnode; | |
| 908 | cnode->prev = NULL; | |
| 909 | cnode->next = gnode->child; | |
| 910 | gnode->child = cnode; | |
| 911 | cnode->parent = gnode; | |
| 912 | } | |
| 913 | ||
| 914 | if(contact->online > 0) | |
| 915 | g->online++; | |
| 916 | if(contact->currentsize > 0) | |
| 917 | g->currentsize++; | |
| 918 | g->totalsize++; | |
| 919 | ||
| 920 | if(ops && cnode->child) | |
| 921 | ops->update(gaimbuddylist, cnode); | |
| 6775 | 922 | |
| 923 | for(bnode = cnode->child; bnode; bnode = bnode->next) | |
| 924 | ops->update(gaimbuddylist, bnode); | |
| 925 | ||
| 6695 | 926 | if (save) |
| 927 | gaim_blist_save(); | |
| 928 | } | |
| 929 | ||
| 7246 | 930 | void gaim_blist_merge_contact(GaimContact *source, GaimBlistNode *node) |
| 6965 | 931 | { |
| 932 | GaimBlistNode *sourcenode = (GaimBlistNode*)source; | |
| 7246 | 933 | GaimBlistNode *targetnode; |
| 934 | GaimBlistNode *prev, *cur, *next; | |
| 935 | GaimContact *target; | |
| 936 | ||
| 937 | if(GAIM_BLIST_NODE_IS_CONTACT(node)) { | |
| 938 | target = (GaimContact*)node; | |
| 939 | prev = gaim_blist_get_last_child(node); | |
| 940 | } else if(GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
| 941 | target = (GaimContact*)node->parent; | |
| 942 | prev = node; | |
| 943 | } else { | |
| 6965 | 944 | return; |
| 7246 | 945 | } |
| 946 | ||
| 947 | if(source == target || !target) | |
| 948 | return; | |
| 949 | ||
| 950 | targetnode = (GaimBlistNode*)target; | |
| 951 | next = sourcenode->child; | |
| 952 | ||
| 953 | while(next) { | |
| 954 | cur = next; | |
| 955 | next = cur->next; | |
| 956 | if(GAIM_BLIST_NODE_IS_BUDDY(cur)) { | |
| 957 | gaim_blist_add_buddy((GaimBuddy*)cur, target, NULL, prev); | |
| 958 | prev = cur; | |
| 959 | } | |
| 6965 | 960 | } |
| 961 | } | |
| 962 | ||
| 6695 | 963 | void gaim_blist_add_group (GaimGroup *group, GaimBlistNode *node) |
| 5228 | 964 | { |
|
7098
22eabd4f5ed4
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
965 | GaimBlistUiOps *ops; |
| 5228 | 966 | GaimBlistNode *gnode = (GaimBlistNode*)group; |
| 967 | gboolean save = FALSE; | |
| 968 | ||
| 6774 | 969 | g_return_if_fail(group != NULL); |
| 970 | g_return_if_fail(GAIM_BLIST_NODE_IS_GROUP((GaimBlistNode*)group)); | |
| 971 | ||
| 5228 | 972 | if (!gaimbuddylist) |
| 973 | gaimbuddylist = gaim_blist_new(); | |
| 974 | ops = gaimbuddylist->ui_ops; | |
| 975 | ||
| 976 | if (!gaimbuddylist->root) { | |
| 977 | gaimbuddylist->root = gnode; | |
| 978 | return; | |
| 979 | } | |
| 980 | ||
| 981 | /* if we're moving to overtop of ourselves, do nothing */ | |
| 982 | if(gnode == node) | |
| 983 | return; | |
| 984 | ||
| 985 | if (gaim_find_group(group->name)) { | |
| 986 | /* This is just being moved */ | |
| 987 | ||
| 988 | ops->remove(gaimbuddylist, (GaimBlistNode*)group); | |
| 989 | ||
| 990 | if(gnode == gaimbuddylist->root) | |
| 991 | gaimbuddylist->root = gnode->next; | |
| 992 | if(gnode->prev) | |
| 993 | gnode->prev->next = gnode->next; | |
| 994 | if(gnode->next) | |
| 995 | gnode->next->prev = gnode->prev; | |
| 996 | ||
| 997 | save = TRUE; | |
| 998 | } | |
| 999 | ||
| 6695 | 1000 | if (node && GAIM_BLIST_NODE_IS_GROUP(node)) { |
| 5634 | 1001 | gnode->next = node->next; |
| 1002 | gnode->prev = node; | |
| 1003 | if(node->next) | |
| 1004 | node->next->prev = gnode; | |
| 1005 | node->next = gnode; | |
| 1006 | } else { | |
| 6807 | 1007 | if(gaimbuddylist->root) |
| 1008 | gaimbuddylist->root->prev = gnode; | |
| 5634 | 1009 | gnode->next = gaimbuddylist->root; |
| 1010 | gnode->prev = NULL; | |
| 1011 | gaimbuddylist->root = gnode; | |
| 1012 | } | |
| 1013 | ||
| 5228 | 1014 | |
| 1015 | if (ops) { | |
| 1016 | ops->update(gaimbuddylist, gnode); | |
| 1017 | for(node = gnode->child; node; node = node->next) | |
| 1018 | ops->update(gaimbuddylist, node); | |
| 1019 | } | |
| 1020 | if (save) | |
| 1021 | gaim_blist_save(); | |
| 1022 | } | |
| 1023 | ||
| 6695 | 1024 | void gaim_blist_remove_contact(GaimContact* contact) |
| 5228 | 1025 | { |
|
7098
22eabd4f5ed4
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
1026 | GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
| 5228 | 1027 | |
| 6695 | 1028 | GaimBlistNode *gnode, *cnode = (GaimBlistNode*)contact; |
| 1029 | ||
| 1030 | gnode = cnode->parent; | |
| 1031 | ||
| 1032 | if(cnode->child) { | |
| 1033 | while(cnode->child) { | |
| 1034 | gaim_blist_remove_buddy((GaimBuddy*)cnode->child); | |
| 1035 | } | |
| 1036 | } else { | |
| 1037 | if(ops) | |
| 1038 | ops->remove(gaimbuddylist, cnode); | |
| 1039 | ||
| 1040 | if(gnode->child == cnode) | |
| 1041 | gnode->child = cnode->next; | |
| 1042 | if(cnode->prev) | |
| 1043 | cnode->prev->next = cnode->next; | |
| 1044 | if(cnode->next) | |
| 1045 | cnode->next->prev = cnode->prev; | |
| 1046 | ||
| 1047 | g_free(contact); | |
| 1048 | } | |
| 1049 | } | |
| 1050 | ||
| 6742 | 1051 | void gaim_blist_remove_buddy (GaimBuddy *buddy) |
| 6695 | 1052 | { |
|
7098
22eabd4f5ed4
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
1053 | GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
| 6695 | 1054 | |
| 1055 | GaimBlistNode *cnode, *node = (GaimBlistNode*)buddy; | |
| 1056 | GaimGroup *group; | |
| 6742 | 1057 | struct _gaim_hbuddy hb; |
| 5228 | 1058 | |
| 6695 | 1059 | cnode = node->parent; |
| 1060 | group = (GaimGroup *)cnode->parent; | |
| 5228 | 1061 | |
| 6695 | 1062 | if(GAIM_BUDDY_IS_ONLINE(buddy)) { |
| 1063 | ((GaimContact*)cnode)->online--; | |
| 1064 | if(((GaimContact*)cnode)->online == 0) | |
| 1065 | group->online--; | |
| 1066 | } | |
| 1067 | if(gaim_account_is_connected(buddy->account)) { | |
| 1068 | ((GaimContact*)cnode)->currentsize--; | |
| 1069 | if(((GaimContact*)cnode)->currentsize == 0) | |
| 1070 | group->currentsize--; | |
| 1071 | } | |
| 1072 | ((GaimContact*)cnode)->totalsize--; | |
| 1073 | ||
| 5228 | 1074 | if (node->prev) |
| 1075 | node->prev->next = node->next; | |
| 1076 | if (node->next) | |
| 1077 | node->next->prev = node->prev; | |
| 6695 | 1078 | if(cnode->child == node) { |
| 1079 | cnode->child = node->next; | |
| 1080 | } | |
| 5228 | 1081 | |
| 6755 | 1082 | |
| 7261 | 1083 | hb.name = g_strdup(gaim_normalize(buddy->account, buddy->name)); |
| 5247 | 1084 | hb.account = buddy->account; |
| 6695 | 1085 | hb.group = ((GaimBlistNode*)buddy)->parent->parent; |
| 6742 | 1086 | g_hash_table_remove(gaimbuddylist->buddies, &hb); |
| 7162 | 1087 | g_free(hb.name); |
| 5247 | 1088 | |
| 5292 | 1089 | if(buddy->timer > 0) |
| 1090 | g_source_remove(buddy->timer); | |
| 1091 | ||
|
6846
f814f02dca87
[gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
6843
diff
changeset
|
1092 | if (buddy->icon != NULL) |
|
f814f02dca87
[gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
6843
diff
changeset
|
1093 | gaim_buddy_icon_unref(buddy->icon); |
|
f814f02dca87
[gaim-migrate @ 7391]
Christian Hammond <chipx86@chipx86.com>
parents:
6843
diff
changeset
|
1094 | |
| 5228 | 1095 | ops->remove(gaimbuddylist, node); |
| 7693 | 1096 | g_hash_table_destroy(buddy->node.settings); |
| 5228 | 1097 | g_free(buddy->name); |
| 1098 | g_free(buddy->alias); | |
| 1099 | g_free(buddy); | |
| 6755 | 1100 | |
| 1101 | if(!cnode->child) | |
| 1102 | gaim_blist_remove_contact((GaimContact*)cnode); | |
| 5228 | 1103 | } |
| 1104 | ||
|
7118
280b3b85a28a
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
1105 | void gaim_blist_remove_chat (GaimChat *chat) |
| 5234 | 1106 | { |
|
7098
22eabd4f5ed4
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
1107 | GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
| 5234 | 1108 | |
| 1109 | GaimBlistNode *gnode, *node = (GaimBlistNode*)chat; | |
| 6695 | 1110 | GaimGroup *group; |
| 5234 | 1111 | |
| 1112 | gnode = node->parent; | |
| 6695 | 1113 | group = (GaimGroup *)gnode; |
| 5234 | 1114 | |
| 1115 | if(gnode->child == node) | |
| 1116 | gnode->child = node->next; | |
| 1117 | if (node->prev) | |
| 1118 | node->prev->next = node->next; | |
| 1119 | if (node->next) | |
| 1120 | node->next->prev = node->prev; | |
| 5277 | 1121 | group->totalsize--; |
| 5855 | 1122 | if (gaim_account_is_connected(chat->account)) { |
| 5277 | 1123 | group->currentsize--; |
| 5394 | 1124 | group->online--; |
| 1125 | } | |
| 5234 | 1126 | |
| 1127 | ops->remove(gaimbuddylist, node); | |
| 1128 | g_hash_table_destroy(chat->components); | |
| 1129 | g_free(chat->alias); | |
| 1130 | g_free(chat); | |
| 1131 | } | |
| 1132 | ||
| 6695 | 1133 | void gaim_blist_remove_group (GaimGroup *group) |
| 5228 | 1134 | { |
|
7098
22eabd4f5ed4
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
1135 | GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
| 5228 | 1136 | GaimBlistNode *node = (GaimBlistNode*)group; |
|
6885
65132ebfc662
[gaim-migrate @ 7431]
Christian Hammond <chipx86@chipx86.com>
parents:
6872
diff
changeset
|
1137 | GList *l; |
| 5228 | 1138 | |
| 1139 | if(node->child) { | |
| 1140 | char *buf; | |
| 1141 | int count = 0; | |
| 1142 | GaimBlistNode *child = node->child; | |
| 1143 | ||
| 1144 | while(child) { | |
| 1145 | count++; | |
| 1146 | child = child->next; | |
| 1147 | } | |
| 1148 | ||
|
6308
12d48b4e80db
[gaim-migrate @ 6807]
Mark Doliner <markdoliner@pidgin.im>
parents:
6307
diff
changeset
|
1149 | 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
|
1150 | "because its account was not logged in." |
|
12d48b4e80db
[gaim-migrate @ 6807]
Mark Doliner <markdoliner@pidgin.im>
parents:
6307
diff
changeset
|
1151 | " This buddy and the group were not " |
|
12d48b4e80db
[gaim-migrate @ 6807]
Mark Doliner <markdoliner@pidgin.im>
parents:
6307
diff
changeset
|
1152 | "removed.\n", |
|
12d48b4e80db
[gaim-migrate @ 6807]
Mark Doliner <markdoliner@pidgin.im>
parents:
6307
diff
changeset
|
1153 | "%d buddies from group %s were not " |
|
12d48b4e80db
[gaim-migrate @ 6807]
Mark Doliner <markdoliner@pidgin.im>
parents:
6307
diff
changeset
|
1154 | "removed because their accounts were " |
|
6336
7c62a14b3486
[gaim-migrate @ 6835]
Mark Doliner <markdoliner@pidgin.im>
parents:
6322
diff
changeset
|
1155 | "not logged in. These buddies and " |
|
7c62a14b3486
[gaim-migrate @ 6835]
Mark Doliner <markdoliner@pidgin.im>
parents:
6322
diff
changeset
|
1156 | "the group were not removed.\n", count), |
|
6308
12d48b4e80db
[gaim-migrate @ 6807]
Mark Doliner <markdoliner@pidgin.im>
parents:
6307
diff
changeset
|
1157 | count, group->name); |
|
5541
d4840f195f45
[gaim-migrate @ 5941]
Christian Hammond <chipx86@chipx86.com>
parents:
5436
diff
changeset
|
1158 | gaim_notify_error(NULL, NULL, _("Group not removed"), buf); |
| 5228 | 1159 | g_free(buf); |
| 1160 | return; | |
| 1161 | } | |
| 1162 | ||
| 1163 | if(gaimbuddylist->root == node) | |
| 1164 | gaimbuddylist->root = node->next; | |
| 1165 | if (node->prev) | |
| 1166 | node->prev->next = node->next; | |
| 1167 | if (node->next) | |
| 1168 | node->next->prev = node->prev; | |
| 1169 | ||
|
6885
65132ebfc662
[gaim-migrate @ 7431]
Christian Hammond <chipx86@chipx86.com>
parents:
6872
diff
changeset
|
1170 | for (l = gaim_connections_get_all(); l != NULL; l = l->next) |
|
65132ebfc662
[gaim-migrate @ 7431]
Christian Hammond <chipx86@chipx86.com>
parents:
6872
diff
changeset
|
1171 | { |
|
65132ebfc662
[gaim-migrate @ 7431]
Christian Hammond <chipx86@chipx86.com>
parents:
6872
diff
changeset
|
1172 | GaimConnection *gc = (GaimConnection *)l->data; |
|
65132ebfc662
[gaim-migrate @ 7431]
Christian Hammond <chipx86@chipx86.com>
parents:
6872
diff
changeset
|
1173 | |
|
65132ebfc662
[gaim-migrate @ 7431]
Christian Hammond <chipx86@chipx86.com>
parents:
6872
diff
changeset
|
1174 | if (gaim_connection_get_state(gc) == GAIM_CONNECTED) |
|
65132ebfc662
[gaim-migrate @ 7431]
Christian Hammond <chipx86@chipx86.com>
parents:
6872
diff
changeset
|
1175 | serv_remove_group(gc, group->name); |
|
65132ebfc662
[gaim-migrate @ 7431]
Christian Hammond <chipx86@chipx86.com>
parents:
6872
diff
changeset
|
1176 | } |
|
65132ebfc662
[gaim-migrate @ 7431]
Christian Hammond <chipx86@chipx86.com>
parents:
6872
diff
changeset
|
1177 | |
| 5228 | 1178 | ops->remove(gaimbuddylist, node); |
| 1179 | g_free(group->name); | |
| 1180 | g_free(group); | |
| 1181 | } | |
| 1182 | ||
| 6695 | 1183 | GaimBuddy *gaim_contact_get_priority_buddy(GaimContact *contact) { |
| 6843 | 1184 | return contact->priority; |
| 6695 | 1185 | } |
| 1186 | ||
| 1187 | const char *gaim_get_buddy_alias_only(GaimBuddy *b) { | |
|
5545
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
1188 | if(!b) |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
1189 | return NULL; |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
1190 | |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
1191 | if(b->alias && b->alias[0]) { |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
1192 | return b->alias; |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
1193 | } |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
1194 | else if (b->server_alias != NULL && |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
1195 | gaim_prefs_get_bool("/core/buddies/use_server_alias")) { |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
1196 | |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
1197 | return b->server_alias; |
|
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 | |
|
a8b1a1262402
[gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents:
5541
diff
changeset
|
1200 | return NULL; |
| 5228 | 1201 | } |
| 1202 | ||
| 6695 | 1203 | const char * gaim_get_buddy_alias (GaimBuddy *buddy) |
| 5228 | 1204 | { |
| 6755 | 1205 | const char *ret; |
| 1206 | ||
| 1207 | if(!buddy) | |
| 1208 | return _("Unknown"); | |
| 5228 | 1209 | |
| 6755 | 1210 | ret= gaim_get_buddy_alias_only(buddy); |
| 1211 | ||
| 1212 | return ret ? ret : buddy->name; | |
| 5228 | 1213 | } |
| 1214 | ||
| 7125 | 1215 | const char *gaim_chat_get_name(GaimChat *chat) |
| 6744 | 1216 | { |
| 1217 | if(chat->alias && *chat->alias) { | |
| 1218 | return chat->alias; | |
| 1219 | } else { | |
| 1220 | struct proto_chat_entry *pce; | |
| 1221 | GList *parts, *tmp; | |
| 1222 | char *ret; | |
| 1223 | ||
| 1224 | parts = GAIM_PLUGIN_PROTOCOL_INFO(chat->account->gc->prpl)->chat_info(chat->account->gc); | |
| 1225 | pce = parts->data; | |
| 1226 | ret = g_hash_table_lookup(chat->components, pce->identifier); | |
| 1227 | for(tmp = parts; tmp; tmp = tmp->next) | |
| 1228 | g_free(tmp->data); | |
| 1229 | g_list_free(parts); | |
| 1230 | ||
| 1231 | return ret; | |
| 1232 | } | |
| 1233 | } | |
| 1234 | ||
| 6695 | 1235 | GaimBuddy *gaim_find_buddy(GaimAccount *account, const char *name) |
| 5228 | 1236 | { |
| 6695 | 1237 | GaimBuddy *buddy; |
| 5247 | 1238 | struct _gaim_hbuddy hb; |
| 5758 | 1239 | GaimBlistNode *group; |
| 5228 | 1240 | |
| 1241 | if (!gaimbuddylist) | |
| 1242 | return NULL; | |
| 6245 | 1243 | |
| 1244 | if (!name) | |
|
5985
69ab892a8fab
[gaim-migrate @ 6433]
Christian Hammond <chipx86@chipx86.com>
parents:
5947
diff
changeset
|
1245 | return NULL; |
| 5228 | 1246 | |
| 7429 | 1247 | hb.account = account; |
| 7261 | 1248 | hb.name = g_strdup(gaim_normalize(account, name)); |
| 7429 | 1249 | |
| 6245 | 1250 | for(group = gaimbuddylist->root; group; group = group->next) { |
| 5758 | 1251 | hb.group = group; |
| 7162 | 1252 | if ((buddy = g_hash_table_lookup(gaimbuddylist->buddies, &hb))) { |
| 1253 | g_free(hb.name); | |
| 5758 | 1254 | return buddy; |
| 7162 | 1255 | } |
| 5758 | 1256 | } |
| 6245 | 1257 | |
| 7162 | 1258 | g_free(hb.name); |
| 5758 | 1259 | return NULL; |
| 5228 | 1260 | } |
| 1261 | ||
| 6872 | 1262 | GaimBuddy *gaim_find_buddy_in_group(GaimAccount *account, const char *name, |
| 1263 | GaimGroup *group) | |
| 1264 | { | |
| 1265 | struct _gaim_hbuddy hb; | |
| 7162 | 1266 | GaimBuddy *ret; |
| 6872 | 1267 | |
| 1268 | if (!gaimbuddylist) | |
| 1269 | return NULL; | |
| 1270 | ||
| 1271 | if (!name) | |
| 1272 | return NULL; | |
| 1273 | ||
| 7261 | 1274 | hb.name = g_strdup(gaim_normalize(account, name)); |
| 6872 | 1275 | hb.account = account; |
| 1276 | hb.group = (GaimBlistNode*)group; | |
| 1277 | ||
| 7162 | 1278 | ret = g_hash_table_lookup(gaimbuddylist->buddies, &hb); |
| 1279 | g_free(hb.name); | |
| 1280 | return ret; | |
| 6872 | 1281 | } |
| 1282 | ||
| 6245 | 1283 | GSList *gaim_find_buddies(GaimAccount *account, const char *name) |
| 1284 | { | |
| 1285 | struct buddy *buddy; | |
| 1286 | struct _gaim_hbuddy hb; | |
| 1287 | GaimBlistNode *group; | |
| 1288 | GSList *ret = NULL; | |
| 1289 | ||
| 1290 | if (!gaimbuddylist) | |
| 1291 | return NULL; | |
| 1292 | ||
| 1293 | if (!name) | |
| 1294 | return NULL; | |
| 1295 | ||
| 7261 | 1296 | hb.name = g_strdup(gaim_normalize(account, name)); |
| 6245 | 1297 | hb.account = account; |
| 1298 | ||
| 1299 | for(group = gaimbuddylist->root; group; group = group->next) { | |
| 1300 | hb.group = group; | |
| 1301 | if ((buddy = g_hash_table_lookup(gaimbuddylist->buddies, &hb)) != NULL) | |
| 1302 | ret = g_slist_append(ret, buddy); | |
| 1303 | } | |
| 1304 | ||
| 7162 | 1305 | g_free(hb.name); |
| 6245 | 1306 | return ret; |
| 1307 | } | |
| 1308 | ||
| 6695 | 1309 | GaimGroup *gaim_find_group(const char *name) |
| 5228 | 1310 | { |
| 1311 | GaimBlistNode *node; | |
| 1312 | if (!gaimbuddylist) | |
| 1313 | return NULL; | |
| 1314 | node = gaimbuddylist->root; | |
| 1315 | while(node) { | |
| 6695 | 1316 | if (!strcmp(((GaimGroup *)node)->name, name)) |
| 1317 | return (GaimGroup *)node; | |
| 5228 | 1318 | node = node->next; |
| 1319 | } | |
| 1320 | return NULL; | |
| 1321 | } | |
|
6456
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1322 | |
|
7118
280b3b85a28a
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
1323 | GaimChat * |
|
6456
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1324 | gaim_blist_find_chat(GaimAccount *account, const char *name) |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1325 | { |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1326 | char *chat_name; |
|
7118
280b3b85a28a
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
1327 | GaimChat *chat; |
|
6456
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1328 | GaimPlugin *prpl; |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1329 | GaimPluginProtocolInfo *prpl_info = NULL; |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1330 | struct proto_chat_entry *pce; |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1331 | GaimBlistNode *node, *group; |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1332 | GList *parts; |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1333 | |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1334 | g_return_val_if_fail(gaim_get_blist() != NULL, NULL); |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1335 | g_return_val_if_fail(name != NULL, NULL); |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1336 | |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1337 | for (group = gaimbuddylist->root; group != NULL; group = group->next) { |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1338 | for (node = group->child; node != NULL; node = node->next) { |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1339 | if (GAIM_BLIST_NODE_IS_CHAT(node)) { |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1340 | |
|
7118
280b3b85a28a
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
1341 | chat = (GaimChat*)node; |
|
6456
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1342 | |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1343 | prpl = gaim_find_prpl(gaim_account_get_protocol(chat->account)); |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1344 | prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1345 | |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1346 | parts = prpl_info->chat_info( |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1347 | gaim_account_get_connection(chat->account)); |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1348 | |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1349 | pce = parts->data; |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1350 | chat_name = g_hash_table_lookup(chat->components, |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1351 | pce->identifier); |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1352 | |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1353 | if (chat->account == account && |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1354 | name != NULL && !strcmp(chat_name, name)) { |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1355 | |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1356 | return chat; |
|
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 | |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1362 | return NULL; |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1363 | } |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1364 | |
| 6695 | 1365 | GaimGroup * |
| 7125 | 1366 | gaim_chat_get_group(GaimChat *chat) |
|
6456
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1367 | { |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1368 | g_return_val_if_fail(chat != NULL, NULL); |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1369 | |
| 6695 | 1370 | return (GaimGroup *)(((GaimBlistNode *)chat)->parent); |
|
6456
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1371 | } |
|
e4e7dee16c1a
[gaim-migrate @ 6965]
Christian Hammond <chipx86@chipx86.com>
parents:
6450
diff
changeset
|
1372 | |
| 6695 | 1373 | GaimGroup *gaim_find_buddys_group(GaimBuddy *buddy) |
| 5228 | 1374 | { |
| 1375 | if (!buddy) | |
| 1376 | return NULL; | |
|
6706
fdd12f90fcf6
[gaim-migrate @ 7232]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
1377 | |
|
fdd12f90fcf6
[gaim-migrate @ 7232]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
1378 | if (((GaimBlistNode *)buddy)->parent == NULL) |
|
fdd12f90fcf6
[gaim-migrate @ 7232]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
1379 | return NULL; |
|
fdd12f90fcf6
[gaim-migrate @ 7232]
Christian Hammond <chipx86@chipx86.com>
parents:
6695
diff
changeset
|
1380 | |
| 6695 | 1381 | return (GaimGroup *)(((GaimBlistNode*)buddy)->parent->parent); |
| 5228 | 1382 | } |
| 1383 | ||
| 6695 | 1384 | GSList *gaim_group_get_accounts(GaimGroup *g) |
| 5228 | 1385 | { |
| 1386 | GSList *l = NULL; | |
| 6695 | 1387 | GaimBlistNode *gnode, *cnode, *bnode; |
| 1388 | ||
| 1389 | gnode = (GaimBlistNode *)g; | |
| 5228 | 1390 | |
| 6695 | 1391 | for(cnode = gnode->child; cnode; cnode = cnode->next) { |
| 1392 | if (GAIM_BLIST_NODE_IS_CHAT(cnode)) { | |
|
7118
280b3b85a28a
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
1393 | if(!g_slist_find(l, ((GaimChat *)cnode)->account)) |
|
280b3b85a28a
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
1394 | l = g_slist_append(l, ((GaimChat *)cnode)->account); |
| 6695 | 1395 | } else if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) { |
| 1396 | for(bnode = cnode->child; bnode; bnode = bnode->next) { | |
| 1397 | if(GAIM_BLIST_NODE_IS_BUDDY(bnode)) { | |
| 1398 | if(!g_slist_find(l, ((GaimBuddy *)bnode)->account)) | |
| 1399 | l = g_slist_append(l, ((GaimBuddy *)bnode)->account); | |
| 1400 | } | |
| 1401 | } | |
| 1402 | } | |
| 5228 | 1403 | } |
| 6695 | 1404 | |
| 5228 | 1405 | return l; |
| 1406 | } | |
| 1407 | ||
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1408 | void gaim_blist_add_account(GaimAccount *account) |
| 5234 | 1409 | { |
|
7098
22eabd4f5ed4
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
1410 | GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
| 6695 | 1411 | GaimBlistNode *gnode, *cnode, *bnode; |
| 5234 | 1412 | |
| 1413 | if(!gaimbuddylist) | |
| 1414 | return; | |
| 1415 | ||
| 6695 | 1416 | if(!ops) |
| 1417 | return; | |
| 1418 | ||
| 1419 | for(gnode = gaimbuddylist->root; gnode; gnode = gnode->next) { | |
| 1420 | if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
| 5234 | 1421 | continue; |
| 6695 | 1422 | for(cnode = gnode->child; cnode; cnode = cnode->next) { |
| 1423 | if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
| 6956 | 1424 | gboolean recompute = FALSE; |
| 6695 | 1425 | for(bnode = cnode->child; bnode; bnode = bnode->next) { |
| 1426 | if(GAIM_BLIST_NODE_IS_BUDDY(bnode) && | |
| 1427 | ((GaimBuddy*)bnode)->account == account) { | |
| 6956 | 1428 | recompute = TRUE; |
| 6695 | 1429 | ((GaimContact*)cnode)->currentsize++; |
| 1430 | if(((GaimContact*)cnode)->currentsize == 1) | |
| 1431 | ((GaimGroup*)gnode)->currentsize++; | |
| 1432 | if(GAIM_BUDDY_IS_ONLINE((GaimBuddy*)bnode)) { | |
| 1433 | ((GaimContact*)cnode)->online++; | |
| 1434 | if(((GaimContact*)cnode)->online == 1) | |
| 1435 | ((GaimGroup*)gnode)->online++; | |
| 1436 | } | |
| 1437 | ops->update(gaimbuddylist, bnode); | |
| 1438 | } | |
| 1439 | } | |
| 6956 | 1440 | if(recompute) { |
| 1441 | gaim_contact_compute_priority_buddy((GaimContact*)cnode); | |
| 1442 | ops->update(gaimbuddylist, cnode); | |
| 1443 | } | |
| 6695 | 1444 | } else if(GAIM_BLIST_NODE_IS_CHAT(cnode) && |
|
7118
280b3b85a28a
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
1445 | ((GaimChat*)cnode)->account == account) { |
| 6901 | 1446 | ((GaimGroup *)gnode)->online++; |
| 1447 | ((GaimGroup *)gnode)->currentsize++; | |
| 1448 | ops->update(gaimbuddylist, cnode); | |
| 5234 | 1449 | } |
| 1450 | } | |
| 6695 | 1451 | ops->update(gaimbuddylist, gnode); |
| 5234 | 1452 | } |
| 1453 | } | |
| 1454 | ||
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1455 | void gaim_blist_remove_account(GaimAccount *account) |
| 5228 | 1456 | { |
|
7098
22eabd4f5ed4
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
1457 | GaimBlistUiOps *ops = gaimbuddylist->ui_ops; |
| 6695 | 1458 | GaimBlistNode *gnode, *cnode, *bnode; |
| 5234 | 1459 | |
| 5228 | 1460 | if (!gaimbuddylist) |
| 1461 | return; | |
| 5234 | 1462 | |
| 6695 | 1463 | for(gnode = gaimbuddylist->root; gnode; gnode = gnode->next) { |
| 1464 | if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
| 5234 | 1465 | continue; |
| 6695 | 1466 | for(cnode = gnode->child; cnode; cnode = cnode->next) { |
| 1467 | if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
| 6957 | 1468 | gboolean recompute = FALSE; |
| 6695 | 1469 | for(bnode = cnode->child; bnode; bnode = bnode->next) { |
| 1470 | if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
| 1471 | continue; | |
| 1472 | if(account == ((GaimBuddy *)bnode)->account) { | |
| 6957 | 1473 | recompute = TRUE; |
| 6695 | 1474 | if(((GaimBuddy*)bnode)->present == GAIM_BUDDY_ONLINE || |
| 1475 | ((GaimBuddy*)bnode)->present == GAIM_BUDDY_SIGNING_ON) { | |
| 1476 | ((GaimContact*)cnode)->online--; | |
| 1477 | if(((GaimContact*)cnode)->online == 0) | |
| 1478 | ((GaimGroup*)gnode)->online--; | |
| 1479 | } | |
| 1480 | ((GaimContact*)cnode)->currentsize--; | |
| 1481 | if(((GaimContact*)cnode)->currentsize == 0) | |
| 1482 | ((GaimGroup*)gnode)->currentsize--; | |
| 1483 | ||
| 1484 | ((GaimBuddy*)bnode)->present = GAIM_BUDDY_OFFLINE; | |
| 1485 | ||
| 6803 | 1486 | ((GaimBuddy*)bnode)->uc = 0; |
| 1487 | ((GaimBuddy*)bnode)->idle = 0; | |
| 1488 | ((GaimBuddy*)bnode)->evil = 0; | |
| 1489 | ||
| 6945 | 1490 | |
| 6695 | 1491 | if(ops) |
| 1492 | ops->remove(gaimbuddylist, bnode); | |
| 1493 | } | |
| 5234 | 1494 | } |
| 6983 | 1495 | if(recompute) { |
| 6959 | 1496 | gaim_contact_compute_priority_buddy((GaimContact*)cnode); |
| 6983 | 1497 | if(ops) |
| 1498 | ops->update(gaimbuddylist, cnode); | |
| 1499 | } | |
| 6695 | 1500 | } else if(GAIM_BLIST_NODE_IS_CHAT(cnode) && |
|
7118
280b3b85a28a
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
1501 | ((GaimChat*)cnode)->account == account) { |
| 6695 | 1502 | ((GaimGroup*)gnode)->currentsize--; |
| 1503 | ((GaimGroup*)gnode)->online--; | |
| 1504 | if(ops) | |
| 1505 | ops->remove(gaimbuddylist, cnode); | |
| 5228 | 1506 | } |
| 1507 | } | |
| 1508 | } | |
| 1509 | } | |
| 1510 | ||
|
7117
4d6a9973c7a9
[gaim-migrate @ 7684]
Christian Hammond <chipx86@chipx86.com>
parents:
7115
diff
changeset
|
1511 | void gaim_blist_parse_toc_buddy_list(GaimAccount *account, char *config) |
| 5228 | 1512 | { |
| 1513 | char *c; | |
| 1514 | char current[256]; | |
| 1515 | GList *bud = NULL; | |
| 1516 | ||
| 1517 | ||
| 1518 | if (config != NULL) { | |
| 1519 | ||
| 1520 | /* skip "CONFIG:" (if it exists) */ | |
| 1521 | c = strncmp(config + 6 /* sizeof(struct sflap_hdr) */ , "CONFIG:", strlen("CONFIG:")) ? | |
| 1522 | strtok(config, "\n") : | |
| 1523 | strtok(config + 6 /* sizeof(struct sflap_hdr) */ + strlen("CONFIG:"), "\n"); | |
| 1524 | do { | |
| 1525 | if (c == NULL) | |
| 1526 | break; | |
| 1527 | if (*c == 'g') { | |
| 1528 | char *utf8 = NULL; | |
|
7108
82655fa54acb
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
1529 | utf8 = gaim_utf8_try_convert(c + 2); |
| 5228 | 1530 | if (utf8 == NULL) { |
| 1531 | g_strlcpy(current, _("Invalid Groupname"), sizeof(current)); | |
| 1532 | } else { | |
| 1533 | g_strlcpy(current, utf8, sizeof(current)); | |
| 1534 | g_free(utf8); | |
| 1535 | } | |
| 1536 | if (!gaim_find_group(current)) { | |
| 6695 | 1537 | GaimGroup *g = gaim_group_new(current); |
| 5634 | 1538 | gaim_blist_add_group(g, |
| 1539 | gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
| 5228 | 1540 | } |
| 1541 | } else if (*c == 'b') { /*&& !gaim_find_buddy(user, c + 2)) {*/ | |
| 1542 | char nm[80], sw[388], *a, *utf8 = NULL; | |
| 1543 | ||
| 1544 | if ((a = strchr(c + 2, ':')) != NULL) { | |
| 1545 | *a++ = '\0'; /* nul the : */ | |
| 1546 | } | |
| 1547 | ||
| 1548 | g_strlcpy(nm, c + 2, sizeof(nm)); | |
| 1549 | if (a) { | |
|
7108
82655fa54acb
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7107
diff
changeset
|
1550 | utf8 = gaim_utf8_try_convert(a); |
| 5228 | 1551 | if (utf8 == NULL) { |
| 1552 | gaim_debug(GAIM_DEBUG_ERROR, "toc blist", | |
| 1553 | "Failed to convert alias for " | |
| 1554 | "'%s' to UTF-8\n", nm); | |
| 1555 | } | |
| 1556 | } | |
| 1557 | if (utf8 == NULL) { | |
| 1558 | sw[0] = '\0'; | |
| 1559 | } else { | |
| 1560 | /* This can leave a partial sequence at the end, | |
| 1561 | * but who cares? */ | |
| 1562 | g_strlcpy(sw, utf8, sizeof(sw)); | |
| 1563 | g_free(utf8); | |
| 1564 | } | |
| 1565 | ||
| 1566 | if (!gaim_find_buddy(account, nm)) { | |
| 6695 | 1567 | GaimBuddy *b = gaim_buddy_new(account, nm, sw); |
| 1568 | GaimGroup *g = gaim_find_group(current); | |
| 1569 | gaim_blist_add_buddy(b, NULL, g, | |
| 5634 | 1570 | gaim_blist_get_last_child((GaimBlistNode*)g)); |
| 5228 | 1571 | bud = g_list_append(bud, g_strdup(nm)); |
| 1572 | } | |
| 1573 | } else if (*c == 'p') { | |
|
6378
233d1294508f
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
1574 | gaim_privacy_permit_add(account, c + 2, TRUE); |
| 5228 | 1575 | } else if (*c == 'd') { |
|
6378
233d1294508f
[gaim-migrate @ 6883]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
1576 | gaim_privacy_deny_add(account, c + 2, TRUE); |
| 5228 | 1577 | } else if (!strncmp("toc", c, 3)) { |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1578 | sscanf(c + strlen(c) - 1, "%d", &account->perm_deny); |
| 5228 | 1579 | gaim_debug(GAIM_DEBUG_MISC, "toc blist", |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1580 | "permdeny: %d\n", account->perm_deny); |
|
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1581 | if (account->perm_deny == 0) |
|
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1582 | account->perm_deny = 1; |
| 5228 | 1583 | } else if (*c == 'm') { |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1584 | sscanf(c + 2, "%d", &account->perm_deny); |
| 5228 | 1585 | gaim_debug(GAIM_DEBUG_MISC, "toc blist", |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1586 | "permdeny: %d\n", account->perm_deny); |
|
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1587 | if (account->perm_deny == 0) |
|
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1588 | account->perm_deny = 1; |
| 5228 | 1589 | } |
| 1590 | } while ((c = strtok(NULL, "\n"))); | |
| 1591 | ||
| 1592 | if(account->gc) { | |
| 1593 | if(bud) { | |
| 1594 | GList *node = bud; | |
| 1595 | serv_add_buddies(account->gc, bud); | |
| 1596 | while(node) { | |
| 1597 | g_free(node->data); | |
| 1598 | node = node->next; | |
| 1599 | } | |
| 1600 | } | |
| 1601 | serv_set_permit_deny(account->gc); | |
| 1602 | } | |
| 1603 | g_list_free(bud); | |
| 1604 | } | |
| 1605 | } | |
| 1606 | ||
| 1607 | #if 0 | |
| 1608 | /* translate an AIM 3 buddylist (*.lst) to a Gaim buddylist */ | |
| 1609 | static GString *translate_lst(FILE *src_fp) | |
| 1610 | { | |
| 1611 | char line[BUF_LEN], *line2; | |
| 1612 | char *name; | |
| 1613 | int i; | |
| 1614 | ||
| 1615 | GString *dest = g_string_new("m 1\n"); | |
| 1616 | ||
| 1617 | while (fgets(line, BUF_LEN, src_fp)) { | |
| 1618 | line2 = g_strchug(line); | |
| 1619 | if (strstr(line2, "group") == line2) { | |
| 1620 | name = strpbrk(line2, " \t\n\r\f") + 1; | |
| 1621 | dest = g_string_append(dest, "g "); | |
| 1622 | for (i = 0; i < strcspn(name, "\n\r"); i++) | |
| 1623 | if (name[i] != '\"') | |
| 1624 | dest = g_string_append_c(dest, name[i]); | |
| 1625 | dest = g_string_append_c(dest, '\n'); | |
| 1626 | } | |
| 1627 | if (strstr(line2, "buddy") == line2) { | |
| 1628 | name = strpbrk(line2, " \t\n\r\f") + 1; | |
| 1629 | dest = g_string_append(dest, "b "); | |
| 1630 | for (i = 0; i < strcspn(name, "\n\r"); i++) | |
| 1631 | if (name[i] != '\"') | |
| 1632 | dest = g_string_append_c(dest, name[i]); | |
| 1633 | dest = g_string_append_c(dest, '\n'); | |
| 1634 | } | |
| 1635 | } | |
| 1636 | ||
| 1637 | return dest; | |
| 1638 | } | |
| 1639 | ||
| 1640 | ||
| 1641 | /* translate an AIM 4 buddylist (*.blt) to Gaim format */ | |
| 1642 | static GString *translate_blt(FILE *src_fp) | |
| 1643 | { | |
| 1644 | int i; | |
| 1645 | char line[BUF_LEN]; | |
| 1646 | char *buddy; | |
| 1647 | ||
| 1648 | GString *dest = g_string_new("m 1\n"); | |
| 1649 | ||
| 1650 | while (strstr(fgets(line, BUF_LEN, src_fp), "Buddy") == NULL); | |
| 1651 | while (strstr(fgets(line, BUF_LEN, src_fp), "list") == NULL); | |
| 1652 | ||
| 1653 | while (1) { | |
| 1654 | fgets(line, BUF_LEN, src_fp); g_strchomp(line); | |
| 1655 | if (strchr(line, '}') != NULL) | |
| 1656 | break; | |
| 1657 | ||
| 1658 | if (strchr(line, '{') != NULL) { | |
| 1659 | /* Syntax starting with "<group> {" */ | |
| 1660 | ||
| 1661 | dest = g_string_append(dest, "g "); | |
| 1662 | buddy = g_strchug(strtok(line, "{")); | |
| 1663 | for (i = 0; i < strlen(buddy); i++) | |
| 1664 | if (buddy[i] != '\"') | |
| 1665 | dest = g_string_append_c(dest, buddy[i]); | |
| 1666 | dest = g_string_append_c(dest, '\n'); | |
| 1667 | while (strchr(fgets(line, BUF_LEN, src_fp), '}') == NULL) { | |
| 1668 | gboolean pounce = FALSE; | |
| 1669 | char *e; | |
| 1670 | g_strchomp(line); | |
| 1671 | buddy = g_strchug(line); | |
| 1672 | gaim_debug(GAIM_DEBUG_MISC, "AIM 4 blt import", | |
| 1673 | "buddy: \"%s\"\n", buddy); | |
| 1674 | dest = g_string_append(dest, "b "); | |
| 1675 | if (strchr(buddy, '{') != NULL) { | |
| 1676 | /* buddy pounce, etc */ | |
| 1677 | char *pos = strchr(buddy, '{') - 1; | |
| 1678 | *pos = 0; | |
| 1679 | pounce = TRUE; | |
| 1680 | } | |
| 1681 | if ((e = strchr(buddy, '\"')) != NULL) { | |
| 1682 | *e = '\0'; | |
| 1683 | buddy++; | |
| 1684 | } | |
| 1685 | dest = g_string_append(dest, buddy); | |
| 1686 | dest = g_string_append_c(dest, '\n'); | |
| 1687 | if (pounce) | |
| 1688 | do | |
| 1689 | fgets(line, BUF_LEN, src_fp); | |
| 1690 | while (!strchr(line, '}')); | |
| 1691 | } | |
| 1692 | } else { | |
| 1693 | ||
| 1694 | /* Syntax "group buddy buddy ..." */ | |
| 1695 | buddy = g_strchug(strtok(line, " \n")); | |
| 1696 | dest = g_string_append(dest, "g "); | |
| 1697 | if (strchr(buddy, '\"') != NULL) { | |
| 1698 | dest = g_string_append(dest, &buddy[1]); | |
| 1699 | dest = g_string_append_c(dest, ' '); | |
| 1700 | buddy = g_strchug(strtok(NULL, " \n")); | |
| 1701 | while (strchr(buddy, '\"') == NULL) { | |
| 1702 | dest = g_string_append(dest, buddy); | |
| 1703 | dest = g_string_append_c(dest, ' '); | |
| 1704 | buddy = g_strchug(strtok(NULL, " \n")); | |
| 1705 | } | |
| 1706 | buddy[strlen(buddy) - 1] = '\0'; | |
| 1707 | dest = g_string_append(dest, buddy); | |
| 1708 | } else { | |
| 1709 | dest = g_string_append(dest, buddy); | |
| 1710 | } | |
| 1711 | dest = g_string_append_c(dest, '\n'); | |
| 1712 | while ((buddy = g_strchug(strtok(NULL, " \n"))) != NULL) { | |
| 1713 | dest = g_string_append(dest, "b "); | |
| 1714 | if (strchr(buddy, '\"') != NULL) { | |
| 1715 | dest = g_string_append(dest, &buddy[1]); | |
| 1716 | dest = g_string_append_c(dest, ' '); | |
| 1717 | buddy = g_strchug(strtok(NULL, " \n")); | |
| 1718 | while (strchr(buddy, '\"') == NULL) { | |
| 1719 | dest = g_string_append(dest, buddy); | |
| 1720 | dest = g_string_append_c(dest, ' '); | |
| 1721 | buddy = g_strchug(strtok(NULL, " \n")); | |
| 1722 | } | |
| 1723 | buddy[strlen(buddy) - 1] = '\0'; | |
| 1724 | dest = g_string_append(dest, buddy); | |
| 1725 | } else { | |
| 1726 | dest = g_string_append(dest, buddy); | |
| 1727 | } | |
| 1728 | dest = g_string_append_c(dest, '\n'); | |
| 1729 | } | |
| 1730 | } | |
| 1731 | } | |
| 1732 | ||
| 1733 | return dest; | |
| 1734 | } | |
| 1735 | ||
| 1736 | static GString *translate_gnomeicu(FILE *src_fp) | |
| 1737 | { | |
| 1738 | char line[BUF_LEN]; | |
| 1739 | GString *dest = g_string_new("m 1\ng Buddies\n"); | |
| 1740 | ||
| 1741 | while (strstr(fgets(line, BUF_LEN, src_fp), "NewContacts") == NULL); | |
| 1742 | ||
| 1743 | while (fgets(line, BUF_LEN, src_fp)) { | |
| 1744 | char *eq; | |
| 1745 | g_strchomp(line); | |
| 1746 | if (line[0] == '\n' || line[0] == '[') | |
| 1747 | break; | |
| 1748 | eq = strchr(line, '='); | |
| 1749 | if (!eq) | |
| 1750 | break; | |
| 1751 | *eq = ':'; | |
| 1752 | eq = strchr(eq, ','); | |
| 1753 | if (eq) | |
| 1754 | *eq = '\0'; | |
| 1755 | dest = g_string_append(dest, "b "); | |
| 1756 | dest = g_string_append(dest, line); | |
| 1757 | dest = g_string_append_c(dest, '\n'); | |
| 1758 | } | |
| 1759 | ||
| 1760 | return dest; | |
| 1761 | } | |
| 1762 | #endif | |
| 1763 | ||
| 1764 | static gchar *get_screenname_filename(const char *name) | |
| 1765 | { | |
| 1766 | gchar **split; | |
| 1767 | gchar *good; | |
| 1768 | gchar *ret; | |
| 1769 | ||
| 1770 | split = g_strsplit(name, G_DIR_SEPARATOR_S, -1); | |
| 1771 | good = g_strjoinv(NULL, split); | |
| 1772 | g_strfreev(split); | |
| 1773 | ||
| 1774 | ret = g_utf8_strup(good, -1); | |
| 1775 | ||
| 1776 | g_free(good); | |
| 1777 | ||
| 1778 | return ret; | |
| 1779 | } | |
| 1780 | ||
| 1781 | static gboolean gaim_blist_read(const char *filename); | |
| 1782 | ||
| 1783 | ||
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
1784 | static void do_import(GaimAccount *account, const char *filename) |
| 5228 | 1785 | { |
| 1786 | GString *buf = NULL; | |
| 1787 | char first[64]; | |
| 1788 | char path[PATHSIZE]; | |
| 1789 | int len; | |
| 1790 | FILE *f; | |
| 1791 | struct stat st; | |
| 1792 | ||
| 1793 | if (filename) { | |
| 1794 | g_snprintf(path, sizeof(path), "%s", filename); | |
| 1795 | } else { | |
| 1796 | char *g_screenname = get_screenname_filename(account->username); | |
|
5943
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1797 | const char *username; |
| 5228 | 1798 | char *file = gaim_user_dir(); |
|
5943
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1799 | GaimProtocol prpl_num; |
|
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1800 | int protocol; |
| 6695 | 1801 | |
|
5943
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1802 | prpl_num = gaim_account_get_protocol(account); |
|
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1803 | |
|
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1804 | protocol = prpl_num; |
|
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1805 | |
|
6450
4c2364a4b6a4
[gaim-migrate @ 6959]
Christian Hammond <chipx86@chipx86.com>
parents:
6392
diff
changeset
|
1806 | /* TODO Somehow move this checking into prpls */ |
|
5943
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1807 | if (prpl_num == GAIM_PROTO_OSCAR) { |
|
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1808 | if ((username = gaim_account_get_username(account)) != NULL) { |
|
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1809 | protocol = (isalpha(*username) |
|
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1810 | ? GAIM_PROTO_TOC : GAIM_PROTO_ICQ); |
|
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1811 | } |
|
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
1812 | } |
| 5228 | 1813 | |
| 1814 | if (file != (char *)NULL) { | |
|
5435
990c340ecb6d
[gaim-migrate @ 5817]
Mark Doliner <markdoliner@pidgin.im>
parents:
5394
diff
changeset
|
1815 | snprintf(path, PATHSIZE, "%s" G_DIR_SEPARATOR_S "%s.%d.blist", file, g_screenname, protocol); |
| 5228 | 1816 | g_free(g_screenname); |
| 1817 | } else { | |
| 1818 | g_free(g_screenname); | |
| 1819 | return; | |
| 1820 | } | |
| 1821 | } | |
| 1822 | ||
| 1823 | if (stat(path, &st)) { | |
| 1824 | gaim_debug(GAIM_DEBUG_ERROR, "blist import", "Unable to stat %s.\n", | |
| 1825 | path); | |
| 1826 | return; | |
| 1827 | } | |
| 1828 | ||
| 1829 | if (!(f = fopen(path, "r"))) { | |
| 1830 | gaim_debug(GAIM_DEBUG_ERROR, "blist import", "Unable to open %s.\n", | |
| 1831 | path); | |
| 1832 | return; | |
| 1833 | } | |
| 1834 | ||
| 1835 | fgets(first, 64, f); | |
| 1836 | ||
| 1837 | if ((first[0] == '\n') || (first[0] == '\r' && first[1] == '\n')) | |
| 1838 | fgets(first, 64, f); | |
| 1839 | ||
| 1840 | #if 0 | |
| 1841 | if (!g_strncasecmp(first, "<xml", strlen("<xml"))) { | |
| 1842 | /* new gaim XML buddy list */ | |
| 1843 | gaim_blist_read(path); | |
| 1844 | ||
| 1845 | /* We really don't need to bother doing stuf like translating AIM 3 buddy lists anymore */ | |
| 1846 | ||
| 1847 | } else if (!g_strncasecmp(first, "Config {", strlen("Config {"))) { | |
| 1848 | /* AIM 4 buddy list */ | |
| 1849 | gaim_debug(GAIM_DEBUG_MISC, "blist import", "aim 4\n"); | |
| 1850 | rewind(f); | |
| 1851 | buf = translate_blt(f); | |
| 1852 | } else if (strstr(first, "group") != NULL) { | |
| 1853 | /* AIM 3 buddy list */ | |
| 1854 | gaim_debug(GAIM_DEBUG_MISC, "blist import", "aim 3\n"); | |
| 1855 | rewind(f); | |
| 1856 | buf = translate_lst(f); | |
| 1857 | } else if (!g_strncasecmp(first, "[User]", strlen("[User]"))) { | |
| 1858 | /* GnomeICU (hopefully) */ | |
| 1859 | gaim_debug(GAIM_DEBUG_MISC, "blist import", "gnomeicu\n"); | |
| 1860 | rewind(f); | |
| 1861 | buf = translate_gnomeicu(f); | |
| 1862 | ||
| 1863 | } else | |
| 1864 | #endif | |
| 1865 | if (first[0] == 'm') { | |
| 1866 | /* Gaim buddy list - no translation */ | |
| 1867 | char buf2[BUF_LONG * 2]; | |
| 1868 | buf = g_string_new(""); | |
| 1869 | rewind(f); | |
| 1870 | while (1) { | |
| 1871 | len = fread(buf2, 1, BUF_LONG * 2 - 1, f); | |
| 1872 | if (len <= 0) | |
| 1873 | break; | |
| 1874 | buf2[len] = '\0'; | |
| 1875 | buf = g_string_append(buf, buf2); | |
| 1876 | if (len != BUF_LONG * 2 - 1) | |
| 1877 | break; | |
| 1878 | } | |
| 1879 | } | |
| 1880 | ||
| 1881 | fclose(f); | |
| 1882 | ||
| 1883 | if (buf) { | |
| 1884 | buf = g_string_prepend(buf, "toc_set_config {"); | |
| 1885 | buf = g_string_append(buf, "}\n"); | |
|
7117
4d6a9973c7a9
[gaim-migrate @ 7684]
Christian Hammond <chipx86@chipx86.com>
parents:
7115
diff
changeset
|
1886 | gaim_blist_parse_toc_buddy_list(account, buf->str); |
| 5228 | 1887 | g_string_free(buf, TRUE); |
| 1888 | } | |
| 1889 | } | |
| 1890 | ||
| 6695 | 1891 | gboolean gaim_group_on_account(GaimGroup *g, GaimAccount *account) { |
| 1892 | GaimBlistNode *cnode, *bnode; | |
| 1893 | for(cnode = ((GaimBlistNode *)g)->child; cnode; cnode = cnode->next) { | |
| 1894 | if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
| 1895 | for(bnode = cnode->child; bnode; bnode = bnode->next) { | |
| 1896 | if(GAIM_BLIST_NODE_IS_BUDDY(bnode)) { | |
| 1897 | GaimBuddy *buddy = (GaimBuddy *)bnode; | |
| 1898 | if((!account && gaim_account_is_connected(buddy->account)) | |
| 1899 | || buddy->account == account) | |
| 1900 | return TRUE; | |
| 1901 | } | |
| 1902 | } | |
| 1903 | } else if(GAIM_BLIST_NODE_IS_CHAT(cnode)) { | |
|
7118
280b3b85a28a
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
1904 | GaimChat *chat = (GaimChat *)cnode; |
| 6695 | 1905 | if((!account && gaim_account_is_connected(chat->account)) |
| 1906 | || chat->account == account) | |
| 1907 | return TRUE; | |
| 1908 | } | |
| 5228 | 1909 | } |
| 1910 | return FALSE; | |
| 1911 | } | |
| 1912 | ||
| 1913 | static gboolean blist_safe_to_write = FALSE; | |
| 1914 | ||
| 7132 | 1915 | static void parse_setting(GaimBlistNode *node, xmlnode *setting) |
| 1916 | { | |
| 1917 | const char *name = xmlnode_get_attrib(setting, "name"); | |
| 7693 | 1918 | const char *type = xmlnode_get_attrib(setting, "type"); |
| 7132 | 1919 | char *value = xmlnode_get_data(setting); |
| 1920 | ||
| 7693 | 1921 | if(!value) |
| 1922 | return; | |
| 1923 | ||
| 1924 | if(!type || !strcmp(type, "string")) | |
| 1925 | gaim_blist_node_set_string(node, name, value); | |
| 1926 | else if(!strcmp(type, "bool")) | |
| 1927 | gaim_blist_node_set_bool(node, name, atoi(value)); | |
| 1928 | else if(!strcmp(type, "int")) | |
| 1929 | gaim_blist_node_set_int(node, name, atoi(value)); | |
| 7132 | 1930 | |
| 1931 | g_free(value); | |
| 1932 | } | |
| 1933 | ||
| 1934 | static void parse_buddy(GaimGroup *group, GaimContact *contact, xmlnode *bnode) | |
| 1935 | { | |
| 1936 | GaimAccount *account; | |
| 1937 | GaimBuddy *buddy; | |
| 7727 | 1938 | char *name = NULL, *alias = NULL; |
| 7153 | 1939 | const char *acct_name, *proto, *protocol; |
| 7132 | 1940 | xmlnode *x; |
| 1941 | ||
| 1942 | acct_name = xmlnode_get_attrib(bnode, "account"); | |
| 7153 | 1943 | protocol = xmlnode_get_attrib(bnode, "protocol"); |
| 1944 | proto = xmlnode_get_attrib(bnode, "proto"); | |
| 1945 | ||
| 1946 | if(!acct_name || (!proto && !protocol)) | |
| 7132 | 1947 | return; |
| 1948 | ||
| 7153 | 1949 | account = gaim_accounts_find(acct_name, proto ? proto : protocol); |
| 7132 | 1950 | |
| 1951 | if(!account) | |
| 1952 | return; | |
| 1953 | ||
| 1954 | if((x = xmlnode_get_child(bnode, "name"))) | |
| 1955 | name = xmlnode_get_data(x); | |
| 1956 | ||
| 1957 | if(!name) | |
| 1958 | return; | |
| 1959 | ||
| 1960 | if((x = xmlnode_get_child(bnode, "alias"))) | |
| 1961 | alias = xmlnode_get_data(x); | |
| 1962 | ||
| 1963 | buddy = gaim_buddy_new(account, name, alias); | |
| 1964 | gaim_blist_add_buddy(buddy, contact, group, | |
| 1965 | gaim_blist_get_last_child((GaimBlistNode*)contact)); | |
| 1966 | ||
| 1967 | for(x = bnode->child; x; x = x->next) { | |
| 1968 | if(x->type != NODE_TYPE_TAG || strcmp(x->name, "setting")) | |
| 1969 | continue; | |
| 1970 | parse_setting((GaimBlistNode*)buddy, x); | |
| 1971 | } | |
| 1972 | ||
| 1973 | g_free(name); | |
| 1974 | if(alias) | |
| 1975 | g_free(alias); | |
| 1976 | } | |
| 1977 | ||
| 1978 | static void parse_contact(GaimGroup *group, xmlnode *cnode) | |
| 1979 | { | |
| 1980 | GaimContact *contact = gaim_contact_new(); | |
| 1981 | xmlnode *x; | |
| 7245 | 1982 | const char *alias; |
| 7132 | 1983 | |
| 1984 | gaim_blist_add_contact(contact, group, | |
| 1985 | gaim_blist_get_last_child((GaimBlistNode*)group)); | |
| 1986 | ||
| 7245 | 1987 | if((alias = xmlnode_get_attrib(cnode, "alias"))) { |
| 7132 | 1988 | gaim_contact_set_alias(contact, alias); |
| 1989 | } | |
| 1990 | ||
| 1991 | for(x = cnode->child; x; x = x->next) { | |
| 1992 | if(x->type != NODE_TYPE_TAG) | |
| 1993 | continue; | |
| 1994 | if(!strcmp(x->name, "buddy")) | |
| 1995 | parse_buddy(group, contact, x); | |
| 1996 | else if(strcmp(x->name, "setting")) | |
| 1997 | parse_setting((GaimBlistNode*)contact, x); | |
| 5228 | 1998 | } |
| 1999 | } | |
| 2000 | ||
| 7132 | 2001 | static void parse_chat(GaimGroup *group, xmlnode *cnode) |
| 2002 | { | |
| 2003 | GaimChat *chat; | |
| 2004 | GaimAccount *account; | |
| 7153 | 2005 | const char *acct_name, *proto, *protocol; |
| 7132 | 2006 | xmlnode *x; |
| 2007 | char *alias = NULL; | |
| 2008 | GHashTable *components; | |
| 2009 | ||
| 2010 | acct_name = xmlnode_get_attrib(cnode, "account"); | |
| 7153 | 2011 | protocol = xmlnode_get_attrib(cnode, "protocol"); |
| 2012 | proto = xmlnode_get_attrib(cnode, "proto"); | |
| 2013 | ||
| 2014 | if(!acct_name || (!proto && !protocol)) | |
| 7132 | 2015 | return; |
| 2016 | ||
| 7153 | 2017 | account = gaim_accounts_find(acct_name, proto ? proto : protocol); |
| 7132 | 2018 | |
| 2019 | if(!account) | |
| 2020 | return; | |
| 2021 | ||
| 2022 | if((x = xmlnode_get_child(cnode, "alias"))) | |
| 2023 | alias = xmlnode_get_data(x); | |
| 2024 | ||
| 2025 | components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
| 2026 | ||
| 2027 | for(x = cnode->child; x; x = x->next) { | |
| 2028 | const char *name; | |
| 2029 | char *value; | |
| 2030 | if(x->type != NODE_TYPE_TAG || strcmp(x->name, "component")) | |
| 2031 | continue; | |
| 2032 | ||
| 2033 | name = xmlnode_get_attrib(x, "name"); | |
| 2034 | value = xmlnode_get_data(x); | |
| 2035 | g_hash_table_replace(components, g_strdup(name), value); | |
| 2036 | } | |
| 2037 | ||
| 2038 | chat = gaim_chat_new(account, alias, components); | |
| 7151 | 2039 | gaim_blist_add_chat(chat, group, |
| 2040 | gaim_blist_get_last_child((GaimBlistNode*)group)); | |
| 7132 | 2041 | |
| 2042 | for(x = cnode->child; x; x = x->next) { | |
| 2043 | if(x->type != NODE_TYPE_TAG || strcmp(x->name, "setting")) | |
| 2044 | continue; | |
| 2045 | parse_setting((GaimBlistNode*)chat, x); | |
| 2046 | } | |
| 2047 | ||
| 2048 | if(alias) | |
| 2049 | g_free(alias); | |
| 2050 | } | |
| 2051 | ||
| 2052 | ||
| 2053 | static void parse_group(xmlnode *groupnode) | |
| 2054 | { | |
| 2055 | const char *name = xmlnode_get_attrib(groupnode, "name"); | |
| 2056 | GaimGroup *group; | |
| 2057 | xmlnode *cnode; | |
| 2058 | ||
| 2059 | if(!name) | |
| 2060 | name = _("Buddies"); | |
| 2061 | ||
| 2062 | group = gaim_group_new(name); | |
| 2063 | gaim_blist_add_group(group, | |
| 2064 | gaim_blist_get_last_sibling(gaimbuddylist->root)); | |
| 2065 | ||
| 2066 | for(cnode = groupnode->child; cnode; cnode = cnode->next) { | |
| 2067 | if(cnode->type != NODE_TYPE_TAG) | |
| 2068 | continue; | |
| 2069 | if(!strcmp(cnode->name, "setting")) | |
| 2070 | parse_setting((GaimBlistNode*)group, cnode); | |
| 2071 | else if(!strcmp(cnode->name, "contact") || | |
| 2072 | !strcmp(cnode->name, "person")) | |
| 2073 | parse_contact(group, cnode); | |
| 2074 | else if(!strcmp(cnode->name, "chat")) | |
| 2075 | parse_chat(group, cnode); | |
| 5228 | 2076 | } |
| 2077 | } | |
| 2078 | ||
| 2079 | static gboolean gaim_blist_read(const char *filename) { | |
| 7132 | 2080 | GError *error; |
| 5228 | 2081 | gchar *contents = NULL; |
| 2082 | gsize length; | |
| 7132 | 2083 | xmlnode *gaim, *blist, *privacy; |
| 5228 | 2084 | |
| 2085 | gaim_debug(GAIM_DEBUG_INFO, "blist import", | |
| 2086 | "Reading %s\n", filename); | |
| 2087 | if(!g_file_get_contents(filename, &contents, &length, &error)) { | |
| 2088 | gaim_debug(GAIM_DEBUG_ERROR, "blist import", | |
| 2089 | "Error reading blist: %s\n", error->message); | |
| 2090 | g_error_free(error); | |
| 2091 | return FALSE; | |
| 2092 | } | |
| 2093 | ||
| 7132 | 2094 | gaim = xmlnode_from_str(contents, length); |
| 2095 | g_free(contents); | |
| 2096 | ||
| 2097 | if(!gaim) { | |
| 2098 | gaim_debug(GAIM_DEBUG_ERROR, "blist import", "Error parsing %s\n", | |
| 2099 | filename); | |
| 5228 | 2100 | return FALSE; |
| 2101 | } | |
| 2102 | ||
| 7132 | 2103 | blist = xmlnode_get_child(gaim, "blist"); |
| 2104 | if(blist) { | |
| 2105 | xmlnode *groupnode; | |
| 2106 | for(groupnode = blist->child; groupnode; groupnode = groupnode->next) { | |
| 2107 | if(groupnode->type != NODE_TYPE_TAG || | |
| 2108 | strcmp(groupnode->name, "group")) | |
| 2109 | continue; | |
| 2110 | ||
| 2111 | parse_group(groupnode); | |
| 2112 | } | |
| 5228 | 2113 | } |
| 2114 | ||
| 7132 | 2115 | privacy = xmlnode_get_child(gaim, "privacy"); |
| 2116 | if(privacy) { | |
| 2117 | xmlnode *anode; | |
| 2118 | for(anode = privacy->child; anode; anode = anode->next) { | |
| 2119 | xmlnode *x; | |
| 2120 | GaimAccount *account; | |
| 7153 | 2121 | const char *acct_name, *proto, *mode, *protocol; |
| 7132 | 2122 | |
| 2123 | acct_name = xmlnode_get_attrib(anode, "name"); | |
| 7153 | 2124 | protocol = xmlnode_get_attrib(anode, "protocol"); |
| 2125 | proto = xmlnode_get_attrib(anode, "proto"); | |
| 7132 | 2126 | mode = xmlnode_get_attrib(anode, "mode"); |
| 2127 | ||
| 7153 | 2128 | if(!acct_name || (!proto && !protocol) || !mode) |
| 7132 | 2129 | continue; |
| 2130 | ||
| 7153 | 2131 | account = gaim_accounts_find(acct_name, proto ? proto : protocol); |
| 7132 | 2132 | |
| 2133 | if(!account) | |
| 2134 | continue; | |
| 2135 | ||
| 2136 | account->perm_deny = atoi(mode); | |
| 2137 | ||
| 2138 | for(x = anode->child; x; x = x->next) { | |
| 2139 | char *name; | |
| 2140 | if(x->type != NODE_TYPE_TAG) | |
| 2141 | continue; | |
| 2142 | ||
| 2143 | if(!strcmp(x->name, "permit")) { | |
| 2144 | name = xmlnode_get_data(x); | |
| 2145 | gaim_privacy_permit_add(account, name, TRUE); | |
| 2146 | g_free(name); | |
| 2147 | } else if(!strcmp(x->name, "block")) { | |
| 2148 | name = xmlnode_get_data(x); | |
| 2149 | gaim_privacy_deny_add(account, name, TRUE); | |
| 2150 | g_free(name); | |
| 2151 | } | |
| 2152 | } | |
| 2153 | } | |
| 2154 | } | |
| 5228 | 2155 | |
| 2156 | gaim_debug(GAIM_DEBUG_INFO, "blist import", "Finished reading %s\n", | |
| 2157 | filename); | |
| 2158 | ||
| 2159 | return TRUE; | |
| 2160 | } | |
| 2161 | ||
| 2162 | void gaim_blist_load() { | |
|
5580
a5a3e6dfb409
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
2163 | GList *accts; |
| 5228 | 2164 | char *user_dir = gaim_user_dir(); |
| 2165 | char *filename; | |
| 2166 | char *msg; | |
| 2167 | ||
| 2168 | blist_safe_to_write = TRUE; | |
| 2169 | ||
| 2170 | if(!user_dir) | |
| 2171 | return; | |
| 2172 | ||
| 2173 | filename = g_build_filename(user_dir, "blist.xml", NULL); | |
| 2174 | ||
| 2175 | if(g_file_test(filename, G_FILE_TEST_EXISTS)) { | |
| 2176 | if(!gaim_blist_read(filename)) { | |
| 2177 | msg = g_strdup_printf(_("An error was encountered parsing your " | |
| 2178 | "buddy list. It has not been loaded.")); | |
|
5436
a0e0bacaa196
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5435
diff
changeset
|
2179 | gaim_notify_error(NULL, NULL, _("Buddy List Error"), msg); |
| 5228 | 2180 | g_free(msg); |
| 2181 | } | |
|
5580
a5a3e6dfb409
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
2182 | } else if(g_list_length(gaim_accounts_get_all())) { |
| 5228 | 2183 | /* 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
|
2184 | for(accts = gaim_accounts_get_all(); accts; accts = accts->next) { |
| 5228 | 2185 | do_import(accts->data, NULL); |
| 2186 | } | |
| 2187 | gaim_blist_save(); | |
| 2188 | } | |
| 2189 | ||
| 2190 | g_free(filename); | |
| 2191 | } | |
| 2192 | ||
|
7060
717cbeb22b6d
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2193 | void |
|
717cbeb22b6d
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2194 | gaim_blist_request_add_buddy(GaimAccount *account, const char *username, |
|
717cbeb22b6d
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2195 | const char *group, const char *alias) |
|
717cbeb22b6d
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2196 | { |
|
7098
22eabd4f5ed4
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
2197 | GaimBlistUiOps *ui_ops; |
|
7060
717cbeb22b6d
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2198 | |
|
717cbeb22b6d
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2199 | ui_ops = gaim_blist_get_ui_ops(); |
|
717cbeb22b6d
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2200 | |
|
717cbeb22b6d
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2201 | if (ui_ops != NULL && ui_ops->request_add_buddy != NULL) |
|
717cbeb22b6d
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2202 | ui_ops->request_add_buddy(account, username, group, alias); |
|
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 | |
|
717cbeb22b6d
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2205 | void |
|
717cbeb22b6d
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2206 | gaim_blist_request_add_chat(GaimAccount *account, GaimGroup *group) |
|
717cbeb22b6d
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2207 | { |
|
7098
22eabd4f5ed4
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
2208 | GaimBlistUiOps *ui_ops; |
|
7060
717cbeb22b6d
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2209 | |
|
717cbeb22b6d
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2210 | ui_ops = gaim_blist_get_ui_ops(); |
|
717cbeb22b6d
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2211 | |
|
717cbeb22b6d
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2212 | if (ui_ops != NULL && ui_ops->request_add_chat != NULL) |
|
717cbeb22b6d
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2213 | ui_ops->request_add_chat(account, group); |
|
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 | |
|
717cbeb22b6d
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2216 | void |
|
717cbeb22b6d
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2217 | gaim_blist_request_add_group(void) |
|
717cbeb22b6d
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2218 | { |
|
7098
22eabd4f5ed4
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
2219 | GaimBlistUiOps *ui_ops; |
|
7060
717cbeb22b6d
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2220 | |
|
717cbeb22b6d
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2221 | ui_ops = gaim_blist_get_ui_ops(); |
|
717cbeb22b6d
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2222 | |
|
717cbeb22b6d
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2223 | if (ui_ops != NULL && ui_ops->request_add_group != NULL) |
|
717cbeb22b6d
[gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
2224 | ui_ops->request_add_group(); |
|
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 | |
| 7693 | 2227 | static void blist_print_setting(const char *key, |
| 2228 | struct gaim_blist_node_setting *setting, FILE *file, int indent) | |
| 2229 | { | |
| 2230 | char *key_val, *data_val = NULL; | |
| 2231 | const char *type = NULL; | |
| 2232 | int i; | |
| 2233 | ||
| 2234 | if(!key) | |
| 2235 | return; | |
| 2236 | ||
| 2237 | switch(setting->type) { | |
| 2238 | case GAIM_BLIST_NODE_SETTING_BOOL: | |
| 2239 | type = "bool"; | |
| 2240 | data_val = g_strdup_printf("%d", setting->value.boolean); | |
| 2241 | break; | |
| 2242 | case GAIM_BLIST_NODE_SETTING_INT: | |
| 2243 | type = "int"; | |
| 2244 | data_val = g_strdup_printf("%d", setting->value.integer); | |
| 2245 | break; | |
| 2246 | case GAIM_BLIST_NODE_SETTING_STRING: | |
| 2247 | if(!setting->value.string) | |
| 2248 | return; | |
| 2249 | ||
| 2250 | type = "string"; | |
| 2251 | data_val = g_markup_escape_text(setting->value.string, -1); | |
| 2252 | break; | |
| 2253 | } | |
| 2254 | ||
| 2255 | /* this can't happen */ | |
| 2256 | if(!type || !data_val) | |
| 2257 | return; | |
| 2258 | ||
| 2259 | for(i=0; i<indent; i++) fprintf(file, "\t"); | |
| 2260 | ||
| 2261 | key_val = g_markup_escape_text(key, -1); | |
| 2262 | fprintf(file, "<setting name=\"%s\" type=\"%s\">%s</setting>\n", key_val, type, | |
| 2263 | data_val); | |
| 2264 | ||
| 2265 | g_free(key_val); | |
| 2266 | g_free(data_val); | |
| 2267 | } | |
| 2268 | ||
| 5228 | 2269 | static void blist_print_group_settings(gpointer key, gpointer data, |
| 2270 | gpointer user_data) { | |
| 7693 | 2271 | blist_print_setting(key, data, user_data, 3); |
| 5228 | 2272 | } |
| 2273 | ||
| 2274 | static void blist_print_buddy_settings(gpointer key, gpointer data, | |
| 2275 | gpointer user_data) { | |
| 7693 | 2276 | blist_print_setting(key, data, user_data, 5); |
| 5228 | 2277 | } |
| 2278 | ||
| 6695 | 2279 | static void blist_print_cnode_settings(gpointer key, gpointer data, |
| 2280 | gpointer user_data) { | |
| 7693 | 2281 | blist_print_setting(key, data, user_data, 4); |
| 6695 | 2282 | } |
| 2283 | ||
| 5234 | 2284 | static void blist_print_chat_components(gpointer key, gpointer data, |
| 2285 | gpointer user_data) { | |
| 2286 | char *key_val; | |
| 2287 | char *data_val; | |
| 2288 | FILE *file = user_data; | |
| 2289 | ||
| 2290 | if(!key || !data) | |
| 2291 | return; | |
| 2292 | ||
| 2293 | key_val = g_markup_escape_text(key, -1); | |
| 2294 | data_val = g_markup_escape_text(data, -1); | |
| 2295 | ||
| 2296 | fprintf(file, "\t\t\t\t<component name=\"%s\">%s</component>\n", key_val, | |
| 2297 | data_val); | |
| 2298 | g_free(key_val); | |
| 2299 | g_free(data_val); | |
| 2300 | } | |
| 2301 | ||
| 6695 | 2302 | static void print_buddy(FILE *file, GaimBuddy *buddy) { |
| 2303 | char *bud_name = g_markup_escape_text(buddy->name, -1); | |
| 2304 | char *bud_alias = NULL; | |
| 2305 | char *acct_name = g_markup_escape_text(buddy->account->username, -1); | |
| 7153 | 2306 | int proto_num = gaim_account_get_protocol(buddy->account); |
| 6695 | 2307 | if(buddy->alias) |
| 2308 | bud_alias= g_markup_escape_text(buddy->alias, -1); | |
| 7153 | 2309 | fprintf(file, "\t\t\t\t<buddy account=\"%s\" proto=\"%s\"", acct_name, |
| 2310 | gaim_account_get_protocol_id(buddy->account)); | |
| 2311 | if(proto_num != -1) | |
| 2312 | fprintf(file, " protocol=\"%d\"", proto_num); | |
| 2313 | fprintf(file, ">\n"); | |
| 2314 | ||
| 6695 | 2315 | fprintf(file, "\t\t\t\t\t<name>%s</name>\n", bud_name); |
| 2316 | if(bud_alias) { | |
| 2317 | fprintf(file, "\t\t\t\t\t<alias>%s</alias>\n", bud_alias); | |
| 2318 | } | |
| 7726 | 2319 | g_hash_table_foreach(buddy->node.settings, blist_print_buddy_settings, file); |
| 6695 | 2320 | fprintf(file, "\t\t\t\t</buddy>\n"); |
| 2321 | g_free(bud_name); | |
| 2322 | g_free(bud_alias); | |
| 2323 | g_free(acct_name); | |
| 2324 | } | |
| 2325 | ||
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
2326 | static void gaim_blist_write(FILE *file, GaimAccount *exp_acct) { |
|
5580
a5a3e6dfb409
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
2327 | GList *accounts; |
|
a5a3e6dfb409
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
2328 | GSList *buds; |
| 6695 | 2329 | GaimBlistNode *gnode, *cnode, *bnode; |
| 5228 | 2330 | fprintf(file, "<?xml version='1.0' encoding='UTF-8' ?>\n"); |
| 2331 | fprintf(file, "<gaim version=\"1\">\n"); | |
| 2332 | fprintf(file, "\t<blist>\n"); | |
| 2333 | ||
| 2334 | for(gnode = gaimbuddylist->root; gnode; gnode = gnode->next) { | |
| 6695 | 2335 | GaimGroup *group; |
| 2336 | ||
| 5228 | 2337 | if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) |
| 2338 | continue; | |
| 6695 | 2339 | |
| 2340 | group = (GaimGroup *)gnode; | |
| 5228 | 2341 | if(!exp_acct || gaim_group_on_account(group, exp_acct)) { |
| 2342 | char *group_name = g_markup_escape_text(group->name, -1); | |
| 2343 | fprintf(file, "\t\t<group name=\"%s\">\n", group_name); | |
| 7693 | 2344 | g_hash_table_foreach(group->node.settings, |
| 2345 | blist_print_group_settings, file); | |
| 6695 | 2346 | for(cnode = gnode->child; cnode; cnode = cnode->next) { |
| 2347 | if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | |
| 6755 | 2348 | GaimContact *contact = (GaimContact*)cnode; |
| 2349 | fprintf(file, "\t\t\t<contact"); | |
| 2350 | if(contact->alias) { | |
| 2351 | char *alias = g_markup_escape_text(contact->alias, -1); | |
| 2352 | fprintf(file, " alias=\"%s\"", alias); | |
| 2353 | g_free(alias); | |
| 2354 | } | |
| 2355 | fprintf(file, ">\n"); | |
| 6695 | 2356 | |
| 2357 | for(bnode = cnode->child; bnode; bnode = bnode->next) { | |
| 2358 | if(GAIM_BLIST_NODE_IS_BUDDY(bnode)) { | |
| 2359 | GaimBuddy *buddy = (GaimBuddy *)bnode; | |
| 2360 | if(!exp_acct || buddy->account == exp_acct) { | |
| 2361 | print_buddy(file, buddy); | |
| 2362 | } | |
| 5234 | 2363 | } |
| 5228 | 2364 | } |
| 6695 | 2365 | |
| 2366 | fprintf(file, "\t\t\t</contact>\n"); | |
| 2367 | } else if(GAIM_BLIST_NODE_IS_CHAT(cnode)) { | |
|
7118
280b3b85a28a
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7117
diff
changeset
|
2368 | GaimChat *chat = (GaimChat *)cnode; |
| 5234 | 2369 | if(!exp_acct || chat->account == exp_acct) { |
| 2370 | char *acct_name = g_markup_escape_text(chat->account->username, -1); | |
| 7153 | 2371 | int proto_num = gaim_account_get_protocol(chat->account); |
| 2372 | fprintf(file, "\t\t\t<chat proto=\"%s\" account=\"%s\"", | |
| 7133 | 2373 | gaim_account_get_protocol_id(chat->account), |
|
5943
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
2374 | acct_name); |
| 7153 | 2375 | if(proto_num != -1) |
| 2376 | fprintf(file, " protocol=\"%d\"", proto_num); | |
| 2377 | fprintf(file, ">\n"); | |
| 2378 | ||
| 5237 | 2379 | if(chat->alias) { |
| 2380 | char *chat_alias = g_markup_escape_text(chat->alias, -1); | |
| 2381 | fprintf(file, "\t\t\t\t<alias>%s</alias>\n", chat_alias); | |
| 2382 | g_free(chat_alias); | |
| 2383 | } | |
| 5234 | 2384 | g_hash_table_foreach(chat->components, |
| 2385 | blist_print_chat_components, file); | |
| 7693 | 2386 | g_hash_table_foreach(chat->node.settings, |
| 6695 | 2387 | blist_print_cnode_settings, file); |
| 5234 | 2388 | fprintf(file, "\t\t\t</chat>\n"); |
| 5237 | 2389 | g_free(acct_name); |
| 5234 | 2390 | } |
| 5228 | 2391 | } |
| 2392 | } | |
| 2393 | fprintf(file, "\t\t</group>\n"); | |
| 2394 | g_free(group_name); | |
| 2395 | } | |
| 2396 | } | |
| 2397 | ||
| 2398 | fprintf(file, "\t</blist>\n"); | |
| 2399 | fprintf(file, "\t<privacy>\n"); | |
| 2400 | ||
|
5580
a5a3e6dfb409
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
2401 | for(accounts = gaim_accounts_get_all(); |
|
a5a3e6dfb409
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
2402 | accounts != NULL; |
|
a5a3e6dfb409
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
2403 | accounts = accounts->next) { |
|
a5a3e6dfb409
[gaim-migrate @ 5984]
Christian Hammond <chipx86@chipx86.com>
parents:
5563
diff
changeset
|
2404 | |
|
5563
d5a7852aa0cb
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5545
diff
changeset
|
2405 | GaimAccount *account = accounts->data; |
| 5228 | 2406 | char *acct_name = g_markup_escape_text(account->username, -1); |
| 7153 | 2407 | int proto_num = gaim_account_get_protocol(account); |
| 5228 | 2408 | if(!exp_acct || account == exp_acct) { |
| 7153 | 2409 | fprintf(file, "\t\t<account proto=\"%s\" name=\"%s\" " |
| 2410 | "mode=\"%d\"", gaim_account_get_protocol_id(account), | |
|
5943
8a052155157a
[gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents:
5906
diff
changeset
|
2411 | acct_name, account->perm_deny); |
| 7153 | 2412 | if(proto_num != -1) |
| 2413 | fprintf(file, " protocol=\"%d\"", proto_num); | |
| 2414 | fprintf(file, ">\n"); | |
| 2415 | ||
| 5228 | 2416 | for(buds = account->permit; buds; buds = buds->next) { |
| 2417 | char *bud_name = g_markup_escape_text(buds->data, -1); | |
| 2418 | fprintf(file, "\t\t\t<permit>%s</permit>\n", bud_name); | |
| 2419 | g_free(bud_name); | |
| 2420 | } | |
| 2421 | for(buds = account->deny; buds; buds = buds->next) { | |
| 2422 | char *bud_name = g_markup_escape_text(buds->data, -1); | |
| 2423 | fprintf(file, "\t\t\t<block>%s</block>\n", bud_name); | |
| 2424 | g_free(bud_name); | |
| 2425 | } | |
| 2426 | fprintf(file, "\t\t</account>\n"); | |
| 2427 | } | |
| 2428 | g_free(acct_name); | |
| 2429 | } | |
| 2430 | ||
| 2431 | fprintf(file, "\t</privacy>\n"); | |
| 2432 | fprintf(file, "</gaim>\n"); | |
| 2433 | } | |
| 2434 | ||
| 2435 | void gaim_blist_save() { | |
| 2436 | FILE *file; | |
| 2437 | char *user_dir = gaim_user_dir(); | |
| 2438 | char *filename; | |
| 2439 | char *filename_real; | |
| 2440 | ||
| 2441 | if(!user_dir) | |
| 2442 | return; | |
| 2443 | if(!blist_safe_to_write) { | |
| 2444 | gaim_debug(GAIM_DEBUG_WARNING, "blist save", | |
| 2445 | "AHH!! Tried to write the blist before we read it!\n"); | |
| 2446 | return; | |
| 2447 | } | |
| 2448 | ||
| 2449 | file = fopen(user_dir, "r"); | |
| 2450 | if(!file) | |
| 2451 | mkdir(user_dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
| 2452 | else | |
| 2453 | fclose(file); | |
| 2454 | ||
| 2455 | filename = g_build_filename(user_dir, "blist.xml.save", NULL); | |
| 2456 | ||
| 2457 | if((file = fopen(filename, "w"))) { | |
| 2458 | gaim_blist_write(file, NULL); | |
| 2459 | fclose(file); | |
| 2460 | chmod(filename, S_IRUSR | S_IWUSR); | |
| 2461 | } else { | |
| 2462 | gaim_debug(GAIM_DEBUG_ERROR, "blist save", "Unable to write %s\n", | |
| 2463 | filename); | |
| 2464 | } | |
| 2465 | ||
| 2466 | filename_real = g_build_filename(user_dir, "blist.xml", NULL); | |
| 2467 | ||
| 2468 | if(rename(filename, filename_real) < 0) | |
| 2469 | gaim_debug(GAIM_DEBUG_ERROR, "blist save", | |
| 2470 | "Error renaming %s to %s\n", filename, filename_real); | |
| 2471 | ||
| 2472 | ||
| 2473 | g_free(filename); | |
| 2474 | g_free(filename_real); | |
| 2475 | } | |
| 2476 | ||
| 7693 | 2477 | |
| 2478 | static void gaim_blist_node_setting_free(struct gaim_blist_node_setting *setting) | |
| 2479 | { | |
| 2480 | switch(setting->type) { | |
| 2481 | case GAIM_BLIST_NODE_SETTING_BOOL: | |
| 2482 | case GAIM_BLIST_NODE_SETTING_INT: | |
| 2483 | break; | |
| 2484 | case GAIM_BLIST_NODE_SETTING_STRING: | |
| 2485 | g_free(setting->value.string); | |
| 2486 | break; | |
| 2487 | } | |
| 2488 | } | |
| 2489 | ||
| 2490 | static void gaim_blist_node_initialize_settings(GaimBlistNode* node) | |
| 2491 | { | |
| 2492 | if(node->settings) | |
| 5228 | 2493 | return; |
| 7693 | 2494 | |
| 2495 | node->settings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, | |
| 2496 | (GDestroyNotify)gaim_blist_node_setting_free); | |
| 2497 | } | |
| 2498 | ||
| 2499 | void gaim_blist_node_remove_setting(GaimBlistNode *node, const char *key) | |
| 2500 | { | |
| 2501 | g_return_if_fail(node != NULL); | |
| 2502 | g_return_if_fail(node->settings != NULL); | |
| 2503 | g_return_if_fail(key != NULL); | |
| 2504 | ||
| 2505 | g_hash_table_remove(node->settings, key); | |
| 5228 | 2506 | } |
| 2507 | ||
| 7693 | 2508 | |
| 2509 | void gaim_blist_node_set_bool(GaimBlistNode* node, const char *key, gboolean value) | |
| 2510 | { | |
| 2511 | struct gaim_blist_node_setting *setting; | |
| 2512 | ||
| 2513 | g_return_if_fail(node != NULL); | |
| 2514 | g_return_if_fail(node->settings != NULL); | |
| 2515 | g_return_if_fail(key != NULL); | |
| 2516 | ||
| 2517 | setting = g_new0(struct gaim_blist_node_setting, 1); | |
| 2518 | setting->type = GAIM_BLIST_NODE_SETTING_BOOL; | |
| 2519 | setting->value.boolean = value; | |
| 2520 | ||
| 2521 | g_hash_table_replace(node->settings, g_strdup(key), setting); | |
| 2522 | } | |
| 2523 | ||
| 2524 | gboolean gaim_blist_node_get_bool(GaimBlistNode* node, const char *key) | |
| 2525 | { | |
| 2526 | struct gaim_blist_node_setting *setting; | |
| 2527 | ||
| 2528 | g_return_val_if_fail(node != NULL, FALSE); | |
| 2529 | g_return_val_if_fail(node->settings != NULL, FALSE); | |
| 2530 | g_return_val_if_fail(key != NULL, FALSE); | |
| 2531 | ||
| 2532 | setting = g_hash_table_lookup(node->settings, key); | |
| 2533 | ||
| 2534 | return setting ? setting->value.boolean : FALSE; | |
| 5228 | 2535 | } |
| 2536 | ||
| 7693 | 2537 | void gaim_blist_node_set_int(GaimBlistNode* node, const char *key, int value) |
| 2538 | { | |
| 2539 | struct gaim_blist_node_setting *setting; | |
| 2540 | ||
| 2541 | g_return_if_fail(node != NULL); | |
| 2542 | g_return_if_fail(node->settings != NULL); | |
| 2543 | g_return_if_fail(key != NULL); | |
| 2544 | ||
| 2545 | setting = g_new0(struct gaim_blist_node_setting, 1); | |
| 2546 | setting->type = GAIM_BLIST_NODE_SETTING_STRING; | |
| 2547 | setting->value.integer = value; | |
| 2548 | ||
| 2549 | g_hash_table_replace(node->settings, g_strdup(key), setting); | |
| 2550 | } | |
| 2551 | ||
| 2552 | int gaim_blist_node_get_int(GaimBlistNode* node, const char *key) | |
| 2553 | { | |
| 2554 | struct gaim_blist_node_setting *setting; | |
| 2555 | ||
| 2556 | g_return_val_if_fail(node != NULL, 0); | |
| 2557 | g_return_val_if_fail(node->settings != NULL, 0); | |
| 2558 | g_return_val_if_fail(key != NULL, 0); | |
| 2559 | ||
| 2560 | setting = g_hash_table_lookup(node->settings, key); | |
| 2561 | ||
| 2562 | return setting ? setting->value.integer : 0; | |
| 2563 | } | |
| 2564 | ||
| 2565 | void gaim_blist_node_set_string(GaimBlistNode* node, const char *key, | |
| 5906 | 2566 | const char *value) |
| 2567 | { | |
| 7693 | 2568 | struct gaim_blist_node_setting *setting; |
| 2569 | ||
| 2570 | g_return_if_fail(node != NULL); | |
| 2571 | g_return_if_fail(node->settings != NULL); | |
| 2572 | g_return_if_fail(key != NULL); | |
| 2573 | ||
| 2574 | setting = g_new0(struct gaim_blist_node_setting, 1); | |
| 2575 | setting->type = GAIM_BLIST_NODE_SETTING_STRING; | |
| 2576 | setting->value.string = g_strdup(value); | |
| 2577 | ||
| 2578 | g_hash_table_replace(node->settings, g_strdup(key), setting); | |
| 2579 | } | |
| 2580 | ||
| 2581 | const char *gaim_blist_node_get_string(GaimBlistNode* node, const char *key) | |
| 2582 | { | |
| 2583 | struct gaim_blist_node_setting *setting; | |
| 2584 | ||
| 2585 | g_return_val_if_fail(node != NULL, NULL); | |
| 2586 | g_return_val_if_fail(node->settings != NULL, NULL); | |
| 2587 | g_return_val_if_fail(key != NULL, NULL); | |
| 2588 | ||
| 2589 | setting = g_hash_table_lookup(node->settings, key); | |
| 2590 | ||
| 2591 | return setting ? setting->value.string : NULL; | |
| 2592 | } | |
| 2593 | ||
| 2594 | ||
| 2595 | /* XXX: this is compatability stuff. Remove after.... oh, I dunno... 0.77 or so */ | |
| 2596 | ||
| 2597 | void gaim_group_set_setting(GaimGroup *g, const char *key, const char *value) | |
| 2598 | { | |
| 2599 | gaim_debug_warning("blist", "gaim_group_set_setting() is deprecated\n"); | |
| 2600 | ||
| 2601 | gaim_blist_node_set_string((GaimBlistNode*)g, key, value); | |
| 2602 | } | |
| 2603 | ||
| 2604 | const char *gaim_group_get_setting(GaimGroup *g, const char *key) | |
| 2605 | { | |
| 2606 | gaim_debug_warning("blist", "gaim_group_get_setting() is deprecated\n"); | |
| 2607 | ||
| 2608 | return gaim_blist_node_get_string((GaimBlistNode*)g, key); | |
| 2609 | } | |
| 2610 | ||
| 2611 | void gaim_chat_set_setting(GaimChat *c, const char *key, const char *value) | |
| 2612 | { | |
| 2613 | gaim_debug_warning("blist", "gaim_chat_set_setting() is deprecated\n"); | |
| 2614 | ||
| 2615 | gaim_blist_node_set_string((GaimBlistNode*)c, key, value); | |
| 5906 | 2616 | } |
| 2617 | ||
| 7125 | 2618 | const char *gaim_chat_get_setting(GaimChat *c, const char *key) |
| 5906 | 2619 | { |
| 7693 | 2620 | gaim_debug_warning("blist", "gaim_chat_get_setting() is deprecated\n"); |
| 2621 | ||
| 2622 | return gaim_blist_node_get_string((GaimBlistNode*)c, key); | |
| 5906 | 2623 | } |
| 2624 | ||
| 7693 | 2625 | void gaim_buddy_set_setting(GaimBuddy *b, const char *key, const char *value) |
| 2626 | { | |
| 2627 | gaim_debug_warning("blist", "gaim_buddy_set_setting() is deprecated\n"); | |
| 2628 | ||
| 2629 | gaim_blist_node_set_string((GaimBlistNode*)b, key, value); | |
| 5228 | 2630 | } |
| 2631 | ||
| 7693 | 2632 | const char *gaim_buddy_get_setting(GaimBuddy *b, const char *key) |
| 2633 | { | |
| 2634 | gaim_debug_warning("blist", "gaim_buddy_get_setting() is deprecated\n"); | |
| 2635 | ||
| 2636 | return gaim_blist_node_get_string((GaimBlistNode*)b, key); | |
| 5228 | 2637 | } |
| 2638 | ||
| 7693 | 2639 | /* XXX: end compat crap */ |
| 2640 | ||
| 6695 | 2641 | int gaim_blist_get_group_size(GaimGroup *group, gboolean offline) { |
| 5228 | 2642 | if(!group) |
| 2643 | return 0; | |
| 2644 | ||
| 5277 | 2645 | return offline ? group->totalsize : group->currentsize; |
| 5228 | 2646 | } |
| 2647 | ||
| 6695 | 2648 | int gaim_blist_get_group_online_count(GaimGroup *group) { |
| 5228 | 2649 | if(!group) |
| 2650 | return 0; | |
| 2651 | ||
| 5277 | 2652 | return group->online; |
| 5228 | 2653 | } |
| 2654 | ||
|
7035
76bca80cd91d
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2655 | void |
|
7098
22eabd4f5ed4
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
2656 | gaim_blist_set_ui_ops(GaimBlistUiOps *ops) |
|
7035
76bca80cd91d
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2657 | { |
|
76bca80cd91d
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2658 | blist_ui_ops = ops; |
|
76bca80cd91d
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2659 | } |
|
76bca80cd91d
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2660 | |
|
7098
22eabd4f5ed4
[gaim-migrate @ 7663]
Christian Hammond <chipx86@chipx86.com>
parents:
7060
diff
changeset
|
2661 | GaimBlistUiOps * |
|
7035
76bca80cd91d
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2662 | gaim_blist_get_ui_ops(void) |
|
76bca80cd91d
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2663 | { |
|
76bca80cd91d
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2664 | return blist_ui_ops; |
|
76bca80cd91d
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2665 | } |
|
76bca80cd91d
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2666 | |
|
76bca80cd91d
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
7003
diff
changeset
|
2667 | |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2668 | void * |
|
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2669 | gaim_blist_get_handle(void) |
|
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2670 | { |
|
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2671 | static int handle; |
| 5228 | 2672 | |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2673 | return &handle; |
|
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2674 | } |
|
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2675 | |
|
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2676 | void |
|
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2677 | gaim_blist_init(void) |
|
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2678 | { |
|
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2679 | void *handle = gaim_blist_get_handle(); |
|
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2680 | |
|
6564
a7a2c1927544
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2681 | gaim_signal_register(handle, "buddy-away", |
|
a7a2c1927544
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2682 | gaim_marshal_VOID__POINTER, NULL, 1, |
|
a7a2c1927544
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2683 | gaim_value_new(GAIM_TYPE_SUBTYPE, |
|
a7a2c1927544
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2684 | GAIM_SUBTYPE_BLIST_BUDDY)); |
|
a7a2c1927544
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2685 | |
|
a7a2c1927544
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2686 | gaim_signal_register(handle, "buddy-back", |
|
a7a2c1927544
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2687 | gaim_marshal_VOID__POINTER, NULL, 1, |
|
a7a2c1927544
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2688 | gaim_value_new(GAIM_TYPE_SUBTYPE, |
|
a7a2c1927544
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2689 | GAIM_SUBTYPE_BLIST_BUDDY)); |
|
6485
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 | gaim_signal_register(handle, "buddy-idle", |
|
6564
a7a2c1927544
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2692 | gaim_marshal_VOID__POINTER, NULL, 1, |
|
a7a2c1927544
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2693 | gaim_value_new(GAIM_TYPE_SUBTYPE, |
|
a7a2c1927544
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2694 | GAIM_SUBTYPE_BLIST_BUDDY)); |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2695 | gaim_signal_register(handle, "buddy-unidle", |
|
6564
a7a2c1927544
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2696 | gaim_marshal_VOID__POINTER, NULL, 1, |
|
a7a2c1927544
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2697 | gaim_value_new(GAIM_TYPE_SUBTYPE, |
|
a7a2c1927544
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2698 | GAIM_SUBTYPE_BLIST_BUDDY)); |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2699 | |
|
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2700 | gaim_signal_register(handle, "buddy-signed-on", |
|
6564
a7a2c1927544
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2701 | gaim_marshal_VOID__POINTER, NULL, 1, |
|
a7a2c1927544
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2702 | gaim_value_new(GAIM_TYPE_SUBTYPE, |
|
a7a2c1927544
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2703 | GAIM_SUBTYPE_BLIST_BUDDY)); |
|
a7a2c1927544
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2704 | |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2705 | gaim_signal_register(handle, "buddy-signed-off", |
|
6564
a7a2c1927544
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2706 | gaim_marshal_VOID__POINTER, NULL, 1, |
|
a7a2c1927544
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2707 | gaim_value_new(GAIM_TYPE_SUBTYPE, |
|
a7a2c1927544
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2708 | GAIM_SUBTYPE_BLIST_BUDDY)); |
|
6485
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2709 | |
|
6564
a7a2c1927544
[gaim-migrate @ 7086]
Christian Hammond <chipx86@chipx86.com>
parents:
6506
diff
changeset
|
2710 | 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
|
2711 | } |
|
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2712 | |
|
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2713 | void |
|
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2714 | gaim_blist_uninit(void) |
|
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2715 | { |
|
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2716 | gaim_signals_unregister_by_instance(gaim_blist_get_handle()); |
|
3c7ba18e32f1
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6473
diff
changeset
|
2717 | } |