comparison src/protocols/gg/buddylist.c @ 11414:d5599677bf32

[gaim-migrate @ 13651] Code split. committer: Tailor Script <tailor@pidgin.im>
author Bartoz Oler <bartosz@pidgin.im>
date Thu, 01 Sep 2005 20:05:01 +0000
parents
children 8724718d387f
comparison
equal deleted inserted replaced
11413:112eb407497e 11414:d5599677bf32
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 "lib/libgadu.h"
25
26 #include "gg.h"
27 #include "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
36 GaimBuddyList *blist;
37 GaimBlistNode *gnode, *cnode, *bnode;
38 GaimBuddy *buddy;
39 uin_t *userlist = NULL;
40 gchar *types = NULL;
41 int userlist_size = 0;
42
43 if ((blist = gaim_get_blist()) != NULL)
44 {
45 for (gnode = blist->root; gnode != NULL; gnode = gnode->next)
46 {
47 if (!GAIM_BLIST_NODE_IS_GROUP(gnode))
48 continue;
49 for (cnode = gnode->child; cnode != NULL; cnode = cnode->next)
50 {
51 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode))
52 continue;
53 for (bnode = cnode->child; bnode != NULL; bnode = bnode->next)
54 {
55 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode))
56 continue;
57 buddy = (GaimBuddy *)bnode;
58
59 if (buddy->account != gc->account)
60 continue;
61
62 userlist_size++;
63 userlist = (uin_t *) g_renew(uin_t, userlist, userlist_size);
64 types = (gchar *) g_renew(gchar, types, userlist_size);
65 userlist[userlist_size - 1] = ggp_str_to_uin(buddy->name);
66 types[userlist_size - 1] = GG_USER_NORMAL;
67 gaim_debug_info("gg", "ggp_buddylist_send: adding %d\n", userlist[userlist_size - 1]);
68 }
69 }
70 }
71 }
72
73 if (userlist) {
74 int ret = gg_notify_ex(info->session, userlist, types, userlist_size);
75 g_free(userlist);
76 g_free(types);
77
78 gaim_debug_info("gg", "send: ret=%d; size=%d\n", ret, userlist_size);
79 }
80 }
81 /* }}} */
82
83 /* void ggp_buddylist_load(GaimConnection *gc, char *buddylist) {{{ */
84 void ggp_buddylist_load(GaimConnection *gc, char *buddylist)
85 {
86 GaimBuddy *buddy;
87 GaimGroup *group;
88 gchar **users_tbl;
89 int i;
90
91 users_tbl = g_strsplit(buddylist, "\r\n", 200);
92
93 for (i = 0; users_tbl[i] != NULL; i++) {
94 gchar **data_tbl;
95 gchar *name, *show, *g;
96
97 if (strlen(users_tbl[i]) == 0)
98 continue;
99
100 data_tbl = g_strsplit(users_tbl[i], ";", 8);
101
102 show = charset_convert(data_tbl[3], "CP1250", "UTF-8");
103 name = data_tbl[6];
104
105 gaim_debug_info("gg", "got buddy: name=%s show=%s\n", name, show);
106
107 if (gaim_find_buddy(gaim_connection_get_account(gc), name)) {
108 g_free(show);
109 g_strfreev(data_tbl);
110 continue;
111 }
112
113 g = g_strdup("Gadu-Gadu");
114
115 if (strlen(data_tbl[5])) {
116 /* Hard limit to at most 50 groups */
117 gchar **group_tbl = g_strsplit(data_tbl[5], ",", 50);
118 if (strlen(group_tbl[0]) > 0) {
119 g_free(g);
120 g = g_strdup(group_tbl[0]);
121 }
122 g_strfreev(group_tbl);
123 }
124
125 buddy = gaim_buddy_new(gaim_connection_get_account(gc), name, strlen(show) ? show : NULL);
126 if (!(group = gaim_find_group(g))) {
127 group = gaim_group_new(g);
128 gaim_blist_add_group(group, NULL);
129 }
130
131 gaim_blist_add_buddy(buddy, NULL, group, NULL);
132 g_free(g);
133
134 g_free(show);
135 g_strfreev(data_tbl);
136 }
137 g_strfreev(users_tbl);
138
139 ggp_buddylist_send(gc);
140
141 }
142 /* }}} */
143
144 /* void ggp_buddylist_offline(GaimConnection *gc) {{{ */
145 void ggp_buddylist_offline(GaimConnection *gc)
146 {
147 GaimBuddyList *blist;
148 GaimBlistNode *gnode, *cnode, *bnode;
149 GaimBuddy *buddy;
150
151 if ((blist = gaim_get_blist()) != NULL)
152 {
153 for (gnode = blist->root; gnode != NULL; gnode = gnode->next)
154 {
155 if (!GAIM_BLIST_NODE_IS_GROUP(gnode))
156 continue;
157 for (cnode = gnode->child; cnode != NULL; cnode = cnode->next)
158 {
159 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode))
160 continue;
161 for (bnode = cnode->child; bnode != NULL; bnode = bnode->next)
162 {
163 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode))
164 continue;
165
166 buddy = (GaimBuddy *)bnode;
167
168 if (buddy->account != gc->account)
169 continue;
170
171 gaim_prpl_got_user_status(
172 gaim_connection_get_account(gc),
173 buddy->name, "offline", NULL);
174 gaim_debug_info("gg", "ggp_buddylist_offline: gone: %s\n", buddy->name);
175 }
176 }
177 }
178 }
179 }
180 /* }}} */
181
182 /* char *ggp_buddylist_dump(GaimAccount *account) {{{ */
183 char *ggp_buddylist_dump(GaimAccount *account)
184 {
185 GaimBuddyList *blist;
186 GaimBlistNode *gnode, *cnode, *bnode;
187 GaimGroup *group;
188 GaimBuddy *buddy;
189
190 char *buddylist = g_strdup("");
191 char *ptr;
192
193 if ((blist = gaim_get_blist()) == NULL)
194 return NULL;
195
196 for (gnode = blist->root; gnode != NULL; gnode = gnode->next) {
197 if (!GAIM_BLIST_NODE_IS_GROUP(gnode))
198 continue;
199
200 group = (GaimGroup *)gnode;
201
202 for (cnode = gnode->child; cnode != NULL; cnode = cnode->next) {
203 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode))
204 continue;
205
206 for (bnode = cnode->child; bnode != NULL; bnode = bnode->next) {
207 gchar *newdata, *name, *show, *gname;
208
209 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode))
210 continue;
211
212 buddy = (GaimBuddy *)bnode;
213 if (buddy->account != account)
214 continue;
215
216 name = buddy->name;
217 show = buddy->alias ? buddy->alias : buddy->name;
218 gname = group->name;
219
220 newdata = g_strdup_printf("%s;%s;%s;%s;%s;%s;%s;%s%s\r\n",
221 show, show, show, show, "", gname, name, "", "");
222
223 ptr = buddylist;
224 buddylist = g_strconcat(ptr, newdata, NULL);
225
226 g_free(newdata);
227 g_free(ptr);
228 }
229 }
230 }
231
232 return buddylist;
233 }
234 /* }}} */
235
236
237 /* vim: set ts=4 sts=0 sw=4 noet: */