Mercurial > pidgin.yaz
comparison pidgin/gtkaccount.c @ 25960:43da17b9a27e
propagate from branch 'im.pidgin.pidgin' (head c5b982597812ab3c0fd2dbca9be31f173fda67bb)
to branch 'im.pidgin.cpw.malu.xmpp.idle' (head 4379b3a32fa6bbd860103c93b291406542af52f9)
author | Marcus Lundblad <ml@update.uu.se> |
---|---|
date | Thu, 22 Jan 2009 20:39:12 +0000 |
parents | a69ce97a1600 |
children | 17b840986607 |
comparison
equal
deleted
inserted
replaced
25959:d978395b4e18 | 25960:43da17b9a27e |
---|---|
82 | 82 |
83 } AccountsWindow; | 83 } AccountsWindow; |
84 | 84 |
85 typedef struct | 85 typedef struct |
86 { | 86 { |
87 GtkWidget *widget; | |
88 gchar *setting; | |
89 PurplePrefType type; | |
90 } ProtocolOptEntry; | |
91 | |
92 typedef struct | |
93 { | |
87 PidginAccountDialogType type; | 94 PidginAccountDialogType type; |
88 | 95 |
89 PurpleAccount *account; | 96 PurpleAccount *account; |
90 char *protocol_id; | 97 char *protocol_id; |
91 PurplePlugin *plugin; | 98 PurplePlugin *plugin; |
738 GList *l; | 745 GList *l; |
739 char buf[1024]; | 746 char buf[1024]; |
740 char *title, *tmp; | 747 char *title, *tmp; |
741 const char *str_value; | 748 const char *str_value; |
742 gboolean bool_value; | 749 gboolean bool_value; |
750 ProtocolOptEntry *opt_entry; | |
743 | 751 |
744 if (dialog->protocol_frame != NULL) { | 752 if (dialog->protocol_frame != NULL) { |
745 gtk_widget_destroy(dialog->protocol_frame); | 753 gtk_widget_destroy(dialog->protocol_frame); |
746 dialog->protocol_frame = NULL; | 754 dialog->protocol_frame = NULL; |
747 } | 755 } |
748 | 756 |
749 if (dialog->protocol_opt_entries != NULL) { | |
750 g_list_free(dialog->protocol_opt_entries); | |
751 dialog->protocol_opt_entries = NULL; | |
752 } | |
753 | |
754 if (dialog->prpl_info == NULL || | 757 if (dialog->prpl_info == NULL || |
755 dialog->prpl_info->protocol_options == NULL) { | 758 dialog->prpl_info->protocol_options == NULL) |
756 | |
757 return; | 759 return; |
760 | |
761 while (dialog->protocol_opt_entries != NULL) { | |
762 ProtocolOptEntry *opt_entry = dialog->protocol_opt_entries->data; | |
763 g_free(opt_entry->setting); | |
764 g_free(opt_entry); | |
765 dialog->protocol_opt_entries = g_list_delete_link(dialog->protocol_opt_entries, dialog->protocol_opt_entries); | |
758 } | 766 } |
759 | 767 |
760 account = dialog->account; | 768 account = dialog->account; |
761 | 769 |
762 /* Build the protocol options frame. */ | 770 /* Build the protocol options frame. */ |
776 | 784 |
777 for (l = dialog->prpl_info->protocol_options; l != NULL; l = l->next) | 785 for (l = dialog->prpl_info->protocol_options; l != NULL; l = l->next) |
778 { | 786 { |
779 option = (PurpleAccountOption *)l->data; | 787 option = (PurpleAccountOption *)l->data; |
780 | 788 |
781 switch (purple_account_option_get_type(option)) | 789 opt_entry = g_new0(ProtocolOptEntry, 1); |
790 opt_entry->type = purple_account_option_get_type(option); | |
791 opt_entry->setting = g_strdup(purple_account_option_get_setting(option)); | |
792 | |
793 switch (opt_entry->type) | |
782 { | 794 { |
783 case PURPLE_PREF_BOOLEAN: | 795 case PURPLE_PREF_BOOLEAN: |
784 if (account == NULL || | 796 if (account == NULL || |
785 strcmp(purple_account_get_protocol_id(account), | 797 strcmp(purple_account_get_protocol_id(account), |
786 dialog->protocol_id)) | 798 dialog->protocol_id)) |
793 purple_account_option_get_setting(option), | 805 purple_account_option_get_setting(option), |
794 purple_account_option_get_default_bool(option)); | 806 purple_account_option_get_default_bool(option)); |
795 } | 807 } |
796 | 808 |
797 tmp = g_strconcat("_", purple_account_option_get_text(option), NULL); | 809 tmp = g_strconcat("_", purple_account_option_get_text(option), NULL); |
798 check = gtk_check_button_new_with_mnemonic(tmp); | 810 opt_entry->widget = check = gtk_check_button_new_with_mnemonic(tmp); |
799 g_free(tmp); | 811 g_free(tmp); |
800 | 812 |
801 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), | 813 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check), |
802 bool_value); | 814 bool_value); |
803 | 815 |
804 gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0); | 816 gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0); |
805 gtk_widget_show(check); | 817 gtk_widget_show(check); |
806 | |
807 dialog->protocol_opt_entries = | |
808 g_list_append(dialog->protocol_opt_entries, check); | |
809 | |
810 break; | 818 break; |
811 | 819 |
812 case PURPLE_PREF_INT: | 820 case PURPLE_PREF_INT: |
813 if (account == NULL || | 821 if (account == NULL || |
814 strcmp(purple_account_get_protocol_id(account), | 822 strcmp(purple_account_get_protocol_id(account), |
823 purple_account_option_get_default_int(option)); | 831 purple_account_option_get_default_int(option)); |
824 } | 832 } |
825 | 833 |
826 g_snprintf(buf, sizeof(buf), "%d", int_value); | 834 g_snprintf(buf, sizeof(buf), "%d", int_value); |
827 | 835 |
828 entry = gtk_entry_new(); | 836 opt_entry->widget = entry = gtk_entry_new(); |
829 gtk_entry_set_text(GTK_ENTRY(entry), buf); | 837 gtk_entry_set_text(GTK_ENTRY(entry), buf); |
830 | 838 |
831 title = g_strdup_printf("_%s:", | 839 title = g_strdup_printf("_%s:", |
832 purple_account_option_get_text(option)); | 840 purple_account_option_get_text(option)); |
833 | |
834 add_pref_box(dialog, vbox, title, entry); | 841 add_pref_box(dialog, vbox, title, entry); |
835 | |
836 g_free(title); | 842 g_free(title); |
837 | |
838 dialog->protocol_opt_entries = | |
839 g_list_append(dialog->protocol_opt_entries, entry); | |
840 | |
841 break; | 843 break; |
842 | 844 |
843 case PURPLE_PREF_STRING: | 845 case PURPLE_PREF_STRING: |
844 if (account == NULL || | 846 if (account == NULL || |
845 strcmp(purple_account_get_protocol_id(account), | 847 strcmp(purple_account_get_protocol_id(account), |
852 str_value = purple_account_get_string(account, | 854 str_value = purple_account_get_string(account, |
853 purple_account_option_get_setting(option), | 855 purple_account_option_get_setting(option), |
854 purple_account_option_get_default_string(option)); | 856 purple_account_option_get_default_string(option)); |
855 } | 857 } |
856 | 858 |
857 entry = gtk_entry_new(); | 859 opt_entry->widget = entry = gtk_entry_new(); |
858 if (purple_account_option_get_masked(option)) | 860 if (purple_account_option_get_masked(option)) |
859 { | 861 { |
860 gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE); | 862 gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE); |
861 if (gtk_entry_get_invisible_char(GTK_ENTRY(entry)) == '*') | 863 if (gtk_entry_get_invisible_char(GTK_ENTRY(entry)) == '*') |
862 gtk_entry_set_invisible_char(GTK_ENTRY(entry), PIDGIN_INVISIBLE_CHAR); | 864 gtk_entry_set_invisible_char(GTK_ENTRY(entry), PIDGIN_INVISIBLE_CHAR); |
865 if (str_value != NULL) | 867 if (str_value != NULL) |
866 gtk_entry_set_text(GTK_ENTRY(entry), str_value); | 868 gtk_entry_set_text(GTK_ENTRY(entry), str_value); |
867 | 869 |
868 title = g_strdup_printf("_%s:", | 870 title = g_strdup_printf("_%s:", |
869 purple_account_option_get_text(option)); | 871 purple_account_option_get_text(option)); |
870 | |
871 add_pref_box(dialog, vbox, title, entry); | 872 add_pref_box(dialog, vbox, title, entry); |
872 | |
873 g_free(title); | 873 g_free(title); |
874 | |
875 dialog->protocol_opt_entries = | |
876 g_list_append(dialog->protocol_opt_entries, entry); | |
877 | |
878 break; | 874 break; |
879 | 875 |
880 case PURPLE_PREF_STRING_LIST: | 876 case PURPLE_PREF_STRING_LIST: |
881 i = 0; | 877 i = 0; |
882 idx = 0; | 878 idx = 0; |
894 purple_account_option_get_default_list_value(option)); | 890 purple_account_option_get_default_list_value(option)); |
895 } | 891 } |
896 | 892 |
897 list = purple_account_option_get_list(option); | 893 list = purple_account_option_get_list(option); |
898 model = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_POINTER); | 894 model = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_POINTER); |
899 combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(model)); | 895 opt_entry->widget = combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(model)); |
900 | 896 |
901 /* Loop through list of PurpleKeyValuePair items */ | 897 /* Loop through list of PurpleKeyValuePair items */ |
902 for (node = list; node != NULL; node = node->next) { | 898 for (node = list; node != NULL; node = node->next) { |
903 if (node->data != NULL) { | 899 if (node->data != NULL) { |
904 kvp = (PurpleKeyValuePair *) node->data; | 900 kvp = (PurpleKeyValuePair *) node->data; |
926 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), | 922 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), |
927 renderer, "text", 0, NULL); | 923 renderer, "text", 0, NULL); |
928 | 924 |
929 title = g_strdup_printf("_%s:", | 925 title = g_strdup_printf("_%s:", |
930 purple_account_option_get_text(option)); | 926 purple_account_option_get_text(option)); |
931 | |
932 add_pref_box(dialog, vbox, title, combo); | 927 add_pref_box(dialog, vbox, title, combo); |
933 | |
934 g_free(title); | 928 g_free(title); |
935 | |
936 dialog->protocol_opt_entries = | |
937 g_list_append(dialog->protocol_opt_entries, combo); | |
938 | |
939 break; | 929 break; |
940 | 930 |
941 | |
942 default: | 931 default: |
943 break; | 932 purple_debug_error("gtkaccount", "Invalid Account Option pref type (%d)\n", |
933 opt_entry->type); | |
934 g_free(opt_entry->setting); | |
935 g_free(opt_entry); | |
936 continue; | |
944 } | 937 } |
938 | |
939 dialog->protocol_opt_entries = | |
940 g_list_append(dialog->protocol_opt_entries, opt_entry); | |
941 | |
945 } | 942 } |
946 } | 943 } |
947 | 944 |
948 static GtkWidget * | 945 static GtkWidget * |
949 make_proxy_dropdown(void) | 946 make_proxy_dropdown(void) |
1150 g_hash_table_remove(account_pref_wins, dialog->account); | 1147 g_hash_table_remove(account_pref_wins, dialog->account); |
1151 | 1148 |
1152 gtk_widget_destroy(dialog->window); | 1149 gtk_widget_destroy(dialog->window); |
1153 | 1150 |
1154 g_list_free(dialog->user_split_entries); | 1151 g_list_free(dialog->user_split_entries); |
1155 g_list_free(dialog->protocol_opt_entries); | 1152 while (dialog->protocol_opt_entries != NULL) { |
1153 ProtocolOptEntry *opt_entry = dialog->protocol_opt_entries->data; | |
1154 g_free(opt_entry->setting); | |
1155 g_free(opt_entry); | |
1156 dialog->protocol_opt_entries = g_list_delete_link(dialog->protocol_opt_entries, dialog->protocol_opt_entries); | |
1157 } | |
1156 g_free(dialog->protocol_id); | 1158 g_free(dialog->protocol_id); |
1157 g_object_unref(dialog->sg); | 1159 g_object_unref(dialog->sg); |
1158 | 1160 |
1159 purple_imgstore_unref(dialog->icon_img); | 1161 purple_imgstore_unref(dialog->icon_img); |
1160 | 1162 |
1315 purple_account_set_username(account, username); | 1317 purple_account_set_username(account, username); |
1316 g_free(username); | 1318 g_free(username); |
1317 | 1319 |
1318 /* Add the protocol settings */ | 1320 /* Add the protocol settings */ |
1319 if (dialog->prpl_info) { | 1321 if (dialog->prpl_info) { |
1320 for (l = dialog->prpl_info->protocol_options, | 1322 ProtocolOptEntry *opt_entry; |
1321 l2 = dialog->protocol_opt_entries; | 1323 GtkTreeIter iter; |
1322 l != NULL && l2 != NULL; | 1324 char *value2; |
1323 l = l->next, l2 = l2->next) { | 1325 int int_value; |
1324 | 1326 gboolean bool_value; |
1325 PurplePrefType type; | 1327 |
1326 PurpleAccountOption *option = l->data; | 1328 for (l2 = dialog->protocol_opt_entries; l2; l2 = l2->next) { |
1327 GtkWidget *widget = l2->data; | 1329 |
1328 GtkTreeIter iter; | 1330 opt_entry = l2->data; |
1329 const char *setting; | 1331 |
1330 char *value2; | 1332 switch (opt_entry->type) { |
1331 int int_value; | |
1332 gboolean bool_value; | |
1333 | |
1334 type = purple_account_option_get_type(option); | |
1335 | |
1336 setting = purple_account_option_get_setting(option); | |
1337 | |
1338 switch (type) { | |
1339 case PURPLE_PREF_STRING: | 1333 case PURPLE_PREF_STRING: |
1340 value = gtk_entry_get_text(GTK_ENTRY(widget)); | 1334 value = gtk_entry_get_text(GTK_ENTRY(opt_entry->widget)); |
1341 purple_account_set_string(account, setting, value); | 1335 purple_account_set_string(account, opt_entry->setting, value); |
1342 break; | 1336 break; |
1343 | 1337 |
1344 case PURPLE_PREF_INT: | 1338 case PURPLE_PREF_INT: |
1345 int_value = atoi(gtk_entry_get_text(GTK_ENTRY(widget))); | 1339 int_value = atoi(gtk_entry_get_text(GTK_ENTRY(opt_entry->widget))); |
1346 purple_account_set_int(account, setting, int_value); | 1340 purple_account_set_int(account, opt_entry->setting, int_value); |
1347 break; | 1341 break; |
1348 | 1342 |
1349 case PURPLE_PREF_BOOLEAN: | 1343 case PURPLE_PREF_BOOLEAN: |
1350 bool_value = | 1344 bool_value = |
1351 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); | 1345 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(opt_entry->widget)); |
1352 purple_account_set_bool(account, setting, bool_value); | 1346 purple_account_set_bool(account, opt_entry->setting, bool_value); |
1353 break; | 1347 break; |
1354 | 1348 |
1355 case PURPLE_PREF_STRING_LIST: | 1349 case PURPLE_PREF_STRING_LIST: |
1356 value2 = NULL; | 1350 value2 = NULL; |
1357 if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &iter)) | 1351 if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(opt_entry->widget), &iter)) |
1358 gtk_tree_model_get(gtk_combo_box_get_model(GTK_COMBO_BOX(widget)), &iter, 1, &value2, -1); | 1352 gtk_tree_model_get(gtk_combo_box_get_model(GTK_COMBO_BOX(opt_entry->widget)), &iter, 1, &value2, -1); |
1359 purple_account_set_string(account, setting, value2); | 1353 purple_account_set_string(account, opt_entry->setting, value2); |
1360 break; | 1354 break; |
1361 | 1355 |
1362 default: | 1356 default: |
1363 break; | 1357 break; |
1364 } | 1358 } |