Index: src/terminal.c
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal.c,v
retrieving revision 1.95
diff -u -5 -r1.95 terminal.c
--- src/terminal.c	4 Mar 2006 06:10:54 -0000	1.95
+++ src/terminal.c	27 Mar 2006 03:07:32 -0000
@@ -36,11 +36,10 @@
 #include <bonobo/bonobo-listener.h>
 #include <libgnome/gnome-program.h>
 #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>
 #include <gdk/gdkx.h>
 
@@ -84,10 +83,11 @@
 static GConfClient *conf = NULL;
 static TerminalApp *app = NULL;
 static gboolean terminal_factory_disabled = FALSE;
 static gboolean initialization_complete = FALSE;
 static GSList *pending_new_terminal_events = NULL;
+static char **extra_args;
 
 #define TERMINAL_STOCK_EDIT "terminal-edit"
 typedef struct
 {
   char *startup_id;
@@ -133,425 +133,464 @@
 
 static gboolean terminal_invoke_factory (int argc, char **argv);
 static void option_parsing_results_free (OptionParsingResults *results);
 
 
-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 gboolean command_option_callback (const gchar *option_name,
+                                         const gchar *value,
+				         gpointer data,
+				         GError **error);
+static gboolean execute_option_callback (const gchar *option_name,
+                                         const gchar *value,
+				         gpointer data,
+				         GError **error);
+static gboolean window_option_callback (const gchar *option_name,
+                                        const gchar *value,
+				        gpointer data,
+				        GError **error);
+static gboolean tab_option_callback (const gchar *option_name,
+                                     const gchar *value,
+				     gpointer data,
+				     GError **error);
+static gboolean show_menubar_option_callback (const gchar *option_name,
+                                              const gchar *value,
+				              gpointer data,
+				              GError **error);
+static gboolean hide_menubar_option_callback (const gchar *option_name,
+                                              const gchar *value,
+				              gpointer data,
+				              GError **error);
+static gboolean full_screen_option_callback (const gchar *option_name,
+                                             const gchar *value,
+				             gpointer data,
+				             GError **error);
+static gboolean role_option_callback (const gchar *option_name,
+                                      const gchar *value,
+				      gpointer data,
+				      GError **error);
+static gboolean geometry_option_callback (const gchar *option_name,
+                                          const gchar *value,
+				          gpointer data,
+				          GError **error);
+static gboolean disable_factory_option_callback (const gchar *option_name,
+                                                 const gchar *value,
+				                 gpointer data,
+				                 GError **error);
+static gboolean use_factory_option_callback (const gchar *option_name,
+                                             const gchar *value,
+				             gpointer data,
+				             GError **error);
+static gboolean title_option_callback (const gchar *option_name,
+                                       const gchar *value,
+				       gpointer data,
+				       GError **error);
+static gboolean working_dir_option_callback (const gchar *option_name,
+                                             const gchar *value,
+				             gpointer data,
+				             GError **error);
+static gboolean default_working_dir_option_callback (const gchar *option_name,
+                                                     const gchar *value,
+				                     gpointer data,
+				                     GError **error);
+static gboolean zoom_option_callback (const gchar *option_name,
+                                      const gchar *value,
+				      gpointer data,
+				      GError **error);
+static gboolean active_option_callback (const gchar *option_name,
+                                        const gchar *value,
+				        gpointer data,
+				        GError **error);
+static gboolean startup_id_option_callback (const gchar *option_name,
+                                            const gchar *value,
+				            gpointer data,
+				            GError **error);
+static gboolean post_options_callback (GOptionContext *context,
+				       GOptionGroup *group,
+				       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
-};  
-
-struct poptOption options[] = {  
-  {
-    NULL, 
-    '\0', 
-    POPT_ARG_CALLBACK | POPT_CBFLAG_POST,
-    parse_options_callback, 
-    0, 
-    NULL, 
-    NULL
-  },
+static const GOptionEntry options[] = {
   {
     "command",
     'e',
-    POPT_ARG_STRING,
-    NULL,
-    OPTION_COMMAND,
+    0,
+    G_OPTION_ARG_CALLBACK,
+    command_option_callback,
     N_("Execute the argument to this option inside the terminal."),
-    NULL
+    N_("COMMAND")
   },
   {
     "execute",
     'x',
-    POPT_ARG_NONE,
-    NULL,
-    OPTION_EXECUTE,
+    G_OPTION_FLAG_NO_ARG,
+    G_OPTION_ARG_CALLBACK,
+    execute_option_callback,
     N_("Execute the remainder of the command line inside the terminal."),
     NULL
   },
   {
     "window",
-    '\0',
-    POPT_ARG_NONE,
-    NULL,
-    OPTION_WINDOW,
+    0,
+    G_OPTION_FLAG_NO_ARG,
+    G_OPTION_ARG_CALLBACK,
+    window_option_callback,
     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_CALLBACK,
+    window_option_callback,
     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,
+    G_OPTION_FLAG_NO_ARG,
+    G_OPTION_ARG_CALLBACK,
+    tab_option_callback,
     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_CALLBACK,
+    tab_option_callback,
     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,
+    G_OPTION_FLAG_HIDDEN,
+    G_OPTION_ARG_CALLBACK,
+    window_option_callback,
     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,
+    G_OPTION_FLAG_HIDDEN,
+    G_OPTION_ARG_CALLBACK,
+    tab_option_callback,
     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_CALLBACK,
+    role_option_callback,
     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,
+    G_OPTION_FLAG_NO_ARG,
+    G_OPTION_ARG_CALLBACK,
+    show_menubar_option_callback,
     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,
+    G_OPTION_FLAG_NO_ARG,
+    G_OPTION_ARG_CALLBACK,
+    hide_menubar_option_callback,
     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,
+    G_OPTION_FLAG_NO_ARG,
+    G_OPTION_ARG_CALLBACK,
+    full_screen_option_callback,
     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_CALLBACK,
+    geometry_option_callback,
     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,
+    G_OPTION_FLAG_NO_ARG,
+    G_OPTION_ARG_CALLBACK,
+    disable_factory_option_callback,
     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,
+    G_OPTION_FLAG_NO_ARG,
+    G_OPTION_ARG_CALLBACK,
+    use_factory_option_callback,
     N_("Register with the activation nameserver [default]"),
     NULL
   },
   {
     "startup-id",
-    '\0',
-    POPT_ARG_STRING,
-    NULL,
-    OPTION_STARTUP_ID,
+    0,
+    G_OPTION_FLAG_HIDDEN,
+    G_OPTION_ARG_CALLBACK,
+    startup_id_option_callback,
     N_("ID for startup notification protocol."),
-    NULL
+    N_("STARTUPID")
   },
   {
     "title",
     't',
-    POPT_ARG_STRING,
-    NULL,
-    OPTION_TITLE,
+    0,
+    G_OPTION_ARG_CALLBACK,
+    title_option_callback,
     N_("Set the terminal's title"),
     N_("TITLE")
   },
   {
     "working-directory",
-    '\0',
-    POPT_ARG_STRING,
-    NULL,
-    OPTION_WORKING_DIRECTORY,
+    0,
+    0,
+    G_OPTION_ARG_CALLBACK,
+    working_dir_option_callback,
     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_CALLBACK,
+    default_working_dir_option_callback,
     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_CALLBACK,
+    zoom_option_callback,
     N_("Set the terminal's zoom factor (1.0 = normal size)"),
     N_("ZOOMFACTOR")
   },
   {
     "active",
-    '\0',
-    POPT_ARG_NONE,
-    NULL,
-    OPTION_ACTIVE,
+    0,
+    G_OPTION_FLAG_NO_ARG,
+    G_OPTION_ARG_CALLBACK,
+    active_option_callback,
     N_("Set the last specified tab as the active one in its window"),
     N_("ZOOMFACTOR")
   },
   
   /*
    * Crappy old compat args
    */
   {
     "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_FLAG_NO_ARG,
+    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_FLAG_NO_ARG,
+    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_FLAG_NO_ARG,
+    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_FLAG_NO_ARG,
+    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_FLAG_NO_ARG,
+    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_FLAG_NO_ARG,
+    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_FLAG_NO_ARG,
+    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_FLAG_NO_ARG,
+    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_FLAG_NO_ARG,
+    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_FLAG_NO_ARG,
+    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_FLAG_NO_ARG,
+    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_FLAG_NO_ARG,
+    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_FLAG_NO_ARG,
+    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_FLAG_NO_ARG,
+    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_FLAG_NO_ARG,
+    G_OPTION_ARG_CALLBACK,
+    unsupported_option_callback,
     NULL, NULL
   },
   {
-    NULL,
-    '\0',
+    G_OPTION_REMAINING,
     0,
-    NULL,
     0,
+    G_OPTION_ARG_STRING_ARRAY,
+    &extra_args,
     NULL,
     NULL
+  },
+  {
+    NULL
   }
 };
 
 typedef struct
 {
@@ -740,450 +779,522 @@
   results->initial_windows = g_list_append (results->initial_windows, iw);
   
   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)
+{
+  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;
 
-  if (reason == POPT_CALLBACK_REASON_POST)
-    {
-      /* Make sure we have some window */
-      if (results->initial_windows == NULL)
-        ensure_top_window (results);
+  if(results->initial_windows == NULL)
+    ensure_top_window (results);
 
-      return;
+  return TRUE;
+}
+
+static gboolean
+command_option_callback (const gchar *option_name,
+                         const gchar *value,
+			 gpointer data,
+			 GError **error)
+{
+  OptionParsingResults *results;
+  GError *err;
+  InitialTab *it;
+  char **exec_argv;
+
+  results = data;
+
+  err = NULL;
+  exec_argv = NULL;
+  if (!g_shell_parse_argv (value, NULL, &exec_argv, &err))
+    {
+      *error = g_error_new(G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
+                           _("Argument to \"%s\" is not a valid command: %s"),
+                           option_name, err->message);
+      g_error_free (err);
+      return FALSE;
     }
-  else if (reason != POPT_CALLBACK_REASON_OPTION)
-    return;
 
-  switch (opt->val & POPT_ARG_MASK)
+  it = ensure_top_tab (results);
+
+  if (it->exec_argv != NULL)
     {
-    case OPTION_COMMAND:
-      {
-        GError *err;
-        InitialTab *it;
-        char **exec_argv;
-            
+      *error = g_error_new(G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
+               _("\"%s\" specified more than once for the same window or tab"),
+               "--command/-e/--execute/-x");
+      return FALSE;
+    }
 
-        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"),
-                        "--command/-e", err->message);
-            g_error_free (err);
-            exit (1);
-          }
+  it->exec_argv = exec_argv;
 
-        it = ensure_top_tab (results);
+  return TRUE;
+}
 
-        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);
-          }
+static gboolean
+execute_option_callback (const gchar *option_name,
+                         const gchar *value,
+			 gpointer data,
+			 GError **error)
+{
+  OptionParsingResults *results;
+  InitialTab *it;
 
-        it->exec_argv = exec_argv;
-      }
-      break;
-
-    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);
-          }
+  results = data;
+      
+  if (results->post_execute_args == NULL)
+    {
+      *error = g_error_new(G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
+                           _("Option \"%s\" requires specifying the command to run on the rest of the command line"),
+			   option_name);
+      return FALSE;
+    }
 
