13870
|
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
|
14021
|
23 #include "blist.h"
|
|
24 #include "debug.h"
|
13870
|
25
|
14021
|
26 #include "buddy_opt.h"
|
13870
|
27 #include "group_hash.h"
|
14021
|
28 #include "group_misc.h"
|
|
29 #include "utils.h"
|
13870
|
30
|
14021
|
31 static gchar *_qq_group_set_my_status_desc(qq_group *group)
|
13870
|
32 {
|
|
33 const char *status_desc;
|
|
34 g_return_val_if_fail(group != NULL, g_strdup(""));
|
|
35
|
|
36 switch (group->my_status) {
|
|
37 case QQ_GROUP_MEMBER_STATUS_NOT_MEMBER:
|
|
38 status_desc = _("I am not member");
|
|
39 break;
|
|
40 case QQ_GROUP_MEMBER_STATUS_IS_MEMBER:
|
|
41 status_desc = _("I am a member");
|
|
42 break;
|
|
43 case QQ_GROUP_MEMBER_STATUS_APPLYING:
|
|
44 status_desc = _("I am applying to join");
|
|
45 break;
|
|
46 case QQ_GROUP_MEMBER_STATUS_IS_ADMIN:
|
|
47 status_desc = _("I am the admin");
|
|
48 break;
|
|
49 default:
|
|
50 status_desc = _("Unknown status");
|
14021
|
51 }
|
13870
|
52
|
|
53 return g_strdup(status_desc);
|
14021
|
54 }
|
13870
|
55
|
14021
|
56 static void _qq_group_add_to_blist(GaimConnection *gc, qq_group *group)
|
13870
|
57 {
|
|
58 GHashTable *components;
|
|
59 GaimGroup *g;
|
|
60 GaimChat *chat;
|
|
61 components = qq_group_to_hashtable(group);
|
|
62 chat = gaim_chat_new(gaim_connection_get_account(gc), group->group_name_utf8, components);
|
|
63 g = qq_get_gaim_group(GAIM_GROUP_QQ_QUN);
|
|
64 gaim_blist_add_chat(chat, g, NULL);
|
|
65 gaim_debug(GAIM_DEBUG_INFO, "QQ", "You have add group \"%s\" to blist locally\n", group->group_name_utf8);
|
14021
|
66 }
|
13870
|
67
|
14021
|
68 /* create a dummy qq_group, which includes only internal_id and external_id
|
|
69 * 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 */
|
|
71 qq_group *qq_group_create_by_id(GaimConnection *gc, guint32 internal_id, guint32 external_id)
|
|
72 {
|
13870
|
73 qq_group *group;
|
|
74 qq_data *qd;
|
|
75
|
|
76 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, NULL);
|
|
77 g_return_val_if_fail(internal_id > 0, NULL);
|
|
78 qd = (qq_data *) gc->proto_data;
|
|
79
|
|
80 group = g_new0(qq_group, 1);
|
|
81 group->my_status = QQ_GROUP_MEMBER_STATUS_NOT_MEMBER;
|
|
82 group->my_status_desc = _qq_group_set_my_status_desc(group);
|
|
83 group->internal_group_id = internal_id;
|
|
84 group->external_group_id = external_id;
|
14021
|
85 group->group_type = 0x01; /* assume permanent Qun */
|
|
86 group->creator_uid = 10000; /* assume by QQ admin */
|
13870
|
87 group->group_category = 0x01;
|
14021
|
88 group->auth_type = 0x02; /* assume need auth */
|
13870
|
89 group->group_name_utf8 = g_strdup("");
|
|
90 group->group_desc_utf8 = g_strdup("");
|
|
91 group->notice_utf8 = g_strdup("");
|
|
92 group->members = NULL;
|
|
93
|
|
94 qd->groups = g_list_append(qd->groups, group);
|
|
95 _qq_group_add_to_blist(gc, group);
|
|
96
|
|
97 return group;
|
14021
|
98 }
|
13870
|
99
|
14021
|
100 /* convert a qq_group to hash-table, which could be component of GaimChat */
|
|
101 GHashTable *qq_group_to_hashtable(qq_group *group)
|
13870
|
102 {
|
|
103 GHashTable *components;
|
|
104 components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
|
105 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_MEMBER_STATUS), g_strdup_printf("%d", group->my_status));
|
|
106 group->my_status_desc = _qq_group_set_my_status_desc(group);
|
|
107
|
|
108 g_hash_table_insert(components,
|
|
109 g_strdup(QQ_GROUP_KEY_INTERNAL_ID), g_strdup_printf("%d", group->internal_group_id));
|
|
110 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_EXTERNAL_ID),
|
|
111 g_strdup_printf("%d", group->external_group_id));
|
|
112 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_GROUP_TYPE), g_strdup_printf("%d", group->group_type));
|
|
113 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_CREATOR_UID), g_strdup_printf("%d", group->creator_uid));
|
|
114 g_hash_table_insert(components,
|
|
115 g_strdup(QQ_GROUP_KEY_GROUP_CATEGORY), g_strdup_printf("%d", group->group_category));
|
|
116 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_AUTH_TYPE), g_strdup_printf("%d", group->auth_type));
|
|
117 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_MEMBER_STATUS_DESC), g_strdup(group->my_status_desc));
|
|
118 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_GROUP_NAME_UTF8), g_strdup(group->group_name_utf8));
|
|
119 g_hash_table_insert(components, g_strdup(QQ_GROUP_KEY_GROUP_DESC_UTF8), g_strdup(group->group_desc_utf8));
|
|
120 return components;
|
14021
|
121 }
|
13870
|
122
|
14021
|
123 /* create a qq_group from hashtable */
|
|
124 qq_group *qq_group_from_hashtable(GaimConnection *gc, GHashTable *data)
|
13870
|
125 {
|
|
126 qq_data *qd;
|
|
127 qq_group *group;
|
|
128
|
|
129 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, NULL);
|
|
130 g_return_val_if_fail(data != NULL, NULL);
|
|
131 qd = (qq_data *) gc->proto_data;
|
|
132
|
|
133 group = g_new0(qq_group, 1);
|
|
134 group->my_status =
|
|
135 qq_string_to_dec_value
|
|
136 (NULL ==
|
|
137 g_hash_table_lookup(data,
|
|
138 QQ_GROUP_KEY_MEMBER_STATUS) ?
|
|
139 g_strdup_printf("%d",
|
|
140 QQ_GROUP_MEMBER_STATUS_NOT_MEMBER) :
|
|
141 g_hash_table_lookup(data, QQ_GROUP_KEY_MEMBER_STATUS));
|
|
142 group->internal_group_id = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_GROUP_KEY_INTERNAL_ID));
|
|
143 group->external_group_id = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_GROUP_KEY_EXTERNAL_ID));
|
|
144 group->group_type = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_GROUP_KEY_GROUP_TYPE));
|
|
145 group->creator_uid = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_GROUP_KEY_CREATOR_UID));
|
|
146 group->group_category = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_GROUP_KEY_GROUP_CATEGORY));
|
|
147 group->auth_type = qq_string_to_dec_value(g_hash_table_lookup(data, QQ_GROUP_KEY_AUTH_TYPE));
|
|
148 group->group_name_utf8 = g_strdup(g_hash_table_lookup(data, QQ_GROUP_KEY_GROUP_NAME_UTF8));
|
|
149 group->group_desc_utf8 = g_strdup(g_hash_table_lookup(data, QQ_GROUP_KEY_GROUP_DESC_UTF8));
|
|
150 group->my_status_desc = _qq_group_set_my_status_desc(group);
|
|
151
|
|
152 qd->groups = g_list_append(qd->groups, group);
|
|
153
|
|
154 return group;
|
14021
|
155 }
|
13870
|
156
|
14021
|
157 /* refresh group local subscription */
|
|
158 void qq_group_refresh(GaimConnection *gc, qq_group *group)
|
13870
|
159 {
|
|
160 GaimChat *chat;
|
|
161 g_return_if_fail(gc != NULL && group != NULL);
|
|
162
|
|
163 chat = gaim_blist_find_chat(gaim_connection_get_account(gc), g_strdup_printf("%d", group->external_group_id));
|
14021
|
164 if (chat == NULL && group->my_status != QQ_GROUP_MEMBER_STATUS_NOT_MEMBER) {
|
13870
|
165 _qq_group_add_to_blist(gc, group);
|
14021
|
166 } else if (chat != NULL) { /* we have a local record, update its info */
|
|
167 /* if there is group_name_utf8, we update the group name */
|
13870
|
168 if (group->group_name_utf8 != NULL && strlen(group->group_name_utf8) > 0)
|
|
169 gaim_blist_alias_chat(chat, group->group_name_utf8);
|
|
170 g_hash_table_replace(chat->components,
|
|
171 g_strdup(QQ_GROUP_KEY_MEMBER_STATUS), g_strdup_printf("%d", group->my_status));
|
|
172 group->my_status_desc = _qq_group_set_my_status_desc(group);
|
|
173 g_hash_table_replace(chat->components,
|
|
174 g_strdup(QQ_GROUP_KEY_MEMBER_STATUS_DESC), g_strdup(group->my_status_desc));
|
|
175 g_hash_table_replace(chat->components,
|
|
176 g_strdup(QQ_GROUP_KEY_INTERNAL_ID),
|
|
177 g_strdup_printf("%d", group->internal_group_id));
|
|
178 g_hash_table_replace(chat->components,
|
|
179 g_strdup(QQ_GROUP_KEY_EXTERNAL_ID),
|
|
180 g_strdup_printf("%d", group->external_group_id));
|
|
181 g_hash_table_replace(chat->components,
|
|
182 g_strdup(QQ_GROUP_KEY_GROUP_TYPE), g_strdup_printf("%d", group->group_type));
|
|
183 g_hash_table_replace(chat->components,
|
|
184 g_strdup(QQ_GROUP_KEY_CREATOR_UID), g_strdup_printf("%d", group->creator_uid));
|
|
185 g_hash_table_replace(chat->components,
|
|
186 g_strdup(QQ_GROUP_KEY_GROUP_CATEGORY),
|
|
187 g_strdup_printf("%d", group->group_category));
|
|
188 g_hash_table_replace(chat->components,
|
|
189 g_strdup(QQ_GROUP_KEY_AUTH_TYPE), g_strdup_printf("%d", group->auth_type));
|
|
190 g_hash_table_replace(chat->components,
|
|
191 g_strdup(QQ_GROUP_KEY_GROUP_NAME_UTF8), g_strdup(group->group_name_utf8));
|
|
192 g_hash_table_replace(chat->components,
|
|
193 g_strdup(QQ_GROUP_KEY_GROUP_DESC_UTF8), g_strdup(group->group_desc_utf8));
|
14021
|
194 }
|
|
195 }
|