[epiphany] prefs-dialog: Bring back default encoding preference



commit 88aacc4f86762c805d2abf092c727e363282b64f
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Wed Feb 1 15:51:50 2017 -0600

    prefs-dialog: Bring back default encoding preference
    
    Bring back this preference. Safari guesses the default encoding based on
    the user's locale, and unless we're going to do that, we should allow
    the user to configure it.

 src/prefs-dialog.c                |   75 +++++++++++++++++++++++++++++++++++++
 src/resources/gtk/prefs-dialog.ui |   39 +++++++++++++++++++
 2 files changed, 114 insertions(+), 0 deletions(-)
---
diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c
index 23f765b..d96e69f 100644
--- a/src/prefs-dialog.c
+++ b/src/prefs-dialog.c
@@ -28,6 +28,7 @@
 #include "ephy-embed-prefs.h"
 #include "ephy-embed-shell.h"
 #include "ephy-embed-utils.h"
+#include "ephy-encodings.h"
 #include "ephy-file-chooser.h"
 #include "ephy-file-helpers.h"
 #include "ephy-gui.h"
@@ -98,6 +99,7 @@ struct _PrefsDialog {
   GtkWidget *clear_personal_data_button;
 
   /* language */
+  GtkWidget *default_encoding_combo;
   GtkTreeView *lang_treeview;
   GtkWidget *lang_add_button;
   GtkWidget *lang_remove_button;
@@ -146,6 +148,12 @@ typedef struct {
 #endif
 
 enum {
+  COL_TITLE_ELIDED,
+  COL_ENCODING,
+  NUM_COLS
+};
+
+enum {
   SEARCH_ENGINE_COL_NAME,
   SEARCH_ENGINE_COL_STOCK_URL,
   SEARCH_ENGINE_COL_URL,
@@ -615,6 +623,7 @@ prefs_dialog_class_init (PrefsDialogClass *klass)
   gtk_widget_class_bind_template_child (widget_class, PrefsDialog, clear_personal_data_button);
 
   /* language */
+  gtk_widget_class_bind_template_child (widget_class, PrefsDialog, default_encoding_combo);
   gtk_widget_class_bind_template_child (widget_class, PrefsDialog, lang_treeview);
   gtk_widget_class_bind_template_child (widget_class, PrefsDialog, lang_add_button);
   gtk_widget_class_bind_template_child (widget_class, PrefsDialog, lang_remove_button);
@@ -715,6 +724,67 @@ combo_set_mapping (const GValue       *value,
 }
 
 static void
+create_node_combo (PrefsDialog   *dialog,
+                   EphyEncodings *encodings,
+                   const char    *default_value)
+{
+  GtkComboBox *combo;
+  GtkCellRenderer *renderer;
+  GtkListStore *store;
+  GList *all_encodings, *p;
+  char *code;
+
+  code = g_settings_get_string (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_DEFAULT_ENCODING);
+  if (code == NULL || ephy_encodings_get_encoding (encodings, code, FALSE) == NULL)
+  {
+    /* safe default */
+    g_settings_set_string (EPHY_SETTINGS_WEB,
+                           EPHY_PREFS_WEB_DEFAULT_ENCODING,
+                           default_value);
+  }
+  g_free (code);
+
+  combo = GTK_COMBO_BOX (dialog->default_encoding_combo);
+
+  store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_STRING);
+  all_encodings = ephy_encodings_get_all (encodings);
+  for (p = all_encodings; p; p = p->next) {
+    GtkTreeIter iter;
+    EphyEncoding *encoding = EPHY_ENCODING (p->data);
+
+    gtk_list_store_append (store, &iter);
+    gtk_list_store_set (store, &iter,
+                        COL_TITLE_ELIDED,
+                        ephy_encoding_get_title_elided (encoding),
+                        -1);
+    gtk_list_store_set (store, &iter,
+                        COL_ENCODING,
+                        ephy_encoding_get_encoding (encoding),
+                        -1);
+  }
+  g_list_free (all_encodings);
+
+  gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), COL_TITLE_ELIDED,
+                                        GTK_SORT_ASCENDING);
+  gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
+
+  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_TITLE_ELIDED,
+                                  NULL);
+
+  g_settings_bind_with_mapping (EPHY_SETTINGS_WEB,
+                                EPHY_PREFS_WEB_DEFAULT_ENCODING,
+                                combo, "active",
+                                G_SETTINGS_BIND_DEFAULT,
+                                combo_get_mapping,
+                                combo_set_mapping,
+                                combo,
+                                NULL);
+}
+
+static void
 language_editor_add (PrefsDialog *pd,
                      const char  *code,
                      const char  *desc)
@@ -1786,6 +1856,7 @@ static void
 setup_language_page (PrefsDialog *dialog)
 {
   GSettings *web_settings;
+  EphyEncodings *encodings;
 
   web_settings = ephy_settings_get (EPHY_PREFS_WEB_SCHEMA);
 
@@ -1795,6 +1866,10 @@ setup_language_page (PrefsDialog *dialog)
                    "active",
                    G_SETTINGS_BIND_DEFAULT);
 
+  encodings = EPHY_ENCODINGS (ephy_embed_shell_get_encodings (EPHY_EMBED_SHELL (ephy_shell_get_default ())));
+
+  create_node_combo (dialog, encodings, "ISO-8859-1");
+
   create_language_section (dialog);
 }
 
diff --git a/src/resources/gtk/prefs-dialog.ui b/src/resources/gtk/prefs-dialog.ui
index 1c404d5..f48cd88 100644
--- a/src/resources/gtk/prefs-dialog.ui
+++ b/src/resources/gtk/prefs-dialog.ui
@@ -666,6 +666,45 @@
                       <object class="GtkLabel">
                         <property name="visible">True</property>
                         <property name="halign">start</property>
+                        <property name="label" translatable="yes">Encodings</property>
+                        <attributes>
+                          <attribute name="weight" value="bold"/>
+                        </attributes>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkGrid">
+                        <property name="visible">True</property>
+                        <property name="column-spacing">12</property>
+                        <property name="margin-start">12</property>
+                        <child>
+                          <object class="GtkLabel">
+                            <property name="visible">True</property>
+                            <property name="halign">start</property>
+                            <property name="label" translatable="yes">De_fault:</property>
+                            <property name="use-underline">True</property>
+                            <property name="mnemonic-widget">default_encoding_combo</property>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="GtkComboBox" id="default_encoding_combo">
+                            <property name="visible">True</property>
+                            <property name="hexpand">True</property>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkBox">
+                    <property name="visible">True</property>
+                    <property name="orientation">vertical</property>
+                    <property name="spacing">6</property>
+                    <child>
+                      <object class="GtkLabel">
+                        <property name="visible">True</property>
+                        <property name="halign">start</property>
                         <property name="label" translatable="yes">Languages</property>
                         <attributes>
                           <attribute name="weight" value="bold"/>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]