gnome-terminal r3129 - trunk/src
- From: chpe svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-terminal r3129 - trunk/src
- Date: Tue, 7 Oct 2008 14:30:40 +0000 (UTC)
Author: chpe
Date: Tue Oct 7 14:30:40 2008
New Revision: 3129
URL: http://svn.gnome.org/viewvc/gnome-terminal?rev=3129&view=rev
Log:
Split off options parsing into terminal-options.[ch].
Added:
trunk/src/terminal-options.c
trunk/src/terminal-options.h
Modified:
trunk/src/Makefile.am
trunk/src/terminal.c
Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Tue Oct 7 14:30:40 2008
@@ -23,6 +23,8 @@
terminal-intl.h \
terminal-marshal.c \
terminal-marshal.h \
+ terminal-options.c \
+ terminal-options.h \
terminal-profile.c \
terminal-profile.h \
terminal-screen.c \
Added: trunk/src/terminal-options.c
==============================================================================
--- (empty file)
+++ trunk/src/terminal-options.c Tue Oct 7 14:30:40 2008
@@ -0,0 +1,1268 @@
+/*
+ * Copyright  2001, 2002 Havoc Pennington
+ * Copyright  2002 Red Hat, Inc.
+ * Copyright  2002 Sun Microsystems
+ * Copyright  2003 Mariano Suarez-Alvarez
+ * Copyright  2008 Christian Persch
+ *
+ * Gnome-terminal 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Gnome-terminal 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 program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <glib.h>
+
+#include "terminal-options.h"
+#include "terminal-intl.h"
+
+static InitialTab*
+initial_tab_new (const char *profile,
+ gboolean is_id)
+{
+ InitialTab *it;
+
+ it = g_slice_new (InitialTab);
+
+ it->profile = g_strdup (profile);
+ it->profile_is_id = is_id;
+ it->exec_argv = NULL;
+ it->title = NULL;
+ it->working_dir = NULL;
+ it->zoom = 1.0;
+ it->zoom_set = FALSE;
+ it->active = FALSE;
+
+ return it;
+}
+
+static void
+initial_tab_free (InitialTab *it)
+{
+ g_free (it->profile);
+ g_strfreev (it->exec_argv);
+ g_free (it->title);
+ g_free (it->working_dir);
+ g_slice_free (InitialTab, it);
+}
+
+static InitialWindow*
+initial_window_new (const char *profile,
+ gboolean is_id)
+{
+ InitialWindow *iw;
+
+ iw = g_slice_new (InitialWindow);
+
+ iw->tabs = g_list_prepend (NULL, initial_tab_new (profile, is_id));
+ iw->force_menubar_state = FALSE;
+ iw->menubar_state = FALSE;
+ iw->start_fullscreen = FALSE;
+ iw->start_maximized = FALSE;
+ iw->geometry = NULL;
+ iw->role = NULL;
+
+ return iw;
+}
+
+static void
+initial_window_free (InitialWindow *iw)
+{
+ g_list_foreach (iw->tabs, (GFunc) initial_tab_free, NULL);
+ g_list_free (iw->tabs);
+ g_free (iw->geometry);
+ g_free (iw->role);
+ g_slice_free (InitialWindow, iw);
+}
+
+static void
+apply_defaults (OptionParsingResults *results,
+ InitialWindow *iw)
+{
+ if (results->default_role)
+ {
+ iw->role = results->default_role;
+ results->default_role = NULL;
+ }
+
+ if (iw->geometry == NULL)
+ iw->geometry = g_strdup (results->default_geometry);
+
+ if (results->default_window_menubar_forced)
+ {
+ iw->force_menubar_state = TRUE;
+ iw->menubar_state = results->default_window_menubar_state;
+
+ results->default_window_menubar_forced = FALSE;
+ }
+
+ iw->start_fullscreen |= results->default_fullscreen;
+ iw->start_maximized |= results->default_maximize;
+}
+
+static InitialWindow*
+ensure_top_window (OptionParsingResults *results)
+{
+ InitialWindow *iw;
+
+ if (results->initial_windows == NULL)
+ {
+ iw = initial_window_new (NULL, FALSE);
+ apply_defaults (results, iw);
+
+ results->initial_windows = g_list_append (results->initial_windows,
+ iw);
+ }
+ else
+ {
+ iw = g_list_last (results->initial_windows)->data;
+ }
+
+ g_assert (iw->tabs);
+
+ return iw;
+}
+
+static InitialTab*
+ensure_top_tab (OptionParsingResults *results)
+{
+ InitialWindow *iw;
+ InitialTab *it;
+
+ iw = ensure_top_window (results);
+
+ g_assert (iw->tabs);
+
+ it = g_list_last (iw->tabs)->data;
+
+ return it;
+}
+
+static InitialWindow*
+add_new_window (OptionParsingResults *results,
+ const char *profile,
+ gboolean is_id)
+{
+ InitialWindow *iw;
+
+ iw = initial_window_new (profile, is_id);
+
+ apply_defaults (results, iw);
+
+ results->initial_windows = g_list_append (results->initial_windows, iw);
+
+ return iw;
+}
+
+/* handle deprecated command line options */
+static gboolean
+unsupported_option_callback (const gchar *option_name,
+ const gchar *value,
+ gpointer data,
+ GError **error)
+{
+ g_printerr (_("Option \"%s\" is no longer supported in this version of gnome-terminal;"
+ " you might want to create a profile with the desired setting, and use"
+ " the new '--window-with-profile' option\n"), option_name);
+ return TRUE; /* we do not want to bail out here but continue */
+}
+
+
+static gboolean
+option_version_cb (const gchar *option_name,
+ const gchar *value,
+ gpointer data,
+ GError **error)
+{
+ g_print ("%s %s\n", _("GNOME Terminal"), VERSION);
+
+ exit (EXIT_SUCCESS);
+ return FALSE;
+}
+
+static gboolean
+option_command_callback (const gchar *option_name,
+ const gchar *value,
+ gpointer data,
+ GError **error)
+{
+ OptionParsingResults *results = data;
+ GError *err = NULL;
+ char **exec_argv;
+
+ if (!g_shell_parse_argv (value, NULL, &exec_argv, &err))
+ {
+ g_set_error(error,
+ G_OPTION_ERROR,
+ G_OPTION_ERROR_BAD_VALUE,
+ _("Argument to \"%s\" is not a valid command: %s"),
+ "--command/-e",
+ err->message);
+ g_error_free (err);
+ return FALSE;
+ }
+
+ if (results->initial_windows)
+ {
+ InitialTab *it = ensure_top_tab (results);
+
+ g_strfreev (it->exec_argv);
+ it->exec_argv = exec_argv;
+ }
+ else
+ {
+ g_strfreev (results->exec_argv);
+ results->exec_argv = exec_argv;
+ }
+
+ return TRUE;
+}
+
+static gboolean
+option_profile_cb (const gchar *option_name,
+ const gchar *value,
+ gpointer data,
+ GError **error)
+{
+ OptionParsingResults *results = data;
+
+ if (results->initial_windows)
+ {
+ InitialTab *it = ensure_top_tab (results);
+
+ g_free (it->profile);
+ it->profile = g_strdup (value);
+ it->profile_is_id = FALSE;
+ }
+ else
+ {
+ g_free (results->default_profile);
+ results->default_profile = g_strdup (value);
+ results->default_profile_is_id = FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean
+option_profile_id_cb (const gchar *option_name,
+ const gchar *value,
+ gpointer data,
+ GError **error)
+{
+ OptionParsingResults *results = data;
+
+ if (results->initial_windows)
+ {
+ InitialTab *it = ensure_top_tab (results);
+
+ g_free (it->profile);
+ it->profile = g_strdup (value);
+ it->profile_is_id = TRUE;
+ }
+ else
+ {
+ g_free (results->default_profile);
+ results->default_profile = g_strdup (value);
+ results->default_profile_is_id = TRUE;
+ }
+
+ return TRUE;
+}
+
+
+static gboolean
+option_window_callback (const gchar *option_name,
+ const gchar *value,
+ gpointer data,
+ GError **error)
+{
+ OptionParsingResults *results = data;
+ gboolean is_profile_id;
+
+ is_profile_id = g_str_has_suffix (option_name, "-with-profile-internal-id");
+
+ add_new_window (results, value, is_profile_id);
+
+ return TRUE;
+}
+
+static gboolean
+option_tab_callback (const gchar *option_name,
+ const gchar *value,
+ gpointer data,
+ GError **error)
+{
+ OptionParsingResults *results = data;
+ gboolean is_profile_id;
+
+ is_profile_id = g_str_has_suffix (option_name, "-with-profile-internal-id");
+
+ if (results->initial_windows)
+ {
+ InitialWindow *iw;
+
+ iw = g_list_last (results->initial_windows)->data;
+ iw->tabs = g_list_append (iw->tabs, initial_tab_new (value, is_profile_id));
+ }
+ else
+ add_new_window (results, value, is_profile_id);
+
+ return TRUE;
+}
+
+static gboolean
+option_role_callback (const gchar *option_name,
+ const gchar *value,
+ gpointer data,
+ GError **error)
+{
+ OptionParsingResults *results = data;
+ InitialWindow *iw;
+
+ if (results->initial_windows)
+ {
+ iw = g_list_last (results->initial_windows)->data;
+ iw->role = g_strdup (value);
+ }
+ else if (!results->default_role)
+ results->default_role = g_strdup (value);
+ else
+ {
+ g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
+ "%s", _("Two roles given for one window"));
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean
+option_show_menubar_callback (const gchar *option_name,
+ const gchar *value,
+ gpointer data,
+ GError **error)
+{
+ OptionParsingResults *results = data;
+ InitialWindow *iw;
+
+ if (results->initial_windows)
+ {
+ iw = g_list_last (results->initial_windows)->data;
+ if (iw->force_menubar_state && iw->menubar_state == TRUE)
+ {
+ g_printerr (_("\"%s\" option given twice for the same window\n"),
+ "--show-menubar");
+
+ return TRUE;
+ }
+
+ iw->force_menubar_state = TRUE;
+ iw->menubar_state = TRUE;
+ }
+ else
+ {
+ results->default_window_menubar_forced = TRUE;
+ results->default_window_menubar_state = TRUE;
+ }
+
+ return TRUE;
+}
+
+static gboolean
+option_hide_menubar_callback (const gchar *option_name,
+ const gchar *value,
+ gpointer data,
+ GError **error)
+{
+ OptionParsingResults *results = data;
+ InitialWindow *iw;
+
+ if (results->initial_windows)
+ {
+ iw = g_list_last (results->initial_windows)->data;
+
+ if (iw->force_menubar_state && iw->menubar_state == FALSE)
+ {
+ g_printerr (_("\"%s\" option given twice for the same window\n"),
+ "--hide-menubar");
+ return TRUE;
+ }
+
+ iw->force_menubar_state = TRUE;
+ iw->menubar_state = FALSE;
+ }
+ else
+ {
+ results->default_window_menubar_forced = TRUE;
+ results->default_window_menubar_state = FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean
+option_maximize_callback (const gchar *option_name,
+ const gchar *value,
+ gpointer data,
+ GError **error)
+{
+ OptionParsingResults *results = data;
+ InitialWindow *iw;
+
+ if (results->initial_windows)
+ {
+ iw = g_list_last (results->initial_windows)->data;
+ iw->start_maximized = TRUE;
+ }
+ else
+ results->default_maximize = TRUE;
+
+ return TRUE;
+}
+
+static gboolean
+option_fullscreen_callback (const gchar *option_name,
+ const gchar *value,
+ gpointer data,
+ GError **error)
+{
+ OptionParsingResults *results = data;
+
+ if (results->initial_windows)
+ {
+ InitialWindow *iw;
+
+ iw = g_list_last (results->initial_windows)->data;
+ iw->start_fullscreen = TRUE;
+ }
+ else
+ results->default_fullscreen = TRUE;
+
+ return TRUE;
+}
+
+static gboolean
+option_geometry_callback (const gchar *option_name,
+ const gchar *value,
+ gpointer data,
+ GError **error)
+{
+ OptionParsingResults *results = data;
+
+ if (results->initial_windows)
+ {
+ InitialWindow *iw;
+
+ iw = g_list_last (results->initial_windows)->data;
+ iw->geometry = g_strdup (value);
+ }
+ else
+ results->default_geometry = g_strdup (value);
+
+ return TRUE;
+}
+
+static gboolean
+option_disable_factory_callback (const gchar *option_name,
+ const gchar *value,
+ gpointer data,
+ GError **error)
+{
+ OptionParsingResults *results = data;
+
+ results->use_factory = FALSE;
+
+ return TRUE;
+}
+
+static gboolean
+option_title_callback (const gchar *option_name,
+ const gchar *value,
+ gpointer data,
+ GError **error)
+{
+ OptionParsingResults *results = data;
+
+ if (results->initial_windows)
+ {
+ InitialTab *it = ensure_top_tab (results);
+
+ g_free (it->title);
+ it->title = g_strdup (value);
+ }
+ else
+ {
+ g_free (results->default_title);
+ results->default_title = g_strdup (value);
+ }
+
+ return TRUE;
+}
+
+static gboolean
+option_working_directory_callback (const gchar *option_name,
+ const gchar *value,
+ gpointer data,
+ GError **error)
+{
+ OptionParsingResults *results = data;
+
+ if (results->initial_windows)
+ {
+ InitialTab *it = ensure_top_tab (results);
+
+ g_free (it->working_dir);
+ it->working_dir = g_strdup (value);
+ }
+ else
+ {
+ g_free (results->default_working_dir);
+ results->default_working_dir = g_strdup (value);
+ }
+
+ return TRUE;
+}
+
+static gboolean
+option_active_callback (const gchar *option_name,
+ const gchar *value,
+ gpointer data,
+ GError **error)
+{
+ OptionParsingResults *results = data;
+ InitialTab *it;
+
+ it = ensure_top_tab (results);
+ it->active = TRUE;
+
+ return TRUE;
+}
+
+static gboolean
+option_zoom_callback (const gchar *option_name,
+ const gchar *value,
+ gpointer data,
+ GError **error)
+{
+ OptionParsingResults *results = data;
+ double zoom;
+ char *end;
+
+ /* Try reading a locale-style double first, in case it was
+ * typed by a person, then fall back to ascii_strtod (we
+ * always save session in C locale format)
+ */
+ end = NULL;
+ errno = 0;
+ zoom = g_strtod (value, &end);
+ if (end == NULL || *end != '\0')
+ {
+ g_set_error (error,
+ G_OPTION_ERROR,
+ G_OPTION_ERROR_BAD_VALUE,
+ _("\"%s\" is not a valid zoom factor"),
+ value);
+ return FALSE;
+ }
+
+ if (zoom < (TERMINAL_SCALE_MINIMUM + 1e-6))
+ {
+ g_printerr (_("Zoom factor \"%g\" is too small, using %g\n"),
+ zoom,
+ TERMINAL_SCALE_MINIMUM);
+ zoom = TERMINAL_SCALE_MINIMUM;
+ }
+
+ if (zoom > (TERMINAL_SCALE_MAXIMUM - 1e-6))
+ {
+ g_printerr (_("Zoom factor \"%g\" is too large, using %g\n"),
+ zoom,
+ TERMINAL_SCALE_MAXIMUM);
+ zoom = TERMINAL_SCALE_MAXIMUM;
+ }
+
+ if (results->initial_windows)
+ {
+ InitialTab *it = ensure_top_tab (results);
+ it->zoom = zoom;
+ it->zoom_set = TRUE;
+ }
+ else
+ results->zoom = zoom;
+
+ return TRUE;
+}
+
+/* Evaluation of the arguments given to the command line options */
+static gboolean
+digest_options_callback (GOptionContext *context,
+ GOptionGroup *group,
+ gpointer data,
+ GError **error)
+{
+ OptionParsingResults *results = data;
+ InitialTab *it;
+
+ /* make sure we have some window in case no options were given */
+ if (results->initial_windows == NULL)
+ it = ensure_top_tab (results);
+
+ if (results->execute)
+ {
+ if (results->exec_argv == NULL)
+ {
+ g_set_error (error,
+ G_OPTION_ERROR,
+ G_OPTION_ERROR_BAD_VALUE,
+ _("Option \"%s\" requires specifying the command to run"
+ " on the rest of the command line"),
+ "--execute/-x");
+ return FALSE;
+ }
+
+ /* Apply -x/--execute command only to the first tab */
+ it = ensure_top_tab (results);
+ it->exec_argv = results->exec_argv;
+ results->exec_argv = NULL;
+ }
+
+ return TRUE;
+}
+
+OptionParsingResults *
+option_parsing_results_new (const char *working_directory,
+ const char *display_name,
+ const char *startup_id,
+ const char **env,
+ int *argc,
+ char **argv)
+{
+ OptionParsingResults *results;
+ int i;
+
+ results = g_slice_new0 (OptionParsingResults);
+
+ results->default_window_menubar_forced = FALSE;
+ results->default_window_menubar_state = TRUE;
+ results->default_fullscreen = FALSE;
+ results->default_maximize = FALSE;
+ results->execute = FALSE;
+ results->use_factory = TRUE;
+
+ results->env = g_strdupv ((char **) env);
+ results->startup_id = g_strdup (startup_id);
+ results->display_name = g_strdup (display_name);
+ results->initial_windows = NULL;
+ results->default_role = NULL;
+ results->default_geometry = NULL;
+ results->default_title = NULL;
+ results->zoom = 1.0;
+
+ results->screen_number = -1;
+ results->default_working_dir = g_strdup (working_directory);
+
+ /* The old -x/--execute option is broken, so we need to pre-scan for it. */
+ /* We now also support passing the command after the -- switch. */
+ results->exec_argv = NULL;
+ for (i = 1 ; i < *argc; ++i)
+ {
+ gboolean is_execute;
+ gboolean is_dashdash;
+ int j, last;
+
+ is_execute = strcmp (argv[i], "-x") == 0 || strcmp (argv[i], "--execute") == 0;
+ is_dashdash = strcmp (argv[i], "--") == 0;
+
+ if (!is_execute && !is_dashdash)
+ continue;
+
+ results->execute = is_execute;
+
+ /* Skip the switch */
+ last = i;
+ ++i;
+ if (i == *argc)
+ break; /* we'll complain about this later for -x/--execute; it's fine for -- */
+
+ /* Collect the args, and remove them from argv */
+ results->exec_argv = g_new0 (char*, *argc - i + 1);
+ for (j = 0; i < *argc; ++i, ++j)
+ results->exec_argv[j] = g_strdup (argv[i]);
+ results->exec_argv[j] = NULL;
+
+ *argc = last;
+ break;
+ }
+
+ return results;
+}
+
+void
+option_parsing_results_free (OptionParsingResults *results)
+{
+ g_list_foreach (results->initial_windows, (GFunc) initial_window_free, NULL);
+ g_list_free (results->initial_windows);
+
+ g_strfreev (results->env);
+ g_free (results->default_role);
+ g_free (results->default_geometry);
+ g_free (results->default_working_dir);
+ g_free (results->default_title);
+ g_free (results->default_profile);
+
+ g_strfreev (results->exec_argv);
+
+ g_free (results->display_name);
+ g_free (results->startup_id);
+
+ g_slice_free (OptionParsingResults, results);
+}
+
+void
+option_parsing_results_check_for_display_name (OptionParsingResults *results,
+ int *argc, char **argv)
+{
+ int i;
+
+ /* The point here is to strip --display, in the case where we
+ * aren't going via gtk_init()
+ */
+ i = 1;
+ while (i < *argc)
+ {
+ gboolean remove_two = FALSE;
+
+ if (strcmp (argv[i], "-x") == 0 ||
+ strcmp (argv[i], "--execute") == 0)
+ {
+ return; /* We can't have --display or --screen past here,
+ * unless intended for the child process.
+ */
+ }
+ else if (strcmp (argv[i], "--display") == 0)
+ {
+ if ((i + 1) >= *argc)
+ {
+ g_printerr (_("No argument given to \"%s\" option\n"), "--display");
+ return; /* option parsing will die on this later, plus it shouldn't happen
+ * because normally gtk_init() parses --display
+ * when not using factory mode.
+ */
+ }
+
+ g_assert (i+1 < *argc);
+ g_free (results->display_name);
+ results->display_name = g_strdup (argv[i+1]);
+
+ remove_two = TRUE;
+ }
+ else if (strcmp (argv[i], "--screen") == 0)
+ {
+ int n;
+ char *end;
+
+ if ((i + 1) >= *argc)
+ {
+ g_printerr (_("\"%s\" option requires an argument\n"), "--screen");
+ return; /* popt will die on this later, plus it shouldn't happen
+ * because normally gtk_init() parses --display
+ * when not using factory mode.
+ */
+ }
+
+ g_assert (i+1 < *argc);
+
+ errno = 0;
+ end = NULL;
+ n = g_ascii_strtoll (argv[i+1], &end, 0);
+ if (errno == 0 && argv[i+1] != end)
+ results->screen_number = n;
+
+ remove_two = TRUE;
+ }
+
+ if (remove_two)
+ {
+ int n_to_move;
+
+ n_to_move = *argc - i - 2;
+ g_assert (n_to_move >= 0);
+
+ if (n_to_move > 0)
+ {
+ g_memmove (&argv[i], &argv[i+2],
+ sizeof (argv[0]) * n_to_move);
+ argv[*argc-1] = NULL;
+ argv[*argc-2] = NULL;
+ }
+ else
+ {
+ argv[i] = NULL;
+ }
+
+ *argc -= 2;
+ }
+ else
+ {
+ ++i;
+ }
+ }
+}
+
+GOptionContext *
+terminal_options_get_goption_context (OptionParsingResults *parsing_results)
+{
+ const GOptionEntry global_unique_goptions[] = {
+ {
+ "disable-factory",
+ 0,
+ G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ option_disable_factory_callback,
+ N_("Do not register with the activation nameserver, do not re-use an active terminal"),
+ NULL
+ },
+ { "version", 0, G_OPTION_FLAG_NO_ARG | G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_CALLBACK, option_version_cb, NULL, NULL },
+ { NULL, 0, 0, 0, NULL, NULL, NULL }
+ };
+
+ const GOptionEntry global_multiple_goptions[] = {
+ {
+ "window",
+ 0,
+ G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ option_window_callback,
+ N_("Open a new window containing a tab with the default profile"),
+ NULL
+ },
+ {
+ "tab",
+ 0,
+ G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ option_tab_callback,
+ N_("Open a new tab in the last-opened window with the default profile"),
+ NULL
+ },
+ { NULL, 0, 0, 0, NULL, NULL, NULL }
+ };
+
+ const GOptionEntry window_goptions[] = {
+ {
+ "show-menubar",
+ 0,
+ G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ option_show_menubar_callback,
+ N_("Turn on the menubar"),
+ NULL
+ },
+ {
+ "hide-menubar",
+ 0,
+ G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ option_hide_menubar_callback,
+ N_("Turn off the menubar"),
+ NULL
+ },
+ {
+ "maximize",
+ 0,
+ G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ option_maximize_callback,
+ N_("Maximise the window"),
+ NULL
+ },
+ {
+ "full-screen",
+ 0,
+ G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ option_fullscreen_callback,
+ N_("Full-screen the window"),
+ NULL
+ },
+ {
+ "geometry",
+ 0,
+ 0,
+ G_OPTION_ARG_CALLBACK,
+ option_geometry_callback,
+ N_("Set the window geometry from the provided X geometry specification; see the \"X\" man page for more information"),
+ N_("GEOMETRY")
+ },
+ {
+ "role",
+ 0,
+ 0,
+ G_OPTION_ARG_CALLBACK,
+ option_role_callback,
+ N_("Set the window role"),
+ N_("ROLE")
+ },
+ {
+ "active",
+ 0,
+ G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ option_active_callback,
+ N_("Set the last specified tab as the active one in its window"),
+ NULL
+ },
+ { NULL, 0, 0, 0, NULL, NULL, NULL }
+ };
+
+ const GOptionEntry terminal_goptions[] = {
+ {
+ "command",
+ 'e',
+ G_OPTION_FLAG_FILENAME,
+ G_OPTION_ARG_CALLBACK,
+ option_command_callback,
+ N_("Execute the argument to this option inside the terminal"),
+ NULL
+ },
+ {
+ "profile",
+ 0,
+ 0,
+ G_OPTION_ARG_CALLBACK,
+ option_profile_cb,
+ N_("Use the given profile instead of the default profile"),
+ N_("PROFILE-NAME")
+ },
+ {
+ "title",
+ 't',
+ 0,
+ G_OPTION_ARG_CALLBACK,
+ option_title_callback,
+ N_("Set the terminal title"),
+ N_("TITLE")
+ },
+ {
+ "working-directory",
+ 0,
+ G_OPTION_FLAG_FILENAME,
+ G_OPTION_ARG_CALLBACK,
+ option_working_directory_callback,
+ N_("Set the working directory"),
+ N_("DIRNAME")
+ },
+ {
+ "zoom",
+ 0,
+ 0,
+ G_OPTION_ARG_CALLBACK,
+ option_zoom_callback,
+ N_("Set the terminalx's zoom factor (1.0 = normal size)"),
+ N_("ZOOM")
+ },
+ { NULL, 0, 0, 0, NULL, NULL, NULL }
+ };
+
+ const GOptionEntry internal_goptions[] = {
+ {
+ "profile-id",
+ 0,
+ G_OPTION_FLAG_HIDDEN,
+ G_OPTION_ARG_CALLBACK,
+ option_profile_id_cb,
+ NULL, NULL
+ },
+ {
+ "window-with-profile",
+ 0,
+ G_OPTION_FLAG_HIDDEN,
+ G_OPTION_ARG_CALLBACK,
+ option_window_callback,
+ NULL, NULL
+ },
+ {
+ "tab-with-profile",
+ 0,
+ G_OPTION_FLAG_HIDDEN,
+ G_OPTION_ARG_CALLBACK,
+ option_tab_callback,
+ NULL, NULL
+ },
+ {
+ "window-with-profile-internal-id",
+ 0,
+ G_OPTION_FLAG_HIDDEN,
+ G_OPTION_ARG_CALLBACK,
+ option_window_callback,
+ NULL, NULL
+ },
+ {
+ "tab-with-profile-internal-id",
+ 0,
+ G_OPTION_FLAG_HIDDEN,
+ G_OPTION_ARG_CALLBACK,
+ option_tab_callback,
+ NULL, NULL
+ },
+ {
+ "default-working-directory",
+ 0,
+ G_OPTION_FLAG_HIDDEN,
+ G_OPTION_ARG_FILENAME,
+ &parsing_results->default_working_dir,
+ NULL, NULL,
+ },
+ {
+ "use-factory",
+ 0,
+ G_OPTION_FLAG_HIDDEN,
+ G_OPTION_ARG_NONE,
+ &parsing_results->use_factory,
+ NULL, NULL
+ },
+ {
+ "startup-id",
+ 0,
+ G_OPTION_FLAG_HIDDEN,
+ G_OPTION_ARG_STRING,
+ &parsing_results->startup_id,
+ NULL,
+ NULL
+ },
+ /*
+ * Crappy old compat args
+ */
+ {
+ "tclass",
+ 0,
+ G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ unsupported_option_callback,
+ NULL, NULL
+ },
+ {
+ "font",
+ 0,
+ G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ unsupported_option_callback,
+ NULL, NULL
+ },
+ {
+ "nologin",
+ 0,
+ G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ unsupported_option_callback,
+ NULL, NULL
+ },
+ {
+ "login",
+ 0,
+ G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ unsupported_option_callback,
+ NULL, NULL
+ },
+ {
+ "foreground",
+ 0,
+ G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ unsupported_option_callback,
+ NULL, NULL
+ },
+ {
+ "background",
+ 0,
+ G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ unsupported_option_callback,
+ NULL, NULL
+ },
+ {
+ "solid",
+ 0,
+ G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ unsupported_option_callback,
+ NULL, NULL
+ },
+ {
+ "bgscroll",
+ 0,
+ G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ unsupported_option_callback,
+ NULL, NULL
+ },
+ {
+ "bgnoscroll",
+ 0,
+ G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ unsupported_option_callback,
+ NULL, NULL
+ },
+ {
+ "shaded",
+ 0,
+ G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ unsupported_option_callback,
+ NULL, NULL
+ },
+ {
+ "noshaded",
+ 0,
+ G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ unsupported_option_callback,
+ NULL, NULL
+ },
+ {
+ "transparent",
+ 0,
+ G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ unsupported_option_callback,
+ NULL, NULL
+ },
+ {
+ "utmp",
+ 0,
+ G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ unsupported_option_callback,
+ NULL, NULL
+ },
+ {
+ "noutmp",
+ 0,
+ G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ unsupported_option_callback,
+ NULL, NULL
+ },
+ {
+ "wtmp",
+ 0,
+ G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ unsupported_option_callback,
+ NULL, NULL
+ },
+ {
+ "nowtmp",
+ 0,
+ G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ unsupported_option_callback,
+ NULL, NULL
+ },
+ {
+ "lastlog",
+ 0,
+ G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ unsupported_option_callback,
+ NULL, NULL
+ },
+ {
+ "nolastlog",
+ 0,
+ G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ unsupported_option_callback,
+ NULL, NULL
+ },
+ {
+ "icon",
+ 0,
+ G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ unsupported_option_callback,
+ NULL, NULL
+ },
+ {
+ "termname",
+ 0,
+ G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ unsupported_option_callback,
+ NULL, NULL
+ },
+ {
+ "start-factory-server",
+ 0,
+ G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
+ G_OPTION_ARG_CALLBACK,
+ unsupported_option_callback,
+ NULL, NULL
+ },
+ { NULL, 0, 0, 0, NULL, NULL, NULL }
+ };
+
+ GOptionContext *context;
+ GOptionGroup *group;
+
+ context = g_option_context_new (NULL);
+ g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
+ g_option_context_set_description (context, N_("GNOME Terminal Emulator"));
+
+ group = g_option_group_new ("gnome-terminal",
+ N_("GNOME Terminal Emulator"),
+ N_("Show GNOME Terminal options"),
+ parsing_results,
+ NULL);
+ g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
+ g_option_group_add_entries (group, global_unique_goptions);
+ g_option_group_add_entries (group, internal_goptions);
+ g_option_group_set_parse_hooks (group, NULL, digest_options_callback);
+ g_option_context_set_main_group (context, group);
+
+ group = g_option_group_new ("terminal",
+ N_("Options to open new windows or terminal tabs; more than one of these may be specified:"),
+ N_("Show terminal options"),
+ parsing_results,
+ NULL);
+ g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
+ g_option_group_add_entries (group, global_multiple_goptions);
+ g_option_context_add_group (context, group);
+
+ group = g_option_group_new ("window-options",
+ N_("Window options; if used before the first --window or --tab argument, sets the default for all windows:"),
+ N_("Show per-window options"),
+ parsing_results,
+ NULL);
+ g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
+ g_option_group_add_entries (group, window_goptions);
+ g_option_context_add_group (context, group);
+
+ group = g_option_group_new ("terminal-options",
+ N_("Terminal options; if used before the first --window or --tab argument, sets the default for all terminals:"),
+ N_("Show per-terminal options"),
+ parsing_results,
+ NULL);
+ g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
+ g_option_group_add_entries (group, terminal_goptions);
+ g_option_context_add_group (context, group);
+
+ return context;
+}
Added: trunk/src/terminal-options.h
==============================================================================
--- (empty file)
+++ trunk/src/terminal-options.h Tue Oct 7 14:30:40 2008
@@ -0,0 +1,107 @@
+/*
+ * Copyright  2001, 2002 Havoc Pennington
+ * Copyright  2002 Red Hat, Inc.
+ * Copyright  2002 Sun Microsystems
+ * Copyright  2003 Mariano Suarez-Alvarez
+ * Copyright  2008 Christian Persch
+ *
+ * Gnome-terminal 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Gnome-terminal 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 program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+#include "terminal-intl.h"
+
+#include "terminal-app.h"
+#include "terminal-accels.h"
+#include "terminal-window.h"
+#include "terminal-util.h"
+#include "profile-editor.h"
+#include "encoding.h"
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <time.h>
+#include <gdk/gdkx.h>
+
+typedef struct
+{
+ char **env;
+ char *startup_id;
+ char *display_name;
+ int screen_number;
+ GList *initial_windows;
+ gboolean default_window_menubar_forced;
+ gboolean default_window_menubar_state;
+ gboolean default_fullscreen;
+ gboolean default_maximize;
+ char *default_role;
+ char *default_geometry;
+ char *default_working_dir;
+ char *default_title;
+ char **exec_argv;
+ char *default_profile;
+ gboolean default_profile_is_id;
+
+ gboolean execute;
+ gboolean use_factory;
+ double zoom;
+} OptionParsingResults;
+
+GOptionContext *get_goption_context (OptionParsingResults *parsing_results);
+
+typedef struct
+{
+ char *profile;
+ gboolean profile_is_id;
+ char **exec_argv;
+ char *title;
+ char *working_dir;
+ double zoom;
+ guint zoom_set : 1;
+ guint active : 1;
+} InitialTab;
+
+typedef struct
+{
+ GList *tabs; /* list of InitialTab */
+
+ gboolean force_menubar_state;
+ gboolean menubar_state;
+
+ gboolean start_fullscreen;
+ gboolean start_maximized;
+
+ char *geometry;
+ char *role;
+
+} InitialWindow;
+
+OptionParsingResults *option_parsing_results_new (const char *working_directory,
+ const char *display_name,
+ const char *startup_id,
+ const char **env,
+ int *argc,
+ char **argv);
+
+void option_parsing_results_free (OptionParsingResults *results);
+
+GOptionContext * terminal_options_get_goption_context (OptionParsingResults *parsing_results);
+
+void option_parsing_results_check_for_display_name (OptionParsingResults *results,
+ int *argc, char **argv);
+
+G_END_DECLS
Modified: trunk/src/terminal.c
==============================================================================
--- trunk/src/terminal.c (original)
+++ trunk/src/terminal.c Tue Oct 7 14:30:40 2008
@@ -27,6 +27,7 @@
#include "terminal-app.h"
#include "terminal-accels.h"
+#include "terminal-options.h"
#include "terminal-window.h"
#include "terminal-util.h"
#include "profile-editor.h"
@@ -123,862 +124,6 @@
static TerminalFactory *factory = NULL;
-typedef struct
-{
- char **env;
- char *startup_id;
- char *display_name;
- int screen_number;
- GList *initial_windows;
- gboolean default_window_menubar_forced;
- gboolean default_window_menubar_state;
- gboolean default_fullscreen;
- gboolean default_maximize;
- char *default_role;
- char *default_geometry;
- char *default_working_dir;
- char *default_title;
- char **exec_argv;
- char *default_profile;
- gboolean default_profile_is_id;
-
- gboolean execute;
- gboolean use_factory;
- double zoom;
-} OptionParsingResults;
-
-static GOptionContext * get_goption_context (OptionParsingResults *parsing_results);
-
-typedef struct
-{
- char *profile;
- gboolean profile_is_id;
- char **exec_argv;
- char *title;
- char *working_dir;
- double zoom;
- guint zoom_set : 1;
- guint active : 1;
-} InitialTab;
-
-typedef struct
-{
- GList *tabs; /* list of InitialTab */
-
- gboolean force_menubar_state;
- gboolean menubar_state;
-
- gboolean start_fullscreen;
- gboolean start_maximized;
-
- char *geometry;
- char *role;
-
-} InitialWindow;
-
-static InitialTab*
-initial_tab_new (const char *profile,
- gboolean is_id)
-{
- InitialTab *it;
-
- it = g_slice_new (InitialTab);
-
- it->profile = g_strdup (profile);
- it->profile_is_id = is_id;
- it->exec_argv = NULL;
- it->title = NULL;
- it->working_dir = NULL;
- it->zoom = 1.0;
- it->zoom_set = FALSE;
- it->active = FALSE;
-
- return it;
-}
-
-static void
-initial_tab_free (InitialTab *it)
-{
- g_free (it->profile);
- g_strfreev (it->exec_argv);
- g_free (it->title);
- g_free (it->working_dir);
- g_slice_free (InitialTab, it);
-}
-
-static InitialWindow*
-initial_window_new (const char *profile,
- gboolean is_id)
-{
- InitialWindow *iw;
-
- iw = g_slice_new (InitialWindow);
-
- iw->tabs = g_list_prepend (NULL, initial_tab_new (profile, is_id));
- iw->force_menubar_state = FALSE;
- iw->menubar_state = FALSE;
- iw->start_fullscreen = FALSE;
- iw->start_maximized = FALSE;
- iw->geometry = NULL;
- iw->role = NULL;
-
- return iw;
-}
-
-static void
-initial_window_free (InitialWindow *iw)
-{
- g_list_foreach (iw->tabs, (GFunc) initial_tab_free, NULL);
- g_list_free (iw->tabs);
- g_free (iw->geometry);
- g_free (iw->role);
- g_slice_free (InitialWindow, iw);
-}
-
-static void
-apply_defaults (OptionParsingResults *results,
- InitialWindow *iw)
-{
- if (results->default_role)
- {
- iw->role = results->default_role;
- results->default_role = NULL;
- }
-
- if (iw->geometry == NULL)
- iw->geometry = g_strdup (results->default_geometry);
-
- if (results->default_window_menubar_forced)
- {
- iw->force_menubar_state = TRUE;
- iw->menubar_state = results->default_window_menubar_state;
-
- results->default_window_menubar_forced = FALSE;
- }
-
- iw->start_fullscreen |= results->default_fullscreen;
- iw->start_maximized |= results->default_maximize;
-}
-
-static InitialWindow*
-ensure_top_window (OptionParsingResults *results)
-{
- InitialWindow *iw;
-
- if (results->initial_windows == NULL)
- {
- iw = initial_window_new (NULL, FALSE);
- apply_defaults (results, iw);
-
- results->initial_windows = g_list_append (results->initial_windows,
- iw);
- }
- else
- {
- iw = g_list_last (results->initial_windows)->data;
- }
-
- g_assert (iw->tabs);
-
- return iw;
-}
-
-static InitialTab*
-ensure_top_tab (OptionParsingResults *results)
-{
- InitialWindow *iw;
- InitialTab *it;
-
- iw = ensure_top_window (results);
-
- g_assert (iw->tabs);
-
- it = g_list_last (iw->tabs)->data;
-
- return it;
-}
-
-static InitialWindow*
-add_new_window (OptionParsingResults *results,
- const char *profile,
- gboolean is_id)
-{
- InitialWindow *iw;
-
- iw = initial_window_new (profile, is_id);
-
- apply_defaults (results, iw);
-
- results->initial_windows = g_list_append (results->initial_windows, iw);
-
- return iw;
-}
-
-/* handle deprecated command line options */
-static gboolean
-unsupported_option_callback (const gchar *option_name,
- const gchar *value,
- gpointer data,
- GError **error)
-{
- g_printerr (_("Option \"%s\" is no longer supported in this version of gnome-terminal;"
- " you might want to create a profile with the desired setting, and use"
- " the new '--window-with-profile' option\n"), option_name);
- return TRUE; /* we do not want to bail out here but continue */
-}
-
-
-static gboolean
-option_version_cb (const gchar *option_name,
- const gchar *value,
- gpointer data,
- GError **error)
-{
- g_print ("%s %s\n", _("GNOME Terminal"), VERSION);
-
- exit (EXIT_SUCCESS);
- return FALSE;
-}
-
-static gboolean
-option_command_callback (const gchar *option_name,
- const gchar *value,
- gpointer data,
- GError **error)
-{
- OptionParsingResults *results = data;
- GError *err = NULL;
- char **exec_argv;
-
- if (!g_shell_parse_argv (value, NULL, &exec_argv, &err))
- {
- g_set_error(error,
- G_OPTION_ERROR,
- G_OPTION_ERROR_BAD_VALUE,
- _("Argument to \"%s\" is not a valid command: %s"),
- "--command/-e",
- err->message);
- g_error_free (err);
- return FALSE;
- }
-
- if (results->initial_windows)
- {
- InitialTab *it = ensure_top_tab (results);
-
- g_strfreev (it->exec_argv);
- it->exec_argv = exec_argv;
- }
- else
- {
- g_strfreev (results->exec_argv);
- results->exec_argv = exec_argv;
- }
-
- return TRUE;
-}
-
-
-static gboolean
-option_profile_cb (const gchar *option_name,
- const gchar *value,
- gpointer data,
- GError **error)
-{
- OptionParsingResults *results = data;
-
- if (results->initial_windows)
- {
- InitialTab *it = ensure_top_tab (results);
-
- g_free (it->profile);
- it->profile = g_strdup (value);
- it->profile_is_id = FALSE;
- }
- else
- {
- g_free (results->default_profile);
- results->default_profile = g_strdup (value);
- results->default_profile_is_id = FALSE;
- }
-
- return TRUE;
-}
-
-
-static gboolean
-option_profile_id_cb (const gchar *option_name,
- const gchar *value,
- gpointer data,
- GError **error)
-{
- OptionParsingResults *results = data;
-
- if (results->initial_windows)
- {
- InitialTab *it = ensure_top_tab (results);
-
- g_free (it->profile);
- it->profile = g_strdup (value);
- it->profile_is_id = TRUE;
- }
- else
- {
- g_free (results->default_profile);
- results->default_profile = g_strdup (value);
- results->default_profile_is_id = TRUE;
- }
-
- return TRUE;
-}
-
-
-static gboolean
-option_window_callback (const gchar *option_name,
- const gchar *value,
- gpointer data,
- GError **error)
-{
- OptionParsingResults *results = data;
- gboolean is_profile_id;
-
- is_profile_id = g_str_has_suffix (option_name, "-with-profile-internal-id");
-
- add_new_window (results, value, is_profile_id);
-
- return TRUE;
-}
-
-
-static gboolean
-option_tab_callback (const gchar *option_name,
- const gchar *value,
- gpointer data,
- GError **error)
-{
- OptionParsingResults *results = data;
- gboolean is_profile_id;
-
- is_profile_id = g_str_has_suffix (option_name, "-with-profile-internal-id");
-
- if (results->initial_windows)
- {
- InitialWindow *iw;
-
- iw = g_list_last (results->initial_windows)->data;
- iw->tabs = g_list_append (iw->tabs, initial_tab_new (value, is_profile_id));
- }
- else
- add_new_window (results, value, is_profile_id);
-
- return TRUE;
-}
-
-
-static gboolean
-option_role_callback (const gchar *option_name,
- const gchar *value,
- gpointer data,
- GError **error)
-{
- OptionParsingResults *results = data;
- InitialWindow *iw;
-
- if (results->initial_windows)
- {
- iw = g_list_last (results->initial_windows)->data;
- iw->role = g_strdup (value);
- }
- else if (!results->default_role)
- results->default_role = g_strdup (value);
- else
- {
- g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
- "%s", _("Two roles given for one window"));
- return FALSE;
- }
-
- return TRUE;
-}
-
-
-static gboolean
-option_show_menubar_callback (const gchar *option_name,
- const gchar *value,
- gpointer data,
- GError **error)
-{
- OptionParsingResults *results = data;
- InitialWindow *iw;
-
- if (results->initial_windows)
- {
- iw = g_list_last (results->initial_windows)->data;
- if (iw->force_menubar_state && iw->menubar_state == TRUE)
- {
- g_printerr (_("\"%s\" option given twice for the same window\n"),
- "--show-menubar");
-
- return TRUE;
- }
-
- iw->force_menubar_state = TRUE;
- iw->menubar_state = TRUE;
- }
- else
- {
- results->default_window_menubar_forced = TRUE;
- results->default_window_menubar_state = TRUE;
- }
-
- return TRUE;
-}
-
-
-static gboolean
-option_hide_menubar_callback (const gchar *option_name,
- const gchar *value,
- gpointer data,
- GError **error)
-{
- OptionParsingResults *results = data;
- InitialWindow *iw;
-
- if (results->initial_windows)
- {
- iw = g_list_last (results->initial_windows)->data;
-
- if (iw->force_menubar_state && iw->menubar_state == FALSE)
- {
- g_printerr (_("\"%s\" option given twice for the same window\n"),
- "--hide-menubar");
- return TRUE;
- }
-
- iw->force_menubar_state = TRUE;
- iw->menubar_state = FALSE;
- }
- else
- {
- results->default_window_menubar_forced = TRUE;
- results->default_window_menubar_state = FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean
-option_maximize_callback (const gchar *option_name,
- const gchar *value,
- gpointer data,
- GError **error)
-{
- OptionParsingResults *results = data;
- InitialWindow *iw;
-
- if (results->initial_windows)
- {
- iw = g_list_last (results->initial_windows)->data;
- iw->start_maximized = TRUE;
- }
- else
- results->default_maximize = TRUE;
-
- return TRUE;
-}
-
-static gboolean
-option_fullscreen_callback (const gchar *option_name,
- const gchar *value,
- gpointer data,
- GError **error)
-{
- OptionParsingResults *results = data;
-
- if (results->initial_windows)
- {
- InitialWindow *iw;
-
- iw = g_list_last (results->initial_windows)->data;
- iw->start_fullscreen = TRUE;
- }
- else
- results->default_fullscreen = TRUE;
-
- return TRUE;
-}
-
-static gboolean
-option_geometry_callback (const gchar *option_name,
- const gchar *value,
- gpointer data,
- GError **error)
-{
- OptionParsingResults *results = data;
-
- if (results->initial_windows)
- {
- InitialWindow *iw;
-
- iw = g_list_last (results->initial_windows)->data;
- iw->geometry = g_strdup (value);
- }
- else
- results->default_geometry = g_strdup (value);
-
- return TRUE;
-}
-
-static gboolean
-option_disable_factory_callback (const gchar *option_name,
- const gchar *value,
- gpointer data,
- GError **error)
-{
- OptionParsingResults *results = data;
-
- results->use_factory = FALSE;
-
- return TRUE;
-}
-
-
-static gboolean
-option_title_callback (const gchar *option_name,
- const gchar *value,
- gpointer data,
- GError **error)
-{
- OptionParsingResults *results = data;
-
- if (results->initial_windows)
- {
- InitialTab *it = ensure_top_tab (results);
-
- g_free (it->title);
- it->title = g_strdup (value);
- }
- else
- {
- g_free (results->default_title);
- results->default_title = g_strdup (value);
- }
-
- return TRUE;
-}
-
-
-static gboolean
-option_working_directory_callback (const gchar *option_name,
- const gchar *value,
- gpointer data,
- GError **error)
-{
- OptionParsingResults *results = data;
-
- if (results->initial_windows)
- {
- InitialTab *it = ensure_top_tab (results);
-
- g_free (it->working_dir);
- it->working_dir = g_strdup (value);
- }
- else
- {
- g_free (results->default_working_dir);
- results->default_working_dir = g_strdup (value);
- }
-
- return TRUE;
-}
-
-
-static gboolean
-option_active_callback (const gchar *option_name,
- const gchar *value,
- gpointer data,
- GError **error)
-{
- OptionParsingResults *results = data;
- InitialTab *it;
-
- it = ensure_top_tab (results);
- it->active = TRUE;
-
- return TRUE;
-}
-
-static gboolean
-option_zoom_callback (const gchar *option_name,
- const gchar *value,
- gpointer data,
- GError **error)
-{
- OptionParsingResults *results = data;
- double zoom;
- char *end;
-
- /* Try reading a locale-style double first, in case it was
- * typed by a person, then fall back to ascii_strtod (we
- * always save session in C locale format)
- */
- end = NULL;
- errno = 0;
- zoom = g_strtod (value, &end);
- if (end == NULL || *end != '\0')
- {
- g_set_error (error,
- G_OPTION_ERROR,
- G_OPTION_ERROR_BAD_VALUE,
- _("\"%s\" is not a valid zoom factor"),
- value);
- return FALSE;
- }
-
- if (zoom < (TERMINAL_SCALE_MINIMUM + 1e-6))
- {
- g_printerr (_("Zoom factor \"%g\" is too small, using %g\n"),
- zoom,
- TERMINAL_SCALE_MINIMUM);
- zoom = TERMINAL_SCALE_MINIMUM;
- }
-
- if (zoom > (TERMINAL_SCALE_MAXIMUM - 1e-6))
- {
- g_printerr (_("Zoom factor \"%g\" is too large, using %g\n"),
- zoom,
- TERMINAL_SCALE_MAXIMUM);
- zoom = TERMINAL_SCALE_MAXIMUM;
- }
-
- if (results->initial_windows)
- {
- InitialTab *it = ensure_top_tab (results);
- it->zoom = zoom;
- it->zoom_set = TRUE;
- }
- else
- results->zoom = zoom;
-
- return TRUE;
-}
-
-/* Evaluation of the arguments given to the command line options */
-static gboolean
-digest_options_callback (GOptionContext *context,
- GOptionGroup *group,
- gpointer data,
- GError **error)
-{
- OptionParsingResults *results = data;
- InitialTab *it;
-
- /* make sure we have some window in case no options were given */
- if (results->initial_windows == NULL)
- it = ensure_top_tab (results);
-
- if (results->execute)
- {
- if (results->exec_argv == NULL)
- {
- g_set_error (error,
- G_OPTION_ERROR,
- G_OPTION_ERROR_BAD_VALUE,
- _("Option \"%s\" requires specifying the command to run"
- " on the rest of the command line"),
- "--execute/-x");
- return FALSE;
- }
-
- /* Apply -x/--execute command only to the first tab */
- it = ensure_top_tab (results);
- it->exec_argv = results->exec_argv;
- results->exec_argv = NULL;
- }
-
- return TRUE;
-}
-
-static OptionParsingResults *
-option_parsing_results_new (const char *working_directory,
- const char *display_name,
- const char *startup_id,
- const char **env,
- int *argc,
- char **argv)
-{
- OptionParsingResults *results;
- int i;
-
- results = g_slice_new0 (OptionParsingResults);
-
- results->default_window_menubar_forced = FALSE;
- results->default_window_menubar_state = TRUE;
- results->default_fullscreen = FALSE;
- results->default_maximize = FALSE;
- results->execute = FALSE;
- results->use_factory = TRUE;
-
- results->env = g_strdupv ((char **) env);
- results->startup_id = g_strdup (startup_id);
- results->display_name = g_strdup (display_name);
- results->initial_windows = NULL;
- results->default_role = NULL;
- results->default_geometry = NULL;
- results->default_title = NULL;
- results->zoom = 1.0;
-
- results->screen_number = -1;
- results->default_working_dir = g_strdup (working_directory);
-
- /* The old -x/--execute option is broken, so we need to pre-scan for it. */
- /* We now also support passing the command after the -- switch. */
- results->exec_argv = NULL;
- for (i = 1 ; i < *argc; ++i)
- {
- gboolean is_execute;
- gboolean is_dashdash;
- int j, last;
-
- is_execute = strcmp (argv[i], "-x") == 0 || strcmp (argv[i], "--execute") == 0;
- is_dashdash = strcmp (argv[i], "--") == 0;
-
- if (!is_execute && !is_dashdash)
- continue;
-
- results->execute = is_execute;
-
- /* Skip the switch */
- last = i;
- ++i;
- if (i == *argc)
- break; /* we'll complain about this later for -x/--execute; it's fine for -- */
-
- /* Collect the args, and remove them from argv */
- results->exec_argv = g_new0 (char*, *argc - i + 1);
- for (j = 0; i < *argc; ++i, ++j)
- results->exec_argv[j] = g_strdup (argv[i]);
- results->exec_argv[j] = NULL;
-
- *argc = last;
- break;
- }
-
- return results;
-}
-
-static void
-option_parsing_results_free (OptionParsingResults *results)
-{
- g_list_foreach (results->initial_windows, (GFunc) initial_window_free, NULL);
- g_list_free (results->initial_windows);
-
- g_strfreev (results->env);
- g_free (results->default_role);
- g_free (results->default_geometry);
- g_free (results->default_working_dir);
- g_free (results->default_title);
- g_free (results->default_profile);
-
- g_strfreev (results->exec_argv);
-
- g_free (results->display_name);
- g_free (results->startup_id);
-
- g_slice_free (OptionParsingResults, results);
-}
-
-static void
-option_parsing_results_check_for_display_name (OptionParsingResults *results,
- int *argc, char **argv)
-{
- int i;
-
- /* The point here is to strip --display, in the case where we
- * aren't going via gtk_init()
- */
- i = 1;
- while (i < *argc)
- {
- gboolean remove_two = FALSE;
-
- if (strcmp (argv[i], "-x") == 0 ||
- strcmp (argv[i], "--execute") == 0)
- {
- return; /* We can't have --display or --screen past here,
- * unless intended for the child process.
- */
- }
- else if (strcmp (argv[i], "--display") == 0)
- {
- if ((i + 1) >= *argc)
- {
- g_printerr (_("No argument given to \"%s\" option\n"), "--display");
- return; /* option parsing will die on this later, plus it shouldn't happen
- * because normally gtk_init() parses --display
- * when not using factory mode.
- */
- }
-
- g_assert (i+1 < *argc);
- g_free (results->display_name);
- results->display_name = g_strdup (argv[i+1]);
-
- remove_two = TRUE;
- }
- else if (strcmp (argv[i], "--screen") == 0)
- {
- int n;
- char *end;
-
- if ((i + 1) >= *argc)
- {
- g_printerr (_("\"%s\" option requires an argument\n"), "--screen");
- return; /* popt will die on this later, plus it shouldn't happen
- * because normally gtk_init() parses --display
- * when not using factory mode.
- */
- }
-
- g_assert (i+1 < *argc);
-
- errno = 0;
- end = NULL;
- n = g_ascii_strtoll (argv[i+1], &end, 0);
- if (errno == 0 && argv[i+1] != end)
- results->screen_number = n;
-
- remove_two = TRUE;
- }
-
- if (remove_two)
- {
- int n_to_move;
-
- n_to_move = *argc - i - 2;
- g_assert (n_to_move >= 0);
-
- if (n_to_move > 0)
- {
- g_memmove (&argv[i], &argv[i+2],
- sizeof (argv[0]) * n_to_move);
- argv[*argc-1] = NULL;
- argv[*argc-2] = NULL;
- }
- else
- {
- argv[i] = NULL;
- }
-
- *argc -= 2;
- }
- else
- {
- ++i;
- }
- }
-}
-
static GdkScreen*
find_screen_by_display_name (const char *display_name,
int screen_number)
@@ -1252,7 +397,7 @@
* to complicated factory setup
*/
- context = get_goption_context (parsing_results);
+ context = terminal_options_get_goption_context (parsing_results);
g_option_context_add_group (context, gtk_get_option_group (TRUE));
g_option_context_add_group (context, egg_sm_client_get_option_group ());
@@ -1407,449 +552,6 @@
/* Factory stuff */
-static GOptionContext *
-get_goption_context (OptionParsingResults *parsing_results)
-{
- const GOptionEntry global_unique_goptions[] = {
- {
- "disable-factory",
- 0,
- G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- option_disable_factory_callback,
- N_("Do not register with the activation nameserver, do not re-use an active terminal"),
- NULL
- },
- { "version", 0, G_OPTION_FLAG_NO_ARG | G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_CALLBACK, option_version_cb, NULL, NULL },
- { NULL, 0, 0, 0, NULL, NULL, NULL }
- };
-
- const GOptionEntry global_multiple_goptions[] = {
- {
- "window",
- 0,
- G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- option_window_callback,
- N_("Open a new window containing a tab with the default profile"),
- NULL
- },
- {
- "tab",
- 0,
- G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- option_tab_callback,
- N_("Open a new tab in the last-opened window with the default profile"),
- NULL
- },
- { NULL, 0, 0, 0, NULL, NULL, NULL }
- };
-
- const GOptionEntry window_goptions[] = {
- {
- "show-menubar",
- 0,
- G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- option_show_menubar_callback,
- N_("Turn on the menubar"),
- NULL
- },
- {
- "hide-menubar",
- 0,
- G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- option_hide_menubar_callback,
- N_("Turn off the menubar"),
- NULL
- },
- {
- "maximize",
- 0,
- G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- option_maximize_callback,
- N_("Maximise the window"),
- NULL
- },
- {
- "full-screen",
- 0,
- G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- option_fullscreen_callback,
- N_("Full-screen the window"),
- NULL
- },
- {
- "geometry",
- 0,
- 0,
- G_OPTION_ARG_CALLBACK,
- option_geometry_callback,
- N_("Set the window geometry from the provided X geometry specification; see the \"X\" man page for more information"),
- N_("GEOMETRY")
- },
- {
- "role",
- 0,
- 0,
- G_OPTION_ARG_CALLBACK,
- option_role_callback,
- N_("Set the window role"),
- N_("ROLE")
- },
- {
- "active",
- 0,
- G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- option_active_callback,
- N_("Set the last specified tab as the active one in its window"),
- NULL
- },
- { NULL, 0, 0, 0, NULL, NULL, NULL }
- };
-
- const GOptionEntry terminal_goptions[] = {
- {
- "command",
- 'e',
- G_OPTION_FLAG_FILENAME,
- G_OPTION_ARG_CALLBACK,
- option_command_callback,
- N_("Execute the argument to this option inside the terminal"),
- NULL
- },
- {
- "profile",
- 0,
- 0,
- G_OPTION_ARG_CALLBACK,
- option_profile_cb,
- N_("Use the given profile instead of the default profile"),
- N_("PROFILE-NAME")
- },
- {
- "title",
- 't',
- 0,
- G_OPTION_ARG_CALLBACK,
- option_title_callback,
- N_("Set the terminal title"),
- N_("TITLE")
- },
- {
- "working-directory",
- 0,
- G_OPTION_FLAG_FILENAME,
- G_OPTION_ARG_CALLBACK,
- option_working_directory_callback,
- N_("Set the working directory"),
- N_("DIRNAME")
- },
- {
- "zoom",
- 0,
- 0,
- G_OPTION_ARG_CALLBACK,
- option_zoom_callback,
- N_("Set the terminalx's zoom factor (1.0 = normal size)"),
- N_("ZOOM")
- },
- { NULL, 0, 0, 0, NULL, NULL, NULL }
- };
-
- const GOptionEntry internal_goptions[] = {
- {
- "profile-id",
- 0,
- G_OPTION_FLAG_HIDDEN,
- G_OPTION_ARG_CALLBACK,
- option_profile_id_cb,
- NULL, NULL
- },
- {
- "window-with-profile",
- 0,
- G_OPTION_FLAG_HIDDEN,
- G_OPTION_ARG_CALLBACK,
- option_window_callback,
- NULL, NULL
- },
- {
- "tab-with-profile",
- 0,
- G_OPTION_FLAG_HIDDEN,
- G_OPTION_ARG_CALLBACK,
- option_tab_callback,
- NULL, NULL
- },
- {
- "window-with-profile-internal-id",
- 0,
- G_OPTION_FLAG_HIDDEN,
- G_OPTION_ARG_CALLBACK,
- option_window_callback,
- NULL, NULL
- },
- {
- "tab-with-profile-internal-id",
- 0,
- G_OPTION_FLAG_HIDDEN,
- G_OPTION_ARG_CALLBACK,
- option_tab_callback,
- NULL, NULL
- },
- {
- "default-working-directory",
- 0,
- G_OPTION_FLAG_HIDDEN,
- G_OPTION_ARG_FILENAME,
- &parsing_results->default_working_dir,
- NULL, NULL,
- },
- {
- "use-factory",
- 0,
- G_OPTION_FLAG_HIDDEN,
- G_OPTION_ARG_NONE,
- &parsing_results->use_factory,
- NULL, NULL
- },
- {
- "startup-id",
- 0,
- G_OPTION_FLAG_HIDDEN,
- G_OPTION_ARG_STRING,
- &parsing_results->startup_id,
- NULL,
- NULL
- },
- /*
- * Crappy old compat args
- */
- {
- "tclass",
- 0,
- G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- unsupported_option_callback,
- NULL, NULL
- },
- {
- "font",
- 0,
- G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- unsupported_option_callback,
- NULL, NULL
- },
- {
- "nologin",
- 0,
- G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- unsupported_option_callback,
- NULL, NULL
- },
- {
- "login",
- 0,
- G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- unsupported_option_callback,
- NULL, NULL
- },
- {
- "foreground",
- 0,
- G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- unsupported_option_callback,
- NULL, NULL
- },
- {
- "background",
- 0,
- G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- unsupported_option_callback,
- NULL, NULL
- },
- {
- "solid",
- 0,
- G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- unsupported_option_callback,
- NULL, NULL
- },
- {
- "bgscroll",
- 0,
- G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- unsupported_option_callback,
- NULL, NULL
- },
- {
- "bgnoscroll",
- 0,
- G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- unsupported_option_callback,
- NULL, NULL
- },
- {
- "shaded",
- 0,
- G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- unsupported_option_callback,
- NULL, NULL
- },
- {
- "noshaded",
- 0,
- G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- unsupported_option_callback,
- NULL, NULL
- },
- {
- "transparent",
- 0,
- G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- unsupported_option_callback,
- NULL, NULL
- },
- {
- "utmp",
- 0,
- G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- unsupported_option_callback,
- NULL, NULL
- },
- {
- "noutmp",
- 0,
- G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- unsupported_option_callback,
- NULL, NULL
- },
- {
- "wtmp",
- 0,
- G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- unsupported_option_callback,
- NULL, NULL
- },
- {
- "nowtmp",
- 0,
- G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- unsupported_option_callback,
- NULL, NULL
- },
- {
- "lastlog",
- 0,
- G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- unsupported_option_callback,
- NULL, NULL
- },
- {
- "nolastlog",
- 0,
- G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- unsupported_option_callback,
- NULL, NULL
- },
- {
- "icon",
- 0,
- G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- unsupported_option_callback,
- NULL, NULL
- },
- {
- "termname",
- 0,
- G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- unsupported_option_callback,
- NULL, NULL
- },
- {
- "start-factory-server",
- 0,
- G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_NO_ARG,
- G_OPTION_ARG_CALLBACK,
- unsupported_option_callback,
- NULL, NULL
- },
- { NULL, 0, 0, 0, NULL, NULL, NULL }
- };
-
- GOptionContext *context;
- GOptionGroup *group;
-
- context = g_option_context_new (NULL);
- g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
- g_option_context_set_description (context, N_("GNOME Terminal Emulator"));
-
- group = g_option_group_new ("gnome-terminal",
- N_("GNOME Terminal Emulator"),
- N_("Show GNOME Terminal options"),
- parsing_results,
- NULL);
- g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
- g_option_group_add_entries (group, global_unique_goptions);
- g_option_group_add_entries (group, internal_goptions);
- g_option_group_set_parse_hooks (group, NULL, digest_options_callback);
- g_option_context_set_main_group (context, group);
-
- group = g_option_group_new ("terminal",
- N_("Options to open new windows or terminal tabs; more than one of these may be specified:"),
- N_("Show terminal options"),
- parsing_results,
- NULL);
- g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
- g_option_group_add_entries (group, global_multiple_goptions);
- g_option_context_add_group (context, group);
-
- group = g_option_group_new ("window-options",
- N_("Window options; if used before the first --window or --tab argument, sets the default for all windows:"),
- N_("Show per-window options"),
- parsing_results,
- NULL);
- g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
- g_option_group_add_entries (group, window_goptions);
- g_option_context_add_group (context, group);
-
- group = g_option_group_new ("terminal-options",
- N_("Terminal options; if used before the first --window or --tab argument, sets the default for all terminals:"),
- N_("Show per-terminal options"),
- parsing_results,
- NULL);
- g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
- g_option_group_add_entries (group, terminal_goptions);
- g_option_context_add_group (context, group);
-
- return context;
-}
-
static gboolean
handle_new_terminal_event (OptionParsingResults *parsing_results)
{
@@ -1885,7 +587,7 @@
/* Find and parse --display */
option_parsing_results_check_for_display_name (parsing_results, &argc, argv);
- context = get_goption_context (parsing_results);
+ context = terminal_options_get_goption_context (parsing_results);
g_option_context_set_ignore_unknown_options (context, TRUE);
if (!g_option_context_parse (context, &argc, &argv, error))
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]