[nautilus/wip/gbsneto/search-popover: 1/8] query: make NautilusQuery a final class



commit 9e3357260448071026260b68bf1db358cc5d9488
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Oct 2 21:45:08 2015 -0300

    query: make NautilusQuery a final class
    
    NautilusQuery handle all the necessary data
    to perform searches throughout directories.
    
    Currently, there is no NautilusQuery subclass
    in Nautilus code, and - since it's inside
    libnautilus-private - there is no way to subclass
    it.
    
    This commit updates NautilusQuery code be a final
    class.

 libnautilus-private/nautilus-query.c |   64 ++++++++++++++++------------------
 libnautilus-private/nautilus-query.h |   18 +---------
 2 files changed, 31 insertions(+), 51 deletions(-)
---
diff --git a/libnautilus-private/nautilus-query.c b/libnautilus-private/nautilus-query.c
index fb7bd48..285bbfe 100644
--- a/libnautilus-private/nautilus-query.c
+++ b/libnautilus-private/nautilus-query.c
@@ -29,7 +29,7 @@
 #include "nautilus-file-utilities.h"
 #include "nautilus-query.h"
 
-struct NautilusQueryDetails {
+struct _NautilusQuery {
        char *text;
        char *location_uri;
        GList *mime_types;
@@ -49,9 +49,10 @@ finalize (GObject *object)
        NautilusQuery *query;
 
        query = NAUTILUS_QUERY (object);
-       g_free (query->details->text);
-       g_strfreev (query->details->prepared_words);
-       g_free (query->details->location_uri);
+
+        g_free (query->text);
+        g_strfreev (query->prepared_words);
+        g_free (query->location_uri);
 
        G_OBJECT_CLASS (nautilus_query_parent_class)->finalize (object);
 }
@@ -63,17 +64,13 @@ nautilus_query_class_init (NautilusQueryClass *class)
 
        gobject_class = G_OBJECT_CLASS (class);
        gobject_class->finalize = finalize;
-
-       g_type_class_add_private (class, sizeof (NautilusQueryDetails));
 }
 
 static void
 nautilus_query_init (NautilusQuery *query)
 {
-       query->details = G_TYPE_INSTANCE_GET_PRIVATE (query, NAUTILUS_TYPE_QUERY,
-                                                     NautilusQueryDetails);
-       query->details->show_hidden = TRUE;
-       query->details->location_uri = nautilus_get_home_directory_uri ();
+        query->show_hidden = TRUE;
+        query->location_uri = nautilus_get_home_directory_uri ();
 }
 
 static gchar *
