Index: configure.in
===================================================================
--- configure.in	(Revision 2281)
+++ configure.in	(Arbeitskopie)
@@ -30,6 +30,8 @@
 STARTUP_NOTIFICATION_REQUIRED=0.8
 VTE_REQUIRED=0.15.3
 GNOMEVFS_REQUIRED=2.4
+GLIB_REQUIRED=2.12.0
+LIBGNOME_REQUIRED=2.14.0
 
 ## here we get the flags we'll actually use
 PKG_CHECK_MODULES(TERM, dnl
@@ -37,9 +39,11 @@
  gconf-2.0 >= $GCONF_REQUIRED dnl
  libglade-2.0 dnl
  libgnomeui-2.0 dnl
+ libgnome-2.0 >= $LIBGNOME_REQUIRED dnl
  libstartup-notification-1.0 >= $STARTUP_NOTIFICATION_REQUIRED dnl
  vte >= $VTE_REQUIRED dnl
- gnome-vfs-2.0 >= $GNOMEVFS_REQUIRED)
+ gnome-vfs-2.0 >= $GNOMEVFS_REQUIRED dnl
+ glib-2.0 >= $GLIB_REQUIRED)
 
 TERM_LIBS="$X_LIBS $X_PRE_LIBS -lX11 $X_EXTRA_LIBS $TERM_LIBS"
 TERM_CFLAGS="$X_CFLAGS $TERM_CFLAGS"
Index: ChangeLog
===================================================================
--- ChangeLog	(Revision 2281)
+++ ChangeLog	(Arbeitskopie)
@@ -1,3 +1,9 @@
+2007-11-14  Christian Kirbach  <Christian.Kirbach@googlemail.com>
+ 
+ 	* src/terminal.c: Migrate from popt to GOption (bug #336155).
+ 	* configure.in: require glib >= 2.12.0, libgnome-2.0 >= 2.14.0.
+	  Some ideas stolen from Michael Plumb's initial patch.
+
 2007-11-09  Takao Fujiwara  <takao.fujiwara@sun.com>
 
 	Bug 471700 – gnome-terminal has an unlocalized license text.
Index: src/terminal.c
===================================================================
--- src/terminal.c	(Revision 2281)
+++ src/terminal.c	(Arbeitskopie)
@@ -38,7 +38,6 @@
 #include <libgnome/gnome-help.h>
 #include <libgnomeui/gnome-ui-init.h>
 #include <libgnomeui/gnome-client.h>
-#include <popt.h>
 #include <string.h>
 #include <stdlib.h>
 #include <time.h>
@@ -102,6 +101,30 @@
   char **post_execute_args;
 } OptionParsingResults;
 
+/* Command line options */
+static char     *option_command = NULL;
+static gboolean  option_execute = FALSE;
+static gboolean  option_window = FALSE;
+static char     *option_window_with_profile = NULL;
+static gboolean  option_tab = FALSE;
+static char     *option_tab_with_profile = NULL;
+static char     *option_window_with_profile_internal_id = NULL;
+static char     *option_tab_with_profile_internal_id = NULL;
+static char     *option_role = NULL;
+static gboolean  option_show_menubar = FALSE;
+static gboolean  option_hide_menubar = FALSE;
+static gboolean  option_fullscreen = FALSE;
+static char     *option_geometry = NULL;
+static gboolean  option_disable_factory = FALSE;
+static gboolean  option_use_factory = FALSE;
+static char     *option_startup_id = NULL;
+static char     *option_title = NULL;
+static char     *option_working_directory = NULL;
+static char     *option_default_working_directory = NULL;
+static char     *option_zoom = NULL;
+static gboolean  option_active = FALSE;
+
+
 static void         sync_profile_list            (gboolean use_this_list,
                                                   GSList  *this_list);
 static TerminalApp* terminal_app_new             (void);
@@ -134,239 +157,210 @@
 static gboolean terminal_invoke_factory (int argc, char **argv);
 static void option_parsing_results_free (OptionParsingResults *results);
 
+static gboolean post_options_callback   (GOptionContext *context,
+                                         GOptionGroup *group,
+                                         gpointer data,
+                                         GError **error);
 
-static void parse_options_callback (poptContext              ctx,
-                                    enum poptCallbackReason  reason,
-                                    const struct poptOption *opt,
-                                    const char              *arg,
-                                    void                    *data);
+static gboolean unsupported_option_callback  (const gchar *option_name,
+                                              const gchar *value,
+                                              gpointer data,
+		                              GError **error);
+
 static void client_die_cb          (GnomeClient             *client,
                                     gpointer                 data);
 
 static void handle_new_terminal_events (void);
 
-enum {
-  OPTION_COMMAND = 1,
-  OPTION_EXECUTE,
-  OPTION_WINDOW,
-  OPTION_WINDOW_WITH_PROFILE,
-  OPTION_TAB,
-  OPTION_TAB_WITH_PROFILE,
-  OPTION_WINDOW_WITH_PROFILE_ID,
-  OPTION_TAB_WITH_PROFILE_ID,
-  OPTION_ROLE,
-  OPTION_SHOW_MENUBAR,
-  OPTION_HIDE_MENUBAR,
-  OPTION_FULLSCREEN,
-  OPTION_GEOMETRY,
-  OPTION_DISABLE_FACTORY,
-  OPTION_USE_FACTORY,
-  OPTION_STARTUP_ID,
-  OPTION_TITLE,
-  OPTION_WORKING_DIRECTORY,
-  OPTION_DEFAULT_WORKING_DIRECTORY,
-  OPTION_ZOOM,
-  OPTION_ACTIVE,
-  OPTION_COMPAT,
-  OPTION_LAST
-};  
+char *test;
 
