[tracker/wip/carlosg/domain-ontologies: 20/20] libtracker-control: Add domain argument to tracker_miner_manager_new_full



commit 3ee1bad537340a7e930ccb75f4357fb3d343a436
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Jun 20 20:30:47 2017 +0200

    libtracker-control: Add domain argument to tracker_miner_manager_new_full
    
    I personally prefer using the excuse of the major version bump than adding
    a tracker_miner_manager_new_fuller() variant, as this is clearly a
    construct_only thing. Creating a TrackerMinerManager with an specific
    domain will allow dealing with the miners spawned for it.

 src/libtracker-control/tracker-control.vapi    |    2 +-
 src/libtracker-control/tracker-miner-manager.c |   58 +++++++++++++++++++-----
 src/libtracker-control/tracker-miner-manager.h |    3 +-
 src/miners/rss/tracker-main.c                  |    1 +
 src/tracker/tracker-config.c                   |    2 +-
 src/tracker/tracker-daemon.c                   |   12 +++---
 src/tracker/tracker-index.c                    |    4 +-
 src/tracker/tracker-reset.c                    |    2 +-
 src/tracker/tracker-status.c                   |    2 +-
 9 files changed, 62 insertions(+), 24 deletions(-)
---
diff --git a/src/libtracker-control/tracker-control.vapi b/src/libtracker-control/tracker-control.vapi
index ceba04a..59de817 100644
--- a/src/libtracker-control/tracker-control.vapi
+++ b/src/libtracker-control/tracker-control.vapi
@@ -8,7 +8,7 @@ namespace Tracker {
                public MinerManager ();
                public static GLib.Quark error_quark ();
                [CCode (has_construct_function = false)]
-               public MinerManager.full (bool auto_start) throws GLib.Error;
+               public MinerManager.full (string? domain_name, bool auto_start) throws GLib.Error;
                public GLib.SList<string>? get_available ();
                public unowned string get_description (string miner);
                public unowned string get_display_name (string miner);
diff --git a/src/libtracker-control/tracker-miner-manager.c b/src/libtracker-control/tracker-miner-manager.c
index c3d712c..3af6c51 100644
--- a/src/libtracker-control/tracker-miner-manager.c
+++ b/src/libtracker-control/tracker-miner-manager.c
@@ -25,6 +25,7 @@
 
 #include <libtracker-common/tracker-dbus.h>
 #include <libtracker-common/tracker-type-utils.h>
+#include <libtracker-common/tracker-domain-ontology.h>
 #include <libtracker-miner/tracker-miner.h>
 
 #include "tracker-miner-manager.h"
@@ -42,7 +43,7 @@
 #define TRACKER_MINER_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TRACKER_TYPE_MINER_MANAGER, 
TrackerMinerManagerPrivate))
 
 #define DESKTOP_ENTRY_GROUP "D-BUS Service"
-#define DBUS_NAME_KEY "Name"
+#define DBUS_NAME_SUFFIX_KEY "NameSuffix"
 #define DBUS_PATH_KEY "Path"
 #define DISPLAY_NAME_KEY "DisplayName"
 #define DESCRIPTION_KEY "Comment"