@@ -97,13 +94,13 @@ nautilus_query_matches_string (NautilusQuery *query,
        gdouble retval;
        gint idx, nonexact_malus;
 
-       if (!query->details->text) {
+        if (!query->text) {
                return -1;
        }
 
-       if (!query->details->prepared_words) {
-               prepared_string = prepare_string_for_compare (query->details->text);
-               query->details->prepared_words = g_strsplit (prepared_string, " ", -1);
+        if (!query->prepared_words) {
+                prepared_string = prepare_string_for_compare (query->text);
+                query->prepared_words = g_strsplit (prepared_string, " ", -1);
                g_free (prepared_string);
        }
 
@@ -112,13 +109,13 @@ nautilus_query_matches_string (NautilusQuery *query,
        ptr = NULL;
        nonexact_malus = 0;
 
-       for (idx = 0; query->details->prepared_words[idx] != NULL; idx++) {
-               if ((ptr = strstr (prepared_string, query->details->prepared_words[idx])) == NULL) {
+        for (idx = 0; query->prepared_words[idx] != NULL; idx++) {
+                if ((ptr = strstr (prepared_string, query->prepared_words[idx])) == NULL) {
                        found = FALSE;
                        break;
                }
 
-               nonexact_malus += strlen (ptr) - strlen (query->details->prepared_words[idx]);
+                nonexact_malus += strlen (ptr) - strlen (query->prepared_words[idx]);
        }
 
        if (!found) {
@@ -142,70 +139,69 @@ nautilus_query_new (void)
 char *
 nautilus_query_get_text (NautilusQuery *query)
 {
-       return g_strdup (query->details->text);
+        return g_strdup (query->text);
 }
 
 void 
 nautilus_query_set_text (NautilusQuery *query, const char *text)
 {
-       g_free (query->details->text);
-       query->details->text = g_strstrip (g_strdup (text));
+        g_free (query->text);
+        query->text = g_strstrip (g_strdup (text));
 
-       g_strfreev (query->details->prepared_words);
-       query->details->prepared_words = NULL;
+        g_strfreev (query->prepared_words);
+        query->prepared_words = NULL;
 }
 
 char *
 nautilus_query_get_location (NautilusQuery *query)
 {
-       return g_strdup (query->details->location_uri);
+        return g_strdup (query->location_uri);
 }
        
 void
 nautilus_query_set_location (NautilusQuery *query, const char *uri)
 {
-       g_free (query->details->location_uri);
-       query->details->location_uri = g_strdup (uri);
+        g_free (query->location_uri);
+        query->location_uri = g_strdup (uri);
 }
 
 GList *
 nautilus_query_get_mime_types (NautilusQuery *query)
 {
-       return g_list_copy_deep (query->details->mime_types, (GCopyFunc) g_strdup, NULL);
+        return g_list_copy_deep (query->mime_types, (GCopyFunc) g_strdup, NULL);
 }
 
 void
 nautilus_query_set_mime_types (NautilusQuery *query, GList *mime_types)
 {
-       g_list_free_full (query->details->mime_types, g_free);
-       query->details->mime_types = g_list_copy_deep (mime_types, (GCopyFunc) g_strdup, NULL);
+        g_list_free_full (query->mime_types, g_free);
+        query->mime_types = g_list_copy_deep (mime_types, (GCopyFunc) g_strdup, NULL);
 }
 
 void
 nautilus_query_add_mime_type (NautilusQuery *query, const char *mime_type)
 {
-       query->details->mime_types = g_list_append (query->details->mime_types,
-                                                   g_strdup (mime_type));
+        query->mime_types = g_list_append (query->mime_types, g_strdup (mime_type));
 }
 
 gboolean
 nautilus_query_get_show_hidden_files (NautilusQuery *query)
 {
-       return query->details->show_hidden;
+        return query->show_hidden;
 }
 
 void
 nautilus_query_set_show_hidden_files (NautilusQuery *query, gboolean show_hidden)
 {
-       query->details->show_hidden = show_hidden;
+        query->show_hidden = show_hidden;
 }
 
 char *
 nautilus_query_to_readable_string (NautilusQuery *query)
 {
-       if (!query || !query->details->text || query->details->text[0] == '\0') {
+        if (!query || !query->text || query->text[0] == '\0') {
                return g_strdup (_("Search"));
        }
 
-       return g_strdup_printf (_("Search for ā€œ%sā€"), query->details->text);
+        return g_strdup_printf (_("Search for ā€œ%sā€"), query->text);
 }
diff --git a/libnautilus-private/nautilus-query.h b/libnautilus-private/nautilus-query.h
index 9ceffe8..df3e473 100644
--- a/libnautilus-private/nautilus-query.h
+++ b/libnautilus-private/nautilus-query.h
@@ -26,24 +26,8 @@
 #include <glib-object.h>
 
 #define NAUTILUS_TYPE_QUERY            (nautilus_query_get_type ())
-#define NAUTILUS_QUERY(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), NAUTILUS_TYPE_QUERY, 
NautilusQuery))
-#define NAUTILUS_QUERY_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_QUERY, 
NautilusQueryClass))
-#define NAUTILUS_IS_QUERY(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NAUTILUS_TYPE_QUERY))
-#define NAUTILUS_IS_QUERY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_QUERY))
-#define NAUTILUS_QUERY_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), NAUTILUS_TYPE_QUERY, 
NautilusQueryClass))
 
-typedef struct NautilusQueryDetails NautilusQueryDetails;
-
-typedef struct NautilusQuery {
-       GObject parent;
-       NautilusQueryDetails *details;
-} NautilusQuery;
-
-typedef struct {
-       GObjectClass parent_class;
-} NautilusQueryClass;
-
-GType          nautilus_query_get_type (void);
+G_DECLARE_FINAL_TYPE (NautilusQuery, nautilus_query, NAUTILUS, QUERY, GObject)
 
 NautilusQuery* nautilus_query_new      (void);
 


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