[gnome-initial-setup] language: Adapt better matching from cc-language-chooser fork
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-initial-setup] language: Adapt better matching from cc-language-chooser fork
- Date: Fri, 15 Mar 2013 20:54:53 +0000 (UTC)
commit 3454786624f70907f118ecaba46b350e5bb59e58
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Fri Mar 15 16:40:42 2013 -0400
language: Adapt better matching from cc-language-chooser fork
Originally written by Rui Matos. Hopefully soon we can merge
our changes back with cc-language-chooser.
gnome-initial-setup/pages/language/Makefile.am | 1 +
gnome-initial-setup/pages/language/cc-util.c | 105 ++++++++++++++++++++
gnome-initial-setup/pages/language/cc-util.h | 28 +++++
.../pages/language/gis-language-page.c | 54 +++++++++--
4 files changed, 181 insertions(+), 7 deletions(-)
---
diff --git a/gnome-initial-setup/pages/language/Makefile.am b/gnome-initial-setup/pages/language/Makefile.am
index 1d4e473..b70f919 100644
--- a/gnome-initial-setup/pages/language/Makefile.am
+++ b/gnome-initial-setup/pages/language/Makefile.am
@@ -19,6 +19,7 @@ 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 \
gis-language-page.c gis-language-page.h \
$(BUILT_SOURCES)
diff --git a/gnome-initial-setup/pages/language/cc-util.c b/gnome-initial-setup/pages/language/cc-util.c
new file mode 100644
index 0000000..7a3366c
--- /dev/null
+++ b/gnome-initial-setup/pages/language/cc-util.c
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2012 Giovanni Campagna <scampa giovanni gmail com>
+ *
+ * The Control Center is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * The Control Center is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with the Control Center; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <glib/gi18n.h>
+
+#include "cc-util.h"
+
+/* Combining diacritical mark?
+ * Basic range: [0x0300,0x036F]
+ * Supplement: [0x1DC0,0x1DFF]
+ * For Symbols: [0x20D0,0x20FF]
+ * Half marks: [0xFE20,0xFE2F]
+ */
+#define IS_CDM_UCS4(c) (((c) >= 0x0300 && (c) <= 0x036F) || \
+ ((c) >= 0x1DC0 && (c) <= 0x1DFF) || \
+ ((c) >= 0x20D0 && (c) <= 0x20FF) || \
+ ((c) >= 0xFE20 && (c) <= 0xFE2F))
+
+/* Copied from tracker/src/libtracker-fts/tracker-parser-glib.c under the GPL
+ * And then from gnome-shell/src/shell-util.c
+ *
+ * Originally written by Aleksander Morgado <aleksander gnu org>
+ */
+char *
+cc_util_normalize_casefold_and_unaccent (const char *str)
+{
+ char *normalized, *tmp;
+ int i = 0, j = 0, ilen;
+
+ if (str == NULL)
+ return NULL;
+
+ normalized = g_utf8_normalize (str, -1, G_NORMALIZE_NFKD);
+ tmp = g_utf8_casefold (normalized, -1);
+ g_free (normalized);
+
+ ilen = strlen (tmp);
+
+ while (i < ilen)
+ {
+ gunichar unichar;
+ gchar *next_utf8;
+ gint utf8_len;
+
+ /* Get next character of the word as UCS4 */
+ unichar = g_utf8_get_char_validated (&tmp[i], -1);
+
+ /* Invalid UTF-8 character or end of original string. */
+ if (unichar == (gunichar) -1 ||
+ unichar == (gunichar) -2)
+ {
+ break;
+ }
+
+ /* Find next UTF-8 character */
+ next_utf8 = g_utf8_next_char (&tmp[i]);
+ utf8_len = next_utf8 - &tmp[i];
+
+ if (IS_CDM_UCS4 ((guint32) unichar))
+ {
+ /* If the given unichar is a combining diacritical mark,
+ * just update the original index, not the output one */
+ i += utf8_len;
+ continue;
+ }
+
+ /* If already found a previous combining
+ * diacritical mark, indexes are different so
+ * need to copy characters. As output and input
+ * buffers may overlap, need to use memmove
+ * instead of memcpy */
+ if (i != j)
+ {
+ memmove (&tmp[j], &tmp[i], utf8_len);
+ }
+
+ /* Update both indexes */
+ i += utf8_len;
+ j += utf8_len;
+ }
+
+ /* Force proper string end */
+ tmp[j] = '\0';
+
+ return tmp;
+}
diff --git a/gnome-initial-setup/pages/language/cc-util.h b/gnome-initial-setup/pages/language/cc-util.h
new file mode 100644
index 0000000..42b09ff
--- /dev/null
+++ b/gnome-initial-setup/pages/language/cc-util.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2012 Giovanni Campagna <scampa giovanni gmail com>
+ *
+ * The Control Center is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * The Control Center is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with the Control Center; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+
+#ifndef _CC_UTIL_H
+#define _CC_UTIL_H
+
+#include <glib.h>
+
+char *cc_util_normalize_casefold_and_unaccent (const char *str);
+
+#endif
diff --git a/gnome-initial-setup/pages/language/gis-language-page.c
b/gnome-initial-setup/pages/language/gis-language-page.c
index 0112fda..d87c49a 100644
--- a/gnome-initial-setup/pages/language/gis-language-page.c
+++ b/gnome-initial-setup/pages/language/gis-language-page.c
@@ -39,6 +39,7 @@
#include <libgnome-desktop/gnome-languages.h>
#include "cc-common-language.h"
+#include "cc-util.h"
#include <glib-object.h>
@@ -75,6 +76,8 @@ typedef struct {
gchar *locale_id;
gchar *locale_name;
+ gchar *locale_current_name;
+ gchar *locale_untranslated_name;
gboolean is_extra;
} LanguageWidget;
@@ -142,6 +145,8 @@ language_widget_free (gpointer data)
* children again. */
g_free (widget->locale_id);
g_free (widget->locale_name);
+ g_free (widget->locale_current_name);
+ g_free (widget->locale_untranslated_name);
g_free (widget);
}
@@ -158,14 +163,18 @@ static GtkWidget *
language_widget_new (const char *locale_id,
gboolean is_extra)
{
- gchar *locale_name;
+ gchar *locale_name, *locale_current_name, *locale_untranslated_name;
LanguageWidget *widget = g_new0 (LanguageWidget, 1);
locale_name = gnome_get_language_from_locale (locale_id, locale_id);
+ locale_current_name = gnome_get_language_from_locale (locale_id, NULL);
+ locale_untranslated_name = gnome_get_language_from_locale (locale_id, "C");
widget->box = padded_label_new (locale_name);
widget->locale_id = g_strdup (locale_id);
widget->locale_name = locale_name;
+ widget->locale_current_name = locale_current_name;
+ widget->locale_untranslated_name = locale_untranslated_name;
widget->is_extra = is_extra;
widget->checkmark = gtk_image_new_from_icon_name ("object-select-symbolic", GTK_ICON_SIZE_MENU);
@@ -253,8 +262,12 @@ language_visible (GtkWidget *child,
{
GisLanguagePage *page = user_data;
GisLanguagePagePrivate *priv = page->priv;
- const gchar *filter_contents;
+ gchar *locale_name = NULL;
+ gchar *locale_current_name = NULL;
+ gchar *locale_untranslated_name = NULL;
+ gchar *filter_contents = NULL;
LanguageWidget *widget;
+ gboolean visible;
if (child == priv->more_item)
return !priv->showing_extra;
@@ -265,14 +278,41 @@ language_visible (GtkWidget *child,
widget = get_language_widget (child);
- filter_contents = gtk_entry_get_text (GTK_ENTRY (priv->filter_entry));
- if (*filter_contents && strcasestr (widget->locale_name, filter_contents) == NULL)
- return FALSE;
-
if (!priv->showing_extra && !widget->is_extra)
return FALSE;
- return TRUE;
+ filter_contents =
+ cc_util_normalize_casefold_and_unaccent (gtk_entry_get_text (GTK_ENTRY (priv->filter_entry)));
+
+ if (!filter_contents)
+ return TRUE;
+
+ visible = FALSE;
+
+ locale_name = cc_util_normalize_casefold_and_unaccent (widget->locale_name);
+ if (strstr (locale_name, filter_contents)) {
+ visible = TRUE;
+ goto out;
+ }
+
+ locale_current_name = cc_util_normalize_casefold_and_unaccent (widget->locale_current_name);
+ if (strstr (locale_current_name, filter_contents)) {
+ visible = TRUE;
+ goto out;
+ }
+
+ locale_untranslated_name = cc_util_normalize_casefold_and_unaccent (widget->locale_untranslated_name);
+ if (strstr (locale_untranslated_name, filter_contents)) {
+ visible = TRUE;
+ goto out;
+ }
+
+ out:
+ g_free (filter_contents);
+ g_free (locale_untranslated_name);
+ g_free (locale_current_name);
+ g_free (locale_name);
+ return visible;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]