Mercurial > pidgin
annotate libgaim/protocols/qq/qq.c @ 15123:c8957b9c6202
[gaim-migrate @ 17909]
fix 1586525
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Thu, 07 Dec 2006 05:57:53 +0000 |
parents | 2c93b0620065 |
children | e952a5fc97b3 |
rev | line source |
---|---|
14192 | 1 /** |
15025 | 2 * @file qq.c |
14192 | 3 * |
4 * gaim | |
5 * | |
15025 | 6 * Gaim is the legal property of its developers, whose names are too numerous |
7 * to list here. Please refer to the COPYRIGHT file distributed with this | |
8 * source distribution. | |
14192 | 9 * |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; if not, write to the Free Software | |
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
23 */ | |
24 | |
25 #include "internal.h" | |
26 | |
27 #ifdef _WIN32 | |
28 #define random rand | |
29 #endif | |
30 | |
31 #include "accountopt.h" | |
32 #include "debug.h" | |
33 #include "notify.h" | |
34 #include "prefs.h" | |
35 #include "prpl.h" | |
36 #include "request.h" | |
37 #include "roomlist.h" | |
38 #include "server.h" | |
39 #include "util.h" | |
40 | |
41 #include "buddy_info.h" | |
42 #include "buddy_opt.h" | |
43 #include "buddy_status.h" | |
44 #include "char_conv.h" | |
14237 | 45 #include "crypt.h" |
14192 | 46 #include "group.h" |
47 #include "group_find.h" | |
48 #include "group_im.h" | |
49 #include "group_info.h" | |
50 #include "group_join.h" | |
51 #include "group_opt.h" | |
52 #include "header_info.h" | |
53 #include "im.h" | |
54 #include "keep_alive.h" | |
55 #include "login_logout.h" | |
56 #include "packet_parse.h" | |
57 #include "qq.h" | |
58 #include "qq_proxy.h" | |
59 #include "send_core.h" | |
60 #include "send_file.h" | |
61 #include "utils.h" | |
62 #include "version.h" | |
63 | |
64 #define OPENQ_AUTHOR "Puzzlebird" | |
65 #define OPENQ_WEBSITE "http://openq.sourceforge.net" | |
66 #define QQ_TCP_QUERY_PORT "8000" | |
67 #define QQ_UDP_PORT "8000" | |
68 | |
69 const gchar *udp_server_list[] = { | |
14195 | 70 "sz.tencent.com", |
71 "sz2.tencent.com", | |
72 "sz3.tencent.com", | |
73 "sz4.tencent.com", | |
74 "sz5.tencent.com", | |
75 "sz6.tencent.com", | |
76 "sz7.tencent.com", | |
77 "sz8.tencent.com", | |
78 "sz9.tencent.com" | |
14192 | 79 }; |
80 const gint udp_server_amount = (sizeof(udp_server_list) / sizeof(udp_server_list[0])); | |
81 | |
82 | |
83 const gchar *tcp_server_list[] = { | |
14195 | 84 "tcpconn.tencent.com", |
85 "tcpconn2.tencent.com", | |
86 "tcpconn3.tencent.com", | |
87 "tcpconn4.tencent.com", | |
88 "tcpconn5.tencent.com", | |
89 "tcpconn6.tencent.com" | |
14192 | 90 }; |
91 const gint tcp_server_amount = (sizeof(tcp_server_list) / sizeof(tcp_server_list[0])); | |
92 | |
93 static void _qq_login(GaimAccount *account) | |
94 { | |
95 const gchar *qq_server, *qq_port; | |
96 qq_data *qd; | |
97 GaimConnection *gc; | |
15075
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
98 GaimPresence *presence; |
14318 | 99 gboolean use_tcp; |
14192 | 100 |
101 g_return_if_fail(account != NULL); | |
102 | |
103 gc = gaim_account_get_connection(account); | |
104 g_return_if_fail(gc != NULL); | |
105 | |
106 gc->flags |= GAIM_CONNECTION_HTML | GAIM_CONNECTION_NO_BGCOLOR | GAIM_CONNECTION_AUTO_RESP; | |
107 | |
108 qd = g_new0(qq_data, 1); | |
14195 | 109 qd->gc = gc; |
14192 | 110 gc->proto_data = qd; |
111 | |
112 qq_server = gaim_account_get_string(account, "server", NULL); | |
113 qq_port = gaim_account_get_string(account, "port", NULL); | |
114 use_tcp = gaim_account_get_bool(account, "use_tcp", FALSE); | |
15075
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
115 presence = gaim_account_get_presence(account); |
14192 | 116 |
117 qd->use_tcp = use_tcp; | |
118 | |
14318 | 119 if(gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_INVISIBLE)) { |
14192 | 120 qd->login_mode = QQ_LOGIN_MODE_HIDDEN; |
14318 | 121 } else if(gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_AWAY) |
122 || gaim_presence_is_status_primitive_active(presence, GAIM_STATUS_EXTENDED_AWAY)) { | |
123 qd->login_mode = QQ_LOGIN_MODE_AWAY; | |
14192 | 124 } else { |
125 qd->login_mode = QQ_LOGIN_MODE_NORMAL; | |
126 } | |
127 | |
128 if (qq_server == NULL || strlen(qq_server) == 0) | |
129 qq_server = use_tcp ? | |
15075
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
130 tcp_server_list[random() % tcp_server_amount] : |
14195 | 131 udp_server_list[random() % udp_server_amount]; |
14192 | 132 |
133 if (qq_port == NULL || strtol(qq_port, NULL, 10) == 0) | |
134 qq_port = use_tcp ? QQ_TCP_QUERY_PORT : QQ_UDP_PORT; | |
135 | |
136 gaim_connection_update_progress(gc, _("Connecting"), 0, QQ_CONNECT_STEPS); | |
15075
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
137 |
14192 | 138 if (qq_connect(account, qq_server, strtol(qq_port, NULL, 10), use_tcp, FALSE) < 0) |
139 gaim_connection_error(gc, _("Unable to connect.")); | |
140 } | |
141 | |
142 /* directly goes for qq_disconnect */ | |
143 static void _qq_close(GaimConnection *gc) | |
144 { | |
145 g_return_if_fail(gc != NULL); | |
146 qq_disconnect(gc); | |
147 } | |
148 | |
149 /* returns the icon name for a buddy or protocol */ | |
150 static const gchar *_qq_list_icon(GaimAccount *a, GaimBuddy *b) | |
151 { | |
15071 | 152 return "qq"; |
14192 | 153 } |
154 | |
155 | |
156 /* a short status text beside buddy icon*/ | |
157 static gchar *_qq_status_text(GaimBuddy *b) | |
158 { | |
159 qq_buddy *q_bud; | |
160 GString *status; | |
161 | |
162 q_bud = (qq_buddy *) b->proto_data; | |
163 if (q_bud == NULL) | |
164 return NULL; | |
165 | |
166 status = g_string_new(""); | |
167 | |
168 switch(q_bud->status) { | |
169 case QQ_BUDDY_OFFLINE: | |
14268 | 170 g_string_append(status, "Offline"); |
14192 | 171 break; |
172 case QQ_BUDDY_ONLINE_NORMAL: | |
173 return NULL; | |
174 break; | |
14268 | 175 /* TODO What does this status mean? Labelling it as offline... */ |
14192 | 176 case QQ_BUDDY_ONLINE_OFFLINE: |
14268 | 177 g_string_append(status, "Offline"); |
14192 | 178 break; |
179 case QQ_BUDDY_ONLINE_AWAY: | |
180 g_string_append(status, "Away"); | |
181 break; | |
182 case QQ_BUDDY_ONLINE_INVISIBLE: | |
183 g_string_append(status, "Invisible"); | |
184 break; | |
185 default: | |
186 g_string_printf(status, "Unknown-%d", q_bud->status); | |
15075
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
187 } |
14192 | 188 |
14497
ae0f94b7f396
[gaim-migrate @ 17216]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
14404
diff
changeset
|
189 return g_string_free(status, FALSE); |
14192 | 190 } |
191 | |
192 | |
193 /* a floating text when mouse is on the icon, show connection status here */ | |
194 static void _qq_tooltip_text(GaimBuddy *b, GString *tooltip, gboolean full) | |
195 { | |
196 qq_buddy *q_bud; | |
197 gchar *ip_str; | |
198 | |
199 g_return_if_fail(b != NULL); | |
200 | |
201 q_bud = (qq_buddy *) b->proto_data; | |
14268 | 202 g_return_if_fail(q_bud != NULL); |
14192 | 203 |
204 if (GAIM_BUDDY_IS_ONLINE(b) && q_bud != NULL) | |
205 { | |
206 ip_str = gen_ip_str(q_bud->ip); | |
207 if (strlen(ip_str) != 0) { | |
15075
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
208 g_string_append_printf(tooltip, "\n<b>%s Address:</b> %s:%d", |
14192 | 209 (q_bud->comm_flag & QQ_COMM_FLAG_TCP_MODE) |
210 ? "TCP" : "UDP", ip_str, q_bud->port); | |
211 } | |
212 g_free(ip_str); | |
213 g_string_append_printf(tooltip, "\n<b>Age:</b> %d", q_bud->age); | |
15075
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
214 switch (q_bud->gender) { |
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
215 case QQ_BUDDY_GENDER_GG: |
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
216 g_string_append(tooltip, "\n<b>Gender:</b> Male"); |
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
217 break; |
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
218 case QQ_BUDDY_GENDER_MM: |
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
219 g_string_append(tooltip, "\n<b>Gender:</b> Female"); |
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
220 break; |
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
221 case QQ_BUDDY_GENDER_UNKNOWN: |
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
222 g_string_append(tooltip, "\n<b>Gender:</b> Unknown"); |
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
223 break; |
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
224 default: |
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
225 g_string_append_printf(tooltip, "\n<b>Gender:</b> ERROR(%d)", q_bud->gender); |
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
226 } |
14268 | 227 /* For debugging */ |
228 /* | |
14192 | 229 g_string_append_printf(tooltip, "\n<b>Flag:</b> %01x", q_bud->flag1); |
230 g_string_append_printf(tooltip, "\n<b>CommFlag:</b> %01x", q_bud->comm_flag); | |
15075
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
231 g_string_append_printf(tooltip, "\n<b>Client:</b> %04x", q_bud->client_version); |
14268 | 232 */ |
14192 | 233 } |
234 } | |
235 | |
236 /* we can show tiny icons on the four corners of buddy icon, */ | |
237 static void _qq_list_emblems(GaimBuddy *b, const char **se, const char **sw, const char **nw, const char **ne) | |
238 { | |
15071 | 239 /* each char** are refering to a filename in pixmaps/gaim/status/default/ */ |
14192 | 240 |
241 qq_buddy *q_bud = b->proto_data; | |
15075
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
242 const char *emblems[4] = { NULL, NULL, NULL, NULL }; |
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
243 int i = 1; |
14192 | 244 |
15075
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
245 if (q_bud == NULL) { |
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
246 emblems[0] = "offline"; |
14192 | 247 } else { |
14318 | 248 if (q_bud->status == QQ_BUDDY_ONLINE_AWAY) |
14265 | 249 emblems[i++] = "away"; |
15072 | 250 /* |
14192 | 251 if (q_bud->comm_flag & QQ_COMM_FLAG_QQ_MEMBER) |
252 emblems[i++] = "qq_member"; | |
15072 | 253 */ |
15075
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
254 if (q_bud->comm_flag & QQ_COMM_FLAG_BIND_MOBILE) |
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
255 emblems[i++] = "wireless"; |
15072 | 256 /* |
14192 | 257 if (q_bud->comm_flag & QQ_COMM_FLAG_VIDEO) |
14265 | 258 emblems[i%4] = "video"; |
15072 | 259 */ |
14192 | 260 |
15075
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
261 } |
14192 | 262 |
15075
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
263 *se = emblems[0]; |
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
264 *sw = emblems[1]; |
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
265 *nw = emblems[2]; |
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
266 *ne = emblems[3]; |
14192 | 267 |
268 return; | |
269 } | |
270 | |
271 /* QQ away status (used to initiate QQ away packet) */ | |
15075
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
272 static GList *_qq_away_states(GaimAccount *ga) |
14192 | 273 { |
274 GaimStatusType *status; | |
275 GList *types = NULL; | |
276 | |
277 status = gaim_status_type_new_full(GAIM_STATUS_AVAILABLE, | |
278 "available", _("QQ: Available"), FALSE, TRUE, FALSE); | |
279 types = g_list_append(types, status); | |
280 | |
15075
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
281 status = gaim_status_type_new_full(GAIM_STATUS_AWAY, |
14192 | 282 "away", _("QQ: Away"), FALSE, TRUE, FALSE); |
15075
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
283 types = g_list_append(types, status); |
14192 | 284 |
15075
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
285 status = gaim_status_type_new_full(GAIM_STATUS_INVISIBLE, |
14192 | 286 "invisible", _("QQ: Invisible"), FALSE, TRUE, FALSE); |
15075
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
287 types = g_list_append(types, status); |
14192 | 288 |
289 status = gaim_status_type_new_full(GAIM_STATUS_OFFLINE, | |
15075
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
290 "offline", _("QQ: Offline"), FALSE, TRUE, FALSE); |
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
291 types = g_list_append(types, status); |
14192 | 292 |
293 return types; | |
294 } | |
295 | |
296 /* initiate QQ away with proper change_status packet */ | |
297 static void _qq_set_away(GaimAccount *account, GaimStatus *status) | |
298 { | |
299 GaimConnection *gc = gaim_account_get_connection(account); | |
300 | |
301 qq_send_packet_change_status(gc); | |
302 } | |
303 | |
304 /* IMPORTANT: GaimConvImFlags -> GaimMessageFlags */ | |
305 /* send an instant msg to a buddy */ | |
306 static gint _qq_send_im(GaimConnection *gc, const gchar *who, const gchar *message, GaimMessageFlags flags) | |
307 { | |
308 gint type, to_uid; | |
309 gchar *msg, *msg_with_qq_smiley; | |
310 qq_data *qd; | |
311 | |
14629 | 312 g_return_val_if_fail(who != NULL, -1); |
14192 | 313 |
314 qd = (qq_data *) gc->proto_data; | |
315 | |
316 g_return_val_if_fail(strlen(message) <= QQ_MSG_IM_MAX, -E2BIG); | |
317 | |
318 type = (flags == GAIM_MESSAGE_AUTO_RESP ? QQ_IM_AUTO_REPLY : QQ_IM_TEXT); | |
319 to_uid = gaim_name_to_uid(who); | |
320 | |
321 /* if msg is to myself, bypass the network */ | |
322 if (to_uid == qd->uid) { | |
323 serv_got_im(gc, who, message, flags, time(NULL)); | |
324 } else { | |
325 msg = utf8_to_qq(message, QQ_CHARSET_DEFAULT); | |
326 msg_with_qq_smiley = gaim_smiley_to_qq(msg); | |
327 qq_send_packet_im(gc, to_uid, msg_with_qq_smiley, type); | |
328 g_free(msg); | |
329 g_free(msg_with_qq_smiley); | |
330 } | |
331 | |
332 return 1; | |
333 } | |
334 | |
335 /* send a chat msg to a QQ Qun */ | |
336 static int _qq_chat_send(GaimConnection *gc, int channel, const char *message, GaimMessageFlags flags) | |
337 { | |
338 gchar *msg, *msg_with_qq_smiley; | |
339 qq_group *group; | |
340 | |
14629 | 341 g_return_val_if_fail(message != NULL, -1); |
14192 | 342 g_return_val_if_fail(strlen(message) <= QQ_MSG_IM_MAX, -E2BIG); |
343 | |
344 group = qq_group_find_by_channel(gc, channel); | |
345 g_return_val_if_fail(group != NULL, -1); | |
346 | |
347 msg = utf8_to_qq(message, QQ_CHARSET_DEFAULT); | |
348 msg_with_qq_smiley = gaim_smiley_to_qq(msg); | |
349 qq_send_packet_group_im(gc, group, msg_with_qq_smiley); | |
350 g_free(msg); | |
351 g_free(msg_with_qq_smiley); | |
352 | |
353 return 1; | |
354 } | |
355 | |
356 /* send packet to get who's detailed information */ | |
357 static void _qq_get_info(GaimConnection *gc, const gchar *who) | |
358 { | |
359 guint32 uid; | |
360 qq_data *qd; | |
361 | |
362 qd = gc->proto_data; | |
363 uid = gaim_name_to_uid(who); | |
364 | |
365 if (uid <= 0) { | |
366 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Not valid QQid: %s\n", who); | |
14319 | 367 gaim_notify_error(gc, NULL, _("Invalid name"), NULL); |
14192 | 368 return; |
369 } | |
370 | |
371 qq_send_packet_get_info(gc, uid, TRUE); | |
372 } | |
373 | |
374 /* get my own information */ | |
375 static void _qq_menu_modify_my_info(GaimPluginAction *action) | |
376 { | |
377 GaimConnection *gc = (GaimConnection *) action->context; | |
378 qq_data *qd; | |
379 | |
380 qd = (qq_data *) gc->proto_data; | |
381 qq_prepare_modify_info(gc); | |
382 } | |
383 | |
384 static void _qq_menu_change_password(GaimPluginAction *action) | |
385 { | |
386 gaim_notify_uri(NULL, "https://password.qq.com"); | |
387 } | |
388 | |
389 /* remove a buddy from my list and remove myself from his list */ | |
390 /* TODO: re-enable this | |
391 static void _qq_menu_block_buddy(GaimBlistNode * node) | |
392 { | |
393 guint32 uid; | |
394 gc_and_uid *g; | |
395 GaimBuddy *buddy; | |
396 GaimConnection *gc; | |
397 // const gchar *who = param_who; gfhuang | |
398 const gchar *who; | |
399 | |
400 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
401 | |
402 buddy = (GaimBuddy *) node; | |
403 gc = gaim_account_get_connection(buddy->account); | |
404 who = buddy->name; | |
14629 | 405 g_return_if_fail(who != NULL); |
14192 | 406 |
407 uid = gaim_name_to_uid(who); | |
408 g_return_if_fail(uid > 0); | |
409 | |
410 g = g_new0(gc_and_uid, 1); | |
411 g->gc = gc; | |
412 g->uid = uid; | |
413 | |
414 gaim_request_action(gc, _("Block Buddy"), | |
415 _("Are you sure to block this buddy?"), NULL, | |
416 1, g, 2, | |
417 _("Cancel"), | |
418 G_CALLBACK(qq_do_nothing_with_gc_and_uid), | |
419 _("Block"), G_CALLBACK(qq_block_buddy_with_gc_and_uid)); | |
420 } | |
421 */ | |
422 | |
423 /* show a brief summary of what we get from login packet */ | |
424 static void _qq_menu_show_login_info(GaimPluginAction *action) | |
425 { | |
426 GaimConnection *gc = (GaimConnection *) action->context; | |
427 qq_data *qd; | |
428 GString *info; | |
429 | |
430 qd = (qq_data *) gc->proto_data; | |
431 info = g_string_new("<html><body>\n"); | |
432 | |
433 g_string_append_printf(info, _("<b>Current Online</b>: %d<br>\n"), qd->all_online); | |
434 g_string_append_printf(info, _("<b>Last Refresh</b>: %s<br>\n"), ctime(&qd->last_get_online)); | |
435 | |
436 g_string_append(info, "<hr>\n"); | |
437 | |
438 g_string_append_printf(info, _("<b>Connection Mode</b>: %s<br>\n"), qd->use_tcp ? "TCP" : "UDP"); | |
439 g_string_append_printf(info, _("<b>Server IP</b>: %s: %d<br>\n"), qd->server_ip, qd->server_port); | |
440 g_string_append_printf(info, _("<b>My Public IP</b>: %s<br>\n"), qd->my_ip); | |
441 | |
442 g_string_append(info, "<hr>\n"); | |
15071 | 443 g_string_append(info, "<i>Information below may not be accurate</i><br>\n"); |
14192 | 444 |
445 g_string_append_printf(info, _("<b>Login Time</b>: %s<br>\n"), ctime(&qd->login_time)); | |
446 g_string_append_printf(info, _("<b>Last Login IP</b>: %s<br>\n"), qd->last_login_ip); | |
447 g_string_append_printf(info, _("<b>Last Login Time</b>: %s\n"), ctime(&qd->last_login_time)); | |
448 | |
449 g_string_append(info, "</body></html>"); | |
450 | |
451 gaim_notify_formatted(gc, NULL, _("Login Information"), NULL, info->str, NULL, NULL); | |
452 | |
453 g_string_free(info, TRUE); | |
454 } | |
455 | |
14242 | 456 /* |
14192 | 457 static void _qq_menu_search_or_add_permanent_group(GaimPluginAction *action) |
458 { | |
459 gaim_roomlist_show_with_account(NULL); | |
460 } | |
14242 | 461 */ |
14192 | 462 |
463 /* | |
464 static void _qq_menu_create_permanent_group(GaimPluginAction * action) | |
465 { | |
466 GaimConnection *gc = (GaimConnection *) action->context; | |
467 gaim_request_input(gc, _("Create QQ Qun"), | |
468 _("Input Qun name here"), | |
469 _("Only QQ member can create permanent Qun"), | |
470 "OpenQ", FALSE, FALSE, NULL, | |
471 _("Create"), G_CALLBACK(qq_group_create_with_name), _("Cancel"), NULL, gc); | |
472 } | |
473 */ | |
474 | |
475 static void _qq_menu_unsubscribe_group(GaimBlistNode * node) | |
476 { | |
477 GaimChat *chat = (GaimChat *)node; | |
478 GaimConnection *gc = gaim_account_get_connection(chat->account); | |
479 GHashTable *components = chat -> components; | |
480 | |
481 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node)); | |
482 | |
14629 | 483 g_return_if_fail(components != NULL); |
14192 | 484 qq_group_exit(gc, components); |
485 } | |
486 | |
14404 | 487 /* |
14192 | 488 static void _qq_menu_manage_group(GaimBlistNode * node) |
489 { | |
490 GaimChat *chat = (GaimChat *)node; | |
491 GaimConnection *gc = gaim_account_get_connection(chat->account); | |
492 GHashTable *components = chat -> components; | |
493 | |
494 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node)); | |
495 | |
14629 | 496 g_return_if_fail(components != NULL); |
14192 | 497 qq_group_manage_group(gc, components); |
498 } | |
499 */ | |
500 | |
501 /* TODO: re-enable this | |
502 static void _qq_menu_send_file(GaimBlistNode * node, gpointer ignored) | |
503 { | |
504 GaimBuddy *buddy; | |
505 GaimConnection *gc; | |
506 qq_buddy *q_bud; | |
507 | |
508 g_return_if_fail (GAIM_BLIST_NODE_IS_BUDDY (node)); | |
509 buddy = (GaimBuddy *) node; | |
510 q_bud = (qq_buddy *) buddy->proto_data; | |
511 // if (is_online (q_bud->status)) { | |
512 gc = gaim_account_get_connection (buddy->account); | |
513 g_return_if_fail (gc != NULL && gc->proto_data != NULL); | |
514 qq_send_file(gc, buddy->name, NULL); | |
515 // } | |
516 } | |
517 */ | |
518 | |
519 /* protocol related menus */ | |
520 static GList *_qq_actions(GaimPlugin *plugin, gpointer context) | |
521 { | |
522 GList *m; | |
523 GaimPluginAction *act; | |
524 | |
525 m = NULL; | |
526 act = gaim_plugin_action_new(_("Modify My Information"), _qq_menu_modify_my_info); | |
527 m = g_list_append(m, act); | |
528 | |
529 act = gaim_plugin_action_new(_("Change Password"), _qq_menu_change_password); | |
530 m = g_list_append(m, act); | |
531 | |
532 act = gaim_plugin_action_new(_("Show Login Information"), _qq_menu_show_login_info); | |
533 m = g_list_append(m, act); | |
534 | |
535 /* | |
536 act = gaim_plugin_action_new(_("Qun: Search a permanent Qun"), _qq_menu_search_or_add_permanent_group); | |
537 m = g_list_append(m, act); | |
538 | |
539 act = gaim_plugin_action_new(_("Qun: Create a permanent Qun"), _qq_menu_create_permanent_group); | |
540 m = g_list_append(m, act); | |
541 */ | |
542 | |
543 return m; | |
544 } | |
545 | |
546 /* chat-related (QQ Qun) menu shown up with right-click */ | |
547 static GList *_qq_chat_menu(GaimBlistNode *node) | |
548 { | |
549 GList *m; | |
550 GaimMenuAction *act; | |
551 | |
552 m = NULL; | |
553 act = gaim_menu_action_new(_("Exit this QQ Qun"), GAIM_CALLBACK(_qq_menu_unsubscribe_group), NULL, NULL); | |
554 m = g_list_append(m, act); | |
555 | |
14404 | 556 /* TODO: enable this |
14192 | 557 act = gaim_menu_action_new(_("Show Details"), GAIM_CALLBACK(_qq_menu_manage_group), NULL, NULL); |
558 m = g_list_append(m, act); | |
14404 | 559 */ |
14192 | 560 |
561 return m; | |
562 } | |
14404 | 563 |
14192 | 564 /* buddy-related menu shown up with right-click */ |
565 static GList *_qq_buddy_menu(GaimBlistNode * node) | |
566 { | |
567 GList *m; | |
568 | |
569 if(GAIM_BLIST_NODE_IS_CHAT(node)) | |
570 return _qq_chat_menu(node); | |
15075
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
571 |
14192 | 572 m = NULL; |
14404 | 573 return m; |
574 } | |
575 | |
15075
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
576 /* TODO : not working, temp commented out by gfhuang |
14192 | 577 |
578 act = gaim_menu_action_new(_("Block this buddy"), GAIM_CALLBACK(_qq_menu_block_buddy), NULL, NULL); //add NULL by gfhuang | |
579 m = g_list_append(m, act); | |
580 // if (q_bud && is_online(q_bud->status)) { | |
581 act = gaim_menu_action_new(_("Send File"), GAIM_CALLBACK(_qq_menu_send_file), NULL, NULL); //add NULL by gfhuang | |
582 m = g_list_append(m, act); | |
583 // } | |
584 */ | |
585 /* | |
586 return m; | |
587 } | |
588 */ | |
589 | |
590 | |
591 static void _qq_keep_alive(GaimConnection *gc) | |
592 { | |
593 qq_group *group; | |
594 qq_data *qd; | |
595 GList *list; | |
596 | |
597 if (NULL == (qd = (qq_data *) gc->proto_data)) | |
598 return; | |
599 | |
600 list = qd->groups; | |
601 while (list != NULL) { | |
602 group = (qq_group *) list->data; | |
603 if (group->my_status == QQ_GROUP_MEMBER_STATUS_IS_MEMBER || | |
604 group->my_status == QQ_GROUP_MEMBER_STATUS_IS_ADMIN) | |
605 /* no need to get info time and time again, online members enough */ | |
14404 | 606 qq_send_cmd_group_get_online_members(gc, group); |
15075
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
607 |
14192 | 608 list = list->next; |
609 } | |
610 | |
611 qq_send_packet_keep_alive(gc); | |
612 | |
613 } | |
614 | |
615 /* convert chat nickname to qq-uid to get this buddy info */ | |
616 /* who is the nickname of buddy in QQ chat-room (Qun) */ | |
617 static void _qq_get_chat_buddy_info(GaimConnection *gc, gint channel, const gchar *who) | |
618 { | |
619 gchar *gaim_name; | |
14629 | 620 g_return_if_fail(who != NULL); |
14192 | 621 |
14404 | 622 gaim_name = chat_name_to_gaim_name(who); |
14192 | 623 if (gaim_name != NULL) |
624 _qq_get_info(gc, gaim_name); | |
625 } | |
626 | |
627 /* convert chat nickname to qq-uid to invite individual IM to buddy */ | |
628 /* who is the nickname of buddy in QQ chat-room (Qun) */ | |
629 static gchar *_qq_get_chat_buddy_real_name(GaimConnection *gc, gint channel, const gchar *who) | |
630 { | |
14629 | 631 g_return_val_if_fail(who != NULL, NULL); |
14404 | 632 return chat_name_to_gaim_name(who); |
14192 | 633 } |
634 | |
635 GaimPlugin *my_protocol = NULL; | |
636 static GaimPluginProtocolInfo prpl_info = { | |
637 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_USE_POINTSIZE, | |
15071 | 638 NULL, /* user_splits */ |
639 NULL, /* protocol_options */ | |
640 {"png", 96, 96, 96, 96, GAIM_ICON_SCALE_SEND}, /* icon_spec */ | |
641 _qq_list_icon, /* list_icon */ | |
642 _qq_list_emblems, /* list_emblems */ | |
643 _qq_status_text, /* status_text */ | |
644 _qq_tooltip_text, /* tooltip_text */ | |
645 _qq_away_states, /* away_states */ | |
646 _qq_buddy_menu, /* blist_node_menu */ | |
647 qq_chat_info, /* chat_info */ | |
648 qq_chat_info_defaults, /* chat_info_defaults */ | |
649 _qq_login, /* login */ | |
650 _qq_close, /* close */ | |
651 _qq_send_im, /* send_im */ | |
652 NULL, /* set_info */ | |
653 NULL, /* send_typing */ | |
654 _qq_get_info, /* get_info */ | |
655 _qq_set_away, /* set_away */ | |
656 NULL, /* set_idle */ | |
657 NULL, /* change_passwd */ | |
658 qq_add_buddy, /* add_buddy */ | |
659 NULL, /* add_buddies */ | |
660 qq_remove_buddy, /* remove_buddy */ | |
661 NULL, /* remove_buddies */ | |
662 NULL, /* add_permit */ | |
663 NULL, /* add_deny */ | |
664 NULL, /* rem_permit */ | |
665 NULL, /* rem_deny */ | |
666 NULL, /* set_permit_deny */ | |
667 qq_group_join, /* join_chat */ | |
668 NULL, /* reject chat invite */ | |
669 NULL, /* get_chat_name */ | |
670 NULL, /* chat_invite */ | |
671 NULL, /* chat_leave */ | |
672 NULL, /* chat_whisper */ | |
673 _qq_chat_send, /* chat_send */ | |
674 _qq_keep_alive, /* keepalive */ | |
675 NULL, /* register_user */ | |
676 _qq_get_chat_buddy_info, /* get_cb_info */ | |
677 NULL, /* get_cb_away */ | |
678 NULL, /* alias_buddy */ | |
679 NULL, /* group_buddy */ | |
680 NULL, /* rename_group */ | |
15075
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
681 NULL, /* buddy_free */ |
15071 | 682 NULL, /* convo_closed */ |
683 NULL, /* normalize */ | |
684 qq_set_my_buddy_icon, /* set_buddy_icon */ | |
685 NULL, /* remove_group */ | |
686 _qq_get_chat_buddy_real_name, /* get_cb_real_name */ | |
687 NULL, /* set_chat_topic */ | |
688 NULL, /* find_blist_chat */ | |
689 qq_roomlist_get_list, /* roomlist_get_list */ | |
690 qq_roomlist_cancel, /* roomlist_cancel */ | |
691 NULL, /* roomlist_expand_category */ | |
692 NULL, /* can_receive_file */ | |
693 qq_send_file, /* send_file */ | |
15075
2c93b0620065
[gaim-migrate @ 17859]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
15072
diff
changeset
|
694 NULL, /* new xfer */ |
15071 | 695 NULL, /* offline_message */ |
696 NULL, /* GaimWhiteboardPrplOps */ | |
697 NULL, /* send_raw */ | |
15123 | 698 NULL, /* roomlist_room_serialize */ |
14192 | 699 }; |
700 | |
701 static GaimPluginInfo info = { | |
702 GAIM_PLUGIN_MAGIC, | |
703 GAIM_MAJOR_VERSION, | |
704 GAIM_MINOR_VERSION, | |
705 GAIM_PLUGIN_PROTOCOL, /**< type */ | |
706 NULL, /**< ui_requirement */ | |
707 0, /**< flags */ | |
708 NULL, /**< dependencies */ | |
709 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
710 | |
711 "prpl-qq", /**< id */ | |
712 "QQ", /**< name */ | |
713 VERSION, /**< version */ | |
714 /** summary */ | |
715 N_("QQ Protocol Plugin"), | |
716 /** description */ | |
717 N_("QQ Protocol Plugin"), | |
718 OPENQ_AUTHOR, /**< author */ | |
719 OPENQ_WEBSITE, /**< homepage */ | |
720 | |
721 NULL, /**< load */ | |
722 NULL, /**< unload */ | |
723 NULL, /**< destroy */ | |
724 | |
725 NULL, /**< ui_info */ | |
726 &prpl_info, /**< extra_info */ | |
14404 | 727 NULL, /**< prefs_info */ |
14192 | 728 _qq_actions |
729 }; | |
730 | |
731 | |
732 static void init_plugin(GaimPlugin *plugin) | |
733 { | |
734 GaimAccountOption *option; | |
735 | |
736 option = gaim_account_option_bool_new(_("Login in TCP"), "use_tcp", FALSE); | |
737 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
738 | |
739 option = gaim_account_option_bool_new(_("Login Hidden"), "hidden", FALSE); | |
740 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
741 | |
14790
a33d179d5508
[gaim-migrate @ 17555]
Richard Laager <rlaager@wiktel.com>
parents:
14629
diff
changeset
|
742 option = gaim_account_option_string_new(_("Server"), "server", NULL); |
14192 | 743 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); |
744 | |
14790
a33d179d5508
[gaim-migrate @ 17555]
Richard Laager <rlaager@wiktel.com>
parents:
14629
diff
changeset
|
745 option = gaim_account_option_string_new(_("Port"), "port", NULL); |
14192 | 746 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); |
747 | |
748 my_protocol = plugin; | |
749 | |
750 gaim_prefs_add_none("/plugins/prpl/qq"); | |
751 gaim_prefs_add_bool("/plugins/prpl/qq/show_status_by_icon", TRUE); | |
752 gaim_prefs_add_bool("/plugins/prpl/qq/show_fake_video", FALSE); | |
753 gaim_prefs_add_bool("/plugins/prpl/qq/prompt_for_missing_packet", TRUE); | |
754 gaim_prefs_add_bool("/plugins/prpl/qq/prompt_group_msg_on_recv", TRUE); | |
755 } | |
756 | |
757 GAIM_INIT_PLUGIN(qq, init_plugin, info); |