[tracker/libtracker-miner] TrackerMinerDiscover: Add miner-progres signal.



commit 20a5a98f87270acfa1cea6126f121440a34aa66b
Author: Carlos Garnacho <carlos lanedo com>
Date:   Tue Sep 1 17:58:43 2009 +0200

    TrackerMinerDiscover: Add miner-progres signal.
    
    With this signal we'll get to know about progress/status in all recognized
    miners.

 src/libtracker-miner/tracker-marshal.list     |    1 +
 src/libtracker-miner/tracker-miner-discover.c |   77 ++++++++++++++++++++++++-
 src/libtracker-miner/tracker-miner-discover.h |    5 ++
 3 files changed, 81 insertions(+), 2 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-marshal.list b/src/libtracker-miner/tracker-marshal.list
index d7f7711..265178b 100644
--- a/src/libtracker-miner/tracker-marshal.list
+++ b/src/libtracker-miner/tracker-marshal.list
@@ -2,6 +2,7 @@ VOID:OBJECT,BOOLEAN
 VOID:OBJECT,OBJECT,BOOLEAN,BOOLEAN
 VOID:POINTER,BOOLEAN,UINT,UINT,UINT,UINT
 VOID:DOUBLE,UINT,UINT,UINT,UINT
+VOID:STRING,STRING,DOUBLE
 VOID:STRING,DOUBLE
 BOOL:OBJECT,OBJECT
 BOOL:OBJECT
diff --git a/src/libtracker-miner/tracker-miner-discover.c b/src/libtracker-miner/tracker-miner-discover.c
index 72fbaa0..624c2d0 100644
--- a/src/libtracker-miner/tracker-miner-discover.c
+++ b/src/libtracker-miner/tracker-miner-discover.c
@@ -26,6 +26,7 @@
 #include "tracker-crawler.h"
 #include "tracker-miner.h"
 #include "tracker-miner-discover.h"
+#include "tracker-marshal.h"
 
 #define TRACKER_MINER_DISCOVER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRACKER_TYPE_MINER_DISCOVER, TrackerMinerDiscoverPrivate))
 
@@ -34,7 +35,7 @@ typedef struct TrackerMinerDiscoverPrivate TrackerMinerDiscoverPrivate;
 struct TrackerMinerDiscoverPrivate {
 	DBusGConnection *connection;
 	DBusGProxy *proxy;
-	TrackerCrawler *crawler;
+	GHashTable *miner_proxies;
 };
 
 static void miner_discover_finalize (GObject *object);
@@ -42,6 +43,13 @@ static void miner_discover_finalize (GObject *object);
 
 G_DEFINE_TYPE (TrackerMinerDiscover, tracker_miner_discover, G_TYPE_OBJECT)
 
+enum {
+	MINER_PROGRESS,
+	LAST_SIGNAL
+};
+
+static guint signals [LAST_SIGNAL] = { 0 };
+
 static void
 tracker_miner_discover_class_init (TrackerMinerDiscoverClass *klass)
 {
@@ -49,14 +57,44 @@ tracker_miner_discover_class_init (TrackerMinerDiscoverClass *klass)
 
 	object_class->finalize = miner_discover_finalize;
 
+	signals [MINER_PROGRESS] =
+		g_signal_new ("miner-progress",
+			      G_OBJECT_CLASS_TYPE (object_class),
+			      G_SIGNAL_RUN_LAST,
+			      G_STRUCT_OFFSET (TrackerMinerDiscoverClass, miner_progress),
+			      NULL, NULL,
+			      tracker_marshal_VOID__STRING_STRING_DOUBLE,
+			      G_TYPE_NONE, 3,
+			      G_TYPE_STRING,
+			      G_TYPE_STRING,
+			      G_TYPE_DOUBLE);
+
 	g_type_class_add_private (object_class, sizeof (TrackerMinerDiscoverPrivate));
 }
 
 static void
+miner_progress_changed (DBusGProxy  *proxy,
+			const gchar *status,
+			gdouble      progress,
+			gpointer     user_data)
+{
+	TrackerMinerDiscover *discover = user_data;
+	TrackerMinerDiscoverPrivate *priv;
+	const gchar *name;
+
+	discover = user_data;
+	priv = TRACKER_MINER_DISCOVER_GET_PRIVATE (discover);
+	name = g_hash_table_lookup (priv->miner_proxies, proxy);
+
+	g_signal_emit (discover, signals[MINER_PROGRESS], 0, name, status, progress);
+}
+
+static void
 tracker_miner_discover_init (TrackerMinerDiscover *discover)
 {
 	TrackerMinerDiscoverPrivate *priv;
 	GError *error = NULL;
+	GSList *miners, *m;
 
 	priv = TRACKER_MINER_DISCOVER_GET_PRIVATE (discover);
 
@@ -77,7 +115,42 @@ tracker_miner_discover_init (TrackerMinerDiscover *discover)
 		g_critical ("Could not get proxy for DBus service");
 	}
 
-	priv->crawler = tracker_crawler_new ();
+	priv->miner_proxies = g_hash_table_new_full (NULL, NULL,
+						     (GDestroyNotify) g_object_unref,
+						     (GDestroyNotify) g_free);
+
+	dbus_g_object_register_marshaller (tracker_marshal_VOID__STRING_DOUBLE,
+					   G_TYPE_NONE,
+					   G_TYPE_STRING,
+					   G_TYPE_DOUBLE,
+					   G_TYPE_INVALID);
+
+	miners = tracker_miner_discover_get_available (discover);
+
+	for (m = miners; m; m = m->next) {
+		DBusGProxy *proxy;
+		gchar *name, *path;
+
+		name = strrchr (m->data, '.');
+		path = g_strdup_printf ("/org/freedesktop/Tracker/Miner/%s", ++name);
+
+		proxy = dbus_g_proxy_new_for_name (priv->connection,
+						   m->data, path,
+						   "org.freedesktop.Tracker.Miner");
+
+		dbus_g_proxy_add_signal (proxy,
+					 "Progress",
+					 G_TYPE_STRING,
+					 G_TYPE_DOUBLE,
+					 G_TYPE_INVALID);
+
+		dbus_g_proxy_connect_signal (proxy,
+					     "Progress",
+					     G_CALLBACK (miner_progress_changed),
+					     discover, NULL);
+
+		g_hash_table_insert (priv->miner_proxies, proxy, g_strdup (m->data));
+	}
 }
 
 static void
diff --git a/src/libtracker-miner/tracker-miner-discover.h b/src/libtracker-miner/tracker-miner-discover.h
index 37cebdb..09196c9 100644
--- a/src/libtracker-miner/tracker-miner-discover.h
+++ b/src/libtracker-miner/tracker-miner-discover.h
@@ -41,6 +41,11 @@ struct TrackerMinerDiscover {
 
 struct TrackerMinerDiscoverClass {
 	GObjectClass parent_class;
+
+	void (* miner_progress) (TrackerMinerDiscover *discover,
+				 const gchar          *miner_name,
+				 const gchar          *status,
+				 gdouble               progress);
 };
 
 GType   tracker_miner_discover_get_type (void) G_GNUC_CONST;



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