Mercurial > pidgin
comparison src/gtkrequest.c @ 11025:8d2007d738d5
[gaim-migrate @ 12899]
sf patch #1180490, from Richard Laager (who else?)
A pretty peach of a patch that allows you to auto-complete screen names
based on log file names.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Thu, 23 Jun 2005 03:04:52 +0000 |
parents | 842a21e7480b |
children | e6b4badef34d |
comparison
equal
deleted
inserted
replaced
11024:1d58cc6c4552 | 11025:8d2007d738d5 |
---|---|
646 gtk_widget_set_sensitive(req_data->ok_button, | 646 gtk_widget_set_sensitive(req_data->ok_button, |
647 gaim_request_fields_all_required_filled(field->group->fields_list)); | 647 gaim_request_fields_all_required_filled(field->group->fields_list)); |
648 } | 648 } |
649 | 649 |
650 static GList * | 650 static GList * |
651 get_online_names(void) | 651 get_screenname_completion_data(gboolean all) |
652 { | 652 { |
653 GList *names = NULL; | 653 GList *names = NULL; |
654 GaimBlistNode *gnode, *cnode, *bnode; | 654 GaimBlistNode *gnode, *cnode, *bnode; |
655 GList *log_sets; | |
656 GList *log_set; | |
655 | 657 |
656 for (gnode = gaim_get_blist()->root; gnode != NULL; gnode = gnode->next) | 658 for (gnode = gaim_get_blist()->root; gnode != NULL; gnode = gnode->next) |
657 { | 659 { |
658 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) | 660 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) |
659 continue; | 661 continue; |
665 | 667 |
666 for (bnode = cnode->child; bnode != NULL; bnode = bnode->next) | 668 for (bnode = cnode->child; bnode != NULL; bnode = bnode->next) |
667 { | 669 { |
668 GaimBuddy *buddy = (GaimBuddy *)bnode; | 670 GaimBuddy *buddy = (GaimBuddy *)bnode; |
669 | 671 |
670 if (!gaim_account_is_connected(buddy->account)) | 672 if (!all && !gaim_account_is_connected(buddy->account)) |
671 continue; | 673 continue; |
672 | 674 |
673 #ifdef NEW_STYLE_COMPLETION | 675 #ifdef NEW_STYLE_COMPLETION |
674 names = g_list_append(names, ((GaimContact *)cnode)->alias); | 676 names = g_list_append(names, ((GaimContact *)cnode)->alias); |
675 names = g_list_append(names, | 677 names = g_list_append(names, |
676 (gpointer)gaim_buddy_get_contact_alias(buddy)); | 678 (gpointer)gaim_buddy_get_contact_alias(buddy)); |
677 names = g_list_append(names, buddy->account); | 679 names = g_list_append(names, buddy->account); |
678 #endif /* NEW_STYLE_COMPLETION */ | 680 #endif /* NEW_STYLE_COMPLETION */ |
679 | 681 |
680 names = g_list_append(names, buddy->name); | 682 names = g_list_append(names, g_strdup(buddy->name)); |
681 } | 683 } |
682 } | 684 } |
685 } | |
686 | |
687 log_sets = gaim_log_get_log_sets(); | |
688 for (log_set = log_sets ; log_set != NULL ; log_set = log_set->next) { | |
689 GaimLogSet *set = log_set->data; | |
690 | |
691 /* 1. Don't show buddies because we will have gotten them above. | |
692 * 2. If we're not showing all accounts, then only show those with | |
693 * non-NULL accounts that are currently connected. | |
694 * 3. The boxes that use this autocomplete code handle only IMs. */ | |
695 if (!set->buddy && | |
696 (all || (set->account != NULL && gaim_account_is_connected(set->account))) && | |
697 set->type != GAIM_LOG_CHAT) { | |
698 #ifdef NEW_STYLE_COMPLETION | |
699 names = g_list_append(names, NULL); | |
700 names = g_list_append(names, NULL); | |
701 names = g_list_append(names, set->account); | |
702 #endif /* NEW_STYLE_COMPLETION */ | |
703 | |
704 names = g_list_append(names, set->name); | |
705 } | |
706 | |
707 g_free(set); | |
683 } | 708 } |
684 | 709 |
685 return names; | 710 return names; |
686 } | 711 } |
687 | 712 |
757 } | 782 } |
758 | 783 |
759 static void | 784 static void |
760 destroy_completion_data(GtkWidget *w, GaimGtkCompletionData *data) | 785 destroy_completion_data(GtkWidget *w, GaimGtkCompletionData *data) |
761 { | 786 { |
787 g_list_foreach(data->completion->items, (GFunc)g_free, NULL); | |
762 g_completion_free(data->completion); | 788 g_completion_free(data->completion); |
763 | 789 |
764 g_free(data); | 790 g_free(data); |
765 } | 791 } |
766 #endif /* !NEW_STYLE_COMPLETION */ | 792 #endif /* !NEW_STYLE_COMPLETION */ |
859 return TRUE; | 885 return TRUE; |
860 } | 886 } |
861 #endif /* !NEW_STYLE_COMPLETION */ | 887 #endif /* !NEW_STYLE_COMPLETION */ |
862 | 888 |
863 static void | 889 static void |
864 setup_screenname_autocomplete(GtkWidget *entry, GaimRequestField *field) | 890 setup_screenname_autocomplete(GtkWidget *entry, GaimRequestField *field, gboolean all) |
865 { | 891 { |
866 #ifdef NEW_STYLE_COMPLETION | 892 #ifdef NEW_STYLE_COMPLETION |
867 GtkListStore *store; | 893 GtkListStore *store; |
868 GtkTreeIter iter; | 894 GtkTreeIter iter; |
869 GtkEntryCompletion *completion; | 895 GtkEntryCompletion *completion; |
870 GList *aliases_and_screennames; | 896 GList *screenname_completion_data; |
871 GList *l; | 897 GList *l; |
872 gpointer *data; | 898 gpointer *data; |
873 | 899 |
874 /* Store the displayed completion value, the screenname, and the value for comparison. */ | 900 /* Store the displayed completion value, the screenname, the value for comparison, and the account. */ |
875 store = gtk_list_store_new(4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); | 901 store = gtk_list_store_new(4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); |
876 | 902 |
877 aliases_and_screennames = get_online_names(); | 903 screenname_completion_data = get_screenname_completion_data(all); |
878 | 904 |
879 /* Loop through the list four elements at a time. */ | 905 /* Loop through the list four elements at a time. */ |
880 for (l = aliases_and_screennames; l != NULL; l = l->next->next->next->next) | 906 for (l = screenname_completion_data; l != NULL; l = l->next->next->next->next) |
881 { | 907 { |
882 char *contact_alias = l->data; | 908 char *contact_alias = l->data; |
883 char *buddy_alias = l->next->data; | 909 char *buddy_alias = l->next->data; |
884 GaimAccount *account = l->next->next->data; | 910 GaimAccount *account = l->next->next->data; |
885 char *screenname = l->next->next->next->data; | 911 char *screenname = l->next->next->next->data; |
927 1, screenname, | 953 1, screenname, |
928 2, NULL, | 954 2, NULL, |
929 3, account, | 955 3, account, |
930 -1); | 956 -1); |
931 } | 957 } |
932 } | 958 |
933 | 959 g_free(screenname); |
934 g_list_free(aliases_and_screennames); | 960 } |
961 | |
962 g_list_free(screenname_completion_data); | |
963 | |
964 /* Sort the completion list by screenname. */ | |
965 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), | |
966 1, GTK_SORT_ASCENDING); | |
935 | 967 |
936 completion = gtk_entry_completion_new(); | 968 completion = gtk_entry_completion_new(); |
937 gtk_entry_completion_set_match_func(completion, screenname_completion_match_func, NULL, NULL); | 969 gtk_entry_completion_set_match_func(completion, screenname_completion_match_func, NULL, NULL); |
938 | 970 |
939 data = g_new0(gpointer, 2); | 971 data = g_new0(gpointer, 2); |
958 | 990 |
959 data->completion = g_completion_new(NULL); | 991 data->completion = g_completion_new(NULL); |
960 | 992 |
961 g_completion_set_compare(data->completion, g_ascii_strncasecmp); | 993 g_completion_set_compare(data->completion, g_ascii_strncasecmp); |
962 | 994 |
963 screennames = get_online_names(); | 995 screennames = get_screenname_completion_data(all); |
964 | 996 |
965 g_completion_add_items(data->completion, screennames); | 997 g_completion_add_items(data->completion, screennames); |
966 | 998 |
967 g_list_free(screennames); | 999 g_list_free(screennames); |
968 | 1000 |
987 G_CALLBACK(req_entry_field_changed_cb), field); | 1019 G_CALLBACK(req_entry_field_changed_cb), field); |
988 } | 1020 } |
989 | 1021 |
990 if ((type_hint = gaim_request_field_get_type_hint(field)) != NULL) | 1022 if ((type_hint = gaim_request_field_get_type_hint(field)) != NULL) |
991 { | 1023 { |
992 if (!strcmp(type_hint, "screenname")) | 1024 if (!strncmp(type_hint, "screenname", sizeof("screenname") - 1)) |
993 { | 1025 { |
994 setup_screenname_autocomplete(entry, field); | 1026 setup_screenname_autocomplete(entry, field, !strcmp(type_hint, "screenname-all")); |
995 } | 1027 } |
996 } | 1028 } |
997 } | 1029 } |
998 | 1030 |
999 static GtkWidget * | 1031 static GtkWidget * |