[gnome-builder/global-search] GbSearchContext: start filling in result info
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/global-search] GbSearchContext: start filling in result info
- Date: Sat, 13 Dec 2014 10:04:01 +0000 (UTC)
commit ed7d927236882ad841cdb8bc1902b2744b5706a7
Author: Christian Hergert <christian hergert me>
Date: Sat Dec 13 02:03:48 2014 -0800
GbSearchContext: start filling in result info
src/search/gb-search-context.c | 66 ++++++++++++++++++++++++++++++++++++++--
src/search/gb-search-context.h | 5 +++
src/search/gb-search-result.c | 24 ++++++++++++++-
src/search/gb-search-result.h | 6 ++-
4 files changed, 95 insertions(+), 6 deletions(-)
---
diff --git a/src/search/gb-search-context.c b/src/search/gb-search-context.c
index 48f0f66..ef6f704 100644
--- a/src/search/gb-search-context.c
+++ b/src/search/gb-search-context.c
@@ -23,12 +23,14 @@
#include "gb-log.h"
#include "gb-search-context.h"
#include "gb-search-provider.h"
+#include "gb-search-result.h"
struct _GbSearchContextPrivate
{
GCancellable *cancellable;
GList *providers;
gchar *search_text;
+ GList *results;
guint executed : 1;
};
@@ -41,6 +43,12 @@ enum {
LAST_PROP
};
+enum {
+ RESULTS_ADDED,
+ LAST_SIGNAL
+};
+
+static guint gSignals [LAST_SIGNAL];
static GParamSpec *gParamSpecs [LAST_PROP];
/**
@@ -108,14 +116,46 @@ gb_search_context_cancel (GbSearchContext *context)
g_cancellable_cancel (context->priv->cancellable);
}
-void
-gb_search_context_add_proposals (GbSearchContext *context,
+/**
+ * gb_search_context_get_results:
+ * @context: A #GbSearchContext
+ *
+ * Fetches the current results.
+ *
+ * Returns: (transfer none): A #GList of current results.
+ */
+const GList *
+gb_search_context_get_results (GbSearchContext *context)
+{
+ g_return_val_if_fail (GB_IS_SEARCH_CONTEXT (context), NULL);
+
+ return context->priv->results;
+}
+
+static void
+gb_search_context_results_added (GbSearchContext *context,
GbSearchProvider *provider,
- GList *proposals,
+ GList *results,
gboolean finished)
{
g_return_if_fail (GB_IS_SEARCH_CONTEXT (context));
g_return_if_fail (GB_IS_SEARCH_PROVIDER (provider));
+
+ context->priv->results = g_list_concat (context->priv->results, results);
+}
+
+void
+gb_search_context_add_results (GbSearchContext *context,
+ GbSearchProvider *provider,
+ GList *proposals,
+ gboolean finished)
+{
+ g_return_if_fail (GB_IS_SEARCH_CONTEXT (context));
+ g_return_if_fail (GB_IS_SEARCH_PROVIDER (provider));
+
+ g_signal_emit (context, gSignals [RESULTS_ADDED], 0,
+ provider, proposals, finished);
+
}
const gchar *
@@ -166,6 +206,10 @@ gb_search_context_finalize (GObject *object)
g_list_foreach (priv->providers, (GFunc)g_object_unref, NULL);
g_clear_pointer (&priv->providers, g_list_free);
+
+ g_list_foreach (priv->results, (GFunc)g_object_unref, NULL);
+ g_clear_pointer (&priv->results, g_list_free);
+
g_clear_pointer (&priv->search_text, g_free);
G_OBJECT_CLASS (gb_search_context_parent_class)->finalize (object);
@@ -222,6 +266,8 @@ gb_search_context_class_init (GbSearchContextClass *klass)
object_class->get_property = gb_search_context_get_property;
object_class->set_property = gb_search_context_set_property;
+ klass->results_added = gb_search_context_results_added;
+
gParamSpecs [PROP_SEARCH_TEXT] =
g_param_spec_string ("search-text",
_("Search Text"),
@@ -242,6 +288,20 @@ gb_search_context_class_init (GbSearchContextClass *klass)
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_PROVIDERS,
gParamSpecs [PROP_PROVIDERS]);
+
+ gSignals [RESULTS_ADDED] =
+ g_signal_new ("results-added",
+ GB_TYPE_SEARCH_CONTEXT,
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL,
+ NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE,
+ 3,
+ GB_TYPE_SEARCH_PROVIDER,
+ G_TYPE_POINTER,
+ G_TYPE_BOOLEAN);
}
static void
diff --git a/src/search/gb-search-context.h b/src/search/gb-search-context.h
index a67c9b9..94bb03b 100644
--- a/src/search/gb-search-context.h
+++ b/src/search/gb-search-context.h
@@ -44,6 +44,11 @@ struct _GbSearchContext
struct _GbSearchContextClass
{
GObjectClass parent;
+
+ void (*results_added) (GbSearchContext *context,
+ GbSearchProvider *provider,
+ GList *results,
+ gboolean finished);
};
GType gb_search_context_get_type (void);
diff --git a/src/search/gb-search-result.c b/src/search/gb-search-result.c
index ca41880..948fc28 100644
--- a/src/search/gb-search-result.c
+++ b/src/search/gb-search-result.c
@@ -20,7 +20,8 @@
struct _GbSearchResultPrivate
{
-
+ gint priority;
+ gfloat score;
};
G_DEFINE_TYPE_WITH_PRIVATE (GbSearchResult, gb_search_result, GTK_TYPE_BIN)
@@ -38,6 +39,27 @@ gb_search_result_new (void)
return g_object_new (GB_TYPE_SEARCH_RESULT, NULL);
}
+gint
+gb_search_result_compare_func (gconstpointer result1,
+ gconstpointer result2)
+{
+ const GbSearchResult *r1 = result1;
+ const GbSearchResult *r2 = result2;
+ gint ret;
+
+ ret = r1->priv->priority - r2->priv->priority;
+
+ if (ret == 0)
+ {
+ if (r1->priv->score > r2->priv->score)
+ return 1;
+ else if (r1->priv->score < r2->priv->score)
+ return -1;
+ }
+
+ return ret;
+}
+
static void
gb_search_result_finalize (GObject *object)
{
diff --git a/src/search/gb-search-result.h b/src/search/gb-search-result.h
index 39f2bca..44e66bf 100644
--- a/src/search/gb-search-result.h
+++ b/src/search/gb-search-result.h
@@ -46,8 +46,10 @@ struct _GbSearchResultClass
GtkBinClass parent;
};
-GType gb_search_result_get_type (void);
-GtkWidget *gb_search_result_new (void);
+GType gb_search_result_get_type (void);
+GtkWidget *gb_search_result_new (void);
+gint gb_search_result_compare_func (gconstpointer result1,
+ gconstpointer result2);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]