summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Atallah <datallah@pidgin.im>2009-01-20 05:58:47 +0000
committerDaniel Atallah <datallah@pidgin.im>2009-01-20 05:58:47 +0000
commit3fadaecdd20ebc1a57ae1786aee64084f6806392 (patch)
tree9b2f2e21123ae1813b550da42369c43970370600
parenta203277912303317d0f2b62b140eddbcf81626f0 (diff)
downloadpidgin-3fadaecdd20ebc1a57ae1786aee64084f6806392.tar.gz
When saving the account settings, use the protocol options that were present at
the time the dialog was created instead of the current protocol options (the list may have changed under us).
-rw-r--r--pidgin/gtkaccount.c118
1 files changed, 56 insertions, 62 deletions
diff --git a/pidgin/gtkaccount.c b/pidgin/gtkaccount.c
index 0f5ec3f4b9..0777467253 100644
--- a/pidgin/gtkaccount.c
+++ b/pidgin/gtkaccount.c
@@ -84,6 +84,13 @@ typedef struct
typedef struct
{
+ GtkWidget *widget;
+ gchar *setting;
+ PurplePrefType type;
+} ProtocolOptEntry;
+
+typedef struct
+{
PidginAccountDialogType type;
PurpleAccount *account;
@@ -740,21 +747,22 @@ add_protocol_options(AccountPrefsDialog *dialog, GtkWidget *parent)
char *title, *tmp;
const char *str_value;
gboolean bool_value;
+ ProtocolOptEntry *opt_entry;
if (dialog->protocol_frame != NULL) {
gtk_widget_destroy(dialog->protocol_frame);
dialog->protocol_frame = NULL;
}
- if (dialog->protocol_opt_entries != NULL) {
- g_list_free(dialog->protocol_opt_entries);
- dialog->protocol_opt_entries = NULL;
- }
-
if (dialog->prpl_info == NULL ||
- dialog->prpl_info->protocol_options == NULL) {
-
+ dialog->prpl_info->protocol_options == NULL)
return;
+
+ while (dialog->protocol_opt_entries != NULL) {
+ ProtocolOptEntry *opt_entry = dialog->protocol_opt_entries->data;
+ g_free(opt_entry->setting);
+ g_free(opt_entry);
+ dialog->protocol_opt_entries = g_list_delete_link(dialog->protocol_opt_entries, dialog->protocol_opt_entries);
}
account = dialog->account;
@@ -778,7 +786,11 @@ add_protocol_options(AccountPrefsDialog *dialog, GtkWidget *parent)
{
option = (PurpleAccountOption *)l->data;
- switch (purple_account_option_get_type(option))
+ opt_entry = g_new0(ProtocolOptEntry, 1);
+ opt_entry->type = purple_account_option_get_type(option);
+ opt_entry->setting = g_strdup(purple_account_option_get_setting(option));
+
+ switch (opt_entry->type)
{
case PURPLE_PREF_BOOLEAN:
if (account == NULL ||
@@ -795,7 +807,7 @@ add_protocol_options(AccountPrefsDialog *dialog, GtkWidget *parent)
}
tmp = g_strconcat("_", purple_account_option_get_text(option), NULL);
- check = gtk_check_button_new_with_mnemonic(tmp);
+ opt_entry->widget = check = gtk_check_button_new_with_mnemonic(tmp);
g_free(tmp);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(check),
@@ -803,10 +815,6 @@ add_protocol_options(AccountPrefsDialog *dialog, GtkWidget *parent)
gtk_box_pack_start(GTK_BOX(vbox), check, FALSE, FALSE, 0);
gtk_widget_show(check);
-
- dialog->protocol_opt_entries =
- g_list_append(dialog->protocol_opt_entries, check);
-
break;
case PURPLE_PREF_INT:
@@ -825,19 +833,13 @@ add_protocol_options(AccountPrefsDialog *dialog, GtkWidget *parent)
g_snprintf(buf, sizeof(buf), "%d", int_value);
- entry = gtk_entry_new();
+ opt_entry->widget = entry = gtk_entry_new();
gtk_entry_set_text(GTK_ENTRY(entry), buf);
title = g_strdup_printf("_%s:",
purple_account_option_get_text(option));
-
add_pref_box(dialog, vbox, title, entry);
-
g_free(title);
-
- dialog->protocol_opt_entries =
- g_list_append(dialog->protocol_opt_entries, entry);
-
break;
case PURPLE_PREF_STRING:
@@ -854,7 +856,7 @@ add_protocol_options(AccountPrefsDialog *dialog, GtkWidget *parent)
purple_account_option_get_default_string(option));
}
- entry = gtk_entry_new();
+ opt_entry->widget = entry = gtk_entry_new();
if (purple_account_option_get_masked(option))
{
gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
@@ -867,14 +869,8 @@ add_protocol_options(AccountPrefsDialog *dialog, GtkWidget *parent)
title = g_strdup_printf("_%s:",
purple_account_option_get_text(option));
-
add_pref_box(dialog, vbox, title, entry);
-
g_free(title);
-
- dialog->protocol_opt_entries =
- g_list_append(dialog->protocol_opt_entries, entry);
-
break;
case PURPLE_PREF_STRING_LIST:
@@ -896,7 +892,7 @@ add_protocol_options(AccountPrefsDialog *dialog, GtkWidget *parent)
list = purple_account_option_get_list(option);
model = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_POINTER);
- combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(model));
+ opt_entry->widget = combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(model));
/* Loop through list of PurpleKeyValuePair items */
for (node = list; node != NULL; node = node->next) {
@@ -928,20 +924,21 @@ add_protocol_options(AccountPrefsDialog *dialog, GtkWidget *parent)
title = g_strdup_printf("_%s:",
purple_account_option_get_text(option));
-
add_pref_box(dialog, vbox, title, combo);
-
g_free(title);
-
- dialog->protocol_opt_entries =
- g_list_append(dialog->protocol_opt_entries, combo);
-
break;
-
default:
- break;
+ purple_debug_error("gtkaccount", "Invalid Account Option pref type (%d)\n",
+ opt_entry->type);
+ g_free(opt_entry->setting);
+ g_free(opt_entry);
+ continue;
}
+
+ dialog->protocol_opt_entries =
+ g_list_append(dialog->protocol_opt_entries, opt_entry);
+
}
}
@@ -1152,7 +1149,12 @@ account_win_destroy_cb(GtkWidget *w, GdkEvent *event,
gtk_widget_destroy(dialog->window);
g_list_free(dialog->user_split_entries);
- g_list_free(dialog->protocol_opt_entries);
+ while (dialog->protocol_opt_entries != NULL) {
+ ProtocolOptEntry *opt_entry = dialog->protocol_opt_entries->data;
+ g_free(opt_entry->setting);
+ g_free(opt_entry);
+ dialog->protocol_opt_entries = g_list_delete_link(dialog->protocol_opt_entries, dialog->protocol_opt_entries);
+ }
g_free(dialog->protocol_id);
g_object_unref(dialog->sg);
@@ -1317,46 +1319,38 @@ ok_account_prefs_cb(GtkWidget *w, AccountPrefsDialog *dialog)
/* Add the protocol settings */
if (dialog->prpl_info) {
- for (l = dialog->prpl_info->protocol_options,
- l2 = dialog->protocol_opt_entries;
- l != NULL && l2 != NULL;
- l = l->next, l2 = l2->next) {
-
- PurplePrefType type;
- PurpleAccountOption *option = l->data;
- GtkWidget *widget = l2->data;
- GtkTreeIter iter;
- const char *setting;
- char *value2;
- int int_value;
- gboolean bool_value;
+ ProtocolOptEntry *opt_entry;
+ GtkTreeIter iter;
+ char *value2;
+ int int_value;
+ gboolean bool_value;
- type = purple_account_option_get_type(option);
+ for (l2 = dialog->protocol_opt_entries; l2; l2 = l2->next) {
- setting = purple_account_option_get_setting(option);
+ opt_entry = l2->data;
- switch (type) {
+ switch (opt_entry->type) {
case PURPLE_PREF_STRING:
- value = gtk_entry_get_text(GTK_ENTRY(widget));
- purple_account_set_string(account, setting, value);
+ value = gtk_entry_get_text(GTK_ENTRY(opt_entry->widget));
+ purple_account_set_string(account, opt_entry->setting, value);
break;
case PURPLE_PREF_INT:
- int_value = atoi(gtk_entry_get_text(GTK_ENTRY(widget)));
- purple_account_set_int(account, setting, int_value);
+ int_value = atoi(gtk_entry_get_text(GTK_ENTRY(opt_entry->widget)));
+ purple_account_set_int(account, opt_entry->setting, int_value);
break;
case PURPLE_PREF_BOOLEAN:
bool_value =
- gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
- purple_account_set_bool(account, setting, bool_value);
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(opt_entry->widget));
+ purple_account_set_bool(account, opt_entry->setting, bool_value);
break;
case PURPLE_PREF_STRING_LIST:
value2 = NULL;
- if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &iter))
- gtk_tree_model_get(gtk_combo_box_get_model(GTK_COMBO_BOX(widget)), &iter, 1, &value2, -1);
- purple_account_set_string(account, setting, value2);
+ if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(opt_entry->widget), &iter))
+ gtk_tree_model_get(gtk_combo_box_get_model(GTK_COMBO_BOX(opt_entry->widget)), &iter, 1, &value2, -1);
+ purple_account_set_string(account, opt_entry->setting, value2);
break;
default: