summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorAli Abdallah <aliovx@gmail.com>2017-05-23 09:10:16 +0200
committerAli Abdallah <aliovx@gmail.com>2017-05-28 10:39:11 +0200
commit95311dbb45d07d8029e27bb374aeefa60e17b339 (patch)
tree80aec73e81fd99bbfce304fc04bf7959d3dffccb /plugins
parent59ba8680de8831ee95dc5fe77b1376dc1fd7771b (diff)
downloadtumbler-95311dbb45d07d8029e27bb374aeefa60e17b339.tar.gz
Added skeleton files for the desktop thumbnailer plugin.
This plugin will add desktop thumbnailer support for tumbler see: https://bugzilla.xfce.org/show_bug.cgi?id=7475
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Makefile.am1
-rw-r--r--plugins/desktop-thumbnailer/Makefile.am44
-rw-r--r--plugins/desktop-thumbnailer/desktop-thumbnailer-plugin.c89
-rw-r--r--plugins/desktop-thumbnailer/desktop-thumbnailer-provider.c123
-rw-r--r--plugins/desktop-thumbnailer/desktop-thumbnailer-provider.h42
-rw-r--r--plugins/desktop-thumbnailer/desktop-thumbnailer.c152
-rw-r--r--plugins/desktop-thumbnailer/desktop-thumbnailer.h42
7 files changed, 493 insertions, 0 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index f2c9f5f..f2b5307 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -27,4 +27,5 @@ SUBDIRS = \
odf-thumbnailer \
poppler-thumbnailer \
raw-thumbnailer \
+ desktop-thumbnailer \
xdg-cache
diff --git a/plugins/desktop-thumbnailer/Makefile.am b/plugins/desktop-thumbnailer/Makefile.am
new file mode 100644
index 0000000..ecb5adf
--- /dev/null
+++ b/plugins/desktop-thumbnailer/Makefile.am
@@ -0,0 +1,44 @@
+if TUMBLER_DESKTOP_THUMBNAILER
+
+tumbler_plugindir = $(libdir)/tumbler-$(TUMBLER_VERSION_API)/plugins
+tumbler_plugin_LTLIBRARIES = \
+ tumbler-desktop-thumbnailer.la
+
+tumbler_desktop_thumbnailer_la_SOURCES = \
+ desktop-thumbnailer-plugin.c \
+ desktop-thumbnailer-provider.c \
+ desktop-thumbnailer-provider.h \
+ desktop-thumbnailer.c \
+ desktop-thumbnailer.h
+
+tumbler_desktop_thumbnailer_la_CFLAGS = \
+ -I$(top_builddir) \
+ -I$(top_builddir)/plugins \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/plugins \
+ -DG_LOG_DOMAIN=\"tumbler-desktop-thumbnailer\" \
+ -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \
+ $(GDK_PIXBUF_CFLAGS) \
+ $(GIO_CFLAGS) \
+ $(GLIB_CFLAGS) \
+ $(PLATFORM_CFLAGS) \
+ $(PLATFORM_CPPFLAGS)
+
+tumbler_desktop_thumbnailer_la_LDFLAGS = \
+ -avoid-version \
+ -export-dynamic \
+ -module \
+ $(PLATFORM_LDFLAGS)
+
+tumbler_desktop_thumbnailer_la_LIBADD = \
+ $(top_builddir)/tumbler/libtumbler-$(TUMBLER_VERSION_API).la \
+ $(GDK_PIXBUF_LIBS) \
+ $(GIO_LIBS) \
+ $(GLIB_LIBS) \
+ -lm
+
+tumbler_desktop_thumbnailer_la_DEPENDENCIES = \
+ $(top_builddir)/tumbler/libtumbler-$(TUMBLER_VERSION_API).la
+
+
+endif \ No newline at end of file
diff --git a/plugins/desktop-thumbnailer/desktop-thumbnailer-plugin.c b/plugins/desktop-thumbnailer/desktop-thumbnailer-plugin.c
new file mode 100644
index 0000000..d4810d0
--- /dev/null
+++ b/plugins/desktop-thumbnailer/desktop-thumbnailer-plugin.c
@@ -0,0 +1,89 @@
+/*
+ *
+ * Copyright (c) 2017 Ali Abdallah <ali@xfce.org>
+ *
+ * This 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.
+ *
+ * This 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 this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <glib-object.h>
+
+#include <tumbler/tumbler.h>
+
+#include <desktop-thumbnailer/desktop-thumbnailer-provider.h>
+#include <desktop-thumbnailer/desktop-thumbnailer.h>
+
+
+G_MODULE_EXPORT void tumbler_plugin_initialize (TumblerProviderPlugin *plugin);
+G_MODULE_EXPORT void tumbler_plugin_shutdown (void);
+G_MODULE_EXPORT void tumbler_plugin_get_types (const GType **types,
+ gint *n_types);
+
+
+
+static GType type_list[1];
+
+
+
+void
+tumbler_plugin_initialize (TumblerProviderPlugin *plugin)
+{
+ const gchar *mismatch;
+
+ /* verify that the tumbler versions are compatible */
+ mismatch = tumbler_check_version (TUMBLER_MAJOR_VERSION, TUMBLER_MINOR_VERSION,
+ TUMBLER_MICRO_VERSION);
+ if (G_UNLIKELY (mismatch != NULL))
+ {
+ g_warning (_("Version mismatch: %s"), mismatch);
+ return;
+ }
+
+#ifdef DEBUG
+ g_print ("Initializing the Tumbler Desktop Thumbnailer plugin\n");
+#endif
+
+ /* register the types provided by this plugin */
+ desktop_thumbnailer_register (plugin);
+ desktop_thumbnailer_provider_register (plugin);
+
+ /* set up the plugin provider type list */
+ type_list[0] = TYPE_DESKTOP_THUMBNAILER_PROVIDER;
+}
+
+
+void
+tumbler_plugin_shutdown (void)
+{
+#ifdef DEBUG
+ g_print ("Shutting down the Tumbler GStreamer Thumbnailer plugin\n");
+#endif
+}
+
+
+
+void
+tumbler_plugin_get_types (const GType **types,
+ gint *n_types)
+{
+ *types = type_list;
+ *n_types = G_N_ELEMENTS (type_list);
+}
diff --git a/plugins/desktop-thumbnailer/desktop-thumbnailer-provider.c b/plugins/desktop-thumbnailer/desktop-thumbnailer-provider.c
new file mode 100644
index 0000000..8ea95c2
--- /dev/null
+++ b/plugins/desktop-thumbnailer/desktop-thumbnailer-provider.c
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2017 Ali Abdallah <ali@xfce.org>
+ *
+ * This 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.
+ *
+ * This 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 this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib.h>
+#include <glib-object.h>
+
+
+#include <tumbler/tumbler.h>
+
+#include <desktop-thumbnailer/desktop-thumbnailer-provider.h>
+#include <desktop-thumbnailer/desktop-thumbnailer.h>
+
+
+
+static void desktop_thumbnailer_provider_thumbnailer_provider_init (TumblerThumbnailerProviderIface *iface);
+static GList *desktop_thumbnailer_provider_get_thumbnailers (TumblerThumbnailerProvider *provider);
+
+
+
+struct _DesktopThumbnailerProviderClass
+{
+ GObjectClass __parent__;
+};
+
+struct _DesktopThumbnailerProvider
+{
+ GObject __parent__;
+};
+
+
+
+G_DEFINE_DYNAMIC_TYPE_EXTENDED (DesktopThumbnailerProvider,
+ desktop_thumbnailer_provider,
+ G_TYPE_OBJECT,
+ 0,
+ TUMBLER_ADD_INTERFACE (TUMBLER_TYPE_THUMBNAILER_PROVIDER,
+ desktop_thumbnailer_provider_thumbnailer_provider_init));
+
+
+
+void
+desktop_thumbnailer_provider_register (TumblerProviderPlugin *plugin)
+{
+ desktop_thumbnailer_provider_register_type (G_TYPE_MODULE (plugin));
+}
+
+
+
+static void
+desktop_thumbnailer_provider_class_init (DesktopThumbnailerProviderClass *klass)
+{
+}
+
+
+
+static void
+desktop_thumbnailer_provider_class_finalize (DesktopThumbnailerProviderClass *klass)
+{
+}
+
+
+
+static void
+desktop_thumbnailer_provider_thumbnailer_provider_init (TumblerThumbnailerProviderIface *iface)
+{
+ iface->get_thumbnailers = desktop_thumbnailer_provider_get_thumbnailers;
+}
+
+
+
+static void
+desktop_thumbnailer_provider_init (DesktopThumbnailerProvider *provider)
+{
+}
+
+
+
+static GList *
+desktop_thumbnailer_provider_get_thumbnailers (TumblerThumbnailerProvider *provider)
+{
+ /* This list is mainly from Totem. Generating a list from
+ * GStreamer isn't realistic, so we have to hardcode it. */
+ /* See https://git.gnome.org/browse/totem/tree/data/mime-type-list.txt */
+ static const char *mime_types[] = {
+ "dummy",
+ NULL
+ };
+
+ DesktopThumbnailer *thumbnailer;
+ GError *error = NULL;
+ GStrv uri_schemes;
+
+ uri_schemes = tumbler_util_get_supported_uri_schemes ();
+
+ thumbnailer = g_object_new (TYPE_DESKTOP_THUMBNAILER,
+ "uri-schemes", uri_schemes,
+ "mime-types", mime_types,
+ NULL);
+
+ g_strfreev (uri_schemes);
+
+ return g_list_append (NULL, thumbnailer);
+}
diff --git a/plugins/desktop-thumbnailer/desktop-thumbnailer-provider.h b/plugins/desktop-thumbnailer/desktop-thumbnailer-provider.h
new file mode 100644
index 0000000..db10a46
--- /dev/null
+++ b/plugins/desktop-thumbnailer/desktop-thumbnailer-provider.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2017 Ali Abdallah <ali@xfce.org>
+ *
+ * This 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.
+ *
+ * This 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 this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __DESKTOP_THUMBNAILER_PROVIDER_H__
+#define __DESKTOP_THUMBNAILER_PROVIDER_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define TYPE_DESKTOP_THUMBNAILER_PROVIDER (desktop_thumbnailer_provider_get_type ())
+#define DESKTOP_THUMBNAILER_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_DESKTOP_THUMBNAILER_PROVIDER, DesktopThumbnailerProvider))
+#define DESKTOP_THUMBNAILER_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DESKTOP_THUMBNAILER_PROVIDER, DesktopThumbnailerProviderClass))
+#define IS_DESKTOP_THUMBNAILER_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_DESKTOP_THUMBNAILER_PROVIDER))
+#define IS_DESKTOP_THUMBNAILER_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DESKTOP_THUMBNAILER_PROVIDER)
+#define DESKTOP_THUMBNAILER_PROVIDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DESKTOP_THUMBNAILER_PROVIDER, DesktopThumbnailerProviderClass))
+
+typedef struct _DesktopThumbnailerProviderClass DesktopThumbnailerProviderClass;
+typedef struct _DesktopThumbnailerProvider DesktopThumbnailerProvider;
+
+GType desktop_thumbnailer_provider_get_type (void) G_GNUC_CONST;
+void desktop_thumbnailer_provider_register (TumblerProviderPlugin *plugin);
+
+G_END_DECLS
+
+#endif /* !__DESKTOP_THUMBNAILER_PROVIDER_H__ */
diff --git a/plugins/desktop-thumbnailer/desktop-thumbnailer.c b/plugins/desktop-thumbnailer/desktop-thumbnailer.c
new file mode 100644
index 0000000..7f025fe
--- /dev/null
+++ b/plugins/desktop-thumbnailer/desktop-thumbnailer.c
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 2017 Ali Abdallah <ali@xfce.org>
+ *
+ * This 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.
+ *
+ * This 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 this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <math.h>
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <glib-object.h>
+
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
+#include <gio/gio.h>
+
+
+#include <tumbler/tumbler.h>
+
+#include <desktop-thumbnailer/desktop-thumbnailer.h>
+
+
+
+static void desktop_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer,
+ GCancellable *cancellable,
+ TumblerFileInfo *info);
+
+
+
+struct _DesktopThumbnailerClass
+{
+ TumblerAbstractThumbnailerClass __parent__;
+};
+
+struct _DesktopThumbnailer
+{
+ TumblerAbstractThumbnailer __parent__;
+};
+
+
+
+G_DEFINE_DYNAMIC_TYPE (DesktopThumbnailer,
+ desktop_thumbnailer,
+ TUMBLER_TYPE_ABSTRACT_THUMBNAILER);
+
+
+
+void
+desktop_thumbnailer_register (TumblerProviderPlugin *plugin)
+{
+ desktop_thumbnailer_register_type (G_TYPE_MODULE (plugin));
+}
+
+
+
+static void
+desktop_thumbnailer_class_init (DesktopThumbnailerClass *klass)
+{
+ TumblerAbstractThumbnailerClass *abstractthumbnailer_class;
+
+ abstractthumbnailer_class = TUMBLER_ABSTRACT_THUMBNAILER_CLASS (klass);
+ abstractthumbnailer_class->create = desktop_thumbnailer_create;
+}
+
+
+
+static void
+desktop_thumbnailer_class_finalize (DesktopThumbnailerClass *klass)
+{
+}
+
+
+
+static void
+desktop_thumbnailer_init (DesktopThumbnailer *thumbnailer)
+{
+}
+
+
+static void
+desktop_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer,
+ GCancellable *cancellable,
+ TumblerFileInfo *info)
+{
+ TumblerThumbnail *thumbnail;
+ const gchar *uri;
+ GFile *file;
+ GError *error = NULL;
+ gchar *path;
+ GdkPixbuf *pixbuf = NULL;
+ TumblerImageData data;
+
+ g_return_if_fail (IS_DESKTOP_THUMBNAILER (thumbnailer));
+ g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
+ g_return_if_fail (TUMBLER_IS_FILE_INFO (info));
+
+ /* do nothing if cancelled */
+ if (g_cancellable_is_cancelled (cancellable))
+ return;
+
+ uri = tumbler_file_info_get_uri (info);
+ file = g_file_new_for_uri (uri);
+
+
+ thumbnail = tumbler_file_info_get_thumbnail (info);
+
+ if (pixbuf != NULL)
+ {
+ data.data = gdk_pixbuf_get_pixels (pixbuf);
+ data.has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
+ data.bits_per_sample = gdk_pixbuf_get_bits_per_sample (pixbuf);
+ data.width = gdk_pixbuf_get_width (pixbuf);
+ data.height = gdk_pixbuf_get_height (pixbuf);
+ data.rowstride = gdk_pixbuf_get_rowstride (pixbuf);
+ data.colorspace = (TumblerColorspace) gdk_pixbuf_get_colorspace (pixbuf);
+
+ tumbler_thumbnail_save_image_data (thumbnail, &data,
+ tumbler_file_info_get_mtime (info),
+ NULL, &error);
+
+ g_object_unref (pixbuf);
+ }
+
+ if (error != NULL)
+ {
+ g_signal_emit_by_name (thumbnailer, "error", uri, error->code, error->message);
+ g_error_free (error);
+ }
+ else
+ {
+ g_signal_emit_by_name (thumbnailer, "ready", uri);
+ }
+
+ g_object_unref (thumbnail);
+}
diff --git a/plugins/desktop-thumbnailer/desktop-thumbnailer.h b/plugins/desktop-thumbnailer/desktop-thumbnailer.h
new file mode 100644
index 0000000..af0ef0c
--- /dev/null
+++ b/plugins/desktop-thumbnailer/desktop-thumbnailer.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2017 Ali Abdallah <ali@xfce.org>
+ *
+ * This 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.
+ *
+ * This 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 this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __DESKTOP_THUMBNAILER_H__
+#define __DESKTOP_THUMBNAILER_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define TYPE_DESKTOP_THUMBNAILER (desktop_thumbnailer_get_type ())
+#define DESKTOP_THUMBNAILER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_DESKTOP_THUMBNAILER, DesktopThumbnailer))
+#define DESKTOP_THUMBNAILER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DESKTOP_THUMBNAILER, DesktopThumbnailerClass))
+#define IS_DESKTOP_THUMBNAILER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_DESKTOP_THUMBNAILER))
+#define IS_DESKTOP_THUMBNAILER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DESKTOP_THUMBNAILER)
+#define DESKTOP_THUMBNAILER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DESKTOP_THUMBNAILER, DesktopThumbnailerClass))
+
+typedef struct _DesktopThumbnailerClass DesktopThumbnailerClass;
+typedef struct _DesktopThumbnailer DesktopThumbnailer;
+
+GType desktop_thumbnailer_get_type (void) G_GNUC_CONST;
+void desktop_thumbnailer_register (TumblerProviderPlugin *plugin);
+
+G_END_DECLS
+
+#endif /* !__DESKTOP_THUMBNAILER_H__ */