[tracker/wip/carlosg/domain-ontologies: 71/93] tracker-miner-fs: Adopt TrackerThumbnailer from libtracker-miner



commit 6e658848bb2d34a73bc495616d848eda62177f2d
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Jun 18 01:31:07 2017 +0200

    tracker-miner-fs: Adopt TrackerThumbnailer from libtracker-miner
    
    It makes no sense to have that at the library level, just move thumbnail
    handling to TrackerMinerFiles.
    
    Coincidentally, this removes further queries that required knowledge about
    the ontology in TrackerMinerFS.

 src/libtracker-miner/Makefile.am                   |    2 -
 src/libtracker-miner/tracker-miner-fs.c            |   93 -----------------
 src/miners/fs/Makefile.am                          |    2 +
 src/miners/fs/tracker-miner-files.c                |  104 ++++++++++++++++++++
 .../fs}/tracker-thumbnailer.c                      |    0
 .../fs}/tracker-thumbnailer.h                      |    0
 6 files changed, 106 insertions(+), 95 deletions(-)
---
diff --git a/src/libtracker-miner/Makefile.am b/src/libtracker-miner/Makefile.am
index 222a3fc..ba10f9c 100644
--- a/src/libtracker-miner/Makefile.am
+++ b/src/libtracker-miner/Makefile.am
@@ -48,8 +48,6 @@ private_sources =                                    \
        tracker-task-pool.c                            \
        tracker-sparql-buffer.h                        \
        tracker-sparql-buffer.c                        \
-       tracker-thumbnailer.c                          \
-       tracker-thumbnailer.h                          \
        tracker-utils.c                                \
        tracker-utils.h
 
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 42dc2f0..4903a43 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -25,7 +25,6 @@
 #include "tracker-miner-fs.h"
 #include "tracker-monitor.h"
 #include "tracker-utils.h"
-#include "tracker-thumbnailer.h"
 #include "tracker-priority-queue.h"
 #include "tracker-task-pool.h"
 #include "tracker-sparql-buffer.h"
@@ -164,11 +163,6 @@ typedef struct {
        TrackerMiner *miner;
 } UpdateProcessingTaskContext;
 
-typedef struct {
-       GMainLoop *main_loop;
-       TrackerMiner *miner;
-} ThumbnailMoveData;
-
 struct _TrackerMinerFSPrivate {
        /* File queues for indexer */
        TrackerPriorityQueue *items_created;
@@ -212,8 +206,6 @@ struct _TrackerMinerFSPrivate {
        /* Writeback tasks */
        TrackerTaskPool *writeback_pool;
 
-       TrackerThumbnailer *thumbnailer;
-
        /* Status */
        GTimer *timer;
        GTimer *extraction_timer;
@@ -771,8 +763,6 @@ miner_fs_initable_init (GInitable     *initable,
                          G_CALLBACK (file_notifier_finished),
                          initable);
 
-       priv->thumbnailer = tracker_thumbnailer_new ();
-
        return TRUE;
 }
 
@@ -851,10 +841,6 @@ fs_finalize (GObject *object)
                g_object_unref (priv->file_notifier);
        }
 
