[gnome-terminal] Move common client code to terminal-client-utils.[ch]
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-terminal] Move common client code to terminal-client-utils.[ch]
- Date: Thu, 3 May 2012 19:03:35 +0000 (UTC)
commit b236ea5dd121b6d3374c19cb656592a691d8b689
Author: Christian Persch <chpe gnome org>
Date: Thu Nov 24 18:58:45 2011 +0100
Move common client code to terminal-client-utils.[ch]
This code will be used by gnome-terminal-client and the legacy
gnome-terminal command.
src/Makefile.am | 4 ++
src/client.c | 74 +++++------------------------
src/terminal-app.c | 43 ++++++++++-------
src/terminal-client-utils.c | 108 +++++++++++++++++++++++++++++++++++++++++++
src/terminal-client-utils.h | 42 +++++++++++++++++
5 files changed, 193 insertions(+), 78 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 76805b4..5fd5aee 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -159,6 +159,8 @@ terminal-gdbus-generated.c terminal-gdbus-generated.h: org.gnome.Terminal.xml Ma
gnome_terminal_client_SOURCES = \
client.c \
+ terminal-client-utils.c \
+ terminal-client-utils.h \
terminal-defines.h \
terminal-intl.h \
$(NULL)
@@ -192,6 +194,8 @@ gnome_terminal_client_LDADD = \
gnome_terminal_SOURCES = \
terminal.c \
+ terminal-client-utils.c \
+ terminal-client-utils.h \
terminal-debug.c \
terminal-debug.h \
terminal-defines.h \
diff --git a/src/client.c b/src/client.c
index 9e195e3..d763031 100644
--- a/src/client.c
+++ b/src/client.c
@@ -40,6 +40,7 @@
#include "terminal-intl.h"
#include "terminal-gdbus-generated.h"
#include "terminal-defines.h"
+#include "terminal-client-utils.h"
/* ---------------------------------------------------------------------------------------------------- */
@@ -280,7 +281,7 @@ get_goption_context (OptionData *data)
N_("PROFILE-NAME") },
{ "title", 0, 0, G_OPTION_ARG_STRING, &data->title,
N_("Set the terminal title"), N_("TITLE") },
- { "cwd", 0, 0, G_OPTION_ARG_STRING, &data->working_directory,
+ { "cwd", 0, 0, G_OPTION_ARG_FILENAME, &data->working_directory,
N_("Set the working directory"), N_("DIRNAME") },
{ "zoom", 0, 0, G_OPTION_ARG_CALLBACK, option_zoom_cb,
N_("Set the terminal's zoom factor (1.0 = normal size)"),
@@ -401,11 +402,6 @@ parse_arguments (int *argcp,
return data;
}
-/**
- * build_create_options_variant:
- *
- * Returns: a floating #GVariant
- */
static GVariant *
build_create_options_variant (OptionData *data)
{
@@ -413,24 +409,15 @@ build_create_options_variant (OptionData *data)
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
- g_variant_builder_add (&builder, "{sv}",
- "display", g_variant_new_bytestring (data->display_name));
-
- if (data->startup_id)
- g_variant_builder_add (&builder, "{sv}",
- "desktop-startup-id", g_variant_new_bytestring (data->startup_id));
- if (data->geometry)
- g_variant_builder_add (&builder, "{sv}",
- "geometry", g_variant_new_string (data->geometry));
- if (data->role)
- g_variant_builder_add (&builder, "{sv}",
- "role", g_variant_new_string (data->role));
- if (data->start_maximized)
- g_variant_builder_add (&builder, "{sv}",
- "maximize-window", g_variant_new_boolean (TRUE));
- if (data->start_fullscreen)
- g_variant_builder_add (&builder, "{sv}",
- "fullscreen-window", g_variant_new_boolean (TRUE));
+ terminal_client_append_create_instance_options (&builder,
+ data->display_name,
+ data->startup_id,
+ data->geometry,
+ data->role,
+ data->profile,
+ data->title,
+ data->start_maximized,
+ data->start_fullscreen);
return g_variant_builder_end (&builder);
}
@@ -444,46 +431,11 @@ static GVariant *
build_exec_options_variant (OptionData *data)
{
GVariantBuilder builder;
- char **envv;
- const char *pwd, *working_directory;
- char path[PATH_MAX];
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
- envv = g_get_environ ();
- envv = g_environ_unsetenv (envv, "DESKTOP_STARTUP_ID");
- envv = g_environ_unsetenv (envv, "GIO_LAUNCHED_DESKTOP_FILE_PID");
- envv = g_environ_unsetenv (envv, "GIO_LAUNCHED_DESKTOP_FILE");
-
- g_variant_builder_add (&builder, "{sv}",
- "environ",
- g_variant_new_bytestring_array ((const char * const *) envv, -1));
-
- /* If $PWD points to the CWD, transmit $PWD instead so as
- * not follow symlinks! See bug #502146.
- */
- pwd = g_environ_getenv (envv, "PWD");
- if (pwd) {
- char *s;
- GError *err = NULL;
- if ((s = g_file_read_link (pwd, &err)) == NULL)
- g_print ("Failed to readlink %s: %s\n", pwd, err->message);
- else
- g_print ("Resolved: %s\n", s);
- }
- if (pwd != NULL && data->working_directory != NULL &&
- readlink (pwd, path, sizeof (path)) != -1) {
- working_directory = pwd;
- } else {
- working_directory = data->working_directory;
- }
-
- g_print ("Transmit pwd = %s (working_directory %s)\n", working_directory, data->working_directory);
-
- g_variant_builder_add (&builder, "{sv}",
- "cwd", g_variant_new_bytestring (working_directory));
-
- g_strfreev (envv);
+ terminal_client_append_exec_options (&builder,
+ data->working_directory);
return g_variant_builder_end (&builder);
}
diff --git a/src/terminal-app.c b/src/terminal-app.c
index e3afbc4..4e6b67e 100644
--- a/src/terminal-app.c
+++ b/src/terminal-app.c
@@ -1158,18 +1158,15 @@ terminal_app_create_instance (TerminalFactory *factory,
GSettings *profile = NULL;
GdkScreen *gdk_screen;
const char *startup_id, *display_name;
+ char *role, *geometry, *profile_name, *title;
int screen_number;
- gboolean is_restored = FALSE;
- gboolean start_fullscreen = FALSE;
- gboolean start_maximized = FALSE;
- gboolean force_menubar_state = FALSE, menubar_state = TRUE;
- char *role = NULL;
- char *title = NULL;
- char *profile_name = NULL;
+ gboolean start_maximized, start_fullscreen;
+ gboolean present_window, present_window_set = FALSE;
gboolean zoom_set = FALSE;
gdouble zoom = 1.0;
+
+ gboolean menubar_state = TRUE, menubar_state_set = FALSE;
gboolean active = TRUE;
- char *geometry = NULL;
if (!g_variant_lookup (options, "display", "^&ay", &display_name)) {
g_dbus_method_invocation_return_error (invocation,
@@ -1190,18 +1187,30 @@ terminal_app_create_instance (TerminalFactory *factory,
if (!g_variant_lookup (options, "desktop-startup-id", "^&ay", &startup_id))
startup_id = NULL;
-
- if (startup_id != NULL)
- _terminal_debug_print (TERMINAL_DEBUG_FACTORY,
- "Startup ID is '%s'\n", startup_id);
-
- if (!g_variant_lookup (options, "zoom", "d", &zoom))
- zoom_set = FALSE;
+ if (!g_variant_lookup (options, "geometry", "&s", &geometry))
+ geometry = NULL;
+ if (!g_variant_lookup (options, "role", "&s", &role))
+ role = NULL;
+ if (!g_variant_lookup (options, "maximize-window", "b", &start_maximized))
+ start_maximized = FALSE;
+ if (!g_variant_lookup (options, "fullscreen-window", "b", &start_fullscreen))
+ start_fullscreen = FALSE;
+ if (!g_variant_lookup (options, "profile", "&s", &profile_name))
+ profile_name = NULL;
+ if (!g_variant_lookup (options, "title", "&s", &title))
+ profile_name = NULL;
+
+ if (g_variant_lookup (options, "present-window", "b", &present_window)) {
+ present_window_set = TRUE;
+ }
+ if (g_variant_lookup (options, "zoom", "d", &zoom)) {
+ zoom_set = TRUE;
+ }
window = terminal_app_new_window (app, gdk_screen);
/* Restored windows shouldn't demand attention; see bug #586308. */
- if (is_restored)
+ if (present_window_set && !present_window)
terminal_window_set_is_restored (window);
if (startup_id != NULL)
@@ -1211,7 +1220,7 @@ terminal_app_create_instance (TerminalFactory *factory,
if (role)
gtk_window_set_role (GTK_WINDOW (window), role);
- if (force_menubar_state)
+ if (menubar_state_set)
terminal_window_set_menubar_visible (window, menubar_state);
if (start_fullscreen)
diff --git a/src/terminal-client-utils.c b/src/terminal-client-utils.c
new file mode 100644
index 0000000..800b7cf
--- /dev/null
+++ b/src/terminal-client-utils.c
@@ -0,0 +1,108 @@
+/*
+ * Copyright  2011 Christian Persch
+ *
+ * This programme is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This programme is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this programme; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include "terminal-client-utils.h"
+
+#include <gio/gio.h>
+
+/**
+ * terminal_client_append_create_instance_options:
+ * @builder: a #GVariantBuilder of #GVariantType "a{sv}"
+ * @display: (array element-type=guint8):
+ * @startup_id: (array element-type=guint8):
+ * @geometry:
+ * @role:
+ * @profile:
+ * @title:
+ * @maximise_window:
+ * @fullscreen_window:
+ *
+ * Appends common options to @builder.
+ */
+void
+terminal_client_append_create_instance_options (GVariantBuilder *builder,
+ const char *display_name,
+ const char *startup_id,
+ const char *geometry,
+ const char *role,
+ const char *profile,
+ const char *title,
+ gboolean maximise_window,
+ gboolean fullscreen_window)
+{
+ /* Bytestring options */
+ g_variant_builder_add (builder, "{sv}",
+ "display", g_variant_new_bytestring (display_name));
+ if (startup_id)
+ 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}",
+ "profile", g_variant_new_string (profile));
+ if (title)
+ g_variant_builder_add (builder, "{sv}",
+ "title", g_variant_new_string (title));
+ if (geometry)
+ g_variant_builder_add (builder, "{sv}",
+ "geometry", g_variant_new_string (geometry));
+ if (role)
+ g_variant_builder_add (builder, "{sv}",
+ "role", g_variant_new_string (role));
+
+ /* Boolean options */
+ if (maximise_window)
+ g_variant_builder_add (builder, "{sv}",
+ "maximize-window", g_variant_new_boolean (TRUE));
+ if (fullscreen_window)
+ g_variant_builder_add (builder, "{sv}",
+ "fullscreen-window", g_variant_new_boolean (TRUE));
+}
+
+/**
+ * terminal_client_append_exec_options:
+ * @builder: a #GVariantBuilder of #GVariantType "a{sv}"
+ * @working_directory: (allow-none): the cwd, or %NULL
+ *
+ * Appends the environment and the working directory to @builder.
+ */
+void
+terminal_client_append_exec_options (GVariantBuilder *builder,
+ const char *working_directory)
+{
+ char **envv;
+
+ envv = g_get_environ ();
+ envv = g_environ_unsetenv (envv, "DESKTOP_STARTUP_ID");
+ envv = g_environ_unsetenv (envv, "GIO_LAUNCHED_DESKTOP_FILE_PID");
+ envv = g_environ_unsetenv (envv, "GIO_LAUNCHED_DESKTOP_FILE");
+
+ g_variant_builder_add (builder, "{sv}",
+ "environ",
+ g_variant_new_bytestring_array ((const char * const *) envv, -1));
+
+ if (working_directory)
+ g_variant_builder_add (builder, "{sv}",
+ "cwd", g_variant_new_bytestring (working_directory));
+
+ g_strfreev (envv);
+}
diff --git a/src/terminal-client-utils.h b/src/terminal-client-utils.h
new file mode 100644
index 0000000..d7c95d9
--- /dev/null
+++ b/src/terminal-client-utils.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright  2011 Christian Persch
+ *
+ * This programme is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This programme is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this programme; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef TERMINAL_CLIENT_UTILS_H
+#define TERMINAL_CLIENT_UTILS_H
+
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+void terminal_client_append_create_instance_options (GVariantBuilder *builder,
+ const char *display_name,
+ const char *startup_id,
+ const char *geometry,
+ const char *role,
+ const char *profile,
+ const char *title,
+ gboolean maximise_window,
+ gboolean fullscreen_window);
+
+void terminal_client_append_exec_options (GVariantBuilder *builder,
+ const char *working_directory);
+
+G_END_DECLS
+
+#endif /* TERMINAL_UTIL_UTILS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]