# HG changeset patch # User cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1244492582 0 # Node ID 0b1992a3dfe762e607407f7182d0c5431e6e424b # Parent f2195628947b28c226d5e5103b5aee0c27a009e7 Proper decoding of file names for filebrowser diff -r f2195628947b -r 0b1992a3dfe7 engine/extensions/filebrowser.py --- a/engine/extensions/filebrowser.py Mon Jun 08 19:56:54 2009 +0000 +++ b/engine/extensions/filebrowser.py Mon Jun 08 20:23:02 2009 +0000 @@ -2,6 +2,7 @@ import pychan import pychan.widgets as widgets +import sys class FileBrowser(object): """ @@ -24,8 +25,8 @@ self.extensions = extensions self.path = './..' - self.dir_list = ('..',) + self.engine.getVFS().listDirectories(self.path) - self.file_list = self.engine.getVFS().listFiles(self.path) + self.dir_list = [] + self.file_list = [] def showBrowser(self): if self._widget: @@ -53,9 +54,29 @@ else: lst.append(new_dir) self.path = '/'.join(lst) + + + def decodeList(list): + fs_encoding = sys.getfilesystemencoding() + if fs_encoding is None: fs_encoding = "ascii" + + newList = [] + for i in list: + try: + newList.append(unicode(i, fs_encoding)) + except: + newList.append("WARNING: This entry could not be decoded!") + print "WARNING: Coult not decode an item!" + return newList - self.dir_list = ('..',) + filter(lambda d: not d.startswith('.'), self.engine.getVFS().listDirectories(self.path)) - self.file_list = filter(lambda f: f.split('.')[-1] in self.extensions, self.engine.getVFS().listFiles(self.path)) + self.dir_list = [] + self.file_list = [] + + dir_list = ('..',) + filter(lambda d: not d.startswith('.'), self.engine.getVFS().listDirectories(str(self.path))) + file_list = filter(lambda f: f.split('.')[-1] in self.extensions, self.engine.getVFS().listFiles(str(self.path))) + + self.dir_list = decodeList(dir_list) + self.file_list = decodeList(file_list) self._widget.distributeInitialData({ 'dirList' : self.dir_list, 'fileList' : self.file_list