14192
|
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 /*
|
|
94 * XXX: Limit of entries in a buddylist that will be imported.
|
|
95 */
|
|
96 users_tbl = g_strsplit(buddylist, "\r\n", 200);
|
|
97
|
|
98 for (i = 0; users_tbl[i] != NULL; i++) {
|
|
99 gchar **data_tbl;
|
|
100 gchar *name, *show, *g;
|
|
101
|
|
102 if (strlen(users_tbl[i]) == 0)
|
|
103 continue;
|
|
104
|
|
105 data_tbl = g_strsplit(users_tbl[i], ";", 8);
|
|
106
|
|
107 show = charset_convert(data_tbl[3], "CP1250", "UTF-8");
|
|
108 name = data_tbl[6];
|
|
109
|
|
110 gaim_debug_info("gg", "got buddy: name=%s show=%s\n", name, show);
|
|
111
|
|
112 if (gaim_find_buddy(gaim_connection_get_account(gc), name)) {
|
|
113 g_free(show);
|
|
114 g_strfreev(data_tbl);
|
|
115 continue;
|
|
116 }
|
|
117
|
|
118 g = g_strdup("Gadu-Gadu");
|
|
119
|
|
120 if (strlen(data_tbl[5])) {
|
|
121 /* Hard limit to at most 50 groups */
|
|
122 gchar **group_tbl = g_strsplit(data_tbl[5], ",", 50);
|
|
123 if (strlen(group_tbl[0]) > 0) {
|
|
124 g_free(g);
|
|
125 g = g_strdup(group_tbl[0]);
|
|
126 }
|
|
127 g_strfreev(group_tbl);
|
|
128 }
|
|
129
|
|
130 buddy = gaim_buddy_new(gaim_connection_get_account(gc), name,
|
|
131 strlen(show) ? show : NULL);
|
|
132
|
|
133 if (!(group = gaim_find_group(g))) {
|
|
134 group = gaim_group_new(g);
|
|
135 gaim_blist_add_group(group, NULL);
|
|
136 }
|
|
137
|
|
138 gaim_blist_add_buddy(buddy, NULL, group, NULL);
|
|
139 g_free(g);
|
|
140
|
|
141 g_free(show);
|
|
142 g_strfreev(data_tbl);
|
|
143 }
|
|
144 g_strfreev(users_tbl);
|
|
145
|
|
146 ggp_buddylist_send(gc);
|
|
147
|
|
148 }
|
|
149 /* }}} */
|
|
150
|
|
151 /* void ggp_buddylist_offline(GaimConnection *gc) {{{ */
|
|
152 void ggp_buddylist_offline(GaimConnection *gc)
|
|
153 {
|
|
154 GaimAccount *account = gaim_connection_get_account(gc);
|
|
155 GaimBuddyList *blist;
|
|
156 GaimBlistNode *gnode, *cnode, *bnode;
|
|
157 GaimBuddy *buddy;
|
|
158
|
|
159 if ((blist = gaim_get_blist()) == NULL)
|
|
160 return;
|
|
161
|
|
162 for (gnode = blist->root; gnode != NULL; gnode = gnode->next) {
|
|
163 if (!GAIM_BLIST_NODE_IS_GROUP(gnode))
|
|
164 continue;
|
|
165
|
|
166 for (cnode = gnode->child; cnode != NULL; cnode = cnode->next) {
|
|
167 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode))
|
|
168 continue;
|
|
169
|
|
170 for (bnode = cnode->child; bnode != NULL; bnode = bnode->next) {
|
|
171 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode))
|
|
172 continue;
|
|
173
|
|
174 buddy = (GaimBuddy *)bnode;
|
|
175
|
|
176 if (buddy->account != account)
|
|
177 continue;
|
|
178
|
|
179 gaim_prpl_got_user_status(
|
|
180 gaim_connection_get_account(gc),
|
|
181 buddy->name, "offline", NULL);
|
|
182
|
|
183 gaim_debug_info("gg",
|
|
184 "ggp_buddylist_offline: gone: %s\n",
|
|
185 buddy->name);
|
|
186 }
|
|
187 }
|
|
188 }
|
|
189 }
|
|
190 /* }}} */
|
|
191
|
|
192 /* char *ggp_buddylist_dump(GaimAccount *account) {{{ */
|
|
193 char *ggp_buddylist_dump(GaimAccount *account)
|
|
194 {
|
|
195 GaimBuddyList *blist;
|
|
196 GaimBlistNode *gnode, *cnode, *bnode;
|
|
197 GaimGroup *group;
|
|
198 GaimBuddy *buddy;
|
|
199
|
|
200 char *buddylist = g_strdup("");
|
|
201 char *ptr;
|
|
202
|
|
203 if ((blist = gaim_get_blist()) == NULL)
|
|
204 return NULL;
|
|
205
|
|
206 for (gnode = blist->root; gnode != NULL; gnode = gnode->next) {
|
|
207 if (!GAIM_BLIST_NODE_IS_GROUP(gnode))
|
|
208 continue;
|
|
209
|
|
210 group = (GaimGroup *)gnode;
|
|
211
|
|
212 for (cnode = gnode->child; cnode != NULL; cnode = cnode->next) {
|
|
213 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode))
|
|
214 continue;
|
|
215
|
|
216 for (bnode = cnode->child; bnode != NULL; bnode = bnode->next) {
|
|
217 gchar *newdata, *name, *alias, *gname;
|
|
218 gchar *cp_alias, *cp_gname;
|
|
219
|
|
220 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode))
|
|
221 continue;
|
|
222
|
|
223 buddy = (GaimBuddy *)bnode;
|
|
224 if (buddy->account != account)
|
|
225 continue;
|
|
226
|
|
227 name = buddy->name;
|
|
228 alias = buddy->alias ? buddy->alias : buddy->name;
|
|
229 gname = group->name;
|
|
230
|
|
231 cp_gname = charset_convert(gname, "UTF-8", "CP1250");
|
|
232 cp_alias = charset_convert(alias, "UTF-8", "CP1250");
|
|
233 newdata = g_strdup_printf(
|
|
234 "%s;%s;%s;%s;%s;%s;%s;%s%s\r\n",
|
|
235 cp_alias, cp_alias, cp_alias, cp_alias,
|
|
236 "", cp_gname, name, "", "");
|
|
237
|
|
238 ptr = buddylist;
|
|
239 buddylist = g_strconcat(ptr, newdata, NULL);
|
|
240
|
|
241 g_free(newdata);
|
|
242 g_free(ptr);
|
|
243 g_free(cp_gname);
|
|
244 g_free(cp_alias);
|
|
245 }
|
|
246 }
|
|
247 }
|
|
248
|
|
249 return buddylist;
|
|
250 }
|
|
251 /* }}} */
|
|
252
|
|
253
|
|
254 /* vim: set ts=8 sts=0 sw=8 noet: */
|