summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nautilus-search-directory.c9
-rw-r--r--src/nautilus-search-engine-model.c18
-rw-r--r--src/nautilus-search-engine-model.h1
-rw-r--r--src/nautilus-search-engine-simple.c11
-rw-r--r--src/nautilus-search-engine-tracker.c12
-rw-r--r--src/nautilus-search-engine.c232
-rw-r--r--src/nautilus-search-engine.h10
-rw-r--r--src/nautilus-search-provider.c9
-rw-r--r--src/nautilus-search-provider.h2
-rw-r--r--test/test-nautilus-search-engine.c4
10 files changed, 88 insertions, 220 deletions
diff --git a/src/nautilus-search-directory.c b/src/nautilus-search-directory.c
index ab3debd10..6692a41f0 100644
--- a/src/nautilus-search-directory.c
+++ b/src/nautilus-search-directory.c
@@ -173,6 +173,8 @@ set_hidden_files (NautilusSearchDirectory *search)
static void
start_search (NautilusSearchDirectory *search)
{
+ NautilusSearchEngineModel *model_provider;
+ NautilusSearchEngineSimple *simple_provider;
gboolean recursive;
if (!search->details->query)
@@ -198,11 +200,12 @@ start_search (NautilusSearchDirectory *search)
nautilus_search_provider_set_query (NAUTILUS_SEARCH_PROVIDER (search->details->engine),
search->details->query);
- nautilus_search_engine_set_model (search->details->engine,
- search->details->base_model);
+ model_provider = nautilus_search_engine_get_model_provider (search->details->engine);
+ nautilus_search_engine_model_set_model (model_provider, search->details->base_model);
+ simple_provider = nautilus_search_engine_get_simple_provider (search->details->engine);
recursive = nautilus_query_get_recursive (search->details->query);
- g_object_set (search->details->engine, "recursive", recursive, NULL);
+ g_object_set (simple_provider, "recursive", recursive, NULL);
reset_file_list (search);
diff --git a/src/nautilus-search-engine-model.c b/src/nautilus-search-engine-model.c
index c77a2c1dc..b8f2a940f 100644
--- a/src/nautilus-search-engine-model.c
+++ b/src/nautilus-search-engine-model.c
@@ -280,17 +280,6 @@ nautilus_search_engine_model_is_running (NautilusSearchProvider *provider)
return model->details->query_pending;
}
-static gboolean
-nautilus_search_engine_model_is_finished (NautilusSearchProvider *provider)
-{
- NautilusSearchEngineModel *model;
-
- model = NAUTILUS_SEARCH_ENGINE_MODEL (provider);
-
- return !model->details->query_pending;
-}
-
-
static void
nautilus_search_provider_init (NautilusSearchProviderInterface *iface)
{
@@ -298,7 +287,6 @@ nautilus_search_provider_init (NautilusSearchProviderInterface *iface)
iface->start = nautilus_search_engine_model_start;
iface->stop = nautilus_search_engine_model_stop;
iface->is_running = nautilus_search_engine_model_is_running;
- iface->is_finished = nautilus_search_engine_model_is_finished;
}
static void
@@ -365,3 +353,9 @@ nautilus_search_engine_model_set_model (NautilusSearchEngineModel *model,
g_clear_object (&model->details->directory);
model->details->directory = nautilus_directory_ref (directory);
}
+
+NautilusDirectory *
+nautilus_search_engine_model_get_model (NautilusSearchEngineModel *model)
+{
+ return model->details->directory;
+}
diff --git a/src/nautilus-search-engine-model.h b/src/nautilus-search-engine-model.h
index 0b6dee30c..16f3388fc 100644
--- a/src/nautilus-search-engine-model.h
+++ b/src/nautilus-search-engine-model.h
@@ -47,5 +47,6 @@ GType nautilus_search_engine_model_get_type (void);
NautilusSearchEngineModel* nautilus_search_engine_model_new (void);
void nautilus_search_engine_model_set_model (NautilusSearchEngineModel *model,
NautilusDirectory *directory);
+NautilusDirectory * nautilus_search_engine_model_get_model (NautilusSearchEngineModel *model);
#endif /* NAUTILUS_SEARCH_ENGINE_MODEL_H */
diff --git a/src/nautilus-search-engine-simple.c b/src/nautilus-search-engine-simple.c
index 1e0549b49..ea2dbe364 100644
--- a/src/nautilus-search-engine-simple.c
+++ b/src/nautilus-search-engine-simple.c
@@ -453,16 +453,6 @@ nautilus_search_engine_simple_is_running (NautilusSearchProvider *provider)
return simple->active_search != NULL;
}
-static gboolean
-nautilus_search_engine_simple_is_finished (NautilusSearchProvider *provider)
-{
- NautilusSearchEngineSimple *simple;
-
- simple = NAUTILUS_SEARCH_ENGINE_SIMPLE (provider);
-
- return simple->active_search == NULL;
-}
-
static void
nautilus_search_engine_simple_set_property (GObject *object,
guint arg_id,
@@ -518,7 +508,6 @@ nautilus_search_provider_init (NautilusSearchProviderInterface *iface)
iface->start = nautilus_search_engine_simple_start;
iface->stop = nautilus_search_engine_simple_stop;
iface->is_running = nautilus_search_engine_simple_is_running;
- iface->is_finished = nautilus_search_engine_simple_is_finished;
}
static void
diff --git a/src/nautilus-search-engine-tracker.c b/src/nautilus-search-engine-tracker.c
index 3ca7f40d5..b868dbf89 100644
--- a/src/nautilus-search-engine-tracker.c
+++ b/src/nautilus-search-engine-tracker.c
@@ -485,17 +485,6 @@ nautilus_search_engine_tracker_is_running (NautilusSearchProvider *provider)
return tracker->details->query_pending;
}
-static gboolean
-nautilus_search_engine_tracker_is_finished (NautilusSearchProvider *provider)
-{
- NautilusSearchEngineTracker *tracker;
-
- tracker = NAUTILUS_SEARCH_ENGINE_TRACKER (provider);
-
- return !tracker->details->query_pending;
-}
-
-
static void
nautilus_search_provider_init (NautilusSearchProviderInterface *iface)
{
@@ -503,7 +492,6 @@ nautilus_search_provider_init (NautilusSearchProviderInterface *iface)
iface->start = nautilus_search_engine_tracker_start;
iface->stop = nautilus_search_engine_tracker_stop;
iface->is_running = nautilus_search_engine_tracker_is_running;
- iface->is_finished = nautilus_search_engine_tracker_is_finished;
}
static void
diff --git a/src/nautilus-search-engine.c b/src/nautilus-search-engine.c
index 64cf6702e..209bd4f80 100644
--- a/src/nautilus-search-engine.c
+++ b/src/nautilus-search-engine.c
@@ -32,23 +32,22 @@
typedef struct
{
- GQueue *providers;
+ NautilusSearchEngineTracker *tracker;
+ NautilusSearchEngineSimple *simple;
+ NautilusSearchEngineModel *model;
GHashTable *uris;
+ guint providers_running;
+ guint providers_finished;
guint providers_error;
gboolean running;
gboolean restart;
-
- NautilusDirectory *directory;
- NautilusQuery *query;
- gboolean recursive;
} NautilusSearchEnginePrivate;
enum
{
PROP_0,
- PROP_RECURSIVE,
PROP_RUNNING,
LAST_PROP
};
@@ -57,12 +56,6 @@ static void nautilus_search_provider_init (NautilusSearchProviderInterface *ifac
static gboolean nautilus_search_engine_is_running (NautilusSearchProvider *provider);
-static void connect_provider_signals (NautilusSearchEngine *engine,
- NautilusSearchProvider *provider);
-
-static void disconnect_provider_signals (NautilusSearchEngine *engine,
- NautilusSearchProvider *provider);
-
G_DEFINE_TYPE_WITH_CODE (NautilusSearchEngine,
nautilus_search_engine,
G_TYPE_OBJECT,
@@ -71,35 +64,6 @@ G_DEFINE_TYPE_WITH_CODE (NautilusSearchEngine,
nautilus_search_provider_init))
static void
-clear_providers_queue (NautilusSearchEngine *engine)
-{
- NautilusSearchEnginePrivate *priv;
- GList *l;
-
- priv = nautilus_search_engine_get_instance_private (engine);
-
- for (l = g_queue_peek_head_link (priv->providers); l != NULL; l = l->next)
- {
- disconnect_provider_signals (engine, NAUTILUS_SEARCH_PROVIDER (l->data));
- g_clear_object (&l->data);
- }
-
- g_queue_clear (priv->providers);
-}
-
-void
-nautilus_search_engine_set_model (NautilusSearchEngine *engine,
- NautilusDirectory *directory)
-{
- NautilusSearchEnginePrivate *priv;
-
- priv = nautilus_search_engine_get_instance_private (engine);
-
- g_clear_object (&priv->directory);
- priv->directory = g_object_ref (directory);
-}
-
-static void
nautilus_search_engine_set_query (NautilusSearchProvider *provider,
NautilusQuery *query)
{
@@ -109,41 +73,20 @@ nautilus_search_engine_set_query (NautilusSearchProvider *provider,
engine = NAUTILUS_SEARCH_ENGINE (provider);
priv = nautilus_search_engine_get_instance_private (engine);
- g_object_ref (query);
- g_clear_object (&priv->query);
- priv->query = query;
+ nautilus_search_provider_set_query (NAUTILUS_SEARCH_PROVIDER (priv->tracker), query);
+ nautilus_search_provider_set_query (NAUTILUS_SEARCH_PROVIDER (priv->model), query);
+ nautilus_search_provider_set_query (NAUTILUS_SEARCH_PROVIDER (priv->simple), query);
}
static void
search_engine_start_real (NautilusSearchEngine *engine)
{
NautilusSearchEnginePrivate *priv;
- NautilusSearchEngineTracker *tracker;
- NautilusSearchEngineSimple *simple;
- NautilusSearchEngineModel *model;
- GList *l;
priv = nautilus_search_engine_get_instance_private (engine);
- clear_providers_queue (engine);
-
- tracker = nautilus_search_engine_tracker_new ();
- g_queue_push_head (priv->providers, tracker);
- connect_provider_signals (engine, NAUTILUS_SEARCH_PROVIDER (tracker));
-
- simple = nautilus_search_engine_simple_new ();
- connect_provider_signals (engine, NAUTILUS_SEARCH_PROVIDER (simple));
- g_object_set (simple, "recursive", priv->recursive, NULL);
- g_queue_push_head (priv->providers, simple);
-
- if (priv->directory)
- {
- model = nautilus_search_engine_model_new ();
- connect_provider_signals (engine, NAUTILUS_SEARCH_PROVIDER (model));
- nautilus_search_engine_model_set_model (model, priv->directory);
- g_queue_push_head (priv->providers, model);
- }
-
+ priv->providers_running = 0;
+ priv->providers_finished = 0;
priv->providers_error = 0;
priv->restart = FALSE;
@@ -152,12 +95,17 @@ search_engine_start_real (NautilusSearchEngine *engine)
g_object_ref (engine);
- for (l = g_queue_peek_head_link (priv->providers); l != NULL; l = l->next)
+ nautilus_search_provider_start (NAUTILUS_SEARCH_PROVIDER (priv->tracker));
+ priv->providers_running++;
+
+ if (nautilus_search_engine_model_get_model (priv->model))
{
- nautilus_search_provider_set_query (NAUTILUS_SEARCH_PROVIDER (l->data),
- priv->query);
- nautilus_search_provider_start (NAUTILUS_SEARCH_PROVIDER (l->data));
+ nautilus_search_provider_start (NAUTILUS_SEARCH_PROVIDER (priv->model));
+ priv->providers_running++;
}
+
+ nautilus_search_provider_start (NAUTILUS_SEARCH_PROVIDER (priv->simple));
+ priv->providers_running++;
}
static void
@@ -165,23 +113,18 @@ nautilus_search_engine_start (NautilusSearchProvider *provider)
{
NautilusSearchEngine *engine;
NautilusSearchEnginePrivate *priv;
- gboolean all_providers_finished;
- GList *l;
+ gint num_finished;
engine = NAUTILUS_SEARCH_ENGINE (provider);
priv = nautilus_search_engine_get_instance_private (engine);
DEBUG ("Search engine start");
- all_providers_finished = TRUE;
- for (l = g_queue_peek_head_link (priv->providers); l != NULL; l = l->next)
- {
- all_providers_finished &= nautilus_search_provider_is_finished (NAUTILUS_SEARCH_PROVIDER (l->data));
- }
+ num_finished = priv->providers_error + priv->providers_finished;
if (priv->running)
{
- if (all_providers_finished &&
+ if (num_finished == priv->providers_running &&
priv->restart)
{
search_engine_start_real (engine);
@@ -194,7 +137,7 @@ nautilus_search_engine_start (NautilusSearchProvider *provider)
g_object_notify (G_OBJECT (provider), "running");
- if (!all_providers_finished)
+ if (num_finished < priv->providers_running)
{
priv->restart = TRUE;
}
@@ -209,17 +152,15 @@ nautilus_search_engine_stop (NautilusSearchProvider *provider)
{
NautilusSearchEngine *engine;
NautilusSearchEnginePrivate *priv;
- GList *l;
engine = NAUTILUS_SEARCH_ENGINE (provider);
priv = nautilus_search_engine_get_instance_private (engine);
DEBUG ("Search engine stop");
- for (l = g_queue_peek_head_link (priv->providers); l != NULL; l = l->next)
- {
- nautilus_search_provider_stop (NAUTILUS_SEARCH_PROVIDER (l->data));
- }
+ nautilus_search_provider_stop (NAUTILUS_SEARCH_PROVIDER (priv->tracker));
+ nautilus_search_provider_stop (NAUTILUS_SEARCH_PROVIDER (priv->model));
+ nautilus_search_provider_stop (NAUTILUS_SEARCH_PROVIDER (priv->simple));
priv->running = FALSE;
priv->restart = FALSE;
@@ -271,23 +212,17 @@ static void
check_providers_status (NautilusSearchEngine *engine)
{
NautilusSearchEnginePrivate *priv;
- gboolean all_providers_finished;
- GList *l;
+ gint num_finished;
priv = nautilus_search_engine_get_instance_private (engine);
+ num_finished = priv->providers_error + priv->providers_finished;
- all_providers_finished = TRUE;
- for (l = g_queue_peek_head_link (priv->providers); l != NULL; l = l->next)
- {
- all_providers_finished &= nautilus_search_provider_is_finished (NAUTILUS_SEARCH_PROVIDER (l->data));
- }
-
- if (!all_providers_finished)
+ if (num_finished < priv->providers_running)
{
return;
}
- if (g_queue_get_length (priv->providers) == priv->providers_error)
+ if (num_finished == priv->providers_error)
{
DEBUG ("Search engine error");
nautilus_search_provider_error (NAUTILUS_SEARCH_PROVIDER (engine),
@@ -341,8 +276,13 @@ search_provider_finished (NautilusSearchProvider *provider,
NautilusSearchProviderStatus status,
NautilusSearchEngine *engine)
{
+ NautilusSearchEnginePrivate *priv;
+
DEBUG ("Search provider finished");
+ priv = nautilus_search_engine_get_instance_private (engine);
+ priv->providers_finished++;
+
check_providers_status (engine);
}
@@ -361,21 +301,6 @@ connect_provider_signals (NautilusSearchEngine *engine,
engine);
}
-static void
-disconnect_provider_signals (NautilusSearchEngine *engine,
- NautilusSearchProvider *provider)
-{
- g_signal_handlers_disconnect_by_func (provider,
- search_provider_hits_added,
- engine);
- g_signal_handlers_disconnect_by_func (provider,
- search_provider_finished,
- engine);
- g_signal_handlers_disconnect_by_func (provider,
- search_provider_error,
- engine);
-}
-
static gboolean
nautilus_search_engine_is_running (NautilusSearchProvider *provider)
{
@@ -408,11 +333,9 @@ nautilus_search_engine_finalize (GObject *object)
g_hash_table_destroy (priv->uris);
- clear_providers_queue (engine);
- g_queue_free (priv->providers);
-
- g_clear_object (&priv->directory);
- g_clear_object (&priv->query);
+ g_clear_object (&priv->tracker);
+ g_clear_object (&priv->model);
+ g_clear_object (&priv->simple);
G_OBJECT_CLASS (nautilus_search_engine_parent_class)->finalize (object);
}
@@ -423,11 +346,8 @@ nautilus_search_engine_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- NautilusSearchEnginePrivate *priv;
NautilusSearchProvider *self = NAUTILUS_SEARCH_PROVIDER (object);
- priv = nautilus_search_engine_get_instance_private (NAUTILUS_SEARCH_ENGINE (self));
-
switch (prop_id)
{
case PROP_RUNNING:
@@ -436,45 +356,12 @@ nautilus_search_engine_get_property (GObject *object,
}
break;
- case PROP_RECURSIVE:
- {
- g_value_set_boolean (value, priv->recursive);
- }
- break;
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
-nautilus_search_engine_set_property (GObject *object,
- guint arg_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- NautilusSearchEnginePrivate *priv;
- NautilusSearchEngine *engine = NAUTILUS_SEARCH_ENGINE (object);
-
- priv = nautilus_search_engine_get_instance_private (NAUTILUS_SEARCH_ENGINE (engine));
-
- switch (arg_id)
- {
- case PROP_RECURSIVE:
- {
- priv->recursive = g_value_get_boolean (value);
- }
- break;
-
- default:
- {
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, arg_id, pspec);
- }
- break;
- }
-}
-
-static void
nautilus_search_engine_class_init (NautilusSearchEngineClass *class)
{
GObjectClass *object_class;
@@ -483,20 +370,6 @@ nautilus_search_engine_class_init (NautilusSearchEngineClass *class)
object_class->finalize = nautilus_search_engine_finalize;
object_class->get_property = nautilus_search_engine_get_property;
- object_class->set_property = nautilus_search_engine_set_property;
-
- /**
- * NautilusSearchEngine::recursive:
- *
- * Whether the search is recursive or not.
- */
- g_object_class_install_property (object_class,
- PROP_RECURSIVE,
- g_param_spec_boolean ("recursive",
- "recursive",
- "recursive",
- FALSE,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
/**
* NautilusSearchEngine::running:
@@ -514,7 +387,14 @@ nautilus_search_engine_init (NautilusSearchEngine *engine)
priv = nautilus_search_engine_get_instance_private (engine);
priv->uris = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
- priv->providers = g_queue_new ();
+ priv->tracker = nautilus_search_engine_tracker_new ();
+ connect_provider_signals (engine, NAUTILUS_SEARCH_PROVIDER (priv->tracker));
+
+ priv->model = nautilus_search_engine_model_new ();
+ connect_provider_signals (engine, NAUTILUS_SEARCH_PROVIDER (priv->model));
+
+ priv->simple = nautilus_search_engine_simple_new ();
+ connect_provider_signals (engine, NAUTILUS_SEARCH_PROVIDER (priv->simple));
}
NautilusSearchEngine *
@@ -526,3 +406,23 @@ nautilus_search_engine_new (void)
return engine;
}
+
+NautilusSearchEngineModel *
+nautilus_search_engine_get_model_provider (NautilusSearchEngine *engine)
+{
+ NautilusSearchEnginePrivate *priv;
+
+ priv = nautilus_search_engine_get_instance_private (engine);
+
+ return priv->model;
+}
+
+NautilusSearchEngineSimple *
+nautilus_search_engine_get_simple_provider (NautilusSearchEngine *engine)
+{
+ NautilusSearchEnginePrivate *priv;
+
+ priv = nautilus_search_engine_get_instance_private (engine);
+
+ return priv->simple;
+}
diff --git a/src/nautilus-search-engine.h b/src/nautilus-search-engine.h
index 93892a23e..0416e8306 100644
--- a/src/nautilus-search-engine.h
+++ b/src/nautilus-search-engine.h
@@ -30,7 +30,7 @@
G_BEGIN_DECLS
-#define NAUTILUS_TYPE_SEARCH_ENGINE (nautilus_search_engine_get_type ())
+#define NAUTILUS_TYPE_SEARCH_ENGINE (nautilus_search_engine_get_type ())
G_DECLARE_DERIVABLE_TYPE (NautilusSearchEngine, nautilus_search_engine, NAUTILUS, SEARCH_ENGINE, GObject)
@@ -39,9 +39,11 @@ struct _NautilusSearchEngineClass
GObjectClass parent_class;
};
-NautilusSearchEngine *nautilus_search_engine_new (void);
-void nautilus_search_engine_set_model (NautilusSearchEngine *engine,
- NautilusDirectory *directory);
+NautilusSearchEngine *nautilus_search_engine_new (void);
+NautilusSearchEngineModel *
+ nautilus_search_engine_get_model_provider (NautilusSearchEngine *engine);
+NautilusSearchEngineSimple *
+ nautilus_search_engine_get_simple_provider (NautilusSearchEngine *engine);
G_END_DECLS
diff --git a/src/nautilus-search-provider.c b/src/nautilus-search-provider.c
index 572e34d42..9a4a6553d 100644
--- a/src/nautilus-search-provider.c
+++ b/src/nautilus-search-provider.c
@@ -143,12 +143,3 @@ nautilus_search_provider_is_running (NautilusSearchProvider *provider)
return NAUTILUS_SEARCH_PROVIDER_GET_IFACE (provider)->is_running (provider);
}
-
-gboolean
-nautilus_search_provider_is_finished (NautilusSearchProvider *provider)
-{
- g_return_val_if_fail (NAUTILUS_IS_SEARCH_PROVIDER (provider), FALSE);
- g_return_val_if_fail (NAUTILUS_SEARCH_PROVIDER_GET_IFACE (provider)->is_finished, FALSE);
-
- return NAUTILUS_SEARCH_PROVIDER_GET_IFACE (provider)->is_finished (provider);
-}
diff --git a/src/nautilus-search-provider.h b/src/nautilus-search-provider.h
index b0c2a69e8..d019c6690 100644
--- a/src/nautilus-search-provider.h
+++ b/src/nautilus-search-provider.h
@@ -73,7 +73,6 @@ struct _NautilusSearchProviderInterface {
NautilusSearchProviderStatus status);
void (*error) (NautilusSearchProvider *provider, const char *error_message);
gboolean (*is_running) (NautilusSearchProvider *provider);
- gboolean (*is_finished) (NautilusSearchProvider *provider);
};
GType nautilus_search_provider_get_type (void) G_GNUC_CONST;
@@ -92,7 +91,6 @@ void nautilus_search_provider_error (NautilusSearchProvider
const char *error_message);
gboolean nautilus_search_provider_is_running (NautilusSearchProvider *provider);
-gboolean nautilus_search_provider_is_finished (NautilusSearchProvider *provider);
G_END_DECLS
diff --git a/test/test-nautilus-search-engine.c b/test/test-nautilus-search-engine.c
index fa30f352f..2ed8af77e 100644
--- a/test/test-nautilus-search-engine.c
+++ b/test/test-nautilus-search-engine.c
@@ -28,6 +28,7 @@ main (int argc,
char *argv[])
{
NautilusSearchEngine *engine;
+ NautilusSearchEngineModel *model;
NautilusDirectory *directory;
NautilusQuery *query;
GFile *location;
@@ -51,7 +52,8 @@ main (int argc,
directory = nautilus_directory_get (location);
g_object_unref (location);
- nautilus_search_engine_set_model (engine, directory);
+ 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));