comparison src/protocols/qq/group_hash.c @ 14021:ef8490f9e823

[gaim-migrate @ 16618] Replaced all C++-style comments with C-style ones. Cleaned up some comments and implemented a more consistent formatting scheme. committer: Tailor Script <tailor@pidgin.im>
author Mark Huetsch <markhuetsch>
date Wed, 02 Aug 2006 15:35:36 +0000
parents 983fd420e86b
children
comparison
equal deleted inserted replaced
14020:13e7ba964993 14021:ef8490f9e823
18 * You should have received a copy of the GNU General Public License 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 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 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */ 21 */
22 22
23 // START OF FILE 23 #include "blist.h"
24 /*****************************************************************************/ 24 #include "debug.h"
25 #include "blist.h" // gaim_blist_find_chat
26 #include "debug.h" // gaim_debug
27 25
28 #include "utils.h" // qq_string_to_dec_value 26 #include "buddy_opt.h"
29 #include "buddy_opt.h" // qq_get_gaim_group
30 #include "group_hash.h" 27 #include "group_hash.h"
31 #include "group_misc.h" // qq_group_get_auth_index_str 28 #include "group_misc.h"
29 #include "utils.h"
32 30
33 /*****************************************************************************/ 31 static gchar *_qq_group_set_my_status_desc(qq_group *group)
34 static gchar *_qq_group_set_my_status_desc(qq_group * group)
35 { 32 {
36 const char *status_desc; 33 const char *status_desc;
37 g_return_val_if_fail(group != NULL, g_strdup("")); 34 g_return_val_if_fail(group != NULL, g_strdup(""));
38 35
39 switch (group->my_status) { 36 switch (group->my_status) {
49 case QQ_GROUP_MEMBER_STATUS_IS_ADMIN: 46 case QQ_GROUP_MEMBER_STATUS_IS_ADMIN:
50 status_desc = _("I am the admin"); 47 status_desc = _("I am the admin");
51 break; 48 break;
52 default: 49 default:
53 status_desc = _("Unknown status"); 50 status_desc = _("Unknown status");
54 } // switch 51 }
55 52
56 return g_strdup(status_desc); 53 return g_strdup(status_desc);
57 } // _qq_group_set_my_status_desc 54 }
58 55
59 /*****************************************************************************/ 56 static void _qq_group_add_to_blist(GaimConnection *gc, qq_group *group)
60 static void _qq_group_add_to_blist(GaimConnection * gc, qq_group * group)
61 { 57 {
62 GHashTable *components; 58 GHashTable *components;
63 GaimGroup *g; 59 GaimGroup *g;
64 GaimChat *chat; 60 GaimChat *chat;
65 components = qq_group_to_hashtable(group); 61 components = qq_group_to_hashtable(group);
66 chat = gaim_chat_new(gaim_connection_get_account(gc), group->group_name_utf8, components); 62 chat = gaim_chat_new(gaim_connection_get_account(gc), group->group_name_utf8, components);
67 g = qq_get_gaim_group(GAIM_GROUP_QQ_QUN); 63 g = qq_get_gaim_group(GAIM_GROUP_QQ_QUN);
68 gaim_blist_add_chat(chat, g, NULL); 64 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); 65 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 66 }
71 67
72 /*****************************************************************************/ 68 /* create a dummy qq_group, which includes only internal_id and external_id
73 // create a dummy qq_group, which includes only internal_id and external_id 69 * all other attributes should be set to empty.
74 // all other attributes should be set to empty. 70 * and we need to send a get_group_info to QQ server to update it right away */
75 // and we need to send a get_group_info to QQ server to update it right away 71 qq_group *qq_group_create_by_id(GaimConnection *gc, guint32 internal_id, guint32 external_id)
76 qq_group *qq_group_create_by_id(GaimConnection * gc, guint32 internal_id, guint32 external_id) { 72 {
77 qq_group *group; 73 qq_group *group;
78 qq_data *qd; 74 qq_data *qd;
79 75
80 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, NULL); 76 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, NULL);
81 g_return_val_if_fail(internal_id > 0, NULL); 77 g_return_val_if_fail(internal_id > 0, NULL);
84 group = g_new0(qq_group, 1); 80 group = g_new0(qq_group, 1);
85 group->my_status = QQ_GROUP_MEMBER_STATUS_NOT_MEMBER; 81 group->my_status = QQ_GROUP_MEMBER_STATUS_NOT_MEMBER;
86 group->my_status_desc = _qq_group_set_my_status_desc(group); 82 group->my_status_desc = _qq_group_set_my_status_desc(group);
87 group->internal_group_id = internal_id; 83 group->internal_group_id = internal_id;
88 group->external_group_id = external_id; 84 group->external_group_id = external_id;
89 group->group_type = 0x01; // assume permanent Qun 85 group->group_type = 0x01; /* assume permanent Qun */
90 group->creator_uid = 10000; // assume by QQ admin 86 group->creator_uid = 10000; /* assume by QQ admin */
91 group->group_category = 0x01; 87 group->group_category = 0x01;
92 group->auth_type = 0x02; // assume need auth 88 group->auth_type = 0x02; /* assume need auth */
93 group->group_name_utf8 = g_strdup(""); 89 group->group_name_utf8 = g_strdup("");
94 group->group_desc_utf8 = g_strdup(""); 90 group->group_desc_utf8 = g_strdup("");
95 group->notice_utf8 = g_strdup(""); 91 group->notice_utf8 = g_strdup("");
96 group->members = NULL; 92 group->members = NULL;
97 93
98 qd->groups = g_list_append(qd->groups, group); 94 qd->groups = g_list_append(qd->groups, group);
99 _qq_group_add_to_blist(gc, group); 95 _qq_group_add_to_blist(gc, group);
100 96
101 return group; 97 return group;
102 } // qq_group_create_by_id 98 }
103 99
104 /*****************************************************************************/ 100 /* convert a qq_group to hash-table, which could be component of GaimChat */
105 // convert a qq_group to hash-table, which could be component of GaimChat 101 GHashTable *qq_group_to_hashtable(qq_group *group)
106 GHashTable *qq_group_to_hashtable(qq_group * group)
107 { 102 {
108 GHashTable *components; 103 GHashTable *components;
109 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); 104 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)); 105 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); 106 group->my_status_desc = _qq_group_set_my_status_desc(group);
121 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_AUTH_TYPE), g_strdup_printf("%d", group->auth_type)); 116 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)); 117 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)); 118 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)); 119 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_GROUP_DESC_UTF8), g_strdup(group->group_desc_utf8));
125 return components; 120 return components;
126 } // qq_group_to_hashtable 121 }
127 122
128 /*****************************************************************************/ 123 /* create a qq_group from hashtable */
129 // create a qq_group from hashtable 124 qq_group *qq_group_from_hashtable(GaimConnection *gc, GHashTable *data)
130 qq_group *qq_group_from_hashtable(GaimConnection * gc, GHashTable * data)
131 { 125 {
132 qq_data *qd; 126 qq_data *qd;
133 qq_group *group; 127 qq_group *group;
134 128
135 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, NULL); 129 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, NULL);
156 group->my_status_desc = _qq_group_set_my_status_desc(group); 150 group->my_status_desc = _qq_group_set_my_status_desc(group);
157 151
158 qd->groups = g_list_append(qd->groups, group); 152 qd->groups = g_list_append(qd->groups, group);
159 153
160 return group; 154 return group;
161 } // qq_group_from_hashtable 155 }
162 156
163 /*****************************************************************************/ 157 /* refresh group local subscription */
164 // refresh group local subscription 158 void qq_group_refresh(GaimConnection *gc, qq_group *group)
165 void qq_group_refresh(GaimConnection * gc, qq_group * group)
166 { 159 {
167 GaimChat *chat; 160 GaimChat *chat;
168 g_return_if_fail(gc != NULL && group != NULL); 161 g_return_if_fail(gc != NULL && group != NULL);
169 162
170 chat = gaim_blist_find_chat(gaim_connection_get_account(gc), g_strdup_printf("%d", group->external_group_id)); 163 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) 164 if (chat == NULL && group->my_status != QQ_GROUP_MEMBER_STATUS_NOT_MEMBER) {
172 _qq_group_add_to_blist(gc, group); 165 _qq_group_add_to_blist(gc, group);
173 else if (chat != NULL) { // we have a local record, update its info 166 } else if (chat != NULL) { /* we have a local record, update its info */
174 // if there is group_name_utf8, we update the group name 167 /* if there is group_name_utf8, we update the group name */
175 if (group->group_name_utf8 != NULL && strlen(group->group_name_utf8) > 0) 168 if (group->group_name_utf8 != NULL && strlen(group->group_name_utf8) > 0)
176 gaim_blist_alias_chat(chat, group->group_name_utf8); 169 gaim_blist_alias_chat(chat, group->group_name_utf8);
177 g_hash_table_replace(chat->components, 170 g_hash_table_replace(chat->components,
178 g_strdup(QQ_GROUP_KEY_MEMBER_STATUS), g_strdup_printf("%d", group->my_status)); 171 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); 172 group->my_status_desc = _qq_group_set_my_status_desc(group);
196 g_strdup(QQ_GROUP_KEY_AUTH_TYPE), g_strdup_printf("%d", group->auth_type)); 189 g_strdup(QQ_GROUP_KEY_AUTH_TYPE), g_strdup_printf("%d", group->auth_type));
197 g_hash_table_replace(chat->components, 190 g_hash_table_replace(chat->components,
198 g_strdup(QQ_GROUP_KEY_GROUP_NAME_UTF8), g_strdup(group->group_name_utf8)); 191 g_strdup(QQ_GROUP_KEY_GROUP_NAME_UTF8), g_strdup(group->group_name_utf8));
199 g_hash_table_replace(chat->components, 192 g_hash_table_replace(chat->components,
200 g_strdup(QQ_GROUP_KEY_GROUP_DESC_UTF8), g_strdup(group->group_desc_utf8)); 193 g_strdup(QQ_GROUP_KEY_GROUP_DESC_UTF8), g_strdup(group->group_desc_utf8));
201 } // if chat 194 }
202 } // qq_group_refresh 195 }
203
204 /*****************************************************************************/
205 // END OF FILE