[Xfce4-commits] <ristretto:master> Generate marshallers with glib-genmarshal, Shamelessly copied from thunar
Stephan Arts
noreply at xfce.org
Sun Nov 14 00:14:01 CET 2010
Updating branch refs/heads/master
to 8ffd71d67ae57e7b90c53725c648d21d91323cf2 (commit)
from 98f6df249ec64bea9d43842e813ca3b18b8a1923 (commit)
commit 8ffd71d67ae57e7b90c53725c648d21d91323cf2
Author: Stephan Arts <stephan at xfce.org>
Date: Sun Nov 14 00:08:20 2010 +0100
Generate marshallers with glib-genmarshal,
Shamelessly copied from thunar
src/Makefile.am | 39 ++++++++++++++++++++++
src/marshal.list | 2 +
src/picture_viewer.c | 57 +--------------------------------
src/thumbnailer.c | 87 +++++++++++++++++++++++++++++++++++++++++++-------
4 files changed, 117 insertions(+), 68 deletions(-)
diff --git a/src/Makefile.am b/src/Makefile.am
index d429a81..82c6bf7 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -17,6 +17,7 @@ ristretto_SOURCES = \
thumbnail_bar.c thumbnail_bar.h \
thumbnail.c thumbnail.h \
thumbnailer.c thumbnailer.h \
+ marshal.c marshal.h \
main.c
ristretto_CFLAGS = \
@@ -47,14 +48,52 @@ ristretto_LDADD = \
INCLUDES = \
-I${top_srcdir}
+DISTCLEANFILES =
+
if MAINTAINER_MODE
+ristretto_built_sources = \
+ marshal.h \
+ marshal.c
+
BUILT_SOURCES = \
+ $(ristretto_built_sources) \
main_window_ui.h
main_window_ui.h: main_window_ui.xml
exo-csource --strip-comments --strip-content --static --name=main_window_ui $< > $@
+marshal.h: stamp-marshal.h
+ @true
+
+stamp-marshal.h: marshal.list Makefile
+ $(AM_V_GEN) ( \
+ cd $(srcdir) \
+ && echo "#ifndef __RSTTO_MARSHAL_H__" > xgen-tmh \
+ && echo "#define __RSTTO_MARSHAL_H__" >> xgen-tmh \
+ && ( glib-genmarshal \
+ --prefix=rstto_marshal \
+ --header marshal.list ) >> xgen-tmh \
+ && echo "#endif /* !__RSTTO_MARSHAL_H__ */" >> xgen-tmh \
+ && ( cmp -s xgen-tmh marshal.h || cp xgen-tmh marshal.h ) \
+ && rm -f xgen-tmh \
+ && echo timestamp > $(@F) \
+ )
+
+marshal.c: marshal.list Makefile
+ $(AM_V_GEN) ( \
+ cd $(srcdir) \
+ && echo "#include \"marshal.h\"" > xgen-tmc \
+ && ( glib-genmarshal \
+ --prefix=rstto_marshal \
+ --body marshal.list ) >> xgen-tmc \
+ && cp xgen-tmc marshal.c \
+ && rm -f xgen-tmc \
+ )
+
+DISTCLEANFILES += \
+ stamp-marshal.h
+
endif
EXTRA_DIST = \
diff --git a/src/marshal.list b/src/marshal.list
new file mode 100644
index 0000000..cf3ade3
--- /dev/null
+++ b/src/marshal.list
@@ -0,0 +1,2 @@
+VOID:OBJECT,OBJECT
+VOID:UINT,BOXED
diff --git a/src/picture_viewer.c b/src/picture_viewer.c
index b171a39..3e6b9ce 100644
--- a/src/picture_viewer.c
+++ b/src/picture_viewer.c
@@ -29,6 +29,7 @@
#include "image_list.h"
#include "picture_viewer.h"
#include "settings.h"
+#include "marshal.h"
typedef enum
{
@@ -128,14 +129,6 @@ static gboolean
rstto_picture_viewer_set_scroll_adjustments(RsttoPictureViewer *, GtkAdjustment *, GtkAdjustment *);
static void
-rstto_marshal_VOID__OBJECT_OBJECT (GClosure *closure,
- GValue *return_value,
- guint n_param_values,
- const GValue *param_values,
- gpointer invocation_hint,
- gpointer marshal_data);
-
-static void
cb_rstto_picture_viewer_value_changed(GtkAdjustment *, RsttoPictureViewer *);
static void
cb_rstto_picture_viewer_nav_iter_changed (RsttoImageListIter *iter, gpointer user_data);
@@ -220,54 +213,6 @@ rstto_picture_viewer_init(RsttoPictureViewer *viewer)
}
/**
- * rstto_marshal_VOID__OBJECT_OBJECT:
- * @closure:
- * @return_value:
- * @n_param_values:
- * @param_values:
- * @invocation_hint:
- * @marshal_data:
- *
- * A marshaller for the set_scroll_adjustments signal.
- */
-static void
-rstto_marshal_VOID__OBJECT_OBJECT (GClosure *closure,
- GValue *return_value,
- guint n_param_values,
- const GValue *param_values,
- gpointer invocation_hint,
- gpointer marshal_data)
-{
- typedef void (*GMarshalFunc_VOID__OBJECT_OBJECT) (gpointer data1,
- gpointer arg_1,
- gpointer arg_2,
- gpointer data2);
- register GMarshalFunc_VOID__OBJECT_OBJECT callback;
- register GCClosure *cc = (GCClosure*) closure;
- register gpointer data1, data2;
-
- g_return_if_fail (n_param_values == 3);
-
- if (G_CCLOSURE_SWAP_DATA (closure))
- {
- data1 = closure->data;
- data2 = g_value_get_object (param_values + 0);
- }
- else
- {
- data1 = g_value_get_object (param_values + 0);
- data2 = closure->data;
- }
- callback = (GMarshalFunc_VOID__OBJECT_OBJECT) (marshal_data ?
- marshal_data : cc->callback);
-
- callback (data1,
- g_value_get_object (param_values + 1),
- g_value_get_object (param_values + 2),
- data2);
-}
-
-/**
* rstto_picture_viewer_class_init:
* @viewer_class:
*
diff --git a/src/thumbnailer.c b/src/thumbnailer.c
index a9f3434..c742829 100644
--- a/src/thumbnailer.c
+++ b/src/thumbnailer.c
@@ -26,6 +26,7 @@
#include "image.h"
#include "thumbnail.h"
#include "thumbnailer.h"
+#include "marshal.h"
static void
rstto_thumbnailer_init (GObject *);
@@ -115,9 +116,18 @@ rstto_thumbnailer_init (GObject *object)
"org.freedesktop.thumbnails.Thumbnailer1",
"/org/freedesktop/thumbnails/Thumbnailer1",
"org.freedesktop.thumbnails.Thumbnailer1");
+
+ dbus_g_object_register_marshaller ((GClosureMarshal) rstto_marshal_VOID__UINT_BOXED,
+ G_TYPE_NONE,
+ G_TYPE_UINT,
+ G_TYPE_STRV,
+ G_TYPE_INVALID);
+
dbus_g_proxy_add_signal (thumbnailer->priv->proxy, "Finished", G_TYPE_UINT, G_TYPE_INVALID);
+ dbus_g_proxy_add_signal (thumbnailer->priv->proxy, "Ready", G_TYPE_UINT, G_TYPE_STRV, G_TYPE_INVALID);
dbus_g_proxy_connect_signal (thumbnailer->priv->proxy, "Finished", G_CALLBACK(cb_rstto_thumbnailer_request_finished), thumbnailer, NULL);
+ dbus_g_proxy_connect_signal (thumbnailer->priv->proxy, "Ready", G_CALLBACK(cb_rstto_thumbnailer_thumbnail_ready), thumbnailer, NULL);
}
}
@@ -225,22 +235,50 @@ void
rstto_thumbnailer_queue_image (RsttoThumbnailer *thumbnailer, RsttoImage *image)
{
if (thumbnailer->priv->request_timer_id)
+ {
g_source_remove (thumbnailer->priv->request_timer_id);
+ if (thumbnailer->priv->handle)
+ {
+ if(dbus_g_proxy_call(thumbnailer->priv->proxy,
+ "Dequeue",
+ NULL,
+ G_TYPE_UINT, thumbnailer->priv->handle,
+ G_TYPE_INVALID) == FALSE);
+ thumbnailer->priv->handle = 0;
+ }
- 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);
+ if (g_slist_find (thumbnailer->priv->queue, image) == NULL)
+ {
+ thumbnailer->priv->queue = g_slist_prepend (thumbnailer->priv->queue, image);
+ }
+
+ thumbnailer->priv->request_timer_id = g_timeout_add_full (G_PRIORITY_LOW, 300, (GSourceFunc)rstto_thumbnailer_queue_request_timer, thumbnailer, NULL);
+ /* g_debug("%s, len: %d", __FUNCTION__, g_slist_length(thumbnailer->priv->queue)); */
}
void
rstto_thumbnailer_dequeue_image (RsttoThumbnailer *thumbnailer, RsttoImage *image)
{
if (thumbnailer->priv->request_timer_id)
+ {
g_source_remove (thumbnailer->priv->request_timer_id);
+ if (thumbnailer->priv->handle)
+ {
+ if(dbus_g_proxy_call(thumbnailer->priv->proxy,
+ "Dequeue",
+ NULL,
+ G_TYPE_UINT, thumbnailer->priv->handle,
+ G_TYPE_INVALID) == FALSE);
+ thumbnailer->priv->handle = 0;
+ }
+ }
thumbnailer->priv->queue = g_slist_remove_all (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);
+ thumbnailer->priv->request_timer_id = g_timeout_add_full (G_PRIORITY_LOW, 300, (GSourceFunc)rstto_thumbnailer_queue_request_timer, thumbnailer, NULL);
+ /* g_debug("%s, len: %d", __FUNCTION__, g_slist_length(thumbnailer->priv->queue)); */
}
static gboolean
@@ -285,7 +323,7 @@ rstto_thumbnailer_queue_request_timer (RsttoThumbnailer *thumbnailer)
G_TYPE_UINT, &thumbnailer->priv->handle,
G_TYPE_INVALID) == FALSE)
{
- g_debug("call faile:%s", error->message);
+ g_debug("call failed:%s", error->message);
/* TOOO: Nice cleanup */
}
@@ -297,13 +335,6 @@ static void
cb_rstto_thumbnailer_request_finished (DBusGProxy *proxy, gint handle, gpointer data)
{
RsttoThumbnailer *thumbnailer = RSTTO_THUMBNAILER (data);
- GSList *iter = thumbnailer->priv->queue;
- GSList *prev;
- while (iter)
- {
- rstto_thumbnail_update (iter->data);
- iter = g_slist_next(iter);
- }
g_slist_free (thumbnailer->priv->queue);
thumbnailer->priv->queue = NULL;
}
@@ -311,7 +342,39 @@ cb_rstto_thumbnailer_request_finished (DBusGProxy *proxy, gint handle, gpointer
static void
cb_rstto_thumbnailer_thumbnail_ready (DBusGProxy *proxy, gint handle, const gchar **uri, gpointer data)
{
- g_debug("Ready");
+ /* g_debug("Ready"); */
+ RsttoThumbnailer *thumbnailer = RSTTO_THUMBNAILER (data);
+ RsttoThumbnail *thumbnail;
+ RsttoImage *image;
+ GFile *file;
+ GSList *iter = thumbnailer->priv->queue;
+ GSList *prev;
+ gint x = 0;
+ gchar *f_uri;
+ while (iter)
+ {
+ if (uri[x] == NULL)
+ {
+ break;
+ }
+
+ thumbnail = iter->data;
+ image = rstto_thumbnail_get_image (thumbnail);
+ file = rstto_image_get_file (image);
+ f_uri = g_file_get_uri (file);
+ if (strcmp (uri[x], f_uri) == 0)
+ {
+ rstto_thumbnail_update (thumbnail);
+ thumbnailer->priv->queue = g_slist_remove (thumbnailer->priv->queue, iter->data);
+
+ iter = thumbnailer->priv->queue;
+ x++;
+ }
+ else
+ {
+ iter = g_slist_next(iter);
+ }
+ }
}
/*
More information about the Xfce4-commits
mailing list