Blame src/terminal-options.c

Packit Service 3bdf47
/*
Packit Service 3bdf47
 * Copyright © 2001, 2002 Havoc Pennington
Packit Service 3bdf47
 * Copyright © 2002 Red Hat, Inc.
Packit Service 3bdf47
 * Copyright © 2002 Sun Microsystems
Packit Service 3bdf47
 * Copyright © 2003 Mariano Suarez-Alvarez
Packit Service 3bdf47
 * Copyright © 2008, 2017 Christian Persch
Packit Service 3bdf47
 *
Packit Service 3bdf47
 * This program is free software: you can redistribute it and/or modify
Packit Service 3bdf47
 * it under the terms of the GNU General Public License as published by
Packit Service 3bdf47
 * the Free Software Foundation, either version 3 of the License, or
Packit Service 3bdf47
 * (at your option) any later version.
Packit Service 3bdf47
 *
Packit Service 3bdf47
 * This program is distributed in the hope that it will be useful,
Packit Service 3bdf47
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 3bdf47
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 3bdf47
 * GNU General Public License for more details.
Packit Service 3bdf47
 *
Packit Service 3bdf47
 * You should have received a copy of the GNU General Public License
Packit Service 3bdf47
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit Service 3bdf47
 */
Packit Service 3bdf47
Packit Service 3bdf47
#include <config.h>
Packit Service 3bdf47
Packit Service 3bdf47
#include <errno.h>
Packit Service 3bdf47
#include <string.h>
Packit Service 3bdf47
#include <stdlib.h>
Packit Service 3bdf47
Packit Service 3bdf47
#include <glib.h>
Packit Service 3bdf47
#include <glib/gi18n.h>
Packit Service 3bdf47
#include <glib/gprintf.h>
Packit Service 3bdf47
Packit Service 3bdf47
#include "terminal-options.h"
Packit Service 3bdf47
#include "terminal-client-utils.h"
Packit Service 3bdf47
#include "terminal-defines.h"
Packit Service 3bdf47
#include "terminal-schemas.h"
Packit Service 3bdf47
#include "terminal-screen.h"
Packit Service 3bdf47
#include "terminal-app.h"
Packit Service 3bdf47
#include "terminal-util.h"
Packit Service 3bdf47
#include "terminal-version.h"
Packit Service 3bdf47
#include "terminal-libgsystem.h"
Packit Service 3bdf47
Packit Service 3bdf47
static int verbosity = 1;
Packit Service 3bdf47
Packit Service 3bdf47
void
Packit Service 3bdf47
terminal_fprintf (FILE* fp,
Packit Service 3bdf47
                  int verbosity_level,
Packit Service 3bdf47
                  const char* format,
Packit Service 3bdf47
                  ...)
