From 879a6f1d68fa76a31cfb198887f8f7c1f8f5d6e8 Mon Sep 17 00:00:00 2001 From: mailchuck Date: Sun, 20 Dec 2015 01:01:11 +0100 Subject: [PATCH] Messagelist loads faster Addresses #149. About 5 times faster. --- src/bitmessageqt/__init__.py | 40 +++------------------ src/bitmessageqt/foldertree.py | 63 +++++++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 37 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index f9d23762..e220c169 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -984,23 +984,9 @@ class MyForm(settingsmixin.SMainWindow): acct.parseMessage(toAddress, fromAddress, subject, "") items = [] - toAddressItem = QtGui.QTableWidgetItem(unicode(acct.toLabel, 'utf-8')) - toAddressItem.setToolTip(unicode(acct.toLabel, 'utf-8') + " (" + str(acct.toAddress) + ")") - toAddressItem.setIcon(avatarize(toAddress)) - toAddressItem.setData(Qt.UserRole, str(toAddress)) - toAddressItem.setTextColor(AccountColor(toAddress).accountColor()) - toAddressItem.setFlags( - QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) - items.append(toAddressItem) + MessageList_AddressWidget(items, str(acct.toAddress), unicode(acct.toLabel, 'utf-8')) - fromAddressItem = QtGui.QTableWidgetItem(unicode(acct.fromLabel, 'utf-8')) - fromAddressItem.setToolTip(unicode(acct.fromLabel, 'utf-8') + " (" + str(acct.fromAddress) + ")") - fromAddressItem.setIcon(avatarize(fromAddress)) - fromAddressItem.setData(Qt.UserRole, str(fromAddress)) - fromAddressItem.setTextColor(AccountColor(fromAddress).accountColor()) - fromAddressItem.setFlags( - QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) - items.append(fromAddressItem) + 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')) @@ -1074,27 +1060,9 @@ class MyForm(settingsmixin.SMainWindow): items = [] #to - to_item = QtGui.QTableWidgetItem(unicode(acct.toLabel, 'utf-8')) - to_item.setToolTip(unicode(acct.toLabel, 'utf-8') + " (" + str(acct.toAddress) + ")") - to_item.setFlags( - QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) - if not read: - to_item.setFont(font) - to_item.setData(Qt.UserRole, str(toAddress)) - to_item.setTextColor(AccountColor(toAddress).accountColor()) - to_item.setIcon(avatarize(toAddress)) - items.append(to_item) + MessageList_AddressWidget(items, str(acct.toAddress), unicode(acct.toLabel, 'utf-8'), not read) # from - from_item = QtGui.QTableWidgetItem(unicode(acct.fromLabel, 'utf-8')) - from_item.setToolTip(unicode(acct.fromLabel, 'utf-8') + " (" + str(fromAddress) + ")") - from_item.setFlags( - QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) - if not read: - from_item.setFont(font) - from_item.setData(Qt.UserRole, str(fromAddress)) - from_item.setTextColor(AccountColor(fromAddress).accountColor()) - from_item.setIcon(avatarize(fromAddress)) - items.append(from_item) + MessageList_AddressWidget(items, str(acct.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')) diff --git a/src/bitmessageqt/foldertree.py b/src/bitmessageqt/foldertree.py index 971cda61..a93862a3 100644 --- a/src/bitmessageqt/foldertree.py +++ b/src/bitmessageqt/foldertree.py @@ -261,8 +261,69 @@ class Ui_SubscriptionWidget(Ui_AddressWidget, AccountMixin): if not self.initialised: return self.emitDataChanged() + + +class MessageList_AddressWidget(QtGui.QTableWidgetItem, AccountMixin, SettingsMixin): + def __init__(self, parent, address = 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.initialised = False + self.isEnabled = True + self.setAddress(address) + self.setLabel(label) + self.setUnread(unread) + self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) + self.initialised = True + self.setType() # does updateText + parent.append(self) + + def setLabel(self, label = None): + if label is None: + label = unicode(shared.config.get(self.address, 'label'), 'utf-8)') + else: + self.label = label + + 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 + " (" + self.address + ")" + elif role == QtCore.Qt.DecorationRole: + if shared.safeConfigGetBoolean('bitmessagesettings', 'useidenticons'): + if self.address is None: + return avatarize(self.label) + else: + return avatarize(self.address) + elif role == QtCore.Qt.FontRole: + font = QtGui.QFont() + font.setBold(self.unread) + return font + elif role == QtCore.Qt.ForegroundRole: + return self.accountBrush() + elif role == QtCore.Qt.UserRole: + return self.address + return super(MessageList_AddressWidget, self).data(role) - + def setData(self, role, value): + if role == QtCore.Qt.EditRole: + self.setLabel() + return + return super(MessageList_AddressWidget, self).setData(role, value) + + # label (or address) alphabetically, disabled at the end + def __lt__(self, other): + if (isinstance(other, MessageList_AddressWidget)): + 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)