PyBitmessage/src/bitmessageqt/__init__.py

2943 lines
152 KiB
Python
Raw Normal View History

2013-06-12 10:05:20 +02:00
try:
import locale
except:
pass
2013-05-02 17:53:54 +02:00
try:
from PyQt4 import QtCore, QtGui
2013-05-02 17:53:54 +02:00
from PyQt4.QtCore import *
from PyQt4.QtGui import *
except Exception as err:
print 'PyBitmessage requires PyQt unless you want to run it as a daemon and interact with it using the API. You can download it from http://www.riverbankcomputing.com/software/pyqt/download or by searching Google for \'PyQt Download\' (without quotes).'
2013-05-02 17:53:54 +02:00
print 'Error message:', err
sys.exit()
try:
_encoding = QtGui.QApplication.UnicodeUTF8
except AttributeError:
2013-06-14 21:58:46 +02:00
print 'QtGui.QApplication.UnicodeUTF8 error:', err
def _translate(context, text):
return QtGui.QApplication.translate(context, text)
withMessagingMenu = False
try:
from gi.repository import MessagingMenu
from gi.repository import Notify
withMessagingMenu = True
except ImportError:
MessagingMenu = None
2013-05-02 17:53:54 +02:00
from addresses import *
import shared
from bitmessageui import *
from newaddressdialog import *
from newsubscriptiondialog import *
from regenerateaddresses import *
from specialaddressbehavior import *
from settings import *
from about import *
from help import *
from iconglossary import *
import sys
from time import strftime, localtime, gmtime
import time
import os
from pyelliptic.openssl import OpenSSL
import pickle
2013-05-14 17:44:51 +02:00
import platform
2013-05-02 17:53:54 +02:00
class MyForm(QtGui.QMainWindow):
str_broadcast_subscribers = '[Broadcast subscribers]'
2013-05-02 17:53:54 +02:00
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
# Ask the user if we may delete their old version 1 addresses if they
# have any.
2013-05-02 17:53:54 +02:00
configSections = shared.config.sections()
for addressInKeysFile in configSections:
if addressInKeysFile != 'bitmessagesettings':
status, addressVersionNumber, streamNumber, hash = decodeAddress(
addressInKeysFile)
2013-05-02 17:53:54 +02:00
if addressVersionNumber == 1:
displayMsg = _translate(
"MainWindow", "One of your addresses, %1, is an old version 1 address. Version 1 addresses are no longer supported. "
+ "May we delete it now?").arg(addressInKeysFile)
reply = QtGui.QMessageBox.question(
self, 'Message', displayMsg, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
2013-05-02 17:53:54 +02:00
if reply == QtGui.QMessageBox.Yes:
shared.config.remove_section(addressInKeysFile)
with open(shared.appdata + 'keys.dat', 'wb') as configfile:
shared.config.write(configfile)
# Configure Bitmessage to start on startup (or remove the
# configuration) based on the setting in the keys.dat file
2013-05-02 17:53:54 +02:00
if 'win32' in sys.platform or 'win64' in sys.platform:
# Auto-startup for Windows
2013-05-02 17:53:54 +02:00
RUN_PATH = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"
self.settings = QSettings(RUN_PATH, QSettings.NativeFormat)
self.settings.remove(
"PyBitmessage") # In case the user moves the program and the registry entry is no longer valid, this will delete the old registry entry.
2013-05-02 17:53:54 +02:00
if shared.config.getboolean('bitmessagesettings', 'startonlogon'):
self.settings.setValue("PyBitmessage", sys.argv[0])
2013-05-02 17:53:54 +02:00
elif 'darwin' in sys.platform:
# startup for mac
2013-05-02 17:53:54 +02:00
pass
elif 'linux' in sys.platform:
# startup for linux
2013-05-02 17:53:54 +02:00
pass
self.ui.labelSendBroadcastWarning.setVisible(False)
# FILE MENU and other buttons
QtCore.QObject.connect(self.ui.actionExit, QtCore.SIGNAL(
"triggered()"), self.quit)
QtCore.QObject.connect(self.ui.actionManageKeys, QtCore.SIGNAL(
"triggered()"), self.click_actionManageKeys)
QtCore.QObject.connect(self.ui.actionDeleteAllTrashedMessages, QtCore.SIGNAL(
"triggered()"), self.click_actionDeleteAllTrashedMessages)
QtCore.QObject.connect(self.ui.actionRegenerateDeterministicAddresses, QtCore.SIGNAL(
"triggered()"), self.click_actionRegenerateDeterministicAddresses)
QtCore.QObject.connect(self.ui.pushButtonNewAddress, QtCore.SIGNAL(
"clicked()"), self.click_NewAddressDialog)
QtCore.QObject.connect(self.ui.comboBoxSendFrom, QtCore.SIGNAL(
"activated(int)"), self.redrawLabelFrom)
QtCore.QObject.connect(self.ui.pushButtonAddAddressBook, QtCore.SIGNAL(
"clicked()"), self.click_pushButtonAddAddressBook)
QtCore.QObject.connect(self.ui.pushButtonAddSubscription, QtCore.SIGNAL(
"clicked()"), self.click_pushButtonAddSubscription)
QtCore.QObject.connect(self.ui.pushButtonAddBlacklist, QtCore.SIGNAL(
"clicked()"), self.click_pushButtonAddBlacklist)
QtCore.QObject.connect(self.ui.pushButtonSend, QtCore.SIGNAL(
"clicked()"), self.click_pushButtonSend)
QtCore.QObject.connect(self.ui.pushButtonLoadFromAddressBook, QtCore.SIGNAL(
"clicked()"), self.click_pushButtonLoadFromAddressBook)
QtCore.QObject.connect(self.ui.radioButtonBlacklist, QtCore.SIGNAL(
"clicked()"), self.click_radioButtonBlacklist)
QtCore.QObject.connect(self.ui.radioButtonWhitelist, QtCore.SIGNAL(
"clicked()"), self.click_radioButtonWhitelist)
QtCore.QObject.connect(self.ui.pushButtonStatusIcon, QtCore.SIGNAL(
"clicked()"), self.click_pushButtonStatusIcon)
QtCore.QObject.connect(self.ui.actionSettings, QtCore.SIGNAL(
"triggered()"), self.click_actionSettings)
QtCore.QObject.connect(self.ui.actionAbout, QtCore.SIGNAL(
"triggered()"), self.click_actionAbout)
QtCore.QObject.connect(self.ui.actionHelp, QtCore.SIGNAL(
"triggered()"), self.click_actionHelp)
# Popup menu for the Inbox tab
2013-05-02 17:53:54 +02:00
self.ui.inboxContextMenuToolbar = QtGui.QToolBar()
# Actions
self.actionReply = self.ui.inboxContextMenuToolbar.addAction(_translate(
"MainWindow", "Reply"), self.on_action_InboxReply)
self.actionAddSenderToAddressBook = self.ui.inboxContextMenuToolbar.addAction(_translate(
"MainWindow", "Add sender to your Address Book"), self.on_action_InboxAddSenderToAddressBook)
self.actionTrashInboxMessage = self.ui.inboxContextMenuToolbar.addAction(
_translate("MainWindow", "Move to Trash"), self.on_action_InboxTrash)
self.actionForceHtml = self.ui.inboxContextMenuToolbar.addAction(_translate(
"MainWindow", "View HTML code as formatted text"), self.on_action_InboxMessageForceHtml)
self.actionSaveMessageAs = self.ui.inboxContextMenuToolbar.addAction(_translate(
"MainWindow", "Save message as..."), self.on_action_InboxSaveMessageAs)
self.ui.tableWidgetInbox.setContextMenuPolicy(
QtCore.Qt.CustomContextMenu)
self.connect(self.ui.tableWidgetInbox, QtCore.SIGNAL(
'customContextMenuRequested(const QPoint&)'), self.on_context_menuInbox)
self.popMenuInbox = QtGui.QMenu(self)
self.popMenuInbox.addAction(self.actionForceHtml)
2013-05-02 17:53:54 +02:00
self.popMenuInbox.addSeparator()
self.popMenuInbox.addAction(self.actionReply)
self.popMenuInbox.addAction(self.actionAddSenderToAddressBook)
2013-05-02 17:53:54 +02:00
self.popMenuInbox.addSeparator()
2013-06-17 00:28:18 +02:00
self.popMenuInbox.addAction( self.actionSaveMessageAs )
2013-05-02 17:53:54 +02:00
self.popMenuInbox.addAction( self.actionTrashInboxMessage )
# Popup menu for the Your Identities tab
2013-05-02 17:53:54 +02:00
self.ui.addressContextMenuToolbar = QtGui.QToolBar()
# Actions
self.actionNew = self.ui.addressContextMenuToolbar.addAction(_translate(
"MainWindow", "New"), self.on_action_YourIdentitiesNew)
self.actionEnable = self.ui.addressContextMenuToolbar.addAction(_translate(
"MainWindow", "Enable"), self.on_action_YourIdentitiesEnable)
self.actionDisable = self.ui.addressContextMenuToolbar.addAction(_translate(
"MainWindow", "Disable"), self.on_action_YourIdentitiesDisable)
self.actionClipboard = self.ui.addressContextMenuToolbar.addAction(_translate(
"MainWindow", "Copy address to clipboard"), self.on_action_YourIdentitiesClipboard)
self.actionSpecialAddressBehavior = self.ui.addressContextMenuToolbar.addAction(_translate(
"MainWindow", "Special address behavior..."), self.on_action_SpecialAddressBehaviorDialog)
self.ui.tableWidgetYourIdentities.setContextMenuPolicy(
QtCore.Qt.CustomContextMenu)
self.connect(self.ui.tableWidgetYourIdentities, QtCore.SIGNAL(
'customContextMenuRequested(const QPoint&)'), self.on_context_menuYourIdentities)
self.popMenu = QtGui.QMenu(self)
self.popMenu.addAction(self.actionNew)
2013-05-02 17:53:54 +02:00
self.popMenu.addSeparator()
self.popMenu.addAction(self.actionClipboard)
2013-05-02 17:53:54 +02:00
self.popMenu.addSeparator()
self.popMenu.addAction(self.actionEnable)
self.popMenu.addAction(self.actionDisable)
self.popMenu.addAction(self.actionSpecialAddressBehavior)
2013-05-02 17:53:54 +02:00
# Popup menu for the Address Book page
2013-05-02 17:53:54 +02:00
self.ui.addressBookContextMenuToolbar = QtGui.QToolBar()
# Actions
self.actionAddressBookSend = self.ui.addressBookContextMenuToolbar.addAction(_translate(
"MainWindow", "Send message to this address"), self.on_action_AddressBookSend)
self.actionAddressBookClipboard = self.ui.addressBookContextMenuToolbar.addAction(_translate(
"MainWindow", "Copy address to clipboard"), self.on_action_AddressBookClipboard)
2013-06-19 18:19:07 +02:00
self.actionAddressBookSubscribe = self.ui.addressBookContextMenuToolbar.addAction(_translate(
"MainWindow", "Subscribe to this address"), self.on_action_AddressBookSubscribe)
self.actionAddressBookNew = self.ui.addressBookContextMenuToolbar.addAction(_translate(
"MainWindow", "Add New Address"), self.on_action_AddressBookNew)
self.actionAddressBookDelete = self.ui.addressBookContextMenuToolbar.addAction(_translate(
"MainWindow", "Delete"), self.on_action_AddressBookDelete)
self.ui.tableWidgetAddressBook.setContextMenuPolicy(
QtCore.Qt.CustomContextMenu)
self.connect(self.ui.tableWidgetAddressBook, QtCore.SIGNAL(
'customContextMenuRequested(const QPoint&)'), self.on_context_menuAddressBook)
self.popMenuAddressBook = QtGui.QMenu(self)
self.popMenuAddressBook.addAction(self.actionAddressBookSend)
self.popMenuAddressBook.addAction(self.actionAddressBookClipboard)
self.popMenuAddressBook.addAction( self.actionAddressBookSubscribe )
2013-05-02 17:53:54 +02:00
self.popMenuAddressBook.addSeparator()
self.popMenuAddressBook.addAction(self.actionAddressBookNew)
self.popMenuAddressBook.addAction(self.actionAddressBookDelete)
2013-05-02 17:53:54 +02:00
# Popup menu for the Subscriptions page
2013-05-02 17:53:54 +02:00
self.ui.subscriptionsContextMenuToolbar = QtGui.QToolBar()
# Actions
self.actionsubscriptionsNew = self.ui.subscriptionsContextMenuToolbar.addAction(
_translate("MainWindow", "New"), self.on_action_SubscriptionsNew)
self.actionsubscriptionsDelete = self.ui.subscriptionsContextMenuToolbar.addAction(
_translate("MainWindow", "Delete"), self.on_action_SubscriptionsDelete)
self.actionsubscriptionsClipboard = self.ui.subscriptionsContextMenuToolbar.addAction(
_translate("MainWindow", "Copy address to clipboard"), self.on_action_SubscriptionsClipboard)
self.actionsubscriptionsEnable = self.ui.subscriptionsContextMenuToolbar.addAction(
_translate("MainWindow", "Enable"), self.on_action_SubscriptionsEnable)
self.actionsubscriptionsDisable = self.ui.subscriptionsContextMenuToolbar.addAction(
_translate("MainWindow", "Disable"), self.on_action_SubscriptionsDisable)
self.ui.tableWidgetSubscriptions.setContextMenuPolicy(
QtCore.Qt.CustomContextMenu)
self.connect(self.ui.tableWidgetSubscriptions, QtCore.SIGNAL(
'customContextMenuRequested(const QPoint&)'), self.on_context_menuSubscriptions)
self.popMenuSubscriptions = QtGui.QMenu(self)
self.popMenuSubscriptions.addAction(self.actionsubscriptionsNew)
self.popMenuSubscriptions.addAction(self.actionsubscriptionsDelete)
2013-05-02 17:53:54 +02:00
self.popMenuSubscriptions.addSeparator()
self.popMenuSubscriptions.addAction(self.actionsubscriptionsEnable)
self.popMenuSubscriptions.addAction(self.actionsubscriptionsDisable)
2013-05-02 17:53:54 +02:00
self.popMenuSubscriptions.addSeparator()
self.popMenuSubscriptions.addAction(self.actionsubscriptionsClipboard)
2013-05-02 17:53:54 +02:00
# Popup menu for the Sent page
2013-05-02 17:53:54 +02:00
self.ui.sentContextMenuToolbar = QtGui.QToolBar()
# Actions
self.actionTrashSentMessage = self.ui.sentContextMenuToolbar.addAction(_translate(
"MainWindow", "Move to Trash"), self.on_action_SentTrash)
self.actionSentClipboard = self.ui.sentContextMenuToolbar.addAction(_translate(
"MainWindow", "Copy destination address to clipboard"), self.on_action_SentClipboard)
self.actionForceSend = self.ui.sentContextMenuToolbar.addAction(_translate(
"MainWindow", "Force send"), self.on_action_ForceSend)
self.ui.tableWidgetSent.setContextMenuPolicy(
QtCore.Qt.CustomContextMenu)
self.connect(self.ui.tableWidgetSent, QtCore.SIGNAL(
'customContextMenuRequested(const QPoint&)'), self.on_context_menuSent)
# self.popMenuSent = QtGui.QMenu( self )
# self.popMenuSent.addAction( self.actionSentClipboard )
# self.popMenuSent.addAction( self.actionTrashSentMessage )
# Popup menu for the Blacklist page
2013-05-02 17:53:54 +02:00
self.ui.blacklistContextMenuToolbar = QtGui.QToolBar()
# Actions
self.actionBlacklistNew = self.ui.blacklistContextMenuToolbar.addAction(_translate(
"MainWindow", "Add new entry"), self.on_action_BlacklistNew)
self.actionBlacklistDelete = self.ui.blacklistContextMenuToolbar.addAction(_translate(
"MainWindow", "Delete"), self.on_action_BlacklistDelete)
self.actionBlacklistClipboard = self.ui.blacklistContextMenuToolbar.addAction(_translate(
"MainWindow", "Copy address to clipboard"), self.on_action_BlacklistClipboard)
self.actionBlacklistEnable = self.ui.blacklistContextMenuToolbar.addAction(_translate(
"MainWindow", "Enable"), self.on_action_BlacklistEnable)
self.actionBlacklistDisable = self.ui.blacklistContextMenuToolbar.addAction(_translate(
"MainWindow", "Disable"), self.on_action_BlacklistDisable)
self.ui.tableWidgetBlacklist.setContextMenuPolicy(
QtCore.Qt.CustomContextMenu)
self.connect(self.ui.tableWidgetBlacklist, QtCore.SIGNAL(
'customContextMenuRequested(const QPoint&)'), self.on_context_menuBlacklist)
self.popMenuBlacklist = QtGui.QMenu(self)
# self.popMenuBlacklist.addAction( self.actionBlacklistNew )
self.popMenuBlacklist.addAction(self.actionBlacklistDelete)
2013-05-02 17:53:54 +02:00
self.popMenuBlacklist.addSeparator()
self.popMenuBlacklist.addAction(self.actionBlacklistClipboard)
2013-05-02 17:53:54 +02:00
self.popMenuBlacklist.addSeparator()
self.popMenuBlacklist.addAction(self.actionBlacklistEnable)
self.popMenuBlacklist.addAction(self.actionBlacklistDisable)
2013-05-02 17:53:54 +02:00
# Initialize the user's list of addresses on the 'Your Identities' tab.
2013-05-02 17:53:54 +02:00
configSections = shared.config.sections()
for addressInKeysFile in configSections:
if addressInKeysFile != 'bitmessagesettings':
isEnabled = shared.config.getboolean(
addressInKeysFile, 'enabled')
newItem = QtGui.QTableWidgetItem(unicode(
shared.config.get(addressInKeysFile, 'label'), 'utf-8)'))
2013-05-02 17:53:54 +02:00
if not isEnabled:
newItem.setTextColor(QtGui.QColor(128, 128, 128))
2013-05-02 17:53:54 +02:00
self.ui.tableWidgetYourIdentities.insertRow(0)
self.ui.tableWidgetYourIdentities.setItem(0, 0, newItem)
newItem = QtGui.QTableWidgetItem(addressInKeysFile)
newItem.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
2013-05-02 17:53:54 +02:00
if not isEnabled:
newItem.setTextColor(QtGui.QColor(128, 128, 128))
if shared.safeConfigGetBoolean(addressInKeysFile, 'mailinglist'):
newItem.setTextColor(QtGui.QColor(137, 04, 177)) # magenta
2013-05-02 17:53:54 +02:00
self.ui.tableWidgetYourIdentities.setItem(0, 1, newItem)
newItem = QtGui.QTableWidgetItem(str(
addressStream(addressInKeysFile)))
newItem.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
2013-05-02 17:53:54 +02:00
if not isEnabled:
newItem.setTextColor(QtGui.QColor(128, 128, 128))
2013-05-02 17:53:54 +02:00
self.ui.tableWidgetYourIdentities.setItem(0, 2, newItem)
if isEnabled:
status, addressVersionNumber, streamNumber, hash = decodeAddress(
addressInKeysFile)
2013-05-02 17:53:54 +02:00
# Load inbox from messages database file
2013-05-02 17:53:54 +02:00
font = QFont()
font.setBold(True)
2013-05-02 20:18:24 +02:00
shared.sqlLock.acquire()
shared.sqlSubmitQueue.put(
'''SELECT msgid, toaddress, fromaddress, subject, received, message, read FROM inbox where folder='inbox' ORDER BY received''')
2013-05-02 17:53:54 +02:00
shared.sqlSubmitQueue.put('')
queryreturn = shared.sqlReturnQueue.get()
2013-05-02 20:18:24 +02:00
shared.sqlLock.release()
2013-05-02 17:53:54 +02:00
for row in queryreturn:
msgid, toAddress, fromAddress, subject, received, message, read = row
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
message = shared.fixPotentiallyInvalidUTF8Data(message)
2013-05-02 17:53:54 +02:00
try:
if toAddress == self.str_broadcast_subscribers:
toLabel = self.str_broadcast_subscribers
2013-05-02 17:53:54 +02:00
else:
toLabel = shared.config.get(toAddress, 'label')
except:
toLabel = ''
if toLabel == '':
toLabel = toAddress
fromLabel = ''
t = (fromAddress,)
2013-05-02 20:18:24 +02:00
shared.sqlLock.acquire()
shared.sqlSubmitQueue.put(
'''select label from addressbook where address=?''')
2013-05-02 17:53:54 +02:00
shared.sqlSubmitQueue.put(t)
queryreturn = shared.sqlReturnQueue.get()
2013-05-02 20:18:24 +02:00
shared.sqlLock.release()
2013-05-02 17:53:54 +02:00
if queryreturn != []:
2013-05-02 17:53:54 +02:00
for row in queryreturn:
fromLabel, = row
if fromLabel == '': # If this address wasn't in our address book...
2013-05-02 17:53:54 +02:00
t = (fromAddress,)
2013-05-02 20:18:24 +02:00
shared.sqlLock.acquire()
shared.sqlSubmitQueue.put(
'''select label from subscriptions where address=?''')
2013-05-02 17:53:54 +02:00
shared.sqlSubmitQueue.put(t)
queryreturn = shared.sqlReturnQueue.get()
2013-05-02 20:18:24 +02:00
shared.sqlLock.release()
2013-05-02 17:53:54 +02:00
if queryreturn != []:
2013-05-02 17:53:54 +02:00
for row in queryreturn:
fromLabel, = row
self.ui.tableWidgetInbox.insertRow(0)
newItem = QtGui.QTableWidgetItem(unicode(toLabel, 'utf-8'))
newItem.setToolTip(unicode(toLabel, 'utf-8'))
newItem.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
2013-05-02 17:53:54 +02:00
if not read:
newItem.setFont(font)
newItem.setData(Qt.UserRole, str(toAddress))
if shared.safeConfigGetBoolean(toAddress, 'mailinglist'):
newItem.setTextColor(QtGui.QColor(137, 04, 177))
self.ui.tableWidgetInbox.setItem(0, 0, newItem)
2013-05-02 17:53:54 +02:00
if fromLabel == '':
newItem = QtGui.QTableWidgetItem(
unicode(fromAddress, 'utf-8'))
newItem.setToolTip(unicode(fromAddress, 'utf-8'))
2013-05-02 17:53:54 +02:00
else:
newItem = QtGui.QTableWidgetItem(unicode(fromLabel, 'utf-8'))
newItem.setToolTip(unicode(fromLabel, 'utf-8'))
newItem.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
2013-05-02 17:53:54 +02:00
if not read:
newItem.setFont(font)
newItem.setData(Qt.UserRole, str(fromAddress))
self.ui.tableWidgetInbox.setItem(0, 1, newItem)
newItem = QtGui.QTableWidgetItem(unicode(subject, 'utf-8'))
newItem.setToolTip(unicode(subject, 'utf-8'))
newItem.setData(Qt.UserRole, unicode(message, 'utf-8)'))
newItem.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
2013-05-02 17:53:54 +02:00
if not read:
newItem.setFont(font)
self.ui.tableWidgetInbox.setItem(0, 2, newItem)
newItem = myTableWidgetItem(unicode(strftime(shared.config.get(
'bitmessagesettings', 'timeformat'), localtime(int(received))), 'utf-8'))
newItem.setToolTip(unicode(strftime(shared.config.get(
'bitmessagesettings', 'timeformat'), localtime(int(received))), 'utf-8'))
newItem.setData(Qt.UserRole, QByteArray(msgid))
newItem.setData(33, int(received))
newItem.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
2013-05-02 17:53:54 +02:00
if not read:
newItem.setFont(font)
self.ui.tableWidgetInbox.setItem(0, 3, newItem)
self.ui.tableWidgetInbox.sortItems(3, Qt.DescendingOrder)
2013-05-02 17:53:54 +02:00
self.ui.tableWidgetInbox.keyPressEvent = self.tableWidgetInboxKeyPressEvent
# Load Sent items from database
2013-05-02 20:18:24 +02:00
shared.sqlLock.acquire()
shared.sqlSubmitQueue.put(
'''SELECT toaddress, fromaddress, subject, message, status, ackdata, lastactiontime FROM sent where folder = 'sent' ORDER BY lastactiontime''')
2013-05-02 17:53:54 +02:00
shared.sqlSubmitQueue.put('')
queryreturn = shared.sqlReturnQueue.get()
2013-05-02 20:18:24 +02:00
shared.sqlLock.release()
2013-05-02 17:53:54 +02:00
for row in queryreturn:
toAddress, fromAddress, subject, message, status, ackdata, lastactiontime = row
subject = shared.fixPotentiallyInvalidUTF8Data(subject)
message = shared.fixPotentiallyInvalidUTF8Data(message)
2013-05-02 17:53:54 +02:00
try:
fromLabel = shared.config.get(fromAddress, 'label')
except:
fromLabel = ''
if fromLabel == '':
fromLabel = fromAddress
toLabel = ''
t = (toAddress,)
2013-05-02 20:18:24 +02:00
shared.sqlLock.acquire()
shared.sqlSubmitQueue.put(
'''select label from addressbook where address=?''')
2013-05-02 17:53:54 +02:00
shared.sqlSubmitQueue.put(t)
queryreturn = shared.sqlReturnQueue.get()
2013-05-02 20:18:24 +02:00
shared.sqlLock.release()
2013-05-02 17:53:54 +02:00
if queryreturn != []:
2013-05-02 17:53:54 +02:00
for row in queryreturn:
toLabel, = row
self.ui.tableWidgetSent.insertRow(0)
if toLabel == '':
newItem = QtGui.QTableWidgetItem(unicode(toAddress, 'utf-8'))
newItem.setToolTip(unicode(toAddress, 'utf-8'))
2013-05-02 17:53:54 +02:00
else:
newItem = QtGui.QTableWidgetItem(unicode(toLabel, 'utf-8'))
newItem.setToolTip(unicode(toLabel, 'utf-8'))
newItem.setData(Qt.UserRole, str(toAddress))
newItem.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
self.ui.tableWidgetSent.setItem(0, 0, newItem)
2013-05-02 17:53:54 +02:00
if fromLabel == '':
newItem = QtGui.QTableWidgetItem(
unicode(fromAddress, 'utf-8'))
newItem.setToolTip(unicode(fromAddress, 'utf-8'))
2013-05-02 17:53:54 +02:00
else:
newItem = QtGui.QTableWidgetItem(unicode(fromLabel, 'utf-8'))
newItem.setToolTip(unicode(fromLabel, 'utf-8'))
newItem.setData(Qt.UserRole, str(fromAddress))
newItem.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
self.ui.tableWidgetSent.setItem(0, 1, newItem)
newItem = QtGui.QTableWidgetItem(unicode(subject, 'utf-8'))
newItem.setToolTip(unicode(subject, 'utf-8'))
newItem.setData(Qt.UserRole, unicode(message, 'utf-8)'))
newItem.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
self.ui.tableWidgetSent.setItem(0, 2, newItem)
2013-05-29 23:18:44 +02:00
if status == 'awaitingpubkey':
statusText = _translate(
"MainWindow", "Waiting on their encryption key. Will request it again soon.")
2013-05-29 23:18:44 +02:00
elif status == 'doingpowforpubkey':
statusText = _translate(
"MainWindow", "Encryption key request queued.")
2013-05-29 23:18:44 +02:00
elif status == 'msgqueued':
statusText = _translate(
"MainWindow", "Queued.")
2013-05-29 23:18:44 +02:00
elif status == 'msgsent':
statusText = _translate("MainWindow", "Message sent. Waiting on acknowledgement. Sent at %1").arg(
unicode(strftime(shared.config.get('bitmessagesettings', 'timeformat'), localtime(lastactiontime)),'utf-8'))
2013-05-29 23:18:44 +02:00
elif status == 'doingmsgpow':
statusText = _translate(
"MainWindow", "Need to do work to send message. Work is queued.")
2013-05-02 17:53:54 +02:00
elif status == 'ackreceived':
statusText = _translate("MainWindow", "Acknowledgement of the message received %1").arg(
unicode(strftime(shared.config.get('bitmessagesettings', 'timeformat'), localtime(lastactiontime)),'utf-8'))
2013-05-29 23:18:44 +02:00
elif status == 'broadcastqueued':
statusText = _translate(
"MainWindow", "Broadcast queued.")
2013-05-02 17:53:54 +02:00
elif status == 'broadcastsent':
statusText = _translate("MainWindow", "Broadcast on %1").arg(unicode(strftime(
shared.config.get('bitmessagesettings', 'timeformat'), localtime(lastactiontime)),'utf-8'))
elif status == 'toodifficult':
statusText = _translate("MainWindow", "Problem: The work demanded by the recipient is more difficult than you are willing to do. %1").arg(
unicode(strftime(shared.config.get('bitmessagesettings', 'timeformat'), localtime(lastactiontime)),'utf-8'))
2013-06-13 21:15:22 +02:00
elif status == 'badkey':
2013-06-17 23:49:06 +02:00
statusText = _translate("MainWindow", "Problem: The recipient\'s encryption key is no good. Could not encrypt message. %1").arg(
unicode(strftime(shared.config.get('bitmessagesettings', 'timeformat'), localtime(lastactiontime)),'utf-8'))
elif status == 'forcepow':
statusText = _translate(
"MainWindow", "Forced difficulty override. Send should start soon.")
2013-05-02 17:53:54 +02:00
else:
statusText = _translate("MainWindow", "Unknown status: %1 %2").arg(status).arg(unicode(
strftime(shared.config.get('bitmessagesettings', 'timeformat'), localtime(lastactiontime)),'utf-8'))
newItem = myTableWidgetItem(statusText)
newItem.setToolTip(statusText)
newItem.setData(Qt.UserRole, QByteArray(ackdata))
newItem.setData(33, int(lastactiontime))
newItem.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
self.ui.tableWidgetSent.setItem(0, 3, newItem)
self.ui.tableWidgetSent.sortItems(3, Qt.DescendingOrder)
self.ui.tableWidgetSent.keyPressEvent = self.tableWidgetSentKeyPressEvent
2013-05-02 17:53:54 +02:00
# Initialize the address book
2013-05-02 20:18:24 +02:00
shared.sqlLock.acquire()
2013-05-02 17:53:54 +02:00
shared.sqlSubmitQueue.put('SELECT * FROM addressbook')
shared.sqlSubmitQueue.put('')
queryreturn = shared.sqlReturnQueue.get()
2013-05-02 20:18:24 +02:00
shared.sqlLock.release()
2013-05-02 17:53:54 +02:00
for row in queryreturn:
label, address = row
self.ui.tableWidgetAddressBook.insertRow(0)
newItem = QtGui.QTableWidgetItem(unicode(label, 'utf-8'))
self.ui.tableWidgetAddressBook.setItem(0, 0, newItem)
newItem = QtGui.QTableWidgetItem(address)
newItem.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
self.ui.tableWidgetAddressBook.setItem(0, 1, newItem)
# Initialize the Subscriptions
self.rerenderSubscriptions()
2013-05-02 17:53:54 +02:00
# Initialize the Blacklist or Whitelist
2013-05-02 17:53:54 +02:00
if shared.config.get('bitmessagesettings', 'blackwhitelist') == 'black':
self.loadBlackWhiteList()
else:
self.ui.tabWidget.setTabText(6, 'Whitelist')
2013-05-02 17:53:54 +02:00
self.ui.radioButtonWhitelist.click()
self.loadBlackWhiteList()
QtCore.QObject.connect(self.ui.tableWidgetYourIdentities, QtCore.SIGNAL(
"itemChanged(QTableWidgetItem *)"), self.tableWidgetYourIdentitiesItemChanged)
QtCore.QObject.connect(self.ui.tableWidgetAddressBook, QtCore.SIGNAL(
"itemChanged(QTableWidgetItem *)"), self.tableWidgetAddressBookItemChanged)
QtCore.QObject.connect(self.ui.tableWidgetSubscriptions, QtCore.SIGNAL(
"itemChanged(QTableWidgetItem *)"), self.tableWidgetSubscriptionsItemChanged)
QtCore.QObject.connect(self.ui.tableWidgetInbox, QtCore.SIGNAL(
"itemSelectionChanged ()"), self.tableWidgetInboxItemClicked)
QtCore.QObject.connect(self.ui.tableWidgetSent, QtCore.SIGNAL(
"itemSelectionChanged ()"), self.tableWidgetSentItemClicked)
# Put the colored icon on the status bar
# self.ui.pushButtonStatusIcon.setIcon(QIcon(":/newPrefix/images/yellowicon.png"))
2013-05-02 17:53:54 +02:00
self.statusbar = self.statusBar()
self.statusbar.insertPermanentWidget(0, self.ui.pushButtonStatusIcon)
self.ui.labelStartupTime.setText(_translate("MainWindow", "Since startup on %1").arg(
unicode(strftime(shared.config.get('bitmessagesettings', 'timeformat'), localtime(int(time.time()))),'utf-8')))
2013-05-02 17:53:54 +02:00
self.numberOfMessagesProcessed = 0
self.numberOfBroadcastsProcessed = 0
self.numberOfPubkeysProcessed = 0
self.UISignalThread = UISignaler()
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"writeNewAddressToTable(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"), self.writeNewAddressToTable)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"updateStatusBar(PyQt_PyObject)"), self.updateStatusBar)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"updateSentItemStatusByHash(PyQt_PyObject,PyQt_PyObject)"), self.updateSentItemStatusByHash)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"updateSentItemStatusByAckdata(PyQt_PyObject,PyQt_PyObject)"), self.updateSentItemStatusByAckdata)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"displayNewInboxMessage(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"), self.displayNewInboxMessage)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"displayNewSentMessage(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"), self.displayNewSentMessage)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"updateNetworkStatusTab()"), self.updateNetworkStatusTab)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"incrementNumberOfMessagesProcessed()"), self.incrementNumberOfMessagesProcessed)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"incrementNumberOfPubkeysProcessed()"), self.incrementNumberOfPubkeysProcessed)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"incrementNumberOfBroadcastsProcessed()"), self.incrementNumberOfBroadcastsProcessed)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"setStatusIcon(PyQt_PyObject)"), self.setStatusIcon)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"rerenderInboxFromLabels()"), self.rerenderInboxFromLabels)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"rerenderSubscriptions()"), self.rerenderSubscriptions)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"removeInboxRowByMsgid(PyQt_PyObject)"), self.removeInboxRowByMsgid)
2013-05-02 17:53:54 +02:00
self.UISignalThread.start()
# Below this point, it would be good if all of the necessary global data
# structures were initialized.
2013-05-02 17:53:54 +02:00
self.rerenderComboBoxSendFrom()
2013-05-02 17:53:54 +02:00
# Show or hide the application window after clicking an item within the
# tray icon or, on Windows, the try icon itself.
def appIndicatorShowOrHideWindow(self):
if not self.actionShow.isChecked():
self.hide()
else:
if sys.platform[0:3] == 'win':
self.setWindowFlags(Qt.Window)
# else:
# self.showMaximized()
self.show()
self.setWindowState(
self.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive)
2013-05-15 18:36:30 +02:00
self.activateWindow()
# pointer to the application
# app = None
# The most recent message
newMessageItem = None
# The most recent broadcast
newBroadcastItem = None
# show the application window
def appIndicatorShow(self):
if self.actionShow is None:
return
2013-05-14 17:44:51 +02:00
if not self.actionShow.isChecked():
self.actionShow.setChecked(True)
self.appIndicatorShowOrHideWindow()
# unchecks the show item on the application indicator
def appIndicatorHide(self):
if self.actionShow is None:
return
2013-05-14 17:44:51 +02:00
if self.actionShow.isChecked():
self.actionShow.setChecked(False)
self.appIndicatorShowOrHideWindow()
# application indicator show or hide
"""# application indicator show or hide
def appIndicatorShowBitmessage(self):
#if self.actionShow == None:
# return
print self.actionShow.isChecked()
if not self.actionShow.isChecked():
self.hide()
#self.setWindowState(self.windowState() & QtCore.Qt.WindowMinimized)
else:
self.appIndicatorShowOrHideWindow()"""
# Show the program window and select inbox tab
2013-05-11 19:30:49 +02:00
def appIndicatorInbox(self, mm_app, source_id):
self.appIndicatorShow()
# select inbox