[gnome-online-miners/wip/rishi/insert-share: 14/24] src: Pass 'previous_resources' separately to the query vfunc



commit 1ac23acd6dd96a6380914d3baf060935f81981cf
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Sep 5 14:16:47 2016 +0200

    src: Pass 'previous_resources' separately to the query vfunc
    
    This will help us reuse the parts of the RefreshDB code for
    implementing InsertSharedContent.

 src/gom-facebook-miner.c     |   18 ++++++++++++++----
 src/gom-flickr-miner.c       |   22 ++++++++++++++++++----
 src/gom-gdata-miner.c        |   28 ++++++++++++++++++++--------
 src/gom-media-server-miner.c |    6 ++++--
 src/gom-miner.c              |    2 +-
 src/gom-miner.h              |    1 +
 src/gom-owncloud-miner.c     |   18 ++++++++++++++----
 src/gom-zpj-miner.c          |   10 +++++++---
 8 files changed, 79 insertions(+), 26 deletions(-)
---
diff --git a/src/gom-facebook-miner.c b/src/gom-facebook-miner.c
index ce45f5b..b9700d3 100644
--- a/src/gom-facebook-miner.c
+++ b/src/gom-facebook-miner.c
@@ -36,6 +36,7 @@ G_DEFINE_TYPE (GomFacebookMiner, gom_facebook_miner, GOM_TYPE_MINER)
 static gboolean
 account_miner_job_process_photo (GomAccountMinerJob *job,
                                  TrackerSparqlConnection *connection,
+                                 GHashTable *previous_resources,
                                  GFBGraphPhoto *photo,
                                  const gchar *parent_resource_urn,
                                  const gchar *creator,
@@ -62,7 +63,7 @@ account_miner_job_process_photo (GomAccountMinerJob *job,
   identifier = g_strdup_printf ("facebook:%s", photo_id);
 
   /* remove from the list of the previous resources */
-  g_hash_table_remove (job->previous_resources, identifier);
+  g_hash_table_remove (previous_resources, identifier);
 
   resource = gom_tracker_sparql_connection_ensure_resource
     (connection,
@@ -179,6 +180,7 @@ account_miner_job_process_photo (GomAccountMinerJob *job,
 static gboolean
 account_miner_job_process_album (GomAccountMinerJob *job,
                                  TrackerSparqlConnection *connection,
+                                 GHashTable *previous_resources,
                                  GFBGraphAlbum *album,
                                  const gchar *creator,
                                  GCancellable *cancellable,
@@ -208,7 +210,7 @@ account_miner_job_process_album (GomAccountMinerJob *job,
   identifier = g_strdup_printf ("photos:collection:facebook:%s", album_id);
 
   /* remove from the list of the previous resources */
-  g_hash_table_remove (job->previous_resources, identifier);
+  g_hash_table_remove (previous_resources, identifier);
 
   resource = gom_tracker_sparql_connection_ensure_resource
     (connection,
@@ -299,7 +301,14 @@ account_miner_job_process_album (GomAccountMinerJob *job,
       GError *local_error = NULL;
       GFBGraphPhoto *photo = GFBGRAPH_PHOTO (l->data);
 
-      account_miner_job_process_photo (job, connection, photo, resource, creator, cancellable, &local_error);
+      account_miner_job_process_photo (job,
+                                       connection,
+                                       previous_resources,
+                                       photo,
+                                       resource,
+                                       creator,
+                                       cancellable,
+                                       &local_error);
       if (local_error != NULL)
         {
           const gchar *photo_id;
@@ -325,6 +334,7 @@ account_miner_job_process_album (GomAccountMinerJob *job,
 static void
 query_facebook (GomAccountMinerJob *job,
                 TrackerSparqlConnection *connection,
+                GHashTable *previous_resources,
                 GCancellable *cancellable,
                 GError **error)
 {
@@ -360,7 +370,7 @@ query_facebook (GomAccountMinerJob *job,
     {
       GFBGraphAlbum *album = GFBGRAPH_ALBUM (l->data);
 
-      account_miner_job_process_album (job, connection, album, me_name, cancellable, &local_error);
+      account_miner_job_process_album (job, connection, previous_resources, album, me_name, cancellable, 
&local_error);
       if (local_error != NULL)
         {
           const gchar *album_id;
diff --git a/src/gom-flickr-miner.c b/src/gom-flickr-miner.c
index a3b75a6..232c7de 100644
--- a/src/gom-flickr-miner.c
+++ b/src/gom-flickr-miner.c
@@ -49,6 +49,7 @@ typedef struct {
 typedef struct {
   FlickrEntry *parent_entry;
   GCancellable *cancellable;
+  GHashTable *previous_resources;
   GMainLoop *loop;
   GomAccountMinerJob *job;
   GrlSource *source;
@@ -58,6 +59,7 @@ typedef struct {
 
 static void account_miner_job_browse_container (GomAccountMinerJob *job,
                                                 TrackerSparqlConnection *connection,
+                                                GHashTable *previous_resources,
                                                 FlickrEntry *entry,
                                                 GCancellable *cancellable);
 
@@ -101,6 +103,7 @@ get_grl_options (GrlSource *source)
 static gboolean
 account_miner_job_process_entry (GomAccountMinerJob *job,
                                  TrackerSparqlConnection *connection,
+                                 GHashTable *previous_resources,
                                  OpType op_type,
                                  FlickrEntry *entry,
                                  GCancellable *cancellable,
@@ -126,7 +129,7 @@ account_miner_job_process_entry (GomAccountMinerJob *job,
                                 id);
 
   /* remove from the list of the previous resources */
-  g_hash_table_remove (job->previous_resources, identifier);
+  g_hash_table_remove (previous_resources, identifier);
 
   if (grl_media_is_container (entry->media))
     class = "nfo:DataContainer";
@@ -309,6 +312,7 @@ source_browse_cb (GrlSource *source,
       entry = create_entry (media, data->parent_entry->media);
       account_miner_job_process_entry (data->job,
                                        data->connection,
+                                       data->previous_resources,
                                        OP_CREATE_HIEARCHY,
                                        entry,
                                        data->cancellable,
@@ -332,6 +336,7 @@ source_browse_cb (GrlSource *source,
 static void
 account_miner_job_browse_container (GomAccountMinerJob *job,
                                     TrackerSparqlConnection *connection,
+                                    GHashTable *previous_resources,
                                     FlickrEntry *entry,
                                     GCancellable *cancellable)
 {
@@ -345,6 +350,7 @@ account_miner_job_browse_container (GomAccountMinerJob *job,
   data.connection = connection;
   data.parent_entry = entry;
   data.job = job;
+  data.previous_resources = previous_resources;
 
   context = g_main_context_new ();
   g_main_context_push_thread_default (context);
@@ -391,7 +397,13 @@ source_search_cb (GrlSource *source,
       FlickrEntry *entry;
 
       entry = create_entry (media, NULL);
-      account_miner_job_process_entry (data->job, data->connection, OP_FETCH_ALL, entry, data->cancellable, 
&local_error);
+      account_miner_job_process_entry (data->job,
+                                       data->connection,
+                                       data->previous_resources,
+                                       OP_FETCH_ALL,
+                                       entry,
+                                       data->cancellable,
+                                       &local_error);
       if (local_error != NULL)
         {
           g_warning ("Unable to process entry %p: %s", media, local_error->message);
@@ -408,6 +420,7 @@ source_search_cb (GrlSource *source,
 static void
 query_flickr (GomAccountMinerJob *job,
               TrackerSparqlConnection *connection,
+              GHashTable *previous_resources,
               GCancellable *cancellable,
               GError **error)
 {
@@ -439,6 +452,7 @@ query_flickr (GomAccountMinerJob *job,
   data.cancellable = cancellable;
   data.connection = connection;
   data.job = job;
+  data.previous_resources = previous_resources;
   context = g_main_context_new ();
   g_main_context_push_thread_default (context);
   data.loop = g_main_loop_new (context, FALSE);
@@ -454,13 +468,13 @@ query_flickr (GomAccountMinerJob *job,
   g_main_context_unref (context);
 
   entry = create_entry (NULL, NULL);
-  account_miner_job_browse_container (job, connection, entry, cancellable);
+  account_miner_job_browse_container (job, connection, previous_resources, entry, cancellable);
   free_entry (entry);
 
   while (!g_queue_is_empty (priv->boxes))
     {
       entry = (FlickrEntry *) g_queue_pop_head (priv->boxes);
-      account_miner_job_browse_container (job, connection, entry, cancellable);
+      account_miner_job_browse_container (job, connection, previous_resources, entry, cancellable);
       free_entry (entry);
     }
 }
diff --git a/src/gom-gdata-miner.c b/src/gom-gdata-miner.c
index a197577..a0f80da 100644
--- a/src/gom-gdata-miner.c
+++ b/src/gom-gdata-miner.c
@@ -57,6 +57,7 @@ generate_fake_email_from_fullname (const gchar *fullname)
 static gboolean
 account_miner_job_process_entry (GomAccountMinerJob *job,
                                  TrackerSparqlConnection *connection,
+                                 GHashTable *previous_resources,
                                  GDataDocumentsService *service,
                                  GDataDocumentsEntry *doc_entry,
                                  GCancellable *cancellable,
@@ -99,7 +100,7 @@ account_miner_job_process_entry (GomAccountMinerJob *job,
     }
 
   /* remove from the list of the previous resources */
-  g_hash_table_remove (job->previous_resources, identifier);
+  g_hash_table_remove (previous_resources, identifier);
 
   if (GDATA_IS_DOCUMENTS_PRESENTATION (doc_entry))
     class = "nfo:Presentation";
@@ -336,6 +337,7 @@ account_miner_job_process_entry (GomAccountMinerJob *job,
 static gboolean
 account_miner_job_process_photo (GomAccountMinerJob *job,
                                  TrackerSparqlConnection *connection,
+                                 GHashTable *previous_resources,
                                  GDataPicasaWebFile *photo,
                                  const gchar *parent_resource_urn,
                                  GCancellable *cancellable,
@@ -390,7 +392,7 @@ account_miner_job_process_photo (GomAccountMinerJob *job,
   identifier = g_strdup_printf ("%s%s", PREFIX_PICASAWEB, id);
 
   /* remove from the list of the previous resources */
-  g_hash_table_remove (job->previous_resources, identifier);
+  g_hash_table_remove (previous_resources, identifier);
 
   resource = gom_tracker_sparql_connection_ensure_resource
     (connection,
@@ -623,6 +625,7 @@ account_miner_job_process_photo (GomAccountMinerJob *job,
 static gboolean
 account_miner_job_process_album (GomAccountMinerJob *job,
                                  TrackerSparqlConnection *connection,
+                                 GHashTable *previous_resources,
                                  GDataPicasaWebService *service,
                                  GDataPicasaWebAlbum *album,
                                  GCancellable *cancellable,
@@ -651,7 +654,7 @@ account_miner_job_process_album (GomAccountMinerJob *job,
   identifier = g_strdup_printf ("photos:collection:%s%s", PREFIX_PICASAWEB, album_id);
 
   /* remove from the list of the previous resources */
-  g_hash_table_remove (job->previous_resources, identifier);
+  g_hash_table_remove (previous_resources, identifier);
 
   resource = gom_tracker_sparql_connection_ensure_resource
     (connection,
@@ -770,7 +773,7 @@ account_miner_job_process_album (GomAccountMinerJob *job,
     {
       GDataPicasaWebFile *file = GDATA_PICASAWEB_FILE (l->data);
 
-      account_miner_job_process_photo (job, connection, file, resource, cancellable, error);
+      account_miner_job_process_photo (job, connection, previous_resources, file, resource, cancellable, 
error);
 
       if (*error != NULL)
         {
@@ -796,6 +799,7 @@ account_miner_job_process_album (GomAccountMinerJob *job,
 static void
 query_gdata_documents (GomAccountMinerJob *job,
                        TrackerSparqlConnection *connection,
+                       GHashTable *previous_resources,
                        GDataDocumentsService *service,
                        GCancellable *cancellable,
                        GError **error)
@@ -840,7 +844,13 @@ query_gdata_documents (GomAccountMinerJob *job,
       for (l = entries; l != NULL; l = l->next)
         {
           local_error = NULL;
-          account_miner_job_process_entry (job, connection, service, l->data, cancellable, &local_error);
+          account_miner_job_process_entry (job,
+                                           connection,
+                                           previous_resources,
+                                           service,
+                                           l->data,
+                                           cancellable,
+                                           &local_error);
 
           if (local_error != NULL)
             {
@@ -861,6 +871,7 @@ query_gdata_documents (GomAccountMinerJob *job,
 static void
 query_gdata_photos (GomAccountMinerJob *job,
                     TrackerSparqlConnection *connection,
+                    GHashTable *previous_resources,
                     GDataPicasaWebService *service,
                     GCancellable *cancellable,
                     GError **error)
@@ -878,7 +889,7 @@ query_gdata_photos (GomAccountMinerJob *job,
     {
       GDataPicasaWebAlbum *album = GDATA_PICASAWEB_ALBUM (l->data);
 
-      account_miner_job_process_album (job, connection, service, album, cancellable, error);
+      account_miner_job_process_album (job, connection, previous_resources, service, album, cancellable, 
error);
 
       if (*error != NULL)
         {
@@ -896,6 +907,7 @@ query_gdata_photos (GomAccountMinerJob *job,
 static void
 query_gdata (GomAccountMinerJob *job,
              TrackerSparqlConnection *connection,
+             GHashTable *previous_resources,
              GCancellable *cancellable,
              GError **error)
 {
@@ -903,11 +915,11 @@ query_gdata (GomAccountMinerJob *job,
 
   service = g_hash_table_lookup (job->services, "documents");
   if (service != NULL)
-    query_gdata_documents (job, connection, GDATA_DOCUMENTS_SERVICE (service), cancellable, error);
+    query_gdata_documents (job, connection, previous_resources, GDATA_DOCUMENTS_SERVICE (service), 
cancellable, error);
 
   service = g_hash_table_lookup (job->services, "photos");
   if (service != NULL)
-    query_gdata_photos (job, connection, GDATA_PICASAWEB_SERVICE (service), cancellable, error);
+    query_gdata_photos (job, connection, previous_resources, GDATA_PICASAWEB_SERVICE (service), cancellable, 
error);
 }
 
 static GHashTable *
diff --git a/src/gom-media-server-miner.c b/src/gom-media-server-miner.c
index db5e5ff..c0c6113 100644
--- a/src/gom-media-server-miner.c
+++ b/src/gom-media-server-miner.c
@@ -41,6 +41,7 @@ G_DEFINE_TYPE_WITH_PRIVATE (GomMediaServerMiner, gom_media_server_miner, GOM_TYP
 static gboolean
 account_miner_job_process_photo (GomAccountMinerJob *job,
                                  TrackerSparqlConnection *connection,
+                                 GHashTable *previous_resources,
                                  GomDlnaPhotoItem *photo,
                                  GCancellable *cancellable,
                                  GError **error)
@@ -57,7 +58,7 @@ account_miner_job_process_photo (GomAccountMinerJob *job,
   identifier = g_strdup_printf ("media-server:%s", photo_id);
 
   /* remove from the list of the previous resources */
-  g_hash_table_remove (job->previous_resources, identifier);
+  g_hash_table_remove (previous_resources, identifier);
 
   resource = gom_tracker_sparql_connection_ensure_resource
     (connection,
@@ -118,6 +119,7 @@ account_miner_job_process_photo (GomAccountMinerJob *job,
 static void
 query_media_server (GomAccountMinerJob *job,
                     TrackerSparqlConnection *connection,
+                    GHashTable *previous_resources,
                     GCancellable *cancellable,
                     GError **error)
 {
@@ -153,7 +155,7 @@ query_media_server (GomAccountMinerJob *job,
     {
       GomDlnaPhotoItem *photo = (GomDlnaPhotoItem *) l->data;
 
-      account_miner_job_process_photo (job, connection, photo, cancellable, &local_error);
+      account_miner_job_process_photo (job, connection, previous_resources, photo, cancellable, 
&local_error);
       if (local_error != NULL)
         {
           g_warning ("Unable to process photo: %s", local_error->message);
diff --git a/src/gom-miner.c b/src/gom-miner.c
index 9c28236..5f46ebf 100644
--- a/src/gom-miner.c
+++ b/src/gom-miner.c
@@ -292,7 +292,7 @@ gom_account_miner_job_query (GomAccountMinerJob *job,
   GCancellable *cancellable;
 
   cancellable = g_task_get_cancellable (job->task);
-  miner_class->query (job, job->connection, cancellable, error);
+  miner_class->query (job, job->connection, job->previous_resources, cancellable, error);
 }
 
 static void
diff --git a/src/gom-miner.h b/src/gom-miner.h
index 921d857..3d86c4a 100644
--- a/src/gom-miner.h
+++ b/src/gom-miner.h
@@ -92,6 +92,7 @@ struct _GomMinerClass
 
   void (*query) (GomAccountMinerJob *job,
                  TrackerSparqlConnection *connection,
+                 GHashTable *previous_resources,
                  GCancellable *cancellable,
                  GError **error);
 };
diff --git a/src/gom-owncloud-miner.c b/src/gom-owncloud-miner.c
index 70de1c4..fd0a252 100644
--- a/src/gom-owncloud-miner.c
+++ b/src/gom-owncloud-miner.c
@@ -52,6 +52,7 @@ typedef struct {
 static gboolean
 account_miner_job_process_file (GomAccountMinerJob *job,
                                 TrackerSparqlConnection *connection,
+                                GHashTable *previous_resources,
                                 GFile *file,
                                 GFileInfo *info,
                                 GFile *parent,
@@ -83,7 +84,7 @@ account_miner_job_process_file (GomAccountMinerJob *job,
   g_checksum_reset (checksum);
 
   /* remove from the list of the previous resources */
-  g_hash_table_remove (job->previous_resources, identifier);
+  g_hash_table_remove (previous_resources, identifier);
 
   name = g_file_info_get_name (info);
   if (type == G_FILE_TYPE_REGULAR)
@@ -214,6 +215,7 @@ account_miner_job_process_file (GomAccountMinerJob *job,
 static void
 account_miner_job_traverse_dir (GomAccountMinerJob *job,
                                 TrackerSparqlConnection *connection,
+                                GHashTable *previous_resources,
                                 GFile *dir,
                                 gboolean is_root,
                                 GCancellable *cancellable,
@@ -246,7 +248,14 @@ account_miner_job_traverse_dir (GomAccountMinerJob *job,
 
       if (type == G_FILE_TYPE_REGULAR || type == G_FILE_TYPE_DIRECTORY)
         {
-          account_miner_job_process_file (job, connection, child, info, is_root ? NULL : dir, cancellable, 
&local_error);
+          account_miner_job_process_file (job,
+                                          connection,
+                                          previous_resources,
+                                          child,
+                                          info,
+                                          is_root ? NULL : dir,
+                                          cancellable,
+                                          &local_error);
           if (local_error != NULL)
             {
               uri = g_file_get_uri (child);
@@ -258,7 +267,7 @@ account_miner_job_traverse_dir (GomAccountMinerJob *job,
 
       if (type == G_FILE_TYPE_DIRECTORY)
         {
-          account_miner_job_traverse_dir (job, connection, child, FALSE, cancellable, &local_error);
+          account_miner_job_traverse_dir (job, connection, previous_resources, child, FALSE, cancellable, 
&local_error);
           if (local_error != NULL)
             {
               uri = g_file_get_uri (child);
@@ -338,6 +347,7 @@ volume_mount_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
 static void
 query_owncloud (GomAccountMinerJob *job,
                 TrackerSparqlConnection *connection,
+                GHashTable *previous_resources,
                 GCancellable *cancellable,
                 GError **error)
 {
@@ -415,7 +425,7 @@ query_owncloud (GomAccountMinerJob *job,
     }
 
   root = g_mount_get_root (mount);
-  account_miner_job_traverse_dir (job, connection, root, TRUE, cancellable, error);
+  account_miner_job_traverse_dir (job, connection, previous_resources, root, TRUE, cancellable, error);
 
   g_object_unref (root);
   g_object_unref (mount);
diff --git a/src/gom-zpj-miner.c b/src/gom-zpj-miner.c
index bccfbc8..23868f7 100644
--- a/src/gom-zpj-miner.c
+++ b/src/gom-zpj-miner.c
@@ -36,6 +36,7 @@ G_DEFINE_TYPE (GomZpjMiner, gom_zpj_miner, GOM_TYPE_MINER)
 static gboolean
 account_miner_job_process_entry (GomAccountMinerJob *job,
                                  TrackerSparqlConnection *connection,
+                                 GHashTable *previous_resources,
                                  ZpjSkydriveEntry *entry,
                                  GCancellable *cancellable,
                                  GError **error)
@@ -55,7 +56,7 @@ account_miner_job_process_entry (GomAccountMinerJob *job,
                                 id);
 
   /* remove from the list of the previous resources */
-  g_hash_table_remove (job->previous_resources, identifier);
+  g_hash_table_remove (previous_resources, identifier);
 
   name = zpj_skydrive_entry_get_name (entry);
 
@@ -210,6 +211,7 @@ account_miner_job_process_entry (GomAccountMinerJob *job,
 static void
 account_miner_job_traverse_folder (GomAccountMinerJob *job,
                                    TrackerSparqlConnection *connection,
+                                   GHashTable *previous_resources,
                                    const gchar *folder_id,
                                    GCancellable *cancellable,
                                    GError **error)
@@ -245,14 +247,14 @@ account_miner_job_traverse_folder (GomAccountMinerJob *job,
 
       if (ZPJ_IS_SKYDRIVE_FOLDER (entry))
         {
-          account_miner_job_traverse_folder (job, connection, id, cancellable, error);
+          account_miner_job_traverse_folder (job, connection, previous_resources, id, cancellable, error);
           if (*error != NULL)
             goto out;
         }
       else if (ZPJ_IS_SKYDRIVE_PHOTO (entry))
         continue;
 
-      account_miner_job_process_entry (job, connection, entry, cancellable, error);
+      account_miner_job_process_entry (job, connection, previous_resources, entry, cancellable, error);
 
       if (*error != NULL)
         {
@@ -269,11 +271,13 @@ account_miner_job_traverse_folder (GomAccountMinerJob *job,
 static void
 query_zpj (GomAccountMinerJob *job,
            TrackerSparqlConnection *connection,
+           GHashTable *previous_resources,
            GCancellable *cancellable,
            GError **error)
 {
   account_miner_job_traverse_folder (job,
                                      connection,
+                                     previous_resources,
                                      ZPJ_SKYDRIVE_FOLDER_SKYDRIVE,
                                      cancellable,
                                      error);


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