fix conflicts after merging

This commit is contained in:
surbhicis 2020-06-10 15:46:16 +05:30
commit 487eab6f78
Signed by untrusted user: surbhicis
GPG Key ID: 48A8C2D218DE7B0B
67 changed files with 2306 additions and 916 deletions

View File

@ -124,9 +124,9 @@ function install_pyopencl()
else else
wine python -m pip install pyopencl-2015.1-cp27-none-win32.whl wine python -m pip install pyopencl-2015.1-cp27-none-win32.whl
fi fi
sed -Ei 's/_DEFAULT_INCLUDE_OPTIONS = .*/_DEFAULT_INCLUDE_OPTIONS = [] /' $WINEPREFIX/drive_c/Python27/Lib/site-packages/pyopencl/__init__.py
} }
function build_dll(){ function build_dll(){
cd ${BASE_DIR} cd ${BASE_DIR}
cd src/bitmsghash cd src/bitmsghash

View File

@ -276,69 +276,3 @@ def addBMIfNotPresent(address):
"""Prepend BM- to an address if it doesn't already have it""" """Prepend BM- to an address if it doesn't already have it"""
address = str(address).strip() address = str(address).strip()
return address if address[:3] == 'BM-' else 'BM-' + address return address if address[:3] == 'BM-' else 'BM-' + address
# TODO: make test case
if __name__ == "__main__":
from pyelliptic import arithmetic
print(
'\nLet us make an address from scratch. Suppose we generate two'
' random 32 byte values and call the first one the signing key'
' and the second one the encryption key:'
)
privateSigningKey = \
'93d0b61371a54b53df143b954035d612f8efa8a3ed1cf842c2186bfd8f876665'
privateEncryptionKey = \
'4b0b73a54e19b059dc274ab69df095fe699f43b17397bca26fdf40f4d7400a3a'
print(
'\nprivateSigningKey = %s\nprivateEncryptionKey = %s' %
(privateSigningKey, privateEncryptionKey)
)
print(
'\nNow let us convert them to public keys by doing'
' an elliptic curve point multiplication.'
)
publicSigningKey = arithmetic.privtopub(privateSigningKey)
publicEncryptionKey = arithmetic.privtopub(privateEncryptionKey)
print(
'\npublicSigningKey = %s\npublicEncryptionKey = %s' %
(publicSigningKey, publicEncryptionKey)
)
print(
'\nNotice that they both begin with the \\x04 which specifies'
' the encoding type. This prefix is not send over the wire.'
' You must strip if off before you send your public key across'
' the wire, and you must add it back when you receive a public key.'
)
publicSigningKeyBinary = \
arithmetic.changebase(publicSigningKey, 16, 256, minlen=64)
publicEncryptionKeyBinary = \
arithmetic.changebase(publicEncryptionKey, 16, 256, minlen=64)
ripe = hashlib.new('ripemd160')
sha = hashlib.new('sha512')
sha.update(publicSigningKeyBinary + publicEncryptionKeyBinary)
ripe.update(sha.digest())
addressVersionNumber = 2
streamNumber = 1
print(
'\nRipe digest that we will encode in the address: %s' %
hexlify(ripe.digest())
)
returnedAddress = \
encodeAddress(addressVersionNumber, streamNumber, ripe.digest())
print('Encoded address: %s' % returnedAddress)
status, addressVersionNumber, streamNumber, data = \
decodeAddress(returnedAddress)
print(
'\nAfter decoding address:\n\tStatus: %s'
'\n\taddressVersionNumber %s'
'\n\tstreamNumber %s'
'\n\tlength of data (the ripe hash): %s'
'\n\tripe data: %s' %
(status, addressVersionNumber, streamNumber, len(data), hexlify(data))
)

View File

@ -27,6 +27,7 @@ import queues
import shared import shared
import shutdown import shutdown
import state import state
import threads
from addresses import ( from addresses import (
addBMIfNotPresent, addBMIfNotPresent,
calculateInventoryHash, calculateInventoryHash,
@ -1209,7 +1210,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
len(encryptedPayload) + requiredPayloadLengthExtraBytes + 8 len(encryptedPayload) + requiredPayloadLengthExtraBytes + 8
) * requiredAverageProofOfWorkNonceTrialsPerByte ) * requiredAverageProofOfWorkNonceTrialsPerByte
) )
with shared.printLock: with threads.printLock:
print( print(
'(For msg message via API) Doing proof of work.' '(For msg message via API) Doing proof of work.'
'Total required difficulty:', 'Total required difficulty:',
@ -1224,8 +1225,8 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
powStartTime = time.time() powStartTime = time.time()
initialHash = hashlib.sha512(encryptedPayload).digest() initialHash = hashlib.sha512(encryptedPayload).digest()
trialValue, nonce = proofofwork.run(target, initialHash) trialValue, nonce = proofofwork.run(target, initialHash)
with shared.printLock: with threads.printLock:
print('(For msg message via API) Found proof of work', trialValue, 'Nonce:', nonce) print '(For msg message via API) Found proof of work', trialValue, 'Nonce:', nonce
try: try:
print( print(
'POW took', int(time.time() - powStartTime), 'POW took', int(time.time() - powStartTime),
@ -1243,8 +1244,8 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
objectType, toStreamNumber, encryptedPayload, objectType, toStreamNumber, encryptedPayload,
int(time.time()) + TTL, '' int(time.time()) + TTL, ''
) )
with shared.printLock: with threads.printLock:
print('Broadcasting inv for msg(API disseminatePreEncryptedMsg command):', hexlify(inventoryHash)) print 'Broadcasting inv for msg(API disseminatePreEncryptedMsg command):', hexlify(inventoryHash)
queues.invQueue.put((toStreamNumber, inventoryHash)) queues.invQueue.put((toStreamNumber, inventoryHash))
def HandleTrashSentMessageByAckDAta(self, params): def HandleTrashSentMessageByAckDAta(self, params):
@ -1297,8 +1298,8 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
Inventory()[inventoryHash] = ( Inventory()[inventoryHash] = (
objectType, pubkeyStreamNumber, payload, int(time.time()) + TTL, '' objectType, pubkeyStreamNumber, payload, int(time.time()) + TTL, ''
) )
with shared.printLock: with threads.printLock:
print('broadcasting inv within API command disseminatePubkey with hash:', hexlify(inventoryHash)) print 'broadcasting inv within API command disseminatePubkey with hash:', hexlify(inventoryHash)
queues.invQueue.put((pubkeyStreamNumber, inventoryHash)) queues.invQueue.put((pubkeyStreamNumber, inventoryHash))
def HandleGetMessageDataByDestinationHash(self, params): def HandleGetMessageDataByDestinationHash(self, params):
@ -1350,15 +1351,15 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
connections_num = len(network.stats.connectedHostsList()) connections_num = len(network.stats.connectedHostsList())
if connections_num == 0: if connections_num == 0:
networkStatus = 'notConnected' networkStatus = 'notConnected'
elif shared.clientHasReceivedIncomingConnections: elif state.clientHasReceivedIncomingConnections:
networkStatus = 'connectedAndReceivingIncomingConnections' networkStatus = 'connectedAndReceivingIncomingConnections'
else: else:
networkStatus = 'connectedButHaveNotReceivedIncomingConnections' networkStatus = 'connectedButHaveNotReceivedIncomingConnections'
return json.dumps({ return json.dumps({
'networkConnections': connections_num, 'networkConnections': connections_num,
'numberOfMessagesProcessed': shared.numberOfMessagesProcessed, 'numberOfMessagesProcessed': state.numberOfMessagesProcessed,
'numberOfBroadcastsProcessed': shared.numberOfBroadcastsProcessed, 'numberOfBroadcastsProcessed': state.numberOfBroadcastsProcessed,
'numberOfPubkeysProcessed': shared.numberOfPubkeysProcessed, 'numberOfPubkeysProcessed': state.numberOfPubkeysProcessed,
'networkStatus': networkStatus, 'networkStatus': networkStatus,
'softwareName': 'PyBitmessage', 'softwareName': 'PyBitmessage',
'softwareVersion': softwareVersion 'softwareVersion': softwareVersion

View File

@ -24,6 +24,7 @@ import network.stats
import queues import queues
import shared import shared
import shutdown import shutdown
import state
from addresses import addBMIfNotPresent, decodeAddress from addresses import addBMIfNotPresent, decodeAddress
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
@ -274,11 +275,11 @@ def drawtab(stdscr):
# Uptime and processing data # Uptime and processing data
stdscr.addstr(6, 35, "Since startup on " + l10n.formatTimestamp(startuptime, False)) stdscr.addstr(6, 35, "Since startup on " + l10n.formatTimestamp(startuptime, False))
stdscr.addstr(7, 40, "Processed " + str( stdscr.addstr(7, 40, "Processed " + str(
shared.numberOfMessagesProcessed).ljust(4) + " person-to-person messages.") state.numberOfMessagesProcessed).ljust(4) + " person-to-person messages.")
stdscr.addstr(8, 40, "Processed " + str( stdscr.addstr(8, 40, "Processed " + str(
shared.numberOfBroadcastsProcessed).ljust(4) + " broadcast messages.") state.numberOfBroadcastsProcessed).ljust(4) + " broadcast messages.")
stdscr.addstr(9, 40, "Processed " + str( stdscr.addstr(9, 40, "Processed " + str(
shared.numberOfPubkeysProcessed).ljust(4) + " public keys.") state.numberOfPubkeysProcessed).ljust(4) + " public keys.")
# Inventory data # Inventory data
stdscr.addstr(11, 35, "Inventory lookups per second: " + str(inventorydata).ljust(3)) stdscr.addstr(11, 35, "Inventory lookups per second: " + str(inventorydata).ljust(3))

View File

@ -0,0 +1,37 @@
#:import ZBarSymbol pyzbar.pyzbar.ZBarSymbol
BoxLayout:
orientation: 'vertical'
ZBarCam:
id: zbarcam
# optional, by default checks all types
code_types: ZBarSymbol.QRCODE, ZBarSymbol.EAN13
scan_callback: app._after_scan
scanner_line_y_initial: self.size[1]/2 +self.qrwidth/2
scanner_line_y_final: self.size[1]/2-self.qrwidth/2
canvas:
Color:
rgba: 0,0,0,.25
#left rect
Rectangle:
pos: self.pos[0], self.pos[1]
size: self.size[0]/2-self.qrwidth/2, self.size[1]
#right rect
Rectangle:
pos: self.size[0]/2+self.qrwidth/2, 0
size: self.size[0]/2-self.qrwidth/2, self.size[1]
#top rect
Rectangle:
pos: self.size[0]/2-self.qrwidth/2, self.size[1]/2+self.qrwidth/2
size: self.qrwidth, self.size[1]/2-self.qrwidth/2
#bottom rect
Rectangle:
pos: self.size[0]/2-self.qrwidth/2, 0
size: self.qrwidth, self.size[1]/2-self.qrwidth/2

View File

@ -948,16 +948,15 @@ class NetworkStat(Screen):
def init_ui(self, dt=0): def init_ui(self, dt=0):
"""Clock Schdule for method networkstat screen""" """Clock Schdule for method networkstat screen"""
import network.stats import network.stats
import shared
from network import objectracker from network import objectracker
self.text_variable_1 = '{0} :: {1}'.format( self.text_variable_1 = '{0} :: {1}'.format(
'Total Connections', str(len(network.stats.connectedHostsList()))) 'Total Connections', str(len(network.stats.connectedHostsList())))
self.text_variable_2 = 'Processed {0} per-to-per messages'.format( self.text_variable_2 = 'Processed {0} per-to-per messages'.format(
str(shared.numberOfMessagesProcessed)) str(state.numberOfMessagesProcessed))
self.text_variable_3 = 'Processed {0} brodcast messages'.format( self.text_variable_3 = 'Processed {0} brodcast messages'.format(
str(shared.numberOfBroadcastsProcessed)) str(state.numberOfBroadcastsProcessed))
self.text_variable_4 = 'Processed {0} public keys'.format( self.text_variable_4 = 'Processed {0} public keys'.format(
str(shared.numberOfPubkeysProcessed)) str(state.numberOfPubkeysProcessed))
self.text_variable_5 = '{0} object to be synced'.format( self.text_variable_5 = '{0} object to be synced'.format(
len(objectracker.missingObjects)) len(objectracker.missingObjects))

View File

@ -32,9 +32,7 @@ from bmconfigparser import BMConfigParser
# this should go before any threads # this should go before any threads
from debug import logger from debug import logger
from helper_startup import ( from helper_startup import (
isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections, adjustHalfOpenConnectionsLimit, start_proxyconfig)
start_proxyconfig
)
from inventory import Inventory from inventory import Inventory
from knownnodes import readKnownNodes from knownnodes import readKnownNodes
# Network objects and threads # Network objects and threads
@ -45,9 +43,8 @@ from network import (
from singleinstance import singleinstance from singleinstance import singleinstance
# Synchronous threads # Synchronous threads
from threads import ( from threads import (
set_thread_name, addressGenerator, objectProcessor, singleCleaner, set_thread_name, printLock,
singleWorker, sqlThread addressGenerator, objectProcessor, singleCleaner, singleWorker, sqlThread)
)
app_dir = os.path.dirname(os.path.abspath(__file__)) app_dir = os.path.dirname(os.path.abspath(__file__))
os.chdir(app_dir) os.chdir(app_dir)
@ -56,26 +53,6 @@ sys.path.insert(0, app_dir)
depends.check_dependencies() depends.check_dependencies()
def connectToStream(streamNumber):
"""Connect to a stream"""
state.streamsInWhichIAmParticipating.append(streamNumber)
if isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections():
# Some XP and Vista systems can only have 10 outgoing connections
# at a time.
state.maximumNumberOfHalfOpenConnections = 9
else:
state.maximumNumberOfHalfOpenConnections = 64
try:
# don't overload Tor
if BMConfigParser().get(
'bitmessagesettings', 'socksproxytype') != 'none':
state.maximumNumberOfHalfOpenConnections = 4
except:
pass
BMConnectionPool().connectToStream(streamNumber)
def _fixSocket(): def _fixSocket():
if sys.platform.startswith('linux'): if sys.platform.startswith('linux'):
@ -157,7 +134,7 @@ def signal_handler(signum, frame):
logger.error("Got signal %i", signum) logger.error("Got signal %i", signum)
# there are possible non-UI variants to run bitmessage # there are possible non-UI variants to run bitmessage
# which should shutdown especially test-mode # which should shutdown especially test-mode
if shared.thisapp.daemon or not state.enableGUI: if state.thisapp.daemon or not state.enableGUI:
shutdown.doCleanShutdown() shutdown.doCleanShutdown()
else: else:
print('# Thread: {}({})'.format(thread.name, thread.ident)) print('# Thread: {}({})'.format(thread.name, thread.ident))
@ -175,6 +152,7 @@ class Main(object):
"""Start main application""" """Start main application"""
# pylint: disable=too-many-statements,too-many-branches,too-many-locals # pylint: disable=too-many-statements,too-many-branches,too-many-locals
_fixSocket() _fixSocket()
adjustHalfOpenConnectionsLimit()
config = BMConfigParser() config = BMConfigParser()
daemon = config.safeGetBoolean('bitmessagesettings', 'daemon') daemon = config.safeGetBoolean('bitmessagesettings', 'daemon')
@ -236,13 +214,10 @@ class Main(object):
' \'-c\' as a commandline argument.' ' \'-c\' as a commandline argument.'
) )
# is the application already running? If yes then exit. # is the application already running? If yes then exit.
try: state.thisapp = singleinstance("", daemon)
shared.thisapp = singleinstance("", daemon)
except Exception:
pass
if daemon: if daemon:
with shared.printLock: with printLock:
print('Running as a daemon. Send TERM signal to end.') print('Running as a daemon. Send TERM signal to end.')
self.daemonize() self.daemonize()
@ -332,7 +307,7 @@ class Main(object):
# start network components if networking is enabled # start network components if networking is enabled
if state.enableNetwork: if state.enableNetwork:
start_proxyconfig() start_proxyconfig()
BMConnectionPool() BMConnectionPool().connectToStream(1)
asyncoreThread = BMNetworkThread() asyncoreThread = BMNetworkThread()
asyncoreThread.daemon = True asyncoreThread.daemon = True
asyncoreThread.start() asyncoreThread.start()
@ -356,7 +331,6 @@ class Main(object):
state.uploadThread.daemon = True state.uploadThread.daemon = True
state.uploadThread.start() state.uploadThread.start()
connectToStream(1)
if config.safeGetBoolean('bitmessagesettings', 'upnp'): if config.safeGetBoolean('bitmessagesettings', 'upnp'):
import upnp import upnp
upnpThread = upnp.uPnPThread() upnpThread = upnp.uPnPThread()
@ -413,7 +387,7 @@ class Main(object):
try: try:
if os.fork(): if os.fork():
# unlock # unlock
shared.thisapp.cleanup() state.thisapp.cleanup()
# wait until grandchild ready # wait until grandchild ready
while True: while True:
time.sleep(1) time.sleep(1)
@ -424,8 +398,7 @@ class Main(object):
pass pass
else: else:
parentPid = os.getpid() parentPid = os.getpid()
# relock state.thisapp.lock() # relock
shared.thisapp.lock()
os.umask(0) os.umask(0)
try: try:
@ -436,20 +409,17 @@ class Main(object):
try: try:
if os.fork(): if os.fork():
# unlock # unlock
shared.thisapp.cleanup() state.thisapp.cleanup()
# wait until child ready # wait until child ready
while True: while True:
time.sleep(1) time.sleep(1)
# pylint: disable=protected-access os._exit(0) # pylint: disable=protected-access
os._exit(0)
except AttributeError: except AttributeError:
# fork not implemented # fork not implemented
pass pass
else: else:
# relock state.thisapp.lock() # relock
shared.thisapp.lock() state.thisapp.lockPid = None # indicate we're the final child
# indicate we're the final child
shared.thisapp.lockPid = None
sys.stdout.flush() sys.stdout.flush()
sys.stderr.flush() sys.stderr.flush()
if not sys.platform.startswith('win'): if not sys.platform.startswith('win'):
@ -488,7 +458,7 @@ All parameters are optional.
@staticmethod @staticmethod
def stop(): def stop():
"""Stop main application""" """Stop main application"""
with shared.printLock: with printLock:
print('Stopping Bitmessage Deamon.') print('Stopping Bitmessage Deamon.')
shutdown.doCleanShutdown() shutdown.doCleanShutdown()
@ -516,4 +486,4 @@ if __name__ == "__main__":
# So far, the creation of and management of the Bitmessage protocol and this # So far, the creation of and management of the Bitmessage protocol and this
# client is a one-man operation. Bitcoin tips are quite appreciated. # client is a one-man operation. Bitcoin tips are quite appreciated.
# 1H5XaDA6fYENLbknwZyjiYXYPQaFjjLX2u # 1Hl5XaDA6fYENLbknwZyjiYXYPQaFjjLX2u

View File

@ -7,6 +7,7 @@ import locale
import os import os
import random import random
import string import string
import subprocess
import sys import sys
import textwrap import textwrap
import threading import threading
@ -17,10 +18,11 @@ from sqlite3 import register_adapter
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from PyQt4.QtNetwork import QLocalSocket, QLocalServer from PyQt4.QtNetwork import QLocalSocket, QLocalServer
import shared
import state
from debug import logger from debug import logger
from tr import _translate from tr import _translate
from addresses import decodeAddress, addBMIfNotPresent from addresses import decodeAddress, addBMIfNotPresent
import shared
from bitmessageui import Ui_MainWindow from bitmessageui import Ui_MainWindow
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
import namecoin import namecoin
@ -29,7 +31,8 @@ from migrationwizard import Ui_MigrationWizard
from foldertree import ( from foldertree import (
AccountMixin, Ui_FolderWidget, Ui_AddressWidget, Ui_SubscriptionWidget, AccountMixin, Ui_FolderWidget, Ui_AddressWidget, Ui_SubscriptionWidget,
MessageList_AddressWidget, MessageList_SubjectWidget, MessageList_AddressWidget, MessageList_SubjectWidget,
Ui_AddressBookWidgetItemLabel, Ui_AddressBookWidgetItemAddress) Ui_AddressBookWidgetItemLabel, Ui_AddressBookWidgetItemAddress,
MessageList_TimeWidget)
import settingsmixin import settingsmixin
import support import support
from helper_ackPayload import genAckPayload from helper_ackPayload import genAckPayload
@ -47,7 +50,6 @@ import paths
from proofofwork import getPowType from proofofwork import getPowType
import queues import queues
import shutdown import shutdown
import state
from statusbar import BMStatusBar from statusbar import BMStatusBar
import sound import sound
# This is needed for tray icon # This is needed for tray icon
@ -72,6 +74,15 @@ def powQueueSize():
return queue_len return queue_len
def openKeysFile():
"""Open keys file with an external editor"""
keysfile = os.path.join(state.appdata, 'keys.dat')
if 'linux' in sys.platform:
subprocess.call(["xdg-open", keysfile])
elif sys.platform.startswith('win'):
os.startfile(keysfile) # pylint: disable=no-member
class MyForm(settingsmixin.SMainWindow): class MyForm(settingsmixin.SMainWindow):
# the maximum frequency of message sounds in seconds # the maximum frequency of message sounds in seconds
@ -214,19 +225,19 @@ class MyForm(settingsmixin.SMainWindow):
if connectSignal: if connectSignal:
self.connect(self.ui.tableWidgetInbox, QtCore.SIGNAL( self.connect(self.ui.tableWidgetInbox, QtCore.SIGNAL(
'customContextMenuRequested(const QPoint&)'), 'customContextMenuRequested(const QPoint&)'),
self.on_context_menuInbox) self.on_context_menuInbox)
self.ui.tableWidgetInboxSubscriptions.setContextMenuPolicy( self.ui.tableWidgetInboxSubscriptions.setContextMenuPolicy(
QtCore.Qt.CustomContextMenu) QtCore.Qt.CustomContextMenu)
if connectSignal: if connectSignal:
self.connect(self.ui.tableWidgetInboxSubscriptions, QtCore.SIGNAL( self.connect(self.ui.tableWidgetInboxSubscriptions, QtCore.SIGNAL(
'customContextMenuRequested(const QPoint&)'), 'customContextMenuRequested(const QPoint&)'),
self.on_context_menuInbox) self.on_context_menuInbox)
self.ui.tableWidgetInboxChans.setContextMenuPolicy( self.ui.tableWidgetInboxChans.setContextMenuPolicy(
QtCore.Qt.CustomContextMenu) QtCore.Qt.CustomContextMenu)
if connectSignal: if connectSignal:
self.connect(self.ui.tableWidgetInboxChans, QtCore.SIGNAL( self.connect(self.ui.tableWidgetInboxChans, QtCore.SIGNAL(
'customContextMenuRequested(const QPoint&)'), 'customContextMenuRequested(const QPoint&)'),
self.on_context_menuInbox) self.on_context_menuInbox)
def init_identities_popup_menu(self, connectSignal=True): def init_identities_popup_menu(self, connectSignal=True):
# Popup menu for the Your Identities tab # Popup menu for the Your Identities tab
@ -266,7 +277,7 @@ class MyForm(settingsmixin.SMainWindow):
if connectSignal: if connectSignal:
self.connect(self.ui.treeWidgetYourIdentities, QtCore.SIGNAL( self.connect(self.ui.treeWidgetYourIdentities, QtCore.SIGNAL(
'customContextMenuRequested(const QPoint&)'), 'customContextMenuRequested(const QPoint&)'),
self.on_context_menuYourIdentities) self.on_context_menuYourIdentities)
# load all gui.menu plugins with prefix 'address' # load all gui.menu plugins with prefix 'address'
self.menu_plugins = {'address': []} self.menu_plugins = {'address': []}
@ -316,7 +327,7 @@ class MyForm(settingsmixin.SMainWindow):
if connectSignal: if connectSignal:
self.connect(self.ui.treeWidgetChans, QtCore.SIGNAL( self.connect(self.ui.treeWidgetChans, QtCore.SIGNAL(
'customContextMenuRequested(const QPoint&)'), 'customContextMenuRequested(const QPoint&)'),
self.on_context_menuChan) self.on_context_menuChan)
def init_addressbook_popup_menu(self, connectSignal=True): def init_addressbook_popup_menu(self, connectSignal=True):
# Popup menu for the Address Book page # Popup menu for the Address Book page
@ -353,7 +364,7 @@ class MyForm(settingsmixin.SMainWindow):
if connectSignal: if connectSignal:
self.connect(self.ui.tableWidgetAddressBook, QtCore.SIGNAL( self.connect(self.ui.tableWidgetAddressBook, QtCore.SIGNAL(
'customContextMenuRequested(const QPoint&)'), 'customContextMenuRequested(const QPoint&)'),
self.on_context_menuAddressBook) self.on_context_menuAddressBook)
def init_subscriptions_popup_menu(self, connectSignal=True): def init_subscriptions_popup_menu(self, connectSignal=True):
# Actions # Actions
@ -382,7 +393,7 @@ class MyForm(settingsmixin.SMainWindow):
if connectSignal: if connectSignal:
self.connect(self.ui.treeWidgetSubscriptions, QtCore.SIGNAL( self.connect(self.ui.treeWidgetSubscriptions, QtCore.SIGNAL(
'customContextMenuRequested(const QPoint&)'), 'customContextMenuRequested(const QPoint&)'),
self.on_context_menuSubscriptions) self.on_context_menuSubscriptions)
def init_sent_popup_menu(self, connectSignal=True): def init_sent_popup_menu(self, connectSignal=True):
# Actions # Actions
@ -417,7 +428,7 @@ class MyForm(settingsmixin.SMainWindow):
db = getSortedSubscriptions(True) db = getSortedSubscriptions(True)
for address in db: for address in db:
for folder in folders: for folder in folders:
if not folder in db[address]: if folder not in db[address]:
db[address][folder] = {} db[address][folder] = {}
if treeWidget.isSortingEnabled(): if treeWidget.isSortingEnabled():
@ -432,7 +443,7 @@ class MyForm(settingsmixin.SMainWindow):
else: else:
toAddress = None toAddress = None
if not toAddress in db: if toAddress not in db:
treeWidget.takeTopLevelItem(i) treeWidget.takeTopLevelItem(i)
# no increment # no increment
continue continue
@ -480,7 +491,6 @@ class MyForm(settingsmixin.SMainWindow):
treeWidget.setSortingEnabled(True) treeWidget.setSortingEnabled(True)
def rerenderTabTreeMessages(self): def rerenderTabTreeMessages(self):
self.rerenderTabTree('messages') self.rerenderTabTree('messages')
@ -551,7 +561,7 @@ class MyForm(settingsmixin.SMainWindow):
else: else:
toAddress = None toAddress = None
if not toAddress in db: if toAddress not in db:
treeWidget.takeTopLevelItem(i) treeWidget.takeTopLevelItem(i)
# no increment # no increment
continue continue
@ -560,8 +570,9 @@ class MyForm(settingsmixin.SMainWindow):
while j < widget.childCount(): while j < widget.childCount():
subwidget = widget.child(j) subwidget = widget.child(j)
try: try:
subwidget.setUnreadCount(db[toAddress][subwidget.folderName]) subwidget.setUnreadCount(
if subwidget.folderName not in ["new", "trash", "sent"]: db[toAddress][subwidget.folderName])
if subwidget.folderName not in ("new", "trash", "sent"):
unread += db[toAddress][subwidget.folderName] unread += db[toAddress][subwidget.folderName]
db[toAddress].pop(subwidget.folderName, None) db[toAddress].pop(subwidget.folderName, None)
except: except:
@ -577,7 +588,7 @@ class MyForm(settingsmixin.SMainWindow):
if toAddress is not None and tab == 'messages' and folder == "new": if toAddress is not None and tab == 'messages' and folder == "new":
continue continue
subwidget = Ui_FolderWidget(widget, j, toAddress, f, c) subwidget = Ui_FolderWidget(widget, j, toAddress, f, c)
if subwidget.folderName not in ["new", "trash", "sent"]: if subwidget.folderName not in ("new", "trash", "sent"):
unread += c unread += c
j += 1 j += 1
widget.setUnreadCount(unread) widget.setUnreadCount(unread)
@ -593,7 +604,7 @@ class MyForm(settingsmixin.SMainWindow):
if toAddress is not None and tab == 'messages' and folder == "new": if toAddress is not None and tab == 'messages' and folder == "new":
continue continue
subwidget = Ui_FolderWidget(widget, j, toAddress, folder, db[toAddress][folder]) subwidget = Ui_FolderWidget(widget, j, toAddress, folder, db[toAddress][folder])
if subwidget.folderName not in ["new", "trash", "sent"]: if subwidget.folderName not in ("new", "trash", "sent"):
unread += db[toAddress][folder] unread += db[toAddress][folder]
j += 1 j += 1
widget.setUnreadCount(unread) widget.setUnreadCount(unread)
@ -730,9 +741,6 @@ class MyForm(settingsmixin.SMainWindow):
QtCore.QObject.connect(self.pushButtonStatusIcon, QtCore.SIGNAL( QtCore.QObject.connect(self.pushButtonStatusIcon, QtCore.SIGNAL(
"clicked()"), self.click_pushButtonStatusIcon) "clicked()"), self.click_pushButtonStatusIcon)
self.numberOfMessagesProcessed = 0
self.numberOfBroadcastsProcessed = 0
self.numberOfPubkeysProcessed = 0
self.unreadCount = 0 self.unreadCount = 0
# Set the icon sizes for the identicons # Set the icon sizes for the identicons
@ -814,6 +822,14 @@ class MyForm(settingsmixin.SMainWindow):
self.initSettings() self.initSettings()
self.resetNamecoinConnection() self.resetNamecoinConnection()
self.sqlInit()
self.indicatorInit()
self.notifierInit()
self.ui.updateNetworkSwitchMenuLabel()
self._firstrun = BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'dontconnect')
self._contact_selected = None self._contact_selected = None
@ -963,40 +979,30 @@ class MyForm(settingsmixin.SMainWindow):
Switch unread for item of msgid and related items in Switch unread for item of msgid and related items in
other STableWidgets "All Accounts" and "Chans" other STableWidgets "All Accounts" and "Chans"
""" """
related = [self.ui.tableWidgetInbox, self.ui.tableWidgetInboxChans] status = widget.item(row, 0).unread
if status != unread:
return
widgets = [self.ui.tableWidgetInbox, self.ui.tableWidgetInboxChans]
rrow = None
try: try:
related.remove(widget) widgets.remove(widget)
related = related.pop() related = widgets.pop()
except ValueError: except ValueError:
rrow = None pass
related = []
else: else:
# maybe use instead: # maybe use instead:
# rrow = related.row(msgid), msgid should be QTableWidgetItem # rrow = related.row(msgid), msgid should be QTableWidgetItem
# related = related.findItems(msgid, QtCore.Qt.MatchExactly), # related = related.findItems(msgid, QtCore.Qt.MatchExactly),
# returns an empty list # returns an empty list
for rrow in xrange(related.rowCount()): for rrow in range(related.rowCount()):
if msgid == str(related.item(rrow, 3).data( if related.item(rrow, 3).data() == msgid:
QtCore.Qt.UserRole).toPyObject()):
break break
else:
rrow = None
status = widget.item(row, 0).unread for col in range(widget.columnCount()):
if status == unread: widget.item(row, col).setUnread(not status)
font = QtGui.QFont() if rrow:
font.setBold(not status) related.item(rrow, col).setUnread(not status)
widget.item(row, 3).setFont(font)
for col in (0, 1, 2):
widget.item(row, col).setUnread(not status)
try:
related.item(rrow, 3).setFont(font)
except (TypeError, AttributeError):
pass
else:
for col in (0, 1, 2):
related.item(rrow, col).setUnread(not status)
# Here we need to update unread count for: # Here we need to update unread count for:
# - all widgets if there is no args # - all widgets if there is no args
@ -1081,43 +1087,46 @@ class MyForm(settingsmixin.SMainWindow):
if sortingEnabled: if sortingEnabled:
tableWidget.setSortingEnabled(False) tableWidget.setSortingEnabled(False)
tableWidget.insertRow(0) tableWidget.insertRow(0)
for i in range(len(items)): for i, item in enumerate(items):
tableWidget.setItem(0, i, items[i]) tableWidget.setItem(0, i, item)
if sortingEnabled: if sortingEnabled:
tableWidget.setSortingEnabled(True) tableWidget.setSortingEnabled(True)
def addMessageListItemSent(self, tableWidget, toAddress, fromAddress, subject, status, ackdata, lastactiontime): def addMessageListItemSent(
acct = accountClass(fromAddress) self, tableWidget, toAddress, fromAddress, subject,
if acct is None: status, ackdata, lastactiontime
acct = BMAccount(fromAddress) ):
acct = accountClass(fromAddress) or BMAccount(fromAddress)
acct.parseMessage(toAddress, fromAddress, subject, "") acct.parseMessage(toAddress, fromAddress, subject, "")
items = []
MessageList_AddressWidget(items, str(toAddress), unicode(acct.toLabel, 'utf-8'))
MessageList_AddressWidget(items, str(fromAddress), unicode(acct.fromLabel, 'utf-8'))
MessageList_SubjectWidget(items, str(subject), unicode(acct.subject, 'utf-8', 'replace'))
if status == 'awaitingpubkey': if status == 'awaitingpubkey':
statusText = _translate( statusText = _translate(
"MainWindow", "Waiting for their encryption key. Will request it again soon.") "MainWindow",
"Waiting for their encryption key. Will request it again soon."
)
elif status == 'doingpowforpubkey': elif status == 'doingpowforpubkey':
statusText = _translate( statusText = _translate(
"MainWindow", "Doing work necessary to request encryption key.") "MainWindow", "Doing work necessary to request encryption key."
)
elif status == 'msgqueued': elif status == 'msgqueued':
statusText = _translate( statusText = _translate("MainWindow", "Queued.")
"MainWindow", "Queued.")
elif status == 'msgsent': elif status == 'msgsent':
statusText = _translate("MainWindow", "Message sent. Waiting for acknowledgement. Sent at %1").arg( statusText = _translate(
l10n.formatTimestamp(lastactiontime)) "MainWindow",
"Message sent. Waiting for acknowledgement. Sent at %1"
).arg(l10n.formatTimestamp(lastactiontime))
elif status == 'msgsentnoackexpected': elif status == 'msgsentnoackexpected':
statusText = _translate("MainWindow", "Message sent. Sent at %1").arg( statusText = _translate(
l10n.formatTimestamp(lastactiontime)) "MainWindow", "Message sent. Sent at %1"
).arg(l10n.formatTimestamp(lastactiontime))
elif status == 'doingmsgpow': elif status == 'doingmsgpow':
statusText = _translate( statusText = _translate(
"MainWindow", "Doing work necessary to send message.") "MainWindow", "Doing work necessary to send message.")
elif status == 'ackreceived': elif status == 'ackreceived':
statusText = _translate("MainWindow", "Acknowledgement of the message received %1").arg( statusText = _translate(
l10n.formatTimestamp(lastactiontime)) "MainWindow",
"Acknowledgement of the message received %1"
).arg(l10n.formatTimestamp(lastactiontime))
elif status == 'broadcastqueued': elif status == 'broadcastqueued':
statusText = _translate( statusText = _translate(
"MainWindow", "Broadcast queued.") "MainWindow", "Broadcast queued.")
@ -1128,58 +1137,64 @@ class MyForm(settingsmixin.SMainWindow):
statusText = _translate("MainWindow", "Broadcast on %1").arg( statusText = _translate("MainWindow", "Broadcast on %1").arg(
l10n.formatTimestamp(lastactiontime)) l10n.formatTimestamp(lastactiontime))
elif status == 'toodifficult': elif status == 'toodifficult':
statusText = _translate("MainWindow", "Problem: The work demanded by the recipient is more difficult than you are willing to do. %1").arg( statusText = _translate(
l10n.formatTimestamp(lastactiontime)) "MainWindow",
"Problem: The work demanded by the recipient is more"
" difficult than you are willing to do. %1"
).arg(l10n.formatTimestamp(lastactiontime))
elif status == 'badkey': elif status == 'badkey':
statusText = _translate("MainWindow", "Problem: The recipient\'s encryption key is no good. Could not encrypt message. %1").arg( statusText = _translate(
l10n.formatTimestamp(lastactiontime)) "MainWindow",
"Problem: The recipient\'s encryption key is no good."
" Could not encrypt message. %1"
).arg(l10n.formatTimestamp(lastactiontime))
elif status == 'forcepow': elif status == 'forcepow':
statusText = _translate( statusText = _translate(
"MainWindow", "Forced difficulty override. Send should start soon.") "MainWindow",
"Forced difficulty override. Send should start soon.")
else: else:
statusText = _translate("MainWindow", "Unknown status: %1 %2").arg(status).arg( statusText = _translate(
"MainWindow", "Unknown status: %1 %2").arg(status).arg(
l10n.formatTimestamp(lastactiontime)) l10n.formatTimestamp(lastactiontime))
newItem = myTableWidgetItem(statusText)
newItem.setToolTip(statusText) items = [
newItem.setData(QtCore.Qt.UserRole, QtCore.QByteArray(ackdata)) MessageList_AddressWidget(
newItem.setData(33, int(lastactiontime)) toAddress, unicode(acct.toLabel, 'utf-8')),
newItem.setFlags( MessageList_AddressWidget(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) fromAddress, unicode(acct.fromLabel, 'utf-8')),
items.append(newItem) MessageList_SubjectWidget(
str(subject), unicode(acct.subject, 'utf-8', 'replace')),
MessageList_TimeWidget(
statusText, False, lastactiontime, ackdata)]
self.addMessageListItem(tableWidget, items) self.addMessageListItem(tableWidget, items)
return acct return acct
def addMessageListItemInbox(self, tableWidget, msgfolder, msgid, toAddress, fromAddress, subject, received, read): def addMessageListItemInbox(
font = QtGui.QFont() self, tableWidget, toAddress, fromAddress, subject,
font.setBold(True) msgid, received, read
):
if toAddress == str_broadcast_subscribers: if toAddress == str_broadcast_subscribers:
acct = accountClass(fromAddress) acct = accountClass(fromAddress)
else: else:
acct = accountClass(toAddress) acct = accountClass(toAddress) or accountClass(fromAddress)
if acct is None:
acct = accountClass(fromAddress)
if acct is None: if acct is None:
acct = BMAccount(fromAddress) acct = BMAccount(fromAddress)
acct.parseMessage(toAddress, fromAddress, subject, "") acct.parseMessage(toAddress, fromAddress, subject, "")
items = [] items = [
#to MessageList_AddressWidget(
MessageList_AddressWidget(items, toAddress, unicode(acct.toLabel, 'utf-8'), not read) toAddress, unicode(acct.toLabel, 'utf-8'), not read),
# from MessageList_AddressWidget(
MessageList_AddressWidget(items, fromAddress, unicode(acct.fromLabel, 'utf-8'), not read) fromAddress, unicode(acct.fromLabel, 'utf-8'), not read),
# subject MessageList_SubjectWidget(
MessageList_SubjectWidget(items, str(subject), unicode(acct.subject, 'utf-8', 'replace'), not read) str(subject), unicode(acct.subject, 'utf-8', 'replace'),
# time received not read),
time_item = myTableWidgetItem(l10n.formatTimestamp(received)) MessageList_TimeWidget(
time_item.setToolTip(l10n.formatTimestamp(received)) l10n.formatTimestamp(received), not read, received, msgid)
time_item.setData(QtCore.Qt.UserRole, QtCore.QByteArray(msgid)) ]
time_item.setData(33, int(received))
time_item.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
if not read:
time_item.setFont(font)
items.append(time_item)
self.addMessageListItem(tableWidget, items) self.addMessageListItem(tableWidget, items)
return acct return acct
# Load Sent items from database # Load Sent items from database
@ -1194,35 +1209,40 @@ class MyForm(settingsmixin.SMainWindow):
xAddress = 'both' xAddress = 'both'
else: else:
tableWidget.setColumnHidden(0, False) tableWidget.setColumnHidden(0, False)
if account is None: tableWidget.setColumnHidden(1, bool(account))
tableWidget.setColumnHidden(1, False)
else:
tableWidget.setColumnHidden(1, True)
xAddress = 'fromaddress' xAddress = 'fromaddress'
tableWidget.setUpdatesEnabled(False) queryreturn = helper_search.search_sql(
tableWidget.setSortingEnabled(False) xAddress, account, "sent", where, what, False)
tableWidget.setRowCount(0)
queryreturn = helper_search.search_sql(xAddress, account, "sent", where, what, False)
for row in queryreturn: for row in queryreturn:
toAddress, fromAddress, subject, status, ackdata, lastactiontime = row self.addMessageListItemSent(tableWidget, *row)
self.addMessageListItemSent(tableWidget, toAddress, fromAddress, subject, status, ackdata, lastactiontime)
tableWidget.horizontalHeader().setSortIndicator( tableWidget.horizontalHeader().setSortIndicator(
3, QtCore.Qt.DescendingOrder) 3, QtCore.Qt.DescendingOrder)
tableWidget.setSortingEnabled(True) tableWidget.setSortingEnabled(True)
tableWidget.horizontalHeaderItem(3).setText(_translate("MainWindow", "Sent", None)) tableWidget.horizontalHeaderItem(3).setText(
_translate("MainWindow", "Sent"))
tableWidget.setUpdatesEnabled(True) tableWidget.setUpdatesEnabled(True)
# Load messages from database file # Load messages from database file
def loadMessagelist(self, tableWidget, account, folder="inbox", where="", what="", unreadOnly = False): def loadMessagelist(
self, tableWidget, account, folder="inbox", where="", what="",
unreadOnly=False
):
tableWidget.setUpdatesEnabled(False)
tableWidget.setSortingEnabled(False)
tableWidget.setRowCount(0)
if folder == 'sent': if folder == 'sent':
self.loadSent(tableWidget, account, where, what) self.loadSent(tableWidget, account, where, what)
return return
if tableWidget == self.ui.tableWidgetInboxSubscriptions: if tableWidget == self.ui.tableWidgetInboxSubscriptions:
xAddress = "fromaddress" xAddress = "fromaddress"
if not what:
where = _translate("MainWindow", "To")
what = str_broadcast_subscribers
else: else:
xAddress = "toaddress" xAddress = "toaddress"
if account is not None: if account is not None:
@ -1232,21 +1252,21 @@ class MyForm(settingsmixin.SMainWindow):
tableWidget.setColumnHidden(0, False) tableWidget.setColumnHidden(0, False)
tableWidget.setColumnHidden(1, False) tableWidget.setColumnHidden(1, False)
tableWidget.setUpdatesEnabled(False) queryreturn = helper_search.search_sql(
tableWidget.setSortingEnabled(False) xAddress, account, folder, where, what, unreadOnly)
tableWidget.setRowCount(0)
queryreturn = helper_search.search_sql(xAddress, account, folder, where, what, unreadOnly)
for row in queryreturn: for row in queryreturn:
msgfolder, msgid, toAddress, fromAddress, subject, received, read = row toAddress, fromAddress, subject, _, msgid, received, read = row
self.addMessageListItemInbox(tableWidget, msgfolder, msgid, toAddress, fromAddress, subject, received, read) self.addMessageListItemInbox(
tableWidget, toAddress, fromAddress, subject,
msgid, received, read)
tableWidget.horizontalHeader().setSortIndicator( tableWidget.horizontalHeader().setSortIndicator(
3, QtCore.Qt.DescendingOrder) 3, QtCore.Qt.DescendingOrder)
tableWidget.setSortingEnabled(True) tableWidget.setSortingEnabled(True)
tableWidget.selectRow(0) tableWidget.selectRow(0)
tableWidget.horizontalHeaderItem(3).setText(_translate("MainWindow", "Received", None)) tableWidget.horizontalHeaderItem(3).setText(
_translate("MainWindow", "Received"))
tableWidget.setUpdatesEnabled(True) tableWidget.setUpdatesEnabled(True)
# create application indicator # create application indicator
@ -1473,9 +1493,9 @@ class MyForm(settingsmixin.SMainWindow):
def handleKeyPress(self, event, focus=None): def handleKeyPress(self, event, focus=None):
"""This method handles keypress events for all widgets on MyForm""" """This method handles keypress events for all widgets on MyForm"""
messagelist = self.getCurrentMessagelist() messagelist = self.getCurrentMessagelist()
folder = self.getCurrentFolder()
if event.key() == QtCore.Qt.Key_Delete: if event.key() == QtCore.Qt.Key_Delete:
if isinstance(focus, MessageView) or isinstance(focus, QtGui.QTableWidget): if isinstance(focus, (MessageView, QtGui.QTableWidget)):
folder = self.getCurrentFolder()
if folder == "sent": if folder == "sent":
self.on_action_SentTrash() self.on_action_SentTrash()
else: else:
@ -1511,17 +1531,18 @@ class MyForm(settingsmixin.SMainWindow):
self.ui.lineEditTo.setFocus() self.ui.lineEditTo.setFocus()
event.ignore() event.ignore()
elif event.key() == QtCore.Qt.Key_F: elif event.key() == QtCore.Qt.Key_F:
searchline = self.getCurrentSearchLine(retObj=True) try:
if searchline: self.getCurrentSearchLine(retObj=True).setFocus()
searchline.setFocus() except AttributeError:
pass
event.ignore() event.ignore()
if not event.isAccepted(): if not event.isAccepted():
return return
if isinstance(focus, MessageView): if isinstance(focus, MessageView):
return MessageView.keyPressEvent(focus, event) return MessageView.keyPressEvent(focus, event)
elif isinstance(focus, QtGui.QTableWidget): if isinstance(focus, QtGui.QTableWidget):
return QtGui.QTableWidget.keyPressEvent(focus, event) return QtGui.QTableWidget.keyPressEvent(focus, event)
elif isinstance(focus, QtGui.QTreeWidget): if isinstance(focus, QtGui.QTreeWidget):
return QtGui.QTreeWidget.keyPressEvent(focus, event) return QtGui.QTreeWidget.keyPressEvent(focus, event)
# menu button 'manage keys' # menu button 'manage keys'
@ -1546,7 +1567,7 @@ class MyForm(settingsmixin.SMainWindow):
reply = QtGui.QMessageBox.question(self, _translate("MainWindow", "Open keys.dat?"), _translate( reply = QtGui.QMessageBox.question(self, _translate("MainWindow", "Open keys.dat?"), _translate(
"MainWindow", "You may manage your keys by editing the keys.dat file stored in\n %1 \nIt is important that you back up this file. Would you like to open the file now? (Be sure to close Bitmessage before making any changes.)").arg(state.appdata), QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) "MainWindow", "You may manage your keys by editing the keys.dat file stored in\n %1 \nIt is important that you back up this file. Would you like to open the file now? (Be sure to close Bitmessage before making any changes.)").arg(state.appdata), QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes: if reply == QtGui.QMessageBox.Yes:
shared.openKeysFile() openKeysFile()
# menu button 'delete all treshed messages' # menu button 'delete all treshed messages'
def click_actionDeleteAllTrashedMessages(self): def click_actionDeleteAllTrashedMessages(self):
@ -1668,7 +1689,7 @@ class MyForm(settingsmixin.SMainWindow):
if color == 'red': if color == 'red':
self.pushButtonStatusIcon.setIcon( self.pushButtonStatusIcon.setIcon(
QtGui.QIcon(":/newPrefix/images/redicon.png")) QtGui.QIcon(":/newPrefix/images/redicon.png"))
shared.statusIconColor = 'red' state.statusIconColor = 'red'
# if the connection is lost then show a notification # if the connection is lost then show a notification
if self.connected and _notifications_enabled: if self.connected and _notifications_enabled:
self.notifierShow( self.notifierShow(
@ -1694,7 +1715,7 @@ class MyForm(settingsmixin.SMainWindow):
self.statusbar.clearMessage() self.statusbar.clearMessage()
self.pushButtonStatusIcon.setIcon( self.pushButtonStatusIcon.setIcon(
QtGui.QIcon(":/newPrefix/images/yellowicon.png")) QtGui.QIcon(":/newPrefix/images/yellowicon.png"))
shared.statusIconColor = 'yellow' state.statusIconColor = 'yellow'
# if a new connection has been established then show a notification # if a new connection has been established then show a notification
if not self.connected and _notifications_enabled: if not self.connected and _notifications_enabled:
self.notifierShow( self.notifierShow(
@ -1712,7 +1733,7 @@ class MyForm(settingsmixin.SMainWindow):
self.statusbar.clearMessage() self.statusbar.clearMessage()
self.pushButtonStatusIcon.setIcon( self.pushButtonStatusIcon.setIcon(
QtGui.QIcon(":/newPrefix/images/greenicon.png")) QtGui.QIcon(":/newPrefix/images/greenicon.png"))
shared.statusIconColor = 'green' state.statusIconColor = 'green'
if not self.connected and _notifications_enabled: if not self.connected and _notifications_enabled:
self.notifierShow( self.notifierShow(
'Bitmessage', 'Bitmessage',
@ -1735,7 +1756,7 @@ class MyForm(settingsmixin.SMainWindow):
self.drawTrayIcon(iconFileName, self.findInboxUnreadCount()) self.drawTrayIcon(iconFileName, self.findInboxUnreadCount())
def calcTrayIcon(self, iconFileName, inboxUnreadCount): def calcTrayIcon(self, iconFileName, inboxUnreadCount):
pixmap = QtGui.QPixmap(":/newPrefix/images/"+iconFileName) pixmap = QtGui.QPixmap(":/newPrefix/images/" + iconFileName)
if inboxUnreadCount > 0: if inboxUnreadCount > 0:
# choose font and calculate font parameters # choose font and calculate font parameters
fontName = "Lucida" fontName = "Lucida"
@ -1747,7 +1768,8 @@ class MyForm(settingsmixin.SMainWindow):
rect = fontMetrics.boundingRect(txt) rect = fontMetrics.boundingRect(txt)
# margins that we add in the top-right corner # margins that we add in the top-right corner
marginX = 2 marginX = 2
marginY = 0 # it looks like -2 is also ok due to the error of metric # it looks like -2 is also ok due to the error of metric
marginY = 0
# if it renders too wide we need to change it to a plus symbol # if it renders too wide we need to change it to a plus symbol
if rect.width() > 20: if rect.width() > 20:
txt = "+" txt = "+"
@ -1787,11 +1809,18 @@ class MyForm(settingsmixin.SMainWindow):
return self.unreadCount return self.unreadCount
def updateSentItemStatusByToAddress(self, toAddress, textToDisplay): def updateSentItemStatusByToAddress(self, toAddress, textToDisplay):
for sent in [self.ui.tableWidgetInbox, self.ui.tableWidgetInboxSubscriptions, self.ui.tableWidgetInboxChans]: for sent in (
self.ui.tableWidgetInbox,
self.ui.tableWidgetInboxSubscriptions,
self.ui.tableWidgetInboxChans
):
treeWidget = self.widgetConvert(sent) treeWidget = self.widgetConvert(sent)
if self.getCurrentFolder(treeWidget) != "sent": if self.getCurrentFolder(treeWidget) != "sent":
continue continue
if treeWidget in [self.ui.treeWidgetSubscriptions, self.ui.treeWidgetChans] and self.getCurrentAccount(treeWidget) != toAddress: if treeWidget in (
self.ui.treeWidgetSubscriptions,
self.ui.treeWidgetChans
) and self.getCurrentAccount(treeWidget) != toAddress:
continue continue
for i in range(sent.rowCount()): for i in range(sent.rowCount()):
@ -1811,15 +1840,17 @@ class MyForm(settingsmixin.SMainWindow):
def updateSentItemStatusByAckdata(self, ackdata, textToDisplay): def updateSentItemStatusByAckdata(self, ackdata, textToDisplay):
if type(ackdata) is str: if type(ackdata) is str:
ackdata = QtCore.QByteArray(ackdata) ackdata = QtCore.QByteArray(ackdata)
for sent in [self.ui.tableWidgetInbox, self.ui.tableWidgetInboxSubscriptions, self.ui.tableWidgetInboxChans]: for sent in (
self.ui.tableWidgetInbox,
self.ui.tableWidgetInboxSubscriptions,
self.ui.tableWidgetInboxChans
):
treeWidget = self.widgetConvert(sent) treeWidget = self.widgetConvert(sent)
if self.getCurrentFolder(treeWidget) != "sent": if self.getCurrentFolder(treeWidget) != "sent":
continue continue
for i in range(sent.rowCount()): for i in range(sent.rowCount()):
toAddress = sent.item( toAddress = sent.item(i, 0).data(QtCore.Qt.UserRole)
i, 0).data(QtCore.Qt.UserRole) tableAckdata = sent.item(i, 3).data()
tableAckdata = sent.item(
i, 3).data(QtCore.Qt.UserRole).toPyObject()
status, addressVersionNumber, streamNumber, ripe = decodeAddress( status, addressVersionNumber, streamNumber, ripe = decodeAddress(
toAddress) toAddress)
if ackdata == tableAckdata: if ackdata == tableAckdata:
@ -1843,8 +1874,7 @@ class MyForm(settingsmixin.SMainWindow):
): ):
i = None i = None
for i in range(inbox.rowCount()): for i in range(inbox.rowCount()):
if msgid == \ if msgid == inbox.item(i, 3).data():
inbox.item(i, 3).data(QtCore.Qt.UserRole).toPyObject():
break break
else: else:
continue continue
@ -1919,11 +1949,13 @@ class MyForm(settingsmixin.SMainWindow):
newRows[address] = [label, AccountMixin.NORMAL] newRows[address] = [label, AccountMixin.NORMAL]
completerList = [] completerList = []
for address in sorted(oldRows, key = lambda x: oldRows[x][2], reverse = True): for address in sorted(
if address in newRows: oldRows, key=lambda x: oldRows[x][2], reverse=True
completerList.append(unicode(newRows[address][0], encoding="UTF-8") + " <" + address + ">") ):
newRows.pop(address) try:
else: completerList.append(
newRows.pop(address)[0] + " <" + address + ">")
except KeyError:
self.ui.tableWidgetAddressBook.removeRow(oldRows[address][2]) self.ui.tableWidgetAddressBook.removeRow(oldRows[address][2])
for address in newRows: for address in newRows:
addRow(address, newRows[address][0], newRows[address][1]) addRow(address, newRows[address][0], newRows[address][1])
@ -1996,11 +2028,14 @@ class MyForm(settingsmixin.SMainWindow):
acct = accountClass(fromAddress) acct = accountClass(fromAddress)
if sendMessageToPeople: # To send a message to specific people (rather than broadcast) # To send a message to specific people (rather than broadcast)
toAddressesList = [s.strip() if sendMessageToPeople:
for s in toAddresses.replace(',', ';').split(';')] toAddressesList = set([
toAddressesList = list(set( s.strip() for s in toAddresses.replace(',', ';').split(';')
toAddressesList)) # remove duplicate addresses. If the user has one address with a BM- and the same address without the BM-, this will not catch it. They'll send the message to the person twice. ])
# remove duplicate addresses. If the user has one address
# with a BM- and the same address without the BM-, this will
# not catch it. They'll send the message to the person twice.
for toAddress in toAddressesList: for toAddress in toAddressesList:
if toAddress != '': if toAddress != '':
# label plus address # label plus address
@ -2119,7 +2154,7 @@ class MyForm(settingsmixin.SMainWindow):
"MainWindow", "Concerning the address %1, Bitmessage cannot handle stream numbers of %2. Perhaps upgrade Bitmessage to the latest version.").arg(toAddress).arg(str(streamNumber))) "MainWindow", "Concerning the address %1, Bitmessage cannot handle stream numbers of %2. Perhaps upgrade Bitmessage to the latest version.").arg(toAddress).arg(str(streamNumber)))
continue continue
self.statusbar.clearMessage() self.statusbar.clearMessage()
if shared.statusIconColor == 'red': if state.statusIconColor == 'red':
self.updateStatusBar(_translate( self.updateStatusBar(_translate(
"MainWindow", "MainWindow",
"Warning: You are currently not connected." "Warning: You are currently not connected."
@ -2308,54 +2343,88 @@ class MyForm(settingsmixin.SMainWindow):
# receives a message to an address that is acting as a # receives a message to an address that is acting as a
# pseudo-mailing-list. The message will be broadcast out. This function # pseudo-mailing-list. The message will be broadcast out. This function
# puts the message on the 'Sent' tab. # puts the message on the 'Sent' tab.
def displayNewSentMessage(self, toAddress, toLabel, fromAddress, subject, message, ackdata): def displayNewSentMessage(
self, toAddress, toLabel, fromAddress, subject,
message, ackdata):
acct = accountClass(fromAddress) acct = accountClass(fromAddress)
acct.parseMessage(toAddress, fromAddress, subject, message) acct.parseMessage(toAddress, fromAddress, subject, message)
tab = -1 tab = -1
for sent in [self.ui.tableWidgetInbox, self.ui.tableWidgetInboxSubscriptions, self.ui.tableWidgetInboxChans]: for sent in (
self.ui.tableWidgetInbox,
self.ui.tableWidgetInboxSubscriptions,
self.ui.tableWidgetInboxChans
):
tab += 1 tab += 1
if tab == 1: if tab == 1:
tab = 2 tab = 2
treeWidget = self.widgetConvert(sent) treeWidget = self.widgetConvert(sent)
if self.getCurrentFolder(treeWidget) != "sent": if self.getCurrentFolder(treeWidget) != "sent":
continue continue
if treeWidget == self.ui.treeWidgetYourIdentities and self.getCurrentAccount(treeWidget) not in (fromAddress, None, False): if treeWidget == self.ui.treeWidgetYourIdentities \
and self.getCurrentAccount(treeWidget) not in (
fromAddress, None, False):
continue continue
elif treeWidget in [self.ui.treeWidgetSubscriptions, self.ui.treeWidgetChans] and self.getCurrentAccount(treeWidget) != toAddress: elif treeWidget in (
self.ui.treeWidgetSubscriptions,
self.ui.treeWidgetChans
) and self.getCurrentAccount(treeWidget) != toAddress:
continue continue
elif not helper_search.check_match(toAddress, fromAddress, subject, message, self.getCurrentSearchOption(tab), self.getCurrentSearchLine(tab)): elif not helper_search.check_match(
toAddress, fromAddress, subject, message,
self.getCurrentSearchOption(tab),
self.getCurrentSearchLine(tab)
):
continue continue
self.addMessageListItemSent(sent, toAddress, fromAddress, subject, "msgqueued", ackdata, time.time()) self.addMessageListItemSent(
self.getAccountTextedit(acct).setPlainText(unicode(message, 'utf-8', 'replace')) sent, toAddress, fromAddress, subject,
"msgqueued", ackdata, time.time())
self.getAccountTextedit(acct).setPlainText(message)
sent.setCurrentCell(0, 0) sent.setCurrentCell(0, 0)
def displayNewInboxMessage(self, inventoryHash, toAddress, fromAddress, subject, message): def displayNewInboxMessage(
if toAddress == str_broadcast_subscribers: self, inventoryHash, toAddress, fromAddress, subject, message):
acct = accountClass(fromAddress) acct = accountClass(
else: fromAddress if toAddress == str_broadcast_subscribers
acct = accountClass(toAddress) else toAddress
)
inbox = self.getAccountMessagelist(acct) inbox = self.getAccountMessagelist(acct)
ret = None ret = treeWidget = None
tab = -1 tab = -1
for treeWidget in [self.ui.treeWidgetYourIdentities, self.ui.treeWidgetSubscriptions, self.ui.treeWidgetChans]: for treeWidget in (
self.ui.treeWidgetYourIdentities,
self.ui.treeWidgetSubscriptions,
self.ui.treeWidgetChans
):
tab += 1 tab += 1
if tab == 1: if tab == 1:
tab = 2 tab = 2
tableWidget = self.widgetConvert(treeWidget) if not helper_search.check_match(
if not helper_search.check_match(toAddress, fromAddress, subject, message, self.getCurrentSearchOption(tab), self.getCurrentSearchLine(tab)): toAddress, fromAddress, subject, message,
self.getCurrentSearchOption(tab),
self.getCurrentSearchLine(tab)
):
continue continue
if tableWidget == inbox and self.getCurrentAccount(treeWidget) == acct.address and self.getCurrentFolder(treeWidget) in ["inbox", None]: tableWidget = self.widgetConvert(treeWidget)
ret = self.addMessageListItemInbox(inbox, "inbox", inventoryHash, toAddress, fromAddress, subject, time.time(), 0) current_account = self.getCurrentAccount(treeWidget)
elif treeWidget == self.ui.treeWidgetYourIdentities and self.getCurrentAccount(treeWidget) is None and self.getCurrentFolder(treeWidget) in ["inbox", "new", None]: current_folder = self.getCurrentFolder(treeWidget)
ret = self.addMessageListItemInbox(tableWidget, "inbox", inventoryHash, toAddress, fromAddress, subject, time.time(), 0) # pylint: disable=too-many-boolean-expressions
if ((tableWidget == inbox
and current_account == acct.address
and current_folder in ("inbox", None))
or (treeWidget == self.ui.treeWidgetYourIdentities
and current_account is None
and current_folder in ("inbox", "new", None))):
ret = self.addMessageListItemInbox(
tableWidget, toAddress, fromAddress, subject,
inventoryHash, time.time(), False)
if ret is None: if ret is None:
acct.parseMessage(toAddress, fromAddress, subject, "") acct.parseMessage(toAddress, fromAddress, subject, "")
else: else:
acct = ret acct = ret
# pylint:disable=undefined-loop-variable
self.propagateUnreadCount(widget=treeWidget if ret else None) self.propagateUnreadCount(widget=treeWidget if ret else None)
if BMConfigParser().getboolean( if BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'showtraynotifications'): 'bitmessagesettings', 'showtraynotifications'):
self.notifierShow( self.notifierShow(
_translate("MainWindow", "New Message"), _translate("MainWindow", "New Message"),
@ -2363,16 +2432,22 @@ class MyForm(settingsmixin.SMainWindow):
unicode(acct.fromLabel, 'utf-8')), unicode(acct.fromLabel, 'utf-8')),
sound.SOUND_UNKNOWN sound.SOUND_UNKNOWN
) )
if self.getCurrentAccount() is not None and ((self.getCurrentFolder(treeWidget) != "inbox" and self.getCurrentFolder(treeWidget) is not None) or self.getCurrentAccount(treeWidget) != acct.address): if self.getCurrentAccount() is not None and (
# Ubuntu should notify of new message irespective of (self.getCurrentFolder(treeWidget) != "inbox"
and self.getCurrentFolder(treeWidget) is not None)
or self.getCurrentAccount(treeWidget) != acct.address):
# Ubuntu should notify of new message irrespective of
# whether it's in current message list or not # whether it's in current message list or not
self.indicatorUpdate(True, to_label=acct.toLabel) self.indicatorUpdate(True, to_label=acct.toLabel)
# cannot find item to pass here ):
if hasattr(acct, "feedback") \ try:
and acct.feedback != GatewayAccount.ALL_OK: if acct.feedback != GatewayAccount.ALL_OK:
if acct.feedback == GatewayAccount.REGISTRATION_DENIED: if acct.feedback == GatewayAccount.REGISTRATION_DENIED:
dialogs.EmailGatewayDialog( dialogs.EmailGatewayDialog(
self, BMConfigParser(), acct).exec_() self, BMConfigParser(), acct).exec_()
# possible other branches?
except AttributeError:
pass
def click_pushButtonAddAddressBook(self, dialog=None): def click_pushButtonAddAddressBook(self, dialog=None):
if not dialog: if not dialog:
@ -2525,17 +2600,11 @@ class MyForm(settingsmixin.SMainWindow):
if idCount == 0: if idCount == 0:
return return
font = QtGui.QFont()
font.setBold(False)
msgids = [] msgids = []
for i in range(0, idCount): for i in range(0, idCount):
msgids.append(str(tableWidget.item( msgids.append(tableWidget.item(i, 3).data())
i, 3).data(QtCore.Qt.UserRole).toPyObject())) for col in xrange(tableWidget.columnCount()):
tableWidget.item(i, 0).setUnread(False) tableWidget.item(i, col).setUnread(False)
tableWidget.item(i, 1).setUnread(False)
tableWidget.item(i, 2).setUnread(False)
tableWidget.item(i, 3).setFont(font)
markread = sqlExecuteChunked( markread = sqlExecuteChunked(
"UPDATE inbox SET read = 1 WHERE msgid IN({0}) AND read=0", "UPDATE inbox SET read = 1 WHERE msgid IN({0}) AND read=0",
@ -2603,10 +2672,8 @@ class MyForm(settingsmixin.SMainWindow):
) + "\n\n" + ) + "\n\n" +
_translate( _translate(
"MainWindow", "Wait until these tasks finish?"), "MainWindow", "Wait until these tasks finish?"),
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No | QtGui.QMessageBox.Yes | QtGui.QMessageBox.No
QtGui.QMessageBox.Cancel, | QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Cancel)
QtGui.QMessageBox.Cancel
)
if reply == QtGui.QMessageBox.No: if reply == QtGui.QMessageBox.No:
waitForPow = False waitForPow = False
elif reply == QtGui.QMessageBox.Cancel: elif reply == QtGui.QMessageBox.Cancel:
@ -2623,16 +2690,14 @@ class MyForm(settingsmixin.SMainWindow):
" synchronisation finishes?", None, " synchronisation finishes?", None,
QtCore.QCoreApplication.CodecForTr, pendingDownload() QtCore.QCoreApplication.CodecForTr, pendingDownload()
), ),
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No | QtGui.QMessageBox.Yes | QtGui.QMessageBox.No
QtGui.QMessageBox.Cancel, | QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Cancel)
QtGui.QMessageBox.Cancel
)
if reply == QtGui.QMessageBox.Yes: if reply == QtGui.QMessageBox.Yes:
self.wait = waitForSync = True self.wait = waitForSync = True
elif reply == QtGui.QMessageBox.Cancel: elif reply == QtGui.QMessageBox.Cancel:
return return
if shared.statusIconColor == 'red' and not BMConfigParser().safeGetBoolean( if state.statusIconColor == 'red' and not BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'dontconnect'): 'bitmessagesettings', 'dontconnect'):
reply = QtGui.QMessageBox.question( reply = QtGui.QMessageBox.question(
self, _translate("MainWindow", "Not connected"), self, _translate("MainWindow", "Not connected"),
@ -2642,10 +2707,8 @@ class MyForm(settingsmixin.SMainWindow):
" quit now, it may cause delivery delays. Wait until" " quit now, it may cause delivery delays. Wait until"
" connected and the synchronisation finishes?" " connected and the synchronisation finishes?"
), ),
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No | QtGui.QMessageBox.Yes | QtGui.QMessageBox.No
QtGui.QMessageBox.Cancel, | QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Cancel)
QtGui.QMessageBox.Cancel
)
if reply == QtGui.QMessageBox.Yes: if reply == QtGui.QMessageBox.Yes:
waitForConnection = True waitForConnection = True
self.wait = waitForSync = True self.wait = waitForSync = True
@ -2660,7 +2723,7 @@ class MyForm(settingsmixin.SMainWindow):
if waitForConnection: if waitForConnection:
self.updateStatusBar(_translate( self.updateStatusBar(_translate(
"MainWindow", "Waiting for network connection...")) "MainWindow", "Waiting for network connection..."))
while shared.statusIconColor == 'red': while state.statusIconColor == 'red':
time.sleep(0.5) time.sleep(0.5)
QtCore.QCoreApplication.processEvents( QtCore.QCoreApplication.processEvents(
QtCore.QEventLoop.AllEvents, 1000 QtCore.QEventLoop.AllEvents, 1000
@ -2752,6 +2815,7 @@ class MyForm(settingsmixin.SMainWindow):
QtCore.QEventLoop.AllEvents, 1000 QtCore.QEventLoop.AllEvents, 1000
) )
shutdown.doCleanShutdown() shutdown.doCleanShutdown()
self.updateStatusBar(_translate( self.updateStatusBar(_translate(
"MainWindow", "Stopping notifications... %1%").arg(90)) "MainWindow", "Stopping notifications... %1%").arg(90))
self.tray.hide() self.tray.hide()
@ -2760,20 +2824,21 @@ class MyForm(settingsmixin.SMainWindow):
"MainWindow", "Shutdown imminent... %1%").arg(100)) "MainWindow", "Shutdown imminent... %1%").arg(100))
logger.info("Shutdown complete") logger.info("Shutdown complete")
super(MyForm, myapp).close() self.close()
# return # FIXME: rewrite loops with timer instead
sys.exit() if self.wait:
self.destroy()
app.quit()
# window close event
def closeEvent(self, event): def closeEvent(self, event):
self.appIndicatorHide() """window close event"""
event.ignore()
trayonclose = BMConfigParser().safeGetBoolean( trayonclose = BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'trayonclose') 'bitmessagesettings', 'trayonclose')
if trayonclose:
event.ignore() self.appIndicatorHide()
if not trayonclose: else:
# quit the application # custom quit method
self.quit() self.quit()
def on_action_InboxMessageForceHtml(self): def on_action_InboxMessageForceHtml(self):
@ -2812,8 +2877,7 @@ class MyForm(settingsmixin.SMainWindow):
# modified = 0 # modified = 0
for row in tableWidget.selectedIndexes(): for row in tableWidget.selectedIndexes():
currentRow = row.row() currentRow = row.row()
msgid = str(tableWidget.item( msgid = tableWidget.item(currentRow, 3).data()
currentRow, 3).data(QtCore.Qt.UserRole).toPyObject())
msgids.add(msgid) msgids.add(msgid)
# if not tableWidget.item(currentRow, 0).unread: # if not tableWidget.item(currentRow, 0).unread:
# modified += 1 # modified += 1
@ -2839,13 +2903,13 @@ class MyForm(settingsmixin.SMainWindow):
# Format predefined text on message reply. # Format predefined text on message reply.
def quoted_text(self, message): def quoted_text(self, message):
if not BMConfigParser().safeGetBoolean('bitmessagesettings', 'replybelow'): if not BMConfigParser().safeGetBoolean('bitmessagesettings', 'replybelow'):
return '\n\n------------------------------------------------------\n' + message return '\n\n------------------------------------------------------\n' + message
quoteWrapper = textwrap.TextWrapper(
replace_whitespace=False, initial_indent='> ',
subsequent_indent='> ', break_long_words=False,
break_on_hyphens=False)
quoteWrapper = textwrap.TextWrapper(replace_whitespace = False,
initial_indent = '> ',
subsequent_indent = '> ',
break_long_words = False,
break_on_hyphens = False)
def quote_line(line): def quote_line(line):
# Do quote empty lines. # Do quote empty lines.
if line == '' or line.isspace(): if line == '' or line.isspace():
@ -2858,18 +2922,20 @@ class MyForm(settingsmixin.SMainWindow):
return quoteWrapper.fill(line) return quoteWrapper.fill(line)
return '\n'.join([quote_line(l) for l in message.splitlines()]) + '\n\n' return '\n'.join([quote_line(l) for l in message.splitlines()]) + '\n\n'
def setSendFromComboBox(self, address = None): def setSendFromComboBox(self, address=None):
if address is None: if address is None:
messagelist = self.getCurrentMessagelist() messagelist = self.getCurrentMessagelist()
if messagelist: if not messagelist:
currentInboxRow = messagelist.currentRow() return
address = messagelist.item( currentInboxRow = messagelist.currentRow()
currentInboxRow, 0).address address = messagelist.item(currentInboxRow, 0).address
for box in [self.ui.comboBoxSendFrom, self.ui.comboBoxSendFromBroadcast]: for box in (
listOfAddressesInComboBoxSendFrom = [str(box.itemData(i).toPyObject()) for i in range(box.count())] self.ui.comboBoxSendFrom, self.ui.comboBoxSendFromBroadcast
if address in listOfAddressesInComboBoxSendFrom: ):
currentIndex = listOfAddressesInComboBoxSendFrom.index(address) for i in range(box.count()):
box.setCurrentIndex(currentIndex) if str(box.itemData(i).toPyObject()) == address:
box.setCurrentIndex(i)
break
else: else:
box.setCurrentIndex(0) box.setCurrentIndex(0)
@ -2901,8 +2967,7 @@ class MyForm(settingsmixin.SMainWindow):
acct = accountClass(toAddressAtCurrentInboxRow) acct = accountClass(toAddressAtCurrentInboxRow)
fromAddressAtCurrentInboxRow = tableWidget.item( fromAddressAtCurrentInboxRow = tableWidget.item(
currentInboxRow, column_from).address currentInboxRow, column_from).address
msgid = str(tableWidget.item( msgid = tableWidget.item(currentInboxRow, 3).data()
currentInboxRow, 3).data(QtCore.Qt.UserRole).toPyObject())
queryreturn = sqlQuery( queryreturn = sqlQuery(
"SELECT message FROM inbox WHERE msgid=?", msgid "SELECT message FROM inbox WHERE msgid=?", msgid
) or sqlQuery("SELECT message FROM sent WHERE ackdata=?", msgid) ) or sqlQuery("SELECT message FROM sent WHERE ackdata=?", msgid)
@ -2985,7 +3050,7 @@ class MyForm(settingsmixin.SMainWindow):
quotedText = self.quoted_text( quotedText = self.quoted_text(
unicode(messageAtCurrentInboxRow, 'utf-8', 'replace')) unicode(messageAtCurrentInboxRow, 'utf-8', 'replace'))
widget['message'].setPlainText(quotedText) widget['message'].setPlainText(quotedText)
if acct.subject[0:3] in ['Re:', 'RE:']: if acct.subject[0:3] in ('Re:', 'RE:'):
widget['subject'].setText( widget['subject'].setText(
tableWidget.item(currentInboxRow, 2).label) tableWidget.item(currentInboxRow, 2).label)
else: else:
@ -3001,7 +3066,6 @@ class MyForm(settingsmixin.SMainWindow):
if not tableWidget: if not tableWidget:
return return
currentInboxRow = tableWidget.currentRow() currentInboxRow = tableWidget.currentRow()
# tableWidget.item(currentRow,1).data(Qt.UserRole).toPyObject()
addressAtCurrentInboxRow = tableWidget.item( addressAtCurrentInboxRow = tableWidget.item(
currentInboxRow, 1).data(QtCore.Qt.UserRole) currentInboxRow, 1).data(QtCore.Qt.UserRole)
self.ui.tabWidget.setCurrentIndex( self.ui.tabWidget.setCurrentIndex(
@ -3015,7 +3079,6 @@ class MyForm(settingsmixin.SMainWindow):
if not tableWidget: if not tableWidget:
return return
currentInboxRow = tableWidget.currentRow() currentInboxRow = tableWidget.currentRow()
# tableWidget.item(currentRow,1).data(Qt.UserRole).toPyObject()
addressAtCurrentInboxRow = tableWidget.item( addressAtCurrentInboxRow = tableWidget.item(
currentInboxRow, 1).data(QtCore.Qt.UserRole) currentInboxRow, 1).data(QtCore.Qt.UserRole)
recipientAddress = tableWidget.item( recipientAddress = tableWidget.item(
@ -3039,23 +3102,28 @@ class MyForm(settingsmixin.SMainWindow):
"Error: You cannot add the same address to your blacklist" "Error: You cannot add the same address to your blacklist"
" twice. Try renaming the existing one if you want.")) " twice. Try renaming the existing one if you want."))
def deleteRowFromMessagelist(self, row = None, inventoryHash = None, ackData = None, messageLists = None): def deleteRowFromMessagelist(
self, row=None, inventoryHash=None, ackData=None, messageLists=None
):
if messageLists is None: if messageLists is None:
messageLists = (self.ui.tableWidgetInbox, self.ui.tableWidgetInboxChans, self.ui.tableWidgetInboxSubscriptions) messageLists = (
self.ui.tableWidgetInbox,
self.ui.tableWidgetInboxChans,
self.ui.tableWidgetInboxSubscriptions
)
elif type(messageLists) not in (list, tuple): elif type(messageLists) not in (list, tuple):
messageLists = (messageLists) messageLists = (messageLists,)
for messageList in messageLists: for messageList in messageLists:
if row is not None: if row is not None:
inventoryHash = str(messageList.item(row, 3).data( inventoryHash = messageList.item(row, 3).data()
QtCore.Qt.UserRole).toPyObject())
messageList.removeRow(row) messageList.removeRow(row)
elif inventoryHash is not None: elif inventoryHash is not None:
for i in range(messageList.rowCount() - 1, -1, -1): for i in range(messageList.rowCount() - 1, -1, -1):
if messageList.item(i, 3).data(QtCore.Qt.UserRole).toPyObject() == inventoryHash: if messageList.item(i, 3).data() == inventoryHash:
messageList.removeRow(i) messageList.removeRow(i)
elif ackData is not None: elif ackData is not None:
for i in range(messageList.rowCount() - 1, -1, -1): for i in range(messageList.rowCount() - 1, -1, -1):
if messageList.item(i, 3).data(QtCore.Qt.UserRole).toPyObject() == ackData: if messageList.item(i, 3).data() == ackData:
messageList.removeRow(i) messageList.removeRow(i)
# Send item on the Inbox tab to trash # Send item on the Inbox tab to trash
@ -3065,20 +3133,21 @@ class MyForm(settingsmixin.SMainWindow):
return return
currentRow = 0 currentRow = 0
folder = self.getCurrentFolder() folder = self.getCurrentFolder()
shifted = QtGui.QApplication.queryKeyboardModifiers() & QtCore.Qt.ShiftModifier shifted = QtGui.QApplication.queryKeyboardModifiers() \
tableWidget.setUpdatesEnabled(False); & QtCore.Qt.ShiftModifier
inventoryHashesToTrash = [] tableWidget.setUpdatesEnabled(False)
inventoryHashesToTrash = set()
# ranges in reversed order # ranges in reversed order
for r in sorted(tableWidget.selectedRanges(), key=lambda r: r.topRow())[::-1]: for r in sorted(
for i in range(r.bottomRow()-r.topRow()+1): tableWidget.selectedRanges(), key=lambda r: r.topRow()
inventoryHashToTrash = str(tableWidget.item( )[::-1]:
r.topRow()+i, 3).data(QtCore.Qt.UserRole).toPyObject()) for i in range(r.bottomRow() - r.topRow() + 1):
if inventoryHashToTrash in inventoryHashesToTrash: inventoryHashesToTrash.add(
continue tableWidget.item(r.topRow() + i, 3).data())
inventoryHashesToTrash.append(inventoryHashToTrash)
currentRow = r.topRow() currentRow = r.topRow()
self.getCurrentMessageTextedit().setText("") self.getCurrentMessageTextedit().setText("")
tableWidget.model().removeRows(r.topRow(), r.bottomRow()-r.topRow()+1) tableWidget.model().removeRows(
r.topRow(), r.bottomRow() - r.topRow() + 1)
idCount = len(inventoryHashesToTrash) idCount = len(inventoryHashesToTrash)
sqlExecuteChunked( sqlExecuteChunked(
("DELETE FROM inbox" if folder == "trash" or shifted else ("DELETE FROM inbox" if folder == "trash" or shifted else
@ -3095,22 +3164,23 @@ class MyForm(settingsmixin.SMainWindow):
return return
currentRow = 0 currentRow = 0
tableWidget.setUpdatesEnabled(False) tableWidget.setUpdatesEnabled(False)
inventoryHashesToTrash = [] inventoryHashesToTrash = set()
# ranges in reversed order # ranges in reversed order
for r in sorted(tableWidget.selectedRanges(), key=lambda r: r.topRow())[::-1]: for r in sorted(
for i in range(r.bottomRow()-r.topRow()+1): tableWidget.selectedRanges(), key=lambda r: r.topRow()
inventoryHashToTrash = str(tableWidget.item( )[::-1]:
r.topRow()+i, 3).data(QtCore.Qt.UserRole).toPyObject()) for i in range(r.bottomRow() - r.topRow() + 1):
if inventoryHashToTrash in inventoryHashesToTrash: inventoryHashesToTrash.add(
continue tableWidget.item(r.topRow() + i, 3).data())
inventoryHashesToTrash.append(inventoryHashToTrash)
currentRow = r.topRow() currentRow = r.topRow()
self.getCurrentMessageTextedit().setText("") self.getCurrentMessageTextedit().setText("")
tableWidget.model().removeRows(r.topRow(), r.bottomRow()-r.topRow()+1) tableWidget.model().removeRows(
r.topRow(), r.bottomRow() - r.topRow() + 1)
tableWidget.selectRow(0 if currentRow == 0 else currentRow - 1) tableWidget.selectRow(0 if currentRow == 0 else currentRow - 1)
idCount = len(inventoryHashesToTrash) idCount = len(inventoryHashesToTrash)
sqlExecuteChunked('''UPDATE inbox SET folder='inbox' WHERE msgid IN({0})''', sqlExecuteChunked(
idCount, *inventoryHashesToTrash) "UPDATE inbox SET folder='inbox' WHERE msgid IN({0})",
idCount, *inventoryHashesToTrash)
tableWidget.selectRow(0 if currentRow == 0 else currentRow - 1) tableWidget.selectRow(0 if currentRow == 0 else currentRow - 1)
tableWidget.setUpdatesEnabled(True) tableWidget.setUpdatesEnabled(True)
self.propagateUnreadCount() self.propagateUnreadCount()
@ -3128,8 +3198,7 @@ class MyForm(settingsmixin.SMainWindow):
subjectAtCurrentInboxRow = '' subjectAtCurrentInboxRow = ''
# Retrieve the message data out of the SQL database # Retrieve the message data out of the SQL database
msgid = str(tableWidget.item( msgid = tableWidget.item(currentInboxRow, 3).data()
currentInboxRow, 3).data(QtCore.Qt.UserRole).toPyObject())
queryreturn = sqlQuery( queryreturn = sqlQuery(
'''select message from inbox where msgid=?''', msgid) '''select message from inbox where msgid=?''', msgid)
if queryreturn != []: if queryreturn != []:
@ -3157,8 +3226,7 @@ class MyForm(settingsmixin.SMainWindow):
shifted = QtGui.QApplication.queryKeyboardModifiers() & QtCore.Qt.ShiftModifier shifted = QtGui.QApplication.queryKeyboardModifiers() & QtCore.Qt.ShiftModifier
while tableWidget.selectedIndexes() != []: while tableWidget.selectedIndexes() != []:
currentRow = tableWidget.selectedIndexes()[0].row() currentRow = tableWidget.selectedIndexes()[0].row()
ackdataToTrash = str(tableWidget.item( ackdataToTrash = tableWidget.item(currentRow, 3).data()
currentRow, 3).data(QtCore.Qt.UserRole).toPyObject())
sqlExecute( sqlExecute(
"DELETE FROM sent" if folder == "trash" or shifted else "DELETE FROM sent" if folder == "trash" or shifted else
"UPDATE sent SET folder='trash'" "UPDATE sent SET folder='trash'"
@ -3381,13 +3449,13 @@ class MyForm(settingsmixin.SMainWindow):
return None return None
def getCurrentTreeWidget(self): def getCurrentTreeWidget(self):
currentIndex = self.ui.tabWidget.currentIndex(); currentIndex = self.ui.tabWidget.currentIndex()
treeWidgetList = [ treeWidgetList = (
self.ui.treeWidgetYourIdentities, self.ui.treeWidgetYourIdentities,
False, False,
self.ui.treeWidgetSubscriptions, self.ui.treeWidgetSubscriptions,
self.ui.treeWidgetChans self.ui.treeWidgetChans
] )
if currentIndex >= 0 and currentIndex < len(treeWidgetList): if currentIndex >= 0 and currentIndex < len(treeWidgetList):
return treeWidgetList[currentIndex] return treeWidgetList[currentIndex]
else: else:
@ -3405,17 +3473,15 @@ class MyForm(settingsmixin.SMainWindow):
return self.ui.treeWidgetYourIdentities return self.ui.treeWidgetYourIdentities
def getCurrentMessagelist(self): def getCurrentMessagelist(self):
currentIndex = self.ui.tabWidget.currentIndex(); currentIndex = self.ui.tabWidget.currentIndex()
messagelistList = [ messagelistList = (
self.ui.tableWidgetInbox, self.ui.tableWidgetInbox,
False, False,
self.ui.tableWidgetInboxSubscriptions, self.ui.tableWidgetInboxSubscriptions,
self.ui.tableWidgetInboxChans, self.ui.tableWidgetInboxChans,
] )
if currentIndex >= 0 and currentIndex < len(messagelistList): if currentIndex >= 0 and currentIndex < len(messagelistList):
return messagelistList[currentIndex] return messagelistList[currentIndex]
else:
return False
def getAccountMessagelist(self, account): def getAccountMessagelist(self, account):
try: try:
@ -3433,24 +3499,18 @@ class MyForm(settingsmixin.SMainWindow):
if messagelist: if messagelist:
currentRow = messagelist.currentRow() currentRow = messagelist.currentRow()
if currentRow >= 0: if currentRow >= 0:
msgid = str(messagelist.item( return messagelist.item(currentRow, 3).data()
currentRow, 3).data(QtCore.Qt.UserRole).toPyObject())
# data is saved at the 4. column of the table...
return msgid
return False
def getCurrentMessageTextedit(self): def getCurrentMessageTextedit(self):
currentIndex = self.ui.tabWidget.currentIndex() currentIndex = self.ui.tabWidget.currentIndex()
messagelistList = [ messagelistList = (
self.ui.textEditInboxMessage, self.ui.textEditInboxMessage,
False, False,
self.ui.textEditInboxMessageSubscriptions, self.ui.textEditInboxMessageSubscriptions,
self.ui.textEditInboxMessageChans, self.ui.textEditInboxMessageChans,
] )
if currentIndex >= 0 and currentIndex < len(messagelistList): if currentIndex >= 0 and currentIndex < len(messagelistList):
return messagelistList[currentIndex] return messagelistList[currentIndex]
else:
return False
def getAccountTextedit(self, account): def getAccountTextedit(self, account):
try: try:
@ -3466,33 +3526,28 @@ class MyForm(settingsmixin.SMainWindow):
def getCurrentSearchLine(self, currentIndex=None, retObj=False): def getCurrentSearchLine(self, currentIndex=None, retObj=False):
if currentIndex is None: if currentIndex is None:
currentIndex = self.ui.tabWidget.currentIndex() currentIndex = self.ui.tabWidget.currentIndex()
messagelistList = [ messagelistList = (
self.ui.inboxSearchLineEdit, self.ui.inboxSearchLineEdit,
False, False,
self.ui.inboxSearchLineEditSubscriptions, self.ui.inboxSearchLineEditSubscriptions,
self.ui.inboxSearchLineEditChans, self.ui.inboxSearchLineEditChans,
] )
if currentIndex >= 0 and currentIndex < len(messagelistList): if currentIndex >= 0 and currentIndex < len(messagelistList):
if retObj: return (
return messagelistList[currentIndex] messagelistList[currentIndex] if retObj
else: else messagelistList[currentIndex].text().toUtf8().data())
return messagelistList[currentIndex].text().toUtf8().data()
else:
return None
def getCurrentSearchOption(self, currentIndex=None): def getCurrentSearchOption(self, currentIndex=None):
if currentIndex is None: if currentIndex is None:
currentIndex = self.ui.tabWidget.currentIndex() currentIndex = self.ui.tabWidget.currentIndex()
messagelistList = [ messagelistList = (
self.ui.inboxSearchOption, self.ui.inboxSearchOption,
False, False,
self.ui.inboxSearchOptionSubscriptions, self.ui.inboxSearchOptionSubscriptions,
self.ui.inboxSearchOptionChans, self.ui.inboxSearchOptionChans,
] )
if currentIndex >= 0 and currentIndex < len(messagelistList): if currentIndex >= 0 and currentIndex < len(messagelistList):
return messagelistList[currentIndex].currentText().toUtf8().data() return messagelistList[currentIndex].currentText()
else:
return None
# Group of functions for the Your Identities dialog box # Group of functions for the Your Identities dialog box
def getCurrentItem(self, treeWidget=None): def getCurrentItem(self, treeWidget=None):
@ -3596,12 +3651,11 @@ class MyForm(settingsmixin.SMainWindow):
tableWidget = self.getCurrentMessagelist() tableWidget = self.getCurrentMessagelist()
currentColumn = tableWidget.currentColumn() currentColumn = tableWidget.currentColumn()
currentRow = tableWidget.currentRow() currentRow = tableWidget.currentRow()
if currentColumn not in [0, 1, 2]: # to, from, subject currentFolder = self.getCurrentFolder()
if self.getCurrentFolder() == "sent": if currentColumn not in (0, 1, 2): # to, from, subject
currentColumn = 0 currentColumn = 0 if currentFolder == "sent" else 1
else:
currentColumn = 1 if currentFolder == "sent":
if self.getCurrentFolder() == "sent":
myAddress = tableWidget.item(currentRow, 1).data(QtCore.Qt.UserRole) myAddress = tableWidget.item(currentRow, 1).data(QtCore.Qt.UserRole)
otherAddress = tableWidget.item(currentRow, 0).data(QtCore.Qt.UserRole) otherAddress = tableWidget.item(currentRow, 0).data(QtCore.Qt.UserRole)
else: else:
@ -3614,11 +3668,11 @@ class MyForm(settingsmixin.SMainWindow):
text = str(tableWidget.item(currentRow, currentColumn).label) text = str(tableWidget.item(currentRow, currentColumn).label)
else: else:
text = tableWidget.item(currentRow, currentColumn).data(QtCore.Qt.UserRole) text = tableWidget.item(currentRow, currentColumn).data(QtCore.Qt.UserRole)
text = unicode(str(text), 'utf-8', 'ignore')
clipboard = QtGui.QApplication.clipboard() clipboard = QtGui.QApplication.clipboard()
clipboard.setText(text) clipboard.setText(text)
#set avatar functions # set avatar functions
def on_action_TreeWidgetSetAvatar(self): def on_action_TreeWidgetSetAvatar(self):
address = self.getCurrentAccount() address = self.getCurrentAccount()
self.setAvatar(address) self.setAvatar(address)
@ -3635,19 +3689,36 @@ class MyForm(settingsmixin.SMainWindow):
thisTableWidget.item( thisTableWidget.item(
currentRow, 0).setIcon(avatarize(addressAtCurrentRow)) currentRow, 0).setIcon(avatarize(addressAtCurrentRow))
# TODO: reuse utils
def setAvatar(self, addressAtCurrentRow): def setAvatar(self, addressAtCurrentRow):
if not os.path.exists(state.appdata + 'avatars/'): if not os.path.exists(state.appdata + 'avatars/'):
os.makedirs(state.appdata + 'avatars/') os.makedirs(state.appdata + 'avatars/')
hash = hashlib.md5(addBMIfNotPresent(addressAtCurrentRow)).hexdigest() hash = hashlib.md5(addBMIfNotPresent(addressAtCurrentRow)).hexdigest()
extensions = ['PNG', 'GIF', 'JPG', 'JPEG', 'SVG', 'BMP', 'MNG', 'PBM', 'PGM', 'PPM', 'TIFF', 'XBM', 'XPM', 'TGA'] extensions = [
# http://pyqt.sourceforge.net/Docs/PyQt4/qimagereader.html#supportedImageFormats 'PNG', 'GIF', 'JPG', 'JPEG', 'SVG', 'BMP', 'MNG', 'PBM',
names = {'BMP':'Windows Bitmap', 'GIF':'Graphic Interchange Format', 'JPG':'Joint Photographic Experts Group', 'JPEG':'Joint Photographic Experts Group', 'MNG':'Multiple-image Network Graphics', 'PNG':'Portable Network Graphics', 'PBM':'Portable Bitmap', 'PGM':'Portable Graymap', 'PPM':'Portable Pixmap', 'TIFF':'Tagged Image File Format', 'XBM':'X11 Bitmap', 'XPM':'X11 Pixmap', 'SVG':'Scalable Vector Graphics', 'TGA':'Targa Image Format'} 'PGM', 'PPM', 'TIFF', 'XBM', 'XPM', 'TGA']
names = {
'BMP': 'Windows Bitmap',
'GIF': 'Graphic Interchange Format',
'JPG': 'Joint Photographic Experts Group',
'JPEG': 'Joint Photographic Experts Group',
'MNG': 'Multiple-image Network Graphics',
'PNG': 'Portable Network Graphics',
'PBM': 'Portable Bitmap',
'PGM': 'Portable Graymap',
'PPM': 'Portable Pixmap',
'TIFF': 'Tagged Image File Format',
'XBM': 'X11 Bitmap',
'XPM': 'X11 Pixmap',
'SVG': 'Scalable Vector Graphics',
'TGA': 'Targa Image Format'}
filters = [] filters = []
all_images_filter = [] all_images_filter = []
current_files = [] current_files = []
for ext in extensions: for ext in extensions:
filters += [ names[ext] + ' (*.' + ext.lower() + ')' ] filters += [names[ext] + ' (*.' + ext.lower() + ')']
all_images_filter += [ '*.' + ext.lower() ] all_images_filter += ['*.' + ext.lower()]
upper = state.appdata + 'avatars/' + hash + '.' + ext.upper() upper = state.appdata + 'avatars/' + hash + '.' + ext.upper()
lower = state.appdata + 'avatars/' + hash + '.' + ext.lower() lower = state.appdata + 'avatars/' + hash + '.' + ext.lower()
if os.path.isfile(lower): if os.path.isfile(lower):
@ -3658,25 +3729,31 @@ class MyForm(settingsmixin.SMainWindow):
filters[1:1] = ['All files (*.*)'] filters[1:1] = ['All files (*.*)']
sourcefile = QtGui.QFileDialog.getOpenFileName( sourcefile = QtGui.QFileDialog.getOpenFileName(
self, _translate("MainWindow", "Set avatar..."), self, _translate("MainWindow", "Set avatar..."),
filter = ';;'.join(filters) filter=';;'.join(filters)
) )
# determine the correct filename (note that avatars don't use the suffix) # determine the correct filename (note that avatars don't use the suffix)
destination = state.appdata + 'avatars/' + hash + '.' + sourcefile.split('.')[-1] destination = state.appdata + 'avatars/' + hash + '.' + sourcefile.split('.')[-1]
exists = QtCore.QFile.exists(destination) exists = QtCore.QFile.exists(destination)
if sourcefile == '': if sourcefile == '':
# ask for removal of avatar # ask for removal of avatar
if exists | (len(current_files)>0): if exists | (len(current_files) > 0):
displayMsg = _translate("MainWindow", "Do you really want to remove this avatar?") displayMsg = _translate(
"MainWindow", "Do you really want to remove this avatar?")
overwrite = QtGui.QMessageBox.question( overwrite = QtGui.QMessageBox.question(
self, 'Message', displayMsg, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) self, 'Message', displayMsg,
QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
else: else:
overwrite = QtGui.QMessageBox.No overwrite = QtGui.QMessageBox.No
else: else:
# ask whether to overwrite old avatar # ask whether to overwrite old avatar
if exists | (len(current_files)>0): if exists | (len(current_files) > 0):
displayMsg = _translate("MainWindow", "You have already set an avatar for this address. Do you really want to overwrite it?") displayMsg = _translate(
"MainWindow",
"You have already set an avatar for this address."
" Do you really want to overwrite it?")
overwrite = QtGui.QMessageBox.question( overwrite = QtGui.QMessageBox.question(
self, 'Message', displayMsg, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) self, 'Message', displayMsg,
QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
else: else:
overwrite = QtGui.QMessageBox.No overwrite = QtGui.QMessageBox.No
@ -3865,8 +3942,7 @@ class MyForm(settingsmixin.SMainWindow):
# Check to see if this item is toodifficult and display an additional # Check to see if this item is toodifficult and display an additional
# menu option (Force Send) if it is. # menu option (Force Send) if it is.
if currentRow >= 0: if currentRow >= 0:
ackData = str(self.ui.tableWidgetInbox.item( ackData = self.ui.tableWidgetInbox.item(currentRow, 3).data()
currentRow, 3).data(QtCore.Qt.UserRole).toPyObject())
queryreturn = sqlQuery('''SELECT status FROM sent where ackdata=?''', ackData) queryreturn = sqlQuery('''SELECT status FROM sent where ackdata=?''', ackData)
for row in queryreturn: for row in queryreturn:
status, = row status, = row
@ -3877,25 +3953,27 @@ class MyForm(settingsmixin.SMainWindow):
def inboxSearchLineEditUpdated(self, text): def inboxSearchLineEditUpdated(self, text):
# dynamic search for too short text is slow # dynamic search for too short text is slow
if len(str(text)) < 3: text = text.toUtf8()
if 0 < len(text) < 3:
return return
messagelist = self.getCurrentMessagelist() messagelist = self.getCurrentMessagelist()
searchOption = self.getCurrentSearchOption()
if messagelist: if messagelist:
searchOption = self.getCurrentSearchOption()
account = self.getCurrentAccount() account = self.getCurrentAccount()
folder = self.getCurrentFolder() folder = self.getCurrentFolder()
self.loadMessagelist(messagelist, account, folder, searchOption, str(text)) self.loadMessagelist(
messagelist, account, folder, searchOption, text)
def inboxSearchLineEditReturnPressed(self): def inboxSearchLineEditReturnPressed(self):
logger.debug("Search return pressed") logger.debug("Search return pressed")
searchLine = self.getCurrentSearchLine() searchLine = self.getCurrentSearchLine()
messagelist = self.getCurrentMessagelist() messagelist = self.getCurrentMessagelist()
if len(str(searchLine)) < 3: if messagelist and len(str(searchLine)) < 3:
searchOption = self.getCurrentSearchOption() searchOption = self.getCurrentSearchOption()
account = self.getCurrentAccount() account = self.getCurrentAccount()
folder = self.getCurrentFolder() folder = self.getCurrentFolder()
self.loadMessagelist(messagelist, account, folder, searchOption, searchLine) self.loadMessagelist(
if messagelist: messagelist, account, folder, searchOption, searchLine)
messagelist.setFocus() messagelist.setFocus()
def treeWidgetItemClicked(self): def treeWidgetItemClicked(self):
@ -3921,7 +3999,7 @@ class MyForm(settingsmixin.SMainWindow):
if (not isinstance(item, Ui_AddressWidget)) or (not self.getCurrentTreeWidget()) or self.getCurrentTreeWidget().currentItem() is None: if (not isinstance(item, Ui_AddressWidget)) or (not self.getCurrentTreeWidget()) or self.getCurrentTreeWidget().currentItem() is None:
return return
# not visible # not visible
if (not self.getCurrentItem()) or (not isinstance (self.getCurrentItem(), Ui_AddressWidget)): if (not self.getCurrentItem()) or (not isinstance(self.getCurrentItem(), Ui_AddressWidget)):
return return
# only currently selected item # only currently selected item
if item.address != self.getCurrentAccount(): if item.address != self.getCurrentAccount():
@ -3954,12 +4032,12 @@ class MyForm(settingsmixin.SMainWindow):
self.recurDepth -= 1 self.recurDepth -= 1
def tableWidgetInboxItemClicked(self): def tableWidgetInboxItemClicked(self):
folder = self.getCurrentFolder()
messageTextedit = self.getCurrentMessageTextedit() messageTextedit = self.getCurrentMessageTextedit()
if not messageTextedit: if not messageTextedit:
return return
msgid = self.getCurrentMessageId() msgid = self.getCurrentMessageId()
folder = self.getCurrentFolder()
if msgid: if msgid:
queryreturn = sqlQuery( queryreturn = sqlQuery(
'''SELECT message FROM %s WHERE %s=?''' % ( '''SELECT message FROM %s WHERE %s=?''' % (
@ -4020,12 +4098,15 @@ class MyForm(settingsmixin.SMainWindow):
self.rerenderAddressBook() self.rerenderAddressBook()
def updateStatusBar(self, data): def updateStatusBar(self, data):
if type(data) is tuple or type(data) is list: try:
option = data[1] option, message = data
message = data[0] except ValueError:
else:
option = 0 option = 0
message = data message = data
except TypeError:
logger.debug(
'Invalid argument for updateStatusBar!', exc_info=True)
if message != "": if message != "":
logger.info('Status bar: ' + message) logger.info('Status bar: ' + message)
@ -4041,19 +4122,16 @@ class MyForm(settingsmixin.SMainWindow):
# Check to see whether we can connect to namecoin. # Check to see whether we can connect to namecoin.
# Hide the 'Fetch Namecoin ID' button if we can't. # Hide the 'Fetch Namecoin ID' button if we can't.
if BMConfigParser().safeGetBoolean( if BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'dontconnect' 'bitmessagesettings', 'dontconnect'
) or self.namecoin.test()[0] == 'failed': ) or self.namecoin.test()[0] == 'failed':
logger.warning( logger.warning(
'There was a problem testing for a Namecoin daemon. Hiding the' 'There was a problem testing for a Namecoin daemon.'
' Fetch Namecoin ID button') ' Hiding the Fetch Namecoin ID button')
self.ui.pushButtonFetchNamecoinID.hide() self.ui.pushButtonFetchNamecoinID.hide()
else: else:
self.ui.pushButtonFetchNamecoinID.show() self.ui.pushButtonFetchNamecoinID.show()
def initSettings(self): def initSettings(self):
QtCore.QCoreApplication.setOrganizationName("PyBitmessage")
QtCore.QCoreApplication.setOrganizationDomain("bitmessage.org")
QtCore.QCoreApplication.setApplicationName("pybitmessageqt")
self.loadSettings() self.loadSettings()
for attr, obj in self.ui.__dict__.iteritems(): for attr, obj in self.ui.__dict__.iteritems():
if hasattr(obj, "__class__") and \ if hasattr(obj, "__class__") and \
@ -4063,20 +4141,11 @@ class MyForm(settingsmixin.SMainWindow):
obj.loadSettings() obj.loadSettings()
# In order for the time columns on the Inbox and Sent tabs to be sorted
# correctly (rather than alphabetically), we need to overload the <
# operator and use this class instead of QTableWidgetItem.
class myTableWidgetItem(QtGui.QTableWidgetItem):
def __lt__(self, other):
return int(self.data(33).toPyObject()) < int(other.data(33).toPyObject())
app = None app = None
myapp = None myapp = None
class MySingleApplication(QtGui.QApplication): class BitmessageQtApplication(QtGui.QApplication):
""" """
Listener to allow our Qt form to get focus when another instance of the Listener to allow our Qt form to get focus when another instance of the
application is open. application is open.
@ -4089,8 +4158,12 @@ class MySingleApplication(QtGui.QApplication):
uuid = '6ec0149b-96e1-4be1-93ab-1465fb3ebf7c' uuid = '6ec0149b-96e1-4be1-93ab-1465fb3ebf7c'
def __init__(self, *argv): def __init__(self, *argv):
super(MySingleApplication, self).__init__(*argv) super(BitmessageQtApplication, self).__init__(*argv)
id = MySingleApplication.uuid id = BitmessageQtApplication.uuid
QtCore.QCoreApplication.setOrganizationName("PyBitmessage")
QtCore.QCoreApplication.setOrganizationDomain("bitmessage.org")
QtCore.QCoreApplication.setApplicationName("pybitmessageqt")
self.server = None self.server = None
self.is_running = False self.is_running = False
@ -4118,6 +4191,8 @@ class MySingleApplication(QtGui.QApplication):
self.server.listen(id) self.server.listen(id)
self.server.newConnection.connect(self.on_new_connection) self.server.newConnection.connect(self.on_new_connection)
self.setStyleSheet("QStatusBar::item { border: 0px solid black }")
def __del__(self): def __del__(self):
if self.server: if self.server:
self.server.close() self.server.close()
@ -4130,25 +4205,19 @@ class MySingleApplication(QtGui.QApplication):
def init(): def init():
global app global app
if not app: if not app:
app = MySingleApplication(sys.argv) app = BitmessageQtApplication(sys.argv)
return app return app
def run(): def run():
global myapp global myapp
app = init() app = init()
app.setStyleSheet("QStatusBar::item { border: 0px solid black }")
myapp = MyForm() myapp = MyForm()
myapp.sqlInit()
myapp.appIndicatorInit(app) myapp.appIndicatorInit(app)
myapp.indicatorInit()
myapp.notifierInit()
myapp._firstrun = BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'dontconnect')
if myapp._firstrun: if myapp._firstrun:
myapp.showConnectDialog() # ask the user if we may connect myapp.showConnectDialog() # ask the user if we may connect
myapp.ui.updateNetworkSwitchMenuLabel()
# try: # try:
# if BMConfigParser().get('bitmessagesettings', 'mailchuck') < 1: # if BMConfigParser().get('bitmessagesettings', 'mailchuck') < 1:
@ -4160,4 +4229,4 @@ def run():
if not BMConfigParser().getboolean('bitmessagesettings', 'startintray'): if not BMConfigParser().getboolean('bitmessagesettings', 'startintray'):
myapp.show() myapp.show()
sys.exit(app.exec_()) app.exec_()

View File

@ -1,9 +1,7 @@
""" """
src/bitmessageqt/address_dialogs.py Dialogs that work with BM address.
===================================
""" """
# pylint: disable=attribute-defined-outside-init # pylint: disable=attribute-defined-outside-init,too-few-public-methods,relative-import
import hashlib import hashlib
@ -14,13 +12,11 @@ import widgets
from account import AccountMixin, GatewayAccount, MailchuckAccount, accountClass, getSortedAccounts from account import AccountMixin, GatewayAccount, MailchuckAccount, accountClass, getSortedAccounts
from addresses import addBMIfNotPresent, decodeAddress, encodeVarint from addresses import addBMIfNotPresent, decodeAddress, encodeVarint
from inventory import Inventory from inventory import Inventory
from retranslateui import RetranslateMixin
from tr import _translate from tr import _translate
class AddressCheckMixin(object): class AddressCheckMixin(object):
"""Base address validation class for QT UI""" """Base address validation class for QT UI"""
# pylint: disable=too-few-public-methods
def __init__(self): def __init__(self):
self.valid = False self.valid = False
@ -33,7 +29,9 @@ class AddressCheckMixin(object):
pass pass
def addressChanged(self, QString): def addressChanged(self, QString):
"""Address validation callback, performs validation and gives feedback""" """
Address validation callback, performs validation and gives feedback
"""
status, addressVersion, streamNumber, ripe = decodeAddress( status, addressVersion, streamNumber, ripe = decodeAddress(
str(QString)) str(QString))
self.valid = status == 'success' self.valid = status == 'success'
@ -102,8 +100,8 @@ class AddressDataDialog(QtGui.QDialog, AddressCheckMixin):
super(AddressDataDialog, self).accept() super(AddressDataDialog, self).accept()
class AddAddressDialog(AddressDataDialog, RetranslateMixin): class AddAddressDialog(AddressDataDialog):
"""QDialog for adding a new address, with validation and translation""" """QDialog for adding a new address"""
def __init__(self, parent=None, address=None): def __init__(self, parent=None, address=None):
super(AddAddressDialog, self).__init__(parent) super(AddAddressDialog, self).__init__(parent)
@ -113,8 +111,8 @@ class AddAddressDialog(AddressDataDialog, RetranslateMixin):
self.lineEditAddress.setText(address) self.lineEditAddress.setText(address)
class NewAddressDialog(QtGui.QDialog, RetranslateMixin): class NewAddressDialog(QtGui.QDialog):
"""QDialog for generating a new address, with translation""" """QDialog for generating a new address"""
def __init__(self, parent=None): def __init__(self, parent=None):
super(NewAddressDialog, self).__init__(parent) super(NewAddressDialog, self).__init__(parent)
@ -175,8 +173,8 @@ class NewAddressDialog(QtGui.QDialog, RetranslateMixin):
)) ))
class NewSubscriptionDialog(AddressDataDialog, RetranslateMixin): class NewSubscriptionDialog(AddressDataDialog):
"""QDialog for subscribing to an address, with validation and translation""" """QDialog for subscribing to an address"""
def __init__(self, parent=None): def __init__(self, parent=None):
super(NewSubscriptionDialog, self).__init__(parent) super(NewSubscriptionDialog, self).__init__(parent)
@ -193,8 +191,8 @@ class NewSubscriptionDialog(AddressDataDialog, RetranslateMixin):
else: else:
Inventory().flush() Inventory().flush()
doubleHashOfAddressData = hashlib.sha512(hashlib.sha512( doubleHashOfAddressData = hashlib.sha512(hashlib.sha512(
encodeVarint(addressVersion) + encodeVarint(addressVersion)
encodeVarint(streamNumber) + ripe + encodeVarint(streamNumber) + ripe
).digest()).digest() ).digest()).digest()
tag = doubleHashOfAddressData[32:] tag = doubleHashOfAddressData[32:]
self.recent = Inventory().by_type_and_tag(3, tag) self.recent = Inventory().by_type_and_tag(3, tag)
@ -218,8 +216,8 @@ class NewSubscriptionDialog(AddressDataDialog, RetranslateMixin):
)) ))
class RegenerateAddressesDialog(QtGui.QDialog, RetranslateMixin): class RegenerateAddressesDialog(QtGui.QDialog):
"""QDialog for regenerating deterministic addresses, with translation""" """QDialog for regenerating deterministic addresses"""
def __init__(self, parent=None): def __init__(self, parent=None):
super(RegenerateAddressesDialog, self).__init__(parent) super(RegenerateAddressesDialog, self).__init__(parent)
widgets.load('regenerateaddresses.ui', self) widgets.load('regenerateaddresses.ui', self)
@ -227,8 +225,10 @@ class RegenerateAddressesDialog(QtGui.QDialog, RetranslateMixin):
QtGui.QWidget.resize(self, QtGui.QWidget.sizeHint(self)) QtGui.QWidget.resize(self, QtGui.QWidget.sizeHint(self))
class SpecialAddressBehaviorDialog(QtGui.QDialog, RetranslateMixin): class SpecialAddressBehaviorDialog(QtGui.QDialog):
"""QDialog for special address behaviour (e.g. mailing list functionality), with translation""" """
QDialog for special address behaviour (e.g. mailing list functionality)
"""
def __init__(self, parent=None, config=None): def __init__(self, parent=None, config=None):
super(SpecialAddressBehaviorDialog, self).__init__(parent) super(SpecialAddressBehaviorDialog, self).__init__(parent)
@ -256,11 +256,7 @@ class SpecialAddressBehaviorDialog(QtGui.QDialog, RetranslateMixin):
self.radioButtonBehaviorMailingList.click() self.radioButtonBehaviorMailingList.click()
else: else:
self.radioButtonBehaveNormalAddress.click() self.radioButtonBehaveNormalAddress.click()
try: mailingListName = config.safeGet(self.address, 'mailinglistname', '')
mailingListName = config.get(
self.address, 'mailinglistname')
except:
mailingListName = ''
self.lineEditMailingListName.setText( self.lineEditMailingListName.setText(
unicode(mailingListName, 'utf-8') unicode(mailingListName, 'utf-8')
) )
@ -294,8 +290,8 @@ class SpecialAddressBehaviorDialog(QtGui.QDialog, RetranslateMixin):
self.parent.rerenderMessagelistToLabels() self.parent.rerenderMessagelistToLabels()
class EmailGatewayDialog(QtGui.QDialog, RetranslateMixin): class EmailGatewayDialog(QtGui.QDialog):
"""QDialog for email gateway control, with translation""" """QDialog for email gateway control"""
def __init__(self, parent, config=None, account=None): def __init__(self, parent, config=None, account=None):
super(EmailGatewayDialog, self).__init__(parent) super(EmailGatewayDialog, self).__init__(parent)
widgets.load('emailgateway.ui', self) widgets.load('emailgateway.ui', self)

View File

@ -104,6 +104,7 @@ class Ui_MainWindow(object):
self.inboxSearchOption.addItem(_fromUtf8("")) self.inboxSearchOption.addItem(_fromUtf8(""))
self.inboxSearchOption.addItem(_fromUtf8("")) self.inboxSearchOption.addItem(_fromUtf8(""))
self.inboxSearchOption.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents) self.inboxSearchOption.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents)
self.inboxSearchOption.setCurrentIndex(3)
self.horizontalSplitterSearch.addWidget(self.inboxSearchOption) self.horizontalSplitterSearch.addWidget(self.inboxSearchOption)
self.horizontalSplitterSearch.handle(1).setEnabled(False) self.horizontalSplitterSearch.handle(1).setEnabled(False)
self.horizontalSplitterSearch.setStretchFactor(0, 1) self.horizontalSplitterSearch.setStretchFactor(0, 1)
@ -403,8 +404,8 @@ class Ui_MainWindow(object):
self.inboxSearchOptionSubscriptions.addItem(_fromUtf8("")) self.inboxSearchOptionSubscriptions.addItem(_fromUtf8(""))
self.inboxSearchOptionSubscriptions.addItem(_fromUtf8("")) self.inboxSearchOptionSubscriptions.addItem(_fromUtf8(""))
self.inboxSearchOptionSubscriptions.addItem(_fromUtf8("")) self.inboxSearchOptionSubscriptions.addItem(_fromUtf8(""))
self.inboxSearchOptionSubscriptions.addItem(_fromUtf8(""))
self.inboxSearchOptionSubscriptions.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents) self.inboxSearchOptionSubscriptions.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents)
self.inboxSearchOptionSubscriptions.setCurrentIndex(2)
self.horizontalSplitter_2.addWidget(self.inboxSearchOptionSubscriptions) self.horizontalSplitter_2.addWidget(self.inboxSearchOptionSubscriptions)
self.horizontalSplitter_2.handle(1).setEnabled(False) self.horizontalSplitter_2.handle(1).setEnabled(False)
self.horizontalSplitter_2.setStretchFactor(0, 1) self.horizontalSplitter_2.setStretchFactor(0, 1)
@ -504,6 +505,7 @@ class Ui_MainWindow(object):
self.inboxSearchOptionChans.addItem(_fromUtf8("")) self.inboxSearchOptionChans.addItem(_fromUtf8(""))
self.inboxSearchOptionChans.addItem(_fromUtf8("")) self.inboxSearchOptionChans.addItem(_fromUtf8(""))
self.inboxSearchOptionChans.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents) self.inboxSearchOptionChans.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToContents)
self.inboxSearchOptionChans.setCurrentIndex(3)
self.horizontalSplitter_6.addWidget(self.inboxSearchOptionChans) self.horizontalSplitter_6.addWidget(self.inboxSearchOptionChans)
self.horizontalSplitter_6.handle(1).setEnabled(False) self.horizontalSplitter_6.handle(1).setEnabled(False)
self.horizontalSplitter_6.setStretchFactor(0, 1) self.horizontalSplitter_6.setStretchFactor(0, 1)
@ -719,10 +721,9 @@ class Ui_MainWindow(object):
self.pushButtonAddSubscription.setText(_translate("MainWindow", "Add new Subscription", None)) self.pushButtonAddSubscription.setText(_translate("MainWindow", "Add new Subscription", None))
self.inboxSearchLineEditSubscriptions.setPlaceholderText(_translate("MainWindow", "Search", None)) self.inboxSearchLineEditSubscriptions.setPlaceholderText(_translate("MainWindow", "Search", None))
self.inboxSearchOptionSubscriptions.setItemText(0, _translate("MainWindow", "All", None)) self.inboxSearchOptionSubscriptions.setItemText(0, _translate("MainWindow", "All", None))
self.inboxSearchOptionSubscriptions.setItemText(1, _translate("MainWindow", "To", None)) self.inboxSearchOptionSubscriptions.setItemText(1, _translate("MainWindow", "From", None))
self.inboxSearchOptionSubscriptions.setItemText(2, _translate("MainWindow", "From", None)) self.inboxSearchOptionSubscriptions.setItemText(2, _translate("MainWindow", "Subject", None))
self.inboxSearchOptionSubscriptions.setItemText(3, _translate("MainWindow", "Subject", None)) self.inboxSearchOptionSubscriptions.setItemText(3, _translate("MainWindow", "Message", None))
self.inboxSearchOptionSubscriptions.setItemText(4, _translate("MainWindow", "Message", None))
self.tableWidgetInboxSubscriptions.setSortingEnabled(True) self.tableWidgetInboxSubscriptions.setSortingEnabled(True)
item = self.tableWidgetInboxSubscriptions.horizontalHeaderItem(0) item = self.tableWidgetInboxSubscriptions.horizontalHeaderItem(0)
item.setText(_translate("MainWindow", "To", None)) item.setText(_translate("MainWindow", "To", None))
@ -770,6 +771,8 @@ class Ui_MainWindow(object):
self.actionRegenerateDeterministicAddresses.setText(_translate("MainWindow", "Regenerate deterministic addresses", None)) self.actionRegenerateDeterministicAddresses.setText(_translate("MainWindow", "Regenerate deterministic addresses", None))
self.actionDeleteAllTrashedMessages.setText(_translate("MainWindow", "Delete all trashed messages", None)) self.actionDeleteAllTrashedMessages.setText(_translate("MainWindow", "Delete all trashed messages", None))
self.actionJoinChan.setText(_translate("MainWindow", "Join / Create chan", None)) self.actionJoinChan.setText(_translate("MainWindow", "Join / Create chan", None))
self.updateNetworkSwitchMenuLabel()
import bitmessage_icons_rc import bitmessage_icons_rc

