e446227
Index: src/terminal-app.h
e446227
===================================================================
e446227
--- src/terminal-app.h	(revision 3380)
e446227
+++ src/terminal-app.h	(working copy)
e446227
@@ -93,6 +93,7 @@
e446227
 
e446227
 gboolean terminal_app_handle_options (TerminalApp *app,
e446227
                                       TerminalOptions *options,
e446227
+                                      gboolean allow_resume,
e446227
                                       GError **error);
e446227
 
e446227
 void terminal_app_edit_profile (TerminalApp     *app,
e446227
Index: src/terminal-options.c
e446227
===================================================================
e446227
--- src/terminal-options.c	(revision 3380)
e446227
+++ src/terminal-options.c	(working copy)
e446227
@@ -636,10 +636,6 @@
e446227
   TerminalOptions *options = data;
e446227
   InitialTab    *it;
e446227
 
e446227
-  /* make sure we have some window in case no options were given */
e446227
-  if (options->initial_windows == NULL)
e446227
-    it = ensure_top_tab (options);
e446227
-
e446227
   if (options->execute)
e446227
     {
e446227
       if (options->exec_argv == NULL)
e446227
@@ -662,6 +658,25 @@
e446227
   return TRUE;
e446227
 }
e446227
 
e446227
+/**
e446227
+ * terminal_options_parse:
e446227
+ * @working_directory: the default working directory
e446227
+ * @display_name: the default X display name
e446227
+ * @startup_id: the startup notification ID
e446227
+ * @env: the environment as variable=value pairs
e446227
+ * @ignore_unknown_options: whether to ignore unknown options when parsing
e446227
+ *   the arguments
e446227
+ * @argcp: (inout) address of the argument count. Changed if any arguments were handled
e446227
+ * @argvp: (inout) address of the argument vector. Any parameters understood by
e446227
+ *   the terminal #GOptionContext are removed
e446227
+ * @error: a #GError to fill in
e446227
+ * @...: a %NULL terminated list of extra #GOptionGroups
e446227
+ *
e446227
+ * Parses the argument vector *@argvp.
e446227
+ *
e446227
+ * Returns: a new #TerminalOptions containing the windows and tabs to open,
e446227
+ *   or %NULL on error.
e446227
+ */
e446227
 TerminalOptions *
e446227
 terminal_options_parse (const char *working_directory,
e446227
                         const char *display_name,
e446227
@@ -758,6 +773,17 @@
e446227
   return NULL;
e446227
 }
e446227
 
e446227
+/**
e446227
+ * terminal_options_merge_config:
e446227
+ * @options:
e446227
+ * @key_file: a #GKeyFile containing to merge the options from
e446227
+ * @error: a #GError to fill in
e446227
+ *
e446227
+ * Merges the saved options from @key_file into @options.
e446227
+ *
e446227
+ * Returns: %TRUE if @key_file was a valid key file containing a stored
e446227
+ *   terminal configuration, or %FALSE on error
e446227
+ */
e446227
 gboolean
e446227
 terminal_options_merge_config (TerminalOptions *options,
e446227
                                GKeyFile *key_file,
e446227
@@ -864,7 +890,25 @@
e446227
   return TRUE;
e446227
 }
e446227
 
e446227
+/**
e446227
+ * terminal_options_ensure_window:
e446227
+ * @options:
e446227
+ *
e446227
+ * Ensure that @options will contain at least one window to open.
e446227
+ */
e446227
 void
e446227
+terminal_options_ensure_window (TerminalOptions *options)
e446227
+{
e446227
+  ensure_top_window (options);
e446227
+}
e446227
+
e446227
+/**
e446227
+ * terminal_options_free:
e446227
+ * @options:
e446227
+ *
e446227
+ * Frees @options.
e446227
+ */
e446227
+void
e446227
 terminal_options_free (TerminalOptions *options)
e446227
 {
e446227
   g_list_foreach (options->initial_windows, (GFunc) initial_window_free, NULL);
e446227
Index: src/terminal-options.h
e446227
===================================================================
e446227
--- src/terminal-options.h	(revision 3380)
e446227
+++ src/terminal-options.h	(working copy)
e446227
@@ -97,12 +97,14 @@
e446227
                                          int *argcp,
e446227
                                          char ***argvp,
e446227
                                          GError **error,
e446227
-                                         ...);
e446227
+                                         ...) G_GNUC_NULL_TERMINATED;
e446227
 
