From 6c4ef64d96a8060b1752b57ae493ea7c112ce314 Mon Sep 17 00:00:00 2001 From: mailchuck Date: Sat, 12 Mar 2016 10:58:48 +0100 Subject: [PATCH] UTF fixes Label edits now accept and save utf8 characters. Addresses #180 Still need to check how it behaves on invalid chars. --- src/bitmessageqt/__init__.py | 2 +- src/bitmessageqt/foldertree.py | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 5b1abfee..39a5c3f6 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -3999,7 +3999,7 @@ class MyForm(settingsmixin.SMainWindow): if item.type == AccountMixin.ALL: return - newLabel = str(item.text(0)) + newLabel = unicode(item.text(0), 'utf-8', 'ignore') oldLabel = item.defaultLabel() # unchanged, do not do anything either diff --git a/src/bitmessageqt/foldertree.py b/src/bitmessageqt/foldertree.py index b9112b49..370e372f 100644 --- a/src/bitmessageqt/foldertree.py +++ b/src/bitmessageqt/foldertree.py @@ -171,7 +171,7 @@ class Ui_AddressWidget(QtGui.QTreeWidgetItem, AccountMixin, SettingsMixin): return unicode(str(QtGui.QApplication.translate("MainWindow", "All accounts")), 'utf-8') else: try: - return unicode(shared.config.get(self.address, 'label'), 'utf-8)') + return unicode(shared.config.get(self.address, 'label'), 'utf-8', 'ignore') except: return unicode(self.address, 'utf-8') @@ -210,7 +210,7 @@ class Ui_AddressWidget(QtGui.QTreeWidgetItem, AccountMixin, SettingsMixin): def setData(self, column, role, value): if role == QtCore.Qt.EditRole and self.type != AccountMixin.SUBSCRIPTION: if isinstance(value, QtCore.QVariant): - shared.config.set(str(self.address), 'label', str(value.toString())) + shared.config.set(str(self.address), 'label', str(value.toString().toUtf8())) else: shared.config.set(str(self.address), 'label', str(value)) shared.writeKeysFile() @@ -236,8 +236,8 @@ class Ui_AddressWidget(QtGui.QTreeWidgetItem, AccountMixin, SettingsMixin): if self.treeWidget().header().sortIndicatorOrder() == QtCore.Qt.DescendingOrder: reverse = True if self._getSortRank() == other._getSortRank(): - x = self._getLabel().decode('utf-8').lower() - y = other._getLabel().decode('utf-8').lower() + x = self._getLabel().lower() + y = other._getLabel().lower() return x < y return (not reverse if self._getSortRank() < other._getSortRank() else reverse) @@ -261,7 +261,7 @@ class Ui_SubscriptionWidget(Ui_AddressWidget, AccountMixin): if queryreturn != []: for row in queryreturn: retval, = row - return unicode(retval, 'utf-8') + return unicode(retval, 'utf-8', 'ignore') return unicode(self.address, 'utf-8') def setType(self): @@ -270,10 +270,11 @@ class Ui_SubscriptionWidget(Ui_AddressWidget, AccountMixin): def setData(self, column, role, value): if role == QtCore.Qt.EditRole: + from debug import logger if isinstance(value, QtCore.QVariant): - label = str(value.toString()) + label = str(value.toString().toUtf8()).decode('utf-8', 'ignore') else: - label = str(value) + label = unicode(value, 'utf-8', 'ignore') sqlExecute( '''UPDATE subscriptions SET label=? WHERE address=?''', label, self.address) @@ -300,7 +301,7 @@ class MessageList_AddressWidget(QtGui.QTableWidgetItem, AccountMixin, SettingsMi queryreturn = None if self.type in (AccountMixin.NORMAL, AccountMixin.CHAN, AccountMixin.MAILINGLIST): try: - newLabel = unicode(shared.config.get(self.address, 'label'), 'utf-8)') + newLabel = unicode(shared.config.get(self.address, 'label'), 'utf-8', 'ignore') except: queryreturn = sqlQuery( '''select label from addressbook where address=?''', self.address) @@ -455,7 +456,7 @@ class Ui_AddressBookWidgetItem(QtGui.QTableWidgetItem, AccountMixin): if self.tableWidget().horizontalHeader().sortIndicatorOrder() == QtCore.Qt.DescendingOrder: reverse = True if self.type == other.type: - return self.label.decode('utf-8').lower() < other.label.decode('utf-8').lower() + return self.label.lower() < other.label.lower() else: return (not reverse if self.type < other.type else reverse) return super(QtGui.QTableWidgetItem, self).__lt__(other)