V0.6 #852

Merged
Atheros1 merged 399 commits from v0.6 into master 2016-05-03 01:58:38 +02:00
2 changed files with 125 additions and 80 deletions
Showing only changes of commit db84d699db - Show all commits

View File

@ -59,6 +59,7 @@ import subprocess
import string
import datetime
from helper_sql import *
import helper_search
import l10n
import openclpow
import types
@ -1081,20 +1082,6 @@ class MyForm(settingsmixin.SMainWindow):
# Load Sent items from database
def loadSent(self, tableWidget, account, where="", what=""):
what = "%" + what + "%"
if where == _translate("MainWindow", "To"):
where = "toaddress"
elif where == _translate("MainWindow", "From"):
where = "fromaddress"
elif where == _translate("MainWindow", "Subject"):
where = "subject"
elif where == _translate("MainWindow", "Message"):
where = "message"
else:
where = "toaddress || fromaddress || subject || message"
tableWidget.setSortingEnabled(False)
if tableWidget == self.ui.tableWidgetInboxChans or tableWidget == self.ui.tableWidgetInboxSubscriptions:
tableWidget.setColumnHidden(0, True)
tableWidget.setColumnHidden(1, False)
@ -1103,16 +1090,11 @@ class MyForm(settingsmixin.SMainWindow):
tableWidget.setColumnHidden(0, False)
tableWidget.setColumnHidden(1, True)
xAddress = 'fromaddress'
sqlStatement = '''
SELECT toaddress, fromaddress, subject, status, ackdata, lastactiontime
FROM sent WHERE ''' + xAddress + '''=? AND folder="sent" AND %s LIKE ?
ORDER BY lastactiontime
''' % (where,)
tableWidget.setSortingEnabled(False)
tableWidget.setRowCount(0)
acct = None
queryreturn = sqlQuery(sqlStatement, account, what)
queryreturn = helper_search.search_sql(xAddress, account, "sent", where, what, False)
for row in queryreturn:
toAddress, fromAddress, subject, status, ackdata, lastactiontime = row
self.addMessageListItemSent(tableWidget, toAddress, fromAddress, subject, status, ackdata, lastactiontime)
@ -1127,52 +1109,21 @@ class MyForm(settingsmixin.SMainWindow):
self.loadSent(tableWidget, account, where, what)
return
if what != "":
what = "%" + what + "%"
if where == _translate("MainWindow", "To"):
where = "toaddress"
elif where == _translate("MainWindow", "From"):
where = "fromaddress"
elif where == _translate("MainWindow", "Subject"):
where = "subject"
elif where == _translate("MainWindow", "Message"):
where = "message"
else:
where = "toaddress || fromaddress || subject || message"
else:
what = None
if tableWidget == self.ui.tableWidgetInboxSubscriptions:
xAddress = "fromaddress"
else:
xAddress = "toaddress"
sqlStatementBase = '''SELECT folder, msgid, toaddress, fromaddress, subject, received, read
FROM inbox '''
sqlStatementParts = []
sqlArguments = []
if account is not None:
sqlStatementParts.append(xAddress + " = ? ")
sqlArguments.append(account)
if folder is not None:
sqlStatementParts.append("folder = ? ")
sqlArguments.append(folder)
if what is not None:
sqlStatementParts.append("%s LIKE ?" % (where))
sqlArguments.append(what)
if unreadOnly:
sqlStatementParts.append("read = 0")
if len(sqlStatementParts) > 0:
sqlStatementBase += "WHERE " + " AND ".join(sqlStatementParts)
queryreturn = sqlQuery(sqlStatementBase, sqlArguments)
tableWidget.setRowCount(0)
if account is not None:
tableWidget.setColumnHidden(0, True)
tableWidget.setColumnHidden(1, False)
else:
tableWidget.setColumnHidden(0, False)
tableWidget.setColumnHidden(1, False)
tableWidget.setSortingEnabled(False)
tableWidget.setRowCount(0)
queryreturn = helper_search.search_sql(xAddress, account, folder, where, what, unreadOnly)
for row in queryreturn:
msgfolder, msgid, toAddress, fromAddress, subject, received, read = row
@ -2336,7 +2287,11 @@ class MyForm(settingsmixin.SMainWindow):
def displayNewSentMessage(self, toAddress, toLabel, fromAddress, subject, message, ackdata):
acct = accountClass(fromAddress)
acct.parseMessage(toAddress, fromAddress, subject, message)
tab = -1
for sent in [self.ui.tableWidgetInbox, self.ui.tableWidgetInboxSubscriptions, self.ui.tableWidgetInboxChans]:
tab += 1
if tab == 1:
tab = 2
treeWidget = self.widgetConvert(sent)
if self.getCurrentFolder(treeWidget) != "sent":
continue
@ -2344,6 +2299,8 @@ class MyForm(settingsmixin.SMainWindow):
continue
elif treeWidget in [self.ui.treeWidgetSubscriptions, self.ui.treeWidgetChans] and self.getCurrentAccount(treeWidget) != toAddress:
continue
elif not helper_search.check_match(toAddress, fromAddress, subject, message, self.getCurrentSearchOption(tab), self.getCurrentSearchLine(tab)):
continue
self.addMessageListItemSent(sent, toAddress, fromAddress, subject, "msgqueued", ackdata, time.time())
self.getAccountTextedit(acct).setPlainText(unicode(message, 'utf-8)', 'replace'))
@ -2356,8 +2313,14 @@ class MyForm(settingsmixin.SMainWindow):
acct = accountClass(toAddress)
inbox = self.getAccountMessagelist(acct)
ret = None
tab = -1
for treeWidget in [self.ui.treeWidgetYourIdentities, self.ui.treeWidgetSubscriptions, self.ui.treeWidgetChans]:
tab += 1
if tab == 1:
tab = 2
tableWidget = self.widgetConvert(treeWidget)
if not helper_search.check_match(toAddress, fromAddress, subject, message, self.getCurrentSearchOption(tab), self.getCurrentSearchLine(tab)):
continue
if tableWidget == inbox and self.getCurrentAccount(treeWidget) == acct.address and self.getCurrentFolder(treeWidget) in ["inbox", None]:
ret = self.addMessageListItemInbox(inbox, "inbox", inventoryHash, toAddress, fromAddress, subject, time.time(), 0)
elif treeWidget == self.ui.treeWidgetYourIdentities and self.getCurrentAccount(treeWidget) is None:
@ -3518,8 +3481,9 @@ class MyForm(settingsmixin.SMainWindow):
except:
return self.ui.textEditInboxMessage
def getCurrentSearchLine(self):
currentIndex = self.ui.tabWidget.currentIndex();
def getCurrentSearchLine(self, currentIndex = None):
if currentIndex is None:
currentIndex = self.ui.tabWidget.currentIndex();
messagelistList = [
self.ui.inboxSearchLineEdit,
False,
@ -3527,12 +3491,13 @@ class MyForm(settingsmixin.SMainWindow):
self.ui.inboxSearchLineEditChans,
]
if currentIndex >= 0 and currentIndex < len(messagelistList):
return messagelistList[currentIndex]
return messagelistList[currentIndex].text().toUtf8().data()
else:
return False
return None
def getCurrentSearchOption(self):
currentIndex = self.ui.tabWidget.currentIndex();
def getCurrentSearchOption(self, currentIndex = None):
if currentIndex is None:
currentIndex = self.ui.tabWidget.currentIndex();
messagelistList = [
self.ui.inboxSearchOption,
False,
@ -3542,7 +3507,7 @@ class MyForm(settingsmixin.SMainWindow):
if currentIndex >= 0 and currentIndex < len(messagelistList):
return messagelistList[currentIndex].currentText().toUtf8().data()
else:
return False
return None
# Group of functions for the Your Identities dialog box
def getCurrentItem(self, treeWidget = None):
@ -3842,26 +3807,26 @@ class MyForm(settingsmixin.SMainWindow):
def inboxSearchLineEditPressed(self):
searchLine = self.getCurrentSearchLine()
searchOption = self.getCurrentSearchOption()
if searchLine:
searchKeyword = searchLine.text().toUtf8().data()
messageTextedit = self.getCurrentMessageTextedit()
if messageTextedit:
messageTextedit.setPlainText(QString(""))
messagelist = self.getCurrentMessagelist()
if messagelist:
account = self.getCurrentAccount()
folder = self.getCurrentFolder()
self.loadMessagelist(messagelist, account, folder, searchOption, searchKeyword)
def treeWidgetItemClicked(self):
messageTextedit = self.getCurrentMessageTextedit()
if messageTextedit:
messageTextedit.setPlainText(QString(""))
messagelist = self.getCurrentMessagelist()
if messagelist:
account = self.getCurrentAccount()
folder = self.getCurrentFolder()
if folder == "new":
self.loadMessagelist(messagelist, account, None, unreadOnly = True)
else:
self.loadMessagelist(messagelist, account, folder)
self.loadMessagelist(messagelist, account, folder, searchOption, searchLine)
def treeWidgetItemClicked(self):
searchLine = self.getCurrentSearchLine()
searchOption = self.getCurrentSearchOption()
messageTextedit = self.getCurrentMessageTextedit()
if messageTextedit:
messageTextedit.setPlainText(QString(""))
messagelist = self.getCurrentMessagelist()
if messagelist:
account = self.getCurrentAccount()
folder = self.getCurrentFolder()
self.loadMessagelist(messagelist, account, folder, searchOption, searchLine)
def treeWidgetItemChanged(self, item, column):
# only for manual edits. automatic edits (setText) are ignored

80
src/helper_search.py Normal file
View File

@ -0,0 +1,80 @@
#!/usr/bin/python2.7
from helper_sql import *
try:
from PyQt4 import QtCore, QtGui
haveQt = True
except:
haveQt = False
def search_translate (context, text):
if haveQt:
return QtGui.QApplication.translate(context, text)
else:
return text.lower()
def search_sql(xAddress = "toaddress", account = None, folder = "inbox", where = None, what = None, unreadOnly = False):
if what is not None and what != "":
what = "%" + what + "%"
if where == search_translate("MainWindow", "To"):
where = "toaddress"
elif where == search_translate("MainWindow", "From"):
where = "fromaddress"
elif where == search_translate("MainWindow", "Subject"):
where = "subject"
elif where == search_translate("MainWindow", "Message"):
where = "message"
else:
where = "toaddress || fromaddress || subject || message"
else:
what = None
if folder == "sent":
sqlStatementBase = '''
SELECT toaddress, fromaddress, subject, status, ackdata, lastactiontime
FROM sent '''
else:
sqlStatementBase = '''SELECT folder, msgid, toaddress, fromaddress, subject, received, read
FROM inbox '''
sqlStatementParts = []
sqlArguments = []
if account is not None:
sqlStatementParts.append(xAddress + " = ? ")
sqlArguments.append(account)
if folder is not None:
if folder == "new":
folder = "inbox"
unreadOnly = True
sqlStatementParts.append("folder = ? ")
sqlArguments.append(folder)
else:
sqlStatementParts.append("folder != ?")
sqlArguments.append("trash")
if what is not None:
sqlStatementParts.append("%s LIKE ?" % (where))
sqlArguments.append(what)
if unreadOnly:
sqlStatementParts.append("read = 0")
if len(sqlStatementParts) > 0:
sqlStatementBase += "WHERE " + " AND ".join(sqlStatementParts)
if folder == "sent":
sqlStatementBase += " ORDER BY lastactiontime"
return sqlQuery(sqlStatementBase, sqlArguments)
def check_match(toAddress, fromAddress, subject, message, where = None, what = None):
if what is not None and what != "":
if where in (search_translate("MainWindow", "To"), search_translate("MainWindow", "All")):
if what.lower() not in toAddress.lower():
return False
elif where in (search_translate("MainWindow", "From"), search_translate("MainWindow", "All")):
if what.lower() not in fromAddress.lower():
return False
elif where in (search_translate("MainWindow", "Subject"), search_translate("MainWindow", "All")):
if what.lower() not in subject.lower():
return False
elif where in (search_translate("MainWindow", "Message"), search_translate("MainWindow", "All")):
if what.lower() not in message.lower():
return False
return True