aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2003-11-30 22:08:32 +0800
committerChristian Persch <chpe@src.gnome.org>2003-11-30 22:08:32 +0800
commit1aa5a63dad335d4f05b65915bb553fb28192ab02 (patch)
treef2572a0a3c6395b029ebb94a1c0797d4a14e858e /src
parent2a4417e4222ce7ce938c5848d43fdbe27089141b (diff)
downloadgsoc2013-epiphany-1aa5a63dad335d4f05b65915bb553fb28192ab02.tar
gsoc2013-epiphany-1aa5a63dad335d4f05b65915bb553fb28192ab02.tar.gz
gsoc2013-epiphany-1aa5a63dad335d4f05b65915bb553fb28192ab02.tar.bz2
gsoc2013-epiphany-1aa5a63dad335d4f05b65915bb553fb28192ab02.tar.lz
gsoc2013-epiphany-1aa5a63dad335d4f05b65915bb553fb28192ab02.tar.xz
gsoc2013-epiphany-1aa5a63dad335d4f05b65915bb553fb28192ab02.tar.zst
gsoc2013-epiphany-1aa5a63dad335d4f05b65915bb553fb28192ab02.zip
Improved API and implementation of EphyDialog. Add support for new combo
2003-11-30 Christian Persch <chpe@cvs.gnome.org> * configure.in: * data/glade/epiphany.glade: * data/glade/prefs-dialog.glade: * embed/downloader-view.c: (downloader_view_build_ui): * embed/ephy-embed-dialog.c: (ephy_embed_dialog_new_with_parent): * embed/ephy-encodings.c: (ephy_encodings_get_detectors): * embed/ephy-encodings.h: * embed/find-dialog.c: (update_navigation_controls), (set_properties), (impl_show), (find_dialog_class_init), (find_dialog_init), (find_dialog_new_with_parent): * embed/print-dialog.c: (impl_show), (print_dialog_init), (print_dialog_new_with_parent), (print_get_info): * lib/ephy-dialog.c: (ephy_dialog_get_type), (lookup_info), (set_sensitivity), (set_value_from_pref), (set_pref_from_value), (set_value_from_editable), (set_value_from_optionmenu), (set_value_from_combobox), (get_radio_button_active_index), (set_value_from_radiobuttongroup), (set_value_from_spin_button), (set_value_from_togglebutton), (set_value_from_info), (set_editable_from_value), (get_index_from_value), (set_optionmenu_from_value), (compare_values), (set_combo_box_from_value), (set_radiobuttongroup_from_value), (set_spin_button_from_value), (set_togglebutton_from_value), (set_info_from_value), (set_pref_from_info), (togglebutton_clicked_cb), (radiobutton_clicked_cb), (spinbutton_timeout_cb), (spinbutton_changed_cb), (changed_cb), (set_info_from_pref), (connect_signals), (disconnect_signals), (init_props), (load_info), (save_info), (setup_default_size), (dialog_destroy_cb), (impl_construct), (impl_show), (ephy_dialog_set_modal), (ephy_dialog_add_enum), (ephy_dialog_set_data_column), (ephy_dialog_set_pref), (ephy_dialog_set_size_group), (ephy_dialog_construct), (ephy_dialog_show), (ephy_dialog_run), (ephy_dialog_get_control), (ephy_dialog_get_value), (ephy_dialog_set_value), (free_prop_info), (ephy_dialog_init), (ephy_dialog_dispose), (ephy_dialog_finalize), (ephy_dialog_set_parent), (ephy_dialog_set_property), (ephy_dialog_get_property), (ephy_dialog_class_init), (ephy_dialog_new), (ephy_dialog_new_with_parent): * lib/ephy-dialog.h: * lib/ephy-file-chooser.c: (ephy_file_chooser_new): * src/ephy-encoding-dialog.c: (sync_embed_cb), (sync_parent_window_cb), (activate_choice), (view_node_selected_cb), (view_node_activated_cb), (ephy_encoding_dialog_init), (ephy_encoding_dialog_new): * src/ephy-shell.c: (ephy_shell_finalize), (ephy_shell_get_pdm_dialog), (ephy_shell_get_prefs_dialog): * src/ephy-shell.h: * src/language-editor.c: (language_editor_get_type), (language_editor_class_init), (language_editor_update_pref), (language_editor_add_button_clicked_cb), (language_editor_set_view), (language_editor_init), (language_editor_new), (language_editor_set_model), (language_editor_add): * src/language-editor.h: * src/pdm-dialog.c: (pdm_dialog_show_help), (action_treeview_selection_changed_cb), (setup_action), (cookies_treeview_selection_changed_cb), (pdm_dialog_cookies_construct), (pdm_dialog_passwords_construct), (pdm_dialog_init), (show_cookies_properties): * src/prefs-dialog.c: (prefs_dialog_get_type), (prefs_dialog_class_init), (prefs_dialog_show_help), (setup_font_combo), (fonts_language_combo_changed_cb), (create_fonts_language_menu), (create_node_combo), (language_combo_changed_cb), (create_language_menu), (get_download_button_label), (create_download_path_label), (prefs_dialog_init), (prefs_dialog_response_cb), (set_homepage_entry), (prefs_homepage_current_button_clicked_cb), (prefs_homepage_blank_button_clicked_cb), (language_dialog_changed_cb), (prefs_language_more_button_clicked_cb), (download_path_response_cb), (prefs_download_path_button_clicked_cb): * src/prefs-dialog.h: * src/window-commands.c: (window_cmd_edit_prefs): Improved API and implementation of EphyDialog. Add support for new combo box, and removed optionmenu. Port all dialogues to new API and use combobox instead of optionmenus.
Diffstat (limited to 'src')
-rw-r--r--src/ephy-encoding-dialog.c28
-rw-r--r--src/ephy-shell.c22
-rw-r--r--src/ephy-shell.h2
-rw-r--r--src/language-editor.c277
-rw-r--r--src/language-editor.h17
-rwxr-xr-xsrc/pdm-dialog.c81
-rw-r--r--src/prefs-dialog.c1176
-rw-r--r--src/prefs-dialog.h8
-rw-r--r--src/window-commands.c4
9 files changed, 650 insertions, 965 deletions
diff --git a/src/ephy-encoding-dialog.c b/src/ephy-encoding-dialog.c
index 6338c93a6..7c6efd7f6 100644
--- a/src/ephy-encoding-dialog.c
+++ b/src/ephy-encoding-dialog.c
@@ -51,11 +51,11 @@ enum
static const
EphyDialogProperty properties [] =
{
- { SCROLLED_WINDOW_PROP, "scrolled_window", NULL, PT_NORMAL, NULL },
- { AUTOMATIC_PROP, "automatic_button", NULL, PT_NORMAL, NULL },
- { AUTOMATIC_PROP, "manual_button", NULL, PT_NORMAL, NULL },
+ { "scrolled_window", NULL, PT_NORMAL, 0 },
+ { "automatic_button", NULL, PT_NORMAL, 0 },
+ { "manual_button", NULL, PT_NORMAL, 0 },
- { -1, NULL, NULL }
+ { NULL }
};
#define EPHY_ENCODING_DIALOG_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_ENCODING_DIALOG, EphyEncodingDialogPrivate))
@@ -161,7 +161,7 @@ sync_embed_cb (EphyEncodingDialog *dialog, GParamSpec *pspec, gpointer dummy)
is_automatic = encoding_is_automatic (info);
- button = ephy_dialog_get_control (EPHY_DIALOG (dialog), AUTOMATIC_PROP);
+ button = ephy_dialog_get_control (EPHY_DIALOG (dialog), properties[AUTOMATIC_PROP].id);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), is_automatic);
ephy_encoding_info_free (info);
@@ -188,7 +188,7 @@ sync_parent_window_cb (EphyEncodingDialog *dialog, GParamSpec *pspec, gpointer d
g_return_if_fail (dialog->priv->window == NULL);
g_value_init (&value, GTK_TYPE_WIDGET);
- g_object_get_property (G_OBJECT (dialog), "ParentWindow", &value);
+ g_object_get_property (G_OBJECT (dialog), "parent-window", &value);
window = EPHY_WINDOW (g_value_get_object (&value));
g_value_unset (&value);
@@ -215,7 +215,7 @@ activate_choice (EphyEncodingDialog *dialog)
info = ephy_embed_get_encoding_info (embed);
if (info == NULL) return;
- button = ephy_dialog_get_control (EPHY_DIALOG (dialog), AUTOMATIC_PROP);
+ button = ephy_dialog_get_control (EPHY_DIALOG (dialog), properties[AUTOMATIC_PROP].id);
is_automatic = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
if (is_automatic)
@@ -265,7 +265,7 @@ view_node_selected_cb (EphyNodeView *view,
if (dialog->priv->update_tag) return;
- button = ephy_dialog_get_control (EPHY_DIALOG (dialog), MANUAL_PROP);
+ button = ephy_dialog_get_control (EPHY_DIALOG (dialog), properties[MANUAL_PROP].id);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
activate_choice (dialog);
@@ -282,7 +282,7 @@ view_node_activated_cb (GtkWidget *view,
if (dialog->priv->update_tag) return;
- button = ephy_dialog_get_control (EPHY_DIALOG (dialog), MANUAL_PROP);
+ button = ephy_dialog_get_control (EPHY_DIALOG (dialog), properties[MANUAL_PROP].id);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
activate_choice (dialog);
@@ -350,20 +350,20 @@ ephy_encoding_dialog_init (EphyEncodingDialog *dialog)
gtk_widget_show (treeview);
scroller = ephy_dialog_get_control
- (EPHY_DIALOG (dialog), SCROLLED_WINDOW_PROP);
+ (EPHY_DIALOG (dialog), properties[SCROLLED_WINDOW_PROP].id);
gtk_container_add (GTK_CONTAINER (scroller), treeview);
- button = ephy_dialog_get_control (EPHY_DIALOG (dialog), AUTOMATIC_PROP);
+ button = ephy_dialog_get_control (EPHY_DIALOG (dialog), properties[AUTOMATIC_PROP].id);
gtk_label_set_use_markup (GTK_LABEL (GTK_BIN (button)->child), TRUE);
g_signal_connect (button, "toggled",
G_CALLBACK (automatic_toggled_cb), dialog);
- button = ephy_dialog_get_control (EPHY_DIALOG (dialog), MANUAL_PROP);
+ button = ephy_dialog_get_control (EPHY_DIALOG (dialog), properties[MANUAL_PROP].id);
gtk_label_set_use_markup (GTK_LABEL (GTK_BIN (button)->child), TRUE);
dialog->priv->enc_view = treeview;
- g_signal_connect (G_OBJECT (dialog), "notify::ParentWindow",
+ g_signal_connect (G_OBJECT (dialog), "notify::parent-window",
G_CALLBACK (sync_parent_window_cb), NULL);
g_signal_connect (G_OBJECT (dialog), "notify::embed",
G_CALLBACK (sync_embed_cb), NULL);
@@ -402,6 +402,6 @@ EphyEncodingDialog *
ephy_encoding_dialog_new (EphyWindow *parent)
{
return g_object_new (EPHY_TYPE_ENCODING_DIALOG,
- "ParentWindow", parent,
+ "parent-window", parent,
NULL);
}
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index a759d0133..62f12f860 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -33,6 +33,7 @@
#include "ephy-bookmarks-editor.h"
#include "ephy-history-window.h"
#include "pdm-dialog.h"
+#include "prefs-dialog.h"
#include "ephy-debug.h"
#include "ephy-extensions-manager.h"
#include "toolbar.h"
@@ -73,6 +74,7 @@ struct EphyShellPrivate
GtkWidget *bme;
GtkWidget *history_window;
GObject *pdm_dialog;
+ GObject *prefs_dialog;
GList *del_on_exit;
guint server_timeout;
};
@@ -503,6 +505,12 @@ ephy_shell_finalize (GObject *object)
g_object_unref (gs->priv->pdm_dialog);
}
+ LOG ("Unref prefs dialog")
+ if (gs->priv->prefs_dialog)
+ {
+ g_object_unref (gs->priv->prefs_dialog);
+ }
+
LOG ("Unref bookmarks")
if (gs->priv->bookmarks)
{
@@ -810,6 +818,20 @@ ephy_shell_get_pdm_dialog (EphyShell *shell)
return shell->priv->pdm_dialog;
}
+GObject *
+ephy_shell_get_prefs_dialog (EphyShell *shell)
+{
+ if (shell->priv->prefs_dialog == NULL)
+ {
+ shell->priv->prefs_dialog = g_object_new (EPHY_TYPE_PREFS_DIALOG, NULL);
+
+ g_object_add_weak_pointer (shell->priv->prefs_dialog,
+ (gpointer *) &shell->priv->prefs_dialog);
+ }
+
+ return shell->priv->prefs_dialog;
+}
+
void
ephy_shell_delete_on_exit (EphyShell *gs, const char *path)
{
diff --git a/src/ephy-shell.h b/src/ephy-shell.h
index 219942f41..c114d415f 100644
--- a/src/ephy-shell.h
+++ b/src/ephy-shell.h
@@ -137,6 +137,8 @@ GtkWidget *ephy_shell_get_history_window (EphyShell *gs);
GObject *ephy_shell_get_pdm_dialog (EphyShell *shell);
+GObject *ephy_shell_get_prefs_dialog (EphyShell *shell);
+
void ephy_shell_delete_on_exit (EphyShell *gs,
const char *path);
diff --git a/src/language-editor.c b/src/language-editor.c
index 016ebd259..28d09515f 100644
--- a/src/language-editor.c
+++ b/src/language-editor.c
@@ -21,6 +21,7 @@
#include "language-editor.h"
#include "ephy-gui.h"
#include "eel-gconf-extensions.h"
+#include "ephy-debug.h"
#include <gtk/gtklabel.h>
#include <gtk/gtkoptionmenu.h>
@@ -31,30 +32,31 @@
#include <gtk/gtktreeselection.h>
#include <gtk/gtkliststore.h>
#include <gtk/gtkcellrenderertext.h>
+#include <glib/gi18n.h>
enum
{
- COL_DESCRIPTION,
- COL_DATA
+ COL_DESCRIPTION,
+ COL_DATA
};
enum
{
- TREEVIEW_PROP,
- ADD_PROP,
- REMOVE_PROP,
- LANGUAGE_PROP
+ TREEVIEW_PROP,
+ ADD_PROP,
+ REMOVE_PROP,
+ LANGUAGE_PROP
};
static const
EphyDialogProperty properties [] =
{
- { TREEVIEW_PROP, "languages_treeview", NULL, PT_NORMAL, NULL },
- { ADD_PROP, "add_button", NULL, PT_NORMAL, NULL },
- { REMOVE_PROP, "remove_button", NULL, PT_NORMAL, NULL },
- { LANGUAGE_PROP, "languages_optionmenu", NULL, PT_NORMAL, NULL },
+ { "languages_treeview", NULL, PT_NORMAL, 0 },
+ { "add_button", NULL, PT_NORMAL, 0 },
+ { "remove_button", NULL, PT_NORMAL, 0 },
+ { "languages_combo", NULL, PT_NORMAL, 0 },
- { -1, NULL, NULL }
+ { NULL }
};
#define EPHY_LANGUAGE_EDITOR_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_LANGUAGE_EDITOR, LanguageEditorPrivate))
@@ -63,75 +65,71 @@ struct LanguageEditorPrivate
{
GtkWidget *treeview;
GtkTreeModel *model;
- GtkWidget *optionmenu;
};
+static void language_editor_class_init (LanguageEditorClass *klass);
+static void language_editor_init (LanguageEditor *ge);
+
+/* Glade callbacks */
+
+void language_editor_close_button_cb (GtkWidget *button,
+ EphyDialog *dialog);
+
enum
{
CHANGED,
LAST_SIGNAL
};
-static void
-language_editor_class_init (LanguageEditorClass *klass);
-static void
-language_editor_init (LanguageEditor *ge);
-
-/* Glade callbacks */
-
-void
-language_editor_close_button_cb (GtkWidget *button, EphyDialog *dialog);
+static gint signals[LAST_SIGNAL];
static GObjectClass *parent_class = NULL;
-static gint signals[LAST_SIGNAL];
-
GType
language_editor_get_type (void)
{
- static GType language_editor_type = 0;
-
- if (language_editor_type == 0)
- {
- static const GTypeInfo our_info =
- {
- sizeof (LanguageEditorClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) language_editor_class_init,
- NULL,
- NULL, /* class_data */
- sizeof (LanguageEditor),
- 0, /* n_preallocs */
- (GInstanceInitFunc) language_editor_init
- };
-
- language_editor_type = g_type_register_static (EPHY_TYPE_DIALOG,
- "LanguageEditor",
- &our_info, 0);
- }
-
- return language_editor_type;
+ static GType type = 0;
+ if (type == 0)
+ {
+ static const GTypeInfo our_info =
+ {
+ sizeof (LanguageEditorClass),
+ NULL, /* base_init */
+ NULL, /* base_finalize */
+ (GClassInitFunc) language_editor_class_init,
+ NULL,
+ NULL, /* class_data */
+ sizeof (LanguageEditor),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) language_editor_init
+ };
+
+ type = g_type_register_static (EPHY_TYPE_DIALOG,
+ "LanguageEditor",
+ &our_info, 0);
+ }
+
+ return type;
}
static void
language_editor_class_init (LanguageEditorClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
- parent_class = g_type_class_peek_parent (klass);
+ parent_class = g_type_class_peek_parent (klass);
signals[CHANGED] =
g_signal_new ("changed",
G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (LanguageEditorClass, changed),
- NULL, NULL,
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (LanguageEditorClass, changed),
+ NULL, NULL,
g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE,
- 1,
- G_TYPE_POINTER);
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_POINTER);
g_type_class_add_private (object_class, sizeof(LanguageEditorPrivate));
}
@@ -140,8 +138,7 @@ static void
language_editor_update_pref (LanguageEditor *editor)
{
GtkTreeIter iter;
- int index;
- GSList *strings = NULL;
+ GSList *codes = NULL;
if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (editor->priv->model), &iter))
{
@@ -150,46 +147,49 @@ language_editor_update_pref (LanguageEditor *editor)
do
{
- GValue val = {0, };
+ GValue value = {0, };
+
gtk_tree_model_get_value (GTK_TREE_MODEL (editor->priv->model),
- &iter, COL_DATA, &val);
- index = g_value_get_int (&val);
- g_value_unset (&val);
+ &iter, COL_DATA, &value);
+
+ codes = g_slist_append (codes, g_value_dup_string (&value));
- strings = g_slist_append(strings, GINT_TO_POINTER(index));
+ g_value_unset (&value);
}
while (gtk_tree_model_iter_next (GTK_TREE_MODEL (editor->priv->model), &iter));
- g_signal_emit (editor, signals[CHANGED], 0, strings);
+ g_signal_emit (editor, signals[CHANGED], 0, codes);
- g_slist_free (strings);
+ g_slist_foreach (codes, (GFunc) g_free, NULL);
+ g_slist_free (codes);
}
static void
language_editor_add_button_clicked_cb (GtkButton *button,
LanguageEditor *editor)
{
- const char *description;
+ GtkWidget *combo;
+ GtkTreeModel *model;
GtkTreeIter iter;
- GtkWidget *menu;
- GtkWidget *item;
- int history;
+ char *code = NULL, *desc = NULL;
+ int index;
- history = gtk_option_menu_get_history (GTK_OPTION_MENU(editor->priv->optionmenu));
- menu = gtk_option_menu_get_menu (GTK_OPTION_MENU(editor->priv->optionmenu));
- item = gtk_menu_get_active (GTK_MENU(menu));
- description = (const char *) g_object_get_data (G_OBJECT(item), "desc");
+ combo = ephy_dialog_get_control (EPHY_DIALOG (editor), properties[LANGUAGE_PROP].id);
+ model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
+ index = gtk_combo_box_get_active (GTK_COMBO_BOX (combo));
- g_return_if_fail (description != NULL);
+ if (gtk_tree_model_iter_nth_child (model, &iter, NULL, index))
+ {
+ gtk_tree_model_get (model, &iter,
+ 0, &desc,
+ 1, &code,
+ -1);
- gtk_list_store_append (GTK_LIST_STORE (editor->priv->model),
- &iter);
+ language_editor_add (editor, code, desc);
- gtk_list_store_set (GTK_LIST_STORE (editor->priv->model),
- &iter,
- COL_DESCRIPTION, description,
- COL_DATA, history,
- -1);
+ g_free (desc);
+ g_free (code);
+ }
language_editor_update_pref (editor);
}
@@ -245,63 +245,59 @@ static void
language_editor_set_view (LanguageEditor *ge,
GtkWidget *treeview,
GtkWidget *add_button,
- GtkWidget *remove_button,
- GtkWidget *optionmenu)
+ GtkWidget *remove_button)
{
GtkTreeViewColumn *column;
- GtkCellRenderer *renderer;
+ GtkCellRenderer *renderer;
GtkListStore *liststore;
GtkTreeSelection *selection;
ge->priv->treeview = treeview;
- ge->priv->optionmenu = optionmenu;
gtk_tree_view_set_reorderable (GTK_TREE_VIEW(ge->priv->treeview), TRUE);
- liststore = gtk_list_store_new (2,
- G_TYPE_STRING,
- G_TYPE_INT);
+ liststore = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
ge->priv->model = GTK_TREE_MODEL (liststore);
- gtk_tree_view_set_model (GTK_TREE_VIEW(ge->priv->treeview),
- ge->priv->model);
+ gtk_tree_view_set_model (GTK_TREE_VIEW(ge->priv->treeview),
+ ge->priv->model);
g_object_unref (ge->priv->model);
- gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(ge->priv->treeview),
- FALSE);
+ gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(ge->priv->treeview),
+ FALSE);
- renderer = gtk_cell_renderer_text_new ();
+ renderer = gtk_cell_renderer_text_new ();
- gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW(ge->priv->treeview),
- 0, "Language",
- renderer,
- "text", 0,
- NULL);
- column = gtk_tree_view_get_column (GTK_TREE_VIEW(ge->priv->treeview), 0);
- gtk_tree_view_column_set_resizable (column, TRUE);
- gtk_tree_view_column_set_sort_column_id (column, COL_DESCRIPTION);
+ gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW(ge->priv->treeview),
+ 0, "Language",
+ renderer,
+ "text", 0,
+ NULL);
+ column = gtk_tree_view_get_column (GTK_TREE_VIEW(ge->priv->treeview), 0);
+ gtk_tree_view_column_set_resizable (column, TRUE);
+ gtk_tree_view_column_set_sort_column_id (column, COL_DESCRIPTION);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(ge->priv->treeview));
- gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
+ gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
/* Connect treeview signals */
g_signal_connect
- (G_OBJECT (ge->priv->treeview),
+ (G_OBJECT (ge->priv->treeview),
"drag_end",
- G_CALLBACK(language_editor_treeview_drag_end_cb),
+ G_CALLBACK (language_editor_treeview_drag_end_cb),
ge);
/* Connect buttons signals */
g_signal_connect
- (G_OBJECT (add_button),
+ (G_OBJECT (add_button),
"clicked",
- G_CALLBACK(language_editor_add_button_clicked_cb),
+ G_CALLBACK (language_editor_add_button_clicked_cb),
ge);
g_signal_connect
- (G_OBJECT (remove_button),
+ (G_OBJECT (remove_button),
"clicked",
- G_CALLBACK(language_editor_remove_button_clicked_cb),
+ G_CALLBACK (language_editor_remove_button_clicked_cb),
ge);
}
@@ -309,60 +305,67 @@ static void
language_editor_init (LanguageEditor *le)
{
GtkWidget *treeview;
- GtkWidget *optionmenu;
GtkWidget *add_button;
GtkWidget *remove_button;
le->priv = EPHY_LANGUAGE_EDITOR_GET_PRIVATE (le);
ephy_dialog_construct (EPHY_DIALOG(le),
- properties,
- "prefs-dialog.glade",
- "languages_dialog");
-
- treeview = ephy_dialog_get_control (EPHY_DIALOG(le),
- TREEVIEW_PROP);
- add_button = ephy_dialog_get_control (EPHY_DIALOG(le),
- ADD_PROP);
- remove_button = ephy_dialog_get_control (EPHY_DIALOG(le),
- REMOVE_PROP);
- optionmenu = ephy_dialog_get_control (EPHY_DIALOG(le),
- LANGUAGE_PROP);
-
- language_editor_set_view (le, treeview, add_button, remove_button,
- optionmenu);
+ properties,
+ "prefs-dialog.glade",
+ "languages_dialog");
+
+ treeview = ephy_dialog_get_control (EPHY_DIALOG(le), properties[TREEVIEW_PROP].id);
+ add_button = ephy_dialog_get_control (EPHY_DIALOG(le), properties[ADD_PROP].id);
+ remove_button = ephy_dialog_get_control (EPHY_DIALOG(le), properties[REMOVE_PROP].id);
+
+ language_editor_set_view (le, treeview, add_button, remove_button);
}
LanguageEditor *
language_editor_new (GtkWidget *parent)
{
return EPHY_LANGUAGE_EDITOR (g_object_new (EPHY_TYPE_LANGUAGE_EDITOR,
- "ParentWindow", parent,
- NULL));
+ "parent-window", parent,
+ NULL));
}
void
-language_editor_set_menu (LanguageEditor *editor,
- GtkWidget *menu)
+language_editor_set_model (LanguageEditor *editor,
+ GtkTreeModel *model)
{
- gtk_option_menu_set_menu (GTK_OPTION_MENU(editor->priv->optionmenu),
- menu);
+ GtkWidget *combo;
+ GtkCellRenderer *renderer;
+
+ combo = ephy_dialog_get_control (EPHY_DIALOG (editor), properties[LANGUAGE_PROP].id);
+
+ gtk_combo_box_set_model (GTK_COMBO_BOX (combo), model);
+
+ 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_DESCRIPTION,
+ NULL);
+
+ ephy_dialog_set_data_column (EPHY_DIALOG (editor), properties[LANGUAGE_PROP].id, COL_DATA);
+
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
}
void
-language_editor_add (LanguageEditor *ge,
- const char *language,
- int id)
+language_editor_add (LanguageEditor *editor,
+ const char *code,
+ const char *desc)
{
GtkTreeIter iter;
- gtk_list_store_append (GTK_LIST_STORE (ge->priv->model),
- &iter);
+ gtk_list_store_append (GTK_LIST_STORE (editor->priv->model), &iter);
- gtk_list_store_set (GTK_LIST_STORE (ge->priv->model),
- &iter,
- COL_DESCRIPTION, language,
- COL_DATA, id,
+ gtk_list_store_set (GTK_LIST_STORE (editor->priv->model), &iter,
+ COL_DESCRIPTION, desc,
+ COL_DATA, code,
-1);
}
diff --git a/src/language-editor.h b/src/language-editor.h
index 4a2cce30c..ee5a62193 100644
--- a/src/language-editor.h
+++ b/src/language-editor.h
@@ -22,6 +22,7 @@
#include "ephy-dialog.h"
#include <gtk/gtkwidget.h>
+#include <gtk/gtktreemodel.h>
#include <glib-object.h>
#include <glib.h>
@@ -34,9 +35,9 @@ G_BEGIN_DECLS
#define EPHY_IS_LANGUAGE_EDITOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EPHY_TYPE_LANGUAGE_EDITOR))
#define EPHY_LANGUAGE_EDITOR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EPHY_TYPE_LANGUAGE_EDITOR, LanguageEditorClass))
-typedef struct LanguageEditor LanguageEditor;
-typedef struct LanguageEditorClass LanguageEditorClass;
-typedef struct LanguageEditorPrivate LanguageEditorPrivate;
+typedef struct LanguageEditor LanguageEditor;
+typedef struct LanguageEditorClass LanguageEditorClass;
+typedef struct LanguageEditorPrivate LanguageEditorPrivate;
struct LanguageEditor
{
@@ -50,19 +51,19 @@ struct LanguageEditorClass
{
EphyDialogClass parent_class;
- void (* changed) (GSList *languages);
+ void (* changed) (GSList *codes);
};
GType language_editor_get_type (void);
LanguageEditor *language_editor_new (GtkWidget *parent);
-void language_editor_set_menu (LanguageEditor *editor,
- GtkWidget *menu);
+void language_editor_set_model (LanguageEditor *editor,
+ GtkTreeModel *model);
void language_editor_add (LanguageEditor *editor,
- const char *language,
- int id);
+ const char *code,
+ const char *desc);
G_END_DECLS
diff --git a/src/pdm-dialog.c b/src/pdm-dialog.c
index d1534de15..ecd7a73b7 100755
--- a/src/pdm-dialog.c
+++ b/src/pdm-dialog.c
@@ -74,18 +74,6 @@ struct PdmDialogPrivate
enum
{
- PROP_WINDOW,
- PROP_NOTEBOOK,
- PROP_COOKIES_TREEVIEW,
- PROP_COOKIES_REMOVE,
- PROP_PASSWORDS_TREEVIEW,
- PROP_PASSWORDS_REMOVE,
- PROP_DIALOG,
- PROP_COOKIES_PROPERTIES
-};
-
-enum
-{
COL_COOKIES_HOST,
COL_COOKIES_NAME,
COL_COOKIES_PATH,
@@ -99,21 +87,40 @@ enum
COL_PASSWORDS_DATA
};
+enum
+{
+ PROP_WINDOW,
+ PROP_NOTEBOOK,
+ PROP_COOKIES_TREEVIEW,
+ PROP_COOKIES_REMOVE,
+ PROP_COOKIES_PROPERTIES,
+ PROP_PASSWORDS_TREEVIEW,
+ PROP_PASSWORDS_REMOVE
+};
+
static const
EphyDialogProperty properties [] =
{
- { PROP_WINDOW, "pdm_dialog", NULL, PT_NORMAL, NULL },
- { PROP_NOTEBOOK, "pdm_notebook", NULL, PT_NORMAL, NULL },
+ { "pdm_dialog", NULL, PT_NORMAL, 0 },
+ { "pdm_notebook", NULL, PT_NORMAL, 0 },
+
+ { "cookies_treeview", NULL, PT_NORMAL, 0 },
+ { "cookies_remove_button", NULL, PT_NORMAL, 0 },
+ { "cookies_properties_button", NULL, PT_NORMAL, 0 },
+ { "passwords_treeview", NULL, PT_NORMAL, 0 },
+ { "passwords_remove_button", NULL, PT_NORMAL, 0 },
- { PROP_COOKIES_TREEVIEW, "cookies_treeview", NULL, PT_NORMAL, NULL },
- { PROP_COOKIES_REMOVE, "cookies_remove_button", NULL, PT_NORMAL, NULL },
- { PROP_PASSWORDS_TREEVIEW, "passwords_treeview", NULL, PT_NORMAL, NULL },
- { PROP_PASSWORDS_REMOVE, "passwords_remove_button", NULL, PT_NORMAL, NULL },
- { PROP_DIALOG, "pdm_dialog", NULL, PT_NORMAL, NULL },
- { PROP_COOKIES_PROPERTIES, "cookies_properties_button", NULL, PT_NORMAL, NULL },
+ { NULL }
+};
- { -1, NULL, NULL }
+static const
+char *size_group [] =
+{
+ "cookies_remove_button",
+ "cookies_properties_button",
+ "passwords_remove_button"
};
+const guint n_size_group = G_N_ELEMENTS (size_group);
static void pdm_dialog_class_init (PdmDialogClass *klass);
static void pdm_dialog_init (PdmDialog *dialog);
@@ -178,20 +185,20 @@ static void
pdm_dialog_show_help (PdmDialog *pd)
{
GtkWidget *notebook, *window;
- gint id;
+ int id;
/* FIXME: Once we actually have documentation we
* should point these at the correct links.
*/
- gchar *help_preferences[] = {
+ char *help_preferences[] = {
"pdm",
"pdm"
};
- window = ephy_dialog_get_control (EPHY_DIALOG (pd), PROP_WINDOW);
+ window = ephy_dialog_get_control (EPHY_DIALOG (pd), properties[PROP_WINDOW].id);
g_return_if_fail (GTK_IS_WINDOW (window));
- notebook = ephy_dialog_get_control (EPHY_DIALOG (pd), PROP_NOTEBOOK);
+ notebook = ephy_dialog_get_control (EPHY_DIALOG (pd), properties[PROP_NOTEBOOK].id);
g_return_if_fail (notebook != NULL);
id = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
@@ -210,7 +217,7 @@ action_treeview_selection_changed_cb (GtkTreeSelection *selection,
has_selection = gtk_tree_selection_count_selected_rows (selection) > 0;
- widget = ephy_dialog_get_control (d, action->remove_id);
+ widget = ephy_dialog_get_control (d, properties[action->remove_id].id);
gtk_widget_set_sensitive (widget, has_selection);
}
@@ -332,7 +339,7 @@ setup_action (PdmActionInfo *action)
GtkTreeSelection *selection;
widget = ephy_dialog_get_control (EPHY_DIALOG(action->dialog),
- action->remove_id);
+ properties[action->remove_id].id);
g_signal_connect (widget, "clicked",
G_CALLBACK (pdm_dialog_remove_button_clicked_cb),
action);
@@ -361,7 +368,7 @@ cookies_treeview_selection_changed_cb (GtkTreeSelection *selection,
has_selection = gtk_tree_selection_count_selected_rows (selection) == 1;
- widget = ephy_dialog_get_control (d, PROP_COOKIES_PROPERTIES);
+ widget = ephy_dialog_get_control (d, properties[PROP_COOKIES_PROPERTIES].id);
gtk_widget_set_sensitive (widget, has_selection);
}
@@ -378,7 +385,7 @@ pdm_dialog_cookies_construct (PdmActionInfo *info)
LOG ("pdm_dialog_cookies_construct")
treeview = GTK_TREE_VIEW (ephy_dialog_get_control
- (EPHY_DIALOG (dialog), PROP_COOKIES_TREEVIEW));
+ (EPHY_DIALOG (dialog), properties[PROP_COOKIES_TREEVIEW].id));
/* set tree model */
liststore = gtk_list_store_new (4,
@@ -636,7 +643,7 @@ pdm_dialog_passwords_construct (PdmActionInfo *info)
LOG ("pdm_dialog_passwords_construct")
treeview = GTK_TREE_VIEW (ephy_dialog_get_control
- (EPHY_DIALOG(dialog), PROP_PASSWORDS_TREEVIEW));
+ (EPHY_DIALOG(dialog), properties[PROP_PASSWORDS_TREEVIEW].id));
/* set tree model */
liststore = gtk_list_store_new (3,
@@ -775,14 +782,6 @@ pdm_dialog_init (PdmDialog *dialog)
PdmActionInfo *cookies, *passwords;
GtkWidget *notebook;
- const int props[] =
- {
- PROP_COOKIES_REMOVE,
- PROP_COOKIES_PROPERTIES,
- PROP_PASSWORDS_REMOVE
- };
- const guint n_props = G_N_ELEMENTS (props);
-
dialog->priv = EPHY_PDM_DIALOG_GET_PRIVATE (dialog);
dialog->priv->cookies = NULL;
@@ -798,7 +797,7 @@ pdm_dialog_init (PdmDialog *dialog)
* avoid the little jerk you get otherwise when switching pages because
* one set of buttons is wider than another.
*/
- ephy_dialog_set_size_group (EPHY_DIALOG (dialog), (int*) props, n_props);
+ ephy_dialog_set_size_group (EPHY_DIALOG (dialog), size_group, n_size_group);
cookies = g_new0 (PdmActionInfo, 1);
cookies->construct = pdm_dialog_cookies_construct;
@@ -830,7 +829,7 @@ pdm_dialog_init (PdmDialog *dialog)
cookies->construct (cookies);
passwords->construct (passwords);
- notebook = ephy_dialog_get_control (EPHY_DIALOG (dialog), PROP_NOTEBOOK);
+ notebook = ephy_dialog_get_control (EPHY_DIALOG (dialog), properties[PROP_NOTEBOOK].id);
sync_notebook_tab (notebook, NULL, 0, dialog);
g_signal_connect (G_OBJECT (notebook), "switch_page",
G_CALLBACK (sync_notebook_tab), dialog);
@@ -862,7 +861,7 @@ show_cookies_properties (PdmDialog *dialog,
char *str;
parent = ephy_dialog_get_control (EPHY_DIALOG(dialog),
- PROP_DIALOG);
+ properties[PROP_WINDOW].id);
gdialog = gtk_dialog_new_with_buttons
(_("Cookie Properties"),
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);
diff --git a/src/prefs-dialog.h b/src/prefs-dialog.h
index dad8dfc00..caceec2d3 100644
--- a/src/prefs-dialog.h
+++ b/src/prefs-dialog.h
@@ -33,9 +33,9 @@ G_BEGIN_DECLS
#define EPHY_IS_PREFS_DIALOG_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EPHY_TYPE_PREFS_DIALOG))
#define EPHY_PREFS_DIALOG_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EPHY_TYPE_PREFS_DIALOG, PrefsDialogClass))
-typedef struct PrefsDialog PrefsDialog;
-typedef struct PrefsDialogClass PrefsDialogClass;
-typedef struct PrefsDialogPrivate PrefsDialogPrivate;
+typedef struct PrefsDialog PrefsDialog;
+typedef struct PrefsDialogClass PrefsDialogClass;
+typedef struct PrefsDialogPrivate PrefsDialogPrivate;
struct PrefsDialog
{
@@ -52,8 +52,6 @@ struct PrefsDialogClass
GType prefs_dialog_get_type (void);
-EphyDialog *prefs_dialog_new (GtkWidget *parent);
-
G_END_DECLS
#endif
diff --git a/src/window-commands.c b/src/window-commands.c
index 25ee9bff7..f519297e6 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -41,7 +41,6 @@
#include "ephy-state.h"
#include "ephy-gui.h"
#include "ephy-zoom.h"
-#include "prefs-dialog.h"
#include "ephy-toolbars-model.h"
#include "egg-editable-toolbar.h"
#include "egg-toolbar-editor.h"
@@ -780,7 +779,8 @@ window_cmd_edit_prefs (GtkAction *action,
{
EphyDialog *dialog;
- dialog = prefs_dialog_new (GTK_WIDGET (window));
+ dialog = EPHY_DIALOG (ephy_shell_get_prefs_dialog (ephy_shell));
+
ephy_dialog_show (dialog);
}