[f-spot/rubenv-gsoc-2009: 13/86] Add a progress reporting signal.



commit 65340e724a83896ba7d1af439468307707fcac31
Author: Ruben Vermeersch <ruben savanne be>
Date:   Sun Jul 19 00:15:38 2009 +0200

    Add a progress reporting signal.

 lib/libfspotraw-sharp/Makefile.am               |    5 +++
 lib/libfspotraw-sharp/libfspotraw.metadata      |    4 ++
 lib/libfspotraw-sharp/libfspotraw.sources       |    1 +
 lib/libfspotraw/.gitignore                      |    2 +
 lib/libfspotraw/Makefile.am                     |   21 ++++++++++++-
 lib/libfspotraw/fspot-librawloader-marshal.list |    1 +
 lib/libfspotraw/fspot-librawloader.cpp          |   39 +++++++++++++++++++++++
 lib/libfspotraw/fspot-librawloader.h            |    8 +----
 src/Loaders/LibrawImageLoader.cs                |    3 ++
 9 files changed, 76 insertions(+), 8 deletions(-)
---
diff --git a/lib/libfspotraw-sharp/Makefile.am b/lib/libfspotraw-sharp/Makefile.am
index 9f044a5..d5419ec 100644
--- a/lib/libfspotraw-sharp/Makefile.am
+++ b/lib/libfspotraw-sharp/Makefile.am
@@ -12,10 +12,15 @@ ASSEMBLIES =				\
 
 all: libfspotraw-sharp.dll
 
+
+
+# The stuff below is needed because gapi2-parser doesn't like .cpp files
 libfspotraw-api.raw: libfspotraw.sources
 	@echo -e "\n*** Extracting the API"
 	touch $@
+	cp $(srcdir)/../libfspotraw/fspot-librawloader.cpp $(srcdir)/../libfspotraw/fspot-librawloader.c
 	gapi2-parser $<
+	rm $(srcdir)/../libfspotraw/fspot-librawloader.c
 
 libfspotraw-api.xml: $(srcdir)/libfspotraw-api.raw $(srcdir)/libfspotraw.metadata
 	@echo -e "\n*** Massaging the raw api into $@"
diff --git a/lib/libfspotraw-sharp/libfspotraw.metadata b/lib/libfspotraw-sharp/libfspotraw.metadata
index 0555939..d423220 100644
--- a/lib/libfspotraw-sharp/libfspotraw.metadata
+++ b/lib/libfspotraw-sharp/libfspotraw.metadata
@@ -2,4 +2,8 @@
 <metadata>
 	<attr path="/api/namespace" name="name">FSpot.Loaders.Native</attr>
 	<attr path="/api/namespace/object[ cname='FSpotLibrawLoader']" name="name">NativeLibrawLoader</attr>
+
+	<!-- Yes, it's here twice, for some reason it generates two bogus nodes -->
+	<remove-node path="/api/namespace/object/property[ type='class']" />
+	<remove-node path="/api/namespace/object/property[ type='class']" />
 </metadata>
diff --git a/lib/libfspotraw-sharp/libfspotraw.sources b/lib/libfspotraw-sharp/libfspotraw.sources
index 9c72eff..f7b2f48 100644
--- a/lib/libfspotraw-sharp/libfspotraw.sources
+++ b/lib/libfspotraw-sharp/libfspotraw.sources
@@ -3,6 +3,7 @@
 		<library name="libfspotraw.dll">
 			<namespace name="FSpot">
 				<file>../libfspotraw/fspot-librawloader.h</file>
+				<file>../libfspotraw/fspot-librawloader.c</file>
 			</namespace>
 		</library>
 	</api>