View File

@ -13,7 +13,6 @@ from address_dialogs import (
SpecialAddressBehaviorDialog SpecialAddressBehaviorDialog
) )
from newchandialog import NewChanDialog from newchandialog import NewChanDialog
from retranslateui import RetranslateMixin
from settings import SettingsDialog from settings import SettingsDialog
from tr import _translate from tr import _translate
from version import softwareVersion from version import softwareVersion
@ -27,7 +26,7 @@ __all__ = [
] ]
class AboutDialog(QtGui.QDialog, RetranslateMixin): class AboutDialog(QtGui.QDialog):
"""The `About` dialog""" """The `About` dialog"""
def __init__(self, parent=None): def __init__(self, parent=None):
super(AboutDialog, self).__init__(parent) super(AboutDialog, self).__init__(parent)
@ -55,7 +54,7 @@ class AboutDialog(QtGui.QDialog, RetranslateMixin):
self.setFixedSize(QtGui.QWidget.sizeHint(self)) self.setFixedSize(QtGui.QWidget.sizeHint(self))
class IconGlossaryDialog(QtGui.QDialog, RetranslateMixin): class IconGlossaryDialog(QtGui.QDialog):
"""The `Icon Glossary` dialog, explaining the status icon colors""" """The `Icon Glossary` dialog, explaining the status icon colors"""
def __init__(self, parent=None, config=None): def __init__(self, parent=None, config=None):
super(IconGlossaryDialog, self).__init__(parent) super(IconGlossaryDialog, self).__init__(parent)
@ -71,7 +70,7 @@ class IconGlossaryDialog(QtGui.QDialog, RetranslateMixin):
self.setFixedSize(QtGui.QWidget.sizeHint(self)) self.setFixedSize(QtGui.QWidget.sizeHint(self))
class HelpDialog(QtGui.QDialog, RetranslateMixin): class HelpDialog(QtGui.QDialog):
"""The `Help` dialog""" """The `Help` dialog"""
def __init__(self, parent=None): def __init__(self, parent=None):
super(HelpDialog, self).__init__(parent) super(HelpDialog, self).__init__(parent)
@ -79,7 +78,7 @@ class HelpDialog(QtGui.QDialog, RetranslateMixin):
self.setFixedSize(QtGui.QWidget.sizeHint(self)) self.setFixedSize(QtGui.QWidget.sizeHint(self))
class ConnectDialog(QtGui.QDialog, RetranslateMixin): class ConnectDialog(QtGui.QDialog):
"""The `Connect` dialog""" """The `Connect` dialog"""
def __init__(self, parent=None): def __init__(self, parent=None):
super(ConnectDialog, self).__init__(parent) super(ConnectDialog, self).__init__(parent)

