[Goodies-commits] r6456 - ristretto/branches/ristretto-gio/src
Stephan Arts
stephan at xfce.org
Wed Jan 14 16:26:02 CET 2009
Author: stephan
Date: 2009-01-14 15:26:02 +0000 (Wed, 14 Jan 2009)
New Revision: 6456
Modified:
ristretto/branches/ristretto-gio/src/image.c
ristretto/branches/ristretto-gio/src/main.c
ristretto/branches/ristretto-gio/src/main_window.c
ristretto/branches/ristretto-gio/src/navigator.c
Log:
Removed threading
Modified: ristretto/branches/ristretto-gio/src/image.c
===================================================================
--- ristretto/branches/ristretto-gio/src/image.c 2009-01-14 06:55:45 UTC (rev 6455)
+++ ristretto/branches/ristretto-gio/src/image.c 2009-01-14 15:26:02 UTC (rev 6456)
@@ -29,6 +29,10 @@
#include "image_transformation.h"
#include "image_transform_orientation.h"
+#ifndef RSTTO_IMAGE_BUFFER_SIZE
+#define RSTTO_IMAGE_BUFFER_SIZE 1024
+#endif
+
enum
{
RSTTO_IMAGE_SIGNAL_UPDATED= 0,
@@ -52,6 +56,8 @@
static void
cb_rstto_image_read_file_ready (GObject *source_object, GAsyncResult *result, gpointer user_data);
+static void
+cb_rstto_image_read_input_stream_ready (GObject *source_object, GAsyncResult *result, gpointer user_data);
static GObjectClass *parent_class = NULL;
@@ -103,15 +109,7 @@
GList *transformations;
- GThread *load_thread;
-
- struct
- {
- GMutex *exif;
- GMutex *thumbnail;
- GMutex *pixbuf;
- GMutex *loader;
- } mutex;
+ guchar *buffer;
};
@@ -122,10 +120,7 @@
image->priv = g_new0 (RsttoImagePriv, 1);
- image->priv->mutex.exif = g_mutex_new();
- image->priv->mutex.thumbnail = g_mutex_new();
- image->priv->mutex.pixbuf = g_mutex_new();
- image->priv->mutex.loader = g_mutex_new();
+ image->priv->buffer = g_new0 (guchar, RSTTO_IMAGE_BUFFER_SIZE);
}
@@ -196,13 +191,14 @@
{
g_list_foreach (image->priv->transformations, (GFunc)g_object_unref, NULL);
g_list_free (image->priv->transformations);
- image->priv->transformations;
+ image->priv->transformations = NULL;
}
- g_mutex_free (image->priv->mutex.loader);
- g_mutex_free (image->priv->mutex.exif);
- g_mutex_free (image->priv->mutex.thumbnail);
- g_mutex_free (image->priv->mutex.pixbuf);
+ if (image->priv->buffer)
+ {
+ g_free (image->priv->buffer);
+ image->priv->buffer = NULL;
+ }
}
@@ -281,59 +277,64 @@
}
-static gpointer
-cb_rstto_image_load (RsttoImage *image)
+static void
+cb_rstto_image_read_file_ready (GObject *source_object, GAsyncResult *result, gpointer user_data)
{
- GFileInputStream *input_stream = NULL;
- gssize read_bytes = 0;
- guchar buffer[1024];
+ GFile *file = G_FILE (source_object);
+ RsttoImage *image = RSTTO_IMAGE (user_data);
- input_stream = g_file_read (image->priv->file, FALSE, NULL);
+ GFileInputStream *file_input_stream = g_file_read_finish (file, result, NULL);
- while (1)
- {
+ g_input_stream_read_async (G_INPUT_STREAM (file_input_stream),
+ image->priv->buffer,
+ RSTTO_IMAGE_BUFFER_SIZE,
+ G_PRIORITY_DEFAULT,
+ NULL,
+ (GAsyncReadyCallback) cb_rstto_image_read_input_stream_ready,
+ image);
+}
- g_mutex_lock (image->priv->mutex.loader);
- if (image->priv->loader == NULL)
- {
- g_mutex_unlock (image->priv->mutex.loader);
- break;
- }
+static void
+cb_rstto_image_read_input_stream_ready (GObject *source_object, GAsyncResult *result, gpointer user_data)
+{
+ RsttoImage *image = RSTTO_IMAGE (user_data);
+ gssize read_bytes = g_input_stream_read_finish (G_INPUT_STREAM (source_object), result, NULL);
+ GError *error = NULL;
- read_bytes = g_input_stream_read (G_INPUT_STREAM (input_stream), &buffer, 1024, NULL, NULL);
-
- if (read_bytes > 0)
+ if (read_bytes > 0)
+ {
+ if(gdk_pixbuf_loader_write (image->priv->loader, (const guchar *)image->priv->buffer, read_bytes, &error) == FALSE)
{
- if(gdk_pixbuf_loader_write(image->priv->loader, (const guchar *)buffer, read_bytes, NULL) == FALSE)
- {
- /* PARSE ERROR */
- g_mutex_unlock (image->priv->mutex.loader);
- break;
- }
+ g_input_stream_close (G_INPUT_STREAM (source_object), NULL, NULL);
}
else
- if (read_bytes == 0)
{
- /* OK */
- gdk_pixbuf_loader_close (image->priv->loader, NULL);
- image->priv->loader = NULL;
- g_mutex_unlock (image->priv->mutex.loader);
- break;
+ g_input_stream_read_async (G_INPUT_STREAM (source_object),
+ image->priv->buffer,
+ RSTTO_IMAGE_BUFFER_SIZE,
+ G_PRIORITY_DEFAULT,
+ NULL,
+ (GAsyncReadyCallback) cb_rstto_image_read_input_stream_ready,
+ image);
}
- else
- {
- /* I/O ERROR */
- gdk_pixbuf_loader_close (image->priv->loader, NULL);
- image->priv->loader = NULL;
- g_mutex_unlock (image->priv->mutex.loader);
- break;
- }
- g_mutex_unlock (image->priv->mutex.loader);
}
+ else
+ if (read_bytes == 0)
+ {
+ /* OK */
+ g_input_stream_close (G_INPUT_STREAM (source_object), NULL, NULL);
+ gdk_pixbuf_loader_close (image->priv->loader, NULL);
+ image->priv->loader = NULL;
+ }
+ else
+ {
+ /* I/O ERROR */
+ g_input_stream_close (G_INPUT_STREAM (source_object), NULL, NULL);
+ gdk_pixbuf_loader_close (image->priv->loader, NULL);
+ image->priv->loader = NULL;
+ }
}
-
-
/**
* rstto_image_load:
* @image : The image to load from disk.
@@ -384,7 +385,7 @@
rstto_image_cache_push_image (cache, image);
- image->priv->load_thread = g_thread_create ((GThreadFunc)cb_rstto_image_load, image, TRUE, NULL);
+ g_file_read_async (image->priv->file, 0, NULL, (GAsyncReadyCallback)cb_rstto_image_read_file_ready, image);
}
else
{
@@ -404,16 +405,12 @@
{
g_return_if_fail (image != NULL);
- g_mutex_lock (image->priv->mutex.loader);
if (image->priv->loader)
{
gdk_pixbuf_loader_close (image->priv->loader, NULL);
image->priv->loader = NULL;
}
- g_mutex_unlock (image->priv->mutex.loader);
- g_thread_join (image->priv->load_thread);
-
if (image->priv->pixbuf)
{
g_object_unref (image->priv->pixbuf);
Modified: ristretto/branches/ristretto-gio/src/main.c
===================================================================
--- ristretto/branches/ristretto-gio/src/main.c 2009-01-14 06:55:45 UTC (rev 6455)
+++ ristretto/branches/ristretto-gio/src/main.c 2009-01-14 15:26:02 UTC (rev 6456)
@@ -40,12 +40,11 @@
RsttoNavigator *navigator;
gint argc;
gchar **argv;
+ gint iter;
} RsttoOpenFiles;
-static gpointer
-cb_rstto_open_files (RsttoOpenFiles *rof);
static gboolean
-cb_rstto_start_open_files_thread (RsttoOpenFiles *rof);
+cb_rstto_open_files (RsttoOpenFiles *rof);
static GOptionEntry entries[] =
@@ -77,13 +76,6 @@
textdomain (GETTEXT_PACKAGE);
#endif
- if (!g_thread_supported ())
- {
- g_debug ("Threading supported, initializing...");
- g_thread_init (NULL);
- }
-
-
if(!gtk_init_with_args(&argc, &argv, _(""), entries, PACKAGE, &cli_error))
{
if (cli_error != NULL)
@@ -114,8 +106,9 @@
rof.navigator = navigator;
rof.argc = argc;
rof.argv = argv;
+ rof.iter = 1;
- gtk_init_add((GtkFunction)cb_rstto_start_open_files_thread, &rof);
+ g_idle_add ((GSourceFunc )cb_rstto_open_files, &rof);
}
@@ -132,19 +125,14 @@
}
static gboolean
-cb_rstto_start_open_files_thread (RsttoOpenFiles *rof)
-{
- g_thread_create ((GThreadFunc)cb_rstto_open_files, rof, FALSE, NULL);
- return FALSE;
-}
-
-static gpointer
cb_rstto_open_files (RsttoOpenFiles *rof)
{
- gint i = 0;
- for (i = 1; i < rof->argc; ++i)
+ if (rof->iter < rof->argc)
{
- GFile *file = g_file_new_for_commandline_arg (rof->argv[i]);
+ GFile *file = g_file_new_for_commandline_arg (rof->argv[rof->iter]);
rstto_navigator_add_file (rof->navigator, file);
+ rof->iter++;
+ return TRUE;
}
+ return FALSE;
}
Modified: ristretto/branches/ristretto-gio/src/main_window.c
===================================================================
--- ristretto/branches/ristretto-gio/src/main_window.c 2009-01-14 06:55:45 UTC (rev 6455)
+++ ristretto/branches/ristretto-gio/src/main_window.c 2009-01-14 15:26:02 UTC (rev 6456)
@@ -309,7 +309,7 @@
title = g_strdup_printf ("%s - %s [%d/%d]", RISTRETTO_APP_TITLE, basename, -1, -1);
gtk_window_set_title (GTK_WINDOW (window), title);
- //rstto_picture_viewer_set_image (RSTTO_PICTURE_VIEWER (window->priv->picture_viewer), image);
+ rstto_picture_viewer_set_image (RSTTO_PICTURE_VIEWER (window->priv->picture_viewer), image);
g_free (basename);
g_free (path);
Modified: ristretto/branches/ristretto-gio/src/navigator.c
===================================================================
--- ristretto/branches/ristretto-gio/src/navigator.c 2009-01-14 06:55:45 UTC (rev 6455)
+++ ristretto/branches/ristretto-gio/src/navigator.c 2009-01-14 15:26:02 UTC (rev 6456)
@@ -35,8 +35,6 @@
static void
rstto_navigator_dispose(GObject *object);
-static GStaticMutex rstto_navigator_image_mutex = G_STATIC_MUTEX_INIT;
-
static GObjectClass *parent_class = NULL;
enum
@@ -53,7 +51,6 @@
struct _RsttoNavigatorPriv
{
GList *images;
- GMutex *images_mutex;
};
static gint rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_COUNT];
@@ -88,7 +85,6 @@
rstto_navigator_init(RsttoNavigator *navigator)
{
navigator->priv = g_new0 (RsttoNavigatorPriv, 1);
- navigator->priv->images_mutex = g_mutex_new();
}
static void
@@ -134,9 +130,7 @@
{
RsttoImage *image = rstto_image_new (file);
- g_static_mutex_lock (&rstto_navigator_image_mutex);
navigator->priv->images = g_list_prepend (navigator->priv->images, image);
- g_static_mutex_unlock (&rstto_navigator_image_mutex);
g_signal_emit (G_OBJECT (navigator), rstto_navigator_signals[RSTTO_NAVIGATOR_SIGNAL_NEW_IMAGE], 0, image, NULL);
}
@@ -146,9 +140,7 @@
{
RsttoNavigatorIter *iter = g_new0 (RsttoNavigatorIter, 1);
- g_static_mutex_lock (&rstto_navigator_image_mutex);
iter->data = navigator->priv->images;
- g_static_mutex_unlock (&rstto_navigator_image_mutex);
return iter;
}
@@ -156,7 +148,6 @@
gboolean
rstto_navigator_iter_next (RsttoNavigatorIter *iter)
{
- g_static_mutex_lock (&rstto_navigator_image_mutex);
if (g_list_next (iter->data))
{
iter->data = g_list_next (iter->data);
@@ -165,13 +156,11 @@
{
iter->data = g_list_first (iter->data);
}
- g_static_mutex_unlock (&rstto_navigator_image_mutex);
}
gboolean
rstto_navigator_iter_previous (RsttoNavigatorIter *iter)
{
- g_static_mutex_lock (&rstto_navigator_image_mutex);
if (g_list_previous (iter->data))
{
iter->data = g_list_previous (iter->data);
@@ -180,7 +169,6 @@
{
iter->data = g_list_last (iter->data);
}
- g_static_mutex_unlock (&rstto_navigator_image_mutex);
}
RsttoImage *
More information about the Goodies-commits
mailing list