annotate src/protocols/qq/buddy_info.c @ 13993:e6977f9435a1

[gaim-migrate @ 16570] *Fixed an off-by-one blood_types bug. *Made it so that only one modify info dialog can be open at a time. *Fixed a bug where the user wasn't always notified when his info had been modified. *Eliminated the ability to send empty strings as info fields as these were making the official client unhappy. committer: Tailor Script <tailor@pidgin.im>
author Mark Huetsch <markhuetsch>
date Tue, 25 Jul 2006 04:31:36 +0000
parents 16102b9c5c4a
children dd19c67be844
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
1 /**
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
2 * The QQ2003C protocol plugin
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
3 *
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
4 * for gaim
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
5 *
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
6 * Copyright (C) 2004 Puzzlebird
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
7 *
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
11 * (at your option) any later version.
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
12 *
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
16 * GNU General Public License for more details.
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
17 *
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
21 */
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
22
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
23 #include "internal.h" // strlen, _("get_text)
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
24 #include "debug.h" // gaim_debug
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
25 #include "notify.h" // gaim_notify
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
26 #include "request.h" // gaim_request_fields_new
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
27
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
28 #include "utils.h" // uid_to_gaim_name
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
29 #include "packet_parse.h" // MAX_PACKET_SIZE
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
30 #include "buddy_info.h" //
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
31 #include "char_conv.h" // qq_to_utf8
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
32 #include "crypt.h" // qq_crypt
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
33 #include "header_info.h" // cmd alias
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
34 #include "keep_alive.h" // qq_update_buddy_contact
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
35 #include "send_core.h" // qq_send_cmd
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
36
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
37 // Below is all of the information necessary to reconstruct the various
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
38 // information fields that one can set in the official client. When we need
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
39 // to know about a specific field (e.g., should "city" be a choice
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
40 // or text field?), we can simply look it up from the template. Note that
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
41 // there are a number of unidentified fields.
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
42
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
43 typedef struct _info_field {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
44 gchar *title;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
45 gchar *id; // used by gaim_request fields
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
46 gint pos;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
47 gchar *group;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
48 gint group_pos; // for display order in the UI
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
49 gint choice; // indicates which character array contains the choices
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
50 gboolean customizable; // whether a user can enter any text as a value, regardless of choice arrays
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
51 gchar *value;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
52 } info_field;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
53
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
54 static const info_field info_template_data[] = {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
55 { N_("User ID"), "uid", 0, QQ_MAIN_INFO, 0, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
56 { N_("Nickname"), "nick", 1, QQ_MAIN_INFO, 1, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
57 { N_("Country/Region"), "country", 2, QQ_MAIN_INFO, 5, QQ_COUNTRY, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
58 { N_("Province/State"), "province", 3, QQ_MAIN_INFO, 6, QQ_PROVINCE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
59 { N_("Zipcode"), "zipcode", 4, QQ_EXTRA_INFO, 7, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
60 { N_("Address"), "address", 5, QQ_EXTRA_INFO, 6, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
61 { N_("Phone Number"), "tel", 6, QQ_EXTRA_INFO, 9, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
62 { N_("Age"), "age", 7, QQ_MAIN_INFO, 3, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
63 { N_("Gender"), "gender", 8, QQ_MAIN_INFO, 4, QQ_GENDER, FALSE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
64 { N_("Name"), "name", 9, QQ_MAIN_INFO, 2, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
65 { N_("Email"), "email", 10, QQ_EXTRA_INFO, 5, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
66 { "pager_sn", "pager_sn", 11, QQ_MISC, 0, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
67 { "pager_num", "pager_num", 12, QQ_MISC, 1, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
68 { "pager_sp", "pager_sp", 13, QQ_MISC, 2, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
69 { "pager_base_num", "pager_base_num", 14, QQ_MISC, 3, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
70 { "pager_type", "pager_type", 15, QQ_MISC, 4, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
71 { N_("Occupation"), "occupation", 16, QQ_EXTRA_INFO, 1, QQ_OCCUPATION, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
72 { N_("Homepage"), "homepage", 17, QQ_EXTRA_INFO, 10, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
73 { "auth_type", "auth_type", 18, QQ_MISC, 5, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
74 { "unknown1", "unknown1", 19, QQ_MISC, 6, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
75 { "unknown2", "unknown2", 20, QQ_MISC, 7, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
76 { "face", "face", 21, QQ_MISC, 8, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
77 { N_("Cellphone Number"), "hp_num", 22, QQ_EXTRA_INFO, 8, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
78 { "hp_type", "hp_type", 23, QQ_MISC, 9, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
79 { N_("Personal Introduction"), "intro", 24, QQ_PERSONAL_INTRO, 0, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
80 { N_("City"), "city", 25, QQ_MAIN_INFO, 7, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
81 { "unknown3", "unknown3", 26, QQ_MISC, 10, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
82 { "unknown4", "unknown4", 27, QQ_MISC, 11, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
83 { "unknown5", "unknown5", 28, QQ_MISC, 12, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
84 { "is_open_hp", "is_open_hp", 29, QQ_MISC, 13, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
85 { "is_open_contact", "is_open_contact", 30, QQ_MISC, 14, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
86 { N_("College"), "college", 31, QQ_EXTRA_INFO, 4, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
87 { N_("Horoscope Symbol"), "horoscope", 32, QQ_EXTRA_INFO, 0, QQ_HOROSCOPE, FALSE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
88 { N_("Zodiac Symbol"), "zodiac", 33, QQ_EXTRA_INFO, 2, QQ_ZODIAC, FALSE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
89 { N_("Blood Type"), "blood", 34, QQ_EXTRA_INFO, 3, QQ_BLOOD, FALSE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
90 { "qq_show", "qq_show", 35, QQ_MISC, 15, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
91 { "unknown6", "unknown6", 36, QQ_MISC, 16, QQ_NO_CHOICE, TRUE, NULL },
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
92 { NULL, NULL, 0, NULL, 0, 0, 0, NULL } //NULL termination
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
93 };
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
94
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
95 //TODO: translate these arrays to their English equivalents
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
96 // and move these characters to the zh_CN po file
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
97 static const gchar *horoscope_names[] = {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
98 "-", "水瓶座", "双鱼座", "牡羊座", "金牛座",
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
99 "双子座", "巨蟹座", "狮子座", "处女座", "天秤座",
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
100 "天蝎座", "射手座", "魔羯座", NULL
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
101 };
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
102
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
103 static const gchar *zodiac_names[] = {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
104 "-", "鼠", "牛", "虎", "兔",
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
105 "龙", "蛇", "马", "羊", "猴",
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
106 "鸡", "狗", "猪", NULL
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
107 };
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
108
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
109 static const gchar *blood_types[] = {
13993
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
110 "-", N_("A"), N_("B"), N_("O"), N_("AB"), N_("Other"), NULL
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
111 };
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
112
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
113 static const gchar *genders[] = {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
114 N_("Male"),
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
115 N_("Female"),
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
116 NULL
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
117 };
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
118
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
119 static const gchar *country_names[] = {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
120 "中国", "中国香港", "中国澳门", "中国台湾",
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
121 "新加坡", "马来西亚", "美国", NULL
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
122 };
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
123
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
124 static const gchar *province_names[] = {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
125 "北京", "天津", "上海", "重庆", "香港",
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
126 "河北", "山西", "内蒙古", "辽宁", "吉林",
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
127 "黑龙江", "江西", "浙江", "江苏", "安徽",
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
128 "福建", "山东", "河南", "湖北", "湖南",
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
129 "广东", "广西", "海南", "四川", "贵州",
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
130 "云南", "西藏", "陕西", "甘肃", "宁夏",
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
131 "青海", "新疆", "台湾", "澳门", NULL
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
132 };
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
133
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
134 static const gchar *occupation_names[] = {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
135 "全职", "兼职", "制造业", "商业", "失业中",
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
136 "学生", "工程师", "政府部门", "教育业", "服务行业",
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
137 "老板", "计算机业", "退休", "金融业",
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
138 "销售/广告/市场", NULL
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
139 };
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
140
13993
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
141 static const gint choice_sizes[] = { 0, 13, 13, 6, 2, 7, 34, 15 };
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
142
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
143
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
144 static const gchar *info_group_headers[] = {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
145 QQ_MAIN_INFO,
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
146 QQ_EXTRA_INFO,
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
147 QQ_PERSONAL_INTRO,
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
148 QQ_MISC
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
149 };
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
150
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
151 static const gchar **choices[] = {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
152 NULL,
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
153 horoscope_names,
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
154 zodiac_names,
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
155 blood_types,
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
156 genders,
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
157 country_names,
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
158 province_names,
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
159 occupation_names
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
160 };
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
161
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
162 /*************** info and info_field methods *****************/
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
163
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
164 // Given an id, return the template for that field.
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
165 // Returns NULL if the id is not found.
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
166 static const info_field *info_field_get_template(const gchar *id)
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
167 {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
168 const info_field *cur_field;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
169 const gchar *cur_id;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
170
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
171 cur_field = info_template_data;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
172 cur_id = cur_field->id;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
173 while(cur_id != NULL) {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
174 if (g_ascii_strcasecmp(cur_id, id) == 0) return cur_field;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
175 cur_field++;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
176 cur_id = cur_field->id;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
177 }
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
178 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Info field with id %s not found!", id);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
179 return NULL;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
180 }
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
181
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
182 // info_fields are compared by their group positions
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
183 static gint info_field_compare(gconstpointer a, gconstpointer b, gpointer unused)
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
184 {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
185 return ((info_field *) a)->group_pos - ((info_field *) b)->group_pos;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
186 }
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
187
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
188 static void info_field_free(info_field *i)
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
189 {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
190 g_free(i->value);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
191 g_free(i);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
192 }
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
193
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
194 // Parses the info_template_data above and returns a newly-allocated list
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
195 // containing the desired fields from segments. This list is ordered by
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
196 // group_pos.
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
197 static GList *info_get_group(const gchar **info, const gchar *group_name)
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
198 {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
199 const info_field *cur;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
200 info_field *entry;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
201 GList *group = NULL;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
202
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
203 cur = info_template_data;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
204 while (cur->id != NULL) {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
205 if (g_ascii_strcasecmp(group_name, cur->group) == 0) {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
206 entry = g_memdup(cur, sizeof(info_field));
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
207 entry->value = g_strdup(info[entry->pos]);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
208 group = g_list_insert_sorted_with_data(group, entry, info_field_compare, NULL);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
209 }
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
210 cur++;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
211 }
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
212
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
213 return group;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
214 }
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
215
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
216 // determines if the given text value and choice group require
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
217 // a lookup from the choice arrays
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
218 static gboolean is_valid_index(gchar *value, gint choice)
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
219 {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
220 gint len, i;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
221
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
222 if (choice == 0) return FALSE;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
223 len = strlen(value);
13993
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
224 // the server sends us an ascii index and none of the arrays has more than 99
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
225 // elements
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
226 if (len > 3 || len == 0) return FALSE;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
227 for (i = 0; i < len; i++)
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
228 if (!g_ascii_isdigit(value[i])) return FALSE;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
229 i = atoi(value);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
230 if (i < 0 || i >= choice_sizes[choice]) return FALSE;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
231 return TRUE;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
232 }
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
233
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
234 // formats a field for printing
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
235 static void append_field_to_str(gpointer field, gpointer str)
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
236 {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
237 info_field *f;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
238 gint choice;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
239 gboolean valid_index;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
240 gchar *value;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
241
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
242 f = (info_field *) field;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
243 choice = f->choice;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
244 valid_index = is_valid_index(f->value, choice);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
245 if (choice && valid_index) value = g_strdup(choices[choice][atoi(f->value)]);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
246 else value = qq_to_utf8(f->value, QQ_CHARSET_DEFAULT);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
247 g_string_append_printf((GString *) str, "<b>%s:</b> %s<br />",
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
248 f->title, value);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
249 g_free(value);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
250 info_field_free(f);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
251 }
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
252
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
253 // formats a group of information for printing
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
254 static void append_group_to_str(GString *str, const gchar *group_name, const gchar **info)
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
255 {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
256 GList *group;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
257
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
258 group = info_get_group(info, group_name);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
259 g_string_append_printf(str, "<b>%s</b><br /><br />", (*(info_field *) group->data).group);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
260 g_list_foreach(group, append_field_to_str, str);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
261 g_list_free(group);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
262 g_string_append_printf(str, "<br />");
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
263 }
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
264
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
265 // takes a contact_info struct and outputs the appropriate fields in
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
266 // a printable format for our upcoming call to gaim_notify_userinfo
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
267 static GString *info_to_str(const gchar **info)
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
268 {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
269 GString *info_text;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
270
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
271 info_text = g_string_new("");
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
272 append_group_to_str(info_text, QQ_MAIN_INFO, info);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
273 append_group_to_str(info_text, QQ_EXTRA_INFO, info);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
274 append_group_to_str(info_text, QQ_PERSONAL_INTRO, info);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
275 //if (QQ_DEBUG) append_group_to_str(info_text, QQ_MISC, info);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
276
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
277 return info_text;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
278 }
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
279
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
280 /*************** packets and UI management *****************/
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
281
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
282 // send a packet to get detailed information of uid
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
283 void qq_send_packet_get_info(GaimConnection * gc, guint32 uid, gboolean show_window)
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
284 {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
285 qq_data *qd;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
286 gchar *uid_str;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
287 qq_info_query *query;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
288
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
289 g_return_if_fail(gc != NULL && gc->proto_data != NULL && uid != 0);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
290
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
291 qd = (qq_data *) gc->proto_data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
292 uid_str = g_strdup_printf("%d", uid);
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
293 qq_send_cmd(gc, QQ_CMD_GET_USER_INFO, TRUE, 0, TRUE, (guint8 *) uid_str, strlen(uid_str));
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
294
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
295 query = g_new0(qq_info_query, 1);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
296 query->uid = uid;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
297 query->show_window = show_window;
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
298 query->modify_info = FALSE;
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
299 qd->info_query = g_list_append(qd->info_query, query);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
300
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
301 g_free(uid_str);
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
302 }
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
303
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
304 // set up the fields requesting personal information and send a get_info packet
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
305 // for myself
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
306 void qq_prepare_modify_info(GaimConnection *gc)
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
307 {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
308 qq_data *qd;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
309 GList *ql;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
310 qq_info_query *query;
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
311
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
312 qd = (qq_data *) gc->proto_data;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
313 qq_send_packet_get_info(gc, qd->uid, FALSE);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
314 // traverse backwards so we get the most recent info_query
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
315 for (ql = g_list_last(qd->info_query); ql != NULL; ql = g_list_previous(ql)) {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
316 query = ql->data;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
317 if (query->uid == qd->uid) query->modify_info = TRUE;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
318 }
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
319 }
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
320
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
321 // send packet to modify personal information, and/or change password
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
322 void qq_send_packet_modify_info(GaimConnection *gc, contact_info *info, gchar *new_passwd)
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
323 {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
324 GaimAccount *a;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
325 gchar *old_passwd, *info_field[QQ_CONTACT_FIELDS];
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
326 gint i;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
327 guint8 *raw_data, *cursor, bar;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
328
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
329 g_return_if_fail(gc != NULL && info != NULL);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
330
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
331 a = gc->account;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
332 old_passwd = a->password;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
333 bar = 0x1f;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
334 raw_data = g_newa(guint8, MAX_PACKET_SIZE - 128);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
335 cursor = raw_data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
336
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
337 g_memmove(info_field, info, sizeof(gchar *) * QQ_CONTACT_FIELDS);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
338
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
339 if (new_passwd == NULL || strlen(new_passwd) == 0)
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
340 create_packet_b(raw_data, &cursor, bar);
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
341 else { // we're gonna change passwd
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
342 create_packet_data(raw_data, &cursor, (guint8 *) old_passwd, strlen(old_passwd));
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
343 create_packet_b(raw_data, &cursor, bar);
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
344 create_packet_data(raw_data, &cursor, (guint8 *) new_passwd, strlen(new_passwd));
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
345 }
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
346
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
347 // important!, skip the first uid entry
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
348 for (i = 1; i < QQ_CONTACT_FIELDS; i++) {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
349 create_packet_b(raw_data, &cursor, bar);
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
350 create_packet_data(raw_data, &cursor, (guint8 *) info_field[i], strlen(info_field[i]));
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
351 }
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
352 create_packet_b(raw_data, &cursor, bar);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
353
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
354 qq_send_cmd(gc, QQ_CMD_UPDATE_INFO, TRUE, 0, TRUE, raw_data, cursor - raw_data);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
355
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
356 }
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
357
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
358 static void modify_info_cancel_cb(modify_info_data *mid)
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
359 {
13993
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
360 qq_data *qd;
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
361
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
362 qd = (qq_data *) mid->gc->proto_data;
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
363 qd->modifying_info = FALSE;
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
364
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
365 g_list_free(mid->misc);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
366 g_free(mid);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
367 }
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
368
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
369 // runs through all of the fields in the modify info UI and put
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
370 // their values into the outgoing packet
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
371 static void parse_field(gpointer field, gpointer outgoing_info)
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
372 {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
373 GaimRequestField *f;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
374 gchar **segments, *value;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
375 const info_field *ft;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
376 const gchar *id;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
377
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
378 f = (GaimRequestField *) field;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
379 segments = (gchar **) outgoing_info;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
380 id = gaim_request_field_get_id(f);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
381 ft = info_field_get_template(id);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
382 if (ft->choice && !ft->customizable)
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
383 value = g_strdup_printf("%d", gaim_request_field_choice_get_value(f));
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
384 else {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
385 value = (gchar *) gaim_request_field_string_get_value(f);
13993
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
386 if (value == NULL) value = g_strdup("-");
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
387 else value = utf8_to_qq(value, QQ_CHARSET_DEFAULT);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
388 }
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
389 segments[ft->pos] = value;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
390 }
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
391
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
392 // dumps the uneditable information straight into the outgoing packet
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
393 static void parse_misc_field(gpointer field, gpointer outgoing_info)
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
394 {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
395 info_field *f;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
396 gchar **segments;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
397
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
398 f = (info_field *) field;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
399 segments = (gchar **) outgoing_info;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
400 segments[f->pos] = g_strdup(f->value);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
401 info_field_free(f);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
402 }
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
403
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
404 // runs through all of the information fields and copies them into an
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
405 // outgoing packet, then sends that packet
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
406 static void modify_info_ok_cb(modify_info_data *mid, GaimRequestFields *fields)
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
407 {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
408 GaimConnection *gc;
13993
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
409 qq_data *qd;
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
410 GList *list, *groups, *group_node;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
411 gchar *info_field[QQ_CONTACT_FIELDS];
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
412 contact_info *info;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
413 gint i;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
414
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
415 gc = mid->gc;
13993
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
416 qd = (qq_data *) gc->proto_data;
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
417 qd->modifying_info = FALSE;
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
418 list = mid->misc;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
419 g_list_foreach(list, parse_misc_field, info_field);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
420 g_list_free(list);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
421 groups = gaim_request_fields_get_groups(fields);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
422 while(groups) {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
423 group_node = groups;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
424 list = gaim_request_field_group_get_fields(group_node->data);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
425 g_list_foreach(list, parse_field, info_field);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
426 groups = g_list_remove_link(groups, group_node);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
427 }
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
428 info = (contact_info *) info_field;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
429
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
430 qq_send_packet_modify_info(gc, info, NULL);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
431 g_free(mid);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
432 for (i = 0; i < QQ_CONTACT_FIELDS; i++)
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
433 g_free(info_field[i]);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
434 }
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
435
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
436 // Sets up the display for one group of information. This includes
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
437 // managing which fields in the UI should be textfields and
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
438 // which choices, and also mapping ints to choice values when appropriate.
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
439 static void setup_group(gpointer field, gpointer group)
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
440 {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
441 info_field *f;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
442 GaimRequestFieldGroup *g;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
443 GaimRequestField *rf;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
444 gint choice, index, j;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
445 gboolean customizable, valid_index, multiline;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
446 gchar *id, *value;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
447
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
448 f = (info_field *) field;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
449 g = (GaimRequestFieldGroup *) group;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
450 choice = f->choice;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
451 customizable = f->customizable;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
452 id = f->id;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
453 valid_index = TRUE;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
454
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
455 if (!choice || customizable) {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
456 valid_index = is_valid_index(f->value, choice);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
457 multiline = id == "intro";
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
458 if (valid_index) {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
459 index = atoi(f->value);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
460 value = (gchar *) choices[choice][index];
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
461 } else value = qq_to_utf8(f->value, QQ_CHARSET_DEFAULT);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
462 rf = gaim_request_field_string_new(id, f->title, value, multiline);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
463 } else {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
464 index = atoi(f->value);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
465 value = (gchar *) choices[choice][index];
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
466 rf = gaim_request_field_choice_new(id, f->title, index);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
467 j = 0;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
468 while(choices[choice][j] != NULL)
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
469 gaim_request_field_choice_add(rf, choices[choice][j++]);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
470 }
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
471 gaim_request_field_group_add_field(g, rf);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
472 if (!valid_index) g_free(value);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
473 info_field_free(f);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
474 }
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
475
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
476 // Takes the info returned by a get_info packet for the user and sets up
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
477 // a form using those values and the info_template.
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
478 static void create_modify_info_dialogue(GaimConnection *gc, const gchar **info)
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
479 {
13993
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
480 qq_data *qd;
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
481 GaimRequestFields *fields;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
482 GaimRequestFieldGroup *group;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
483 GaimRequestField *field;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
484 GList *group_list;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
485 modify_info_data *mid;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
486 gint i;
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
487
13993
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
488 // so we only have one dialog open at a time
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
489 qd = (qq_data *) gc->proto_data;
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
490 if (!qd->modifying_info) {
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
491 qd->modifying_info = TRUE;
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
492
13993
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
493 fields = gaim_request_fields_new();
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
494
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
495 // we only care about the first 3 groups, not the miscellaneous stuff
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
496 for (i = 0; i < 3; i++) {
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
497 group = gaim_request_field_group_new(info_group_headers[i]);
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
498 gaim_request_fields_add_group(fields, group);
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
499 group_list = info_get_group(info, info_group_headers[i]);
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
500 g_list_foreach(group_list, setup_group, group);
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
501 g_list_free(group_list);
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
502 }
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
503
13993
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
504 //set this manually here instead of generating a new template column
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
505 field = gaim_request_fields_get_field(fields, "uid");
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
506 gaim_request_field_string_set_editable(field, FALSE);
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
507
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
508 //we need to pass the info that doesn't get modified as aux data
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
509 //because we'll still need it when we send the modify_info packet
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
510 mid = g_new0(modify_info_data, 1);
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
511 mid->gc = gc;
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
512 mid->misc = info_get_group(info, info_group_headers[3]);
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
513
13993
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
514 gaim_request_fields(gc, _("Modify my information"),
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
515 _("Modify my information"), NULL, fields,
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
516 _("Update my information"), G_CALLBACK(modify_info_ok_cb),
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
517 _("Cancel"), G_CALLBACK(modify_info_cancel_cb),
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
518 mid);
13993
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
519 }
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
520 }
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
521
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
522 // process the reply of modify_info packet
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
523 void qq_process_modify_info_reply(guint8 *buf, gint buf_len, GaimConnection *gc)
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
524 {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
525 qq_data *qd;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
526 gint len;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
527 guint8 *data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
528
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
529 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
530 g_return_if_fail(buf != NULL && buf_len != 0);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
531
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
532 qd = (qq_data *) gc->proto_data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
533 len = buf_len;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
534 data = g_newa(guint8, len);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
535
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
536 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
13993
e6977f9435a1 [gaim-migrate @ 16570]
Mark Huetsch <markhuetsch>
parents: 13989
diff changeset
537 data[len] = '\0';
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
538 if (qd->uid == atoi((gchar *) data)) { // return should be my uid
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
539 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Update info ACK OK\n");
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
540 gaim_notify_info(gc, NULL, _("Your information has been updated"), NULL);
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
541 }
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
542 } else
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
543 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt modify info reply\n");
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
544
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
545 }
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
546
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
547 // after getting info or modify myself, refresh the buddy list accordingly
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
548 void qq_refresh_buddy_and_myself(contact_info *info, GaimConnection *gc)
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
549 {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
550 GaimBuddy *b;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
551 qq_data *qd;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
552 qq_buddy *q_bud;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
553 gchar *alias_utf8;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
554
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
555 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
556 qd = (qq_data *) gc->proto_data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
557
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
558 alias_utf8 = qq_to_utf8(info->nick, QQ_CHARSET_DEFAULT);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
559 if (qd->uid == strtol(info->uid, NULL, 10)) { // it is me
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
560 qd->my_icon = strtol(info->face, NULL, 10);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
561 if (alias_utf8 != NULL)
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
562 gaim_account_set_alias(gc->account, alias_utf8);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
563 }
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
564 // update buddy list (including myself, if myself is the buddy)
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
565 b = gaim_find_buddy(gc->account, uid_to_gaim_name(strtol(info->uid, NULL, 10)));
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
566 q_bud = (b == NULL) ? NULL : (qq_buddy *) b->proto_data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
567 if (q_bud != NULL) { // I have this buddy
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
568 q_bud->age = strtol(info->age, NULL, 10);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
569 q_bud->gender = strtol(info->gender, NULL, 10);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
570 q_bud->icon = strtol(info->face, NULL, 10);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
571 if (alias_utf8 != NULL)
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
572 q_bud->nickname = g_strdup(alias_utf8);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
573 qq_update_buddy_contact(gc, q_bud);
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
574 }
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
575 g_free(alias_utf8);
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
576 }
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
577
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
578 // process reply to get_info packet
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
579 void qq_process_get_info_reply(guint8 *buf, gint buf_len, GaimConnection *gc)
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
580 {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
581 gint len;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
582 guint8 *data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
583 gchar **segments;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
584 qq_info_query *query;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
585 qq_data *qd;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
586 contact_info *info;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
587 GList *list, *query_list;
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
588 GString *info_text;
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
589
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
590 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
591 g_return_if_fail(buf != NULL && buf_len != 0);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
592
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
593 qd = (qq_data *) gc->proto_data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
594 list = query_list = NULL;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
595 len = buf_len;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
596 data = g_newa(guint8, len);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
597 info = NULL;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
598
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
599 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
600 if (NULL == (segments = split_data(data, len, "\x1e", QQ_CONTACT_FIELDS)))
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
601 return;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
602
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
603 info = (contact_info *) segments;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
604 qq_refresh_buddy_and_myself(info, gc);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
605
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
606 query_list = qd->info_query;
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
607 // ensure we're processing the right query
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
608 while (query_list) {
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
609 query = (qq_info_query *) query_list->data;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
610 if (query->uid == atoi(info->uid)) {
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
611 if (query->show_window) {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
612 info_text = info_to_str((const gchar **) segments);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
613 gaim_notify_userinfo(gc, info->uid, info_text->str, NULL, NULL);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
614 g_string_free(info_text, TRUE);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
615 } else if (query->modify_info) {
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
616 create_modify_info_dialogue(gc, (const gchar **) segments);
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
617 }
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
618 qd->info_query = g_list_remove(qd->info_query, qd->info_query->data);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
619 g_free(query);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
620 break;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
621 }
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
622 query_list = query_list->next;
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
623 }
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
624
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
625 g_strfreev(segments);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
626 } else
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
627 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt get info reply\n");
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
628
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
629 }
13870
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
630
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
631 void qq_info_query_free(qq_data * qd)
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
632 {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
633 gint i;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
634 qq_info_query *p;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
635
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
636 g_return_if_fail(qd != NULL);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
637
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
638 i = 0;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
639 while (qd->info_query != NULL) {
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
640 p = (qq_info_query *) (qd->info_query->data);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
641 qd->info_query = g_list_remove(qd->info_query, p);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
642 g_free(p);
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
643 i++;
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
644 }
983fd420e86b [gaim-migrate @ 16340]
Mark Huetsch <markhuetsch>
parents:
diff changeset
645 gaim_debug(GAIM_DEBUG_INFO, "QQ", "%d info queries are freed!\n", i);
13989
16102b9c5c4a [gaim-migrate @ 16562]
Mark Huetsch <markhuetsch>
parents: 13870
diff changeset
646 }