Commit b3e352f4 authored by Benjamin Berg's avatar Benjamin Berg

Improve PICKONE_* handling in GtkPrinterOptionWidget (bug #543520)

This patch modifies GtkPrinterOptionWidget to support loading them
again. It also allows the user to enter values from the dropdown list
to select the item.
parent 6fa6576d
......@@ -366,8 +366,8 @@ combo_box_set (GtkWidget *combo,
gtk_tree_model_foreach (model, set_cb, &set_data);
}
static char *
combo_box_get (GtkWidget *combo)
static gchar *
combo_box_get (GtkWidget *combo, gboolean *custom)
{
GtkTreeModel *model;
gchar *value;
......@@ -377,7 +377,41 @@ combo_box_get (GtkWidget *combo)
value = NULL;
if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter))
gtk_tree_model_get (model, &iter, VALUE_COLUMN, &value, -1);
{
gtk_tree_model_get (model, &iter, VALUE_COLUMN, &value, -1);
*custom = FALSE;
}
else
{
if (gtk_combo_box_get_has_entry (GTK_COMBO_BOX (combo)))
{
value = g_strdup (gtk_entry_get_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (combo)))));
*custom = TRUE;
}
if (!value || !gtk_tree_model_get_iter_first (model, &iter))
return value;
/* If the user entered an item from the dropdown list manually, return
* the non-custom option instead. */
do
{
gchar *val, *name;
gtk_tree_model_get (model, &iter, VALUE_COLUMN, &val,
NAME_COLUMN, &name, -1);
if (g_str_equal (value, name))
{
*custom = FALSE;
g_free (name);
g_free (value);
return val;
}
g_free (val);
g_free (name);
}
while (gtk_tree_model_iter_next (model, &iter));
}
return value;
}
......@@ -558,25 +592,29 @@ combo_changed_cb (GtkWidget *combo,
gchar *value;
gchar *filtered_val = NULL;
gboolean changed;
gboolean custom = TRUE;
g_signal_handler_block (priv->source, priv->source_changed_handler);
value = combo_box_get (combo);
value = combo_box_get (combo, &custom);
/* handle some constraints */
switch (priv->source->type)
/* Handle constraints if the user entered a custom value. */
if (custom)
{
case GTK_PRINTER_OPTION_TYPE_PICKONE_PASSCODE:
filtered_val = filter_numeric (value, FALSE, FALSE, &changed);
break;
case GTK_PRINTER_OPTION_TYPE_PICKONE_INT:
filtered_val = filter_numeric (value, TRUE, FALSE, &changed);
break;
case GTK_PRINTER_OPTION_TYPE_PICKONE_REAL:
filtered_val = filter_numeric (value, TRUE, TRUE, &changed);
break;
default:
break;
switch (priv->source->type)
{
case GTK_PRINTER_OPTION_TYPE_PICKONE_PASSCODE:
filtered_val = filter_numeric (value, FALSE, FALSE, &changed);
break;
case GTK_PRINTER_OPTION_TYPE_PICKONE_INT:
filtered_val = filter_numeric (value, TRUE, FALSE, &changed);
break;
case GTK_PRINTER_OPTION_TYPE_PICKONE_REAL:
filtered_val = filter_numeric (value, TRUE, TRUE, &changed);
break;
default:
break;
}
}
if (filtered_val)
......@@ -873,6 +911,22 @@ update_widgets (GtkPrinterOptionWidget *widget)
case GTK_PRINTER_OPTION_TYPE_STRING:
gtk_entry_set_text (GTK_ENTRY (priv->entry), source->value);
break;
case GTK_PRINTER_OPTION_TYPE_PICKONE_PASSWORD:
case GTK_PRINTER_OPTION_TYPE_PICKONE_PASSCODE:
case GTK_PRINTER_OPTION_TYPE_PICKONE_REAL:
case GTK_PRINTER_OPTION_TYPE_PICKONE_INT:
case GTK_PRINTER_OPTION_TYPE_PICKONE_STRING:
{
GtkEntry *entry;
entry = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (priv->combo)));
if (gtk_printer_option_has_choice (source, source->value))
combo_box_set (priv->combo, source->value);
else
gtk_entry_set_text (entry, source->value);
break;
}
case GTK_PRINTER_OPTION_TYPE_FILESAVE:
{
gchar *filename = g_filename_from_uri (source->value, NULL, NULL);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment