Email Gateway UI implementation
First steps, only a tiny part works
This commit is contained in:
parent
83109796fe
commit
033be9b5bf
|
@ -56,6 +56,7 @@ from helper_sql import *
|
||||||
import l10n
|
import l10n
|
||||||
from utils import *
|
from utils import *
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
from account import *
|
||||||
|
|
||||||
def _translate(context, text):
|
def _translate(context, text):
|
||||||
return QtGui.QApplication.translate(context, text)
|
return QtGui.QApplication.translate(context, text)
|
||||||
|
@ -1004,9 +1005,13 @@ class MyForm(QtGui.QMainWindow):
|
||||||
font = QFont()
|
font = QFont()
|
||||||
font.setBold(True)
|
font.setBold(True)
|
||||||
queryreturn = sqlQuery(sqlStatement, account, folder, what)
|
queryreturn = sqlQuery(sqlStatement, account, folder, what)
|
||||||
|
acct = None
|
||||||
for row in queryreturn:
|
for row in queryreturn:
|
||||||
msgid, toAddress, fromAddress, subject, received, read = row
|
msgid, toAddress, fromAddress, subject, received, read = row
|
||||||
|
if acct is None:
|
||||||
|
acct = accountClass(toAddress)
|
||||||
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
|
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
|
||||||
|
acct.parseMessage(toAddress, fromAddress, subject, "")
|
||||||
try:
|
try:
|
||||||
if toAddress == self.str_broadcast_subscribers:
|
if toAddress == self.str_broadcast_subscribers:
|
||||||
toLabel = self.str_broadcast_subscribers
|
toLabel = self.str_broadcast_subscribers
|
||||||
|
@ -1018,6 +1023,8 @@ class MyForm(QtGui.QMainWindow):
|
||||||
toLabel = toAddress
|
toLabel = toAddress
|
||||||
|
|
||||||
fromLabel = ''
|
fromLabel = ''
|
||||||
|
if type(acct) == MailchuckAccount:
|
||||||
|
fromLabel = acct.fromAddress
|
||||||
if shared.config.has_section(fromAddress):
|
if shared.config.has_section(fromAddress):
|
||||||
fromLabel = shared.config.get(fromAddress, 'label')
|
fromLabel = shared.config.get(fromAddress, 'label')
|
||||||
|
|
||||||
|
@ -1066,8 +1073,8 @@ class MyForm(QtGui.QMainWindow):
|
||||||
from_item.setIcon(avatarize(fromAddress))
|
from_item.setIcon(avatarize(fromAddress))
|
||||||
tableWidget.setItem(0, 1, from_item)
|
tableWidget.setItem(0, 1, from_item)
|
||||||
# subject
|
# subject
|
||||||
subject_item = QtGui.QTableWidgetItem(unicode(subject, 'utf-8'))
|
subject_item = QtGui.QTableWidgetItem(unicode(acct.subject, 'utf-8'))
|
||||||
subject_item.setToolTip(unicode(subject, 'utf-8'))
|
subject_item.setToolTip(unicode(acct.subject, 'utf-8'))
|
||||||
subject_item.setFlags(
|
subject_item.setFlags(
|
||||||
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
||||||
if not read:
|
if not read:
|
||||||
|
@ -1751,11 +1758,12 @@ class MyForm(QtGui.QMainWindow):
|
||||||
def drawTrayIcon(self, iconFileName, inboxUnreadCount):
|
def drawTrayIcon(self, iconFileName, inboxUnreadCount):
|
||||||
self.tray.setIcon(self.calcTrayIcon(iconFileName, inboxUnreadCount))
|
self.tray.setIcon(self.calcTrayIcon(iconFileName, inboxUnreadCount))
|
||||||
|
|
||||||
def changedInboxUnread(self):
|
def changedInboxUnread(self, row = None):
|
||||||
self.drawTrayIcon(self.currentTrayIconFileName, self.findInboxUnreadCount())
|
self.drawTrayIcon(self.currentTrayIconFileName, self.findInboxUnreadCount())
|
||||||
if self.ui.tabWidget.currentIndex() == 0:
|
|
||||||
self.rerenderTabTreeMessages()
|
self.rerenderTabTreeMessages()
|
||||||
elif self.ui.tabWidget.currentIndex() == 2:
|
if not row is None:
|
||||||
|
row[1], row[6]
|
||||||
|
if self.ui.tabWidget.currentIndex() == 2:
|
||||||
self.rerenderTabTreeSubscriptions()
|
self.rerenderTabTreeSubscriptions()
|
||||||
elif self.ui.tabWidget.currentIndex() == 3:
|
elif self.ui.tabWidget.currentIndex() == 3:
|
||||||
self.rerenderTabTreeChans()
|
self.rerenderTabTreeChans()
|
||||||
|
@ -2281,6 +2289,8 @@ more work your computer must do to send the message. A Time-To-Live of four or f
|
||||||
font = QFont()
|
font = QFont()
|
||||||
font.setBold(True)
|
font.setBold(True)
|
||||||
self.ui.tableWidgetInbox.setSortingEnabled(False)
|
self.ui.tableWidgetInbox.setSortingEnabled(False)
|
||||||
|
account = accountClass(toAddress)
|
||||||
|
account.parseMessage(toAddress, fromAddress, subject, message)
|
||||||
newItem = QtGui.QTableWidgetItem(unicode(toLabel, 'utf-8'))
|
newItem = QtGui.QTableWidgetItem(unicode(toLabel, 'utf-8'))
|
||||||
newItem.setToolTip(unicode(toLabel, 'utf-8'))
|
newItem.setToolTip(unicode(toLabel, 'utf-8'))
|
||||||
newItem.setFont(font)
|
newItem.setFont(font)
|
||||||
|
@ -2293,7 +2303,12 @@ more work your computer must do to send the message. A Time-To-Live of four or f
|
||||||
newItem.setIcon(avatarize(toAddress))
|
newItem.setIcon(avatarize(toAddress))
|
||||||
self.ui.tableWidgetInbox.setItem(0, 0, newItem)
|
self.ui.tableWidgetInbox.setItem(0, 0, newItem)
|
||||||
|
|
||||||
if fromLabel == '':
|
if type(account) is MailchuckAccount:
|
||||||
|
newItem = QtGui.QTableWidgetItem(unicode(account.fromAddress, 'utf-8'))
|
||||||
|
newItem.setToolTip(unicode(account.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(account.fromAddress, 'utf-8'), self.SOUND_UNKNOWN, None)
|
||||||
|
elif fromLabel == '':
|
||||||
newItem = QtGui.QTableWidgetItem(unicode(fromAddress, 'utf-8'))
|
newItem = QtGui.QTableWidgetItem(unicode(fromAddress, 'utf-8'))
|
||||||
newItem.setToolTip(unicode(fromAddress, 'utf-8'))
|
newItem.setToolTip(unicode(fromAddress, 'utf-8'))
|
||||||
if shared.config.getboolean('bitmessagesettings', 'showtraynotifications'):
|
if shared.config.getboolean('bitmessagesettings', 'showtraynotifications'):
|
||||||
|
@ -2308,7 +2323,7 @@ more work your computer must do to send the message. A Time-To-Live of four or f
|
||||||
newItem.setIcon(avatarize(fromAddress))
|
newItem.setIcon(avatarize(fromAddress))
|
||||||
self.ui.tableWidgetInbox.setItem(0, 1, newItem)
|
self.ui.tableWidgetInbox.setItem(0, 1, newItem)
|
||||||
newItem = QtGui.QTableWidgetItem(unicode(subject, 'utf-8)'))
|
newItem = QtGui.QTableWidgetItem(unicode(subject, 'utf-8)'))
|
||||||
newItem.setToolTip(unicode(subject, 'utf-8)'))
|
newItem.setToolTip(unicode(account.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.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)
|
newItem.setFont(font)
|
||||||
self.ui.tableWidgetInbox.setItem(0, 2, newItem)
|
self.ui.tableWidgetInbox.setItem(0, 2, newItem)
|
||||||
|
@ -3272,25 +3287,25 @@ more work your computer must do to send the message. A Time-To-Live of four or f
|
||||||
|
|
||||||
# Group of functions for the Your Identities dialog box
|
# Group of functions for the Your Identities dialog box
|
||||||
def getCurrentAccount(self):
|
def getCurrentAccount(self):
|
||||||
treeWidget = self.getCurrentTreeWidget()
|
#treeWidget = self.getCurrentTreeWidget()
|
||||||
|
treeWidget = self.ui.treeWidgetYourIdentities
|
||||||
if treeWidget:
|
if treeWidget:
|
||||||
currentItem = treeWidget.currentItem()
|
currentItem = treeWidget.currentItem()
|
||||||
if currentItem:
|
if currentItem:
|
||||||
accountFolder = currentItem.data(0, Qt.UserRole).toPyObject()
|
account = currentItem.address
|
||||||
account = accountFolder[0]
|
return account
|
||||||
return str(account)
|
|
||||||
else:
|
else:
|
||||||
# TODO need debug msg?
|
# TODO need debug msg?
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def getCurrentFolder(self):
|
def getCurrentFolder(self):
|
||||||
treeWidget = self.getCurrentTreeWidget()
|
#treeWidget = self.getCurrentTreeWidget()
|
||||||
|
treeWidget = self.ui.treeWidgetYourIdentities
|
||||||
if treeWidget:
|
if treeWidget:
|
||||||
currentItem = treeWidget.currentItem()
|
currentItem = treeWidget.currentItem()
|
||||||
if currentItem:
|
if currentItem:
|
||||||
accountFolder = currentItem.data(0, Qt.UserRole).toPyObject()
|
account = currentItem.folderName
|
||||||
folder = accountFolder[1]
|
return account
|
||||||
return str(folder)
|
|
||||||
else:
|
else:
|
||||||
# TODO need debug msg?
|
# TODO need debug msg?
|
||||||
return False
|
return False
|
||||||
|
|
63
src/bitmessageqt/account.py
Normal file
63
src/bitmessageqt/account.py
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
from PyQt4 import QtCore, QtGui
|
||||||
|
|
||||||
|
import shared
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
|
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:
|
||||||
|
return GatewayAccount(address)
|
||||||
|
except:
|
||||||
|
return BMAccount(address)
|
||||||
|
|
||||||
|
class BMAccount(object):
|
||||||
|
def __init__(self, address):
|
||||||
|
self.address = address
|
||||||
|
|
||||||
|
def parseMessage(self, toAddress, fromAddress, subject, message):
|
||||||
|
self.toAddress = toAddress
|
||||||
|
self.fromAddress = fromAddress
|
||||||
|
self.subject = subject
|
||||||
|
self.message = message
|
||||||
|
|
||||||
|
class GatewayAccount(BMAccount):
|
||||||
|
def __init__(self, address):
|
||||||
|
super(BMAccount, self).__init__(address)
|
||||||
|
|
||||||
|
def parseMessage(self, toAddress, fromAddress, subject, message):
|
||||||
|
super(BMAccount, self).parseMessage(toAddress, fromAddress, subject, message)
|
||||||
|
|
||||||
|
class MailchuckAccount(GatewayAccount):
|
||||||
|
registrationAddress = "BM-2cVYYrhaY5Gbi3KqrX9Eae2NRNrkfrhCSA"
|
||||||
|
unregistrationAddress = "BM-2cVMAHTRjZHCTPMue75XBK5Tco175DtJ9J"
|
||||||
|
relayAddress = "BM-2cWim8aZwUNqxzjMxstnUMtVEUQJeezstf"
|
||||||
|
regExpIncoming = re.compile("(.*)MAILCHUCK-FROM::(\S+) \| (.*)")
|
||||||
|
regExpOutgoing = re.compile("(\S+) (.*)")
|
||||||
|
def __init__(self, address):
|
||||||
|
super(GatewayAccount, self).__init__(address)
|
||||||
|
|
||||||
|
def parseMessage(self, toAddress, fromAddress, subject, message):
|
||||||
|
super(GatewayAccount, self).parseMessage(toAddress, fromAddress, subject, message)
|
||||||
|
if fromAddress == self.relayAddress:
|
||||||
|
matches = self.regExpIncoming.search(subject)
|
||||||
|
if not matches is None:
|
||||||
|
self.subject = ""
|
||||||
|
if not matches.group(1) is None:
|
||||||
|
self.subject += matches.group(1)
|
||||||
|
if not matches.group(3) is None:
|
||||||
|
self.subject += matches.group(3)
|
||||||
|
if not matches.group(2) is None:
|
||||||
|
self.fromAddress = 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)
|
|
@ -36,7 +36,7 @@ class Ui_FolderWidget(QtGui.QTreeWidgetItem):
|
||||||
self.setFont(0, font)
|
self.setFont(0, font)
|
||||||
self.setText(0, text)
|
self.setText(0, text)
|
||||||
self.setToolTip(0, text)
|
self.setToolTip(0, text)
|
||||||
self.setData(0, QtCore.Qt.UserRole, [self.address, self.folderName])
|
# self.setData(0, QtCore.Qt.UserRole, [self.address, self.folderName])
|
||||||
|
|
||||||
# inbox, sent, thrash first, rest alphabetically
|
# inbox, sent, thrash first, rest alphabetically
|
||||||
def __lt__(self, other):
|
def __lt__(self, other):
|
||||||
|
@ -108,7 +108,7 @@ class Ui_AddressWidget(QtGui.QTreeWidgetItem):
|
||||||
self.setIcon(0, avatarize(self.address))
|
self.setIcon(0, avatarize(self.address))
|
||||||
self.setText(0, text)
|
self.setText(0, text)
|
||||||
self.setToolTip(0, text)
|
self.setToolTip(0, text)
|
||||||
self.setData(0, QtCore.Qt.UserRole, [self.address, "inbox"])
|
# self.setData(0, QtCore.Qt.UserRole, [self.address, "inbox"])
|
||||||
|
|
||||||
def setExpanded(self, expand):
|
def setExpanded(self, expand):
|
||||||
super(Ui_AddressWidget, self).setExpanded(expand)
|
super(Ui_AddressWidget, self).setExpanded(expand)
|
||||||
|
|
Reference in New Issue
Block a user