Address Qt.UserData fix

The previous commit broke places where UserData was read from the
mesagelist line, because it's now a string rather than a QVariant. This
actually simplifies things.
This commit is contained in:
mailchuck 2015-12-20 01:21:54 +01:00
parent 33064601ac
commit 1c084a80b5
Signed by untrusted user who does not match committer: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
2 changed files with 50 additions and 48 deletions

View File

@ -1897,8 +1897,8 @@ class MyForm(settingsmixin.SMainWindow):
continue continue
for i in range(sent.rowCount()): for i in range(sent.rowCount()):
rowAddress = str(sent.item( rowAddress = sent.item(
i, 0).data(Qt.UserRole).toPyObject()) i, 0).data(Qt.UserRole)
if toAddress == rowAddress: if toAddress == rowAddress:
sent.item(i, 3).setToolTip(textToDisplay) sent.item(i, 3).setToolTip(textToDisplay)
try: try:
@ -1917,8 +1917,8 @@ class MyForm(settingsmixin.SMainWindow):
if self.getCurrentFolder(treeWidget) != "sent": if self.getCurrentFolder(treeWidget) != "sent":
continue continue
for i in range(sent.rowCount()): for i in range(sent.rowCount()):
toAddress = str(sent.item( toAddress = sent.item(
i, 0).data(Qt.UserRole).toPyObject()) i, 0).data(Qt.UserRole)
tableAckdata = sent.item( tableAckdata = sent.item(
i, 3).data(Qt.UserRole).toPyObject() i, 3).data(Qt.UserRole).toPyObject()
status, addressVersionNumber, streamNumber, ripe = decodeAddress( status, addressVersionNumber, streamNumber, ripe = decodeAddress(
@ -1945,7 +1945,7 @@ class MyForm(settingsmixin.SMainWindow):
self.statusBar().showMessage(_translate( self.statusBar().showMessage(_translate(
"MainWindow", "Message trashed")) "MainWindow", "Message trashed"))
treeWidget = self.widgetConvert(inbox) treeWidget = self.widgetConvert(inbox)
self.propagateUnreadCount(str(inbox.item(i, 1 if inbox == self.ui.tableWidgetInboxSubscriptions else 0).data(Qt.UserRole).toPyObject()), self.getCurrentFolder(treeWidget), treeWidget, 0) self.propagateUnreadCount(inbox.item(i, 1 if inbox == self.ui.tableWidgetInboxSubscriptions else 0).data(Qt.UserRole), self.getCurrentFolder(treeWidget), treeWidget, 0)
inbox.removeRow(i) inbox.removeRow(i)
break break
@ -1981,8 +1981,8 @@ class MyForm(settingsmixin.SMainWindow):
def rerenderInboxFromLabels(self): def rerenderInboxFromLabels(self):
for i in range(self.ui.tableWidgetInbox.rowCount()): for i in range(self.ui.tableWidgetInbox.rowCount()):
addressToLookup = str(self.ui.tableWidgetInbox.item( addressToLookup = self.ui.tableWidgetInbox.item(
i, 1).data(Qt.UserRole).toPyObject()) i, 1).data(Qt.UserRole)
fromLabel = '' fromLabel = ''
queryreturn = sqlQuery( queryreturn = sqlQuery(
'''select label from addressbook where address=?''', addressToLookup) '''select label from addressbook where address=?''', addressToLookup)
@ -2021,8 +2021,8 @@ class MyForm(settingsmixin.SMainWindow):
def rerenderInboxToLabels(self): def rerenderInboxToLabels(self):
for i in range(self.ui.tableWidgetInbox.rowCount()): for i in range(self.ui.tableWidgetInbox.rowCount()):
toAddress = str(self.ui.tableWidgetInbox.item( toAddress = self.ui.tableWidgetInbox.item(
i, 0).data(Qt.UserRole).toPyObject()) i, 0).data(Qt.UserRole)
# Message might be to an address we own like a chan address. Let's look for that label. # Message might be to an address we own like a chan address. Let's look for that label.
if shared.config.has_section(toAddress): if shared.config.has_section(toAddress):
toLabel = shared.config.get(toAddress, 'label') toLabel = shared.config.get(toAddress, 'label')
@ -2044,8 +2044,8 @@ class MyForm(settingsmixin.SMainWindow):
def rerenderSentFromLabels(self): def rerenderSentFromLabels(self):
for i in range(self.ui.tableWidgetInbox.rowCount()): for i in range(self.ui.tableWidgetInbox.rowCount()):
fromAddress = str(self.ui.tableWidgetInbox.item( fromAddress = self.ui.tableWidgetInbox.item(
i, 1).data(Qt.UserRole).toPyObject()) i, 1).data(Qt.UserRole)
# Message might be from an address we own like a chan address. Let's look for that label. # Message might be from an address we own like a chan address. Let's look for that label.
if shared.config.has_section(fromAddress): if shared.config.has_section(fromAddress):
fromLabel = shared.config.get(fromAddress, 'label') fromLabel = shared.config.get(fromAddress, 'label')
@ -2058,8 +2058,8 @@ class MyForm(settingsmixin.SMainWindow):
def rerenderSentToLabels(self): def rerenderSentToLabels(self):
for i in range(self.ui.tableWidgetInbox.rowCount()): for i in range(self.ui.tableWidgetInbox.rowCount()):
addressToLookup = str(self.ui.tableWidgetInbox.item( addressToLookup = self.ui.tableWidgetInbox.item(
i, 0).data(Qt.UserRole).toPyObject()) i, 0).data(Qt.UserRole)
toLabel = '' toLabel = ''
queryreturn = sqlQuery( queryreturn = sqlQuery(
'''select label from addressbook where address=?''', addressToLookup) '''select label from addressbook where address=?''', addressToLookup)
@ -3004,9 +3004,9 @@ class MyForm(settingsmixin.SMainWindow):
"?," * len(inventoryHashesToMarkUnread))[:-1], *inventoryHashesToMarkUnread) "?," * len(inventoryHashesToMarkUnread))[:-1], *inventoryHashesToMarkUnread)
if modified == 1: if modified == 1:
# performance optimisation # performance optimisation
self.propagateUnreadCount(str(tableWidget.item(currentRow, 1 if tableWidget == self.ui.tableWidgetInboxSubscriptions else 0).data(Qt.UserRole).toPyObject()), self.getCurrentFolder()) self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget == self.ui.tableWidgetInboxSubscriptions else 0).data(Qt.UserRole), self.getCurrentFolder())
else: else:
self.propagateUnreadCount(str(tableWidget.item(currentRow, 1 if tableWidget == self.ui.tableWidgetInboxSubscriptions else 0).data(Qt.UserRole).toPyObject()), self.getCurrentFolder(), self.getCurrentTreeWidget(), 0) self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget == self.ui.tableWidgetInboxSubscriptions else 0).data(Qt.UserRole), self.getCurrentFolder(), self.getCurrentTreeWidget(), 0)
# tableWidget.selectRow(currentRow + 1) # tableWidget.selectRow(currentRow + 1)
# This doesn't de-select the last message if you try to mark it unread, but that doesn't interfere. Might not be necessary. # This doesn't de-select the last message if you try to mark it unread, but that doesn't interfere. Might not be necessary.
# We could also select upwards, but then our problem would be with the topmost message. # We could also select upwards, but then our problem would be with the topmost message.
@ -3049,11 +3049,11 @@ class MyForm(settingsmixin.SMainWindow):
self.replyFromTab = self.ui.tabWidget.currentIndex() self.replyFromTab = self.ui.tabWidget.currentIndex()
currentInboxRow = tableWidget.currentRow() currentInboxRow = tableWidget.currentRow()
toAddressAtCurrentInboxRow = str(tableWidget.item( toAddressAtCurrentInboxRow = tableWidget.item(
currentInboxRow, 0).data(Qt.UserRole).toPyObject()) currentInboxRow, 0).data(Qt.UserRole)
acct = accountClass(toAddressAtCurrentInboxRow) acct = accountClass(toAddressAtCurrentInboxRow)
fromAddressAtCurrentInboxRow = str(tableWidget.item( fromAddressAtCurrentInboxRow = tableWidget.item(
currentInboxRow, 1).data(Qt.UserRole).toPyObject()) currentInboxRow, 1).data(Qt.UserRole)
msgid = str(tableWidget.item( msgid = str(tableWidget.item(
currentInboxRow, 3).data(Qt.UserRole).toPyObject()) currentInboxRow, 3).data(Qt.UserRole).toPyObject())
queryreturn = sqlQuery( queryreturn = sqlQuery(
@ -3115,8 +3115,8 @@ class MyForm(settingsmixin.SMainWindow):
return return
currentInboxRow = tableWidget.currentRow() currentInboxRow = tableWidget.currentRow()
# tableWidget.item(currentRow,1).data(Qt.UserRole).toPyObject() # tableWidget.item(currentRow,1).data(Qt.UserRole).toPyObject()
addressAtCurrentInboxRow = str(tableWidget.item( addressAtCurrentInboxRow = tableWidget.item(
currentInboxRow, 1).data(Qt.UserRole).toPyObject()) currentInboxRow, 1).data(Qt.UserRole)
# Let's make sure that it isn't already in the address book # Let's make sure that it isn't already in the address book
queryreturn = sqlQuery('''select * from addressbook where address=?''', queryreturn = sqlQuery('''select * from addressbook where address=?''',
addressAtCurrentInboxRow) addressAtCurrentInboxRow)
@ -3137,10 +3137,10 @@ class MyForm(settingsmixin.SMainWindow):
return return
currentInboxRow = tableWidget.currentRow() currentInboxRow = tableWidget.currentRow()
# tableWidget.item(currentRow,1).data(Qt.UserRole).toPyObject() # tableWidget.item(currentRow,1).data(Qt.UserRole).toPyObject()
addressAtCurrentInboxRow = str(tableWidget.item( addressAtCurrentInboxRow = tableWidget.item(
currentInboxRow, 1).data(Qt.UserRole).toPyObject()) currentInboxRow, 1).data(Qt.UserRole)
recipientAddress = str(tableWidget.item( recipientAddress = tableWidget.item(
currentInboxRow, 0).data(Qt.UserRole).toPyObject()) currentInboxRow, 0).data(Qt.UserRole)
# Let's make sure that it isn't already in the address book # Let's make sure that it isn't already in the address book
queryreturn = sqlQuery('''select * from blacklist where address=?''', queryreturn = sqlQuery('''select * from blacklist where address=?''',
addressAtCurrentInboxRow) addressAtCurrentInboxRow)
@ -3174,9 +3174,9 @@ class MyForm(settingsmixin.SMainWindow):
else: else:
sqlExecute('''UPDATE inbox SET folder='trash' WHERE msgid=?''', inventoryHashToTrash) sqlExecute('''UPDATE inbox SET folder='trash' WHERE msgid=?''', inventoryHashToTrash)
if tableWidget.item(currentRow, 0).font().bold(): if tableWidget.item(currentRow, 0).font().bold():
self.propagateUnreadCount(str(tableWidget.item(currentRow, 1 if tableWidget == self.ui.tableWidgetInboxSubscriptions else 0).data(Qt.UserRole).toPyObject()), folder, self.getCurrentTreeWidget(), -1) self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget == self.ui.tableWidgetInboxSubscriptions else 0).data(Qt.UserRole), folder, self.getCurrentTreeWidget(), -1)
if folder != "trash" and not shifted: if folder != "trash" and not shifted:
self.propagateUnreadCount(str(tableWidget.item(currentRow, 1 if tableWidget == self.ui.tableWidgetInboxSubscriptions else 0).data(Qt.UserRole).toPyObject()), "trash", self.getCurrentTreeWidget(), 1) self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget == self.ui.tableWidgetInboxSubscriptions else 0).data(Qt.UserRole), "trash", self.getCurrentTreeWidget(), 1)
self.getCurrentMessageTextedit().setText("") self.getCurrentMessageTextedit().setText("")
tableWidget.removeRow(currentRow) tableWidget.removeRow(currentRow)
@ -3199,8 +3199,8 @@ class MyForm(settingsmixin.SMainWindow):
currentRow, 3).data(Qt.UserRole).toPyObject()) currentRow, 3).data(Qt.UserRole).toPyObject())
sqlExecute('''UPDATE inbox SET folder='inbox' WHERE msgid=?''', inventoryHashToTrash) sqlExecute('''UPDATE inbox SET folder='inbox' WHERE msgid=?''', inventoryHashToTrash)
if tableWidget.item(currentRow, 0).font().bold(): if tableWidget.item(currentRow, 0).font().bold():
self.propagateUnreadCount(str(tableWidget.item(currentRow, 1 if tableWidget == self.ui.tableWidgetInboxSubscriptions else 0).data(Qt.UserRole).toPyObject()), "inbox", self.getCurrentTreeWidget(), 1) self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget == self.ui.tableWidgetInboxSubscriptions else 0).data(Qt.UserRole), "inbox", self.getCurrentTreeWidget(), 1)
self.propagateUnreadCount(str(tableWidget.item(currentRow, 1 if tableWidget == self.ui.tableWidgetInboxSubscriptions else 0).data(Qt.UserRole).toPyObject()), "trash", self.getCurrentTreeWidget(), -1) self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget == self.ui.tableWidgetInboxSubscriptions else 0).data(Qt.UserRole), "trash", self.getCurrentTreeWidget(), -1)
self.getCurrentMessageTextedit().setText("") self.getCurrentMessageTextedit().setText("")
tableWidget.removeRow(currentRow) tableWidget.removeRow(currentRow)
self.statusBar().showMessage(_translate( self.statusBar().showMessage(_translate(
@ -3259,7 +3259,7 @@ class MyForm(settingsmixin.SMainWindow):
else: else:
sqlExecute('''UPDATE sent SET folder='trash' WHERE ackdata=?''', ackdataToTrash) sqlExecute('''UPDATE sent SET folder='trash' WHERE ackdata=?''', ackdataToTrash)
if tableWidget.item(currentRow, 0).font().bold(): if tableWidget.item(currentRow, 0).font().bold():
self.propagateUnreadCount(str(tableWidget.item(currentRow, 1 if tableWidget == self.ui.tableWidgetInboxSubscriptions else 0).data(Qt.UserRole).toPyObject()), folder, self.getCurrentTreeWidget(), -1) self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget == self.ui.tableWidgetInboxSubscriptions else 0).data(Qt.UserRole), folder, self.getCurrentTreeWidget(), -1)
self.getCurrentMessageTextedit().setPlainText("") self.getCurrentMessageTextedit().setPlainText("")
tableWidget.removeRow(currentRow) tableWidget.removeRow(currentRow)
self.statusBar().showMessage(_translate( self.statusBar().showMessage(_translate(
@ -3271,8 +3271,8 @@ class MyForm(settingsmixin.SMainWindow):
def on_action_ForceSend(self): def on_action_ForceSend(self):
currentRow = self.ui.tableWidgetInbox.currentRow() currentRow = self.ui.tableWidgetInbox.currentRow()
addressAtCurrentRow = str(self.ui.tableWidgetInbox.item( addressAtCurrentRow = self.ui.tableWidgetInbox.item(
currentRow, 0).data(Qt.UserRole).toPyObject()) currentRow, 0).data(Qt.UserRole)
toRipe = decodeAddress(addressAtCurrentRow)[3] toRipe = decodeAddress(addressAtCurrentRow)[3]
sqlExecute( sqlExecute(
'''UPDATE sent SET status='forcepow' WHERE toripe=? AND status='toodifficult' and folder='sent' ''', '''UPDATE sent SET status='forcepow' WHERE toripe=? AND status='toodifficult' and folder='sent' ''',
@ -3286,8 +3286,8 @@ class MyForm(settingsmixin.SMainWindow):
def on_action_SentClipboard(self): def on_action_SentClipboard(self):
currentRow = self.ui.tableWidgetInbox.currentRow() currentRow = self.ui.tableWidgetInbox.currentRow()
addressAtCurrentRow = str(self.ui.tableWidgetInbox.item( addressAtCurrentRow = self.ui.tableWidgetInbox.item(
currentRow, 0).data(Qt.UserRole).toPyObject()) currentRow, 0).data(Qt.UserRole)
clipboard = QtGui.QApplication.clipboard() clipboard = QtGui.QApplication.clipboard()
clipboard.setText(str(addressAtCurrentRow)) clipboard.setText(str(addressAtCurrentRow))
@ -3722,18 +3722,18 @@ class MyForm(settingsmixin.SMainWindow):
else: else:
currentColumn = 1 currentColumn = 1
if self.getCurrentFolder() == "sent": if self.getCurrentFolder() == "sent":
myAddress = str(tableWidget.item(currentRow, 1).data(Qt.UserRole).toPyObject()) myAddress = tableWidget.item(currentRow, 1).data(Qt.UserRole)
otherAddress = str(tableWidget.item(currentRow, 0).data(Qt.UserRole).toPyObject()) otherAddress = tableWidget.item(currentRow, 0).data(Qt.UserRole)
else: else:
myAddress = str(tableWidget.item(currentRow, 0).data(Qt.UserRole).toPyObject()) myAddress = tableWidget.item(currentRow, 0).data(Qt.UserRole)
otherAddress = str(tableWidget.item(currentRow, 1).data(Qt.UserRole).toPyObject()) otherAddress = tableWidget.item(currentRow, 1).data(Qt.UserRole)
account = accountClass(myAddress) account = accountClass(myAddress)
if isinstance(account, GatewayAccount) and otherAddress == account.relayAddress and ( if isinstance(account, GatewayAccount) and otherAddress == account.relayAddress and (
(currentColumn in [0, 2] and self.getCurrentFolder() == "sent") or (currentColumn in [0, 2] and self.getCurrentFolder() == "sent") or
(currentColumn in [1, 2] and self.getCurrentFolder() != "sent")): (currentColumn in [1, 2] and self.getCurrentFolder() != "sent")):
text = str(tableWidget.item(currentRow, currentColumn).text()) text = str(tableWidget.item(currentRow, currentColumn).label)
else: else:
text = str(tableWidget.item(currentRow, currentColumn).data(Qt.UserRole).toPyObject()) text = tableWidget.item(currentRow, currentColumn).data(Qt.UserRole)
clipboard = QtGui.QApplication.clipboard() clipboard = QtGui.QApplication.clipboard()
clipboard.setText(str(text)) clipboard.setText(str(text))
@ -3871,8 +3871,8 @@ class MyForm(settingsmixin.SMainWindow):
self.popMenuInbox.addAction(self.actionForceHtml) self.popMenuInbox.addAction(self.actionForceHtml)
self.popMenuInbox.addAction(self.actionMarkUnread) self.popMenuInbox.addAction(self.actionMarkUnread)
self.popMenuInbox.addSeparator() self.popMenuInbox.addSeparator()
address = str(tableWidget.item( address = tableWidget.item(
tableWidget.currentRow(), 0).data(Qt.UserRole).toPyObject()) tableWidget.currentRow(), 0).data(Qt.UserRole)
account = accountClass(address) account = accountClass(address)
if account.type == AccountMixin.CHAN: if account.type == AccountMixin.CHAN:
self.popMenuInbox.addAction(self.actionReplyChan) self.popMenuInbox.addAction(self.actionReplyChan)
@ -4012,13 +4012,11 @@ class MyForm(settingsmixin.SMainWindow):
# inventoryHashToMarkRead = str(tableWidget.item( # inventoryHashToMarkRead = str(tableWidget.item(
# currentRow, 3).data(Qt.UserRole).toPyObject()) # currentRow, 3).data(Qt.UserRole).toPyObject())
# inventoryHashesToMarkRead.append(inventoryHashToMarkRead) # inventoryHashesToMarkRead.append(inventoryHashToMarkRead)
tableWidget.item(currentRow, 0).setFont(font) tableWidget.item(currentRow, 0).setUnread(False)
tableWidget.item(currentRow, 0).setTextColor(AccountColor(str(tableWidget.item(currentRow, 0).data(Qt.UserRole).toPyObject())).accountColor()) tableWidget.item(currentRow, 1).setUnread(False)
tableWidget.item(currentRow, 1).setFont(font)
tableWidget.item(currentRow, 1).setTextColor(AccountColor(str(tableWidget.item(currentRow, 1).data(Qt.UserRole).toPyObject())).accountColor())
tableWidget.item(currentRow, 2).setFont(font) tableWidget.item(currentRow, 2).setFont(font)
tableWidget.item(currentRow, 3).setFont(font) tableWidget.item(currentRow, 3).setFont(font)
self.propagateUnreadCount(str(tableWidget.item(currentRow, 1 if tableWidget == self.ui.tableWidgetInboxSubscriptions else 0).data(Qt.UserRole).toPyObject()), folder, self.getCurrentTreeWidget(), -1) self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget == self.ui.tableWidgetInboxSubscriptions else 0).data(Qt.UserRole), folder, self.getCurrentTreeWidget(), -1)
else: else:
data = self.getCurrentMessageId() data = self.getCurrentMessageId()

View File

@ -284,9 +284,13 @@ class MessageList_AddressWidget(QtGui.QTableWidgetItem, AccountMixin, SettingsMi
label = unicode(shared.config.get(self.address, 'label'), 'utf-8)') label = unicode(shared.config.get(self.address, 'label'), 'utf-8)')
else: else:
self.label = label self.label = label
if self.initialised:
self.emitDataChanged()
def setUnread(self, unread): def setUnread(self, unread):
self.unread = unread self.unread = unread
if self.initialised:
self.emitDataChanged()
def data(self, role): def data(self, role):
if role == QtCore.Qt.DisplayRole: if role == QtCore.Qt.DisplayRole: