[gtk+] Store locations as GFile



commit 71b3e0b66b9a9b14ac7e87fdb019e50e4bd23148
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Jul 24 15:29:51 2015 -0400

    Store locations as GFile
    
    It is a bit pointless to have the file chooser get a uri from an
    existing GFile to put in the query, only to have some of the search
    engines reconstruct a GFile from it.

 gtk/gtkfilechooserwidget.c   |    5 +----
 gtk/gtkquery.c               |   15 +++++++--------
 gtk/gtkquery.h               |    6 +++---
 gtk/gtksearchenginesimple.c  |    7 +++----
 gtk/gtksearchenginetracker.c |    8 +++++---
 5 files changed, 19 insertions(+), 22 deletions(-)
---
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index 978608d..4b0a2d7 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -7208,10 +7208,7 @@ search_start_query (GtkFileChooserWidget *impl,
   file = gtk_places_sidebar_get_location (GTK_PLACES_SIDEBAR (priv->places_sidebar));
   if (file)
     {
-      gchar *location;
-      location = g_file_get_uri (file);
-      gtk_query_set_location (priv->search_query, location);
-      g_free (location);
+      gtk_query_set_location (priv->search_query, file);
       g_object_unref (file);
     }
 
diff --git a/gtk/gtkquery.c b/gtk/gtkquery.c
index bc81b7d..d7eca90 100644
--- a/gtk/gtkquery.c
+++ b/gtk/gtkquery.c
@@ -27,7 +27,7 @@
 struct _GtkQueryPrivate
 {
   gchar *text;
-  gchar *location_uri;
+  GFile *location;
   GList *mime_types;
   gchar **words;
 };
@@ -41,8 +41,8 @@ finalize (GObject *object)
 
   query = GTK_QUERY (object);
 
+  g_clear_object (&query->priv->location);
   g_free (query->priv->text);
-  g_free (query->priv->location_uri);
   g_strfreev (query->priv->words);
 
   G_OBJECT_CLASS (gtk_query_parent_class)->finalize (object);
@@ -87,18 +87,17 @@ gtk_query_set_text (GtkQuery    *query,
   query->priv->words = NULL;
 }
 
-const gchar *
+GFile *
 gtk_query_get_location (GtkQuery *query)
 {
-  return query->priv->location_uri;
+  return query->priv->location;
 }
 
 void
-gtk_query_set_location (GtkQuery    *query,
-                        const gchar *uri)
+gtk_query_set_location (GtkQuery *query,
+                        GFile    *file)
 {
-  g_free (query->priv->location_uri);
-  query->priv->location_uri = g_strdup (uri);
+  g_set_object (&query->priv->location, file);
 }
 
 static gchar *
diff --git a/gtk/gtkquery.h b/gtk/gtkquery.h
index 5027505..0aa5ff9 100644
--- a/gtk/gtkquery.h
+++ b/gtk/gtkquery.h
@@ -22,7 +22,7 @@
 #ifndef __GTK_QUERY_H__
 #define __GTK_QUERY_H__
 
-#include <glib-object.h>
+#include <gio/gio.h>
 
 G_BEGIN_DECLS
 
@@ -57,9 +57,9 @@ const gchar *gtk_query_get_text       (GtkQuery    *query);
 void         gtk_query_set_text       (GtkQuery    *query,
                                        const gchar *text);
 
-const gchar *gtk_query_get_location   (GtkQuery    *query);
+GFile       *gtk_query_get_location   (GtkQuery    *query);
 void         gtk_query_set_location   (GtkQuery    *query,
-                                       const gchar *uri);
+                                       GFile       *file);
 
 gboolean     gtk_query_matches_string (GtkQuery    *query,
                                        const gchar *string);
diff --git a/gtk/gtksearchenginesimple.c b/gtk/gtksearchenginesimple.c
index def577a..d61bb30 100644
--- a/gtk/gtksearchenginesimple.c
+++ b/gtk/gtksearchenginesimple.c
@@ -92,7 +92,6 @@ search_thread_data_new (GtkSearchEngineSimple *engine,
                        GtkQuery              *query)
 {
   SearchThreadData *data;
-  const gchar *uri;
   GFile *location;
 
   data = g_new0 (SearchThreadData, 1);
@@ -101,9 +100,9 @@ search_thread_data_new (GtkSearchEngineSimple *engine,
   data->directories = g_queue_new ();
   data->query = g_object_ref (query);
   data->recursive = _gtk_search_engine_get_recursive (GTK_SEARCH_ENGINE (engine));
-  uri = gtk_query_get_location (query);
-  if (uri != NULL)
-    location = g_file_new_for_uri (uri);
+  location = gtk_query_get_location (query);
+  if (location)
+    g_object_ref (location);
   else
     location = g_file_new_for_path (g_get_home_dir ());
   g_queue_push_tail (data->directories, location);
diff --git a/gtk/gtksearchenginetracker.c b/gtk/gtksearchenginetracker.c
index 29edb7f..7c4e063 100644
--- a/gtk/gtksearchenginetracker.c
+++ b/gtk/gtksearchenginetracker.c
@@ -321,7 +321,7 @@ gtk_search_engine_tracker_start (GtkSearchEngine *engine)
 {
   GtkSearchEngineTracker *tracker;
   const gchar *search_text;
-  const gchar *location_uri;
+  GFile *location;
   GString *sparql;
   gboolean recursive;
 
@@ -340,7 +340,7 @@ gtk_search_engine_tracker_start (GtkSearchEngine *engine)
     }
 
   search_text = gtk_query_get_text (tracker->query);
-  location_uri = gtk_query_get_location (tracker->query);
+  location = gtk_query_get_location (tracker->query);
   recursive = _gtk_search_engine_get_recursive (engine);
 
   sparql = g_string_new ("SELECT nie:url(?urn) "
@@ -360,8 +360,9 @@ gtk_search_engine_tracker_start (GtkSearchEngine *engine)
   sparql_append_string_literal_lower_case (sparql, search_text);
   g_string_append (sparql, ")");
 
-  if (location_uri)
+  if (location)
     {
+      gchar *location_uri = g_file_get_uri (location);
       g_string_append (sparql, " && ");
       if (recursive)
         g_string_append (sparql, "tracker:uri-is-descendant(");
@@ -369,6 +370,7 @@ gtk_search_engine_tracker_start (GtkSearchEngine *engine)
         g_string_append (sparql, "tracker:uri-is-parent(");
       sparql_append_string_literal (sparql, location_uri, FALSE);
       g_string_append (sparql, ",nie:url(?urn))");
+      g_free (location_uri);
     }
 
   g_string_append (sparql, ")");


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