New message in correct tab

Newly arriving messages now appear in the correct tab. Previously it
assumed it was always "Messages" tab. Partially addresses #3.
This commit is contained in:
mailchuck 2015-10-22 23:56:20 +02:00
parent 71553ae188
commit 01df34680d
No known key found for this signature in database
GPG Key ID: B6311FA753FBF089

View File

@ -2238,31 +2238,33 @@ class MyForm(QtGui.QMainWindow):
# pseudo-mailing-list. The message will be broadcast out. This function # pseudo-mailing-list. The message will be broadcast out. This function
# puts the message on the 'Sent' tab. # puts the message on the 'Sent' tab.
def displayNewSentMessage(self, toAddress, toLabel, fromAddress, subject, message, ackdata): def displayNewSentMessage(self, toAddress, toLabel, fromAddress, subject, message, ackdata):
if self.getCurrentFolder() != "sent" or self.getCurrentAccount() != fromAddress:
return
subject = shared.fixPotentiallyInvalidUTF8Data(subject) subject = shared.fixPotentiallyInvalidUTF8Data(subject)
message = shared.fixPotentiallyInvalidUTF8Data(message) message = shared.fixPotentiallyInvalidUTF8Data(message)
acct = accountClass(fromAddress) acct = accountClass(fromAddress)
acct.parseMessage(toAddress, fromAddress, subject, message) acct.parseMessage(toAddress, fromAddress, subject, message)
sent = self.getAccountMessagelist(acct)
treeWidget = self.getAccountTreeWidget(acct)
if self.getCurrentFolder(treeWidget) != "sent" or self.getCurrentAccount(treeWidget) != fromAddress:
return
self.ui.tableWidgetInbox.setSortingEnabled(False) sent.setSortingEnabled(False)
self.ui.tableWidgetInbox.insertRow(0) sent.insertRow(0)
newItem = QtGui.QTableWidgetItem(unicode(acct.toLabel, 'utf-8')) newItem = QtGui.QTableWidgetItem(unicode(acct.toLabel, 'utf-8'))
newItem.setToolTip(unicode(acct.toLabel, 'utf-8')) newItem.setToolTip(unicode(acct.toLabel, 'utf-8'))
newItem.setData(Qt.UserRole, str(toAddress)) newItem.setData(Qt.UserRole, str(toAddress))
newItem.setIcon(avatarize(toAddress)) newItem.setIcon(avatarize(toAddress))
self.ui.tableWidgetInbox.setItem(0, 0, newItem) sent.setItem(0, 0, newItem)
newItem = QtGui.QTableWidgetItem(unicode(acct.fromLabel, 'utf-8')) newItem = QtGui.QTableWidgetItem(unicode(acct.fromLabel, 'utf-8'))
newItem.setToolTip(unicode(acct.fromLabel, 'utf-8')) newItem.setToolTip(unicode(acct.fromLabel, 'utf-8'))
newItem.setData(Qt.UserRole, str(fromAddress)) newItem.setData(Qt.UserRole, str(fromAddress))
newItem.setIcon(avatarize(fromAddress)) newItem.setIcon(avatarize(fromAddress))
self.ui.tableWidgetInbox.setItem(0, 1, newItem) sent.setItem(0, 1, newItem)
newItem = QtGui.QTableWidgetItem(unicode(acct.subject, 'utf-8)')) newItem = QtGui.QTableWidgetItem(unicode(acct.subject, 'utf-8)'))
newItem.setToolTip(unicode(acct.subject, 'utf-8)')) newItem.setToolTip(unicode(acct.subject, 'utf-8)'))
newItem.setData(Qt.UserRole, str(subject)) newItem.setData(Qt.UserRole, str(subject))
#newItem.setData(Qt.UserRole, unicode(message, 'utf-8)')) # No longer hold the message in the table; we'll use a SQL query to display it as needed. #newItem.setData(Qt.UserRole, unicode(message, 'utf-8)')) # No longer hold the message in the table; we'll use a SQL query to display it as needed.
self.ui.tableWidgetInbox.setItem(0, 2, newItem) sent.setItem(0, 2, newItem)
# newItem = QtGui.QTableWidgetItem('Doing work necessary to send # newItem = QtGui.QTableWidgetItem('Doing work necessary to send
# broadcast...'+ # broadcast...'+
# l10n.formatTimestamp()) # l10n.formatTimestamp())
@ -2270,18 +2272,18 @@ class MyForm(QtGui.QMainWindow):
newItem.setToolTip(_translate("MainWindow", "Work is queued. %1").arg(l10n.formatTimestamp())) newItem.setToolTip(_translate("MainWindow", "Work is queued. %1").arg(l10n.formatTimestamp()))
newItem.setData(Qt.UserRole, QByteArray(ackdata)) newItem.setData(Qt.UserRole, QByteArray(ackdata))
newItem.setData(33, int(time.time())) newItem.setData(33, int(time.time()))
self.ui.tableWidgetInbox.setItem(0, 3, newItem) sent.setItem(0, 3, newItem)
self.ui.textEditInboxMessage.setPlainText(unicode(message, 'utf-8)')) self.getAccountTextedit(acct).setPlainText(unicode(message, 'utf-8)'))
self.ui.tableWidgetInbox.setSortingEnabled(True) sent.setSortingEnabled(True)
def displayNewInboxMessage(self, inventoryHash, toAddress, fromAddress, subject, message): def displayNewInboxMessage(self, inventoryHash, toAddress, fromAddress, subject, message):
if (self.getCurrentFolder() != "inbox" and self.getCurrentFolder() != False) or self.getCurrentAccount() != toAddress:
return
subject = shared.fixPotentiallyInvalidUTF8Data(subject) subject = shared.fixPotentiallyInvalidUTF8Data(subject)
acct = accountClass(toAddress) acct = accountClass(toAddress)
acct.parseMessage(toAddress, fromAddress, subject, message) acct.parseMessage(toAddress, fromAddress, subject, message)
inbox = self.getAccountMessagelist(acct)
inbox = self.getCurrentMessagelist() treeWidget = self.getAccountTreeWidget(acct)
if (self.getCurrentFolder(treeWidget) != "inbox" and self.getCurrentFolder(treeWidget) != False) or self.getCurrentAccount(treeWidget) != toAddress:
return
font = QFont() font = QFont()
font.setBold(True) font.setBold(True)
@ -3264,6 +3266,17 @@ class MyForm(QtGui.QMainWindow):
else: else:
return False return False
def getAccountTreeWidget(self, account):
try:
if account.type == 'chan':
return self.ui.treeWidgetChans
elif account.type == 'subscription':
return self.ui.treeWidgetSubscriptions
else:
return self.ui.treeWidgetYourIdentities
except:
return self.ui.treeWidgetYourIdentities
def getCurrentMessagelist(self): def getCurrentMessagelist(self):
currentIndex = self.ui.tabWidget.currentIndex(); currentIndex = self.ui.tabWidget.currentIndex();
messagelistList = [ messagelistList = [
@ -3277,6 +3290,17 @@ class MyForm(QtGui.QMainWindow):
else: else:
return False return False
def getAccountMessagelist(self, account):
try:
if account.type == 'chan':
return self.ui.tableWidgetInboxChans
elif account.type == 'subscription':
return self.ui.tableWidgetInboxSubscriptions
else:
return self.ui.tableWidgetInbox
except:
return self.ui.tableWidgetInbox
def getCurrentMessageId(self): def getCurrentMessageId(self):
messagelist = self.getCurrentMessagelist() messagelist = self.getCurrentMessagelist()
if messagelist: if messagelist:
@ -3300,6 +3324,17 @@ class MyForm(QtGui.QMainWindow):
else: else:
return False return False
def getAccountTextedit(self, account):
try:
if account.type == 'chan':
return self.ui.textEditInboxMessageChans
elif account.type == 'subscription':
return self.ui.textEditInboxSubscriptions
else:
return self.ui.textEditInboxMessage
except:
return self.ui.textEditInboxMessage
def getCurrentSearchLine(self): def getCurrentSearchLine(self):
currentIndex = self.ui.tabWidget.currentIndex(); currentIndex = self.ui.tabWidget.currentIndex();
messagelistList = [ messagelistList = [
@ -3327,7 +3362,8 @@ class MyForm(QtGui.QMainWindow):
return False return False
# Group of functions for the Your Identities dialog box # Group of functions for the Your Identities dialog box
def getCurrentItem(self): def getCurrentItem(self, treeWidget = None):
if treeWidget is None:
treeWidget = self.getCurrentTreeWidget() treeWidget = self.getCurrentTreeWidget()
if treeWidget: if treeWidget:
currentItem = treeWidget.currentItem() currentItem = treeWidget.currentItem()
@ -3335,8 +3371,8 @@ class MyForm(QtGui.QMainWindow):
return currentItem return currentItem
return False return False
def getCurrentAccount(self): def getCurrentAccount(self, treeWidget = None):
currentItem = self.getCurrentItem() currentItem = self.getCurrentItem(treeWidget)
if currentItem: if currentItem:
account = currentItem.address account = currentItem.address
return account return account
@ -3344,7 +3380,8 @@ class MyForm(QtGui.QMainWindow):
# TODO need debug msg? # TODO need debug msg?
return False return False
def getCurrentFolder(self): def getCurrentFolder(self, treeWidget = None):
if treeWidget is None:
treeWidget = self.getCurrentTreeWidget() treeWidget = self.getCurrentTreeWidget()
#treeWidget = self.ui.treeWidgetYourIdentities #treeWidget = self.ui.treeWidgetYourIdentities
if treeWidget: if treeWidget: