[gnome-terminal] Make legacy command line client work again



commit 2c37f3aeb790d8f0730d38818f1a8a100b4cd195
Author: Christian Persch <chpe gnome org>
Date:   Thu Nov 24 22:53:45 2011 +0100

    Make legacy command line client work again

 src/terminal-app.c     |    8 +--
 src/terminal-app.h     |   26 -------
 src/terminal-options.c |   56 ++++++++++++---
 src/terminal-options.h |   28 +++++++-
 src/terminal-screen.c  |    2 +
 src/terminal-util.c    |   42 -----------
 src/terminal-util.h    |   10 ---
 src/terminal-window.c  |    1 +
 src/terminal.c         |  185 ++++++++++++++++++++++++-----------------------
 9 files changed, 172 insertions(+), 186 deletions(-)
---
diff --git a/src/terminal-app.c b/src/terminal-app.c
index 4e6b67e..48bc29b 100644
--- a/src/terminal-app.c
+++ b/src/terminal-app.c
@@ -117,12 +117,6 @@ enum
   NUM_COLUMNS
 };
 
-enum
-{
-  SOURCE_DEFAULT = 0,
-  SOURCE_SESSION = 1
-};
-
 static TerminalApp *global_app = NULL;
 
 /* Helper functions */
@@ -1661,6 +1655,8 @@ terminal_app_get_active_encodings (TerminalApp *app)
   return g_slist_sort (list, (GCompareFunc) compare_encodings);
 }
 
+#include "terminal-options.h"
+
 void
 terminal_app_save_config (TerminalApp *app,
                           GKeyFile *key_file)
diff --git a/src/terminal-app.h b/src/terminal-app.h
index 5ec789b..a31256e 100644
--- a/src/terminal-app.h
+++ b/src/terminal-app.h
@@ -28,32 +28,6 @@
 
 G_BEGIN_DECLS
 
-/* Terminal conf files */
-
-#define TERMINAL_CONFIG_VERSION             (1) /* Bump this for any changes */
-#define TERMINAL_CONFIG_COMPAT_VERSION      (1) /* Bump this for incompatible changes */
-
-#define TERMINAL_CONFIG_GROUP               "GNOME Terminal Configuration"
-#define TERMINAL_CONFIG_PROP_VERSION        "Version"
-#define TERMINAL_CONFIG_PROP_COMPAT_VERSION "CompatVersion"
-#define TERMINAL_CONFIG_PROP_WINDOWS        "Windows"
-
-#define TERMINAL_CONFIG_WINDOW_PROP_ACTIVE_TAB       "ActiveTerminal"
-#define TERMINAL_CONFIG_WINDOW_PROP_FULLSCREEN       "Fullscreen"
-#define TERMINAL_CONFIG_WINDOW_PROP_GEOMETRY         "Geometry"
-#define TERMINAL_CONFIG_WINDOW_PROP_MAXIMIZED        "Maximized"
-#define TERMINAL_CONFIG_WINDOW_PROP_MENUBAR_VISIBLE  "MenubarVisible"
-#define TERMINAL_CONFIG_WINDOW_PROP_ROLE             "Role"
-#define TERMINAL_CONFIG_WINDOW_PROP_TABS             "Terminals"
-
-#define TERMINAL_CONFIG_TERMINAL_PROP_HEIGHT             "Height"
-#define TERMINAL_CONFIG_TERMINAL_PROP_COMMAND            "Command"
-#define TERMINAL_CONFIG_TERMINAL_PROP_PROFILE_ID         "ProfileID"
-#define TERMINAL_CONFIG_TERMINAL_PROP_TITLE              "Title"
-#define TERMINAL_CONFIG_TERMINAL_PROP_WIDTH              "Width"
-#define TERMINAL_CONFIG_TERMINAL_PROP_WORKING_DIRECTORY  "WorkingDirectory"
-#define TERMINAL_CONFIG_TERMINAL_PROP_ZOOM               "Zoom"
-
 #define GNOME_TERMINAL_ICON_NAME "utilities-terminal"
 
 #define MONOSPACE_FONT_KEY_NAME                 "monospace-font-name"
