Back to index

indicator-appmenu  12.10.0
Classes | Defines | Typedefs | Functions | Variables
hudquery.c File Reference
#include "hudquery.h"
#include "hudresult.h"

Go to the source code of this file.

Classes

struct  _HudQuery
 SECTION:hudquery : HudQuery : a stateful query against a #HudSource. More...

Defines

#define G_LOG_DOMAIN   "hudquery"

Typedefs

typedef GObjectClass HudQueryClass

Functions

static void hud_query_find_max_usage (gpointer data, gpointer user_data)
static gint hud_query_compare_results (gconstpointer a, gconstpointer b, gpointer user_data)
static void hud_query_refresh (HudQuery *query)
static gboolean hud_query_dispatch_refresh (gpointer user_data)
static void hud_query_source_changed (HudSource *source, gpointer user_data)
static void hud_query_finalize (GObject *object)
static void hud_query_init (HudQuery *query)
static void hud_query_class_init (HudQueryClass *class)
HudQuery * hud_query_new (HudSource *source, const gchar *search_string, gint num_results)
 hud_query_new: : the #HudSource against which to search : the string to search for : the maximum number of results to report
GVariant * hud_query_get_query_key (HudQuery *query)
 hud_query_get_query_key: : a #HudQuery
HudQuery * hud_query_lookup (GVariant *query_key)
 hud_query_lookup: : a query key
void hud_query_close (HudQuery *query)
 hud_query_close: : a #HudQuery
guint hud_query_get_n_results (HudQuery *query)
 hud_query_get_n_results: : a #HudQuery
HudResult * hud_query_get_result_by_index (HudQuery *query, guint i)
 hud_query_get_result_by_index: : a #HudQuery : the index of the result

Variables

static guint hud_query_changed_signal
static HudQuery * last_created_query

Class Documentation

struct _HudQuery

SECTION:hudquery : HudQuery : a stateful query against a #HudSource.

HudQuery is a stateful query for a particular search string against

a given #HudSource.

The query monitors its source for the "change" signal and re-submits the query when changes are reported. The query has its own change signal that is fired when this happens.

The query maintains a list of results from the search which are sorted by relevance and accessible by index. Contrast this with the stateless nature of #HudSource. HudQuery:

This is an opaque structure type.

Definition at line 48 of file hudquery.c.

Class Members
gint num_results
GObject parent_instance
guint refresh_id
GPtrArray * results
gchar * search_string
HudSource * source
HudTokenList * token_list

Define Documentation

#define G_LOG_DOMAIN   "hudquery"

Definition at line 19 of file hudquery.c.


Typedef Documentation

typedef GObjectClass HudQueryClass

Definition at line 61 of file hudquery.c.


Function Documentation

static void hud_query_class_init ( HudQueryClass class) [static]

HudQuery::changed: : a #HudQuery

Indicates that the results of have changed.

Definition at line 171 of file hudquery.c.

{
  hud_query_changed_signal = g_signal_new ("changed", HUD_TYPE_QUERY, G_SIGNAL_RUN_LAST, 0, NULL,
                                           NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);

  class->finalize = hud_query_finalize;
}

Here is the call graph for this function:

void hud_query_close ( HudQuery *  query)

hud_query_close: : a #HudQuery

Closes a #HudQuery.

This drops the query from the internal list of queries. Future use of hud_query_lookup() to find this query will fail.

You must still release your own reference on , if you have one. This only drops the internal reference.

Definition at line 282 of file hudquery.c.

{
  if (query == last_created_query)
    g_clear_object (&last_created_query);
}

Here is the caller graph for this function:

static gint hud_query_compare_results ( gconstpointer  a,
gconstpointer  b,
gpointer  user_data 
) [static]

Definition at line 84 of file hudquery.c.

