aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ephy-dialog.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ephy-dialog.c')
-rw-r--r--lib/ephy-dialog.c1144
1 files changed, 17 insertions, 1127 deletions
diff --git a/lib/ephy-dialog.c b/lib/ephy-dialog.c
index f39a9f7b5..1ca4d0daa 100644
--- a/lib/ephy-dialog.c
+++ b/lib/ephy-dialog.c
@@ -23,7 +23,6 @@
#include "ephy-dialog.h"
#include "ephy-state.h"
#include "ephy-gui.h"
-#include "eel-gconf-extensions.h"
#include "ephy-debug.h"
#include <stdlib.h>
@@ -46,41 +45,17 @@ enum
PROP_DEFAULT_HEIGHT
};
-typedef enum
-{
- PT_TOGGLEBUTTON,
- PT_RADIOBUTTON,
- PT_SPINBUTTON,
- PT_COMBOBOX,
- PT_EDITABLE,
- PT_UNKNOWN
-} WidgetType;
-
-typedef struct
-{
- const char *id;
- EphyDialog *dialog;
- char *pref;
- EphyDialogApplyType apply_type;
- GtkWidget *widget;
- WidgetType widget_type;
- GType data_type;
- GList *string_enum;
- int data_col;
- gboolean loaded;
- gboolean sane_state;
-} PropertyInfo;
-
#define EPHY_DIALOG_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_DIALOG, EphyDialogPrivate))
struct _EphyDialogPrivate
{
char *name;
- GHashTable *props;
GtkWidget *parent;
GtkWidget *dialog;
+ GtkBuilder *builder;
+
guint has_default_size : 1;
guint disposing : 1;
guint initialized : 1;
@@ -89,8 +64,6 @@ struct _EphyDialogPrivate
int default_height;
};
-#define SPIN_DELAY 0.20
-
enum
{
CHANGED,
@@ -132,905 +105,6 @@ ephy_dialog_get_type (void)
return type;
}
-static PropertyInfo *
-lookup_info (EphyDialog *dialog, const char *id)
-{
- return g_hash_table_lookup (dialog->priv->props, id);
-}
-
-static void
-set_sensitivity (PropertyInfo *info, gboolean sensitive)
-{
- g_return_if_fail (info->widget != NULL);
-
- if (info->widget_type == PT_RADIOBUTTON)
- {
- GSList *list, *l;
-
- list = gtk_radio_button_get_group (GTK_RADIO_BUTTON (info->widget));
-
- for (l = list; l != NULL; l = l->next)
- {
- sensitive = gtk_widget_is_sensitive (GTK_WIDGET (l->data)) && sensitive;
- gtk_widget_set_sensitive (GTK_WIDGET (l->data), sensitive);
- }
- }
- else if (info->widget_type == PT_EDITABLE)
- {
- sensitive = gtk_widget_is_sensitive (info->widget) && sensitive;
- gtk_editable_set_editable (GTK_EDITABLE (info->widget), sensitive);
- }
- else
- {
- sensitive = gtk_widget_is_sensitive (info->widget) && sensitive;
- gtk_widget_set_sensitive (info->widget, sensitive);
- }
-}
-
-static void
-set_value_from_pref (PropertyInfo *info, GValue *value)
-{
- char *text;
-
- switch (info->data_type)
- {
- case G_TYPE_STRING:
- g_value_init (value, G_TYPE_STRING);
- text = eel_gconf_get_string (info->pref);
- g_value_take_string (value, text);
- break;
- case G_TYPE_INT:
- g_value_init (value, G_TYPE_INT);
- g_value_set_int (value, eel_gconf_get_integer (info->pref));
- break;
- case G_TYPE_FLOAT:
- g_value_init (value, G_TYPE_FLOAT);
- g_value_set_float (value, eel_gconf_get_float (info->pref));
- break;
- case G_TYPE_BOOLEAN:
- g_value_init (value, G_TYPE_BOOLEAN);
- g_value_set_boolean (value, eel_gconf_get_boolean (info->pref));
- break;
- default:
- g_warning ("Unsupported value read from pref %s\n", info->pref);
- break;
- }
-}
-
-static void
-set_pref_from_value (PropertyInfo *info, GValue *value)
-{
- const char *pref = info->pref;
-
- if (!G_VALUE_HOLDS (value, info->data_type))
- {
- g_warning ("Value type mismatch for id[%s], pref[%s]", info->id, info->pref);
- return;
- }
-
- switch (info->data_type)
- {
- case G_TYPE_STRING:
- {
- const char *string = g_value_get_string (value);
- if (string != NULL)
- {
- eel_gconf_set_string (pref, string);
- }
- else
- {
- eel_gconf_unset_key (pref);
- }
- break;
- }
- case G_TYPE_INT:
- eel_gconf_set_integer (pref, g_value_get_int (value));
- break;
- case G_TYPE_FLOAT:
- eel_gconf_set_float (pref, g_value_get_float (value));
- break;
- case G_TYPE_BOOLEAN:
- eel_gconf_set_boolean (pref, g_value_get_boolean (value));
- break;
- default:
- break;
- }
-}
-
-static gboolean
-set_value_from_editable (PropertyInfo *info, GValue *value)
-{
- char *text;
- gboolean retval = TRUE;
- gboolean free_text = TRUE;
-
- g_return_val_if_fail (GTK_IS_EDITABLE (info->widget), FALSE);
-
- text = gtk_editable_get_chars (GTK_EDITABLE (info->widget), 0, -1);
-
- g_value_init (value, info->data_type);
- switch (info->data_type)
- {
- case G_TYPE_STRING:
- g_value_take_string (value, text);
- free_text = FALSE;
- break;
- /* FIXME : handle possible errors in the input for int and float */
- case G_TYPE_INT:
- g_value_set_int (value, atoi (text));
- break;
- case G_TYPE_FLOAT:
- g_value_set_float (value, strtod (text, NULL));
- break;
- default:
- retval = FALSE;
- g_value_unset (value);
- g_warning ("Unsupported value type for editable %s", info->id);
- break;
- }
-
- if (free_text)
- {
- g_free (text);
- }
-
- return retval;
-}
-
-static gboolean
-set_value_from_combobox (PropertyInfo *info, GValue *value)
-{
- g_return_val_if_fail (GTK_IS_COMBO_BOX (info->widget), FALSE);
-
- if (info->data_col != -1)
- {
- GtkTreeModel *model;
- GtkTreeIter iter;
-
- if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (info->widget), &iter))
- {
- model = gtk_combo_box_get_model (GTK_COMBO_BOX (info->widget));
- gtk_tree_model_get_value (model, &iter, info->data_col, value);
-
- return TRUE;
- }
- }
- else if (info->data_type == G_TYPE_INT)
- {
- int index;
-
- index = gtk_combo_box_get_active (GTK_COMBO_BOX (info->widget));
-
- if (index >= 0)
- {
- g_value_init (value, G_TYPE_INT);
- g_value_set_int (value, index);
-
- return TRUE;
- }
- }
- else
- {
- g_warning ("Unsupported data type for combo %s\n", info->id);
- }
-
- return FALSE;
-}
-
-static int
-get_radio_button_active_index (GtkWidget *radiobutton)
-{
- GtkToggleButton *toggle_button;
- GSList *list;
- int index, i, length;
-
- /* get group list */
- list = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiobutton));
- length = g_slist_length (list);
-
- /* iterate over list to find active button */
- for (i = 0; list != NULL; i++, list = list->next)
- {
- /* get button and text */
- toggle_button = GTK_TOGGLE_BUTTON (list->data);
- if (gtk_toggle_button_get_active (toggle_button))
- {
- break;
- }
- }
-
- /* check we didn't run off end */
- g_assert (list != NULL);
-
- /* return index (reverse order!) */
- return index = (length - 1) - i;
-}
-
-static gboolean
-set_value_from_radiobuttongroup (PropertyInfo *info, GValue *value)
-{
- gboolean retval = TRUE;
- int index;
-
- g_return_val_if_fail (GTK_IS_RADIO_BUTTON (info->widget), FALSE);
-
- index = get_radio_button_active_index (info->widget);
- g_return_val_if_fail (index >= 0, FALSE);
-
- if (info->data_type == G_TYPE_STRING)
- {
- g_return_val_if_fail (info->string_enum != NULL, FALSE);
- g_return_val_if_fail (g_list_nth_data (info->string_enum, index) != NULL, FALSE);
-
- g_value_init (value, G_TYPE_STRING);
- g_value_set_string (value, (char*) g_list_nth_data (info->string_enum, index));
- }
- else if (info->data_type == G_TYPE_INT)
- {
- g_value_init (value, G_TYPE_INT);
- g_value_set_int (value, index);
- }
- else
- {
- retval = FALSE;
- g_warning ("unsupported data type for radio button %s\n", info->id);
- }
-
- return retval;
-}
-
-static gboolean
-set_value_from_spin_button (PropertyInfo *info, GValue *value)
-{
- gboolean retval = TRUE;
- gdouble f;
- gboolean is_int;
-
- g_return_val_if_fail (GTK_IS_SPIN_BUTTON (info->widget), FALSE);
-
- f = gtk_spin_button_get_value (GTK_SPIN_BUTTON (info->widget));
-
- is_int = (gtk_spin_button_get_digits (GTK_SPIN_BUTTON(info->widget)) == 0);
-
- if (info->data_type == G_TYPE_INT && is_int)
- {
- g_value_init (value, G_TYPE_INT);
- g_value_set_int (value, (int) f);
- }
- else if (info->data_type == G_TYPE_FLOAT)
- {
- g_value_init (value, G_TYPE_FLOAT);
- g_value_set_float (value, f);
- }
- else
- {
- retval = FALSE;
- g_warning ("Unsupported data type for spin button %s\n", info->id);
- }
-
- return retval;
-}
-
-static gboolean
-set_value_from_togglebutton (PropertyInfo *info, GValue *value)
-{
- gboolean retval = TRUE;
- gboolean active;
-
- g_return_val_if_fail (GTK_IS_TOGGLE_BUTTON (info->widget), FALSE);
-
- active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (info->widget));
-
- if (info->apply_type & PT_INVERTED)
- {
- active = !active;
- }
-
- if (info->data_type == G_TYPE_BOOLEAN)
- {
- g_value_init (value, info->data_type);
- g_value_set_boolean (value, active);
- }
- else
- {
- retval = FALSE;
- g_warning ("Unsupported data type for toggle button %s\n", info->id);
- }
-
- return retval;
-}
-
-static gboolean
-set_value_from_info (PropertyInfo *info, GValue *value)
-{
- gboolean retval;
-
- if (info->sane_state == FALSE)
- {
- return FALSE;
- }
-
- switch (info->widget_type)
- {
- case PT_SPINBUTTON:
- retval = set_value_from_spin_button (info, value);
- break;
- case PT_RADIOBUTTON:
- retval = set_value_from_radiobuttongroup (info, value);
- break;
- case PT_TOGGLEBUTTON:
- retval = set_value_from_togglebutton (info, value);
- break;
- case PT_EDITABLE:
- retval = set_value_from_editable (info, value);
- break;
- case PT_COMBOBOX:
- retval = set_value_from_combobox (info, value);
- break;
- default:
- retval = FALSE;
- g_warning ("Unsupported widget type\n");
- break;
- }
-
- return retval;
-}
-
-static void
-set_editable_from_value (PropertyInfo *info, const GValue *value)
-{
- char *text = NULL;
- int pos = 0; /* insertion position */
-
- g_return_if_fail (GTK_IS_EDITABLE (info->widget));
-
- switch (info->data_type)
- {
- case G_TYPE_STRING:
- text = g_value_dup_string (value);
- break;
- case G_TYPE_INT:
- text = g_strdup_printf ("%d", g_value_get_int (value));
- break;
- case G_TYPE_FLOAT:
- text = g_strdup_printf ("%.2f", g_value_get_float (value));
- break;
- default:
- break;
- }
-
- if (text == NULL)
- {
- text = g_strdup ("");
- }
-
- info->sane_state = TRUE;
-
- gtk_editable_delete_text (GTK_EDITABLE (info->widget), 0, -1);
- gtk_editable_insert_text (GTK_EDITABLE (info->widget), text, strlen (text), &pos);
-
- g_free (text);
-}
-
-static int
-strcmp_with_null (const char *key1,
- const char *key2)
-{
- if (key1 == NULL && key2 == NULL)
- {
- return 0;
- }
- if (key1 == NULL)
- {
- return -1;
- }
- if (key2 == NULL)
- {
- return 1;
- }
-
- return strcmp (key1, key2);
-}
-
-static int
-get_index_from_value (const GValue *value, GList *string_enum)
-{
- int index = -1;
- const char *val;
- GList *s = NULL;
-
- if (string_enum)
- {
- val = g_value_get_string (value);
-
- s = g_list_find_custom (string_enum, val, (GCompareFunc) strcmp_with_null);
-
- if (s)
- {
- index = g_list_position (string_enum, s);
- }
-
- }
- else
- {
- index = g_value_get_int (value);
- }
-
- return index;
-}
-
-static gboolean
-compare_values (const GValue *a, const GValue *b)
-{
- if (G_VALUE_HOLDS (a, G_TYPE_STRING))
- {
- const char *ta, *tb;
-
- ta = g_value_get_string (a);
- tb = g_value_get_string (b);
-
- return (strcmp_with_null (ta, tb) == 0);
- }
- else if (G_VALUE_HOLDS (a, G_TYPE_INT))
- {
- return g_value_get_int (a) == g_value_get_int (b);
- }
- else if (G_VALUE_HOLDS (a, G_TYPE_FLOAT))
- {
- return g_value_get_float (a) == g_value_get_float (b);
- }
- else if (G_VALUE_HOLDS (a, G_TYPE_BOOLEAN))
- {
- return g_value_get_boolean (a) == g_value_get_boolean (b);
- }
-
- return FALSE;
-}
-
-static void
-set_combo_box_from_value (PropertyInfo *info, const GValue *value)
-{
- g_return_if_fail (GTK_IS_COMBO_BOX (info->widget));
-
- if (info->data_col != -1)
- {
- GValue data = { 0, };
- GtkTreeModel *model;
- GtkTreeIter iter;
- gboolean valid, found = FALSE;
-
- model = gtk_combo_box_get_model (GTK_COMBO_BOX (info->widget));
-
- valid = gtk_tree_model_get_iter_first (model, &iter);
- while (valid)
- {
- gtk_tree_model_get_value (model, &iter, info->data_col, &data);
- found = compare_values (&data, value);
- g_value_unset (&data);
-
- if (found) break;
-
- valid = gtk_tree_model_iter_next (model, &iter);
- }
-
- if (found)
- {
- gtk_combo_box_set_active_iter (GTK_COMBO_BOX (info->widget), &iter);
- }
- else
- {
- gtk_combo_box_set_active (GTK_COMBO_BOX (info->widget), 0);
- }
-
- info->sane_state = found;
- }
- else if (info->data_type == G_TYPE_INT)
- {
- int index;
-
- index = g_value_get_int (value);
-
- info->sane_state = index >= 0;
-
- g_return_if_fail (index >= -1);
-
- gtk_combo_box_set_active (GTK_COMBO_BOX (info->widget), index);
- }
- else
- {
- g_warning ("Unsupported data type for combo box %s\n", info->id);
- }
-}
-
-static void
-set_radiobuttongroup_from_value (PropertyInfo *info, const GValue *value)
-{
- GtkToggleButton *button;
- GSList *list;
- gint length;
- int index;
-
- g_return_if_fail (GTK_IS_RADIO_BUTTON (info->widget));
-
- list = gtk_radio_button_get_group (GTK_RADIO_BUTTON (info->widget));
-
- length = g_slist_length (list);
-
- index = get_index_from_value (value, info->string_enum);
-
- /* new buttons are *prepended* to the list, so button added as first
- * has last position in the list */
- index = (length - 1) - index;
-
- if (index < 0 || index >= length)
- {
- info->sane_state = FALSE;
- g_return_if_fail (index >= 0 && index < length);
- return;
- }
-
- button = GTK_TOGGLE_BUTTON (g_slist_nth_data (list, index));
- g_return_if_fail (button != NULL);
-
- info->sane_state = TRUE;
-
- if (gtk_toggle_button_get_active (button) == FALSE)
- {
- gtk_toggle_button_set_active (button, TRUE);
- }
-}
-
-static void
-set_spin_button_from_value (PropertyInfo *info, const GValue *value)
-{
- gdouble f = 0.0;
- gboolean is_int;
-
- g_return_if_fail (GTK_IS_SPIN_BUTTON (info->widget));
-
- is_int = (gtk_spin_button_get_digits (GTK_SPIN_BUTTON (info->widget)) == 0);
-
- if (info->data_type == G_TYPE_INT && is_int)
- {
- f = (float) g_value_get_int (value);
- }
- else if (info->data_type == G_TYPE_FLOAT)
- {
- f = g_value_get_float (value);
- }
- else
- {
- info->sane_state = FALSE;
- g_warning ("Unsupported data type for spin button %s\n", info->id);
- return;
- }
-
- info->sane_state = TRUE;
-
- gtk_spin_button_set_value (GTK_SPIN_BUTTON (info->widget), f);
-}
-
-static void
-set_togglebutton_from_value (PropertyInfo *info, const GValue *value)
-{
- gboolean active;
-
- g_return_if_fail (GTK_IS_TOGGLE_BUTTON (info->widget));
- g_return_if_fail (info->data_type == G_TYPE_BOOLEAN);
-
- active = g_value_get_boolean (value);
-
- if (info->apply_type & PT_INVERTED)
- {
- active = !active;
- }
-
- info->sane_state = TRUE;
-
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (info->widget), active);
-}
-
-static void
-set_info_from_value (PropertyInfo *info, const GValue *value)
-{
- if (!G_VALUE_HOLDS (value, info->data_type))
- {
- g_warning ("Incompatible value types for id %s\n", info->id);
- return;
- }
-
- switch (info->widget_type)
- {
- case PT_SPINBUTTON:
- set_spin_button_from_value (info, value);
- break;
- case PT_RADIOBUTTON:
- set_radiobuttongroup_from_value (info, value);
- break;
- case PT_TOGGLEBUTTON:
- set_togglebutton_from_value (info, value);
- break;
- case PT_EDITABLE:
- set_editable_from_value (info, value);
- break;
- case PT_COMBOBOX:
- set_combo_box_from_value (info, value);
- break;
- default:
- g_warning ("Unknown widget type\n");
- break;
- }
-}
-
-/* widget changed callbacks */
-
-static void
-set_pref_from_info_and_emit (PropertyInfo *info)
-{
- GValue value = { 0, };
-
- if (!set_value_from_info (info, &value))
- {
- return;
- }
-
- g_signal_emit (info->dialog, signals[CHANGED], g_quark_from_string (info->id), &value);
-
- if ((info->apply_type & PT_AUTOAPPLY) && info->pref != NULL)
- {
- set_pref_from_value (info, &value);
- }
-
- g_value_unset (&value);
-}
-
-static void
-togglebutton_clicked_cb (GtkWidget *widget, PropertyInfo *info)
-{
- info->sane_state = TRUE;
-
- set_pref_from_info_and_emit (info);
-}
-
-static void
-radiobutton_clicked_cb (GtkWidget *widget, PropertyInfo *info)
-{
- info->sane_state = TRUE;
-
- if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget)))
- {
- return;
- }
-
- set_pref_from_info_and_emit (info);
-}
-
-static gboolean
-spinbutton_timeout_cb (PropertyInfo *info)
-{
- GTimer *spin_timer;
-
- spin_timer = (GTimer *) g_object_get_data (G_OBJECT (info->widget), "timer");
-
- /* timer still valid? */
- if (spin_timer == NULL)
- {
- /* don't call me again */
- return FALSE;
- }
-
- /* okay, we're ready to set */
- if (g_timer_elapsed (spin_timer, NULL) >= SPIN_DELAY)
- {
- /* kill off the timer */
- g_timer_destroy (spin_timer);
- g_object_set_data (G_OBJECT (info->widget), "timer", NULL);
-
- /* HACK update the spinbutton here so that the
- * changes made directly in the entry are accepted
- * and set in the pref. Otherwise the old value is used */
- gtk_spin_button_update (GTK_SPIN_BUTTON (info->widget));
-
- info->sane_state = TRUE;
-
- set_pref_from_info_and_emit (info);
-
- /* done, don't run again */
- return FALSE;
- }
-
- /* not elapsed yet, call me again */
- return TRUE;
-}
-
-static void
-spinbutton_changed_cb (GtkWidget *widget, PropertyInfo *info)
-{
- GTimer *spin_timer;
-
- if ((info->apply_type & PT_AUTOAPPLY) == 0) return;
-
- spin_timer = g_object_get_data (G_OBJECT (info->widget), "timer");
-
- /* destroy an existing timer */
- if (spin_timer != NULL)
- {
- g_timer_destroy (spin_timer);
- }
-
- /* start tnew timer */
- spin_timer = g_timer_new();
- g_timer_start (spin_timer);
- g_object_set_data (G_OBJECT (info->widget), "timer", spin_timer);
-
- g_timeout_add (50, (GSourceFunc) spinbutton_timeout_cb, info);
-}
-
-static void
-changed_cb (GtkWidget *widget, PropertyInfo *info)
-{
- info->sane_state = TRUE;
-
- set_pref_from_info_and_emit (info);
-}
-
-static void
-connect_signals (gpointer key, PropertyInfo *info, EphyDialog *dialog)
-{
- GSList *list;
-
- g_return_if_fail (info->widget != NULL);
-
- switch (info->widget_type)
- {
- case PT_TOGGLEBUTTON:
- g_signal_connect (G_OBJECT (info->widget), "clicked",
- G_CALLBACK (togglebutton_clicked_cb),
- (gpointer)info);
- break;
- case PT_RADIOBUTTON:
- list = gtk_radio_button_get_group
- (GTK_RADIO_BUTTON (info->widget));
- for (; list != NULL; list = list->next)
- {
- g_signal_connect
- (G_OBJECT (list->data), "clicked",
- G_CALLBACK (radiobutton_clicked_cb),
- info);
- }
- break;
- case PT_SPINBUTTON:
- g_signal_connect (G_OBJECT (info->widget), "changed",
- G_CALLBACK (spinbutton_changed_cb),
- info);
- break;
- case PT_COMBOBOX:
- g_signal_connect (G_OBJECT (info->widget), "changed",
- G_CALLBACK (changed_cb), info);
- break;
- case PT_EDITABLE:
- g_signal_connect (G_OBJECT (info->widget), "changed",
- G_CALLBACK (changed_cb), info);
- break;
- case PT_UNKNOWN:
- break;
- }
-}
-
-static void
-disconnect_signals (gpointer key, PropertyInfo *info, EphyDialog *dialog)
-{
- g_return_if_fail (info->widget != NULL);
-
- g_signal_handlers_disconnect_matched (info->widget, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, info);
-}
-
-static void
-init_props (EphyDialog *dialog, const EphyDialogProperty *properties, GtkBuilder *builder)
-{
- int i;
-
- for (i = 0 ; properties[i].id != NULL; i++)
- {
- PropertyInfo *info = g_new0 (PropertyInfo, 1);
-
- info->id = properties[i].id;
- info->dialog = dialog;
- info->pref = g_strdup (properties[i].pref);
- info->apply_type = properties[i].apply_type;
- info->string_enum = NULL;
- info->data_col = -1;
-
- info->widget = (GtkWidget*)gtk_builder_get_object (builder, info->id);
-
- if (GTK_IS_COMBO_BOX (info->widget))
- {
- info->widget_type = PT_COMBOBOX;
- info->data_type = G_TYPE_INT;
- }
- else if (GTK_IS_SPIN_BUTTON (info->widget))
- {
- info->widget_type = PT_SPINBUTTON;
- info->data_type = G_TYPE_INT;
- }
- else if (GTK_IS_RADIO_BUTTON (info->widget))
- {
- info->widget_type = PT_RADIOBUTTON;
- info->data_type = G_TYPE_INT;
- }
- else if (GTK_IS_TOGGLE_BUTTON (info->widget))
- {
- info->widget_type = PT_TOGGLEBUTTON;
- info->data_type = G_TYPE_BOOLEAN;
- }
- else if (GTK_IS_EDITABLE (info->widget))
- {
- info->widget_type = PT_EDITABLE;
- info->data_type = G_TYPE_STRING;
- }
- else
- {
- info->widget_type = PT_UNKNOWN;
- info->data_type = G_TYPE_INVALID;
- }
-
- if (properties[i].data_type != 0)
- {
- info->data_type = properties[i].data_type;
- }
-
- info->loaded = FALSE;
- info->sane_state = FALSE;
-
- g_hash_table_insert (dialog->priv->props, (char *) info->id, info);
- }
-}
-
-static void
-load_info (gpointer key, PropertyInfo *info, EphyDialog *dialog)
-{
- GValue value = { 0, };
-
- g_return_if_fail (info->widget != NULL);
-
- if (info->pref != NULL)
- {
- set_value_from_pref (info, &value);
- set_info_from_value (info, &value);
-
- g_signal_emit (info->dialog, signals[CHANGED], g_quark_from_string (info->id), &value);
-
- g_value_unset (&value);
-
- set_sensitivity (info, eel_gconf_key_is_writable (info->pref));
- }
-
- info->loaded = TRUE;
-}
-
-static void
-save_info (gpointer key, PropertyInfo *info, EphyDialog *dialog)
-{
- GValue value = { 0, };
-
- if (info->pref == NULL || (info->apply_type & PT_NORMAL) == 0)
- {
- return;
- }
-
- if (!info->sane_state)
- {
- g_warning ("Not persisting insane state of id[%s]", info->id);
- return;
- }
-
- if (set_value_from_info (info, &value))
- {
- set_pref_from_value (info, &value);
- g_value_unset (&value);
- }
-}
-
static void
setup_default_size (EphyDialog *dialog)
{
@@ -1058,8 +132,6 @@ setup_default_size (EphyDialog *dialog)
static void
dialog_destroy_cb (GtkWidget *widget, EphyDialog *dialog)
{
- g_hash_table_foreach (dialog->priv->props, (GHFunc) save_info, dialog);
-
if (dialog->priv->disposing == FALSE)
{
g_object_unref (dialog);
@@ -1068,7 +140,6 @@ dialog_destroy_cb (GtkWidget *widget, EphyDialog *dialog)
static void
impl_construct (EphyDialog *dialog,
- const EphyDialogProperty *properties,
const char *file,
const char *name,
const char *domain)
@@ -1087,7 +158,9 @@ impl_construct (EphyDialog *dialog,
return;
}
- priv->dialog = (GtkWidget*)gtk_builder_get_object (builder, name);
+ priv->builder = g_object_ref (builder);
+ priv->dialog = GTK_WIDGET (gtk_builder_get_object (builder, name));
+
g_return_if_fail (priv->dialog != NULL);
if (priv->name == NULL)
@@ -1095,11 +168,6 @@ impl_construct (EphyDialog *dialog,
priv->name = g_strdup (name);
}
- if (properties)
- {
- init_props (dialog, properties, builder);
- }
-
g_signal_connect_object (dialog->priv->dialog, "destroy",
G_CALLBACK(dialog_destroy_cb), dialog, 0);
@@ -1109,14 +177,6 @@ impl_construct (EphyDialog *dialog,
static void
impl_show (EphyDialog *dialog)
{
- if (dialog->priv->initialized == FALSE)
- {
- dialog->priv->initialized = TRUE;
-
- g_hash_table_foreach (dialog->priv->props, (GHFunc) load_info, dialog);
- g_hash_table_foreach (dialog->priv->props, (GHFunc) connect_signals, dialog);
- }
-
setup_default_size (dialog);
if (dialog->priv->parent != NULL)
@@ -1132,100 +192,6 @@ impl_show (EphyDialog *dialog)
}
/**
- * ephy_dialog_add_enum:
- * @dialog: an #EphyDialog
- * @property_id: string identifier of the property to modify
- * @n_items: length of @items array
- * @items: array of items to add to @property_id
- *
- * Modifies the property identified by @property_id in @dialog to have its
- * string_enum member set to a #GList constructed with the elements given as
- * @items.
- **/
-void
-ephy_dialog_add_enum (EphyDialog *dialog,
- const char *property_id,
- guint n_items,
- const char *const *items)
-{
- PropertyInfo *info;
- int i = 0;
- GList *l = NULL;
-
- g_return_if_fail (EPHY_IS_DIALOG (dialog));
-
- info = lookup_info (dialog, property_id);
- g_return_if_fail (info != NULL);
-
- for (i = 0; i < n_items; i++)
- {
- l = g_list_prepend (l, g_strdup (items[i]));
- }
-
- info->string_enum = g_list_reverse (l);
-}
-
-/**
- * ephy_dialog_set_data_column:
- * @dialog: an #EphyDialog
- * @property_id: string identifier of the property to modify
- * @column: value for the data_col member of @property_id
- *
- * Sets the data_col member of the property identified by @property_id in @dialog
- * to @column.
- **/
-void
-ephy_dialog_set_data_column (EphyDialog *dialog,
- const char *property_id,
- int column)
-{
- PropertyInfo *info;
-
- g_return_if_fail (EPHY_IS_DIALOG (dialog));
-
- info = lookup_info (dialog, property_id);
- g_return_if_fail (info != NULL);
-
- info->data_col = column;
-}
-
-/**
- * ephy_dialog_set_pref:
- * @dialog: an #EphyDialog
- * @property_id: string identifier of the property to modify
- * @pref: preference value of the property identified by @property_id
- *
- * Sets the pref member of the property of @dialog identified by @property_id
- * to @pref.
- **/
-void
-ephy_dialog_set_pref (EphyDialog *dialog,
- const char *property_id,
- const char *pref)
-{
- PropertyInfo *info;
-
- g_return_if_fail (EPHY_IS_DIALOG (dialog));
-
- info = lookup_info (dialog, property_id);
- g_return_if_fail (info != NULL);
-
- disconnect_signals (NULL, info, dialog);
-
- info->loaded = FALSE;
- info->sane_state = FALSE;
- g_free (info->pref);
- info->pref = g_strdup (pref);
-
- if (dialog->priv->initialized)
- {
- /* dialog is already initialised, so initialise this here */
- load_info (NULL, info, dialog);
- connect_signals (NULL, info, dialog);
- }
-}
-
-/**
* ephy_dialog_set_size_group:
* @dialog: an #EphyDialog
* @first_id: id of a widget in @dialog
@@ -1250,14 +216,12 @@ ephy_dialog_set_size_group (EphyDialog *dialog,
while (first_id != NULL)
{
- PropertyInfo *info;
+ GtkWidget *widget;
- info = lookup_info (dialog, first_id);
- g_return_if_fail (info != NULL);
+ widget = ephy_dialog_get_control (dialog, first_id);
+ g_return_if_fail (widget != NULL);
- g_return_if_fail (info->widget != NULL);
-
- gtk_size_group_add_widget (size_group, info->widget);
+ gtk_size_group_add_widget (size_group, widget);
first_id = va_arg (vl, const char*);
}
@@ -1270,24 +234,21 @@ ephy_dialog_set_size_group (EphyDialog *dialog,
/**
* ephy_dialog_construct:
* @dialog: an #EphyDialog
- * @properties: an array of #EphyDialogProperty elements
* @file: the path to a #GtkBuilder file
* @name: name of the widget to use for @dialog, found in @file
* @domain: translation domain to set for @dialog
*
* Constructs the widget part of @dialog using the widget identified by @name
- * in the #GtkBuilder file found at @file. Fills the dialog properties with
- * @properties and sets translation domain to @domain.
+ * in the #GtkBuilder file found at @file.
**/
void
ephy_dialog_construct (EphyDialog *dialog,
- const EphyDialogProperty *properties,
const char *file,
const char *name,
const char *domain)
{
EphyDialogClass *klass = EPHY_DIALOG_GET_CLASS (dialog);
- klass->construct (dialog, properties, file, name, domain);
+ klass->construct (dialog, file, name, domain);
}
/**
@@ -1354,16 +315,16 @@ ephy_dialog_run (EphyDialog *dialog)
**/
GtkWidget *
ephy_dialog_get_control (EphyDialog *dialog,
- const char *property_id)
+ const char *object_id)
{
- PropertyInfo *info;
+ GtkWidget *widget;
g_return_val_if_fail (EPHY_IS_DIALOG (dialog), NULL);
- info = lookup_info (dialog, property_id);
- g_return_val_if_fail (info != NULL, NULL);
+ widget = GTK_WIDGET (gtk_builder_get_object (dialog->priv->builder,
+ object_id));
- return info->widget;
+ return widget;
}
/**
@@ -1383,7 +344,6 @@ ephy_dialog_get_controls (EphyDialog *dialog,
const char *first_id,
...)
{
- PropertyInfo *info;
GtkWidget **wptr;
va_list varargs;
@@ -1391,11 +351,8 @@ ephy_dialog_get_controls (EphyDialog *dialog,
while (first_id != NULL)
{
- info = lookup_info (dialog, first_id);
- g_return_if_fail (info != NULL);
-
wptr = va_arg (varargs, GtkWidget **);
- *wptr = info->widget;
+ *wptr = ephy_dialog_get_control (dialog, first_id);
first_id = va_arg (varargs, const char *);
}
@@ -1403,68 +360,6 @@ ephy_dialog_get_controls (EphyDialog *dialog,
va_end (varargs);
}
-/**
- * ephy_dialog_get_value:
- * @dialog: an #EphyDialog
- * @property_id: property name
- * @value: (out): location to store the value of @property_id
- *
- * Gets the value of @property_id and stores it in @value.
- *
- * Returns: %TRUE if the operation was successful
- */
-gboolean
-ephy_dialog_get_value (EphyDialog *dialog,
- const char *property_id,
- GValue *value)
-{
- PropertyInfo *info;
-
- g_return_val_if_fail (EPHY_IS_DIALOG (dialog), FALSE);
-
- info = lookup_info (dialog, property_id);
- g_return_val_if_fail (info != NULL, FALSE);
-
- return set_value_from_info (info, value);
-}
-
-/**
- * ephy_dialog_set_value:
- * @dialog: an #EphyDialog
- * @property_id: @dialog property to set
- * @value: value to set @property_id to
- *
- * Sets the property identified by @property_id to @value in @dialog.
- **/
-void
-ephy_dialog_set_value (EphyDialog *dialog,
- const char *property_id,
- const GValue *value)
-{
- PropertyInfo *info;
-
- g_return_if_fail (EPHY_IS_DIALOG (dialog));
-
- info = lookup_info (dialog, property_id);
- g_return_if_fail (info != NULL);
-
- set_info_from_value (info, value);
-}
-
-static void
-free_prop_info (PropertyInfo *info)
-{
- if (info->string_enum)
- {
- g_list_foreach (info->string_enum, (GFunc)g_free, NULL);
- g_list_free (info->string_enum);
- }
-
- g_free (info->pref);
-
- g_free (info);
-}
-
static void
ephy_dialog_init (EphyDialog *dialog)
{
@@ -1472,9 +367,6 @@ ephy_dialog_init (EphyDialog *dialog)
dialog->priv->default_width = -1;
dialog->priv->default_height = -1;
-
- dialog->priv->props = g_hash_table_new_full
- (g_str_hash, g_str_equal, NULL, (GDestroyNotify) free_prop_info);
}
static void
@@ -1497,8 +389,6 @@ ephy_dialog_finalize (GObject *object)
{
EphyDialog *dialog = EPHY_DIALOG (object);
- g_hash_table_destroy (dialog->priv->props);
-
g_free (dialog->priv->name);
G_OBJECT_CLASS (parent_class)->finalize (object);