Please review this patch
--
Philip Van Hoof
freelance software developer
Codeminded BVBA - http://codeminded.be
--
Philip Van Hoof, freelance software developer
home: me at pvanhoof dot be
gnome: pvanhoof at gnome dot org
http://pvanhoof.be/blog
http://codeminded.be
Index: src/tracker-indexer/tracker-thumbnailer.c
===
--- src/tracker-indexer/tracker-thumbnailer.c (revision 0)
+++ src/tracker-indexer/tracker-thumbnailer.c (revision 0)
@@ -0,0 +1,290 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2006, Mr Jamie McCracken ([EMAIL PROTECTED])
+ * Copyright (C) 2008, Nokia
+
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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.
+ */
+
+#include "config.h"
+
+#include "tracker-dbus.h"
+
+/* Undef this to disable thumbnailing (don't remove unless you understand that
+ * that either you need to put in place another method to disable/enable this
+ * and that what will be used by the packager is probably *your* default,
+ * or unless you want to break expected functionality on-purpose)
+ *
+ * (It's not the first time that these ifdef-else-endifs where rewrapped
+ * incorrectly, and that way obviously broke the feature)
+ */
+
+#ifndef THUMBNAILING_OVER_DBUS
+#define THUMBNAILING_OVER_DBUS
+#endif
+
+#ifdef THUMBNAILING_OVER_DBUS
+
+static GStrvthumbnailable = NULL;
+static gchar *batch[51] = { 0 };
+static gchar *hints[51] = { 0 };
+static guintcount = 0;
+static gboolean timeout_runs = FALSE;
+
+static void
+thumbnail_generic_cb (DBusGProxy *proxy,
+ DBusGProxyCall *call,
+ gpointer user_data)
+{
+ GError *error = NULL;
+ guint handle;
+
+ /* The point of this is dbus-glib correctness. Answering this because
+ * this comment used to be the question: what is the point of this.
+ * It's correct this way because we do asynchronous DBus calls using
+ * glib-dbus. For asynchronous DBus calls it's recommended (if not
+ * required for cleaning up) to call dbus_g_proxy_end_call. */
+
+ dbus_g_proxy_end_call (proxy, call, &error,
+ G_TYPE_UINT, &handle,
+ G_TYPE_INVALID);
+
+ if (error) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
+}
+
+static gboolean
+thumbnail_this (GStrv list, const gchar *mime)
+{
+ guint i = 0;
+ gboolean retval = FALSE;
+
+ if (!list)
+ return TRUE;
+
+ while (list[i] != NULL && !retval) {
+ if (g_ascii_strcasecmp (list[i], mime) == 0)
+ retval = TRUE;
+ i++;
+ }
+
+ return retval;
+
+}
+
+static gboolean
+request_thumbnails (gpointer data)
+{
+ if (timeout_runs) {
+ guint i;
+
+ timeout_runs = FALSE;
+ batch[count] = NULL;
+ hints[count] = NULL;
+
+ g_debug ("Requesting thumbnails");
+
+ dbus_g_proxy_begin_call (tracker_dbus_get_thumbnailer (),
+ "Queue",
+ thumbnail_generic_cb,
+ NULL, NULL,
+ G_TYPE_STRV, batch,
+ G_TYPE_STRV, hints,
+ G_TYPE_UINT, 0,
+ G_TYPE_INVALID);
+
+ for (i = 0; i <= count; i++) {
+ g_free (batch[i]);
+ g_free (hints[i]);
+ batch[i] = NULL;
+ hints[i] = NULL;
+ }
+
+ count = 0;
+ }
+
+ return FALSE;
+}
+
+
+static void
+prepare_thumbnailer (void)
+{
+ static gboolean tried = FALSE;
+
+ /* It's known that this relatively small GStrv is leaked: it contains
+ * the MIME types that the DBus thumbnailer supports. If a MIME type
+ * is not within this list, yet we retrieved it once, then we decide
+ * not to perform thumbnail actions over DBus. This is a performance
+ * improvement and the GStrv can be resident in memory until the end
+ * of the application - it's a cache -
+ *
+ * It doesn't support detecting when the DBus thumbnailer starts
+ * supporting more formats (which can indeed start happening). This is
+ * a known tradeoff and limitation of this cache. We could enhance this
+ * cache to listen for changes on the bus, and invalidate it once we
+ * know that more MIME types have become supported. It has no high
+ * priority now, though (therefore, is this a TODO). */
+
+ if (!tried) {
+ GStrv mimes = NULL;
+ GError *error = NULL;
+
+ dbus_g_proxy_call (tracker_dbus_get_thumb_manager(),
+ "GetSupported", &error, G_TYPE_INVALID,
+ G_TYPE_STRV, &mimes, G_TYPE_INVALID);
+ if (error)
+ g_error_free (error);
+