{
  HudResult *result_a = *(HudResult * const *) a;
  HudResult *result_b = *(HudResult * const *) b;
  gint max_usage = GPOINTER_TO_INT (user_data);
  guint distance_a;
  guint distance_b;

  distance_a = hud_result_get_distance (result_a, max_usage);
  distance_b = hud_result_get_distance (result_b, max_usage);

  return distance_a - distance_b;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static gboolean hud_query_dispatch_refresh ( gpointer  user_data) [static]

Definition at line 122 of file hudquery.c.

{
  HudQuery *query = user_data;

  hud_query_refresh (query);

  g_signal_emit (query, hud_query_changed_signal, 0);

  query->refresh_id = 0;

  return G_SOURCE_REMOVE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void hud_query_finalize ( GObject *  object) [static]

Definition at line 145 of file hudquery.c.

{
  HudQuery *query = HUD_QUERY (object);

  g_debug ("Destroyed query '%s'", query->search_string);

  if (query->refresh_id)
    g_source_remove (query->refresh_id);

  hud_source_unuse (query->source);

  g_object_unref (query->source);
  hud_token_list_free (query->token_list);
  g_free (query->search_string);
  g_ptr_array_unref (query->results);

  G_OBJECT_CLASS (hud_query_parent_class)
    ->finalize (object);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void hud_query_find_max_usage ( gpointer  data,
gpointer  user_data 
) [static]

Definition at line 69 of file hudquery.c.

{
  guint *max_usage = user_data;
  HudResult *result = data;
  HudItem *item;
  guint usage;

  item = hud_result_get_item (result);
  usage = hud_item_get_usage (item);

  *max_usage = MAX (*max_usage, usage);
}

Here is the call graph for this function:

Here is the caller graph for this function:

guint hud_query_get_n_results ( HudQuery *  query)

hud_query_get_n_results: : a #HudQuery

Gets the number of results in .

Returns: the number of results

Definition at line 297 of file hudquery.c.

{
  return query->results->len;
}

Here is the caller graph for this function:

GVariant* hud_query_get_query_key ( HudQuery *  query)

hud_query_get_query_key: : a #HudQuery

Returns the query key for .

Each #HudQuery has a unique identifying key that is assigned when the query is created.

FIXME: This is a lie.

Returns: (transfer none): the query key for

Definition at line 245 of file hudquery.c.

{
  static GVariant *query_key;

  if (query_key == NULL)
    query_key = g_variant_ref_sink (g_variant_new_string ("query key"));

  return query_key;
}

Here is the caller graph for this function:

HudResult* hud_query_get_result_by_index ( HudQuery *  query,
guint  i 
)

hud_query_get_result_by_index: : a #HudQuery : the index of the result

Gets the result from .

must be less than the number of results in the query. See hud_query_get_n_results().

Returns: (transfer none): the #HudResult at position

Definition at line 315 of file hudquery.c.

{
  return query->results->pdata[i];
}

Here is the caller graph for this function:

static void hud_query_init ( HudQuery *  query) [static]

Definition at line 166 of file hudquery.c.

{
}
HudQuery* hud_query_lookup ( GVariant *  query_key)

hud_query_lookup: : a query key

Finds the query that has the given .

Returns: (transfer none): the query, or NULL if no such query exists

Definition at line 264 of file hudquery.c.

{
  return last_created_query;
}

Here is the caller graph for this function:

HudQuery* hud_query_new ( HudSource *  source,
const gchar *  search_string,
gint  num_results 
)

hud_query_new: : the #HudSource against which to search : the string to search for : the maximum number of results to report

Creates a #HudQuery.

A #HudQuery is a stateful search for against a .

Each #HudQuery is assigned a "query key" when it is created. This can be used to lookup the hud query later using hud_query_lookup(). Because of this, an internal reference is held on the query and the query won't be completely freed until you call hud_query_close() on it in addition to releasing your ref.

Returns: the new #HudQuery

Definition at line 204 of file hudquery.c.

{
  HudQuery *query;

  g_debug ("Created query '%s'", search_string);

  query = g_object_new (HUD_TYPE_QUERY, NULL);
  query->source = g_object_ref (source);
  query->results = g_ptr_array_new_with_free_func (g_object_unref);
  query->search_string = g_strdup (search_string);
  query->token_list = hud_token_list_new_from_string (query->search_string);
  query->num_results = num_results;

  hud_source_use (query->source);

  hud_query_refresh (query);

  g_signal_connect_object (source, "changed", G_CALLBACK (hud_query_source_changed), query, 0);

  g_clear_object (&last_created_query);
  last_created_query = g_object_ref (query);

  return query;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void hud_query_refresh ( HudQuery *  query) [static]

Definition at line 101 of file hudquery.c.

{
  guint max_usage = 0;
  guint64 start_time;

  start_time = g_get_monotonic_time ();

  g_ptr_array_set_size (query->results, 0);

  if (hud_token_list_get_length (query->token_list) != 0)
    hud_source_search (query->source, query->results, query->token_list);

  g_ptr_array_foreach (query->results, hud_query_find_max_usage, &max_usage);
  g_ptr_array_sort_with_data (query->results, hud_query_compare_results, GINT_TO_POINTER (max_usage));
  if (query->results->len > query->num_results)
    g_ptr_array_set_size (query->results, query->num_results);

  g_debug ("query took %dus\n", (int) (g_get_monotonic_time () - start_time));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void hud_query_source_changed ( HudSource *  source,
gpointer  user_data 
) [static]

Definition at line 135 of file hudquery.c.

{
  HudQuery *query = user_data;

  if (!query->refresh_id)
    query->refresh_id = g_idle_add (hud_query_dispatch_refresh, query);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

guint hud_query_changed_signal [static]

Definition at line 64 of file hudquery.c.

HudQuery* last_created_query [static]

Definition at line 66 of file hudquery.c.