[gnome-control-center/wip/region-panel: 27/43] common: Allow using multiple words to filter languages
- From: Rui Matos <rtcm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/region-panel: 27/43] common: Allow using multiple words to filter languages
- Date: Sun, 17 Feb 2013 00:32:14 +0000 (UTC)
commit 9b2c842ae43a0716770acb3bdc9f5f1d0ed0339f
Author: Rui Matos <tiagomatos gmail com>
Date: Tue Feb 5 01:44:27 2013 +0100
common: Allow using multiple words to filter languages
All words must match.
panels/common/cc-language-chooser.c | 59 ++++++++++++++++++++++++----------
1 files changed, 41 insertions(+), 18 deletions(-)
---
diff --git a/panels/common/cc-language-chooser.c b/panels/common/cc-language-chooser.c
index a54c952..cc88a7b 100644
--- a/panels/common/cc-language-chooser.c
+++ b/panels/common/cc-language-chooser.c
@@ -48,6 +48,7 @@ typedef struct {
gboolean adding_languages;
gboolean showing_extra;
gchar *language;
+ gchar **filter_words;
} CcLanguageChooserPrivate;
#define GET_PRIVATE(chooser) ((CcLanguageChooserPrivate *) g_object_get_data (G_OBJECT (chooser), "private"))
@@ -226,6 +227,19 @@ add_all_languages (GtkDialog *chooser)
}
static gboolean
+match_all (gchar **words,
+ const gchar *str)
+{
+ gchar **w;
+
+ for (w = words; *w; ++w)
+ if (!strstr (str, *w))
+ return FALSE;
+
+ return TRUE;
+}
+
+static gboolean
language_visible (GtkWidget *child,
gpointer user_data)
{
@@ -234,7 +248,6 @@ language_visible (GtkWidget *child,
gchar *locale_name = NULL;
gchar *locale_current_name = NULL;
gchar *locale_untranslated_name = NULL;
- gchar *filter_contents = NULL;
gboolean is_extra;
gboolean visible;
@@ -250,37 +263,28 @@ language_visible (GtkWidget *child,
if (!priv->showing_extra && is_extra)
return FALSE;
- filter_contents =
- cc_util_normalize_casefold_and_unaccent (gtk_entry_get_text (GTK_ENTRY
(priv->filter_entry)));
-
- if (!filter_contents)
+ if (!priv->filter_words)
return TRUE;
visible = FALSE;
locale_name =
cc_util_normalize_casefold_and_unaccent (g_object_get_data (G_OBJECT (child),
"locale-name"));
- if (strstr (locale_name, filter_contents)) {
- visible = TRUE;
+ visible = match_all (priv->filter_words, locale_name);
+ if (visible)
goto out;
- }
locale_current_name =
cc_util_normalize_casefold_and_unaccent (g_object_get_data (G_OBJECT (child),
"locale-current-name"));
- if (strstr (locale_current_name, filter_contents)) {
- visible = TRUE;
+ visible = match_all (priv->filter_words, locale_current_name);
+ if (visible)
goto out;
- }
locale_untranslated_name =
cc_util_normalize_casefold_and_unaccent (g_object_get_data (G_OBJECT (child),
"locale-untranslated-name"));
- if (strstr (locale_untranslated_name, filter_contents)) {
- visible = TRUE;
- goto out;
- }
+ visible = match_all (priv->filter_words, locale_untranslated_name);
out:
- g_free (filter_contents);
g_free (locale_untranslated_name);
g_free (locale_current_name);
g_free (locale_name);
@@ -288,6 +292,25 @@ out:
}
static void
+filter_changed (GtkDialog *chooser)
+{
+ CcLanguageChooserPrivate *priv = GET_PRIVATE (chooser);
+ gchar *filter_contents = NULL;
+
+ g_clear_pointer (&priv->filter_words, g_strfreev);
+
+ filter_contents =
+ cc_util_normalize_casefold_and_unaccent (gtk_entry_get_text (GTK_ENTRY
(priv->filter_entry)));
+ if (!filter_contents) {
+ egg_list_box_refilter (EGG_LIST_BOX (priv->language_list));
+ return;
+ }
+ priv->filter_words = g_strsplit_set (g_strstrip (filter_contents), " ", 0);
+ g_free (filter_contents);
+ egg_list_box_refilter (EGG_LIST_BOX (priv->language_list));
+}
+
+static void
show_more (GtkDialog *chooser)
{
CcLanguageChooserPrivate *priv = GET_PRIVATE (chooser);
@@ -371,6 +394,7 @@ cc_language_chooser_private_free (gpointer data)
{
CcLanguageChooserPrivate *priv = data;
+ g_strfreev (priv->filter_words);
g_free (priv->language);
g_free (priv);
}
@@ -419,8 +443,7 @@ cc_language_chooser_new (GtkWidget *parent)
add_all_languages (GTK_DIALOG (chooser));
g_signal_connect_swapped (priv->filter_entry, "changed",
- G_CALLBACK (egg_list_box_refilter),
- priv->language_list);
+ G_CALLBACK (filter_changed), chooser);
g_signal_connect (priv->language_list, "child-activated",
G_CALLBACK (child_activated), chooser);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]