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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
/* 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"
#ifdef WITH_SMCLIENT
#include <unistd.h>
#include "eggsmclient.h"
#ifdef GDK_WINDOWING_X11
#include "eggdesktopfile.h"
#endif
static char *
totem_session_create_key (void)
{
char *filename, *path;
filename = g_strdup_printf ("playlist-%d-%d-%u.pls",
(int) getpid (),
(int) time (NULL),
g_random_int ());
path = g_build_filename (totem_dot_dir (), filename, NULL);
g_free (filename);
return 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);
}
G_GNUC_NORETURN static void
totem_quit_cb (EggSMClient *client,
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;
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) {
totem_signal_unblock_by_data (totem->playlist, totem);
totem_action_set_mrl (totem, NULL, 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, &subtitle);
totem_action_set_mrl_with_warning (totem, mrl, subtitle, FALSE);
/* We do the seeking after being told that the stream is seekable,
* not straight away */
g_free (mrl);
g_free (subtitle);
}
#else
void
totem_session_add_options (GOptionContext *context)
{
}
void
totem_session_setup (Totem *totem, char **argv)
{
}
void
totem_session_restore (Totem *totem, char **argv)
{
}
#endif /* WITH_SMCLIENT */
|