Back to index

indicator-appmenu  12.10.0
Classes | Typedefs | Functions
hudresult.c File Reference
#include "hudresult.h"
#include <string.h>
#include "hudsettings.h"
#include "hudtoken.h"

Go to the source code of this file.

Classes

struct  _HudResult

Typedefs

typedef GObjectClass HudResultClass
 SECTION:hudresult : HudResult : a search result: a #HudItem plus metadata about why it matched.

Functions

static void hud_result_finalize (GObject *object)
static void hud_result_init (HudResult *result)
static void hud_result_class_init (HudResultClass *class)
HudResult * hud_result_get_if_matched (HudItem *item, HudTokenList *search_tokens, guint penalty)
 hud_result_get_if_matched: : a #HudItem : the search string used : a penalty value
static void hud_result_format_tokens (GString *string, HudStringList *tokens)
static void hud_result_format_description (HudResult *result)
HudResult * hud_result_new (HudItem *item, HudTokenList *search_tokens, guint penalty)
 hud_result_new: : a #HudItem : the search string used : a penalty value
guint hud_result_get_distance (HudResult *result, guint max_usage)
 hud_result_get_distance:
HudItem * hud_result_get_item (HudResult *result)
 hud_result_get_item:
const gchar * hud_result_get_html_description (HudResult *result)
 hud_result_get_html_description:

Class Documentation

struct _HudResult

Definition at line 44 of file hudresult.c.

Class Members
gchar * description
guint distance
HudItem * item
const gchar ** matched
GObject parent_instance

Typedef Documentation

typedef GObjectClass HudResultClass

SECTION:hudresult : HudResult : a search result: a #HudItem plus metadata about why it matched.

A #HudResult is a wrapper around a #HudItem plus information about why (and how closely) it matched a particular search. HudResult:

This is an opaque structure type.

Definition at line 42 of file hudresult.c.


Function Documentation

static void hud_result_class_init ( HudResultClass class) [static]

Definition at line 76 of file hudresult.c.

{
  class->finalize = hud_result_finalize;
}

Here is the call graph for this function:

static void hud_result_finalize ( GObject *  object) [static]

Definition at line 58 of file hudresult.c.

{
  HudResult *result = HUD_RESULT (object);

  g_object_unref (result->item);
  g_free (result->matched);
  g_free (result->description);

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

Here is the caller graph for this function:

static void hud_result_format_description ( HudResult *  result) [static]

Definition at line 138 of file hudresult.c.

{
  GString *description;
  gint i;

  description = g_string_new (NULL);
  hud_result_format_tokens (description, hud_item_get_tokens (result->item));

  for (i = 0; result->matched[i]; i++)
    {
      gchar *escaped;
      gchar *match;

      escaped = g_markup_escape_text (result->matched[i], -1);
      match = strstr (description->str, escaped);

      if (match != NULL)
        {
          gsize start, end;

          start = match - description->str;
          end = start + strlen (escaped);

          /* modify the end first so that the modification to the start
           * doesn't change the offset of the end */
          g_string_insert (description, end, "</b>");
          g_string_insert (description, start, "<b>");
        }

      g_free (escaped);
    }

  result->description = g_string_free (description, FALSE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void hud_result_format_tokens ( GString *  string,
HudStringList *  tokens 
) [static]

Definition at line 118 of file hudresult.c.

{
  HudStringList *tail;
  gchar *escaped;

  tail = hud_string_list_get_tail (tokens);

  if (tail)
    {
      hud_result_format_tokens (string, tail);
      g_string_append (string, " &gt; ");
    }

  escaped = g_markup_escape_text (hud_string_list_get_head (tokens), -1);
  g_string_append (string, escaped);
  g_free (escaped);
}

Here is the call graph for this function:

Here is the caller graph for this function:

guint hud_result_get_distance ( HudResult *  result,
guint  max_usage 
)

hud_result_get_distance:

Returns:
: a #HudResult : the maximum usage count we consider

Returns the "adjusted" distance of

Returns:
.

If is zero then the returned value is equal to the distance between the #HudItem used to create the result and the search string.

If is non-zero then it is taken to be the usage count of the most-used item in the same query as this result. The distance is adjusted for this fact to penalise less-frequently-used item.

Returns: the adjusted distance

Definition at line 228 of file hudresult.c.

{
  guint distance;

  g_return_val_if_fail (HUD_IS_RESULT (result), G_MAXINT);

  distance = result->distance;

  if (max_usage != 0)
    {
      guint usage, inverse_usage;

      usage = hud_item_get_usage (result->item);
      inverse_usage = max_usage - usage;
      distance += (distance * inverse_usage) / max_usage;
    }

  return distance;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const gchar* hud_result_get_html_description ( HudResult *  result)

hud_result_get_html_description:

Returns:
: a #HudResult

Returns a textual description of

Returns:
with the parts of the text that matched the search string strenghtened (ie: in bold).

Returns: the description

Definition at line 273 of file hudresult.c.

{
  return result->description;
}

Here is the caller graph for this function:

HudResult* hud_result_get_if_matched ( HudItem *  item,
HudTokenList *  search_tokens,
guint  penalty 
)

hud_result_get_if_matched: : a #HudItem : the search string used : a penalty value

Creates a #HudResult for , only if the resulting unadjusted distance would be less than or equal to the maximum distance specified in the HUD settings.

This is the same as hud_result_new() except that it will return NULL if the distance is too great.

The penalty value is ignored when checking the maximum distance but will impact the distance of the created result. As a result, the returned #HudResult may have an effective distance greater than the maximum distance.

Returns: a new #HudResult, or NULL in event of a poor match

Definition at line 102 of file hudresult.c.

{
  if (!hud_item_get_enabled (item))
    return NULL;

  /* ignore the penalty in the max-distance calculation */
  if (hud_token_list_distance (hud_item_get_token_list (item), search_tokens, NULL) <= hud_settings.max_distance)
    return hud_result_new (item, search_tokens, penalty);
  else
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

HudItem* hud_result_get_item ( HudResult *  result)

hud_result_get_item:

Returns:
: a #HudResult

Gets the #HudItem for

Returns:
.

Returns: (transfer none): a #HudItem

Definition at line 258 of file hudresult.c.

{
  return result->item;
}

Here is the caller graph for this function:

static void hud_result_init ( HudResult *  result) [static]

Definition at line 71 of file hudresult.c.

{
}
HudResult* hud_result_new ( HudItem *  item,
HudTokenList *  search_tokens,
guint  penalty 
)

hud_result_new: : a #HudItem : the search string used : a penalty value

Creates a #HudResult for as search for using .

If is non-zero then it is used to increase the distance of the result. This is used to decrease the ranking of matches from the indicators.

Returns: the new #HudResult

Definition at line 188 of file hudresult.c.

{
  HudResult *result;

  g_return_val_if_fail (HUD_IS_ITEM (item), NULL);
  g_return_val_if_fail (search_tokens != NULL, NULL);

  result = g_object_new (HUD_TYPE_RESULT, NULL);
  result->item = g_object_ref (item);
  result->distance = hud_token_list_distance (hud_item_get_token_list (item), search_tokens, &result->matched);
  hud_result_format_description (result);

  result->distance += (result->distance * penalty) / 100;

  if (result->distance == 0 && penalty > 0)
    result->distance = 1;

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function: