query: Remove private pointer

This commit is contained in:
Timm Bäder 2019-05-15 17:53:18 +02:00
parent d53d7eb9e7
commit 7793818f2a
2 changed files with 28 additions and 20 deletions

View File

@ -37,13 +37,15 @@ G_DEFINE_TYPE_WITH_PRIVATE (GtkQuery, gtk_query, G_TYPE_OBJECT)
static void static void
finalize (GObject *object) finalize (GObject *object)
{ {
GtkQuery *query; GtkQuery *query = GTK_QUERY (object);
GtkQueryPrivate *priv = gtk_query_get_instance_private (query);
query = GTK_QUERY (object); query = GTK_QUERY (object);
g_clear_object (&query->priv->location); g_clear_object (&priv->location);
g_free (query->priv->text); g_free (priv->text);
g_strfreev (query->priv->words); g_strfreev (priv->words);
G_OBJECT_CLASS (gtk_query_parent_class)->finalize (object); G_OBJECT_CLASS (gtk_query_parent_class)->finalize (object);
} }
@ -60,7 +62,6 @@ gtk_query_class_init (GtkQueryClass *class)
static void static void
gtk_query_init (GtkQuery *query) gtk_query_init (GtkQuery *query)
{ {
query->priv = gtk_query_get_instance_private (query);
} }
GtkQuery * GtkQuery *
@ -73,31 +74,39 @@ gtk_query_new (void)
const gchar * const gchar *
gtk_query_get_text (GtkQuery *query) gtk_query_get_text (GtkQuery *query)
{ {
return query->priv->text; GtkQueryPrivate *priv = gtk_query_get_instance_private (query);
return priv->text;
} }
void void
gtk_query_set_text (GtkQuery *query, gtk_query_set_text (GtkQuery *query,
const gchar *text) const gchar *text)
{ {
g_free (query->priv->text); GtkQueryPrivate *priv = gtk_query_get_instance_private (query);
query->priv->text = g_strdup (text);
g_strfreev (query->priv->words); g_free (priv->text);
query->priv->words = NULL; priv->text = g_strdup (text);
g_strfreev (priv->words);
priv->words = NULL;
} }
GFile * GFile *
gtk_query_get_location (GtkQuery *query) gtk_query_get_location (GtkQuery *query)
{ {
return query->priv->location; GtkQueryPrivate *priv = gtk_query_get_instance_private (query);
return priv->location;
} }
void void
gtk_query_set_location (GtkQuery *query, gtk_query_set_location (GtkQuery *query,
GFile *file) GFile *file)
{ {
g_set_object (&query->priv->location, file); GtkQueryPrivate *priv = gtk_query_get_instance_private (query);
g_set_object (&priv->location, file);
} }
static gchar * static gchar *
@ -116,26 +125,27 @@ gboolean
gtk_query_matches_string (GtkQuery *query, gtk_query_matches_string (GtkQuery *query,
const gchar *string) const gchar *string)
{ {
GtkQueryPrivate *priv = gtk_query_get_instance_private (query);
gchar *prepared; gchar *prepared;
gboolean found; gboolean found;
gint i; gint i;
if (!query->priv->text) if (!priv->text)
return FALSE; return FALSE;
if (!query->priv->words) if (!priv->words)
{ {
prepared = prepare_string_for_compare (query->priv->text); prepared = prepare_string_for_compare (priv->text);
query->priv->words = g_strsplit (prepared, " ", -1); priv->words = g_strsplit (prepared, " ", -1);
g_free (prepared); g_free (prepared);
} }
prepared = prepare_string_for_compare (string); prepared = prepare_string_for_compare (string);
found = TRUE; found = TRUE;
for (i = 0; query->priv->words[i]; i++) for (i = 0; priv->words[i]; i++)
{ {
if (strstr (prepared, query->priv->words[i]) == NULL) if (strstr (prepared, priv->words[i]) == NULL)
{ {
found = FALSE; found = FALSE;
break; break;

View File

@ -40,8 +40,6 @@ typedef struct _GtkQueryPrivate GtkQueryPrivate;
struct _GtkQuery struct _GtkQuery
{ {
GObject parent; GObject parent;
GtkQueryPrivate *priv;
}; };
struct _GtkQueryClass struct _GtkQueryClass