e446227
 gboolean terminal_options_merge_config (TerminalOptions *options,
e446227
                                         GKeyFile *key_file,
e446227
                                         GError **error);
e446227
 
e446227
+void terminal_options_ensure_window (TerminalOptions *options);
e446227
+
e446227
 void terminal_options_free (TerminalOptions *options);
e446227
 
e446227
 G_END_DECLS
e446227
Index: src/terminal.c
e446227
===================================================================
e446227
--- src/terminal.c	(revision 3380)
e446227
+++ src/terminal.c	(working copy)
e446227
@@ -475,7 +475,7 @@
e446227
   terminal_app_initialize (options->use_factory);
e446227
   g_signal_connect (terminal_app_get (), "quit", G_CALLBACK (gtk_main_quit), NULL);
e446227
 
e446227
-  terminal_app_handle_options (terminal_app_get (), options, NULL);
e446227
+  terminal_app_handle_options (terminal_app_get (), options, TRUE /* allow resume */, NULL);
e446227
   terminal_options_free (options);
e446227
 
e446227
   /* Now change directory to $HOME so we don't prevent unmounting, e.g. if the
e446227
@@ -499,7 +499,7 @@
e446227
 static gboolean
e446227
 handle_new_terminal_event (TerminalOptions *options)
e446227
 {
e446227
-  terminal_app_handle_options (terminal_app_get (), options, NULL);
e446227
+  terminal_app_handle_options (terminal_app_get (), options, FALSE /* no resume */, NULL);
e446227
 
e446227
   return FALSE;
e446227
 }
e446227
Index: src/terminal-app.c
e446227
===================================================================
e446227
--- src/terminal-app.c	(revision 3380)
e446227
+++ src/terminal-app.c	(working copy)
e446227
@@ -1643,9 +1643,24 @@
e446227
   return global_app;
e446227
 }
e446227
 
e446227
+/**
e446227
+ * terminal_app_handle_options:
e446227
+ * @app:
e446227
+ * @options: a #TerminalOptions
e446227
+ * @allow_resume: whether to merge the terminal configuration from the
e446227
+ *   saved session on resume
e446227
+ * @error: a #GError to fill in
e446227
+ *
e446227
+ * Processes @options. It loads or saves the terminal configuration, or
e446227
+ * opens the specified windows and tabs.
e446227
+ *
e446227
+ * Returns: %TRUE if @options could be successfully handled, or %FALSE on
e446227
+ *   error
e446227
+ */
e446227
 gboolean
e446227
 terminal_app_handle_options (TerminalApp *app,
e446227
                              TerminalOptions *options,
e446227
+                             gboolean allow_resume,
e446227
                              GError **error)
e446227
 {
e446227
   GList *lw;
e446227
@@ -1673,6 +1688,27 @@
e446227
       /* fall-through on success */
e446227
     }
e446227
 
e446227
+#ifdef WITH_SMCLIENT
e446227
+{
e446227
+  EggSMClient *sm_client;
e446227
+
e446227
+  sm_client = egg_sm_client_get ();
e446227
+
e446227
+  if (allow_resume && egg_sm_client_is_resumed (sm_client))
e446227
+    {
e446227
+      GKeyFile *key_file;
e446227
+
e446227
+      key_file = egg_sm_client_get_state_file (sm_client);
e446227
+      if (key_file != NULL &&
e446227
+          !terminal_options_merge_config (options, key_file, error))
e446227
+        return FALSE;
e446227
+    }
e446227
+}
e446227
+#endif
e446227
+
e446227
+  /* Make sure we option at least one window */
e446227
+  terminal_options_ensure_window (options);
e446227
+
e446227
   for (lw = options->initial_windows;  lw != NULL; lw = lw->next)
e446227
     {
e446227
       InitialWindow *iw = lw->data;