Some UI code refactoring #553

Merged
Atheros1 merged 2 commits from master into master 2013-11-08 00:27:55 +01:00
Showing only changes of commit 90fd189fa8 - Show all commits

View File

@ -54,20 +54,6 @@ try:
except AttributeError: except AttributeError:
print 'QtGui.QApplication.UnicodeUTF8 error:', err print 'QtGui.QApplication.UnicodeUTF8 error:', err
FIELD_COLUMNS = {
'To': 'toaddress',
'From': 'fromaddress',
'Subject': 'subject',
'Message': 'message,'
}
SELECT_INBOX_QUERY = '''
SELECT msgid, toaddress, fromaddress, subject, received, read
FROM inbox WHERE folder="inbox" AND %s LIKE ?
ORDER BY received
'''
def _translate(context, text): def _translate(context, text):
return QtGui.QApplication.translate(context, text) return QtGui.QApplication.translate(context, text)
@ -884,12 +870,22 @@ class MyForm(QtGui.QMainWindow):
# Load inbox from messages database file # Load inbox from messages database file
def loadInbox(self, where="", what=""): def loadInbox(self, where="", what=""):
what = "%" + what + "%" what = "%" + what + "%"
if where in FIELD_COLUMNS: if where == "To":
where = FIELD_COLUMNS[where] where = "toaddress"
elif where == "From":
where = "fromaddress"
elif where == "Subject":
where = "subject"
elif where == "Message":
where = "message"
else: else:
where = "toaddress || fromaddress || subject || message" where = "toaddress || fromaddress || subject || message"
sqlStatement = SELECT_INBOX_QUERY % (where,) sqlStatement = '''
SELECT msgid, toaddress, fromaddress, subject, received, read
FROM inbox WHERE folder="inbox" AND %s LIKE ?
ORDER BY received
''' % (where,)
while self.ui.tableWidgetInbox.rowCount() > 0: while self.ui.tableWidgetInbox.rowCount() > 0:
self.ui.tableWidgetInbox.removeRow(0) self.ui.tableWidgetInbox.removeRow(0)