comparison 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
comparison
equal deleted inserted replaced
13992:0567de116699 13993:e6977f9435a1
105 "龙", "蛇", "马", "羊", "猴", 105 "龙", "蛇", "马", "羊", "猴",
106 "鸡", "狗", "猪", NULL 106 "鸡", "狗", "猪", NULL
107 }; 107 };
108 108
109 static const gchar *blood_types[] = { 109 static const gchar *blood_types[] = {
110 "其它", "A型", "B型", "O型", "AB型", NULL 110 "-", N_("A"), N_("B"), N_("O"), N_("AB"), N_("Other"), NULL
111 }; 111 };
112 112
113 static const gchar *genders[] = { 113 static const gchar *genders[] = {
114 N_("Male"), 114 N_("Male"),
115 N_("Female"), 115 N_("Female"),
136 "学生", "工程师", "政府部门", "教育业", "服务行业", 136 "学生", "工程师", "政府部门", "教育业", "服务行业",
137 "老板", "计算机业", "退休", "金融业", 137 "老板", "计算机业", "退休", "金融业",
138 "销售/广告/市场", NULL 138 "销售/广告/市场", NULL
139 }; 139 };
140 140
141 static const gint choice_sizes[] = { 0, 13, 13, 5, 2, 7, 34, 15 }; 141 static const gint choice_sizes[] = { 0, 13, 13, 6, 2, 7, 34, 15 };
142 142
143 143
144 static const gchar *info_group_headers[] = { 144 static const gchar *info_group_headers[] = {
145 QQ_MAIN_INFO, 145 QQ_MAIN_INFO,
146 QQ_EXTRA_INFO, 146 QQ_EXTRA_INFO,
219 { 219 {
220 gint len, i; 220 gint len, i;
221 221
222 if (choice == 0) return FALSE; 222 if (choice == 0) return FALSE;
223 len = strlen(value); 223 len = strlen(value);
224 // the server sends us an ascii index and none of arrays has more than 99 224 // the server sends us an ascii index and none of the arrays has more than 99
225 // elements 225 // elements
226 if (len > 3 || len == 0) return FALSE; 226 if (len > 3 || len == 0) return FALSE;
227 for (i = 0; i < len; i++) 227 for (i = 0; i < len; i++)
228 if (!g_ascii_isdigit(value[i])) return FALSE; 228 if (!g_ascii_isdigit(value[i])) return FALSE;
229 i = atoi(value); 229 i = atoi(value);
355 355
356 } 356 }
357 357
358 static void modify_info_cancel_cb(modify_info_data *mid) 358 static void modify_info_cancel_cb(modify_info_data *mid)
359 { 359 {
360 qq_data *qd;
361
362 qd = (qq_data *) mid->gc->proto_data;
363 qd->modifying_info = FALSE;
364
360 g_list_free(mid->misc); 365 g_list_free(mid->misc);
361 g_free(mid); 366 g_free(mid);
362 } 367 }
363 368
364 // runs through all of the fields in the modify info UI and put 369 // runs through all of the fields in the modify info UI and put
376 ft = info_field_get_template(id); 381 ft = info_field_get_template(id);
377 if (ft->choice && !ft->customizable) 382 if (ft->choice && !ft->customizable)
378 value = g_strdup_printf("%d", gaim_request_field_choice_get_value(f)); 383 value = g_strdup_printf("%d", gaim_request_field_choice_get_value(f));
379 else { 384 else {
380 value = (gchar *) gaim_request_field_string_get_value(f); 385 value = (gchar *) gaim_request_field_string_get_value(f);
381 if (value == NULL) value = g_strdup(""); 386 if (value == NULL) value = g_strdup("-");
382 else value = utf8_to_qq(value, QQ_CHARSET_DEFAULT); 387 else value = utf8_to_qq(value, QQ_CHARSET_DEFAULT);
383 } 388 }
384 segments[ft->pos] = value; 389 segments[ft->pos] = value;
385 } 390 }
386 391
399 // runs through all of the information fields and copies them into an 404 // runs through all of the information fields and copies them into an
400 // outgoing packet, then sends that packet 405 // outgoing packet, then sends that packet
401 static void modify_info_ok_cb(modify_info_data *mid, GaimRequestFields *fields) 406 static void modify_info_ok_cb(modify_info_data *mid, GaimRequestFields *fields)
402 { 407 {
403 GaimConnection *gc; 408 GaimConnection *gc;
409 qq_data *qd;
404 GList *list, *groups, *group_node; 410 GList *list, *groups, *group_node;
405 gchar *info_field[QQ_CONTACT_FIELDS]; 411 gchar *info_field[QQ_CONTACT_FIELDS];
406 contact_info *info; 412 contact_info *info;
407 gint i; 413 gint i;
408 414
409 gc = mid->gc; 415 gc = mid->gc;
416 qd = (qq_data *) gc->proto_data;
417 qd->modifying_info = FALSE;
410 list = mid->misc; 418 list = mid->misc;
411 g_list_foreach(list, parse_misc_field, info_field); 419 g_list_foreach(list, parse_misc_field, info_field);
412 g_list_free(list); 420 g_list_free(list);
413 groups = gaim_request_fields_get_groups(fields); 421 groups = gaim_request_fields_get_groups(fields);
414 while(groups) { 422 while(groups) {
467 475
468 // Takes the info returned by a get_info packet for the user and sets up 476 // Takes the info returned by a get_info packet for the user and sets up
469 // a form using those values and the info_template. 477 // a form using those values and the info_template.
470 static void create_modify_info_dialogue(GaimConnection *gc, const gchar **info) 478 static void create_modify_info_dialogue(GaimConnection *gc, const gchar **info)
471 { 479 {
480 qq_data *qd;
472 GaimRequestFields *fields; 481 GaimRequestFields *fields;
473 GaimRequestFieldGroup *group; 482 GaimRequestFieldGroup *group;
474 GaimRequestField *field; 483 GaimRequestField *field;
475 GList *group_list; 484 GList *group_list;
476 modify_info_data *mid; 485 modify_info_data *mid;
477 gint i; 486 gint i;
478 487
479 fields = gaim_request_fields_new(); 488 // so we only have one dialog open at a time
489 qd = (qq_data *) gc->proto_data;
490 if (!qd->modifying_info) {
491 qd->modifying_info = TRUE;
492
493 fields = gaim_request_fields_new();
480 494
481 // we only care about the first 3 groups, not the miscellaneous stuff 495 // we only care about the first 3 groups, not the miscellaneous stuff
482 for (i = 0; i < 3; i++) { 496 for (i = 0; i < 3; i++) {
483 group = gaim_request_field_group_new(info_group_headers[i]); 497 group = gaim_request_field_group_new(info_group_headers[i]);
484 gaim_request_fields_add_group(fields, group); 498 gaim_request_fields_add_group(fields, group);
485 group_list = info_get_group(info, info_group_headers[i]); 499 group_list = info_get_group(info, info_group_headers[i]);
486 g_list_foreach(group_list, setup_group, group); 500 g_list_foreach(group_list, setup_group, group);
487 g_list_free(group_list); 501 g_list_free(group_list);
488 } 502 }
489 503
490 //set this manually here instead of generating a new template column 504 //set this manually here instead of generating a new template column
491 field = gaim_request_fields_get_field(fields, "uid"); 505 field = gaim_request_fields_get_field(fields, "uid");
492 gaim_request_field_string_set_editable(field, FALSE); 506 gaim_request_field_string_set_editable(field, FALSE);
493 507
494 //we need to pass the info that doesn't get modified as aux data 508 //we need to pass the info that doesn't get modified as aux data
495 //because we'll still need it when we send the modify_info packet 509 //because we'll still need it when we send the modify_info packet
496 mid = g_new0(modify_info_data, 1); 510 mid = g_new0(modify_info_data, 1);
497 mid->gc = gc; 511 mid->gc = gc;
498 mid->misc = info_get_group(info, info_group_headers[3]); 512 mid->misc = info_get_group(info, info_group_headers[3]);
499 513
500 gaim_request_fields(gc, _("Modify my information"), 514 gaim_request_fields(gc, _("Modify my information"),
501 _("Modify my information"), NULL, fields, 515 _("Modify my information"), NULL, fields,
502 _("Update my information"), G_CALLBACK(modify_info_ok_cb), 516 _("Update my information"), G_CALLBACK(modify_info_ok_cb),
503 _("Cancel"), G_CALLBACK(modify_info_cancel_cb), 517 _("Cancel"), G_CALLBACK(modify_info_cancel_cb),
504 mid); 518 mid);
519 }
505 } 520 }
506 521
507 // process the reply of modify_info packet 522 // process the reply of modify_info packet
508 void qq_process_modify_info_reply(guint8 *buf, gint buf_len, GaimConnection *gc) 523 void qq_process_modify_info_reply(guint8 *buf, gint buf_len, GaimConnection *gc)
509 { 524 {
517 qd = (qq_data *) gc->proto_data; 532 qd = (qq_data *) gc->proto_data;
518 len = buf_len; 533 len = buf_len;
519 data = g_newa(guint8, len); 534 data = g_newa(guint8, len);
520 535
521 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) { 536 if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
537 data[len] = '\0';
522 if (qd->uid == atoi((gchar *) data)) { // return should be my uid 538 if (qd->uid == atoi((gchar *) data)) { // return should be my uid
523 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Update info ACK OK\n"); 539 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Update info ACK OK\n");
524 gaim_notify_info(gc, NULL, _("Your information has been updated"), NULL); 540 gaim_notify_info(gc, NULL, _("Your information has been updated"), NULL);
525 } 541 }
526 } else 542 } else
556 q_bud->nickname = g_strdup(alias_utf8); 572 q_bud->nickname = g_strdup(alias_utf8);
557 qq_update_buddy_contact(gc, q_bud); 573 qq_update_buddy_contact(gc, q_bud);
558 } 574 }
559 g_free(alias_utf8); 575 g_free(alias_utf8);
560 } 576 }
561
562 // XXX When we don't have any immediate response, we send duplicate get info packets
563 // to the server. If the server ends up responding to multiple packets, we get multiple
564 // modify info dialogues, which is annoying. Fix this.
565 577
566 // process reply to get_info packet 578 // process reply to get_info packet
567 void qq_process_get_info_reply(guint8 *buf, gint buf_len, GaimConnection *gc) 579 void qq_process_get_info_reply(guint8 *buf, gint buf_len, GaimConnection *gc)
568 { 580 {
569 gint len; 581 gint len;