diff --git a/lib/libfspotraw/.gitignore b/lib/libfspotraw/.gitignore
index 33b9466..937361d 100644
--- a/lib/libfspotraw/.gitignore
+++ b/lib/libfspotraw/.gitignore
@@ -6,3 +6,5 @@
 /*.lo
 /*.la
 /LibRaw-*.tar.gz
+/fspot-librawloader-marshal.c
+/fspot-librawloader-marshal.h
diff --git a/lib/libfspotraw/Makefile.am b/lib/libfspotraw/Makefile.am
index 02ddd85..24f80b6 100644
--- a/lib/libfspotraw/Makefile.am
+++ b/lib/libfspotraw/Makefile.am
@@ -34,5 +34,24 @@ extract: $(LIBRAW).tar.gz
 	mv $(LIBRAW) LibRaw
 	git add LibRaw
 
-EXTRA_DIST = 	\
+EXTRA_DIST = 						\
+	fspot-librawloader-marshal.list	\
 	LibRaw/COPYRIGHT
+
+MPREFIX = fspot_librawloader_marshal
+TMPNAME = $(srcdir)/fspot-librawloader-marshal.tmp
+LIST = $(srcdir)/fspot-librawloader-marshal.list
+
+fspot-librawloader-marshal.h: $(LIST)
+	( @GLIB_GENMARSHAL@ --prefix=$(MPREFIX) $< --header > $(TMPNAME) \
+	&& mv $(TMPNAME) $@  ) || ( rm -f $(TMPNAME) && exit 1 )
+
+fspot-librawloader-marshal.c: fspot-librawloader-marshal.h
+	( @GLIB_GENMARSHAL@ --prefix=$(MPREFIX) $(LIST) --body > $(TMPNAME) \
+	&& mv $(TMPNAME) $@ ) || ( rm -f $(TMPNAME) && exit 1 )
+
+MARSHAL_GENERATED = fspot-librawloader-marshal.c fspot-librawloader-marshal.h
+
+BUILT_SOURCES = $(MARSHAL_GENERATED)
+
+CLEANFILES = $(MARSHAL_GENERATED)
diff --git a/lib/libfspotraw/fspot-librawloader-marshal.list b/lib/libfspotraw/fspot-librawloader-marshal.list
new file mode 100644
index 0000000..1ae86ea
--- /dev/null
+++ b/lib/libfspotraw/fspot-librawloader-marshal.list
@@ -0,0 +1 @@
+NONE:UINT,UINT
diff --git a/lib/libfspotraw/fspot-librawloader.cpp b/lib/libfspotraw/fspot-librawloader.cpp
index be6ab1c..9ae951e 100644
--- a/lib/libfspotraw/fspot-librawloader.cpp
+++ b/lib/libfspotraw/fspot-librawloader.cpp
@@ -8,11 +8,25 @@
 //
 
 #include "fspot-librawloader.h"
+#include "fspot-librawloader-marshal.h"
 
 #include <libraw/libraw.h>
 
 G_DEFINE_TYPE (FSpotLibrawLoader, fspot_librawloader, G_TYPE_OBJECT);
 
+enum {
+	PROGRESS_UPDATED,
+	LAST_SIGNAL
+};
+
+enum {
+	PROP_0,
+	PROP_FILENAME,
+	PROP_PROGRESS
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
 static void
 fspot_librawloader_set_property (GObject	  *object,
 								 guint		   property_id,
@@ -28,6 +42,8 @@ static void fspot_librawloader_finalize (GObject *object);
 
 static void open_if_needed (FSpotLibrawLoader *self);
 
+static int libraw_progress_callback (void *user_data, enum LibRaw_progress p, int iteration, int expected);
+
 #define FSPOT_LIBRAWLOADER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), FSPOT_TYPE_LIBRAWLOADER, FSpotLibrawLoaderPriv))
 
 struct _FSpotLibrawLoaderPriv
@@ -50,6 +66,17 @@ fspot_librawloader_class_init (FSpotLibrawLoaderClass *klass)
 	gobject_class->dispose      = fspot_librawloader_dispose;
 	gobject_class->finalize     = fspot_librawloader_finalize;
 
+	signals[PROGRESS_UPDATED] =
+		g_signal_new ("progress-updated",
+				G_OBJECT_CLASS_TYPE (gobject_class),
+				G_SIGNAL_RUN_LAST,
+				G_STRUCT_OFFSET (FSpotLibrawLoaderClass, progress_updated),
+				NULL, NULL,
+				fspot_librawloader_marshal_VOID__UINT_UINT,
+				G_TYPE_NONE, 2,
+				G_TYPE_UINT,
+				G_TYPE_UINT);
+
 	pspec = g_param_spec_string ("filename",
 								 "The full path of the RAW files.",
 								 "Set filename",
@@ -81,6 +108,8 @@ fspot_librawloader_init (FSpotLibrawLoader *self)
 	self->priv->raw_proc = new LibRaw;
 	self->priv->opened = false;
 	self->priv->progress = 0;
+
+	self->priv->raw_proc->set_progress_handler (libraw_progress_callback, self);
 }
 
 static void
@@ -221,3 +250,13 @@ open_if_needed (FSpotLibrawLoader *self)
 		self->priv->opened = true;
 	}
 }
+
+static int
+libraw_progress_callback (void *user_data, enum LibRaw_progress p, int iteration, int expected)
+{
+	FSpotLibrawLoader *self = FSPOT_LIBRAWLOADER (user_data);
+
+	g_print ("Emitting %d/%d\n", iteration, expected);
+	g_signal_emit (self, signals[PROGRESS_UPDATED], 0, iteration, expected);
+	return 0;
+}
diff --git a/lib/libfspotraw/fspot-librawloader.h b/lib/libfspotraw/fspot-librawloader.h
index cab47bd..27bb548 100644
--- a/lib/libfspotraw/fspot-librawloader.h
+++ b/lib/libfspotraw/fspot-librawloader.h
@@ -22,13 +22,6 @@ G_BEGIN_DECLS
 #define FSPOT_IS_LIBRAWLOADER_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE ((klass), FSPOT_TYPE_LIBRAWLOADER))
 #define FSPOT_LIBRAWLOADER_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS ((obj), FSPOT_TYPE_LIBRAWLOADER, FSpotLibrawLoaderClass))
 
-enum {
-	PROP_0,
-
-	PROP_FILENAME,
-	PROP_PROGRESS
-};
-
 typedef struct _FSpotLibrawLoader		FSpotLibrawLoader;
 typedef struct _FSpotLibrawLoaderClass	FSpotLibrawLoaderClass;
 typedef struct _FSpotLibrawLoaderPriv	FSpotLibrawLoaderPriv;
@@ -45,6 +38,7 @@ struct _FSpotLibrawLoaderClass
 {
 	GObjectClass parent_class;
 
+	void (* progress_updated) (FSpotLibrawLoader *loader, guint done, guint total);
 };
 
 GType fspot_librawloader_get_type (void);
diff --git a/src/Loaders/LibrawImageLoader.cs b/src/Loaders/LibrawImageLoader.cs
index 7ecf04b..68744fe 100644
--- a/src/Loaders/LibrawImageLoader.cs
+++ b/src/Loaders/LibrawImageLoader.cs
@@ -55,6 +55,9 @@ namespace FSpot.Loaders {
 
 		void LoadFull ()
 		{
+			loader.ProgressUpdated += delegate (object o, ProgressUpdatedArgs args) {
+				Log.Debug ("Loading RAW: {0}/{1}", args.Done, args.Total);
+			};
 			full = loader.LoadFull ();
 			PixbufOrientation = PixbufOrientation.TopLeft;
 			GLib.Idle.Add (delegate {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]