31
31
#include <gmodule.h>
32
32
#include <string.h>
33
33
#include <gdk/gdkkeysyms.h>
34
#include <gconf/gconf-client.h>
34
#include <libpeas/peas-activatable.h>
37
37
#include <X11/XF86keysym.h>
40
#include "totem-plugin.h"
40
41
#include "totem-screenshot-plugin.h"
41
42
#include "totem-screenshot.h"
42
43
#include "totem-gallery.h"
43
44
#include "totem-uri.h"
44
45
#include "backend/bacon-video-widget.h"
46
struct TotemScreenshotPluginPrivate {
47
#define TOTEM_TYPE_SCREENSHOT_PLUGIN (totem_screenshot_plugin_get_type ())
48
#define TOTEM_SCREENSHOT_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TOTEM_TYPE_SCREENSHOT_PLUGIN, TotemScreenshotPlugin))
49
#define TOTEM_SCREENSHOT_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), TOTEM_TYPE_SCREENSHOT_PLUGIN, TotemScreenshotPluginClass))
50
#define TOTEM_IS_SCREENSHOT_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TOTEM_TYPE_SCREENSHOT_PLUGIN))
51
#define TOTEM_IS_SCREENSHOT_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TOTEM_TYPE_SCREENSHOT_PLUGIN))
52
#define TOTEM_SCREENSHOT_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TOTEM_TYPE_SCREENSHOT_PLUGIN, TotemScreenshotPluginClass))
48
56
BaconVideoWidget *bvw;
51
59
gulong notify_logo_mode_signal;
52
60
gulong key_press_event_signal;
55
63
gboolean save_to_disk;
58
66
GtkActionGroup *action_group;
61
static gboolean impl_activate (TotemPlugin *plugin, TotemObject *totem, GError **error);
62
static void impl_deactivate (TotemPlugin *plugin, TotemObject *totem);
64
TOTEM_PLUGIN_REGISTER (TotemScreenshotPlugin, totem_screenshot_plugin)
67
totem_screenshot_plugin_class_init (TotemScreenshotPluginClass *klass)
69
TotemPluginClass *plugin_class = TOTEM_PLUGIN_CLASS (klass);
71
g_type_class_add_private (klass, sizeof (TotemScreenshotPluginPrivate));
73
plugin_class->activate = impl_activate;
74
plugin_class->deactivate = impl_deactivate;
78
totem_screenshot_plugin_init (TotemScreenshotPlugin *plugin)
80
plugin->priv = G_TYPE_INSTANCE_GET_PRIVATE (plugin, TOTEM_TYPE_SCREENSHOT_PLUGIN, TotemScreenshotPluginPrivate);
67
} TotemScreenshotPluginPrivate;
69
TOTEM_PLUGIN_REGISTER(TOTEM_TYPE_SCREENSHOT_PLUGIN,
70
TotemScreenshotPlugin,
71
totem_screenshot_plugin)
84
74
take_screenshot_action_cb (GtkAction *action, TotemScreenshotPlugin *self)
98
totem_action_error (_("Totem could not get a screenshot of the video."), err->message, priv->totem);
88
totem_action_error (priv->totem, _("Totem could not get a screenshot of the video."), err->message);
99
89
g_error_free (err);
103
93
pixbuf = bacon_video_widget_get_current_frame (priv->bvw);
104
94
if (pixbuf == NULL) {
105
totem_action_error (_("Totem could not get a screenshot of the video."), _("This is not supposed to happen; please file a bug report."), priv->totem);
95
totem_action_error (priv->totem, _("Totem could not get a screenshot of the video."), _("This is not supposed to happen; please file a bug report."));
109
dialog = totem_screenshot_new (priv->totem, TOTEM_PLUGIN (self), pixbuf);
99
dialog = totem_screenshot_new (priv->totem, pixbuf);
111
101
gtk_dialog_run (GTK_DIALOG (dialog));
112
102
gtk_widget_destroy (dialog);
131
121
if (bacon_video_widget_get_logo_mode (self->priv->bvw) != FALSE)
134
dialog = GTK_DIALOG (totem_gallery_new (totem, TOTEM_PLUGIN (self)));
124
dialog = GTK_DIALOG (totem_gallery_new (totem));
136
126
g_signal_connect (dialog, "response",
137
127
G_CALLBACK (take_gallery_response_cb), self);
194
disable_save_to_disk_changed_cb (GConfClient *client, guint connection_id, GConfEntry *entry, TotemScreenshotPlugin *self)
184
disable_save_to_disk_changed_cb (GSettings *settings, const gchar *key, TotemScreenshotPlugin *self)
196
self->priv->save_to_disk = !gconf_client_get_bool (client, "/desktop/gnome/lockdown/disable_save_to_disk", NULL);
186
self->priv->save_to_disk = !g_settings_get_boolean (settings, "disable-save-to-disk");
200
impl_activate (TotemPlugin *plugin, TotemObject *totem, GError **error)
190
impl_activate (PeasActivatable *plugin)
202
192
GtkWindow *window;
203
193
GtkUIManager *manager;
205
194
TotemScreenshotPlugin *self = TOTEM_SCREENSHOT_PLUGIN (plugin);
206
195
TotemScreenshotPluginPrivate *priv = self->priv;
207
196
const GtkActionEntry menu_entries[] = {
209
198
{ "take-gallery", NULL, N_("Create Screenshot _Gallery..."), NULL, N_("Create a gallery of screenshots"), G_CALLBACK (take_gallery_action_cb) }
213
priv->bvw = BACON_VIDEO_WIDGET (totem_get_video_widget (totem));
201
priv->totem = g_object_get_data (G_OBJECT (plugin), "object");
202
priv->bvw = BACON_VIDEO_WIDGET (totem_get_video_widget (priv->totem));
214
203
priv->got_metadata_signal = g_signal_connect (G_OBJECT (priv->bvw),
216
205
G_CALLBACK (got_metadata_cb),
223
212
/* Key press handler */
224
window = totem_get_main_window (totem);
213
window = totem_get_main_window (priv->totem);
225
214
priv->key_press_event_signal = g_signal_connect (G_OBJECT (window),
226
215
"key-press-event",
227
216
G_CALLBACK (window_key_press_event_cb),
234
223
gtk_action_group_add_actions (priv->action_group, menu_entries,
235
224
G_N_ELEMENTS (menu_entries), self);
237
manager = totem_get_ui_manager (totem);
226
manager = totem_get_ui_manager (priv->totem);
239
228
gtk_ui_manager_insert_action_group (manager, priv->action_group, -1);
240
229
g_object_unref (priv->action_group);
250
239
"/ui/tmw-menubar/edit/repeat-mode", NULL,
251
240
NULL, GTK_UI_MANAGER_SEPARATOR, TRUE);
253
/* Set up a GConf watch for lockdown keys */
254
client = gconf_client_get_default ();
255
priv->gconf_id = gconf_client_notify_add (client, "/desktop/gnome/lockdown/disable_save_to_disk",
256
(GConfClientNotifyFunc) disable_save_to_disk_changed_cb,
258
disable_save_to_disk_changed_cb (client, priv->gconf_id, NULL, self);
259
g_object_unref (client);
242
/* Set up a GSettings watch for lockdown keys */
243
priv->settings = g_settings_new ("org.gnome.desktop.lockdown");
244
g_signal_connect (priv->settings, "changed::disable-save-to-disk", (GCallback) disable_save_to_disk_changed_cb, self);
245
disable_save_to_disk_changed_cb (priv->settings, "disable-save-to-disk", self);
261
247
/* Update the menu entries' states */
262
248
update_state (self);
268
impl_deactivate (TotemPlugin *plugin, TotemObject *totem)
252
impl_deactivate (PeasActivatable *plugin)
270
254
TotemScreenshotPluginPrivate *priv = TOTEM_SCREENSHOT_PLUGIN (plugin)->priv;
271
255
GtkWindow *window;
272
256
GtkUIManager *manager;
275
258
/* Disconnect signal handlers */
276
259
g_signal_handler_disconnect (G_OBJECT (priv->bvw), priv->got_metadata_signal);
277
260
g_signal_handler_disconnect (G_OBJECT (priv->bvw), priv->notify_logo_mode_signal);
279
window = totem_get_main_window (totem);
262
window = totem_get_main_window (priv->totem);
280
263
g_signal_handler_disconnect (G_OBJECT (window), priv->key_press_event_signal);
281
264
g_object_unref (window);
283
/* Disconnect from GConf */
284
client = gconf_client_get_default ();
285
gconf_client_notify_remove (client, priv->gconf_id);
286
g_object_unref (client);
266
/* Disconnect from GSettings */
267
g_object_unref (priv->settings);
288
269
/* Remove the menu */
289
manager = totem_get_ui_manager (totem);
270
manager = totem_get_ui_manager (priv->totem);
290
271
gtk_ui_manager_remove_ui (manager, priv->ui_merge_id);
291
272
gtk_ui_manager_remove_action_group (manager, priv->action_group);
320
301
totem_screenshot_plugin_setup_file_chooser (const char *filename_format, const char *movie_title)
323
304
char *path, *filename, *full, *uri;
326
307
/* Set the default path */
327
client = gconf_client_get_default ();
328
path = gconf_client_get_string (client, "/apps/totem/screenshot_save_path", NULL);
329
g_object_unref (client);
308
settings = g_settings_new (TOTEM_GSETTINGS_SCHEMA);
309
path = g_settings_get_string (settings, "screenshot-save-uri");
310
g_object_unref (settings);
331
312
/* Default to the Pictures directory */
332
if (path == NULL || path[0] == '\0') {
334
315
path = totem_pictures_dir ();
335
316
/* No pictures dir, then it's the home dir */
366
347
dir = g_file_get_path (parent);
367
348
g_object_unref (parent);
369
client = gconf_client_get_default ();
370
gconf_client_set_string (client,
371
"/apps/totem/screenshot_save_path",
350
settings = g_settings_new (TOTEM_GSETTINGS_SCHEMA);
351
g_settings_set_string (settings, "screenshot-save-uri", dir);
352
g_object_unref (settings);