-       if (priv->thumbnailer) {
-               g_object_unref (priv->thumbnailer);
-       }
-
        if (priv->roots_to_notify) {
                g_hash_table_unref (priv->roots_to_notify);
 
@@ -1532,11 +1518,6 @@ item_remove (TrackerMinerFS *fs,
        g_debug ("Removing item: '%s' (Deleted from filesystem or no longer monitored)",
                 uri);
 
-       if (!only_children) {
-               if (fs->priv->thumbnailer)
-                       tracker_thumbnailer_remove_add (fs->priv->thumbnailer, uri, NULL);
-       }
-
        g_object_set_qdata (G_OBJECT (file),
                            fs->priv->quark_recursive_removal,
                            GINT_TO_POINTER (TRUE));
@@ -1563,39 +1544,6 @@ item_remove (TrackerMinerFS *fs,
        return TRUE;
 }
 
-static void
-move_thumbnails_cb (GObject      *object,
-                    GAsyncResult *result,
-                    gpointer      user_data)
-{
-       ThumbnailMoveData *data = user_data;
-       TrackerMinerFS *fs = TRACKER_MINER_FS (data->miner);
-       GError *error = NULL;
-
-       TrackerSparqlCursor *cursor = tracker_sparql_connection_query_finish (TRACKER_SPARQL_CONNECTION 
(object), result, &error);
-
-       if (error) {
-               g_critical ("Could move thumbnails: %s", error->message);
-               g_error_free (error);
-       } else {
-               while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
-                       const gchar *src, *dst, *mimetype;
-
-                       src = tracker_sparql_cursor_get_string (cursor, 0, NULL);
-                       dst = tracker_sparql_cursor_get_string (cursor, 1, NULL);
-                       mimetype = tracker_sparql_cursor_get_string (cursor, 2, NULL);
-
-                       if (fs->priv->thumbnailer) {
-                               tracker_thumbnailer_move_add (fs->priv->thumbnailer,
-                                                             src, mimetype, dst);
-                       }
-               }
-       }
-
-       g_object_unref (cursor);
-       g_main_loop_quit (data->main_loop);
-}
-
 static gboolean
 item_move (TrackerMinerFS *fs,
            GFile          *file,
@@ -1614,8 +1562,6 @@ item_move (TrackerMinerFS *fs,
 
        /* FIXME: Should check the _NO_STAT on TrackerDirectoryFlags first! */
        file_info = g_file_query_info (file,
-                                      G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME ","
-                                      G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
                                       G_FILE_ATTRIBUTE_STANDARD_TYPE,
                                       G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
                                       NULL, NULL);
@@ -1668,42 +1614,6 @@ item_move (TrackerMinerFS *fs,
                     (flags & TRACKER_DIRECTORY_FLAG_RECURSE) != 0 &&
                     g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY);
 
-       if (fs->priv->thumbnailer) {
-               tracker_thumbnailer_move_add (fs->priv->thumbnailer, source_uri,
-                                             g_file_info_get_content_type (file_info),
-                                             uri);
-
-               if (recursive) {
-                       ThumbnailMoveData move_data;
-                       gchar *query;
-
-                       g_debug ("Moving thumbnails within '%s'", uri);
-
-                       /* Push all moved files to thumbnailer */
-                       move_data.main_loop = g_main_loop_new (NULL, FALSE);
-                       move_data.miner = TRACKER_MINER (fs);
-
-                       query = g_strdup_printf ("SELECT ?url ?new_url nie:mimeType(?u) {"
-                                                "  ?u a rdfs:Resource ;"
-                                                "     nie:url ?url ."
-                                                "  BIND (CONCAT (\"%s/\", SUBSTR (?url, STRLEN (\"%s/\") + 
1)) AS ?new_url) ."
-                                                "  FILTER (STRSTARTS (?url, \"%s/\"))"
-                                                "}",
-                                                uri, source_uri, source_uri);
-
-                       tracker_sparql_connection_query_async (tracker_miner_get_connection (TRACKER_MINER 
(fs)),
-                                                              query,
-                                                              NULL,
-                                                              move_thumbnails_cb,
-                                                              &move_data);
-
-                       g_main_loop_run (move_data.main_loop);
-                       g_main_loop_unref (move_data.main_loop);
-                       g_free (query);
-               }
-       }
-
-
        /* Delete destination item from store if any */
        item_remove (fs, file, FALSE);
 
