summaryrefslogtreecommitdiff
path: root/trunk/src/totem-session.c
blob: 151c01c89a8ef46fb924d02024ce52ed96d50c54 (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/* 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., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.

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

#include "config.h"

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

#ifndef HAVE_GTK_ONLY

#include <libgnome/gnome-config.h>
#include <libgnomeui/gnome-client.h>

static char *
totem_session_create_key (void)
{
	char *filename, *path;

	filename = g_strdup_printf ("totem-%d-%d-%u.pls",
			(int) getpid (),
			(int) time (NULL),
			g_random_int ());
	path = g_build_filename (g_get_home_dir (),
			".gnome2", filename, NULL);
	g_free (filename);

	return path;
}

static gboolean
totem_save_yourself_cb (GnomeClient *client, int phase, GnomeSaveStyle style,
		gboolean shutting_down, GnomeInteractStyle interact_style,
		gboolean fast, Totem *totem)
{
	char *argv[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL };
	int i = 0;
	char *path_id, *current, *seek, *uri;

	if (style == GNOME_SAVE_GLOBAL)
		return TRUE;

	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;
	gnome_client_set_discard_command (client, i, argv);

	/* How to clone or restart */
	i = 0;
	current = g_strdup_printf ("%d",
			totem_playlist_get_current (totem->playlist));
	seek = g_strdup_printf ("%"G_GINT64_FORMAT,
			bacon_video_widget_get_current_time (totem->bvw));
	argv[i++] = (char *) 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;

	gnome_client_set_clone_command (client, i, argv);
	gnome_client_set_restart_command (client, i, argv);

	g_free (path_id);
	g_free (current);
	g_free (seek);
	g_free (uri);

	return TRUE;
}

static void
totem_client_die_cb (GnomeClient *client, Totem *totem)
{
	totem_action_exit (totem);
}

void
totem_session_setup (Totem *totem, char **argv)
{
	GnomeClient *client;
	GnomeClientFlags flags;

	totem->argv0 = argv[0];

	client = gnome_master_client ();
	g_signal_connect (G_OBJECT (client), "save-yourself",
			G_CALLBACK (totem_save_yourself_cb), totem);
	g_signal_connect (G_OBJECT (client), "die",
			G_CALLBACK (totem_client_die_cb), totem);

	flags = gnome_client_get_flags (client);
	if (flags & GNOME_CLIENT_RESTORED)
		totem->session_restored = TRUE;
}

void
totem_session_restore (Totem *totem, char **filenames)
{
	char *mrl, *uri;

	g_return_if_fail (filenames[0] != NULL);
	uri = filenames[0];

	totem_signal_block_by_data (totem->playlist, totem);

	if (totem_playlist_add_mrl (totem->playlist, uri, NULL) == FALSE)
	{
		totem_signal_unblock_by_data (totem->playlist, totem);
		totem_action_set_mrl (totem, NULL);
		g_free (uri);
		return;
	}

	totem_signal_unblock_by_data (totem->playlist, totem);

	if (totem->index != 0)
		totem_playlist_set_current (totem->playlist, totem->index);
	mrl = totem_playlist_get_current_mrl (totem->playlist);

	totem_action_set_mrl_with_warning (totem, mrl, FALSE);

	if (totem->seek_to != 0)
	{
		bacon_video_widget_seek_time (totem->bvw,
				totem->seek_to, NULL);
	}
	bacon_video_widget_pause (totem->bvw);

	g_free (mrl);

	return;
}

#else

void
totem_session_setup (Totem *totem, char **argv)
{
}

void
totem_session_restore (Totem *totem, char **argv)
{
}

#endif /* !HAVE_GTK_ONLY */