[gnome-tweak-tool] tweakmodel: Factor out a function to prepare strings for searching



commit 692dbde13777dcc8d2e41590aef2e0a46acd7cca
Author: Rui Matos <tiagomatos gmail com>
Date:   Mon May 29 18:42:56 2017 +0200

    tweakmodel: Factor out a function to prepare strings for searching
    
    And use the GLib utf-8 APIs instead of Python's since those are just
    confusing.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=783141

 gtweak/tweakmodel.py |   11 +++++++----
 gtweak/tweakview.py  |    4 ++--
 2 files changed, 9 insertions(+), 6 deletions(-)
---
diff --git a/gtweak/tweakmodel.py b/gtweak/tweakmodel.py
index 0ad94de..750e108 100644
--- a/gtweak/tweakmodel.py
+++ b/gtweak/tweakmodel.py
@@ -21,7 +21,7 @@ import os.path
 
 import gtweak
 from gtweak.utils import SchemaList, LogoutNotification, Notification
-from gi.repository import Gtk
+from gi.repository import Gtk, GLib
 
 def N_(x): return x
 
@@ -39,6 +39,9 @@ TWEAK_GROUP_FILES = _("Files")
 
 LOG = logging.getLogger(__name__)
 
+def string_for_search(s):
+    return GLib.utf8_casefold(GLib.utf8_normalize(s, -1, GLib.NormalizeMode.ALL), -1)
+
 class Tweak(object):
 
     main_window = None
@@ -57,10 +60,10 @@ class Tweak(object):
 
     def search_matches(self, txt):
         if self._search_cache == None:
-            self._search_cache = self.name.decode("utf-8","ignore").lower() + " " + \
-                                self.description.decode("utf-8","ignore").lower()
+            self._search_cache = string_for_search(self.name) + " " + \
+                                string_for_search(self.description)
             try:
-                self._search_cache += " " + self.extra_info.decode("utf-8","ignore").lower()
+                self._search_cache += " " + string_for_search(self.extra_info)
             except:
                 LOG.warning("Error adding search info", exc_info=True)
         return  txt in self._search_cache
diff --git a/gtweak/tweakview.py b/gtweak/tweakview.py
index 5452540..b0633c8 100644
--- a/gtweak/tweakview.py
+++ b/gtweak/tweakview.py
@@ -23,7 +23,7 @@ import datetime
 from gi.repository import Gtk, Gdk, GObject
 
 import gtweak.tweakmodel
-from gtweak.tweakmodel import TweakModel
+from gtweak.tweakmodel import TweakModel, string_for_search
 from gtweak.widgets import Title
 
 class Window(Gtk.ApplicationWindow):
@@ -245,7 +245,7 @@ class Window(Gtk.ApplicationWindow):
             self.listbox.select_row(row)
 
     def _on_search(self, entry):
-        txt = entry.get_text().decode("utf-8","ignore").lower()
+        txt = string_for_search(entry.get_text())
         tweaks, group = self._model.search_matches(txt)
         self.show_only_tweaks(tweaks)        
         self._on_list_changed(group)


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