1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3
* Copyright (C) 2007 Patrick Hulin <patrick.hulin@gmail.com>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program 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
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
* The Totem project hereby grant permission for non-gpl compatible GStreamer
20
* plugins to be used and distributed together with GStreamer and Totem. This
21
* permission are above and beyond the permissions granted by the GPL license
22
* Totem is covered by.
24
* See license_change file for details.
31
#include <glib-object.h>
32
#include <glib/gi18n-lib.h>
33
#include <libpeas/peas-activatable.h>
34
#include <libpeas/peas-extension-base.h>
35
#include <libpeas/peas-object-module.h>
39
#include "totem-plugin.h"
42
#define TOTEM_TYPE_THUMBNAIL_PLUGIN (totem_thumbnail_plugin_get_type ())
43
#define TOTEM_THUMBNAIL_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TOTEM_TYPE_THUMBNAIL_PLUGIN, TotemThumbnailPlugin))
44
#define TOTEM_THUMBNAIL_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), TOTEM_TYPE_THUMBNAIL_PLUGIN, TotemThumbnailPluginClass))
45
#define TOTEM_IS_THUMBNAIL_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TOTEM_TYPE_THUMBNAIL_PLUGIN))
46
#define TOTEM_IS_THUMBNAIL_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TOTEM_TYPE_THUMBNAIL_PLUGIN))
47
#define TOTEM_THUMBNAIL_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TOTEM_TYPE_THUMBNAIL_PLUGIN, TotemThumbnailPluginClass))
51
guint file_closed_handler_id;
52
guint file_opened_handler_id;
55
} TotemThumbnailPluginPrivate;
57
TOTEM_PLUGIN_REGISTER(TOTEM_TYPE_THUMBNAIL_PLUGIN, TotemThumbnailPlugin, totem_thumbnail_plugin)
60
set_icon_to_default (TotemObject *totem)
62
GtkWindow *window = NULL;
63
g_return_if_fail (TOTEM_IS_OBJECT (totem));
65
window = totem_get_main_window (totem);
66
gtk_window_set_icon (window, NULL);
67
gtk_window_set_icon_name (window, "totem");
71
update_from_state (TotemThumbnailPluginPrivate *priv,
75
GdkPixbuf *pixbuf = NULL;
76
GtkWindow *window = NULL;
77
char *file_basename, *file_name, *uri_md5;
80
g_return_if_fail (TOTEM_IS_OBJECT (totem));
81
window = totem_get_main_window (totem);
84
set_icon_to_default (totem);
88
uri_md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5,
91
file_basename = g_strdup_printf ("%s.png", uri_md5);
92
file_name = g_build_filename (g_get_home_dir (),
98
pixbuf = gdk_pixbuf_new_from_file (file_name, &err);
99
/* Try loading from the "large" thumbnails if normal fails */
100
if (pixbuf == NULL && err != NULL && err->domain == G_FILE_ERROR) {
101
g_clear_error (&err);
103
file_name= g_build_filename (g_get_home_dir (),
109
pixbuf = gdk_pixbuf_new_from_file (file_name, &err);
113
g_free (file_basename);
116
if (pixbuf == NULL) {
117
if (err != NULL && err->domain != G_FILE_ERROR) {
118
g_printerr ("%s\n", err->message);
120
set_icon_to_default (totem);
124
gtk_window_set_icon (window, pixbuf);
126
g_object_unref (pixbuf);
130
file_opened_cb (TotemObject *totem,
132
TotemThumbnailPlugin *pi)
134
update_from_state (pi->priv, totem, mrl);
138
file_closed_cb (TotemObject *totem,
139
TotemThumbnailPlugin *pi)
141
update_from_state (pi->priv, totem, NULL);
145
impl_activate (PeasActivatable *plugin)
147
TotemThumbnailPlugin *pi = TOTEM_THUMBNAIL_PLUGIN (plugin);
150
pi->priv->totem = g_object_get_data (G_OBJECT (plugin), "object");
151
pi->priv->window = totem_get_main_window (pi->priv->totem);
153
pi->priv->file_opened_handler_id = g_signal_connect (G_OBJECT (pi->priv->totem),
155
G_CALLBACK (file_opened_cb),
157
pi->priv->file_closed_handler_id = g_signal_connect (G_OBJECT (pi->priv->totem),
159
G_CALLBACK (file_closed_cb),
162
g_object_get (pi->priv->totem, "current-mrl", &mrl, NULL);
164
update_from_state (pi->priv, pi->priv->totem, mrl);
170
impl_deactivate (PeasActivatable *plugin)
172
TotemThumbnailPlugin *pi = TOTEM_THUMBNAIL_PLUGIN (plugin);
174
g_signal_handler_disconnect (pi->priv->totem, pi->priv->file_opened_handler_id);
175
g_signal_handler_disconnect (pi->priv->totem, pi->priv->file_closed_handler_id);
177
set_icon_to_default (pi->priv->totem);