V0.6 #852

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

View File

@ -447,7 +447,9 @@ class MyForm(QtGui.QMainWindow):
elif tab == 'chan':
treeWidget = self.ui.treeWidgetChans
#treeWidget.clear()
# sort ascending when creating
if treeWidget.topLevelItemCount() == 0:
treeWidget.header().setSortIndicator(0, Qt.AscendingOrder)
# init dictionary
db = {}
@ -860,6 +862,10 @@ class MyForm(QtGui.QMainWindow):
else:
where = "toaddress || fromaddress || subject || message"
tableWidget.setColumnHidden(0, False)
tableWidget.setColumnHidden(1, True)
tableWidget.setSortingEnabled(False)
sqlStatement = '''
SELECT toaddress, fromaddress, subject, status, ackdata, lastactiontime
FROM sent WHERE fromaddress=? AND folder="sent" AND %s LIKE ?
@ -868,60 +874,34 @@ class MyForm(QtGui.QMainWindow):
while tableWidget.rowCount() > 0:
tableWidget.removeRow(0)
acct = None
queryreturn = sqlQuery(sqlStatement, account, what)
for row in queryreturn:
toAddress, fromAddress, subject, status, ackdata, lastactiontime = row
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
if shared.config.has_section(fromAddress):
fromLabel = shared.config.get(fromAddress, 'label')
else:
fromLabel = fromAddress
toLabel = ''
queryreturn = sqlQuery(
'''select label from addressbook where address=?''', toAddress)
if queryreturn != []:
for row in queryreturn:
toLabel, = row
if toLabel == '':
# It might be a broadcast message. We should check for that
# label.
queryreturn = sqlQuery(
'''select label from subscriptions where address=?''', toAddress)
if queryreturn != []:
for row in queryreturn:
toLabel, = row
if toLabel == '':
if shared.config.has_section(toAddress):
toLabel = shared.config.get(toAddress, 'label')
if toLabel == '':
toLabel = toAddress
if acct is None:
acct = accountClass(fromAddress)
acct.parseMessage(toAddress, fromAddress, subject, "")
tableWidget.insertRow(0)
toAddressItem = QtGui.QTableWidgetItem(unicode(toLabel, 'utf-8'))
toAddressItem.setToolTip(unicode(toLabel, 'utf-8'))
toAddressItem = QtGui.QTableWidgetItem(unicode(acct.toLabel, 'utf-8'))
toAddressItem.setToolTip(unicode(acct.toLabel, 'utf-8'))
toAddressItem.setIcon(avatarize(toAddress))
toAddressItem.setData(Qt.UserRole, str(toAddress))
toAddressItem.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
tableWidget.setItem(0, 0, toAddressItem)
if fromLabel == '':
fromLabel = fromAddress
fromAddressItem = QtGui.QTableWidgetItem(unicode(fromLabel, 'utf-8'))
fromAddressItem.setToolTip(unicode(fromLabel, 'utf-8'))
fromAddressItem = QtGui.QTableWidgetItem(unicode(acct.fromLabel, 'utf-8'))
fromAddressItem.setToolTip(unicode(acct.fromLabel, 'utf-8'))
fromAddressItem.setIcon(avatarize(fromAddress))
fromAddressItem.setData(Qt.UserRole, str(fromAddress))
fromAddressItem.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
tableWidget.setItem(0, 1, fromAddressItem)
subjectItem = QtGui.QTableWidgetItem(unicode(subject, 'utf-8'))
subjectItem.setToolTip(unicode(subject, 'utf-8'))
subjectItem = QtGui.QTableWidgetItem(unicode(acct.subject, 'utf-8'))
subjectItem.setToolTip(unicode(acct.subject, 'utf-8'))
subjectItem.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
tableWidget.setItem(0, 2, subjectItem)
@ -972,7 +952,9 @@ class MyForm(QtGui.QMainWindow):
newItem.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
tableWidget.setItem(0, 3, newItem)
tableWidget.sortItems(3, Qt.DescendingOrder)
tableWidget.setSortingEnabled(False)
tableWidget.horizontalHeader().setSortIndicator(3, Qt.DescendingOrder)
tableWidget.keyPressEvent = self.tableWidgetInboxKeyPressEvent
# Load messages from database file
@ -993,62 +975,43 @@ class MyForm(QtGui.QMainWindow):
else:
where = "toaddress || fromaddress || subject || message"
if folder != False:
sqlStatement = '''
SELECT msgid, toaddress, fromaddress, subject, received, read
SELECT folder, msgid, toaddress, fromaddress, subject, received, read
FROM inbox WHERE toaddress=? AND folder=? AND %s LIKE ?
ORDER BY received
''' % (where)
queryreturn = sqlQuery(sqlStatement, account, folder, what)
else:
sqlStatement = '''
SELECT folder, msgid, toaddress, fromaddress, subject, received, read
FROM inbox WHERE toaddress=? AND folder != "trash" AND %s LIKE ?
ORDER BY received
''' % (where)
queryreturn = sqlQuery(sqlStatement, account, what)
while tableWidget.rowCount() > 0:
tableWidget.removeRow(0)
tableWidget.setColumnHidden(0, True)
tableWidget.setColumnHidden(1, False)
tableWidget.setSortingEnabled(False)
font = QFont()
font.setBold(True)
queryreturn = sqlQuery(sqlStatement, account, folder, what)
acct = None
for row in queryreturn:
msgid, toAddress, fromAddress, subject, received, read = row
msgfolder, msgid, toAddress, fromAddress, subject, received, read = row
if acct is None:
acct = accountClass(toAddress)
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
acct.parseMessage(toAddress, fromAddress, subject, "")
try:
if toAddress == self.str_broadcast_subscribers:
toLabel = self.str_broadcast_subscribers
else:
toLabel = shared.config.get(toAddress, 'label')
except:
toLabel = ''
if toLabel == '':
toLabel = toAddress
fromLabel = ''
if type(acct) == MailchuckAccount:
fromLabel = acct.fromAddress
if shared.config.has_section(fromAddress):
fromLabel = shared.config.get(fromAddress, 'label')
if fromLabel == '': # If the fromAddress isn't one of our addresses and isn't a chan
queryreturn = sqlQuery(
'''select label from addressbook where address=?''', fromAddress)
if queryreturn != []:
for row in queryreturn:
fromLabel, = row
if fromLabel == '': # If this address wasn't in our address book...
queryreturn = sqlQuery(
'''select label from subscriptions where address=?''', fromAddress)
if queryreturn != []:
for row in queryreturn:
fromLabel, = row
if fromLabel == '':
fromLabel = fromAddress
# message row
tableWidget.insertRow(0)
# to
to_item = QtGui.QTableWidgetItem(unicode(toLabel, 'utf-8'))
to_item.setToolTip(unicode(toLabel, 'utf-8'))
to_item = QtGui.QTableWidgetItem(unicode(acct.toLabel, 'utf-8'))
to_item.setToolTip(unicode(acct.toLabel, 'utf-8'))
to_item.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
if not read:
@ -1061,8 +1024,8 @@ class MyForm(QtGui.QMainWindow):
to_item.setIcon(avatarize(toAddress))
tableWidget.setItem(0, 0, to_item)
# from
from_item = QtGui.QTableWidgetItem(unicode(fromLabel, 'utf-8'))
from_item.setToolTip(unicode(fromLabel, 'utf-8'))
from_item = QtGui.QTableWidgetItem(unicode(acct.fromLabel, 'utf-8'))
from_item.setToolTip(unicode(acct.fromLabel, 'utf-8'))
from_item.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
if not read:
@ -1091,7 +1054,8 @@ class MyForm(QtGui.QMainWindow):
time_item.setFont(font)
tableWidget.setItem(0, 3, time_item)
tableWidget.sortItems(3, Qt.DescendingOrder)
tableWidget.horizontalHeader().setSortIndicator(3, Qt.DescendingOrder)
tableWidget.setSortingEnabled(True)
tableWidget.keyPressEvent = self.tableWidgetInboxKeyPressEvent
# create application indicator
@ -1761,8 +1725,8 @@ class MyForm(QtGui.QMainWindow):
def changedInboxUnread(self, row = None):
self.drawTrayIcon(self.currentTrayIconFileName, self.findInboxUnreadCount())
self.rerenderTabTreeMessages()
if not row is None:
row[1], row[6]
# if not row is None:
# row[1], row[6]
if self.ui.tabWidget.currentIndex() == 2:
self.rerenderTabTreeSubscriptions()
elif self.ui.tabWidget.currentIndex() == 3:
@ -2216,35 +2180,23 @@ more work your computer must do to send the message. A Time-To-Live of four or f
return
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
message = shared.fixPotentiallyInvalidUTF8Data(message)
try:
fromLabel = shared.config.get(fromAddress, 'label')
except:
fromLabel = ''
if fromLabel == '':
fromLabel = fromAddress
acct = accountClass(fromAddress)
acct.parseMessage(toAddress, fromAddress, subject, message)
self.ui.tableWidgetInbox.setSortingEnabled(False)
self.ui.tableWidgetInbox.insertRow(0)
if toLabel == '':
newItem = QtGui.QTableWidgetItem(unicode(toAddress, 'utf-8'))
newItem.setToolTip(unicode(toAddress, 'utf-8'))
else:
newItem = QtGui.QTableWidgetItem(unicode(toLabel, 'utf-8'))
newItem.setToolTip(unicode(toLabel, 'utf-8'))
newItem = QtGui.QTableWidgetItem(unicode(acct.toLabel, 'utf-8'))
newItem.setToolTip(unicode(acct.toLabel, 'utf-8'))
newItem.setData(Qt.UserRole, str(toAddress))
newItem.setIcon(avatarize(toAddress))
self.ui.tableWidgetInbox.setItem(0, 0, newItem)
if fromLabel == '':
newItem = QtGui.QTableWidgetItem(unicode(fromAddress, 'utf-8'))
newItem.setToolTip(unicode(fromAddress, 'utf-8'))
else:
newItem = QtGui.QTableWidgetItem(unicode(fromLabel, 'utf-8'))
newItem.setToolTip(unicode(fromLabel, 'utf-8'))
newItem = QtGui.QTableWidgetItem(unicode(acct.fromLabel, 'utf-8'))
newItem.setToolTip(unicode(acct.fromLabel, 'utf-8'))
newItem.setData(Qt.UserRole, str(fromAddress))
newItem.setIcon(avatarize(fromAddress))
self.ui.tableWidgetInbox.setItem(0, 1, newItem)
newItem = QtGui.QTableWidgetItem(unicode(subject, 'utf-8)'))
newItem.setToolTip(unicode(subject, 'utf-8)'))
newItem = QtGui.QTableWidgetItem(unicode(acct.subject, 'utf-8)'))
newItem.setToolTip(unicode(acct.subject, 'utf-8)'))
#newItem.setData(Qt.UserRole, unicode(message, 'utf-8)')) # No longer hold the message in the table; we'll use a SQL query to display it as needed.
self.ui.tableWidgetInbox.setItem(0, 2, newItem)
# newItem = QtGui.QTableWidgetItem('Doing work necessary to send
@ -2259,40 +2211,17 @@ more work your computer must do to send the message. A Time-To-Live of four or f
self.ui.tableWidgetInbox.setSortingEnabled(True)
def displayNewInboxMessage(self, inventoryHash, toAddress, fromAddress, subject, message):
if self.getCurrentFolder() != "inbox" or self.getCurrentAccount() != toAddress:
if (self.getCurrentFolder() != "inbox" and self.getCurrentFolder() != False) or self.getCurrentAccount() != toAddress:
return
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
fromLabel = ''
queryreturn = sqlQuery(
'''select label from addressbook where address=?''', fromAddress)
if queryreturn != []:
for row in queryreturn:
fromLabel, = row
else:
# There might be a label in the subscriptions table
queryreturn = sqlQuery(
'''select label from subscriptions where address=?''', fromAddress)
if queryreturn != []:
for row in queryreturn:
fromLabel, = row
try:
if toAddress == self.str_broadcast_subscribers:
toLabel = self.str_broadcast_subscribers
else:
toLabel = shared.config.get(toAddress, 'label')
except:
toLabel = ''
if toLabel == '':
toLabel = toAddress
acct = accountClass(toAddress)
acct.parseMessage(toAddress, fromAddress, subject, message)
font = QFont()
font.setBold(True)
self.ui.tableWidgetInbox.setSortingEnabled(False)
account = accountClass(toAddress)
account.parseMessage(toAddress, fromAddress, subject, message)
newItem = QtGui.QTableWidgetItem(unicode(toLabel, 'utf-8'))
newItem.setToolTip(unicode(toLabel, 'utf-8'))
newItem = QtGui.QTableWidgetItem(unicode(acct.toLabel, 'utf-8'))
newItem.setToolTip(unicode(acct.toLabel, 'utf-8'))
newItem.setFont(font)
newItem.setData(Qt.UserRole, str(toAddress))
if shared.safeConfigGetBoolean(str(toAddress), 'mailinglist'):
@ -2303,27 +2232,16 @@ more work your computer must do to send the message. A Time-To-Live of four or f
newItem.setIcon(avatarize(toAddress))
self.ui.tableWidgetInbox.setItem(0, 0, newItem)
if type(account) is MailchuckAccount:
newItem = QtGui.QTableWidgetItem(unicode(account.fromAddress, 'utf-8'))
newItem.setToolTip(unicode(account.fromAddress, 'utf-8'))
newItem = QtGui.QTableWidgetItem(unicode(acct.fromLabel, 'utf-8'))
newItem.setToolTip(unicode(acct.fromLabel, 'utf-8'))
if shared.config.getboolean('bitmessagesettings', 'showtraynotifications'):
self.notifierShow(unicode(_translate("MainWindow",'New Message').toUtf8(),'utf-8'), unicode(_translate("MainWindow",'From ').toUtf8(),'utf-8') + unicode(account.fromAddress, 'utf-8'), self.SOUND_UNKNOWN, None)
elif fromLabel == '':
newItem = QtGui.QTableWidgetItem(unicode(fromAddress, 'utf-8'))
newItem.setToolTip(unicode(fromAddress, 'utf-8'))
if shared.config.getboolean('bitmessagesettings', 'showtraynotifications'):
self.notifierShow(unicode(_translate("MainWindow",'New Message').toUtf8(),'utf-8'), unicode(_translate("MainWindow",'From ').toUtf8(),'utf-8') + unicode(fromAddress, 'utf-8'), self.SOUND_UNKNOWN, None)
else:
newItem = QtGui.QTableWidgetItem(unicode(fromLabel, 'utf-8'))
newItem.setToolTip(unicode(unicode(fromLabel, 'utf-8')))
if shared.config.getboolean('bitmessagesettings', 'showtraynotifications'):
self.notifierShow(unicode(_translate("MainWindow",'New Message').toUtf8(),'utf-8'), unicode(_translate("MainWindow",'From ').toUtf8(),'utf-8') + unicode(fromLabel, 'utf-8'), self.SOUND_KNOWN, unicode(fromLabel, 'utf-8'))
self.notifierShow(unicode(_translate("MainWindow",'New Message').toUtf8(),'utf-8'), unicode(_translate("MainWindow",'From ').toUtf8(),'utf-8') + unicode(acct.fromLabel, 'utf-8'), self.SOUND_UNKNOWN, None)
newItem.setData(Qt.UserRole, str(fromAddress))
newItem.setFont(font)
newItem.setIcon(avatarize(fromAddress))
self.ui.tableWidgetInbox.setItem(0, 1, newItem)
newItem = QtGui.QTableWidgetItem(unicode(subject, 'utf-8)'))
newItem.setToolTip(unicode(account.subject, 'utf-8)'))
newItem = QtGui.QTableWidgetItem(unicode(acct.subject, 'utf-8)'))
newItem.setToolTip(unicode(acct.subject, 'utf-8)'))
#newItem.setData(Qt.UserRole, unicode(message, 'utf-8)')) # No longer hold the message in the table; we'll use a SQL query to display it as needed.
newItem.setFont(font)
self.ui.tableWidgetInbox.setItem(0, 2, newItem)
@ -2334,7 +2252,7 @@ more work your computer must do to send the message. A Time-To-Live of four or f
newItem.setFont(font)
self.ui.tableWidgetInbox.setItem(0, 3, newItem)
self.ui.tableWidgetInbox.setSortingEnabled(True)
self.ubuntuMessagingMenuUpdate(True, newItem, toLabel)
self.ubuntuMessagingMenuUpdate(True, newItem, self.toLabel)
def click_pushButtonAddAddressBook(self):
self.AddAddressDialogInstance = AddAddressDialog(self)
@ -2955,11 +2873,14 @@ more work your computer must do to send the message. A Time-To-Live of four or f
tableWidget = self.getCurrentMessagelist()
if not tableWidget:
return
unread = False
while tableWidget.selectedIndexes() != []:
currentRow = tableWidget.selectedIndexes()[0].row()
inventoryHashToTrash = str(tableWidget.item(
currentRow, 3).data(Qt.UserRole).toPyObject())
sqlExecute('''UPDATE inbox SET folder='trash' WHERE msgid=?''', inventoryHashToTrash)
if tableWidget.item(currentRow, 0).font().bold():
unread = True
self.ui.textEditInboxMessage.setText("")
tableWidget.removeRow(currentRow)
self.statusBar().showMessage(_translate(
@ -2968,6 +2889,8 @@ more work your computer must do to send the message. A Time-To-Live of four or f
tableWidget.selectRow(currentRow)
else:
tableWidget.selectRow(currentRow - 1)
if unread:
changedInboxUnread()
def on_action_InboxSaveMessageAs(self):
tableWidget = self.getCurrentMessagelist()
@ -3303,9 +3226,8 @@ more work your computer must do to send the message. A Time-To-Live of four or f
treeWidget = self.ui.treeWidgetYourIdentities
if treeWidget:
currentItem = treeWidget.currentItem()
if currentItem:
account = currentItem.folderName
return account
if currentItem and hasattr(currentItem, 'folderName'):
return currentItem.folderName
else:
# TODO need debug msg?
return False
@ -3518,7 +3440,7 @@ more work your computer must do to send the message. A Time-To-Live of four or f
refresh = False
for row in queryreturn:
message, read = row
if folder == 'inbox' and read == 0:
if folder != 'sent' and read == 0:
markread = sqlQuery(
'''UPDATE inbox SET read = 1 WHERE msgid = ?''', msgid)
refresh = True

View File

@ -3,30 +3,58 @@ from PyQt4 import QtCore, QtGui
import shared
import re
import sys
import inspect
from helper_sql import *
def accountClass(address):
if not shared.config.has_section(address):
return None
try:
gateway = shared.config.get(address, "gateway")
if (gateway == "mailchuck"):
return MailchuckAccount(address)
else:
for name, cls in inspect.getmembers(sys.modules[__name__], inspect.isclass):
# obj = g(address)
if issubclass(cls, GatewayAccount) and cls.gatewayName == gateway:
return cls(address)
# general gateway
return GatewayAccount(address)
except:
pass
# no gateway
return BMAccount(address)
class BMAccount(object):
def __init__(self, address):
def __init__(self, address = None):
self.address = address
def getLabel(self, address = None):
if address is None:
address = self.address
label = address
if shared.config.has_section(address):
label = shared.config.get(address, 'label')
queryreturn = sqlQuery(
'''select label from addressbook where address=?''', address)
if queryreturn != []:
for row in queryreturn:
label, = row
else:
queryreturn = sqlQuery(
'''select label from subscriptions where address=?''', address)
if queryreturn != []:
for row in queryreturn:
label, = row
return label
def parseMessage(self, toAddress, fromAddress, subject, message):
self.toAddress = toAddress
self.fromAddress = fromAddress
self.subject = subject
self.message = message
self.fromLabel = self.getLabel(fromAddress)
self.toLabel = self.getLabel(toAddress)
class GatewayAccount(BMAccount):
gatewayName = None
def __init__(self, address):
super(BMAccount, self).__init__(address)
@ -34,6 +62,8 @@ class GatewayAccount(BMAccount):
super(BMAccount, self).parseMessage(toAddress, fromAddress, subject, message)
class MailchuckAccount(GatewayAccount):
# set "gateway" in keys.dat to this
gatewayName = "mailchuck"
registrationAddress = "BM-2cVYYrhaY5Gbi3KqrX9Eae2NRNrkfrhCSA"
unregistrationAddress = "BM-2cVMAHTRjZHCTPMue75XBK5Tco175DtJ9J"
relayAddress = "BM-2cWim8aZwUNqxzjMxstnUMtVEUQJeezstf"
@ -53,11 +83,11 @@ class MailchuckAccount(GatewayAccount):
if not matches.group(3) is None:
self.subject += matches.group(3)
if not matches.group(2) is None:
self.fromAddress = matches.group(2)
self.fromLabel = matches.group(2)
if toAddress == self.relayAddress:
matches = self.regExpOutgoing.search(subject)
if not matches is None:
if not matches.group(2) is None:
self.subject = matches.group(2)
if not matches.group(1) is None:
self.toAddress = matches.group(1)
self.toLabel = matches.group(1)

View File

@ -49,11 +49,13 @@ class Ui_FolderWidget(QtGui.QTreeWidgetItem):
y = self.folderWeight[other.folderName]
else:
y = 4
reverse = False
if self.treeWidget().header().sortIndicatorOrder() == QtCore.Qt.DescendingOrder:
reverse = True
if x == y:
return self.folderName > other.folderName
return self.folderName < other.folderName
else:
return x > y
return (x >= y if reverse else x < y)
return super(QtGui.QTreeWidgetItem, self).__lt__(other)
@ -117,6 +119,9 @@ class Ui_AddressWidget(QtGui.QTreeWidgetItem):
# label (or address) alphabetically, disabled at the end
def __lt__(self, other):
if (isinstance(other, Ui_AddressWidget)):
reverse = False
if self.treeWidget().header().sortIndicatorOrder() == QtCore.Qt.DescendingOrder:
reverse = True
if shared.config.getboolean(self.address, 'enabled') == shared.config.getboolean(other.address, 'enabled'):
if shared.config.get(self.address, 'label'):
x = shared.config.get(self.address, 'label').decode('utf-8').lower()
@ -126,8 +131,8 @@ class Ui_AddressWidget(QtGui.QTreeWidgetItem):
y = shared.config.get(other.address, 'label').decode('utf-8').lower()
else:
y = other.address.decode('utf-8').lower()
return y < x
return x < y
# else:
return (False if shared.config.getboolean(self.address, 'enabled') else True)
return (not reverse if shared.config.getboolean(self.address, 'enabled') else reverse)
return super(QtGui.QTreeWidgetItem, self).__lt__(other)