Skip to content

Commit

Permalink
Generate marshallers with glib-genmarshal,
Browse files Browse the repository at this point in the history
Shamelessly copied from thunar
  • Loading branch information
stephanarts committed Nov 13, 2010
1 parent 98f6df2 commit 8ffd71d
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 68 deletions.
39 changes: 39 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 = \
Expand Down Expand Up @@ -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 = \
Expand Down
2 changes: 2 additions & 0 deletions src/marshal.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VOID:OBJECT,OBJECT
VOID:UINT,BOXED
57 changes: 1 addition & 56 deletions src/picture_viewer.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "image_list.h"
#include "picture_viewer.h"
#include "settings.h"
#include "marshal.h"

typedef enum
{
Expand Down Expand Up @@ -127,14 +128,6 @@ rstto_picture_viewer_queued_repaint (RsttoPictureViewer *viewer, gboolean refres
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
Expand Down Expand Up @@ -219,54 +212,6 @@ rstto_picture_viewer_init(RsttoPictureViewer *viewer)
GDK_ACTION_COPY | GDK_ACTION_LINK | GDK_ACTION_MOVE | GDK_ACTION_PRIVATE);
}

/**
* 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:
Expand Down
87 changes: 75 additions & 12 deletions src/thumbnailer.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "image.h"
#include "thumbnail.h"
#include "thumbnailer.h"
#include "marshal.h"

static void
rstto_thumbnailer_init (GObject *);
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 */
}

Expand All @@ -297,21 +335,46 @@ 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;
}

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);
}
}
}

/*
Expand Down

0 comments on commit 8ffd71d

Please sign in to comment.