Mercurial > pidgin
comparison src/gtkblist.c @ 13478:38dcde2c8c4b
[gaim-migrate @ 15854]
Make the type-ahead search in the buddy list only match on the beginning of words.
Fixes SF Bug Report #1442845
Major thanks to behdad from #gtk+ on irc.gnome.org for help walking me through the Pango code.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Thu, 09 Mar 2006 06:26:16 +0000 |
parents | 5251e354d213 |
children | 56abb67edec9 |
comparison
equal
deleted
inserted
replaced
13477:d18f5962d454 | 13478:38dcde2c8c4b |
---|---|
3373 * used rarely, so it shouldn't matter TOO much. | 3373 * used rarely, so it shouldn't matter TOO much. |
3374 */ | 3374 */ |
3375 static gboolean | 3375 static gboolean |
3376 _search_func(GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer search_data) | 3376 _search_func(GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer search_data) |
3377 { | 3377 { |
3378 gboolean result; | |
3379 gchar *enteredstring; | 3378 gchar *enteredstring; |
3380 gchar *withmarkup; | 3379 gchar *withmarkup; |
3381 gchar *nomarkup; | 3380 gchar *nomarkup; |
3382 gchar *normalized; | 3381 gchar *normalized; |
3382 gboolean result; | |
3383 size_t i; | |
3384 size_t len; | |
3385 PangoLogAttr *log_attrs; | |
3386 gchar *word; | |
3383 | 3387 |
3384 gtk_tree_model_get(model, iter, column, &withmarkup, -1); | 3388 gtk_tree_model_get(model, iter, column, &withmarkup, -1); |
3385 | 3389 |
3386 enteredstring = g_utf8_casefold(gaim_normalize(NULL, key), -1); | 3390 enteredstring = g_utf8_casefold(gaim_normalize(NULL, key), -1); |
3387 nomarkup = gaim_markup_strip_html(withmarkup); | 3391 nomarkup = gaim_markup_strip_html(withmarkup); |
3388 normalized = g_utf8_casefold(gaim_normalize(NULL, nomarkup), -1); | 3392 normalized = g_utf8_casefold(gaim_normalize(NULL, nomarkup), -1); |
3389 | 3393 |
3390 result = (g_strstr_len(normalized, strlen(normalized), enteredstring) == NULL); | 3394 if (gaim_str_has_prefix(normalized, enteredstring)) |
3395 { | |
3396 g_free(withmarkup); | |
3397 g_free(enteredstring); | |
3398 g_free(nomarkup); | |
3399 g_free(normalized); | |
3400 return FALSE; | |
3401 } | |
3402 | |
3403 | |
3404 /* Use Pango to separate by words. */ | |
3405 len = g_utf8_strlen(normalized, -1); | |
3406 log_attrs = g_new(PangoLogAttr, len + 1); | |
3407 | |
3408 pango_get_log_attrs(normalized, len, -1, NULL, log_attrs, len + 1); | |
3409 | |
3410 word = normalized; | |
3411 result = TRUE; | |
3412 for (i = 0; i < (len - 1) ; i++) | |
3413 { | |
3414 if (log_attrs[i].is_word_start && | |
3415 gaim_str_has_prefix(word, enteredstring)) | |
3416 { | |
3417 result = FALSE; | |
3418 break; | |
3419 } | |
3420 word = g_utf8_next_char(word); | |
3421 } | |
3422 g_free(log_attrs); | |
3423 | |
3424 /* The non-Pango version. */ | |
3425 #if 0 | |
3426 word = normalized; | |
3427 result = TRUE; | |
3428 while (word[0] != '\0') | |
3429 { | |
3430 gunichar c = g_utf8_get_char(word); | |
3431 if (!g_unichar_isalnum(c)) | |
3432 { | |
3433 word = g_utf8_find_next_char(word, NULL); | |
3434 if (gaim_str_has_prefix(word, enteredstring)) | |
3435 { | |
3436 result = FALSE; | |
3437 break; | |
3438 } | |
3439 } | |
3440 else | |
3441 word = g_utf8_find_next_char(word, NULL); | |
3442 } | |
3443 #endif | |
3391 | 3444 |
3392 g_free(withmarkup); | 3445 g_free(withmarkup); |
3393 g_free(enteredstring); | 3446 g_free(enteredstring); |
3394 g_free(nomarkup); | 3447 g_free(nomarkup); |
3395 g_free(normalized); | 3448 g_free(normalized); |