-        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)
+    {
+      *error = g_error_new(G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
+                _("\"%s\" specified more than once for the same window or tab"),
+                "--command/-e/--execute/-x");
+      return FALSE;
+    }
 
-        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;
+  it->exec_argv = results->post_execute_args;
+  results->post_execute_args = NULL;
 
+  return TRUE;
+}
 
-        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;
+static gboolean
+window_option_callback (const gchar *option_name,
+                        const gchar *value,
+			gpointer data,
+			GError **error)
+{
+  OptionParsingResults *results;
+  InitialWindow *iw;
+  const char *profile;
 
-        iw = add_new_window (results, profile,
-                             opt->val == OPTION_WINDOW_WITH_PROFILE_ID);
-      }
-      break;
-
-    case OPTION_TAB:
-    case OPTION_TAB_WITH_PROFILE:
-    case OPTION_TAB_WITH_PROFILE_ID:
-      {
-        InitialWindow *iw;
-        const char *profile;
+  results = data;
 
+  if (option_name == "--window")
+    profile = NULL;
+  else
+    profile = value;
 
-        if (opt->val == OPTION_TAB)
-          profile = NULL;
-        else if (arg == NULL)
-          {
-            g_printerr (_("Option \"%s\" requires an argument specifying what profile to use\n"),
-                        "--tab-with-profile");
-            exit (1);
-          }
-        else
-          profile = arg;
+  iw = add_new_window (results, profile,
+                       option_name == "--window-with-profile-internal-id");
 
-                
-        if (results->initial_windows)
-          {
-            iw = g_list_last (results->initial_windows)->data;
+  return TRUE;
+}
+
+static gboolean
+tab_option_callback (const gchar *option_name,
+                     const gchar *value,
+		     gpointer data,
+		     GError **error)
+{
+  OptionParsingResults *results;
+  InitialWindow *iw;
+  const char *profile;
+
+  results = data;
+
+  if (option_name == "--tab")
+    profile = NULL;
+  else
+    profile = value;
 
-            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;
+  if (results->initial_windows)
+    {
+      iw = g_list_last (results->initial_windows)->data;
+
+      iw->tabs = g_list_append (iw->tabs,
+                                initial_tab_new (profile,
+                                                 option_name == "--tab-with-profile-internal-id"));
+    }
+  else
+    {
+      iw = add_new_window (results, profile, 
+                           option_name == "--tab-with-profile-internal-id");
+    }
+
+  return TRUE;
+}
+
+static gboolean
+show_menubar_option_callback (const gchar *option_name,
+                              const gchar *value,
+			      gpointer data,
+			      GError **error)
+{
+  OptionParsingResults *results;
+  InitialWindow *iw;
+
+  results = data;
             
-        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)
+        {
+          *error = g_error_new(G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
+               _("\"%s\" option given twice for the same window"), option_name);
+          return FALSE;
+        }
+          
+      iw->force_menubar_state = TRUE;
+      iw->menubar_state = TRUE;
+    }
+  else
+    {
+      results->default_window_menubar_forced = TRUE;
+      results->default_window_menubar_state = TRUE;
+    }
 
