[PATCH 14/14] tracker: make connection retrieval asynchronous



From: Lionel Landwerlin <lionel g landwerlin linux intel com>

Signed-off-by: Lionel Landwerlin <lionel g landwerlin linux intel com>
---
 src/tracker/grl-tracker.c |   63 +++++++++++++++++++++++++-------------------
 1 files changed, 36 insertions(+), 27 deletions(-)

diff --git a/src/tracker/grl-tracker.c b/src/tracker/grl-tracker.c
index 1691dee..fb23e6a 100644
--- a/src/tracker/grl-tracker.c
+++ b/src/tracker/grl-tracker.c
@@ -208,20 +208,24 @@ static GrlSupportedOps grl_tracker_source_supported_operations (GrlMetadataSourc
 static const GList *grl_tracker_source_supported_keys (GrlMetadataSource *source);
 
 
-static void grl_tracker_source_query (GrlMediaSource *source,
+static void grl_tracker_source_query (GrlMediaSource          *source,
                                       GrlMediaSourceQuerySpec *qs);
 
-static void grl_tracker_source_search (GrlMediaSource *source,
+static void grl_tracker_source_search (GrlMediaSource           *source,
                                        GrlMediaSourceSearchSpec *ss);
 
-static void grl_tracker_source_metadata (GrlMediaSource *source,
+static void grl_tracker_source_metadata (GrlMediaSource             *source,
                                          GrlMediaSourceMetadataSpec *ms);
 
-static void grl_tracker_source_browse (GrlMediaSource *source,
+static void grl_tracker_source_browse (GrlMediaSource           *source,
                                        GrlMediaSourceBrowseSpec *bs);
 
 static void setup_key_mappings (void);
 
+static void tracker_get_connection_cb (GObject              *object,
+                                       GAsyncResult         *res,
+                                       GrlTrackerSourcePriv *priv);
+
 static const gchar *tracker_browsing_mode_to_str (tracker_browsing_mode_t mode);
 
 static tracker_browsing_mode_t tracker_browsing_mode_from_str (const gchar *str);
@@ -243,7 +247,7 @@ grl_tracker_plugin_init (GrlPluginRegistry *registry,
 
   GRL_LOG_DOMAIN_INIT (tracker_log_domain, "tracker");
 
-  GRL_DEBUG ("tracker_plugin_init");
+  GRL_DEBUG ("%s", __FUNCTION__);
 
   GrlTrackerSource *source = grl_tracker_source_new ();
 
@@ -279,26 +283,13 @@ GRL_PLUGIN_REGISTER (grl_tracker_plugin_init,
 static GrlTrackerSource *
 grl_tracker_source_new (void)
 {
-  GError *error = NULL;
-  GrlTrackerSource *source;
-  TrackerSparqlConnection *connection;
-
-  GRL_DEBUG ("grl_tracker_source_new");
-
-  connection = tracker_sparql_connection_get_direct (NULL, &error);
-  if (!connection) {
-    GRL_WARNING ("Failed to get Tracker connection: %s", error->message);
-    return NULL;
-  }
-
-  source =  g_object_new (GRL_TRACKER_SOURCE_TYPE,
-                          "source-id", SOURCE_ID,
-                          "source-name", SOURCE_NAME,
-                          "source-desc", SOURCE_DESC,
-                          NULL);
-  source->priv->tracker_connection = connection;
+  GRL_DEBUG ("%s", __FUNCTION__);
 
-  return source;
+  return g_object_new (GRL_TRACKER_SOURCE_TYPE,
+                       "source-id", SOURCE_ID,
+                       "source-name", SOURCE_NAME,
+                       "source-desc", SOURCE_DESC,
+                       NULL);
 }
 
 G_DEFINE_TYPE (GrlTrackerSource, grl_tracker_source, GRL_TYPE_MEDIA_SOURCE);
@@ -327,7 +318,7 @@ grl_tracker_source_class_init (GrlTrackerSourceClass * klass)
                                    g_param_spec_string ("browsing-mode",
                                                         "browsing-mode",
                                                         "Method used to browse a tracker source (category,directory,flat)",
-                                                        "directory",
+                                                        "category",
                                                         G_PARAM_READABLE
                                                         | G_PARAM_WRITABLE
                                                         | G_PARAM_STATIC_NAME));
@@ -340,9 +331,16 @@ grl_tracker_source_class_init (GrlTrackerSourceClass * klass)
 static void
 grl_tracker_source_init (GrlTrackerSource *source)
 {
-  source->priv = GRL_TRACKER_SOURCE_GET_PRIVATE (source);
+  GrlTrackerSourcePriv *priv = GRL_TRACKER_SOURCE_GET_PRIVATE (source);
+
+  source->priv = priv;
+
+  priv->browsing_mode = TRACKER_BROWSING_MODE_CATEGORY;
+
+  tracker_sparql_connection_get_async (NULL,
+                                       (GAsyncReadyCallback) tracker_get_connection_cb,
+                                       priv);
 
-  source->priv->browsing_mode = TRACKER_BROWSING_MODE_CATEGORY;
 }
 
 static void
@@ -394,6 +392,9 @@ grl_tracker_source_set_property (GObject      *object,
         tracker_browsing_mode_from_str (g_value_get_string (value));
       if (mode != TRACKER_BROWSING_MODE_INVALID)
         priv->browsing_mode = mode;
+      else
+        GRL_WARNING ("Trying to set a wrong browsing mode: %s",
+                     g_value_get_string (value));
     }
     break;
 
@@ -566,6 +567,14 @@ setup_key_mappings (void)
                       "video");
 }
 
+static void
+tracker_get_connection_cb (GObject *object,
+                           GAsyncResult *res,
+                           GrlTrackerSourcePriv *priv)
+{
+  priv->tracker_connection = tracker_sparql_connection_get_finish (res, NULL);
+}
+
 static tracker_grl_sparql_t *
 get_mapping_from_sparql (const gchar *key)
 {
-- 
1.7.2.3



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