[tracker/gdbus: 14/101] libtracker-miner: GDBus porting of tracker-miner-manager.c



commit 487d9f65ed2af8061d98f03e32614fc4495b992a
Author: Philip Van Hoof <philip codeminded be>
Date:   Tue Dec 28 14:03:33 2010 +0100

    libtracker-miner: GDBus porting of tracker-miner-manager.c

 src/libtracker-miner/tracker-miner-manager.c |  505 +++++++++++++++-----------
 1 files changed, 302 insertions(+), 203 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-manager.c b/src/libtracker-miner/tracker-miner-manager.c
index 568f86e..f2745af 100644
--- a/src/libtracker-miner/tracker-miner-manager.c
+++ b/src/libtracker-miner/tracker-miner-manager.c
@@ -19,6 +19,8 @@
 
 #include "config.h"
 
+#include <gio/gio.h>
+
 #include <libtracker-common/tracker-dbus.h>
 #include <libtracker-common/tracker-type-utils.h>
 
@@ -26,8 +28,6 @@
 #include "tracker-miner-object.h"
 #include "tracker-miner-manager.h"
 #include "tracker-marshal.h"
-#include "tracker-miner-client.h"
-#include "tracker-miner-files-index-client.h"
 #include "tracker-miner-dbus.h"
 
 /**
@@ -56,12 +56,16 @@ struct MinerData {
 	gchar *dbus_path;
 	gchar *display_name;
 	gchar *description;
+
+	GDBusConnection *connection;
+	guint progress_signal;
+	guint paused_signal;
+	guint resumed_signal;
+	guint watch_name_signal;
 };
 
 struct TrackerMinerManagerPrivate {
-	DBusGConnection *connection;
-	DBusGProxy *proxy;
-
+	GDBusConnection *connection;
 	GList *miners;
 	GHashTable *miner_proxies;
 };
@@ -69,7 +73,6 @@ struct TrackerMinerManagerPrivate {
 static void miner_manager_finalize (GObject *object);
 static void initialize_miners_data (TrackerMinerManager *manager);
 
-
 G_DEFINE_TYPE (TrackerMinerManager, tracker_miner_manager, G_TYPE_OBJECT)
 
 enum {
@@ -185,7 +188,7 @@ tracker_miner_manager_class_init (TrackerMinerManagerClass *klass)
 	g_type_class_add_private (object_class, sizeof (TrackerMinerManagerPrivate));
 }
 
-static DBusGProxy *
+static GDBusProxy *
 find_miner_proxy (TrackerMinerManager *manager,
                   const gchar         *name,
                   gboolean             try_suffix)
@@ -213,68 +216,60 @@ find_miner_proxy (TrackerMinerManager *manager,
 }
 
 static void
-name_owner_changed_cb (DBusGProxy  *proxy,
-                       const gchar *name,
-                       const gchar *old_owner,
-                       const gchar *new_owner,
-                       gpointer     user_data)
+miner_appears (GDBusConnection *connection,
+               const gchar     *name,
+               const gchar     *name_owner,
+               gpointer         user_data)
 {
-	TrackerMinerManager *manager = user_data;
-
-	if (find_miner_proxy (manager, name, FALSE) != NULL) {
-		if (new_owner && (!old_owner || !*old_owner)) {
-			g_signal_emit (manager, signals[MINER_ACTIVATED], 0, name);
-		} else if (old_owner && (!new_owner || !*new_owner)) {
-			g_signal_emit (manager, signals[MINER_DEACTIVATED], 0, name);
-		}
-	}
+	g_signal_emit (user_data, signals[MINER_ACTIVATED], 0, name);
 }
 
 static void
-miner_progress_changed (DBusGProxy  *proxy,
-                        const gchar *status,
-                        gdouble      progress,
-                        gpointer     user_data)
+miner_disappears (GDBusConnection *connection,
+                  const gchar     *name,
+                  gpointer         user_data)
 {
-	TrackerMinerManager *manager = user_data;
-	TrackerMinerManagerPrivate *priv;
-	const gchar *name;
-
-	manager = user_data;
-	priv = TRACKER_MINER_MANAGER_GET_PRIVATE (manager);
-	name = g_hash_table_lookup (priv->miner_proxies, proxy);
-
-	g_signal_emit (manager, signals[MINER_PROGRESS], 0, name, status, progress);
+	g_signal_emit (user_data, signals[MINER_DEACTIVATED], 0, name);
 }
 
 static void
-miner_paused (DBusGProxy *proxy,
-              gpointer    user_data)
+miner_progress_changed (GDBusConnection *connection,
+                        const gchar     *sender_name,
+                        const gchar     *object_path,
+                        const gchar     *interface_name,
+                        const gchar     *signal_name,
+                        GVariant        *parameters,
+                        gpointer         user_data)
 {
-	TrackerMinerManager *manager = user_data;
-	TrackerMinerManagerPrivate *priv;
-	const gchar *name;
-
-	manager = user_data;
-	priv = TRACKER_MINER_MANAGER_GET_PRIVATE (manager);
-	name = g_hash_table_lookup (priv->miner_proxies, proxy);
+	const gchar *status = NULL;
+	gdouble progress = 0;
 
-	g_signal_emit (manager, signals[MINER_PAUSED], 0, name);
+	g_variant_get (parameters, "(sd)", &status, &progress);
+	g_signal_emit (user_data, signals[MINER_PROGRESS], 0, sender_name, status, progress);
 }
 
 static void
-miner_resumed (DBusGProxy *proxy,
-               gpointer    user_data)
+miner_paused (GDBusConnection *connection,
+              const gchar     *sender_name,
+              const gchar     *object_path,
+              const gchar     *interface_name,
+              const gchar     *signal_name,
+              GVariant        *parameters,
+              gpointer         user_data)
 {
-	TrackerMinerManager *manager = user_data;
-	TrackerMinerManagerPrivate *priv;
-	const gchar *name;
-
-	manager = user_data;
-	priv = TRACKER_MINER_MANAGER_GET_PRIVATE (manager);
-	name = g_hash_table_lookup (priv->miner_proxies, proxy);
+	g_signal_emit (user_data, signals[MINER_PAUSED], 0, sender_name);
+}
 
-	g_signal_emit (manager, signals[MINER_RESUMED], 0, name);
+static void
+miner_resumed (GDBusConnection *connection,
+               const gchar     *sender_name,
+               const gchar     *object_path,
+               const gchar     *interface_name,
+               const gchar     *signal_name,
+               GVariant        *parameters,
+               gpointer         user_data)
+{
+	g_signal_emit (user_data, signals[MINER_RESUMED], 0, sender_name);
 }
 
 static void
@@ -286,7 +281,7 @@ tracker_miner_manager_init (TrackerMinerManager *manager)
 
 	priv = TRACKER_MINER_MANAGER_GET_PRIVATE (manager);
 
-	priv->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+	priv->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
 
 	if (!priv->connection) {
 		g_critical ("Could not connect to the D-Bus session bus, %s",
@@ -294,78 +289,102 @@ tracker_miner_manager_init (TrackerMinerManager *manager)
 		g_clear_error (&error);
 	}
 
-	priv->proxy = dbus_g_proxy_new_for_name (priv->connection,
-	                                         DBUS_SERVICE_DBUS,
-	                                         DBUS_PATH_DBUS,
-	                                         DBUS_INTERFACE_DBUS);
-
-	if (!priv->proxy) {
-		g_critical ("Could not get proxy for D-Bus service");
-	}
-
 	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);
-
-	dbus_g_proxy_add_signal (priv->proxy,
-	                         "NameOwnerChanged",
-	                         G_TYPE_STRING,
-	                         G_TYPE_STRING,
-	                         G_TYPE_STRING,
-	                         G_TYPE_INVALID);
-
-	dbus_g_proxy_connect_signal (priv->proxy,
-	                             "NameOwnerChanged",
-	                             G_CALLBACK (name_owner_changed_cb),
-	                             manager, NULL);
-
 	initialize_miners_data (manager);
 
 	for (m = priv->miners; m; m = m->next) {
-		DBusGProxy *proxy;
+		GDBusProxy *proxy;
 		MinerData *data;
 
 		data = m->data;
+		data->connection = g_object_ref (priv->connection);
+
+		/* FIXME: todo test all these routines */
+
+		proxy = g_dbus_proxy_new_sync (priv->connection,
+		                               G_DBUS_PROXY_FLAGS_NONE,
+		                               NULL,
+		                               data->dbus_name,
+		                               data->dbus_path,
+		                               TRACKER_MINER_DBUS_INTERFACE,
+		                               NULL,
+		                               &error);
+
+
+		if (error) {
+			g_critical ("Could not create proxy on the D-Bus session bus, %s",
+			            error ? error->message : "no error given.");
+			g_clear_error (&error);
+			continue;
+		}
 
