Mercurial > pidgin.yaz
comparison src/protocols/qq/group_hash.c @ 13870:983fd420e86b
[gaim-migrate @ 16340]
Performed minor cleanup of the OpenQ codebase and patched it into the Gaim trunk as a prpl, providing basic QQ functionality.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Huetsch <markhuetsch> |
---|---|
date | Mon, 26 Jun 2006 02:58:54 +0000 |
parents | |
children | ef8490f9e823 |
comparison
equal
deleted
inserted
replaced
13869:5642f4658b59 | 13870:983fd420e86b |
---|---|
1 /** | |
2 * The QQ2003C protocol plugin | |
3 * | |
4 * for gaim | |
5 * | |
6 * Copyright (C) 2004 Puzzlebird | |
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 // START OF FILE | |
24 /*****************************************************************************/ | |
25 #include "blist.h" // gaim_blist_find_chat | |
26 #include "debug.h" // gaim_debug | |
27 | |
28 #include "utils.h" // qq_string_to_dec_value | |
29 #include "buddy_opt.h" // qq_get_gaim_group | |
30 #include "group_hash.h" | |
31 #include "group_misc.h" // qq_group_get_auth_index_str | |
32 | |
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 } // switch | |
55 | |
56 return g_strdup(status_desc); | |
57 } // _qq_group_set_my_status_desc | |
58 | |
59 /*****************************************************************************/ | |
60 static void _qq_group_add_to_blist(GaimConnection * gc, qq_group * group) | |
61 { | |
62 GHashTable *components; | |
63 GaimGroup *g; | |
64 GaimChat *chat; | |
65 components = qq_group_to_hashtable(group); | |
66 chat = gaim_chat_new(gaim_connection_get_account(gc), group->group_name_utf8, components); | |
67 g = qq_get_gaim_group(GAIM_GROUP_QQ_QUN); | |
68 gaim_blist_add_chat(chat, g, NULL); | |
69 gaim_debug(GAIM_DEBUG_INFO, "QQ", "You have add group \"%s\" to blist locally\n", group->group_name_utf8); | |
70 } // _qq_group_add_to_blist | |
71 | |
72 /*****************************************************************************/ | |
73 // create a dummy qq_group, which includes only internal_id and external_id | |
74 // all other attributes should be set to empty. | |
75 // and we need to send a get_group_info to QQ server to update it right away | |
76 qq_group *qq_group_create_by_id(GaimConnection * gc, guint32 internal_id, guint32 external_id) { | |
77 qq_group *group; | |
78 qq_data *qd; | |
79 | |
80 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, NULL); | |
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(""); | |
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 } // qq_group_create_by_id | |
103 | |
104 /*****************************************************************************/ | |
105 // convert a qq_group to hash-table, which could be component of GaimChat | |
106 GHashTable *qq_group_to_hashtable(qq_group * group) | |
107 { | |
108 GHashTable *components; | |
109 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); | |
110 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_MEMBER_STATUS), g_strdup_printf("%d", group->my_status)); | |
111 group->my_status_desc = _qq_group_set_my_status_desc(group); | |
112 | |
113 g_hash_table_insert(components, | |
114 g_strdup(QQ_GROUP_KEY_INTERNAL_ID), g_strdup_printf("%d", group->internal_group_id)); | |
115 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_EXTERNAL_ID), | |
116 g_strdup_printf("%d", group->external_group_id)); | |
117 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_GROUP_TYPE), g_strdup_printf("%d", group->group_type)); | |
118 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_CREATOR_UID), g_strdup_printf("%d", group->creator_uid)); | |
119 g_hash_table_insert(components, | |
120 g_strdup(QQ_GROUP_KEY_GROUP_CATEGORY), g_strdup_printf("%d", group->group_category)); | |
121 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_AUTH_TYPE), g_strdup_printf("%d", group->auth_type)); | |
122 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_MEMBER_STATUS_DESC), g_strdup(group->my_status_desc)); | |
123 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_GROUP_NAME_UTF8), g_strdup(group->group_name_utf8)); | |
124 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_GROUP_DESC_UTF8), g_strdup(group->group_desc_utf8)); | |
125 return components; | |
126 } // qq_group_to_hashtable | |
127 | |
128 /*****************************************************************************/ | |
129 // create a qq_group from hashtable | |
130 qq_group *qq_group_from_hashtable(GaimConnection * gc, GHashTable * data) | |
131 { | |
132 qq_data *qd; | |
133 qq_group *group; | |
134 | |
135 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, NULL); | |
136 g_return_val_if_fail(data != NULL, NULL); | |
137 qd = (qq_data *) gc->proto_data; | |
138 | |
139 group = g_new0(qq_group, 1); | |
140 group->my_status = | |
141 qq_string_to_dec_value | |
142 (NULL == | |
143 g_hash_table_lookup(data, | |
144 QQ_GROUP_KEY_MEMBER_STATUS) ? | |
145 g_strdup_printf("%d", | |
146 QQ_GROUP_MEMBER_STATUS_NOT_MEMBER) : | |
147 g_hash_table_lookup(data, QQ_GROUP_KEY_MEMBER_STATUS)); | |
148 group->internal_group_id = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_GROUP_KEY_INTERNAL_ID)); | |
149 group->external_group_id = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_GROUP_KEY_EXTERNAL_ID)); | |
150 group->group_type = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_GROUP_KEY_GROUP_TYPE)); | |
151 group->creator_uid = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_GROUP_KEY_CREATOR_UID)); | |
152 group->group_category = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_GROUP_KEY_GROUP_CATEGORY)); | |
153 group->auth_type = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_GROUP_KEY_AUTH_TYPE)); | |
154 group->group_name_utf8 = g_strdup(g_hash_table_lookup(data, QQ_GROUP_KEY_GROUP_NAME_UTF8)); | |
155 group->group_desc_utf8 = g_strdup(g_hash_table_lookup(data, QQ_GROUP_KEY_GROUP_DESC_UTF8)); | |
156 group->my_status_desc = _qq_group_set_my_status_desc(group); | |
157 | |
158 qd->groups = g_list_append(qd->groups, group); | |
159 | |
160 return group; | |
161 } // qq_group_from_hashtable | |
162 | |
163 /*****************************************************************************/ | |
164 // refresh group local subscription | |
165 void qq_group_refresh(GaimConnection * gc, qq_group * group) | |
166 { | |
167 GaimChat *chat; | |
168 g_return_if_fail(gc != NULL && group != NULL); | |
169 | |
170 chat = gaim_blist_find_chat(gaim_connection_get_account(gc), g_strdup_printf("%d", group->external_group_id)); | |
171 if (chat == NULL && group->my_status != QQ_GROUP_MEMBER_STATUS_NOT_MEMBER) | |
172 _qq_group_add_to_blist(gc, group); | |
173 else if (chat != NULL) { // we have a local record, update its info | |
174 // if there is group_name_utf8, we update the group name | |
175 if (group->group_name_utf8 != NULL && strlen(group->group_name_utf8) > 0) | |
176 gaim_blist_alias_chat(chat, group->group_name_utf8); | |
177 g_hash_table_replace(chat->components, | |
178 g_strdup(QQ_GROUP_KEY_MEMBER_STATUS), g_strdup_printf("%d", group->my_status)); | |
179 group->my_status_desc = _qq_group_set_my_status_desc(group); | |
180 g_hash_table_replace(chat->components, | |
181 g_strdup(QQ_GROUP_KEY_MEMBER_STATUS_DESC), g_strdup(group->my_status_desc)); | |
182 g_hash_table_replace(chat->components, | |
183 g_strdup(QQ_GROUP_KEY_INTERNAL_ID), | |
184 g_strdup_printf("%d", group->internal_group_id)); | |
185 g_hash_table_replace(chat->components, | |
186 g_strdup(QQ_GROUP_KEY_EXTERNAL_ID), | |
187 g_strdup_printf("%d", group->external_group_id)); | |
188 g_hash_table_replace(chat->components, | |
189 g_strdup(QQ_GROUP_KEY_GROUP_TYPE), g_strdup_printf("%d", group->group_type)); | |
190 g_hash_table_replace(chat->components, | |
191 g_strdup(QQ_GROUP_KEY_CREATOR_UID), g_strdup_printf("%d", group->creator_uid)); | |
192 g_hash_table_replace(chat->components, | |
193 g_strdup(QQ_GROUP_KEY_GROUP_CATEGORY), | |
194 g_strdup_printf("%d", group->group_category)); | |
195 g_hash_table_replace(chat->components, | |
196 g_strdup(QQ_GROUP_KEY_AUTH_TYPE), g_strdup_printf("%d", group->auth_type)); | |
197 g_hash_table_replace(chat->components, | |
198 g_strdup(QQ_GROUP_KEY_GROUP_NAME_UTF8), g_strdup(group->group_name_utf8)); | |
199 g_hash_table_replace(chat->components, | |
200 g_strdup(QQ_GROUP_KEY_GROUP_DESC_UTF8), g_strdup(group->group_desc_utf8)); | |
201 } // if chat | |
202 } // qq_group_refresh | |
203 | |
204 /*****************************************************************************/ | |
205 // END OF FILE |