View File

@ -1,8 +1,8 @@
""" """
src/bitmessageqt/foldertree.py Folder tree and messagelist widgets definitions.
==============================
""" """
# pylint: disable=too-many-arguments,bad-super-call,attribute-defined-outside-init # pylint: disable=too-many-arguments,bad-super-call
# pylint: disable=attribute-defined-outside-init
from cgi import escape from cgi import escape
@ -20,6 +20,8 @@ _translate("MainWindow", "new")
_translate("MainWindow", "sent") _translate("MainWindow", "sent")
_translate("MainWindow", "trash") _translate("MainWindow", "trash")
TimestampRole = QtCore.Qt.UserRole + 1
class AccountMixin(object): class AccountMixin(object):
"""UI-related functionality for accounts""" """UI-related functionality for accounts"""
@ -334,13 +336,14 @@ class Ui_SubscriptionWidget(Ui_AddressWidget):
class BMTableWidgetItem(QtGui.QTableWidgetItem, SettingsMixin): class BMTableWidgetItem(QtGui.QTableWidgetItem, SettingsMixin):
"""A common abstract class for Table widget item""" """A common abstract class for Table widget item"""
def __init__(self, parent=None, label=None, unread=False): def __init__(self, label=None, unread=False):
super(QtGui.QTableWidgetItem, self).__init__() super(QtGui.QTableWidgetItem, self).__init__()
self.setLabel(label) self.setLabel(label)
self.setUnread(unread) self.setUnread(unread)
self._setup() self._setup()
if parent is not None:
parent.append(self) def _setup(self):
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
def setLabel(self, label): def setLabel(self, label):
"""Set object label""" """Set object label"""
@ -353,7 +356,7 @@ class BMTableWidgetItem(QtGui.QTableWidgetItem, SettingsMixin):
def data(self, role): def data(self, role):
"""Return object data (QT UI)""" """Return object data (QT UI)"""
if role in ( if role in (
QtCore.Qt.DisplayRole, QtCore.Qt.EditRole, QtCore.Qt.ToolTipRole QtCore.Qt.DisplayRole, QtCore.Qt.EditRole, QtCore.Qt.ToolTipRole
): ):
return self.label return self.label
elif role == QtCore.Qt.FontRole: elif role == QtCore.Qt.FontRole:
@ -367,7 +370,9 @@ class BMAddressWidget(BMTableWidgetItem, AccountMixin):
"""A common class for Table widget item with account""" """A common class for Table widget item with account"""
def _setup(self): def _setup(self):
super(BMAddressWidget, self)._setup()
self.setEnabled(True) self.setEnabled(True)
self.setType()
def _getLabel(self): def _getLabel(self):
return self.label return self.label
@ -387,14 +392,9 @@ class BMAddressWidget(BMTableWidgetItem, AccountMixin):
class MessageList_AddressWidget(BMAddressWidget): class MessageList_AddressWidget(BMAddressWidget):
"""Address item in a messagelist""" """Address item in a messagelist"""
def __init__(self, parent, address=None, label=None, unread=False): def __init__(self, address=None, label=None, unread=False):
self.setAddress(address) self.setAddress(address)
super(MessageList_AddressWidget, self).__init__(parent, label, unread) super(MessageList_AddressWidget, self).__init__(label, unread)
def _setup(self):
self.isEnabled = True
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
self.setType()
def setLabel(self, label=None): def setLabel(self, label=None):
"""Set label""" """Set label"""
@ -443,12 +443,9 @@ class MessageList_AddressWidget(BMAddressWidget):
class MessageList_SubjectWidget(BMTableWidgetItem): class MessageList_SubjectWidget(BMTableWidgetItem):
"""Message list subject item""" """Message list subject item"""
def __init__(self, parent, subject=None, label=None, unread=False): def __init__(self, subject=None, label=None, unread=False):
self.setSubject(subject) self.setSubject(subject)
super(MessageList_SubjectWidget, self).__init__(parent, label, unread) super(MessageList_SubjectWidget, self).__init__(label, unread)
def _setup(self):
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
def setSubject(self, subject): def setSubject(self, subject):
"""Set subject""" """Set subject"""
@ -469,6 +466,37 @@ class MessageList_SubjectWidget(BMTableWidgetItem):
return super(QtGui.QTableWidgetItem, self).__lt__(other) return super(QtGui.QTableWidgetItem, self).__lt__(other)
# In order for the time columns on the Inbox and Sent tabs to be sorted
# correctly (rather than alphabetically), we need to overload the <
# operator and use this class instead of QTableWidgetItem.
class MessageList_TimeWidget(BMTableWidgetItem):
"""
A subclass of QTableWidgetItem for received (lastactiontime) field.
'<' operator is overloaded to sort by TimestampRole == 33
msgid is available by QtCore.Qt.UserRole
"""
def __init__(self, label=None, unread=False, timestamp=None, msgid=''):
super(MessageList_TimeWidget, self).__init__(label, unread)
self.setData(QtCore.Qt.UserRole, QtCore.QByteArray(msgid))
self.setData(TimestampRole, int(timestamp))
def __lt__(self, other):
return self.data(TimestampRole) < other.data(TimestampRole)
def data(self, role=QtCore.Qt.UserRole):
"""
Returns expected python types for QtCore.Qt.UserRole and TimestampRole
custom roles and super for any Qt role
"""
data = super(MessageList_TimeWidget, self).data(role)
if role == TimestampRole:
return int(data.toPyObject())
if role == QtCore.Qt.UserRole:
return str(data.toPyObject())
return data
class Ui_AddressBookWidgetItem(BMAddressWidget): class Ui_AddressBookWidgetItem(BMAddressWidget):
"""Addressbook item""" """Addressbook item"""
# pylint: disable=unused-argument # pylint: disable=unused-argument
@ -518,8 +546,8 @@ class Ui_AddressBookWidgetItem(BMAddressWidget):
class Ui_AddressBookWidgetItemLabel(Ui_AddressBookWidgetItem): class Ui_AddressBookWidgetItemLabel(Ui_AddressBookWidgetItem):
"""Addressbook label item""" """Addressbook label item"""
def __init__(self, address, label, acc_type): def __init__(self, address, label, acc_type):
super(Ui_AddressBookWidgetItemLabel, self).__init__(label, acc_type)
self.address = address self.address = address
super(Ui_AddressBookWidgetItemLabel, self).__init__(label, acc_type)
def data(self, role): def data(self, role):
"""Return object data""" """Return object data"""
@ -530,9 +558,8 @@ class Ui_AddressBookWidgetItemLabel(Ui_AddressBookWidgetItem):
class Ui_AddressBookWidgetItemAddress(Ui_AddressBookWidgetItem): class Ui_AddressBookWidgetItemAddress(Ui_AddressBookWidgetItem):
"""Addressbook address item""" """Addressbook address item"""
def __init__(self, address, label, acc_type): def __init__(self, address, label, acc_type):
super(Ui_AddressBookWidgetItemAddress, self).__init__(address, acc_type)
self.address = address self.address = address
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) super(Ui_AddressBookWidgetItemAddress, self).__init__(address, acc_type)
def data(self, role): def data(self, role):
"""Return object data""" """Return object data"""

