Mercurial > pidgin
annotate libgaim/protocols/qq/qq.c @ 15071:902f3621aa13
[gaim-migrate @ 17855]
Use the QQ faces as buddy icons instead of status icons. Also, a few minor cleanups and a bug fix for faces > 33.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Huetsch <markhuetsch> |
---|---|
date | Thu, 30 Nov 2006 10:30:13 +0000 |
parents | c039c920e11c |
children | 322d6b5472a4 |
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; | |
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); | |
115 presence = gaim_account_get_presence(account); | |
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 ? | |
14195 | 130 tcp_server_list[random() % tcp_server_amount] : |
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); | |
14195 | 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); | |
187 } | |
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) { | |
208 g_string_append_printf(tooltip, "\n<b>%s Address:</b> %s:%d", | |
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); | |
214 switch (q_bud->gender) { | |
215 case QQ_BUDDY_GENDER_GG: | |
14268 | 216 g_string_append(tooltip, "\n<b>Gender:</b> Male"); |
14192 | 217 break; |
218 case QQ_BUDDY_GENDER_MM: | |
14268 | 219 g_string_append(tooltip, "\n<b>Gender:</b> Female"); |
14192 | 220 break; |
221 case QQ_BUDDY_GENDER_UNKNOWN: | |
14268 | 222 g_string_append(tooltip, "\n<b>Gender:</b> Unknown"); |
14192 | 223 break; |
224 default: | |
225 g_string_append_printf(tooltip, "\n<b>Gender:</b> ERROR(%d)", q_bud->gender); | |
14268 | 226 } |
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); | |
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; | |
242 const char *emblems[4] = { NULL, NULL, NULL, NULL }; | |
14265 | 243 int i = 1; |
14192 | 244 |
245 if (q_bud == NULL) { | |
246 emblems[0] = "offline"; | |
247 } else { | |
14265 | 248 /* TODO the wireless icon is a bit too big to look good with QQ faces */ |
14318 | 249 if (q_bud->status == QQ_BUDDY_ONLINE_AWAY) |
14265 | 250 emblems[i++] = "away"; |
14192 | 251 if (q_bud->comm_flag & QQ_COMM_FLAG_QQ_MEMBER) |
252 emblems[i++] = "qq_member"; | |
253 if (q_bud->comm_flag & QQ_COMM_FLAG_BIND_MOBILE) | |
254 emblems[i++] = "wireless"; | |
255 if (q_bud->comm_flag & QQ_COMM_FLAG_VIDEO) | |
14265 | 256 emblems[i%4] = "video"; |
14192 | 257 |
258 } | |
259 | |
260 *se = emblems[0]; | |
261 *sw = emblems[1]; | |
262 *nw = emblems[2]; | |
263 *ne = emblems[3]; | |
264 | |
265 return; | |
266 } | |
267 | |
268 /* QQ away status (used to initiate QQ away packet) */ | |
269 static GList *_qq_away_states(GaimAccount *ga) | |
270 { | |
271 GaimStatusType *status; | |
272 GList *types = NULL; | |
273 | |
274 status = gaim_status_type_new_full(GAIM_STATUS_AVAILABLE, | |
275 "available", _("QQ: Available"), FALSE, TRUE, FALSE); | |
276 types = g_list_append(types, status); | |
277 | |
278 status = gaim_status_type_new_full(GAIM_STATUS_AWAY, | |
279 "away", _("QQ: Away"), FALSE, TRUE, FALSE); | |
280 types = g_list_append(types, status); | |
281 | |
282 status = gaim_status_type_new_full(GAIM_STATUS_INVISIBLE, | |
283 "invisible", _("QQ: Invisible"), FALSE, TRUE, FALSE); | |
284 types = g_list_append(types, status); | |
285 | |
286 status = gaim_status_type_new_full(GAIM_STATUS_OFFLINE, | |
287 "offline", _("QQ: Offline"), FALSE, TRUE, FALSE); | |
288 types = g_list_append(types, status); | |
289 | |
290 return types; | |
291 } | |
292 | |
293 /* initiate QQ away with proper change_status packet */ | |
294 static void _qq_set_away(GaimAccount *account, GaimStatus *status) | |
295 { | |
296 GaimConnection *gc = gaim_account_get_connection(account); | |
297 | |
298 qq_send_packet_change_status(gc); | |
299 } | |
300 | |
301 /* IMPORTANT: GaimConvImFlags -> GaimMessageFlags */ | |
302 /* send an instant msg to a buddy */ | |
303 static gint _qq_send_im(GaimConnection *gc, const gchar *who, const gchar *message, GaimMessageFlags flags) | |
304 { | |
305 gint type, to_uid; | |
306 gchar *msg, *msg_with_qq_smiley; | |
307 qq_data *qd; | |
308 | |
14629 | 309 g_return_val_if_fail(who != NULL, -1); |
14192 | 310 |
311 qd = (qq_data *) gc->proto_data; | |
312 | |
313 g_return_val_if_fail(strlen(message) <= QQ_MSG_IM_MAX, -E2BIG); | |
314 | |
315 type = (flags == GAIM_MESSAGE_AUTO_RESP ? QQ_IM_AUTO_REPLY : QQ_IM_TEXT); | |
316 to_uid = gaim_name_to_uid(who); | |
317 | |
318 /* if msg is to myself, bypass the network */ | |
319 if (to_uid == qd->uid) { | |
320 serv_got_im(gc, who, message, flags, time(NULL)); | |
321 } else { | |
322 msg = utf8_to_qq(message, QQ_CHARSET_DEFAULT); | |
323 msg_with_qq_smiley = gaim_smiley_to_qq(msg); | |
324 qq_send_packet_im(gc, to_uid, msg_with_qq_smiley, type); | |
325 g_free(msg); | |
326 g_free(msg_with_qq_smiley); | |
327 } | |
328 | |
329 return 1; | |
330 } | |
331 | |
332 /* send a chat msg to a QQ Qun */ | |
333 static int _qq_chat_send(GaimConnection *gc, int channel, const char *message, GaimMessageFlags flags) | |
334 { | |
335 gchar *msg, *msg_with_qq_smiley; | |
336 qq_group *group; | |
337 | |
14629 | 338 g_return_val_if_fail(message != NULL, -1); |
14192 | 339 g_return_val_if_fail(strlen(message) <= QQ_MSG_IM_MAX, -E2BIG); |
340 | |
341 group = qq_group_find_by_channel(gc, channel); | |
342 g_return_val_if_fail(group != NULL, -1); | |
343 | |
344 msg = utf8_to_qq(message, QQ_CHARSET_DEFAULT); | |
345 msg_with_qq_smiley = gaim_smiley_to_qq(msg); | |
346 qq_send_packet_group_im(gc, group, msg_with_qq_smiley); | |
347 g_free(msg); | |
348 g_free(msg_with_qq_smiley); | |
349 | |
350 return 1; | |
351 } | |
352 | |
353 /* send packet to get who's detailed information */ | |
354 static void _qq_get_info(GaimConnection *gc, const gchar *who) | |
355 { | |
356 guint32 uid; | |
357 qq_data *qd; | |
358 | |
359 qd = gc->proto_data; | |
360 uid = gaim_name_to_uid(who); | |
361 | |
362 if (uid <= 0) { | |
363 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Not valid QQid: %s\n", who); | |
14319 | 364 gaim_notify_error(gc, NULL, _("Invalid name"), NULL); |
14192 | 365 return; |
366 } | |
367 | |
368 qq_send_packet_get_info(gc, uid, TRUE); | |
369 } | |
370 | |
371 /* get my own information */ | |
372 static void _qq_menu_modify_my_info(GaimPluginAction *action) | |
373 { | |
374 GaimConnection *gc = (GaimConnection *) action->context; | |
375 qq_data *qd; | |
376 | |
377 qd = (qq_data *) gc->proto_data; | |
378 qq_prepare_modify_info(gc); | |
379 } | |
380 | |
381 static void _qq_menu_change_password(GaimPluginAction *action) | |
382 { | |
383 gaim_notify_uri(NULL, "https://password.qq.com"); | |
384 } | |
385 | |
386 /* remove a buddy from my list and remove myself from his list */ | |
387 /* TODO: re-enable this | |
388 static void _qq_menu_block_buddy(GaimBlistNode * node) | |
389 { | |
390 guint32 uid; | |
391 gc_and_uid *g; | |
392 GaimBuddy *buddy; | |
393 GaimConnection *gc; | |
394 // const gchar *who = param_who; gfhuang | |
395 const gchar *who; | |
396 | |
397 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
398 | |
399 buddy = (GaimBuddy *) node; | |
400 gc = gaim_account_get_connection(buddy->account); | |
401 who = buddy->name; | |
14629 | 402 g_return_if_fail(who != NULL); |
14192 | 403 |
404 uid = gaim_name_to_uid(who); | |
405 g_return_if_fail(uid > 0); | |
406 | |
407 g = g_new0(gc_and_uid, 1); | |
408 g->gc = gc; | |
409 g->uid = uid; | |
410 | |
411 gaim_request_action(gc, _("Block Buddy"), | |
412 _("Are you sure to block this buddy?"), NULL, | |
413 1, g, 2, | |
414 _("Cancel"), | |
415 G_CALLBACK(qq_do_nothing_with_gc_and_uid), | |
416 _("Block"), G_CALLBACK(qq_block_buddy_with_gc_and_uid)); | |
417 } | |
418 */ | |
419 | |
420 /* show a brief summary of what we get from login packet */ | |
421 static void _qq_menu_show_login_info(GaimPluginAction *action) | |
422 { | |
423 GaimConnection *gc = (GaimConnection *) action->context; | |
424 qq_data *qd; | |
425 GString *info; | |
426 | |
427 qd = (qq_data *) gc->proto_data; | |
428 info = g_string_new("<html><body>\n"); | |
429 | |
430 g_string_append_printf(info, _("<b>Current Online</b>: %d<br>\n"), qd->all_online); | |
431 g_string_append_printf(info, _("<b>Last Refresh</b>: %s<br>\n"), ctime(&qd->last_get_online)); | |
432 | |
433 g_string_append(info, "<hr>\n"); | |
434 | |
435 g_string_append_printf(info, _("<b>Connection Mode</b>: %s<br>\n"), qd->use_tcp ? "TCP" : "UDP"); | |
436 g_string_append_printf(info, _("<b>Server IP</b>: %s: %d<br>\n"), qd->server_ip, qd->server_port); | |
437 g_string_append_printf(info, _("<b>My Public IP</b>: %s<br>\n"), qd->my_ip); | |
438 | |
439 g_string_append(info, "<hr>\n"); | |
15071 | 440 g_string_append(info, "<i>Information below may not be accurate</i><br>\n"); |
14192 | 441 |
442 g_string_append_printf(info, _("<b>Login Time</b>: %s<br>\n"), ctime(&qd->login_time)); | |
443 g_string_append_printf(info, _("<b>Last Login IP</b>: %s<br>\n"), qd->last_login_ip); | |
444 g_string_append_printf(info, _("<b>Last Login Time</b>: %s\n"), ctime(&qd->last_login_time)); | |
445 | |
446 g_string_append(info, "</body></html>"); | |
447 | |
448 gaim_notify_formatted(gc, NULL, _("Login Information"), NULL, info->str, NULL, NULL); | |
449 | |
450 g_string_free(info, TRUE); | |
451 } | |
452 | |
14242 | 453 /* |
14192 | 454 static void _qq_menu_search_or_add_permanent_group(GaimPluginAction *action) |
455 { | |
456 gaim_roomlist_show_with_account(NULL); | |
457 } | |
14242 | 458 */ |
14192 | 459 |
460 /* | |
461 static void _qq_menu_create_permanent_group(GaimPluginAction * action) | |
462 { | |
463 GaimConnection *gc = (GaimConnection *) action->context; | |
464 gaim_request_input(gc, _("Create QQ Qun"), | |
465 _("Input Qun name here"), | |
466 _("Only QQ member can create permanent Qun"), | |
467 "OpenQ", FALSE, FALSE, NULL, | |
468 _("Create"), G_CALLBACK(qq_group_create_with_name), _("Cancel"), NULL, gc); | |
469 } | |
470 */ | |
471 | |
472 static void _qq_menu_unsubscribe_group(GaimBlistNode * node) | |
473 { | |
474 GaimChat *chat = (GaimChat *)node; | |
475 GaimConnection *gc = gaim_account_get_connection(chat->account); | |
476 GHashTable *components = chat -> components; | |
477 | |
478 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node)); | |
479 | |
14629 | 480 g_return_if_fail(components != NULL); |
14192 | 481 qq_group_exit(gc, components); |
482 } | |
483 | |
14404 | 484 /* |
14192 | 485 static void _qq_menu_manage_group(GaimBlistNode * node) |
486 { | |
487 GaimChat *chat = (GaimChat *)node; | |
488 GaimConnection *gc = gaim_account_get_connection(chat->account); | |
489 GHashTable *components = chat -> components; | |
490 | |
491 g_return_if_fail(GAIM_BLIST_NODE_IS_CHAT(node)); | |
492 | |
14629 | 493 g_return_if_fail(components != NULL); |
14192 | 494 qq_group_manage_group(gc, components); |
495 } | |
496 */ | |
497 | |
498 /* TODO: re-enable this | |
499 static void _qq_menu_send_file(GaimBlistNode * node, gpointer ignored) | |
500 { | |
501 GaimBuddy *buddy; | |
502 GaimConnection *gc; | |
503 qq_buddy *q_bud; | |
504 | |
505 g_return_if_fail (GAIM_BLIST_NODE_IS_BUDDY (node)); | |
506 buddy = (GaimBuddy *) node; | |
507 q_bud = (qq_buddy *) buddy->proto_data; | |
508 // if (is_online (q_bud->status)) { | |
509 gc = gaim_account_get_connection (buddy->account); | |
510 g_return_if_fail (gc != NULL && gc->proto_data != NULL); | |
511 qq_send_file(gc, buddy->name, NULL); | |
512 // } | |
513 } | |
514 */ | |
515 | |
516 /* protocol related menus */ | |
517 static GList *_qq_actions(GaimPlugin *plugin, gpointer context) | |
518 { | |
519 GList *m; | |
520 GaimPluginAction *act; | |
521 | |
522 m = NULL; | |
523 act = gaim_plugin_action_new(_("Modify My Information"), _qq_menu_modify_my_info); | |
524 m = g_list_append(m, act); | |
525 | |
526 act = gaim_plugin_action_new(_("Change Password"), _qq_menu_change_password); | |
527 m = g_list_append(m, act); | |
528 | |
529 act = gaim_plugin_action_new(_("Show Login Information"), _qq_menu_show_login_info); | |
530 m = g_list_append(m, act); | |
531 | |
532 /* | |
533 act = gaim_plugin_action_new(_("Qun: Search a permanent Qun"), _qq_menu_search_or_add_permanent_group); | |
534 m = g_list_append(m, act); | |
535 | |
536 act = gaim_plugin_action_new(_("Qun: Create a permanent Qun"), _qq_menu_create_permanent_group); | |
537 m = g_list_append(m, act); | |
538 */ | |
539 | |
540 return m; | |
541 } | |
542 | |
543 /* chat-related (QQ Qun) menu shown up with right-click */ | |
544 static GList *_qq_chat_menu(GaimBlistNode *node) | |
545 { | |
546 GList *m; | |
547 GaimMenuAction *act; | |
548 | |
549 m = NULL; | |
550 act = gaim_menu_action_new(_("Exit this QQ Qun"), GAIM_CALLBACK(_qq_menu_unsubscribe_group), NULL, NULL); | |
551 m = g_list_append(m, act); | |
552 | |
14404 | 553 /* TODO: enable this |
14192 | 554 act = gaim_menu_action_new(_("Show Details"), GAIM_CALLBACK(_qq_menu_manage_group), NULL, NULL); |
555 m = g_list_append(m, act); | |
14404 | 556 */ |
14192 | 557 |
558 return m; | |
559 } | |
14404 | 560 |
14192 | 561 /* buddy-related menu shown up with right-click */ |
562 static GList *_qq_buddy_menu(GaimBlistNode * node) | |
563 { | |
564 GList *m; | |
565 | |
566 if(GAIM_BLIST_NODE_IS_CHAT(node)) | |
567 return _qq_chat_menu(node); | |
568 | |
569 m = NULL; | |
14404 | 570 return m; |
571 } | |
572 | |
14192 | 573 /* TODO : not working, temp commented out by gfhuang |
574 | |
575 act = gaim_menu_action_new(_("Block this buddy"), GAIM_CALLBACK(_qq_menu_block_buddy), NULL, NULL); //add NULL by gfhuang | |
576 m = g_list_append(m, act); | |
577 // if (q_bud && is_online(q_bud->status)) { | |
578 act = gaim_menu_action_new(_("Send File"), GAIM_CALLBACK(_qq_menu_send_file), NULL, NULL); //add NULL by gfhuang | |
579 m = g_list_append(m, act); | |
580 // } | |
581 */ | |
582 /* | |
583 return m; | |
584 } | |
585 */ | |
586 | |
587 | |
588 static void _qq_keep_alive(GaimConnection *gc) | |
589 { | |
590 qq_group *group; | |
591 qq_data *qd; | |
592 GList *list; | |
593 | |
594 if (NULL == (qd = (qq_data *) gc->proto_data)) | |
595 return; | |
596 | |
597 list = qd->groups; | |
598 while (list != NULL) { | |
599 group = (qq_group *) list->data; | |
600 if (group->my_status == QQ_GROUP_MEMBER_STATUS_IS_MEMBER || | |
601 group->my_status == QQ_GROUP_MEMBER_STATUS_IS_ADMIN) | |
602 /* no need to get info time and time again, online members enough */ | |
14404 | 603 qq_send_cmd_group_get_online_members(gc, group); |
14192 | 604 |
605 list = list->next; | |
606 } | |
607 | |
608 qq_send_packet_keep_alive(gc); | |
609 | |
610 } | |
611 | |
612 /* convert chat nickname to qq-uid to get this buddy info */ | |
613 /* who is the nickname of buddy in QQ chat-room (Qun) */ | |
614 static void _qq_get_chat_buddy_info(GaimConnection *gc, gint channel, const gchar *who) | |
615 { | |
616 gchar *gaim_name; | |
14629 | 617 g_return_if_fail(who != NULL); |
14192 | 618 |
14404 | 619 gaim_name = chat_name_to_gaim_name(who); |
14192 | 620 if (gaim_name != NULL) |
621 _qq_get_info(gc, gaim_name); | |
622 } | |
623 | |
624 /* convert chat nickname to qq-uid to invite individual IM to buddy */ | |
625 /* who is the nickname of buddy in QQ chat-room (Qun) */ | |
626 static gchar *_qq_get_chat_buddy_real_name(GaimConnection *gc, gint channel, const gchar *who) | |
627 { | |
14629 | 628 g_return_val_if_fail(who != NULL, NULL); |
14404 | 629 return chat_name_to_gaim_name(who); |
14192 | 630 } |
631 | |
632 GaimPlugin *my_protocol = NULL; | |
633 static GaimPluginProtocolInfo prpl_info = { | |
634 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_USE_POINTSIZE, | |
15071 | 635 NULL, /* user_splits */ |
636 NULL, /* protocol_options */ | |
637 {"png", 96, 96, 96, 96, GAIM_ICON_SCALE_SEND}, /* icon_spec */ | |
638 _qq_list_icon, /* list_icon */ | |
639 _qq_list_emblems, /* list_emblems */ | |
640 _qq_status_text, /* status_text */ | |
641 _qq_tooltip_text, /* tooltip_text */ | |
642 _qq_away_states, /* away_states */ | |
643 _qq_buddy_menu, /* blist_node_menu */ | |
644 qq_chat_info, /* chat_info */ | |
645 qq_chat_info_defaults, /* chat_info_defaults */ | |
646 _qq_login, /* login */ | |
647 _qq_close, /* close */ | |
648 _qq_send_im, /* send_im */ | |
649 NULL, /* set_info */ | |
650 NULL, /* send_typing */ | |
651 _qq_get_info, /* get_info */ | |
652 _qq_set_away, /* set_away */ | |
653 NULL, /* set_idle */ | |
654 NULL, /* change_passwd */ | |
655 qq_add_buddy, /* add_buddy */ | |
656 NULL, /* add_buddies */ | |
657 qq_remove_buddy, /* remove_buddy */ | |
658 NULL, /* remove_buddies */ | |
659 NULL, /* add_permit */ | |
660 NULL, /* add_deny */ | |
661 NULL, /* rem_permit */ | |
662 NULL, /* rem_deny */ | |
663 NULL, /* set_permit_deny */ | |
664 qq_group_join, /* join_chat */ | |
665 NULL, /* reject chat invite */ | |
666 NULL, /* get_chat_name */ | |
667 NULL, /* chat_invite */ | |
668 NULL, /* chat_leave */ | |
669 NULL, /* chat_whisper */ | |
670 _qq_chat_send, /* chat_send */ | |
671 _qq_keep_alive, /* keepalive */ | |
672 NULL, /* register_user */ | |
673 _qq_get_chat_buddy_info, /* get_cb_info */ | |
674 NULL, /* get_cb_away */ | |
675 NULL, /* alias_buddy */ | |
676 NULL, /* group_buddy */ | |
677 NULL, /* rename_group */ | |
678 NULL, /* buddy_free */ | |
679 NULL, /* convo_closed */ | |
680 NULL, /* normalize */ | |
681 qq_set_my_buddy_icon, /* set_buddy_icon */ | |
682 NULL, /* remove_group */ | |
683 _qq_get_chat_buddy_real_name, /* get_cb_real_name */ | |
684 NULL, /* set_chat_topic */ | |
685 NULL, /* find_blist_chat */ | |
686 qq_roomlist_get_list, /* roomlist_get_list */ | |
687 qq_roomlist_cancel, /* roomlist_cancel */ | |
688 NULL, /* roomlist_expand_category */ | |
689 NULL, /* can_receive_file */ | |
690 qq_send_file, /* send_file */ | |
691 NULL, /* new xfer */ | |
692 NULL, /* offline_message */ | |
693 NULL, /* GaimWhiteboardPrplOps */ | |
694 NULL, /* send_raw */ | |
14192 | 695 }; |
696 | |
697 static GaimPluginInfo info = { | |
698 GAIM_PLUGIN_MAGIC, | |
699 GAIM_MAJOR_VERSION, | |
700 GAIM_MINOR_VERSION, | |
701 GAIM_PLUGIN_PROTOCOL, /**< type */ | |
702 NULL, /**< ui_requirement */ | |
703 0, /**< flags */ | |
704 NULL, /**< dependencies */ | |
705 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
706 | |
707 "prpl-qq", /**< id */ | |
708 "QQ", /**< name */ | |
709 VERSION, /**< version */ | |
710 /** summary */ | |
711 N_("QQ Protocol Plugin"), | |
712 /** description */ | |
713 N_("QQ Protocol Plugin"), | |
714 OPENQ_AUTHOR, /**< author */ | |
715 OPENQ_WEBSITE, /**< homepage */ | |
716 | |
717 NULL, /**< load */ | |
718 NULL, /**< unload */ | |
719 NULL, /**< destroy */ | |
720 | |
721 NULL, /**< ui_info */ | |
722 &prpl_info, /**< extra_info */ | |
14404 | 723 NULL, /**< prefs_info */ |
14192 | 724 _qq_actions |
725 }; | |
726 | |
727 | |
728 static void init_plugin(GaimPlugin *plugin) | |
729 { | |
730 GaimAccountOption *option; | |
731 | |
732 option = gaim_account_option_bool_new(_("Login in TCP"), "use_tcp", FALSE); | |
733 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
734 | |
735 option = gaim_account_option_bool_new(_("Login Hidden"), "hidden", FALSE); | |
736 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
737 | |
14790
a33d179d5508
[gaim-migrate @ 17555]
Richard Laager <rlaager@wiktel.com>
parents:
14629
diff
changeset
|
738 option = gaim_account_option_string_new(_("Server"), "server", NULL); |
14192 | 739 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); |
740 | |
14790
a33d179d5508
[gaim-migrate @ 17555]
Richard Laager <rlaager@wiktel.com>
parents:
14629
diff
changeset
|
741 option = gaim_account_option_string_new(_("Port"), "port", NULL); |
14192 | 742 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); |
743 | |
744 my_protocol = plugin; | |
745 | |
746 gaim_prefs_add_none("/plugins/prpl/qq"); | |
747 gaim_prefs_add_bool("/plugins/prpl/qq/show_status_by_icon", TRUE); | |
748 gaim_prefs_add_bool("/plugins/prpl/qq/show_fake_video", FALSE); | |
749 gaim_prefs_add_bool("/plugins/prpl/qq/prompt_for_missing_packet", TRUE); | |
750 gaim_prefs_add_bool("/plugins/prpl/qq/prompt_group_msg_on_recv", TRUE); | |
751 } | |
752 | |
753 GAIM_INIT_PLUGIN(qq, init_plugin, info); |