summaryrefslogtreecommitdiff
path: root/src/totem-session.c
blob: d703b8be7e7fd5f6336db0551236c5116e00b60d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* totem-session.c

   Copyright (C) 2004 Bastien Nocera

   The Gnome Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   The Gnome Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with the Gnome Library; see the file COPYING.LIB.  If not,
   write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301  USA.

   Author: Bastien Nocera <hadess@hadess.net>
 */

#include "config.h"

#include "totem.h"
#include "totem-private.h"
#include "totem-session.h"
#include "totem-uri.h"

static GFile *
get_session_file (void)
{
	GFile *file;
	char *path;

	path = g_build_filename (totem_dot_dir (), "session_state.xspf", NULL);
	file = g_file_new_for_path (path);
	g_free (path);

	return file;
}

static char *
get_session_filename (void)
{
	GFile *file;
	char *uri;

	file = get_session_file ();
	uri = g_file_get_uri (file);
	g_object_unref (file);

	return uri;
}

gboolean
totem_session_try_restore (Totem *totem)
{
	char *uri;
	char *mrl, *subtitle;

	if (totem_playlist_get_save (totem->playlist) == FALSE)
		return FALSE;

	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. */
	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 FALSE;
	}
	g_free (uri);

	totem_signal_unblock_by_data (totem->playlist, totem);

	subtitle = NULL;
	mrl = totem_playlist_get_current_mrl (totem->playlist, &subtitle);

	if (mrl != NULL)
		totem_object_set_main_page (totem, "player", FALSE);

	totem_action_set_mrl (totem, mrl, subtitle);

	/* We do the seeking after being told that the stream is seekable,
	 * not straight away */

	g_free (mrl);
	g_free (subtitle);

	return TRUE;
}

void
totem_session_save (Totem *totem)
{
	GFile *file;
	gint64 curr = -1;

	if (totem->bvw == NULL)
		return;

	file = get_session_file ();
	if (!totem_playing_dvd (totem->mrl))
		curr = bacon_video_widget_get_current_time (totem->bvw);
	totem_playlist_save_session_playlist (totem->playlist, file, curr);
	g_object_unref (file);
}