View File

@ -1,32 +1,45 @@
"""Language Box Module for Locale Settings"""
# pylint: disable=too-few-public-methods,bad-continuation
import glob import glob
import os import os
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from bmconfigparser import BMConfigParser
import paths import paths
from bmconfigparser import BMConfigParser
class LanguageBox(QtGui.QComboBox): class LanguageBox(QtGui.QComboBox):
languageName = {"system": "System Settings", "eo": "Esperanto", "en_pirate": "Pirate English"} """LanguageBox class for Qt UI"""
def __init__(self, parent = None): languageName = {
"system": "System Settings", "eo": "Esperanto",
"en_pirate": "Pirate English"
}
def __init__(self, parent=None):
super(QtGui.QComboBox, self).__init__(parent) super(QtGui.QComboBox, self).__init__(parent)
self.populate() self.populate()
def populate(self): def populate(self):
"""Populates drop down list with all available languages."""
self.clear() self.clear()
localesPath = os.path.join (paths.codePath(), 'translations') localesPath = os.path.join(paths.codePath(), 'translations')
self.addItem(QtGui.QApplication.translate("settingsDialog", "System Settings", "system"), "system") self.addItem(QtGui.QApplication.translate(
"settingsDialog", "System Settings", "system"), "system")
self.setCurrentIndex(0) self.setCurrentIndex(0)
self.setInsertPolicy(QtGui.QComboBox.InsertAlphabetically) self.setInsertPolicy(QtGui.QComboBox.InsertAlphabetically)
for translationFile in sorted(glob.glob(os.path.join(localesPath, "bitmessage_*.qm"))): for translationFile in sorted(
localeShort = os.path.split(translationFile)[1].split("_", 1)[1][:-3] glob.glob(os.path.join(localesPath, "bitmessage_*.qm"))
locale = QtCore.QLocale(QtCore.QString(localeShort)) ):
localeShort = \
os.path.split(translationFile)[1].split("_", 1)[1][:-3]
if localeShort in LanguageBox.languageName: if localeShort in LanguageBox.languageName:
self.addItem(LanguageBox.languageName[localeShort], localeShort) self.addItem(
elif locale.nativeLanguageName() == "": LanguageBox.languageName[localeShort], localeShort)
self.addItem(localeShort, localeShort)
else: else:
self.addItem(locale.nativeLanguageName(), localeShort) locale = QtCore.QLocale(localeShort)
self.addItem(
locale.nativeLanguageName() or localeShort, localeShort)
configuredLocale = BMConfigParser().safeGet( configuredLocale = BMConfigParser().safeGet(
'bitmessagesettings', 'userlocale', "system") 'bitmessagesettings', 'userlocale', "system")

