Moved myTableWidgetItem to foldertree.MessageList_TimeWidget
This commit is contained in:
parent
aa333a66a6
commit
08ff39e1ff
|
@ -31,7 +31,8 @@ from migrationwizard import Ui_MigrationWizard
|
||||||
from foldertree import (
|
from foldertree import (
|
||||||
AccountMixin, Ui_FolderWidget, Ui_AddressWidget, Ui_SubscriptionWidget,
|
AccountMixin, Ui_FolderWidget, Ui_AddressWidget, Ui_SubscriptionWidget,
|
||||||
MessageList_AddressWidget, MessageList_SubjectWidget,
|
MessageList_AddressWidget, MessageList_SubjectWidget,
|
||||||
Ui_AddressBookWidgetItemLabel, Ui_AddressBookWidgetItemAddress)
|
Ui_AddressBookWidgetItemLabel, Ui_AddressBookWidgetItemAddress,
|
||||||
|
MessageList_TimeWidget)
|
||||||
import settingsmixin
|
import settingsmixin
|
||||||
import support
|
import support
|
||||||
from helper_ackPayload import genAckPayload
|
from helper_ackPayload import genAckPayload
|
||||||
|
@ -970,40 +971,30 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
Switch unread for item of msgid and related items in
|
Switch unread for item of msgid and related items in
|
||||||
other STableWidgets "All Accounts" and "Chans"
|
other STableWidgets "All Accounts" and "Chans"
|
||||||
"""
|
"""
|
||||||
related = [self.ui.tableWidgetInbox, self.ui.tableWidgetInboxChans]
|
status = widget.item(row, 0).unread
|
||||||
|
if status != unread:
|
||||||
|
return
|
||||||
|
|
||||||
|
widgets = [self.ui.tableWidgetInbox, self.ui.tableWidgetInboxChans]
|
||||||
|
rrow = None
|
||||||
try:
|
try:
|
||||||
related.remove(widget)
|
widgets.remove(widget)
|
||||||
related = related.pop()
|
related = widgets.pop()
|
||||||
except ValueError:
|
except ValueError:
|
||||||
rrow = None
|
pass
|
||||||
related = []
|
|
||||||
else:
|
else:
|
||||||
# maybe use instead:
|
# maybe use instead:
|
||||||
# rrow = related.row(msgid), msgid should be QTableWidgetItem
|
# rrow = related.row(msgid), msgid should be QTableWidgetItem
|
||||||
# related = related.findItems(msgid, QtCore.Qt.MatchExactly),
|
# related = related.findItems(msgid, QtCore.Qt.MatchExactly),
|
||||||
# returns an empty list
|
# returns an empty list
|
||||||
for rrow in xrange(related.rowCount()):
|
for rrow in range(related.rowCount()):
|
||||||
if msgid == str(related.item(rrow, 3).data(
|
if related.item(rrow, 3).data() == msgid:
|
||||||
QtCore.Qt.UserRole).toPyObject()):
|
|
||||||
break
|
break
|
||||||
else:
|
|
||||||
rrow = None
|
|
||||||
|
|
||||||
status = widget.item(row, 0).unread
|
for col in range(widget.columnCount()):
|
||||||
if status == unread:
|
widget.item(row, col).setUnread(not status)
|
||||||
font = QtGui.QFont()
|
if rrow:
|
||||||
font.setBold(not status)
|
related.item(rrow, col).setUnread(not status)
|
||||||
widget.item(row, 3).setFont(font)
|
|
||||||
for col in (0, 1, 2):
|
|
||||||
widget.item(row, col).setUnread(not status)
|
|
||||||
|
|
||||||
try:
|
|
||||||
related.item(rrow, 3).setFont(font)
|
|
||||||
except (TypeError, AttributeError):
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
for col in (0, 1, 2):
|
|
||||||
related.item(rrow, col).setUnread(not status)
|
|
||||||
|
|
||||||
# Here we need to update unread count for:
|
# Here we need to update unread count for:
|
||||||
# - all widgets if there is no args
|
# - all widgets if there is no args
|
||||||
|
@ -1100,11 +1091,6 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
acct = accountClass(fromAddress) or BMAccount(fromAddress)
|
acct = accountClass(fromAddress) or BMAccount(fromAddress)
|
||||||
acct.parseMessage(toAddress, fromAddress, subject, "")
|
acct.parseMessage(toAddress, fromAddress, subject, "")
|
||||||
|
|
||||||
items = []
|
|
||||||
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', 'replace'))
|
|
||||||
|
|
||||||
if status == 'awaitingpubkey':
|
if status == 'awaitingpubkey':
|
||||||
statusText = _translate(
|
statusText = _translate(
|
||||||
"MainWindow",
|
"MainWindow",
|
||||||
|
@ -1162,22 +1148,24 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
statusText = _translate(
|
statusText = _translate(
|
||||||
"MainWindow", "Unknown status: %1 %2").arg(status).arg(
|
"MainWindow", "Unknown status: %1 %2").arg(status).arg(
|
||||||
l10n.formatTimestamp(lastactiontime))
|
l10n.formatTimestamp(lastactiontime))
|
||||||
newItem = myTableWidgetItem(statusText)
|
|
||||||
newItem.setToolTip(statusText)
|
items = [
|
||||||
newItem.setData(QtCore.Qt.UserRole, QtCore.QByteArray(ackdata))
|
MessageList_AddressWidget(
|
||||||
newItem.setData(33, int(lastactiontime))
|
toAddress, unicode(acct.toLabel, 'utf-8')),
|
||||||
newItem.setFlags(
|
MessageList_AddressWidget(
|
||||||
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
fromAddress, unicode(acct.fromLabel, 'utf-8')),
|
||||||
items.append(newItem)
|
MessageList_SubjectWidget(
|
||||||
|
str(subject), unicode(acct.subject, 'utf-8', 'replace')),
|
||||||
|
MessageList_TimeWidget(
|
||||||
|
statusText, False, lastactiontime, ackdata)]
|
||||||
self.addMessageListItem(tableWidget, items)
|
self.addMessageListItem(tableWidget, items)
|
||||||
|
|
||||||
return acct
|
return acct
|
||||||
|
|
||||||
def addMessageListItemInbox(
|
def addMessageListItemInbox(
|
||||||
self, tableWidget, toAddress, fromAddress, subject,
|
self, tableWidget, toAddress, fromAddress, subject,
|
||||||
msgid, received, read
|
msgid, received, read
|
||||||
):
|
):
|
||||||
font = QtGui.QFont()
|
|
||||||
font.setBold(True)
|
|
||||||
if toAddress == str_broadcast_subscribers:
|
if toAddress == str_broadcast_subscribers:
|
||||||
acct = accountClass(fromAddress)
|
acct = accountClass(fromAddress)
|
||||||
else:
|
else:
|
||||||
|
@ -1186,24 +1174,19 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
acct = BMAccount(fromAddress)
|
acct = BMAccount(fromAddress)
|
||||||
acct.parseMessage(toAddress, fromAddress, subject, "")
|
acct.parseMessage(toAddress, fromAddress, subject, "")
|
||||||
|
|
||||||
items = []
|
items = [
|
||||||
#to
|
MessageList_AddressWidget(
|
||||||
MessageList_AddressWidget(items, toAddress, unicode(acct.toLabel, 'utf-8'), not read)
|
toAddress, unicode(acct.toLabel, 'utf-8'), not read),
|
||||||
# from
|
MessageList_AddressWidget(
|
||||||
MessageList_AddressWidget(items, fromAddress, unicode(acct.fromLabel, 'utf-8'), not read)
|
fromAddress, unicode(acct.fromLabel, 'utf-8'), not read),
|
||||||
# subject
|
MessageList_SubjectWidget(
|
||||||
MessageList_SubjectWidget(items, str(subject), unicode(acct.subject, 'utf-8', 'replace'), not read)
|
str(subject), unicode(acct.subject, 'utf-8', 'replace'),
|
||||||
# time received
|
not read),
|
||||||
time_item = myTableWidgetItem(l10n.formatTimestamp(received))
|
MessageList_TimeWidget(
|
||||||
time_item.setToolTip(l10n.formatTimestamp(received))
|
l10n.formatTimestamp(received), not read, received, msgid)
|
||||||
time_item.setData(QtCore.Qt.UserRole, QtCore.QByteArray(msgid))
|
]
|
||||||
time_item.setData(33, int(received))
|
|
||||||
time_item.setFlags(
|
|
||||||
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
|
||||||
if not read:
|
|
||||||
time_item.setFont(font)
|
|
||||||
items.append(time_item)
|
|
||||||
self.addMessageListItem(tableWidget, items)
|
self.addMessageListItem(tableWidget, items)
|
||||||
|
|
||||||
return acct
|
return acct
|
||||||
|
|
||||||
# Load Sent items from database
|
# Load Sent items from database
|
||||||
|
@ -1855,10 +1838,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 = sent.item(
|
toAddress = sent.item(i, 0).data(QtCore.Qt.UserRole)
|
||||||
i, 0).data(QtCore.Qt.UserRole)
|
tableAckdata = sent.item(i, 3).data()
|
||||||
tableAckdata = sent.item(
|
|
||||||
i, 3).data(QtCore.Qt.UserRole).toPyObject()
|
|
||||||
status, addressVersionNumber, streamNumber, ripe = decodeAddress(
|
status, addressVersionNumber, streamNumber, ripe = decodeAddress(
|
||||||
toAddress)
|
toAddress)
|
||||||
if ackdata == tableAckdata:
|
if ackdata == tableAckdata:
|
||||||
|
@ -1882,8 +1863,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
):
|
):
|
||||||
i = None
|
i = None
|
||||||
for i in range(inbox.rowCount()):
|
for i in range(inbox.rowCount()):
|
||||||
if msgid == \
|
if msgid == inbox.item(i, 3).data():
|
||||||
inbox.item(i, 3).data(QtCore.Qt.UserRole).toPyObject():
|
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
|
@ -2609,17 +2589,11 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
if idCount == 0:
|
if idCount == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
font = QtGui.QFont()
|
|
||||||
font.setBold(False)
|
|
||||||
|
|
||||||
msgids = []
|
msgids = []
|
||||||
for i in range(0, idCount):
|
for i in range(0, idCount):
|
||||||
msgids.append(str(tableWidget.item(
|
msgids.append(tableWidget.item(i, 3).data())
|
||||||
i, 3).data(QtCore.Qt.UserRole).toPyObject()))
|
for col in xrange(tableWidget.columnCount()):
|
||||||
tableWidget.item(i, 0).setUnread(False)
|
tableWidget.item(i, col).setUnread(False)
|
||||||
tableWidget.item(i, 1).setUnread(False)
|
|
||||||
tableWidget.item(i, 2).setUnread(False)
|
|
||||||
tableWidget.item(i, 3).setFont(font)
|
|
||||||
|
|
||||||
markread = sqlExecuteChunked(
|
markread = sqlExecuteChunked(
|
||||||
"UPDATE inbox SET read = 1 WHERE msgid IN({0}) AND read=0",
|
"UPDATE inbox SET read = 1 WHERE msgid IN({0}) AND read=0",
|
||||||
|
@ -2890,8 +2864,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
# modified = 0
|
# modified = 0
|
||||||
for row in tableWidget.selectedIndexes():
|
for row in tableWidget.selectedIndexes():
|
||||||
currentRow = row.row()
|
currentRow = row.row()
|
||||||
msgid = str(tableWidget.item(
|
msgid = tableWidget.item(currentRow, 3).data()
|
||||||
currentRow, 3).data(QtCore.Qt.UserRole).toPyObject())
|
|
||||||
msgids.add(msgid)
|
msgids.add(msgid)
|
||||||
# if not tableWidget.item(currentRow, 0).unread:
|
# if not tableWidget.item(currentRow, 0).unread:
|
||||||
# modified += 1
|
# modified += 1
|
||||||
|
@ -2981,8 +2954,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
acct = accountClass(toAddressAtCurrentInboxRow)
|
acct = accountClass(toAddressAtCurrentInboxRow)
|
||||||
fromAddressAtCurrentInboxRow = tableWidget.item(
|
fromAddressAtCurrentInboxRow = tableWidget.item(
|
||||||
currentInboxRow, column_from).address
|
currentInboxRow, column_from).address
|
||||||
msgid = str(tableWidget.item(
|
msgid = tableWidget.item(currentInboxRow, 3).data()
|
||||||
currentInboxRow, 3).data(QtCore.Qt.UserRole).toPyObject())
|
|
||||||
queryreturn = sqlQuery(
|
queryreturn = sqlQuery(
|
||||||
"SELECT message FROM inbox WHERE msgid=?", msgid
|
"SELECT message FROM inbox WHERE msgid=?", msgid
|
||||||
) or sqlQuery("SELECT message FROM sent WHERE ackdata=?", msgid)
|
) or sqlQuery("SELECT message FROM sent WHERE ackdata=?", msgid)
|
||||||
|
@ -3081,7 +3053,6 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
if not tableWidget:
|
if not tableWidget:
|
||||||
return
|
return
|
||||||
currentInboxRow = tableWidget.currentRow()
|
currentInboxRow = tableWidget.currentRow()
|
||||||
# tableWidget.item(currentRow,1).data(Qt.UserRole).toPyObject()
|
|
||||||
addressAtCurrentInboxRow = tableWidget.item(
|
addressAtCurrentInboxRow = tableWidget.item(
|
||||||
currentInboxRow, 1).data(QtCore.Qt.UserRole)
|
currentInboxRow, 1).data(QtCore.Qt.UserRole)
|
||||||
self.ui.tabWidget.setCurrentIndex(
|
self.ui.tabWidget.setCurrentIndex(
|
||||||
|
@ -3095,7 +3066,6 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
if not tableWidget:
|
if not tableWidget:
|
||||||
return
|
return
|
||||||
currentInboxRow = tableWidget.currentRow()
|
currentInboxRow = tableWidget.currentRow()
|
||||||
# tableWidget.item(currentRow,1).data(Qt.UserRole).toPyObject()
|
|
||||||
addressAtCurrentInboxRow = tableWidget.item(
|
addressAtCurrentInboxRow = tableWidget.item(
|
||||||
currentInboxRow, 1).data(QtCore.Qt.UserRole)
|
currentInboxRow, 1).data(QtCore.Qt.UserRole)
|
||||||
recipientAddress = tableWidget.item(
|
recipientAddress = tableWidget.item(
|
||||||
|
@ -3132,16 +3102,15 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
messageLists = (messageLists,)
|
messageLists = (messageLists,)
|
||||||
for messageList in messageLists:
|
for messageList in messageLists:
|
||||||
if row is not None:
|
if row is not None:
|
||||||
inventoryHash = str(messageList.item(row, 3).data(
|
inventoryHash = messageList.item(row, 3).data()
|
||||||
QtCore.Qt.UserRole).toPyObject())
|
|
||||||
messageList.removeRow(row)
|
messageList.removeRow(row)
|
||||||
elif inventoryHash is not None:
|
elif inventoryHash is not None:
|
||||||
for i in range(messageList.rowCount() - 1, -1, -1):
|
for i in range(messageList.rowCount() - 1, -1, -1):
|
||||||
if messageList.item(i, 3).data(QtCore.Qt.UserRole).toPyObject() == inventoryHash:
|
if messageList.item(i, 3).data() == inventoryHash:
|
||||||
messageList.removeRow(i)
|
messageList.removeRow(i)
|
||||||
elif ackData is not None:
|
elif ackData is not None:
|
||||||
for i in range(messageList.rowCount() - 1, -1, -1):
|
for i in range(messageList.rowCount() - 1, -1, -1):
|
||||||
if messageList.item(i, 3).data(QtCore.Qt.UserRole).toPyObject() == ackData:
|
if messageList.item(i, 3).data() == ackData:
|
||||||
messageList.removeRow(i)
|
messageList.removeRow(i)
|
||||||
|
|
||||||
# Send item on the Inbox tab to trash
|
# Send item on the Inbox tab to trash
|
||||||
|
@ -3160,12 +3129,12 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
tableWidget.selectedRanges(), key=lambda r: r.topRow()
|
tableWidget.selectedRanges(), key=lambda r: r.topRow()
|
||||||
)[::-1]:
|
)[::-1]:
|
||||||
for i in range(r.bottomRow() - r.topRow() + 1):
|
for i in range(r.bottomRow() - r.topRow() + 1):
|
||||||
inventoryHashToTrash = str(tableWidget.item(
|
inventoryHashesToTrash.add(
|
||||||
r.topRow() + i, 3).data(QtCore.Qt.UserRole).toPyObject())
|
tableWidget.item(r.topRow() + i, 3).data())
|
||||||
inventoryHashesToTrash.add(inventoryHashToTrash)
|
|
||||||
currentRow = r.topRow()
|
currentRow = r.topRow()
|
||||||
self.getCurrentMessageTextedit().setText("")
|
self.getCurrentMessageTextedit().setText("")
|
||||||
tableWidget.model().removeRows(r.topRow(), r.bottomRow()-r.topRow()+1)
|
tableWidget.model().removeRows(
|
||||||
|
r.topRow(), r.bottomRow() - r.topRow() + 1)
|
||||||
idCount = len(inventoryHashesToTrash)
|
idCount = len(inventoryHashesToTrash)
|
||||||
sqlExecuteChunked(
|
sqlExecuteChunked(
|
||||||
("DELETE FROM inbox" if folder == "trash" or shifted else
|
("DELETE FROM inbox" if folder == "trash" or shifted else
|
||||||
|
@ -3188,9 +3157,8 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
tableWidget.selectedRanges(), key=lambda r: r.topRow()
|
tableWidget.selectedRanges(), key=lambda r: r.topRow()
|
||||||
)[::-1]:
|
)[::-1]:
|
||||||
for i in range(r.bottomRow() - r.topRow() + 1):
|
for i in range(r.bottomRow() - r.topRow() + 1):
|
||||||
inventoryHashToTrash = str(tableWidget.item(
|
inventoryHashesToTrash.add(
|
||||||
r.topRow() + i, 3).data(QtCore.Qt.UserRole).toPyObject())
|
tableWidget.item(r.topRow() + i, 3).data())
|
||||||
inventoryHashesToTrash.add(inventoryHashToTrash)
|
|
||||||
currentRow = r.topRow()
|
currentRow = r.topRow()
|
||||||
self.getCurrentMessageTextedit().setText("")
|
self.getCurrentMessageTextedit().setText("")
|
||||||
tableWidget.model().removeRows(
|
tableWidget.model().removeRows(
|
||||||
|
@ -3217,8 +3185,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
subjectAtCurrentInboxRow = ''
|
subjectAtCurrentInboxRow = ''
|
||||||
|
|
||||||
# Retrieve the message data out of the SQL database
|
# Retrieve the message data out of the SQL database
|
||||||
msgid = str(tableWidget.item(
|
msgid = tableWidget.item(currentInboxRow, 3).data()
|
||||||
currentInboxRow, 3).data(QtCore.Qt.UserRole).toPyObject())
|
|
||||||
queryreturn = sqlQuery(
|
queryreturn = sqlQuery(
|
||||||
'''select message from inbox where msgid=?''', msgid)
|
'''select message from inbox where msgid=?''', msgid)
|
||||||
if queryreturn != []:
|
if queryreturn != []:
|
||||||
|
@ -3246,8 +3213,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
shifted = QtGui.QApplication.queryKeyboardModifiers() & QtCore.Qt.ShiftModifier
|
shifted = QtGui.QApplication.queryKeyboardModifiers() & QtCore.Qt.ShiftModifier
|
||||||
while tableWidget.selectedIndexes() != []:
|
while tableWidget.selectedIndexes() != []:
|
||||||
currentRow = tableWidget.selectedIndexes()[0].row()
|
currentRow = tableWidget.selectedIndexes()[0].row()
|
||||||
ackdataToTrash = str(tableWidget.item(
|
ackdataToTrash = tableWidget.item(currentRow, 3).data()
|
||||||
currentRow, 3).data(QtCore.Qt.UserRole).toPyObject())
|
|
||||||
sqlExecute(
|
sqlExecute(
|
||||||
"DELETE FROM sent" if folder == "trash" or shifted else
|
"DELETE FROM sent" if folder == "trash" or shifted else
|
||||||
"UPDATE sent SET folder='trash'"
|
"UPDATE sent SET folder='trash'"
|
||||||
|
@ -3520,11 +3486,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
if messagelist:
|
if messagelist:
|
||||||
currentRow = messagelist.currentRow()
|
currentRow = messagelist.currentRow()
|
||||||
if currentRow >= 0:
|
if currentRow >= 0:
|
||||||
msgid = str(messagelist.item(
|
return messagelist.item(currentRow, 3).data()
|
||||||
currentRow, 3).data(QtCore.Qt.UserRole).toPyObject())
|
|
||||||
# data is saved at the 4. column of the table...
|
|
||||||
return msgid
|
|
||||||
return False
|
|
||||||
|
|
||||||
def getCurrentMessageTextedit(self):
|
def getCurrentMessageTextedit(self):
|
||||||
currentIndex = self.ui.tabWidget.currentIndex()
|
currentIndex = self.ui.tabWidget.currentIndex()
|
||||||
|
@ -3967,8 +3929,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
# Check to see if this item is toodifficult and display an additional
|
# Check to see if this item is toodifficult and display an additional
|
||||||
# menu option (Force Send) if it is.
|
# menu option (Force Send) if it is.
|
||||||
if currentRow >= 0:
|
if currentRow >= 0:
|
||||||
ackData = str(self.ui.tableWidgetInbox.item(
|
ackData = self.ui.tableWidgetInbox.item(currentRow, 3).data()
|
||||||
currentRow, 3).data(QtCore.Qt.UserRole).toPyObject())
|
|
||||||
queryreturn = sqlQuery('''SELECT status FROM sent where ackdata=?''', ackData)
|
queryreturn = sqlQuery('''SELECT status FROM sent where ackdata=?''', ackData)
|
||||||
for row in queryreturn:
|
for row in queryreturn:
|
||||||
status, = row
|
status, = row
|
||||||
|
@ -4170,15 +4131,6 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
obj.loadSettings()
|
obj.loadSettings()
|
||||||
|
|
||||||
|
|
||||||
# In order for the time columns on the Inbox and Sent tabs to be sorted
|
|
||||||
# correctly (rather than alphabetically), we need to overload the <
|
|
||||||
# operator and use this class instead of QTableWidgetItem.
|
|
||||||
class myTableWidgetItem(QtGui.QTableWidgetItem):
|
|
||||||
|
|
||||||
def __lt__(self, other):
|
|
||||||
return int(self.data(33).toPyObject()) < int(other.data(33).toPyObject())
|
|
||||||
|
|
||||||
|
|
||||||
app = None
|
app = None
|
||||||
myapp = None
|
myapp = None
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
"""
|
"""
|
||||||
src/bitmessageqt/foldertree.py
|
Folder tree and messagelist widgets definitions.
|
||||||
==============================
|
|
||||||
"""
|
"""
|
||||||
# pylint: disable=too-many-arguments,bad-super-call,attribute-defined-outside-init
|
# pylint: disable=too-many-arguments,bad-super-call
|
||||||
|
# pylint: disable=attribute-defined-outside-init
|
||||||
|
|
||||||
from cgi import escape
|
from cgi import escape
|
||||||
|
|
||||||
|
@ -20,6 +20,8 @@ _translate("MainWindow", "new")
|
||||||
_translate("MainWindow", "sent")
|
_translate("MainWindow", "sent")
|
||||||
_translate("MainWindow", "trash")
|
_translate("MainWindow", "trash")
|
||||||
|
|
||||||
|
TimestampRole = QtCore.Qt.UserRole + 1
|
||||||
|
|
||||||
|
|
||||||
class AccountMixin(object):
|
class AccountMixin(object):
|
||||||
"""UI-related functionality for accounts"""
|
"""UI-related functionality for accounts"""
|
||||||
|
@ -334,13 +336,14 @@ class Ui_SubscriptionWidget(Ui_AddressWidget):
|
||||||
class BMTableWidgetItem(QtGui.QTableWidgetItem, SettingsMixin):
|
class BMTableWidgetItem(QtGui.QTableWidgetItem, SettingsMixin):
|
||||||
"""A common abstract class for Table widget item"""
|
"""A common abstract class for Table widget item"""
|
||||||
|
|
||||||
def __init__(self, parent=None, label=None, unread=False):
|
def __init__(self, label=None, unread=False):
|
||||||
super(QtGui.QTableWidgetItem, self).__init__()
|
super(QtGui.QTableWidgetItem, self).__init__()
|
||||||
self.setLabel(label)
|
self.setLabel(label)
|
||||||
self.setUnread(unread)
|
self.setUnread(unread)
|
||||||
self._setup()
|
self._setup()
|
||||||
if parent is not None:
|
|
||||||
parent.append(self)
|
def _setup(self):
|
||||||
|
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
||||||
|
|
||||||
def setLabel(self, label):
|
def setLabel(self, label):
|
||||||
"""Set object label"""
|
"""Set object label"""
|
||||||
|
@ -353,7 +356,7 @@ class BMTableWidgetItem(QtGui.QTableWidgetItem, SettingsMixin):
|
||||||
def data(self, role):
|
def data(self, role):
|
||||||
"""Return object data (QT UI)"""
|
"""Return object data (QT UI)"""
|
||||||
if role in (
|
if role in (
|
||||||
QtCore.Qt.DisplayRole, QtCore.Qt.EditRole, QtCore.Qt.ToolTipRole
|
QtCore.Qt.DisplayRole, QtCore.Qt.EditRole, QtCore.Qt.ToolTipRole
|
||||||
):
|
):
|
||||||
return self.label
|
return self.label
|
||||||
elif role == QtCore.Qt.FontRole:
|
elif role == QtCore.Qt.FontRole:
|
||||||
|
@ -367,7 +370,9 @@ class BMAddressWidget(BMTableWidgetItem, AccountMixin):
|
||||||
"""A common class for Table widget item with account"""
|
"""A common class for Table widget item with account"""
|
||||||
|
|
||||||
def _setup(self):
|
def _setup(self):
|
||||||
|
super(BMAddressWidget, self)._setup()
|
||||||
self.setEnabled(True)
|
self.setEnabled(True)
|
||||||
|
self.setType()
|
||||||
|
|
||||||
def _getLabel(self):
|
def _getLabel(self):
|
||||||
return self.label
|
return self.label
|
||||||
|
@ -387,14 +392,9 @@ class BMAddressWidget(BMTableWidgetItem, AccountMixin):
|
||||||
|
|
||||||
class MessageList_AddressWidget(BMAddressWidget):
|
class MessageList_AddressWidget(BMAddressWidget):
|
||||||
"""Address item in a messagelist"""
|
"""Address item in a messagelist"""
|
||||||
def __init__(self, parent, address=None, label=None, unread=False):
|
def __init__(self, address=None, label=None, unread=False):
|
||||||
self.setAddress(address)
|
self.setAddress(address)
|
||||||
super(MessageList_AddressWidget, self).__init__(parent, label, unread)
|
super(MessageList_AddressWidget, self).__init__(label, unread)
|
||||||
|
|
||||||
def _setup(self):
|
|
||||||
self.isEnabled = True
|
|
||||||
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
|
||||||
self.setType()
|
|
||||||
|
|
||||||
def setLabel(self, label=None):
|
def setLabel(self, label=None):
|
||||||
"""Set label"""
|
"""Set label"""
|
||||||
|
@ -443,12 +443,9 @@ class MessageList_AddressWidget(BMAddressWidget):
|
||||||
|
|
||||||
class MessageList_SubjectWidget(BMTableWidgetItem):
|
class MessageList_SubjectWidget(BMTableWidgetItem):
|
||||||
"""Message list subject item"""
|
"""Message list subject item"""
|
||||||
def __init__(self, parent, subject=None, label=None, unread=False):
|
def __init__(self, subject=None, label=None, unread=False):
|
||||||
self.setSubject(subject)
|
self.setSubject(subject)
|
||||||
super(MessageList_SubjectWidget, self).__init__(parent, label, unread)
|
super(MessageList_SubjectWidget, self).__init__(label, unread)
|
||||||
|
|
||||||
def _setup(self):
|
|
||||||
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
|
||||||
|
|
||||||
def setSubject(self, subject):
|
def setSubject(self, subject):
|
||||||
"""Set subject"""
|
"""Set subject"""
|
||||||
|
@ -469,6 +466,37 @@ class MessageList_SubjectWidget(BMTableWidgetItem):
|
||||||
return super(QtGui.QTableWidgetItem, self).__lt__(other)
|
return super(QtGui.QTableWidgetItem, self).__lt__(other)
|
||||||
|
|
||||||
|
|
||||||
|
# In order for the time columns on the Inbox and Sent tabs to be sorted
|
||||||
|
# correctly (rather than alphabetically), we need to overload the <
|
||||||
|
# operator and use this class instead of QTableWidgetItem.
|
||||||
|
class MessageList_TimeWidget(BMTableWidgetItem):
|
||||||
|
"""
|
||||||
|
A subclass of QTableWidgetItem for received (lastactiontime) field.
|
||||||
|
'<' operator is overloaded to sort by TimestampRole == 33
|
||||||
|
msgid is available by QtCore.Qt.UserRole
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, label=None, unread=False, timestamp=None, msgid=''):
|
||||||
|
super(MessageList_TimeWidget, self).__init__(label, unread)
|
||||||
|
self.setData(QtCore.Qt.UserRole, QtCore.QByteArray(msgid))
|
||||||
|
self.setData(TimestampRole, int(timestamp))
|
||||||
|
|
||||||
|
def __lt__(self, other):
|
||||||
|
return self.data(TimestampRole) < other.data(TimestampRole)
|
||||||
|
|
||||||
|
def data(self, role=QtCore.Qt.UserRole):
|
||||||
|
"""
|
||||||
|
Returns expected python types for QtCore.Qt.UserRole and TimestampRole
|
||||||
|
custom roles and super for any Qt role
|
||||||
|
"""
|
||||||
|
data = super(MessageList_TimeWidget, self).data(role)
|
||||||
|
if role == TimestampRole:
|
||||||
|
return int(data.toPyObject())
|
||||||
|
if role == QtCore.Qt.UserRole:
|
||||||
|
return str(data.toPyObject())
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
class Ui_AddressBookWidgetItem(BMAddressWidget):
|
class Ui_AddressBookWidgetItem(BMAddressWidget):
|
||||||
"""Addressbook item"""
|
"""Addressbook item"""
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
|
@ -518,8 +546,8 @@ class Ui_AddressBookWidgetItem(BMAddressWidget):
|
||||||
class Ui_AddressBookWidgetItemLabel(Ui_AddressBookWidgetItem):
|
class Ui_AddressBookWidgetItemLabel(Ui_AddressBookWidgetItem):
|
||||||
"""Addressbook label item"""
|
"""Addressbook label item"""
|
||||||
def __init__(self, address, label, acc_type):
|
def __init__(self, address, label, acc_type):
|
||||||
super(Ui_AddressBookWidgetItemLabel, self).__init__(label, acc_type)
|
|
||||||
self.address = address
|
self.address = address
|
||||||
|
super(Ui_AddressBookWidgetItemLabel, self).__init__(label, acc_type)
|
||||||
|
|
||||||
def data(self, role):
|
def data(self, role):
|
||||||
"""Return object data"""
|
"""Return object data"""
|
||||||
|
@ -530,9 +558,8 @@ class Ui_AddressBookWidgetItemLabel(Ui_AddressBookWidgetItem):
|
||||||
class Ui_AddressBookWidgetItemAddress(Ui_AddressBookWidgetItem):
|
class Ui_AddressBookWidgetItemAddress(Ui_AddressBookWidgetItem):
|
||||||
"""Addressbook address item"""
|
"""Addressbook address item"""
|
||||||
def __init__(self, address, label, acc_type):
|
def __init__(self, address, label, acc_type):
|
||||||
super(Ui_AddressBookWidgetItemAddress, self).__init__(address, acc_type)
|
|
||||||
self.address = address
|
self.address = address
|
||||||
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
super(Ui_AddressBookWidgetItemAddress, self).__init__(address, acc_type)
|
||||||
|
|
||||||
def data(self, role):
|
def data(self, role):
|
||||||
"""Return object data"""
|
"""Return object data"""
|
||||||
|
|
Reference in New Issue
Block a user