comparison libpurple/protocols/qq/group_internal.c @ 24154:237e5a94e11c

2008.10.08 - ccpaging <ccpaging(at)gmail.com> * Update group part * Delete some meaningless functions and data * Added 'change my icon' 2008.10.08 - lonicerae <lonicerae(at)gmail.com> * Merge 20081008 patch into trunk
author SHiNE CsyFeK <csyfek@gmail.com>
date Wed, 22 Oct 2008 15:08:30 +0000
parents 1bdf7b602684
children 3c52353b83ae
comparison
equal deleted inserted replaced
24153:340fc40fe4ef 24154:237e5a94e11c
140 g_hash_table_insert(components, g_strdup(QQ_ROOM_KEY_TITLE_UTF8), g_strdup(group->title_utf8)); 140 g_hash_table_insert(components, g_strdup(QQ_ROOM_KEY_TITLE_UTF8), g_strdup(group->title_utf8));
141 g_hash_table_insert(components, g_strdup(QQ_ROOM_KEY_DESC_UTF8), g_strdup(group->desc_utf8)); 141 g_hash_table_insert(components, g_strdup(QQ_ROOM_KEY_DESC_UTF8), g_strdup(group->desc_utf8));
142 return components; 142 return components;
143 } 143 }
144 144
145 static gint str2dec(const gchar *str)
146 {
147 g_return_val_if_fail(str != NULL, 0);
148 return strtol(str, NULL, 10);
149 }
150
145 /* create a qq_group from hashtable */ 151 /* create a qq_group from hashtable */
146 qq_group *qq_room_create_by_hashtable(PurpleConnection *gc, GHashTable *data) 152 qq_group *qq_room_data_new_by_hashtable(PurpleConnection *gc, GHashTable *data)
147 { 153 {
148 qq_data *qd; 154 qq_data *qd;
149 qq_group *group; 155 qq_group *group;
150 156
151 g_return_val_if_fail(data != NULL, NULL); 157 g_return_val_if_fail(data != NULL, NULL);
152 qd = (qq_data *) gc->proto_data; 158 qd = (qq_data *) gc->proto_data;
153 159
154 group = g_new0(qq_group, 1); 160 group = g_new0(qq_group, 1);
155 group->my_role = 161 group->my_role =
156 qq_string_to_dec_value 162 str2dec
157 (NULL == 163 (NULL ==
158 g_hash_table_lookup(data, 164 g_hash_table_lookup(data,
159 QQ_ROOM_KEY_ROLE) ? 165 QQ_ROOM_KEY_ROLE) ?
160 g_strdup_printf("%d", QQ_ROOM_ROLE_NO) : 166 g_strdup_printf("%d", QQ_ROOM_ROLE_NO) :
161 g_hash_table_lookup(data, QQ_ROOM_KEY_ROLE)); 167 g_hash_table_lookup(data, QQ_ROOM_KEY_ROLE));
162 group->id = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_ROOM_KEY_INTERNAL_ID)); 168 group->id = str2dec(g_hash_table_lookup(data, QQ_ROOM_KEY_INTERNAL_ID));
163 group->ext_id = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_ROOM_KEY_EXTERNAL_ID)); 169 group->ext_id = str2dec(g_hash_table_lookup(data, QQ_ROOM_KEY_EXTERNAL_ID));
164 group->type8 = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_ROOM_KEY_TYPE)); 170 group->type8 = str2dec(g_hash_table_lookup(data, QQ_ROOM_KEY_TYPE));
165 group->creator_uid = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_ROOM_KEY_CREATOR_UID)); 171 group->creator_uid = str2dec(g_hash_table_lookup(data, QQ_ROOM_KEY_CREATOR_UID));
166 group->category = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_ROOM_KEY_CATEGORY)); 172 group->category = str2dec(g_hash_table_lookup(data, QQ_ROOM_KEY_CATEGORY));
167 group->auth_type = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_ROOM_KEY_AUTH_TYPE)); 173 group->auth_type = str2dec(g_hash_table_lookup(data, QQ_ROOM_KEY_AUTH_TYPE));
168 group->title_utf8 = g_strdup(g_hash_table_lookup(data, QQ_ROOM_KEY_TITLE_UTF8)); 174 group->title_utf8 = g_strdup(g_hash_table_lookup(data, QQ_ROOM_KEY_TITLE_UTF8));
169 group->desc_utf8 = g_strdup(g_hash_table_lookup(data, QQ_ROOM_KEY_DESC_UTF8)); 175 group->desc_utf8 = g_strdup(g_hash_table_lookup(data, QQ_ROOM_KEY_DESC_UTF8));
170 group->my_role_desc = get_role_desc(group); 176 group->my_role_desc = get_role_desc(group);
171 group->is_got_info = FALSE; 177 group->is_got_buddies = FALSE;
172 178
179 purple_debug_info("QQ", "Created room info from hashtable: %s, %d, id %d\n",
180 group->title_utf8, group->ext_id, group->id);
173 qd->groups = g_list_append(qd->groups, group); 181 qd->groups = g_list_append(qd->groups, group);
174 return group; 182 return group;
175 } 183 }
176 184
177 /* refresh group local subscription */ 185 /* refresh group local subscription */
220 g_hash_table_replace(chat->components, 228 g_hash_table_replace(chat->components,
221 g_strdup(QQ_ROOM_KEY_TITLE_UTF8), g_strdup(group->title_utf8)); 229 g_strdup(QQ_ROOM_KEY_TITLE_UTF8), g_strdup(group->title_utf8));
222 g_hash_table_replace(chat->components, 230 g_hash_table_replace(chat->components,
223 g_strdup(QQ_ROOM_KEY_DESC_UTF8), g_strdup(group->desc_utf8)); 231 g_strdup(QQ_ROOM_KEY_DESC_UTF8), g_strdup(group->desc_utf8));
224 } 232 }
225
226 /* NOTE: If we knew how to convert between an external and internal group id, as the official
227 * client seems to, the following would be unnecessary. That would be ideal. */
228
229 /* Use list to specify if id's alternate id is pending discovery. */
230 void qq_set_pending_id(GSList **list, guint32 id, gboolean pending)
231 {
232 if (pending)
233 *list = g_slist_prepend(*list, GINT_TO_POINTER(id));
234 else
235 *list = g_slist_remove(*list, GINT_TO_POINTER(id));
236 }
237
238 /* Return the location of id in list, or NULL if not found */
239 GSList *qq_get_pending_id(GSList *list, guint32 id)
240 {
241 return g_slist_find(list, GINT_TO_POINTER(id));
242 }