[gnome-initial-setup] cc-language-chooser: Use glib for string searching



commit fc481ff1ef27c1066845480c9092031582289b62
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Fri Nov 1 02:18:19 2013 -0400

    cc-language-chooser: Use glib for string searching
    
    ... and move cc-util to keyboard/, since it depends on it, and --as-needed
    will remove it before the keyboard page has a chance to link to it.

 gnome-initial-setup/pages/keyboard/Makefile.am     |    1 +
 .../pages/keyboard/cc-input-chooser.c              |    2 +-
 .../pages/{language => keyboard}/cc-util.c         |    0
 .../pages/{language => keyboard}/cc-util.h         |    0
 gnome-initial-setup/pages/language/Makefile.am     |    1 -
 .../pages/language/cc-language-chooser.c           |   56 +++-----------------
 6 files changed, 9 insertions(+), 51 deletions(-)
---
diff --git a/gnome-initial-setup/pages/keyboard/Makefile.am b/gnome-initial-setup/pages/keyboard/Makefile.am
index 1d8831d..4fd4d11 100644
--- a/gnome-initial-setup/pages/keyboard/Makefile.am
+++ b/gnome-initial-setup/pages/keyboard/Makefile.am
@@ -18,6 +18,7 @@ BUILT_SOURCES += keyboard-resources.c keyboard-resources.h
 libgiskeyboard_la_SOURCES =                            \
        cc-input-chooser.c cc-input-chooser.h           \
        cc-ibus-utils.c cc-ibus-utils.h                 \
+       cc-util.c cc-util.h                             \
        gis-keyboard-page.c gis-keyboard-page.h         \
        $(BUILT_SOURCES)
 
diff --git a/gnome-initial-setup/pages/keyboard/cc-input-chooser.c 
b/gnome-initial-setup/pages/keyboard/cc-input-chooser.c
index 86e7e8d..3b0371f 100644
--- a/gnome-initial-setup/pages/keyboard/cc-input-chooser.c
+++ b/gnome-initial-setup/pages/keyboard/cc-input-chooser.c
@@ -25,8 +25,8 @@
 #include <libgnome-desktop/gnome-languages.h>
 
 #include <../language/cc-common-language.h>
-#include <../language/cc-util.h>
 #include "cc-input-chooser.h"
+#include "cc-util.h"
 
 #ifdef HAVE_IBUS
 #include <ibus.h>
diff --git a/gnome-initial-setup/pages/language/cc-util.c b/gnome-initial-setup/pages/keyboard/cc-util.c
similarity index 100%
rename from gnome-initial-setup/pages/language/cc-util.c
rename to gnome-initial-setup/pages/keyboard/cc-util.c
diff --git a/gnome-initial-setup/pages/language/cc-util.h b/gnome-initial-setup/pages/keyboard/cc-util.h
similarity index 100%
rename from gnome-initial-setup/pages/language/cc-util.h
rename to gnome-initial-setup/pages/keyboard/cc-util.h
diff --git a/gnome-initial-setup/pages/language/Makefile.am b/gnome-initial-setup/pages/language/Makefile.am
index 13d95cf..cca48f9 100644
--- a/gnome-initial-setup/pages/language/Makefile.am
+++ b/gnome-initial-setup/pages/language/Makefile.am
@@ -19,7 +19,6 @@ BUILT_SOURCES += language-resources.c language-resources.h
 
 libgislanguage_la_SOURCES =                            \
        cc-common-language.c cc-common-language.h       \
-       cc-util.c cc-util.h                             \
        cc-language-chooser.c cc-language-chooser.h     \
        gis-welcome-widget.c gis-welcome-widget.h       \
        gis-language-page.c gis-language-page.h         \
diff --git a/gnome-initial-setup/pages/language/cc-language-chooser.c 
b/gnome-initial-setup/pages/language/cc-language-chooser.c
index 26b9167..e85ac3c 100644
--- a/gnome-initial-setup/pages/language/cc-language-chooser.c
+++ b/gnome-initial-setup/pages/language/cc-language-chooser.c
@@ -35,7 +35,6 @@
 #include <libgnome-desktop/gnome-languages.h>
 
 #include "cc-common-language.h"
