comparison libpurple/protocols/qq/qq.c @ 15373:5fe8042783c1

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