-		proxy = dbus_g_proxy_new_for_name (priv->connection,
-		                                   data->dbus_name,
-		                                   data->dbus_path,
-		                                   TRACKER_MINER_DBUS_INTERFACE);
-
-		dbus_g_proxy_add_signal (proxy,
-		                         "Progress",
-		                         G_TYPE_STRING,
-		                         G_TYPE_DOUBLE,
-		                         G_TYPE_INVALID);
-		dbus_g_proxy_add_signal (proxy, "Paused", G_TYPE_INVALID);
-		dbus_g_proxy_add_signal (proxy, "Resumed", G_TYPE_INVALID);
-
-		dbus_g_proxy_connect_signal (proxy,
-		                             "Progress",
-		                             G_CALLBACK (miner_progress_changed),
-		                             manager, NULL);
-		dbus_g_proxy_connect_signal (proxy,
-		                             "Paused",
-		                             G_CALLBACK (miner_paused),
-		                             manager, NULL);
-		dbus_g_proxy_connect_signal (proxy,
-		                             "Resumed",
-		                             G_CALLBACK (miner_resumed),
-		                             manager, NULL);
+		data->progress_signal = g_dbus_connection_signal_subscribe (priv->connection,
+		                                                            data->dbus_name,
+		                                                            TRACKER_MINER_DBUS_INTERFACE,
+		                                                            "Progress",
+		                                                            data->dbus_path,
+		                                                            NULL,
+		                                                            G_DBUS_SIGNAL_FLAGS_NONE,
+		                                                            miner_progress_changed,
+		                                                            manager,
+		                                                            NULL);
+
+		data->paused_signal = g_dbus_connection_signal_subscribe (priv->connection,
+		                                                          data->dbus_name,
+		                                                          TRACKER_MINER_DBUS_INTERFACE,
+		                                                          "Paused",
+		                                                          data->dbus_path,
+		                                                          NULL,
+		                                                          G_DBUS_SIGNAL_FLAGS_NONE,
+		                                                          miner_paused,
+		                                                          manager,
+		                                                          NULL);
+
+
+		data->resumed_signal = g_dbus_connection_signal_subscribe (priv->connection,
+		                                                           data->dbus_name,
+		                                                           TRACKER_MINER_DBUS_INTERFACE,
+		                                                           "Resumed",
+		                                                           data->dbus_path,
+		                                                           NULL,
+		                                                           G_DBUS_SIGNAL_FLAGS_NONE,
+		                                                           miner_resumed,
+		                                                           manager,
+		                                                           NULL);
 
 		g_hash_table_insert (priv->miner_proxies, proxy, g_strdup (data->dbus_name));
