aboutsummaryrefslogtreecommitdiffstats
path: root/src/prefs-dialog.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/prefs-dialog.c')
-rw-r--r--src/prefs-dialog.c1176
1 files changed, 418 insertions, 758 deletions
diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c
index 83b149163..e9e2a207f 100644
--- a/src/prefs-dialog.c
+++ b/src/prefs-dialog.c
@@ -1,5 +1,6 @@
/*
- * Copyright (C) 2000, 2001, 2002 Marco Pesenti Gritti
+ * Copyright (C) 200-2003 Marco Pesenti Gritti
+ * Copyright (C) 2003 Christian Persch
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -39,6 +40,8 @@
#include "ephy-debug.h"
#include "ephy-ellipsizing-label.h"
#include "ephy-file-chooser.h"
+#include "ephy-tree-model-node.h"
+#include "ephy-tree-model-sort.h"
#include <glib/gi18n.h>
#include <gtk/gtkframe.h>
@@ -46,42 +49,37 @@
#include <gtk/gtkvbox.h>
#include <gtk/gtkradiobutton.h>
#include <gtk/gtktogglebutton.h>
+#include <gtk/gtkcombobox.h>
+#include <gtk/gtktreemodel.h>
+#include <gtk/gtkliststore.h>
#include <gtk/gtkimage.h>
#include <gtk/gtklabel.h>
#include <gtk/gtkstock.h>
#include <string.h>
-static void
-prefs_dialog_class_init (PrefsDialogClass *klass);
-static void
-prefs_dialog_init (PrefsDialog *pd);
-static void
-prefs_dialog_finalize (GObject *object);
+#define CONF_FONTS_FOR_LANGUAGE "/apps/epiphany/dialogs/preferences_font_language"
-/* Glade callbacks */
-void
-prefs_proxy_auto_url_reload_cb (GtkWidget *button,
- EphyDialog *dialog);
-void
-prefs_clear_cache_button_clicked_cb (GtkWidget *button,
- gpointer data);
-void
-prefs_dialog_response_cb (GtkDialog *dialog, gint response_id, gpointer data);
-void
-fonts_language_optionmenu_changed_cb (GtkWidget *optionmenu, EphyDialog *dialog);
-void
-prefs_homepage_current_button_clicked_cb (GtkWidget *button,
- EphyDialog *dialog);
-void
-prefs_homepage_blank_button_clicked_cb (GtkWidget *button,
- EphyDialog *dialog);
-void
-prefs_language_more_button_clicked_cb (GtkWidget *button,
- EphyDialog *dialog);
+static void prefs_dialog_class_init (PrefsDialogClass *klass);
+static void prefs_dialog_init (PrefsDialog *pd);
-void
-prefs_download_path_button_clicked_cb (GtkWidget *button,
- EphyDialog *dialog);
+/* Glade callbacks */
+void prefs_proxy_auto_url_reload_cb (GtkWidget *button,
+ EphyDialog *dialog);
+void prefs_clear_cache_button_clicked_cb (GtkWidget *button,
+ gpointer data);
+void prefs_dialog_response_cb (GtkDialog *widget,
+ gint response_id,
+ EphyDialog *dialog);
+void fonts_language_combo_changed_cb (GtkComboBox *combo,
+ EphyDialog *dialog);
+void prefs_homepage_current_button_clicked_cb (GtkWidget *button,
+ EphyDialog *dialog);
+void prefs_homepage_blank_button_clicked_cb (GtkWidget *button,
+ EphyDialog *dialog);
+void prefs_language_more_button_clicked_cb (GtkWidget *button,
+ EphyDialog *dialog);
+void prefs_download_path_button_clicked_cb (GtkWidget *button,
+ EphyDialog *dialog);
static const
struct
@@ -186,13 +184,21 @@ enum
};
const
-char *size_prefs[] =
+char *size_prefs [] =
{
CONF_RENDERING_FONT_FIXED_SIZE,
CONF_RENDERING_FONT_VAR_SIZE,
CONF_RENDERING_FONT_MIN_SIZE
};
+const
+int default_size [] =
+{
+ 10,
+ 11,
+ 7
+};
+
enum
{
WINDOW_PROP,
@@ -229,75 +235,76 @@ enum
AUTO_ENCODING_LABEL_PROP
};
-#define CONF_FONTS_FOR_LANGUAGE "/apps/epiphany/dialogs/preferences_font_language"
-
static const
EphyDialogProperty properties [] =
{
- { WINDOW_PROP, "prefs_dialog", NULL, PT_NORMAL, NULL },
- { NOTEBOOK_PROP, "prefs_notebook", NULL, PT_NORMAL, NULL },
+ { "prefs_dialog", NULL, PT_NORMAL, 0},
+ { "prefs_notebook", NULL, PT_NORMAL, 0},
/* General */
- { HOMEPAGE_ENTRY_PROP, "homepage_entry", CONF_GENERAL_HOMEPAGE, PT_AUTOAPPLY, NULL },
- { AUTO_OPEN_PROP, "auto_open_downloads_checkbutton", CONF_AUTO_OPEN_DOWNLOADS, PT_AUTOAPPLY, NULL},
- { DOWNLOAD_PATH_BUTTON_PROP, "download_path_button", NULL, PT_NORMAL, NULL },
+ { "homepage_entry", CONF_GENERAL_HOMEPAGE, PT_AUTOAPPLY, G_TYPE_STRING },
+ { "auto_open_downloads_checkbutton", CONF_AUTO_OPEN_DOWNLOADS, PT_AUTOAPPLY, 0 },
+ { "download_path_button", NULL, PT_NORMAL, 0 },
/* Fonts and Colors */
- { FONTS_LANGUAGE_PROP, "fonts_language_optionmenu", CONF_FONTS_FOR_LANGUAGE, PT_AUTOAPPLY, NULL },
- { VARIABLE_PROP, "variable_combo", NULL, PT_NORMAL, NULL },
- { MONOSPACE_PROP, "monospace_combo", NULL, PT_NORMAL, NULL },
- { FIXED_SIZE_PROP, "fixed_size_spinbutton", NULL, PT_NORMAL, NULL },
- { VARIABLE_SIZE_PROP, "variable_size_spinbutton", NULL, PT_NORMAL, NULL },
- { MIN_SIZE_PROP, "min_size_spinbutton", NULL, PT_NORMAL, NULL },
- { USE_COLORS_PROP, "use_colors_checkbutton", CONF_RENDERING_USE_OWN_COLORS, PT_AUTOAPPLY, NULL },
- { USE_FONTS_PROP, "use_fonts_checkbutton", CONF_RENDERING_USE_OWN_FONTS, PT_AUTOAPPLY, NULL },
+ { "fonts_language_combo", CONF_FONTS_FOR_LANGUAGE, PT_AUTOAPPLY, G_TYPE_STRING },
+ { "variable_combo", NULL, PT_AUTOAPPLY, G_TYPE_STRING },
+ { "monospace_combo", NULL, PT_AUTOAPPLY, G_TYPE_STRING },
+ { "fixed_size_spinbutton", NULL, PT_AUTOAPPLY, 0 },
+ { "variable_size_spinbutton", NULL, PT_AUTOAPPLY, 0 },
+ { "min_size_spinbutton", NULL, PT_AUTOAPPLY, 0 },
+ { "use_colors_checkbutton", CONF_RENDERING_USE_OWN_COLORS, PT_AUTOAPPLY, 0 },
+ { "use_fonts_checkbutton", CONF_RENDERING_USE_OWN_FONTS, PT_AUTOAPPLY, 0 },
/* Privacy */
- { ALLOW_POPUPS_PROP, "popups_allow_checkbutton", CONF_SECURITY_ALLOW_POPUPS, PT_AUTOAPPLY, NULL },
- { ALLOW_JAVA_PROP, "enable_java_checkbutton", CONF_SECURITY_JAVA_ENABLED, PT_AUTOAPPLY, NULL },
- { ALLOW_JS_PROP, "enable_javascript_checkbutton", CONF_SECURITY_JAVASCRIPT_ENABLED, PT_AUTOAPPLY, NULL },
- { ACCEPT_COOKIES_PROP, "cookies_radiobutton", CONF_SECURITY_COOKIES_ACCEPT, PT_AUTOAPPLY, NULL },
- { DISK_CACHE_PROP, "disk_cache_spin", CONF_NETWORK_CACHE_SIZE, PT_AUTOAPPLY, NULL },
+ { "popups_allow_checkbutton", CONF_SECURITY_ALLOW_POPUPS, PT_AUTOAPPLY, 0 },
+ { "enable_java_checkbutton", CONF_SECURITY_JAVA_ENABLED, PT_AUTOAPPLY, 0 },
+ { "enable_javascript_checkbutton", CONF_SECURITY_JAVASCRIPT_ENABLED, PT_AUTOAPPLY, 0 },
+ { "cookies_radiobutton", CONF_SECURITY_COOKIES_ACCEPT, PT_AUTOAPPLY, G_TYPE_STRING },
+ { "disk_cache_spin", CONF_NETWORK_CACHE_SIZE, PT_AUTOAPPLY, 0 },
/* Languages */
- { AUTO_ENCODING_PROP, "auto_encoding_optionmenu", CONF_LANGUAGE_AUTODETECT_ENCODING, PT_AUTOAPPLY, NULL },
- { DEFAULT_ENCODING_PROP, "default_encoding_optionmenu", CONF_LANGUAGE_DEFAULT_ENCODING, PT_AUTOAPPLY, NULL },
- { LANGUAGE_PROP, "language_optionmenu", NULL, PT_NORMAL, NULL },
- { LANGUAGE_LABEL_PROP, "language_label", NULL, PT_NORMAL, NULL },
- { DEFAULT_ENCODING_LABEL_PROP, "default_encoding_label", NULL, PT_NORMAL, NULL },
- { AUTO_ENCODING_LABEL_PROP, "auto_encoding_label", NULL, PT_NORMAL, NULL },
-
- { -1, NULL, NULL }
+ { "auto_encoding_combo", CONF_LANGUAGE_AUTODETECT_ENCODING, PT_AUTOAPPLY, G_TYPE_STRING },
+ { "default_encoding_combo", CONF_LANGUAGE_DEFAULT_ENCODING, PT_AUTOAPPLY, G_TYPE_STRING },
+ { "language_combo", NULL, PT_NORMAL, G_TYPE_STRING },
+ { "language_label", NULL, PT_NORMAL, 0 },
+ { "default_encoding_label", NULL, PT_NORMAL, 0 },
+ { "auto_encoding_label", NULL, PT_NORMAL, 0 },
+
+ { NULL }
};
-static
-int lang_size_group [] =
+static const
+char *lang_size_group [] =
{
- LANGUAGE_LABEL_PROP,
- DEFAULT_ENCODING_LABEL_PROP,
- AUTO_ENCODING_LABEL_PROP
+ "language_label",
+ "default_encoding_label",
+ "auto_encoding_label"
};
+
static guint n_lang_size_group = G_N_ELEMENTS (lang_size_group);
+enum
+{
+ COL_FONTS_LANG_NAME,
+ COL_FONTS_LANG_CODE
+};
-typedef struct
+enum
{
- gchar *name;
- gchar *key;
- gchar *code;
-} EphyLangItem;
+ COL_LANG_NAME,
+ COL_LANG_CODE
+};
+
+enum
+{
+ COL_ENC_NAME,
+ COL_ENC_CODE
+};
#define EPHY_PREFS_DIALOG_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_PREFS_DIALOG, PrefsDialogPrivate))
struct PrefsDialogPrivate
{
- GtkWidget *notebook;
- GtkWidget *window;
-
- GList *langs;
- GList *fonts_languages;
-
- guint language;
- gboolean switching;
};
static GObjectClass *parent_class = NULL;
@@ -305,701 +312,368 @@ static GObjectClass *parent_class = NULL;
GType
prefs_dialog_get_type (void)
{
- static GType prefs_dialog_type = 0;
-
- if (prefs_dialog_type == 0)
- {
- static const GTypeInfo our_info =
- {
- sizeof (PrefsDialogClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) prefs_dialog_class_init,
- NULL,
- NULL, /* class_data */
- sizeof (PrefsDialog),
- 0, /* n_preallocs */
- (GInstanceInitFunc) prefs_dialog_init
- };
-
- prefs_dialog_type = g_type_register_static (EPHY_TYPE_DIALOG,
- "PrefsDialog",
- &our_info, 0);
- }
-
- return prefs_dialog_type;
-
-}
-
-EphyDialog *
-prefs_dialog_new (GtkWidget *parent)
-{
- EphyDialog *dialog;
+ static GType type = 0;
- dialog = EPHY_DIALOG (g_object_new (EPHY_TYPE_PREFS_DIALOG,
- "ParentWindow", parent,
- NULL));
+ if (type == 0)
+ {
+ static const GTypeInfo our_info =
+ {
+ sizeof (PrefsDialogClass),
+ NULL, /* base_init */
+ NULL, /* base_finalize */
+ (GClassInitFunc) prefs_dialog_class_init,
+ NULL,
+ NULL, /* class_data */
+ sizeof (PrefsDialog),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) prefs_dialog_init
+ };
+
+ type = g_type_register_static (EPHY_TYPE_DIALOG,
+ "PrefsDialog",
+ &our_info, 0);
+ }
- return dialog;
+ return type;
}
static void
prefs_dialog_class_init (PrefsDialogClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- parent_class = g_type_class_peek_parent (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = prefs_dialog_finalize;
+ parent_class = g_type_class_peek_parent (klass);
g_type_class_add_private (object_class, sizeof(PrefsDialogPrivate));
}
static void
-free_lang_item (EphyLangItem *item, gpointer user_data)
+prefs_dialog_show_help (EphyDialog *dialog)
{
- if (item == NULL) return;
-
- g_free (item->name);
- g_free (item->key);
- g_free (item->code);
- g_free (item);
-}
-
-static void
-prefs_dialog_finalize (GObject *object)
-{
- PrefsDialog *pd = EPHY_PREFS_DIALOG (object);
- GtkWidget *button;
-
- /* Free the ellipsizing label in the button */
- button = ephy_dialog_get_control (EPHY_DIALOG (pd), DOWNLOAD_PATH_BUTTON_PROP);
- gtk_widget_destroy (GTK_WIDGET (GTK_BIN (button)->child));
-
- g_list_foreach (pd->priv->langs, (GFunc) free_lang_item, NULL);
- g_list_free (pd->priv->langs);
-
- g_list_foreach (pd->priv->fonts_languages, (GFunc) g_free, NULL);
- g_list_free (pd->priv->fonts_languages);
-
- G_OBJECT_CLASS (parent_class)->finalize (object);
-}
-
-static void
-prefs_dialog_show_help (PrefsDialog *pd)
-{
- gint id;
+ GtkWidget *window, *notebook;
+ int id;
/* FIXME: Once we actually have documentation we
* should point these at the correct links.
*/
- gchar *help_preferences[] = {
+ char *help_preferences[] = {
"setting-preferences",
"setting-preferences",
"setting-preferences",
"setting-preferences"
};
- id = gtk_notebook_get_current_page (GTK_NOTEBOOK (pd->priv->notebook));
-
- ephy_gui_help (GTK_WINDOW (pd->priv->window), "epiphany", help_preferences[id]);
-}
-
-static const char *
-get_current_language_code (PrefsDialog *dialog)
-{
- GList *lang;
- const EphyFontsLanguageInfo *info;
+ window = ephy_dialog_get_control (dialog, properties[WINDOW_PROP].id);
+ notebook = ephy_dialog_get_control (dialog, properties[NOTEBOOK_PROP].id);
- lang = g_list_nth (dialog->priv->fonts_languages, dialog->priv->language);
- g_assert (lang != NULL);
- info = (EphyFontsLanguageInfo *) lang->data;
+ id = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
+ id = CLAMP (id, 0, 3);
- return info->code;
+ ephy_gui_help (GTK_WINDOW (window), "epiphany", help_preferences[id]);
}
static void
-setup_font_menu (PrefsDialog *dialog,
- const char *type,
- GtkWidget *combo)
+setup_font_combo (EphyDialog *dialog,
+ const char *type,
+ const char *code,
+ int prop)
{
- GList *fonts = NULL;
- gchar *name;
+ GtkWidget *combo;
+ GtkListStore *store;
+ GtkTreeIter iter;
+ GList *fonts, *l;
+ char *name;
char key[255];
- GtkWidget *entry = GTK_COMBO(combo)->entry;
EphyEmbedSingle *single;
single = ephy_embed_shell_get_embed_single
(EPHY_EMBED_SHELL (ephy_shell));
+ fonts = ephy_embed_single_get_font_list (single, code);
- fonts = ephy_embed_single_get_font_list
- (single, get_current_language_code (dialog));
-
- /* Get the default font */
- g_snprintf (key, 255, "%s_%s_%s", CONF_RENDERING_FONT, type,
- get_current_language_code (dialog));
+ g_snprintf (key, 255, "%s_%s_%s", CONF_RENDERING_FONT, type, code);
name = eel_gconf_get_string (key);
- if (name == NULL)
+
+ /* sanitise the pref */
+ if (name == NULL || name[0] == '\0'
+ || g_list_find_custom (fonts, name, (GCompareFunc) strcmp) == NULL)
{
- if (strcmp (type, "variable") == 0)
+ if (prop == VARIABLE_PROP)
{
- name = g_strdup ("sans-serif");
+ eel_gconf_set_string (key, "sans-serif");
}
else
{
- name = g_strdup ("monospace");
+ eel_gconf_set_string (key, "monospace");
}
}
-
- /* set popdown doesnt like NULL */
- if (fonts == NULL)
- {
- fonts = g_list_alloc ();
- }
-
- gtk_combo_set_popdown_strings (GTK_COMBO(combo), fonts);
-
- /* set the default value */
- if (name != NULL)
- {
- int pos = 0;
-
- gtk_editable_delete_text (GTK_EDITABLE(entry), 0, -1);
- gtk_editable_insert_text (GTK_EDITABLE(entry),
- name, strlen (name),
- &pos);
- }
-
g_free (name);
- g_list_foreach (fonts, (GFunc)g_free, NULL);
- g_list_free (fonts);
-}
+ combo = ephy_dialog_get_control (dialog, properties[prop].id);
+ store = gtk_list_store_new (1, G_TYPE_STRING);
-static void
-save_font_menu (PrefsDialog *dialog,
- int type,
- GtkWidget *entry)
-{
- char *name;
- char key[255];
-
- name = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1);
-
- /* do not save empty fonts */
- if (!name || *name == '\0')
+ for (l = fonts; l != NULL; l = l->next)
{
- g_free (name);
- return;
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter, 0, (char *) l->data, -1);
}
+ g_list_foreach (fonts, (GFunc) g_free, NULL);
+ g_list_free (fonts);
- g_snprintf (key, 255, "%s_%s_%s", CONF_RENDERING_FONT,
- fonts_types[type],
- get_current_language_code (dialog));
- eel_gconf_set_string (key, name);
- g_free (name);
-}
-
-static void
-font_entry_changed_cb (GtkWidget *entry, PrefsDialog *dialog)
-{
- int type;
-
- if (dialog->priv->switching) return;
-
- type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT(entry),
- "type"));
- save_font_menu (dialog, type, entry);
-}
-
-static void
-attach_font_signal (PrefsDialog *dialog, int prop,
- gpointer type)
-{
- GtkWidget *combo;
- GtkWidget *entry;
-
- combo = ephy_dialog_get_control (EPHY_DIALOG(dialog),
- prop);
- entry = GTK_COMBO(combo)->entry;
- g_object_set_data (G_OBJECT(entry), "type", type);
- g_signal_connect (entry, "changed",
- G_CALLBACK(font_entry_changed_cb),
- dialog);
-}
-
-static void
-attach_fonts_signals (PrefsDialog *dialog)
-{
- attach_font_signal (dialog, VARIABLE_PROP,
- GINT_TO_POINTER(FONT_TYPE_VARIABLE));
- attach_font_signal (dialog, MONOSPACE_PROP,
- GINT_TO_POINTER(FONT_TYPE_MONOSPACE));
-}
-
-static void
-size_spinbutton_changed_cb (GtkWidget *spin, PrefsDialog *dialog)
-{
- int type;
- char key[255];
-
- if (dialog->priv->switching) return;
-
- type = GPOINTER_TO_INT(g_object_get_data (G_OBJECT(spin), "type"));
-
- g_snprintf (key, 255, "%s_%s",
- size_prefs[type],
- get_current_language_code (dialog));
- eel_gconf_set_integer (key, gtk_spin_button_get_value (GTK_SPIN_BUTTON (spin)));
-}
-
-static void
-attach_size_controls_signals (PrefsDialog *dialog)
-{
- GtkWidget *spin;
-
- spin = ephy_dialog_get_control (EPHY_DIALOG(dialog),
- FIXED_SIZE_PROP);
- g_object_set_data (G_OBJECT(spin), "type",
- GINT_TO_POINTER(FONT_SIZE_FIXED));
- g_signal_connect (spin, "value_changed",
- G_CALLBACK(size_spinbutton_changed_cb),
- dialog);
+ ephy_dialog_set_pref (dialog, properties[prop].id, NULL);
- spin = ephy_dialog_get_control (EPHY_DIALOG(dialog),
- VARIABLE_SIZE_PROP);
- g_object_set_data (G_OBJECT(spin), "type",
- GINT_TO_POINTER(FONT_SIZE_VAR));
- g_signal_connect (spin, "value_changed",
- G_CALLBACK(size_spinbutton_changed_cb),
- dialog);
+ gtk_combo_box_set_model (GTK_COMBO_BOX (combo), GTK_TREE_MODEL (store));
- spin = ephy_dialog_get_control (EPHY_DIALOG(dialog),
- MIN_SIZE_PROP);
- g_object_set_data (G_OBJECT(spin), "type",
- GINT_TO_POINTER(FONT_SIZE_MIN));
- g_signal_connect (spin, "value_changed",
- G_CALLBACK(size_spinbutton_changed_cb),
- dialog);
+ ephy_dialog_set_pref (dialog, properties[prop].id, key);
}
-static void
-setup_size_control (PrefsDialog *dialog,
- const char *pref,
- int default_size,
- GtkWidget *spin)
+void
+fonts_language_combo_changed_cb (GtkComboBox *combo,
+ EphyDialog *dialog)
{
- char key[255];
+ GValue value = { 0, };
+ const char *code;
+ char key[128];
int size;
- g_snprintf (key, 255, "%s_%s", pref,
- get_current_language_code (dialog));
- size = eel_gconf_get_integer (key);
+ ephy_dialog_get_value (dialog, properties[FONTS_LANGUAGE_PROP].id, &value);
+ code = g_value_get_string (&value);
- if (size == 0) size = default_size;
+ setup_font_combo (dialog, "variable", code, VARIABLE_PROP);
+ setup_font_combo (dialog, "monospace", code, MONOSPACE_PROP);
- gtk_spin_button_set_value (GTK_SPIN_BUTTON(spin), size);
-}
-
-static void
-setup_size_controls (PrefsDialog *dialog)
-{
- GtkWidget *spin;
+ g_snprintf (key, sizeof (key), "%s_%s", size_prefs[FONT_SIZE_VAR], code);
+ size = eel_gconf_get_integer (key);
+ if (size <= 0)
+ {
+ eel_gconf_set_integer (key, default_size[FONT_SIZE_VAR]);
+ }
+ ephy_dialog_set_pref (dialog, properties[VARIABLE_SIZE_PROP].id, key);
- spin = ephy_dialog_get_control (EPHY_DIALOG(dialog),
- FIXED_SIZE_PROP);
- setup_size_control (dialog, CONF_RENDERING_FONT_FIXED_SIZE, 10, spin);
+ g_snprintf (key, sizeof (key), "%s_%s", size_prefs[FONT_SIZE_FIXED], code);
+ size = eel_gconf_get_integer (key);
+ if (size <= 0)
+ {
+ eel_gconf_set_integer (key, default_size[FONT_SIZE_FIXED]);
+ }
+ ephy_dialog_set_pref (dialog, properties[FIXED_SIZE_PROP].id, key);
- spin = ephy_dialog_get_control (EPHY_DIALOG(dialog),
- VARIABLE_SIZE_PROP);
- setup_size_control (dialog, CONF_RENDERING_FONT_VAR_SIZE, 11, spin);
+ g_snprintf (key, sizeof (key), "%s_%s", size_prefs[FONT_SIZE_MIN], code);
+ size = eel_gconf_get_integer (key);
+ if (size <= 0)
+ {
+ eel_gconf_set_integer (key, default_size[FONT_SIZE_MIN]);
+ }
+ ephy_dialog_set_pref (dialog, properties[MIN_SIZE_PROP].id, key);
- spin = ephy_dialog_get_control (EPHY_DIALOG(dialog),
- MIN_SIZE_PROP);
- setup_size_control (dialog, CONF_RENDERING_FONT_MIN_SIZE, 7, spin);
+ g_value_unset (&value);
}
static void
-setup_fonts (PrefsDialog *dialog)
+create_fonts_language_menu (EphyDialog *dialog)
{
GtkWidget *combo;
-
- dialog->priv->switching = TRUE;
-
- combo = ephy_dialog_get_control (EPHY_DIALOG(dialog),
- VARIABLE_PROP);
- setup_font_menu (dialog, "variable", combo);
-
- combo = ephy_dialog_get_control (EPHY_DIALOG(dialog),
- MONOSPACE_PROP);
- setup_font_menu (dialog, "monospace", combo);
-
- dialog->priv->switching = FALSE;
-}
-
-static int
-fonts_language_info_cmp (const EphyFontsLanguageInfo *i1,
- const EphyFontsLanguageInfo *i2)
-{
- return g_utf8_collate (i1->title, i2->title);
-}
-
-static void
-create_fonts_language_menu (PrefsDialog *dialog)
-{
- GtkWidget *optionmenu, *menu;
- GList *list = NULL, *l;
+ GtkCellRenderer *renderer;
+ GtkListStore *store;
+ GtkTreeModel *sortmodel;
+ GtkTreeIter iter;
guint n_fonts_languages, i;
- char **lang_codes;
const EphyFontsLanguageInfo *fonts_languages;
- optionmenu = ephy_dialog_get_control (EPHY_DIALOG (dialog),
- FONTS_LANGUAGE_PROP);
+ combo = ephy_dialog_get_control (dialog, properties[FONTS_LANGUAGE_PROP].id);
- menu = gtk_menu_new ();
+ store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
fonts_languages = ephy_font_languages ();
n_fonts_languages = ephy_font_n_languages ();
for (i = 0; i < n_fonts_languages; i++)
{
- EphyFontsLanguageInfo *info;
-
- info = g_new0 (EphyFontsLanguageInfo, 1);
- info->title = _(fonts_languages[i].title);
- info->code = fonts_languages[i].code;
-
- list = g_list_prepend (list, info);
- }
-
- dialog->priv->fonts_languages =
- g_list_sort (list, (GCompareFunc) fonts_language_info_cmp);
-
- for (l = dialog->priv->fonts_languages; l != NULL; l = l->next)
- {
- EphyFontsLanguageInfo *info = (EphyFontsLanguageInfo *) l->data;
- GtkWidget *item;
-
- item = gtk_menu_item_new_with_label (info->title);
- gtk_menu_shell_append (GTK_MENU_SHELL(menu), item);
- gtk_widget_show (item);
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ COL_FONTS_LANG_NAME, _(fonts_languages[i].title),
+ COL_FONTS_LANG_CODE, fonts_languages[i].code,
+ -1);
}
- gtk_option_menu_set_menu (GTK_OPTION_MENU(optionmenu), menu);
+ sortmodel = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (store));
+ gtk_tree_sortable_set_sort_column_id
+ (GTK_TREE_SORTABLE (sortmodel), COL_FONTS_LANG_NAME, GTK_SORT_ASCENDING);
- lang_codes = g_new0 (char *, n_fonts_languages);
- for (l = dialog->priv->fonts_languages, i=0; l != NULL; l = l->next)
- {
- EphyFontsLanguageInfo *info = (EphyFontsLanguageInfo *) l->data;
+ gtk_combo_box_set_model (GTK_COMBO_BOX (combo), sortmodel);
- lang_codes[i] = info->code;
+ 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", COL_FONTS_LANG_NAME,
+ NULL);
- i++;
- }
- ephy_dialog_add_enum (EPHY_DIALOG (dialog), FONTS_LANGUAGE_PROP,
- n_fonts_languages, (const char **) lang_codes);
- /* the entries themselves are const, so don't use g_strfreev here */
- g_free (lang_codes);
+ ephy_dialog_set_data_column (dialog, properties[FONTS_LANGUAGE_PROP].id, COL_FONTS_LANG_CODE);
- dialog->priv->language =
- gtk_option_menu_get_history (GTK_OPTION_MENU (optionmenu));
-
- g_signal_connect (optionmenu, "changed",
- G_CALLBACK (fonts_language_optionmenu_changed_cb),
+ g_signal_connect (combo, "changed",
+ G_CALLBACK (fonts_language_combo_changed_cb),
dialog);
}
-static int
-find_encoding_in_list_cmp (gconstpointer info, const char *encoding)
-{
- EphyNode *node = (EphyNode *) info;
- const char *code;
-
- code = ephy_node_get_property_string
- (node, EPHY_NODE_ENCODING_PROP_ENCODING);
-
- return strcmp (code, encoding);
-}
-
-static int
-sort_encodings (gconstpointer a, gconstpointer b)
-{
- EphyNode *node1 = (EphyNode *) a;
- EphyNode *node2 = (EphyNode *) b;
- const char *key1, *key2;
-
- key1 = ephy_node_get_property_string
- (node1, EPHY_NODE_ENCODING_PROP_COLLATION_KEY);
- key2 = ephy_node_get_property_string
- (node2, EPHY_NODE_ENCODING_PROP_COLLATION_KEY);
-
- return strcmp (key1, key2);
-}
-
-static int
-sort_detectors (gconstpointer a, gconstpointer b)
-{
- EphyNode *node1 = (EphyNode *) a;
- EphyNode *node2 = (EphyNode *) b;
- const char *code1, *code2;
-
- code1 = ephy_node_get_property_string
- (node1, EPHY_NODE_ENCODING_PROP_ENCODING);
- code2 = ephy_node_get_property_string
- (node2, EPHY_NODE_ENCODING_PROP_ENCODING);
-
- /* "" is the code for No Autodetector; make sure it's first
- * in the list.
- */
- if (strcmp (code1, "") == 0)
- {
- return -1;
- }
- if (strcmp (code2, "") == 0)
- {
- return 1;
- }
-
- return sort_encodings (a, b);
-}
-
static void
-create_optionmenu (PrefsDialog *dialog,
- int property,
- GList *list,
+create_node_combo (EphyDialog *dialog,
+ int prop,
+ EphyEncodings *encodings,
+ EphyNode *node,
const char *key,
const char *default_value)
{
- GList *element, *l;
- GtkWidget *menu, *optionmenu;
- char *value;
- char **codes;
- guint pos, i, num;
-
- menu = gtk_menu_new ();
-
- optionmenu = ephy_dialog_get_control (EPHY_DIALOG (dialog),
- property);
-
- num = g_list_length (list);
- codes = g_new0 (char *, num);
+ EphyTreeModelNode *node_model;
+ GtkTreeModel *sort_model;
+ GtkComboBox *combo;
+ GtkCellRenderer *renderer;
+ char *code;
+ int title_col, data_col;
- for (l = list, i=0; l != NULL; l = l->next, i++)
+ code = eel_gconf_get_string (key);
+ if (code == NULL || ephy_encodings_get_node (encodings, code) == NULL)
{
- EphyNode *node = (EphyNode *) l->data;
- const char *title, *code;
- GtkWidget *item;
-
- title = ephy_node_get_property_string
- (node, EPHY_NODE_ENCODING_PROP_TITLE_ELIDED);
-
- item = gtk_menu_item_new_with_label (title);
- gtk_menu_shell_append (GTK_MENU_SHELL(menu), item);
- gtk_widget_show (item);
-
- code = ephy_node_get_property_string
- (node, EPHY_NODE_ENCODING_PROP_ENCODING);
- codes[i] = (char *) code;
+ /* safe default */
+ eel_gconf_set_string (key, default_value);
}
+ g_free (code);
- gtk_option_menu_set_menu (GTK_OPTION_MENU (optionmenu), menu);
+ combo = GTK_COMBO_BOX (ephy_dialog_get_control (dialog, properties[prop].id));
- /* init value */
- value = eel_gconf_get_string (key);
- /* fallback */
- if (value == NULL || value[0] == '\0')
- {
- g_free (value);
- value = g_strdup (default_value);
- }
+ node_model = ephy_tree_model_node_new (node, NULL);
- element = g_list_find_custom (list, value,
- (GCompareFunc) find_encoding_in_list_cmp);
- g_free (value);
- pos = g_list_position (list, element);
+ title_col = ephy_tree_model_node_add_prop_column
+ (node_model, G_TYPE_STRING, EPHY_NODE_ENCODING_PROP_TITLE_ELIDED);
+ data_col = ephy_tree_model_node_add_prop_column
+ (node_model, G_TYPE_STRING, EPHY_NODE_ENCODING_PROP_ENCODING);
- ephy_dialog_add_enum (EPHY_DIALOG (dialog), property,
- num, (const char **) codes);
+ sort_model = ephy_tree_model_sort_new (GTK_TREE_MODEL (node_model));
- gtk_option_menu_set_history (GTK_OPTION_MENU(optionmenu), pos);
+ gtk_tree_sortable_set_sort_column_id
+ (GTK_TREE_SORTABLE (sort_model), title_col, GTK_SORT_ASCENDING);
- /* the entries themselves are const, so we don't use g_strfreev here */
- g_free (codes);
-}
+ gtk_combo_box_set_model (combo, GTK_TREE_MODEL (sort_model));
-static gint
-compare_lang_items (const EphyLangItem *i1, const EphyLangItem *i2)
-{
- return strcmp (i1->key, i2->key);
-}
+ 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", title_col,
+ NULL);
-static gint
-find_lang_code (const EphyLangItem *i1, const gchar *code)
-{
- return strcmp (i1->code, code);
+ ephy_dialog_set_data_column (dialog, properties[prop].id, data_col);
}
static void
-create_languages_list (PrefsDialog *dialog)
+language_combo_changed_cb (GtkComboBox *combo,
+ EphyDialog *dialog)
{
- GList *list = NULL, *lang;
- GSList *pref_list, *l;
- EphyLangItem *item;
- const gchar *code;
- guint i;
-
- for (i = 0; i < n_languages; i++)
- {
- item = g_new0 (EphyLangItem, 1);
-
- item->name = g_strdup (_(languages[i].name));
- item->key = g_utf8_collate_key (item->name, -1);
- item->code = g_strdup (languages[i].code);
-
- list = g_list_prepend (list, item);
- }
-
- /* add custom languages */
- pref_list = eel_gconf_get_string_list (CONF_RENDERING_LANGUAGE);
-
- for (l = pref_list; l != NULL; l = l->next)
- {
- code = (const gchar*) l->data;
-
- lang = g_list_find_custom (list, code,
- (GCompareFunc) find_lang_code);
-
- if (lang == NULL)
- {
- /* not found in list */
- item = g_new0 (EphyLangItem, 1);
-
- item->name = g_strdup_printf (_("Custom [%s]"), code);
- item->key = g_utf8_collate_key (item->name, -1);
- item->code = g_strdup (code);
-
- list = g_list_prepend (list, item);
- }
- }
-
- if (pref_list)
- {
- g_slist_foreach (pref_list, (GFunc) g_free, NULL);
- g_slist_free (pref_list);
- }
-
- list = g_list_sort (list, (GCompareFunc) compare_lang_items);
-
- dialog->priv->langs = list;
-}
+ GValue value = { 0, };
+ GSList *list;
-static GtkWidget *
-general_prefs_new_language_menu (PrefsDialog *dialog)
-{
- GList *l;
- GtkWidget *menu;
- EphyLangItem *li;
+ list = eel_gconf_get_string_list (CONF_RENDERING_LANGUAGE);
+ /* delete the first list item */
+ list = g_slist_remove_link (list, list);
- menu = gtk_menu_new ();
+ ephy_dialog_get_value (dialog, properties[LANGUAGE_PROP].id, &value);
- for (l = dialog->priv->langs; l != NULL; l = l->next)
- {
- GtkWidget *item;
+ /* add the new language code upfront */
+ list = g_slist_prepend (list, g_value_dup_string (&value));
+ g_value_unset (&value);
- li = (EphyLangItem*) l->data;
- item = gtk_menu_item_new_with_label (li->name);
- gtk_menu_shell_append (GTK_MENU_SHELL(menu), item);
- gtk_widget_show (item);
- g_object_set_data (G_OBJECT (item), "desc", li->name);
- }
+ eel_gconf_set_string_list (CONF_RENDERING_LANGUAGE, list);
- return menu;
+ g_slist_foreach (list, (GFunc) g_free, NULL);
+ g_slist_free (list);
}
static void
-language_menu_changed_cb (GtkOptionMenu *option_menu,
- gpointer data)
+create_language_menu (EphyDialog *dialog)
{
- gint i;
- GSList *list = NULL;
- GList *lang = NULL;
-
- g_return_if_fail (EPHY_IS_PREFS_DIALOG (data));
+ GtkComboBox *combo;
+ GtkListStore *store;
+ GtkTreeModel *sortmodel;
+ GtkTreeIter iter;
+ GtkCellRenderer *renderer;
+ int i;
+ GSList *list, *l;
+ /* init value from first element of the list */
list = eel_gconf_get_string_list (CONF_RENDERING_LANGUAGE);
- g_return_if_fail (list != NULL);
- /* Subst the first item according to the optionmenu */
- i = gtk_option_menu_get_history (option_menu);
+ combo = GTK_COMBO_BOX (ephy_dialog_get_control
+ (dialog, properties[LANGUAGE_PROP].id));
- lang = g_list_nth (EPHY_PREFS_DIALOG (data)->priv->langs, i);
+ store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
- if (lang)
+ for (i = 0; i < n_languages; i++)
{
- g_free (list->data);
- list->data = g_strdup (((EphyLangItem *) lang->data)->code);
+ gtk_list_store_append (store, &iter);
- eel_gconf_set_string_list (CONF_RENDERING_LANGUAGE, list);
+ gtk_list_store_set (store, &iter,
+ COL_LANG_NAME, _(languages[i].name),
+ COL_LANG_CODE, languages[i].code,
+ -1);
}
- g_slist_foreach (list, (GFunc) g_free, NULL);
- g_slist_free (list);
-}
-
-static void
-create_language_menu (PrefsDialog *dialog)
-{
- GtkWidget *optionmenu;
- GtkWidget *menu;
- const gchar *code;
- gint i = 0;
- GSList *list;
- GList *lang;
-
- optionmenu = ephy_dialog_get_control (EPHY_DIALOG (dialog),
- LANGUAGE_PROP);
-
- menu = general_prefs_new_language_menu (dialog);
-
- gtk_option_menu_set_menu (GTK_OPTION_MENU(optionmenu), menu);
-
- /* init value from first element of the list */
- list = eel_gconf_get_string_list (CONF_RENDERING_LANGUAGE);
- if (list)
+ /* add additional list items */
+ for (l = list; l != NULL; l = l->next)
{
- code = (const gchar *) list->data;
- lang = g_list_find_custom (dialog->priv->langs, code,
- (GCompareFunc)find_lang_code);
+ const char *code = (const char *) l->data;
+ int i;
+
+ if (code == NULL) continue;
- if (lang)
+ for (i = 0; i < n_languages; i++)
{
- i = g_list_position (dialog->priv->langs, lang);
+ if (strcmp (languages[i].code, code) == 0) break;
}
- g_slist_foreach (list, (GFunc) g_free, NULL);
- g_slist_free (list);
+ /* code isn't in stock list */
+ if (i == n_languages)
+ {
+ char *text;
+
+ text = g_strdup_printf (_("Custom [%s]"), code);
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ COL_LANG_NAME, text,
+ COL_LANG_CODE, code,
+ -1);
+ g_free (text);
+ }
}
- gtk_option_menu_set_history (GTK_OPTION_MENU(optionmenu), i);
+ sortmodel = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (store));
+ gtk_tree_sortable_set_sort_column_id
+ (GTK_TREE_SORTABLE (sortmodel), COL_LANG_NAME, GTK_SORT_ASCENDING);
- g_signal_connect (optionmenu, "changed",
- G_CALLBACK (language_menu_changed_cb),
- dialog);
-}
+ gtk_combo_box_set_model (combo, sortmodel);
-static void
-set_homepage_entry (EphyDialog *dialog,
- const char *new_location)
-{
- GtkWidget *entry;
- int pos = 0;
+ ephy_dialog_set_data_column
+ (dialog, properties[LANGUAGE_PROP].id, COL_LANG_CODE);
- entry = ephy_dialog_get_control (dialog, HOMEPAGE_ENTRY_PROP);
+ 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", COL_LANG_NAME,
+ NULL);
- gtk_editable_delete_text (GTK_EDITABLE (entry), 0, -1);
- gtk_editable_insert_text (GTK_EDITABLE (entry), new_location,
- strlen (new_location),
- &pos);
+ g_signal_connect (combo, "changed",
+ G_CALLBACK (language_combo_changed_cb), dialog);
+
+ /* set combo from first element of the list */
+ if (list && list->data)
+ {
+ const char *code = (const char *) list->data;
+ GValue value = { 0, };
+
+ g_value_init (&value, G_TYPE_STRING);
+ g_value_set_string (&value, code);
+ ephy_dialog_set_value (dialog, properties[LANGUAGE_PROP].id, &value);
+ g_value_unset (&value);
+ }
+
+ g_slist_foreach (list, (GFunc) g_free, NULL);
+ g_slist_free (list);
}
static char*
@@ -1011,7 +685,7 @@ get_download_button_label ()
tmp = g_build_filename (g_get_home_dir (), "Desktop", NULL);
desktop_path = g_filename_to_utf8 (tmp, -1, NULL, NULL, NULL);
g_free (tmp);
- if (!g_utf8_collate (key, desktop_path))
+ if (g_utf8_collate (key, desktop_path) == 0)
{
g_free (key);
label = g_strdup (_("Desktop"));
@@ -1026,18 +700,17 @@ get_download_button_label ()
}
static void
-create_download_path_label (PrefsDialog *pd)
+create_download_path_label (EphyDialog *dialog)
{
- char *dir;
GtkWidget *button, *label;
- EphyDialog *dialog = EPHY_DIALOG (pd);
+ char *dir;
- button = ephy_dialog_get_control (dialog, DOWNLOAD_PATH_BUTTON_PROP);
+ button = ephy_dialog_get_control (dialog, properties[DOWNLOAD_PATH_BUTTON_PROP].id);
dir = get_download_button_label ();
label = ephy_ellipsizing_label_new (dir);
ephy_ellipsizing_label_set_mode ((EphyEllipsizingLabel*)label,
- EPHY_ELLIPSIZE_START);
+ EPHY_ELLIPSIZE_START);
gtk_container_add (GTK_CONTAINER (button), label);
g_free (dir);
gtk_widget_show (label);
@@ -1048,70 +721,77 @@ prefs_dialog_init (PrefsDialog *pd)
{
EphyDialog *dialog = EPHY_DIALOG (pd);
EphyEncodings *encodings;
+ GtkWidget *window;
GdkPixbuf *icon;
- GList *list;
+ GtkCellRenderer *renderer;
+ GtkWidget *combo;
pd->priv = EPHY_PREFS_DIALOG_GET_PRIVATE (pd);
- ephy_dialog_construct (EPHY_DIALOG (pd),
+ ephy_dialog_construct (dialog,
properties,
"prefs-dialog.glade",
"prefs_dialog");
- ephy_dialog_add_enum (EPHY_DIALOG (pd), ACCEPT_COOKIES_PROP,
+ ephy_dialog_add_enum (dialog, properties[ACCEPT_COOKIES_PROP].id,
n_cookies_accept_enum, cookies_accept_enum);
- ephy_dialog_set_size_group (EPHY_DIALOG (pd), lang_size_group,
+ ephy_dialog_set_size_group (dialog, lang_size_group,
n_lang_size_group);
- pd->priv->window = ephy_dialog_get_control (dialog, WINDOW_PROP);
- pd->priv->notebook = ephy_dialog_get_control (dialog, NOTEBOOK_PROP);
- pd->priv->langs = NULL;
- pd->priv->fonts_languages = NULL;
+ window = ephy_dialog_get_control (dialog, properties[WINDOW_PROP].id);
- icon = gtk_widget_render_icon (pd->priv->window,
+ icon = gtk_widget_render_icon (window,
GTK_STOCK_PREFERENCES,
GTK_ICON_SIZE_MENU,
"prefs_dialog");
- gtk_window_set_icon (GTK_WINDOW (pd->priv->window), icon);
+ gtk_window_set_icon (GTK_WINDOW (window), icon);
g_object_unref(icon);
- pd->priv->switching = FALSE;
- create_fonts_language_menu (pd);
- attach_fonts_signals (pd);
- attach_size_controls_signals (pd);
- create_languages_list (pd);
+ combo = ephy_dialog_get_control (dialog, properties[VARIABLE_PROP].id);
+ 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);
+ ephy_dialog_set_data_column (dialog, properties[VARIABLE_PROP].id, 0);
+ combo = ephy_dialog_get_control (dialog, properties[MONOSPACE_PROP].id);
+ 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);
+ ephy_dialog_set_data_column (dialog, properties[MONOSPACE_PROP].id, 0);
+
+ create_fonts_language_menu (dialog);
encodings = EPHY_ENCODINGS (ephy_embed_shell_get_encodings
(EPHY_EMBED_SHELL (ephy_shell)));
- list = ephy_encodings_get_encodings (encodings, LG_ALL);
- list = g_list_sort (list, (GCompareFunc) sort_encodings);
- create_optionmenu (pd, DEFAULT_ENCODING_PROP, list,
+ create_node_combo (dialog, DEFAULT_ENCODING_PROP, encodings,
+ ephy_encodings_get_all (encodings),
CONF_LANGUAGE_DEFAULT_ENCODING, "ISO-8859-1");
- g_list_free (list);
-
- list = ephy_encodings_get_detectors (encodings);
- list = g_list_sort (list, (GCompareFunc) sort_detectors);
- create_optionmenu (pd, AUTO_ENCODING_PROP, list,
+ create_node_combo (dialog, AUTO_ENCODING_PROP, encodings,
+ ephy_encodings_get_detectors (encodings),
CONF_LANGUAGE_AUTODETECT_ENCODING, "");
- g_list_free (list);
- create_language_menu (pd);
- create_download_path_label (pd);
+ create_language_menu (dialog);
+
+ create_download_path_label (dialog);
}
void
-prefs_dialog_response_cb (GtkDialog *dialog, gint response_id, gpointer data)
+prefs_dialog_response_cb (GtkDialog *widget,
+ gint response_id,
+ EphyDialog *dialog)
{
if (response_id == GTK_RESPONSE_CLOSE)
{
- gtk_widget_destroy (GTK_WIDGET(dialog));
+ g_object_unref (dialog);
}
else if (response_id == GTK_RESPONSE_HELP)
{
- PrefsDialog *pd = (PrefsDialog *)data;
- prefs_dialog_show_help (pd);
+ prefs_dialog_show_help (dialog);
}
}
@@ -1127,20 +807,16 @@ prefs_clear_cache_button_clicked_cb (GtkWidget *button,
ephy_embed_single_clear_cache (single);
}
-void
-fonts_language_optionmenu_changed_cb (GtkWidget *optionmenu,
- EphyDialog *dialog)
+static void
+set_homepage_entry (EphyDialog *dialog,
+ char *new_location)
{
- guint i;
- PrefsDialog *pd = EPHY_PREFS_DIALOG (dialog);
-
- i = gtk_option_menu_get_history
- (GTK_OPTION_MENU (optionmenu));
+ GValue value = { 0, };
- pd->priv->language = i;
-
- setup_fonts (pd);
- setup_size_controls (pd);
+ g_value_init (&value, G_TYPE_STRING);
+ g_value_take_string (&value, new_location);
+ ephy_dialog_set_value (dialog, properties[HOMEPAGE_ENTRY_PROP].id, &value);
+ g_value_unset (&value);
}
void
@@ -1161,81 +837,33 @@ prefs_homepage_current_button_clicked_cb (GtkWidget *button,
location = ephy_embed_get_location (embed, TRUE);
set_homepage_entry (dialog, location);
- g_free (location);
}
void
prefs_homepage_blank_button_clicked_cb (GtkWidget *button,
EphyDialog *dialog)
{
- set_homepage_entry (dialog, "");
-}
-
-static void
-fill_language_editor (LanguageEditor *le, PrefsDialog *dialog)
-{
- GSList *strings;
- GSList *tmp;
- GList *lang;
- gint i;
- const gchar *code;
- EphyLangItem *li;
-
- strings = eel_gconf_get_string_list (CONF_RENDERING_LANGUAGE);
- g_return_if_fail (strings != NULL);
-
- for (tmp = strings; tmp != NULL; tmp = g_slist_next (tmp))
- {
- code = (const gchar *) tmp->data;
-
- lang = g_list_find_custom (dialog->priv->langs, code,
- (GCompareFunc) find_lang_code);
-
- if (lang)
- {
- i = g_list_position (dialog->priv->langs, lang);
- li = (EphyLangItem *) lang->data;
-
- language_editor_add (le, li->name, i);
- }
- }
-
- g_slist_foreach (strings, (GFunc) g_free, NULL);
- g_slist_free (strings);
+ set_homepage_entry (dialog, NULL);
}
static void
language_dialog_changed_cb (LanguageEditor *le,
GSList *list,
- PrefsDialog *dialog)
+ EphyDialog *dialog)
{
- GtkWidget *optionmenu;
- const GSList *l;
- GSList *langs = NULL;
- GList *lang;
- gint i;
- EphyLangItem *li;
-
- optionmenu = ephy_dialog_get_control (EPHY_DIALOG (dialog),
- LANGUAGE_PROP);
- gtk_option_menu_set_history (GTK_OPTION_MENU(optionmenu),
- GPOINTER_TO_INT(list->data));
+ LOG ("language_dialog_changed_cb")
- for (l = list; l != NULL; l = l->next)
+ if (list && list->data)
{
- i = GPOINTER_TO_INT (l->data);
- lang = g_list_nth (dialog->priv->langs, i);
+ GValue value = { 0, };
- if (lang)
- {
- li = (EphyLangItem *) lang->data;
-
- langs = g_slist_append (langs, li->code);
- }
+ g_value_init (&value, G_TYPE_STRING);
+ g_value_set_string (&value, (char *) list->data);
+ ephy_dialog_set_value (dialog, properties[LANGUAGE_PROP].id, &value);
+ g_value_unset (&value);
}
- eel_gconf_set_string_list (CONF_RENDERING_LANGUAGE, langs);
- g_slist_free (langs);
+ eel_gconf_set_string_list (CONF_RENDERING_LANGUAGE, list);
}
void
@@ -1243,22 +871,53 @@ prefs_language_more_button_clicked_cb (GtkWidget *button,
EphyDialog *dialog)
{
LanguageEditor *editor;
- GtkWidget *menu;
- GtkWidget *toplevel;
+ GtkWidget *window, *combo;
+ GtkTreeModel *model;
+ GSList *codes, *l;
+
+ window = ephy_dialog_get_control (dialog, properties[WINDOW_PROP].id);
+ combo = ephy_dialog_get_control (dialog, properties[LANGUAGE_PROP].id);
+ model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
+
+ editor = language_editor_new (window);
+ language_editor_set_model (editor, model);
+
+ codes = eel_gconf_get_string_list (CONF_RENDERING_LANGUAGE);
+ for (l = codes; l != NULL; l = l->next)
+ {
+ const char *code = (const char *) l->data;
+ int i;
+
+ if (code == NULL) continue;
+
+ for (i = 0; i < n_languages; i++)
+ {
+ if (strcmp (languages[i].code, code) == 0) break;
+ }
- menu = general_prefs_new_language_menu (EPHY_PREFS_DIALOG (dialog));
+ if (i == n_languages)
+ {
+ char *desc;
+ desc = g_strdup_printf (_("Custom [%s]"), code);
+ language_editor_add (editor, code, desc);\
+ g_free (desc);
+ }
+ else
+ {
+ language_editor_add (editor, code, _(languages[i].name));
+ }
+ }
+ g_slist_foreach (codes, (GFunc) g_free, NULL);
+ g_slist_free (codes);
- toplevel = gtk_widget_get_toplevel (button);
- editor = language_editor_new (toplevel);
- language_editor_set_menu (editor, menu);
- fill_language_editor (editor, EPHY_PREFS_DIALOG (dialog));
- ephy_dialog_set_modal (EPHY_DIALOG(editor), TRUE);
+ /* FIXME: make it only modal to prefs dialogue, not to all windows */
+ ephy_dialog_set_modal (EPHY_DIALOG (editor), TRUE);
g_signal_connect (editor, "changed",
- G_CALLBACK(language_dialog_changed_cb),
+ G_CALLBACK (language_dialog_changed_cb),
dialog);
- ephy_dialog_show (EPHY_DIALOG(editor));
+ ephy_dialog_show (EPHY_DIALOG (editor));
}
static void
@@ -1276,9 +935,9 @@ download_path_response_cb (GtkDialog *fc, gint response, EphyDialog *dialog)
eel_gconf_set_string (CONF_STATE_DOWNLOAD_DIR, dir);
- button = ephy_dialog_get_control (dialog, DOWNLOAD_PATH_BUTTON_PROP);
+ button = ephy_dialog_get_control (dialog, properties[DOWNLOAD_PATH_BUTTON_PROP].id);
label = get_download_button_label ();
- ephy_ellipsizing_label_set_text ((EphyEllipsizingLabel*)GTK_BIN (button)->child,
+ ephy_ellipsizing_label_set_text ((EphyEllipsizingLabel*) GTK_BIN (button)->child,
label);
g_free (dir);
g_free (label);
@@ -1294,10 +953,11 @@ prefs_download_path_button_clicked_cb (GtkWidget *button,
{
GtkWidget *parent;
EphyFileChooser *fc;
- parent = ephy_dialog_get_control (dialog, WINDOW_PROP);
+
+ parent = ephy_dialog_get_control (dialog, properties[WINDOW_PROP].id);
fc = ephy_file_chooser_new (_("Select a directory"),
- GTK_WIDGET (parent),
+ GTK_WIDGET (parent),
GTK_FILE_CHOOSER_ACTION_OPEN,
NULL);
gtk_file_chooser_set_folder_mode (GTK_FILE_CHOOSER (fc), TRUE);