-#include "cc-util.h"
 
 #include <glib-object.h>
 
@@ -48,7 +47,6 @@ struct _CcLanguageChooserPrivate
         GtkWidget *more_item;
 
         gboolean showing_extra;
-        gchar **filter_words;
         gchar *language;
 };
 typedef struct _CcLanguageChooserPrivate CcLanguageChooserPrivate;
@@ -246,30 +244,15 @@ add_all_languages (CcLanguageChooser *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 (GtkListBoxRow *row,
                   gpointer       user_data)
 {
         CcLanguageChooser *chooser = user_data;
         CcLanguageChooserPrivate *priv = cc_language_chooser_get_instance_private (chooser);
-        gchar *locale_name = NULL;
-        gchar *locale_current_name = NULL;
-        gchar *locale_untranslated_name = NULL;
         LanguageWidget *widget;
         gboolean visible;
         GtkWidget *child;
+        const char *search_term;
 
         child = gtk_bin_get_child (GTK_BIN (row));
         if (child == priv->more_item)
@@ -280,30 +263,25 @@ language_visible (GtkListBoxRow *row,
         if (!priv->showing_extra && widget->is_extra)
                 return FALSE;
 
-        if (!priv->filter_words)
-                return TRUE;
+        search_term = gtk_entry_get_text (GTK_ENTRY (priv->filter_entry));
+        if (!search_term || !*search_term)
+                return FALSE;
 
         visible = FALSE;
 
-        locale_name = cc_util_normalize_casefold_and_unaccent (widget->locale_name);
-        visible = match_all (priv->filter_words, locale_name);
+        visible = g_str_match_string (search_term, widget->locale_name, TRUE);
         if (visible)
                 goto out;
 
-        locale_current_name = cc_util_normalize_casefold_and_unaccent (widget->locale_current_name);
-        visible = match_all (priv->filter_words, locale_current_name);
+        visible = g_str_match_string (search_term, widget->locale_current_name, TRUE);
         if (visible)
                 goto out;
 
-        locale_untranslated_name = cc_util_normalize_casefold_and_unaccent 
(widget->locale_untranslated_name);
-        visible = match_all (priv->filter_words, locale_untranslated_name);
+        visible = g_str_match_string (search_term, widget->locale_untranslated_name, TRUE);
         if (visible)
                 goto out;
 
  out:
-        g_free (locale_untranslated_name);
-        g_free (locale_current_name);
-        g_free (locale_name);
         return visible;
 }
 
@@ -337,16 +315,6 @@ filter_changed (GtkEntry        *entry,
                 CcLanguageChooser *chooser)
 {
         CcLanguageChooserPrivate *priv = cc_language_chooser_get_instance_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)
-                return;
-        priv->filter_words = g_strsplit_set (g_strstrip (filter_contents), " ", 0);
-        g_free (filter_contents);
         gtk_list_box_invalidate_filter (GTK_LIST_BOX (priv->language_list));
 }
 
@@ -490,15 +458,6 @@ cc_language_chooser_set_property (GObject      *object,
 }
 
 static void
-cc_language_chooser_finalize (GObject *object)
-{
-        CcLanguageChooser *chooser = CC_LANGUAGE_CHOOSER (object);
-        CcLanguageChooserPrivate *priv = cc_language_chooser_get_instance_private (chooser);
-
-        g_strfreev (priv->filter_words);
-}
-
-static void
 cc_language_chooser_class_init (CcLanguageChooserClass *klass)
 {
         GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -510,7 +469,6 @@ cc_language_chooser_class_init (CcLanguageChooserClass *klass)
 
         object_class->get_property = cc_language_chooser_get_property;
         object_class->set_property = cc_language_chooser_set_property;
-        object_class->finalize = cc_language_chooser_finalize;
         object_class->constructed = cc_language_chooser_constructed;
 
         obj_props[PROP_LANGUAGE] =


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]