# HG changeset patch # User Sean Egan # Date 1132044123 0 # Node ID 36a0c8719af3b41739436020e08813d95e3672c6 # Parent d4cd7d443795c57a03ebd7ef42b7db04436fedb2 [gaim-migrate @ 14403] Account option lists UI from Don. committer: Tailor Script diff -r d4cd7d443795 -r 36a0c8719af3 src/accountopt.h --- a/src/accountopt.h Tue Nov 15 06:06:47 2005 +0000 +++ b/src/accountopt.h Tue Nov 15 08:42:03 2005 +0000 @@ -133,8 +133,8 @@ * The list passed will be owned by the account option, and the * strings inside will be freed automatically. * - * The list is in key, value pairs. The key is the ID stored and used - * internally, and the value is the label displayed. + * The list is a list of GaimKeyValuePair items. The key is the ID stored and + * used internally, and the value is the label displayed. * * @param text The text of the option. * @param pref_name The account preference name for the option. diff -r d4cd7d443795 -r 36a0c8719af3 src/gtkaccount.c --- a/src/gtkaccount.c Tue Nov 15 06:06:47 2005 +0000 +++ b/src/gtkaccount.c Tue Nov 15 08:42:03 2005 +0000 @@ -964,6 +964,14 @@ GtkWidget *vbox; GtkWidget *check; GtkWidget *entry; + GtkWidget *combo; + GList *list; + GList *node; + gint i, idx; + GtkListStore *model; + GtkTreeIter iter; + GtkCellRenderer *renderer; + GaimKeyValuePair *kvp; GList *l; char buf[1024]; char *title; @@ -1105,6 +1113,73 @@ break; + case GAIM_PREF_STRING_LIST: + i = 0; + idx = -1; + + if (account == NULL || + strcmp(gaim_account_get_protocol_id(account), + dialog->protocol_id)) + { + str_value = gaim_account_option_get_default_string(option); + } + else + { + str_value = gaim_account_get_string(account, + gaim_account_option_get_setting(option), + gaim_account_option_get_default_string(option)); + } + + + list = gaim_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)); + + //if (gaim_account_option_get_masked(option)) + //gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE); + + /* Loop through list of GaimKeyValuePair items */ + for (node = list; node != NULL; node = node->next) { + if (node->data != NULL) { + kvp = (GaimKeyValuePair *) node->data; + if ((idx < 0) && (kvp->value != NULL) && (str_value != NULL)) + if (!g_utf8_collate(kvp->value, str_value)) + idx = i; + + gtk_list_store_append(model, &iter); + gtk_list_store_set(model, &iter, + 0, kvp->key, + 1, kvp->value, + -1); + } + + i++; + } + + /* Set default */ + if (idx >= 0) + gtk_combo_box_set_active(GTK_COMBO_BOX(combo), idx); + + /* Define renderer */ + renderer = gtk_cell_renderer_text_new(); + gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), renderer, + TRUE); + gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), + renderer, "text", 0, NULL); + + title = g_strdup_printf("%s:", + gaim_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; } @@ -1449,6 +1524,7 @@ GaimPrefType type; GaimAccountOption *option = l->data; GtkWidget *widget = l2->data; + GtkTreeIter iter; const char *setting; int int_value; gboolean bool_value; @@ -1474,6 +1550,12 @@ gaim_account_set_bool(account, setting, bool_value); break; + case GAIM_PREF_STRING_LIST: + 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, &value, -1); + gaim_account_set_string(dialog->account, setting, value); + break; + default: break; } diff -r d4cd7d443795 -r 36a0c8719af3 src/util.h --- a/src/util.h Tue Nov 15 06:06:47 2005 +0000 +++ b/src/util.h Tue Nov 15 08:42:03 2005 +0000 @@ -37,6 +37,22 @@ extern "C" { #endif + +/** + * A key-value pair. + * + * This is used by, among other things, gaim_gtk_combo* functions to pass in a + * list of key-value pairs so it can display a user-friendly value. + */ +typedef struct _GaimKeyValuePair +{ + gchar *key; + void *value; + +} GaimKeyValuePair; + + + /**************************************************************************/ /** @name Base16 Functions */ /**************************************************************************/