[gnome-photos] query-builder, source: Shuffle some code around



commit 91bf3ccdca6a98b2561d2f91e7945cfd74504b20
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Feb 5 20:13:04 2018 +0100

    query-builder, source: Shuffle some code around
    
    The code to build a filter for local content is only used by Source.
    There's no need to expose it as a public photos-query-builder.h API.
    
    This keeps the code in sync with gnome-documents.

 src/photos-query-builder.c | 68 --------------------------------------------
 src/photos-query-builder.h |  2 --
 src/photos-source.c        | 70 ++++++++++++++++++++++++++++++++++++++++++++--
 3 files changed, 68 insertions(+), 72 deletions(-)
---
diff --git a/src/photos-query-builder.c b/src/photos-query-builder.c
index 66b435c7..84effc69 100644
--- a/src/photos-query-builder.c
+++ b/src/photos-query-builder.c
@@ -25,19 +25,12 @@
 
 #include <string.h>
 
-#include <gio/gio.h>
-
 #include "photos-base-manager.h"
 #include "photos-query-builder.h"
 #include "photos-search-type.h"
 #include "photos-source-manager.h"
 #include "photos-search-match-manager.h"
 #include "photos-search-type-manager.h"
-#include "photos-utils.h"
-
-
-static const gchar *TRACKER_SCHEMA = "org.freedesktop.Tracker.Miner.Files";
-static const gchar *TRACKER_KEY_RECURSIVE_DIRECTORIES = "index-recursive-directories";
 
 
 static gchar *
@@ -374,64 +367,3 @@ photos_query_builder_update_mtime_query (PhotosSearchContextState *state, const
 
   return query;
 }
