Implemented folder and widget args in propagateUnreadCount(), removed the rest
This commit is contained in:
parent
ffdd91b021
commit
0c1e516921
|
@ -967,35 +967,44 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
for col in (0, 1, 2):
|
for col in (0, 1, 2):
|
||||||
related.item(rrow, col).setUnread(not status)
|
related.item(rrow, col).setUnread(not status)
|
||||||
|
|
||||||
def propagateUnreadCount(
|
# Here we need to update unread count for:
|
||||||
self, address=None, folder='inbox', widget=None, type=1):
|
# - all widgets if there is no args
|
||||||
widgets = (
|
# - All accounts
|
||||||
self.ui.treeWidgetYourIdentities,
|
# - corresponding account if current is "All accounts"
|
||||||
self.ui.treeWidgetSubscriptions, self.ui.treeWidgetChans)
|
# - current account otherwise
|
||||||
|
def propagateUnreadCount(self, folder=None, widget=None):
|
||||||
queryReturn = sqlQuery(
|
queryReturn = sqlQuery(
|
||||||
'SELECT toaddress, folder, COUNT(msgid) AS cnt'
|
'SELECT toaddress, folder, COUNT(msgid) AS cnt'
|
||||||
' FROM inbox WHERE read = 0 GROUP BY toaddress, folder')
|
' FROM inbox WHERE read = 0 GROUP BY toaddress, folder')
|
||||||
totalUnread = {}
|
totalUnread = {}
|
||||||
normalUnread = {}
|
normalUnread = {}
|
||||||
for addr, folder, count in queryReturn:
|
|
||||||
try:
|
|
||||||
normalUnread[addr][folder] = count
|
|
||||||
except KeyError:
|
|
||||||
normalUnread[addr] = {folder: count}
|
|
||||||
try:
|
|
||||||
totalUnread[folder] += count
|
|
||||||
except KeyError:
|
|
||||||
totalUnread[folder] = count
|
|
||||||
queryReturn = sqlQuery(
|
|
||||||
'SELECT fromaddress, folder, COUNT(msgid) AS cnt FROM inbox'
|
|
||||||
' WHERE read = 0 AND toaddress = ? GROUP BY fromaddress, folder',
|
|
||||||
str_broadcast_subscribers)
|
|
||||||
broadcastsUnread = {}
|
broadcastsUnread = {}
|
||||||
for addr, folder, count in queryReturn:
|
for addr, fld, count in queryReturn:
|
||||||
try:
|
try:
|
||||||
broadcastsUnread[addr][folder] = count
|
normalUnread[addr][fld] = count
|
||||||
except KeyError:
|
except KeyError:
|
||||||
broadcastsUnread[addr] = {folder: count}
|
normalUnread[addr] = {fld: count}
|
||||||
|
try:
|
||||||
|
totalUnread[fld] += count
|
||||||
|
except KeyError:
|
||||||
|
totalUnread[fld] = count
|
||||||
|
if widget in (
|
||||||
|
self.ui.treeWidgetSubscriptions, self.ui.treeWidgetChans):
|
||||||
|
widgets = (self.ui.treeWidgetYourIdentities,)
|
||||||
|
else:
|
||||||
|
widgets = (
|
||||||
|
self.ui.treeWidgetYourIdentities,
|
||||||
|
self.ui.treeWidgetSubscriptions, self.ui.treeWidgetChans
|
||||||
|
)
|
||||||
|
queryReturn = sqlQuery(
|
||||||
|
'SELECT fromaddress, folder, COUNT(msgid) AS cnt'
|
||||||
|
' FROM inbox WHERE read = 0 AND toaddress = ?'
|
||||||
|
' GROUP BY fromaddress, folder', str_broadcast_subscribers)
|
||||||
|
for addr, fld, count in queryReturn:
|
||||||
|
try:
|
||||||
|
broadcastsUnread[addr][fld] = count
|
||||||
|
except KeyError:
|
||||||
|
broadcastsUnread[addr] = {fld: count}
|
||||||
|
|
||||||
for treeWidget in widgets:
|
for treeWidget in widgets:
|
||||||
root = treeWidget.invisibleRootItem()
|
root = treeWidget.invisibleRootItem()
|
||||||
|
@ -1020,6 +1029,8 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
folderName = folderItem.folderName
|
folderName = folderItem.folderName
|
||||||
if folderName == "new":
|
if folderName == "new":
|
||||||
folderName = "inbox"
|
folderName = "inbox"
|
||||||
|
if folder and folderName != folder:
|
||||||
|
continue
|
||||||
if addressItem.type == AccountMixin.ALL:
|
if addressItem.type == AccountMixin.ALL:
|
||||||
newCount = totalUnread.get(folderName, 0)
|
newCount = totalUnread.get(folderName, 0)
|
||||||
else:
|
else:
|
||||||
|
@ -1783,19 +1794,26 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
else:
|
else:
|
||||||
sent.item(i, 3).setText(textToDisplay)
|
sent.item(i, 3).setText(textToDisplay)
|
||||||
|
|
||||||
def removeInboxRowByMsgid(self, msgid): # msgid and inventoryHash are the same thing
|
def removeInboxRowByMsgid(self, msgid):
|
||||||
for inbox in ([
|
# msgid and inventoryHash are the same thing
|
||||||
|
for inbox in (
|
||||||
self.ui.tableWidgetInbox,
|
self.ui.tableWidgetInbox,
|
||||||
self.ui.tableWidgetInboxSubscriptions,
|
self.ui.tableWidgetInboxSubscriptions,
|
||||||
self.ui.tableWidgetInboxChans]):
|
self.ui.tableWidgetInboxChans
|
||||||
|
):
|
||||||
for i in range(inbox.rowCount()):
|
for i in range(inbox.rowCount()):
|
||||||
if msgid == str(inbox.item(i, 3).data(QtCore.Qt.UserRole).toPyObject()):
|
if msgid == \
|
||||||
self.updateStatusBar(
|
inbox.item(i, 3).data(QtCore.Qt.UserRole).toPyObject():
|
||||||
_translate("MainWindow", "Message trashed"))
|
|
||||||
treeWidget = self.widgetConvert(inbox)
|
|
||||||
self.propagateUnreadCount(inbox.item(i, 1 if inbox.item(i, 1).type == AccountMixin.SUBSCRIPTION else 0).data(QtCore.Qt.UserRole), self.getCurrentFolder(treeWidget), treeWidget, 0)
|
|
||||||
inbox.removeRow(i)
|
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
self.updateStatusBar(_translate("MainWindow", "Message trashed"))
|
||||||
|
treeWidget = self.widgetConvert(inbox)
|
||||||
|
self.propagateUnreadCount(
|
||||||
|
# wrong assumption about current folder here:
|
||||||
|
self.getCurrentFolder(treeWidget), treeWidget
|
||||||
|
)
|
||||||
|
inbox.removeRow(i)
|
||||||
|
|
||||||
def newVersionAvailable(self, version):
|
def newVersionAvailable(self, version):
|
||||||
self.notifiedNewVersion = ".".join(str(n) for n in version)
|
self.notifiedNewVersion = ".".join(str(n) for n in version)
|
||||||
|
@ -2293,7 +2311,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
acct.parseMessage(toAddress, fromAddress, subject, "")
|
acct.parseMessage(toAddress, fromAddress, subject, "")
|
||||||
else:
|
else:
|
||||||
acct = ret
|
acct = ret
|
||||||
self.propagateUnreadCount(acct.address)
|
self.propagateUnreadCount(widget=treeWidget if ret else None)
|
||||||
if BMConfigParser().getboolean(
|
if BMConfigParser().getboolean(
|
||||||
'bitmessagesettings', 'showtraynotifications'):
|
'bitmessagesettings', 'showtraynotifications'):
|
||||||
self.notifierShow(
|
self.notifierShow(
|
||||||
|
@ -2676,7 +2694,6 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
), QtGui.QMessageBox.Yes | QtGui.QMessageBox.No
|
), QtGui.QMessageBox.Yes | QtGui.QMessageBox.No
|
||||||
) != QtGui.QMessageBox.Yes:
|
) != QtGui.QMessageBox.Yes:
|
||||||
return
|
return
|
||||||
# addressAtCurrentRow = self.getCurrentAccount()
|
|
||||||
tableWidget = self.getCurrentMessagelist()
|
tableWidget = self.getCurrentMessagelist()
|
||||||
|
|
||||||
idCount = tableWidget.rowCount()
|
idCount = tableWidget.rowCount()
|
||||||
|
@ -2702,7 +2719,6 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
|
|
||||||
if markread > 0:
|
if markread > 0:
|
||||||
self.propagateUnreadCount()
|
self.propagateUnreadCount()
|
||||||
# addressAtCurrentRow, self.getCurrentFolder(), None, 0)
|
|
||||||
|
|
||||||
def click_NewAddressDialog(self):
|
def click_NewAddressDialog(self):
|
||||||
dialogs.NewAddressDialog(self)
|
dialogs.NewAddressDialog(self)
|
||||||
|
@ -2987,15 +3003,13 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
)
|
)
|
||||||
|
|
||||||
self.propagateUnreadCount()
|
self.propagateUnreadCount()
|
||||||
# if rowcount == 1:
|
# tableWidget.selectRow(currentRow + 1)
|
||||||
# # performance optimisation
|
# This doesn't de-select the last message if you try to mark it
|
||||||
# self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget.item(currentRow, 1).type == AccountMixin.SUBSCRIPTION else 0).data(QtCore.Qt.UserRole), self.getCurrentFolder())
|
# unread, but that doesn't interfere. Might not be necessary.
|
||||||
# else:
|
# We could also select upwards, but then our problem would be
|
||||||
# self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget.item(currentRow, 1).type == AccountMixin.SUBSCRIPTION else 0).data(QtCore.Qt.UserRole), self.getCurrentFolder(), self.getCurrentTreeWidget(), 0)
|
# with the topmost message.
|
||||||
# tableWidget.selectRow(currentRow + 1)
|
# tableWidget.clearSelection() manages to mark the message
|
||||||
# This doesn't de-select the last message if you try to mark it unread, but that doesn't interfere. Might not be necessary.
|
# as read again.
|
||||||
# We could also select upwards, but then our problem would be with the topmost message.
|
|
||||||
# tableWidget.clearSelection() manages to mark the message as read again.
|
|
||||||
|
|
||||||
# Format predefined text on message reply.
|
# Format predefined text on message reply.
|
||||||
def quoted_text(self, message):
|
def quoted_text(self, message):
|
||||||
|
@ -3241,17 +3255,14 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
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)
|
||||||
if folder == "trash" or shifted:
|
sqlExecuteChunked(
|
||||||
sqlExecuteChunked('''DELETE FROM inbox WHERE msgid IN ({0})''',
|
"DELETE FROM inbox" if folder == "trash" or shifted else
|
||||||
idCount, *inventoryHashesToTrash)
|
"UPDATE inbox SET folder='trash'"
|
||||||
else:
|
" WHERE msgid IN ({0})", idCount, *inventoryHashesToTrash)
|
||||||
sqlExecuteChunked('''UPDATE inbox SET folder='trash' WHERE msgid IN ({0})''',
|
|
||||||
idCount, *inventoryHashesToTrash)
|
|
||||||
tableWidget.selectRow(0 if currentRow == 0 else currentRow - 1)
|
tableWidget.selectRow(0 if currentRow == 0 else currentRow - 1)
|
||||||
tableWidget.setUpdatesEnabled(True)
|
tableWidget.setUpdatesEnabled(True)
|
||||||
self.propagateUnreadCount(self.getCurrentAccount, folder)
|
self.propagateUnreadCount(folder)
|
||||||
self.updateStatusBar(_translate(
|
self.updateStatusBar(_translate("MainWindow", "Moved items to trash."))
|
||||||
"MainWindow", "Moved items to trash."))
|
|
||||||
|
|
||||||
def on_action_TrashUndelete(self):
|
def on_action_TrashUndelete(self):
|
||||||
tableWidget = self.getCurrentMessagelist()
|
tableWidget = self.getCurrentMessagelist()
|
||||||
|
@ -3271,16 +3282,13 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
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)
|
||||||
if currentRow == 0:
|
tableWidget.selectRow(0 if currentRow == 0 else currentRow - 1)
|
||||||
tableWidget.selectRow(currentRow)
|
|
||||||
else:
|
|
||||||
tableWidget.selectRow(currentRow - 1)
|
|
||||||
idCount = len(inventoryHashesToTrash)
|
idCount = len(inventoryHashesToTrash)
|
||||||
sqlExecuteChunked('''UPDATE inbox SET folder='inbox' WHERE msgid IN({0})''',
|
sqlExecuteChunked('''UPDATE inbox SET folder='inbox' WHERE msgid IN({0})''',
|
||||||
idCount, *inventoryHashesToTrash)
|
idCount, *inventoryHashesToTrash)
|
||||||
tableWidget.selectRow(0 if currentRow == 0 else currentRow - 1)
|
tableWidget.selectRow(0 if currentRow == 0 else currentRow - 1)
|
||||||
tableWidget.setUpdatesEnabled(True)
|
tableWidget.setUpdatesEnabled(True)
|
||||||
self.propagateUnreadCount(self.getCurrentAccount)
|
self.propagateUnreadCount()
|
||||||
self.updateStatusBar(_translate("MainWindow", "Undeleted item."))
|
self.updateStatusBar(_translate("MainWindow", "Undeleted item."))
|
||||||
|
|
||||||
def on_action_InboxSaveMessageAs(self):
|
def on_action_InboxSaveMessageAs(self):
|
||||||
|
@ -3317,8 +3325,6 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
|
|
||||||
# Send item on the Sent tab to trash
|
# Send item on the Sent tab to trash
|
||||||
def on_action_SentTrash(self):
|
def on_action_SentTrash(self):
|
||||||
currentRow = 0
|
|
||||||
unread = False
|
|
||||||
tableWidget = self.getCurrentMessagelist()
|
tableWidget = self.getCurrentMessagelist()
|
||||||
if not tableWidget:
|
if not tableWidget:
|
||||||
return
|
return
|
||||||
|
@ -3328,12 +3334,11 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
currentRow = tableWidget.selectedIndexes()[0].row()
|
currentRow = tableWidget.selectedIndexes()[0].row()
|
||||||
ackdataToTrash = str(tableWidget.item(
|
ackdataToTrash = str(tableWidget.item(
|
||||||
currentRow, 3).data(QtCore.Qt.UserRole).toPyObject())
|
currentRow, 3).data(QtCore.Qt.UserRole).toPyObject())
|
||||||
if folder == "trash" or shifted:
|
sqlExecute(
|
||||||
sqlExecute('''DELETE FROM sent WHERE ackdata=?''', ackdataToTrash)
|
"DELETE FROM sent" if folder == "trash" or shifted else
|
||||||
else:
|
"UPDATE sent SET folder='trash'"
|
||||||
sqlExecute('''UPDATE sent SET folder='trash' WHERE ackdata=?''', ackdataToTrash)
|
" WHERE ackdata = ?", ackdataToTrash
|
||||||
if tableWidget.item(currentRow, 0).unread:
|
)
|
||||||
self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget.item(currentRow, 1).type == AccountMixin.SUBSCRIPTION else 0).data(QtCore.Qt.UserRole), folder, self.getCurrentTreeWidget(), -1)
|
|
||||||
self.getCurrentMessageTextedit().setPlainText("")
|
self.getCurrentMessageTextedit().setPlainText("")
|
||||||
tableWidget.removeRow(currentRow)
|
tableWidget.removeRow(currentRow)
|
||||||
self.updateStatusBar(_translate(
|
self.updateStatusBar(_translate(
|
||||||
|
@ -3669,30 +3674,21 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
def getCurrentAccount(self, treeWidget=None):
|
def getCurrentAccount(self, treeWidget=None):
|
||||||
currentItem = self.getCurrentItem(treeWidget)
|
currentItem = self.getCurrentItem(treeWidget)
|
||||||
if currentItem:
|
if currentItem:
|
||||||
account = currentItem.address
|
return currentItem.address
|
||||||
return account
|
|
||||||
else:
|
|
||||||
# TODO need debug msg?
|
|
||||||
return False
|
|
||||||
|
|
||||||
def getCurrentFolder(self, treeWidget=None):
|
def getCurrentFolder(self, treeWidget=None):
|
||||||
if treeWidget is None:
|
currentItem = self.getCurrentItem(treeWidget)
|
||||||
treeWidget = self.getCurrentTreeWidget()
|
try:
|
||||||
#treeWidget = self.ui.treeWidgetYourIdentities
|
return currentItem.folderName
|
||||||
if treeWidget:
|
except AttributeError:
|
||||||
currentItem = treeWidget.currentItem()
|
pass
|
||||||
if currentItem and hasattr(currentItem, 'folderName'):
|
|
||||||
return currentItem.folderName
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def setCurrentItemColor(self, color):
|
def setCurrentItemColor(self, color):
|
||||||
treeWidget = self.getCurrentTreeWidget()
|
currentItem = self.getCurrentItem()
|
||||||
if treeWidget:
|
if currentItem:
|
||||||
brush = QtGui.QBrush()
|
brush = QtGui.QBrush()
|
||||||
brush.setStyle(QtCore.Qt.NoBrush)
|
brush.setStyle(QtCore.Qt.NoBrush)
|
||||||
brush.setColor(color)
|
brush.setColor(color)
|
||||||
currentItem = treeWidget.currentItem()
|
|
||||||
currentItem.setForeground(0, brush)
|
currentItem.setForeground(0, brush)
|
||||||
|
|
||||||
def getAddressbookSelectedItems(self):
|
def getAddressbookSelectedItems(self):
|
||||||
|
@ -4059,19 +4055,19 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
messagelist.setFocus()
|
messagelist.setFocus()
|
||||||
|
|
||||||
def treeWidgetItemClicked(self):
|
def treeWidgetItemClicked(self):
|
||||||
searchLine = self.getCurrentSearchLine()
|
messagelist = self.getCurrentMessagelist()
|
||||||
searchOption = self.getCurrentSearchOption()
|
if not messagelist:
|
||||||
|
return
|
||||||
messageTextedit = self.getCurrentMessageTextedit()
|
messageTextedit = self.getCurrentMessageTextedit()
|
||||||
if messageTextedit:
|
if messageTextedit:
|
||||||
messageTextedit.setPlainText(QtCore.QString(""))
|
messageTextedit.setPlainText("")
|
||||||
messagelist = self.getCurrentMessagelist()
|
account = self.getCurrentAccount()
|
||||||
if messagelist:
|
folder = self.getCurrentFolder()
|
||||||
account = self.getCurrentAccount()
|
# refresh count indicator
|
||||||
folder = self.getCurrentFolder()
|
self.propagateUnreadCount(folder)
|
||||||
treeWidget = self.getCurrentTreeWidget()
|
self.loadMessagelist(
|
||||||
# refresh count indicator
|
messagelist, account, folder,
|
||||||
self.propagateUnreadCount(account.address if hasattr(account, 'address') else None, folder, treeWidget, 0)
|
self.getCurrentSearchOption(), self.getCurrentSearchLine())
|
||||||
self.loadMessagelist(messagelist, account, folder, searchOption, searchLine)
|
|
||||||
|
|
||||||
def treeWidgetItemChanged(self, item, column):
|
def treeWidgetItemChanged(self, item, column):
|
||||||
# only for manual edits. automatic edits (setText) are ignored
|
# only for manual edits. automatic edits (setText) are ignored
|
||||||
|
|
Loading…
Reference in New Issue
Block a user