Implement enumeration proxies with custom entries as well

This commit is contained in:
Christian Dywan 2009-11-03 18:01:22 +01:00
parent cadfa53e7a
commit 1c0d18bc06
2 changed files with 60 additions and 34 deletions

View file

@ -195,6 +195,7 @@ proxy_picker_button_changed_cb (HildonPickerButton* button,
gint value = hildon_picker_button_get_active (button);
const gchar* property = g_object_get_data (G_OBJECT (button), "property");
g_object_set (object, property, value, NULL);
/* FIXME: Implement custom-PROPERTY */
}
#else
static void
@ -203,6 +204,36 @@ proxy_combo_box_changed_cb (GtkComboBox* button,
{
gint value = gtk_combo_box_get_active (button);
const gchar* property = g_object_get_data (G_OBJECT (button), "property");
gint custom_value = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
"katze-custom-value"));
if (custom_value)
{
GtkWidget* child = gtk_bin_get_child (GTK_BIN (button));
if (value == custom_value && GTK_IS_CELL_VIEW (child))
{
GtkWidget* entry = gtk_entry_new ();
const gchar* custom_property = g_object_get_data (G_OBJECT (button),
"katze-custom-property");
/* FIXME: Fill in the previous value for convenience
gint old_value = katze_object_get_integer (object, custom_property);
if (old_value && *old_value)
gtk_entry_set_text (GTK_ENTRY (entry), ""); */
gtk_widget_show (entry);
gtk_container_add (GTK_CONTAINER (button), entry);
gtk_widget_grab_focus (entry);
g_signal_connect (entry, "focus-out-event",
G_CALLBACK (proxy_entry_focus_out_event_cb), object);
g_object_set_data_full (G_OBJECT (entry), "property",
g_strdup (custom_property), g_free);
}
else if (value != custom_value && GTK_IS_ENTRY (child))
{
/* Force the combo to change the item again */
gtk_widget_destroy (child);
gtk_combo_box_set_active (button, value + 1);
gtk_combo_box_set_active (button, value);
}
}
g_object_set (object, property, value, NULL);
}
#endif
@ -309,6 +340,9 @@ katze_app_info_get_all_for_category (const gchar* category)
* for choosing an application to open TYPE files, ie. "text/plain".
* "application-CATEGORY": the widget created will be particularly suitable
* for choosing an application to open CATEGORY files, ie. "Network".
* "custom-PROPERTY": the last value of an enumeration will be the "custom"
* value, where the user may enter text freely, which then updates
* the property PROPERTY instead. This applies only to enumerations.
*
* Any other values for @hint are silently ignored.
*
@ -605,6 +639,10 @@ katze_property_proxy (gpointer object,
GEnumClass* enum_class = G_ENUM_CLASS (
g_type_class_ref (pspec->value_type));
gint value = katze_object_get_enum (object, property);
const gchar* custom = NULL;
if (hint && g_str_has_prefix (hint, "custom-"))
custom = &hint[7];
#ifdef HAVE_HILDON_2_2
GtkWidget* selector;
@ -637,6 +675,26 @@ katze_property_proxy (gpointer object,
g_signal_connect (widget, "changed",
G_CALLBACK (proxy_combo_box_changed_cb), object);
#endif
if (custom)
{
if (value == (gint)(enum_class->n_values - 1))
{
GtkWidget* entry = gtk_entry_new ();
gchar* text = katze_object_get_string (object, custom);
if (text && *text)
gtk_entry_set_text (GTK_ENTRY (entry), text);
gtk_widget_show (entry);
gtk_container_add (GTK_CONTAINER (widget), entry);
g_signal_connect (entry, "focus-out-event",
G_CALLBACK (proxy_entry_focus_out_event_cb), object);
g_object_set_data_full (G_OBJECT (entry), "property",
g_strdup (custom), g_free);
}
g_object_set_data (G_OBJECT (widget), "katze-custom-value",
GINT_TO_POINTER (enum_class->n_values - 1));
g_object_set_data (G_OBJECT (widget), "katze-custom-property",
(gpointer)custom);
}
g_type_class_unref (enum_class);
}
else

View file

@ -170,17 +170,6 @@ midori_preferences_homepage_current_clicked_cb (GtkWidget* button,
}
}
static void
midori_preferences_notify_preferred_encoding_cb (MidoriWebSettings* settings,
GParamSpec* pspec,
GtkWidget* entry)
{
MidoriPreferredEncoding preferred_encoding;
preferred_encoding = katze_object_get_enum (settings, "preferred-encoding");
gtk_widget_set_sensitive (entry, preferred_encoding == MIDORI_ENCODING_CUSTOM);
}
#if !HAVE_HILDON
static void
midori_preferences_notify_auto_detect_proxy_cb (MidoriWebSettings* settings,
@ -194,16 +183,6 @@ midori_preferences_notify_auto_detect_proxy_cb (MidoriWebSettings* settings,
}
#endif
static void
midori_preferences_notify_identify_as_cb (MidoriWebSettings* settings,
GParamSpec* pspec,
GtkWidget* entry)
{
MidoriIdentity identify_as = katze_object_get_enum (settings, "identify-as");
gtk_widget_set_sensitive (entry, identify_as == MIDORI_IDENT_CUSTOM);
}
#if HAVE_OSX
static void
midori_preferences_help_clicked_cb (GtkWidget* button,
@ -401,14 +380,8 @@ midori_preferences_set_settings (MidoriPreferences* preferences,
#endif
label = katze_property_label (settings, "preferred-encoding");
INDENTED_ADD (label);
button = katze_property_proxy (settings, "preferred-encoding", NULL);
button = katze_property_proxy (settings, "preferred-encoding", "custom-default-encoding");
SPANNED_ADD (button);
entry = katze_property_proxy (settings, "default-encoding", NULL);
gtk_widget_set_tooltip_text (entry, _("The character encoding to use by default"));
g_signal_connect (settings, "notify::preferred-encoding",
G_CALLBACK (midori_preferences_notify_preferred_encoding_cb), entry);
midori_preferences_notify_preferred_encoding_cb (settings, NULL, entry);
SPANNED_ADD (entry);
/* Page "Behavior" */
PAGE_NEW (GTK_STOCK_SELECT_COLOR, _("Behavior"));
@ -538,13 +511,8 @@ midori_preferences_set_settings (MidoriPreferences* preferences,
#endif
label = katze_property_label (settings, "identify-as");
INDENTED_ADD (label);
button = katze_property_proxy (settings, "identify-as", NULL);
button = katze_property_proxy (settings, "identify-as", "custom-ident-string");
SPANNED_ADD (button);
entry = katze_property_proxy (settings, "ident-string", NULL);
g_signal_connect (settings, "notify::identify-as",
G_CALLBACK (midori_preferences_notify_identify_as_cb), entry);
midori_preferences_notify_identify_as_cb (settings, NULL, entry);
SPANNED_ADD (entry);
/* Page "Privacy" */
PAGE_NEW (GTK_STOCK_INDEX, _("Privacy"));