Mercurial > pidgin.yaz
comparison libpurple/protocols/qq/group_internal.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 group_internal.c | |
3 * | |
4 * gaim | |
5 * | |
6 * Gaim is the legal property of its developers, whose names are too numerous | |
7 * to list here. Please refer to the COPYRIGHT file distributed with this | |
8 * source distribution. | |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; if not, write to the Free Software | |
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
23 */ | |
24 | |
25 #include "blist.h" | |
26 #include "debug.h" | |
27 | |
28 #include "buddy_opt.h" | |
29 #include "group_free.h" | |
30 #include "group_internal.h" | |
31 #include "group_misc.h" | |
32 #include "utils.h" | |
33 | |
34 static gchar *_qq_group_set_my_status_desc(qq_group *group) | |
35 { | |
36 const char *status_desc; | |
37 g_return_val_if_fail(group != NULL, g_strdup("")); | |
38 | |
39 switch (group->my_status) { | |
40 case QQ_GROUP_MEMBER_STATUS_NOT_MEMBER: | |
41 status_desc = _("I am not member"); | |
42 break; | |
43 case QQ_GROUP_MEMBER_STATUS_IS_MEMBER: | |
44 status_desc = _("I am a member"); | |
45 break; | |
46 case QQ_GROUP_MEMBER_STATUS_APPLYING: | |
47 status_desc = _("I am applying to join"); | |
48 break; | |
49 case QQ_GROUP_MEMBER_STATUS_IS_ADMIN: | |
50 status_desc = _("I am the admin"); | |
51 break; | |
52 default: | |
53 status_desc = _("Unknown status"); | |
54 } | |
55 | |
56 return g_strdup(status_desc); | |
57 } | |
58 | |
59 static void _qq_group_add_to_blist(GaimConnection *gc, qq_group *group) | |
60 { | |
61 GHashTable *components; | |
62 GaimGroup *g; | |
63 GaimChat *chat; | |
64 components = qq_group_to_hashtable(group); | |
65 chat = gaim_chat_new(gaim_connection_get_account(gc), group->group_name_utf8, components); | |
66 g = qq_get_gaim_group(GAIM_GROUP_QQ_QUN); | |
67 gaim_blist_add_chat(chat, g, NULL); | |
68 gaim_debug(GAIM_DEBUG_INFO, "QQ", "You have added group \"%s\" to blist locally\n", group->group_name_utf8); | |
69 } | |
70 | |
71 /* Create a dummy qq_group, which includes only internal_id, external_id, | |
72 * and potentially group_name_utf8, in case we need to call group_conv_show_window | |
73 * right after creation. All other attributes are set to empty. | |
74 * We need to send a get_group_info to the QQ server to update it right away */ | |
75 qq_group *qq_group_create_internal_record(GaimConnection *gc, | |
76 guint32 internal_id, guint32 external_id, gchar *group_name_utf8) | |
77 { | |
78 qq_group *group; | |
79 qq_data *qd; | |
80 | |
81 g_return_val_if_fail(internal_id > 0, NULL); | |
82 qd = (qq_data *) gc->proto_data; | |
83 | |
84 group = g_new0(qq_group, 1); | |
85 group->my_status = QQ_GROUP_MEMBER_STATUS_NOT_MEMBER; | |
86 group->my_status_desc = _qq_group_set_my_status_desc(group); | |
87 group->internal_group_id = internal_id; | |
88 group->external_group_id = external_id; | |
89 group->group_type = 0x01; /* assume permanent Qun */ | |
90 group->creator_uid = 10000; /* assume by QQ admin */ | |
91 group->group_category = 0x01; | |
92 group->auth_type = 0x02; /* assume need auth */ | |
93 group->group_name_utf8 = g_strdup(group_name_utf8 == NULL ? "" : group_name_utf8); | |
94 group->group_desc_utf8 = g_strdup(""); | |
95 group->notice_utf8 = g_strdup(""); | |
96 group->members = NULL; | |
97 | |
98 qd->groups = g_list_append(qd->groups, group); | |
99 _qq_group_add_to_blist(gc, group); | |
100 | |
101 return group; | |
102 } | |
103 | |
104 void qq_group_delete_internal_record(qq_data *qd, guint32 internal_group_id) | |
105 { | |
106 qq_group *group; | |
107 GList *list; | |
108 | |
109 list = qd->groups; | |
110 while (list != NULL) { | |
111 group = (qq_group *) qd->groups->data; | |
112 if (internal_group_id == group->internal_group_id) { | |
113 qd->groups = g_list_remove(qd->groups, group); | |
114 qq_group_free(group); | |
115 break; | |
116 } else { | |
117 list = list->next; | |
118 } | |
119 } | |
120 } | |
121 | |
122 /* convert a qq_group to hash-table, which could be component of GaimChat */ | |
123 GHashTable *qq_group_to_hashtable(qq_group *group) | |
124 { | |
125 GHashTable *components; | |
126 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
127 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_MEMBER_STATUS), g_strdup_printf("%d", group->my_status)); | |
128 group->my_status_desc = _qq_group_set_my_status_desc(group); | |
129 | |
130 g_hash_table_insert(components, | |
131 g_strdup(QQ_GROUP_KEY_INTERNAL_ID), g_strdup_printf("%d", group->internal_group_id)); | |
132 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_EXTERNAL_ID), | |
133 g_strdup_printf("%d", group->external_group_id)); | |
134 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_GROUP_TYPE), g_strdup_printf("%d", group->group_type)); | |
135 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_CREATOR_UID), g_strdup_printf("%d", group->creator_uid)); | |
136 g_hash_table_insert(components, | |
137 g_strdup(QQ_GROUP_KEY_GROUP_CATEGORY), g_strdup_printf("%d", group->group_category)); | |
138 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_AUTH_TYPE), g_strdup_printf("%d", group->auth_type)); | |
139 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_MEMBER_STATUS_DESC), g_strdup(group->my_status_desc)); | |
140 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_GROUP_NAME_UTF8), g_strdup(group->group_name_utf8)); | |
141 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_GROUP_DESC_UTF8), g_strdup(group->group_desc_utf8)); | |
142 return components; | |
143 } | |
144 | |
145 /* create a qq_group from hashtable */ | |
146 qq_group *qq_group_from_hashtable(GaimConnection *gc, GHashTable *data) | |
147 { | |
148 qq_data *qd; | |
149 qq_group *group; | |
150 | |
151 g_return_val_if_fail(data != NULL, NULL); | |
152 qd = (qq_data *) gc->proto_data; | |
153 | |
154 group = g_new0(qq_group, 1); | |
155 group->my_status = | |
156 qq_string_to_dec_value | |
157 (NULL == | |
158 g_hash_table_lookup(data, | |
159 QQ_GROUP_KEY_MEMBER_STATUS) ? | |
160 g_strdup_printf("%d", | |
161 QQ_GROUP_MEMBER_STATUS_NOT_MEMBER) : | |
162 g_hash_table_lookup(data, QQ_GROUP_KEY_MEMBER_STATUS)); | |
163 group->internal_group_id = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_GROUP_KEY_INTERNAL_ID)); | |
164 group->external_group_id = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_GROUP_KEY_EXTERNAL_ID)); | |
165 group->group_type = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_GROUP_KEY_GROUP_TYPE)); | |
166 group->creator_uid = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_GROUP_KEY_CREATOR_UID)); | |
167 group->group_category = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_GROUP_KEY_GROUP_CATEGORY)); | |
168 group->auth_type = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_GROUP_KEY_AUTH_TYPE)); | |
169 group->group_name_utf8 = g_strdup(g_hash_table_lookup(data, QQ_GROUP_KEY_GROUP_NAME_UTF8)); | |
170 group->group_desc_utf8 = g_strdup(g_hash_table_lookup(data, QQ_GROUP_KEY_GROUP_DESC_UTF8)); | |
171 group->my_status_desc = _qq_group_set_my_status_desc(group); | |
172 | |
173 qd->groups = g_list_append(qd->groups, group); | |
174 | |
175 return group; | |
176 } | |
177 | |
178 /* refresh group local subscription */ | |
179 void qq_group_refresh(GaimConnection *gc, qq_group *group) | |
180 { | |
181 GaimChat *chat; | |
182 gchar *external_group_id; | |
183 g_return_if_fail(group != NULL); | |
184 | |
185 external_group_id = g_strdup_printf("%d", group->external_group_id); | |
186 chat = gaim_blist_find_chat(gaim_connection_get_account(gc), external_group_id); | |
187 g_free(external_group_id); | |
188 if (chat == NULL && group->my_status != QQ_GROUP_MEMBER_STATUS_NOT_MEMBER) { | |
189 _qq_group_add_to_blist(gc, group); | |
190 } else if (chat != NULL) { /* we have a local record, update its info */ | |
191 /* if there is group_name_utf8, we update the group name */ | |
192 if (group->group_name_utf8 != NULL && strlen(group->group_name_utf8) > 0) | |
193 gaim_blist_alias_chat(chat, group->group_name_utf8); | |
194 g_hash_table_replace(chat->components, | |
195 g_strdup(QQ_GROUP_KEY_MEMBER_STATUS), g_strdup_printf("%d", group->my_status)); | |
196 group->my_status_desc = _qq_group_set_my_status_desc(group); | |
197 g_hash_table_replace(chat->components, | |
198 g_strdup(QQ_GROUP_KEY_MEMBER_STATUS_DESC), g_strdup(group->my_status_desc)); | |
199 g_hash_table_replace(chat->components, | |
200 g_strdup(QQ_GROUP_KEY_INTERNAL_ID), | |
201 g_strdup_printf("%d", group->internal_group_id)); | |
202 g_hash_table_replace(chat->components, | |
203 g_strdup(QQ_GROUP_KEY_EXTERNAL_ID), | |
204 g_strdup_printf("%d", group->external_group_id)); | |
205 g_hash_table_replace(chat->components, | |
206 g_strdup(QQ_GROUP_KEY_GROUP_TYPE), g_strdup_printf("%d", group->group_type)); | |
207 g_hash_table_replace(chat->components, | |
208 g_strdup(QQ_GROUP_KEY_CREATOR_UID), g_strdup_printf("%d", group->creator_uid)); | |
209 g_hash_table_replace(chat->components, | |
210 g_strdup(QQ_GROUP_KEY_GROUP_CATEGORY), | |
211 g_strdup_printf("%d", group->group_category)); | |
212 g_hash_table_replace(chat->components, | |
213 g_strdup(QQ_GROUP_KEY_AUTH_TYPE), g_strdup_printf("%d", group->auth_type)); | |
214 g_hash_table_replace(chat->components, | |
215 g_strdup(QQ_GROUP_KEY_GROUP_NAME_UTF8), g_strdup(group->group_name_utf8)); | |
216 g_hash_table_replace(chat->components, | |
217 g_strdup(QQ_GROUP_KEY_GROUP_DESC_UTF8), g_strdup(group->group_desc_utf8)); | |
218 } | |
219 } | |
220 | |
221 /* NOTE: If we knew how to convert between an external and internal group id, as the official | |
222 * client seems to, the following would be unnecessary. That would be ideal. */ | |
223 | |
224 /* Use list to specify if id's alternate id is pending discovery. */ | |
225 void qq_set_pending_id(GSList **list, guint32 id, gboolean pending) | |
226 { | |
227 if (pending) | |
228 *list = g_slist_prepend(*list, GINT_TO_POINTER(id)); | |
229 else | |
230 *list = g_slist_remove(*list, GINT_TO_POINTER(id)); | |
231 } | |
232 | |
233 /* Return the location of id in list, or NULL if not found */ | |
234 GSList *qq_get_pending_id(GSList *list, guint32 id) | |
235 { | |
236 return g_slist_find(list, GINT_TO_POINTER(id)); | |
237 } |