+
+		data->watch_name_signal = g_bus_watch_name (G_BUS_TYPE_SESSION,
+		                                            data->dbus_name,
+		                                            G_BUS_NAME_WATCHER_FLAGS_NONE,
+		                                            miner_appears,
+		                                            miner_disappears,
+		                                            manager,
+		                                            NULL);
+
 	}
 }
 
 static void
 miner_data_free (MinerData *data)
 {
+	if (data->watch_name_signal)
+		g_bus_unwatch_name (data->watch_name_signal);
+	if (data->progress_signal)
+		g_dbus_connection_signal_unsubscribe (data->connection,
+		                                      data->progress_signal);
+	if (data->paused_signal)
+		g_dbus_connection_signal_unsubscribe (data->connection,
+		                                      data->paused_signal);
+	if (data->resumed_signal)
+		g_dbus_connection_signal_unsubscribe (data->connection,
+		                                      data->resumed_signal);
+	if (data->connection)
+		g_object_unref (data->connection);
+
 	g_free (data->dbus_path);
 	g_free (data->display_name);
 	g_slice_free (MinerData, data);
@@ -378,16 +397,13 @@ miner_manager_finalize (GObject *object)
 
 	priv = TRACKER_MINER_MANAGER_GET_PRIVATE (object);
 
-	if (priv->proxy) {
-		g_object_unref (priv->proxy);
-	}
-
 	if (priv->connection) {
-		dbus_g_connection_unref (priv->connection);
+		g_object_unref (priv->connection);
 	}
 
 	g_list_foreach (priv->miners, (GFunc) miner_data_free, NULL);
 	g_list_free (priv->miners);
+	g_hash_table_unref (priv->miner_proxies);
 
 	G_OBJECT_CLASS (tracker_miner_manager_parent_class)->finalize (object);
 }