@@ -58,6 +59,7 @@ struct MinerData {
        gchar *dbus_path;
        gchar *display_name;
        gchar *description;
+       gchar *name_suffix;
 
        GDBusConnection *connection;
        guint progress_signal;
@@ -74,6 +76,8 @@ struct TrackerMinerManagerPrivate {
 
        /* Property values */
        gboolean auto_start;
+       gchar *domain_ontology_name;
+       TrackerDomainOntology *domain_ontology;
 };
 
 static void miner_manager_initable_iface_init (GInitableIface         *iface);
@@ -94,7 +98,8 @@ G_DEFINE_TYPE_WITH_CODE (TrackerMinerManager, tracker_miner_manager, G_TYPE_OBJE
 
 enum {
        PROP_0,
-       PROP_AUTO_START
+       PROP_AUTO_START,
+       PROP_DOMAIN_ONTOLOGY
 };
 
 enum {
@@ -124,6 +129,13 @@ tracker_miner_manager_class_init (TrackerMinerManagerClass *klass)
                                                              "If set, auto starts miners when querying their 
status",
                                                               TRUE,
                                                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+       g_object_class_install_property (object_class,
+                                        PROP_DOMAIN_ONTOLOGY,
+                                        g_param_spec_string ("domain-ontology",
+                                                             "Domain ontology",
+                                                             "The domain ontology this object controls",
+                                                             NULL,
+                                                             G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 
        /**
         * TrackerMinerManager::miner-progress:
@@ -248,6 +260,9 @@ miner_manager_set_property (GObject      *object,
        case PROP_AUTO_START:
                priv->auto_start = g_value_get_boolean (value);
                break;
+       case PROP_DOMAIN_ONTOLOGY:
+               priv->domain_ontology_name = g_value_dup_string (value);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -270,6 +285,9 @@ miner_manager_get_property (GObject    *object,
        case PROP_AUTO_START:
                g_value_set_boolean (value, priv->auto_start);
                break;
+       case PROP_DOMAIN_ONTOLOGY:
+               g_value_set_string (value, priv->domain_ontology_name);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -414,6 +432,13 @@ miner_manager_initable_init (GInitable     *initable,
                return FALSE;
        }
 
+       priv->domain_ontology = tracker_domain_ontology_new (priv->domain_ontology_name,
+                                                            cancellable, &inner_error);
+       if (!priv->domain_ontology) {
+               g_propagate_error (error, inner_error);
+               return FALSE;
+       }
+
        initialize_miners_data (manager);
 
        for (m = priv->miners; m; m = m->next) {
@@ -533,6 +558,7 @@ miner_data_free (MinerData *data)
        g_free (data->dbus_name);
        g_free (data->display_name);
        g_free (data->description);
+       g_free (data->name_suffix);
        g_slice_free (MinerData, data);
 }
 
@@ -550,6 +576,8 @@ miner_manager_finalize (GObject *object)
        g_list_foreach (priv->miners, (GFunc) miner_data_free, NULL);
        g_list_free (priv->miners);
        g_hash_table_unref (priv->miner_proxies);
+       g_free (priv->domain_ontology_name);
+       g_object_unref (priv->domain_ontology);
 
        G_OBJECT_CLASS (tracker_miner_manager_parent_class)->finalize (object);
 }
@@ -597,8 +625,9 @@ tracker_miner_manager_new (void)
  * Since: 0.10.5
  **/
 TrackerMinerManager *
-tracker_miner_manager_new_full (gboolean   auto_start,
-                                GError   **error)
+tracker_miner_manager_new_full (const gchar  *domain_ontology,
+                                gboolean      auto_start,
+                                GError      **error)
 {
        GError *inner_error = NULL;
        TrackerMinerManager *manager;
@@ -606,6 +635,7 @@ tracker_miner_manager_new_full (gboolean   auto_start,
        manager = g_initable_new (TRACKER_TYPE_MINER_MANAGER,
                                  NULL,
                                  &inner_error,
+                                 "domain-ontology", domain_ontology,
                                  "auto-start", auto_start,
                                  NULL);
        if (inner_error)
@@ -636,6 +666,7 @@ tracker_miner_manager_get_running (TrackerMinerManager *manager)
        GVariant *v;
        GVariantIter *iter;
        const gchar *str = NULL;
+       gchar *prefix;
 
        g_return_val_if_fail (TRACKER_IS_MINER_MANAGER (manager), NULL);
 
@@ -664,9 +695,11 @@ tracker_miner_manager_get_running (TrackerMinerManager *manager)
                return NULL;
        }
 
+       prefix = tracker_domain_ontology_get_domain (priv->domain_ontology, "Miner");
+
        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)) {
+               if (!g_str_has_prefix (str, prefix)) {
                        continue;
                }
 
@@ -675,6 +708,7 @@ tracker_miner_manager_get_running (TrackerMinerManager *manager)
 
        g_variant_iter_free (iter);
        g_variant_unref (v);
+       g_free (prefix);
 
        list = g_slist_reverse (list);
 
@@ -688,7 +722,7 @@ check_file (GFile    *file,
        TrackerMinerManager *manager;
        TrackerMinerManagerPrivate *priv;
        GKeyFile *key_file;
-       gchar *path, *dbus_path, *dbus_name, *display_name, *description;
+       gchar *path, *dbus_path, *display_name, *name_suffix, *description;
        GError *error = NULL;
        MinerData *data;
 
@@ -707,15 +741,15 @@ check_file (GFile    *file,
        }
 
        dbus_path = g_key_file_get_string (key_file, DESKTOP_ENTRY_GROUP, DBUS_PATH_KEY, NULL);
-       dbus_name = g_key_file_get_string (key_file, DESKTOP_ENTRY_GROUP, DBUS_NAME_KEY, NULL);
        display_name = g_key_file_get_locale_string (key_file, DESKTOP_ENTRY_GROUP, DISPLAY_NAME_KEY, NULL, 
NULL);
+       name_suffix = g_key_file_get_string (key_file, DESKTOP_ENTRY_GROUP, DBUS_NAME_SUFFIX_KEY, NULL);
 
-       if (!dbus_path || !dbus_name || !display_name) {
-               g_warning ("Essential data (DBusPath, DBusName or Name) are missing in miner .desktop file");
+       if (!dbus_path || !display_name || !name_suffix) {
+               g_warning ("Essential data (DBusPath, NameSuffix or Name) are missing in miner .desktop 
file");
                g_key_file_free (key_file);
                g_free (dbus_path);
                g_free (display_name);
-               g_free (dbus_name);
+               g_free (name_suffix);
                return;
        }
 
@@ -723,7 +757,9 @@ check_file (GFile    *file,
 
        data = g_slice_new0 (MinerData);
        data->dbus_path = dbus_path;
-       data->dbus_name = dbus_name;        /* In .service file as Name */
+       data->name_suffix = name_suffix;
+       data->dbus_name = tracker_domain_ontology_get_domain (priv->domain_ontology,
+                                                             name_suffix);
        data->display_name = display_name;
        data->description = description;    /* In .desktop file as _comment */
 
diff --git a/src/libtracker-control/tracker-miner-manager.h b/src/libtracker-control/tracker-miner-manager.h
index 38729a9..941d47b 100644
--- a/src/libtracker-control/tracker-miner-manager.h
+++ b/src/libtracker-control/tracker-miner-manager.h
@@ -97,7 +97,8 @@ GType                tracker_miner_manager_get_type           (void) G_GNUC_CONS
 GQuark               tracker_miner_manager_error_quark        (void) G_GNUC_CONST;
 
 TrackerMinerManager *tracker_miner_manager_new                (void);
-TrackerMinerManager *tracker_miner_manager_new_full           (gboolean              auto_start,
+TrackerMinerManager *tracker_miner_manager_new_full           (const gchar          *domain_ontology,
+                                                               gboolean              auto_start,
                                                                GError              **error);
 GSList *             tracker_miner_manager_get_running        (TrackerMinerManager  *manager);
 GSList *             tracker_miner_manager_get_available      (TrackerMinerManager  *manager);
diff --git a/src/miners/rss/tracker-main.c b/src/miners/rss/tracker-main.c
index 06d9d36..fae4967 100644
--- a/src/miners/rss/tracker-main.c
+++ b/src/miners/rss/tracker-main.c
@@ -67,6 +67,7 @@ main (int argc, char **argv)
        GOptionContext *context;
        TrackerMinerRSS *miner;
        GError *error = NULL;
+       GDBusConnection *connection;
        TrackerMinerProxy *proxy;
        TrackerDomainOntology *domain_ontology;
        gchar *dbus_name;
diff --git a/src/tracker/tracker-config.c b/src/tracker/tracker-config.c
index 9dfc143..f8314e1 100644
--- a/src/tracker/tracker-config.c
+++ b/src/tracker/tracker-config.c
@@ -55,7 +55,7 @@ tracker_gsettings_get_all (gint *longest_name_length)
        SchemaWithPath *swp;
 
        /* Don't auto-start the miners here */
-       manager = tracker_miner_manager_new_full (FALSE, &error);
+       manager = tracker_miner_manager_new_full (NULL, FALSE, &error);
        if (!manager) {
                g_printerr (_("Could not get GSettings for miners, manager could not be created, %s"),
                            error ? error->message : _("No error given"));
diff --git a/src/tracker/tracker-daemon.c b/src/tracker/tracker-daemon.c
index 290b3c0..4f1588c 100644
--- a/src/tracker/tracker-daemon.c
+++ b/src/tracker/tracker-daemon.c
@@ -884,7 +884,7 @@ miner_pause (const gchar *miner,
        guint32 cookie;
 
        /* Don't auto-start the miners here */
-       manager = tracker_miner_manager_new_full (FALSE, &error);
+       manager = tracker_miner_manager_new_full (NULL, FALSE, &error);
        if (!manager) {
                g_printerr (_("Could not pause miner, manager could not be created, %s"),
                            error ? error->message : _("No error given"));
@@ -942,7 +942,7 @@ miner_resume (const gchar *miner,
        gchar *str;
 
        /* Don't auto-start the miners here */
-       manager = tracker_miner_manager_new_full (FALSE, &error);
+       manager = tracker_miner_manager_new_full (NULL, FALSE, &error);
        if (!manager) {
                g_printerr (_("Could not resume miner, manager could not be created, %s"),
                            error ? error->message : _("No error given"));
@@ -977,7 +977,7 @@ miner_list (gboolean available,
        GError *error = NULL;
 
        /* Don't auto-start the miners here */
-       manager = tracker_miner_manager_new_full (FALSE, &error);
+       manager = tracker_miner_manager_new_full (NULL, FALSE, &error);
        if (!manager) {
                g_printerr (_("Could not list miners, manager could not be created, %s"),
                            error ? error->message : _("No error given"));
@@ -1046,7 +1046,7 @@ miner_pause_details (void)
        gint paused_miners = 0;
 
        /* Don't auto-start the miners here */
-       manager = tracker_miner_manager_new_full (FALSE, &error);
+       manager = tracker_miner_manager_new_full (NULL, FALSE, &error);
        if (!manager) {
                g_printerr (_("Could not get pause details, manager could not be created, %s"),
                            error ? error->message : _("No error given"));
@@ -1303,7 +1303,7 @@ daemon_run (void)
                GSList *l;
 
                /* Don't auto-start the miners here */
-               manager = tracker_miner_manager_new_full (FALSE, &error);
+               manager = tracker_miner_manager_new_full (NULL, FALSE, &error);
                if (!manager) {
                        g_printerr (_("Could not get status, manager could not be created, %s"),
                                    error ? error->message : _("No error given"));
@@ -1662,7 +1662,7 @@ daemon_run (void)
                g_print ("%s\n", _("Starting miners…"));
 
                /* Auto-start the miners here */
-               manager = tracker_miner_manager_new_full (TRUE, &error);
+               manager = tracker_miner_manager_new_full (NULL, TRUE, &error);
                if (!manager) {
                        g_printerr (_("Could not start miners, manager could not be created, %s"),
                                    error ? error->message : _("No error given"));
diff --git a/src/tracker/tracker-index.c b/src/tracker/tracker-index.c
index 9658652..4f32d96 100644
--- a/src/tracker/tracker-index.c
+++ b/src/tracker/tracker-index.c
@@ -117,7 +117,7 @@ reindex_mimes (void)
        TrackerMinerManager *manager;
 
        /* Auto-start the miners here if we need to */
-       manager = tracker_miner_manager_new_full (TRUE, &error);
+       manager = tracker_miner_manager_new_full (NULL, TRUE, &error);
        if (!manager) {
                g_printerr (_("Could not reindex mimetypes, manager could not be created, %s"),
                            error ? error->message : _("No error given"));
@@ -149,7 +149,7 @@ index_or_reindex_file (void)
        gchar **p;
 
        /* Auto-start the miners here if we need to */
-       manager = tracker_miner_manager_new_full (TRUE, &error);
+       manager = tracker_miner_manager_new_full (NULL, TRUE, &error);
        if (!manager) {
                g_printerr (_("Could not (re)index file, manager could not be created, %s"),
                            error ? error->message : _("No error given"));
diff --git a/src/tracker/tracker-reset.c b/src/tracker/tracker-reset.c
index fa7a2ee..e6029c2 100644
--- a/src/tracker/tracker-reset.c
+++ b/src/tracker/tracker-reset.c
@@ -189,7 +189,7 @@ delete_info_recursively (GFile *file)
                           "and will be reindexed again."));
 
        /* Request reindexing of this data, it was previously in the store. */
-       miner_manager = tracker_miner_manager_new_full (FALSE, NULL);
+       miner_manager = tracker_miner_manager_new_full (NULL, FALSE, NULL);
        tracker_miner_manager_index_file (miner_manager, file, &error);
        g_object_unref (miner_manager);
 
diff --git a/src/tracker/tracker-status.c b/src/tracker/tracker-status.c
index 3b25be1..ddca985 100644
--- a/src/tracker/tracker-status.c
+++ b/src/tracker/tracker-status.c
@@ -574,7 +574,7 @@ are_miners_finished (gint *max_remaining_time)
        gint _max_remaining_time = 0;
 
        /* Don't auto-start the miners here */
-       manager = tracker_miner_manager_new_full (FALSE, &error);
+       manager = tracker_miner_manager_new_full (NULL, FALSE, &error);
        if (!manager) {
                g_printerr (_("Could not get status, manager could not be created, %s"),
                            error ? error->message : _("No error given"));


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