From 79c8a16b8d293a7a52e55ff0a5d165607e591bd8 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 31 Jan 2020 16:52:03 +0100 Subject: [PATCH] Remove simple search engine --- gtk/gtksearchengine.c | 47 +---- gtk/gtksearchenginesimple.c | 386 ------------------------------------ gtk/gtksearchenginesimple.h | 52 ----- gtk/meson.build | 1 - 4 files changed, 1 insertion(+), 485 deletions(-) delete mode 100644 gtk/gtksearchenginesimple.c delete mode 100644 gtk/gtksearchenginesimple.h diff --git a/gtk/gtksearchengine.c b/gtk/gtksearchengine.c index 74496c9695..3f7ba58a3a 100644 --- a/gtk/gtksearchengine.c +++ b/gtk/gtksearchengine.c @@ -21,7 +21,6 @@ #include "config.h" #include "gtksearchengine.h" -#include "gtksearchenginesimple.h" #include "gtksearchenginetracker.h" #include "gtksearchenginemodel.h" #include "gtksearchenginequartz.h" @@ -38,10 +37,6 @@ struct _GtkSearchEnginePrivate { gboolean native_running; gchar *native_error; - GtkSearchEngine *simple; - gboolean simple_running; - gchar *simple_error; - GtkSearchEngine *model; gboolean model_running; gchar *model_error; @@ -74,9 +69,6 @@ set_query (GtkSearchEngine *engine, if (engine->priv->native) _gtk_search_engine_set_query (engine->priv->native, query); - if (engine->priv->simple) - _gtk_search_engine_set_query (engine->priv->simple, query); - if (engine->priv->model) _gtk_search_engine_set_query (engine->priv->model, query); } @@ -93,13 +85,6 @@ start (GtkSearchEngine *engine) engine->priv->native_running = TRUE; } - if (engine->priv->simple) - { - g_clear_pointer (&engine->priv->simple_error, g_free); - _gtk_search_engine_start (engine->priv->simple); - engine->priv->simple_running = TRUE; - } - if (engine->priv->model) { g_clear_pointer (&engine->priv->model_error, g_free); @@ -119,12 +104,6 @@ stop (GtkSearchEngine *engine) engine->priv->native_running = FALSE; } - if (engine->priv->simple) - { - _gtk_search_engine_stop (engine->priv->simple); - engine->priv->simple_running = FALSE; - } - if (engine->priv->model) { _gtk_search_engine_stop (engine->priv->model); @@ -144,9 +123,6 @@ finalize (GObject *object) g_clear_object (&engine->priv->native); g_free (engine->priv->native_error); - g_clear_object (&engine->priv->simple); - g_free (engine->priv->simple_error); - g_clear_object (&engine->priv->model); g_free (engine->priv->model_error); @@ -241,7 +217,7 @@ update_status (GtkSearchEngine *engine) { gboolean running; - running = engine->priv->native_running || engine->priv->simple_running; + running = engine->priv->native_running; if (running != engine->priv->running) { @@ -251,8 +227,6 @@ update_status (GtkSearchEngine *engine) { if (engine->priv->native_error) _gtk_search_engine_error (engine, engine->priv->native_error); - else if (engine->priv->simple_error) - _gtk_search_engine_error (engine, engine->priv->simple_error); else if (engine->priv->model_error) _gtk_search_engine_error (engine, engine->priv->model_error); else @@ -269,8 +243,6 @@ finished (GtkSearchEngine *engine, if (engine == composite->priv->native) composite->priv->native_running = FALSE; - else if (engine == composite->priv->simple) - composite->priv->simple_running = FALSE; else if (engine == composite->priv->model) composite->priv->model_running = FALSE; @@ -290,12 +262,6 @@ error (GtkSearchEngine *engine, composite->priv->native_error = g_strdup (message); composite->priv->native_running = FALSE; } - else if (engine == composite->priv->simple) - { - g_free (composite->priv->simple_error); - composite->priv->simple_error = g_strdup (message); - composite->priv->simple_running = FALSE; - } else if (engine == composite->priv->model) { g_free (composite->priv->model_error); @@ -363,20 +329,12 @@ _gtk_search_engine_new (void) engine = g_object_new (GTK_TYPE_SEARCH_ENGINE, NULL); - engine->priv->simple = _gtk_search_engine_simple_new (); - g_debug ("Using simple search engine"); - connect_engine_signals (engine->priv->simple, engine); - #ifdef HAVE_TRACKER engine->priv->native = _gtk_search_engine_tracker_new (); if (engine->priv->native) { g_debug ("Using Tracker search engine"); connect_engine_signals (engine->priv->native, engine); - _gtk_search_engine_simple_set_indexed_cb (GTK_SEARCH_ENGINE_SIMPLE (engine->priv->simple), - _gtk_search_engine_tracker_is_indexed, - g_object_ref (engine->priv->native), - g_object_unref); } #endif @@ -461,9 +419,6 @@ _gtk_search_engine_set_recursive (GtkSearchEngine *engine, if (engine->priv->native) _gtk_search_engine_set_recursive (engine->priv->native, recursive); - - if (engine->priv->simple) - _gtk_search_engine_set_recursive (engine->priv->simple, recursive); } gboolean diff --git a/gtk/gtksearchenginesimple.c b/gtk/gtksearchenginesimple.c deleted file mode 100644 index dfefed3aca..0000000000 --- a/gtk/gtksearchenginesimple.c +++ /dev/null @@ -1,386 +0,0 @@ -/* - * Copyright (C) 2005 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * Author: Alexander Larsson - * - * Based on nautilus-search-engine-simple.c - */ - -#include "config.h" - -#include - -#include - -#include "gtksearchenginesimple.h" -#include "gtkfilesystem.h" -#include "gtkprivate.h" - -#include - -#define BATCH_SIZE 500 - -typedef struct -{ - GtkSearchEngineSimple *engine; - GCancellable *cancellable; - - GQueue *directories; - - gint n_processed_files; - GList *hits; - - GtkQuery *query; - gboolean recursive; -} SearchThreadData; - - -struct _GtkSearchEngineSimple -{ - GtkSearchEngine parent; - - GtkQuery *query; - - SearchThreadData *active_search; - - gboolean query_finished; - - GtkSearchEngineSimpleIsIndexed is_indexed_callback; - gpointer is_indexed_data; - GDestroyNotify is_indexed_data_destroy; -}; - -struct _GtkSearchEngineSimpleClass -{ - GtkSearchEngineClass parent_class; -}; - -G_DEFINE_TYPE (GtkSearchEngineSimple, _gtk_search_engine_simple, GTK_TYPE_SEARCH_ENGINE) - -static void -gtk_search_engine_simple_dispose (GObject *object) -{ - GtkSearchEngineSimple *simple = GTK_SEARCH_ENGINE_SIMPLE (object); - - g_clear_object (&simple->query); - - if (simple->active_search) - { - g_cancellable_cancel (simple->active_search->cancellable); - simple->active_search = NULL; - } - - _gtk_search_engine_simple_set_indexed_cb (simple, NULL, NULL, NULL); - - G_OBJECT_CLASS (_gtk_search_engine_simple_parent_class)->dispose (object); -} - -static void -queue_if_local (SearchThreadData *data, - GFile *file) -{ - if (file && - !_gtk_file_consider_as_remote (file) && - !g_file_has_uri_scheme (file, "recent")) - g_queue_push_tail (data->directories, g_object_ref (file)); -} - -static SearchThreadData * -search_thread_data_new (GtkSearchEngineSimple *engine, - GtkQuery *query) -{ - SearchThreadData *data; - - data = g_new0 (SearchThreadData, 1); - - data->engine = g_object_ref (engine); - data->directories = g_queue_new (); - data->query = g_object_ref (query); - data->recursive = _gtk_search_engine_get_recursive (GTK_SEARCH_ENGINE (engine)); - queue_if_local (data, gtk_query_get_location (query)); - - data->cancellable = g_cancellable_new (); - - return data; -} - -static void -search_thread_data_free (SearchThreadData *data) -{ - g_queue_foreach (data->directories, (GFunc)g_object_unref, NULL); - g_queue_free (data->directories); - g_object_unref (data->cancellable); - g_object_unref (data->query); - g_object_unref (data->engine); - - g_free (data); -} - -static gboolean -search_thread_done_idle (gpointer user_data) -{ - SearchThreadData *data; - - data = user_data; - - if (!g_cancellable_is_cancelled (data->cancellable)) - _gtk_search_engine_finished (GTK_SEARCH_ENGINE (data->engine)); - - data->engine->active_search = NULL; - search_thread_data_free (data); - - return FALSE; -} - -typedef struct -{ - GList *hits; - SearchThreadData *thread_data; -} Batch; - -static gboolean -search_thread_add_hits_idle (gpointer user_data) -{ - Batch *batch = user_data; - - if (!g_cancellable_is_cancelled (batch->thread_data->cancellable)) - _gtk_search_engine_hits_added (GTK_SEARCH_ENGINE (batch->thread_data->engine), batch->hits); - - g_list_free_full (batch->hits, (GDestroyNotify)_gtk_search_hit_free); - g_free (batch); - - return FALSE; -} - -static void -send_batch (SearchThreadData *data) -{ - Batch *batch; - - data->n_processed_files = 0; - - if (data->hits) - { - guint id; - - batch = g_new (Batch, 1); - batch->hits = data->hits; - batch->thread_data = data; - - id = g_idle_add (search_thread_add_hits_idle, batch); - g_source_set_name_by_id (id, "[gtk] search_thread_add_hits_idle"); - } - - data->hits = NULL; -} - -static gboolean -is_indexed (GtkSearchEngineSimple *engine, - GFile *location) -{ - if (engine->is_indexed_callback) - { - if (engine->is_indexed_callback (location, engine->is_indexed_data)) - { - gchar *uri = g_file_get_uri (location); - g_debug ("Simple search engine: Skipping indexed location: %s\n", uri); - g_free (uri); - - return TRUE; - } - } - - return FALSE; -} - -static void -visit_directory (GFile *dir, SearchThreadData *data) -{ - GFileEnumerator *enumerator; - GFileInfo *info; - GFile *child; - const gchar *display_name; - - enumerator = g_file_enumerate_children (dir, - G_FILE_ATTRIBUTE_STANDARD_NAME "," - G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME "," - G_FILE_ATTRIBUTE_STANDARD_TYPE "," - G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN "," - G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP "," - G_FILE_ATTRIBUTE_STANDARD_SIZE "," - G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," - G_FILE_ATTRIBUTE_STANDARD_TARGET_URI "," - G_FILE_ATTRIBUTE_TIME_MODIFIED "," - G_FILE_ATTRIBUTE_TIME_ACCESS "," - G_FILE_ATTRIBUTE_ACCESS_CAN_RENAME "," - G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH "," - G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - data->cancellable, NULL); - if (enumerator == NULL) - return; - - while (g_file_enumerator_iterate (enumerator, &info, &child, data->cancellable, NULL)) - { - if (info == NULL) - break; - - display_name = g_file_info_get_display_name (info); - if (display_name == NULL) - continue; - - if (g_file_info_get_is_hidden (info)) - continue; - - if (gtk_query_matches_string (data->query, display_name)) - { - GtkSearchHit *hit; - - hit = g_new (GtkSearchHit, 1); - hit->file = g_object_ref (child); - hit->info = g_object_ref (info); - data->hits = g_list_prepend (data->hits, hit); - } - - data->n_processed_files++; - if (data->n_processed_files > BATCH_SIZE) - send_batch (data); - - if (data->recursive && - g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY && - !is_indexed (data->engine, child)) - queue_if_local (data, child); - } - - g_object_unref (enumerator); -} - -static gpointer -search_thread_func (gpointer user_data) -{ - SearchThreadData *data; - GFile *dir; - guint id; - - data = user_data; - - while (!g_cancellable_is_cancelled (data->cancellable) && - (dir = g_queue_pop_head (data->directories)) != NULL) - { - visit_directory (dir, data); - g_object_unref (dir); - } - - if (!g_cancellable_is_cancelled (data->cancellable)) - send_batch (data); - - id = g_idle_add (search_thread_done_idle, data); - g_source_set_name_by_id (id, "[gtk] search_thread_done_idle"); - - return NULL; -} - -static void -gtk_search_engine_simple_start (GtkSearchEngine *engine) -{ - GtkSearchEngineSimple *simple; - SearchThreadData *data; - - simple = GTK_SEARCH_ENGINE_SIMPLE (engine); - - if (simple->active_search != NULL) - return; - - if (simple->query == NULL) - return; - - data = search_thread_data_new (simple, simple->query); - - g_thread_unref (g_thread_new ("file-search", search_thread_func, data)); - - simple->active_search = data; -} - -static void -gtk_search_engine_simple_stop (GtkSearchEngine *engine) -{ - GtkSearchEngineSimple *simple; - - simple = GTK_SEARCH_ENGINE_SIMPLE (engine); - - if (simple->active_search != NULL) - { - g_cancellable_cancel (simple->active_search->cancellable); - simple->active_search = NULL; - } -} - -static void -gtk_search_engine_simple_set_query (GtkSearchEngine *engine, - GtkQuery *query) -{ - GtkSearchEngineSimple *simple; - - simple = GTK_SEARCH_ENGINE_SIMPLE (engine); - - if (query) - g_object_ref (query); - - if (simple->query) - g_object_unref (simple->query); - - simple->query = query; -} - -static void -_gtk_search_engine_simple_class_init (GtkSearchEngineSimpleClass *class) -{ - GObjectClass *gobject_class; - GtkSearchEngineClass *engine_class; - - gobject_class = G_OBJECT_CLASS (class); - gobject_class->dispose = gtk_search_engine_simple_dispose; - - engine_class = GTK_SEARCH_ENGINE_CLASS (class); - engine_class->set_query = gtk_search_engine_simple_set_query; - engine_class->start = gtk_search_engine_simple_start; - engine_class->stop = gtk_search_engine_simple_stop; -} - -static void -_gtk_search_engine_simple_init (GtkSearchEngineSimple *engine) -{ -} - -GtkSearchEngine * -_gtk_search_engine_simple_new (void) -{ - return g_object_new (GTK_TYPE_SEARCH_ENGINE_SIMPLE, NULL); -} - -void -_gtk_search_engine_simple_set_indexed_cb (GtkSearchEngineSimple *engine, - GtkSearchEngineSimpleIsIndexed callback, - gpointer data, - GDestroyNotify destroy) -{ - if (engine->is_indexed_data_destroy) - engine->is_indexed_data_destroy (engine->is_indexed_data); - - engine->is_indexed_callback = callback; - engine->is_indexed_data = data; - engine->is_indexed_data_destroy = destroy; -} diff --git a/gtk/gtksearchenginesimple.h b/gtk/gtksearchenginesimple.h deleted file mode 100644 index 08efcc9cc6..0000000000 --- a/gtk/gtksearchenginesimple.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2005 Red Hat, Inc - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - * - * Author: Alexander Larsson - * - * Based on nautilus-search-engine-simple.h - */ - -#ifndef __GTK_SEARCH_ENGINE_SIMPLE_H__ -#define __GTK_SEARCH_ENGINE_SIMPLE_H__ - -#include "gtksearchengine.h" - -G_BEGIN_DECLS - -#define GTK_TYPE_SEARCH_ENGINE_SIMPLE (_gtk_search_engine_simple_get_type ()) -#define GTK_SEARCH_ENGINE_SIMPLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_SEARCH_ENGINE_SIMPLE, GtkSearchEngineSimple)) -#define GTK_SEARCH_ENGINE_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_SEARCH_ENGINE_SIMPLE, GtkSearchEngineSimpleClass)) -#define GTK_IS_SEARCH_ENGINE_SIMPLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_SEARCH_ENGINE_SIMPLE)) -#define GTK_IS_SEARCH_ENGINE_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_SEARCH_ENGINE_SIMPLE)) -#define GTK_SEARCH_ENGINE_SIMPLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_SEARCH_ENGINE_SIMPLE, GtkSearchEngineSimpleClass)) - -typedef struct _GtkSearchEngineSimple GtkSearchEngineSimple; -typedef struct _GtkSearchEngineSimpleClass GtkSearchEngineSimpleClass; - -GType _gtk_search_engine_simple_get_type (void); - -GtkSearchEngine* _gtk_search_engine_simple_new (void); - -typedef gboolean (*GtkSearchEngineSimpleIsIndexed) (GFile *location, gpointer data); - -void _gtk_search_engine_simple_set_indexed_cb (GtkSearchEngineSimple *engine, - GtkSearchEngineSimpleIsIndexed callback, - gpointer data, - GDestroyNotify destroy); - -G_END_DECLS - -#endif /* __GTK_SEARCH_ENGINE_SIMPLE_H__ */ diff --git a/gtk/meson.build b/gtk/meson.build index 17156b001a..bd162d1be5 100644 --- a/gtk/meson.build +++ b/gtk/meson.build @@ -134,7 +134,6 @@ gtk_private_sources = files([ 'gtkscaler.c', 'gtksearchengine.c', 'gtksearchenginemodel.c', - 'gtksearchenginesimple.c', 'gtksizerequestcache.c', 'gtkstyleanimation.c', 'gtkstylecascade.c',