[gnome-terminal/gnome-3-4: 2/10] Add 'encoding' profile setting



commit ea2bf3a3209917a469b74287b43be4ff789b0b12
Author: Christian Persch <chpe gnome org>
Date:   Fri Jan 20 22:21:25 2012 +0100

    Add 'encoding' profile setting
    
    No UI yet, and won't get UI for 3.4.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=108711

 src/gnome-terminal.schemas.in |   15 +++++++++++++++
 src/terminal-app.c            |   11 ++++++++---
 src/terminal-profile.c        |   17 +++++++++++++++++
 src/terminal-profile.h        |    1 +
 src/terminal-screen.c         |    9 +++++++++
 5 files changed, 50 insertions(+), 3 deletions(-)
---
diff --git a/src/gnome-terminal.schemas.in b/src/gnome-terminal.schemas.in
index 763ec22..0dc0d92 100644
--- a/src/gnome-terminal.schemas.in
+++ b/src/gnome-terminal.schemas.in
@@ -703,6 +703,21 @@
       </locale>
     </schema>
 
+    <schema>
+      <key>/schemas/apps/gnome-terminal/profiles/Default/encoding</key>
+      <applyto>/apps/gnome-terminal/profiles/Default/encoding</applyto>
+      <owner>gnome-terminal</owner>
+      <type>string</type>
+      <locale name="C">
+         <default>current</default>
+         <short>Default encoding</short>
+         <long>
+          Default encoding. Can be either "current" to use the current locale's
+          encoding, or else any of the known encodings.
+         </long>
+      </locale>
+    </schema>
+
     <!-- Keybindings -->
 
     <schema>
