minfoprovider: Fixed support for more than one query
authorSimón Pena <spenap@gmail.com>
Mon, 31 May 2010 09:34:30 +0000 (11:34 +0200)
committerSimón Pena <spenap@gmail.com>
Mon, 31 May 2010 09:34:30 +0000 (11:34 +0200)
The service is able to perform more than a search without object path
collisions, due to the following changes:
* The TMDBMovie service has been updated so that the object path it gets
contains a suffix.
* The MInfoProvider service keeps track of the searches it has done,
and uses that search count + found movie ID to build their suffix
* The TODO is updated to reflect this change

TODO
src/mvs-minfo-provider-service.c
src/mvs-tmdb-movie-service.c
src/mvs-tmdb-movie-service.h

diff --git a/TODO b/TODO
index 6a4b62d..832cae1 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,9 +1,8 @@
 Release 0.1:
 * Expose TMDBMovie via DBus
        - Creating TMDB movie-service gobject
-               + Getters for each property
-       - A method to generate UID must be added
-       - The result objects lifetime must be controlled and finalized
+               + Getters for each property     
+    - The result objects lifetime must be controlled and finalized
        when not needed.
 * Update build so that it creates a .service file
 * Create a MovieManager class in Python to ask for and retrieve results
index 1e6e049..389cf05 100644 (file)
@@ -47,6 +47,7 @@ mvs_minfo_provider_service_signals[LAST_SIGNAL] = { 0 };
 struct _MvsMInfoProviderServicePrivate {
         MvsMInfoProvider *minfo_provider;
         DBusGConnection *connection;
+        guint search_id;
 };
 
 gboolean
@@ -75,10 +76,16 @@ response_received_cb (MvsMInfoProvider *provider, GList *list,
         for (iter = list; iter; iter = iter->next) {
                 if (MVS_IS_TMDB_MOVIE (iter->data)) {
                         MvsTmdbMovie *tmdb_movie = MVS_TMDB_MOVIE (iter->data);
+                        gchar *uid_suffix = g_strdup_printf ("%d_%s",
+                                        self->priv->search_id,
+                                        mvs_tmdb_movie_get_id (tmdb_movie));
 
                         mvs_tmdb_movie_print (tmdb_movie);
-                        movie = mvs_tmdb_movie_service_new (self->priv->connection, tmdb_movie, i);
-                        object_paths[i] = g_strdup_printf ("/TMDBMovie/%d", i);
+                        movie = mvs_tmdb_movie_service_new (self->priv->connection,
+                                        tmdb_movie, uid_suffix);
+                        object_paths[i] = g_strdup_printf ("/TMDBMovie/%s",
+                                        uid_suffix);
+                        g_free (uid_suffix);
                 }
                 i++;
         }
@@ -86,6 +93,7 @@ response_received_cb (MvsMInfoProvider *provider, GList *list,
 
         g_signal_emit (self, mvs_minfo_provider_service_signals[RESPONSE_RECEIVED], 0, object_paths);
         g_strfreev (object_paths);
+        self->priv->search_id++;
 }
 
 static void
@@ -189,6 +197,7 @@ mvs_minfo_provider_service_init (MvsMInfoProviderService *self)
         self->priv = GET_PRIVATE (self);
         self->priv->minfo_provider = mvs_minfo_provider_new ();
         self->priv->connection = NULL;
+        self->priv->search_id = 0;
 
         g_signal_connect (self->priv->minfo_provider, "response-received",
                           G_CALLBACK (response_received_cb), self);
index 36b910b..9c2bfa6 100644 (file)
@@ -37,7 +37,7 @@ enum {
 struct _MvsTMDBMovieServicePrivate {
         MvsTmdbMovie *movie;
         DBusGConnection *connection;
-        guint id;
+        gchar *suffix;
 };
 
 gboolean
@@ -71,8 +71,8 @@ setup_dbus (MvsTMDBMovieService *self)
                 g_error_free (error);
         }
 
-        object_path = g_strdup_printf (TMDB_MOVIE_SERVICE_OBJECT_PATH "/%d",
-                        self->priv->id);
+        object_path = g_strdup_printf (TMDB_MOVIE_SERVICE_OBJECT_PATH "/%s",
+                        self->priv->suffix);
 
         dbus_g_connection_register_g_object (self->priv->connection,
                                              object_path,
@@ -113,6 +113,7 @@ mvs_tmdb_movie_service_finalize (GObject *object)
         if (self->priv->connection) {
                 dbus_g_connection_unref (self->priv->connection);
         }
+        g_free (self->priv->suffix);
         g_object_unref (self->priv->movie);
         G_OBJECT_CLASS (mvs_tmdb_movie_service_parent_class)->finalize (object);
 }
@@ -143,14 +144,15 @@ mvs_tmdb_movie_service_init (MvsTMDBMovieService *self)
         self->priv = GET_PRIVATE (self);
         self->priv->movie = NULL;
         self->priv->connection = NULL;
+        self->priv->suffix = NULL;
 }
 
 MvsTMDBMovieService*
 mvs_tmdb_movie_service_new (DBusGConnection *connection,
-                MvsTmdbMovie *movie, guint id)
+                MvsTmdbMovie *movie, const gchar *suffix)
 {
         MvsTMDBMovieService *instance = g_object_new (MVS_TYPE_TMDB_MOVIE_SERVICE, NULL);
-        instance->priv->id = id;
+        instance->priv->suffix = g_strdup(suffix);
         g_object_set (instance, "connection", connection, NULL);
         instance->priv->movie = movie;
         return instance;
index a185e72..d9f9e2d 100644 (file)
@@ -51,7 +51,7 @@ typedef struct {
 
 GType mvs_tmdb_movie_service_get_type (void);
 MvsTMDBMovieService* mvs_tmdb_movie_service_new (DBusGConnection *connection,
-                MvsTmdbMovie *movie, guint id);
+                MvsTmdbMovie *movie, const gchar *suffix);
 
 G_END_DECLS