Global folder, global search, unread folder

Fixes #38
Fixes #39

Minor unread refresh issues.
This commit is contained in:
mailchuck 2015-11-27 00:56:25 +01:00 committed by Peter Surda
parent 6862952c55
commit be02116af9
2 changed files with 84 additions and 55 deletions

View File

@ -377,7 +377,8 @@ class MyForm(settingsmixin.SMainWindow):
def rerenderTabTreeSubscriptions(self):
treeWidget = self.ui.treeWidgetSubscriptions
folders = ['inbox', 'sent', 'trash']
folders = Ui_FolderWidget.folderWeight.keys()
folders.remove("new")
# sort ascending when creating
if treeWidget.topLevelItemCount() == 0:
@ -463,7 +464,7 @@ class MyForm(settingsmixin.SMainWindow):
treeWidget = self.ui.treeWidgetYourIdentities
elif tab == 'chan':
treeWidget = self.ui.treeWidgetChans
folders = ['inbox', 'sent', 'trash']
folders = Ui_FolderWidget.folderWeight.keys()
# sort ascending when creating
if treeWidget.topLevelItemCount() == 0:
@ -494,11 +495,18 @@ class MyForm(settingsmixin.SMainWindow):
enabled[toAddress] = isEnabled
# get number of (unread) messages
total = 0
queryreturn = sqlQuery('SELECT toaddress, folder, count(msgid) as cnt FROM inbox WHERE read = 0 GROUP BY toaddress, folder')
for row in queryreturn:
toaddress, folder, cnt = row
total += cnt
if toaddress in db and folder in db[toaddress]:
db[toaddress][folder] = cnt
if tab == "messages":
db[None] = {}
db[None]["inbox"] = total
db[None]["new"] = total
enabled[None] = True
if treeWidget.isSortingEnabled():
treeWidget.setSortingEnabled(False)
@ -546,6 +554,10 @@ class MyForm(settingsmixin.SMainWindow):
j = 0
unread = 0
for folder in folders:
if toAddress is not None and folder == "new":
continue
if toAddress is None and folder in ["trash", "sent"]:
continue
subwidget = Ui_FolderWidget(widget, j, toAddress, folder, db[toAddress][folder])
unread += db[toAddress][folder]
j += 1
@ -914,22 +926,25 @@ class MyForm(settingsmixin.SMainWindow):
if isinstance(item, Ui_AddressWidget):
self.drawTrayIcon(self.currentTrayIconFileName, self.findInboxUnreadCount(self.unreadCount -1))
if widget == None:
if widget == None or self.getCurrentAccount() == None:
widgets = [self.ui.treeWidgetYourIdentities, self.ui.treeWidgetSubscriptions, self.ui.treeWidgetChans]
else:
widgets = [widget]
# FIXME this is a hack
if folder == "new":
folder = "inbox"
for treeWidget in widgets:
root = treeWidget.invisibleRootItem()
for i in range(root.childCount()):
addressItem = root.child(i)
if address is not None and addressItem.data(0, QtCore.Qt.UserRole) != address:
if addressItem.type != AccountMixin.ALL and address is not None and addressItem.data(0, QtCore.Qt.UserRole) != address:
continue
updateUnreadCount(addressItem)
if addressItem.childCount == 0:
continue
for j in range(addressItem.childCount()):
folderItem = addressItem.child(j)
if folder is not None and folderItem.folderName != folder:
if folder is not None and folderItem.folderName != folder and addressItem.type != AccountMixin.ALL:
continue
updateUnreadCount(folderItem)
@ -1052,46 +1067,56 @@ class MyForm(settingsmixin.SMainWindow):
tableWidget.keyPressEvent = self.tableWidgetSentKeyPressEvent
# Load messages from database file
def loadMessagelist(self, tableWidget, account, folder="inbox", where="", what=""):
def loadMessagelist(self, tableWidget, account, folder="inbox", where="", what="", unreadOnly = False):
if folder == 'sent':
self.loadSent(tableWidget, account, where, what)
return
what = "%" + what + "%"
if where == _translate("MainWindow", "To"):
where = "toaddress"
elif where == _translate("MainWindow", "From"):
where = "fromaddress"
elif where == _translate("MainWindow", "Subject"):
where = "subject"
elif where == _translate("MainWindow", "Message"):
where = "message"
if what != "":
what = "%" + what + "%"
if where == _translate("MainWindow", "To"):
where = "toaddress"
elif where == _translate("MainWindow", "From"):
where = "fromaddress"
elif where == _translate("MainWindow", "Subject"):
where = "subject"
elif where == _translate("MainWindow", "Message"):
where = "message"
else:
where = "toaddress || fromaddress || subject || message"
else:
where = "toaddress || fromaddress || subject || message"
what = None
if tableWidget == self.ui.tableWidgetInboxSubscriptions:
xAddress = "fromaddress"
else:
xAddress = "toaddress"
sqlStatementBase = '''SELECT folder, msgid, toaddress, fromaddress, subject, received, read
FROM inbox '''
sqlStatementParts = []
sqlArguments = []
if account is not None:
sqlStatementParts.append(xAddress + " = ? ")
sqlArguments.append(account)
if folder is not None:
sqlStatement = '''
SELECT folder, msgid, toaddress, fromaddress, subject, received, read
FROM inbox WHERE ''' + xAddress + '''=? AND folder=? AND %s LIKE ?
ORDER BY received
''' % (where)
queryreturn = sqlQuery(sqlStatement, account, folder, what)
else:
sqlStatement = '''
SELECT folder, msgid, toaddress, fromaddress, subject, received, read
FROM inbox WHERE ''' + xAddress + '''=? AND folder != "trash" AND %s LIKE ?
ORDER BY received
''' % (where)
queryreturn = sqlQuery(sqlStatement, account, what)
sqlStatementParts.append("folder = ? ")
sqlArguments.append(folder)
if what is not None:
sqlStatementParts.append("%s LIKE ?" % (where))
sqlArguments.append(what)
if unreadOnly:
sqlStatementParts.append("read = 0")
if len(sqlStatementParts) > 0:
sqlStatementBase += "WHERE " + " AND ".join(sqlStatementParts)
queryreturn = sqlQuery(sqlStatementBase, sqlArguments)
tableWidget.setRowCount(0)
tableWidget.setColumnHidden(0, True)
tableWidget.setColumnHidden(1, False)
if account is not None:
tableWidget.setColumnHidden(0, True)
tableWidget.setColumnHidden(1, False)
else:
tableWidget.setColumnHidden(0, False)
tableWidget.setColumnHidden(1, False)
tableWidget.setSortingEnabled(False)
font = QFont()
@ -1911,7 +1936,7 @@ class MyForm(settingsmixin.SMainWindow):
self.statusBar().showMessage(_translate(
"MainWindow", "Message trashed"))
treeWidget = self.widgetConvert(inbox)
self.propagateUnreadCount(self.getCurrentAccount(treeWidget), self.getCurrentFolder(treeWidget), treeWidget, 0)
self.propagateUnreadCount(str(inbox.item(i, 1 if inbox == self.ui.tableWidgetInboxSubscriptions else 0).data(Qt.UserRole).toPyObject()), self.getCurrentFolder(treeWidget), treeWidget, 0)
inbox.removeRow(i)
break
@ -2420,7 +2445,7 @@ class MyForm(settingsmixin.SMainWindow):
self.propagateUnreadCount(acct.address)
if shared.config.getboolean('bitmessagesettings', 'showtraynotifications'):
self.notifierShow(unicode(_translate("MainWindow",'New Message').toUtf8(),'utf-8'), unicode(_translate("MainWindow",'From ').toUtf8(),'utf-8') + unicode(acct.fromLabel, 'utf-8'), self.SOUND_UNKNOWN, None)
if (self.getCurrentFolder(treeWidget) != "inbox" and self.getCurrentFolder(treeWidget) is not None) or self.getCurrentAccount(treeWidget) != acct.address:
if self.getCurrentAccount() is not None and ((self.getCurrentFolder(treeWidget) != "inbox" and self.getCurrentFolder(treeWidget) is not None) or self.getCurrentAccount(treeWidget) != acct.address):
# Ubuntu should notify of new message irespective of whether it's in current message list or not
self.ubuntuMessagingMenuUpdate(True, None, acct.toLabel)
return
@ -3007,9 +3032,9 @@ class MyForm(settingsmixin.SMainWindow):
"?," * len(inventoryHashesToMarkUnread))[:-1], *inventoryHashesToMarkUnread)
if modified == 1:
# performance optimisation
self.propagateUnreadCount(self.getCurrentAccount(), self.getCurrentFolder())
self.propagateUnreadCount(str(tableWidget.item(currentRow, 1 if tableWidget == self.ui.tableWidgetInboxSubscriptions else 0).data(Qt.UserRole).toPyObject()), self.getCurrentFolder())
else:
self.propagateUnreadCount(self.getCurrentAccount(), self.getCurrentFolder(), self.getCurrentTreeWidget(), 0)
self.propagateUnreadCount(str(tableWidget.item(currentRow, 1 if tableWidget == self.ui.tableWidgetInboxSubscriptions else 0).data(Qt.UserRole).toPyObject()), self.getCurrentFolder(), self.getCurrentTreeWidget(), 0)
# 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.
# We could also select upwards, but then our problem would be with the topmost message.
@ -3170,7 +3195,10 @@ class MyForm(settingsmixin.SMainWindow):
else:
sqlExecute('''UPDATE inbox SET folder='trash' WHERE msgid=?''', inventoryHashToTrash)
if tableWidget.item(currentRow, 0).font().bold():
unread = True
self.propagateUnreadCount(str(tableWidget.item(currentRow, 1 if tableWidget == self.ui.tableWidgetInboxSubscriptions else 0).data(Qt.UserRole).toPyObject()), folder, self.getCurrentTreeWidget(), -1)
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.getCurrentMessageTextedit().setText("")
tableWidget.removeRow(currentRow)
self.statusBar().showMessage(_translate(
@ -3179,8 +3207,6 @@ class MyForm(settingsmixin.SMainWindow):
tableWidget.selectRow(currentRow)
else:
tableWidget.selectRow(currentRow - 1)
if unread:
self.propagateUnreadCount(self.getCurrentAccount(), None, self.getCurrentTreeWidget(), 0)
def on_action_TrashUndelete(self):
tableWidget = self.getCurrentMessagelist()
@ -3194,7 +3220,8 @@ class MyForm(settingsmixin.SMainWindow):
currentRow, 3).data(Qt.UserRole).toPyObject())
sqlExecute('''UPDATE inbox SET folder='inbox' WHERE msgid=?''', inventoryHashToTrash)
if tableWidget.item(currentRow, 0).font().bold():
unread = True
self.propagateUnreadCount(str(tableWidget.item(currentRow, 1 if tableWidget == self.ui.tableWidgetInboxSubscriptions else 0).data(Qt.UserRole).toPyObject()), "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.getCurrentMessageTextedit().setText("")
tableWidget.removeRow(currentRow)
self.statusBar().showMessage(_translate(
@ -3203,8 +3230,6 @@ class MyForm(settingsmixin.SMainWindow):
tableWidget.selectRow(currentRow)
else:
tableWidget.selectRow(currentRow - 1)
if unread:
self.propagateUnreadCount(self.getCurrentAccount(), None, self.getCurrentTreeWidget(), 0)
def on_action_InboxSaveMessageAs(self):
tableWidget = self.getCurrentMessagelist()
@ -3255,7 +3280,7 @@ class MyForm(settingsmixin.SMainWindow):
else:
sqlExecute('''UPDATE sent SET folder='trash' WHERE ackdata=?''', ackdataToTrash)
if tableWidget.item(currentRow, 0).font().bold():
unread = True
self.propagateUnreadCount(str(tableWidget.item(currentRow, 1 if tableWidget == self.ui.tableWidgetInboxSubscriptions else 0).data(Qt.UserRole).toPyObject()), folder, self.getCurrentTreeWidget(), -1)
self.getCurrentMessageTextedit().setPlainText("")
tableWidget.removeRow(currentRow)
self.statusBar().showMessage(_translate(
@ -3264,8 +3289,6 @@ class MyForm(settingsmixin.SMainWindow):
self.ui.tableWidgetInbox.selectRow(currentRow)
else:
self.ui.tableWidgetInbox.selectRow(currentRow - 1)
if unread:
self.propagateUnreadCount(self.getCurrentAccount(), None, self.getCurrentTreeWidget(), 0)
def on_action_ForceSend(self):
currentRow = self.ui.tableWidgetInbox.currentRow()
@ -3630,7 +3653,7 @@ class MyForm(settingsmixin.SMainWindow):
return currentItem
return False
def getCurrentAccount(self, treeWidget = None):
def getCurrentAccount(self, treeWidget = None, force = None):
currentItem = self.getCurrentItem(treeWidget)
if currentItem:
account = currentItem.address
@ -3895,7 +3918,10 @@ class MyForm(settingsmixin.SMainWindow):
if messagelist:
account = self.getCurrentAccount()
folder = self.getCurrentFolder()
self.loadMessagelist(messagelist, account, folder)
if folder == "new":
self.loadMessagelist(messagelist, account, None, unreadOnly = True)
else:
self.loadMessagelist(messagelist, account, folder)
def treeWidgetItemChanged(self, item, column):
# only for manual edits. automatic edits (setText) are ignored
@ -3977,7 +4003,7 @@ class MyForm(settingsmixin.SMainWindow):
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, 3).setFont(font)
self.propagateUnreadCount(self.getCurrentAccount(), folder, self.getCurrentTreeWidget(), -1)
self.propagateUnreadCount(str(tableWidget.item(currentRow, 1 if tableWidget == self.ui.tableWidgetInboxSubscriptions else 0).data(Qt.UserRole).toPyObject()), folder, self.getCurrentTreeWidget(), -1)
else:
data = self.getCurrentMessageId()

View File

@ -39,7 +39,10 @@ class AccountMixin (object):
return brush
def setAddress(self, address):
self.address = str(address)
if address is None:
self.address = None
else:
self.address = str(address)
self.updateText()
def setUnreadCount(self, cnt):
@ -71,7 +74,7 @@ class AccountMixin (object):
class Ui_FolderWidget(QtGui.QTreeWidgetItem, AccountMixin):
folderWeight = {"inbox": 1, "sent": 2, "trash": 3}
folderWeight = {"inbox": 1, "new": 2, "sent": 3, "trash": 4}
def __init__(self, parent, pos = 0, address = "", folderName = "", unreadCount = 0):
super(QtGui.QTreeWidgetItem, self).__init__()
self.initialised = False
@ -110,11 +113,11 @@ class Ui_FolderWidget(QtGui.QTreeWidgetItem, AccountMixin):
if self.folderName in self.folderWeight:
x = self.folderWeight[self.folderName]
else:
x = 4
x = 99
if other.folderName in self.folderWeight:
y = self.folderWeight[other.folderName]
else:
y = 4
y = 99
reverse = False
if self.treeWidget().header().sortIndicatorOrder() == QtCore.Qt.DescendingOrder:
reverse = True
@ -141,12 +144,12 @@ class Ui_AddressWidget(QtGui.QTreeWidgetItem, AccountMixin, SettingsMixin):
def _getLabel(self):
if self.address is None:
label = QtGui.QApplication.translate("MainWindow", "All accounts")
return unicode(str(QtGui.QApplication.translate("MainWindow", "All accounts")), 'utf-8')
else:
try:
return unicode(shared.config.get(self.address, 'label'), 'utf-8)')
except:
return self.address
return unicode(self.address, 'utf-8')
def _getAddressBracket(self, unreadCount = False):
ret = ""