Author: abrander
Date: 2010-01-14 19:27:24 +0100 (Thu, 14 Jan 2010)
New Revision: 2990

Modified:
   branches/rawstudio-ng-color/src/rs-store.c
Log:
Ported RSStore to the new fancy io-abstraction layer.

Modified: branches/rawstudio-ng-color/src/rs-store.c
===================================================================
--- branches/rawstudio-ng-color/src/rs-store.c  2010-01-14 18:11:23 UTC (rev 
2989)
+++ branches/rawstudio-ng-color/src/rs-store.c  2010-01-14 18:27:24 UTC (rev 
2990)
@@ -33,7 +33,6 @@
 #include "rs-cache.h"
 #include "rs-pixbuf.h"
 #include "eog-pixbuf-cell-renderer.h"
-#include "rs-preload.h"
 #include "rs-photo.h"
 #include "rs-library.h"
 
@@ -86,6 +85,10 @@
        GtkTreePath *tooltip_last_path;
 };
 
+/* Classes to user for io-system */ 
+#define PRELOAD_CLASS (82764283)
+#define METADATA_CLASS (542344)
+
 /* Define the boiler plate stuff using the predefined macro */
 G_DEFINE_TYPE (RSStore, rs_store, GTK_TYPE_HBOX);
 
@@ -107,9 +110,6 @@
        GtkTreePath *path;
 } WORKER_JOB;
 
-static GAsyncQueue *loader_queue = NULL;
-static gpointer worker_thread(gpointer data);
-
 /* FIXME: Remember to remove stores from this too! */
 static GList *all_stores = NULL;
 
@@ -152,6 +152,7 @@
 void store_get_type(GtkListStore *store, GtkTreeIter *iter, gint *type);
 void store_get_fullname(GtkListStore *store, GtkTreeIter *iter, gchar 
**fullname);
 void store_set_members(GtkListStore *store, GtkTreeIter *iter, GList *members);
+void got_metadata(RSMetadata *metadata, gpointer user_data);
 
 /**
  * Class initializer
@@ -192,16 +193,6 @@
                icon_priority_D = gdk_pixbuf_new_from_file(PACKAGE_DATA_DIR 
"/pixmaps/" PACKAGE "/overlay_deleted.png", NULL);
                icon_exported = gdk_pixbuf_new_from_file(PACKAGE_DATA_DIR 
"/pixmaps/" PACKAGE "/overlay_exported.png", NULL);
        }
-
-       if (!loader_queue)
-       {
-               gint i = (rs_get_number_of_processor_cores()*3)/2;
-               loader_queue = g_async_queue_new();
-               while(i--)
-               {
-                       g_thread_create(worker_thread, NULL, FALSE, NULL);
-               }
-       }
 }
 
 /**
@@ -361,7 +352,7 @@
        gchar *filename;
        gtk_tree_model_get(model, iter, FULLNAME_COLUMN, &filename, -1);
 
-       rs_preload(filename);
+       rs_io_idle_prefetch_file(filename, PRELOAD_CLASS);
 }
 
 static void
@@ -374,7 +365,7 @@
        GtkTreePath *path, *next, *prev;
        GtkTreeModel *model = gtk_icon_view_get_model (iconview);
 
-       rs_preload_cancel_all();
+       rs_io_idle_cancel_class(PRELOAD_CLASS);
 
        /* Get a list of selected icons */
        selected = gtk_icon_view_get_selected_items(iconview);
@@ -1070,7 +1061,8 @@
        job->exported = exported;
        job->model = g_object_ref(GTK_TREE_MODEL(store->store));
        job->path = gtk_tree_model_get_path(GTK_TREE_MODEL(store->store), 
&iter);
-       g_async_queue_push(loader_queue, job);
+
+       rs_io_idle_read_metadata(job->filename, METADATA_CLASS, got_metadata, 
job);
 }
 
 static gint
@@ -1132,9 +1124,7 @@
        GtkTreeIter i;
 
        /* Empty the loader queue */
-       g_async_queue_lock(loader_queue);
-       while(g_async_queue_try_pop_unlocked(loader_queue));
-       g_async_queue_unlock(loader_queue);
+       rs_io_idle_cancel_class(METADATA_CLASS);
 
        /* If we got no store, iterate though all */
        if (!store)
@@ -1212,7 +1202,11 @@
 
        /* Block the priority count */
        g_signal_handler_block(store->store, store->counthandler);
