| |
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 #include "internal.h" |
| |
24 |
| |
25 #include "debug.h" |
| |
26 #include "prpl.h" |
| |
27 #include "request.h" |
| |
28 |
| |
29 #include "group_hash.h" |
| |
30 #include "group_info.h" |
| |
31 #include "group_search.h" |
| |
32 #include "utils.h" |
| |
33 |
| |
34 #include "group.h" |
| |
35 |
| |
36 static void _qq_group_search_callback(GaimConnection *gc, const gchar *input) |
| |
37 { |
| |
38 guint32 external_group_id; |
| |
39 |
| |
40 g_return_if_fail(gc != NULL && input != NULL); |
| |
41 external_group_id = qq_string_to_dec_value(input); |
| |
42 /* 0x00000000 means search for demo group */ |
| |
43 qq_send_cmd_group_search_group(gc, external_group_id); |
| |
44 } |
| |
45 |
| |
46 /* This is needed for GaimChat node to be valid */ |
| |
47 GList *qq_chat_info(GaimConnection *gc) |
| |
48 { |
| |
49 GList *m; |
| |
50 struct proto_chat_entry *pce; |
| |
51 |
| |
52 m = NULL; |
| |
53 |
| |
54 pce = g_new0(struct proto_chat_entry, 1); |
| |
55 pce->label = _("ID: "); |
| |
56 pce->identifier = QQ_GROUP_KEY_EXTERNAL_ID; |
| |
57 m = g_list_append(m, pce); |
| |
58 |
| |
59 pce = g_new0(struct proto_chat_entry, 1); |
| |
60 pce->label = _("Admin: "); |
| |
61 pce->identifier = QQ_GROUP_KEY_CREATOR_UID; |
| |
62 m = g_list_append(m, pce); |
| |
63 |
| |
64 pce = g_new0(struct proto_chat_entry, 1); |
| |
65 pce->label = _("Status: "); |
| |
66 pce->identifier = QQ_GROUP_KEY_MEMBER_STATUS_DESC; |
| |
67 m = g_list_append(m, pce); |
| |
68 |
| |
69 return m; |
| |
70 } |
| |
71 |
| |
72 /* get a list of qq groups */ |
| |
73 GaimRoomlist *qq_roomlist_get_list(GaimConnection *gc) |
| |
74 { |
| |
75 GList *fields; |
| |
76 qq_data *qd; |
| |
77 GaimRoomlist *rl; |
| |
78 GaimRoomlistField *f; |
| |
79 |
| |
80 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, NULL); |
| |
81 qd = (qq_data *) gc->proto_data; |
| |
82 |
| |
83 fields = NULL; |
| |
84 rl = gaim_roomlist_new(gaim_connection_get_account(gc)); |
| |
85 qd->roomlist = rl; |
| |
86 |
| |
87 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, _("Group ID"), QQ_GROUP_KEY_EXTERNAL_ID, FALSE); |
| |
88 fields = g_list_append(fields, f); |
| |
89 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, _("Creator"), QQ_GROUP_KEY_CREATOR_UID, FALSE); |
| |
90 fields = g_list_append(fields, f); |
| |
91 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, |
| |
92 _("Group Description"), QQ_GROUP_KEY_GROUP_DESC_UTF8, FALSE); |
| |
93 fields = g_list_append(fields, f); |
| |
94 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, "", QQ_GROUP_KEY_INTERNAL_ID, TRUE); |
| |
95 fields = g_list_append(fields, f); |
| |
96 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, "", QQ_GROUP_KEY_GROUP_TYPE, TRUE); |
| |
97 fields = g_list_append(fields, f); |
| |
98 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, _("Auth"), QQ_GROUP_KEY_AUTH_TYPE, TRUE); |
| |
99 fields = g_list_append(fields, f); |
| |
100 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, "", QQ_GROUP_KEY_GROUP_CATEGORY, TRUE); |
| |
101 fields = g_list_append(fields, f); |
| |
102 f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, "", QQ_GROUP_KEY_GROUP_NAME_UTF8, TRUE); |
| |
103 |
| |
104 fields = g_list_append(fields, f); |
| |
105 gaim_roomlist_set_fields(rl, fields); |
| |
106 gaim_roomlist_set_in_progress(qd->roomlist, TRUE); |
| |
107 |
| |
108 gaim_request_input(gc, _("QQ Qun"), |
| |
109 _("Please input external group ID"), |
| |
110 _("You can only search for permanent QQ group\nInput 0 or leave it blank to search for demo groups"), |
| |
111 NULL, FALSE, FALSE, NULL, _("Search"), |
| |
112 G_CALLBACK(_qq_group_search_callback), _("Cancel"), NULL, gc); |
| |
113 |
| |
114 return qd->roomlist; |
| |
115 } |
| |
116 |
| |
117 /* free roomlist space, I have no idea when this one is called ... */ |
| |
118 void qq_roomlist_cancel(GaimRoomlist *list) |
| |
119 { |
| |
120 qq_data *qd; |
| |
121 GaimConnection *gc; |
| |
122 |
| |
123 g_return_if_fail(list != NULL); |
| |
124 gc = gaim_account_get_connection(list->account); |
| |
125 |
| |
126 g_return_if_fail(gc != NULL && gc->proto_data != NULL); |
| |
127 qd = (qq_data *) gc->proto_data; |
| |
128 |
| |
129 gaim_roomlist_set_in_progress(list, FALSE); |
| |
130 gaim_roomlist_unref(list); |
| |
131 } |
| |
132 |
| |
133 /* this should be called upon signin, even when we did not open group chat window */ |
| |
134 void qq_group_init(GaimConnection *gc) |
| |
135 { |
| |
136 gint i; |
| |
137 GaimAccount *account; |
| |
138 GaimChat *chat; |
| |
139 GaimGroup *gaim_group; |
| |
140 GaimBlistNode *node; |
| |
141 qq_group *group; |
| |
142 |
| |
143 g_return_if_fail(gc != NULL); |
| |
144 account = gaim_connection_get_account(gc); |
| |
145 |
| |
146 |
| |
147 gaim_group = gaim_find_group(GAIM_GROUP_QQ_QUN); |
| |
148 if (gaim_group == NULL) { |
| |
149 gaim_debug(GAIM_DEBUG_INFO, "QQ", "We have no QQ Qun\n"); |
| |
150 return; |
| |
151 } |
| |
152 |
| |
153 i = 0; |
| |
154 for (node = ((GaimBlistNode *) gaim_group)->child; node != NULL; node = node->next) |
| |
155 if (GAIM_BLIST_NODE_IS_CHAT(node)) { /* got one */ |
| |
156 chat = (GaimChat *) node; |
| |
157 if (account != chat->account) |
| |
158 continue; /* very important here ! */ |
| |
159 group = qq_group_from_hashtable(gc, chat->components); |
| |
160 if (group != NULL) { |
| |
161 i++; |
| |
162 qq_send_cmd_group_get_group_info(gc, group); /* get group info and members */ |
| |
163 } |
| |
164 } |
| |
165 |
| |
166 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Load %d QQ Qun configurations\n", i); |
| |
167 } |