[totem] main: Save the session state on exit



commit cb576fd87361623275cc1ff11764d733a5ceecc1
Author: Bastien Nocera <hadess hadess net>
Date:   Sat Mar 9 01:06:54 2013 +0100

    main: Save the session state on exit
    
    Using a playlist to save the complete state. In the future,
    we'll check whether the user wants to save the state, and save
    it more regularly to stave off crashes.

 src/totem-object.c  |    3 +
 src/totem-options.c |   10 ----
 src/totem-private.h |    3 -
 src/totem-session.c |  150 ++++++++-------------------------------------------
 src/totem-session.h |    5 +-
 src/totem.c         |   16 +++---
 6 files changed, 35 insertions(+), 152 deletions(-)
---
diff --git a/src/totem-object.c b/src/totem-object.c
index 9b071d3..5d5e02b 100644
--- a/src/totem-object.c
+++ b/src/totem-object.c
@@ -62,6 +62,7 @@
 #include "video-utils.h"
 #include "totem-dnd-menu.h"
 #include "totem-preferences.h"
+#include "totem-session.h"
 
 #define WANT_MIME_TYPES 1
 #include "totem-mime-types.h"
@@ -1115,6 +1116,8 @@ totem_object_action_exit (TotemObject *totem)
        totem_action_save_state (totem, page_id);
        g_free (page_id);
 
+       totem_session_save (totem);
+
        totem_sublang_exit (totem);
        totem_destroy_file_filters ();
 
diff --git a/src/totem-options.c b/src/totem-options.c
index 119d1a7..a2b9fe2 100644
--- a/src/totem-options.c
+++ b/src/totem-options.c
@@ -95,16 +95,6 @@ totem_options_get_context (void)
 }
 
 void