View File

@ -1,7 +1,5 @@
""" """
src/bitmessageqt/networkstatus.py Network status tab widget definition.
=================================
""" """
import time import time
@ -11,7 +9,7 @@ from PyQt4 import QtCore, QtGui
import knownnodes import knownnodes
import l10n import l10n
import network.stats import network.stats
import shared import state
import widgets import widgets
from inventory import Inventory from inventory import Inventory
from network.connectionpool import BMConnectionPool from network.connectionpool import BMConnectionPool
@ -34,8 +32,6 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin):
header.setSortIndicator(0, QtCore.Qt.AscendingOrder) header.setSortIndicator(0, QtCore.Qt.AscendingOrder)
self.startup = time.localtime() self.startup = time.localtime()
self.labelStartupTime.setText(_translate("networkstatus", "Since startup on %1").arg(
l10n.formatTimestamp(self.startup)))
self.UISignalThread = UISignaler.get() self.UISignalThread = UISignaler.get()
# pylint: disable=no-member # pylint: disable=no-member
@ -96,8 +92,8 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin):
"Object(s) to be synced: %n", "Object(s) to be synced: %n",
None, None,
QtCore.QCoreApplication.CodecForTr, QtCore.QCoreApplication.CodecForTr,
network.stats.pendingDownload() + network.stats.pendingDownload()
network.stats.pendingUpload())) + network.stats.pendingUpload()))
def updateNumberOfMessagesProcessed(self): def updateNumberOfMessagesProcessed(self):
"""Update the counter for number of processed messages""" """Update the counter for number of processed messages"""
@ -108,7 +104,7 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin):
"Processed %n person-to-person message(s).", "Processed %n person-to-person message(s).",
None, None,
QtCore.QCoreApplication.CodecForTr, QtCore.QCoreApplication.CodecForTr,
shared.numberOfMessagesProcessed)) state.numberOfMessagesProcessed))
def updateNumberOfBroadcastsProcessed(self): def updateNumberOfBroadcastsProcessed(self):
"""Update the counter for the number of processed broadcasts""" """Update the counter for the number of processed broadcasts"""
@ -119,7 +115,7 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin):
"Processed %n broadcast message(s).", "Processed %n broadcast message(s).",
None, None,
QtCore.QCoreApplication.CodecForTr, QtCore.QCoreApplication.CodecForTr,
shared.numberOfBroadcastsProcessed)) state.numberOfBroadcastsProcessed))
def updateNumberOfPubkeysProcessed(self): def updateNumberOfPubkeysProcessed(self):
"""Update the counter for the number of processed pubkeys""" """Update the counter for the number of processed pubkeys"""
@ -130,7 +126,7 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin):
"Processed %n public key(s).", "Processed %n public key(s).",
None, None,
QtCore.QCoreApplication.CodecForTr, QtCore.QCoreApplication.CodecForTr,
shared.numberOfPubkeysProcessed)) state.numberOfPubkeysProcessed))
def updateNumberOfBytes(self): def updateNumberOfBytes(self):
""" """
@ -207,7 +203,7 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin):
self.tableWidgetConnectionCount.item(0, 0).setData(QtCore.Qt.UserRole, destination) self.tableWidgetConnectionCount.item(0, 0).setData(QtCore.Qt.UserRole, destination)
self.tableWidgetConnectionCount.item(0, 1).setData(QtCore.Qt.UserRole, outbound) self.tableWidgetConnectionCount.item(0, 1).setData(QtCore.Qt.UserRole, outbound)
else: else:
if len(BMConnectionPool().inboundConnections) == 0: if not BMConnectionPool().inboundConnections:
self.window().setStatusIcon('yellow') self.window().setStatusIcon('yellow')
for i in range(self.tableWidgetConnectionCount.rowCount()): for i in range(self.tableWidgetConnectionCount.rowCount()):
if self.tableWidgetConnectionCount.item(i, 0).data(QtCore.Qt.UserRole).toPyObject() != destination: if self.tableWidgetConnectionCount.item(i, 0).data(QtCore.Qt.UserRole).toPyObject() != destination:
@ -225,9 +221,9 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin):
# FYI: The 'singlelistener' thread sets the icon color to green when it # FYI: The 'singlelistener' thread sets the icon color to green when it
# receives an incoming connection, meaning that the user's firewall is # receives an incoming connection, meaning that the user's firewall is
# configured correctly. # configured correctly.
if self.tableWidgetConnectionCount.rowCount() and shared.statusIconColor == 'red': if self.tableWidgetConnectionCount.rowCount() and state.statusIconColor == 'red':
self.window().setStatusIcon('yellow') self.window().setStatusIcon('yellow')
elif self.tableWidgetConnectionCount.rowCount() == 0 and shared.statusIconColor != "red": elif self.tableWidgetConnectionCount.rowCount() == 0 and state.statusIconColor != "red":
self.window().setStatusIcon('red') self.window().setStatusIcon('red')
# timer driven # timer driven
@ -240,6 +236,15 @@ class NetworkStatus(QtGui.QWidget, RetranslateMixin):
self.updateNumberOfObjectsToBeSynced() self.updateNumberOfObjectsToBeSynced()
def retranslateUi(self): def retranslateUi(self):
"""Conventional Qt Designer method for dynamic l10n"""
super(NetworkStatus, self).retranslateUi() super(NetworkStatus, self).retranslateUi()
self.labelStartupTime.setText(_translate("networkstatus", "Since startup on %1").arg( self.labelTotalConnections.setText(
l10n.formatTimestamp(self.startup))) _translate(
"networkstatus", "Total Connections: %1").arg(
str(self.tableWidgetConnectionCount.rowCount())))
self.labelStartupTime.setText(_translate(
"networkstatus", "Since startup on %1"
).arg(l10n.formatTimestamp(self.startup)))
self.updateNumberOfMessagesProcessed()
self.updateNumberOfBroadcastsProcessed()
self.updateNumberOfPubkeysProcessed()

View File

@ -9,13 +9,13 @@ from PyQt4 import QtCore, QtGui
import widgets import widgets
from addresses import addBMIfNotPresent from addresses import addBMIfNotPresent
from addressvalidator import AddressValidator, PassPhraseValidator from addressvalidator import AddressValidator, PassPhraseValidator
from queues import UISignalQueue, addressGeneratorQueue, apiAddressGeneratorReturnQueue from queues import (
from retranslateui import RetranslateMixin addressGeneratorQueue, apiAddressGeneratorReturnQueue, UISignalQueue)
from tr import _translate from tr import _translate
from utils import str_chan from utils import str_chan
class NewChanDialog(QtGui.QDialog, RetranslateMixin): class NewChanDialog(QtGui.QDialog):
"""The `New Chan` dialog""" """The `New Chan` dialog"""
def __init__(self, parent=None): def __init__(self, parent=None):
super(NewChanDialog, self).__init__(parent) super(NewChanDialog, self).__init__(parent)

View File

@ -1,3 +1,6 @@
"""
This module setting file is for settings
"""
import ConfigParser import ConfigParser
import os import os
import sys import sys
@ -11,7 +14,6 @@ import namecoin
import openclpow import openclpow
import paths import paths
import queues import queues
import shared
import state import state
import tempfile import tempfile
import widgets import widgets
@ -111,7 +113,7 @@ class SettingsDialog(QtGui.QDialog):
tempfile.NamedTemporaryFile( tempfile.NamedTemporaryFile(
dir=paths.lookupExeFolder(), delete=True dir=paths.lookupExeFolder(), delete=True
).close() # should autodelete ).close() # should autodelete
except: except Exception:
self.checkBoxPortableMode.setDisabled(True) self.checkBoxPortableMode.setDisabled(True)
if 'darwin' in sys.platform: if 'darwin' in sys.platform:
@ -338,7 +340,7 @@ class SettingsDialog(QtGui.QDialog):
proxytype_index = self.comboBoxProxyType.currentIndex() proxytype_index = self.comboBoxProxyType.currentIndex()
if proxytype_index == 0: if proxytype_index == 0:
if self._proxy_type and shared.statusIconColor != 'red': if self._proxy_type and state.statusIconColor != 'red':
self.net_restart_needed = True self.net_restart_needed = True
elif self.comboBoxProxyType.currentText() != self._proxy_type: elif self.comboBoxProxyType.currentText() != self._proxy_type:
self.net_restart_needed = True self.net_restart_needed = True
@ -408,14 +410,14 @@ class SettingsDialog(QtGui.QDialog):
self.config.set( self.config.set(
'bitmessagesettings', 'defaultnoncetrialsperbyte', 'bitmessagesettings', 'defaultnoncetrialsperbyte',
str(int( str(int(
float(self.lineEditTotalDifficulty.text()) * float(self.lineEditTotalDifficulty.text())
defaults.networkDefaultProofOfWorkNonceTrialsPerByte))) * defaults.networkDefaultProofOfWorkNonceTrialsPerByte)))
if float(self.lineEditSmallMessageDifficulty.text()) >= 1: if float(self.lineEditSmallMessageDifficulty.text()) >= 1:
self.config.set( self.config.set(
'bitmessagesettings', 'defaultpayloadlengthextrabytes', 'bitmessagesettings', 'defaultpayloadlengthextrabytes',
str(int( str(int(
float(self.lineEditSmallMessageDifficulty.text()) * float(self.lineEditSmallMessageDifficulty.text())
defaults.networkDefaultPayloadLengthExtraBytes))) * defaults.networkDefaultPayloadLengthExtraBytes)))
if self.comboBoxOpenCL.currentText().toUtf8() != self.config.safeGet( if self.comboBoxOpenCL.currentText().toUtf8() != self.config.safeGet(
'bitmessagesettings', 'opencl'): 'bitmessagesettings', 'opencl'):
@ -427,40 +429,40 @@ class SettingsDialog(QtGui.QDialog):
acceptableDifficultyChanged = False acceptableDifficultyChanged = False
if ( if (
float(self.lineEditMaxAcceptableTotalDifficulty.text()) >= 1 or float(self.lineEditMaxAcceptableTotalDifficulty.text()) >= 1
float(self.lineEditMaxAcceptableTotalDifficulty.text()) == 0 or float(self.lineEditMaxAcceptableTotalDifficulty.text()) == 0
): ):
if self.config.get( if self.config.get(
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte' 'bitmessagesettings', 'maxacceptablenoncetrialsperbyte'
) != str(int( ) != str(int(
float(self.lineEditMaxAcceptableTotalDifficulty.text()) * float(self.lineEditMaxAcceptableTotalDifficulty.text())
defaults.networkDefaultProofOfWorkNonceTrialsPerByte) * defaults.networkDefaultProofOfWorkNonceTrialsPerByte)
): ):
# the user changed the max acceptable total difficulty # the user changed the max acceptable total difficulty
acceptableDifficultyChanged = True acceptableDifficultyChanged = True
self.config.set( self.config.set(
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte', 'bitmessagesettings', 'maxacceptablenoncetrialsperbyte',
str(int( str(int(
float(self.lineEditMaxAcceptableTotalDifficulty.text()) * float(self.lineEditMaxAcceptableTotalDifficulty.text())
defaults.networkDefaultProofOfWorkNonceTrialsPerByte)) * defaults.networkDefaultProofOfWorkNonceTrialsPerByte))
) )
if ( if (
float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) >= 1 or float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) >= 1
float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) == 0 or float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) == 0
): ):
if self.config.get( if self.config.get(
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes' 'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes'
) != str(int( ) != str(int(
float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) * float(self.lineEditMaxAcceptableSmallMessageDifficulty.text())
defaults.networkDefaultPayloadLengthExtraBytes) * defaults.networkDefaultPayloadLengthExtraBytes)
): ):
# the user changed the max acceptable small message difficulty # the user changed the max acceptable small message difficulty
acceptableDifficultyChanged = True acceptableDifficultyChanged = True
self.config.set( self.config.set(
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes', 'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes',
str(int( str(int(
float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) * float(self.lineEditMaxAcceptableSmallMessageDifficulty.text())
defaults.networkDefaultPayloadLengthExtraBytes)) * defaults.networkDefaultPayloadLengthExtraBytes))
) )
if acceptableDifficultyChanged: if acceptableDifficultyChanged:
# It might now be possible to send msgs which were previously # It might now be possible to send msgs which were previously
@ -473,6 +475,8 @@ class SettingsDialog(QtGui.QDialog):
" WHERE status='toodifficult'") " WHERE status='toodifficult'")
queues.workerQueue.put(('sendmessage', '')) queues.workerQueue.put(('sendmessage', ''))
stopResendingDefaults = False
# UI setting to stop trying to send messages after X days/months # UI setting to stop trying to send messages after X days/months
# I'm open to changing this UI to something else if someone has a better idea. # I'm open to changing this UI to something else if someone has a better idea.
if self.lineEditDays.text() == '' and self.lineEditMonths.text() == '': if self.lineEditDays.text() == '' and self.lineEditMonths.text() == '':
@ -480,7 +484,8 @@ class SettingsDialog(QtGui.QDialog):
# default behavior. The input is blank/blank # default behavior. The input is blank/blank
self.config.set('bitmessagesettings', 'stopresendingafterxdays', '') self.config.set('bitmessagesettings', 'stopresendingafterxdays', '')
self.config.set('bitmessagesettings', 'stopresendingafterxmonths', '') self.config.set('bitmessagesettings', 'stopresendingafterxmonths', '')
shared.maximumLengthOfTimeToBotherResendingMessages = float('inf') state.maximumLengthOfTimeToBotherResendingMessages = float('inf')
stopResendingDefaults = True
try: try:
days = float(self.lineEditDays.text()) days = float(self.lineEditDays.text())
@ -493,10 +498,10 @@ class SettingsDialog(QtGui.QDialog):
self.lineEditMonths.setText("0") self.lineEditMonths.setText("0")
months = 0.0 months = 0.0
if days >= 0 and months >= 0: if days >= 0 and months >= 0 and not stopResendingDefaults:
shared.maximumLengthOfTimeToBotherResendingMessages = \ state.maximumLengthOfTimeToBotherResendingMessages = \
days * 24 * 60 * 60 + months * 60 * 60 * 24 * 365 / 12 days * 24 * 60 * 60 + months * 60 * 60 * 24 * 365 / 12
if shared.maximumLengthOfTimeToBotherResendingMessages < 432000: if state.maximumLengthOfTimeToBotherResendingMessages < 432000:
# If the time period is less than 5 hours, we give # If the time period is less than 5 hours, we give
# zero values to all fields. No message will be sent again. # zero values to all fields. No message will be sent again.
QtGui.QMessageBox.about( QtGui.QMessageBox.about(
@ -513,7 +518,7 @@ class SettingsDialog(QtGui.QDialog):
'bitmessagesettings', 'stopresendingafterxdays', '0') 'bitmessagesettings', 'stopresendingafterxdays', '0')
self.config.set( self.config.set(
'bitmessagesettings', 'stopresendingafterxmonths', '0') 'bitmessagesettings', 'stopresendingafterxmonths', '0')
shared.maximumLengthOfTimeToBotherResendingMessages = 0.0 state.maximumLengthOfTimeToBotherResendingMessages = 0.0
else: else:
self.config.set( self.config.set(
'bitmessagesettings', 'stopresendingafterxdays', str(days)) 'bitmessagesettings', 'stopresendingafterxdays', str(days))
@ -535,8 +540,8 @@ class SettingsDialog(QtGui.QDialog):
self.parent.updateStartOnLogon() self.parent.updateStartOnLogon()
if ( if (
state.appdata != paths.lookupExeFolder() and state.appdata != paths.lookupExeFolder()
self.checkBoxPortableMode.isChecked() and self.checkBoxPortableMode.isChecked()
): ):
# If we are NOT using portable mode now but the user selected # If we are NOT using portable mode now but the user selected
# that we should... # that we should...
@ -554,12 +559,12 @@ class SettingsDialog(QtGui.QDialog):
try: try:
os.remove(previousAppdataLocation + 'debug.log') os.remove(previousAppdataLocation + 'debug.log')
os.remove(previousAppdataLocation + 'debug.log.1') os.remove(previousAppdataLocation + 'debug.log.1')
except: except Exception:
pass pass
if ( if (
state.appdata == paths.lookupExeFolder() and state.appdata == paths.lookupExeFolder()
not self.checkBoxPortableMode.isChecked() and not self.checkBoxPortableMode.isChecked()
): ):
# If we ARE using portable mode now but the user selected # If we ARE using portable mode now but the user selected
# that we shouldn't... # that we shouldn't...
@ -577,5 +582,5 @@ class SettingsDialog(QtGui.QDialog):
try: try:
os.remove(paths.lookupExeFolder() + 'debug.log') os.remove(paths.lookupExeFolder() + 'debug.log')
os.remove(paths.lookupExeFolder() + 'debug.log.1') os.remove(paths.lookupExeFolder() + 'debug.log.1')
except: except Exception:
pass pass

View File

@ -1,33 +1,43 @@
"""Composing support request message functions."""
# pylint: disable=no-member
import ctypes import ctypes
from PyQt4 import QtCore, QtGui
import ssl import ssl
import sys import sys
import time import time
from PyQt4 import QtCore
import account import account
from bmconfigparser import BMConfigParser
from debug import logger
import defaults import defaults
from foldertree import AccountMixin import network.stats
from helper_sql import *
from l10n import getTranslationLanguage
from openclpow import openclAvailable, openclEnabled
import paths import paths
import proofofwork import proofofwork
import queues
import state
from bmconfigparser import BMConfigParser
from foldertree import AccountMixin
from helper_sql import sqlExecute, sqlQuery
from l10n import getTranslationLanguage
from openclpow import openclEnabled
from pyelliptic.openssl import OpenSSL from pyelliptic.openssl import OpenSSL
from settings import getSOCKSProxyType from settings import getSOCKSProxyType
import queues
import network.stats
import state
from version import softwareVersion from version import softwareVersion
from tr import _translate
# this is BM support address going to Peter Surda # this is BM support address going to Peter Surda
OLD_SUPPORT_ADDRESS = 'BM-2cTkCtMYkrSPwFTpgcBrMrf5d8oZwvMZWK' OLD_SUPPORT_ADDRESS = 'BM-2cTkCtMYkrSPwFTpgcBrMrf5d8oZwvMZWK'
SUPPORT_ADDRESS = 'BM-2cUdgkDDAahwPAU6oD2A7DnjqZz3hgY832' SUPPORT_ADDRESS = 'BM-2cUdgkDDAahwPAU6oD2A7DnjqZz3hgY832'
SUPPORT_LABEL = 'PyBitmessage support' SUPPORT_LABEL = _translate("Support", "PyBitmessage support")
SUPPORT_MY_LABEL = 'My new address' SUPPORT_MY_LABEL = _translate("Support", "My new address")
SUPPORT_SUBJECT = 'Support request' SUPPORT_SUBJECT = 'Support request'
SUPPORT_MESSAGE = '''You can use this message to send a report to one of the PyBitmessage core developers regarding PyBitmessage or the mailchuck.com email service. If you are using PyBitmessage involuntarily, for example because your computer was infected with ransomware, this is not an appropriate venue for resolving such issues. SUPPORT_MESSAGE = _translate("Support", '''
You can use this message to send a report to one of the PyBitmessage core \
developers regarding PyBitmessage or the mailchuck.com email service. \
If you are using PyBitmessage involuntarily, for example because \
your computer was infected with ransomware, this is not an appropriate venue \
for resolving such issues.
Please describe what you are trying to do: Please describe what you are trying to do:
@ -37,7 +47,8 @@ Please describe what happens instead:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Please write above this line and if possible, keep the information about your environment below intact. Please write above this line and if possible, keep the information about your \
environment below intact.
PyBitmessage version: {} PyBitmessage version: {}
Operating system: {} Operating system: {}
@ -52,15 +63,19 @@ Locale: {}
SOCKS: {} SOCKS: {}
UPnP: {} UPnP: {}
Connected hosts: {} Connected hosts: {}
''' ''')
def checkAddressBook(myapp): def checkAddressBook(myapp):
sqlExecute('''DELETE from addressbook WHERE address=?''', OLD_SUPPORT_ADDRESS) sqlExecute('DELETE from addressbook WHERE address=?', OLD_SUPPORT_ADDRESS)
queryreturn = sqlQuery('''SELECT * FROM addressbook WHERE address=?''', SUPPORT_ADDRESS) queryreturn = sqlQuery('SELECT * FROM addressbook WHERE address=?', SUPPORT_ADDRESS)
if queryreturn == []: if queryreturn == []:
sqlExecute('''INSERT INTO addressbook VALUES (?,?)''', str(QtGui.QApplication.translate("Support", SUPPORT_LABEL)), SUPPORT_ADDRESS) sqlExecute(
'INSERT INTO addressbook VALUES (?,?)',
SUPPORT_LABEL.toUtf8(), SUPPORT_ADDRESS)
myapp.rerenderAddressBook() myapp.rerenderAddressBook()
def checkHasNormalAddress(): def checkHasNormalAddress():
for address in account.getSortedAccounts(): for address in account.getSortedAccounts():
acct = account.accountClass(address) acct = account.accountClass(address)
@ -68,23 +83,33 @@ def checkHasNormalAddress():
return address return address
return False return False
def createAddressIfNeeded(myapp): def createAddressIfNeeded(myapp):
if not checkHasNormalAddress(): if not checkHasNormalAddress():
queues.addressGeneratorQueue.put(('createRandomAddress', 4, 1, str(QtGui.QApplication.translate("Support", SUPPORT_MY_LABEL)), 1, "", False, defaults.networkDefaultProofOfWorkNonceTrialsPerByte, defaults.networkDefaultPayloadLengthExtraBytes)) queues.addressGeneratorQueue.put((
'createRandomAddress', 4, 1,
SUPPORT_MY_LABEL.toUtf8(),
1, "", False,
defaults.networkDefaultProofOfWorkNonceTrialsPerByte,
defaults.networkDefaultPayloadLengthExtraBytes
))
while state.shutdown == 0 and not checkHasNormalAddress(): while state.shutdown == 0 and not checkHasNormalAddress():
time.sleep(.2) time.sleep(.2)
myapp.rerenderComboBoxSendFrom() myapp.rerenderComboBoxSendFrom()
return checkHasNormalAddress() return checkHasNormalAddress()
def createSupportMessage(myapp): def createSupportMessage(myapp):
checkAddressBook(myapp) checkAddressBook(myapp)
address = createAddressIfNeeded(myapp) address = createAddressIfNeeded(myapp)
if state.shutdown: if state.shutdown:
return return
myapp.ui.lineEditSubject.setText(str(QtGui.QApplication.translate("Support", SUPPORT_SUBJECT))) myapp.ui.lineEditSubject.setText(SUPPORT_SUBJECT)
addrIndex = myapp.ui.comboBoxSendFrom.findData(address, QtCore.Qt.UserRole, QtCore.Qt.MatchFixedString | QtCore.Qt.MatchCaseSensitive) addrIndex = myapp.ui.comboBoxSendFrom.findData(
if addrIndex == -1: # something is very wrong address, QtCore.Qt.UserRole,
QtCore.Qt.MatchFixedString | QtCore.Qt.MatchCaseSensitive)
if addrIndex == -1: # something is very wrong
return return
myapp.ui.comboBoxSendFrom.setCurrentIndex(addrIndex) myapp.ui.comboBoxSendFrom.setCurrentIndex(addrIndex)
myapp.ui.lineEditTo.setText(SUPPORT_ADDRESS) myapp.ui.lineEditTo.setText(SUPPORT_ADDRESS)
@ -108,7 +133,8 @@ def createSupportMessage(myapp):
architecture = "32" if ctypes.sizeof(ctypes.c_voidp) == 4 else "64" architecture = "32" if ctypes.sizeof(ctypes.c_voidp) == 4 else "64"
pythonversion = sys.version pythonversion = sys.version
opensslversion = "%s (Python internal), %s (external for PyElliptic)" % (ssl.OPENSSL_VERSION, OpenSSL._version) opensslversion = "%s (Python internal), %s (external for PyElliptic)" % (
ssl.OPENSSL_VERSION, OpenSSL._version)
frozen = "N/A" frozen = "N/A"
if paths.frozen: if paths.frozen:
@ -123,7 +149,9 @@ def createSupportMessage(myapp):
upnp = BMConfigParser().safeGet('bitmessagesettings', 'upnp', "N/A") upnp = BMConfigParser().safeGet('bitmessagesettings', 'upnp', "N/A")
connectedhosts = len(network.stats.connectedHostsList()) connectedhosts = len(network.stats.connectedHostsList())
myapp.ui.textEditMessage.setText(str(QtGui.QApplication.translate("Support", SUPPORT_MESSAGE)).format(version, os, architecture, pythonversion, opensslversion, frozen, portablemode, cpow, openclpow, locale, socks, upnp, connectedhosts)) myapp.ui.textEditMessage.setText(unicode(SUPPORT_MESSAGE, 'utf-8').format(
version, os, architecture, pythonversion, opensslversion, frozen,
portablemode, cpow, openclpow, locale, socks, upnp, connectedhosts))
# single msg tab # single msg tab
myapp.ui.tabWidgetSend.setCurrentIndex( myapp.ui.tabWidgetSend.setCurrentIndex(

View File

@ -1,13 +1,16 @@
from PyQt4 import QtGui
import hashlib import hashlib
import os import os
from PyQt4 import QtGui
import state
from addresses import addBMIfNotPresent from addresses import addBMIfNotPresent
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
import state
str_broadcast_subscribers = '[Broadcast subscribers]' str_broadcast_subscribers = '[Broadcast subscribers]'
str_chan = '[chan]' str_chan = '[chan]'
def identiconize(address): def identiconize(address):
size = 48 size = 48
@ -28,32 +31,40 @@ def identiconize(address):
# the identicons to decrease the risk of attacks where someone creates # the identicons to decrease the risk of attacks where someone creates
# an address to mimic someone else's identicon. # an address to mimic someone else's identicon.
identiconsuffix = BMConfigParser().get('bitmessagesettings', 'identiconsuffix') identiconsuffix = BMConfigParser().get('bitmessagesettings', 'identiconsuffix')
if (identicon_lib[:len('qidenticon')] == 'qidenticon'): if identicon_lib[:len('qidenticon')] == 'qidenticon':
# print identicon_lib
# originally by: # originally by:
# :Author:Shin Adachi <shn@glucose.jp> # :Author:Shin Adachi <shn@glucose.jp>
# Licesensed under FreeBSD License. # Licesensed under FreeBSD License.
# stripped from PIL and uses QT instead (by sendiulo, same license) # stripped from PIL and uses QT instead (by sendiulo, same license)
import qidenticon import qidenticon
hash = hashlib.md5(addBMIfNotPresent(address)+identiconsuffix).hexdigest() icon_hash = hashlib.md5(
use_two_colors = (identicon_lib[:len('qidenticon_two')] == 'qidenticon_two') addBMIfNotPresent(address) + identiconsuffix).hexdigest()
opacity = int(not((identicon_lib == 'qidenticon_x') | (identicon_lib == 'qidenticon_two_x') | (identicon_lib == 'qidenticon_b') | (identicon_lib == 'qidenticon_two_b')))*255 use_two_colors = identicon_lib[:len('qidenticon_two')] == 'qidenticon_two'
opacity = int(
identicon_lib not in (
'qidenticon_x', 'qidenticon_two_x',
'qidenticon_b', 'qidenticon_two_b'
)) * 255
penwidth = 0 penwidth = 0
image = qidenticon.render_identicon(int(hash, 16), size, use_two_colors, opacity, penwidth) image = qidenticon.render_identicon(
int(icon_hash, 16), size, use_two_colors, opacity, penwidth)
# filename = './images/identicons/'+hash+'.png' # filename = './images/identicons/'+hash+'.png'
# image.save(filename) # image.save(filename)
idcon = QtGui.QIcon() idcon = QtGui.QIcon()
idcon.addPixmap(image, QtGui.QIcon.Normal, QtGui.QIcon.Off) idcon.addPixmap(image, QtGui.QIcon.Normal, QtGui.QIcon.Off)
return idcon return idcon
elif identicon_lib == 'pydenticon': elif identicon_lib == 'pydenticon':
# print identicon_lib # Here you could load pydenticon.py
# Here you could load pydenticon.py (just put it in the "src" folder of your Bitmessage source) # (just put it in the "src" folder of your Bitmessage source)
from pydenticon import Pydenticon from pydenticon import Pydenticon
# It is not included in the source, because it is licensed under GPLv3 # It is not included in the source, because it is licensed under GPLv3
# GPLv3 is a copyleft license that would influence our licensing # 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 # Find the source here:
# note that it requires PIL to be installed: http://www.pythonware.com/products/pil/ # https://github.com/azaghal/pydenticon
idcon_render = Pydenticon(addBMIfNotPresent(address)+identiconsuffix, size*3) # note that it requires pillow (or PIL) to be installed:
# https://python-pillow.org/
idcon_render = Pydenticon(
addBMIfNotPresent(address) + identiconsuffix, size * 3)
rendering = idcon_render._render() rendering = idcon_render._render()
data = rendering.convert("RGBA").tostring("raw", "RGBA") data = rendering.convert("RGBA").tostring("raw", "RGBA")
qim = QtGui.QImage(data, size, size, QtGui.QImage.Format_ARGB32) qim = QtGui.QImage(data, size, size, QtGui.QImage.Format_ARGB32)
@ -62,32 +73,31 @@ def identiconize(address):
idcon.addPixmap(pix, QtGui.QIcon.Normal, QtGui.QIcon.Off) idcon.addPixmap(pix, QtGui.QIcon.Normal, QtGui.QIcon.Off)
return idcon return idcon
def avatarize(address): def avatarize(address):
""" """
loads a supported image for the given address' hash form 'avatars' folder Loads a supported image for the given address' hash form 'avatars' folder
falls back to default avatar if 'default.*' file exists falls back to default avatar if 'default.*' file exists
falls back to identiconize(address) falls back to identiconize(address)
""" """
idcon = QtGui.QIcon() idcon = QtGui.QIcon()
hash = hashlib.md5(addBMIfNotPresent(address)).hexdigest() icon_hash = hashlib.md5(addBMIfNotPresent(address)).hexdigest()
str_broadcast_subscribers = '[Broadcast subscribers]'
if address == str_broadcast_subscribers: if address == str_broadcast_subscribers:
# don't hash [Broadcast subscribers] # don't hash [Broadcast subscribers]
hash = address icon_hash = address
# http://pyqt.sourceforge.net/Docs/PyQt4/qimagereader.html#supportedImageFormats # https://www.riverbankcomputing.com/static/Docs/PyQt4/qimagereader.html#supportedImageFormats
# print QImageReader.supportedImageFormats ()
# QImageReader.supportedImageFormats () # QImageReader.supportedImageFormats ()
extensions = ['PNG', 'GIF', 'JPG', 'JPEG', 'SVG', 'BMP', 'MNG', 'PBM', 'PGM', 'PPM', 'TIFF', 'XBM', 'XPM', 'TGA'] extensions = [
'PNG', 'GIF', 'JPG', 'JPEG', 'SVG', 'BMP', 'MNG', 'PBM', 'PGM', 'PPM',
'TIFF', 'XBM', 'XPM', 'TGA']
# try to find a specific avatar # try to find a specific avatar
for ext in extensions: for ext in extensions:
lower_hash = state.appdata + 'avatars/' + hash + '.' + ext.lower() lower_hash = state.appdata + 'avatars/' + icon_hash + '.' + ext.lower()
upper_hash = state.appdata + 'avatars/' + hash + '.' + ext.upper() upper_hash = state.appdata + 'avatars/' + icon_hash + '.' + ext.upper()
if os.path.isfile(lower_hash): if os.path.isfile(lower_hash):
# print 'found avatar of ', address
idcon.addFile(lower_hash) idcon.addFile(lower_hash)
return idcon return idcon
elif os.path.isfile(upper_hash): elif os.path.isfile(upper_hash):
# print 'found avatar of ', address
idcon.addFile(upper_hash) idcon.addFile(upper_hash)
return idcon return idcon
# if we haven't found any, try to find a default avatar # if we haven't found any, try to find a default avatar

View File

@ -138,9 +138,9 @@ class objectProcessor(threading.Thread):
# bypass nonce and time, retain object type/version/stream + body # bypass nonce and time, retain object type/version/stream + body
readPosition = 16 readPosition = 16
if bytes(data[readPosition:]) in shared.ackdataForWhichImWatching: if bytes(data[readPosition:]) in state.ackdataForWhichImWatching:
logger.info('This object is an acknowledgement bound for me.') logger.info('This object is an acknowledgement bound for me.')
del shared.ackdataForWhichImWatching[bytes(data[readPosition:])] del state.ackdataForWhichImWatching[bytes(data[readPosition:])]
sqlExecute( sqlExecute(
'UPDATE sent SET status=?, lastactiontime=?' 'UPDATE sent SET status=?, lastactiontime=?'
' WHERE ackdata=?', ' WHERE ackdata=?',
@ -284,7 +284,7 @@ class objectProcessor(threading.Thread):
def processpubkey(self, data): def processpubkey(self, data):
"""Process a pubkey object""" """Process a pubkey object"""
pubkeyProcessingStartTime = time.time() pubkeyProcessingStartTime = time.time()
shared.numberOfPubkeysProcessed += 1 state.numberOfPubkeysProcessed += 1
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateNumberOfPubkeysProcessed', 'no data')) 'updateNumberOfPubkeysProcessed', 'no data'))
readPosition = 20 # bypass the nonce, time, and object type readPosition = 20 # bypass the nonce, time, and object type
@ -457,7 +457,7 @@ class objectProcessor(threading.Thread):
def processmsg(self, data): def processmsg(self, data):
"""Process a message object""" """Process a message object"""
messageProcessingStartTime = time.time() messageProcessingStartTime = time.time()
shared.numberOfMessagesProcessed += 1 state.numberOfMessagesProcessed += 1
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateNumberOfMessagesProcessed', 'no data')) 'updateNumberOfMessagesProcessed', 'no data'))
readPosition = 20 # bypass the nonce, time, and object type readPosition = 20 # bypass the nonce, time, and object type
@ -803,7 +803,7 @@ class objectProcessor(threading.Thread):
def processbroadcast(self, data): def processbroadcast(self, data):
"""Process a broadcast object""" """Process a broadcast object"""
messageProcessingStartTime = time.time() messageProcessingStartTime = time.time()
shared.numberOfBroadcastsProcessed += 1 state.numberOfBroadcastsProcessed += 1
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateNumberOfBroadcastsProcessed', 'no data')) 'updateNumberOfBroadcastsProcessed', 'no data'))
inventoryHash = calculateInventoryHash(data) inventoryHash = calculateInventoryHash(data)

View File

@ -36,6 +36,13 @@ from network.connectionpool import BMConnectionPool
from network.threads import StoppableThread from network.threads import StoppableThread
#: Equals 4 weeks. You could make this longer if you want
#: but making it shorter would not be advisable because
#: there is a very small possibility that it could keep you
#: from obtaining a needed pubkey for a period of time.
lengthOfTimeToHoldOnToAllPubkeys = 2419200
class singleCleaner(StoppableThread): class singleCleaner(StoppableThread):
"""The singleCleaner thread class""" """The singleCleaner thread class"""
name = "singleCleaner" name = "singleCleaner"
@ -46,7 +53,7 @@ class singleCleaner(StoppableThread):
gc.disable() gc.disable()
timeWeLastClearedInventoryAndPubkeysTables = 0 timeWeLastClearedInventoryAndPubkeysTables = 0
try: try:
shared.maximumLengthOfTimeToBotherResendingMessages = ( state.maximumLengthOfTimeToBotherResendingMessages = (
float(BMConfigParser().get( float(BMConfigParser().get(
'bitmessagesettings', 'stopresendingafterxdays')) 'bitmessagesettings', 'stopresendingafterxdays'))
* 24 * 60 * 60 * 24 * 60 * 60
@ -58,7 +65,7 @@ class singleCleaner(StoppableThread):
# Either the user hasn't set stopresendingafterxdays and # Either the user hasn't set stopresendingafterxdays and
# stopresendingafterxmonths yet or the options are missing # stopresendingafterxmonths yet or the options are missing
# from the config file. # from the config file.
shared.maximumLengthOfTimeToBotherResendingMessages = float('inf') state.maximumLengthOfTimeToBotherResendingMessages = float('inf')
# initial wait # initial wait
if state.shutdown == 0: if state.shutdown == 0:
@ -75,8 +82,8 @@ class singleCleaner(StoppableThread):
# If we are running as a daemon then we are going to fill up the UI # If we are running as a daemon then we are going to fill up the UI
# queue which will never be handled by a UI. We should clear it to # queue which will never be handled by a UI. We should clear it to
# save memory. # save memory.
# ..FIXME redundant? # FIXME redundant?
if shared.thisapp.daemon or not state.enableGUI: if state.thisapp.daemon or not state.enableGUI:
queues.UISignalQueue.queue.clear() queues.UISignalQueue.queue.clear()
if timeWeLastClearedInventoryAndPubkeysTables < \ if timeWeLastClearedInventoryAndPubkeysTables < \
int(time.time()) - 7380: int(time.time()) - 7380:
@ -86,7 +93,7 @@ class singleCleaner(StoppableThread):
# pubkeys # pubkeys
sqlExecute( sqlExecute(
"DELETE FROM pubkeys WHERE time<? AND usedpersonally='no'", "DELETE FROM pubkeys WHERE time<? AND usedpersonally='no'",
int(time.time()) - shared.lengthOfTimeToHoldOnToAllPubkeys) int(time.time()) - lengthOfTimeToHoldOnToAllPubkeys)
# Let us resend getpubkey objects if we have not yet heard # Let us resend getpubkey objects if we have not yet heard
# a pubkey, and also msg objects if we have not yet heard # a pubkey, and also msg objects if we have not yet heard
@ -96,7 +103,7 @@ class singleCleaner(StoppableThread):
" WHERE ((status='awaitingpubkey' OR status='msgsent')" " WHERE ((status='awaitingpubkey' OR status='msgsent')"
" AND folder='sent' AND sleeptill<? AND senttime>?)", " AND folder='sent' AND sleeptill<? AND senttime>?)",
int(time.time()), int(time.time()) int(time.time()), int(time.time())
- shared.maximumLengthOfTimeToBotherResendingMessages - state.maximumLengthOfTimeToBotherResendingMessages
) )
for row in queryreturn: for row in queryreturn:
if len(row) < 2: if len(row) < 2:
@ -133,7 +140,8 @@ class singleCleaner(StoppableThread):
' is full. Bitmessage will now exit.'), ' is full. Bitmessage will now exit.'),
True) True)
)) ))
if shared.thisapp.daemon or not state.enableGUI: # FIXME redundant?
if state.thisapp.daemon or not state.enableGUI:
os._exit(1) os._exit(1)
# inv/object tracking # inv/object tracking

