Quick fix for #1081 #1096

Merged
g1itch merged 3 commits from ui-fixes into v0.6 2018-01-27 07:46:15 +01:00
2 changed files with 35 additions and 28 deletions
Showing only changes of commit 80fdb08f03 - Show all commits

View File

@ -2509,48 +2509,42 @@ class MyForm(settingsmixin.SMainWindow):
# self.rerenderInboxToLabels() # self.rerenderInboxToLabels()
def on_action_MarkAllRead(self): def on_action_MarkAllRead(self):
def partialUpdate(folder, msgids): if QtGui.QMessageBox.question(
if len(msgids) == 0: self, "Marking all messages as read?",
return 0 _translate(
if folder == 'sent': "MainWindow",
return sqlExecute( "Are you sure you would like to mark all messages read?"
"UPDATE sent SET read = 1 WHERE ackdata IN(%s) AND read=0" %(",".join("?"*len(msgids))), *msgids) ), QMessageBox.Yes | QMessageBox.No) != QMessageBox.Yes:
else:
return sqlExecute(
"UPDATE inbox SET read = 1 WHERE msgid IN(%s) AND read=0" %(",".join("?"*len(msgids))), *msgids)
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 return
addressAtCurrentRow = self.getCurrentAccount() addressAtCurrentRow = self.getCurrentAccount()
tableWidget = self.getCurrentMessagelist() tableWidget = self.getCurrentMessagelist()
if tableWidget.rowCount() == 0: idCount = tableWidget.rowCount()
if idCount == 0:
return return
msgids = []
font = QFont() font = QFont()
font.setBold(False) font.setBold(False)
markread = 0 msgids = []
for i in range(0, idCount):
for i in range(0, tableWidget.rowCount()):
msgids.append(str(tableWidget.item( msgids.append(str(tableWidget.item(
i, 3).data(Qt.UserRole).toPyObject())) i, 3).data(Qt.UserRole).toPyObject()))
tableWidget.item(i, 0).setUnread(False) tableWidget.item(i, 0).setUnread(False)
tableWidget.item(i, 1).setUnread(False) tableWidget.item(i, 1).setUnread(False)
tableWidget.item(i, 2).setUnread(False) tableWidget.item(i, 2).setUnread(False)
tableWidget.item(i, 3).setFont(font) tableWidget.item(i, 3).setFont(font)
# sqlite default limit, unfortunately getting/setting isn't exposed to python
if i % 999 == 0:
markread += partialUpdate(self.getCurrentFolder(), msgids)
msgids = []
if len(msgids) > 0: markread = sqlExecuteChunked(
markread += partialUpdate(self.getCurrentFolder(), msgids) "UPDATE %s SET read = 1 WHERE %s IN({0}) AND read=0" % (
('sent', 'ackdata') if self.getCurrentFolder() == 'sent'
else ('inbox', 'msgid')
), idCount, *msgids
)
if markread > 0: if markread > 0:
self.propagateUnreadCount(addressAtCurrentRow, self.getCurrentFolder(), None, 0) self.propagateUnreadCount(
addressAtCurrentRow, self.getCurrentFolder(), None, 0)
def click_NewAddressDialog(self): def click_NewAddressDialog(self):
addresses = [] addresses = []

View File

@ -21,8 +21,10 @@ def sqlQuery(sqlStatement, *args):
return queryreturn return queryreturn
def sqlExecuteChunked(sqlStatement, idCount, *args): def sqlExecuteChunked(sqlStatement, idCount, *args):
#SQLITE_MAX_VARIABLE_NUMBER, unfortunately getting/setting isn't exposed to python # SQLITE_MAX_VARIABLE_NUMBER,
# unfortunately getting/setting isn't exposed to python
sqlExecuteChunked.chunkSize = 999 sqlExecuteChunked.chunkSize = 999
if idCount == 0 or idCount > len(args): if idCount == 0 or idCount > len(args):
@ -30,15 +32,26 @@ def sqlExecuteChunked(sqlStatement, idCount, *args):
totalRowCount = 0 totalRowCount = 0
with sqlLock: with sqlLock:
for i in range(len(args)-idCount, len(args), sqlExecuteChunked.chunkSize - (len(args)-idCount)): for i in range(
sqlSubmitQueue.put(sqlStatement) len(args) - idCount, len(args),
sqlExecuteChunked.chunkSize - (len(args) - idCount)
):
chunk_slice = args[
i:i+sqlExecuteChunked.chunkSize - (len(args) - idCount)
]
sqlSubmitQueue.put(
sqlStatement.format(','.join('?' * len(chunk_slice)))
)
# first static args, and then iterative chunk # first static args, and then iterative chunk
sqlSubmitQueue.put(args[0:len(args)-idCount] + args[i:i+sqlExecuteChunked.chunkSize - (len(args)-idCount)]) sqlSubmitQueue.put(
args[0:len(args)-idCount] + chunk_slice
)
retVal = sqlReturnQueue.get() retVal = sqlReturnQueue.get()
totalRowCount += retVal[1] totalRowCount += retVal[1]
sqlSubmitQueue.put('commit') sqlSubmitQueue.put('commit')
return totalRowCount return totalRowCount
def sqlExecute(sqlStatement, *args): def sqlExecute(sqlStatement, *args):
sqlLock.acquire() sqlLock.acquire()
sqlSubmitQueue.put(sqlStatement) sqlSubmitQueue.put(sqlStatement)