-totem_options_process_late (Totem *totem, const TotemCmdLineOptions *options)
-{
-       /* Handle --playlist-idx */
-       totem->index = options->playlistidx;
-
-       /* Handle --seek */
-       totem->seek_to_start = options->seek;
-}
-
-void
 totem_options_process_early (Totem *totem, const TotemCmdLineOptions* options)
 {
        if (options->quit) {
diff --git a/src/totem-private.h b/src/totem-private.h
index c48b44d..ff92472 100644
--- a/src/totem-private.h
+++ b/src/totem-private.h
@@ -137,10 +137,7 @@ struct _TotemObject {
        gboolean drives_changed;
 
        /* session */
-       const char *argv0;
        gint64 seek_to_start;
-       guint index;
-       gboolean session_restored;
 
        /* Window State */
        int window_w, window_h;
diff --git a/src/totem-session.c b/src/totem-session.c
index 1221acd..d3d018a 100644
--- a/src/totem-session.c
+++ b/src/totem-session.c
@@ -27,139 +27,40 @@
 #include "totem-session.h"
 #include "totem-uri.h"
 
-#ifdef WITH_SMCLIENT
-
-#include <unistd.h>
-
-#include "eggsmclient.h"
-
-#ifdef GDK_WINDOWING_X11
-#include "eggdesktopfile.h"
-#endif
-
 static char *
-totem_session_create_key (void)
+get_session_filename (void)
 {
-       char *filename, *path;
-
-       filename = g_strdup_printf ("playlist-%d-%d-%u.xspf",
-                       (int) getpid (),
-                       (int) time (NULL),
-                       g_random_int ());
-       path = g_build_filename (totem_dot_dir (), filename, NULL);
-       g_free (filename);
+       char *path, *uri;
 
-       return path;
-}
+       path = g_build_filename (g_get_user_config_dir (), "totem", "session_state.xspf", NULL);
+       uri = g_filename_to_uri (path, NULL, NULL);
+       g_free (path);
 
-static void
-totem_save_state_cb (EggSMClient *client,
-                    GKeyFile *key_file,
-                    Totem *totem)
-{
-       const char *argv[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL };
-       int i = 0;
-       char *path_id, *current, *seek, *uri;
-       int current_index;
-
-       current_index = totem_playlist_get_current (totem->playlist);
-
-       if (current_index == -1)
-               return;
-
-       path_id = totem_session_create_key ();
-       totem_playlist_save_current_playlist (totem->playlist, path_id);
-
-       /* How to discard the save */
-       argv[i++] = "rm";
-       argv[i++] = "-f";
-       argv[i++] = path_id;
-       egg_sm_client_set_discard_command (client, i, (const char **) argv);
-
-       /* How to clone or restart */
-       i = 0;
-       current = g_strdup_printf ("%d", current_index);
-       seek = g_strdup_printf ("%"G_GINT64_FORMAT,
-                       bacon_video_widget_get_current_time (totem->bvw));
-       argv[i++] = totem->argv0;
-       argv[i++] = "--playlist-idx";
-       argv[i++] = current;
-       argv[i++] = "--seek";
-       argv[i++] = seek;
-
-       uri = g_filename_to_uri (path_id, NULL, NULL);
-       argv[i++] = uri;
-
-       /* FIXME: what's this used for? */
-       /* egg_sm_client_set_clone_command (client, i, argv); */
-
-       egg_sm_client_set_restart_command (client, i, (const char **) argv);
-
-       g_free (path_id);
-       g_free (current);
-       g_free (seek);
-       g_free (uri);
+       return uri;
 }
 
-G_GNUC_NORETURN static void
-totem_quit_cb (EggSMClient *client,
-              Totem *totem)
+gboolean
+totem_session_try_restore (Totem *totem)
 {
-       totem_action_exit (totem);
-}
-
-void
-totem_session_add_options (GOptionContext *context)
-{
-#ifdef GDK_WINDOWING_X11
-       egg_set_desktop_file_without_defaults (DATADIR "/applications/" PACKAGE ".desktop");
-#endif
-
-       g_option_context_add_group (context, egg_sm_client_get_option_group ());
-}
-
-void
-totem_session_setup (Totem *totem, char **argv)
-{
-       EggSMClient *sm_client;
-
-       totem->argv0 = argv[0];
-
-       sm_client = egg_sm_client_get ();
-       g_signal_connect (sm_client, "save-state",
-                         G_CALLBACK (totem_save_state_cb), totem);
-       g_signal_connect (sm_client, "quit",
-                         G_CALLBACK (totem_quit_cb), totem);
-
-       if (egg_sm_client_is_resumed (sm_client))
-               totem->session_restored = TRUE;
-}
-
-void
-totem_session_restore (Totem *totem, char **filenames)
-{
-       char *mrl, *uri, *subtitle;
-
-       g_return_if_fail (filenames != NULL);
-       g_return_if_fail (filenames[0] != NULL);
-       uri = filenames[0];
-       subtitle = NULL;
+       char *uri;
+       char *mrl, *subtitle;
 
        totem_signal_block_by_data (totem->playlist, totem);
 
        /* Possibly the only place in Totem where it makes sense to add an MRL to the playlist synchronously, 
since we haven't yet entered
         * the GTK+ main loop, and thus can't freeze the application. */
-       if (totem_playlist_add_mrl_sync (totem->playlist, uri, NULL) == FALSE) {
+       uri = get_session_filename ();
+       if (totem_playlist_add_mrl_sync (totem->playlist, uri, &totem->seek_to_start) == FALSE) {
                totem_signal_unblock_by_data (totem->playlist, totem);
                totem_action_set_mrl (totem, NULL, NULL);
                g_free (uri);
-               return;
+               return FALSE;
        }
+       g_free (uri);
 
        totem_signal_unblock_by_data (totem->playlist, totem);
 
-       if (totem->index != 0)
-               totem_playlist_set_current (totem->playlist, totem->index);
+       subtitle = NULL;
        mrl = totem_playlist_get_current_mrl (totem->playlist, &subtitle);
 
        totem_action_set_mrl_with_warning (totem, mrl, subtitle, FALSE);
@@ -169,23 +70,18 @@ totem_session_restore (Totem *totem, char **filenames)
 
        g_free (mrl);
        g_free (subtitle);
-}
-
-#else
 
-void
-totem_session_add_options (GOptionContext *context)
-{
+       return TRUE;
 }
 
 void
-totem_session_setup (Totem *totem, char **argv)
+totem_session_save (Totem *totem)
 {
-}
+       char *uri;
 
-void
-totem_session_restore (Totem *totem, char **argv)
-{
+       uri = get_session_filename ();
+       /* FIXME: Save the current seek time somehow */
+       /* FIXME: Check whether we actually want to be saved */
+       totem_playlist_save_current_playlist (totem->playlist, uri);
+       g_free (uri);
 }
-
-#endif /* WITH_SMCLIENT */
diff --git a/src/totem-session.h b/src/totem-session.h
index cca9bda..321c933 100644
--- a/src/totem-session.h
+++ b/src/totem-session.h
@@ -27,9 +27,8 @@
 
 G_BEGIN_DECLS
 
-void totem_session_add_options (GOptionContext *context);
-void totem_session_setup (Totem *totem, char **argv);
-void totem_session_restore (Totem *totem, char **filenames);
+gboolean totem_session_try_restore (Totem *totem);
+void totem_session_save (Totem *totem);
 
 G_END_DECLS
 
diff --git a/src/totem.c b/src/totem.c
index e80b0f4..4c4951d 100644
--- a/src/totem.c
+++ b/src/totem.c
@@ -114,7 +114,6 @@ app_init (Totem *totem, char **argv)
                                         gtk_scale_button_get_adjustment (GTK_SCALE_BUTTON (totem->volume)));
        gtk_range_set_adjustment (GTK_RANGE (totem->fs->seek), totem->seekadj);
 
-       totem_session_setup (totem, argv);
        totem_setup_file_monitoring (totem);
        totem_setup_file_filters ();
        totem_app_menu_setup (totem);
@@ -150,21 +149,20 @@ app_init (Totem *totem, char **argv)
 
        totem_setup_recent (totem);
 
-       /* Command-line handling */
-       totem_options_process_late (totem, &optionstate);
-
        /* Initialise all the plugins, and set the default page, in case
         * it comes from a plugin */
        totem_object_plugins_init (totem);
        totem_sidebar_set_current_page (totem, sidebar_pageid, FALSE);
        g_free (sidebar_pageid);
 
-       if (totem->session_restored != FALSE) {
-               totem_session_restore (totem, optionstate.filenames);
-       } else if (optionstate.filenames != NULL && totem_action_open_files (totem, optionstate.filenames)) {
-               totem_action_play_pause (totem);
+       if (optionstate.filenames == NULL) {
+               if (totem_session_try_restore (totem) == FALSE)
+                       totem_action_set_mrl (totem, NULL, NULL);
        } else {
-               totem_action_set_mrl (totem, NULL, NULL);
+               if (totem_action_open_files (totem, optionstate.filenames))
+                       totem_action_play_pause (totem);
+               else
+                       totem_action_set_mrl (totem, NULL, NULL);
        }
 
        /* Set the logo at the last minute so we won't try to show it before a video */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]