-struct poptOption options[] = {  
+static const GOptionEntry goptions[] = {  
   {
-    NULL, 
-    '\0', 
-    POPT_ARG_CALLBACK | POPT_CBFLAG_POST,
-    parse_options_callback, 
-    0, 
-    NULL, 
-    NULL
-  },
-  {
     "command",
     'e',
-    POPT_ARG_STRING,
-    NULL,
-    OPTION_COMMAND,
+    0,
+    G_OPTION_ARG_STRING,
+    &option_command,
     N_("Execute the argument to this option inside the terminal."),
     NULL
   },
   {
     "execute",
     'x',
-    POPT_ARG_NONE,
-    NULL,
-    OPTION_EXECUTE,
+    0,
+    G_OPTION_ARG_NONE,
+    &option_execute,
     N_("Execute the remainder of the command line inside the terminal."),
     NULL
   },
   {
     "window",
-    '\0',
-    POPT_ARG_NONE,
-    NULL,
-    OPTION_WINDOW,
+    0,
+    0,
+    G_OPTION_ARG_NONE,
+    &option_window,
     N_("Open a new window containing a tab with the default profile. More than one of these options can be provided."),
     NULL
   },
   {
     "window-with-profile",
-    '\0',
-    POPT_ARG_STRING,
-    NULL,
-    OPTION_WINDOW_WITH_PROFILE,
+    0,
+    0,
+    G_OPTION_ARG_STRING,
+    &option_window_with_profile,
     N_("Open a new window containing a tab with the given profile. More than one of these options can be provided."),
     N_("PROFILENAME")
   },
   {
     "tab",
-    '\0',
-    POPT_ARG_NONE,
-    NULL,
-    OPTION_TAB,
+    0,
+    0,
+    G_OPTION_ARG_NONE,
+    &option_tab,
     N_("Open a new tab in the last-opened window with the default profile. More than one of these options can be provided."),
     NULL
   },
   {
     "tab-with-profile",
-    '\0',
-    POPT_ARG_STRING,
-    NULL,
-    OPTION_TAB_WITH_PROFILE,
+    0,
+    0,
+    G_OPTION_ARG_STRING,
+    &option_tab_with_profile,
     N_("Open a new tab in the last-opened window with the given profile. More than one of these options can be provided."),
     N_("PROFILENAME")
   },
   {
     "window-with-profile-internal-id",
-    '\0',
-    POPT_ARG_STRING,
-    NULL,
-    OPTION_WINDOW_WITH_PROFILE_ID,
+    0,
+    0,
+    G_OPTION_ARG_STRING,
+    &option_window_with_profile_internal_id,
     N_("Open a new window containing a tab with the given profile ID. Used internally to save sessions."),
     N_("PROFILEID")
   },
   {
     "tab-with-profile-internal-id",
-    '\0',
-    POPT_ARG_STRING,
-    NULL,
-    OPTION_TAB_WITH_PROFILE_ID,
+    0,
+    0,
+    G_OPTION_ARG_STRING,
+    &option_tab_with_profile_internal_id,
     N_("Open a new tab in the last-opened window with the given profile ID. Used internally to save sessions."),
     N_("PROFILEID")
   },
   {
     "role",
-    '\0',
-    POPT_ARG_STRING,
-    NULL,
-    OPTION_ROLE,
+    0,
+    0,
+    G_OPTION_ARG_STRING,
+    &option_role,
     N_("Set the role for the last-specified window; applies to only one window; can be specified once for each window you create from the command line."),
     N_("ROLE")
   },
   {
     "show-menubar",
-    '\0',
-    POPT_ARG_NONE,
-    NULL,
-    OPTION_SHOW_MENUBAR,
+    0,
+    0,
+    G_OPTION_ARG_NONE,
+    &option_show_menubar,
     N_("Turn on the menubar for the last-specified window; applies to only one window; can be specified once for each window you create from the command line."),
     NULL
   },
   {
     "hide-menubar",
-    '\0',
-    POPT_ARG_NONE,
-    NULL,
-    OPTION_HIDE_MENUBAR,
+    0,
+    0,
+    G_OPTION_ARG_NONE,
+    &option_hide_menubar,
     N_("Turn off the menubar for the last-specified window; applies to only one window; can be specified once for each window you create from the command line."),
     NULL
   },
   {
     "full-screen",
-    '\0',
-    POPT_ARG_NONE,
-    NULL,
-    OPTION_FULLSCREEN,
+    0,
+    0,
+    G_OPTION_ARG_NONE,
+    &option_fullscreen,
     N_("Set the last-specified window into fullscreen mode; applies to only one window; can be specified once for each window you create from the command line."),
     NULL
   },
   {
     "geometry",
-    '\0',
-    POPT_ARG_STRING,
-    NULL,
-    OPTION_GEOMETRY,
+    0,
+    0,
+    G_OPTION_ARG_STRING,
+    &option_geometry,
     N_("X geometry specification (see \"X\" man page), can be specified once per window to be opened."),
     N_("GEOMETRY")
   },
   {
     "disable-factory",
-    '\0',
-    POPT_ARG_NONE,
-    NULL,
-    OPTION_DISABLE_FACTORY,
+    0,
+    0,
+    G_OPTION_ARG_NONE,
+    &option_disable_factory,
     N_("Do not register with the activation nameserver, do not re-use an active terminal"),
     NULL
   },
   {
     "use-factory",
-    '\0',
-    POPT_ARG_NONE,
-    NULL,
-    OPTION_USE_FACTORY,
+    0,
+    0,
+    G_OPTION_ARG_NONE,
+    &option_use_factory,
     N_("Register with the activation nameserver [default]"),
     NULL
   },
   {
     "startup-id",
-    '\0',
-    POPT_ARG_STRING,
-    NULL,
-    OPTION_STARTUP_ID,
+    0,
+    0,
+    G_OPTION_ARG_STRING,
+    &option_startup_id,
     N_("ID for startup notification protocol."),
     NULL
   },
   {
     "title",
     't',
-    POPT_ARG_STRING,
-    NULL,
-    OPTION_TITLE,
+    0,
+    G_OPTION_ARG_STRING,
+    &option_title,
     N_("Set the terminal's title"),
     N_("TITLE")
   },
   {
     "working-directory",
-    '\0',
-    POPT_ARG_STRING,
-    NULL,
-    OPTION_WORKING_DIRECTORY,
+    0,
+    0,
+    G_OPTION_ARG_FILENAME,
+    &option_working_directory,
     N_("Set the terminal's working directory"),
     N_("DIRNAME")
   },
   {
     "default-working-directory",
-    '\0',
-    POPT_ARG_STRING,
-    NULL,
-    OPTION_DEFAULT_WORKING_DIRECTORY,
+    0,
+    0,
+    G_OPTION_ARG_FILENAME,
+    &option_default_working_directory,
     N_("Set the default terminal's working directory. Used internally"),
     N_("DIRNAME")
   },
   {
     "zoom",
-    '\0',
-    POPT_ARG_STRING,
-    NULL,
-    OPTION_ZOOM,
+    0,
+    0,
+    G_OPTION_ARG_STRING,
+    &option_zoom,
     N_("Set the terminal's zoom factor (1.0 = normal size)"),
     N_("ZOOMFACTOR")
   },
   {
     "active",
-    '\0',
-    POPT_ARG_NONE,
-    NULL,
-    OPTION_ACTIVE,
+    0,
+    0,
+    G_OPTION_ARG_NONE,
+    &option_active,
     N_("Set the last specified tab as the active one in its window"),
     N_("ZOOMFACTOR")
   },
@@ -376,179 +370,173 @@
    */
   {
     "tclass",
-    '\0',
-    POPT_ARG_STRING | POPT_ARGFLAG_DOC_HIDDEN,
-    NULL,
-    OPTION_COMPAT,
+    0,
+    G_OPTION_FLAG_HIDDEN,
+    G_OPTION_ARG_CALLBACK,
+    unsupported_option_callback,
     NULL, NULL
   },
   {
     "font",
-    '\0',
-    POPT_ARG_STRING | POPT_ARGFLAG_DOC_HIDDEN,
-    NULL,
-    OPTION_COMPAT,
+    0,
+    G_OPTION_FLAG_HIDDEN,
+    G_OPTION_ARG_CALLBACK,
+    unsupported_option_callback,
     NULL, NULL
   },  
   {
     "nologin",
-    '\0',
-    POPT_ARG_NONE | POPT_ARGFLAG_DOC_HIDDEN,
-    NULL,
-    OPTION_COMPAT,
+    0,
+    G_OPTION_FLAG_HIDDEN,
+    G_OPTION_ARG_CALLBACK,
+    unsupported_option_callback,
     NULL, NULL
   },
   {
     "login",
-    '\0',
-    POPT_ARG_NONE | POPT_ARGFLAG_DOC_HIDDEN,
-    NULL,
-    OPTION_COMPAT,
+    0,
+    G_OPTION_FLAG_HIDDEN,
+    G_OPTION_ARG_CALLBACK,
+    unsupported_option_callback,
     NULL, NULL
   },
   {
     "foreground",
-    '\0',
-    POPT_ARG_STRING | POPT_ARGFLAG_DOC_HIDDEN,
-    NULL,
-    OPTION_COMPAT,
+    0,
+    G_OPTION_FLAG_HIDDEN,
+    G_OPTION_ARG_CALLBACK,
+    unsupported_option_callback,
     NULL, NULL
   },  
   {
     "background",
-    '\0',
-    POPT_ARG_STRING | POPT_ARGFLAG_DOC_HIDDEN,
-    NULL,
-    OPTION_COMPAT,
+    0,
+    G_OPTION_FLAG_HIDDEN,
+    G_OPTION_ARG_CALLBACK,
+    unsupported_option_callback,
     NULL, NULL
   },
   {
     "solid",
-    '\0',
-    POPT_ARG_NONE | POPT_ARGFLAG_DOC_HIDDEN,
-    NULL,
-    OPTION_COMPAT,
+    0,
+    G_OPTION_FLAG_HIDDEN,
+    G_OPTION_ARG_CALLBACK,
+    unsupported_option_callback,
     NULL, NULL
   },
   {
     "bgscroll",
-    '\0',
-    POPT_ARG_NONE | POPT_ARGFLAG_DOC_HIDDEN,
-    NULL,
-    OPTION_COMPAT,
+    0,
+    G_OPTION_FLAG_HIDDEN,
+    G_OPTION_ARG_CALLBACK,
+    unsupported_option_callback,
     NULL, NULL
   },
   {
     "bgnoscroll",
-    '\0',
-    POPT_ARG_NONE | POPT_ARGFLAG_DOC_HIDDEN,
-    NULL,
-    OPTION_COMPAT,
+    0,
+    G_OPTION_FLAG_HIDDEN,
+    G_OPTION_ARG_CALLBACK,
+    unsupported_option_callback,
     NULL, NULL
   },  
   {
     "shaded",
-    '\0',
-    POPT_ARG_NONE | POPT_ARGFLAG_DOC_HIDDEN,
-    NULL,
-    OPTION_COMPAT,
+    0,
+    G_OPTION_FLAG_HIDDEN,
+    G_OPTION_ARG_CALLBACK,
+    unsupported_option_callback,
     NULL, NULL
   },  
   {
     "noshaded",
-    '\0',
-    POPT_ARG_NONE | POPT_ARGFLAG_DOC_HIDDEN,
-    NULL,
-    OPTION_COMPAT,
+    0,
+    G_OPTION_FLAG_HIDDEN,
+    G_OPTION_ARG_CALLBACK,
+    unsupported_option_callback,
     NULL, NULL
   },  
   {
     "transparent",
-    '\0',
-    POPT_ARG_NONE | POPT_ARGFLAG_DOC_HIDDEN,
-    NULL,
-    OPTION_COMPAT,
+    0,
+    G_OPTION_FLAG_HIDDEN,
+    G_OPTION_ARG_CALLBACK,
+    unsupported_option_callback,
     NULL, NULL
   },  
   {
     "utmp",
-    '\0',
-    POPT_ARG_NONE | POPT_ARGFLAG_DOC_HIDDEN,
-    NULL,
-    OPTION_COMPAT,
+    0,
+    G_OPTION_FLAG_HIDDEN,
+    G_OPTION_ARG_CALLBACK,
+    unsupported_option_callback,
     NULL, NULL
   },  
   {
     "noutmp",
-    '\0',
-    POPT_ARG_NONE | POPT_ARGFLAG_DOC_HIDDEN,
-    NULL,
-    OPTION_COMPAT,
+    0,
+    G_OPTION_FLAG_HIDDEN,
+    G_OPTION_ARG_CALLBACK,
+    unsupported_option_callback,
     NULL, NULL
   },  
   {
     "wtmp",
-    '\0',
-    POPT_ARG_NONE | POPT_ARGFLAG_DOC_HIDDEN,
-    NULL,
-    OPTION_COMPAT,
+    0,
+    G_OPTION_FLAG_HIDDEN,
+    G_OPTION_ARG_CALLBACK,
+    unsupported_option_callback,
     NULL, NULL
   },
   {
     "nowtmp",
-    '\0',
-    POPT_ARG_NONE | POPT_ARGFLAG_DOC_HIDDEN,
-    NULL,
-    OPTION_COMPAT,
+    0,
+    G_OPTION_FLAG_HIDDEN,
+    G_OPTION_ARG_CALLBACK,
+    unsupported_option_callback,
     NULL, NULL
   },  
   {
     "lastlog",
-    '\0',
-    POPT_ARG_NONE | POPT_ARGFLAG_DOC_HIDDEN,
-    NULL,
-    OPTION_COMPAT,
+    0,
+    G_OPTION_FLAG_HIDDEN,
+    G_OPTION_ARG_CALLBACK,
+    unsupported_option_callback,
     NULL, NULL
   },  
   {
     "nolastlog",
-    '\0',
-    POPT_ARG_NONE | POPT_ARGFLAG_DOC_HIDDEN,
-    NULL,
-    OPTION_COMPAT,
+    0,
+    G_OPTION_FLAG_HIDDEN,
+    G_OPTION_ARG_CALLBACK,
+    unsupported_option_callback,
     NULL, NULL
   },
   {
     "icon",
-    '\0',
-    POPT_ARG_STRING | POPT_ARGFLAG_DOC_HIDDEN,
-    NULL,
-    OPTION_COMPAT,
+    0,
+    G_OPTION_FLAG_HIDDEN,
+    G_OPTION_ARG_CALLBACK,
+    unsupported_option_callback,
     NULL, NULL
   },  
   {
     "termname",
-    '\0',
-    POPT_ARG_STRING | POPT_ARGFLAG_DOC_HIDDEN,
-    NULL,
-    OPTION_COMPAT,
+    0,
+    G_OPTION_FLAG_HIDDEN,
+    G_OPTION_ARG_CALLBACK,
+    unsupported_option_callback,
     NULL, NULL
   },
   {
     "start-factory-server",
-    '\0',
-    POPT_ARG_NONE | POPT_ARGFLAG_DOC_HIDDEN,
-    NULL,
-    OPTION_COMPAT,
+    0,
+    G_OPTION_FLAG_HIDDEN,
+    G_OPTION_ARG_CALLBACK,
+    unsupported_option_callback,
     NULL, NULL
   },
   {
-    NULL,
-    '\0',
-    0,
-    NULL,
-    0,
-    NULL,
     NULL
   }
 };
@@ -742,446 +730,411 @@
   return iw;
 }
 
