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