[gnome-builder/global-search: 4/4] GbSearchManager: execute search using context
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/global-search: 4/4] GbSearchManager: execute search using context
- Date: Sat, 13 Dec 2014 07:50:02 +0000 (UTC)
commit e5efd79def95c8ebc13b526eac76ba7ae0bff5c7
Author: Christian Hergert <christian hergert me>
Date: Fri Dec 12 23:49:31 2014 -0800
GbSearchManager: execute search using context
src/search/gb-search-context.c | 23 +++++++++++++++++++++++
src/search/gb-search-context.h | 1 +
src/search/gb-search-manager.c | 34 ++++++++++++++++++++++++++++------
src/search/gb-search-manager.h | 2 ++
4 files changed, 54 insertions(+), 6 deletions(-)
---
diff --git a/src/search/gb-search-context.c b/src/search/gb-search-context.c
index 680ee5d..48f0f66 100644
--- a/src/search/gb-search-context.c
+++ b/src/search/gb-search-context.c
@@ -29,6 +29,7 @@ struct _GbSearchContextPrivate
GCancellable *cancellable;
GList *providers;
gchar *search_text;
+ guint executed : 1;
};
G_DEFINE_TYPE_WITH_PRIVATE (GbSearchContext, gb_search_context, G_TYPE_OBJECT)
@@ -60,6 +61,28 @@ gb_search_context_new (const GList *providers,
NULL);
}
+void
+gb_search_context_execute (GbSearchContext *context)
+{
+ GbSearchContextPrivate *priv;
+ GList *iter;
+
+ g_return_if_fail (GB_IS_SEARCH_CONTEXT (context));
+
+ priv = context->priv;
+
+ if (priv->executed)
+ {
+ g_warning ("GbSearchContext has already been executed.");
+ return;
+ }
+
+ priv->executed = 1;
+
+ for (iter = priv->providers; iter; iter = iter->next)
+ gb_search_provider_populate (iter->data, context, priv->cancellable);
+}
+
/**
* gb_search_context_get_cancellable:
* @context: A #GbSearchContext
diff --git a/src/search/gb-search-context.h b/src/search/gb-search-context.h
index 31a48b9..a67c9b9 100644
--- a/src/search/gb-search-context.h
+++ b/src/search/gb-search-context.h
@@ -54,6 +54,7 @@ void gb_search_context_add_results (GbSearchContext *context,
GbSearchProvider *provider,
GList *results,
gboolean finished);
+void gb_search_context_execute (GbSearchContext *context);
G_END_DECLS
diff --git a/src/search/gb-search-manager.c b/src/search/gb-search-manager.c
index 07f8d82..ec2e093 100644
--- a/src/search/gb-search-manager.c
+++ b/src/search/gb-search-manager.c
@@ -16,12 +16,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#define G_LOG_DOMAIN "search-manager"
+
+#include <glib/gi18n.h>
+
+#include "gb-search-context.h"
#include "gb-search-manager.h"
#include "gb-search-provider.h"
struct _GbSearchManagerPrivate
{
- GPtrArray *providers;
+ GList *providers;
};
G_DEFINE_TYPE_WITH_PRIVATE (GbSearchManager, gb_search_manager, G_TYPE_OBJECT)
@@ -59,8 +64,26 @@ gb_search_manager_add_provider (GbSearchManager *manager,
g_return_if_fail (GB_IS_SEARCH_MANAGER (manager));
g_return_if_fail (GB_IS_SEARCH_PROVIDER (provider));
- g_ptr_array_add (manager->priv->providers, g_object_ref (provider));
- g_ptr_array_sort (manager->priv->providers, sort_provider);
+ manager->priv->providers =
+ g_list_sort (g_list_prepend (manager->priv->providers,
+ g_object_ref (provider)),
+ sort_provider);
+}
+
+GbSearchContext *
+gb_search_manager_search (GbSearchManager *manager,
+ const gchar *search_text)
+{
+ GbSearchContext *context;
+
+ g_return_val_if_fail (GB_IS_SEARCH_MANAGER (manager), NULL);
+ g_return_val_if_fail (search_text, NULL);
+
+ context = gb_search_context_new (manager->priv->providers, search_text);
+
+ gb_search_context_execute (context);
+
+ return context;
}
static void
@@ -68,7 +91,8 @@ gb_search_manager_finalize (GObject *object)
{
GbSearchManagerPrivate *priv = GB_SEARCH_MANAGER (object)->priv;
- g_clear_pointer (&priv->providers, g_ptr_array_unref);
+ g_list_foreach (priv->providers, (GFunc)g_object_unref, NULL);
+ g_clear_pointer (&priv->providers, g_list_free);
G_OBJECT_CLASS (gb_search_manager_parent_class)->finalize (object);
}
@@ -117,6 +141,4 @@ static void
gb_search_manager_init (GbSearchManager *self)
{
self->priv = gb_search_manager_get_instance_private (self);
-
- self->priv->providers = g_ptr_array_new_with_free_func (g_object_unref);
}
diff --git a/src/search/gb-search-manager.h b/src/search/gb-search-manager.h
index 9947d85..5c862fe 100644
--- a/src/search/gb-search-manager.h
+++ b/src/search/gb-search-manager.h
@@ -55,6 +55,8 @@ GbSearchManager *gb_search_manager_new (void);
GbSearchManager *gb_search_manager_get_default (void);
void gb_search_manager_add_provider (GbSearchManager *manager,
GbSearchProvider *provider);
+GbSearchContext *gb_search_manager_search (GbSearchManager *manager,
+ const gchar *search_text);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]