1 /* totem-session.c
2
3 Copyright (C) 2004 Bastien Nocera
4
5 The Gnome Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
9
10 The Gnome Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the Gnome Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301 USA.
19
20 Author: Bastien Nocera <hadess@hadess.net>
21 */
22
23 #include "config.h"
24
25 #include "totem.h"
26 #include "totem-private.h"
27 #include "totem-session.h"
28 #include "totem-uri.h"
29
30 static GFile *session_file = NULL;
31
32 static GFile *
get_session_file(void)33 get_session_file (void)
34 {
35 char *path;
36
37 if (session_file)
38 return session_file;
39
40 path = g_build_filename (totem_dot_dir (), "session_state.xspf", NULL);
41 session_file = g_file_new_for_path (path);
42 g_free (path);
43
44 return session_file;
45 }
46
47 static char *
get_session_filename(void)48 get_session_filename (void)
49 {
50 return g_file_get_uri (get_session_file ());
51 }
52
53 gboolean
totem_session_try_restore(Totem * totem)54 totem_session_try_restore (Totem *totem)
55 {
56 char *uri;
57 char *mrl, *subtitle;
58
59 totem_signal_block_by_data (totem->playlist, totem);
60 totem->pause_start = TRUE;
61
62 /* Possibly the only place in Totem where it makes sense to add an MRL to the playlist synchronously, since we haven't yet entered
63 * the GTK+ main loop, and thus can't freeze the application. */
64 uri = get_session_filename ();
65 if (totem_playlist_add_mrl_sync (totem->playlist, uri) == FALSE) {
66 totem->pause_start = FALSE;
67 totem_signal_unblock_by_data (totem->playlist, totem);
68 totem_object_set_mrl (totem, NULL, NULL);
69 g_free (uri);
70 return FALSE;
71 }
72 g_free (uri);
73
74 totem_signal_unblock_by_data (totem->playlist, totem);
75
76 subtitle = NULL;
77 mrl = totem_playlist_get_current_mrl (totem->playlist, &subtitle);
78
79 if (mrl != NULL)
80 totem_object_set_main_page (totem, "player");
81
82 totem_object_set_mrl (totem, mrl, subtitle);
83
84 /* We do the seeking after being told that the stream is seekable,
85 * not straight away */
86
87 g_free (mrl);
88 g_free (subtitle);
89
90 return TRUE;
91 }
92
93 void
totem_session_save(Totem * totem)94 totem_session_save (Totem *totem)
95 {
96 GFile *file;
97 gint64 curr = -1;
98
99 if (totem->bvw == NULL)
100 return;
101
102 file = get_session_file ();
103 if (!totem_playing_dvd (totem->mrl))
104 curr = bacon_video_widget_get_current_time (totem->bvw) / 1000;
105 totem_playlist_save_session_playlist (totem->playlist, file, curr);
106 }
107
108 void
totem_session_cleanup(Totem * totem)109 totem_session_cleanup (Totem *totem)
110 {
111 g_file_delete (get_session_file (), NULL, NULL);
112 g_clear_object (&session_file);
113 }
114