PyBitmessage/src/bitmessageqt/__init__.py

3874 lines
200 KiB
Python
Raw Normal View History

2013-06-12 08:05:20 +00:00
try:
import locale
except:
pass
withMessagingMenu = False
try:
from gi.repository import MessagingMenu
from gi.repository import Notify
withMessagingMenu = True
except ImportError:
MessagingMenu = None
2013-05-02 15:53:54 +00:00
from addresses import *
import shared
from bitmessageui import *
from namecoin import namecoinConnection, ensureNamecoinOptions
2013-05-02 15:53:54 +00:00
from newaddressdialog import *
from addaddressdialog import *
2013-05-02 15:53:54 +00:00
from newsubscriptiondialog import *
from regenerateaddresses import *
2013-07-22 05:10:22 +00:00
from newchandialog import *
2013-05-02 15:53:54 +00:00
from specialaddressbehavior import *
from settings import *
from about import *
from help import *
from iconglossary import *
from connect import *
2013-05-02 15:53:54 +00:00
import sys
from time import strftime, localtime, gmtime
import time
import os
2013-11-01 23:25:24 +00:00
import hashlib
2013-05-02 15:53:54 +00:00
from pyelliptic.openssl import OpenSSL
import pickle
2013-05-14 15:44:51 +00:00
import platform
import textwrap
2013-07-15 19:45:03 +00:00
import debug
from debug import logger
2013-07-15 16:58:22 +00:00
import subprocess
import datetime
2013-08-27 00:01:19 +00:00
from helper_sql import *
2013-05-02 15:53:54 +00:00
2013-06-25 20:26:12 +00:00
try:
from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
2013-06-25 20:26:12 +00:00
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).'
print 'Error message:', err
sys.exit()
try:
_encoding = QtGui.QApplication.UnicodeUTF8
except AttributeError:
print 'QtGui.QApplication.UnicodeUTF8 error:', err
def _translate(context, text):
return QtGui.QApplication.translate(context, text)
def identiconize(address):
2013-09-18 15:39:45 +00:00
size = 48
2013-09-18 15:39:45 +00:00
# If you include another identicon library, please generate an
# example identicon with the following md5 hash:
# 3fd4bf901b9d4ea1394f0fb358725b28
2013-09-17 08:55:26 +00:00
try:
2013-11-01 23:25:24 +00:00
identicon_lib = shared.config.get('bitmessagesettings', 'identiconlib')
2013-09-17 08:55:26 +00:00
except:
2013-11-01 23:25:24 +00:00
# default to qidenticon_two_x
identicon_lib = 'qidenticon_two_x'
# As an 'identiconsuffix' you could put "@bitmessge.ch" or "@bm.addr" to make it compatible with other identicon generators. (Note however, that E-Mail programs might convert the BM-address to lowercase first.)
# It can be used as a pseudo-password to salt the generation of the identicons to decrease the risk
# of attacks where someone creates an address to mimic someone else's identicon.
identiconsuffix = shared.config.get('bitmessagesettings', 'identiconsuffix')
2013-09-17 08:55:26 +00:00
2013-11-01 23:25:24 +00:00
if not shared.config.getboolean('bitmessagesettings', 'useidenticons'):
idcon = QtGui.QIcon()
return idcon
2013-09-19 19:28:22 +00:00
2013-09-17 08:55:26 +00:00
if (identicon_lib[:len('qidenticon')] == 'qidenticon'):
# print identicon_lib
# originally by:
# :Author:Shin Adachi <shn@glucose.jp>
# Licesensed under FreeBSD License.
2013-09-19 19:28:22 +00:00
# stripped from PIL and uses QT instead (by sendiulo, same license)
import qidenticon
2013-09-17 08:55:26 +00:00
hash = hashlib.md5(addBMIfNotPresent(address)+identiconsuffix).hexdigest()
use_two_colors = (identicon_lib[:len('qidenticon_two')] == 'qidenticon_two')
2013-09-18 15:39:45 +00:00
opacity = int(not((identicon_lib == 'qidenticon_x') | (identicon_lib == 'qidenticon_two_x') | (identicon_lib == 'qidenticon_b') | (identicon_lib == 'qidenticon_two_b')))*255
2013-09-17 08:55:26 +00:00
penwidth = 0
2013-09-18 15:39:45 +00:00
image = qidenticon.render_identicon(int(hash, 16), size, use_two_colors, opacity, penwidth)
# filename = './images/identicons/'+hash+'.png'
# image.save(filename)
idcon = QtGui.QIcon()
2013-09-18 15:39:45 +00:00
idcon.addPixmap(image, QtGui.QIcon.Normal, QtGui.QIcon.Off)
return idcon
2013-09-17 08:55:26 +00:00
elif identicon_lib == 'pydenticon':
# print identicon_lib
2013-09-17 08:55:26 +00:00
# Here you could load pydenticon.py (just put it in the "src" folder of your Bitmessage source)
from pydenticon import Pydenticon
2013-09-17 08:55:26 +00:00
# It is not included in the source, because it is licensed under GPLv3
# GPLv3 is a copyleft license that would influence our licensing
# Find the source here: http://boottunes.googlecode.com/svn-history/r302/trunk/src/pydenticon.py
# note that it requires PIL to be installed: http://www.pythonware.com/products/pil/
2013-09-18 15:39:45 +00:00
idcon_render = Pydenticon(addBMIfNotPresent(address)+identiconsuffix, size*3)
2013-09-17 08:55:26 +00:00
rendering = idcon_render._render()
data = rendering.convert("RGBA").tostring("raw", "RGBA")
qim = QImage(data, size, size, QImage.Format_ARGB32)
pix = QPixmap.fromImage(qim)
idcon = QtGui.QIcon()
idcon.addPixmap(pix, QtGui.QIcon.Normal, QtGui.QIcon.Off)
return idcon
2013-09-19 19:28:22 +00:00
2013-11-01 23:25:24 +00:00
def avatarize(address):
"""
loads a supported image for the given address' hash form 'avatars' folder
falls back to default avatar if 'default.*' file exists
2013-11-01 23:25:24 +00:00
falls back to identiconize(address)
"""
2013-09-19 19:28:22 +00:00
idcon = QtGui.QIcon()
2013-11-01 23:25:24 +00:00
hash = hashlib.md5(addBMIfNotPresent(address)).hexdigest()
str_broadcast_subscribers = '[Broadcast subscribers]'
if address == str_broadcast_subscribers:
# don't hash [Broadcast subscribers]
hash = address
# http://pyqt.sourceforge.net/Docs/PyQt4/qimagereader.html#supportedImageFormats
# print QImageReader.supportedImageFormats ()
# QImageReader.supportedImageFormats ()
extensions = ['PNG', 'GIF', 'JPG', 'JPEG', 'SVG', 'BMP', 'MNG', 'PBM', 'PGM', 'PPM', 'TIFF', 'XBM', 'XPM', 'TGA']
# try to find a specific avatar
for ext in extensions:
lower_hash = shared.appdata + 'avatars/' + hash + '.' + ext.lower()
upper_hash = shared.appdata + 'avatars/' + hash + '.' + ext.upper()
if os.path.isfile(lower_hash):
# print 'found avatar of ', address
idcon.addFile(lower_hash)
return idcon
elif os.path.isfile(upper_hash):
# print 'found avatar of ', address
idcon.addFile(upper_hash)
return idcon
# if we haven't found any, try to find a default avatar
for ext in extensions:
lower_default = shared.appdata + 'avatars/' + 'default.' + ext.lower()
upper_default = shared.appdata + 'avatars/' + 'default.' + ext.upper()
if os.path.isfile(lower_default):
default = lower_default
idcon.addFile(lower_default)
return idcon
elif os.path.isfile(upper_default):
default = upper_default
idcon.addFile(upper_default)
return idcon
# If no avatar is found
return identiconize(address)
2013-05-02 15:53:54 +00:00
class MyForm(QtGui.QMainWindow):
# sound type constants
SOUND_NONE = 0
SOUND_KNOWN = 1
SOUND_UNKNOWN = 2
SOUND_CONNECTED = 3
SOUND_DISCONNECTED = 4
SOUND_CONNECTION_GREEN = 5
# the last time that a message arrival sound was played
lastSoundTime = datetime.datetime.now() - datetime.timedelta(days=1)
# the maximum frequency of message sounds in seconds
maxSoundFrequencySec = 60
str_broadcast_subscribers = '[Broadcast subscribers]'
2013-07-22 05:10:22 +00:00
str_chan = '[chan]'
def init_file_menu(self):
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)
2013-07-22 05:10:22 +00:00
QtCore.QObject.connect(self.ui.actionJoinChan, QtCore.SIGNAL(
"triggered()"),
self.click_actionJoinChan) # also used for creating chans.
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.pushButtonFetchNamecoinID, QtCore.SIGNAL(
"clicked()"), self.click_pushButtonFetchNamecoinID)
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)
def init_inbox_popup_menu(self):
# Popup menu for the Inbox tab
2013-05-02 15:53:54 +00: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.actionMarkUnread = self.ui.inboxContextMenuToolbar.addAction(
_translate(
"MainWindow", "Mark Unread"), self.on_action_InboxMarkUnread)
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-07-26 02:00:54 +00:00
self.popMenuInbox.addAction(self.actionMarkUnread)
2013-05-02 15:53:54 +00:00
self.popMenuInbox.addSeparator()
self.popMenuInbox.addAction(self.actionReply)
self.popMenuInbox.addAction(self.actionAddSenderToAddressBook)
2013-05-02 15:53:54 +00:00
self.popMenuInbox.addSeparator()
self.popMenuInbox.addAction(self.actionSaveMessageAs)
self.popMenuInbox.addAction(self.actionTrashInboxMessage)
2013-05-02 15:53:54 +00:00
def init_identities_popup_menu(self):
# Popup menu for the Your Identities tab
2013-05-02 15:53:54 +00: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.actionSetAvatar = self.ui.addressContextMenuToolbar.addAction(
_translate(
"MainWindow", "Set avatar..."),
self.on_action_YourIdentitiesSetAvatar)
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 15:53:54 +00:00
self.popMenu.addSeparator()
self.popMenu.addAction(self.actionClipboard)
2013-05-02 15:53:54 +00:00
self.popMenu.addSeparator()
self.popMenu.addAction(self.actionEnable)
self.popMenu.addAction(self.actionDisable)
2013-09-20 12:30:53 +00:00
self.popMenu.addAction(self.actionSetAvatar)
self.popMenu.addAction(self.actionSpecialAddressBehavior)
2013-05-02 15:53:54 +00:00
def init_addressbook_popup_menu(self):
# Popup menu for the Address Book page
2013-05-02 15:53:54 +00: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)
self.actionAddressBookSubscribe = self.ui.addressBookContextMenuToolbar.addAction(
_translate(
"MainWindow", "Subscribe to this address"),
self.on_action_AddressBookSubscribe)
self.actionAddressBookSetAvatar = self.ui.addressBookContextMenuToolbar.addAction(
_translate(
"MainWindow", "Set avatar..."),
self.on_action_AddressBookSetAvatar)
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)
self.popMenuAddressBook.addAction(self.actionAddressBookSetAvatar)
2013-05-02 15:53:54 +00:00
self.popMenuAddressBook.addSeparator()
self.popMenuAddressBook.addAction(self.actionAddressBookNew)
self.popMenuAddressBook.addAction(self.actionAddressBookDelete)
2013-05-02 15:53:54 +00:00
def init_subscriptions_popup_menu(self):
# Popup menu for the Subscriptions page
2013-05-02 15:53:54 +00: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.actionsubscriptionsSetAvatar = self.ui.subscriptionsContextMenuToolbar.addAction(
_translate("MainWindow", "Set avatar..."),
self.on_action_SubscriptionsSetAvatar)
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 15:53:54 +00:00
self.popMenuSubscriptions.addSeparator()
self.popMenuSubscriptions.addAction(self.actionsubscriptionsEnable)
self.popMenuSubscriptions.addAction(self.actionsubscriptionsDisable)
self.popMenuSubscriptions.addAction(self.actionsubscriptionsSetAvatar)
2013-05-02 15:53:54 +00:00
self.popMenuSubscriptions.addSeparator()
self.popMenuSubscriptions.addAction(self.actionsubscriptionsClipboard)
2013-05-02 15:53:54 +00:00
def init_sent_popup_menu(self):
# Popup menu for the Sent page
2013-05-02 15:53:54 +00: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 )
def init_blacklist_popup_menu(self):
# Popup menu for the Blacklist page
2013-05-02 15:53:54 +00: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.actionBlacklistSetAvatar = self.ui.blacklistContextMenuToolbar.addAction(
_translate(
"MainWindow", "Set avatar..."),
self.on_action_BlacklistSetAvatar)
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 15:53:54 +00:00
self.popMenuBlacklist.addSeparator()
self.popMenuBlacklist.addAction(self.actionBlacklistClipboard)
2013-05-02 15:53:54 +00:00
self.popMenuBlacklist.addSeparator()
self.popMenuBlacklist.addAction(self.actionBlacklistEnable)
self.popMenuBlacklist.addAction(self.actionBlacklistDisable)
self.popMenuBlacklist.addAction(self.actionBlacklistSetAvatar)
2013-05-02 15:53:54 +00: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.
configSections = shared.config.sections()
for addressInKeysFile in configSections:
if addressInKeysFile != 'bitmessagesettings':
status, addressVersionNumber, streamNumber, hash = decodeAddress(
addressInKeysFile)
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)
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
if 'win32' in sys.platform or 'win64' in sys.platform:
# Auto-startup for Windows
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.
if shared.config.getboolean('bitmessagesettings', 'startonlogon'):
self.settings.setValue("PyBitmessage", sys.argv[0])
elif 'darwin' in sys.platform:
# startup for mac
pass
elif 'linux' in sys.platform:
# startup for linux
pass
self.totalNumberOfBytesReceived = 0
self.totalNumberOfBytesSent = 0
self.ui.labelSendBroadcastWarning.setVisible(False)
self.timer = QtCore.QTimer()
self.timer.start(2000) # milliseconds
QtCore.QObject.connect(self.timer, QtCore.SIGNAL("timeout()"), self.runEveryTwoSeconds)
self.init_file_menu()
self.init_inbox_popup_menu()
self.init_identities_popup_menu()
self.init_addressbook_popup_menu()
self.init_subscriptions_popup_menu()
self.init_sent_popup_menu()
self.init_blacklist_popup_menu()
# Initialize the user's list of addresses on the 'Your Identities' tab.
2013-05-02 15:53:54 +00: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 15:53:54 +00:00
if not isEnabled:
newItem.setTextColor(QtGui.QColor(128, 128, 128))
2013-05-02 15:53:54 +00:00
self.ui.tableWidgetYourIdentities.insertRow(0)
2013-09-19 19:28:22 +00:00
newItem.setIcon(avatarize(addressInKeysFile))
2013-05-02 15:53:54 +00:00
self.ui.tableWidgetYourIdentities.setItem(0, 0, newItem)
newItem = QtGui.QTableWidgetItem(addressInKeysFile)
newItem.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
2013-07-22 05:10:22 +00:00
if shared.safeConfigGetBoolean(addressInKeysFile, 'chan'):
newItem.setTextColor(QtGui.QColor(216, 119, 0)) # orange
2013-05-02 15:53:54 +00: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 15:53:54 +00:00
self.ui.tableWidgetYourIdentities.setItem(0, 1, newItem)
newItem = QtGui.QTableWidgetItem(str(
decodeAddress(addressInKeysFile)[2]))
newItem.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
2013-05-02 15:53:54 +00:00
if not isEnabled:
newItem.setTextColor(QtGui.QColor(128, 128, 128))
2013-05-02 15:53:54 +00:00
self.ui.tableWidgetYourIdentities.setItem(0, 2, newItem)
if isEnabled:
status, addressVersionNumber, streamNumber, hash = decodeAddress(
addressInKeysFile)
2013-05-02 15:53:54 +00:00
# Load inbox from messages database file
2013-07-12 08:24:24 +00:00
self.loadInbox()
# Load Sent items from database
2013-07-12 08:24:24 +00:00
self.loadSent()
2013-05-02 15:53:54 +00:00
# Initialize the address book
self.rerenderAddressBook()
# Initialize the Subscriptions
self.rerenderSubscriptions()
2013-05-02 15:53:54 +00:00
2013-07-12 08:24:24 +00:00
# Initialize the inbox search
QtCore.QObject.connect(self.ui.inboxSearchLineEdit, QtCore.SIGNAL(
"returnPressed()"), self.inboxSearchLineEditPressed)
2013-07-12 08:42:52 +00:00
# Initialize the sent search
QtCore.QObject.connect(self.ui.sentSearchLineEdit, QtCore.SIGNAL(
"returnPressed()"), self.sentSearchLineEditPressed)
# Initialize the Blacklist or Whitelist
2013-05-02 15:53:54 +00:00
if shared.config.get('bitmessagesettings', 'blackwhitelist') == 'black':
self.loadBlackWhiteList()
else:
self.ui.tabWidget.setTabText(6, 'Whitelist')
2013-05-02 15:53:54 +00: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 15:53:54 +00: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 15:53:54 +00:00
self.numberOfMessagesProcessed = 0
self.numberOfBroadcastsProcessed = 0
self.numberOfPubkeysProcessed = 0
# Set the icon sizes for the identicons
identicon_size = 3*7
self.ui.tableWidgetInbox.setIconSize(QtCore.QSize(identicon_size, identicon_size))
self.ui.tableWidgetSent.setIconSize(QtCore.QSize(identicon_size, identicon_size))
self.ui.tableWidgetYourIdentities.setIconSize(QtCore.QSize(identicon_size, identicon_size))
self.ui.tableWidgetSubscriptions.setIconSize(QtCore.QSize(identicon_size, identicon_size))
self.ui.tableWidgetAddressBook.setIconSize(QtCore.QSize(identicon_size, identicon_size))
self.ui.tableWidgetBlacklist.setIconSize(QtCore.QSize(identicon_size, identicon_size))
2013-05-02 15:53:54 +00:00
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(
"updateNumberOfMessagesProcessed()"), self.updateNumberOfMessagesProcessed)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"updateNumberOfPubkeysProcessed()"), self.updateNumberOfPubkeysProcessed)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"updateNumberOfBroadcastsProcessed()"), self.updateNumberOfBroadcastsProcessed)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"setStatusIcon(PyQt_PyObject)"), self.setStatusIcon)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"changedInboxUnread(PyQt_PyObject)"), self.changedInboxUnread)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"rerenderInboxFromLabels()"), self.rerenderInboxFromLabels)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"rerenderSentToLabels()"), self.rerenderSentToLabels)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"rerenderAddressBook()"), self.rerenderAddressBook)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"rerenderSubscriptions()"), self.rerenderSubscriptions)
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"removeInboxRowByMsgid(PyQt_PyObject)"), self.removeInboxRowByMsgid)
2013-09-05 00:14:25 +00:00
QtCore.QObject.connect(self.UISignalThread, QtCore.SIGNAL(
"displayAlert(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"), self.displayAlert)
2013-05-02 15:53:54 +00:00
self.UISignalThread.start()
# Below this point, it would be good if all of the necessary global data
# structures were initialized.
2013-05-02 15:53:54 +00:00
self.rerenderComboBoxSendFrom()
# Check to see whether we can connect to namecoin. Hide the 'Fetch Namecoin ID' button if we can't.
2013-08-14 23:46:59 +00:00
try:
options = {}
options["type"] = shared.config.get('bitmessagesettings', 'namecoinrpctype')
options["host"] = shared.config.get('bitmessagesettings', 'namecoinrpchost')
options["port"] = shared.config.get('bitmessagesettings', 'namecoinrpcport')
options["user"] = shared.config.get('bitmessagesettings', 'namecoinrpcuser')
options["password"] = shared.config.get('bitmessagesettings', 'namecoinrpcpassword')
nc = namecoinConnection(options)
if nc.test()[0] == 'failed':
self.ui.pushButtonFetchNamecoinID.hide()
except:
print 'There was a problem testing for a Namecoin daemon. Hiding the Fetch Namecoin ID button'
self.ui.pushButtonFetchNamecoinID.hide()
2013-05-02 15:53:54 +00: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 16:36:30 +00: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 15:44:51 +00: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 15:44:51 +00: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 17:30:49 +00:00
def appIndicatorInbox(self, mm_app, source_id):
self.appIndicatorShow()