-
-
-gchar *
-photos_query_builder_filter_local (void)
-{
-  g_autoptr (GSettings) settings = NULL;
-  g_autoptr (GString) tracker_filter = NULL;
-  g_auto (GStrv) tracker_dirs = NULL;
-  g_autofree gchar *desktop_uri = NULL;
-  g_autofree gchar *download_uri = NULL;
-  g_autofree gchar *export_path = NULL;
-  g_autofree gchar *export_uri = NULL;
-  gchar *filter;
-  const gchar *path;
-  g_autofree gchar *pictures_uri = NULL;
-  guint i;
-
-  settings = g_settings_new (TRACKER_SCHEMA);
-  tracker_dirs = g_settings_get_strv (settings, TRACKER_KEY_RECURSIVE_DIRECTORIES);
-  tracker_filter = g_string_new ("");
-
-  for (i = 0; tracker_dirs[i] != NULL; i++)
-    {
-      g_autofree gchar *tracker_uri = NULL;
-
-      /* ignore special XDG placeholders, since we handle those internally */
-      if (tracker_dirs[i][0] == '&' || tracker_dirs[i][0] == '$')
-        continue;
-
-      tracker_uri = photos_utils_convert_path_to_uri (tracker_dirs[i]);
-      g_string_append_printf (tracker_filter, " || fn:contains (nie:url (?urn), '%s')", tracker_uri);
-    }
-
-  path = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
-  desktop_uri = photos_utils_convert_path_to_uri (path);
-
-  path = g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD);
-  download_uri = photos_utils_convert_path_to_uri (path);
-
-  path = g_get_user_special_dir (G_USER_DIRECTORY_PICTURES);
-  pictures_uri = photos_utils_convert_path_to_uri (path);
-
-  export_path = g_build_filename (path, PHOTOS_EXPORT_SUBPATH, NULL);
-  export_uri = photos_utils_convert_path_to_uri (export_path);
-
-  filter = g_strdup_printf ("(((fn:contains (nie:url (?urn), '%s')"
-                            "   || fn:contains (nie:url (?urn), '%s')"
-                            "   || fn:contains (nie:url (?urn), '%s')"
-                            "   %s)"
-                            "  && !fn:contains (nie:url (?urn), '%s'))"
-                            " || fn:starts-with (nao:identifier (?urn), '%s')"
-                            " || (?urn = nfo:image-category-screenshot))",
-                            desktop_uri,
-                            download_uri,
-                            pictures_uri,
-                            tracker_filter->str,
-                            export_uri,
-                            PHOTOS_QUERY_LOCAL_COLLECTIONS_IDENTIFIER);
-
-  return filter;
-}
diff --git a/src/photos-query-builder.h b/src/photos-query-builder.h
index a895529b..3703fe8f 100644
--- a/src/photos-query-builder.h
+++ b/src/photos-query-builder.h
@@ -61,8 +61,6 @@ PhotosQuery  *photos_query_builder_single_query        (PhotosSearchContextState
 
 PhotosQuery  *photos_query_builder_update_mtime_query (PhotosSearchContextState *state, const gchar 
*resource);
 
-gchar        *photos_query_builder_filter_local        (void);
-
 G_END_DECLS
 
 #endif /* PHOTOS_QUERY_BUILDER */
diff --git a/src/photos-source.c b/src/photos-source.c
index 24e0706c..845f1c86 100644
--- a/src/photos-source.c
+++ b/src/photos-source.c
@@ -27,8 +27,9 @@
 
 #include "egg-counter.h"
 #include "photos-filterable.h"
-#include "photos-query-builder.h"
+#include "photos-query.h"
 #include "photos-source.h"
+#include "photos-utils.h"
 
 
 struct _PhotosSource
@@ -59,6 +60,71 @@ G_DEFINE_TYPE_WITH_CODE (PhotosSource, photos_source, G_TYPE_OBJECT,
 EGG_DEFINE_COUNTER (instances, "PhotosSource", "Instances", "Number of PhotosSource instances")
 
 
+static const gchar *TRACKER_SCHEMA = "org.freedesktop.Tracker.Miner.Files";
+static const gchar *TRACKER_KEY_RECURSIVE_DIRECTORIES = "index-recursive-directories";
+
+
+static gchar *
+photos_source_build_filter_local (void)
+{
+  g_autoptr (GSettings) settings = NULL;
+  g_autoptr (GString) tracker_filter = NULL;
+  g_auto (GStrv) tracker_dirs = NULL;
+  g_autofree gchar *desktop_uri = NULL;
+  g_autofree gchar *download_uri = NULL;
+  g_autofree gchar *export_path = NULL;
+  g_autofree gchar *export_uri = NULL;
+  gchar *filter;
+  const gchar *path;
+  g_autofree gchar *pictures_uri = NULL;
+  guint i;
+
+  settings = g_settings_new (TRACKER_SCHEMA);
+  tracker_dirs = g_settings_get_strv (settings, TRACKER_KEY_RECURSIVE_DIRECTORIES);
+  tracker_filter = g_string_new ("");
+
+  for (i = 0; tracker_dirs[i] != NULL; i++)
+    {
+      g_autofree gchar *tracker_uri = NULL;
+
+      /* ignore special XDG placeholders, since we handle those internally */
+      if (tracker_dirs[i][0] == '&' || tracker_dirs[i][0] == '$')
+        continue;
+
+      tracker_uri = photos_utils_convert_path_to_uri (tracker_dirs[i]);
+      g_string_append_printf (tracker_filter, " || fn:contains (nie:url (?urn), '%s')", tracker_uri);
+    }
+
+  path = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
+  desktop_uri = photos_utils_convert_path_to_uri (path);
+
+  path = g_get_user_special_dir (G_USER_DIRECTORY_DOWNLOAD);
+  download_uri = photos_utils_convert_path_to_uri (path);
+
+  path = g_get_user_special_dir (G_USER_DIRECTORY_PICTURES);
+  pictures_uri = photos_utils_convert_path_to_uri (path);
+
+  export_path = g_build_filename (path, PHOTOS_EXPORT_SUBPATH, NULL);
+  export_uri = photos_utils_convert_path_to_uri (export_path);
+
+  filter = g_strdup_printf ("(((fn:contains (nie:url (?urn), '%s')"
+                            "   || fn:contains (nie:url (?urn), '%s')"
+                            "   || fn:contains (nie:url (?urn), '%s')"
+                            "   %s)"
+                            "  && !fn:contains (nie:url (?urn), '%s'))"
+                            " || fn:starts-with (nao:identifier (?urn), '%s')"
+                            " || (?urn = nfo:image-category-screenshot))",
+                            desktop_uri,
+                            download_uri,
+                            pictures_uri,
+                            tracker_filter->str,
+                            export_uri,
+                            PHOTOS_QUERY_LOCAL_COLLECTIONS_IDENTIFIER);
+
+  return filter;
+}
+
+
 static gchar *
 photos_source_build_filter_resource (PhotosSource *self)
 {
@@ -93,7 +159,7 @@ photos_source_get_filter (PhotosFilterable *iface)
   g_assert_cmpstr (self->id, !=, PHOTOS_SOURCE_STOCK_ALL);
 
   if (g_strcmp0 (self->id, PHOTOS_SOURCE_STOCK_LOCAL) == 0)
-    return photos_query_builder_filter_local ();
+    return photos_source_build_filter_local ();
 
   return photos_source_build_filter_resource (self);
 }


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