comparison src/protocols/gg/gg.c @ 13640:d12bbe6da705

[gaim-migrate @ 16038] * Changed signatures of some of the search results notify API functions. * GG PRPL: Support parallel public directory searches. committer: Tailor Script <tailor@pidgin.im>
author Bartoz Oler <bartosz@pidgin.im>
date Sun, 16 Apr 2006 10:10:55 +0000
parents fa7313d125ac
children 87d41308a0eb
comparison
equal deleted inserted replaced
13639:43c7e892d8bf 13640:d12bbe6da705
502 502
503 /* ----- PUBLIC DIRECTORY SEARCH ---------------------------------------- */ 503 /* ----- PUBLIC DIRECTORY SEARCH ---------------------------------------- */
504 504
505 /* 505 /*
506 */ 506 */
507 /* static void ggp_callback_show_next(GaimConnection *gc, GList *row) {{{ */ 507 /* static void ggp_callback_show_next(GaimConnection *gc, GList *row, void *user_data) {{{ */
508 static void ggp_callback_show_next(GaimConnection *gc, GList *row) 508 static void ggp_callback_show_next(GaimConnection *gc, GList *row, void *user_data)
509 { 509 {
510 GGPInfo *info = gc->proto_data; 510 GGPInfo *info = gc->proto_data;
511 511 GGPSearchForm *form = user_data;
512 g_free(info->search_form->offset); 512 guint32 seq;
513 info->search_form->offset = g_strdup(info->search_form->last_uin); 513
514 ggp_search_start(gc, info->search_form); 514 g_free(form->offset);
515 } 515 form->offset = g_strdup(form->last_uin);
516 /* }}} */ 516
517 517 ggp_search_remove(info->searches, form->seq);
518 /* 518
519 */ 519 seq = ggp_search_start(gc, form);
520 /* static void ggp_callback_add_buddy(GaimConnection *gc, GList *row) {{{ */ 520 ggp_search_add(info->searches, seq, form);
521 static void ggp_callback_add_buddy(GaimConnection *gc, GList *row) 521 }
522 /* }}} */
523
524 /*
525 */
526 /* static void ggp_callback_add_buddy(GaimConnection *gc, GList *row, void *user_data) {{{ */
527 static void ggp_callback_add_buddy(GaimConnection *gc, GList *row, void *user_data)
522 { 528 {
523 gaim_blist_request_add_buddy(gaim_connection_get_account(gc), 529 gaim_blist_request_add_buddy(gaim_connection_get_account(gc),
524 g_list_nth_data(row, 0), NULL, NULL); 530 g_list_nth_data(row, 0), NULL, NULL);
525 } 531 }
526 /* }}} */ 532 /* }}} */
530 /* static void ggp_callback_find_buddies(GaimConnection *gc, GaimRequestFields *fields) {{{ */ 536 /* static void ggp_callback_find_buddies(GaimConnection *gc, GaimRequestFields *fields) {{{ */
531 static void ggp_callback_find_buddies(GaimConnection *gc, GaimRequestFields *fields) 537 static void ggp_callback_find_buddies(GaimConnection *gc, GaimRequestFields *fields)
532 { 538 {
533 GGPInfo *info = gc->proto_data; 539 GGPInfo *info = gc->proto_data;
534 GGPSearchForm *form; 540 GGPSearchForm *form;
535 541 guint32 seq;
536 form = ggp_search_form_new(); 542
537 info->search_form = form; 543 form = ggp_search_form_new(GGP_SEARCH_TYPE_FULL);
538 544
545 form->user_data = info;
539 form->lastname = charset_convert( 546 form->lastname = charset_convert(
540 gaim_request_fields_get_string(fields, "lastname"), 547 gaim_request_fields_get_string(fields, "lastname"),
541 "UTF-8", "CP1250"); 548 "UTF-8", "CP1250");
542 form->firstname = charset_convert( 549 form->firstname = charset_convert(
543 gaim_request_fields_get_string(fields, "firstname"), 550 gaim_request_fields_get_string(fields, "firstname"),
567 form->active = gaim_request_fields_get_bool(fields, "active") 574 form->active = gaim_request_fields_get_bool(fields, "active")
568 ? g_strdup(GG_PUBDIR50_ACTIVE_TRUE) : NULL; 575 ? g_strdup(GG_PUBDIR50_ACTIVE_TRUE) : NULL;
569 576
570 form->offset = g_strdup("0"); 577 form->offset = g_strdup("0");
571 578
572 ggp_search_start(gc, form); 579 seq = ggp_search_start(gc, form);
580 ggp_search_add(info->searches, seq, form);
573 } 581 }
574 /* }}} */ 582 /* }}} */
575 583
576 /* 584 /*
577 */ 585 */
578 /* static void ggp_find_buddies(GaimPluginAction *action) {{{ */ 586 /* static void ggp_find_buddies(GaimPluginAction *action) {{{ */
579 static void ggp_find_buddies(GaimPluginAction *action) 587 static void ggp_find_buddies(GaimPluginAction *action)
580 { 588 {
581 GaimConnection *gc = (GaimConnection *)action->context; 589 GaimConnection *gc = (GaimConnection *)action->context;
582 GGPInfo *info = gc->proto_data;
583 590
584 GaimRequestFields *fields; 591 GaimRequestFields *fields;
585 GaimRequestFieldGroup *group; 592 GaimRequestFieldGroup *group;
586 GaimRequestField *field; 593 GaimRequestField *field;
587
588 if (info->search_form != NULL) {
589 gaim_notify_error(gc, NULL,
590 _("Unable to initiate a new search"),
591 _("You have a pending search. Please wait for it to finish."));
592 return;
593 }
594 594
595 fields = gaim_request_fields_new(); 595 fields = gaim_request_fields_new();
596 group = gaim_request_field_group_new(NULL); 596 group = gaim_request_field_group_new(NULL);
597 gaim_request_fields_add_group(fields, group); 597 gaim_request_fields_add_group(fields, group);
598 598
945 } 945 }
946 /* }}} */ 946 /* }}} */
947 947
948 /* 948 /*
949 */ 949 */
950 /* static void ggp_sr_close_cb(GaimAccount *account) {{{ */ 950 /* static void ggp_sr_close_cb(GGPSearchForm *form) {{{ */
951 static void ggp_sr_close_cb(GaimAccount *account) 951 static void ggp_sr_close_cb(GGPSearchForm *form)
952 { 952 {
953 GaimConnection *gc = gaim_account_get_connection(account); 953 GGPInfo *info = form->user_data;
954 GGPInfo *info = gc->proto_data; 954
955 GGPSearchForm *f; 955 ggp_search_remove(info->searches, form->seq);
956 956 ggp_search_form_destroy(form);
957 info->searchresults_window = NULL;
958
959 f = info->search_form;
960 g_free(f->uin);
961 g_free(f->lastname);
962 g_free(f->firstname);
963 g_free(f->nickname);
964 g_free(f->city);
965 g_free(f->birthyear);
966 g_free(f->gender);
967 g_free(f->active);
968 g_free(f->offset);
969 g_free(f->last_uin);
970 g_free(f);
971
972 info->search_form = NULL;
973 } 957 }
974 /* }}} */ 958 /* }}} */
975 959
976 /* 960 /*
977 */ 961 */
978 /* static void ggp_pubdir_reply_handler(GaimConnection *gc, gg_pubdir50_t req) {{{ */ 962 /* static void ggp_pubdir_reply_handler(GaimConnection *gc, gg_pubdir50_t req) {{{ */
979 static void ggp_pubdir_reply_handler(GaimConnection *gc, gg_pubdir50_t req) 963 static void ggp_pubdir_reply_handler(GaimConnection *gc, gg_pubdir50_t req)
980 { 964 {
981 GaimAccount *account = gaim_connection_get_account(gc);
982 GGPInfo *info = gc->proto_data; 965 GGPInfo *info = gc->proto_data;
983 GaimNotifySearchResults *results; 966 GaimNotifySearchResults *results;
984 GaimNotifySearchColumn *column; 967 GaimNotifySearchColumn *column;
968 GGPSearchForm *form;
985 int res_count = 0; 969 int res_count = 0;
986 int start; 970 int start;
987 int i; 971 int i;
972 guint32 seq;
973
974 seq = gg_pubdir50_seq(req);
975 form = ggp_search_get(info->searches, seq);
976
977 if (form == NULL) {
978 /*
979 * this can happen when user will request more results
980 * and close the results window before they arrive.
981 */
982 gaim_debug_error("gg", "No search form available for this search!\n");
983 return;
984 }
988 985
989 res_count = gg_pubdir50_count(req); 986 res_count = gg_pubdir50_count(req);
990 if (res_count < 1) { 987 if (res_count < 1) {
991 gaim_debug_info("gg", "GG_EVENT_PUBDIR50_SEARCH_REPLY: Nothing found\n"); 988 gaim_debug_info("gg", "GG_EVENT_PUBDIR50_SEARCH_REPLY: Nothing found\n");
992 gaim_notify_error(gc, NULL, 989 gaim_notify_error(gc, NULL,
993 _("No matching users found"), 990 _("No matching users found"),
994 _("There are no users matching your search criteria.")); 991 _("There are no users matching your search criteria."));
995 ggp_sr_close_cb(account); 992 ggp_sr_close_cb(form);
996 return; 993 return;
997 } 994 }
998 res_count = (res_count > 20) ? 20 : res_count; 995 res_count = (res_count > 20) ? 20 : res_count;
999 996
1000 results = gaim_notify_searchresults_new(); 997 results = gaim_notify_searchresults_new();
1003 gaim_debug_error("gg", "ggp_pubdir_reply_handler: " 1000 gaim_debug_error("gg", "ggp_pubdir_reply_handler: "
1004 "Unable to display the search results.\n"); 1001 "Unable to display the search results.\n");
1005 gaim_notify_error(gc, NULL, 1002 gaim_notify_error(gc, NULL,
1006 _("Unable to display the search results."), 1003 _("Unable to display the search results."),
1007 NULL); 1004 NULL);
1008 ggp_sr_close_cb(account); 1005 ggp_sr_close_cb(form);
1009 return; 1006 return;
1010 } 1007 }
1011 1008
1012 column = gaim_notify_searchresults_column_new(_("UIN")); 1009 column = gaim_notify_searchresults_column_new(_("UIN"));
1013 gaim_notify_searchresults_column_add(results, column); 1010 gaim_notify_searchresults_column_add(results, column);
1047 (birth && strncmp(birth, "0", 1)) ? birth : g_strdup("-")); 1044 (birth && strncmp(birth, "0", 1)) ? birth : g_strdup("-"));
1048 1045
1049 gaim_notify_searchresults_row_add(results, row); 1046 gaim_notify_searchresults_row_add(results, row);
1050 1047
1051 if (i == res_count - 1) { 1048 if (i == res_count - 1) {
1052 g_free(info->search_form->last_uin); 1049 g_free(form->last_uin);
1053 info->search_form->last_uin = ggp_search_get_result(req, i, 1050 form->last_uin = ggp_search_get_result(req, i, GG_PUBDIR50_UIN);
1054 GG_PUBDIR50_UIN);
1055 } 1051 }
1056 } 1052 }
1057 1053
1058 gaim_notify_searchresults_button_add(results, GAIM_NOTIFY_BUTTON_CONTINUE, 1054 gaim_notify_searchresults_button_add(results, GAIM_NOTIFY_BUTTON_CONTINUE,
1059 ggp_callback_show_next); 1055 ggp_callback_show_next);
1060 gaim_notify_searchresults_button_add(results, GAIM_NOTIFY_BUTTON_ADD, 1056 gaim_notify_searchresults_button_add(results, GAIM_NOTIFY_BUTTON_ADD,
1061 ggp_callback_add_buddy); 1057 ggp_callback_add_buddy);
1062 if (info->searchresults_window == NULL) { 1058 if (form->window == NULL) {
1063 void *h = gaim_notify_searchresults(gc, 1059 void *h = gaim_notify_searchresults(gc,
1064 _("Gadu-Gadu Public Directory"), 1060 _("Gadu-Gadu Public Directory"),
1065 _("Search results"), NULL, results, 1061 _("Search results"), NULL, results,
1066 (GaimNotifyCloseCallback)ggp_sr_close_cb, 1062 (GaimNotifyCloseCallback)ggp_sr_close_cb,
1067 account); 1063 form);
1068 1064
1069 if (h == NULL) { 1065 if (h == NULL) {
1070 gaim_debug_error("gg", "ggp_pubdir_reply_handler: " 1066 gaim_debug_error("gg", "ggp_pubdir_reply_handler: "
1071 "Unable to display the search results.\n"); 1067 "Unable to display the search results.\n");
1072 gaim_notify_error(gc, NULL, 1068 gaim_notify_error(gc, NULL,
1073 _("Unable to display the search results."), 1069 _("Unable to display the search results."),
1074 NULL); 1070 NULL);
1075 ggp_sr_close_cb(account); 1071 ggp_sr_close_cb(form);
1076 return; 1072 return;
1077 } 1073 }
1078 1074
1079 info->searchresults_window = h; 1075 form->window = h;
1080 } else { 1076 } else {
1081 gaim_notify_searchresults_new_rows(gc, results, 1077 gaim_notify_searchresults_new_rows(gc, results, form->window);
1082 info->searchresults_window, NULL);
1083 } 1078 }
1084 } 1079 }
1085 /* }}} */ 1080 /* }}} */
1086 1081
1087 /** 1082 /**
1558 glp = g_new0(struct gg_login_params, 1); 1553 glp = g_new0(struct gg_login_params, 1);
1559 info = g_new0(GGPInfo, 1); 1554 info = g_new0(GGPInfo, 1);
1560 1555
1561 /* Probably this should be moved to *_new() function. */ 1556 /* Probably this should be moved to *_new() function. */
1562 info->session = NULL; 1557 info->session = NULL;
1563 info->searchresults_window = NULL;
1564 info->chats = NULL; 1558 info->chats = NULL;
1565 info->chats_count = 0; 1559 info->chats_count = 0;
1566 info->token = NULL; 1560 info->token = NULL;
1561 info->searches = ggp_search_new();
1567 1562
1568 gc->proto_data = info; 1563 gc->proto_data = info;
1569 1564
1570 glp->uin = ggp_get_uin(account); 1565 glp->uin = ggp_get_uin(account);
1571 glp->password = (char *)gaim_account_get_password(account); 1566 glp->password = (char *)gaim_account_get_password(account);
1604 if (info->session != NULL) { 1599 if (info->session != NULL) {
1605 ggp_set_status(account, status); 1600 ggp_set_status(account, status);
1606 gg_logoff(info->session); 1601 gg_logoff(info->session);
1607 gg_free_session(info->session); 1602 gg_free_session(info->session);
1608 } 1603 }
1604
1605 ggp_search_destroy(info->searches);
1609 g_free(info); 1606 g_free(info);
1610 gc->proto_data = NULL; 1607 gc->proto_data = NULL;
1611 } 1608 }
1612 1609
1613 if (gc->inpa > 0) 1610 if (gc->inpa > 0)
1649 /* static void ggp_get_info(GaimConnection *gc, const char *name) { {{{ */ 1646 /* static void ggp_get_info(GaimConnection *gc, const char *name) { {{{ */
1650 static void ggp_get_info(GaimConnection *gc, const char *name) 1647 static void ggp_get_info(GaimConnection *gc, const char *name)
1651 { 1648 {
1652 GGPInfo *info = gc->proto_data; 1649 GGPInfo *info = gc->proto_data;
1653 GGPSearchForm *form; 1650 GGPSearchForm *form;
1654 1651 guint32 seq;
1655 if (info->search_form != NULL) { 1652
1656 gaim_notify_error(gc, NULL, 1653 form = ggp_search_form_new(GGP_SEARCH_TYPE_INFO);
1657 _("Unable to initiate a new search"), 1654
1658 _("You have a pending search. Please wait for it to finish.")); 1655 form->user_data = info;
1659 return;
1660 }
1661
1662 form = ggp_search_form_new();
1663 info->search_form = form;
1664
1665 form->uin = g_strdup(name); 1656 form->uin = g_strdup(name);
1666 form->offset = g_strdup("0"); 1657 form->offset = g_strdup("0");
1667 form->last_uin = g_strdup("0"); 1658 form->last_uin = g_strdup("0");
1668 1659
1669 ggp_search_start(gc, form); 1660 seq = ggp_search_start(gc, form);
1661 ggp_search_add(info->searches, seq, form);
1670 } 1662 }
1671 /* }}} */ 1663 /* }}} */
1672 1664
1673 /* static void ggp_set_status(GaimAccount *account, GaimStatus *status) {{{ */ 1665 /* static void ggp_set_status(GaimAccount *account, GaimStatus *status) {{{ */
1674 static void ggp_set_status(GaimAccount *account, GaimStatus *status) 1666 static void ggp_set_status(GaimAccount *account, GaimStatus *status)