Packit Service 3bdf47
{
Packit Service 3bdf47
  if (verbosity < verbosity_level)
Packit Service 3bdf47
    return;
Packit Service 3bdf47
Packit Service 3bdf47
  va_list args;
Packit Service 3bdf47
  va_start(args, format);
Packit Service 3bdf47
  gs_free char *str = g_strdup_vprintf(format, args);
Packit Service 3bdf47
  va_end(args);
Packit Service 3bdf47
Packit Service 3bdf47
  gs_strfreev char **lines = g_strsplit_set(str, "\n\r", -1);
Packit Service 3bdf47
  for (gsize i = 0; lines[i]; ++i) {
Packit Service 3bdf47
    if (lines[i][0] != '\0')
Packit Service 3bdf47
      g_fprintf(fp, "# %s\n", lines[i]);
Packit Service 3bdf47
  }
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
#if GLIB_CHECK_VERSION (2, 50, 0)
Packit Service 3bdf47
Packit Service 3bdf47
/* Need to install a special log writer so we never output
Packit Service 3bdf47
 * anything without the '# ' prepended, in case --print-environment
Packit Service 3bdf47
 * is used.
Packit Service 3bdf47
 */
Packit Service 3bdf47
GLogWriterOutput
Packit Service 3bdf47
terminal_log_writer (GLogLevelFlags log_level,
Packit Service 3bdf47
                     const GLogField *fields,
Packit Service 3bdf47
                     gsize n_fields,
Packit Service 3bdf47
                     gpointer user_data)
Packit Service 3bdf47
{
Packit Service 3bdf47
  for (gsize i = 0; i < n_fields; i++) {
Packit Service 3bdf47
    if (g_str_equal (fields[i].key, "MESSAGE"))
Packit Service 3bdf47
      terminal_printerr ("%s\n", (const char*)fields[i].value);
Packit Service 3bdf47
  }
Packit Service 3bdf47
Packit Service 3bdf47
  return G_LOG_WRITER_HANDLED;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
#endif /* GLIB 2.50 */
Packit Service 3bdf47
Packit Service 3bdf47
static GOptionContext *get_goption_context (TerminalOptions *options);
Packit Service 3bdf47
Packit Service 3bdf47
static TerminalSettingsList *
Packit Service 3bdf47
terminal_options_ensure_profiles_list (TerminalOptions *options)
Packit Service 3bdf47
{
Packit Service 3bdf47
  if (options->profiles_list == NULL)
Packit Service 3bdf47
    options->profiles_list = terminal_profiles_list_new ();
Packit Service 3bdf47
Packit Service 3bdf47
  return options->profiles_list;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static char *
Packit Service 3bdf47
terminal_util_key_file_get_string_unescape (GKeyFile *key_file,
Packit Service 3bdf47
                                            const char *group,
Packit Service 3bdf47
                                            const char *key,
Packit Service 3bdf47
                                            GError **error)
Packit Service 3bdf47
{
Packit Service 3bdf47
  char *escaped, *unescaped;
Packit Service 3bdf47
Packit Service 3bdf47
  escaped = g_key_file_get_string (key_file, group, key, error);
Packit Service 3bdf47
  if (!escaped)
Packit Service 3bdf47
    return NULL;
Packit Service 3bdf47
Packit Service 3bdf47
  unescaped = g_strcompress (escaped);
Packit Service 3bdf47
  g_free (escaped);
Packit Service 3bdf47
Packit Service 3bdf47
  return unescaped;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static char **
Packit Service 3bdf47
terminal_util_key_file_get_argv (GKeyFile *key_file,
Packit Service 3bdf47
                                 const char *group,
Packit Service 3bdf47
                                 const char *key,
Packit Service 3bdf47
                                 int *argc,
Packit Service 3bdf47
                                 GError **error)
Packit Service 3bdf47
{
Packit Service 3bdf47
  char **argv;
Packit Service 3bdf47
  char *flat;
Packit Service 3bdf47
  gboolean retval;
Packit Service 3bdf47
Packit Service 3bdf47
  flat = terminal_util_key_file_get_string_unescape (key_file, group, key, error);
Packit Service 3bdf47
  if (!flat)
Packit Service 3bdf47
    return NULL;
Packit Service 3bdf47
Packit Service 3bdf47
  retval = g_shell_parse_argv (flat, argc, &argv, error);
Packit Service 3bdf47
  g_free (flat);
Packit Service 3bdf47
Packit Service 3bdf47
  if (retval)
Packit Service 3bdf47
    return argv;
Packit Service 3bdf47
Packit Service 3bdf47
  return NULL;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static InitialTab*
Packit Service 3bdf47
initial_tab_new (char *profile /* adopts */)
Packit Service 3bdf47
{
Packit Service 3bdf47
  InitialTab *it;
Packit Service 3bdf47
Packit Service 3bdf47
  it = g_slice_new (InitialTab);
Packit Service 3bdf47
Packit Service 3bdf47
  it->profile = profile;
Packit Service 3bdf47
  it->exec_argv = NULL;
Packit Service 3bdf47
  it->title = NULL;
Packit Service 3bdf47
  it->working_dir = NULL;
Packit Service 3bdf47
  it->zoom = 1.0;
Packit Service 3bdf47
  it->zoom_set = FALSE;
Packit Service 3bdf47
  it->active = FALSE;
Packit Service 3bdf47
  it->fd_list = NULL;
Packit Service 3bdf47
  it->fd_array = NULL;
Packit Service 3bdf47
Packit Service 3bdf47
  return it;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static void
Packit Service 3bdf47
initial_tab_free (InitialTab *it)
Packit Service 3bdf47
{
Packit Service 3bdf47
  g_free (it->profile);
Packit Service 3bdf47
  g_strfreev (it->exec_argv);
Packit Service 3bdf47
  g_free (it->title);
Packit Service 3bdf47
  g_free (it->working_dir);
Packit Service 3bdf47
  g_clear_object (&it->fd_list);
Packit Service 3bdf47
  if (it->fd_array)
Packit Service 3bdf47
    g_array_unref (it->fd_array);
Packit Service 3bdf47
  g_slice_free (InitialTab, it);
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static InitialWindow*
Packit Service 3bdf47
initial_window_new (guint source_tag)
Packit Service 3bdf47
{
Packit Service 3bdf47
  InitialWindow *iw;
Packit Service 3bdf47
Packit Service 3bdf47
  iw = g_slice_new0 (InitialWindow);
Packit Service 3bdf47
  iw->source_tag = source_tag;
Packit Service 3bdf47
Packit Service 3bdf47
  return iw;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static void
Packit Service 3bdf47
initial_window_free (InitialWindow *iw)
Packit Service 3bdf47
{
Packit Service 3bdf47
  g_list_free_full (iw->tabs, (GDestroyNotify) initial_tab_free);
Packit Service 3bdf47
  g_free (iw->geometry);
Packit Service 3bdf47
  g_free (iw->role);
Packit Service 3bdf47
  g_slice_free (InitialWindow, iw);
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static void
Packit Service 3bdf47
apply_window_defaults (TerminalOptions *options,
Packit Service 3bdf47
                       InitialWindow *iw)
Packit Service 3bdf47
{
Packit Service 3bdf47
  if (options->default_role)
Packit Service 3bdf47
    {
Packit Service 3bdf47
      iw->role = options->default_role;
Packit Service 3bdf47
      options->default_role = NULL;
Packit Service 3bdf47
    }
Packit Service 3bdf47
Packit Service 3bdf47
  if (iw->geometry == NULL)
Packit Service 3bdf47
    iw->geometry = g_strdup (options->default_geometry);
Packit Service 3bdf47
Packit Service 3bdf47
  if (options->default_window_menubar_forced)
Packit Service 3bdf47
    {
Packit Service 3bdf47
      iw->force_menubar_state = TRUE;
Packit Service 3bdf47
      iw->menubar_state = options->default_window_menubar_state;
Packit Service 3bdf47
Packit Service 3bdf47
      options->default_window_menubar_forced = FALSE;
Packit Service 3bdf47
    }
Packit Service 3bdf47
Packit Service 3bdf47
  iw->start_fullscreen |= options->default_fullscreen;
Packit Service 3bdf47
  iw->start_maximized |= options->default_maximize;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static void
Packit Service 3bdf47
apply_tab_defaults (TerminalOptions *options,
Packit Service 3bdf47
                    InitialTab *it)
Packit Service 3bdf47
{
Packit Service 3bdf47
  it->wait = options->default_wait;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static InitialWindow*
Packit Service 3bdf47
add_new_window (TerminalOptions *options,
Packit Service 3bdf47
                char *profile /* adopts */,
Packit Service 3bdf47
                gboolean implicit_if_first_window)
Packit Service 3bdf47
{
Packit Service 3bdf47
  InitialWindow *iw;
Packit Service 3bdf47
  InitialTab *it;
Packit Service 3bdf47
Packit Service 3bdf47
  iw = initial_window_new (0);
Packit Service 3bdf47
  iw->implicit_first_window = (options->initial_windows == NULL) && implicit_if_first_window;
Packit Service 3bdf47
  apply_window_defaults (options, iw);
Packit Service 3bdf47
Packit Service 3bdf47
  it = initial_tab_new (profile);
Packit Service 3bdf47
  iw->tabs = g_list_prepend (NULL, it);
Packit Service 3bdf47
  apply_tab_defaults (options, it);
Packit Service 3bdf47
Packit Service 3bdf47
  options->initial_windows = g_list_append (options->initial_windows, iw);
Packit Service 3bdf47
  return iw;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static InitialWindow*
Packit Service 3bdf47
ensure_top_window (TerminalOptions *options,
Packit Service 3bdf47
                   gboolean implicit_if_first_window)
Packit Service 3bdf47
{
Packit Service 3bdf47
  InitialWindow *iw;
Packit Service 3bdf47
Packit Service 3bdf47
  if (options->initial_windows == NULL)
Packit Service 3bdf47
    iw = add_new_window (options, NULL /* profile */, implicit_if_first_window);
Packit Service 3bdf47
  else
Packit Service 3bdf47
      iw = g_list_last (options->initial_windows)->data;
Packit Service 3bdf47
Packit Service 3bdf47
  g_assert_nonnull (iw->tabs);
Packit Service 3bdf47
Packit Service 3bdf47
  return iw;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static InitialTab*
Packit Service 3bdf47
ensure_top_tab (TerminalOptions *options)
Packit Service 3bdf47
{
Packit Service 3bdf47
  InitialWindow *iw;
Packit Service 3bdf47
  InitialTab *it;
Packit Service 3bdf47
Packit Service 3bdf47
  iw = ensure_top_window (options, TRUE);
Packit Service 3bdf47
Packit Service 3bdf47
  g_assert_nonnull (iw->tabs);
Packit Service 3bdf47
Packit Service 3bdf47
  it = g_list_last (iw->tabs)->data;
Packit Service 3bdf47
Packit Service 3bdf47
  return it;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
/* handle deprecated command line options */
Packit Service 3bdf47
Packit Service 3bdf47
static void
Packit Service 3bdf47
deprecated_option_warning (const gchar *option_name)
Packit Service 3bdf47
{
Packit Service 3bdf47
  terminal_printerr (_("Option “%s” is deprecated and might be removed in a later version of gnome-terminal."),
Packit Service 3bdf47
                     option_name);
Packit Service 3bdf47
  terminal_printerr ("\n");
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static void
Packit Service 3bdf47
deprecated_command_option_warning (const char *option_name)
Packit Service 3bdf47
{
Packit Service 3bdf47
  deprecated_option_warning (option_name);
Packit Service 3bdf47
Packit Service 3bdf47
  /* %s is being replaced with "-- " (without quotes), which must be used literally, not translatable */
Packit Service 3bdf47
  terminal_printerr (_("Use “%s” to terminate the options and put the command line to execute after it."), "-- ");
Packit Service 3bdf47
  terminal_printerr ("\n");
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static gboolean
Packit Service 3bdf47
unsupported_option_callback (const gchar *option_name,
Packit Service 3bdf47
                             const gchar *value,
Packit Service 3bdf47
                             gpointer     data,
Packit Service 3bdf47
                             GError     **error)
Packit Service 3bdf47
{
Packit Service 3bdf47
  terminal_printerr (_("Option “%s” is no longer supported in this version of gnome-terminal."),
Packit Service 3bdf47
              option_name);
Packit Service 3bdf47
  terminal_printerr ("\n");
Packit Service 3bdf47
  return TRUE; /* we do not want to bail out here but continue */
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static gboolean
Packit Service 3bdf47
unsupported_option_fatal_callback (const gchar *option_name,
Packit Service 3bdf47
                                   const gchar *value,
Packit Service 3bdf47
                                   gpointer     data,
Packit Service 3bdf47
                                   GError     **error)
Packit Service 3bdf47
{
Packit Service 3bdf47
  g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_UNKNOWN_OPTION,
Packit Service 3bdf47
               _("Option “%s” is no longer supported in this version of gnome-terminal."),
Packit Service 3bdf47
               option_name);
Packit Service 3bdf47
  return FALSE;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
Packit Service 3bdf47
static gboolean G_GNUC_NORETURN
Packit Service 3bdf47
option_version_cb (const gchar *option_name,
Packit Service 3bdf47
                   const gchar *value,
Packit Service 3bdf47
                   gpointer     data,
Packit Service 3bdf47
                   GError     **error)
Packit Service 3bdf47
{
Packit Service 3bdf47
  terminal_print ("GNOME Terminal %s using VTE %u.%u.%u %s\n",
Packit Service 3bdf47
                  VERSION,
Packit Service 3bdf47
                  vte_get_major_version (),
Packit Service 3bdf47
                  vte_get_minor_version (),
Packit Service 3bdf47
                  vte_get_micro_version (),
Packit Service 3bdf47
                  vte_get_features ());
Packit Service 3bdf47
  exit (EXIT_SUCCESS);
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static gboolean
Packit Service 3bdf47
option_verbosity_cb (const gchar *option_name,
Packit Service 3bdf47
                     const gchar *value,
Packit Service 3bdf47
                     gpointer     data,
Packit Service 3bdf47
                     GError     **error)
Packit Service 3bdf47
{
Packit Service 3bdf47
  if (g_str_equal (option_name, "--quiet") || g_str_equal (option_name, "-q"))
Packit Service 3bdf47
    verbosity = 0;
Packit Service 3bdf47
  else
Packit Service 3bdf47
    verbosity++;
Packit Service 3bdf47
Packit Service 3bdf47
  return TRUE;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static gboolean
Packit Service 3bdf47
option_app_id_callback (const gchar *option_name,
Packit Service 3bdf47
                          const gchar *value,
Packit Service 3bdf47
                          gpointer     data,
Packit Service 3bdf47
                          GError     **error)
Packit Service 3bdf47
{
Packit Service 3bdf47
  TerminalOptions *options = data;
Packit Service 3bdf47
Packit Service 3bdf47
  if (!g_application_id_is_valid (value)) {
Packit Service 3bdf47
    g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
Packit Service 3bdf47
                 "\"%s\" is not a valid application ID", value);
Packit Service 3bdf47
    return FALSE;
Packit Service 3bdf47
  }
Packit Service 3bdf47
Packit Service 3bdf47
  g_free (options->server_app_id);
Packit Service 3bdf47
  options->server_app_id = g_strdup (value);
Packit Service 3bdf47
Packit Service 3bdf47
  return TRUE;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static gboolean
Packit Service 3bdf47
option_command_callback (const gchar *option_name,
Packit Service 3bdf47
                         const gchar *value,
Packit Service 3bdf47
                         gpointer     data,
Packit Service 3bdf47
                         GError     **error)
Packit Service 3bdf47
{
Packit Service 3bdf47
  TerminalOptions *options = data;
Packit Service 3bdf47
  GError *err = NULL;
Packit Service 3bdf47
  char  **exec_argv;
Packit Service 3bdf47
Packit Service 3bdf47
  deprecated_command_option_warning (option_name);
Packit Service 3bdf47
Packit Service 3bdf47
  if (!g_shell_parse_argv (value, NULL, &exec_argv, &err))
Packit Service 3bdf47
    {
Packit Service 3bdf47
      g_set_error(error,
Packit Service 3bdf47
                  G_OPTION_ERROR,
Packit Service 3bdf47
                  G_OPTION_ERROR_BAD_VALUE,
Packit Service 3bdf47
                  _("Argument to “%s” is not a valid command: %s"),
Packit Service 3bdf47
                   "--command/-e",
Packit Service 3bdf47
                  err->message);
Packit Service 3bdf47
      g_error_free (err);
Packit Service 3bdf47
      return FALSE;
Packit Service 3bdf47
    }
Packit Service 3bdf47
Packit Service 3bdf47
  if (options->initial_windows)
Packit Service 3bdf47
    {
Packit Service 3bdf47
      InitialTab *it = ensure_top_tab (options);
Packit Service 3bdf47
Packit Service 3bdf47
      g_strfreev (it->exec_argv);
Packit Service 3bdf47
      it->exec_argv = exec_argv;
Packit Service 3bdf47
    }
Packit Service 3bdf47
  else
Packit Service 3bdf47
    {
Packit Service 3bdf47
      g_strfreev (options->exec_argv);
Packit Service 3bdf47
      options->exec_argv = exec_argv;
Packit Service 3bdf47
    }
Packit Service 3bdf47
Packit Service 3bdf47
  return TRUE;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static gboolean
Packit Service 3bdf47
option_profile_cb (const gchar *option_name,
Packit Service 3bdf47
                   const gchar *value,
Packit Service 3bdf47
                   gpointer     data,
Packit Service 3bdf47
                   GError     **error)
Packit Service 3bdf47
{
Packit Service 3bdf47
  TerminalOptions *options = data;
Packit Service 3bdf47
  char *profile;
Packit Service 3bdf47
Packit Service 3bdf47
  profile = terminal_profiles_list_dup_uuid_or_name (terminal_options_ensure_profiles_list (options),
Packit Service 3bdf47
                                                     value, error);
Packit Service 3bdf47
  if (profile == NULL)
Packit Service 3bdf47
  {
Packit Service 3bdf47
      terminal_printerr ("Profile '%s' specified but not found. Attempting to fall back "
Packit Service 3bdf47
                         "to the default profile.\n", value);
Packit Service 3bdf47
      g_clear_error (error);
Packit Service 3bdf47
      profile = terminal_profiles_list_dup_uuid_or_name (terminal_options_ensure_profiles_list (options),
Packit Service 3bdf47
                                                         NULL, error);
Packit Service 3bdf47
  }
Packit Service 3bdf47
Packit Service 3bdf47
  if (profile == NULL)
Packit Service 3bdf47
      return FALSE;
Packit Service 3bdf47
Packit Service 3bdf47
  if (options->initial_windows)
Packit Service 3bdf47
    {
Packit Service 3bdf47
      InitialTab *it = ensure_top_tab (options);
Packit Service 3bdf47
Packit Service 3bdf47
      g_free (it->profile);
Packit Service 3bdf47
      it->profile = profile;
Packit Service 3bdf47
    }
Packit Service 3bdf47
  else
Packit Service 3bdf47
    {
Packit Service 3bdf47
      g_free (options->default_profile);
Packit Service 3bdf47
      options->default_profile = profile;
Packit Service 3bdf47
    }
Packit Service 3bdf47
Packit Service 3bdf47
  return TRUE;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static gboolean
Packit Service 3bdf47
option_profile_id_cb (const gchar *option_name,
Packit Service 3bdf47
                      const gchar *value,
Packit Service 3bdf47
                      gpointer     data,
Packit Service 3bdf47
                      GError     **error)
Packit Service 3bdf47
{
Packit Service 3bdf47
  TerminalOptions *options = data;
Packit Service 3bdf47
  char *profile;
Packit Service 3bdf47
Packit Service 3bdf47
  profile = terminal_profiles_list_dup_uuid (terminal_options_ensure_profiles_list (options),
Packit Service 3bdf47
                                             value, error);
Packit Service 3bdf47
  if (profile == NULL)
Packit Service 3bdf47
    return FALSE;
Packit Service 3bdf47
Packit Service 3bdf47
  if (options->initial_windows)
Packit Service 3bdf47
    {
Packit Service 3bdf47
      InitialTab *it = ensure_top_tab (options);
Packit Service 3bdf47
Packit Service 3bdf47
      g_free (it->profile);
Packit Service 3bdf47
      it->profile = profile;
Packit Service 3bdf47
    }
Packit Service 3bdf47
  else
Packit Service 3bdf47
    {
Packit Service 3bdf47
      g_free (options->default_profile);
Packit Service 3bdf47
      options->default_profile = profile;
Packit Service 3bdf47
    }
Packit Service 3bdf47
Packit Service 3bdf47
  return TRUE;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
Packit Service 3bdf47
static gboolean
Packit Service 3bdf47
option_window_callback (const gchar *option_name,
Packit Service 3bdf47
                        const gchar *value,
Packit Service 3bdf47
                        gpointer     data,
Packit Service 3bdf47
                        GError     **error)
Packit Service 3bdf47
{
Packit Service 3bdf47
  TerminalOptions *options = data;
Packit Service 3bdf47
  char *profile;
Packit Service 3bdf47
Packit Service 3bdf47
  if (value != NULL) {
Packit Service 3bdf47
    profile = terminal_profiles_list_dup_uuid_or_name (terminal_options_ensure_profiles_list (options),
Packit Service 3bdf47
                                                       value, error);
Packit Service 3bdf47
Packit Service 3bdf47
    if (value && profile == NULL) {
Packit Service 3bdf47
      terminal_printerr ("Profile '%s' specified but not found. Attempting to fall back "
Packit Service 3bdf47
                         "to the default profile.\n", value);
Packit Service 3bdf47
      g_clear_error (error);
Packit Service 3bdf47
      profile = terminal_profiles_list_dup_uuid_or_name (terminal_options_ensure_profiles_list (options),
Packit Service 3bdf47
                                                         NULL, error);
Packit Service 3bdf47
    }
Packit Service 3bdf47
Packit Service 3bdf47
    if (profile == NULL)
Packit Service 3bdf47
      return FALSE;
Packit Service 3bdf47
  } else
Packit Service 3bdf47
    profile = NULL;
Packit Service 3bdf47
Packit Service 3bdf47
  add_new_window (options, profile /* adopts */, FALSE);
Packit Service 3bdf47
Packit Service 3bdf47
  return TRUE;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static gboolean
Packit Service 3bdf47
option_tab_callback (const gchar *option_name,
Packit Service 3bdf47
                     const gchar *value,
Packit Service 3bdf47
                     gpointer     data,
Packit Service 3bdf47
                     GError     **error)
Packit Service 3bdf47
{
Packit Service 3bdf47
  TerminalOptions *options = data;
Packit Service 3bdf47
  char *profile;
Packit Service 3bdf47
Packit Service 3bdf47
  if (value != NULL) {
Packit Service 3bdf47
    profile = terminal_profiles_list_dup_uuid_or_name (terminal_options_ensure_profiles_list (options),
Packit Service 3bdf47
                                                       value, error);
Packit Service 3bdf47
    if (profile == NULL)
Packit Service 3bdf47
      return FALSE;
Packit Service 3bdf47
  } else
Packit Service 3bdf47
    profile = NULL;
Packit Service 3bdf47
Packit Service 3bdf47
  if (options->initial_windows)
Packit Service 3bdf47
    {
Packit Service 3bdf47
      InitialWindow *iw;
Packit Service 3bdf47
Packit Service 3bdf47
      iw = g_list_last (options->initial_windows)->data;
Packit Service 3bdf47
      iw->tabs = g_list_append (iw->tabs, initial_tab_new (profile /* adopts */));
Packit Service 3bdf47
    }
Packit Service 3bdf47
  else
Packit Service 3bdf47
    add_new_window (options, profile /* adopts */, TRUE);
Packit Service 3bdf47
Packit Service 3bdf47
  return TRUE;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static gboolean
Packit Service 3bdf47
option_role_callback (const gchar *option_name,
Packit Service 3bdf47
                      const gchar *value,
Packit Service 3bdf47
                      gpointer     data,
Packit Service 3bdf47
                      GError     **error)
Packit Service 3bdf47
{
Packit Service 3bdf47
  TerminalOptions *options = data;
Packit Service 3bdf47
  InitialWindow *iw;
Packit Service 3bdf47
Packit Service 3bdf47
  if (options->initial_windows)
Packit Service 3bdf47
    {
Packit Service 3bdf47
      iw = g_list_last (options->initial_windows)->data;
Packit Service 3bdf47
      iw->role = g_strdup (value);
Packit Service 3bdf47
    }
Packit Service 3bdf47
  else if (!options->default_role)
Packit Service 3bdf47
    options->default_role = g_strdup (value);
Packit Service 3bdf47
  else
Packit Service 3bdf47
    {
Packit Service 3bdf47
      g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
Packit Service 3bdf47
                   "%s", _("Two roles given for one window"));
Packit Service 3bdf47
      return FALSE;
Packit Service 3bdf47
    }
Packit Service 3bdf47
Packit Service 3bdf47
  return TRUE;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static gboolean
Packit Service 3bdf47
option_show_menubar_callback (const gchar *option_name,
Packit Service 3bdf47
                              const gchar *value,
Packit Service 3bdf47
                              gpointer     data,
Packit Service 3bdf47
                              GError     **error)
Packit Service 3bdf47
{
Packit Service 3bdf47
  TerminalOptions *options = data;
Packit Service 3bdf47
  InitialWindow *iw;
Packit Service 3bdf47
Packit Service 3bdf47
  if (options->initial_windows)
Packit Service 3bdf47
    {
Packit Service 3bdf47
      iw = g_list_last (options->initial_windows)->data;
Packit Service 3bdf47
      if (iw->force_menubar_state && iw->menubar_state == TRUE)
Packit Service 3bdf47
        {
Packit Service 3bdf47
          terminal_printerr_detail (_("“%s” option given twice for the same window\n"),
Packit Service 3bdf47
                                    "--show-menubar");
Packit Service 3bdf47
Packit Service 3bdf47
          return TRUE;
Packit Service 3bdf47
        }
Packit Service 3bdf47
Packit Service 3bdf47
      iw->force_menubar_state = TRUE;
Packit Service 3bdf47
      iw->menubar_state = TRUE;
Packit Service 3bdf47
    }
Packit Service 3bdf47
  else
Packit Service 3bdf47
    {
Packit Service 3bdf47
      options->default_window_menubar_forced = TRUE;
Packit Service 3bdf47
      options->default_window_menubar_state = TRUE;
Packit Service 3bdf47
    }
Packit Service 3bdf47
Packit Service 3bdf47
  return TRUE;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static gboolean
Packit Service 3bdf47
option_hide_menubar_callback (const gchar *option_name,
Packit Service 3bdf47
                              const gchar *value,
Packit Service 3bdf47
                              gpointer     data,
Packit Service 3bdf47
                              GError     **error)
Packit Service 3bdf47
{
Packit Service 3bdf47
  TerminalOptions *options = data;
Packit Service 3bdf47
  InitialWindow *iw;
Packit Service 3bdf47
Packit Service 3bdf47
  if (options->initial_windows)
Packit Service 3bdf47
    {
Packit Service 3bdf47
      iw = g_list_last (options->initial_windows)->data;
Packit Service 3bdf47
Packit Service 3bdf47
      if (iw->force_menubar_state && iw->menubar_state == FALSE)
Packit Service 3bdf47
        {
Packit Service 3bdf47
          terminal_printerr_detail (_("“%s” option given twice for the same window\n"),
Packit Service 3bdf47
                                    "--hide-menubar");
Packit Service 3bdf47
          return TRUE;
Packit Service 3bdf47
        }
Packit Service 3bdf47
Packit Service 3bdf47
      iw->force_menubar_state = TRUE;
Packit Service 3bdf47
      iw->menubar_state = FALSE;
Packit Service 3bdf47
    }
Packit Service 3bdf47
  else
Packit Service 3bdf47
    {
Packit Service 3bdf47
      options->default_window_menubar_forced = TRUE;
Packit Service 3bdf47
      options->default_window_menubar_state = FALSE;
Packit Service 3bdf47
    }
Packit Service 3bdf47
Packit Service 3bdf47
  return TRUE;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static gboolean
Packit Service 3bdf47
option_maximize_callback (const gchar *option_name,
Packit Service 3bdf47
                          const gchar *value,
Packit Service 3bdf47
                          gpointer     data,
Packit Service 3bdf47
                          GError     **error)
Packit Service 3bdf47
{
Packit Service 3bdf47
  TerminalOptions *options = data;
Packit Service 3bdf47
  InitialWindow *iw;
Packit Service 3bdf47
Packit Service 3bdf47
  if (options->initial_windows)
Packit Service 3bdf47
    {
Packit Service 3bdf47
      iw = g_list_last (options->initial_windows)->data;
Packit Service 3bdf47
      iw->start_maximized = TRUE;
Packit Service 3bdf47
    }
Packit Service 3bdf47
  else
Packit Service 3bdf47
    options->default_maximize = TRUE;
Packit Service 3bdf47
Packit Service 3bdf47
  return TRUE;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static gboolean
Packit Service 3bdf47
option_fullscreen_callback (const gchar *option_name,
Packit Service 3bdf47
                            const gchar *value,
Packit Service 3bdf47
                            gpointer     data,
Packit Service 3bdf47
                            GError     **error)
Packit Service 3bdf47
{
Packit Service 3bdf47
  TerminalOptions *options = data;
Packit Service 3bdf47
Packit Service 3bdf47
  if (options->initial_windows)
Packit Service 3bdf47
    {
Packit Service 3bdf47
      InitialWindow *iw;
Packit Service 3bdf47
Packit Service 3bdf47
      iw = g_list_last (options->initial_windows)->data;
Packit Service 3bdf47
      iw->start_fullscreen = TRUE;
Packit Service 3bdf47
    }
Packit Service 3bdf47
  else
Packit Service 3bdf47
    options->default_fullscreen = TRUE;
Packit Service 3bdf47
Packit Service 3bdf47
  return TRUE;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static gboolean
Packit Service 3bdf47
option_geometry_callback (const gchar *option_name,
Packit Service 3bdf47
                          const gchar *value,
Packit Service 3bdf47
                          gpointer     data,
Packit Service 3bdf47
                          GError     **error)
Packit Service 3bdf47
{
Packit Service 3bdf47
  TerminalOptions *options = data;
Packit Service 3bdf47
Packit Service 3bdf47
  if (options->initial_windows)
Packit Service 3bdf47
    {
Packit Service 3bdf47
      InitialWindow *iw;
Packit Service 3bdf47
Packit Service 3bdf47
      iw = g_list_last (options->initial_windows)->data;
Packit Service 3bdf47
      iw->geometry = g_strdup (value);
Packit Service 3bdf47
    }
Packit Service 3bdf47
  else
Packit Service 3bdf47
    options->default_geometry = g_strdup (value);
Packit Service 3bdf47
Packit Service 3bdf47
  return TRUE;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static gboolean
Packit Service 3bdf47
option_load_config_cb (const gchar *option_name,
Packit Service 3bdf47
                       const gchar *value,
Packit Service 3bdf47
                       gpointer     data,
Packit Service 3bdf47
                       GError     **error)
Packit Service 3bdf47
{
Packit Service 3bdf47
  TerminalOptions *options = data;
Packit Service 3bdf47
  GFile *file;
Packit Service 3bdf47
  char *config_file;
Packit Service 3bdf47
  GKeyFile *key_file;
Packit Service 3bdf47
  gboolean result;
Packit Service 3bdf47
Packit Service 3bdf47
  file = g_file_new_for_commandline_arg (value);
Packit Service 3bdf47
  config_file = g_file_get_path (file);
Packit Service 3bdf47
  g_object_unref (file);
Packit Service 3bdf47
Packit Service 3bdf47
  key_file = g_key_file_new ();
Packit Service 3bdf47
  result = g_key_file_load_from_file (key_file, config_file, 0, error) &&
Packit Service 3bdf47
           terminal_options_merge_config (options, key_file,
Packit Service 3bdf47
                                          strcmp (option_name, "load-config") == 0 ? SOURCE_DEFAULT : SOURCE_SESSION,
Packit Service 3bdf47
                                          error);
Packit Service 3bdf47
  g_key_file_free (key_file);
Packit Service 3bdf47
  g_free (config_file);
Packit Service 3bdf47
Packit Service 3bdf47
  return result;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static gboolean
Packit Service 3bdf47
option_title_callback (const gchar *option_name,
Packit Service 3bdf47
                       const gchar *value,
Packit Service 3bdf47
                       gpointer     data,
Packit Service 3bdf47
                       GError     **error)
Packit Service 3bdf47
{
Packit Service 3bdf47
  TerminalOptions *options = data;
Packit Service 3bdf47
Packit Service 3bdf47
  if (options->initial_windows)
Packit Service 3bdf47
    {
Packit Service 3bdf47
      InitialTab *it = ensure_top_tab (options);
Packit Service 3bdf47
Packit Service 3bdf47
      g_free (it->title);
Packit Service 3bdf47
      it->title = g_strdup (value);
Packit Service 3bdf47
    }
Packit Service 3bdf47
  else
Packit Service 3bdf47
    {
Packit Service 3bdf47
      g_free (options->default_title);
Packit Service 3bdf47
      options->default_title = g_strdup (value);
Packit Service 3bdf47
    }
Packit Service 3bdf47
Packit Service 3bdf47
  return TRUE;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static gboolean
Packit Service 3bdf47
option_working_directory_callback (const gchar *option_name,
Packit Service 3bdf47
                                   const gchar *value,
Packit Service 3bdf47
                                   gpointer     data,
Packit Service 3bdf47
                                   GError     **error)
Packit Service 3bdf47
{
Packit Service 3bdf47
  TerminalOptions *options = data;
Packit Service 3bdf47
Packit Service 3bdf47
  if (options->initial_windows)
Packit Service 3bdf47
    {
Packit Service 3bdf47
      InitialTab *it = ensure_top_tab (options);
Packit Service 3bdf47
Packit Service 3bdf47
      g_free (it->working_dir);
Packit Service 3bdf47
      it->working_dir = g_strdup (value);
Packit Service 3bdf47
    }
Packit Service 3bdf47
  else
Packit Service 3bdf47
    {
Packit Service 3bdf47
      g_free (options->default_working_dir);
Packit Service 3bdf47
      options->default_working_dir = g_strdup (value);
Packit Service 3bdf47
    }
Packit Service 3bdf47
Packit Service 3bdf47
  return TRUE;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static gboolean
Packit Service 3bdf47
option_wait_cb (const gchar *option_name,
Packit Service 3bdf47
                const gchar *value,
Packit Service 3bdf47
                gpointer     data,
Packit Service 3bdf47
                GError     **error)
Packit Service 3bdf47
{
Packit Service 3bdf47
  TerminalOptions *options = data;
Packit Service 3bdf47
Packit Service 3bdf47
  if (options->initial_windows)
Packit Service 3bdf47
    {
Packit Service 3bdf47
      InitialTab *it = ensure_top_tab (options);
Packit Service 3bdf47
Packit Service 3bdf47
      g_free (it->working_dir);
Packit Service 3bdf47
      it->wait = TRUE;
Packit Service 3bdf47
    }
Packit Service 3bdf47
  else
Packit Service 3bdf47
    {
Packit Service 3bdf47
      options->default_wait = TRUE;
Packit Service 3bdf47
    }
Packit Service 3bdf47
Packit Service 3bdf47
  return TRUE;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static gboolean
Packit Service 3bdf47
option_pass_fd_cb (const gchar *option_name,
Packit Service 3bdf47
                   const gchar *value,
Packit Service 3bdf47
                   gpointer     data,
Packit Service 3bdf47
                   GError     **error)
Packit Service 3bdf47
{
Packit Service 3bdf47
  TerminalOptions *options = data;
Packit Service 3bdf47
Packit Service 3bdf47
  errno = 0;
Packit Service 3bdf47
  char *end;
Packit Service 3bdf47
  gint64 v = g_ascii_strtoll (value, &end, 10);
Packit Service 3bdf47
  if (errno || end == value || v == -1 || v < G_MININT || v > G_MAXINT) {
Packit Service 3bdf47
    g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
Packit Service 3bdf47
                 "Failed to parse \"%s\" as file descriptor number",
Packit Service 3bdf47
                 value);
Packit Service 3bdf47
    return FALSE;
Packit Service 3bdf47
  }
Packit Service 3bdf47
Packit Service 3bdf47
  int fd = v;
Packit Service 3bdf47
  if (fd == STDIN_FILENO ||
Packit Service 3bdf47
      fd == STDOUT_FILENO ||
Packit Service 3bdf47
      fd == STDERR_FILENO) {
Packit Service 3bdf47
    g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
Packit Service 3bdf47
                 "FD passing of %s is not supported",
Packit Service 3bdf47
                 fd == STDIN_FILENO ? "stdin" : fd == STDOUT_FILENO ? "stdout" : "stderr");
Packit Service 3bdf47
    return FALSE;
Packit Service 3bdf47
  }
Packit Service 3bdf47
Packit Service 3bdf47
  InitialTab *it = ensure_top_tab (options);
Packit Service 3bdf47
  if (it->fd_list == NULL)
Packit Service 3bdf47
    it->fd_list = g_unix_fd_list_new ();
Packit Service 3bdf47
  if (it->fd_array == NULL)
Packit Service 3bdf47
    it->fd_array = g_array_sized_new (FALSE /* zero terminate */,
Packit Service 3bdf47
                                      TRUE /* clear */,
Packit Service 3bdf47
                                      sizeof (PassFdElement),
Packit Service 3bdf47
                                      8 /* that should be plenty */);
Packit Service 3bdf47
Packit Service 3bdf47
Packit Service 3bdf47
  for (guint i = 0; i < it->fd_array->len; i++) {
Packit Service 3bdf47
    PassFdElement *e = &g_array_index (it->fd_array, PassFdElement, i);
Packit Service 3bdf47
    if (e->fd == fd) {
Packit Service 3bdf47
      g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
Packit Service 3bdf47
                   _("Cannot pass FD %d twice"), fd);
Packit Service 3bdf47
      return FALSE;
Packit Service 3bdf47
    }
Packit Service 3bdf47
  }
Packit Service 3bdf47
Packit Service 3bdf47
  int idx = g_unix_fd_list_append (it->fd_list, fd, error);
Packit Service 3bdf47
  if (idx == -1) {
Packit Service 3bdf47
    g_prefix_error (error, "%d: ", fd);
Packit Service 3bdf47
    return FALSE;
Packit Service 3bdf47
  }
Packit Service 3bdf47
Packit Service 3bdf47
  PassFdElement e = { idx, fd };
Packit Service 3bdf47
  g_array_append_val (it->fd_array, e);
Packit Service 3bdf47
Packit Service 3bdf47
#if 0
Packit Service 3bdf47
  if (fd == STDOUT_FILENO ||
Packit Service 3bdf47
      fd == STDERR_FILENO)
Packit Service 3bdf47
    verbosity = 0;
Packit Service 3bdf47
  if (fd == STDIN_FILENO)
Packit Service 3bdf47
    it->wait = TRUE;
Packit Service 3bdf47
#endif
Packit Service 3bdf47
Packit Service 3bdf47
  return TRUE;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static gboolean
Packit Service 3bdf47
option_active_callback (const gchar *option_name,
Packit Service 3bdf47
                        const gchar *value,
Packit Service 3bdf47
                        gpointer     data,
Packit Service 3bdf47
                        GError     **error)
Packit Service 3bdf47
{
Packit Service 3bdf47
  TerminalOptions *options = data;
Packit Service 3bdf47
  InitialTab *it;
Packit Service 3bdf47
Packit Service 3bdf47
  it = ensure_top_tab (options);
Packit Service 3bdf47
  it->active = TRUE;
Packit Service 3bdf47
Packit Service 3bdf47
  return TRUE;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static gboolean
Packit Service 3bdf47
option_zoom_callback (const gchar *option_name,
Packit Service 3bdf47
                      const gchar *value,
Packit Service 3bdf47
                      gpointer     data,
Packit Service 3bdf47
                      GError     **error)
Packit Service 3bdf47
{
Packit Service 3bdf47
  TerminalOptions *options = data;
Packit Service 3bdf47
  double zoom;
Packit Service 3bdf47
  char *end;
Packit Service 3bdf47
Packit Service 3bdf47
  /* Try reading a locale-style double first, in case it was
Packit Service 3bdf47
    * typed by a person, then fall back to ascii_strtod (we
Packit Service 3bdf47
    * always save session in C locale format)
Packit Service 3bdf47
    */
Packit Service 3bdf47
  end = NULL;
Packit Service 3bdf47
  errno = 0;
Packit Service 3bdf47
  zoom = g_strtod (value, &end;;
Packit Service 3bdf47
  if (end == NULL || *end != '\0')
Packit Service 3bdf47
    {
Packit Service 3bdf47
      g_set_error (error,
Packit Service 3bdf47
                   G_OPTION_ERROR,
Packit Service 3bdf47
                   G_OPTION_ERROR_BAD_VALUE,
Packit Service 3bdf47
                   _("“%s” is not a valid zoom factor"),
Packit Service 3bdf47
                   value);
Packit Service 3bdf47
      return FALSE;
Packit Service 3bdf47
    }
Packit Service 3bdf47
Packit Service 3bdf47
  if (zoom < (TERMINAL_SCALE_MINIMUM + 1e-6))
Packit Service 3bdf47
    {
Packit Service 3bdf47
      terminal_printerr (_("Zoom factor “%g” is too small, using %g\n"),
Packit Service 3bdf47
                         zoom,
Packit Service 3bdf47
                         TERMINAL_SCALE_MINIMUM);
Packit Service 3bdf47
      zoom = TERMINAL_SCALE_MINIMUM;
Packit Service 3bdf47
    }
Packit Service 3bdf47
Packit Service 3bdf47
  if (zoom > (TERMINAL_SCALE_MAXIMUM - 1e-6))
Packit Service 3bdf47
    {
Packit Service 3bdf47
      terminal_printerr (_("Zoom factor “%g” is too large, using %g\n"),
Packit Service 3bdf47
                         zoom,
Packit Service 3bdf47
                         TERMINAL_SCALE_MAXIMUM);
Packit Service 3bdf47
      zoom = TERMINAL_SCALE_MAXIMUM;
Packit Service 3bdf47
    }
Packit Service 3bdf47
Packit Service 3bdf47
  if (options->initial_windows)
Packit Service 3bdf47
    {
Packit Service 3bdf47
      InitialTab *it = ensure_top_tab (options);
Packit Service 3bdf47
      it->zoom = zoom;
Packit Service 3bdf47
      it->zoom_set = TRUE;
Packit Service 3bdf47
    }
Packit Service 3bdf47
  else
Packit Service 3bdf47
    {
Packit Service 3bdf47
      options->zoom = zoom;
Packit Service 3bdf47
      options->zoom_set = TRUE;
Packit Service 3bdf47
    }
Packit Service 3bdf47
Packit Service 3bdf47
  return TRUE;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
/* Evaluation of the arguments given to the command line options */
Packit Service 3bdf47
static gboolean
Packit Service 3bdf47
digest_options_callback (GOptionContext *context,
Packit Service 3bdf47
                         GOptionGroup *group,
Packit Service 3bdf47
                         gpointer      data,
Packit Service 3bdf47
                         GError      **error)
Packit Service 3bdf47
{
Packit Service 3bdf47
  TerminalOptions *options = data;
Packit Service 3bdf47
  InitialTab    *it;
Packit Service 3bdf47
Packit Service 3bdf47
  if (options->execute)
Packit Service 3bdf47
    {
Packit Service 3bdf47
      if (options->exec_argv == NULL)
Packit Service 3bdf47
        {
Packit Service 3bdf47
          g_set_error (error,
Packit Service 3bdf47
                       G_OPTION_ERROR,
Packit Service 3bdf47
                       G_OPTION_ERROR_BAD_VALUE,
Packit Service 3bdf47
                       _("Option “%s” requires specifying the command to run"
Packit Service 3bdf47
                         " on the rest of the command line"),
Packit Service 3bdf47
                       "--execute/-x");
Packit Service 3bdf47
          return FALSE;
Packit Service 3bdf47
        }
Packit Service 3bdf47
Packit Service 3bdf47
      /* Apply -x/--execute command only to the first tab */
Packit Service 3bdf47
      it = ensure_top_tab (options);
Packit Service 3bdf47
      it->exec_argv = options->exec_argv;
Packit Service 3bdf47
      options->exec_argv = NULL;
Packit Service 3bdf47
    }
Packit Service 3bdf47
Packit Service 3bdf47
  return TRUE;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
/**
Packit Service 3bdf47
 * terminal_options_parse:
Packit Service 3bdf47
 * @argcp: (inout) address of the argument count. Changed if any arguments were handled
Packit Service 3bdf47
 * @argvp: (inout) address of the argument vector. Any parameters understood by
Packit Service 3bdf47
 *   the terminal #GOptionContext are removed
Packit Service 3bdf47
 * @error: a #GError to fill in
Packit Service 3bdf47
 *
Packit Service 3bdf47
 * Parses the argument vector *@argvp.
Packit Service 3bdf47
 *
Packit Service 3bdf47
 * Returns: a new #TerminalOptions containing the windows and tabs to open,
Packit Service 3bdf47
 *   or %NULL on error.
Packit Service 3bdf47
 */
Packit Service 3bdf47
TerminalOptions *
Packit Service 3bdf47
terminal_options_parse (int *argcp,
Packit Service 3bdf47
                        char ***argvp,
Packit Service 3bdf47
                        GError **error)
Packit Service 3bdf47
{
Packit Service 3bdf47
  TerminalOptions *options;
Packit Service 3bdf47
  GOptionContext *context;
Packit Service 3bdf47
  gboolean retval;
Packit Service 3bdf47
  int i;
Packit Service 3bdf47
  char **argv = *argvp;
Packit Service 3bdf47
Packit Service 3bdf47
  options = g_new0 (TerminalOptions, 1);
Packit Service 3bdf47
Packit Service 3bdf47
  options->print_environment = FALSE;
Packit Service 3bdf47
  options->default_window_menubar_forced = FALSE;
Packit Service 3bdf47
  options->default_window_menubar_state = TRUE;
Packit Service 3bdf47
  options->default_fullscreen = FALSE;
Packit Service 3bdf47
  options->default_maximize = FALSE;
Packit Service 3bdf47
  options->execute = FALSE;
Packit Service 3bdf47
Packit Service 3bdf47
  const char *startup_id = g_getenv ("DESKTOP_STARTUP_ID");
Packit Service 3bdf47
  options->startup_id = g_strdup (startup_id && startup_id[0] ? startup_id : NULL);
Packit Service 3bdf47
  options->display_name = NULL;
Packit Service 3bdf47
  options->initial_windows = NULL;
Packit Service 3bdf47
  options->default_role = NULL;
Packit Service 3bdf47
  options->default_geometry = NULL;
Packit Service 3bdf47
  options->default_title = NULL;
Packit Service 3bdf47
  options->zoom = 1.0;
Packit Service 3bdf47
  options->zoom_set = FALSE;
Packit Service 3bdf47
Packit Service 3bdf47
  options->default_working_dir = g_get_current_dir ();
Packit Service 3bdf47
Packit Service 3bdf47
  /* Collect info from gnome-terminal private env vars */
Packit Service 3bdf47
  const char *server_unique_name = g_getenv (TERMINAL_ENV_SERVICE_NAME);
Packit Service 3bdf47
  if (server_unique_name != NULL) {
Packit Service 3bdf47
    if (g_dbus_is_unique_name (server_unique_name))
Packit Service 3bdf47
      options->server_unique_name = g_strdup (server_unique_name);
Packit Service 3bdf47
    else
Packit Service 3bdf47
      terminal_printerr ("Warning: %s set but \"%s\" is not a unique D-Bus name.\n",
Packit Service 3bdf47
                         TERMINAL_ENV_SERVICE_NAME,
Packit Service 3bdf47
                         server_unique_name);
Packit Service 3bdf47
  }
Packit Service 3bdf47
Packit Service 3bdf47
  const char *parent_screen_object_path = g_getenv (TERMINAL_ENV_SCREEN);
Packit Service 3bdf47
  if (parent_screen_object_path != NULL) {
Packit Service 3bdf47
    if (g_variant_is_object_path (parent_screen_object_path))
Packit Service 3bdf47
      options->parent_screen_object_path = g_strdup (parent_screen_object_path);
Packit Service 3bdf47
    else
Packit Service 3bdf47
      terminal_printerr ("Warning: %s set but \"%s\" is not a valid D-Bus object path.\n",
Packit Service 3bdf47
                         TERMINAL_ENV_SCREEN,
Packit Service 3bdf47
                         parent_screen_object_path);
Packit Service 3bdf47
  }
Packit Service 3bdf47
Packit Service 3bdf47
  /* The old -x/--execute option is broken, so we need to pre-scan for it. */
Packit Service 3bdf47
  /* We now also support passing the command after the -- switch. */
Packit Service 3bdf47
  options->exec_argv = NULL;
Packit Service 3bdf47
  for (i = 1 ; i < *argcp; ++i)
Packit Service 3bdf47
    {
Packit Service 3bdf47
      gboolean is_execute;
Packit Service 3bdf47
      gboolean is_dashdash;
Packit Service 3bdf47
      int j, last;
Packit Service 3bdf47
Packit Service 3bdf47
      is_execute = strcmp (argv[i], "-x") == 0 || strcmp (argv[i], "--execute") == 0;
Packit Service 3bdf47
      is_dashdash = strcmp (argv[i], "--") == 0;
Packit Service 3bdf47
Packit Service 3bdf47
      if (!is_execute && !is_dashdash)
Packit Service 3bdf47
        continue;
Packit Service 3bdf47
Packit Service 3bdf47
      if (is_execute)
Packit Service 3bdf47
        deprecated_command_option_warning (argv[i]);
Packit Service 3bdf47
Packit Service 3bdf47
      options->execute = is_execute;
Packit Service 3bdf47
Packit Service 3bdf47
      /* Skip the switch */
Packit Service 3bdf47
      last = i;
Packit Service 3bdf47
      ++i;
Packit Service 3bdf47
      if (i == *argcp)
Packit Service 3bdf47
        break; /* we'll complain about this later for -x/--execute; it's fine for -- */
Packit Service 3bdf47
Packit Service 3bdf47
      /* Collect the args, and remove them from argv */
Packit Service 3bdf47
      options->exec_argv = g_new0 (char*, *argcp - i + 1);
Packit Service 3bdf47
      for (j = 0; i < *argcp; ++i, ++j)
Packit Service 3bdf47
        options->exec_argv[j] = g_strdup (argv[i]);
Packit Service 3bdf47
      options->exec_argv[j] = NULL;
Packit Service 3bdf47
Packit Service 3bdf47
      *argcp = last;
Packit Service 3bdf47
      break;
Packit Service 3bdf47
    }
Packit Service 3bdf47
Packit Service 3bdf47
  context = get_goption_context (options);
Packit Service 3bdf47
  retval = g_option_context_parse (context, argcp, argvp, error);
Packit Service 3bdf47
  g_option_context_free (context);
Packit Service 3bdf47
Packit Service 3bdf47
  if (!retval) {
Packit Service 3bdf47
    terminal_options_free (options);
Packit Service 3bdf47
    return NULL;
Packit Service 3bdf47
  }
Packit Service 3bdf47
Packit Service 3bdf47
  /* Do this here so that gdk_display is initialized */
Packit Service 3bdf47
  if (options->startup_id == NULL)
Packit Service 3bdf47
    options->startup_id = terminal_client_get_fallback_startup_id ();
Packit Service 3bdf47
  /* Still NULL? */
Packit Service 3bdf47
  if (options->startup_id == NULL)
Packit Service 3bdf47
    terminal_printerr_detail ("Warning: DESKTOP_STARTUP_ID not set and no fallback available.\n");
Packit Service 3bdf47
Packit Service 3bdf47
  GdkDisplay *display = gdk_display_get_default ();
Packit Service 3bdf47
  if (display != NULL)
Packit Service 3bdf47
    options->display_name = g_strdup (gdk_display_get_name (display));
Packit Service 3bdf47
Packit Service 3bdf47
  /* Sanity check */
Packit Service 3bdf47
  guint wait = 0;
Packit Service 3bdf47
  for (GList *lw = options->initial_windows;  lw != NULL; lw = lw->next) {
Packit Service 3bdf47
    InitialWindow *iw = lw->data;
Packit Service 3bdf47
    for (GList *lt = iw->tabs; lt != NULL; lt = lt->next) {
Packit Service 3bdf47
      InitialTab *it = lt->data;
Packit Service 3bdf47
      if (it->wait)
Packit Service 3bdf47
        wait++;
Packit Service 3bdf47
    }
Packit Service 3bdf47
  }
Packit Service 3bdf47
Packit Service 3bdf47
  if (wait > 1) {
Packit Service 3bdf47
    g_set_error_literal (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
Packit Service 3bdf47
                         _("Can only use --wait once"));
Packit Service 3bdf47
    return FALSE;
Packit Service 3bdf47
  }
Packit Service 3bdf47
Packit Service 3bdf47
  return options;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
/**
Packit Service 3bdf47
 * terminal_options_merge_config:
Packit Service 3bdf47
 * @options:
Packit Service 3bdf47
 * @key_file: a #GKeyFile containing to merge the options from
Packit Service 3bdf47
 * @source_tag: a source_tag to use in new #InitialWindows
Packit Service 3bdf47
 * @error: a #GError to fill in
Packit Service 3bdf47
 *
Packit Service 3bdf47
 * Merges the saved options from @key_file into @options.
Packit Service 3bdf47
 *
Packit Service 3bdf47
 * Returns: %TRUE if @key_file was a valid key file containing a stored
Packit Service 3bdf47
 *   terminal configuration, or %FALSE on error
Packit Service 3bdf47
 */
Packit Service 3bdf47
gboolean
Packit Service 3bdf47
terminal_options_merge_config (TerminalOptions *options,
Packit Service 3bdf47
                               GKeyFile *key_file,
Packit Service 3bdf47
                               guint source_tag,
Packit Service 3bdf47
                               GError **error)
Packit Service 3bdf47
{
Packit Service 3bdf47
  int version, compat_version;
Packit Service 3bdf47
  char **groups;
Packit Service 3bdf47
  guint i;
Packit Service 3bdf47
  gboolean have_error = FALSE;
Packit Service 3bdf47
  GList *initial_windows = NULL;
Packit Service 3bdf47
Packit Service 3bdf47
  if (!g_key_file_has_group (key_file, TERMINAL_CONFIG_GROUP))
Packit Service 3bdf47
    {
Packit Service 3bdf47
      g_set_error_literal (error, TERMINAL_OPTION_ERROR,
Packit Service 3bdf47
                           TERMINAL_OPTION_ERROR_INVALID_CONFIG_FILE,
Packit Service 3bdf47
                           _("Not a valid terminal config file."));
Packit Service 3bdf47
      return FALSE;
Packit Service 3bdf47
    }
Packit Service 3bdf47
  
Packit Service 3bdf47
  version = g_key_file_get_integer (key_file, TERMINAL_CONFIG_GROUP, TERMINAL_CONFIG_PROP_VERSION, NULL);
Packit Service 3bdf47
  compat_version = g_key_file_get_integer (key_file, TERMINAL_CONFIG_GROUP, TERMINAL_CONFIG_PROP_COMPAT_VERSION, NULL);
Packit Service 3bdf47
Packit Service 3bdf47
  if (version <= 0 ||
Packit Service 3bdf47
      compat_version <= 0 ||
Packit Service 3bdf47
      compat_version > TERMINAL_CONFIG_COMPAT_VERSION)
Packit Service 3bdf47
    {
Packit Service 3bdf47
      g_set_error_literal (error, TERMINAL_OPTION_ERROR,
Packit Service 3bdf47
                           TERMINAL_OPTION_ERROR_INCOMPATIBLE_CONFIG_FILE,
Packit Service 3bdf47
                           _("Incompatible terminal config file version."));
Packit Service 3bdf47
      return FALSE;
Packit Service 3bdf47
    }
Packit Service 3bdf47
Packit Service 3bdf47
  groups = g_key_file_get_string_list (key_file, TERMINAL_CONFIG_GROUP, TERMINAL_CONFIG_PROP_WINDOWS, NULL, error);
Packit Service 3bdf47
  if (!groups)
Packit Service 3bdf47
    return FALSE;
Packit Service 3bdf47
Packit Service 3bdf47
  for (i = 0; groups[i]; ++i)
Packit Service 3bdf47
    {
Packit Service 3bdf47
      const char *window_group = groups[i];
Packit Service 3bdf47
      char *active_terminal;
Packit Service 3bdf47
      char **tab_groups;
Packit Service 3bdf47
      InitialWindow *iw;
Packit Service 3bdf47
      guint j;
Packit Service 3bdf47
Packit Service 3bdf47
      tab_groups = g_key_file_get_string_list (key_file, window_group, TERMINAL_CONFIG_WINDOW_PROP_TABS, NULL, error);
Packit Service 3bdf47
      if (!tab_groups)
Packit Service 3bdf47
        continue; /* no tabs in this window, skip it */
Packit Service 3bdf47
Packit Service 3bdf47
      iw = initial_window_new (source_tag);
Packit Service 3bdf47
      initial_windows = g_list_append (initial_windows, iw);
Packit Service 3bdf47
      apply_window_defaults (options, iw);
Packit Service 3bdf47
Packit Service 3bdf47
      active_terminal = g_key_file_get_string (key_file, window_group, TERMINAL_CONFIG_WINDOW_PROP_ACTIVE_TAB, NULL);
Packit Service 3bdf47
      iw->role = g_key_file_get_string (key_file, window_group, TERMINAL_CONFIG_WINDOW_PROP_ROLE, NULL);
Packit Service 3bdf47
      iw->geometry = g_key_file_get_string (key_file, window_group, TERMINAL_CONFIG_WINDOW_PROP_GEOMETRY, NULL);
Packit Service 3bdf47
      iw->start_fullscreen = g_key_file_get_boolean (key_file, window_group, TERMINAL_CONFIG_WINDOW_PROP_FULLSCREEN, NULL);
Packit Service 3bdf47
      iw->start_maximized = g_key_file_get_boolean (key_file, window_group, TERMINAL_CONFIG_WINDOW_PROP_MAXIMIZED, NULL);
Packit Service 3bdf47
      if (g_key_file_has_key (key_file, window_group, TERMINAL_CONFIG_WINDOW_PROP_MENUBAR_VISIBLE, NULL))
Packit Service 3bdf47
        {
Packit Service 3bdf47
          iw->force_menubar_state = TRUE;
Packit Service 3bdf47
          iw->menubar_state = g_key_file_get_boolean (key_file, window_group, TERMINAL_CONFIG_WINDOW_PROP_MENUBAR_VISIBLE, NULL);
Packit Service 3bdf47
        }
Packit Service 3bdf47
Packit Service 3bdf47
      for (j = 0; tab_groups[j]; ++j)
Packit Service 3bdf47
        {
Packit Service 3bdf47
          const char *tab_group = tab_groups[j];
Packit Service 3bdf47
          InitialTab *it;
Packit Service 3bdf47
          char *profile;
Packit Service 3bdf47
Packit Service 3bdf47
          profile = g_key_file_get_string (key_file, tab_group, TERMINAL_CONFIG_TERMINAL_PROP_PROFILE_ID, NULL);
Packit Service 3bdf47
          it = initial_tab_new (profile /* adopts */);
Packit Service 3bdf47
Packit Service 3bdf47
          iw->tabs = g_list_append (iw->tabs, it);
Packit Service 3bdf47
Packit Service 3bdf47
          if (g_strcmp0 (active_terminal, tab_group) == 0)
Packit Service 3bdf47
            it->active = TRUE;
Packit Service 3bdf47
Packit Service 3bdf47
/*          it->width = g_key_file_get_integer (key_file, tab_group, TERMINAL_CONFIG_TERMINAL_PROP_WIDTH, NULL);
Packit Service 3bdf47
          it->height = g_key_file_get_integer (key_file, tab_group, TERMINAL_CONFIG_TERMINAL_PROP_HEIGHT, NULL);*/
Packit Service 3bdf47
          it->working_dir = terminal_util_key_file_get_string_unescape (key_file, tab_group, TERMINAL_CONFIG_TERMINAL_PROP_WORKING_DIRECTORY, NULL);
Packit Service 3bdf47
          it->title = g_key_file_get_string (key_file, tab_group, TERMINAL_CONFIG_TERMINAL_PROP_TITLE, NULL);
Packit Service 3bdf47
Packit Service 3bdf47
          if (g_key_file_has_key (key_file, tab_group, TERMINAL_CONFIG_TERMINAL_PROP_COMMAND, NULL) &&
Packit Service 3bdf47
              !(it->exec_argv = terminal_util_key_file_get_argv (key_file, tab_group, TERMINAL_CONFIG_TERMINAL_PROP_COMMAND, NULL, error)))
Packit Service 3bdf47
            {
Packit Service 3bdf47
              have_error = TRUE;
Packit Service 3bdf47
              break;
Packit Service 3bdf47
            }
Packit Service 3bdf47
        }
Packit Service 3bdf47
Packit Service 3bdf47
      g_free (active_terminal);
Packit Service 3bdf47
      g_strfreev (tab_groups);
Packit Service 3bdf47
Packit Service 3bdf47
      if (have_error)
Packit Service 3bdf47
        break;
Packit Service 3bdf47
    }
Packit Service 3bdf47
Packit Service 3bdf47
  g_strfreev (groups);
Packit Service 3bdf47
Packit Service 3bdf47
  if (have_error)
Packit Service 3bdf47
    {
Packit Service 3bdf47
      g_list_free_full (initial_windows, (GDestroyNotify) initial_window_free);
Packit Service 3bdf47
      return FALSE;
Packit Service 3bdf47
    }
Packit Service 3bdf47
Packit Service 3bdf47
  options->initial_windows = g_list_concat (options->initial_windows, initial_windows);
Packit Service 3bdf47
Packit Service 3bdf47
  return TRUE;
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
/**
Packit Service 3bdf47
 * terminal_options_ensure_window:
Packit Service 3bdf47
 * @options:
Packit Service 3bdf47
 *
Packit Service 3bdf47
 * Ensure that @options will contain at least one window to open.
Packit Service 3bdf47
 */
Packit Service 3bdf47
void
Packit Service 3bdf47
terminal_options_ensure_window (TerminalOptions *options)
Packit Service 3bdf47
{
Packit Service 3bdf47
  gs_unref_object GSettings *global_settings =
Packit Service 3bdf47
    g_settings_new (TERMINAL_SETTING_SCHEMA);
Packit Service 3bdf47
Packit Service 3bdf47
  gs_free char *mode_str = g_settings_get_string (global_settings,
Packit Service 3bdf47
                                                  TERMINAL_SETTING_NEW_TERMINAL_MODE_KEY);
Packit Service 3bdf47
Packit Service 3bdf47
  gboolean implicit_if_first_window = g_str_equal (mode_str, "tab");
Packit Service 3bdf47
  ensure_top_window (options, implicit_if_first_window);
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
/**
Packit Service 3bdf47
 * terminal_options_free:
Packit Service 3bdf47
 * @options:
Packit Service 3bdf47
 *
Packit Service 3bdf47
 * Frees @options.
Packit Service 3bdf47
 */
Packit Service 3bdf47
void
Packit Service 3bdf47
terminal_options_free (TerminalOptions *options)
Packit Service 3bdf47
{
Packit Service 3bdf47
  g_list_free_full (options->initial_windows, (GDestroyNotify) initial_window_free);
Packit Service 3bdf47
Packit Service 3bdf47
  g_free (options->default_role);
Packit Service 3bdf47
  g_free (options->default_geometry);
Packit Service 3bdf47
  g_free (options->default_working_dir);
Packit Service 3bdf47
  g_free (options->default_title);
Packit Service 3bdf47
  g_free (options->default_profile);
Packit Service 3bdf47
Packit Service 3bdf47
  g_strfreev (options->exec_argv);
Packit Service 3bdf47
Packit Service 3bdf47
  g_free (options->server_unique_name);
Packit Service 3bdf47
  g_free (options->parent_screen_object_path);
Packit Service 3bdf47
Packit Service 3bdf47
  g_free (options->display_name);
Packit Service 3bdf47
  g_free (options->startup_id);
Packit Service 3bdf47
  g_free (options->server_app_id);
Packit Service 3bdf47
Packit Service 3bdf47
  g_free (options->sm_client_id);
Packit Service 3bdf47
  g_free (options->sm_config_prefix);
Packit Service 3bdf47
Packit Service 3bdf47
  g_clear_object (&options->profiles_list);
Packit Service 3bdf47
Packit Service 3bdf47
  g_free (options);
Packit Service 3bdf47
}
Packit Service 3bdf47
Packit Service 3bdf47
static GOptionContext *
Packit Service 3bdf47
get_goption_context (TerminalOptions *options)
Packit Service 3bdf47
{
Packit Service 3bdf47
  const GOptionEntry global_unique_goptions[] = {
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "app-id",
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_FLAG_HIDDEN,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      option_app_id_callback,
Packit Service 3bdf47
      "Server application ID",
Packit Service 3bdf47
      "ID"
Packit Service 3bdf47
    },
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "disable-factory",
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_FLAG_NO_ARG | G_OPTION_FLAG_HIDDEN,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      unsupported_option_fatal_callback,
Packit Service 3bdf47
      N_("Do not register with the activation nameserver, do not re-use an active terminal"),
Packit Service 3bdf47
      NULL
Packit Service 3bdf47
    },
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "load-config",
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_FLAG_FILENAME,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      option_load_config_cb,
Packit Service 3bdf47
      N_("Load a terminal configuration file"),
Packit Service 3bdf47
      N_("FILE")
Packit Service 3bdf47
    },
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "save-config",
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_FLAG_FILENAME | G_OPTION_FLAG_HIDDEN,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      unsupported_option_callback,
Packit Service 3bdf47
      NULL, NULL
Packit Service 3bdf47
    },
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "preferences",
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_ARG_NONE,
Packit Service 3bdf47
      &options->show_preferences,
Packit Service 3bdf47
      N_("Show preferences window"),
Packit Service 3bdf47
      NULL
Packit Service 3bdf47
    },
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "print-environment",
Packit Service 3bdf47
      'p',
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_ARG_NONE,
Packit Service 3bdf47
      &options->print_environment,
Packit Service 3bdf47
      N_("Print environment variables to interact with the terminal"),
Packit Service 3bdf47
      NULL
Packit Service 3bdf47
    },
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "version",
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_FLAG_NO_ARG | G_OPTION_FLAG_HIDDEN,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      option_version_cb,
Packit Service 3bdf47
      NULL,
Packit Service 3bdf47
      NULL
Packit Service 3bdf47
    },
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "verbose",
Packit Service 3bdf47
      'v',
Packit Service 3bdf47
      G_OPTION_FLAG_NO_ARG,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      option_verbosity_cb,
Packit Service 3bdf47
      N_("Increase diagnostic verbosity"),
Packit Service 3bdf47
      NULL
Packit Service 3bdf47
    },
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "quiet",
Packit Service 3bdf47
      'q',
Packit Service 3bdf47
      G_OPTION_FLAG_NO_ARG,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      option_verbosity_cb,
Packit Service 3bdf47
      N_("Suppress output"),
Packit Service 3bdf47
      NULL
Packit Service 3bdf47
    },
Packit Service 3bdf47
    { NULL, 0, 0, 0, NULL, NULL, NULL }
Packit Service 3bdf47
  };
Packit Service 3bdf47
Packit Service 3bdf47
  const GOptionEntry global_multiple_goptions[] = {
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "window",
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_FLAG_NO_ARG,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      option_window_callback,
Packit Service 3bdf47
      N_("Open a new window containing a tab with the default profile"),
Packit Service 3bdf47
      NULL
Packit Service 3bdf47
    },
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "tab",
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_FLAG_NO_ARG,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      option_tab_callback,
Packit Service 3bdf47
      N_("Open a new tab in the last-opened window with the default profile"),
Packit Service 3bdf47
      NULL
Packit Service 3bdf47
    },
Packit Service 3bdf47
    { NULL, 0, 0, 0, NULL, NULL, NULL }
Packit Service 3bdf47
  };
Packit Service 3bdf47
Packit Service 3bdf47
  const GOptionEntry window_goptions[] = {
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "show-menubar",
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_FLAG_NO_ARG,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      option_show_menubar_callback,
Packit Service 3bdf47
      N_("Turn on the menubar"),
Packit Service 3bdf47
      NULL
Packit Service 3bdf47
    },
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "hide-menubar",
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_FLAG_NO_ARG,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      option_hide_menubar_callback,
Packit Service 3bdf47
      N_("Turn off the menubar"),
Packit Service 3bdf47
      NULL
Packit Service 3bdf47
    },
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "maximize",
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_FLAG_NO_ARG,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      option_maximize_callback,
Packit Service 3bdf47
      N_("Maximize the window"),
Packit Service 3bdf47
      NULL
Packit Service 3bdf47
    },
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "full-screen",
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_FLAG_NO_ARG,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      option_fullscreen_callback,
Packit Service 3bdf47
      N_("Full-screen the window"),
Packit Service 3bdf47
      NULL
Packit Service 3bdf47
    },
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "geometry",
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      option_geometry_callback,
Packit Service 3bdf47
      N_("Set the window size; for example: 80x24, or 80x24+200+200 (COLSxROWS+X+Y)"),
Packit Service 3bdf47
      N_("GEOMETRY")
Packit Service 3bdf47
    },
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "role",
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      option_role_callback,
Packit Service 3bdf47
      N_("Set the window role"),
Packit Service 3bdf47
      N_("ROLE")
Packit Service 3bdf47
    },
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "active",
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_FLAG_NO_ARG,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      option_active_callback,
Packit Service 3bdf47
      N_("Set the last specified tab as the active one in its window"),
Packit Service 3bdf47
      NULL
Packit Service 3bdf47
    },
Packit Service 3bdf47
    { NULL, 0, 0, 0, NULL, NULL, NULL }
Packit Service 3bdf47
  };
Packit Service 3bdf47
Packit Service 3bdf47
  const GOptionEntry terminal_goptions[] = {
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "command",
Packit Service 3bdf47
      'e',
Packit Service 3bdf47
      G_OPTION_FLAG_FILENAME,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      option_command_callback,
Packit Service 3bdf47
      N_("Execute the argument to this option inside the terminal"),
Packit Service 3bdf47
      NULL
Packit Service 3bdf47
    },
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "profile",
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      option_profile_cb,
Packit Service 3bdf47
      N_("Use the given profile instead of the default profile"),
Packit Service 3bdf47
      N_("PROFILE-NAME")
Packit Service 3bdf47
    },
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "title",
Packit Service 3bdf47
      't',
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      option_title_callback,
Packit Service 3bdf47
      N_("Set the initial terminal title"),
Packit Service 3bdf47
      N_("TITLE")
Packit Service 3bdf47
    },
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "working-directory",
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_FLAG_FILENAME,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      option_working_directory_callback,
Packit Service 3bdf47
      N_("Set the working directory"),
Packit Service 3bdf47
      N_("DIRNAME")
Packit Service 3bdf47
    },
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "wait",
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_FLAG_NO_ARG,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      option_wait_cb,
Packit Service 3bdf47
      N_("Wait until the child exits"),
Packit Service 3bdf47
      NULL
Packit Service 3bdf47
    },
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "fd",
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      option_pass_fd_cb,
Packit Service 3bdf47
      N_("Forward file descriptor"),
Packit Service 3bdf47
      /* FD = file descriptor */
Packit Service 3bdf47
      N_("FD")
Packit Service 3bdf47
    },
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "zoom",
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      option_zoom_callback,
Packit Service 3bdf47
      N_("Set the terminal’s zoom factor (1.0 = normal size)"),
Packit Service 3bdf47
      N_("ZOOM")
Packit Service 3bdf47
    },
Packit Service 3bdf47
    { NULL, 0, 0, 0, NULL, NULL, NULL }
Packit Service 3bdf47
  };
Packit Service 3bdf47
Packit Service 3bdf47
  const GOptionEntry internal_goptions[] = {  
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "profile-id",
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_FLAG_HIDDEN,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      option_profile_id_cb,
Packit Service 3bdf47
      NULL, NULL
Packit Service 3bdf47
    },
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "window-with-profile",
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_FLAG_HIDDEN,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      option_window_callback,
Packit Service 3bdf47
      NULL, NULL
Packit Service 3bdf47
    },
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "tab-with-profile",
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_FLAG_HIDDEN,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      option_tab_callback,
Packit Service 3bdf47
      NULL, NULL
Packit Service 3bdf47
    },
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "window-with-profile-internal-id",
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_FLAG_HIDDEN,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      option_window_callback,
Packit Service 3bdf47
      NULL, NULL
Packit Service 3bdf47
    },
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "tab-with-profile-internal-id",
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_FLAG_HIDDEN,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      option_tab_callback,
Packit Service 3bdf47
      NULL, NULL
Packit Service 3bdf47
    },
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "default-working-directory",
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_FLAG_HIDDEN,
Packit Service 3bdf47
      G_OPTION_ARG_FILENAME,
Packit Service 3bdf47
      &options->default_working_dir,
Packit Service 3bdf47
      NULL, NULL,
Packit Service 3bdf47
    },
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "use-factory",
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_FLAG_NO_ARG | G_OPTION_FLAG_HIDDEN,
Packit Service 3bdf47
      G_OPTION_ARG_CALLBACK,
Packit Service 3bdf47
      unsupported_option_callback,
Packit Service 3bdf47
      NULL, NULL
Packit Service 3bdf47
    },
Packit Service 3bdf47
    {
Packit Service 3bdf47
      "startup-id",
Packit Service 3bdf47
      0,
Packit Service 3bdf47
      G_OPTION_FLAG_HIDDEN,
Packit Service 3bdf47
      G_OPTION_ARG_STRING,
Packit Service 3bdf47
      &options->startup_id,
Packit Service 3bdf47
      NULL,
Packit Service 3bdf47
      NULL
Packit Service 3bdf47
    },
Packit Service 3bdf47
    { NULL, 0, 0, 0, NULL, NULL, NULL }
Packit Service 3bdf47
  };
Packit Service 3bdf47
Packit Service 3bdf47
  const GOptionEntry smclient_goptions[] = {
Packit Service 3bdf47
    { "sm-client-disable",    0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE,     &options->sm_client_disable,    NULL, NULL },
Packit Service 3bdf47
    { "sm-client-state-file", 0, G_OPTION_FLAG_HIDDEN | G_OPTION_FLAG_FILENAME, G_OPTION_ARG_CALLBACK, option_load_config_cb, NULL, NULL },
Packit Service 3bdf47
    { "sm-client-id",         0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING,   &options->sm_client_id,         NULL, NULL },
Packit Service 3bdf47
    { "sm-disable",           0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE,     &options->sm_client_disable,    NULL, NULL },
Packit Service 3bdf47
    { "sm-config-prefix",     0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING,   &options->sm_config_prefix,     NULL, NULL },
Packit Service 3bdf47
    { NULL }
Packit Service 3bdf47
  };
Packit Service 3bdf47
Packit Service 3bdf47
  GOptionContext *context;
Packit Service 3bdf47
  GOptionGroup *group;
Packit Service 3bdf47
  gs_free char *parameter;
Packit Service 3bdf47
Packit Service 3bdf47
  parameter = g_strdup_printf ("[-- %s …]", _("COMMAND"));
Packit Service 3bdf47
  context = g_option_context_new (parameter);
Packit Service 3bdf47
  g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
Packit Service 3bdf47
  g_option_context_set_ignore_unknown_options (context, FALSE);
Packit Service 3bdf47
Packit Service 3bdf47
  g_option_context_add_group (context, gtk_get_option_group (TRUE));
Packit Service 3bdf47
Packit Service 3bdf47
  group = g_option_group_new ("gnome-terminal",
Packit Service 3bdf47
                              N_("GNOME Terminal Emulator"),
Packit Service 3bdf47
                              N_("Show GNOME Terminal options"),
Packit Service 3bdf47
                              options,
Packit Service 3bdf47
                              NULL);
Packit Service 3bdf47
  g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
Packit Service 3bdf47
  g_option_group_add_entries (group, global_unique_goptions);
Packit Service 3bdf47
  g_option_group_add_entries (group, internal_goptions);
Packit Service 3bdf47
  g_option_group_set_parse_hooks (group, NULL, digest_options_callback);
Packit Service 3bdf47
  g_option_context_set_main_group (context, group);
Packit Service 3bdf47
Packit Service 3bdf47
  group = g_option_group_new ("terminal",
Packit Service 3bdf47
                              N_("Options to open new windows or terminal tabs; more than one of these may be specified:"),
Packit Service 3bdf47
                              N_("Show terminal options"),
Packit Service 3bdf47
                              options,
Packit Service 3bdf47
                              NULL);
Packit Service 3bdf47
  g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
Packit Service 3bdf47
  g_option_group_add_entries (group, global_multiple_goptions);
Packit Service 3bdf47
  g_option_context_add_group (context, group);
Packit Service 3bdf47
Packit Service 3bdf47
  group = g_option_group_new ("window-options",
Packit Service 3bdf47
                              N_("Window options; if used before the first --window or --tab argument, sets the default for all windows:"),
Packit Service 3bdf47
                              N_("Show per-window options"),
Packit Service 3bdf47
                              options,
Packit Service 3bdf47
                              NULL);
Packit Service 3bdf47
  g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
Packit Service 3bdf47
  g_option_group_add_entries (group, window_goptions);
Packit Service 3bdf47
  g_option_context_add_group (context, group);
Packit Service 3bdf47
Packit Service 3bdf47
  group = g_option_group_new ("terminal-options",
Packit Service 3bdf47
                              N_("Terminal options; if used before the first --window or --tab argument, sets the default for all terminals:"),
Packit Service 3bdf47
                              N_("Show per-terminal options"),
Packit Service 3bdf47
                              options,
Packit Service 3bdf47
                              NULL);
Packit Service 3bdf47
  g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
Packit Service 3bdf47
  g_option_group_add_entries (group, terminal_goptions);
Packit Service 3bdf47
  g_option_context_add_group (context, group);
Packit Service 3bdf47
Packit Service 3bdf47
  group = g_option_group_new ("sm-client", "", "", options, NULL);
Packit Service 3bdf47
  g_option_group_add_entries (group, smclient_goptions);
Packit Service 3bdf47
  g_option_context_add_group (context, group);
Packit Service 3bdf47
Packit Service 3bdf47
  return context;
Packit Service 3bdf47
}