@@ -2143,9 +2053,6 @@ item_queue_handlers_cb (gpointer user_data)
                        if (tracker_task_pool_get_size (TRACKER_TASK_POOL (fs->priv->sparql_buffer)) == 0) {
                                /* Print stats and signal finished */
                                process_stop (fs);
-
-                               if (fs->priv->thumbnailer)
-                                       tracker_thumbnailer_send (fs->priv->thumbnailer);
                        } else {
                                /* Flush any possible pending update here */
                                tracker_sparql_buffer_flush (fs->priv->sparql_buffer,
diff --git a/src/miners/fs/Makefile.am b/src/miners/fs/Makefile.am
index 253091b..9ba5e97 100644
--- a/src/miners/fs/Makefile.am
+++ b/src/miners/fs/Makefile.am
@@ -40,6 +40,8 @@ tracker_miner_fs_SOURCES =                             \
        tracker-miner-files-peer-listener.h            \
        tracker-storage.c                              \
        tracker-storage.h                              \
+       tracker-thumbnailer.c                          \
+       tracker-thumbnailer.h                          \
        tracker-writeback-listener.c                   \
        tracker-writeback-listener.h                   \
        tracker-writeback-dispatcher.c                 \
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index 3c86bbd..93b1b3d 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -45,6 +45,7 @@
 #include "tracker-config.h"
 #include "tracker-storage.h"
 #include "tracker-extract-watchdog.h"
+#include "tracker-thumbnailer.h"
 
 #define DISK_SPACE_CHECK_FREQUENCY 10
 #define SECONDS_PER_DAY 86400
@@ -104,8 +105,15 @@ struct TrackerMinerFilesPrivate {
        guint stale_volumes_check_id;
 
        GList *extraction_queue;
+
+       TrackerThumbnailer *thumbnailer;
 };
 
+typedef struct {
+       GMainLoop *main_loop;
+       TrackerMiner *miner;
+} ThumbnailMoveData;
+
 enum {
        VOLUME_MOUNTED_IN_STORE = 1 << 0,
        VOLUME_MOUNTED = 1 << 1
@@ -565,6 +573,7 @@ miner_files_initable_init (GInitable     *initable,
        disk_space_check_start (mf);
 
        mf->private->extract_watchdog = tracker_extract_watchdog_new ();
+       mf->private->thumbnailer = tracker_thumbnailer_new ();
 
        return TRUE;
 }
@@ -666,6 +675,10 @@ miner_files_finalize (GObject *object)
                priv->stale_volumes_check_id = 0;
        }
 
+       if (priv->thumbnailer) {
+               g_object_unref (priv->thumbnailer);
+       }
+
        g_list_free (priv->extraction_queue);
 
        G_OBJECT_CLASS (tracker_miner_files_parent_class)->finalize (object);
@@ -2438,6 +2451,11 @@ miner_files_finished (TrackerMinerFS *fs,
                       gint            files_found,
                       gint            files_ignored)
 {
+       TrackerMinerFilesPrivate *priv = TRACKER_MINER_FILES (fs)->private;
+
+       if (priv->thumbnailer)
+               tracker_thumbnailer_send (priv->thumbnailer);
+
        tracker_miner_files_set_last_crawl_done (TRUE);
 }
 
@@ -2488,15 +2506,59 @@ static gchar *
 miner_files_remove_file (TrackerMinerFS *fs,
                          GFile          *file)
 {
+       TrackerMinerFilesPrivate *priv = TRACKER_MINER_FILES (fs)->private;
+
+       if (priv->thumbnailer) {
+               gchar *uri;
+
+               uri = g_file_get_uri (file);
+               tracker_thumbnailer_remove_add (priv->thumbnailer, uri, NULL);
+               g_free (uri);
+       }
+
        return create_delete_sparql (file, TRUE, TRUE);
 }
 
+static void
+move_thumbnails_cb (GObject      *object,
+                    GAsyncResult *result,
+                    gpointer      user_data)
+{
+       ThumbnailMoveData *data = user_data;
+       TrackerMinerFilesPrivate *priv = TRACKER_MINER_FILES (data->miner)->private;
+       GError *error = NULL;
+
+       TrackerSparqlCursor *cursor = tracker_sparql_connection_query_finish (TRACKER_SPARQL_CONNECTION 
(object), result, &error);
+
+       if (error) {
+               g_critical ("Could move thumbnails: %s", error->message);
+               g_error_free (error);
+       } else {
+               while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
+                       const gchar *src, *dst, *mimetype;
+
+                       src = tracker_sparql_cursor_get_string (cursor, 0, NULL);
+                       dst = tracker_sparql_cursor_get_string (cursor, 1, NULL);
+                       mimetype = tracker_sparql_cursor_get_string (cursor, 2, NULL);
+
+                       if (priv->thumbnailer) {
+                               tracker_thumbnailer_move_add (priv->thumbnailer,
+                                                             src, mimetype, dst);
+                       }
+               }
+       }
+
+       g_object_unref (cursor);
+       g_main_loop_quit (data->main_loop);
+}
+
 static gchar *
 miner_files_move_file (TrackerMinerFS *fs,
                        GFile          *file,
                        GFile          *source_file,
                        gboolean        recursive)
 {
+       TrackerMinerFilesPrivate *priv = TRACKER_MINER_FILES (fs)->private;
        GString *sparql = g_string_new (NULL);
        const gchar *new_parent_iri;
        gchar *uri, *source_uri, *display_name;
@@ -2508,6 +2570,48 @@ miner_files_move_file (TrackerMinerFS *fs,
        source_uri = g_file_get_uri (source_file);
        source_iri = tracker_miner_fs_query_urn (fs, file);
 
+       if (priv->thumbnailer) {
+               GFileInfo *file_info;
+
+               file_info = g_file_query_info (file,
+                                              G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+                                              G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+                                              NULL, NULL);
+               tracker_thumbnailer_move_add (priv->thumbnailer, source_uri,
+                                             g_file_info_get_content_type (file_info),
+                                             uri);
+               g_object_unref (file_info);
+
+               if (recursive) {
+                       ThumbnailMoveData move_data;
+                       gchar *query;
+
+                       g_debug ("Moving thumbnails within '%s'", uri);
+
+                       /* Push all moved files to thumbnailer */
+                       move_data.main_loop = g_main_loop_new (NULL, FALSE);
+                       move_data.miner = TRACKER_MINER (fs);
+
+                       query = g_strdup_printf ("SELECT ?url ?new_url nie:mimeType(?u) {"
+                                                "  ?u a rdfs:Resource ;"
+                                                "     nie:url ?url ."
+                                                "  BIND (CONCAT (\"%s/\", SUBSTR (?url, STRLEN (\"%s/\") + 
1)) AS ?new_url) ."
+                                                "  FILTER (STRSTARTS (?url, \"%s/\"))"
+                                                "}",
+                                                uri, source_uri, source_uri);
+
+                       tracker_sparql_connection_query_async (tracker_miner_get_connection (TRACKER_MINER 
(fs)),
+                                                              query,
+                                                              NULL,
+                                                              move_thumbnails_cb,
+                                                              &move_data);
+
+                       g_main_loop_run (move_data.main_loop);
+                       g_main_loop_unref (move_data.main_loop);
+                       g_free (query);
+               }
+       }
+
        path = g_file_get_path (file);
        basename = g_filename_display_basename (path);
        display_name = tracker_sparql_escape_string (basename);
diff --git a/src/libtracker-miner/tracker-thumbnailer.c b/src/miners/fs/tracker-thumbnailer.c
similarity index 100%
rename from src/libtracker-miner/tracker-thumbnailer.c
rename to src/miners/fs/tracker-thumbnailer.c
diff --git a/src/libtracker-miner/tracker-thumbnailer.h b/src/miners/fs/tracker-thumbnailer.h
similarity index 100%
rename from src/libtracker-miner/tracker-thumbnailer.h
rename to src/miners/fs/tracker-thumbnailer.h


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