Optimise UI deleting and undeleting multiple messages
- use sqlExecuteChunked and disable UI updates while removing entries
This commit is contained in:
parent
bc7227f513
commit
0f61ed9f19
|
@ -2985,54 +2985,61 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
tableWidget = self.getCurrentMessagelist()
|
tableWidget = self.getCurrentMessagelist()
|
||||||
if not tableWidget:
|
if not tableWidget:
|
||||||
return
|
return
|
||||||
unread = False
|
|
||||||
currentRow = 0
|
currentRow = 0
|
||||||
folder = self.getCurrentFolder()
|
folder = self.getCurrentFolder()
|
||||||
shifted = QtGui.QApplication.queryKeyboardModifiers() & QtCore.Qt.ShiftModifier
|
shifted = QtGui.QApplication.queryKeyboardModifiers() & QtCore.Qt.ShiftModifier
|
||||||
while tableWidget.selectedIndexes():
|
tableWidget.setUpdatesEnabled(False);
|
||||||
currentRow = tableWidget.selectedIndexes()[0].row()
|
inventoryHashesToTrash = []
|
||||||
|
for row in tableWidget.selectedIndexes():
|
||||||
|
currentRow = row.row()
|
||||||
inventoryHashToTrash = str(tableWidget.item(
|
inventoryHashToTrash = str(tableWidget.item(
|
||||||
currentRow, 3).data(Qt.UserRole).toPyObject())
|
currentRow, 3).data(QtCore.Qt.UserRole).toPyObject())
|
||||||
if folder == "trash" or shifted:
|
if inventoryHashToTrash in inventoryHashesToTrash:
|
||||||
sqlExecute('''DELETE FROM inbox WHERE msgid=?''', inventoryHashToTrash)
|
continue
|
||||||
else:
|
inventoryHashesToTrash.append(inventoryHashToTrash)
|
||||||
sqlExecute('''UPDATE inbox SET folder='trash' WHERE msgid=?''', inventoryHashToTrash)
|
|
||||||
if tableWidget.item(currentRow, 0).unread:
|
|
||||||
self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget.item(currentRow, 1).type == AccountMixin.SUBSCRIPTION else 0).data(Qt.UserRole), folder, self.getCurrentTreeWidget(), -1)
|
|
||||||
if folder != "trash" and not shifted:
|
|
||||||
self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget.item(currentRow, 1).type == AccountMixin.SUBSCRIPTION else 0).data(Qt.UserRole), "trash", self.getCurrentTreeWidget(), 1)
|
|
||||||
|
|
||||||
self.getCurrentMessageTextedit().setText("")
|
|
||||||
tableWidget.removeRow(currentRow)
|
tableWidget.removeRow(currentRow)
|
||||||
|
idCount = len(inventoryHashesToTrash)
|
||||||
|
if folder == "trash" or shifted:
|
||||||
|
sqlExecuteChunked('''DELETE FROM inbox WHERE msgid IN ({0})''',
|
||||||
|
idCount, *inventoryHashesToTrash)
|
||||||
|
else:
|
||||||
|
sqlExecuteChunked('''UPDATE inbox SET folder='trash' WHERE msgid IN ({0})''',
|
||||||
|
idCount, *inventoryHashesToTrash)
|
||||||
|
tableWidget.selectRow(0 if currentRow == 0 else currentRow - 1)
|
||||||
|
self.getCurrentMessageTextedit().setText("")
|
||||||
|
tableWidget.setUpdatesEnabled(True)
|
||||||
|
self.propagateUnreadCount(self.getCurrentAccount, folder)
|
||||||
self.statusBar().showMessage(_translate(
|
self.statusBar().showMessage(_translate(
|
||||||
"MainWindow", "Moved items to trash."), 10000)
|
"MainWindow", "Moved items to trash."), 10000)
|
||||||
if currentRow == 0:
|
|
||||||
tableWidget.selectRow(currentRow)
|
|
||||||
else:
|
|
||||||
tableWidget.selectRow(currentRow - 1)
|
|
||||||
|
|
||||||
def on_action_TrashUndelete(self):
|
def on_action_TrashUndelete(self):
|
||||||
tableWidget = self.getCurrentMessagelist()
|
tableWidget = self.getCurrentMessagelist()
|
||||||
if not tableWidget:
|
if not tableWidget:
|
||||||
return
|
return
|
||||||
unread = False
|
|
||||||
currentRow = 0
|
currentRow = 0
|
||||||
while tableWidget.selectedIndexes():
|
tableWidget.setUpdatesEnabled(False)
|
||||||
currentRow = tableWidget.selectedIndexes()[0].row()
|
inventoryHashesToTrash = []
|
||||||
|
for row in tableWidget.selectedIndexes():
|
||||||
|
currentRow = row.row()
|
||||||
inventoryHashToTrash = str(tableWidget.item(
|
inventoryHashToTrash = str(tableWidget.item(
|
||||||
currentRow, 3).data(Qt.UserRole).toPyObject())
|
currentRow, 3).data(QtCore.Qt.UserRole).toPyObject())
|
||||||
sqlExecute('''UPDATE inbox SET folder='inbox' WHERE msgid=?''', inventoryHashToTrash)
|
if inventoryHashToTrash in inventoryHashesToTrash:
|
||||||
if tableWidget.item(currentRow, 0).unread:
|
continue
|
||||||
self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget.item(currentRow, 1).type == AccountMixin.SUBSCRIPTION else 0).data(Qt.UserRole), "inbox", self.getCurrentTreeWidget(), 1)
|
inventoryHashesToTrash.append(inventoryHashToTrash)
|
||||||
self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget.item(currentRow, 1).type == AccountMixin.SUBSCRIPTION else 0).data(Qt.UserRole), "trash", self.getCurrentTreeWidget(), -1)
|
|
||||||
self.getCurrentMessageTextedit().setText("")
|
|
||||||
tableWidget.removeRow(currentRow)
|
tableWidget.removeRow(currentRow)
|
||||||
self.statusBar().showMessage(_translate(
|
|
||||||
"MainWindow", "Undeleted item."), 10000)
|
|
||||||
if currentRow == 0:
|
if currentRow == 0:
|
||||||
tableWidget.selectRow(currentRow)
|
tableWidget.selectRow(currentRow)
|
||||||
else:
|
else:
|
||||||
tableWidget.selectRow(currentRow - 1)
|
tableWidget.selectRow(currentRow - 1)
|
||||||
|
idCount = len(inventoryHashesToTrash)
|
||||||
|
sqlExecuteChunked('''UPDATE inbox SET folder='inbox' WHERE msgid IN({0})''',
|
||||||
|
idCount, *inventoryHashesToTrash)
|
||||||
|
tableWidget.selectRow(0 if currentRow == 0 else currentRow - 1)
|
||||||
|
self.getCurrentMessageTextedit().setText("")
|
||||||
|
tableWidget.setUpdatesEnabled(True)
|
||||||
|
self.propagateUnreadCount(self.getCurrentAccount)
|
||||||
|
self.statusBar().showMessage(_translate(
|
||||||
|
"MainWindow", "Undeleted items."), 10000)
|
||||||
|
|
||||||
def on_action_InboxSaveMessageAs(self):
|
def on_action_InboxSaveMessageAs(self):
|
||||||
tableWidget = self.getCurrentMessagelist()
|
tableWidget = self.getCurrentMessagelist()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user