6 * Copyright (C) 2005 Bartosz Oler <bartosz@bzimage.us>
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
39 /* void ggp_buddylist_send(PurpleConnection *gc) {{{ */
40 /* this is for for notify purposes, not synchronizing buddy list */
41 void ggp_buddylist_send(PurpleConnection
*gc
)
43 GGPInfo
*info
= purple_connection_get_protocol_data(gc
);
44 PurpleAccount
*account
= purple_connection_get_account(gc
);
51 buddies
= purple_blist_find_buddies(account
, NULL
);
53 size
= g_slist_length(buddies
);
54 userlist
= g_new(uin_t
, size
);
55 types
= g_new(gchar
, size
);
57 for (buddies
= purple_blist_find_buddies(account
, NULL
); buddies
;
58 buddies
= g_slist_delete_link(buddies
, buddies
), ++i
)
60 PurpleBuddy
*buddy
= buddies
->data
;
61 const gchar
*name
= purple_buddy_get_name(buddy
);
63 userlist
[i
] = ggp_str_to_uin(name
);
64 types
[i
] = GG_USER_NORMAL
;
65 purple_debug_info("gg", "ggp_buddylist_send: adding %d\n",
69 ret
= gg_notify_ex(info
->session
, userlist
, types
, size
);
70 purple_debug_info("gg", "send: ret=%d; size=%d\n", ret
, size
);
79 /* void ggp_buddylist_load(PurpleConnection *gc, char *buddylist) {{{ */
80 void ggp_buddylist_load(PurpleConnection
*gc
, char *buddylist
)
86 char *utf8buddylist
= ggp_convert_from_cp1250(buddylist
);
88 /* Don't limit the number of records in a buddylist. */
89 users_tbl
= g_strsplit(utf8buddylist
, "\r\n", -1);
91 for (i
= 0; users_tbl
[i
] != NULL
; i
++) {
93 gchar
*name
, *show
, *g
;
98 data_tbl
= g_strsplit(users_tbl
[i
], ";", 8);
99 if (g_strv_length(data_tbl
) < 8) {
100 purple_debug_warning("gg",
101 "Something is wrong on line %d of the buddylist. Skipping.\n",
106 show
= data_tbl
[F_NICKNAME
];
107 name
= data_tbl
[F_UIN
];
108 if ('\0' == *name
|| !atol(name
)) {
109 purple_debug_warning("gg",
110 "Identifier on line %d of the buddylist is not a number. Skipping.\n",
119 purple_debug_info("gg", "got buddy: name=%s; show=%s\n", name
, show
);
121 if (purple_blist_find_buddy(purple_connection_get_account(gc
), name
)) {
122 g_strfreev(data_tbl
);
126 g
= g_strdup("Gadu-Gadu");
128 if ('\0' != *(data_tbl
[F_GROUP
])) {
129 /* XXX: Probably buddy should be added to all the groups. */
130 /* Hard limit to at most 50 groups */
131 gchar
**group_tbl
= g_strsplit(data_tbl
[F_GROUP
], ",", 50);
132 if (g_strv_length(group_tbl
) > 0) {
134 g
= g_strdup(group_tbl
[0]);
136 g_strfreev(group_tbl
);
139 buddy
= purple_buddy_new(purple_connection_get_account(gc
),
140 name
, *show
== '\0' ? NULL
: show
);
142 if (!(group
= purple_blist_find_group(g
))) {
143 group
= purple_group_new(g
);
144 purple_blist_add_group(group
, NULL
);
147 purple_blist_add_buddy(buddy
, NULL
, group
, NULL
);
150 g_strfreev(data_tbl
);
152 g_strfreev(users_tbl
);
153 g_free(utf8buddylist
);
155 ggp_buddylist_send(gc
);
159 /* char *ggp_buddylist_dump(PurpleAccount *account) {{{ */
160 char *ggp_buddylist_dump(PurpleAccount
*account
)
163 GString
*buddylist
= g_string_sized_new(1024);
166 for (buddies
= purple_blist_find_buddies(account
, NULL
); buddies
;
167 buddies
= g_slist_delete_link(buddies
, buddies
))
169 PurpleBuddy
*buddy
= buddies
->data
;
170 PurpleGroup
*group
= purple_buddy_get_group(buddy
);
171 const char *bname
= purple_buddy_get_name(buddy
);
172 const char *gname
= purple_group_get_name(group
);
173 const char *alias
= purple_buddy_get_alias(buddy
);
178 g_string_append_printf(buddylist
,
179 "%s;%s;%s;%s;%s;%s;%s;%s%s\r\n",
180 alias
, alias
, alias
, alias
,
181 "", gname
, bname
, "", "");
184 ptr
= ggp_convert_to_cp1250(buddylist
->str
);
185 g_string_free(buddylist
, TRUE
);
190 const char * ggp_buddylist_get_buddy_name(PurpleConnection
*gc
, const uin_t uin
)
192 const char *uin_s
= ggp_uin_to_str(uin
);
193 PurpleBuddy
*buddy
= purple_blist_find_buddy(
194 purple_connection_get_account(gc
), uin_s
);
197 return purple_buddy_get_alias(buddy
);
202 /* vim: set ts=8 sts=0 sw=8 noet: */