diff --git a/src/terminal-options.c b/src/terminal-options.c
index 5e5a62a..20ab08f 100644
--- a/src/terminal-options.c
+++ b/src/terminal-options.c
@@ -36,6 +36,48 @@
 
 static GOptionContext *get_goption_context (TerminalOptions *options);
 
+static char *
+terminal_util_key_file_get_string_unescape (GKeyFile *key_file,
+                                            const char *group,
+                                            const char *key,
+                                            GError **error)
+{
+  char *escaped, *unescaped;
+
+  escaped = g_key_file_get_string (key_file, group, key, error);
+  if (!escaped)
+    return NULL;
+
+  unescaped = g_strcompress (escaped);
+  g_free (escaped);
+
+  return unescaped;
+}
+
+static char **
+terminal_util_key_file_get_argv (GKeyFile *key_file,
+                                 const char *group,
+                                 const char *key,
+                                 int *argc,
+                                 GError **error)
+{
+  char **argv;
+  char *flat;
+  gboolean retval;
+
+  flat = terminal_util_key_file_get_string_unescape (key_file, group, key, error);
+  if (!flat)
+    return NULL;
+
+  retval = g_shell_parse_argv (flat, argc, &argv, error);
+  g_free (flat);
+
+  if (retval)
+    return argv;
+
+  return NULL;
+}
+
 static InitialTab*
 initial_tab_new (const char *profile,
                  gboolean    is_id)
@@ -625,7 +667,10 @@ option_zoom_callback (const gchar *option_name,
       it->zoom_set = TRUE;
     }
   else
-    options->zoom = zoom;
+    {
+      options->zoom = zoom;
+      options->zoom_set = TRUE;
+    }
 
   return TRUE;
 }