-static void
-parse_options_callback (poptContext              ctx,
-                        enum poptCallbackReason  reason,
-                        const struct poptOption *opt,
-                        const char              *arg,
-                        void                    *data)
+static gboolean
+unsupported_option_callback (const gchar *option_name,
+                             const gchar *value,
+                             gpointer data,
+                             GError **error)
 {
-  OptionParsingResults *results;
+  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;
+}
 
+static gboolean
+post_options_callback (GOptionContext *context,
+                       GOptionGroup *group,
+                       gpointer data,
+                       GError **error)
+{
+  OptionParsingResults *results;
   results = data;
+	
+  GError *err;
+  char   **exec_argv;
+  InitialTab    *it;
+  InitialWindow *iw;
 
-  if (reason == POPT_CALLBACK_REASON_POST)
-    {
-      /* Make sure we have some window */
-      if (results->initial_windows == NULL)
-        ensure_top_window (results);
-
-      return;
-    }
-  else if (reason != POPT_CALLBACK_REASON_OPTION)
-    return;
-
-  switch (opt->val & POPT_ARG_MASK)
-    {
-    case OPTION_COMMAND:
-      {
-        GError *err;
-        InitialTab *it;
-        char **exec_argv;
+  
+/* OPTION_COMMAND */
+  if (option_command)
+    { 
+      if (strlen(option_command) == 0)
+        {
+          g_printerr (_("Option \"%s\" requires specifying the command to run\n"), "--command/-e");
+          exit (1);
+        }
             
-
-        if (arg == NULL)
-          {
-            g_printerr (_("Option \"%s\" requires specifying the command to run\n"), "--command/-e");
-            exit (1);
-          }
-            
-        err = NULL;
-        exec_argv = NULL;
-        if (!g_shell_parse_argv (arg, NULL, &exec_argv, &err))
-          {
-            g_printerr (_("Argument to \"%s\" is not a valid command: %s\n"),
+      err = NULL;
+      exec_argv = NULL;
+      if (!g_shell_parse_argv (option_command, NULL, &exec_argv, &err))
+        {
+          g_printerr (_("Argument to \"%s\" is not a valid command: %s\n"),
                         "--command/-e", err->message);
-            g_error_free (err);
-            exit (1);
-          }
+          g_error_free (err);
+          exit (1);
+        }
 
-        it = ensure_top_tab (results);
+      it = ensure_top_tab (results);
 
-        if (it->exec_argv != NULL)
-          {
-            g_printerr (_("\"%s\" specified more than once for the same window or tab\n"),
+      if (it->exec_argv != NULL)
+        {
+          g_printerr (_("\"%s\" specified more than once for the same window or tab\n"),
                         "--command/-e/--execute/-x");
-            exit (1);
-          }
+          exit (1);
+        }
 
-        it->exec_argv = exec_argv;
-      }
-      break;
+      it->exec_argv = exec_argv;
+    }
+     
+/*  OPTION_EXECUTE */
+  if (option_execute)
+    {         
+      if (results->post_execute_args == NULL)
+        {
+          g_printerr (_("Option \"%s\" requires specifying the command to run on the rest of the command line\n"),
+                      "--execute/-x");
+          exit (1);
+        }
 
-    case OPTION_EXECUTE:
-      {
-        InitialTab *it;
-            
-        if (results->post_execute_args == NULL)
-          {
-            g_printerr (_("Option \"%s\" requires specifying the command to run on the rest of the command line\n"),
-                        "--execute/-x");
-            exit (1);
-          }
+      it = ensure_top_tab (results);
 
-        it = ensure_top_tab (results);
+      if (it->exec_argv != NULL)
+        {
+          g_printerr (_("\"%s\" specified more than once for the same window or tab\n"),
+                      "--command/-e/--execute/-x");
+          exit (1);
+        }
 
-        if (it->exec_argv != NULL)
+      it->exec_argv = results->post_execute_args;
+      results->post_execute_args = NULL;
+    } 
+         
+/*  OPTION_WINDOW */
+/*  OPTION_WINDOW_WITH_PROFILE */
+/*  OPTION_WINDOW_WITH_PROFILE_ID */
+  if (option_window ||
+      option_window_with_profile ||
+      option_window_with_profile_internal_id)
+    {
+      const char *profile;
+		
+      if (option_window)
+        profile = NULL;
+      else 
+		if (strlen(option_window_with_profile) == 0 ||
+            strlen(option_window_with_profile_internal_id) == 0)
           {
-            g_printerr (_("\"%s\" specified more than once for the same window or tab\n"),
-                        "--command/-e/--execute/-x");
-            exit (1);
-          }
-
-        it->exec_argv = results->post_execute_args;
-        results->post_execute_args = NULL;
-      }
-      break;
-          
-    case OPTION_WINDOW:
-    case OPTION_WINDOW_WITH_PROFILE:
-    case OPTION_WINDOW_WITH_PROFILE_ID:
-      {
-        InitialWindow *iw;
-        const char *profile;
-
-
-        if (opt->val == OPTION_WINDOW)
-          profile = NULL;
-        else if (arg == NULL)
-          {
             g_printerr (_("Option \"%s\" requires an argument specifying what profile to use\n"),
                         "--window-with-profile");
             exit (1);
           }
         else
-          profile = arg;
-
+          {
+            if (strlen(option_window_with_profile)) 
+              profile = option_window_with_profile;
+            if (strlen(option_window_with_profile_internal_id))
+              profile = option_window_with_profile_internal_id;
+          }
         iw = add_new_window (results, profile,
-                             opt->val == OPTION_WINDOW_WITH_PROFILE_ID);
-      }
-      break;
+                             strlen(option_window_with_profile_internal_id) ?
+							                                      TRUE : FALSE);
+     }                       
 
-    case OPTION_TAB:
-    case OPTION_TAB_WITH_PROFILE:
-    case OPTION_TAB_WITH_PROFILE_ID:
-      {
-        InitialWindow *iw;
-        const char *profile;
+/*  OPTION_TAB */
+/*  OPTION_TAB_WITH_PROFILE */
+/*  OPTION_TAB_WITH_PROFILE_ID */
+  if (option_tab ||
+      option_tab_with_profile ||
+      option_tab_with_profile_internal_id)
+    {
+      const char *profile;
 
-
-        if (opt->val == OPTION_TAB)
-          profile = NULL;
-        else if (arg == NULL)
+      if (option_tab)
+        profile = NULL;
+      else 
+		if (strlen(option_tab_with_profile) == 0 &&
+			strlen(option_tab_with_profile_internal_id) == 0)
           {
             g_printerr (_("Option \"%s\" requires an argument specifying what profile to use\n"),
-                        "--tab-with-profile");
+                        "--tab-with-profile(-id)");
             exit (1);
           }
         else
-          profile = arg;
+          if (strlen(option_tab_with_profile))
+			profile = option_tab_with_profile;
+		  else
+			profile = option_tab_with_profile_internal_id;
 
                 
-        if (results->initial_windows)
-          {
-            iw = g_list_last (results->initial_windows)->data;
+       if (results->initial_windows)
+         {
+           iw = g_list_last (results->initial_windows)->data;
 
-            iw->tabs = g_list_append (iw->tabs,
-                                      initial_tab_new (profile,
-                                                       opt->val == OPTION_TAB_WITH_PROFILE_ID));
-          }
-        else
-          {
-            iw = add_new_window (results, profile, 
-                                 opt->val == OPTION_TAB_WITH_PROFILE_ID);
-          }
-      }
-      break;
-          
-    case OPTION_SHOW_MENUBAR:
-      {
-        InitialWindow *iw;
+           iw->tabs = 
+		       g_list_append (iw->tabs,
+                              initial_tab_new (profile,
+                              strlen(option_tab_with_profile_internal_id) ?
+										                        TRUE:FALSE));
+         }
+       else
+         {
+           iw = add_new_window (results, profile, 
+                                strlen(option_tab_with_profile_internal_id) ?
+								                                 TRUE:FALSE);
+         }
+	  }
+	
+/*  OPTION_SHOW_MENUBAR */
+  if (option_show_menubar)
+    {
             
-        if (results->initial_windows)
-          {
-            iw = g_list_last (results->initial_windows)->data;
+      if (results->initial_windows)
+        {
+          iw = g_list_last (results->initial_windows)->data;
 
-            if (iw->force_menubar_state)
-              {
-                g_printerr (_("\"%s\" option given twice for the same window\n"), "--show-menubar");
+          if (iw->force_menubar_state)
+            {
+              g_printerr (_("\"%s\" option given twice for the same window\n"), "--show-menubar");
 
-                exit (1);
-              }
+              exit (1);
+            }
                 
-            iw->force_menubar_state = TRUE;
-            iw->menubar_state = TRUE;
-          }
-        else
-          {
-            results->default_window_menubar_forced = TRUE;
-            results->default_window_menubar_state = TRUE;
-          }
-      }
-      break;
-          
-    case OPTION_HIDE_MENUBAR:
-      {
-        InitialWindow *iw;
-            
-        if (results->initial_windows)
-          {
-            iw = g_list_last (results->initial_windows)->data;
+          iw->force_menubar_state = TRUE;
+          iw->menubar_state = TRUE;
+        }
+      else
+        {
+          results->default_window_menubar_forced = TRUE;
+          results->default_window_menubar_state = TRUE;
+        }
+    }
+   
+/*  OPTION_HIDE_MENUBAR */
+  if (option_hide_menubar)
+    {         
+      if (results->initial_windows)
+        {
+          iw = g_list_last (results->initial_windows)->data;
 
-            if (iw->force_menubar_state)
-              {
-                g_printerr (_("\"%s\" option given twice for the same window\n"), "--hide-menubar");
+          if (iw->force_menubar_state)
+            {
+              g_printerr (_("\"%s\" option given twice for the same window\n"), "--hide-menubar");
 
-                exit (1);
-              }
+              exit (1);
+            }
                 
-            iw->force_menubar_state = TRUE;
-            iw->menubar_state = FALSE;                
-          }
-        else
-          {
-            results->default_window_menubar_forced = TRUE;
-            results->default_window_menubar_state = FALSE;
-          }
-      }
-      break;
+          iw->force_menubar_state = TRUE;
+          iw->menubar_state = FALSE;                
+        }
+      else
+        {
+          results->default_window_menubar_forced = TRUE;
+          results->default_window_menubar_state = FALSE;
+        }
+    }
+      
+/*  OPTION_FULLSCREEN */
+  if (option_fullscreen)
+    {           
+      if (results->initial_windows)
+        {
+          iw = g_list_last (results->initial_windows)->data;
 
-    case OPTION_FULLSCREEN:
-      {
-        InitialWindow *iw;
-            
-        if (results->initial_windows)
-          {
-            iw = g_list_last (results->initial_windows)->data;
+          iw->start_fullscreen = TRUE;
+        }
+      else
+        {
+          results->default_start_fullscreen = TRUE;
+        }
+    }      
 
-            iw->start_fullscreen = TRUE;
-          }
-        else
-          {
-            results->default_start_fullscreen = TRUE;
-          }
-      }
-      break;
-
-    case OPTION_ROLE:
-      {
-        InitialWindow *iw;
-
-
-        if (arg == NULL)
-          {
-            g_printerr (_("Option \"%s\" requires an argument giving the role\n"), "--role");
-            exit (1);
-          }
+/*  OPTION_ROLE */
+  if (option_role)
+    {
+      if (strlen(option_role) == 0)
+        {
+          g_printerr (_("Option \"%s\" requires an argument giving the role\n"), "--role");
+          exit (1);
+        }
             
-        if (results->initial_windows)
-          {
-            iw = g_list_last (results->initial_windows)->data;
-            if (iw->role)
-              {
-                g_printerr (_("Two roles given for one window\n"));
-                exit (1);
-              }
+      if (results->initial_windows)
+        {
+          iw = g_list_last (results->initial_windows)->data;
+          if (iw->role)
+            {
+              g_printerr (_("Two roles given for one window\n"));
+              exit (1);
+            }
 
-            iw->role = g_strdup (arg);
-          }
-      }
-      break;
+          iw->role = g_strdup (option_role);
+        }
+    }
 
-    case OPTION_GEOMETRY:
-      {
-        InitialWindow *iw;
-
-
-        if (arg == NULL)
-          {
-            g_printerr (_("Option \"%s\" requires an argument giving the geometry\n"), "--geometry");
-            exit (1);
-          }
+/*  OPTION_GEOMETRY */
+  if (option_geometry)
+    {
+      if (strlen(option_geometry) == 0)
+        {
+          g_printerr (_("Option \"%s\" requires an argument giving the geometry\n"), "--geometry");
+          exit (1);
+        }
             
-        if (results->initial_windows)
-          {
-            iw = g_list_last (results->initial_windows)->data;
-            if (iw->geometry)
-              {
-                g_printerr (_("Two \"%s\" options given for one window\n"), "--geometry");
-                exit (1);
-              }
+      if (results->initial_windows)
+        {
+          iw = g_list_last (results->initial_windows)->data;
+          if (iw->geometry)
+            {
+              g_printerr (_("Two \"%s\" options given for one window\n"), "--geometry");
+              exit (1);
+            }
 
-            iw->geometry = g_strdup (arg);
-          }
-        else
-          {
-            if (results->default_geometry)
-              {
-                g_printerr (_("Two geometries given for one window\n"));
-                exit (1);
-              }
-            else
-              {
-                results->default_geometry = g_strdup (arg);
-              }
-          }
-      }
-      break;
+          iw->geometry = g_strdup (option_geometry);
+        }
+      else
+        {
+          if (results->default_geometry)
+            {
+              g_printerr (_("Two geometries given for one window\n"));
+              exit (1);
+            }
+          else
+            {
+              results->default_geometry = g_strdup (option_geometry);
+            }
+        }
+    }
+	
+/*  OPTION_DISABLE_FACTORY */
+  if (option_disable_factory)
+    terminal_factory_disabled = TRUE;
 
-    case OPTION_DISABLE_FACTORY:
-      terminal_factory_disabled = TRUE;
-      break;
+/*  OPTION_USE_FACTORY */
+  if (option_use_factory)
+    terminal_factory_disabled = FALSE;
 
-    case OPTION_USE_FACTORY:
-      terminal_factory_disabled = FALSE;
-      break;
+/*  OPTION_TITLE */            
+  if (option_title)
+    {
+      if (strlen(option_title) == 0)
+        {
+          g_printerr (_("Option \"%s\" requires an argument giving the title\n"), "--title");
+          exit (1);
+        }
 
-    case OPTION_TITLE:
-      {
-        InitialTab *it;
-            
+      it = ensure_top_tab (results);
 
-        if (arg == NULL)
-          {
-            g_printerr (_("Option \"%s\" requires an argument giving the title\n"), "--title");
-            exit (1);
-          }
+	  if (it->title)
+        {
+          g_printerr (_("Two \"%s\" options given for one tab\n"), "--title");
+          exit (1);
+        }
 
-        it = ensure_top_tab (results);
+      it->title = g_strdup (option_title);
+    }
 
-        if (it->title)
-          {
-            g_printerr (_("Two \"%s\" options given for one tab\n"), "--title");
-            exit (1);
-          }
+/*  OPTION_WORKING_DIRECTORY */
+  if (option_working_directory)
+    {
+      if (strlen(option_working_directory) == 0)
+        {
+          g_printerr (_("Option \"%s\" requires an argument giving the directory\n"), "--working-directory");
+          exit (1);
+        }
 
-        it->title = g_strdup (arg);
-      }
-      break;
+      it = ensure_top_tab (results);
 
-    case OPTION_WORKING_DIRECTORY:
-      {
-        InitialTab *it;
-            
+      if (it->working_dir)
+        {
+          g_printerr (_("Two \"%s\" options given for one tab\n"), "--working-directory");
+          exit (1);
+        }
 
-        if (arg == NULL)
-          {
-            g_printerr (_("Option \"%s\" requires an argument giving the directory\n"), "--working-directory");
-            exit (1);
-          }
+      it->working_dir = g_strdup (option_working_directory);
+	}
 
-        it = ensure_top_tab (results);
+/*  OPTION_DEFAULT_WORKING_DIRECTORY */
+  if (option_default_working_directory)
+    {
+      if (strlen(option_working_directory) == 0)
+        {
+          g_printerr (_("Option --default-working-directory requires an argument giving the directory\n"));
+          exit (1);
+        }
 
-        if (it->working_dir)
-          {
-            g_printerr (_("Two \"%s\" options given for one tab\n"), "--working-directory");
-            exit (1);
-          }
+      if (results->default_working_dir)
+        {
+          g_printerr (_("Two --default-working-directories given\n"));
+          exit (1);
+        }
 
-        it->working_dir = g_strdup (arg);
-      }
-      break;
+      results->default_working_dir = g_strdup (option_working_directory);
+	}
 
-    case OPTION_DEFAULT_WORKING_DIRECTORY:
-      {
-        if (arg == NULL)
-          {
-            g_printerr (_("Option --default-working-directory requires an argument giving the directory\n"));
-            exit (1);
-          }
-
-        if (results->default_working_dir)
-          {
-            g_printerr (_("Two --default-working-directories given\n"));
-            exit (1);
-          }
-
-        results->default_working_dir = g_strdup (arg);
-      }
-      break;
-
-    case OPTION_ZOOM:
-      {
-        InitialTab *it;            
-        double val;
-        char *end;
+/*  OPTION_ZOOM */
+  if (option_zoom)
+    {
+      double val;
+      char *end;
         
-        if (arg == NULL)
-          {
-            g_printerr (_("Option \"%s\" requires an argument giving the zoom factor\n"), "--zoom");
-            exit (1);
-          }
+      if (strlen(option_zoom) == 0)
+        {
+          g_printerr (_("Option \"%s\" requires an argument giving the zoom factor\n"), "--zoom");
+          exit (1);
+        }
 
-        it = ensure_top_tab (results);
+      it = ensure_top_tab (results);
 
-        if (it->zoom_set)
-          {
-            g_printerr (_("Two \"%s\" options given for one tab\n"), "--zoom");
-            exit (1);
-          }
-
-        /* 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;
-        val = g_strtod (arg, &end);
-        if (end == NULL || *end != '\0')
-          {
-            val = g_ascii_strtod (arg, &end);
-            if (end == NULL || *end != '\0')
-              {
-                g_printerr (_("\"%s\" is not a valid zoom factor\n"),
-                            arg);
-                exit (1);
-              }
-          }
-
-        if (val < (TERMINAL_SCALE_MINIMUM + 1e-6))
-          {
-            g_printerr (_("Zoom factor \"%g\" is too small, using %g\n"),
-                        val, TERMINAL_SCALE_MINIMUM);
-            val = TERMINAL_SCALE_MINIMUM;
-          }
-
-        if (val > (TERMINAL_SCALE_MAXIMUM - 1e-6))
-          {
-            g_printerr (_("Zoom factor \"%g\" is too large, using %g\n"),
-                        val, TERMINAL_SCALE_MAXIMUM);
-            val = TERMINAL_SCALE_MAXIMUM;
-          }
-        
-        it->zoom = val;
-        it->zoom_set = TRUE;
-      }
-      break;
-
-    case OPTION_ACTIVE:
-      {
-        InitialTab *it;
-
-        it = ensure_top_tab (results);
-
-        it->active = TRUE;
-      }
-      break;
-      
-    case OPTION_COMPAT:
-      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"), opt->longName);
-      break;
-
-    case OPTION_STARTUP_ID:
-      if (results->startup_id != NULL)
+      if (it->zoom_set)
         {
-          g_printerr (_("\"%s\" option given twice\n"), "--startup-id");
+          g_printerr (_("Two \"%s\" options given for one tab\n"), "--zoom");
           exit (1);
         }
-      else if (arg == NULL)
+
+      /* 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;
+      val = g_strtod (option_zoom, &end);
+      if (end == NULL || *end != '\0')
         {
-          g_printerr (_("\"%s\" option requires an argument\n"), "--startup-id");
-          exit (1);
+          val = g_ascii_strtod (option_zoom, &end);
+          if (end == NULL || *end != '\0')
+            {
+              g_printerr (_("\"%s\" is not a valid zoom factor\n"),
+                          option_zoom);
+              exit (1);
+            }
         }
-      else
+
+      if (val < (TERMINAL_SCALE_MINIMUM + 1e-6))
         {
-          results->startup_id = g_strdup (arg);
+          g_printerr (_("Zoom factor \"%g\" is too small, using %g\n"),
+                      val, TERMINAL_SCALE_MINIMUM);
+          val = TERMINAL_SCALE_MINIMUM;
         }
-      break;
-      
-    case OPTION_LAST:
-      g_assert_not_reached ();
-      break;
-      /* no default so we get warnings on missing items */
-    }
+
+      if (val > (TERMINAL_SCALE_MAXIMUM - 1e-6))
+        {
+          g_printerr (_("Zoom factor \"%g\" is too large, using %g\n"),
+                      val, TERMINAL_SCALE_MAXIMUM);
+          val = TERMINAL_SCALE_MAXIMUM;
+        }
+        
+      it->zoom = val;
+      it->zoom_set = TRUE;
+	}
+/*  OPTION_ACTIVE */
+  if (option_active)
+	{
+      it = ensure_top_tab (results);
+
+      it->active = TRUE;
+	}
+	
+  return TRUE;
 }
 
 static void
@@ -1288,7 +1241,7 @@
           if ((i + 1) >= *argc)
             {
               g_printerr (_("No argument given to \"%s\" option\n"), "--display");
-              return; /* popt will die on this later, plus it shouldn't happen
+              return; /* popt (GOption?) will die on this later, plus it shouldn't happen
                        * because normally gtk_init() parses --display
                        * when not using factory mode.
                        */
@@ -1569,11 +1522,11 @@
 main (int argc, char **argv)
 {
   GError *err;
-  poptContext ctx;
+  GOptionContext *context;
+  GOptionGroup *option_group;
   int i;
   int argc_copy;
   char **argv_copy;
-  const char **args;
   const char *startup_id;
   const char *display_name;
   GdkDisplay *display;
@@ -1623,9 +1576,35 @@
                                                      * to complicated factory setup
                                                      */
   
-  gtk_init (&argc, &argv);
+  module_info.requirements = reqs;
 
-  /* Do this here so that gdk_display is initialized */
+  context = g_option_context_new (N_("- GNOME Terminal Emulator"));
+
+  g_option_context_set_translation_domain(context, GETTEXT_PACKAGE);
+
+  option_group = g_option_group_new (N_("gnome-terminal"),
+                                     N_("GNOME Terminal Emulator"),
+				     N_("Show GNOME Terminal options"),
+				     results,
+				     NULL);
+
+  g_option_group_set_translation_domain (option_group, GETTEXT_PACKAGE);
+  g_option_context_add_main_entries (context, goptions, GETTEXT_PACKAGE);
+  g_option_group_set_parse_hooks(option_group, NULL, post_options_callback);
+
+  /* This automagically makes GOption parse */
+  program = gnome_program_init (PACKAGE, VERSION,
+                                &module_info,
+                                argc,
+                                argv,
+                                GNOME_PARAM_GOPTION_CONTEXT, context,
+                                GNOME_PARAM_APP_PREFIX, TERM_PREFIX,
+                                GNOME_PARAM_APP_SYSCONFDIR, TERM_SYSCONFDIR,
+                                GNOME_PARAM_APP_DATADIR, TERM_DATADIR,
+                                GNOME_PARAM_APP_LIBDIR, TERM_LIBDIR,
+                                NULL); 
+
+ /* Do this here so that gdk_display is initialized */
   if (results->startup_id == NULL)
     {
       /* Create a fake one containing a timestamp that we can use */
@@ -1641,35 +1620,7 @@
   display_name = gdk_display_get_name (display);
   results->display_name = g_strdup (display_name);
   
-  module_info.requirements = reqs;
 
-  options[0].descrip = (void*) results; /* I hate GnomeProgram, popt, and their
-                                         * mutant spawn
-                                         */
-  program = gnome_program_init (PACKAGE, VERSION,
-                                &module_info,
-                                argc,
-                                argv,
-                                GNOME_PARAM_POPT_TABLE, options,
-                                GNOME_PARAM_APP_PREFIX, TERM_PREFIX,
-                                GNOME_PARAM_APP_SYSCONFDIR, TERM_SYSCONFDIR,
-                                GNOME_PARAM_APP_DATADIR, TERM_DATADIR,
-                                GNOME_PARAM_APP_LIBDIR, TERM_LIBDIR,
-                                NULL); 
-  
-  g_object_get (G_OBJECT (program),
-                GNOME_PARAM_POPT_CONTEXT, &ctx,
-                NULL);
-  
-  args = poptGetArgs (ctx);
-  if (args)
-    {
-      g_printerr (_("Invalid argument: \"%s\"\n"), *args);
-      g_strfreev (argv_copy);
-      return 1;
-    }
-  poptFreeContext (ctx);
-
   option_parsing_results_apply_directory_defaults (results);
   
   gtk_rc_parse_string ("style \"hig-dialog\" {\n"
@@ -3680,10 +3631,10 @@
 handle_new_terminal_event (int          argc,
                            char       **argv)
 {
-  int nextopt;
-  poptContext ctx;
-  const void *store;
+  GOptionContext *ctx;
+  GOptionGroup *option_group;
   OptionParsingResults *results;
+  GError *error = NULL;
 
   g_assert (initialization_complete);
   
@@ -3693,30 +3644,26 @@
   option_parsing_results_check_for_display_name (results,
                                                  &argc,
                                                  argv);
+	
+  ctx = g_option_context_new (N_("GNOME Terminal Emulator"));
+  option_group = g_option_group_new (N_("gnome-terminal"),
+                                     N_("GNOME Terminal Emulator"),
+                                     N_("Show GNOME Terminal options"),
+				                     results,
+                                     NULL);
+  g_option_group_add_entries (option_group, goptions);
+  g_option_group_set_translation_domain (option_group, GETTEXT_PACKAGE);
+  g_option_group_set_parse_hooks(option_group, NULL, post_options_callback);
+  g_option_context_set_main_group(ctx, option_group);
   
-  store = options[0].descrip;
-  options[0].descrip = (void*) results; /* I hate GnomeProgram, popt, and their
-                                         * mutant spawn
-                                         */
-  ctx = poptGetContext (PACKAGE,
-                        argc,
-                        (const char**)argv,
-			options, 0);
-  
   g_return_if_fail (app != NULL);
 
-  while ((nextopt = poptGetNextOpt (ctx)) > 0 ||
-	 nextopt == POPT_ERROR_BADOPT)
-    /* do nothing */ ;
+  if(g_option_context_parse(ctx, &argc, &argv, &error) < 0)
+      g_warning ("Error parsing options: %s, passed from terminal child",
+	  error->message);
 
-  if (nextopt != -1)
-    g_warning ("Error on option %s: %s, passed from terminal child",
-	       poptBadOption (ctx, 0),
-	       poptStrerror (nextopt));
-
-  poptFreeContext (ctx);
-  options[0].descrip = store;
-
+  g_option_context_free (ctx);
+	
   option_parsing_results_apply_directory_defaults (results);
 
   new_terminal_with_options (results);
