mirror of
https://gitlab.gnome.org/GNOME/nautilus
synced 2024-11-05 16:04:31 +00:00
ff6ccbaf40
It was working as: - Search directory starts a new search - Search engine starts all search providers, each one in its own thread. - User changes query - Search engine stops all search providers - Searchs providers, since they are in its own thread, cancel in a unknown time. - Search directory starts a new search, even before all providers are finished. - Search engine is marked as need to restart. - Search providers finished. - Search engine emits finished signal, since all search providers now are stopped. - Clients doesn't have a way to know if the engine actually finished searching the current search, or the previous search that the client asked to stop. That might confuse clients if they ask for results. - Search engine restart the search providers without noticing the client, that thinks that the latest search it started was finished already. So to fix this confusion, only report that the engine actually finished if the engine is not going to restart the search providers. In this way a client can start a batch of consecutive searches without the risk of getting search finished signals from previous searches. Clients now will always get the search-finished signal of the latest search they started.
59 lines
1.6 KiB
C
59 lines
1.6 KiB
C
#include <libnautilus-private/nautilus-search-provider.h>
|
|
#include <libnautilus-private/nautilus-search-engine.h>
|
|
#include <gtk/gtk.h>
|
|
|
|
static void
|
|
hits_added_cb (NautilusSearchEngine *engine, GSList *hits)
|
|
{
|
|
g_print ("hits added\n");
|
|
while (hits) {
|
|
g_print (" - %s\n", (char *)hits->data);
|
|
hits = hits->next;
|
|
}
|
|
}
|
|
|
|
static void
|
|
finished_cb (NautilusSearchEngine *engine,
|
|
NautilusSearchProviderStatus status)
|
|
{
|
|
g_print ("finished!\n");
|
|
gtk_main_quit ();
|
|
}
|
|
|
|
int
|
|
main (int argc, char* argv[])
|
|
{
|
|
NautilusSearchEngine *engine;
|
|
NautilusSearchEngineModel *model;
|
|
NautilusDirectory *directory;
|
|
NautilusQuery *query;
|
|
GFile *location;
|
|
|
|
gtk_init (&argc, &argv);
|
|
|
|
engine = nautilus_search_engine_new ();
|
|
g_signal_connect (engine, "hits-added",
|
|
G_CALLBACK (hits_added_cb), NULL);
|
|
g_signal_connect (engine, "finished",
|
|
G_CALLBACK (finished_cb), NULL);
|
|
|
|
query = nautilus_query_new ();
|
|
nautilus_query_set_text (query, "richard hult");
|
|
nautilus_search_provider_set_query (NAUTILUS_SEARCH_PROVIDER (engine), query);
|
|
g_object_unref (query);
|
|
|
|
location = g_file_new_for_path (g_get_home_dir ());
|
|
directory = nautilus_directory_get (location);
|
|
g_object_unref (location);
|
|
|
|
model = nautilus_search_engine_get_model_provider (engine);
|
|
nautilus_search_engine_model_set_model (model, directory);
|
|
g_object_unref (directory);
|
|
|
|
nautilus_search_provider_start (NAUTILUS_SEARCH_PROVIDER (engine));
|
|
nautilus_search_provider_stop (NAUTILUS_SEARCH_PROVIDER (engine));
|
|
g_object_unref (engine);
|
|
|
|
gtk_main ();
|
|
return 0;
|
|
}
|