~titan-lien/ubuntu/saucy/totem/totem.dev

« back to all changes in this revision

Viewing changes to src/plugins/thumbnail/totem-thumbnail.c

  • Committer: Package Import Robot
  • Author(s): Michael Biebl, Sjoerd Simons, Michael Biebl, Josselin Mouette
  • Date: 2011-11-27 06:21:34 UTC
  • mfrom: (1.4.8) (5.1.23 sid)
  • Revision ID: package-import@ubuntu.com-20111127062134-c3ikko9wdfn9m2av
Tags: 3.2.1-1
[ Sjoerd Simons ]
* New upstream release
* debian/control.in: Update build-depends
* debian/rules: Enable vala plugins
* debian/totem-plugins.install:
  - Add grilo and rotation plugins
  - Remove jamendo, thumbnail and tracker plugins

[ Michael Biebl ]
* debian/control.in:
  - Bump Depends on python-gobject to (>= 2.90.3).

[ Josselin Mouette ]
* Replace python-gobject dependencies by python-gi.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
 
/* 
3
 
 * Copyright (C) 2007 Patrick Hulin <patrick.hulin@gmail.com>
4
 
 *
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.
9
 
 *
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.
14
 
 *
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.
18
 
 *
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.
23
 
 *
24
 
 * See license_change file for details.
25
 
 *
26
 
 */
27
 
 
28
 
#include "config.h"
29
 
 
30
 
#include <glib.h>
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>
36
 
#include <gmodule.h>
37
 
#include <string.h>
38
 
 
39
 
#include "totem-plugin.h"
40
 
#include "totem.h"
41
 
 
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))
48
 
 
49
 
typedef struct
50
 
{
51
 
        guint file_closed_handler_id;
52
 
        guint file_opened_handler_id;
53
 
        GtkWindow *window;
54
 
        TotemObject *totem;
55
 
} TotemThumbnailPluginPrivate;
56
 
 
57
 
TOTEM_PLUGIN_REGISTER(TOTEM_TYPE_THUMBNAIL_PLUGIN, TotemThumbnailPlugin, totem_thumbnail_plugin)
58
 
 
59
 
static void
60
 
set_icon_to_default (TotemObject *totem)
61
 
{
62
 
        GtkWindow *window = NULL;
63
 
        g_return_if_fail (TOTEM_IS_OBJECT (totem));
64
 
 
65
 
        window = totem_get_main_window (totem);
66
 
        gtk_window_set_icon (window, NULL);
67
 
        gtk_window_set_icon_name (window, "totem");
68
 
}
69
 
 
70
 
static void
71
 
update_from_state (TotemThumbnailPluginPrivate *priv,
72
 
                   TotemObject *totem,
73
 
                   const char *mrl)
74
 
{
75
 
        GdkPixbuf *pixbuf = NULL;
76
 
        GtkWindow *window = NULL;
77
 
        char *file_basename, *file_name, *uri_md5;
78
 
        GError *err = NULL;
79
 
 
80
 
        g_return_if_fail (TOTEM_IS_OBJECT (totem));
81
 
        window = totem_get_main_window (totem);
82
 
 
83
 
        if (mrl == NULL) {
84
 
                set_icon_to_default (totem);
85
 
                return;
86
 
        }
87
 
 
88
 
        uri_md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5,
89
 
                                                 mrl,
90
 
                                                 strlen (mrl));
91
 
        file_basename = g_strdup_printf ("%s.png", uri_md5);
92
 
        file_name = g_build_filename (g_get_home_dir (),
93
 
                                      ".thumbnails",
94
 
                                      "normal",
95
 
                                      file_basename,
96
 
                                      NULL);
97
 
 
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);
102
 
                g_free (file_name);
103
 
                file_name= g_build_filename (g_get_home_dir (),
104
 
                                             ".thumbnails",
105
 
                                             "large",
106
 
                                             file_basename,
107
 
                                             NULL);
108
 
 
109
 
                pixbuf = gdk_pixbuf_new_from_file (file_name, &err);
110
 
        }
111
 
 
112
 
        g_free (uri_md5);
113
 
        g_free (file_basename);
114
 
        g_free (file_name);
115
 
 
116
 
        if (pixbuf == NULL) {
117
 
                if (err != NULL && err->domain != G_FILE_ERROR) {
118
 
                        g_printerr ("%s\n", err->message);
119
 
                }
120
 
                set_icon_to_default (totem);
121
 
                return;
122
 
        }
123
 
 
124
 
        gtk_window_set_icon (window, pixbuf);
125
 
 
126
 
        g_object_unref (pixbuf);
127
 
}
128
 
 
129
 
static void
130
 
file_opened_cb (TotemObject *totem,
131
 
                const char *mrl,
132
 
                TotemThumbnailPlugin *pi)
133
 
{
134
 
        update_from_state (pi->priv, totem, mrl);
135
 
}
136
 
 
137
 
static void
138
 
file_closed_cb (TotemObject *totem,
139
 
                 TotemThumbnailPlugin *pi)
140
 
{
141
 
        update_from_state (pi->priv, totem, NULL);
142
 
}
143
 
 
144
 
static void
145
 
impl_activate (PeasActivatable *plugin)
146
 
{
147
 
        TotemThumbnailPlugin *pi = TOTEM_THUMBNAIL_PLUGIN (plugin);
148
 
        char *mrl;
149
 
 
150
 
        pi->priv->totem = g_object_get_data (G_OBJECT (plugin), "object");
151
 
        pi->priv->window = totem_get_main_window (pi->priv->totem);
152
 
 
153
 
        pi->priv->file_opened_handler_id = g_signal_connect (G_OBJECT (pi->priv->totem),
154
 
                                                             "file-opened",
155
 
                                                             G_CALLBACK (file_opened_cb),
156
 
                                                             pi);
157
 
        pi->priv->file_closed_handler_id = g_signal_connect (G_OBJECT (pi->priv->totem),
158
 
                                                             "file-closed",
159
 
                                                             G_CALLBACK (file_closed_cb),
160
 
                                                             pi);
161
 
 
162
 
        g_object_get (pi->priv->totem, "current-mrl", &mrl, NULL);
163
 
 
164
 
        update_from_state (pi->priv, pi->priv->totem, mrl);
165
 
 
166
 
        g_free (mrl);
167
 
}
168
 
 
169
 
static void
170
 
impl_deactivate (PeasActivatable *plugin)
171
 
{
172
 
        TotemThumbnailPlugin *pi = TOTEM_THUMBNAIL_PLUGIN (plugin);
173
 
 
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);
176
 
 
177
 
        set_icon_to_default (pi->priv->totem);
178
 
}
179