Mercurial > pidgin
comparison src/gtkrequest.c @ 10668:aafe8f30b826
[gaim-migrate @ 12208]
Richard Laager again.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 07 Mar 2005 19:12:15 +0000 |
parents | 57589eb36449 |
children | 179b0245a2f7 |
comparison
equal
deleted
inserted
replaced
10667:51ea57c36056 | 10668:aafe8f30b826 |
---|---|
630 gtk_widget_set_sensitive(req_data->ok_button, | 630 gtk_widget_set_sensitive(req_data->ok_button, |
631 gaim_request_fields_all_required_filled(field->group->fields_list)); | 631 gaim_request_fields_all_required_filled(field->group->fields_list)); |
632 } | 632 } |
633 | 633 |
634 GList * | 634 GList * |
635 get_online_screennames(void) | 635 get_online_names(void) |
636 { | 636 { |
637 GList *screennames = NULL; | 637 GList *names = NULL; |
638 GaimBlistNode *gnode, *cnode, *bnode; | 638 GaimBlistNode *gnode, *cnode, *bnode; |
639 | 639 |
640 for (gnode = gaim_get_blist()->root; gnode != NULL; gnode = gnode->next) | 640 for (gnode = gaim_get_blist()->root; gnode != NULL; gnode = gnode->next) |
641 { | 641 { |
642 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) | 642 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) |
652 GaimBuddy *buddy = (GaimBuddy *)bnode; | 652 GaimBuddy *buddy = (GaimBuddy *)bnode; |
653 | 653 |
654 if (!gaim_account_is_connected(buddy->account)) | 654 if (!gaim_account_is_connected(buddy->account)) |
655 continue; | 655 continue; |
656 | 656 |
657 screennames = g_list_append(screennames, g_strdup(buddy->name)); | 657 #ifdef NEW_STYLE_COMPLETION |
658 names = g_list_append(names, ((GaimContact *)cnode)->alias); | |
659 names = g_list_append(names, | |
660 (gpointer)gaim_buddy_get_contact_alias(buddy)); | |
661 #endif /* NEW_STYLE_COMPLETION */ | |
662 | |
663 names = g_list_append(names, buddy->name); | |
658 } | 664 } |
659 } | 665 } |
660 } | 666 } |
661 | 667 |
662 return screennames; | 668 return names; |
663 } | 669 } |
664 | 670 |
665 #ifndef NEW_STYLE_COMPLETION | 671 #ifndef NEW_STYLE_COMPLETION |
666 static gboolean | 672 static gboolean |
667 completion_entry_event(GtkEditable *entry, GdkEventKey *event, | 673 completion_entry_event(GtkEditable *entry, GdkEventKey *event, |
734 } | 740 } |
735 | 741 |
736 static void | 742 static void |
737 destroy_completion_data(GtkWidget *w, GaimGtkCompletionData *data) | 743 destroy_completion_data(GtkWidget *w, GaimGtkCompletionData *data) |
738 { | 744 { |
739 g_list_foreach(data->completion->items, (GFunc)g_free, NULL); | |
740 g_completion_free(data->completion); | 745 g_completion_free(data->completion); |
741 | 746 |
742 g_free(data); | 747 g_free(data); |
748 } | |
749 #endif /* !NEW_STYLE_COMPLETION */ | |
750 | |
751 #ifdef NEW_STYLE_COMPLETION | |
752 static gboolean screenname_completion_match_func(GtkEntryCompletion *completion, | |
753 const gchar *key, GtkTreeIter *iter, gpointer user_data) { | |
754 | |
755 GValue val = { 0, }; | |
756 GtkTreeModel *model; | |
757 char *screenname = NULL; | |
758 char *alias = NULL; | |
759 char *temp; | |
760 gboolean ret = FALSE; | |
761 | |
762 model = gtk_entry_completion_get_model (completion); | |
763 | |
764 gtk_tree_model_get_value(model, iter, 1, &val); | |
765 temp = (gchar *)g_value_get_string(&val); | |
766 if (temp) { | |
767 temp = g_utf8_normalize(temp, -1, G_NORMALIZE_DEFAULT); | |
768 screenname = g_utf8_casefold(temp, -1); | |
769 g_free(temp); | |
770 } | |
771 g_value_unset(&val); | |
772 | |
773 gtk_tree_model_get_value(model, iter, 2, &val); | |
774 temp = (gchar *)g_value_get_string(&val); | |
775 if (temp) { | |
776 temp = g_utf8_normalize(temp, -1, G_NORMALIZE_DEFAULT); | |
777 alias = g_utf8_casefold(temp, -1); | |
778 g_free(temp); | |
779 } | |
780 g_value_unset(&val); | |
781 | |
782 if (g_str_has_prefix(screenname, key) || | |
783 g_str_has_prefix(alias, key)) | |
784 ret = TRUE; | |
785 | |
786 g_free(screenname); | |
787 g_free(alias); | |
788 | |
789 return ret; | |
790 } | |
791 | |
792 static gboolean screenname_completion_match_selected_cb(GtkEntryCompletion *completion, | |
793 GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data) { | |
794 | |
795 GValue val = { 0, }; | |
796 | |
797 gtk_tree_model_get_value(model, iter, 1, &val); | |
798 gtk_entry_set_text(GTK_ENTRY(user_data), g_value_get_string(&val)); | |
799 g_value_unset(&val); | |
800 | |
801 return TRUE; | |
743 } | 802 } |
744 #endif /* !NEW_STYLE_COMPLETION */ | 803 #endif /* !NEW_STYLE_COMPLETION */ |
745 | 804 |
746 static void | 805 static void |
747 setup_screenname_autocomplete(GtkWidget *entry, GaimRequestField *field) | 806 setup_screenname_autocomplete(GtkWidget *entry, GaimRequestField *field) |
748 { | 807 { |
749 #ifdef NEW_STYLE_COMPLETION | 808 #ifdef NEW_STYLE_COMPLETION |
750 GtkListStore *store; | 809 GtkListStore *store; |
751 GtkTreeIter iter; | 810 GtkTreeIter iter; |
752 GtkEntryCompletion *completion; | 811 GtkEntryCompletion *completion; |
753 GList *screennames, *l; | 812 GList *aliases_and_screennames, *l; |
754 | 813 |
755 store = gtk_list_store_new(1, G_TYPE_STRING); | 814 /* Store the displayed completion value, the screenname, and the value for comparison. */ |
756 | 815 store = gtk_list_store_new(3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); |
757 screennames = get_online_screennames(); | 816 |
758 | 817 aliases_and_screennames = get_online_names(); |
759 for (l = screennames; l != NULL; l = l->next) | 818 |
819 /* Loop through the list three elements at a time. */ | |
820 for (l = aliases_and_screennames; l != NULL; l = l->next->next->next) | |
760 { | 821 { |
761 gtk_list_store_append(store, &iter); | 822 char *contact_alias = l->data; |
762 gtk_list_store_set(store, &iter, 0, l->data, -1); | 823 char *buddy_alias = l->next->data; |
763 } | 824 char *screenname = l->next->next->data; |
764 | 825 gboolean completion_added = FALSE; |
765 g_list_foreach(screennames, (GFunc)g_free, NULL); | 826 |
766 g_list_free(screennames); | 827 /* There's no sense listing things like: 'xxx "xxx"' |
828 when the screenname and buddy alias match. */ | |
829 if (buddy_alias && strcmp(buddy_alias, screenname)) { | |
830 char *completion_entry = g_strdup_printf("%s \"%s\"", screenname, buddy_alias); | |
831 gtk_list_store_append(store, &iter); | |
832 gtk_list_store_set(store, &iter, | |
833 0, completion_entry, | |
834 1, screenname, | |
835 2, buddy_alias, | |
836 -1); | |
837 g_free(completion_entry); | |
838 completion_added = TRUE; | |
839 } | |
840 | |
841 /* There's no sense listing things like: 'xxx "xxx"' | |
842 when the screenname and contact alias match. */ | |
843 if (contact_alias && strcmp(contact_alias, screenname)) { | |
844 /* We don't want duplicates when the contact and buddy alias match. */ | |
845 if (strcmp(contact_alias, buddy_alias)) { | |
846 char *completion_entry = g_strdup_printf("%s \"%s\"", | |
847 screenname, contact_alias); | |
848 gtk_list_store_append(store, &iter); | |
849 gtk_list_store_set(store, &iter, | |
850 0, completion_entry, | |
851 1, screenname, | |
852 2, contact_alias, | |
853 -1); | |
854 g_free(completion_entry); | |
855 completion_added = TRUE; | |
856 } | |
857 } | |
858 | |
859 if (completion_added == FALSE) { | |
860 /* Add the buddy's screenname. */ | |
861 gtk_list_store_append(store, &iter); | |
862 gtk_list_store_set(store, &iter, | |
863 0, screenname, | |
864 1, screenname, | |
865 2, NULL, | |
866 -1); | |
867 } | |
868 } | |
869 | |
870 g_list_free(aliases_and_screennames); | |
767 | 871 |
768 completion = gtk_entry_completion_new(); | 872 completion = gtk_entry_completion_new(); |
873 gtk_entry_completion_set_match_func(completion, screenname_completion_match_func, NULL, NULL); | |
874 g_signal_connect(G_OBJECT(completion), "match-selected", | |
875 G_CALLBACK(screenname_completion_match_selected_cb), entry); | |
769 gtk_entry_set_completion(GTK_ENTRY(entry), completion); | 876 gtk_entry_set_completion(GTK_ENTRY(entry), completion); |
770 g_object_unref(completion); | 877 g_object_unref(completion); |
771 | 878 |
772 gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(store)); | 879 gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(store)); |
773 g_object_unref(store); | 880 g_object_unref(store); |
782 | 889 |
783 data->completion = g_completion_new(NULL); | 890 data->completion = g_completion_new(NULL); |
784 | 891 |
785 g_completion_set_compare(data->completion, g_ascii_strncasecmp); | 892 g_completion_set_compare(data->completion, g_ascii_strncasecmp); |
786 | 893 |
787 screennames = get_online_screennames(); | 894 screennames = get_online_names(); |
788 | 895 |
789 g_completion_add_items(data->completion, screennames); | 896 g_completion_add_items(data->completion, screennames); |
790 | 897 |
791 g_list_free(screennames); | 898 g_list_free(screennames); |
792 | 899 |