dont freeze UI when mass-moving to trash

This commit is contained in:
themighty1 2014-12-26 13:04:40 +02:00
parent 0c0e0e527b
commit 841b4f59c7

View File

@ -2789,19 +2789,29 @@ class MyForm(QtGui.QMainWindow):
# Send item on the Inbox tab to trash # Send item on the Inbox tab to trash
def on_action_InboxTrash(self): def on_action_InboxTrash(self):
while self.ui.tableWidgetInbox.selectedIndexes() != []: inventoryHashesToTrash = []
currentRow = self.ui.tableWidgetInbox.selectedIndexes()[0].row() unsorted_ranges = self.ui.tableWidgetInbox.selectedRanges()
inventoryHashToTrash = str(self.ui.tableWidgetInbox.item( ranges = sorted(unsorted_ranges, key=lambda r: r.topRow())
currentRow, 3).data(Qt.UserRole).toPyObject()) for r in ranges:
sqlExecute('''UPDATE inbox SET folder='trash' WHERE msgid=?''', inventoryHashToTrash) for i in range(r.bottomRow()-r.topRow()+1):
self.ui.textEditInboxMessage.setText("") inventoryHashToTrash = str(self.ui.tableWidgetInbox.item(
self.ui.tableWidgetInbox.removeRow(currentRow) r.topRow()+i, 3).data(Qt.UserRole).toPyObject())
self.statusBar().showMessage(_translate( inventoryHashesToTrash.append(inventoryHashToTrash)
"MainWindow", "Moved items to trash. There is no user interface to view your trash, but it is still on disk if you are desperate to get it back.")) #sqlite requires the exact number of ?s to prevent injection
if currentRow == 0: sqlExecute('''UPDATE inbox SET folder='trash' WHERE msgid IN (%s)''' % (
self.ui.tableWidgetInbox.selectRow(currentRow) "?," * len(inventoryHashesToTrash))[:-1], *inventoryHashesToTrash)
else:
self.ui.tableWidgetInbox.selectRow(currentRow - 1) self.ui.textEditInboxMessage.setText("")
self.statusBar().showMessage(_translate(
"MainWindow", "Moved items to trash. There is no user interface to view your trash, but it is still on disk if you are desperate to get it back."))
#remove ranges from model/view going from bottom to top
for r in ranges[::-1]:
self.ui.tableWidgetInbox.model().removeRows(r.topRow(),
r.bottomRow()-r.topRow()+1)
lastRow = r.topRow()
self.ui.tableWidgetInbox.selectRow(0 if lastRow == 0 else lastRow-1)
self.changedInboxUnread()
def on_action_InboxSaveMessageAs(self): def on_action_InboxSaveMessageAs(self):
currentInboxRow = self.ui.tableWidgetInbox.currentRow() currentInboxRow = self.ui.tableWidgetInbox.currentRow()