-                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;
+  return TRUE;
+}
+
+static gboolean
+hide_menubar_option_callback (const gchar *option_name,
+                              const gchar *value,
+			      gpointer data,
+			      GError **error)
+{
+  OptionParsingResults *results;
+  InitialWindow *iw;
+
+  results = data;
+      
+  if (results->initial_windows)
+    {
+      iw = g_list_last (results->initial_windows)->data;
+
+      if (iw->force_menubar_state)
+        {
+          *error = g_error_new(G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
+              _("\"%s\" option given twice for the same window"), option_name);
+          return FALSE;
+        }
           
-    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 = FALSE;                
+    }
+  else
+    {
+      results->default_window_menubar_forced = TRUE;
+      results->default_window_menubar_state = FALSE;
+    }
 
-            if (iw->force_menubar_state)
-              {
-                g_printerr (_("\"%s\" option given twice for the same window\n"), "--hide-menubar");
+  return TRUE;
+}
 
-                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;
+static gboolean
+full_screen_option_callback (const gchar *option_name,
+                             const gchar *value,
+			     gpointer data,
+			     GError **error)
+{
+  OptionParsingResults *results;
+  InitialWindow *iw;
 
-    case OPTION_FULLSCREEN:
-      {
-        InitialWindow *iw;
-            
-        if (results->initial_windows)
-          {
-            iw = g_list_last (results->initial_windows)->data;
+  results = data;
+      
+  if (results->initial_windows)
+    {
+      iw = g_list_last (results->initial_windows)->data;
 
-            iw->start_fullscreen = TRUE;
-          }
-        else
-          {
-            results->default_start_fullscreen = TRUE;
-          }
-      }
-      break;
+      iw->start_fullscreen = TRUE;
+    }
+  else
+    {
+      results->default_start_fullscreen = TRUE;
+    }
 
-    case OPTION_ROLE:
-      {
-        InitialWindow *iw;
+  return TRUE;
+}
 
+static gboolean
+role_option_callback (const gchar *option_name,
+                      const gchar *value,
+		      gpointer data,
+		      GError **error)
+{
+  OptionParsingResults *results;
+  InitialWindow *iw;
 
-        if (arg == NULL)
-          {
-            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);
-              }
+  results = data;
 
-            iw->role = g_strdup (arg);
-          }
-      }
-      break;
+  if (results->initial_windows)
+    {
+      iw = g_list_last (results->initial_windows)->data;
+      if (iw->role)
+        {
+          *error = g_error_new(G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
+                               _("Two roles given for one window"));
+          return FALSE;
+        }
 
-    case OPTION_GEOMETRY:
-      {
-        InitialWindow *iw;
+      iw->role = g_strdup (value);
+    }
 
+  return TRUE;
+}
 
