comparison libpurple/protocols/gg/buddylist.c @ 15374:5fe8042783c1

Rename gtk/ and libgaim/ to pidgin/ and libpurple/
author Sean Egan <seanegan@gmail.com>
date Sat, 20 Jan 2007 02:32:10 +0000
parents
children 32c366eeeb99
comparison
equal deleted inserted replaced
15373:f79e0f4df793 15374:5fe8042783c1
1 /**
2 * @file buddylist.c
3 *
4 * gaim
5 *
6 * Copyright (C) 2005 Bartosz Oler <bartosz@bzimage.us>
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
23
24 #include <libgadu.h>
25
26 #include "gg.h"
27 #include "gg-utils.h"
28 #include "buddylist.h"
29
30
31 /* void ggp_buddylist_send(GaimConnection *gc) {{{ */
32 void ggp_buddylist_send(GaimConnection *gc)
33 {
34 GGPInfo *info = gc->proto_data;
35 GaimAccount *account = gaim_connection_get_account(gc);
36
37 GaimBuddyList *blist;
38 GaimBlistNode *gnode, *cnode, *bnode;
39 GaimBuddy *buddy;
40 uin_t *userlist = NULL;
41 gchar *types = NULL;
42 int size = 0;
43
44 if ((blist = gaim_get_blist()) == NULL)
45 return;
46
47 for (gnode = blist->root; gnode != NULL; gnode = gnode->next) {
48 if (!GAIM_BLIST_NODE_IS_GROUP(gnode))
49 continue;
50
51 for (cnode = gnode->child; cnode != NULL; cnode = cnode->next) {
52 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode))
53 continue;
54
55 for (bnode = cnode->child; bnode != NULL; bnode = bnode->next) {
56 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode))
57 continue;
58
59 buddy = (GaimBuddy *)bnode;
60
61 if (buddy->account != account)
62 continue;
63
64 size++;
65 userlist = (uin_t *) g_renew(uin_t, userlist, size);
66 types = (gchar *) g_renew(gchar, types, size);
67 userlist[size - 1] = ggp_str_to_uin(buddy->name);
68 types[size - 1] = GG_USER_NORMAL;
69 gaim_debug_info("gg", "ggp_buddylist_send: adding %d\n",
70 userlist[size - 1]);
71 }
72 }
73 }
74
75 if (userlist) {
76 int ret = gg_notify_ex(info->session, userlist, types, size);
77 g_free(userlist);
78 g_free(types);
79
80 gaim_debug_info("gg", "send: ret=%d; size=%d\n", ret, size);
81 }
82 }
83 /* }}} */
84
85 /* void ggp_buddylist_load(GaimConnection *gc, char *buddylist) {{{ */
86 void ggp_buddylist_load(GaimConnection *gc, char *buddylist)
87 {
88 GaimBuddy *buddy;
89 GaimGroup *group;
90 gchar **users_tbl;
91 int i;
92
93 /* Don't limit a number of records in a buddylist. */
94 users_tbl = g_strsplit(buddylist, "\r\n", -1);
95
96 for (i = 0; users_tbl[i] != NULL; i++) {
97 gchar **data_tbl;
98 gchar *name, *show, *g;
99
100 if (strlen(users_tbl[i]) == 0)
101 continue;
102
103 data_tbl = g_strsplit(users_tbl[i], ";", 8);
104 if (ggp_array_size(data_tbl) < 8) {
105 gaim_debug_warning("gg",
106 "Something is wrong on line %d of the buddylist. Skipping.\n",
107 i + 1);
108 continue;
109 }
110
111 show = charset_convert(data_tbl[3], "CP1250", "UTF-8");
112 name = data_tbl[6];
113 if ('\0' == *name) {
114 gaim_debug_warning("gg",
115 "Something is wrong on line %d of the buddylist. Skipping.\n",
116 i + 1);
117 continue;
118 }
119
120 if ('\0' == *show) {
121 show = g_strdup(name);
122 }
123
124 gaim_debug_info("gg", "got buddy: name=%s show=%s\n", name, show);
125
126 if (gaim_find_buddy(gaim_connection_get_account(gc), name)) {
127 g_free(show);
128 g_strfreev(data_tbl);
129 continue;
130 }
131
132 g = g_strdup("Gadu-Gadu");
133
134 if ('\0' != data_tbl[5]) {
135 /* XXX: Probably buddy should be added to all the groups. */
136 /* Hard limit to at most 50 groups */
137 gchar **group_tbl = g_strsplit(data_tbl[5], ",", 50);
138 if (ggp_array_size(group_tbl) > 0) {
139 g_free(g);
140 g = g_strdup(group_tbl[0]);
141 }
142 g_strfreev(group_tbl);
143 }
144
145 buddy = gaim_buddy_new(gaim_connection_get_account(gc), name,
146 strlen(show) ? show : NULL);
147
148 if (!(group = gaim_find_group(g))) {
149 group = gaim_group_new(g);
150 gaim_blist_add_group(group, NULL);
151 }
152
153 gaim_blist_add_buddy(buddy, NULL, group, NULL);
154 g_free(g);
155
156 g_free(show);
157 g_strfreev(data_tbl);
158 }
159 g_strfreev(users_tbl);
160
161 ggp_buddylist_send(gc);
162
163 }
164 /* }}} */
165
166 /* void ggp_buddylist_offline(GaimConnection *gc) {{{ */
167 void ggp_buddylist_offline(GaimConnection *gc)
168 {
169 GaimAccount *account = gaim_connection_get_account(gc);
170 GaimBuddyList *blist;
171 GaimBlistNode *gnode, *cnode, *bnode;
172 GaimBuddy *buddy;
173
174 if ((blist = gaim_get_blist()) == NULL)
175 return;
176
177 for (gnode = blist->root; gnode != NULL; gnode = gnode->next) {
178 if (!GAIM_BLIST_NODE_IS_GROUP(gnode))
179 continue;
180
181 for (cnode = gnode->child; cnode != NULL; cnode = cnode->next) {
182 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode))
183 continue;
184
185 for (bnode = cnode->child; bnode != NULL; bnode = bnode->next) {
186 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode))
187 continue;
188
189 buddy = (GaimBuddy *)bnode;
190
191 if (buddy->account != account)
192 continue;
193
194 gaim_prpl_got_user_status(
195 gaim_connection_get_account(gc),
196 buddy->name, "offline", NULL);
197
198 gaim_debug_info("gg",
199 "ggp_buddylist_offline: gone: %s\n",
200 buddy->name);
201 }
202 }
203 }
204 }
205 /* }}} */
206
207 /* char *ggp_buddylist_dump(GaimAccount *account) {{{ */
208 char *ggp_buddylist_dump(GaimAccount *account)
209 {
210 GaimBuddyList *blist;
211 GaimBlistNode *gnode, *cnode, *bnode;
212 GaimGroup *group;
213 GaimBuddy *buddy;
214
215 char *buddylist = g_strdup("");
216 char *ptr;
217
218 if ((blist = gaim_get_blist()) == NULL)
219 return NULL;
220
221 for (gnode = blist->root; gnode != NULL; gnode = gnode->next) {
222 if (!GAIM_BLIST_NODE_IS_GROUP(gnode))
223 continue;
224
225 group = (GaimGroup *)gnode;
226
227 for (cnode = gnode->child; cnode != NULL; cnode = cnode->next) {
228 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode))
229 continue;
230
231 for (bnode = cnode->child; bnode != NULL; bnode = bnode->next) {
232 gchar *newdata, *name, *alias, *gname;
233 gchar *cp_alias, *cp_gname;
234
235 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode))
236 continue;
237
238 buddy = (GaimBuddy *)bnode;
239 if (buddy->account != account)
240 continue;
241
242 name = buddy->name;
243 alias = buddy->alias ? buddy->alias : buddy->name;
244 gname = group->name;
245
246 cp_gname = charset_convert(gname, "UTF-8", "CP1250");
247 cp_alias = charset_convert(alias, "UTF-8", "CP1250");
248 newdata = g_strdup_printf(
249 "%s;%s;%s;%s;%s;%s;%s;%s%s\r\n",
250 cp_alias, cp_alias, cp_alias, cp_alias,
251 "", cp_gname, name, "", "");
252
253 ptr = buddylist;
254 buddylist = g_strconcat(ptr, newdata, NULL);
255
256 g_free(newdata);
257 g_free(ptr);
258 g_free(cp_gname);
259 g_free(cp_alias);
260 }
261 }
262 }
263
264 return buddylist;
265 }
266 /* }}} */
267
268
269 /* vim: set ts=8 sts=0 sw=8 noet: */