[Xfce4-commits] <ristretto:ristretto-0.0> Add rudimentary support for tumbler.
Stephan Arts
noreply at xfce.org
Sun Oct 23 19:24:15 CEST 2011
Updating branch refs/heads/ristretto-0.0
to 6e636bef4a505fb4a42a70a372b7891dc15286b2 (commit)
from 3e01c494643d4cbdff7cb0c08e44028c35c0893a (commit)
commit 6e636bef4a505fb4a42a70a372b7891dc15286b2
Author: Stephan Arts <stephan at xfce.org>
Date: Fri Jan 8 00:29:15 2010 +0100
Add rudimentary support for tumbler.
configure.in.in | 2 +-
src/Makefile.am | 1 +
src/thumbnail.c | 7 +
src/thumbnail.h | 3 +
src/thumbnail_bar.c | 14 +++
src/thumbnailer.c | 314 +++++++++++++++++++++++++++++++++++++++++++++++++++
src/thumbnailer.h | 69 +++++++++++
7 files changed, 409 insertions(+), 1 deletions(-)
diff --git a/configure.in.in b/configure.in.in
index 123a1f1..c71f168 100644
--- a/configure.in.in
+++ b/configure.in.in
@@ -11,7 +11,7 @@ dnl *** Version information ***
dnl ***************************
m4_define([ristretto_version_major], [0])
m4_define([ristretto_version_minor], [0])
-m4_define([ristretto_version_micro], [22])
+m4_define([ristretto_version_micro], [90])
m4_define([ristretto_version_build], [r at REVISION@])
m4_define([ristretto_version_tag], [gio]) # Leave empty for releases
m4_define([ristretto_version], [ristretto_version_major().ristretto_version_minor().ristretto_version_micro()ifelse(ristretto_version_tag(),[],[], [-ifelse(ristretto_version_tag(), [svn], [ristretto_version_tag()-ristretto_version_build()], [ristretto_version_tag()])])])
diff --git a/src/Makefile.am b/src/Makefile.am
index 1fdba5f..e5e8a5f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -14,6 +14,7 @@ ristretto_SOURCES = \
app_menu_item.c app_menu_item.h \
thumbnail_bar.c thumbnail_bar.h \
thumbnail.c thumbnail.h \
+ thumbnailer.c thumbnailer.h \
main.c
ristretto_CFLAGS = \
diff --git a/src/thumbnail.c b/src/thumbnail.c
index 16e8f27..90744d3 100644
--- a/src/thumbnail.c
+++ b/src/thumbnail.c
@@ -339,3 +339,10 @@ rstto_thumbnail_leave (GtkButton *button)
gtk_widget_set_state (GTK_WIDGET (button), GTK_STATE_NORMAL);
gtk_widget_queue_draw (GTK_WIDGET (button));
}
+
+void
+rstto_thumbnail_update (RsttoThumbnail *thumb)
+{
+
+ gtk_widget_queue_draw (GTK_WIDGET (thumb));
+}
diff --git a/src/thumbnail.h b/src/thumbnail.h
index 9b1c054..6d23b62 100644
--- a/src/thumbnail.h
+++ b/src/thumbnail.h
@@ -64,6 +64,9 @@ GType rstto_thumbnail_get_type();
GtkWidget *rstto_thumbnail_new (RsttoImage *image);
RsttoImage *rstto_thumbnail_get_image (RsttoThumbnail *thumb);
+
+void rstto_thumbnail_update (RsttoThumbnail *thumb);
+
G_END_DECLS
#endif /* __RISTRETTO_THUMBNAIL_H__ */
diff --git a/src/thumbnail_bar.c b/src/thumbnail_bar.c
index 02f24d1..db7b832 100644
--- a/src/thumbnail_bar.c
+++ b/src/thumbnail_bar.c
@@ -28,6 +28,7 @@
#include "image_list.h"
#include "thumbnail.h"
#include "thumbnail_bar.h"
+#include "thumbnailer.h"
struct _RsttoThumbnailBarPriv
{
@@ -37,6 +38,7 @@ struct _RsttoThumbnailBarPriv
gboolean auto_center;
gint begin;
gint end;
+
RsttoImageList *image_list;
RsttoImageListIter *iter;
RsttoImageListIter *internal_iter;
@@ -49,6 +51,8 @@ struct _RsttoThumbnailBarPriv
gint offset;
gboolean motion;
} motion;
+
+ RsttoThumbnailer *thumbnailer;
};
static void
@@ -140,6 +144,7 @@ rstto_thumbnail_bar_init(RsttoThumbnailBar *bar)
bar->priv = g_new0(RsttoThumbnailBarPriv, 1);
bar->priv->auto_center = TRUE;
+ bar->priv->thumbnailer = rstto_thumbnailer_new();
GTK_WIDGET_UNSET_FLAGS(bar, GTK_NO_WINDOW);
gtk_widget_set_redraw_on_allocate(GTK_WIDGET(bar), TRUE);
@@ -150,6 +155,7 @@ rstto_thumbnail_bar_init(RsttoThumbnailBar *bar)
bar->priv->offset = 0;
bar->priv->scroll_speed = 20;
+
g_signal_connect(G_OBJECT(bar), "scroll_event", G_CALLBACK(cb_rstto_thumbnail_bar_scroll_event), NULL);
}
@@ -250,6 +256,8 @@ rstto_thumbnail_bar_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
GtkRequisition child_requisition;
GList *iter = bar->priv->thumbs;
+ RsttoImage *image = NULL;
+
gtk_widget_style_get(widget, "spacing", &spacing, NULL);
widget->allocation = *allocation;
@@ -312,9 +320,15 @@ rstto_thumbnail_bar_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
{
gtk_widget_set_child_visible(GTK_WIDGET(iter->data), TRUE);
gtk_widget_size_allocate(GTK_WIDGET(iter->data), &child_allocation);
+
+ /* Do thumbnailing stuff */
+ rstto_thumbnailer_queue_image (bar->priv->thumbnailer, iter->data);
}
else
+ {
gtk_widget_set_child_visible(GTK_WIDGET(iter->data), FALSE);
+ rstto_thumbnailer_dequeue_image (bar->priv->thumbnailer, iter->data);
+ }
child_allocation.x += child_allocation.width + spacing;
iter = g_list_next(iter);
diff --git a/src/thumbnailer.c b/src/thumbnailer.c
new file mode 100644
index 0000000..623f742
--- /dev/null
+++ b/src/thumbnailer.c
@@ -0,0 +1,314 @@
+/*
+ * Copyright (c) 2009 Stephan Arts <stephan at xfce.org>
+ *
+ * This program 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 program 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 General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+
+#include <glib.h>
+#include <gtk/gtk.h>
+#include <gio/gio.h>
+#include <dbus/dbus-glib.h>
+
+#include "image.h"
+#include "thumbnail.h"
+#include "thumbnailer.h"
+
+static void
+rstto_thumbnailer_init (GObject *);
+static void
+rstto_thumbnailer_class_init (GObjectClass *);
+
+static void
+rstto_thumbnailer_dispose (GObject *object);
+static void
+rstto_thumbnailer_finalize (GObject *object);
+
+static void
+rstto_thumbnailer_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void
+rstto_thumbnailer_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec);
+
+static void
+cb_rstto_thumbnailer_request_finished (DBusGProxy *proxy, gint handle, gpointer data);
+static void
+cb_rstto_thumbnailer_thumbnail_ready (DBusGProxy *proxy, gint handle, const gchar **uri, gpointer data);
+
+static gboolean
+rstto_thumbnailer_queue_request_timer (RsttoThumbnailer *thumbnailer);
+
+static GObjectClass *parent_class = NULL;
+
+static RsttoThumbnailer *thumbnailer_object;
+
+enum
+{
+ PROP_0,
+};
+
+GType
+rstto_thumbnailer_get_type (void)
+{
+ static GType rstto_thumbnailer_type = 0;
+
+ if (!rstto_thumbnailer_type)
+ {
+ static const GTypeInfo rstto_thumbnailer_info =
+ {
+ sizeof (RsttoThumbnailerClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) rstto_thumbnailer_class_init,
+ (GClassFinalizeFunc) NULL,
+ NULL,
+ sizeof (RsttoThumbnailer),
+ 0,
+ (GInstanceInitFunc) rstto_thumbnailer_init,
+ NULL
+ };
+
+ rstto_thumbnailer_type = g_type_register_static (G_TYPE_OBJECT, "RsttoThumbnailer", &rstto_thumbnailer_info, 0);
+ }
+ return rstto_thumbnailer_type;
+}
+
+struct _RsttoThumbnailerPriv
+{
+ DBusGConnection *connection;
+ DBusGProxy *proxy;
+ GSList *queue;
+ gint handle;
+
+ gint request_timer_id;
+};
+
+static void
+rstto_thumbnailer_init (GObject *object)
+{
+ RsttoThumbnailer *thumbnailer = RSTTO_THUMBNAILER (object);
+
+ thumbnailer->priv = g_new0 (RsttoThumbnailerPriv, 1);
+ thumbnailer->priv->connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
+ if (thumbnailer->priv->connection)
+ {
+
+ thumbnailer->priv->proxy = dbus_g_proxy_new_for_name (thumbnailer->priv->connection,
+ "org.freedesktop.thumbnails.Thumbnailer1",
+ "/org/freedesktop/thumbnails/Thumbnailer1",
+ "org.freedesktop.thumbnails.Thumbnailer1");
+ dbus_g_proxy_add_signal (thumbnailer->priv->proxy, "Finished", G_TYPE_UINT, G_TYPE_INVALID);
+
+ dbus_g_proxy_connect_signal (thumbnailer->priv->proxy, "Finished", cb_rstto_thumbnailer_request_finished, thumbnailer, NULL);
+ }
+}
+
+
+static void
+rstto_thumbnailer_class_init (GObjectClass *object_class)
+{
+ GParamSpec *pspec;
+
+ RsttoThumbnailerClass *thumbnailer_class = RSTTO_THUMBNAILER_CLASS (object_class);
+
+ parent_class = g_type_class_peek_parent (thumbnailer_class);
+
+ object_class->dispose = rstto_thumbnailer_dispose;
+ object_class->finalize = rstto_thumbnailer_finalize;
+
+ object_class->set_property = rstto_thumbnailer_set_property;
+ object_class->get_property = rstto_thumbnailer_get_property;
+
+}
+
+/**
+ * rstto_thumbnailer_dispose:
+ * @object:
+ *
+ */
+static void
+rstto_thumbnailer_dispose (GObject *object)
+{
+ RsttoThumbnailer *thumbnailer = RSTTO_THUMBNAILER (object);
+
+ if (thumbnailer->priv)
+ {
+ g_free (thumbnailer->priv);
+ thumbnailer->priv = NULL;
+ }
+}
+
+/**
+ * rstto_thumbnailer_finalize:
+ * @object:
+ *
+ */
+static void
+rstto_thumbnailer_finalize (GObject *object)
+{
+}
+
+
+
+/**
+ * rstto_thumbnailer_new:
+ *
+ *
+ * Singleton
+ */
+RsttoThumbnailer *
+rstto_thumbnailer_new (void)
+{
+ if (thumbnailer_object == NULL)
+ {
+ thumbnailer_object = g_object_new (RSTTO_TYPE_THUMBNAILER, NULL);
+ }
+ else
+ {
+ g_object_ref (thumbnailer_object);
+ }
+
+ return thumbnailer_object;
+}
+
+
+static void
+rstto_thumbnailer_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ RsttoThumbnailer *thumbnailer = RSTTO_THUMBNAILER (object);
+
+ switch (property_id)
+ {
+ default:
+ break;
+ }
+
+}
+
+static void
+rstto_thumbnailer_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ RsttoThumbnailer *thumbnailer = RSTTO_THUMBNAILER (object);
+
+ switch (property_id)
+ {
+ default:
+ break;
+ }
+}
+
+void
+rstto_thumbnailer_queue_image (RsttoThumbnailer *thumbnailer, RsttoImage *image)
+{
+ if (thumbnailer->priv->request_timer_id)
+ g_source_remove (thumbnailer->priv->request_timer_id);
+
+ thumbnailer->priv->queue = g_slist_prepend (thumbnailer->priv->queue, image);
+
+ thumbnailer->priv->request_timer_id = g_timeout_add_full (G_PRIORITY_LOW, 100, (GSourceFunc)rstto_thumbnailer_queue_request_timer, thumbnailer, NULL);
+}
+
+void
+rstto_thumbnailer_dequeue_image (RsttoThumbnailer *thumbnailer, RsttoImage *image)
+{
+ if (thumbnailer->priv->request_timer_id)
+ g_source_remove (thumbnailer->priv->request_timer_id);
+
+ thumbnailer->priv->queue = g_slist_remove (thumbnailer->priv->queue, image);
+
+ thumbnailer->priv->request_timer_id = g_timeout_add_full (G_PRIORITY_LOW, 100, (GSourceFunc)rstto_thumbnailer_queue_request_timer, thumbnailer, NULL);
+}
+
+static gboolean
+rstto_thumbnailer_queue_request_timer (RsttoThumbnailer *thumbnailer)
+{
+ gchar **uris;
+ gchar **mimetypes;
+ GSList *iter;
+ gint i = 0;
+ GFile *file;
+ RsttoImage *image;
+ GError *error = NULL;
+
+ uris = g_new0 (gchar *, g_slist_length(thumbnailer->priv->queue)+1);
+ mimetypes = g_new0 (gchar *, g_slist_length(thumbnailer->priv->queue)+1);
+
+ iter = thumbnailer->priv->queue;
+ while (iter)
+ {
+ image = rstto_thumbnail_get_image (RSTTO_THUMBNAIL(iter->data));
+ file = rstto_image_get_file (image);
+ uris[i] = g_file_get_uri (file);
+ mimetypes[i] = "image/jpeg";
+ iter = g_slist_next(iter);
+ i++;
+ }
+
+ if(dbus_g_proxy_call(thumbnailer->priv->proxy,
+ "Queue",
+ &error,
+ G_TYPE_STRV, uris,
+ G_TYPE_STRV, mimetypes,
+ G_TYPE_STRING, "normal",
+ G_TYPE_STRING, "default",
+ G_TYPE_UINT, 0,
+ G_TYPE_INVALID,
+ G_TYPE_UINT, &thumbnailer->priv->handle,
+ G_TYPE_INVALID) == FALSE)
+ {
+ g_debug("call faile:%s", error->message);
+ /* TOOO: Nice cleanup */
+ }
+
+ thumbnailer->priv->request_timer_id = 0;
+ return FALSE;
+}
+
+static void
+cb_rstto_thumbnailer_request_finished (DBusGProxy *proxy, gint handle, gpointer data)
+{
+ RsttoThumbnailer *thumbnailer = RSTTO_THUMBNAILER (data);
+ GSList *iter = thumbnailer->priv->queue;
+ while (iter)
+ {
+ rstto_thumbnail_update (iter->data);
+ iter = g_slist_next(iter);
+ }
+
+ g_debug("Finished");
+}
+
+static void
+cb_rstto_thumbnailer_thumbnail_ready (DBusGProxy *proxy, gint handle, const gchar **uri, gpointer data)
+{
+ g_debug("Ready");
+}
+
+/*
+
+
+*/
diff --git a/src/thumbnailer.h b/src/thumbnailer.h
new file mode 100644
index 0000000..464fc4b
--- /dev/null
+++ b/src/thumbnailer.h
@@ -0,0 +1,69 @@
+/*
+ * This program 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 program 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 General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __RISTRETTO_THUMBNAILER_H__
+#define __RISTRETTO_THUMBNAILER_H__
+
+G_BEGIN_DECLS
+
+#define RSTTO_TYPE_THUMBNAILER rstto_thumbnailer_get_type()
+
+#define RSTTO_THUMBNAILER(obj)( \
+ G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ RSTTO_TYPE_THUMBNAILER, \
+ RsttoThumbnailer))
+
+#define RSTTO_IS_THUMBNAILER(obj)( \
+ G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ RSTTO_TYPE_THUMBNAILER))
+
+#define RSTTO_THUMBNAILER_CLASS(klass)( \
+ G_TYPE_CHECK_CLASS_CAST ((klass), \
+ RSTTO_TYPE_THUMBNAILER, \
+ RsttoThumbnailerClass))
+
+#define RSTTO_IS_THUMBNAILER_CLASS(klass)( \
+ G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ RSTTO_TYPE_THUMBNAILER()))
+
+
+typedef struct _RsttoThumbnailer RsttoThumbnailer;
+typedef struct _RsttoThumbnailerPriv RsttoThumbnailerPriv;
+
+struct _RsttoThumbnailer
+{
+ GObject parent;
+
+ RsttoThumbnailerPriv *priv;
+};
+
+typedef struct _RsttoThumbnailerClass RsttoThumbnailerClass;
+
+struct _RsttoThumbnailerClass
+{
+ GObjectClass parent_class;
+};
+
+RsttoThumbnailer *rstto_thumbnailer_new (void);
+GType rstto_thumbnailer_get_type (void);
+
+void
+rstto_thumbnailer_queue_image (RsttoThumbnailer *thumbnailer, RsttoImage *image);
+void
+rstto_thumbnailer_dequeue_image (RsttoThumbnailer *thumbnailer, RsttoImage *image);
+G_END_DECLS
+
+#endif /* __RISTRETTO_THUMBNAILER_H__ */
More information about the Xfce4-commits
mailing list