View File

@ -99,25 +99,25 @@ class singleWorker(StoppableThread):
hexlify(privEncryptionKey)) hexlify(privEncryptionKey))
) )
# Initialize the shared.ackdataForWhichImWatching data structure # Initialize the state.ackdataForWhichImWatching data structure
queryreturn = sqlQuery( queryreturn = sqlQuery(
'''SELECT ackdata FROM sent WHERE status = 'msgsent' ''') '''SELECT ackdata FROM sent WHERE status = 'msgsent' ''')
for row in queryreturn: for row in queryreturn:
ackdata, = row ackdata, = row
self.logger.info('Watching for ackdata %s', hexlify(ackdata)) self.logger.info('Watching for ackdata %s', hexlify(ackdata))
shared.ackdataForWhichImWatching[ackdata] = 0 state.ackdataForWhichImWatching[ackdata] = 0
# Fix legacy (headerless) watched ackdata to include header # Fix legacy (headerless) watched ackdata to include header
for oldack in shared.ackdataForWhichImWatching: for oldack in state.ackdataForWhichImWatching:
if len(oldack) == 32: if len(oldack) == 32:
# attach legacy header, always constant (msg/1/1) # attach legacy header, always constant (msg/1/1)
newack = '\x00\x00\x00\x02\x01\x01' + oldack newack = '\x00\x00\x00\x02\x01\x01' + oldack
shared.ackdataForWhichImWatching[newack] = 0 state.ackdataForWhichImWatching[newack] = 0
sqlExecute( sqlExecute(
'UPDATE sent SET ackdata=? WHERE ackdata=?', 'UPDATE sent SET ackdata=? WHERE ackdata=?',
newack, oldack newack, oldack
) )
del shared.ackdataForWhichImWatching[oldack] del state.ackdataForWhichImWatching[oldack]
# give some time for the GUI to start # give some time for the GUI to start
# before we start on existing POW tasks. # before we start on existing POW tasks.
@ -867,7 +867,7 @@ class singleWorker(StoppableThread):
embeddedTime = int(time.time() + TTL) embeddedTime = int(time.time() + TTL)
# if we aren't sending this to ourselves or a chan # if we aren't sending this to ourselves or a chan
if not BMConfigParser().has_section(toaddress): if not BMConfigParser().has_section(toaddress):
shared.ackdataForWhichImWatching[ackdata] = 0 state.ackdataForWhichImWatching[ackdata] = 0
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateSentItemStatusByAckdata', ( 'updateSentItemStatusByAckdata', (
ackdata, ackdata,

11
src/download.wget Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,92 +1,115 @@
"""Additional SQL helper for searching messages""" """
Additional SQL helper for searching messages.
Used by :mod:`.bitmessageqt`.
"""
from helper_sql import sqlQuery
try:
from PyQt4 import QtGui
haveQt = True
except ImportError:
haveQt = False
# pylint: disable=too-many-arguments # pylint: disable=too-many-arguments
from helper_sql import sqlQuery
from tr import _translate
def search_translate(context, text): def search_sql(
"""Translation wrapper""" xAddress='toaddress', account=None, folder='inbox', where=None,
if haveQt: what=None, unreadOnly=False
return QtGui.QApplication.translate(context, text) ):
return text.lower() """
Search for messages from given account and folder having search term
in one of it's fields.
:param str xAddress: address field checked
def search_sql(xAddress="toaddress", account=None, folder="inbox", where=None, what=None, unreadOnly=False): ('fromaddress', 'toaddress' or 'both')
"""Perform a search in mailbox tables""" :param account: the account which is checked
# pylint: disable=too-many-branches :type account: :class:`.bitmessageqt.account.BMAccount`
if what is not None and what != "": instance
what = "%" + what + "%" :param str folder: the folder which is checked
if where == search_translate("MainWindow", "To"): :param str where: message field which is checked ('toaddress',
where = "toaddress" 'fromaddress', 'subject' or 'message'), by default check any field
elif where == search_translate("MainWindow", "From"): :param str what: the search term
where = "fromaddress" :param bool unreadOnly: if True, search only for unread messages
elif where == search_translate("MainWindow", "Subject"): :return: all messages where <where> field contains <what>
where = "subject" :rtype: list[list]
elif where == search_translate("MainWindow", "Message"): """
where = "message" # pylint: disable=too-many-arguments, too-many-branches
if what:
what = '%' + what + '%'
if where == _translate("MainWindow", "To"):
where = 'toaddress'
elif where == _translate("MainWindow", "From"):
where = 'fromaddress'
elif where == _translate("MainWindow", "Subject"):
where = 'subject'
elif where == _translate("MainWindow", "Message"):
where = 'message'
else: else:
where = "toaddress || fromaddress || subject || message" where = 'toaddress || fromaddress || subject || message'
else:
what = None
if folder == "sent": sqlStatementBase = 'SELECT toaddress, fromaddress, subject, ' + (
sqlStatementBase = ''' 'status, ackdata, lastactiontime FROM sent ' if folder == 'sent'
SELECT toaddress, fromaddress, subject, status, ackdata, lastactiontime else 'folder, msgid, received, read FROM inbox '
FROM sent ''' )
else:
sqlStatementBase = '''SELECT folder, msgid, toaddress, fromaddress, subject, received, read
FROM inbox '''
sqlStatementParts = [] sqlStatementParts = []
sqlArguments = [] sqlArguments = []
if account is not None: if account is not None:
if xAddress == 'both': if xAddress == 'both':
sqlStatementParts.append("(fromaddress = ? OR toaddress = ?)") sqlStatementParts.append('(fromaddress = ? OR toaddress = ?)')
sqlArguments.append(account) sqlArguments.append(account)
sqlArguments.append(account) sqlArguments.append(account)
else: else:
sqlStatementParts.append(xAddress + " = ? ") sqlStatementParts.append(xAddress + ' = ? ')
sqlArguments.append(account) sqlArguments.append(account)
if folder is not None: if folder is not None:
if folder == "new": if folder == 'new':
folder = "inbox" folder = 'inbox'
unreadOnly = True unreadOnly = True
sqlStatementParts.append("folder = ? ") sqlStatementParts.append('folder = ? ')
sqlArguments.append(folder) sqlArguments.append(folder)
else: else:
sqlStatementParts.append("folder != ?") sqlStatementParts.append('folder != ?')
sqlArguments.append("trash") sqlArguments.append('trash')
if what is not None: if what:
sqlStatementParts.append("%s LIKE ?" % (where)) sqlStatementParts.append('%s LIKE ?' % (where))
sqlArguments.append(what) sqlArguments.append(what)
if unreadOnly: if unreadOnly:
sqlStatementParts.append("read = 0") sqlStatementParts.append('read = 0')
if sqlStatementParts: if sqlStatementParts:
sqlStatementBase += "WHERE " + " AND ".join(sqlStatementParts) sqlStatementBase += 'WHERE ' + ' AND '.join(sqlStatementParts)
if folder == "sent": if folder == 'sent':
sqlStatementBase += " ORDER BY lastactiontime" sqlStatementBase += ' ORDER BY lastactiontime'
return sqlQuery(sqlStatementBase, sqlArguments) return sqlQuery(sqlStatementBase, sqlArguments)
def check_match(toAddress, fromAddress, subject, message, where=None, what=None):
"""Check if a single message matches a filter (used when new messages are added to messagelists)""" def check_match(
if what is not None and what != "": toAddress, fromAddress, subject, message, where=None, what=None):
if where in (search_translate("MainWindow", "To"), search_translate("MainWindow", "All")): """
if what.lower() not in toAddress.lower(): Check if a single message matches a filter (used when new messages
return False are added to messagelists)
elif where in (search_translate("MainWindow", "From"), search_translate("MainWindow", "All")): """
if what.lower() not in fromAddress.lower(): # pylint: disable=too-many-arguments
return False if not what:
elif where in (search_translate("MainWindow", "Subject"), search_translate("MainWindow", "All")): return True
if what.lower() not in subject.lower():
return False if where in (
elif where in (search_translate("MainWindow", "Message"), search_translate("MainWindow", "All")): _translate("MainWindow", "To"), _translate("MainWindow", "All")
if what.lower() not in message.lower(): ):
return False if what.lower() not in toAddress.lower():
return False
elif where in (
_translate("MainWindow", "From"), _translate("MainWindow", "All")
):
if what.lower() not in fromAddress.lower():
return False
elif where in (
_translate("MainWindow", "Subject"),
_translate("MainWindow", "All")
):
if what.lower() not in subject.lower():
return False
elif where in (
_translate("MainWindow", "Message"),
_translate("MainWindow", "All")
):
if what.lower() not in message.lower():
return False
return True return True

View File

@ -279,19 +279,28 @@ def updateConfig():
config.save() config.save()
def isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections(): def adjustHalfOpenConnectionsLimit():
"""Check for (mainly XP and Vista) limitations""" """Check and satisfy half-open connections limit (mainly XP and Vista)"""
if BMConfigParser().safeGet(
'bitmessagesettings', 'socksproxytype', 'none') != 'none':
state.maximumNumberOfHalfOpenConnections = 4
return
is_limited = False
try: try:
if sys.platform[0:3] == "win": if sys.platform[0:3] == "win":
# Some XP and Vista systems can only have 10 outgoing
# connections at a time.
VER_THIS = StrictVersion(platform.version()) VER_THIS = StrictVersion(platform.version())
return ( is_limited = (
StrictVersion("5.1.2600") <= VER_THIS and StrictVersion("5.1.2600") <= VER_THIS and
StrictVersion("6.0.6000") >= VER_THIS StrictVersion("6.0.6000") >= VER_THIS
) )
return False except ValueError:
except Exception:
pass pass
state.maximumNumberOfHalfOpenConnections = 9 if is_limited else 64
def start_proxyconfig(): def start_proxyconfig():
"""Check socksproxytype and start any proxy configuration plugin""" """Check socksproxytype and start any proxy configuration plugin"""

View File

@ -2,8 +2,8 @@
High level cryptographic functions based on `.pyelliptic` OpenSSL bindings. High level cryptographic functions based on `.pyelliptic` OpenSSL bindings.
.. note:: .. note::
Upstream pyelliptic was upgraded from SHA1 to SHA256 for signing. Upstream pyelliptic was upgraded from SHA1 to SHA256 for signing. We must
We must upgrade PyBitmessage gracefully. `upgrade PyBitmessage gracefully. <https://github.com/Bitmessage/PyBitmessage/issues/953>`_
`More discussion. <https://github.com/yann2192/pyelliptic/issues/32>`_ `More discussion. <https://github.com/yann2192/pyelliptic/issues/32>`_
""" """
@ -69,7 +69,7 @@ def sign(msg, hexPrivkey):
"digestalg" setting "digestalg" setting
""" """
digestAlg = BMConfigParser().safeGet( digestAlg = BMConfigParser().safeGet(
'bitmessagesettings', 'digestalg', 'sha1') 'bitmessagesettings', 'digestalg', 'sha256')
if digestAlg == "sha1": if digestAlg == "sha1":
# SHA1, this will eventually be deprecated # SHA1, this will eventually be deprecated
return makeCryptor(hexPrivkey).sign( return makeCryptor(hexPrivkey).sign(

BIN
src/images/btc.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

BIN
src/images/buy.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

BIN
src/images/buynew.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

BIN
src/images/buynew1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

BIN
src/images/credits.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

BIN
src/images/creditss.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

BIN
src/images/gpay.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

BIN
src/images/gplay.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

BIN
src/images/gplayfinal.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
src/images/gplayss.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

BIN
src/images/images.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

BIN
src/images/paypal.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

View File

@ -0,0 +1,15 @@
"""
Exposes `XCamera` directly in `xcamera` rather than `xcamera.xcamera`.
Also note this may break `pip` since all imports within `xcamera.py` would be
required at setup time. This is because `version.py` (same directory) is used
by the `setup.py` file.
Hence we're not exposing `XCamera` if `pip` is detected.
"""
import os
project_dir = os.path.abspath(
os.path.join(__file__, os.pardir, os.pardir, os.pardir, os.pardir))
using_pip = os.path.basename(project_dir).startswith('pip-')
# only exposes `XCamera` if not within `pip` ongoing install
if not using_pip:
from .xcamera import XCamera # noqa

View File

@ -0,0 +1,85 @@
from kivy.logger import Logger
from jnius import JavaException, PythonJavaClass, autoclass, java_method
Camera = autoclass('android.hardware.Camera')
AndroidActivityInfo = autoclass('android.content.pm.ActivityInfo')
AndroidPythonActivity = autoclass('org.kivy.android.PythonActivity')
PORTRAIT = AndroidActivityInfo.SCREEN_ORIENTATION_PORTRAIT
LANDSCAPE = AndroidActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
class ShutterCallback(PythonJavaClass):
__javainterfaces__ = ('android.hardware.Camera$ShutterCallback', )
@java_method('()V')
def onShutter(self):
# apparently, it is enough to have an empty shutter callback to play
# the standard shutter sound. If you pass None instead of shutter_cb
# below, the standard sound doesn't play O_o
pass
class PictureCallback(PythonJavaClass):
__javainterfaces__ = ('android.hardware.Camera$PictureCallback', )
def __init__(self, filename, on_success):
super(PictureCallback, self).__init__()
self.filename = filename
self.on_success = on_success
@java_method('([BLandroid/hardware/Camera;)V')
def onPictureTaken(self, data, camera):
s = data.tostring()
with open(self.filename, 'wb') as f:
f.write(s)
Logger.info('xcamera: picture saved to %s', self.filename)
camera.startPreview()
self.on_success(self.filename)
class AutoFocusCallback(PythonJavaClass):
__javainterfaces__ = ('android.hardware.Camera$AutoFocusCallback', )
def __init__(self, filename, on_success):
super(AutoFocusCallback, self).__init__()
self.filename = filename
self.on_success = on_success
@java_method('(ZLandroid/hardware/Camera;)V')
def onAutoFocus(self, success, camera):
if success:
Logger.info('xcamera: autofocus succeeded, taking picture...')
shutter_cb = ShutterCallback()
picture_cb = PictureCallback(self.filename, self.on_success)
camera.takePicture(shutter_cb, None, picture_cb)
else:
Logger.info('xcamera: autofocus failed')
def take_picture(camera_widget, filename, on_success):
# to call the android API, we need access to the underlying
# android.hardware.Camera instance. However, there is no official way to
# retrieve it from the camera widget, so we need to dig into internal
# attributes :-( This works at least on kivy 1.9.1, but it might break any
# time soon.
camera = camera_widget._camera._android_camera
params = camera.getParameters()
params.setFocusMode("auto")
camera.setParameters(params)
cb = AutoFocusCallback(filename, on_success)
Logger.info('xcamera: starting autofocus...')
try:
camera.autoFocus(cb)
except JavaException as e:
Logger.info('Error when calling autofocus: {}'.format(e))
def set_orientation(value):
previous = get_orientation()
AndroidPythonActivity.mActivity.setRequestedOrientation(value)
return previous
def get_orientation():
return AndroidPythonActivity.mActivity.getRequestedOrientation()

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,43 @@
#!/usr/bin/env python
from kivy.app import App
from kivy.lang import Builder
kv = """
#:import XCamera kivy_garden.xcamera.XCamera
FloatLayout:
orientation: 'vertical'
XCamera:
id: xcamera
on_picture_taken: app.picture_taken(*args)
BoxLayout:
orientation: 'horizontal'
size_hint: 1, None
height: sp(50)
Button:
text: 'Set landscape'
on_release: xcamera.force_landscape()
Button:
text: 'Restore orientation'
on_release: xcamera.restore_orientation()
"""
class CameraApp(App):
def build(self):
return Builder.load_string(kv)
def picture_taken(self, obj, filename):
print('Picture taken and saved to {}'.format(filename))
def main():
CameraApp().run()
if __name__ == '__main__':
main()

View File

@ -0,0 +1,37 @@
from kivy.utils import platform
def play_shutter():
# bah, apparently we need to delay the import of kivy.core.audio, lese
# kivy cannot find a camera provider, at lease on linux. Maybe a
# gstreamer/pygame issue?
from kivy.core.audio import SoundLoader
sound = SoundLoader.load("data/shutter.wav")
sound.play()
if platform == 'android':
from .android_api import (
LANDSCAPE, PORTRAIT, take_picture, set_orientation, get_orientation)
else:
# generic fallback for taking pictures. Probably not the best quality,
# they are meant mostly for testing
LANDSCAPE = 'landscape'
PORTRAIT = 'portrait'
def take_picture(camera_widget, filename, on_success):
camera_widget.texture.save(filename, flipped=False)
play_shutter()
on_success(filename)
def set_orientation(value):
previous = get_orientation()
print('FAKE orientation set to {}'.format(value))
get_orientation.value = value
return previous
def get_orientation():
return get_orientation.value
get_orientation.value = PORTRAIT

View File

@ -0,0 +1 @@
__version__ = '2019.0928'

View File

@ -0,0 +1,41 @@
#:import xcamera kivy_garden.xcamera.xcamera
<XCameraIconButton>
icon_color: (0, 0, 0, 1)
_down_color: xcamera.darker(self.icon_color)
icon_size: dp(50)
canvas.before:
Color:
rgba: self.icon_color if self.state == 'normal' else self._down_color
Ellipse:
pos: self.pos
size: self.size
size_hint: None, None
size: self.icon_size, self.icon_size
font_size: self.icon_size/2
<XCamera>:
# \ue800 corresponds to the camera icon in the font
icon: u"[font=data/icons.ttf]\ue800[/font]"
icon_color: (0.13, 0.58, 0.95, 0.8)
icon_size: dp(70)
id: camera
resolution: 640, 480 #1920, 1080 # #
allow_stretch: True
# Shoot button
XCameraIconButton:
id: shoot_button
markup: True
text: root.icon
icon_color: root.icon_color
icon_size: root.icon_size
on_release: root.shoot()
# position
right: root.width - dp(10)
center_y: root.center_y

View File

@ -0,0 +1,116 @@
import datetime
import os
from kivy.clock import mainthread
from kivy.lang import Builder
from kivy.properties import ObjectProperty
from kivy.resources import resource_add_path
from kivy.uix.behaviors import ButtonBehavior
from kivy.uix.camera import Camera
from kivy.uix.label import Label
from kivy.utils import platform
from .platform_api import LANDSCAPE, set_orientation, take_picture
ROOT = os.path.dirname(os.path.abspath(__file__))
resource_add_path(ROOT)
def darker(color, factor=0.5):
r, g, b, a = color
r *= factor
g *= factor
b *= factor
return r, g, b, a
def get_filename():
return datetime.datetime.now().strftime('%Y-%m-%d %H.%M.%S.jpg')
def is_android():
return platform == 'android'
def check_camera_permission():
"""
Android runtime `CAMERA` permission check.
"""
if not is_android():
return True
from android.permissions import Permission, check_permission
permission = Permission.CAMERA
return check_permission(permission)
def check_request_camera_permission(callback=None):
"""
Android runtime `CAMERA` permission check & request.
"""
had_permission = check_camera_permission()
if not had_permission:
from android.permissions import Permission, request_permissions
permissions = [Permission.CAMERA]
request_permissions(permissions, callback)
return had_permission
class XCameraIconButton(ButtonBehavior, Label):
pass
class XCamera(Camera):
directory = ObjectProperty(None)
_previous_orientation = None
__events__ = ('on_picture_taken', 'on_camera_ready')
def __init__(self, **kwargs):
Builder.load_file(os.path.join(ROOT, "xcamera.kv"))
super().__init__(**kwargs)
def _on_index(self, *largs):
"""
Overrides `kivy.uix.camera.Camera._on_index()` to make sure
`camera.open()` is not called unless Android `CAMERA` permission is
granted, refs #5.
"""
@mainthread
def on_permissions_callback(permissions, grant_results):
"""
On camera permission callback calls parent `_on_index()` method.
"""
if all(grant_results):
self._on_index_dispatch(*largs)
if check_request_camera_permission(callback=on_permissions_callback):
self._on_index_dispatch(*largs)
def _on_index_dispatch(self, *largs):
super()._on_index(*largs)
self.dispatch('on_camera_ready')
def on_picture_taken(self, filename):
"""
This event is fired every time a picture has been taken.
"""
pass
def on_camera_ready(self):
"""
Fired when the camera is ready.
"""
pass
def shoot(self):
def on_success(filename):
self.dispatch('on_picture_taken', filename)
filename = get_filename()
if self.directory:
filename = os.path.join(self.directory, filename)
take_picture(self, filename, on_success)
def force_landscape(self):
self._previous_orientation = set_orientation(LANDSCAPE)
def restore_orientation(self):
if self._previous_orientation is not None:
set_orientation(self._previous_orientation)

View File

@ -0,0 +1,15 @@
"""
Exposes `ZBarCam` directly in `zbarcam` rather than `zbarcam.zbarcam`.
Also note this may break `pip` since all imports within `zbarcam.py` would be
required at setup time. This is because `version.py` (same directory) is used
by the `setup.py` file.
Hence we're not exposing `ZBarCam` if `pip` is detected.
"""
import os
project_dir = os.path.abspath(
os.path.join(__file__, os.pardir, os.pardir, os.pardir, os.pardir))
using_pip = os.path.basename(project_dir).startswith('pip-')
# only exposes `ZBarCam` if not within `pip` ongoing install
if not using_pip:
from .zbarcam import ZBarCam # noqa

View File

@ -0,0 +1,21 @@
from kivy.utils import platform
from PIL import ImageOps
def is_android():
return platform == 'android'
def is_ios():
return platform == 'ios'
def fix_android_image(pil_image):
"""
On Android, the image seems mirrored and rotated somehow, refs #32.
"""
if not is_android():
return pil_image
pil_image = pil_image.rotate(90)
pil_image = ImageOps.mirror(pil_image)
return pil_image

View File

@ -0,0 +1,7 @@
__version__ = '2019.1020'
# The `__version_code__` is used for the F-Droid auto update and should match
# the `versionCode` from the `build.gradle` file located in:
# `.buildozer/android/platform/build-*/dists/zbarcamdemo__*/build.gradle`
# The auto update method used is the `HTTP`, see:
# https://f-droid.org/en/docs/Build_Metadata_Reference/#UpdateCheckMode
__version_code__ = 721202920

View File

@ -0,0 +1,26 @@
#:import XCamera kivy_garden.xcamera.XCamera
#:import is_android kivy_garden.zbarcam.utils.is_android
<ZBarCam>:
Widget:
# invert width/height on rotated Android
# https://stackoverflow.com/a/45192295/185510
id: proxy
XCamera:
id: xcamera
play: True
resolution: root.resolution
allow_stretch: True
keep_ratio: True
center: self.size and proxy.center
size:
(proxy.height, proxy.width) if is_android() \
else (proxy.width, proxy.height)
# Android camera rotation workaround, refs:
# https://github.com/AndreMiras/garden.zbarcam/issues/3
canvas.before:
PushMatrix
Rotate:
angle: -90 if is_android() else 0
origin: self.center
canvas.after:
PopMatrix

View File

@ -0,0 +1,214 @@
import os
from collections import namedtuple
import PIL
from kivy.clock import Clock
from kivy.lang import Builder
from kivy.properties import ListProperty, ObjectProperty, NumericProperty
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.animation import Animation
from kivy.graphics import Color, Line
from pyzbar import pyzbar
from kivy.utils import platform
# from android.runnable import run_on_ui_thread
from .utils import fix_android_image
MODULE_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
from kivy.metrics import dp
class ZBarCam(BoxLayout):
"""
Widget that use the Camera and zbar to detect qrcode.
When found, the `codes` will be updated.
"""
resolution = ListProperty([640, 480])
qrwidth = dp(250) if platform=='android' else dp(600)
# qrwidth= dp(500) #width of QR code scanner
line_length= qrwidth/4 #width of boundary line (Focus Box)
scanner_line_y_initial= NumericProperty(0)
scanner_line_y_final= NumericProperty(0)
scanner_line_y= NumericProperty(0)
scanner_line_width= dp(2)
sscanner_line_alpha=1
border_line_alpha=0.4
symbols = ListProperty([])
Symbol = namedtuple('Symbol', ['type', 'data'])
scan_callback= ObjectProperty(None)
# checking all possible types by default
code_types = ListProperty(set(pyzbar.ZBarSymbol))
def __init__(self, **kwargs):
# lazy loading the kv file rather than loading at module level,
# that way the `XCamera` import doesn't happen too early
Builder.load_file(os.path.join(MODULE_DIRECTORY, "zbarcam.kv"))
super().__init__(**kwargs)
Clock.schedule_once(lambda dt: self._setup())
self.register_event_type("on_scan")
def _setup(self):
"""
Postpones some setup tasks that require self.ids dictionary.
"""
self._remove_shoot_button()
# `self.xcamera._camera` instance may not be available if e.g.
# the `CAMERA` permission is not granted
self.xcamera.bind(on_camera_ready=self._on_camera_ready)
# camera may still be ready before we bind the event
if self.xcamera._camera is not None:
self._on_camera_ready(self.xcamera)
def _on_camera_ready(self, xcamera):
"""
Starts binding when the `xcamera._camera` instance is ready.
"""
xcamera._camera.bind(on_texture=self._on_texture)
#print((self.scanner_line_y_initial, self.scanner_line_y_final))
#print(self.size[0])
Clock.schedule_once(lambda dt: self.start_animation(1), 0)
#start scanning animation
#self.init_scanner_line(self.scanner_line_y_final)
def _remove_shoot_button(self):
"""
Removes the "shoot button", see:
https://github.com/kivy-garden/garden.xcamera/pull/3
"""
xcamera = self.xcamera
shoot_button = xcamera.children[0]
xcamera.remove_widget(shoot_button)
def _on_texture(self, instance):
#print((self.scanner_line_y_initial, self.scanner_line_y_final))
#print(self.size[0])
self.symbols = self._detect_qrcode_frame(
texture=instance.texture, code_types=self.code_types)
txt= ', '.join([symbol.data.decode("utf-8") for symbol in self.symbols])
if txt:
self.scanner_line_alpha=0
self.dispatch("on_scan", txt)
else: self.scanner_line_alpha=1
def on_scan(self, text, *args):
if self.scan_callback:
self.scan_callback(text)
def init_scanner_line(self, *args):
self.scanner_line_y= self.scanner_line_y_initial
Clock.schedule_once(lambda dt: self._update_canvas())
self.update_scanner_line(self.scanner_line_y_final+self.scanner_line_width, self.scanner_line_y_initial-self.scanner_line_width)
def update_scanner_line(self, val1, val2, *args):
anim= Animation(
d=1.5,
scanner_line_y= val1,
)
anim += Animation(
d=1.5,
scanner_line_y= val2,
)
#anim.stop_all(self)
anim.bind(on_complete=self._repeat_anim)
anim.bind(on_progress=self._update_canvas)
anim.start(self)
def start_animation(self, val, *args):
anim= Animation(
d=.7,
border_line_alpha=val
)
anim.bind(on_complete=self._repeat_anim)
anim.bind(on_progress=self.update_border_line)
anim.start(self)
def _repeat_anim(self, inst, widget):
inst.unbind(on_complete=self._repeat_anim)
border_line_alpha = 0.4 if self.border_line_alpha==1 else 1
self.start_animation(border_line_alpha)
# self.update_scanner_line(self.scanner_line_y_final+self.scanner_line_width, self.scanner_line_y_initial-self.scanner_line_width)
def _update_canvas(self, *args):
self.canvas.remove_group("scanner_line")
with self.canvas:
Color(rgba=(0,1,0,self.scanner_line_alpha), group="scanner_line")
Line(
group="scanner_line",
points= [
self.size[0]/2-self.qrwidth/2+1, self.scanner_line_y,
self.size[0]/2+self.qrwidth/2-1, self.scanner_line_y
],
width=self.scanner_line_width,
cap="none"
)
def update_border_line(self, *args):
self.canvas.remove_group("qr_line")
with self.canvas:
Color(rgba=(1,1,1,self.border_line_alpha), group="qr_line")
#top left
Line(points=[\
self.size[0]/2-self.qrwidth/2, self.size[1]/2+self.qrwidth/2-self.line_length,\
self.size[0]/2-self.qrwidth/2, self.size[1]/2+self.qrwidth/2,\
self.size[0]/2-self.qrwidth/2+self.line_length, self.size[1]/2+self.qrwidth/2], width=dp(2),cap= "none", group="qr_line")
#top right
Line(points=[\
self.size[0]/2+self.qrwidth/2, self.size[1]/2+self.qrwidth/2-self.line_length,\
self.size[0]/2+self.qrwidth/2, self.size[1]/2+self.qrwidth/2,\
self.size[0]/2+self.qrwidth/2-self.line_length, self.size[1]/2+self.qrwidth/2], width=dp(2),cap= "none", group="qr_line")
#bottom right
Line(points=[\
self.size[0]/2+self.qrwidth/2, self.size[1]/2-self.qrwidth/2+self.line_length,\
self.size[0]/2+self.qrwidth/2, self.size[1]/2-self.qrwidth/2,\
self.size[0]/2+self.qrwidth/2-self.line_length, self.size[1]/2-self.qrwidth/2], width= dp(2), cap="none", group="qr_line")
#bottom left
Line(points=[\
self.size[0]/2-self.qrwidth/2, self.size[1]/2-self.qrwidth/2+self.line_length,\
self.size[0]/2-self.qrwidth/2, self.size[1]/2-self.qrwidth/2,\
self.size[0]/2-self.qrwidth/2+self.line_length, self.size[1]/2-self.qrwidth/2],width= dp(2),cap= "none", group="qr_line")
@classmethod
def _detect_qrcode_frame(cls, texture, code_types):
image_data = texture.pixels
size = texture.size
#print(cls.height.value, cls.width)
#print(image_data)
# Fix for mode mismatch between texture.colorfmt and data returned by
# texture.pixels. texture.pixels always returns RGBA, so that should
# be passed to PIL no matter what texture.colorfmt returns. refs:
# https://github.com/AndreMiras/garden.zbarcam/issues/41
pil_image = PIL.Image.frombytes(mode='RGBA', size=size,
data=image_data)
pil_image = fix_android_image(pil_image)
pil_image.thumbnail(size, PIL.Image.ANTIALIAS)
qrwidth= cls.qrwidth
cropped_image = pil_image.crop((size[0]/2-qrwidth/4.5,size[1]/2-qrwidth/4.5,size[0]/2+qrwidth/4.5,size[1]/2+qrwidth/4.5))
#print(pil_image.size)
symbols = []
codes = pyzbar.decode(cropped_image, symbols=code_types)
for code in codes:
symbol = ZBarCam.Symbol(type=code.type, data=code.data)
symbols.append(symbol)
return symbols
@property
def xcamera(self):
return self.ids['xcamera']
def start(self):
self.xcamera.play = True
def stop(self):
self.xcamera.play = False

View File

@ -444,9 +444,10 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
if stream not in state.streamsInWhichIAmParticipating: if stream not in state.streamsInWhichIAmParticipating:
continue continue
if ( if (
decodedIP and time.time() - seenTime > 0 and decodedIP
seenTime > time.time() - ADDRESS_ALIVE and and time.time() - seenTime > 0
port > 0 and seenTime > time.time() - ADDRESS_ALIVE
and port > 0
): ):
peer = Peer(decodedIP, port) peer = Peer(decodedIP, port)
try: try:
@ -514,9 +515,11 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
Incoming version. Incoming version.
Parse and log, remember important things, like streams, bitfields, etc. Parse and log, remember important things, like streams, bitfields, etc.
""" """
decoded = self.decode_payload_content("IQQiiQlslv")
(self.remoteProtocolVersion, self.services, self.timestamp, (self.remoteProtocolVersion, self.services, self.timestamp,
self.sockNode, self.peerNode, self.nonce, self.userAgent, self.sockNode, self.peerNode, self.nonce, self.userAgent
self.streams) = self.decode_payload_content("IQQiiQlsLv") ) = decoded[:7]
self.streams = decoded[7:]
self.nonce = struct.pack('>Q', self.nonce) self.nonce = struct.pack('>Q', self.nonce)
self.timeOffset = self.timestamp - int(time.time()) self.timeOffset = self.timestamp - int(time.time())
logger.debug('remoteProtocolVersion: %i', self.remoteProtocolVersion) logger.debug('remoteProtocolVersion: %i', self.remoteProtocolVersion)
@ -541,7 +544,8 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
logger.debug( logger.debug(
'%(host)s:%(port)i sending version', '%(host)s:%(port)i sending version',
self.destination._asdict()) self.destination._asdict())
if self.services & protocol.NODE_SSL == protocol.NODE_SSL: if ((self.services & protocol.NODE_SSL == protocol.NODE_SSL)
and protocol.haveSSL(not self.isOutbound)):
self.isSSL = True self.isSSL = True
if not self.verackReceived: if not self.verackReceived:
return True return True
@ -599,7 +603,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
'Closed connection to {} because we are already connected' 'Closed connection to {} because we are already connected'
' to that IP.'.format(self.destination)) ' to that IP.'.format(self.destination))
return False return False
except: except Exception:
pass pass
if not self.isOutbound: if not self.isOutbound:
# incoming from a peer we're connected to as outbound, # incoming from a peer we're connected to as outbound,

