[gnome-terminal] client: Forward the locale charset to the server



commit 07e73205f9d16156ad297d4b1ce001e6e8851fdb
Author: Christian Persch <chpe gnome org>
Date:   Sun Feb 21 15:10:16 2016 +0100

    client: Forward the locale charset to the server
    
    When providing an override command to use instead of the profile's
    command, use the remote locale's charset together with the command.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=732128

 src/client.vapi             |    1 +
 src/gterminal.vala          |    4 ++++
 src/terminal-app.c          |    3 ++-
 src/terminal-app.h          |    1 +
 src/terminal-client-utils.c |   18 +++++++++++-------
 src/terminal-client-utils.h |    1 +
 src/terminal-gdbus.c        |    7 +++++--
 src/terminal-nautilus.c     |    1 +
 src/terminal-screen.c       |   15 +++++++++++++++
 src/terminal-screen.h       |    1 +
 src/terminal-window.c       |    2 +-
 src/terminal.c              |    8 ++++----
 12 files changed, 47 insertions(+), 15 deletions(-)
---
diff --git a/src/client.vapi b/src/client.vapi
index ff8680d..941bb43 100644
--- a/src/client.vapi
+++ b/src/client.vapi
@@ -24,6 +24,7 @@ namespace Terminal.Client {
                                               string? geometry,
                                               string? role,
                                               string? profile,
+                                              string? encoding,
                                               string? title,
                                               bool active,
                                               bool maximise_window,
diff --git a/src/gterminal.vala b/src/gterminal.vala
index f1835eb..7de6e07 100644
--- a/src/gterminal.vala
+++ b/src/gterminal.vala
@@ -416,6 +416,9 @@ namespace GTerminal
   {
     var server = get_server ();
 
+    string encoding;
+    GLib.get_charset (out encoding);
+
     var builder = new GLib.VariantBuilder (VariantType.VARDICT);
     Terminal.Client.append_create_instance_options (builder,
                                                     OpenOptions.display_name,
@@ -423,6 +426,7 @@ namespace GTerminal
                                                     OpenOptions.geometry,
                                                     OpenOptions.role,
                                                     OpenOptions.profile,
+                                                    encoding,
                                                     null /* title */,
                                                     true,
                                                     OpenOptions.maximise,
diff --git a/src/terminal-app.c b/src/terminal-app.c
index f47a427..2d9129c 100644
--- a/src/terminal-app.c
+++ b/src/terminal-app.c
@@ -609,6 +609,7 @@ TerminalScreen *
 terminal_app_new_terminal (TerminalApp     *app,
                            TerminalWindow  *window,
                            GSettings       *profile,
+                           const char      *encoding,
                            char           **override_command,
                            const char      *title,
                            const char      *working_dir,
@@ -620,7 +621,7 @@ terminal_app_new_terminal (TerminalApp     *app,
   g_return_val_if_fail (TERMINAL_IS_APP (app), NULL);
   g_return_val_if_fail (TERMINAL_IS_WINDOW (window), NULL);
 
-  screen = terminal_screen_new (profile, override_command, title,
+  screen = terminal_screen_new (profile, encoding, override_command, title,
                                 working_dir, child_env, zoom);
 
   terminal_window_add_screen (window, screen, -1);
diff --git a/src/terminal-app.h b/src/terminal-app.h
index 6bf2f81..1348dcc 100644
--- a/src/terminal-app.h
+++ b/src/terminal-app.h
@@ -74,6 +74,7 @@ TerminalWindow * terminal_app_new_window   (TerminalApp *app,
 TerminalScreen *terminal_app_new_terminal (TerminalApp     *app,
                                            TerminalWindow  *window,
                                            GSettings       *profile,
+                                           const char      *encoding,
                                            char           **override_command,
                                            const char      *title,
                                            const char      *working_dir,
diff --git a/src/terminal-client-utils.c b/src/terminal-client-utils.c
index 7f9fb9a..36a415c 100644
--- a/src/terminal-client-utils.c
+++ b/src/terminal-client-utils.c
@@ -54,6 +54,7 @@ terminal_client_append_create_instance_options (GVariantBuilder *builder,
                                                 const char      *geometry,
                                                 const char      *role,
                                                 const char      *profile,
+                                                const char      *encoding,
                                                 const char      *title,
                                                 gboolean         active,
                                                 gboolean         maximise_window,
@@ -63,21 +64,24 @@ terminal_client_append_create_instance_options (GVariantBuilder *builder,
   g_variant_builder_add (builder, "{sv}",
                          "display", g_variant_new_bytestring (display_name));
   if (startup_id)
-    g_variant_builder_add (builder, "{sv}", 
+    g_variant_builder_add (builder, "{sv}",
                            "desktop-startup-id", g_variant_new_bytestring (startup_id));
 
   /* String options */
   if (profile)
-    g_variant_builder_add (builder, "{sv}", 
+    g_variant_builder_add (builder, "{sv}",
                            "profile", g_variant_new_string (profile));
+  if (encoding)
+    g_variant_builder_add (builder, "{sv}",
+                           "encoding", g_variant_new_string (encoding));
   if (title)
-    g_variant_builder_add (builder, "{sv}", 
+    g_variant_builder_add (builder, "{sv}",
                            "title", g_variant_new_string (title));
   if (geometry)
-    g_variant_builder_add (builder, "{sv}", 
+    g_variant_builder_add (builder, "{sv}",
                            "geometry", g_variant_new_string (geometry));
   if (role)
-    g_variant_builder_add (builder, "{sv}", 
+    g_variant_builder_add (builder, "{sv}",
                            "role", g_variant_new_string (role));
 
   /* Boolean options */
@@ -86,10 +90,10 @@ terminal_client_append_create_instance_options (GVariantBuilder *builder,
                            "active", g_variant_new_boolean (active));
 
   if (maximise_window)
-    g_variant_builder_add (builder, "{sv}", 
+    g_variant_builder_add (builder, "{sv}",
                            "maximize-window", g_variant_new_boolean (TRUE));
   if (fullscreen_window)
-    g_variant_builder_add (builder, "{sv}", 
+    g_variant_builder_add (builder, "{sv}",
                            "fullscreen-window", g_variant_new_boolean (TRUE));
 }
 
diff --git a/src/terminal-client-utils.h b/src/terminal-client-utils.h
index 6489601..fc3b968 100644
--- a/src/terminal-client-utils.h
+++ b/src/terminal-client-utils.h
@@ -29,6 +29,7 @@ void terminal_client_append_create_instance_options (GVariantBuilder *builder,
                                                      const char      *geometry,
                                                      const char      *role,
                                                      const char      *profile,
+                                                     const char      *encoding,
                                                      const char      *title,
                                                      gboolean         active,
                                                      gboolean         maximise_window,
diff --git a/src/terminal-gdbus.c b/src/terminal-gdbus.c
index 40f426a..bb456b2 100644
--- a/src/terminal-gdbus.c
+++ b/src/terminal-gdbus.c
@@ -368,7 +368,7 @@ terminal_factory_impl_create_instance (TerminalFactory *factory,
   TerminalObjectSkeleton *skeleton;
   char *object_path;
   GSettings *profile = NULL;
-  const char *profile_uuid, *title;
+  const char *profile_uuid, *title, *encoding;
   gboolean zoom_set = FALSE;
   gdouble zoom = 1.0;
   guint window_id;
@@ -381,6 +381,9 @@ terminal_factory_impl_create_instance (TerminalFactory *factory,
   if (!g_variant_lookup (options, "profile", "&s", &profile_uuid))
     profile_uuid = NULL;
 
+  if (!g_variant_lookup (options, "encoding", "&s", &encoding))
+    encoding = NULL; /* use profile encoding */
+
   profiles_list = terminal_app_get_profiles_list (app);
   profile = terminal_profiles_list_ref_profile_by_uuid (profiles_list, profile_uuid, &err);
   if (profile == NULL)
@@ -461,7 +464,7 @@ terminal_factory_impl_create_instance (TerminalFactory *factory,
   if (g_variant_lookup (options, "zoom", "d", &zoom))
     zoom_set = TRUE;
 
-  screen = terminal_screen_new (profile, NULL, title, NULL, NULL, 
+  screen = terminal_screen_new (profile, encoding, NULL, title, NULL, NULL,
                                 zoom_set ? zoom : 1.0);
   terminal_window_add_screen (window, screen, -1);
 
diff --git a/src/terminal-nautilus.c b/src/terminal-nautilus.c
index 1f6e627..6c5fc63 100644
--- a/src/terminal-nautilus.c
+++ b/src/terminal-nautilus.c
@@ -382,6 +382,7 @@ create_terminal (ExecData *data /* transfer full */)
                                                   NULL /* geometry */,
                                                   NULL /* role */,
                                                   NULL /* use default profile */,
+                                                  NULL /* use profile encoding */,
                                                   NULL /* title */,
                                                   TRUE, /* active */
                                                   FALSE /* maximised */,
diff --git a/src/terminal-screen.c b/src/terminal-screen.c
index e34f749..97854ad 100644
--- a/src/terminal-screen.c
+++ b/src/terminal-screen.c
@@ -679,6 +679,7 @@ terminal_screen_finalize (GObject *object)
 
 TerminalScreen *
 terminal_screen_new (GSettings       *profile,
+                     const char      *encoding,
                      char           **override_command,
                      const char      *title,
                      const char      *working_dir,
@@ -694,6 +695,20 @@ terminal_screen_new (GSettings       *profile,
   priv = screen->priv;
 
   terminal_screen_set_profile (screen, profile);
+
+  /* If we got an encoding together with an override command,
+   * override the profile encoding; otherwise use the profile
+   * encoding.
+   */
+  if (encoding != NULL && override_command != NULL) {
+    TerminalEncoding *enc;
+
+    enc = terminal_app_ensure_encoding (terminal_app_get (), encoding);
+    vte_terminal_set_encoding (VTE_TERMINAL (screen),
+                               terminal_encoding_get_charset (enc),
+                               NULL);
+  }
+
   vte_terminal_set_size (VTE_TERMINAL (screen),
                          g_settings_get_int (profile, TERMINAL_PROFILE_DEFAULT_SIZE_COLUMNS_KEY),
                          g_settings_get_int (profile, TERMINAL_PROFILE_DEFAULT_SIZE_ROWS_KEY));
diff --git a/src/terminal-screen.h b/src/terminal-screen.h
index 8097bde..f3b4013 100644
--- a/src/terminal-screen.h
+++ b/src/terminal-screen.h
@@ -76,6 +76,7 @@ GType terminal_screen_get_type (void) G_GNUC_CONST;
 const char *terminal_screen_get_uuid (TerminalScreen *screen);
 
 TerminalScreen *terminal_screen_new (GSettings       *profile,
+                                     const char      *encoding,
                                      char           **override_command,
                                      const char      *title,
                                      const char      *working_dir,
diff --git a/src/terminal-window.c b/src/terminal-window.c
index 4c2dd47..8b78849 100644
--- a/src/terminal-window.c
+++ b/src/terminal-window.c
@@ -408,7 +408,7 @@ action_new_terminal_cb (GSimpleAction *action,
     window = terminal_app_new_window (app, gtk_widget_get_screen (GTK_WIDGET (window)));
 
   new_working_directory = terminal_screen_get_current_dir (priv->active_screen);
-  terminal_app_new_terminal (app, window, profile,
+  terminal_app_new_terminal (app, window, profile, NULL /* use profile encoding */,
                              NULL, NULL,
                              new_working_directory,
                              terminal_screen_get_initial_environment (priv->active_screen),
diff --git a/src/terminal.c b/src/terminal.c
index 97db938..f6ab0a5 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -63,11 +63,10 @@ handle_options (TerminalFactory *factory,
 {
   GList *lw;
   GError *err;
+  const char *encoding;
 
-#if 0
-  gdk_screen = terminal_app_get_screen_by_display_name (options->display_name,
-                                                        options->screen_number);
-#endif
+  /* We need to forward the locale encoding to the server, see bug #732128 */
+  g_get_charset (&encoding);
 
   /* Make sure we open at least one window */
   terminal_options_ensure_window (options);
@@ -102,6 +101,7 @@ handle_options (TerminalFactory *factory,
                                                           iw->geometry,
                                                           iw->role,
                                                           it->profile ? it->profile : 
options->default_profile,
+                                                          encoding,
                                                           it->title ? it->title : options->default_title,
                                                           it->active,
                                                           iw->start_maximized,


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