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): def rerenderTabTreeSubscriptions(self):
treeWidget = self.ui.treeWidgetSubscriptions treeWidget = self.ui.treeWidgetSubscriptions
folders = ['inbox', 'sent', 'trash'] folders = Ui_FolderWidget.folderWeight.keys()
folders.remove("new")
# sort ascending when creating # sort ascending when creating
if treeWidget.topLevelItemCount() == 0: if treeWidget.topLevelItemCount() == 0:
@ -463,7 +464,7 @@ class MyForm(settingsmixin.SMainWindow):
treeWidget = self.ui.treeWidgetYourIdentities treeWidget = self.ui.treeWidgetYourIdentities
elif tab == 'chan': elif tab == 'chan':
treeWidget = self.ui.treeWidgetChans treeWidget = self.ui.treeWidgetChans
folders = ['inbox', 'sent', 'trash'] folders = Ui_FolderWidget.folderWeight.keys()
# sort ascending when creating # sort ascending when creating
if treeWidget.topLevelItemCount() == 0: if treeWidget.topLevelItemCount() == 0:
@ -494,11 +495,18 @@ class MyForm(settingsmixin.SMainWindow):
enabled[toAddress] = isEnabled enabled[toAddress] = isEnabled
# get number of (unread) messages # 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') queryreturn = sqlQuery('SELECT toaddress, folder, count(msgid) as cnt FROM inbox WHERE read = 0 GROUP BY toaddress, folder')
for row in queryreturn: for row in queryreturn:
toaddress, folder, cnt = row toaddress, folder, cnt = row
total += cnt
if toaddress in db and folder in db[toaddress]: if toaddress in db and folder in db[toaddress]:
db[toaddress][folder] = cnt db[toaddress][folder] = cnt
if tab == "messages":
db[None] = {}
db[None]["inbox"] = total
db[None]["new"] = total
enabled[None] = True
if treeWidget.isSortingEnabled(): if treeWidget.isSortingEnabled():
treeWidget.setSortingEnabled(False) treeWidget.setSortingEnabled(False)
@ -546,6 +554,10 @@ class MyForm(settingsmixin.SMainWindow):
j = 0 j = 0
unread = 0 unread = 0
for folder in folders: 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]) subwidget = Ui_FolderWidget(widget, j, toAddress, folder, db[toAddress][folder])
unread += db[toAddress][folder] unread += db[toAddress][folder]
j += 1 j += 1
@ -914,22 +926,25 @@ class MyForm(settingsmixin.SMainWindow):
if isinstance(item, Ui_AddressWidget): if isinstance(item, Ui_AddressWidget):
self.drawTrayIcon(self.currentTrayIconFileName, self.findInboxUnreadCount(self.unreadCount -1)) 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] widgets = [self.ui.treeWidgetYourIdentities, self.ui.treeWidgetSubscriptions, self.ui.treeWidgetChans]
else: else:
widgets = [widget] widgets = [widget]
# FIXME this is a hack
if folder == "new":
folder = "inbox"
for treeWidget in widgets: for treeWidget in widgets:
root = treeWidget.invisibleRootItem() root = treeWidget.invisibleRootItem()
for i in range(root.childCount()): for i in range(root.childCount()):
addressItem = root.child(i) 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 continue
updateUnreadCount(addressItem) updateUnreadCount(addressItem)
if addressItem.childCount == 0: if addressItem.childCount == 0:
continue continue
for j in range(addressItem.childCount()): for j in range(addressItem.childCount()):
folderItem = addressItem.child(j) 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 continue
updateUnreadCount(folderItem) updateUnreadCount(folderItem)
@ -1052,11 +1067,12 @@ class MyForm(settingsmixin.SMainWindow):
tableWidget.keyPressEvent = self.tableWidgetSentKeyPressEvent tableWidget.keyPressEvent = self.tableWidgetSentKeyPressEvent
# Load messages from database file # 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': if folder == 'sent':
self.loadSent(tableWidget, account, where, what) self.loadSent(tableWidget, account, where, what)
return return
if what != "":
what = "%" + what + "%" what = "%" + what + "%"
if where == _translate("MainWindow", "To"): if where == _translate("MainWindow", "To"):
where = "toaddress" where = "toaddress"
@ -1068,30 +1084,39 @@ class MyForm(settingsmixin.SMainWindow):
where = "message" where = "message"
else: else:
where = "toaddress || fromaddress || subject || message" where = "toaddress || fromaddress || subject || message"
else:
what = None
if tableWidget == self.ui.tableWidgetInboxSubscriptions: if tableWidget == self.ui.tableWidgetInboxSubscriptions:
xAddress = "fromaddress" xAddress = "fromaddress"
else: else:
xAddress = "toaddress" 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: if folder is not None:
sqlStatement = ''' sqlStatementParts.append("folder = ? ")
SELECT folder, msgid, toaddress, fromaddress, subject, received, read sqlArguments.append(folder)
FROM inbox WHERE ''' + xAddress + '''=? AND folder=? AND %s LIKE ? if what is not None:
ORDER BY received sqlStatementParts.append("%s LIKE ?" % (where))
''' % (where) sqlArguments.append(what)
queryreturn = sqlQuery(sqlStatement, account, folder, what) if unreadOnly:
else: sqlStatementParts.append("read = 0")
sqlStatement = ''' if len(sqlStatementParts) > 0:
SELECT folder, msgid, toaddress, fromaddress, subject, received, read sqlStatementBase += "WHERE " + " AND ".join(sqlStatementParts)
FROM inbox WHERE ''' + xAddress + '''=? AND folder != "trash" AND %s LIKE ? queryreturn = sqlQuery(sqlStatementBase, sqlArguments)
ORDER BY received
''' % (where)
queryreturn = sqlQuery(sqlStatement, account, what)
tableWidget.setRowCount(0) tableWidget.setRowCount(0)
if account is not None:
tableWidget.setColumnHidden(0, True) tableWidget.setColumnHidden(0, True)
tableWidget.setColumnHidden(1, False) tableWidget.setColumnHidden(1, False)
else:
tableWidget.setColumnHidden(0, False)
tableWidget.setColumnHidden(1, False)
tableWidget.setSortingEnabled(False) tableWidget.setSortingEnabled(False)
font = QFont() font = QFont()
@ -1911,7 +1936,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(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) inbox.removeRow(i)
break break
@ -2420,7 +2445,7 @@ class MyForm(settingsmixin.SMainWindow):
self.propagateUnreadCount(acct.address) self.propagateUnreadCount(acct.address)
if shared.config.getboolean('bitmessagesettings', 'showtraynotifications'): 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) 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 # Ubuntu should notify of new message irespective of whether it's in current message list or not
self.ubuntuMessagingMenuUpdate(True, None, acct.toLabel) self.ubuntuMessagingMenuUpdate(True, None, acct.toLabel)
return return
@ -3007,9 +3032,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(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: 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) # 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.
@ -3170,7 +3195,10 @@ 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():
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("") self.getCurrentMessageTextedit().setText("")
tableWidget.removeRow(currentRow) tableWidget.removeRow(currentRow)
self.statusBar().showMessage(_translate( self.statusBar().showMessage(_translate(
@ -3179,8 +3207,6 @@ class MyForm(settingsmixin.SMainWindow):
tableWidget.selectRow(currentRow) tableWidget.selectRow(currentRow)
else: else:
tableWidget.selectRow(currentRow - 1) tableWidget.selectRow(currentRow - 1)
if unread:
self.propagateUnreadCount(self.getCurrentAccount(), None, self.getCurrentTreeWidget(), 0)
def on_action_TrashUndelete(self): def on_action_TrashUndelete(self):
tableWidget = self.getCurrentMessagelist() tableWidget = self.getCurrentMessagelist()
@ -3194,7 +3220,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():
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("") self.getCurrentMessageTextedit().setText("")
tableWidget.removeRow(currentRow) tableWidget.removeRow(currentRow)
self.statusBar().showMessage(_translate( self.statusBar().showMessage(_translate(
@ -3203,8 +3230,6 @@ class MyForm(settingsmixin.SMainWindow):
tableWidget.selectRow(currentRow) tableWidget.selectRow(currentRow)
else: else:
tableWidget.selectRow(currentRow - 1) tableWidget.selectRow(currentRow - 1)
if unread:
self.propagateUnreadCount(self.getCurrentAccount(), None, self.getCurrentTreeWidget(), 0)
def on_action_InboxSaveMessageAs(self): def on_action_InboxSaveMessageAs(self):
tableWidget = self.getCurrentMessagelist() tableWidget = self.getCurrentMessagelist()
@ -3255,7 +3280,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():
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("") self.getCurrentMessageTextedit().setPlainText("")
tableWidget.removeRow(currentRow) tableWidget.removeRow(currentRow)
self.statusBar().showMessage(_translate( self.statusBar().showMessage(_translate(
@ -3264,8 +3289,6 @@ class MyForm(settingsmixin.SMainWindow):
self.ui.tableWidgetInbox.selectRow(currentRow) self.ui.tableWidgetInbox.selectRow(currentRow)
else: else:
self.ui.tableWidgetInbox.selectRow(currentRow - 1) self.ui.tableWidgetInbox.selectRow(currentRow - 1)
if unread:
self.propagateUnreadCount(self.getCurrentAccount(), None, self.getCurrentTreeWidget(), 0)
def on_action_ForceSend(self): def on_action_ForceSend(self):
currentRow = self.ui.tableWidgetInbox.currentRow() currentRow = self.ui.tableWidgetInbox.currentRow()
@ -3630,7 +3653,7 @@ class MyForm(settingsmixin.SMainWindow):
return currentItem return currentItem
return False return False
def getCurrentAccount(self, treeWidget = None): def getCurrentAccount(self, treeWidget = None, force = None):
currentItem = self.getCurrentItem(treeWidget) currentItem = self.getCurrentItem(treeWidget)
if currentItem: if currentItem:
account = currentItem.address account = currentItem.address
@ -3895,6 +3918,9 @@ class MyForm(settingsmixin.SMainWindow):
if messagelist: if messagelist:
account = self.getCurrentAccount() account = self.getCurrentAccount()
folder = self.getCurrentFolder() folder = self.getCurrentFolder()
if folder == "new":
self.loadMessagelist(messagelist, account, None, unreadOnly = True)
else:
self.loadMessagelist(messagelist, account, folder) self.loadMessagelist(messagelist, account, folder)
def treeWidgetItemChanged(self, item, column): def treeWidgetItemChanged(self, item, column):
@ -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, 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(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: else:
data = self.getCurrentMessageId() data = self.getCurrentMessageId()

View File

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