~indicator-applet-developers/indicator-appmenu/trunk.13.04

« back to all changes in this revision

Viewing changes to src/hudresult.c

* Upstream Merge
  * GMenuModel menu support

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
#include "hudresult.h"
20
20
 
 
21
#include <string.h>
 
22
 
21
23
#include "hudsettings.h"
22
24
#include "distance.h"
23
25
 
138
140
    return NULL;
139
141
}
140
142
 
 
143
/* recurse so that we can avoid having to prepend the string */
 
144
static void
 
145
hud_result_format_tokens (GString       *string,
 
146
                          HudStringList *tokens)
 
147
{
 
148
  HudStringList *tail;
 
149
  gchar *escaped;
 
150
 
 
151
  tail = hud_string_list_get_tail (tokens);
 
152
 
 
153
  if (tail)
 
154
    {
 
155
      hud_result_format_tokens (string, tail);
 
156
      g_string_append (string, " &gt; ");
 
157
    }
 
158
 
 
159
  escaped = g_markup_escape_text (hud_string_list_get_head (tokens), -1);
 
160
  g_string_append (string, escaped);
 
161
  g_free (escaped);
 
162
}
 
163
 
 
164
static void
 
165
hud_result_format_description (HudResult *result)
 
166
{
 
167
  GString *description;
 
168
  gint i;
 
169
 
 
170
  description = g_string_new (NULL);
 
171
  hud_result_format_tokens (description, hud_item_get_tokens (result->item));
 
172
 
 
173
  for (i = 0; result->matched[i]; i++)
 
174
    {
 
175
      gchar *escaped;
 
176
      gchar *match;
 
177
 
 
178
      escaped = g_markup_escape_text (result->matched[i], -1);
 
179
      match = strstr (description->str, escaped);
 
180
 
 
181
      if (match != NULL)
 
182
        {
 
183
          gsize start, end;
 
184
 
 
185
          start = match - description->str;
 
186
          end = start + strlen (escaped);
 
187
 
 
188
          /* modify the end first so that the modification to the start
 
189
           * doesn't change the offset of the end */
 
190
          g_string_insert (description, end, "</b>");
 
191
          g_string_insert (description, start, "<b>");
 
192
        }
 
193
 
 
194
      g_free (escaped);
 
195
    }
 
196
 
 
197
  result->description = g_string_free (description, FALSE);
 
198
}
 
199
 
141
200
/**
142
201
 * hud_result_new:
143
202
 * @item: a #HudItem
165
224
  result = g_object_new (HUD_TYPE_RESULT, NULL);
166
225
  result->item = g_object_ref (item);
167
226
  result->distance = calculate_distance_from_list (search_string, hud_item_get_tokens (item), &result->matched);
168
 
  result->description = hud_string_list_pretty_print (hud_item_get_tokens (result->item));
 
227
  hud_result_format_description (result);
169
228
 
170
229
  result->distance += (result->distance * penalty) / 100;
171
230