+
+       /* While we're loading, we keep the IO lock to ourself. We need to read 
very basic meta and directory data */
+       rs_io_lock();
        items = load_directory(store, path, library, load_8bit, load_recursive);
+       rs_io_unlock();
 
        /* unset model and make sure we have enough columns */
        for (n=0;n<NUM_VIEWS;n++)
@@ -2392,63 +2386,53 @@
                                                -1);
 }
 
-static gpointer
-worker_thread(gpointer data)
+void
+got_metadata(RSMetadata *metadata, gpointer user_data)
 {
-       WORKER_JOB *job;
+       WORKER_JOB *job = user_data;
        GdkPixbuf *pixbuf, *pixbuf_clean;
        GtkTreeIter iter;
-       RSMetadata *metadata;
 
-       while((job = g_async_queue_pop(loader_queue)))
-       {
-               metadata = rs_metadata_new_from_file(job->filename);
-               g_assert(RS_IS_METADATA(metadata));
+       pixbuf = rs_metadata_get_thumbnail(metadata);
 
-               pixbuf = rs_metadata_get_thumbnail(metadata);
+       if (pixbuf==NULL)
+               /* We will use this, if no thumbnail can be loaded */
+               pixbuf = gtk_widget_render_icon(GTK_WIDGET(job->store),
+                       GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_DIALOG, NULL);
 
-               if (pixbuf==NULL)
-                       /* We will use this, if no thumbnail can be loaded */
-                       pixbuf = gtk_widget_render_icon(GTK_WIDGET(job->store),
-                               GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_DIALOG, 
NULL);
+       pixbuf_clean = gdk_pixbuf_copy(pixbuf);
 
-               pixbuf_clean = gdk_pixbuf_copy(pixbuf);
+       /* Update thumbnail */
+       thumbnail_update(pixbuf, pixbuf_clean, job->priority, job->exported);
 
-               /* Update thumbnail */
-               thumbnail_update(pixbuf, pixbuf_clean, job->priority, 
job->exported);
+       g_assert(pixbuf != NULL);
+       g_assert(pixbuf_clean != NULL);
 
-               g_assert(pixbuf != NULL);
-               g_assert(pixbuf_clean != NULL);
+       /* Add the new thumbnail to the store */
+       gdk_threads_enter();
+       if (tree_find_filename(job->model, job->filename, &iter, NULL))
+       {
+               gtk_list_store_set(GTK_LIST_STORE(job->model), &iter,
+                       METADATA_COLUMN, metadata,
+                       TEXT_COLUMN, job->name,
+                       PIXBUF_COLUMN, pixbuf,
+                       PIXBUF_CLEAN_COLUMN, pixbuf_clean,
+                       -1);
+       }
 
-               /* Add the new thumbnail to the store */
-               gdk_threads_enter();
-               if (tree_find_filename(job->model, job->filename, &iter, NULL))
-               {
-                       gtk_list_store_set(GTK_LIST_STORE(job->model), &iter,
-                               METADATA_COLUMN, metadata,
-                               TEXT_COLUMN, job->name,
-                               PIXBUF_COLUMN, pixbuf,
-                               PIXBUF_CLEAN_COLUMN, pixbuf_clean,
-                               -1);
-               }
+       gdk_threads_leave();
 
-               /* Add to library */
-               rs_library_add_photo_with_metadata(rs_library_get_singleton(), 
job->filename, metadata);
+       /* Add to library */
+       rs_library_add_photo_with_metadata(rs_library_get_singleton(), 
job->filename, metadata);
 
-               gdk_threads_leave();
+       /* The GtkListStore should have ref'ed these */
+       g_object_unref(pixbuf);
+       g_object_unref(pixbuf_clean);
 
-               /* The GtkListStore should have ref'ed these */
-               g_object_unref(pixbuf);
-               g_object_unref(pixbuf_clean);
-
-               /* Clean up the job */
-               g_free(job->filename);
-               gtk_tree_path_free(job->path);
-               g_object_unref(job->store);
-               g_object_unref(job->model);
-               g_free(job);
-       }
-
-       /* This is only to stop gcc from complaining, we will never return */
-       return NULL;
+       /* Clean up the job */
+       g_free(job->filename);
+       gtk_tree_path_free(job->path);
+       g_object_unref(job->store);
+       g_object_unref(job->model);
+       g_free(job);
 }


_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit

Reply via email to