-        if (arg == NULL)
-          {
-            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);
-              }
+static gboolean
+geometry_option_callback (const gchar *option_name,
+                          const gchar *value,
+			  gpointer data,
+			  GError **error)
+{
+  OptionParsingResults *results;
+  InitialWindow *iw;
 
-            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;
+  results = data;
 
-    case OPTION_DISABLE_FACTORY:
-      terminal_factory_disabled = TRUE;
-      break;
-
-    case OPTION_USE_FACTORY:
-      terminal_factory_disabled = FALSE;
-      break;
-
-    case OPTION_TITLE:
-      {
-        InitialTab *it;
-            
+  if (results->initial_windows)
+    {
+      iw = g_list_last (results->initial_windows)->data;
+      if (iw->geometry)
+        {
+          *error = g_error_new(G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
+                     _("Two \"%s\" options given for one window"), option_name);
+          return FALSE;
+        }
 
-        if (arg == NULL)
-          {
-            g_printerr (_("Option \"%s\" requires an argument giving the title\n"), "--title");
-            exit (1);
-          }
+      iw->geometry = g_strdup (value);
+    }
+  else
+    {
+      if (results->default_geometry)
+        {
+          *error = g_error_new(G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
+                               _("Two geometries given for one window"));
+          return FALSE;
+        }
+      else
+        {
+          results->default_geometry = g_strdup (value);
+        }
+    }
 
-        it = ensure_top_tab (results);
+  return TRUE;
+}
 
-        if (it->title)
-          {
-            g_printerr (_("Two \"%s\" options given for one tab\n"), "--title");
-            exit (1);
-          }
+static gboolean
+disable_factory_option_callback (const gchar *option_name,
+                                 const gchar *value,
+				 gpointer data,
+				 GError **error)
+{
+  terminal_factory_disabled = TRUE;
 
-        it->title = g_strdup (arg);
-      }
-      break;
-
-    case OPTION_WORKING_DIRECTORY:
-      {
-        InitialTab *it;
-            
+  return TRUE;
+}
 
-        if (arg == NULL)
-          {
-            g_printerr (_("Option \"%s\" requires an argument giving the directory\n"), "--working-directory");
-            exit (1);
-          }
+static gboolean
+use_factory_option_callback (const gchar *option_name,
+                             const gchar *value,
+			     gpointer data,
+			     GError **error)
+{
+  terminal_factory_disabled = FALSE;
 
-        it = ensure_top_tab (results);
+  return TRUE;
+}
 
-        if (it->working_dir)
-          {
-            g_printerr (_("Two \"%s\" options given for one tab\n"), "--working-directory");
-            exit (1);
-          }
+static gboolean
+title_option_callback (const gchar *option_name,
+                       const gchar *value,
+		       gpointer data,
+		       GError **error)
+{
+  OptionParsingResults *results;
+  InitialTab *it;
 
-        it->working_dir = g_strdup (arg);
-      }
-      break;
-
-    case OPTION_DEFAULT_WORKING_DIRECTORY:
-      {
-        if (arg == NULL)
-          {
-            g_printerr (_("Option --default-working-directory requires an argument giving the directory\n"));
-            exit (1);
-          }
+  results = data;
 
-        if (results->default_working_dir)
-          {
-            g_printerr (_("Two --default-working-directories given\n"));
-            exit (1);
-          }
+  it = ensure_top_tab (results);
 
-        results->default_working_dir = g_strdup (arg);
-      }
-      break;
-
-    case OPTION_ZOOM:
-      {
-        InitialTab *it;            
-        double val;
-        char *end;
-        
-        if (arg == NULL)
-          {
-            g_printerr (_("Option \"%s\" requires an argument giving the zoom factor\n"), "--zoom");
-            exit (1);
-          }
+  if (it->title)
+    {
+      *error = g_error_new(G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
+                        _("Two \"%s\" options given for one tab"), option_name);
+      return FALSE;
+    }
 
-        it = ensure_top_tab (results);
+  it->title = g_strdup (value);
 
-        if (it->zoom_set)
-          {
-            g_printerr (_("Two \"%s\" options given for one tab\n"), "--zoom");
-            exit (1);
-          }
+  return TRUE;
+}
 
-        /* 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);
-              }
-          }
+static gboolean
+working_dir_option_callback (const gchar *option_name,
+                             const gchar *value,
+			     gpointer data,
+			     GError **error)
+{
+  OptionParsingResults *results;
+  InitialTab *it;
 
-        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;
-          }
+  results = data;
 
-        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;
+  it = ensure_top_tab (results);
 
-    case OPTION_STARTUP_ID:
-      if (results->startup_id != NULL)
-        {
-          g_printerr (_("\"%s\" option given twice\n"), "--startup-id");
-          exit (1);
-        }
-      else if (arg == NULL)
-        {
-          g_printerr (_("\"%s\" option requires an argument\n"), "--startup-id");
-          exit (1);
-        }
-      else
+  if (it->working_dir)
+    {
+      *error = g_error_new(G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
+                        _("Two \"%s\" options given for one tab"), option_name);
+      return FALSE;
+    }
+
+  it->working_dir = g_strdup (value);
+
+  return TRUE;
+}
+
+static gboolean
+default_working_dir_option_callback (const gchar *option_name,
+                                     const gchar *value,
+				     gpointer data,
+				     GError **error)
+{
+  OptionParsingResults *results;
+
+  results = data;
+
+  if (results->default_working_dir)
+    {
+      *error = g_error_new(G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
+                           _("Two %s given"), option_name);
+      return FALSE;
+    }
+
+  results->default_working_dir = g_strdup (value);
+
+  return TRUE;
+}
+
+static gboolean
+zoom_option_callback (const gchar *option_name,
+                      const gchar *value,
+		      gpointer data,
+		      GError **error)
+{
+  OptionParsingResults *results;
+  InitialTab *it;            
+  double val;
+  char *end;
+  
+  results = data;
+
+  it = ensure_top_tab (results);
+
+  if (it->zoom_set)
+    {
+      *error = g_error_new(G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
+                        _("Two \"%s\" options given for one tab"), option_name);
+      return FALSE;
+    }
+
+  /* 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 (value, &end);
+  if (end == NULL || *end != '\0')
+    {
+      val = g_ascii_strtod (value, &end);
+      if (end == NULL || *end != '\0')
         {
-          results->startup_id = g_strdup (arg);
+          *error = g_error_new(G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
+                               _("\"%s\" is not a valid zoom factor"), value);
+          return FALSE;
         }
-      break;
-      
-    case OPTION_LAST:
-      g_assert_not_reached ();
-      break;
-      /* no default so we get warnings on missing items */
     }