View File

@ -89,6 +89,7 @@ class BMConnectionPool(object):
def connectToStream(self, streamNumber): def connectToStream(self, streamNumber):
"""Connect to a bitmessage stream""" """Connect to a bitmessage stream"""
self.streams.append(streamNumber) self.streams.append(streamNumber)
state.streamsInWhichIAmParticipating.append(streamNumber)
def getConnectionByAddr(self, addr): def getConnectionByAddr(self, addr):
""" """

View File

@ -14,7 +14,6 @@ from network import connectionpool
import helper_random import helper_random
import knownnodes import knownnodes
import protocol import protocol
import shared
import state import state
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from helper_random import randomBytes from helper_random import randomBytes
@ -35,6 +34,9 @@ from queues import UISignalQueue, invQueue, receiveDataQueue
logger = logging.getLogger('default') logger = logging.getLogger('default')
maximumAgeOfNodesThatIAdvertiseToOthers = 10800 #: Equals three hours
class TCPConnection(BMProto, TLSDispatcher): class TCPConnection(BMProto, TLSDispatcher):
# pylint: disable=too-many-instance-attributes # pylint: disable=too-many-instance-attributes
""" """
@ -142,7 +144,7 @@ class TCPConnection(BMProto, TLSDispatcher):
def set_connection_fully_established(self): def set_connection_fully_established(self):
"""Initiate inventory synchronisation.""" """Initiate inventory synchronisation."""
if not self.isOutbound and not self.local: if not self.isOutbound and not self.local:
shared.clientHasReceivedIncomingConnections = True state.clientHasReceivedIncomingConnections = True
UISignalQueue.put(('setStatusIcon', 'green')) UISignalQueue.put(('setStatusIcon', 'green'))
UISignalQueue.put( UISignalQueue.put(
('updateNetworkStatusTab', ( ('updateNetworkStatusTab', (
@ -176,7 +178,7 @@ class TCPConnection(BMProto, TLSDispatcher):
filtered = [ filtered = [
(k, v) for k, v in iter(nodes.items()) (k, v) for k, v in iter(nodes.items())
if v["lastseen"] > int(time.time()) - if v["lastseen"] > int(time.time()) -
shared.maximumAgeOfNodesThatIAdvertiseToOthers and maximumAgeOfNodesThatIAdvertiseToOthers and
v["rating"] >= 0 and len(k.host) <= 22 v["rating"] >= 0 and len(k.host) <= 22
] ]
# sent 250 only if the remote isn't interested in it # sent 250 only if the remote isn't interested in it

View File

@ -12,6 +12,7 @@ This is an abandoned package maintained inside of the PyBitmessage.
from .cipher import Cipher from .cipher import Cipher
from .ecc import ECC from .ecc import ECC
from .eccblind import ECCBlind from .eccblind import ECCBlind
from .eccblindchain import ECCBlindChain
from .hash import hmac_sha256, hmac_sha512, pbkdf2 from .hash import hmac_sha256, hmac_sha512, pbkdf2
from .openssl import OpenSSL from .openssl import OpenSSL
@ -21,6 +22,7 @@ __all__ = [
'OpenSSL', 'OpenSSL',
'ECC', 'ECC',
'ECCBlind', 'ECCBlind',
'ECCBlindChain',
'Cipher', 'Cipher',
'hmac_sha256', 'hmac_sha256',
'hmac_sha512', 'hmac_sha512',

View File

@ -10,8 +10,70 @@ http://www.isecure-journal.com/article_39171_47f9ec605dd3918c2793565ec21fcd7a.pd
# variable names are based on the math in the paper, so they don't conform # variable names are based on the math in the paper, so they don't conform
# to PEP8 # to PEP8
import time
from hashlib import sha256
from struct import pack, unpack
from .openssl import OpenSSL from .openssl import OpenSSL
# first byte in serialisation can contain data
Y_BIT = 0x01
COMPRESSED_BIT = 0x02
# formats
BIGNUM = '!32s'
EC = '!B32s'
PUBKEY = '!BB33s'
class Expiration(object):
"""Expiration of pubkey"""
@staticmethod
def deserialize(val):
"""Create an object out of int"""
year = ((val & 0xF0) >> 4) + 2020
month = val & 0x0F
assert month < 12
return Expiration(year, month)
def __init__(self, year, month):
assert isinstance(year, int)
assert year > 2019 and year < 2036
assert isinstance(month, int)
assert month < 12
self.year = year
self.month = month
self.exp = year + month / 12.0
def serialize(self):
"""Make int out of object"""
return ((self.year - 2020) << 4) + self.month
def verify(self):
"""Check if the pubkey has expired"""
now = time.gmtime()
return self.exp >= now.tm_year + (now.tm_mon - 1) / 12.0
class Value(object):
"""Value of a pubkey"""
@staticmethod
def deserialize(val):
"""Make object out of int"""
return Value(val)
def __init__(self, value=0xFF):
assert isinstance(value, int)
self.value = value
def serialize(self):
"""Make int out of object"""
return self.value & 0xFF
def verify(self, value):
"""Verify against supplied value"""
return value <= self.value
class ECCBlind(object): # pylint: disable=too-many-instance-attributes class ECCBlind(object): # pylint: disable=too-many-instance-attributes
""" """
@ -21,8 +83,8 @@ class ECCBlind(object): # pylint: disable=too-many-instance-attributes
# init # init
k = None k = None
R = None R = None
keypair = None
F = None F = None
d = None
Q = None Q = None
a = None a = None
b = None b = None
@ -33,92 +95,183 @@ class ECCBlind(object): # pylint: disable=too-many-instance-attributes
m_ = None m_ = None
s_ = None s_ = None
signature = None signature = None
exp = None
val = None
@staticmethod def ec_get_random(self):
def ec_get_random(group, ctx):
""" """
Random point from finite field Random integer within the EC order
""" """
order = OpenSSL.BN_new() randomnum = OpenSSL.BN_new()
OpenSSL.EC_GROUP_get_order(group, order, ctx) OpenSSL.BN_rand(randomnum, OpenSSL.BN_num_bits(self.n), 0, 0)
OpenSSL.BN_rand(order, OpenSSL.BN_num_bits(order), 0, 0) return randomnum
return order
@staticmethod def ec_invert(self, a):
def ec_invert(group, a, ctx):
""" """
ECC inversion ECC inversion
""" """
order = OpenSSL.BN_new() inverse = OpenSSL.BN_mod_inverse(0, a, self.n, self.ctx)
OpenSSL.EC_GROUP_get_order(group, order, ctx)
inverse = OpenSSL.BN_mod_inverse(0, a, order, ctx)
return inverse return inverse
@staticmethod def ec_gen_keypair(self):
def ec_gen_keypair(group, ctx):
""" """
Generate an ECC keypair Generate an ECC keypair
We're using compressed keys
""" """
d = ECCBlind.ec_get_random(group, ctx) d = self.ec_get_random()
Q = OpenSSL.EC_POINT_new(group) Q = OpenSSL.EC_POINT_new(self.group)
OpenSSL.EC_POINT_mul(group, Q, d, 0, 0, 0) OpenSSL.EC_POINT_mul(self.group, Q, d, 0, 0, 0)
return (d, Q) return (d, Q)
@staticmethod def ec_Ftor(self, F):
def ec_Ftor(F, group, ctx):
""" """
x0 coordinate of F x0 coordinate of F
""" """
# F = (x0, y0) # F = (x0, y0)
x0 = OpenSSL.BN_new() x0 = OpenSSL.BN_new()
y0 = OpenSSL.BN_new() y0 = OpenSSL.BN_new()
OpenSSL.EC_POINT_get_affine_coordinates_GFp(group, F, x0, y0, ctx) OpenSSL.EC_POINT_get_affine_coordinates(self.group, F, x0, y0, self.ctx)
OpenSSL.BN_free(y0)
return x0 return x0
def __init__(self, curve="secp256k1", pubkey=None): def _ec_point_serialize(self, point):
"""Make an EC point into a string"""
try:
x = OpenSSL.BN_new()
y = OpenSSL.BN_new()
OpenSSL.EC_POINT_get_affine_coordinates(
self.group, point, x, y, 0)
y_byte = (OpenSSL.BN_is_odd(y) & Y_BIT) | COMPRESSED_BIT
l_ = OpenSSL.BN_num_bytes(self.n)
try:
bx = OpenSSL.malloc(0, l_)
OpenSSL.BN_bn2binpad(x, bx, l_)
out = bx.raw
except AttributeError:
# padding manually
bx = OpenSSL.malloc(0, OpenSSL.BN_num_bytes(x))
OpenSSL.BN_bn2bin(x, bx)
out = bx.raw.rjust(l_, chr(0))
return pack(EC, y_byte, out)
finally:
OpenSSL.BN_clear_free(x)
OpenSSL.BN_clear_free(y)
def _ec_point_deserialize(self, data):
"""Make a string into an EC point"""
y_bit, x_raw = unpack(EC, data)
x = OpenSSL.BN_bin2bn(x_raw, OpenSSL.BN_num_bytes(self.n), 0)
y_bit &= Y_BIT
retval = OpenSSL.EC_POINT_new(self.group)
OpenSSL.EC_POINT_set_compressed_coordinates(self.group,
retval,
x,
y_bit,
self.ctx)
return retval
def _bn_serialize(self, bn):
"""Make a string out of BigNum"""
l_ = OpenSSL.BN_num_bytes(self.n)
try:
o = OpenSSL.malloc(0, l_)
OpenSSL.BN_bn2binpad(bn, o, l_)
return o.raw
except AttributeError:
o = OpenSSL.malloc(0, OpenSSL.BN_num_bytes(bn))
OpenSSL.BN_bn2bin(bn, o)
return o.raw.rjust(l_, chr(0))
def _bn_deserialize(self, data):
"""Make a BigNum out of string"""
x = OpenSSL.BN_bin2bn(data, OpenSSL.BN_num_bytes(self.n), 0)
return x
def _init_privkey(self, privkey):
"""Initialise private key out of string/bytes"""
self.d = self._bn_deserialize(privkey)
def privkey(self):
"""Make a private key into a string"""
return pack(BIGNUM, self.d)
def _init_pubkey(self, pubkey):
"""Initialise pubkey out of string/bytes"""
unpacked = unpack(PUBKEY, pubkey)
self.expiration = Expiration.deserialize(unpacked[0])
self.value = Value.deserialize(unpacked[1])
self.Q = self._ec_point_deserialize(unpacked[2])
def pubkey(self):
"""Make a pubkey into a string"""
return pack(PUBKEY, self.expiration.serialize(),
self.value.serialize(),
self._ec_point_serialize(self.Q))
def __init__(self, curve="secp256k1", pubkey=None, privkey=None, # pylint: disable=too-many-arguments
year=2025, month=11, value=0xFF):
self.ctx = OpenSSL.BN_CTX_new() self.ctx = OpenSSL.BN_CTX_new()
if pubkey: # ECC group
self.group, self.G, self.n, self.Q = pubkey self.group = OpenSSL.EC_GROUP_new_by_curve_name(
else: OpenSSL.get_curve(curve))
self.group = OpenSSL.EC_GROUP_new_by_curve_name(
OpenSSL.get_curve(curve))
# Order n
self.n = OpenSSL.BN_new()
OpenSSL.EC_GROUP_get_order(self.group, self.n, self.ctx)
# Generator G # Order n
self.G = OpenSSL.EC_GROUP_get0_generator(self.group) self.n = OpenSSL.BN_new()
OpenSSL.EC_GROUP_get_order(self.group, self.n, self.ctx)
# new keypair # Generator G
self.keypair = ECCBlind.ec_gen_keypair(self.group, self.ctx) self.G = OpenSSL.EC_GROUP_get0_generator(self.group)
self.Q = self.keypair[1]
self.pubkey = (self.group, self.G, self.n, self.Q)
# Identity O (infinity) # Identity O (infinity)
self.iO = OpenSSL.EC_POINT_new(self.group) self.iO = OpenSSL.EC_POINT_new(self.group)
OpenSSL.EC_POINT_set_to_infinity(self.group, self.iO) OpenSSL.EC_POINT_set_to_infinity(self.group, self.iO)
if privkey:
assert pubkey
# load both pubkey and privkey from bytes
self._init_privkey(privkey)
self._init_pubkey(pubkey)
elif pubkey:
# load pubkey from bytes
self._init_pubkey(pubkey)
else:
# new keypair
self.d, self.Q = self.ec_gen_keypair()
if not year or not month:
now = time.gmtime()
if now.tm_mon == 12:
self.expiration = Expiration(now.tm_year + 1, 1)
else:
self.expiration = Expiration(now.tm_year, now.tm_mon + 1)
else:
self.expiration = Expiration(year, month)
self.value = Value(value)
def __del__(self):
OpenSSL.BN_free(self.n)
OpenSSL.BN_CTX_free(self.ctx)
def signer_init(self): def signer_init(self):
""" """
Init signer Init signer
""" """
# Signer: Random integer k # Signer: Random integer k
self.k = ECCBlind.ec_get_random(self.group, self.ctx) self.k = self.ec_get_random()
# R = kG # R = kG
self.R = OpenSSL.EC_POINT_new(self.group) self.R = OpenSSL.EC_POINT_new(self.group)
OpenSSL.EC_POINT_mul(self.group, self.R, self.k, 0, 0, 0) OpenSSL.EC_POINT_mul(self.group, self.R, self.k, 0, 0, 0)
return self.R return self._ec_point_serialize(self.R)
def create_signing_request(self, R, msg): def create_signing_request(self, R, msg):
""" """
Requester creates a new signing request Requester creates a new signing request
""" """
self.R = R self.R = self._ec_point_deserialize(R)
msghash = sha256(msg).digest()
# Requester: 3 random blinding factors # Requester: 3 random blinding factors
self.F = OpenSSL.EC_POINT_new(self.group) self.F = OpenSSL.EC_POINT_new(self.group)
@ -128,12 +281,12 @@ class ECCBlind(object): # pylint: disable=too-many-instance-attributes
# F != O # F != O
while OpenSSL.EC_POINT_cmp(self.group, self.F, self.iO, self.ctx) == 0: while OpenSSL.EC_POINT_cmp(self.group, self.F, self.iO, self.ctx) == 0:
self.a = ECCBlind.ec_get_random(self.group, self.ctx) self.a = self.ec_get_random()
self.b = ECCBlind.ec_get_random(self.group, self.ctx) self.b = self.ec_get_random()
self.c = ECCBlind.ec_get_random(self.group, self.ctx) self.c = self.ec_get_random()
# F = b^-1 * R... # F = b^-1 * R...
self.binv = ECCBlind.ec_invert(self.group, self.b, self.ctx) self.binv = self.ec_invert(self.b)
OpenSSL.EC_POINT_mul(self.group, temp, 0, self.R, self.binv, 0) OpenSSL.EC_POINT_mul(self.group, temp, 0, self.R, self.binv, 0)
OpenSSL.EC_POINT_copy(self.F, temp) OpenSSL.EC_POINT_copy(self.F, temp)
@ -147,52 +300,58 @@ class ECCBlind(object): # pylint: disable=too-many-instance-attributes
OpenSSL.EC_POINT_add(self.group, self.F, self.F, temp, 0) OpenSSL.EC_POINT_add(self.group, self.F, self.F, temp, 0)
# F = (x0, y0) # F = (x0, y0)
self.r = ECCBlind.ec_Ftor(self.F, self.group, self.ctx) self.r = self.ec_Ftor(self.F)
# Requester: Blinding (m' = br(m) + a) # Requester: Blinding (m' = br(m) + a)
self.m = OpenSSL.BN_new() self.m = OpenSSL.BN_new()
OpenSSL.BN_bin2bn(msg, len(msg), self.m) OpenSSL.BN_bin2bn(msghash, len(msghash), self.m)
self.m_ = OpenSSL.BN_new() self.m_ = OpenSSL.BN_new()
OpenSSL.BN_mod_mul(self.m_, self.b, self.r, self.n, self.ctx) OpenSSL.BN_mod_mul(self.m_, self.b, self.r, self.n, self.ctx)
OpenSSL.BN_mod_mul(self.m_, self.m_, self.m, self.n, self.ctx) OpenSSL.BN_mod_mul(self.m_, self.m_, self.m, self.n, self.ctx)
OpenSSL.BN_mod_add(self.m_, self.m_, self.a, self.n, self.ctx) OpenSSL.BN_mod_add(self.m_, self.m_, self.a, self.n, self.ctx)
return self.m_ return self._bn_serialize(self.m_)
def blind_sign(self, m_): def blind_sign(self, m_):
""" """
Signer blind-signs the request Signer blind-signs the request
""" """
self.m_ = m_ self.m_ = self._bn_deserialize(m_)
self.s_ = OpenSSL.BN_new() self.s_ = OpenSSL.BN_new()
OpenSSL.BN_mod_mul(self.s_, self.keypair[0], self.m_, self.n, self.ctx) OpenSSL.BN_mod_mul(self.s_, self.d, self.m_, self.n, self.ctx)
OpenSSL.BN_mod_add(self.s_, self.s_, self.k, self.n, self.ctx) OpenSSL.BN_mod_add(self.s_, self.s_, self.k, self.n, self.ctx)
return self.s_ OpenSSL.BN_free(self.k)
return self._bn_serialize(self.s_)
def unblind(self, s_): def unblind(self, s_):
""" """
Requester unblinds the signature Requester unblinds the signature
""" """
self.s_ = s_ self.s_ = self._bn_deserialize(s_)
s = OpenSSL.BN_new() s = OpenSSL.BN_new()
OpenSSL.BN_mod_mul(s, self.binv, self.s_, self.n, self.ctx) OpenSSL.BN_mod_mul(s, self.binv, self.s_, self.n, self.ctx)
OpenSSL.BN_mod_add(s, s, self.c, self.n, self.ctx) OpenSSL.BN_mod_add(s, s, self.c, self.n, self.ctx)
OpenSSL.BN_free(self.a)
OpenSSL.BN_free(self.b)
OpenSSL.BN_free(self.c)
self.signature = (s, self.F) self.signature = (s, self.F)
return self.signature return self._bn_serialize(s) + self._ec_point_serialize(self.F)
def verify(self, msg, signature): def verify(self, msg, signature, value=1):
""" """
Verify signature with certifier's pubkey Verify signature with certifier's pubkey
""" """
# convert msg to BIGNUM # convert msg to BIGNUM
self.m = OpenSSL.BN_new() self.m = OpenSSL.BN_new()
OpenSSL.BN_bin2bn(msg, len(msg), self.m) msghash = sha256(msg).digest()
OpenSSL.BN_bin2bn(msghash, len(msghash), self.m)
# init # init
s, self.F = signature s, self.F = (self._bn_deserialize(signature[0:32]),
self._ec_point_deserialize(signature[32:]))
if self.r is None: if self.r is None:
self.r = ECCBlind.ec_Ftor(self.F, self.group, self.ctx) self.r = self.ec_Ftor(self.F)
lhs = OpenSSL.EC_POINT_new(self.group) lhs = OpenSSL.EC_POINT_new(self.group)
rhs = OpenSSL.EC_POINT_new(self.group) rhs = OpenSSL.EC_POINT_new(self.group)
@ -206,5 +365,10 @@ class ECCBlind(object): # pylint: disable=too-many-instance-attributes
retval = OpenSSL.EC_POINT_cmp(self.group, lhs, rhs, self.ctx) retval = OpenSSL.EC_POINT_cmp(self.group, lhs, rhs, self.ctx)
if retval == -1: if retval == -1:
raise RuntimeError("EC_POINT_cmp returned an error") raise RuntimeError("EC_POINT_cmp returned an error")
else: elif not self.value.verify(value):
return retval == 0 return False
elif not self.expiration.verify():
return False
elif retval != 0:
return False
return True

View File

@ -0,0 +1,52 @@
"""
Blind signature chain with a top level CA
"""
from .eccblind import ECCBlind
class ECCBlindChain(object): # pylint: disable=too-few-public-methods
"""
# Class for ECC Blind Chain signature functionality
"""
def __init__(self, ca=None, chain=None):
self.chain = []
self.ca = []
if ca:
for i in range(0, len(ca), 35):
self.ca.append(ca[i:i + 35])
if chain:
self.chain.append(chain[0:35])
for i in range(35, len(chain), 100):
if len(chain[i:]) == 65:
self.chain.append(chain[i:i + 65])
else:
self.chain.append(chain[i:i + 100])
def verify(self, msg, value):
"""Verify a chain provides supplied message and value"""
parent = None
l_ = 0
for level in self.chain:
l_ += 1
pubkey = None
signature = None
if len(level) == 100:
pubkey, signature = (level[0:35], level[35:])
elif len(level) == 35:
if level not in self.ca:
return False
parent = level
continue
else:
signature = level
verifier_obj = ECCBlind(pubkey=parent)
if pubkey:
if not verifier_obj.verify(pubkey, signature, value):
return False
parent = pubkey
else:
return verifier_obj.verify(msg=msg, signature=signature,
value=value)
return None

View File

@ -10,6 +10,7 @@ needed openssl functionality in class _OpenSSL.
import ctypes import ctypes
from kivy.utils import platform from kivy.utils import platform
import sys import sys
# pylint: disable=protected-access # pylint: disable=protected-access
OpenSSL = None OpenSSL = None
@ -97,6 +98,10 @@ class _OpenSSL(object):
self.BN_free.restype = None self.BN_free.restype = None
self.BN_free.argtypes = [ctypes.c_void_p] self.BN_free.argtypes = [ctypes.c_void_p]
self.BN_clear_free = self._lib.BN_clear_free
self.BN_clear_free.restype = None
self.BN_clear_free.argtypes = [ctypes.c_void_p]
self.BN_num_bits = self._lib.BN_num_bits self.BN_num_bits = self._lib.BN_num_bits
self.BN_num_bits.restype = ctypes.c_int self.BN_num_bits.restype = ctypes.c_int
self.BN_num_bits.argtypes = [ctypes.c_void_p] self.BN_num_bits.argtypes = [ctypes.c_void_p]
@ -105,6 +110,15 @@ class _OpenSSL(object):
self.BN_bn2bin.restype = ctypes.c_int self.BN_bn2bin.restype = ctypes.c_int
self.BN_bn2bin.argtypes = [ctypes.c_void_p, ctypes.c_void_p] self.BN_bn2bin.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
try:
self.BN_bn2binpad = self._lib.BN_bn2binpad
self.BN_bn2binpad.restype = ctypes.c_int
self.BN_bn2binpad.argtypes = [ctypes.c_void_p, ctypes.c_void_p,
ctypes.c_int]
except AttributeError:
# optional, we have a workaround
pass
self.BN_bin2bn = self._lib.BN_bin2bn self.BN_bin2bn = self._lib.BN_bin2bn
self.BN_bin2bn.restype = ctypes.c_void_p self.BN_bin2bn.restype = ctypes.c_void_p
self.BN_bin2bn.argtypes = [ctypes.c_void_p, ctypes.c_int, self.BN_bin2bn.argtypes = [ctypes.c_void_p, ctypes.c_int,
@ -147,6 +161,20 @@ class _OpenSSL(object):
ctypes.c_void_p, ctypes.c_void_p,
ctypes.c_void_p] ctypes.c_void_p]
try:
self.EC_POINT_get_affine_coordinates = \
self._lib.EC_POINT_get_affine_coordinates
except AttributeError:
# OpenSSL docs say only use this for backwards compatibility
self.EC_POINT_get_affine_coordinates = \
self._lib.EC_POINT_get_affine_coordinates_GF2m
self.EC_POINT_get_affine_coordinates.restype = ctypes.c_int
self.EC_POINT_get_affine_coordinates.argtypes = [ctypes.c_void_p,
ctypes.c_void_p,
ctypes.c_void_p,
ctypes.c_void_p,
ctypes.c_void_p]
self.EC_KEY_set_private_key = self._lib.EC_KEY_set_private_key self.EC_KEY_set_private_key = self._lib.EC_KEY_set_private_key
self.EC_KEY_set_private_key.restype = ctypes.c_int self.EC_KEY_set_private_key.restype = ctypes.c_int
self.EC_KEY_set_private_key.argtypes = [ctypes.c_void_p, self.EC_KEY_set_private_key.argtypes = [ctypes.c_void_p,
@ -171,6 +199,34 @@ class _OpenSSL(object):
ctypes.c_void_p, ctypes.c_void_p,
ctypes.c_void_p] ctypes.c_void_p]
try:
self.EC_POINT_set_affine_coordinates = \
self._lib.EC_POINT_set_affine_coordinates
except AttributeError:
# OpenSSL docs say only use this for backwards compatibility
self.EC_POINT_set_affine_coordinates = \
self._lib.EC_POINT_set_affine_coordinates_GF2m
self.EC_POINT_set_affine_coordinates.restype = ctypes.c_int
self.EC_POINT_set_affine_coordinates.argtypes = [ctypes.c_void_p,
ctypes.c_void_p,
ctypes.c_void_p,
ctypes.c_void_p,
ctypes.c_void_p]
try:
self.EC_POINT_set_compressed_coordinates = \
self._lib.EC_POINT_set_compressed_coordinates
except AttributeError:
# OpenSSL docs say only use this for backwards compatibility
self.EC_POINT_set_compressed_coordinates = \
self._lib.EC_POINT_set_compressed_coordinates_GF2m
self.EC_POINT_set_compressed_coordinates.restype = ctypes.c_int
self.EC_POINT_set_compressed_coordinates.argtypes = [ctypes.c_void_p,
ctypes.c_void_p,
ctypes.c_void_p,
ctypes.c_int,
ctypes.c_void_p]
self.EC_POINT_new = self._lib.EC_POINT_new self.EC_POINT_new = self._lib.EC_POINT_new
self.EC_POINT_new.restype = ctypes.c_void_p self.EC_POINT_new.restype = ctypes.c_void_p
self.EC_POINT_new.argtypes = [ctypes.c_void_p] self.EC_POINT_new.argtypes = [ctypes.c_void_p]
@ -215,10 +271,6 @@ class _OpenSSL(object):
self._lib.ECDH_set_method.argtypes = [ctypes.c_void_p, self._lib.ECDH_set_method.argtypes = [ctypes.c_void_p,
ctypes.c_void_p] ctypes.c_void_p]
self.BN_CTX_new = self._lib.BN_CTX_new
self._lib.BN_CTX_new.restype = ctypes.c_void_p
self._lib.BN_CTX_new.argtypes = []
self.ECDH_compute_key = self._lib.ECDH_compute_key self.ECDH_compute_key = self._lib.ECDH_compute_key
self.ECDH_compute_key.restype = ctypes.c_int self.ECDH_compute_key.restype = ctypes.c_int
self.ECDH_compute_key.argtypes = [ctypes.c_void_p, self.ECDH_compute_key.argtypes = [ctypes.c_void_p,
@ -401,7 +453,7 @@ class _OpenSSL(object):
try: try:
self.PKCS5_PBKDF2_HMAC = self._lib.PKCS5_PBKDF2_HMAC self.PKCS5_PBKDF2_HMAC = self._lib.PKCS5_PBKDF2_HMAC
except: except Exception:
# The above is not compatible with all versions of OSX. # The above is not compatible with all versions of OSX.
self.PKCS5_PBKDF2_HMAC = self._lib.PKCS5_PBKDF2_HMAC_SHA1 self.PKCS5_PBKDF2_HMAC = self._lib.PKCS5_PBKDF2_HMAC_SHA1
@ -477,13 +529,19 @@ class _OpenSSL(object):
self.BN_cmp.argtypes = [ctypes.c_void_p, self.BN_cmp.argtypes = [ctypes.c_void_p,
ctypes.c_void_p] ctypes.c_void_p]
try:
self.BN_is_odd = self._lib.BN_is_odd
self.BN_is_odd.restype = ctypes.c_int
self.BN_is_odd.argtypes = [ctypes.c_void_p]
except AttributeError:
# OpenSSL 1.1.0 implements this as a function, but earlier
# versions as macro, so we need to workaround
self.BN_is_odd = self.BN_is_odd_compatible
self.BN_bn2dec = self._lib.BN_bn2dec self.BN_bn2dec = self._lib.BN_bn2dec
self.BN_bn2dec.restype = ctypes.c_char_p self.BN_bn2dec.restype = ctypes.c_char_p
self.BN_bn2dec.argtypes = [ctypes.c_void_p] self.BN_bn2dec.argtypes = [ctypes.c_void_p]
self.BN_CTX_free = self._lib.BN_CTX_free
self.BN_CTX_free.argtypes = [ctypes.c_void_p]
self.EC_GROUP_new_by_curve_name = self._lib.EC_GROUP_new_by_curve_name self.EC_GROUP_new_by_curve_name = self._lib.EC_GROUP_new_by_curve_name
self.EC_GROUP_new_by_curve_name.restype = ctypes.c_void_p self.EC_GROUP_new_by_curve_name.restype = ctypes.c_void_p
self.EC_GROUP_new_by_curve_name.argtypes = [ctypes.c_int] self.EC_GROUP_new_by_curve_name.argtypes = [ctypes.c_int]
@ -600,6 +658,16 @@ class _OpenSSL(object):
""" """
return int((self.BN_num_bits(x) + 7) / 8) return int((self.BN_num_bits(x) + 7) / 8)
def BN_is_odd_compatible(self, x):
"""
returns if BN is odd
we assume big endianness, and that BN is initialised
"""
length = self.BN_num_bytes(x)
data = self.malloc(0, length)
OpenSSL.BN_bn2bin(x, data)
return ord(data[length - 1]) & 1
def get_cipher(self, name): def get_cipher(self, name):
""" """
returns the OpenSSL cipher instance returns the OpenSSL cipher instance
@ -735,7 +803,7 @@ def loadOpenSSL():
try: try:
OpenSSL = _OpenSSL(library) OpenSSL = _OpenSSL(library)
return return
except: except Exception:
pass pass
raise Exception( raise Exception(
"Couldn't find and load the OpenSSL library. You must install it.") "Couldn't find and load the OpenSSL library. You must install it.")

View File

@ -13,7 +13,6 @@ import os
import stat import stat
import subprocess import subprocess
import sys import sys
import threading
from binascii import hexlify from binascii import hexlify
from pyelliptic import arithmetic from pyelliptic import arithmetic
from kivy.utils import platform from kivy.utils import platform
@ -27,19 +26,6 @@ from debug import logger
from helper_sql import sqlQuery from helper_sql import sqlQuery
# pylint: disable=logging-format-interpolation # pylint: disable=logging-format-interpolation
verbose = 1
# This is obsolete with the change to protocol v3
# but the singleCleaner thread still hasn't been updated
# so we need this a little longer.
maximumAgeOfAnObjectThatIAmWillingToAccept = 216000
# Equals 4 weeks. You could make this longer if you want
# but making it shorter would not be advisable because
# there is a very small possibility that it could keep you
# from obtaining a needed pubkey for a period of time.
lengthOfTimeToHoldOnToAllPubkeys = 2419200
maximumAgeOfNodesThatIAdvertiseToOthers = 10800 # Equals three hours
myECCryptorObjects = {} myECCryptorObjects = {}
MyECSubscriptionCryptorObjects = {} MyECSubscriptionCryptorObjects = {}
# The key in this dictionary is the RIPE hash which is encoded # The key in this dictionary is the RIPE hash which is encoded
@ -48,19 +34,6 @@ myAddressesByHash = {}
# The key in this dictionary is the tag generated from the address. # The key in this dictionary is the tag generated from the address.
myAddressesByTag = {} myAddressesByTag = {}
broadcastSendersForWhichImWatching = {} broadcastSendersForWhichImWatching = {}
printLock = threading.Lock()
statusIconColor = 'red'
thisapp = None # singleton lock instance
ackdataForWhichImWatching = {}
# used by API command clientStatus
clientHasReceivedIncomingConnections = False
numberOfMessagesProcessed = 0
numberOfBroadcastsProcessed = 0
numberOfPubkeysProcessed = 0
maximumLengthOfTimeToBotherResendingMessages = 0
def isAddressInMyAddressBook(address): def isAddressInMyAddressBook(address):
@ -279,11 +252,3 @@ def fixSensitiveFilePermissions(filename, hasEnabledKeys):
except Exception: except Exception:
logger.exception('Keyfile permissions could not be fixed.') logger.exception('Keyfile permissions could not be fixed.')
raise raise
def openKeysFile():
"""Open keys file with an external editor"""
if 'linux' in sys.platform:
subprocess.call(["xdg-open", state.appdata + 'keys.dat'])
else:
os.startfile(state.appdata + 'keys.dat')

View File

@ -4,7 +4,6 @@ import queue as Queue
import threading import threading
import time import time
import shared
import state import state
from debug import logger from debug import logger
from helper_sql import sqlQuery, sqlStoredProcedure from helper_sql import sqlQuery, sqlStoredProcedure
@ -80,9 +79,9 @@ def doCleanShutdown():
except Queue.Empty: except Queue.Empty:
break break
if shared.thisapp.daemon or not state.enableGUI: # ..fixme:: redundant? if state.thisapp.daemon or not state.enableGUI:
logger.info('Clean shutdown complete.') logger.info('Clean shutdown complete.')
shared.thisapp.cleanup() state.thisapp.cleanup()
os._exit(0) # pylint: disable=protected-access os._exit(0) # pylint: disable=protected-access
else: else:
logger.info('Core shutdown complete.') logger.info('Core shutdown complete.')

View File

@ -26,6 +26,9 @@ enableSTDIO = False # enable STDIO threads
curses = False curses = False
sqlReady = False # set to true by sqlTread when ready for processing sqlReady = False # set to true by sqlTread when ready for processing
maximumNumberOfHalfOpenConnections = 0 maximumNumberOfHalfOpenConnections = 0
maximumLengthOfTimeToBotherResendingMessages = 0
invThread = None invThread = None
addrThread = None addrThread = None
downloadThread = None downloadThread = None
@ -108,3 +111,21 @@ availabe_credit = 0
in_sent_method = False in_sent_method = False
in_search_mode = False in_search_mode = False
clientHasReceivedIncomingConnections = False
"""used by API command clientStatus"""
numberOfMessagesProcessed = 0
numberOfBroadcastsProcessed = 0
numberOfPubkeysProcessed = 0
statusIconColor = 'red'
"""
GUI status icon color
.. note:: bad style, refactor it
"""
ackdataForWhichImWatching = {}
thisapp = None
"""Singleton instance"""

View File

@ -12,15 +12,18 @@ import time
import unittest import unittest
import knownnodes import knownnodes
import protocol
import state import state
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from helper_msgcoding import MsgEncode, MsgDecode from helper_msgcoding import MsgEncode, MsgDecode
from helper_startup import start_proxyconfig from helper_startup import start_proxyconfig
from network import asyncore_pollchoose as asyncore from network import asyncore_pollchoose as asyncore
from network.bmproto import BMProto
from network.connectionpool import BMConnectionPool from network.connectionpool import BMConnectionPool
from network.node import Peer from network.node import Node, Peer
from network.tcp import Socks4aBMConnection, Socks5BMConnection, TCPConnection from network.tcp import Socks4aBMConnection, Socks5BMConnection, TCPConnection
from queues import excQueue from queues import excQueue
from version import softwareVersion
try: try:
import stem.version as stem_version import stem.version as stem_version
@ -216,6 +219,29 @@ class TestCore(unittest.TestCase):
% peer.host) % peer.host)
self.fail('Failed to connect to at least 3 nodes within 360 sec') self.fail('Failed to connect to at least 3 nodes within 360 sec')
@staticmethod
def _decode_msg(data, pattern):
proto = BMProto()
proto.bm_proto_reset()
proto.payload = data[protocol.Header.size:]
return proto.decode_payload_content(pattern)
def test_version(self):
"""check encoding/decoding of the version message"""
# with single stream
msg = protocol.assembleVersionMessage('127.0.0.1', 8444, [1])
decoded = self._decode_msg(msg, "IQQiiQlsLv")
peer, _, ua, streams = self._decode_msg(msg, "IQQiiQlsLv")[4:]
self.assertEqual(peer, Node(3, '127.0.0.1', 8444))
self.assertEqual(ua, '/PyBitmessage:' + softwareVersion + '/')
self.assertEqual(streams, [1])
# with multiple streams
msg = protocol.assembleVersionMessage('127.0.0.1', 8444, [1, 2, 3])
decoded = self._decode_msg(msg, "IQQiiQlslv")
peer, _, ua = decoded[4:7]
streams = decoded[7:]
self.assertEqual(streams, [1, 2, 3])
def run(): def run():
"""Starts all tests defined in this module""" """Starts all tests defined in this module"""

View File

@ -3,11 +3,14 @@ Test for ECC blind signatures
""" """
import os import os
import unittest import unittest
from ctypes import cast, c_char_p from hashlib import sha256
from pybitmessage.pyelliptic.eccblind import ECCBlind from pybitmessage.pyelliptic.eccblind import ECCBlind
from pybitmessage.pyelliptic.eccblindchain import ECCBlindChain
from pybitmessage.pyelliptic.openssl import OpenSSL from pybitmessage.pyelliptic.openssl import OpenSSL
# pylint: disable=protected-access
class TestBlindSig(unittest.TestCase): class TestBlindSig(unittest.TestCase):
""" """
@ -19,34 +22,255 @@ class TestBlindSig(unittest.TestCase):
# (1) Initialization # (1) Initialization
signer_obj = ECCBlind() signer_obj = ECCBlind()
point_r = signer_obj.signer_init() point_r = signer_obj.signer_init()
self.assertEqual(len(signer_obj.pubkey()), 35)
# (2) Request # (2) Request
requester_obj = ECCBlind(pubkey=signer_obj.pubkey) requester_obj = ECCBlind(pubkey=signer_obj.pubkey())
# only 64 byte messages are planned to be used in Bitmessage # only 64 byte messages are planned to be used in Bitmessage
msg = os.urandom(64) msg = os.urandom(64)
msg_blinded = requester_obj.create_signing_request(point_r, msg) msg_blinded = requester_obj.create_signing_request(point_r, msg)
self.assertEqual(len(msg_blinded), 32)
# check # check
msg_blinded_str = OpenSSL.malloc(0, OpenSSL.BN_num_bytes(msg_blinded)) self.assertNotEqual(sha256(msg).digest(), msg_blinded)
OpenSSL.BN_bn2bin(msg_blinded, msg_blinded_str)
self.assertNotEqual(msg, cast(msg_blinded_str, c_char_p).value)
# (3) Signature Generation # (3) Signature Generation
signature_blinded = signer_obj.blind_sign(msg_blinded) signature_blinded = signer_obj.blind_sign(msg_blinded)
assert isinstance(signature_blinded, str)
self.assertEqual(len(signature_blinded), 32)
# (4) Extraction # (4) Extraction
signature = requester_obj.unblind(signature_blinded) signature = requester_obj.unblind(signature_blinded)
assert isinstance(signature, str)
self.assertEqual(len(signature), 65)
# check self.assertNotEqual(signature, signature_blinded)
signature_blinded_str = OpenSSL.malloc(0,
OpenSSL.BN_num_bytes(
signature_blinded))
signature_str = OpenSSL.malloc(0, OpenSSL.BN_num_bytes(signature[0]))
OpenSSL.BN_bn2bin(signature_blinded, signature_blinded_str)
OpenSSL.BN_bn2bin(signature[0], signature_str)
self.assertNotEqual(cast(signature_str, c_char_p).value,
cast(signature_blinded_str, c_char_p).value)
# (5) Verification # (5) Verification
verifier_obj = ECCBlind(pubkey=signer_obj.pubkey) verifier_obj = ECCBlind(pubkey=signer_obj.pubkey())
self.assertTrue(verifier_obj.verify(msg, signature)) self.assertTrue(verifier_obj.verify(msg, signature))
def test_is_odd(self):
"""Test our implementation of BN_is_odd"""
for _ in range(1024):
obj = ECCBlind()
x = OpenSSL.BN_new()
y = OpenSSL.BN_new()
OpenSSL.EC_POINT_get_affine_coordinates(
obj.group, obj.Q, x, y, 0)
self.assertEqual(OpenSSL.BN_is_odd(y),
OpenSSL.BN_is_odd_compatible(y))
def test_serialize_ec_point(self):
"""Test EC point serialization/deserialization"""
for _ in range(1024):
try:
obj = ECCBlind()
obj2 = ECCBlind()
randompoint = obj.Q
serialized = obj._ec_point_serialize(randompoint)
secondpoint = obj2._ec_point_deserialize(serialized)
x0 = OpenSSL.BN_new()
y0 = OpenSSL.BN_new()
OpenSSL.EC_POINT_get_affine_coordinates(obj.group,
randompoint, x0,
y0, obj.ctx)
x1 = OpenSSL.BN_new()
y1 = OpenSSL.BN_new()
OpenSSL.EC_POINT_get_affine_coordinates(obj2.group,
secondpoint, x1,
y1, obj2.ctx)
self.assertEqual(OpenSSL.BN_cmp(y0, y1), 0)
self.assertEqual(OpenSSL.BN_cmp(x0, x1), 0)
self.assertEqual(OpenSSL.EC_POINT_cmp(obj.group, randompoint,
secondpoint, 0), 0)
finally:
OpenSSL.BN_free(x0)
OpenSSL.BN_free(x1)
OpenSSL.BN_free(y0)
OpenSSL.BN_free(y1)
del obj
del obj2
def test_serialize_bn(self):
"""Test Bignum serialization/deserialization"""
for _ in range(1024):
obj = ECCBlind()
obj2 = ECCBlind()
randomnum = obj.d
serialized = obj._bn_serialize(randomnum)
secondnum = obj2._bn_deserialize(serialized)
self.assertEqual(OpenSSL.BN_cmp(randomnum, secondnum), 0)
def test_blind_sig_many(self):
"""Test a lot of blind signatures"""
for _ in range(1024):
self.test_blind_sig()
def test_blind_sig_value(self):
"""Test blind signature value checking"""
signer_obj = ECCBlind(value=5)
point_r = signer_obj.signer_init()
requester_obj = ECCBlind(pubkey=signer_obj.pubkey())
msg = os.urandom(64)
msg_blinded = requester_obj.create_signing_request(point_r, msg)
signature_blinded = signer_obj.blind_sign(msg_blinded)
signature = requester_obj.unblind(signature_blinded)
verifier_obj = ECCBlind(pubkey=signer_obj.pubkey())
self.assertFalse(verifier_obj.verify(msg, signature, value=8))
def test_blind_sig_expiration(self):
"""Test blind signature expiration checking"""
signer_obj = ECCBlind(year=2020, month=1)
point_r = signer_obj.signer_init()
requester_obj = ECCBlind(pubkey=signer_obj.pubkey())
msg = os.urandom(64)
msg_blinded = requester_obj.create_signing_request(point_r, msg)
signature_blinded = signer_obj.blind_sign(msg_blinded)
signature = requester_obj.unblind(signature_blinded)
verifier_obj = ECCBlind(pubkey=signer_obj.pubkey())
self.assertFalse(verifier_obj.verify(msg, signature))
def test_blind_sig_chain(self): # pylint: disable=too-many-locals
"""Test blind signature chain using a random certifier key and a random message"""
test_levels = 4
msg = os.urandom(1024)
ca = ECCBlind()
signer_obj = ca
output = bytearray()
for level in range(test_levels):
if not level:
output.extend(ca.pubkey())
requester_obj = ECCBlind(pubkey=signer_obj.pubkey())
child_obj = ECCBlind()
point_r = signer_obj.signer_init()
pubkey = child_obj.pubkey()
if level == test_levels - 1:
msg_blinded = requester_obj.create_signing_request(point_r,
msg)
else:
msg_blinded = requester_obj.create_signing_request(point_r,
pubkey)
signature_blinded = signer_obj.blind_sign(msg_blinded)
signature = requester_obj.unblind(signature_blinded)
if level != test_levels - 1:
output.extend(pubkey)
output.extend(signature)
signer_obj = child_obj
verifychain = ECCBlindChain(ca=ca.pubkey(), chain=str(output))
self.assertTrue(verifychain.verify(msg=msg, value=1))
def test_blind_sig_chain_wrong_ca(self): # pylint: disable=too-many-locals
"""Test blind signature chain with an unlisted ca"""
test_levels = 4
msg = os.urandom(1024)
ca = ECCBlind()
fake_ca = ECCBlind()
signer_obj = fake_ca
output = bytearray()
for level in range(test_levels):
requester_obj = ECCBlind(pubkey=signer_obj.pubkey())
child_obj = ECCBlind()
if not level:
# unlisted CA, but a syntactically valid pubkey
output.extend(fake_ca.pubkey())
point_r = signer_obj.signer_init()
pubkey = child_obj.pubkey()
if level == test_levels - 1:
msg_blinded = requester_obj.create_signing_request(point_r,
msg)
else:
msg_blinded = requester_obj.create_signing_request(point_r,
pubkey)
signature_blinded = signer_obj.blind_sign(msg_blinded)
signature = requester_obj.unblind(signature_blinded)
if level != test_levels - 1:
output.extend(pubkey)
output.extend(signature)
signer_obj = child_obj
verifychain = ECCBlindChain(ca=ca.pubkey(), chain=str(output))
self.assertFalse(verifychain.verify(msg, 1))
def test_blind_sig_chain_wrong_msg(self): # pylint: disable=too-many-locals
"""Test blind signature chain with a fake message"""
test_levels = 4
msg = os.urandom(1024)
fake_msg = os.urandom(1024)
ca = ECCBlind()
signer_obj = ca
output = bytearray()
for level in range(test_levels):
if not level:
output.extend(ca.pubkey())
requester_obj = ECCBlind(pubkey=signer_obj.pubkey())
child_obj = ECCBlind()
point_r = signer_obj.signer_init()
pubkey = child_obj.pubkey()
if level == test_levels - 1:
msg_blinded = requester_obj.create_signing_request(point_r,
msg)
else:
msg_blinded = requester_obj.create_signing_request(point_r,
pubkey)
signature_blinded = signer_obj.blind_sign(msg_blinded)
signature = requester_obj.unblind(signature_blinded)
if level != test_levels - 1:
output.extend(pubkey)
output.extend(signature)
signer_obj = child_obj
verifychain = ECCBlindChain(ca=ca.pubkey(), chain=str(output))
self.assertFalse(verifychain.verify(fake_msg, 1))
def test_blind_sig_chain_wrong_intermediary(self): # pylint: disable=too-many-locals
"""Test blind signature chain using a fake intermediary pubkey"""
test_levels = 4
msg = os.urandom(1024)
wrong_level = 2
ca = ECCBlind()
signer_obj = ca
fake_intermediary = ECCBlind()
output = bytearray()
for level in range(test_levels):
if not level:
output.extend(ca.pubkey())
requester_obj = ECCBlind(pubkey=signer_obj.pubkey())
child_obj = ECCBlind()
point_r = signer_obj.signer_init()
pubkey = child_obj.pubkey()
if level == test_levels - 1:
msg_blinded = requester_obj.create_signing_request(point_r,
msg)
else:
msg_blinded = requester_obj.create_signing_request(point_r,
pubkey)
signature_blinded = signer_obj.blind_sign(msg_blinded)
signature = requester_obj.unblind(signature_blinded)
if level == wrong_level:
output.extend(fake_intermediary.pubkey())
elif level != test_levels - 1:
output.extend(pubkey)
output.extend(signature)
signer_obj = child_obj
verifychain = ECCBlindChain(ca=ca.pubkey(), chain=str(output))
self.assertFalse(verifychain.verify(msg, 1))

View File

@ -6,6 +6,7 @@ import hashlib
import unittest import unittest
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
from binascii import hexlify, unhexlify from binascii import hexlify, unhexlify
from pybitmessage.pyelliptic import arithmetic
try: try:
from Crypto.Hash import RIPEMD from Crypto.Hash import RIPEMD
@ -20,8 +21,13 @@ sample_pubsigningkey = unhexlify(
sample_pubencryptionkey = unhexlify( sample_pubencryptionkey = unhexlify(
'044597d59177fc1d89555d38915f581b5ff2286b39d022ca0283d2bdd5c36be5d3c' '044597d59177fc1d89555d38915f581b5ff2286b39d022ca0283d2bdd5c36be5d3c'
'e7b9b97792327851a562752e4b79475d1f51f5a71352482b241227f45ed36a9') 'e7b9b97792327851a562752e4b79475d1f51f5a71352482b241227f45ed36a9')
sample_privatesigningkey = \
'93d0b61371a54b53df143b954035d612f8efa8a3ed1cf842c2186bfd8f876665'
sample_privateencryptionkey = \
'4b0b73a54e19b059dc274ab69df095fe699f43b17397bca26fdf40f4d7400a3a'
sample_ripe = '003cd097eb7f35c87b5dc8b4538c22cb55312a9f' sample_ripe = '003cd097eb7f35c87b5dc8b4538c22cb55312a9f'
# stream: 1, version: 2
sample_address = 'BM-onkVu1KKL2UaUss5Upg9vXmqd3esTmV79'
_sha = hashlib.new('sha512') _sha = hashlib.new('sha512')
_sha.update(sample_pubsigningkey + sample_pubencryptionkey) _sha.update(sample_pubsigningkey + sample_pubencryptionkey)
@ -59,3 +65,34 @@ class TestCrypto(RIPEMD160TestCase, unittest.TestCase):
@staticmethod @staticmethod
def _hashdigest(data): def _hashdigest(data):
return RIPEMD.RIPEMD160Hash(data).digest() return RIPEMD.RIPEMD160Hash(data).digest()
class TestAddresses(unittest.TestCase):
"""Test addresses manipulations"""
def test_privtopub(self):
"""Generate public keys and check the result"""
self.assertEqual(
arithmetic.privtopub(sample_privatesigningkey),
hexlify(sample_pubsigningkey)
)
self.assertEqual(
arithmetic.privtopub(sample_privateencryptionkey),
hexlify(sample_pubencryptionkey)
)
def test_address(self):
"""Create address and check the result"""
from pybitmessage import addresses
from pybitmessage.fallback import RIPEMD160Hash
sha = hashlib.new('sha512')
sha.update(sample_pubsigningkey + sample_pubencryptionkey)
ripe_hash = RIPEMD160Hash(sha.digest()).digest()
self.assertEqual(ripe_hash, unhexlify(sample_ripe))
self.assertEqual(
addresses.encodeAddress(2, 1, ripe_hash), sample_address)
self.assertEqual(
addresses.decodeAddress(sample_address),
('success', 2, 1, ripe_hash))

54
src/tests/test_openssl.py Normal file
View File

@ -0,0 +1,54 @@
"""
Test if OpenSSL is working correctly
"""
import unittest
from pybitmessage.pyelliptic.openssl import OpenSSL
try:
OpenSSL.BN_bn2binpad
have_pad = True
except AttributeError:
have_pad = None
class TestOpenSSL(unittest.TestCase):
"""
Test cases for OpenSSL
"""
def test_is_odd(self):
"""Test BN_is_odd implementation"""
ctx = OpenSSL.BN_CTX_new()
a = OpenSSL.BN_new()
group = OpenSSL.EC_GROUP_new_by_curve_name(
OpenSSL.get_curve("secp256k1"))
OpenSSL.EC_GROUP_get_order(group, a, ctx)
bad = 0
for _ in range(1024):
OpenSSL.BN_rand(a, OpenSSL.BN_num_bits(a), 0, 0)
if not OpenSSL.BN_is_odd(a) == OpenSSL.BN_is_odd_compatible(a):
bad += 1
self.assertEqual(bad, 0)
@unittest.skipUnless(have_pad, 'Skipping OpenSSL pad test')
def test_padding(self):
"""Test an alternatie implementation of bn2binpad"""
ctx = OpenSSL.BN_CTX_new()
a = OpenSSL.BN_new()
n = OpenSSL.BN_new()
group = OpenSSL.EC_GROUP_new_by_curve_name(
OpenSSL.get_curve("secp256k1"))
OpenSSL.EC_GROUP_get_order(group, n, ctx)
bad = 0
for _ in range(1024):
OpenSSL.BN_rand(a, OpenSSL.BN_num_bits(n), 0, 0)
b = OpenSSL.malloc(0, OpenSSL.BN_num_bytes(n))
c = OpenSSL.malloc(0, OpenSSL.BN_num_bytes(a))
OpenSSL.BN_bn2binpad(a, b, OpenSSL.BN_num_bytes(n))
OpenSSL.BN_bn2bin(a, c)
if b.raw != c.raw.rjust(OpenSSL.BN_num_bytes(n), chr(0)):
bad += 1
self.assertEqual(bad, 0)

View File

@ -40,7 +40,9 @@ else:
threading.Thread._Thread__bootstrap = _thread_name_hack threading.Thread._Thread__bootstrap = _thread_name_hack
printLock = threading.Lock()
__all__ = [ __all__ = [
"addressGenerator", "objectProcessor", "singleCleaner", "singleWorker", "addressGenerator", "objectProcessor", "singleCleaner", "singleWorker",
"sqlThread" "sqlThread", "printLock"
] ]