[tracker/miner-writeback: 2/2] libtracker-miner: Add writeback signal to TrackerMiner



commit 4124761d46f809a140ce54d09841b693ac3fc907
Author: Adrien Bustany <abustany gnome org>
Date:   Thu Mar 25 13:37:40 2010 -0300

    libtracker-miner: Add writeback signal to TrackerMiner
    
    This commits add a new signal "writeback" to the TrackerMiner class. This
    signal is emitted when the store emits the Writeback signal, and only if the
    "writeback-enabled" property was set on the miner at construction time.

 src/libtracker-miner/tracker-miner-0.7.vapi |    1 +
 src/libtracker-miner/tracker-miner-object.c |   58 ++++++++++++++++++++++++++-
 src/libtracker-miner/tracker-miner-object.h |    5 ++
 3 files changed, 63 insertions(+), 1 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-0.7.vapi b/src/libtracker-miner/tracker-miner-0.7.vapi
index d198810..a48862a 100644
--- a/src/libtracker-miner/tracker-miner-0.7.vapi
+++ b/src/libtracker-miner/tracker-miner-0.7.vapi
@@ -36,6 +36,7 @@ namespace Tracker {
 		public virtual void started ();
 		public void stop ();
 		public virtual void stopped ();
+		public virtual void writeback (GLib.HashTable properties);
 		public signal void error (GLib.Error e);
 	}
 	[CCode (ref_function = "tracker_miner_fs_ref", unref_function = "tracker_miner_fs_unref", cheader_filename = "libtracker-miner/tracker-miner-fs.h")]
diff --git a/src/libtracker-miner/tracker-miner-object.c b/src/libtracker-miner/tracker-miner-object.c
index 008c1bd..24e685d 100644
--- a/src/libtracker-miner/tracker-miner-object.c
+++ b/src/libtracker-miner/tracker-miner-object.c
@@ -54,6 +54,7 @@ struct TrackerMinerPrivate {
 	gchar *name;
 	gchar *status;
 	gdouble progress;
+	gboolean writeback_enabled;
 
 	gint availability_cookie;
 
@@ -81,7 +82,8 @@ enum {
 	PROP_0,
 	PROP_NAME,
 	PROP_STATUS,
-	PROP_PROGRESS
+	PROP_PROGRESS,
+	PROP_WRITEBACK_ENABLED
 };
 
 enum {
@@ -92,6 +94,7 @@ enum {
 	PROGRESS,
 	ERROR,
 	IGNORE_NEXT_UPDATE,
+	WRITEBACK,
 	LAST_SIGNAL
 };
 
@@ -121,6 +124,8 @@ static void       sparql_cancelled_cb          (GCancellable  *cancellable,
 static void       store_name_monitor_cb (TrackerMiner *miner,
                                          const gchar  *name,
                                          gboolean      available);
+static void       store_writeback_cb    (const GHashTable *properties,
+                                         gpointer          user_data);
 
 G_DEFINE_ABSTRACT_TYPE (TrackerMiner, tracker_miner, G_TYPE_OBJECT)
 
@@ -258,6 +263,29 @@ tracker_miner_class_init (TrackerMinerClass *klass)
 		              G_TYPE_NONE, 1,
 		              G_TYPE_STRV);
 
+	/**
+	 * TrackerMiner::writeback:
+	 * @miner: the #TrackerMiner
+	 * @properties: a hash table where the keys are the uris of the resource,
+	 *              and the values the name of the properties to writeback.
+	 *
+	 * the ::writeback signal is emitted when a RDF property annotated with
+	 * tracker:writeback is modified. The miner can use that signal to sync
+	 * back the changes from the RDF store to the file.
+	 *
+	 * This signal is only emitted if the "writeback-enabled" property is set
+	 * to true
+	 */
+	signals[WRITEBACK] =
+		g_signal_new ("writeback",
+		              G_OBJECT_CLASS_TYPE (object_class),
+		              G_SIGNAL_RUN_LAST,
+		              G_STRUCT_OFFSET (TrackerMinerClass, writeback),
+		              NULL, NULL,
+		              g_cclosure_marshal_VOID__BOXED,
+		              G_TYPE_NONE, 1,
+		              G_TYPE_PTR_ARRAY);
+
 	g_object_class_install_property (object_class,
 	                                 PROP_NAME,
 	                                 g_param_spec_string ("name",
@@ -281,6 +309,13 @@ tracker_miner_class_init (TrackerMinerClass *klass)
 	                                                      1.0,
 	                                                      0.0,
 	                                                      G_PARAM_READWRITE));
+	g_object_class_install_property (object_class,
+	                                 PROP_WRITEBACK_ENABLED,
+	                                 g_param_spec_boolean ("writeback-enabled",
+	                                                       "Writeback enabled",
+	                                                       "Writeback enabled",
+	                                                       FALSE,
+	                                                       G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 
 	g_type_class_add_private (object_class, sizeof (TrackerMinerPrivate));
 
@@ -355,6 +390,9 @@ miner_set_property (GObject      *object,
 		miner_update_progress (miner);
 		break;
 	}
+	case PROP_WRITEBACK_ENABLED:
+		miner->private->writeback_enabled = g_value_get_boolean (value);
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -379,6 +417,9 @@ miner_get_property (GObject    *object,
 	case PROP_PROGRESS:
 		g_value_set_double (value, miner->private->progress);
 		break;
+	case PROP_WRITEBACK_ENABLED:
+		g_value_set_boolean (value, miner->private->writeback_enabled);
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -431,6 +472,10 @@ miner_constructed (GObject *object)
 	tracker_miner_dbus_init (miner, &dbus_glib_tracker_miner_object_info);
 	tracker_miner_dbus_add_name_watch (miner, "org.freedesktop.Tracker1",
                                        store_name_monitor_cb);
+
+	if (miner->private->writeback_enabled) {
+		tracker_resources_writeback_connect (miner->private->client, store_writeback_cb, miner);
+	}
 }
 
 static void
@@ -469,6 +514,17 @@ store_name_monitor_cb (TrackerMiner *miner,
 	}
 }
 
+static void
+store_writeback_cb (const GHashTable *properties,
+                    gpointer          user_data)
+{
+	g_return_if_fail (properties != NULL);
+	g_return_if_fail (TRACKER_IS_MINER (user_data));
+
+	g_signal_emit (user_data, signals[WRITEBACK], 0,
+	               properties);
+}
+
 static PauseData *
 pause_data_new (const gchar *application,
                 const gchar *reason)
diff --git a/src/libtracker-miner/tracker-miner-object.h b/src/libtracker-miner/tracker-miner-object.h
index 3792742..b9200a8 100644
--- a/src/libtracker-miner/tracker-miner-object.h
+++ b/src/libtracker-miner/tracker-miner-object.h
@@ -63,6 +63,8 @@ struct TrackerMiner {
  * @progress: progress.
  * @error: error.
  * @ignore_next_update: Called after ignore on next update event happens.
+ * @writeback: Called when the store issues a Writeback signal, and if the
+ *             "writeback-enabled" property is set to true.
  *
  * Virtual methods left to implement.
  **/
@@ -85,6 +87,9 @@ typedef struct {
 
 	void (* ignore_next_update) (TrackerMiner *miner,
 	                             const GStrv   urls);
+
+	void (* writeback)          (TrackerMiner     *miner,
+	                             const GHashTable *properties);
 } TrackerMinerClass;
 
 GType            tracker_miner_get_type                    (void) G_GNUC_CONST;



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