+
+  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;
+
+  return TRUE;
+}
+
+static gboolean
+active_option_callback (const gchar *option_name,
+                        const gchar *value,
+			gpointer data,
+			GError **error)
+{
+  OptionParsingResults *results;
+  InitialTab *it;
+
+  results = data;
+
+  it = ensure_top_tab (results);
+
+  it->active = TRUE;
+
+  return TRUE;
+}
+
+static gboolean
+startup_id_option_callback (const gchar *option_name,
+                            const gchar *value,
+			    gpointer data,
+			    GError **error)
+{
+  OptionParsingResults *results;
+
+  results = data;
+
+  if (results->startup_id != NULL)
+    {
+      *error = g_error_new(G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
+                           _("\"%s\" option given twice"), option_name);
+      return FALSE;
+    }
+  else
+    {
+      results->startup_id = g_strdup (value);
+    }
+
+  return TRUE;
 }
 
 static void
 option_parsing_results_free (OptionParsingResults *results)
 {
@@ -1286,12 +1397,12 @@
       else if (strcmp (argv[i], "--display") == 0)
         {          
           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
-                       * because normally gtk_init() parses --display
+              return; /* goption will die on this later, plus it shouldn't
+		       * happen because normally gtk_init() parses --display
                        * when not using factory mode.
                        */
             }
           
           if (results->display_name)
@@ -1308,12 +1419,12 @@
           char *end;
           
           if ((i + 1) >= *argc)
             {
               g_printerr (_("\"%s\" option requires an argument\n"), "--screen");
-              return; /* popt will die on this later, plus it shouldn't happen
-                       * because normally gtk_init() parses --display
+              return; /* goption will die on this later, plus it shouldn't
+                       * happen because normally gtk_init() parses --display
                        * when not using factory mode.
                        */
             }
 
           g_assert (i+1 < *argc);
@@ -1567,15 +1678,15 @@
 
 int
 main (int argc, char **argv)
 {
   GError *err;
-  poptContext ctx;
+  GOptionContext *ctx;
+  GOptionGroup *option_group;
   int i;
   int argc_copy;
   char **argv_copy;
-  const char **args;
   const char *startup_id;
   const char *display_name;
   GdkDisplay *display;
   GnomeModuleRequirement reqs[] = {
     { "2.0.0", NULL },
@@ -1641,36 +1752,38 @@
   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
-                                         */
+  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, options);
+  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);
+  
   program = gnome_program_init (PACKAGE, VERSION,
                                 &module_info,
                                 argc,
                                 argv,
-                                GNOME_PARAM_POPT_TABLE, options,
+                                GNOME_PARAM_GOPTION_CONTEXT, ctx,
                                 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)
+  if (extra_args)
     {
-      g_printerr (_("Invalid argument: \"%s\"\n"), *args);
+      g_printerr (_("Invalid argument: \"%s\"\n"), *extra_args);
       g_strfreev (argv_copy);
       return 1;
     }
-  poptFreeContext (ctx);
 
   option_parsing_results_apply_directory_defaults (results);
   
   gtk_rc_parse_string ("style \"hig-dialog\" {\n"
                          "GtkDialog::action-area-border = 0\n"
@@ -3672,46 +3785,42 @@
 
 static void
 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);
   
   results = option_parsing_results_init (&argc, argv);
   
   /* Find and parse --display */
   option_parsing_results_check_for_display_name (results,
                                                  &argc,
                                                  argv);
-  
-  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);
-  
+
+  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, options);
+  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);
+
   g_return_if_fail (app != NULL);
 
-  while ((nextopt = poptGetNextOpt (ctx)) > 0 ||
-	 nextopt == POPT_ERROR_BADOPT)
-    /* do nothing */ ;
-
-  if (nextopt != -1)
-    g_warning ("Error on option %s: %s, passed from terminal child",
-	       poptBadOption (ctx, 0),
-	       poptStrerror (nextopt));
+  if(g_option_context_parse(ctx, &argc, &argv, &error) < 0)
+      g_warning ("Error parsing options: %s, passed from terminal child",
+	  error->message);
 
-  poptFreeContext (ctx);
-  options[0].descrip = store;
+  g_option_context_free (ctx);
 
   option_parsing_results_apply_directory_defaults (results);
 
   new_terminal_with_options (results);
 
