From e5d1ac0d6935f2e227114d1702dedafb163acba9 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?R=C3=A9mi=20Vanicat?= Date: Mon, 18 Jun 2007 21:16:06 +0200 Subject: [PATCH] Make quodlibet to use LC_LOCATE locale to sort --- quodlibet/browsers/albums.py | 6 +++--- quodlibet/browsers/paned.py | 4 ++-- quodlibet/qltk/information.py | 8 ++++---- quodlibet/qltk/songlist.py | 4 ++-- quodlibet/util/__init__.py | 20 ++++++++++++++++++++ 5 files changed, 31 insertions(+), 11 deletions(-) diff --git a/quodlibet/browsers/albums.py b/quodlibet/browsers/albums.py index 84a8d1c..83abe6e 100644 --- a/quodlibet/browsers/albums.py +++ b/quodlibet/browsers/albums.py @@ -382,7 +382,7 @@ class AlbumList(Browser, gtk.VBox, util.InstanceTracker): if (a1 and a2) is None: return cmp(a1, a2) elif not a1.title: return 1 elif not a2.title: return -1 - else: return cmp(a1.key, a2.key) + else: return util.strcoll(a1.key, a2.key) def __compare_artist(self, model, i1, i2): a1, a2 = model[i1][0], model[i2][0] @@ -391,8 +391,8 @@ class AlbumList(Browser, gtk.VBox, util.InstanceTracker): elif not a2.title: return -1 elif not a1.people and a2.people: return 1 elif not a2.people and a1.people: return -1 - else: return (cmp(a1.people and a1.people[0], - a2.people and a2.people[0]) or + else: return (util.strcoll(a1.people and a1.people[0], + a2.people and a2.people[0]) or cmp(a1.date or "ZZZZ", a2.date or "ZZZZ") or cmp(a1.key, a2.key)) diff --git a/quodlibet/browsers/paned.py b/quodlibet/browsers/paned.py index 2533b16..a4c0565 100644 --- a/quodlibet/browsers/paned.py +++ b/quodlibet/browsers/paned.py @@ -251,7 +251,7 @@ class PanedBrowser(gtk.VBox, Browser, util.InstanceTracker): new[val].add(song) if new: - keys = sorted(new.keys()) + keys = sorted(new.keys(),key=util.strxfrm) if keys[0] == "": unknown = new[""] keys.pop(0) @@ -260,7 +260,7 @@ class PanedBrowser(gtk.VBox, Browser, util.InstanceTracker): if row[0][0] == "<": continue elif not keys: break - if util.unescape(row[0]) > keys[0]: + if util.strcoll(util.unescape(row[0]),keys[0]) > 0: key = keys.pop(0) model.insert_before( row.iter, row=[util.escape(key), new[key]]) diff --git a/quodlibet/qltk/information.py b/quodlibet/qltk/information.py index 71f04b6..857b23d 100644 --- a/quodlibet/qltk/information.py +++ b/quodlibet/qltk/information.py @@ -349,8 +349,8 @@ class OneAlbum(qltk.Notebook): artists.update(song.list("artist")) performers.update(song.list("performer")) - artists = sorted(artists) - performers = sorted(performers) + artists = sorted(artists,key=util.strxfrm) + performers = sorted(performers,key=util.strxfrm) if artists: if len(artists) == 1: title = _("artist") @@ -485,7 +485,7 @@ class ManySongs(qltk.Notebook): for song in songs: if "artist" in song: artists.update(song.list("artist")) else: none += 1 - artists = sorted(artists) + artists = sorted(artists,key=util.strxfrm) num_artists = len(artists) if none: artists.append(ngettext("%d song with no artist", @@ -501,7 +501,7 @@ class ManySongs(qltk.Notebook): for song in songs: if "album" in song: albums.update(song.list("album")) else: none += 1 - albums = sorted(albums) + albums = sorted(albums,key=util.strxfrm) num_albums = len(albums) if none: albums.append(ngettext("%d song with no album", diff --git a/quodlibet/qltk/songlist.py b/quodlibet/qltk/songlist.py index ffc9111..6893e19 100644 --- a/quodlibet/qltk/songlist.py +++ b/quodlibet/qltk/songlist.py @@ -733,9 +733,9 @@ class SongList(AllTreeView, util.InstanceTracker): if callable(tag): # A pattern is currently selected. - sort_func = lambda song: (tag(song), song.sort_key, song) + sort_func = lambda song: (util.strxfrm(tag(song)), song.sort_key, song) else: - sort_func = lambda song: (song(tag), song.sort_key, song) + sort_func = lambda song: (util.strxfrm(song(tag)), song.sort_key, song) songs.sort(key=sort_func, reverse=reverse) else: self.set_sort_by(None, refresh=False) diff --git a/quodlibet/util/__init__.py b/quodlibet/util/__init__.py index 176785e..fd22cbc 100644 --- a/quodlibet/util/__init__.py +++ b/quodlibet/util/__init__.py @@ -174,6 +174,26 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. return transopts, args +def to(string, frm="utf-8"): + """Convert a string to the system encoding; used if you need to + print to stdout. If you pass in a str (rather than a unicode) you + should specify the encoding it's in with 'frm'.""" + if isinstance(string, unicode): + return string.encode(ENCODING, "replace") + else: + return string.decode(frm).encode(ENCODING, "replace") + +def strcoll(string1,string2): + """compare two unicode string according to LC_COLLATE + """ + return locale.strcoll(to(string1),to(string2)) + +def strxfrm(string): + """transform a string with strxfrm, + return the argument unchanded when there is an AttributeError""" + try: return locale.strxfrm(to(string)) + except AttributeError: return string + def mtime(filename): """Return the mtime of a file, or 0 if an error occurs.""" try: return os.path.getmtime(filename) -- 1.5.2.1