From 3b30afea29dec4d8f2cadccd956d7ec61ec13fd1 Mon Sep 17 00:00:00 2001 From: mailchuck Date: Mon, 21 Dec 2015 21:08:28 +0100 Subject: [PATCH] Messagelist subject class Messagelist subjects now are their own class. Fixes #153 Also fixes replies/clipboard for gatewayed messages. --- src/bitmessageqt/__init__.py | 36 ++++++++------------------ src/bitmessageqt/foldertree.py | 46 ++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 25 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index a894db21..a193b1c6 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -984,16 +984,9 @@ class MyForm(settingsmixin.SMainWindow): acct.parseMessage(toAddress, fromAddress, subject, "") items = [] - MessageList_AddressWidget(items, str(acct.toAddress), unicode(acct.toLabel, 'utf-8')) - - MessageList_AddressWidget(items, str(acct.fromAddress), unicode(acct.fromLabel, 'utf-8')) - - subjectItem = QtGui.QTableWidgetItem(unicode(acct.subject, 'utf-8')) - subjectItem.setToolTip(unicode(acct.subject, 'utf-8')) - subjectItem.setData(Qt.UserRole, str(subject)) - subjectItem.setFlags( - QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) - items.append(subjectItem) + MessageList_AddressWidget(items, str(toAddress), unicode(acct.toLabel, 'utf-8')) + MessageList_AddressWidget(items, str(fromAddress), unicode(acct.fromLabel, 'utf-8')) + MessageList_SubjectWidget(items, str(subject), unicode(acct.subject, 'utf-8')) if status == 'awaitingpubkey': statusText = _translate( @@ -1060,18 +1053,11 @@ class MyForm(settingsmixin.SMainWindow): items = [] #to - MessageList_AddressWidget(items, str(acct.toAddress), unicode(acct.toLabel, 'utf-8'), not read) + MessageList_AddressWidget(items, toAddress, unicode(acct.toLabel, 'utf-8'), not read) # from - MessageList_AddressWidget(items, str(acct.fromAddress), unicode(acct.fromLabel, 'utf-8'), not read) + MessageList_AddressWidget(items, fromAddress, unicode(acct.fromLabel, 'utf-8'), not read) # subject - subject_item = QtGui.QTableWidgetItem(unicode(acct.subject, 'utf-8')) - subject_item.setToolTip(unicode(acct.subject, 'utf-8')) - subject_item.setData(Qt.UserRole, str(subject)) - subject_item.setFlags( - QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) - if not read: - subject_item.setFont(font) - items.append(subject_item) + MessageList_SubjectWidget(items, str(subject), unicode(acct.subject, 'utf-8'), not read) # time received time_item = myTableWidgetItem(l10n.formatTimestamp(received)) time_item.setToolTip(l10n.formatTimestamp(received)) @@ -3000,7 +2986,7 @@ class MyForm(settingsmixin.SMainWindow): inventoryHashesToMarkUnread.append(inventoryHashToMarkUnread) tableWidget.item(currentRow, 0).setUnread(True) tableWidget.item(currentRow, 1).setUnread(True) - tableWidget.item(currentRow, 2).setFont(font) + tableWidget.item(currentRow, 2).setUnread(True) tableWidget.item(currentRow, 3).setFont(font) #sqlite requires the exact number of ?s to prevent injection sqlExecute('''UPDATE inbox SET read=0 WHERE msgid IN (%s)''' % ( @@ -3064,7 +3050,7 @@ class MyForm(settingsmixin.SMainWindow): if queryreturn != []: for row in queryreturn: messageAtCurrentInboxRow, = row - acct.parseMessage(toAddressAtCurrentInboxRow, fromAddressAtCurrentInboxRow, unicode(tableWidget.item(currentInboxRow, 2).data(Qt.UserRole).toPyObject(), 'utf-8'), messageAtCurrentInboxRow) + acct.parseMessage(toAddressAtCurrentInboxRow, fromAddressAtCurrentInboxRow, tableWidget.item(currentInboxRow, 2).subject, messageAtCurrentInboxRow) widget = { 'subject': self.ui.lineEditSubject, 'from': self.ui.comboBoxSendFrom, @@ -3148,7 +3134,7 @@ class MyForm(settingsmixin.SMainWindow): queryreturn = sqlQuery('''select * from blacklist where address=?''', addressAtCurrentInboxRow) if queryreturn == []: - label = "\"" + unicode(tableWidget.item(currentInboxRow, 2).data(Qt.UserRole).toString(), 'utf-8') + "\" in " + shared.config.get(recipientAddress, "label") + label = "\"" + tableWidget.item(currentInboxRow, 2).subject + "\" in " + shared.config.get(recipientAddress, "label") sqlExecute('''INSERT INTO blacklist VALUES (?,?, ?)''', label, addressAtCurrentInboxRow, True) @@ -3219,7 +3205,7 @@ class MyForm(settingsmixin.SMainWindow): return currentInboxRow = tableWidget.currentRow() try: - subjectAtCurrentInboxRow = str(tableWidget.item(currentInboxRow,2).text()) + subjectAtCurrentInboxRow = str(tableWidget.item(currentInboxRow,2).data(Qt.UserRole)) except: subjectAtCurrentInboxRow = '' @@ -4017,7 +4003,7 @@ class MyForm(settingsmixin.SMainWindow): # inventoryHashesToMarkRead.append(inventoryHashToMarkRead) tableWidget.item(currentRow, 0).setUnread(False) tableWidget.item(currentRow, 1).setUnread(False) - tableWidget.item(currentRow, 2).setFont(font) + tableWidget.item(currentRow, 2).setUnread(False) tableWidget.item(currentRow, 3).setFont(font) self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget == self.ui.tableWidgetInboxSubscriptions else 0).data(Qt.UserRole), folder, self.getCurrentTreeWidget(), -1) diff --git a/src/bitmessageqt/foldertree.py b/src/bitmessageqt/foldertree.py index 6715b183..6d81f143 100644 --- a/src/bitmessageqt/foldertree.py +++ b/src/bitmessageqt/foldertree.py @@ -324,6 +324,52 @@ class MessageList_AddressWidget(QtGui.QTableWidgetItem, AccountMixin, SettingsMi return super(QtGui.QTableWidgetItem, self).__lt__(other) +class MessageList_SubjectWidget(QtGui.QTableWidgetItem, SettingsMixin): + def __init__(self, parent, subject = None, label = None, unread = False): + super(QtGui.QTableWidgetItem, self).__init__() + #parent.insertTopLevelItem(pos, self) + # only set default when creating + #super(QtGui.QTreeWidgetItem, self).setExpanded(shared.config.getboolean(self.address, 'enabled')) + self.setSubject(subject) + self.setLabel(label) + self.setUnread(unread) + self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) + parent.append(self) + + def setLabel(self, label): + self.label = label + + def setSubject(self, subject): + self.subject = subject + + def setUnread(self, unread): + self.unread = unread + + def data(self, role): + if role == QtCore.Qt.DisplayRole: + return self.label + elif role == QtCore.Qt.EditRole: + return self.label + elif role == QtCore.Qt.ToolTipRole: + return self.label + elif role == QtCore.Qt.FontRole: + font = QtGui.QFont() + font.setBold(self.unread) + return font + elif role == QtCore.Qt.UserRole: + return self.subject + return super(MessageList_SubjectWidget, self).data(role) + + def setData(self, role, value): + return super(MessageList_SubjectWidget, self).setData(role, value) + + # label (or address) alphabetically, disabled at the end + def __lt__(self, other): + if (isinstance(other, MessageList_SubjectWidget)): + return self.label.lower() < other.label.lower() + return super(QtGui.QTableWidgetItem, self).__lt__(other) + + class Ui_AddressBookWidgetItem(QtGui.QTableWidgetItem, AccountMixin): def __init__ (self, text, type = AccountMixin.NORMAL): super(QtGui.QTableWidgetItem, self).__init__(text)