Add "Mark all messages unread" context menu item

- account context menu how has a "Mark all messages unread" item
- folders now have a context menu as well and it has this item too
This commit is contained in:
Peter Šurda 2016-08-20 22:38:36 +02:00
parent ca031dc421
commit 67c3d7bbca
Signed by: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87

View File

@ -260,6 +260,10 @@ class MyForm(settingsmixin.SMainWindow):
_translate( _translate(
"MainWindow", "Email gateway"), "MainWindow", "Email gateway"),
self.on_action_EmailGatewayDialog) self.on_action_EmailGatewayDialog)
self.actionMarkAllRead = self.ui.addressContextMenuToolbarYourIdentities.addAction(
_translate(
"MainWindow", "Mark all messages as read"),
self.on_action_MarkAllRead)
self.ui.treeWidgetYourIdentities.setContextMenuPolicy( self.ui.treeWidgetYourIdentities.setContextMenuPolicy(
QtCore.Qt.CustomContextMenu) QtCore.Qt.CustomContextMenu)
@ -2628,6 +2632,39 @@ class MyForm(settingsmixin.SMainWindow):
# shared.writeKeysFile() # shared.writeKeysFile()
# self.rerenderInboxToLabels() # self.rerenderInboxToLabels()
def on_action_MarkAllRead(self):
if QtGui.QMessageBox.question(self, "Marking all messages as read?", _translate("MainWindow", "Are you sure you would like to mark all messages read?"), QMessageBox.Yes|QMessageBox.No) != QMessageBox.Yes:
return
addressAtCurrentRow = self.getCurrentAccount()
tableWidget = self.getCurrentMessagelist()
if tableWidget.rowCount() == 0:
return
msgids = []
font = QFont()
font.setBold(False)
for i in range(0, tableWidget.rowCount()):
msgids.append(str(tableWidget.item(
i, 3).data(Qt.UserRole).toPyObject()))
tableWidget.item(i, 0).setUnread(False)
tableWidget.item(i, 1).setUnread(False)
tableWidget.item(i, 2).setUnread(False)
tableWidget.item(i, 3).setFont(font)
markread = 0
if self.getCurrentFolder() == 'sent':
markread = sqlExecute(
"UPDATE sent SET read = 1 WHERE ackdata IN(%s) AND read=0" %(",".join("?"*len(msgids))), *msgids)
else:
markread = sqlExecute(
"UPDATE inbox SET read = 1 WHERE msgid IN(%s) AND read=0" %(",".join("?"*len(msgids))), *msgids)
if markread > 0:
self.propagateUnreadCount(addressAtCurrentRow, self.getCurrentFolder(), None, 0)
def click_NewAddressDialog(self): def click_NewAddressDialog(self):
addresses = [] addresses = []
for addressInKeysFile in getSortedAccounts(): for addressInKeysFile in getSortedAccounts():
@ -3282,9 +3319,8 @@ class MyForm(settingsmixin.SMainWindow):
def on_context_menuSubscriptions(self, point): def on_context_menuSubscriptions(self, point):
currentItem = self.getCurrentItem() currentItem = self.getCurrentItem()
if not isinstance(currentItem, Ui_AddressWidget):
return
self.popMenuSubscriptions = QtGui.QMenu(self) self.popMenuSubscriptions = QtGui.QMenu(self)
if isinstance(currentItem, Ui_AddressWidget):
self.popMenuSubscriptions.addAction(self.actionsubscriptionsNew) self.popMenuSubscriptions.addAction(self.actionsubscriptionsNew)
self.popMenuSubscriptions.addAction(self.actionsubscriptionsDelete) self.popMenuSubscriptions.addAction(self.actionsubscriptionsDelete)
self.popMenuSubscriptions.addSeparator() self.popMenuSubscriptions.addSeparator()
@ -3295,6 +3331,8 @@ class MyForm(settingsmixin.SMainWindow):
self.popMenuSubscriptions.addAction(self.actionsubscriptionsSetAvatar) self.popMenuSubscriptions.addAction(self.actionsubscriptionsSetAvatar)
self.popMenuSubscriptions.addSeparator() self.popMenuSubscriptions.addSeparator()
self.popMenuSubscriptions.addAction(self.actionsubscriptionsClipboard) self.popMenuSubscriptions.addAction(self.actionsubscriptionsClipboard)
self.popMenuSubscriptions.addSeparator()
self.popMenuSubscriptions.addAction(self.actionMarkAllRead)
self.popMenuSubscriptions.exec_( self.popMenuSubscriptions.exec_(
self.ui.treeWidgetSubscriptions.mapToGlobal(point)) self.ui.treeWidgetSubscriptions.mapToGlobal(point))
@ -3629,9 +3667,8 @@ class MyForm(settingsmixin.SMainWindow):
def on_context_menuYourIdentities(self, point): def on_context_menuYourIdentities(self, point):
currentItem = self.getCurrentItem() currentItem = self.getCurrentItem()
if not isinstance(currentItem, Ui_AddressWidget):
return
self.popMenuYourIdentities = QtGui.QMenu(self) self.popMenuYourIdentities = QtGui.QMenu(self)
if isinstance(currentItem, Ui_AddressWidget):
self.popMenuYourIdentities.addAction(self.actionNewYourIdentities) self.popMenuYourIdentities.addAction(self.actionNewYourIdentities)
self.popMenuYourIdentities.addSeparator() self.popMenuYourIdentities.addSeparator()
self.popMenuYourIdentities.addAction(self.actionClipboardYourIdentities) self.popMenuYourIdentities.addAction(self.actionClipboardYourIdentities)
@ -3643,15 +3680,16 @@ class MyForm(settingsmixin.SMainWindow):
self.popMenuYourIdentities.addAction(self.actionSetAvatarYourIdentities) self.popMenuYourIdentities.addAction(self.actionSetAvatarYourIdentities)
self.popMenuYourIdentities.addAction(self.actionSpecialAddressBehaviorYourIdentities) self.popMenuYourIdentities.addAction(self.actionSpecialAddressBehaviorYourIdentities)
self.popMenuYourIdentities.addAction(self.actionEmailGateway) self.popMenuYourIdentities.addAction(self.actionEmailGateway)
self.popMenuYourIdentities.addSeparator()
self.popMenuYourIdentities.addAction(self.actionMarkAllRead)
self.popMenuYourIdentities.exec_( self.popMenuYourIdentities.exec_(
self.ui.treeWidgetYourIdentities.mapToGlobal(point)) self.ui.treeWidgetYourIdentities.mapToGlobal(point))
# TODO make one popMenu # TODO make one popMenu
def on_context_menuChan(self, point): def on_context_menuChan(self, point):
currentItem = self.getCurrentItem() currentItem = self.getCurrentItem()
if not isinstance(currentItem, Ui_AddressWidget):
return
self.popMenu = QtGui.QMenu(self) self.popMenu = QtGui.QMenu(self)
if isinstance(currentItem, Ui_AddressWidget):
self.popMenu.addAction(self.actionNew) self.popMenu.addAction(self.actionNew)
self.popMenu.addAction(self.actionDelete) self.popMenu.addAction(self.actionDelete)
self.popMenu.addSeparator() self.popMenu.addSeparator()
@ -3662,6 +3700,8 @@ class MyForm(settingsmixin.SMainWindow):
else: else:
self.popMenu.addAction(self.actionEnable) self.popMenu.addAction(self.actionEnable)
self.popMenu.addAction(self.actionSetAvatar) self.popMenu.addAction(self.actionSetAvatar)
self.popMenu.addSeparator()
self.popMenu.addAction(self.actionMarkAllRead)
self.popMenu.exec_( self.popMenu.exec_(
self.ui.treeWidgetChans.mapToGlobal(point)) self.ui.treeWidgetChans.mapToGlobal(point))