@@ -422,45 +438,59 @@ tracker_miner_manager_get_running (TrackerMinerManager *manager)
 	TrackerMinerManagerPrivate *priv;
 	GSList *list = NULL;
 	GError *error = NULL;
-	gchar **p, **result;
+	GVariant *v;
 
 	g_return_val_if_fail (TRACKER_IS_MINER_MANAGER (manager), NULL);
 
 	priv = TRACKER_MINER_MANAGER_GET_PRIVATE (manager);
 
-	if (!priv->connection || !priv->proxy) {
+	if (!priv->connection) {
 		return NULL;
 	}
 
-	if (!dbus_g_proxy_call (priv->proxy, "ListNames", &error,
-	                        G_TYPE_INVALID,
-	                        G_TYPE_STRV, &result,
-	                        G_TYPE_INVALID)) {
+	v = g_dbus_connection_call_sync (priv->connection,
+	                                 "org.freedesktop.DBus",
+	                                 "/org/freedesktop/DBus",
+	                                 "org.freedesktop.DBus",
+	                                 "ListNames",
+	                                 NULL,
+	                                 G_VARIANT_TYPE ("(as)"),
+	                                 G_DBUS_CALL_FLAGS_NONE,
+	                                 -1,
+	                                 NULL,
+	                                 &error);
+
+	if (error) {
 		g_critical ("Could not get a list of names registered on the session bus, %s",
 		            error ? error->message : "no error given");
 		g_clear_error (&error);
 		return NULL;
 	}
 
-	if (result) {
-		for (p = result; *p; p++) {
-			if (!g_str_has_prefix (*p, TRACKER_MINER_DBUS_NAME_PREFIX)) {
+	if (v) {
+		GVariantIter *iter;
+		gchar *str;
+
+		g_variant_get (v, "(as)", &iter);
+		while (g_variant_iter_loop (iter, "s", &str)) {
+			if (!g_str_has_prefix (str, TRACKER_MINER_DBUS_NAME_PREFIX)) {
 				continue;
 			}
 
 			/* Special case miner-fs which has
 			 * additional D-Bus interface.
 			 */
-			if (strcmp (*p, "org.freedesktop.Tracker1.Miner.Files.Index") == 0) {
+			if (strcmp (str, "org.freedesktop.Tracker1.Miner.Files.Index") == 0) {
 				continue;
 			}
 
-			list = g_slist_prepend (list, g_strdup (*p));
+			list = g_slist_prepend (list, g_strdup (str));
 		}
 
-		list = g_slist_reverse (list);
+		g_variant_iter_free (iter);
+		g_variant_unref (v);
 
-		g_strfreev (result);
+		list = g_slist_reverse (list);
 	}
 
 	return list;
@@ -540,7 +570,8 @@ initialize_miners_data (TrackerMinerManager *manager)
 	GMainLoop *main_loop;
 	GFile *file;
 	TrackerCrawler *crawler;
-        const gchar    *miners_dir;
+	const gchar *miners_dir;
+
 	crawler = tracker_crawler_new ();
 	main_loop = g_main_loop_new (NULL, FALSE);
 
@@ -552,12 +583,12 @@ initialize_miners_data (TrackerMinerManager *manager)
 	                  main_loop);
 
 	/* Go through service files */
-        miners_dir = g_getenv ("TRACKER_MINERS_DIR");
-        if (G_LIKELY (miners_dir == NULL)) {
-                miners_dir = TRACKER_MINERS_DIR ;
-        } else {
-                g_message ("Crawling miners in '%s' (set in env)", miners_dir);
-        }
+	miners_dir = g_getenv ("TRACKER_MINERS_DIR");
+	if (G_LIKELY (miners_dir == NULL)) {
+		miners_dir = TRACKER_MINERS_DIR;
+	} else {
+		g_message ("Crawling miners in '%s' (set in env)", miners_dir);
+	}
 
 	file = g_file_new_for_path (miners_dir);
 	tracker_crawler_start (crawler, file, TRUE);
@@ -610,7 +641,7 @@ tracker_miner_manager_get_available (TrackerMinerManager *manager)
  * until all pause requests have been resumed.
  *
  * Returns: %TRUE if the miner was paused successfully, otherwise
- * %FALSE. 
+ * %FALSE.
  **/
 gboolean
 tracker_miner_manager_pause (TrackerMinerManager *manager,
@@ -618,9 +649,10 @@ tracker_miner_manager_pause (TrackerMinerManager *manager,
                              const gchar         *reason,
                              guint32             *cookie)
 {
-	DBusGProxy *proxy;
+	GDBusProxy *proxy;
 	const gchar *app_name;
 	GError *error = NULL;
+	GVariant *v;
 
 	g_return_val_if_fail (TRACKER_IS_MINER_MANAGER (manager), FALSE);
 	g_return_val_if_fail (miner != NULL, FALSE);
@@ -644,7 +676,13 @@ tracker_miner_manager_pause (TrackerMinerManager *manager,
 		app_name = "TrackerMinerManager client";
 	}
 
-	org_freedesktop_Tracker1_Miner_pause (proxy, app_name, reason, cookie, &error);
+	v = g_dbus_proxy_call_sync (proxy,
+	                            "Pause",
+	                            g_variant_new ("(ss)", app_name, reason),
+	                            G_DBUS_CALL_FLAGS_NONE,
+	                            -1,
+	                            NULL,
+	                            &error);
 
 	if (error) {
 		g_critical ("Could not pause miner '%s': %s", miner, error->message);
@@ -652,6 +690,12 @@ tracker_miner_manager_pause (TrackerMinerManager *manager,
 		return FALSE;
 	}
 
+	if (cookie) {
+		g_variant_get (v, "(i)", cookie);
+	}
+
+	g_variant_unref (v);
+
 	return TRUE;
 }
 
@@ -662,18 +706,19 @@ tracker_miner_manager_pause (TrackerMinerManager *manager,
  * @cookie: pause cookie
  *
  * Tells @miner to resume activity. The miner won't actually resume
- * operations until all pause requests have been resumed. 
+ * operations until all pause requests have been resumed.
  *
  * Returns: %TRUE if the miner was successfully resumed, otherwise
- * %FALSE. 
+ * %FALSE.
  **/
 gboolean
 tracker_miner_manager_resume (TrackerMinerManager *manager,
                               const gchar         *miner,
                               guint32              cookie)
 {
-	DBusGProxy *proxy;
+	GDBusProxy *proxy;
 	GError *error = NULL;
+	GVariant *v;
 
 	g_return_val_if_fail (TRACKER_IS_MINER_MANAGER (manager), FALSE);
 	g_return_val_if_fail (miner != NULL, FALSE);
@@ -684,7 +729,14 @@ tracker_miner_manager_resume (TrackerMinerManager *manager,
 		return FALSE;
 	}
 
-	org_freedesktop_Tracker1_Miner_resume (proxy, cookie, &error);
+	/* FIXME: todo test this call */
+	v = g_dbus_proxy_call_sync (proxy,
+	                            "Resume",
+	                            g_variant_new ("(i)", (gint) cookie),
+	                            G_DBUS_CALL_FLAGS_NONE,
+	                            -1,
+	                            NULL,
+	                            &error);
 
 	if (error) {
 		g_critical ("Could not resume miner '%s': %s", miner, error->message);
@@ -692,6 +744,8 @@ tracker_miner_manager_resume (TrackerMinerManager *manager,
 		return FALSE;
 	}
 
+	g_variant_unref (v);
+
 	return TRUE;
 }
 
@@ -710,24 +764,38 @@ tracker_miner_manager_is_active (TrackerMinerManager *manager,
 {
 	TrackerMinerManagerPrivate *priv;
 	GError *error = NULL;
-	gboolean active;
+	gboolean active = FALSE;
+	GVariant *v;
 
 	g_return_val_if_fail (TRACKER_IS_MINER_MANAGER (manager), FALSE);
 	g_return_val_if_fail (miner != NULL, FALSE);
 
 	priv = TRACKER_MINER_MANAGER_GET_PRIVATE (manager);
 
-	if (!dbus_g_proxy_call (priv->proxy, "NameHasOwner", &error,
-	                        G_TYPE_STRING, miner,
-	                        G_TYPE_INVALID,
-	                        G_TYPE_BOOLEAN, &active,
-	                        G_TYPE_INVALID)) {
+	v = g_dbus_connection_call_sync (priv->connection,
+	                                 "org.freedesktop.DBus",
+	                                 "/org/freedesktop/DBus",
+	                                 "org.freedesktop.DBus",
+	                                 "NameHasOwner",
+	                                 g_variant_new ("(s)", miner),
+	                                 NULL,
+	                                 G_DBUS_CALL_FLAGS_NONE,
+	                                 -1,
+	                                 NULL,
+	                                 &error);
+
+	if (error) {
 		g_critical ("Could not check whether miner '%s' is currently active: %s",
 		            miner, error ? error->message : "no error given");
 		g_error_free (error);
 		return FALSE;
 	}
 
+	if (v) {
+		g_variant_get (v, "(b)", &active);
+		g_variant_unref (v);
+	}
+
 	return active;
 }
 
@@ -749,10 +817,10 @@ tracker_miner_manager_get_status (TrackerMinerManager  *manager,
                                   gchar               **status,
                                   gdouble              *progress)
 {
-	DBusGProxy *proxy;
+	GDBusProxy *proxy;
 	GError *error = NULL;
 	gdouble p;
-	gchar *st;
+	GVariant *v;
 
 	g_return_val_if_fail (TRACKER_IS_MINER_MANAGER (manager), FALSE);
 	g_return_val_if_fail (miner != NULL, FALSE);
@@ -764,7 +832,18 @@ tracker_miner_manager_get_status (TrackerMinerManager  *manager,
 		return FALSE;
 	}
 
-	org_freedesktop_Tracker1_Miner_get_progress (proxy, &p, &error);
+	v = g_dbus_proxy_call_sync (proxy,
+	                            "GetProgress",
+	                            NULL,
+	                            G_DBUS_CALL_FLAGS_NONE,
+	                            -1,
+	                            NULL,
+	                            &error);
+
+	if (v) {
+		g_variant_get (v, "(d)", &p);
+		g_variant_unref (v);
+	}
 
 	if (error) {
 		/* We handle this error as a special case, some
@@ -780,20 +859,27 @@ tracker_miner_manager_get_status (TrackerMinerManager  *manager,
 		return FALSE;
 	}
 
-	org_freedesktop_Tracker1_Miner_get_status (proxy, &st, &error);
+	v = g_dbus_proxy_call_sync (proxy,
+	                            "GetStatus",
+	                            NULL,
+	                            G_DBUS_CALL_FLAGS_NONE,
+	                            -1,
+	                            NULL,
+	                            &error);
 
 	if (error) {
 		g_critical ("Could not get miner status for '%s': %s", miner,
 		            error->message);
 		g_error_free (error);
-
 		return FALSE;
 	}
 
-	if (status) {
-		*status = st;
-	} else {
-		g_free (st);
+	if (v) {
+		if (status) {
+			g_variant_get (v, "(s)", status);
+		}
+
+		g_variant_unref (v);
 	}
 
 	if (progress) {
@@ -824,10 +910,11 @@ tracker_miner_manager_is_paused (TrackerMinerManager *manager,
                                  GStrv               *applications,
                                  GStrv               *reasons)
 {
-	DBusGProxy *proxy;
+	GDBusProxy *proxy;
 	GStrv apps, r;
 	GError *error = NULL;
 	gboolean paused;
+	GVariant *v;
 
 	if (applications) {
 		*applications = NULL;
@@ -847,16 +934,27 @@ tracker_miner_manager_is_paused (TrackerMinerManager *manager,
 		return FALSE;
 	}
 
-	org_freedesktop_Tracker1_Miner_get_pause_details (proxy, &apps, &r, &error);
+	/* FIXME: todo test this call */
+	v = g_dbus_proxy_call_sync (proxy,
+	                            "GetPauseDetails",
+	                            NULL,
+	                            G_DBUS_CALL_FLAGS_NONE,
+	                            -1,
+	                            NULL,
+	                            &error);
 
 	if (error) {
 		g_critical ("Could not get pause details for miner '%s': %s", miner,
 		            error->message);
 		g_error_free (error);
-
 		return TRUE;
 	}
 
+	if (v) {
+		g_variant_get (v, "(^as^as)", &apps, &r);
+		g_variant_unref (v);
+	}
+
 	paused = (g_strv_length (apps) > 0);
 
 	if (applications) {
@@ -957,9 +1055,9 @@ tracker_miner_manager_ignore_next_update (TrackerMinerManager *manager,
                                           const gchar         *miner,
                                           const gchar        **urls)
 {
-	DBusGProxy *proxy;
-	const gchar *app_name;
+	GDBusProxy *proxy;
 	GError *error = NULL;
+	GVariant *v;
 
 	g_return_val_if_fail (TRACKER_IS_MINER_MANAGER (manager), FALSE);
 	g_return_val_if_fail (miner != NULL, FALSE);
@@ -971,18 +1069,13 @@ tracker_miner_manager_ignore_next_update (TrackerMinerManager *manager,
 		return FALSE;
 	}
 
-	/* Find a reasonable app name */
-	app_name = g_get_application_name ();
-
-	if (!app_name) {
-		app_name = g_get_prgname ();
-	}
-
-	if (!app_name) {
-		app_name = "TrackerMinerManager client";
-	}
-
-	org_freedesktop_Tracker1_Miner_ignore_next_update (proxy, urls, &error);
+	v = g_dbus_proxy_call_sync (proxy,
+	                            "IgnoreNextUpdate",
+	                            g_variant_new ("(as)", urls),
+	                            G_DBUS_CALL_FLAGS_NONE,
+	                            -1,
+	                            NULL,
+	                            &error);
 
 	if (error) {
 		g_warning ("Could not ignore next update for miner '%s': %s", miner, error->message);
@@ -990,6 +1083,8 @@ tracker_miner_manager_ignore_next_update (TrackerMinerManager *manager,
 		return FALSE;
 	}
 
+	g_variant_unref (v);
+
 	return TRUE;
 }
 
@@ -1030,9 +1125,8 @@ tracker_miner_manager_reindex_by_mimetype (TrackerMinerManager  *manager,
                                            const GStrv           mimetypes,
                                            GError              **error)
 {
-	static DBusGProxy *proxy = NULL;
 	TrackerMinerManagerPrivate *priv;
-	GError *internal_error = NULL;
+	GVariant *v;
 
 	g_return_val_if_fail (TRACKER_IS_MINER_MANAGER (manager), FALSE);
 	g_return_val_if_fail (mimetypes != NULL, FALSE);
@@ -1048,23 +1142,24 @@ tracker_miner_manager_reindex_by_mimetype (TrackerMinerManager  *manager,
 
 	priv = TRACKER_MINER_MANAGER_GET_PRIVATE (manager);
 
-	if (G_UNLIKELY (!proxy)) {
-		proxy = dbus_g_proxy_new_for_name (priv->connection,
-		                                   "org.freedesktop.Tracker1.Miner.Files.Index",
-		                                   "/org/freedesktop/Tracker1/Miner/Files/Index",
-		                                   "org.freedesktop.Tracker1.Miner.Files.Index");
-	}
-
-	org_freedesktop_Tracker1_Miner_Files_Index_reindex_mime_types (proxy,
-	                                                               (const gchar **) mimetypes,
-	                                                               &internal_error);
-
-	if (internal_error) {
-		g_propagate_error (error, internal_error);
-		return FALSE;
+	v = g_dbus_connection_call_sync (priv->connection,
+	                                 "org.freedesktop.Tracker1.Miner.Files.Index",
+	                                 "/org/freedesktop/Tracker1/Miner/Files/Index",
+	                                 "org.freedesktop.Tracker1.Miner.Files.Index",
+	                                 "ReindexMimeTypes",
+	                                 g_variant_new ("(as)", mimetypes),
+	                                 NULL,
+	                                 G_DBUS_CALL_FLAGS_NONE,
+	                                 -1,
+	                                 NULL,
+	                                 error);
+
+	if (v) {
+		g_variant_unref (v);
+		return TRUE;
 	}
 
-	return TRUE;
+	return FALSE;
 }
 
 /**
@@ -1084,10 +1179,9 @@ tracker_miner_manager_index_file (TrackerMinerManager  *manager,
                                   GFile                *file,
                                   GError              **error)
 {
-	static DBusGProxy *proxy = NULL;
 	TrackerMinerManagerPrivate *priv;
-	GError *internal_error = NULL;
 	gchar *uri;
+	GVariant *v;
 
 	g_return_val_if_fail (TRACKER_IS_MINER_MANAGER (manager), FALSE);
 	g_return_val_if_fail (G_IS_FILE (file), FALSE);
@@ -1111,21 +1205,26 @@ tracker_miner_manager_index_file (TrackerMinerManager  *manager,
 
 	priv = TRACKER_MINER_MANAGER_GET_PRIVATE (manager);
 
-	if (G_UNLIKELY (!proxy)) {
-		proxy = dbus_g_proxy_new_for_name (priv->connection,
-		                                   "org.freedesktop.Tracker1.Miner.Files.Index",
-		                                   "/org/freedesktop/Tracker1/Miner/Files/Index",
-		                                   "org.freedesktop.Tracker1.Miner.Files.Index");
-	}
-
 	uri = g_file_get_uri (file);
-	org_freedesktop_Tracker1_Miner_Files_Index_index_file (proxy, uri, &internal_error);
+
+	v = g_dbus_connection_call_sync (priv->connection,
+	                                 "org.freedesktop.Tracker1.Miner.Files.Index",
+	                                 "/org/freedesktop/Tracker1/Miner/Files/Index",
+	                                 "org.freedesktop.Tracker1.Miner.Files.Index",
+	                                 "IndexFile",
+	                                 g_variant_new ("(s)", uri),
+	                                 NULL,
+	                                 G_DBUS_CALL_FLAGS_NONE,
+	                                 -1,
+	                                 NULL,
+	                                 error);
+
 	g_free (uri);
 
-	if (internal_error) {
-		g_propagate_error (error, internal_error);
-		return FALSE;
+	if (v) {
+		g_variant_unref (v);
+		return TRUE;
 	}
 
-	return TRUE;
+	return FALSE;
 }



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