@@ -667,7 +712,6 @@ digest_options_callback (GOptionContext *context,
  * @working_directory: the default working directory
  * @display_name: the default X display name
  * @startup_id: the startup notification ID
- * @env: the environment as variable=value pairs
  * @remote_arguments: whether the caller is the factory process or not
  * @ignore_unknown_options: whether to ignore unknown options when parsing
  *   the arguments
@@ -686,7 +730,6 @@ TerminalOptions *
 terminal_options_parse (const char *working_directory,
                         const char *display_name,
                         const char *startup_id,
-                        char **env,
                         gboolean remote_arguments,
                         gboolean ignore_unknown_options,
                         int *argcp,
@@ -712,7 +755,6 @@ terminal_options_parse (const char *working_directory,
   options->execute = FALSE;
   options->use_factory = TRUE;
 
-  options->env = g_strdupv (env);
   options->startup_id = g_strdup (startup_id && startup_id[0] ? startup_id : NULL);
   options->display_name = g_strdup (display_name);
   options->initial_windows = NULL;
@@ -720,6 +762,7 @@ terminal_options_parse (const char *working_directory,
   options->default_geometry = NULL;
   options->default_title = NULL;
   options->zoom = 1.0;
+  options->zoom_set = FALSE;
 
   options->screen_number = -1;
   options->default_working_dir = g_strdup (working_directory);
@@ -780,8 +823,6 @@ terminal_options_parse (const char *working_directory,
   return NULL;
 }
 
-#ifdef TERMINAL_SERVER
-
 /**
  * terminal_options_merge_config:
  * @options:
@@ -901,8 +942,6 @@ terminal_options_merge_config (TerminalOptions *options,
   return TRUE;
 }
 
-#endif /* TERMINAL_SERVIER */
-
 /**
  * terminal_options_ensure_window:
  * @options:
@@ -927,7 +966,6 @@ terminal_options_free (TerminalOptions *options)
   g_list_foreach (options->initial_windows, (GFunc) initial_window_free, NULL);
   g_list_free (options->initial_windows);
 
-  g_strfreev (options->env);
   g_free (options->default_role);
   g_free (options->default_geometry);
   g_free (options->default_working_dir);
diff --git a/src/terminal-options.h b/src/terminal-options.h
index 536d6e9..c5aff62 100644
--- a/src/terminal-options.h
+++ b/src/terminal-options.h
@@ -26,10 +26,33 @@
 
 G_BEGIN_DECLS
 
+#define TERMINAL_CONFIG_VERSION             (1) /* Bump this for any changes */
+#define TERMINAL_CONFIG_COMPAT_VERSION      (1) /* Bump this for incompatible changes */
+
+#define TERMINAL_CONFIG_GROUP               "GNOME Terminal Configuration"
+#define TERMINAL_CONFIG_PROP_VERSION        "Version"
+#define TERMINAL_CONFIG_PROP_COMPAT_VERSION "CompatVersion"
+#define TERMINAL_CONFIG_PROP_WINDOWS        "Windows"
+
+#define TERMINAL_CONFIG_WINDOW_PROP_ACTIVE_TAB       "ActiveTerminal"
+#define TERMINAL_CONFIG_WINDOW_PROP_FULLSCREEN       "Fullscreen"
+#define TERMINAL_CONFIG_WINDOW_PROP_GEOMETRY         "Geometry"
+#define TERMINAL_CONFIG_WINDOW_PROP_MAXIMIZED        "Maximized"
+#define TERMINAL_CONFIG_WINDOW_PROP_MENUBAR_VISIBLE  "MenubarVisible"
+#define TERMINAL_CONFIG_WINDOW_PROP_ROLE             "Role"
+#define TERMINAL_CONFIG_WINDOW_PROP_TABS             "Terminals"
+
+#define TERMINAL_CONFIG_TERMINAL_PROP_HEIGHT             "Height"
+#define TERMINAL_CONFIG_TERMINAL_PROP_COMMAND            "Command"
+#define TERMINAL_CONFIG_TERMINAL_PROP_PROFILE_ID         "ProfileID"
+#define TERMINAL_CONFIG_TERMINAL_PROP_TITLE              "Title"
+#define TERMINAL_CONFIG_TERMINAL_PROP_WIDTH              "Width"
+#define TERMINAL_CONFIG_TERMINAL_PROP_WORKING_DIRECTORY  "WorkingDirectory"
+#define TERMINAL_CONFIG_TERMINAL_PROP_ZOOM               "Zoom"
+
 typedef struct
 {
   gboolean remote_arguments;
-  char   **env;
   char    *startup_id;
   char    *display_name;
   int      screen_number;
@@ -53,6 +76,8 @@ typedef struct
   char    *config_file;
   gboolean load_config;
   gboolean save_config;
+
+  guint zoom_set : 1;
 } TerminalOptions;
 
 typedef struct
@@ -97,7 +122,6 @@ typedef enum {
 TerminalOptions *terminal_options_parse (const char *working_directory,
                                          const char *display_name,
                                          const char *startup_id,
-                                         char **env,
                                          gboolean remote_arguments,
                                          gboolean ignore_unknown_options,
                                          int *argcp,
diff --git a/src/terminal-screen.c b/src/terminal-screen.c
index 6394284..7b3ed26 100644
--- a/src/terminal-screen.c
+++ b/src/terminal-screen.c
@@ -2077,6 +2077,8 @@ terminal_screen_check_match (TerminalScreen *screen,
   return NULL;
 }
 
+#include "terminal-options.h"
+
 void
 terminal_screen_save_config (TerminalScreen *screen,
                              GKeyFile *key_file,
diff --git a/src/terminal-util.c b/src/terminal-util.c
index 4e7d4a3..1ae2923 100644
--- a/src/terminal-util.c
+++ b/src/terminal-util.c
@@ -445,24 +445,6 @@ terminal_util_key_file_set_string_escape (GKeyFile *key_file,
   g_free (escaped);
 }
 
-char *
-terminal_util_key_file_get_string_unescape (GKeyFile *key_file,
-                                            const char *group,
-                                            const char *key,
-                                            GError **error)
-{
-  char *escaped, *unescaped;
-
-  escaped = g_key_file_get_string (key_file, group, key, error);
-  if (!escaped)
-    return NULL;
-
-  unescaped = g_strcompress (escaped);
-  g_free (escaped);
-
-  return unescaped;
-}
-
 void
 terminal_util_key_file_set_argv (GKeyFile *key_file,
                                  const char *group,
@@ -489,30 +471,6 @@ terminal_util_key_file_set_argv (GKeyFile *key_file,
   g_strfreev (quoted_argv);
 }
 
-char **
-terminal_util_key_file_get_argv (GKeyFile *key_file,
-                                 const char *group,
-                                 const char *key,
-                                 int *argc,
-                                 GError **error)
-{
-  char **argv;
-  char *flat;
-  gboolean retval;
-
-  flat = terminal_util_key_file_get_string_unescape (key_file, group, key, error);
-  if (!flat)
-    return NULL;
-
-  retval = g_shell_parse_argv (flat, argc, &argv, error);
-  g_free (flat);
-
-  if (retval)
-    return argv;
-
-  return NULL;
-}
-
 /* Proxy stuff */
 
 /*
diff --git a/src/terminal-util.h b/src/terminal-util.h
index 9604020..90f46b6 100644
--- a/src/terminal-util.h
+++ b/src/terminal-util.h
@@ -68,21 +68,11 @@ void terminal_util_key_file_set_string_escape    (GKeyFile *key_file,
                                                   const char *group,
                                                   const char *key,
                                                   const char *string);
-char *terminal_util_key_file_get_string_unescape (GKeyFile *key_file,
-                                                  const char *group,
-                                                  const char *key,
-                                                  GError **error);
-
 void terminal_util_key_file_set_argv      (GKeyFile *key_file,
                                            const char *group,
                                            const char *key,
                                            int argc,
                                            char **argv);
-char **terminal_util_key_file_get_argv    (GKeyFile *key_file,
-                                           const char *group,
-                                           const char *key,
-                                           int *argc,
-                                           GError **error);
 
 void terminal_util_add_proxy_env (GHashTable *env_table);
 
diff --git a/src/terminal-window.c b/src/terminal-window.c
index c56d2a6..511cc22 100644
--- a/src/terminal-window.c
+++ b/src/terminal-window.c
@@ -3822,6 +3822,7 @@ terminal_window_get_ui_manager (TerminalWindow *window)
   return priv->ui_manager;
 }
 
+#include "terminal-options.h"
 void
 terminal_window_save_state (TerminalWindow *window,
                             GKeyFile *key_file,
diff --git a/src/terminal.c b/src/terminal.c
index 2d8b2d3..8374e2b 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -43,6 +43,13 @@
 #include "terminal-options.h"
 #include "terminal-gdbus-generated.h"
 #include "terminal-defines.h"
+#include "terminal-client-utils.h"
+
+enum
+{
+  SOURCE_DEFAULT = 0,
+  SOURCE_SESSION = 1
+};
 
 /**
  * handle_options:
@@ -61,23 +68,23 @@
 static gboolean
 handle_options (TerminalFactory *factory,
                 TerminalOptions *options,
-                char **envv,
                 gboolean allow_resume,
                 GError **error)
 {
-#if 0
   GList *lw;
-  GdkScreen *gdk_screen;
+  GError *err;
 
+#if 0
   gdk_screen = terminal_app_get_screen_by_display_name (options->display_name,
                                                         options->screen_number);
+#endif
 
   if (options->save_config)
     {
 #if 0
       if (options->remote_arguments)
         return terminal_app_save_config_file (app, options->config_file, error);
-      
+
       g_set_error_literal (error, TERMINAL_OPTION_ERROR, TERMINAL_OPTION_ERROR_NOT_IN_FACTORY,
                             "Cannot use \"--save-config\" when starting the factory process");
       return FALSE;
@@ -124,96 +131,108 @@ handle_options (TerminalFactory *factory,
   /* Make sure we open at least one window */
   terminal_options_ensure_window (options);
 
-  if (options->startup_id != NULL)
-    _terminal_debug_print (TERMINAL_DEBUG_FACTORY,
-                           "Startup ID is '%s'\n",
-                           options->startup_id);
-
   for (lw = options->initial_windows;  lw != NULL; lw = lw->next)
     {
       InitialWindow *iw = lw->data;
       GList *lt;
-#if 0
-      TerminalWindow *window;
 
       g_assert (iw->tabs);
 
-      /* Create & setup new window */
-      window = terminal_app_new_window (app, gdk_screen);
-
-      /* Restored windows shouldn't demand attention; see bug #586308. */
-      if (iw->source_tag == SOURCE_SESSION)
-        terminal_window_set_is_restored (window);
-
-      if (options->startup_id != NULL)
-        gtk_window_set_startup_id (GTK_WINDOW (window), options->startup_id);
-
-      /* Overwrite the default, unique window role set in terminal_window_init */
-      if (iw->role)
-        gtk_window_set_role (GTK_WINDOW (window), iw->role);
-
-      if (iw->force_menubar_state)
-        terminal_window_set_menubar_visible (window, iw->menubar_state);
-
-      if (iw->start_fullscreen)
-        gtk_window_fullscreen (GTK_WINDOW (window));
-      if (iw->start_maximized)
-        gtk_window_maximize (GTK_WINDOW (window));
-#endif
-
       /* Now add the tabs */
       for (lt = iw->tabs; lt != NULL; lt = lt->next)
         {
           InitialTab *it = lt->data;
+          GVariantBuilder builder;
+          char *object_path;
+          TerminalReceiver *receiver;
+          char **argv;
+          int argc;
+
+          err = NULL;
+
+          g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
+
+          terminal_client_append_create_instance_options (&builder,
+                                                          options->display_name,
+                                                          options->startup_id,
+                                                          iw->geometry,
+                                                          iw->role,
+                                                          it->profile ? it->profile : options->default_profile,
+                                                          it->title ? it->title : options->default_title,
+                                                          iw->start_maximized,
+                                                          iw->start_fullscreen);
+
+          /* Restored windows shouldn't demand attention; see bug #586308. */
+          if (iw->source_tag == SOURCE_SESSION)
+            g_variant_builder_add (&builder, "{sv}",
+                                   "present-window", g_variant_new_boolean (FALSE));
+          if (options->zoom_set || it->zoom_set)
+            g_variant_builder_add (&builder, "{sv}",
+                                   "zoom", g_variant_new_double (it->zoom_set ? it->zoom : options->zoom));
+#if 0
+          if (iw->force_menubar_state)
+            terminal_window_set_menubar_visible (window, iw->menubar_state);
+#endif
 #if 0
-          GSettings *profile = NULL;
-          TerminalScreen *screen;
-
-          if (it->profile)
-            {
-              if (it->profile_is_id)
-                profile = terminal_app_get_profile_by_name (app, it->profile);
-              else
-                profile = terminal_app_get_profile_by_visible_name (app, it->profile);
-
-              if (profile == NULL)
-                g_printerr (_("No such profile \"%s\", using default profile\n"), it->profile);
-            }
-          if (profile == NULL)
-            profile = g_object_ref (g_hash_table_lookup (app->profiles, "profile0"));
-          g_assert (profile);
-
-          screen = terminal_app_new_terminal (app, window, profile,
-                                              it->exec_argv ? it->exec_argv : options->exec_argv,
-                                              it->title ? it->title : options->default_title,
-                                              it->working_dir ? it->working_dir : options->default_working_dir,
-                                              options->env,
-                                              it->zoom_set ? it->zoom : options->zoom);
-          g_object_unref (profile);
-
           if (it->active)
             terminal_window_switch_screen (window, screen);
 #endif
-        }
 
-#if 0
-      if (iw->geometry)
-        {
-          _terminal_debug_print (TERMINAL_DEBUG_GEOMETRY,
-                                "[window %p] applying geometry %s\n",
-                                window, iw->geometry);
+          if (!terminal_factory_call_create_instance_sync 
+                 (factory,
+                  g_variant_builder_end (&builder),
+                  &object_path,
+                  NULL /* cancellable */,
+                  &err)) {
+            g_printerr ("Error creating terminal: %s\n", err->message);
+            g_error_free (err);
+
+            /* Continue processing the remaining options! */
+            continue;
+          }
+
+          receiver = terminal_receiver_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+                                                               G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
+                                                               G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
+                                                               TERMINAL_UNIQUE_NAME,
+                                                               object_path,
+                                                               NULL /* cancellable */,
+                                                               &err);
+          if (receiver == NULL) {
+            g_printerr ("Failed to create proxy for terminal: %s\n", err->message);
+            g_error_free (err);
+            g_free (object_path);
+
+            /* Continue processing the remaining options! */
+            continue;
+          }
+          g_free (object_path);
+
+          g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
+
+          terminal_client_append_exec_options (&builder,
+                                               it->working_dir ? it->working_dir 
+                                                               : options->default_working_dir);
+
+          argv = it->exec_argv ? it->exec_argv : options->exec_argv,
+          argc = argv ? g_strv_length (argv) : 0;
+
+          if (!terminal_receiver_call_exec_sync (receiver,
+                                                 g_variant_builder_end (&builder),
+                                                 g_variant_new_bytestring_array ((const char * const *) argv, argc),
+                                                NULL /* cancellable */,
+                                                &err)) {
+            g_printerr ("Error: %s\n", err->message);
+            g_error_free (err);
+
+            /* Continue processing the remaining options! */
+            continue;
+          }
 
-          if (!terminal_window_parse_geometry (window, iw->geometry))
-            g_printerr (_("Invalid geometry string \"%s\"\n"), iw->geometry);
         }
-
-      gtk_window_present (GTK_WINDOW (window));
-#endif
     }
 
   return TRUE;
-#endif
-  return FALSE;
 }
 
 /* Copied from libnautilus/nautilus-program-choosing.c; Needed in case
@@ -271,7 +290,7 @@ int
 main (int argc, char **argv)
 {
   int i;
-  char **argv_copy, **envv;
+  char **argv_copy;
   const char *startup_id, *display_name;
   GdkDisplay *display;
   TerminalOptions *options;
@@ -302,7 +321,6 @@ main (int argc, char **argv)
   options = terminal_options_parse (working_directory,
                                     NULL,
                                     startup_id,
-                                    NULL,
                                     FALSE,
                                     FALSE,
                                     &argc, &argv,
@@ -360,27 +378,12 @@ main (int argc, char **argv)
     goto out;
   }
 
-  envv = g_get_environ ();
-#if 0
-  if (!terminal_factory_call_handle_arguments_sync (factory,
-                                                    working_directory ? working_directory : "",
-                                                    display_name ? display_name : "",
-                                                    startup_id ? startup_id : "",
-                                                    (const char * const *) envv,
-                                                    (const char * const *) argv_copy,
-                                                    NULL /* cancellable */,
-                                                    &error)) {
-    g_printerr ("Error opening terminal: %s\n", error->message);
-    g_error_free (error);
-  } else {
-#endif
-  if (!handle_options (factory, options, envv, TRUE /* allow resume */, &error)) {
+  if (!handle_options (factory, options, TRUE /* allow resume */, &error)) {
     g_printerr ("Failed to handle arguments: %s\n", error->message);
   } else {
     exit_code = EXIT_SUCCESS;
   }
 
-  g_strfreev (envv);
   g_object_unref (factory);
 
 out:



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