Mercurial > pidgin
changeset 12106:36a0c8719af3
[gaim-migrate @ 14403]
Account option lists UI from Don.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Tue, 15 Nov 2005 08:42:03 +0000 |
parents | d4cd7d443795 |
children | 40724851e95e |
files | src/accountopt.h src/gtkaccount.c src/util.h |
diffstat | 3 files changed, 100 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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.
--- 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; }
--- 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 */ /**************************************************************************/