diff --git a/src/terminal-app.c b/src/terminal-app.c
index 0f198e7..f24d942 100644
--- a/src/terminal-app.c
+++ b/src/terminal-app.c
@@ -1998,9 +1998,14 @@ terminal_app_get_encodings (TerminalApp *app)
 /**
  * terminal_app_ensure_encoding:
  * @app:
- * @charset:
+ * @charset: (allow-none): a charset, or %NULL
  *
- * Ensures there's a #TerminalEncoding for @charset available.
+ * Ensures there's a #TerminalEncoding for @charset available. If @charset
+ * is %NULL, returns the #TerminalEncoding for the locale's charset. If
+ * @charset is not a known charset, returns a #TerminalEncoding for a 
+ * custom charset.
+ * 
+ * Returns: (transfer none): a #TerminalEncoding
  */
 TerminalEncoding *
 terminal_app_ensure_encoding (TerminalApp *app,
@@ -2008,7 +2013,7 @@ terminal_app_ensure_encoding (TerminalApp *app,
 {
   TerminalEncoding *encoding;
 
-  encoding = g_hash_table_lookup (app->encodings, charset);
+  encoding = g_hash_table_lookup (app->encodings, charset ? charset : "current");
   if (encoding == NULL)
     {
       encoding = terminal_encoding_new (charset,
diff --git a/src/terminal-profile.c b/src/terminal-profile.c
index 58ed5dd..6332a68 100644
--- a/src/terminal-profile.c
+++ b/src/terminal-profile.c
@@ -29,6 +29,7 @@
 #include "terminal-app.h"
 #include "terminal-debug.h"
 #include "terminal-intl.h"
+#include "terminal-encoding.h"
 #include "terminal-profile.h"
 #include "terminal-screen.h"
 #include "terminal-type-builtins.h"
@@ -63,6 +64,7 @@ enum
   PROP_DEFAULT_SIZE_ROWS,
   PROP_DEFAULT_SHOW_MENUBAR,
   PROP_DELETE_BINDING,
+  PROP_ENCODING,
   PROP_EXIT_ACTION,
   PROP_FONT,
   PROP_FOREGROUND_COLOR,
@@ -104,6 +106,7 @@ enum
 #define KEY_DEFAULT_SIZE_ROWS "default_size_rows"
 #define KEY_DELETE_BINDING "delete_binding"
 #define KEY_EXIT_ACTION "exit_action"
+#define KEY_ENCODING "encoding"
 #define KEY_FONT "font"
 #define KEY_FOREGROUND_COLOR "foreground_color"
 #define KEY_LOGIN_SHELL "login_shell"
@@ -141,6 +144,7 @@ enum
 #define DEFAULT_DEFAULT_SIZE_COLUMNS  (80)
 #define DEFAULT_DEFAULT_SIZE_ROWS     (24)
 #define DEFAULT_DELETE_BINDING        (VTE_ERASE_DELETE_SEQUENCE)
+#define DEFAULT_ENCODING              (NULL)
 #define DEFAULT_EXIT_ACTION           (TERMINAL_EXIT_CLOSE)
 #define DEFAULT_FONT                  ("Monospace 12")
 #define DEFAULT_FOREGROUND_COLOR      ("#000000")
@@ -506,6 +510,10 @@ terminal_profile_reset_property_internal (TerminalProfile *profile,
         g_value_set_boxed (value, &DEFAULT_BACKGROUND_COLOR);
         break;
 
+      case PROP_ENCODING:
+        g_value_set_boxed (value, terminal_app_ensure_encoding (terminal_app_get (), DEFAULT_ENCODING));
+        break;
+
       case PROP_FONT:
         g_value_take_boxed (value, pango_font_description_from_string (DEFAULT_FONT));
         break;
@@ -627,6 +635,13 @@ terminal_profile_gconf_notify_cb (GConfClient *client,
 
       g_value_take_boxed (&value, pango_font_description_from_string (gconf_value_get_string (gconf_value)));
     }
+  else if (G_PARAM_SPEC_VALUE_TYPE (pspec) == TERMINAL_TYPE_ENCODING)
+    {
+      if (gconf_value->type != GCONF_VALUE_STRING)
+        goto out;
+
+      g_value_set_boxed (&value, terminal_app_ensure_encoding (terminal_app_get (), gconf_value_get_string (gconf_value)));
+    }
   else if (G_IS_PARAM_SPEC_DOUBLE (pspec))
     {
       if (gconf_value->type != GCONF_VALUE_FLOAT)
@@ -963,6 +978,7 @@ terminal_profile_init (TerminalProfile *profile)
   terminal_profile_reset_property_internal (profile, g_object_class_find_property (object_class, TERMINAL_PROFILE_FOREGROUND_COLOR), FALSE);
   terminal_profile_reset_property_internal (profile, g_object_class_find_property (object_class, TERMINAL_PROFILE_BOLD_COLOR), FALSE);
   terminal_profile_reset_property_internal (profile, g_object_class_find_property (object_class, TERMINAL_PROFILE_BACKGROUND_COLOR), FALSE);
+  terminal_profile_reset_property_internal (profile, g_object_class_find_property (object_class, TERMINAL_PROFILE_ENCODING), FALSE);
   terminal_profile_reset_property_internal (profile, g_object_class_find_property (object_class, TERMINAL_PROFILE_FONT), FALSE);
   terminal_profile_reset_property_internal (profile, g_object_class_find_property (object_class, TERMINAL_PROFILE_PALETTE), FALSE);
 }
@@ -1308,6 +1324,7 @@ terminal_profile_class_init (TerminalProfileClass *klass)
 
   TERMINAL_PROFILE_PROPERTY_BOXED (BACKGROUND_COLOR, GDK_TYPE_COLOR, KEY_BACKGROUND_COLOR);
   TERMINAL_PROFILE_PROPERTY_BOXED (BOLD_COLOR, GDK_TYPE_COLOR, KEY_BOLD_COLOR);
+  TERMINAL_PROFILE_PROPERTY_BOXED (ENCODING, TERMINAL_TYPE_ENCODING, KEY_ENCODING);
   TERMINAL_PROFILE_PROPERTY_BOXED (FONT, PANGO_TYPE_FONT_DESCRIPTION, KEY_FONT);
   TERMINAL_PROFILE_PROPERTY_BOXED (FOREGROUND_COLOR, GDK_TYPE_COLOR, KEY_FOREGROUND_COLOR);
 
diff --git a/src/terminal-profile.h b/src/terminal-profile.h
index d1474fb..ca877fc 100644
--- a/src/terminal-profile.h
+++ b/src/terminal-profile.h
@@ -81,6 +81,7 @@ typedef enum
 #define TERMINAL_PROFILE_DEFAULT_SIZE_COLUMNS   "default-size-columns"
 #define TERMINAL_PROFILE_DEFAULT_SIZE_ROWS      "default-size-rows"
 #define TERMINAL_PROFILE_DELETE_BINDING         "delete-binding"
+#define TERMINAL_PROFILE_ENCODING               "encoding"
 #define TERMINAL_PROFILE_EXIT_ACTION            "exit-action"
 #define TERMINAL_PROFILE_FONT                   "font"
 #define TERMINAL_PROFILE_FOREGROUND_COLOR       "foreground-color"
diff --git a/src/terminal-screen.c b/src/terminal-screen.c
index acfd5d8..b20b404 100644
--- a/src/terminal-screen.c
+++ b/src/terminal-screen.c
@@ -929,6 +929,15 @@ terminal_screen_profile_notify_cb (TerminalProfile *profile,
     _terminal_screen_update_scrollbar (screen);
 
   if (!prop_name ||
+      prop_name == I_(TERMINAL_PROFILE_ENCODING))
+    {
+      TerminalEncoding *encoding;
+
+      encoding = terminal_profile_get_property_boxed (profile, TERMINAL_PROFILE_ENCODING);
+      vte_terminal_set_encoding (vte_terminal, terminal_encoding_get_charset (encoding));
+    }
+
+  if (!prop_name ||
       prop_name == I_(TERMINAL_PROFILE_TITLE_MODE) ||
       prop_name == I_(TERMINAL_PROFILE_TITLE))
     {



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