Revert "removed the inset sent query and using the comman helper_sent.inset method for data insertion"

This commit is contained in:
navjotcis 2020-09-15 22:28:25 +05:30 committed by GitHub
parent 54d47f4f2f
commit 383d08978d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
294 changed files with 14111 additions and 10312 deletions

4
.gitignore vendored
View File

@ -17,8 +17,4 @@ dist
*.egg-info *.egg-info
docs/_*/* docs/_*/*
docs/autodoc/ docs/autodoc/
build/sphinx/
pyan/ pyan/
.buildozer/
bin/
src/images/default_identicon/

View File

@ -1,9 +0,0 @@
version: 2
python:
version: 2.7
install:
- requirements: docs/requirements.txt
- method: setuptools
path: .
system_packages: true

View File

@ -6,7 +6,6 @@ addons:
packages: packages:
- build-essential - build-essential
- libcap-dev - libcap-dev
- tor
install: install:
- pip install -r requirements.txt - pip install -r requirements.txt
- ln -s src pybitmessage # tests environment - ln -s src pybitmessage # tests environment

View File

@ -1,5 +1,5 @@
Copyright (c) 2012-2016 Jonathan Warren Copyright (c) 2012-2016 Jonathan Warren
Copyright (c) 2012-2020 The Bitmessage Developers Copyright (c) 2012-2019 The Bitmessage Developers
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

51
LICENSE
View File

@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2012-2016 Jonathan Warren Copyright (c) 2012-2016 Jonathan Warren
Copyright (c) 2012-2020 The Bitmessage Developers Copyright (c) 2012-2019 The Bitmessage Developers
Permission is hereby granted, free of charge, to any person obtaining a copy of Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in this software and associated documentation files (the "Software"), to deal in
@ -22,7 +22,7 @@ SOFTWARE.
===== qidenticon.py identicon python implementation with QPixmap output by sendiulo <sendiulo@gmx.net> ===== qidenticon.py identicon python implementation with QPixmap output by sendiulo <sendiulo@gmx.net>
qidenticon.py is Licensed under FreeBSD License. qidenticon.py is Licesensed under FreeBSD License.
(http://www.freebsd.org/copyright/freebsd-license.html) (http://www.freebsd.org/copyright/freebsd-license.html)
Copyright 2013 "Sendiulo". All rights reserved. Copyright 2013 "Sendiulo". All rights reserved.
@ -36,7 +36,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS OR I
===== based on identicon.py identicon python implementation. by Shin Adachi <shn@glucose.jp> ===== based on identicon.py identicon python implementation. by Shin Adachi <shn@glucose.jp>
identicon.py is Licensed under FreeBSD License. identicon.py is Licesensed under FreeBSD License.
(http://www.freebsd.org/copyright/freebsd-license.html) (http://www.freebsd.org/copyright/freebsd-license.html)
Copyright 1994-2009 Shin Adachi. All rights reserved. Copyright 1994-2009 Shin Adachi. All rights reserved.
@ -47,48 +47,3 @@ Redistribution and use in source and binary forms, with or without modification,
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
===== based on asyncore_pollchoose.py asyncore_pollchoose python implementation. by Sam Rushing <rushing@nightmare.com>
Copyright 1996 by Sam Rushing. All Rights Reserved
Permission to use, copy, modify, and distribute this software and
its documentation for any purpose and without fee is hereby
granted, provided that the above copyright notice appear in all
copies and that both that copyright notice and this permission
notice appear in supporting documentation, and that the name of Sam
Rushing not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior
permission.
SAM RUSHING DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
NO EVENT SHALL SAM RUSHING BE LIABLE FOR ANY SPECIAL, INDIRECT OR
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
===== based on namecoin.py namecoin.py python implementation by Daniel Kraft <d@domob.eu>
Copyright (C) 2013 by Daniel Kraft <d@domob.eu>
This file is part of the Bitmessage project.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -14,10 +14,12 @@ Development
---------- ----------
Bitmessage is a collaborative project. You are welcome to submit pull requests Bitmessage is a collaborative project. You are welcome to submit pull requests
although if you plan to put a non-trivial amount of work into coding new although if you plan to put a non-trivial amount of work into coding new
features, it is recommended that you first describe your ideas in the features, it is recommended that you first solicit feedback on the DevTalk
separate issue. pseudo-mailing list:
BM-2D9QKN4teYRvoq2fyzpiftPh9WP9qggtzh
Feel welcome to join chan "bitmessage", BM-2cWy7cvHoq3f1rYMerRJp8PT653jjSuEdY Feel welcome to join chan "bitmessage", BM-2cWy7cvHoq3f1rYMerRJp8PT653jjSuEdY
which is on preview here: https://beamstat.com/chan/bitmessage
References References
---------- ----------

View File

@ -1,6 +1,6 @@
PyBitmessage(Android) PyBitmessage(Android)
This sample aims to be as close to a real world example of a mobile. It has a more refined design and also provides a practical example of how a mobile app would interact and communicate with its addresses. This sample aims to be as close to a real world example of a mobile. It has a more refined design and also provides a practical example of how a mobile app would interact and communicate with its adresses.
Steps for trying out this sample: Steps for trying out this sample:
@ -13,7 +13,7 @@ This sample uses the kivy as Kivy is an open source, cross-platform Python frame
Kivy is written in Python and Cython, supports various input devices and has an extensive widget library. With the same codebase, you can target Windows, OS X, Linux, Android and iOS. All Kivy widgets are built with multitouch support. Kivy is written in Python and Cython, supports various input devices and has an extensive widget library. With the same codebase, you can target Windows, OS X, Linux, Android and iOS. All Kivy widgets are built with multitouch support.
Kivy in support take Buildozer which is a tool that automates the entire build process. It downloads and sets up all the prerequisite for python-for-android, including the android SDK and NDK, then builds an apk that can be automatically pushed to the device. Kivy in support take Buildozer which is a tool that automates the entire build process. It downloads and sets up all the prequisites for python-for-android, including the android SDK and NDK, then builds an apk that can be automatically pushed to the device.
Buildozer currently works only in Linux, and is an alpha release, but it already works well and can significantly simplify the apk build. Buildozer currently works only in Linux, and is an alpha release, but it already works well and can significantly simplify the apk build.

2
build/README.md Normal file
View File

@ -0,0 +1,2 @@
This directory contains scripts that are helpful for developers when building
or maintaining PyBitmessage.

16
build/changelang.sh Executable file
View File

@ -0,0 +1,16 @@
export LANG=de_DE.UTF-8
export LANGUAGE=de_DE
export LC_CTYPE="de_DE.UTF-8"
export LC_NUMERIC=de_DE.UTF-8
export LC_TIME=de_DE.UTF-8
export LC_COLLATE="de_DE.UTF-8"
export LC_MONETARY=de_DE.UTF-8
export LC_MESSAGES="de_DE.UTF-8"
export LC_PAPER=de_DE.UTF-8
export LC_NAME=de_DE.UTF-8
export LC_ADDRESS=de_DE.UTF-8
export LC_TELEPHONE=de_DE.UTF-8
export LC_MEASUREMENT=de_DE.UTF-8
export LC_IDENTIFICATION=de_DE.UTF-8
export LC_ALL=
python2.7 src/bitmessagemain.py

23
build/compiletest.py Executable file
View File

@ -0,0 +1,23 @@
#!/usr/bin/python2.7
import ctypes
import fnmatch
import os
import sys
import traceback
matches = []
for root, dirnames, filenames in os.walk('src'):
for filename in fnmatch.filter(filenames, '*.py'):
matches.append(os.path.join(root, filename))
for filename in matches:
source = open(filename, 'r').read() + '\n'
try:
compile(source, filename, 'exec')
except Exception as e:
if 'win' in sys.platform:
ctypes.windll.user32.MessageBoxA(0, traceback.format_exc(), "Exception in " + filename, 1)
else:
print "Exception in %s: %s" % (filename, traceback.format_exc())
sys.exit(1)

11
build/mergepullrequest.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
if [ -z "$1" ]; then
echo "You must specify pull request number"
exit
fi
git pull
git checkout v0.6
git fetch origin pull/"$1"/head:"$1"
git merge --ff-only "$1"

26
build/osx.sh Executable file
View File

@ -0,0 +1,26 @@
#!/bin/bash
# OS X Build script wrapper around the py2app script.
# This build can only be generated on OS X.
# Requires all build dependencies for Bitmessage
# Especially important is OpenSSL installed through brew
export ARCHFLAGS="-arch i386 -arch x86_64"
if [[ -z "$1" ]]; then
echo "Please supply a version number for this release as the first argument."
exit
fi
echo "Creating OS X packages for Bitmessage."
export PYBITMESSAGEVERSION=$1
cd src && python2.7 build_osx.py py2app
if [[ $? = "0" ]]; then
hdiutil create -fs HFS+ -volname "Bitmessage" -srcfolder dist/Bitmessage.app dist/bitmessage-v$1.dmg
else
echo "Problem creating Bitmessage.app, stopping."
exit
fi

22
build/updatetranslations.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
if [ ! -f "$1" ]; then
echo "$1 not found, please specify the file name for source"
exit
fi
srcdir=`mktemp -d`
unzip "$1" -d $srcdir
for i in $srcdir/*ts; do
o=`basename $i|cut -b3-`
o="${o,,}"
o="${o//@/_}"
echo "$i -> $o"
mv "$i" "$HOME/src/PyBitmessage/src/translations/$o"
done
rm -rf -- $srcdir
lrelease-qt4 "$HOME/src/PyBitmessage/src/translations/bitmessage.pro"

View File

@ -1,165 +0,0 @@
#!/bin/bash
# INIT
MACHINE_TYPE=`uname -m`
BASE_DIR=$(pwd)
PYTHON_VERSION=2.7.17
PYQT_VERSION=4-4.11.4-gpl-Py2.7-Qt4.8.7
OPENSSL_VERSION=1_0_2t
SRCPATH=~/Downloads
#Functions
function download_sources_32 {
if [ ! -d ${SRCPATH} ]; then
mkdir -p ${SRCPATH}
fi
wget -P ${SRCPATH} -c -nc --content-disposition \
https://www.python.org/ftp/python/${PYTHON_VERSION}/python-${PYTHON_VERSION}.msi \
https://download.microsoft.com/download/1/1/1/1116b75a-9ec3-481a-a3c8-1777b5381140/vcredist_x86.exe \
https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/PyQt${PYQT_VERSION}-x32.exe?raw=true \
https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/Win32OpenSSL-${OPENSSL_VERSION}.exe?raw=true \
https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/pyopencl-2015.1-cp27-none-win32.whl?raw=true
}
function download_sources_64 {
if [ ! -d ${SRCPATH} ]; then
mkdir -p ${SRCPATH}
fi
wget -P ${SRCPATH} -c -nc --content-disposition \
http://www.python.org/ftp/python/${PYTHON_VERSION}/python-${PYTHON_VERSION}.amd64.msi \
https://download.microsoft.com/download/d/2/4/d242c3fb-da5a-4542-ad66-f9661d0a8d19/vcredist_x64.exe \
https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/PyQt${PYQT_VERSION}-x64.exe?raw=true \
https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/Win64OpenSSL-${OPENSSL_VERSION}.exe?raw=true \
https://github.com/Bitmessage/ThirdPartyLibraries/blob/master/pyopencl-2015.1-cp27-none-win_amd64.whl?raw=true
}
function download_sources {
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
download_sources_64
else
download_sources_32
fi
}
function install_wine {
echo "Setting up wine"
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
export WINEPREFIX=${HOME}/.wine64 WINEARCH=win64
else
export WINEPREFIX=${HOME}/.wine32 WINEARCH=win32
fi
rm -rf ${WINEPREFIX}
rm -rf packages/pyinstaller/{build,dist}
}
function install_python(){
cd ${SRCPATH}
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
echo "Installing Python ${PYTHON_VERSION} 64b"
wine msiexec -i python-${PYTHON_VERSION}.amd64.msi /q /norestart
echo "Installing vcredist for 64 bit"
wine vcredist_x64.exe /q /norestart
else
echo "Installing Python ${PYTHON_VERSION} 32b"
wine msiexec -i python-${PYTHON_VERSION}.msi /q /norestart
# MSVCR 2008 required for Windows XP
cd ${SRCPATH}
echo "Installing vc_redist (2008) for 32 bit "
wine vcredist_x86.exe /Q
fi
echo "Upgrading pip"
wine python -m pip install --upgrade pip
}
function install_pyqt(){
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
echo "Installing PyQt-${PYQT_VERSION} 64b"
wine PyQt${PYQT_VERSION}-x64.exe /S /WX
else
echo "Installing PyQt-${PYQT_VERSION} 32b"
wine PyQt${PYQT_VERSION}-x32.exe /S /WX
fi
}
function install_openssl(){
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
echo "Installing OpenSSL ${OPENSSL_VERSION} 64b"
wine Win64OpenSSL-${OPENSSL_VERSION}.exe /q /norestart /silent /verysilent /sp- /suppressmsgboxes
else
echo "Installing OpenSSL ${OPENSSL_VERSION} 32b"
wine Win32OpenSSL-${OPENSSL_VERSION}.exe /q /norestart /silent /verysilent /sp- /suppressmsgboxes
fi
}
function install_pyinstaller()
{
cd ${BASE_DIR}
echo "Installing PyInstaller"
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
wine python -m pip install pyinstaller
else
# 3.2.1 is the last version to work on XP
# see https://github.com/pyinstaller/pyinstaller/issues/2931
wine python -m pip install -I pyinstaller==3.2.1
fi
}
function install_msgpack()
{
cd ${BASE_DIR}
echo "Installing msgpack"
wine python -m pip install msgpack-python
}
function install_pyopencl()
{
cd ${SRCPATH}
echo "Installing PyOpenCL"
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
wine python -m pip install pyopencl-2015.1-cp27-none-win_amd64.whl
else
wine python -m pip install pyopencl-2015.1-cp27-none-win32.whl
fi
}
function build_dll(){
cd ${BASE_DIR}
cd src/bitmsghash
if [ ${MACHINE_TYPE} == 'x86_64' ]; then
echo "Create dll"
x86_64-w64-mingw32-g++ -D_WIN32 -Wall -O3 -march=native -I$HOME/.wine64/drive_c/OpenSSL-Win64/include -I/usr/x86_64-w64-mingw32/include -L$HOME/.wine64/drive_c/OpenSSL-Win64/lib -c bitmsghash.cpp
x86_64-w64-mingw32-g++ -static-libgcc -shared bitmsghash.o -D_WIN32 -O3 -march=native -I$HOME/.wine64/drive_c/OpenSSL-Win64/include -L$HOME/.wine64/drive_c/OpenSSL-Win64 -L/usr/lib/x86_64-linux-gnu/wine -fPIC -shared -lcrypt32 -leay32 -lwsock32 -o bitmsghash64.dll -Wl,--out-implib,bitmsghash.a
else
echo "Create dll"
i686-w64-mingw32-g++ -D_WIN32 -Wall -m32 -O3 -march=native -I$HOME/.wine32/drive_c/OpenSSL-Win32/include -I/usr/i686-w64-mingw32/include -L$HOME/.wine32/drive_c/OpenSSL-Win32/lib -c bitmsghash.cpp
i686-w64-mingw32-g++ -static-libgcc -shared bitmsghash.o -D_WIN32 -O3 -march=native -I$HOME/.wine32/drive_c/OpenSSL-Win32/include -L$HOME/.wine32/drive_c/OpenSSL-Win32/lib/MinGW -fPIC -shared -lcrypt32 -leay32 -lwsock32 -o bitmsghash32.dll -Wl,--out-implib,bitmsghash.a
fi
}
function build_exe(){
cd ${BASE_DIR}
cd packages/pyinstaller
wine pyinstaller bitmessagemain.spec
}
# prepare on ubuntu
# dpkg --add-architecture i386
# apt update
# apt -y install wget wine-stable wine-development winetricks mingw-w64 wine32 wine64 xvfb
download_sources
if [ "$1" == "--download-only" ]; then
exit
fi
install_wine
install_python
install_pyqt
install_openssl
install_pyopencl
install_msgpack
install_pyinstaller
build_dll
build_exe

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python2 #!/usr/bin/env python2
""" """
Check dependencies and give recommendations about how to satisfy them Check dependendies and give recommendations about how to satisfy them
Limitations: Limitations:
@ -164,7 +164,7 @@ if (not compiler or prereqs) and OPSYS in PACKAGE_MANAGER:
if not compiler: if not compiler:
compilerToPackages() compilerToPackages()
prereqToPackages() prereqToPackages()
if prereqs and mandatory: if mandatory:
sys.exit(1) sys.exit(1)
else: else:
print("All the dependencies satisfied, you can install PyBitmessage") print("All the dependencies satisfied, you can install PyBitmessage")

View File

@ -1,4 +0,0 @@
/* Hide "On GitHub" section from versions menu */
li.wy-breadcrumbs-aside > a.fa {
display: none;
}

View File

@ -2,24 +2,35 @@
""" """
Configuration file for the Sphinx documentation builder. Configuration file for the Sphinx documentation builder.
For a full list of options see the documentation: This file does only contain a selection of the most common options. For a
full list see the documentation:
http://www.sphinx-doc.org/en/master/config http://www.sphinx-doc.org/en/master/config
-- Path setup --------------------------------------------------------------
If extensions (or modules to document with autodoc) are in another directory,
add these directories to sys.path here. If the directory is relative to the
documentation root, use os.path.abspath to make it absolute, like shown here.
""" """
import os import os
import sys import sys
from sphinx.apidoc import main
from mock import Mock as MagicMock
sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath('..'))
sys.path.insert(0, os.path.abspath('../src')) sys.path.insert(0, os.path.abspath('../src'))
sys.path.insert(0, os.path.abspath('../src/pyelliptic'))
from importlib import import_module import version
import version # noqa:E402
# -- Project information ----------------------------------------------------- # -- Project information -----------------------------------------------------
project = u'PyBitmessage' project = u'PyBitmessage'
copyright = u'2019, The Bitmessage Team' # pylint: disable=redefined-builtin copyright = u'2018, The Bitmessage Team' # pylint: disable=redefined-builtin
author = u'The Bitmessage Team' author = u'The Bitmessage Team'
# The short X.Y version # The short X.Y version
@ -39,18 +50,15 @@ release = version
# ones. # ones.
extensions = [ extensions = [
'sphinx.ext.autodoc', 'sphinx.ext.autodoc',
'sphinx.ext.coverage', # FIXME: unused # 'sphinx.ext.doctest', # Currently disabled due to bad doctests
'sphinx.ext.imgmath', # legacy unused
'sphinx.ext.intersphinx', 'sphinx.ext.intersphinx',
'sphinx.ext.linkcode',
'sphinx.ext.napoleon',
'sphinx.ext.todo', 'sphinx.ext.todo',
'sphinxcontrib.apidoc', 'sphinx.ext.coverage',
'sphinx.ext.imgmath',
'sphinx.ext.viewcode',
'm2r', 'm2r',
] ]
default_role = 'obj'
# Add any paths that contain templates here, relative to this directory. # Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates'] templates_path = ['_templates']
@ -67,29 +75,23 @@ master_doc = 'index'
# #
# This is also used if you do content translation via gettext catalogs. # This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases. # Usually you set "language" from the command line for these cases.
# language = None language = None
# List of patterns, relative to source directory, that match files and # List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files. # directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path . # This pattern also affects html_static_path and html_extra_path .
exclude_patterns = ['_build'] exclude_patterns = [u'_build', 'Thumbs.db', '.DS_Store']
# The name of the Pygments (syntax highlighting) style to use. # The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx' pygments_style = 'sphinx'
# Don't prepend every class or function name with full module path
add_module_names = False
# A list of ignored prefixes for module index sorting.
modindex_common_prefix = ['pybitmessage.']
# -- Options for HTML output ------------------------------------------------- # -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for # The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes. # a list of builtin themes.
# #
html_theme = 'sphinx_rtd_theme' html_theme = 'alabaster'
# Theme options are theme-specific and customize the look and feel of a theme # Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the # further. For a list of options available for each theme, see the
@ -102,10 +104,6 @@ html_theme = 'sphinx_rtd_theme'
# so a file named "default.css" will overwrite the builtin "default.css". # so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static'] html_static_path = ['_static']
html_css_files = [
'custom.css',
]
# Custom sidebar templates, must be a dictionary that maps document names # Custom sidebar templates, must be a dictionary that maps document names
# to template names. # to template names.
# #
@ -116,7 +114,10 @@ html_css_files = [
# #
# html_sidebars = {} # html_sidebars = {}
html_show_sourcelink = False # Deal with long lines in source view
html_theme_options = {
'page_width': '1366px',
}
# -- Options for HTMLHelp output --------------------------------------------- # -- Options for HTMLHelp output ---------------------------------------------
@ -198,74 +199,10 @@ epub_exclude_files = ['search.html']
# -- Extension configuration ------------------------------------------------- # -- Extension configuration -------------------------------------------------
autodoc_mock_imports = [
'debug',
'pybitmessage.bitmessagekivy',
'pybitmessage.bitmessageqt.addressvalidator',
'pybitmessage.helper_startup',
'pybitmessage.network.httpd',
'pybitmessage.network.https',
'ctypes',
'dialog',
'gi',
'kivy',
'logging',
'msgpack',
'numpy',
'pkg_resources',
'pycanberra',
'pyopencl',
'PyQt4',
'pyxdg',
'qrcode',
'stem',
]
autodoc_member_order = 'bysource'
# Apidoc settings
apidoc_module_dir = '../pybitmessage'
apidoc_output_dir = 'autodoc'
apidoc_excluded_paths = [
'bitmessagekivy', 'build_osx.py',
'bitmessageqt/addressvalidator.py', 'bitmessageqt/migrationwizard.py',
'bitmessageqt/newaddresswizard.py', 'helper_startup.py',
'kivymd', 'main.py', 'navigationdrawer', 'network/http*',
'pybitmessage', 'tests', 'version.py'
]
apidoc_module_first = True
apidoc_separate_modules = True
apidoc_toc_file = False
apidoc_extra_args = ['-a']
# Napoleon settings
napoleon_google_docstring = True
# linkcode function
def linkcode_resolve(domain, info):
"""This generates source URL's for sphinx.ext.linkcode"""
if domain != 'py' or not info['module']:
return
try:
home = os.path.abspath(import_module('pybitmessage').__path__[0])
mod = import_module(info['module']).__file__
except ImportError:
return
repo = 'https://github.com/Bitmessage/PyBitmessage/blob/v0.6/src%s'
path = mod.replace(home, '')
if path != mod:
# put the link only for top level definitions
if len(info['fullname'].split('.')) > 1:
return
if path.endswith('.pyc'):
path = path[:-1]
return repo % path
# -- Options for intersphinx extension --------------------------------------- # -- Options for intersphinx extension ---------------------------------------
# Example configuration for intersphinx: refer to the Python standard library. # Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/2.7/': None} intersphinx_mapping = {'https://docs.python.org/': None}
# -- Options for todo extension ---------------------------------------------- # -- Options for todo extension ----------------------------------------------

View File

@ -1,2 +1,2 @@
.. mdinclude:: ../../../fabfile/README.md .. mdinclude:: fabfile/README.md

View File

@ -21,12 +21,12 @@ If we are to make bold claims about protecting your privacy we should demonstrat
- looking to audit - looking to audit
- warrant canary - warrant canary
Digital footprint Digital foootprint
------------------ ------------------
Your internet use can reveal metadata you wouldn't expect. This can be connected with other information about you if you're not careful. Your internet use can reveal metadata you wouldn't expect. This can be connected with other information about you if you're not careful.
* Use separate addresses for different purposes * Use separate addresses for different puprose
* Don't make the same mistakes all the time * Don't make the same mistakes all the time
* Your language use is unique. The more you type, the more you fingerprint yourself. The words you know and use often vs the words you don't know or use often. * Your language use is unique. The more you type, the more you fingerprint yourself. The words you know and use often vs the words you don't know or use often.

View File

@ -11,17 +11,17 @@ Bitmessage makes use of fabric_ to define tasks such as building documentation o
Code style and linters Code style and linters
---------------------- ----------------------
We aim to be PEP8 compliant but we recognize that we have a long way still to go. Currently we have style and lint exceptions specified at the most specific place we can. We are ignoring certain issues project-wide in order to avoid alert-blindness, avoid style and lint regressions and to allow continuous integration to hook into the output from the tools. While it is hoped that all new changes pass the checks, fixing some existing violations are mini-projects in themselves. Current thinking on ignorable violations is reflected in the options and comments in setup.cfg. Module and line-level lint warnings represent refactoring opportunities. We aim to be PEP8 compliant but we recognise that we have a long way still to go. Currently we have style and lint exceptions specified at the most specific place we can. We are ignoring certain issues project-wide in order to avoid alert-blindess, avoid style and lint regressions and to allow continuous integration to hook into the output from the tools. While it is hoped that all new changes pass the checks, fixing some existing violations are mini-projects in themselves. Current thinking on ignorable violations is reflected in the options and comments in setup.cfg. Module and line-level lint warnings represent refactoring opportunities.
Pull requests Pull requests
------------- -------------
There is a template at PULL_REQUEST_TEMPLATE.md that appears in the pull-request description. Please replace this text with something appropriate to your changes based on the ideas in the template. There is a template at PULL_REQUEST_TEMPLATE.md that appears in the pull-request description. Please replace this text with something appropriate to your changes based off the ideas in the template.
Bike-shedding Bike-shedding
------------- -------------
Beyond having well-documented, Pythonic code with static analysis tool checks, extensive test coverage and powerful devops tools, what else can we have? Without violating any linters there is room for making arbitrary decisions solely for the sake of project consistency. These are the stuff of the pedant's PR comments. Rather than have such conversations in PR comments, we can lay out the result of discussion here. Beyond having well-documented, Pythonic code with static analysis tool checks, extensive test coverage and powerful devops tools, what else can we have? Without violating any linters there is room for making arbirary decisions solely for the sake of project consistency. These are the stuff of the pedant's PR comments. Rather than have such conversations in PR comments, we can lay out the result of discussion here.
I'm putting up a strawman for each topic here, mostly based on my memory of reading related Stack Overflow articles etc. If contributors feel strongly (and we don't have anything better to do) then maybe we can convince each other to update this section. I'm putting up a strawman for each topic here, mostly based on my memory of reading related Stack Overflow articles etc. If contributors feel strongly (and we don't have anything better to do) then maybe we can convince each other to update this section.
@ -49,7 +49,7 @@ British vs American spelling
Dependency graph Dependency graph
---------------- ----------------
These images are not very useful right now but the aim is to tweak the settings of one or more of them to be informative, and/or divide them up into smaller graphs. These images are not very useful right now but the aim is to tweak the settings of one or more of them to be informative, and/or divide them up into smaller grapghs.
To re-build them, run `fab build_docs:dep_graphs=true`. Note that the dot graph takes a lot of time. To re-build them, run `fab build_docs:dep_graphs=true`. Note that the dot graph takes a lot of time.

View File

@ -1,8 +1,8 @@
Processes Processes
========= =========
In order to keep the Bitmessage project running, the team runs a number of systems and accounts that form the In other to keep the Bitmessage project running the team run a number of systems and accounts that form the
development pipeline and continuous delivery process. We are always striving to improve this process. Towards development pipeline and continuous delivery process. We are always striving to improve the process. Towards
that end it is documented here. that end it is documented here.
@ -20,7 +20,7 @@ Our official Github_ account is Bitmessage. Our issue tracker is here as well.
BitMessage BitMessage
---------- ----------
We eat our own dog food! You can send us bug reports via the [chan] bitmessage BM-2cWy7cvHoq3f1rYMerRJp8PT653jjSuEdY We eat our own dog food! You can send us bug reports via the Bitmessage chan at xxx
.. _website: https://bitmessage.org .. _website: https://bitmessage.org

View File

@ -1,17 +1,9 @@
.. mdinclude:: ../README.md .. mdinclude:: ../README.md
Documentation
-------------
.. toctree::
:maxdepth: 3
autodoc/pybitmessage
Legacy pages
------------
.. toctree:: .. toctree::
:maxdepth: 2 :maxdepth: 2
overview
usage usage
contribute contribute

View File

@ -1,2 +0,0 @@
m2r
sphinxcontrib-apidoc

View File

@ -1,6 +1,6 @@
# Fabric # Fabric
[Fabric](https://www.fabfile.org) is a Python library for performing devops tasks. You can think of it a bit like a [Fabric](https://www.fabfile.org) is a Python library for performing devops tasks. You can thing of it a bit like a
makefile on steroids for Python. Its api abstracts away the clunky way you would run shell commands in Python, check makefile on steroids for Python. Its api abstracts away the clunky way you would run shell commands in Python, check
return values and manage stdio. Tasks may be targetted at particular hosts or group of hosts. return values and manage stdio. Tasks may be targetted at particular hosts or group of hosts.
@ -46,7 +46,7 @@ Furthermore, you can use -- to run arbitrary shell commands rather than tasks:
There are a number of advantages that should benefit us: There are a number of advantages that should benefit us:
* Common tasks can be written in Python and executed consistently * Common tasks can be writen in Python and executed consistently
* Common tasks are now under source control * Common tasks are now under source control
* All developers can run the same commands, if the underlying command sequence for a task changes (after review, obv) * All developers can run the same commands, if the underlying command sequence for a task changes (after review, obv)
the user does not have to care the user does not have to care

View File

@ -15,7 +15,7 @@ OSX:
https://github.com/Bitmessage/PyBitmessage/releases https://github.com/Bitmessage/PyBitmessage/releases
Works on OSX 10.7.5 or higher Wors on OSX 10.7.5 or higher
Arch linux: Arch linux:

View File

@ -1,89 +1,65 @@
import ctypes import ctypes
import os import os
import time import time
import sys
if ctypes.sizeof(ctypes.c_voidp) == 4:
arch=32
else:
arch=64
sslName = 'OpenSSL-Win%s' % ("32" if arch == 32 else "64")
site_root = os.path.abspath(HOMEPATH)
spec_root = os.path.abspath(SPECPATH)
cdrivePath = site_root[0:3]
srcPath = os.path.join(spec_root[:-20], "src")
qtBase = "PyQt4"
openSSLPath = os.path.join(cdrivePath, sslName)
msvcrDllPath = os.path.join(cdrivePath, "windows", "system32")
pythonDllPath = os.path.join(cdrivePath, "Python27")
outPath = os.path.join(spec_root, "bitmessagemain")
importPath = srcPath
sys.path.insert(0,importPath)
os.chdir(sys.path[0])
from version import softwareVersion
srcPath = "C:\\src\\PyBitmessage\\src\\"
qtPath = "C:\\Qt-4.8.7\\"
openSSLPath = "C:\\OpenSSL-1.0.2j\\bin\\"
outPath = "C:\\src\\PyInstaller-3.2.1\\bitmessagemain"
today = time.strftime("%Y%m%d") today = time.strftime("%Y%m%d")
snapshot = False snapshot = False
os.rename(os.path.join(srcPath, '__init__.py'), os.path.join(srcPath, '__init__.py.backup')) os.rename(os.path.join(srcPath, '__init__.py'), os.path.join(srcPath, '__init__.py.backup'))
# -*- mode: python -*- # -*- mode: python -*-
a = Analysis( a = Analysis([srcPath + 'bitmessagemain.py'],
[os.path.join(srcPath, 'bitmessagemain.py')],
pathex=[outPath], pathex=[outPath],
hiddenimports=['bitmessageqt.languagebox', 'pyopencl','numpy', 'win32com' , 'setuptools.msvc' ,'_cffi_backend'], hiddenimports=[],
hookspath=None, hookspath=None,
runtime_hooks=None runtime_hooks=None)
)
os.rename(os.path.join(srcPath, '__init__.py.backup'), os.path.join(srcPath, '__init__.py')) os.rename(os.path.join(srcPath, '__init__.py.backup'), os.path.join(srcPath, '__init__.py'))
def addTranslations(): def addTranslations():
import os import os
extraDatas = [] extraDatas = []
for file_ in os.listdir(os.path.join(srcPath, 'translations')): for file in os.listdir(srcPath + 'translations'):
if file_[-3:] != ".qm": if file[-3:] != ".qm":
continue continue
extraDatas.append((os.path.join('translations', file_), extraDatas.append((os.path.join('translations', file), os.path.join(srcPath, 'translations', file), 'DATA'))
os.path.join(srcPath, 'translations', file_), 'DATA')) for file in os.listdir(qtPath + 'translations'):
for libdir in sys.path: if file[0:3] != "qt_" or file[5:8] != ".qm":
qtdir = os.path.join(libdir, qtBase, 'translations')
if os.path.isdir(qtdir):
break
if not os.path.isdir(qtdir):
return extraDatas
for file_ in os.listdir(qtdir):
if file_[0:3] != "qt_" or file_[5:8] != ".qm":
continue continue
extraDatas.append((os.path.join('translations', file_), extraDatas.append((os.path.join('translations', file), os.path.join(qtPath, 'translations', file), 'DATA'))
os.path.join(qtdir, file_), 'DATA'))
return extraDatas return extraDatas
def addUIs(): def addUIs():
import os import os
extraDatas = [] extraDatas = []
for file_ in os.listdir(os.path.join(srcPath, 'bitmessageqt')): for file in os.listdir(srcPath + 'bitmessageqt'):
if file_[-3:] != ".ui": if file[-3:] != ".ui":
continue continue
extraDatas.append((os.path.join('ui', file_), os.path.join(srcPath, extraDatas.append((os.path.join('ui', file), os.path.join(srcPath, 'bitmessageqt', file), 'DATA'))
'bitmessageqt', file_), 'DATA'))
return extraDatas return extraDatas
# append the translations directory # append the translations directory
a.datas += addTranslations() a.datas += addTranslations()
a.datas += addUIs() a.datas += addUIs()
if ctypes.sizeof(ctypes.c_voidp) == 4:
arch=32
else:
arch=64
a.binaries += [('libeay32.dll', os.path.join(openSSLPath, 'libeay32.dll'), 'BINARY'), a.binaries += [('libeay32.dll', openSSLPath + 'libeay32.dll', 'BINARY'),
('python27.dll', os.path.join(pythonDllPath, 'python27.dll'), 'BINARY'),
(os.path.join('bitmsghash', 'bitmsghash%i.dll' % (arch)), os.path.join(srcPath, 'bitmsghash', 'bitmsghash%i.dll' % (arch)), 'BINARY'), (os.path.join('bitmsghash', 'bitmsghash%i.dll' % (arch)), os.path.join(srcPath, 'bitmsghash', 'bitmsghash%i.dll' % (arch)), 'BINARY'),
(os.path.join('bitmsghash', 'bitmsghash.cl'), os.path.join(srcPath, 'bitmsghash', 'bitmsghash.cl'), 'BINARY'), (os.path.join('bitmsghash', 'bitmsghash.cl'), os.path.join(srcPath, 'bitmsghash', 'bitmsghash.cl'), 'BINARY'),
(os.path.join('sslkeys', 'cert.pem'), os.path.join(srcPath, 'sslkeys', 'cert.pem'), 'BINARY'), (os.path.join('sslkeys', 'cert.pem'), os.path.join(srcPath, 'sslkeys', 'cert.pem'), 'BINARY'),
(os.path.join('sslkeys', 'key.pem'), os.path.join(srcPath, 'sslkeys', 'key.pem'), 'BINARY') (os.path.join('sslkeys', 'key.pem'), os.path.join(srcPath, 'sslkeys', 'key.pem'), 'BINARY')
] ]
with open(os.path.join(srcPath, 'version.py'), 'rt') as f:
softwareVersion = f.readline().split('\'')[1]
fname = 'Bitmessage_%s_%s.exe' % ("x86" if arch == 32 else "x64", softwareVersion) fname = 'Bitmessage_%s_%s.exe' % ("x86" if arch == 32 else "x64", softwareVersion)
if snapshot: if snapshot:
@ -96,18 +72,8 @@ exe = EXE(pyz,
a.zipfiles, a.zipfiles,
a.datas, a.datas,
a.binaries, a.binaries,
[],
name=fname, name=fname,
debug=False, debug=False,
strip=None, strip=None,
upx=False, upx=False,
console=False, icon= os.path.join(srcPath, 'images', 'can-icon.ico')) console=False, icon= os.path.join(srcPath, 'images', 'can-icon.ico'))
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=False,
name='main')

View File

@ -1 +0,0 @@
src

View File

@ -1,17 +1,14 @@
# Since there is overlap in the violations that the different tools check for, it makes sense to quiesce some warnings # Since there is overlap in the violations that the different tools check for, it makes sense to quiesce some warnings
# in some tools if those warnings in other tools are preferred. This avoids the need to add duplicate lint warnings. # in some tools if those warnings in other tools are preferred. This avoids the need to add duplicate lint warnings.
# max-line-length should be removed ASAP!
[pycodestyle] [pycodestyle]
max-line-length = 119 max-line-length = 119
[flake8] [flake8]
max-line-length = 119 max-line-length = 119
ignore = E722,F841,W503 ignore = E722,F841
# E722: pylint is preferred for bare-except # E722: pylint is preferred for bare-except
# F841: pylint is preferred for unused-variable # F841: pylint is preferred for unused-variable
# W503: deprecated: https://bugs.python.org/issue26763 - https://www.python.org/dev/peps/pep-0008/#should-a-line-break-before-or-after-a-binary-operator
# pylint honours the [MESSAGES CONTROL] section # pylint honours the [MESSAGES CONTROL] section
# as well as [MASTER] section # as well as [MASTER] section

View File

@ -16,8 +16,13 @@ EXTRAS_REQUIRE = {
'prctl': ['python_prctl'], # Named threads 'prctl': ['python_prctl'], # Named threads
'qrcode': ['qrcode'], 'qrcode': ['qrcode'],
'sound;platform_system=="Windows"': ['winsound'], 'sound;platform_system=="Windows"': ['winsound'],
'tor': ['stem'], 'docs': [
'docs': ['sphinx', 'sphinxcontrib-apidoc', 'm2r'] 'sphinx', # fab build_docs
'graphviz', # fab build_docs
'curses', # src/depends.py
'python2-pythondialog', # src/depends.py
'm2r', # fab build_docs
]
} }
@ -64,6 +69,7 @@ if __name__ == "__main__":
'pybitmessage.network', 'pybitmessage.network',
'pybitmessage.plugins', 'pybitmessage.plugins',
'pybitmessage.pyelliptic', 'pybitmessage.pyelliptic',
'pybitmessage.socks',
'pybitmessage.storage' 'pybitmessage.storage'
] ]
@ -141,17 +147,10 @@ if __name__ == "__main__":
'libmessaging =' 'libmessaging ='
'pybitmessage.plugins.indicator_libmessaging [gir]' 'pybitmessage.plugins.indicator_libmessaging [gir]'
], ],
'bitmessage.proxyconfig': [
'stem = pybitmessage.plugins.proxyconfig_stem [tor]'
],
# 'console_scripts': [ # 'console_scripts': [
# 'pybitmessage = pybitmessage.bitmessagemain:main' # 'pybitmessage = pybitmessage.bitmessagemain:main'
# ] # ]
}, },
scripts=['src/pybitmessage'], scripts=['src/pybitmessage'],
cmdclass={'install': InstallCmd}, cmdclass={'install': InstallCmd}
command_options={
'build_sphinx': {
'source_dir': ('setup.py', 'docs')}
}
) )

@ -1 +0,0 @@
Subproject commit 5aa322da9179dae305fde5af1db516c1ad9baea4

View File

@ -1,22 +1,25 @@
""" """
Operations with addresses src/addresses.py
================
""" """
# pylint: disable=redefined-outer-name,inconsistent-return-statements # pylint: disable=redefined-outer-name,inconsistent-return-statements
import hashlib import hashlib
from binascii import hexlify, unhexlify from binascii import hexlify, unhexlify
from struct import pack, unpack from struct import pack, unpack
from debug import logger from debug import logger
ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
def encodeBase58(num, alphabet=ALPHABET): def encodeBase58(num, alphabet=ALPHABET):
"""Encode a number in Base X """Encode a number in Base X
Args: `num`: The number to encode
num: The number to encode `alphabet`: The alphabet to use for encoding
alphabet: The alphabet to use for encoding
""" """
if num == 0: if num == 0:
return alphabet[0] return alphabet[0]
@ -24,6 +27,7 @@ def encodeBase58(num, alphabet=ALPHABET):
base = len(alphabet) base = len(alphabet)
while num: while num:
rem = num % base rem = num % base
# print 'num is:', num
num = num // base num = num // base
arr.append(alphabet[rem]) arr.append(alphabet[rem])
arr.reverse() arr.reverse()
@ -33,9 +37,9 @@ def encodeBase58(num, alphabet=ALPHABET):
def decodeBase58(string, alphabet=ALPHABET): def decodeBase58(string, alphabet=ALPHABET):
"""Decode a Base X encoded string into the number """Decode a Base X encoded string into the number
Args: Arguments:
string: The encoded string - `string`: The encoded string
alphabet: The alphabet to use for encoding - `alphabet`: The alphabet to use for encoding
""" """
base = len(alphabet) base = len(alphabet)
num = 0 num = 0
@ -50,20 +54,11 @@ def decodeBase58(string, alphabet=ALPHABET):
return num return num
class varintEncodeError(Exception):
"""Exception class for encoding varint"""
pass
class varintDecodeError(Exception):
"""Exception class for decoding varint data"""
pass
def encodeVarint(integer): def encodeVarint(integer):
"""Convert integer into varint bytes""" """Convert integer into varint bytes"""
if integer < 0: if integer < 0:
raise varintEncodeError('varint cannot be < 0') logger.error('varint cannot be < 0')
raise SystemExit
if integer < 253: if integer < 253:
return pack('>B', integer) return pack('>B', integer)
if integer >= 253 and integer < 65536: if integer >= 253 and integer < 65536:
@ -73,7 +68,13 @@ def encodeVarint(integer):
if integer >= 4294967296 and integer < 18446744073709551616: if integer >= 4294967296 and integer < 18446744073709551616:
return pack('>B', 255) + pack('>Q', integer) return pack('>B', 255) + pack('>Q', integer)
if integer >= 18446744073709551616: if integer >= 18446744073709551616:
raise varintEncodeError('varint cannot be >= 18446744073709551616') logger.error('varint cannot be >= 18446744073709551616')
raise SystemExit
class varintDecodeError(Exception):
"""Exception class for decoding varint data"""
pass
def decodeVarint(data): def decodeVarint(data):
@ -178,8 +179,7 @@ def decodeAddress(address):
returns (status, address version number, stream number, returns (status, address version number, stream number,
data (almost certainly a ripe hash)) data (almost certainly a ripe hash))
""" """
# pylint: disable=too-many-return-statements,too-many-statements # pylint: disable=too-many-return-statements,too-many-statements,too-many-return-statements,too-many-branches
# pylint: disable=too-many-branches
address = str(address).strip() address = str(address).strip()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 669 B

View File

@ -1,11 +1,19 @@
# pylint: disable=too-many-locals,too-many-lines,no-self-use,too-many-public-methods,too-many-branches
# pylint: disable=too-many-statements
""" """
src/api.py
==========
# Copyright (c) 2012-2016 Jonathan Warren
# Copyright (c) 2012-2019 The Bitmessage developers
This is not what you run to run the Bitmessage API. Instead, enable the API This is not what you run to run the Bitmessage API. Instead, enable the API
( https://bitmessage.org/wiki/API ) and optionally enable daemon mode ( https://bitmessage.org/wiki/API ) and optionally enable daemon mode
( https://bitmessage.org/wiki/Daemon ) then run bitmessagemain.py. ( https://bitmessage.org/wiki/Daemon ) then run bitmessagemain.py.
""" """
# Copyright (c) 2012-2016 Jonathan Warren
# Copyright (c) 2012-2020 The Bitmessage developers from __future__ import absolute_import
# pylint: disable=too-many-lines,no-self-use,unused-variable,unused-argument
import base64 import base64
import errno import errno
import hashlib import hashlib
@ -13,34 +21,30 @@ import json
import random # nosec import random # nosec
import socket import socket
import subprocess import subprocess
import threading
import time import time
from binascii import hexlify, unhexlify from binascii import hexlify, unhexlify
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler, SimpleXMLRPCServer from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler, SimpleXMLRPCServer
from struct import pack from struct import pack
from version import softwareVersion
import defaults import defaults
import helper_inbox import helper_inbox
import helper_sent import helper_sent
import helper_threading
import network.stats import network.stats
import proofofwork import proofofwork
import queues import queues
import shared import shared
import shutdown import shutdown
import state import state
from addresses import ( from addresses import addBMIfNotPresent, calculateInventoryHash, decodeAddress, decodeVarint, varintDecodeError
addBMIfNotPresent,
calculateInventoryHash,
decodeAddress,
decodeVarint,
varintDecodeError
)
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from debug import logger from debug import logger
from helper_ackPayload import genAckPayload from helper_ackPayload import genAckPayload
from helper_sql import SqlBulkExecute, sqlExecute, sqlQuery, sqlStoredProcedure from helper_sql import SqlBulkExecute, sqlExecute, sqlQuery, sqlStoredProcedure
from inventory import Inventory from inventory import Inventory
from network.threads import StoppableThread
from version import softwareVersion
str_chan = '[chan]' str_chan = '[chan]'
@ -69,10 +73,11 @@ class StoppableXMLRPCServer(SimpleXMLRPCServer):
# This thread, of which there is only one, runs the API. # This thread, of which there is only one, runs the API.
class singleAPI(StoppableThread): class singleAPI(threading.Thread, helper_threading.StoppableThread):
"""API thread""" """API thread"""
def __init__(self):
name = "singleAPI" threading.Thread.__init__(self, name="singleAPI")
self.initStop()
def stopThread(self): def stopThread(self):
super(singleAPI, self).stopThread() super(singleAPI, self).stopThread()
@ -96,8 +101,6 @@ class singleAPI(StoppableThread):
for attempt in range(50): for attempt in range(50):
try: try:
if attempt > 0: if attempt > 0:
logger.warning(
'Failed to start API listener on port %s', port)
port = random.randint(32767, 65535) port = random.randint(32767, 65535)
se = StoppableXMLRPCServer( se = StoppableXMLRPCServer(
(BMConfigParser().get( (BMConfigParser().get(
@ -109,9 +112,8 @@ class singleAPI(StoppableThread):
continue continue
else: else:
if attempt > 0: if attempt > 0:
logger.warning('Setting apiport to %s', port)
BMConfigParser().set( BMConfigParser().set(
'bitmessagesettings', 'apiport', str(port)) "bitmessagesettings", "apiport", str(port))
BMConfigParser().save() BMConfigParser().save()
break break
se.register_introspection_functions() se.register_introspection_functions()
@ -137,11 +139,9 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
""" """
This is one of several classes that constitute the API This is one of several classes that constitute the API
This class was written by Vaibhav Bhatia. This class was written by Vaibhav Bhatia. Modified by Jonathan Warren (Atheros).
Modified by Jonathan Warren (Atheros).
http://code.activestate.com/recipes/501148-xmlrpc-serverclient-which-does-cookie-handling-and/ http://code.activestate.com/recipes/501148-xmlrpc-serverclient-which-does-cookie-handling-and/
""" """
# pylint: disable=too-many-public-methods
def do_POST(self): def do_POST(self):
""" """
@ -178,8 +178,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
# SimpleXMLRPCDispatcher. To maintain backwards compatibility, # SimpleXMLRPCDispatcher. To maintain backwards compatibility,
# check to see if a subclass implements _dispatch and dispatch # check to see if a subclass implements _dispatch and dispatch
# using that method if present. # using that method if present.
# pylint: disable=protected-access response = self.server._marshaled_dispatch( # pylint: disable=protected-access
response = self.server._marshaled_dispatch(
data, getattr(self, '_dispatch', None) data, getattr(self, '_dispatch', None)
) )
except BaseException: # This should only happen if the module is buggy except BaseException: # This should only happen if the module is buggy
@ -217,10 +216,8 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
_, encstr = self.headers.get('Authorization').split() _, encstr = self.headers.get('Authorization').split()
emailid, password = encstr.decode('base64').split(':') emailid, password = encstr.decode('base64').split(':')
return ( return (
emailid == BMConfigParser().get( emailid == BMConfigParser().get('bitmessagesettings', 'apiusername') and
'bitmessagesettings', 'apiusername') and password == BMConfigParser().get('bitmessagesettings', 'apipassword')
password == BMConfigParser().get(
'bitmessagesettings', 'apipassword')
) )
else: else:
logger.warning( logger.warning(
@ -257,14 +254,10 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
if status == 'invalidcharacters': if status == 'invalidcharacters':
raise APIError(9, 'Invalid characters in address: ' + address) raise APIError(9, 'Invalid characters in address: ' + address)
if status == 'versiontoohigh': if status == 'versiontoohigh':
raise APIError( raise APIError(10, 'Address version number too high (or zero) in address: ' + address)
10,
'Address version number too high (or zero) in address: ' +
address)
if status == 'varintmalformed': if status == 'varintmalformed':
raise APIError(26, 'Malformed varint in address: ' + address) raise APIError(26, 'Malformed varint in address: ' + address)
raise APIError( raise APIError(7, 'Could not decode address: %s : %s' % (address, status))
7, 'Could not decode address: %s : %s' % (address, status))
if addressVersionNumber < 2 or addressVersionNumber > 4: if addressVersionNumber < 2 or addressVersionNumber > 4:
raise APIError( raise APIError(
11, 'The address version number currently must be 2, 3 or 4.' 11, 'The address version number currently must be 2, 3 or 4.'
@ -282,9 +275,10 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
def HandleListAddresses(self, method): def HandleListAddresses(self, method):
"""Handle a request to list addresses""" """Handle a request to list addresses"""
data = '{"addresses":[' data = '{"addresses":['
for addressInKeysFile in BMConfigParser().addresses(): for addressInKeysFile in BMConfigParser().addresses():
status, addressVersionNumber, streamNumber, hash01 = decodeAddress( status, addressVersionNumber, streamNumber, hash01 = decodeAddress( # pylint: disable=unused-variable
addressInKeysFile) addressInKeysFile)
if len(data) > 20: if len(data) > 20:
data += ',' data += ','
@ -388,19 +382,16 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
elif len(params) == 3: elif len(params) == 3:
label, eighteenByteRipe, totalDifficulty = params label, eighteenByteRipe, totalDifficulty = params
nonceTrialsPerByte = int( nonceTrialsPerByte = int(
defaults.networkDefaultProofOfWorkNonceTrialsPerByte * defaults.networkDefaultProofOfWorkNonceTrialsPerByte * totalDifficulty)
totalDifficulty)
payloadLengthExtraBytes = BMConfigParser().get( payloadLengthExtraBytes = BMConfigParser().get(
'bitmessagesettings', 'defaultpayloadlengthextrabytes') 'bitmessagesettings', 'defaultpayloadlengthextrabytes')
elif len(params) == 4: elif len(params) == 4:
label, eighteenByteRipe, totalDifficulty, \ label, eighteenByteRipe, totalDifficulty, \
smallMessageDifficulty = params smallMessageDifficulty = params
nonceTrialsPerByte = int( nonceTrialsPerByte = int(
defaults.networkDefaultProofOfWorkNonceTrialsPerByte * defaults.networkDefaultProofOfWorkNonceTrialsPerByte * totalDifficulty)
totalDifficulty)
payloadLengthExtraBytes = int( payloadLengthExtraBytes = int(
defaults.networkDefaultPayloadLengthExtraBytes * defaults.networkDefaultPayloadLengthExtraBytes * smallMessageDifficulty)
smallMessageDifficulty)
else: else:
raise APIError(0, 'Too many parameters!') raise APIError(0, 'Too many parameters!')
label = self._decode(label, "base64") label = self._decode(label, "base64")
@ -418,7 +409,6 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
def HandleCreateDeterministicAddresses(self, params): def HandleCreateDeterministicAddresses(self, params):
"""Handle a request to create a deterministic address""" """Handle a request to create a deterministic address"""
# pylint: disable=too-many-branches, too-many-statements
if not params: if not params:
raise APIError(0, 'I need parameters!') raise APIError(0, 'I need parameters!')
@ -474,8 +464,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
passphrase, numberOfAddresses, addressVersionNumber, \ passphrase, numberOfAddresses, addressVersionNumber, \
streamNumber, eighteenByteRipe, totalDifficulty = params streamNumber, eighteenByteRipe, totalDifficulty = params
nonceTrialsPerByte = int( nonceTrialsPerByte = int(
defaults.networkDefaultProofOfWorkNonceTrialsPerByte * defaults.networkDefaultProofOfWorkNonceTrialsPerByte * totalDifficulty)
totalDifficulty)
payloadLengthExtraBytes = BMConfigParser().get( payloadLengthExtraBytes = BMConfigParser().get(
'bitmessagesettings', 'defaultpayloadlengthextrabytes') 'bitmessagesettings', 'defaultpayloadlengthextrabytes')
@ -484,11 +473,9 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
streamNumber, eighteenByteRipe, totalDifficulty, \ streamNumber, eighteenByteRipe, totalDifficulty, \
smallMessageDifficulty = params smallMessageDifficulty = params
nonceTrialsPerByte = int( nonceTrialsPerByte = int(
defaults.networkDefaultProofOfWorkNonceTrialsPerByte * defaults.networkDefaultProofOfWorkNonceTrialsPerByte * totalDifficulty)
totalDifficulty)
payloadLengthExtraBytes = int( payloadLengthExtraBytes = int(
defaults.networkDefaultPayloadLengthExtraBytes * defaults.networkDefaultPayloadLengthExtraBytes * smallMessageDifficulty)
smallMessageDifficulty)
else: else:
raise APIError(0, 'Too many parameters!') raise APIError(0, 'Too many parameters!')
if not passphrase: if not passphrase:
@ -622,8 +609,9 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
label = str_chan + ' ' + passphrase label = str_chan + ' ' + passphrase
except BaseException: except BaseException:
label = str_chan + ' ' + repr(passphrase) label = str_chan + ' ' + repr(passphrase)
status, addressVersionNumber, streamNumber, toRipe = (
self._verifyAddress(suppliedAddress)) status, addressVersionNumber, streamNumber, toRipe = self._verifyAddress( # pylint: disable=unused-variable
suppliedAddress)
suppliedAddress = addBMIfNotPresent(suppliedAddress) suppliedAddress = addBMIfNotPresent(suppliedAddress)
queues.apiAddressGeneratorReturnQueue.queue.clear() queues.apiAddressGeneratorReturnQueue.queue.clear()
queues.addressGeneratorQueue.put(( queues.addressGeneratorQueue.put((
@ -646,8 +634,8 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
raise APIError(0, 'I need parameters.') raise APIError(0, 'I need parameters.')
elif len(params) == 1: elif len(params) == 1:
address, = params address, = params
status, addressVersionNumber, streamNumber, toRipe = ( # pylint: disable=unused-variable
self._verifyAddress(address)) status, addressVersionNumber, streamNumber, toRipe = self._verifyAddress(address)
address = addBMIfNotPresent(address) address = addBMIfNotPresent(address)
if not BMConfigParser().has_section(address): if not BMConfigParser().has_section(address):
raise APIError( raise APIError(
@ -668,8 +656,8 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
raise APIError(0, 'I need parameters.') raise APIError(0, 'I need parameters.')
elif len(params) == 1: elif len(params) == 1:
address, = params address, = params
status, addressVersionNumber, streamNumber, toRipe = ( # pylint: disable=unused-variable
self._verifyAddress(address)) status, addressVersionNumber, streamNumber, toRipe = self._verifyAddress(address)
address = addBMIfNotPresent(address) address = addBMIfNotPresent(address)
if not BMConfigParser().has_section(address): if not BMConfigParser().has_section(address):
raise APIError( raise APIError(
@ -681,7 +669,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
shared.reloadMyAddressHashes() shared.reloadMyAddressHashes()
return 'success' return 'success'
def HandleGetAllInboxMessages(self, params): def HandleGetAllInboxMessages(self, params): # pylint: disable=unused-argument
"""Handle a request to get all inbox messages""" """Handle a request to get all inbox messages"""
queryreturn = sqlQuery( queryreturn = sqlQuery(
@ -709,7 +697,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
data += ']}' data += ']}'
return data return data
def HandleGetAllInboxMessageIds(self, params): def HandleGetAllInboxMessageIds(self, params): # pylint: disable=unused-argument
"""Handle a request to get all inbox message IDs""" """Handle a request to get all inbox message IDs"""
queryreturn = sqlQuery( queryreturn = sqlQuery(
@ -768,7 +756,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
data += ']}' data += ']}'
return data return data
def HandleGetAllSentMessages(self, params): def HandleGetAllSentMessages(self, params): # pylint: disable=unused-argument
"""Handle a request to get all sent messages""" """Handle a request to get all sent messages"""
queryreturn = sqlQuery( queryreturn = sqlQuery(
@ -797,7 +785,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
data += ']}' data += ']}'
return data return data
def HandleGetAllSentMessageIds(self, params): def HandleGetAllSentMessageIds(self, params): # pylint: disable=unused-argument
"""Handle a request to get all sent message IDs""" """Handle a request to get all sent message IDs"""
queryreturn = sqlQuery( queryreturn = sqlQuery(
@ -888,7 +876,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
data = '{"sentMessages":[' data = '{"sentMessages":['
for row in queryreturn: for row in queryreturn:
msgid, toAddress, fromAddress, subject, lastactiontime, message, \ msgid, toAddress, fromAddress, subject, lastactiontime, message, \
encodingtype, status, ackdata = row encodingtype, status, ackdata = row # pylint: disable=unused-variable
subject = shared.fixPotentiallyInvalidUTF8Data(subject) subject = shared.fixPotentiallyInvalidUTF8Data(subject)
message = shared.fixPotentiallyInvalidUTF8Data(message) message = shared.fixPotentiallyInvalidUTF8Data(message)
if len(data) > 25: if len(data) > 25:
@ -967,7 +955,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
sqlExecute('''UPDATE sent SET folder='trash' WHERE msgid=?''', msgid) sqlExecute('''UPDATE sent SET folder='trash' WHERE msgid=?''', msgid)
return 'Trashed sent message (assuming message existed).' return 'Trashed sent message (assuming message existed).'
def HandleSendMessage(self, params): # pylint: disable=too-many-locals def HandleSendMessage(self, params):
"""Handle a request to send a message""" """Handle a request to send a message"""
if not params: if not params:
@ -998,6 +986,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
TTL = 28 * 24 * 60 * 60 TTL = 28 * 24 * 60 * 60
toAddress = addBMIfNotPresent(toAddress) toAddress = addBMIfNotPresent(toAddress)
fromAddress = addBMIfNotPresent(fromAddress) fromAddress = addBMIfNotPresent(fromAddress)
# pylint: disable=unused-variable
status, addressVersionNumber, streamNumber, toRipe = \ status, addressVersionNumber, streamNumber, toRipe = \
self._verifyAddress(toAddress) self._verifyAddress(toAddress)
self._verifyAddress(fromAddress) self._verifyAddress(fromAddress)
@ -1171,9 +1160,10 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
queues.UISignalQueue.put(('rerenderSubscriptions', '')) queues.UISignalQueue.put(('rerenderSubscriptions', ''))
return 'Deleted subscription if it existed.' return 'Deleted subscription if it existed.'
def ListSubscriptions(self, params): def ListSubscriptions(self, params): # pylint: disable=unused-argument
"""Handle a request to list susbcriptions""" """Handle a request to list susbcriptions"""
# pylint: disable=unused-variable
queryreturn = sqlQuery( queryreturn = sqlQuery(
"SELECT label, address, enabled FROM subscriptions") "SELECT label, address, enabled FROM subscriptions")
data = {'subscriptions': []} data = {'subscriptions': []}
@ -1208,15 +1198,12 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
) )
with shared.printLock: with shared.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:',
float( float(
requiredAverageProofOfWorkNonceTrialsPerByte requiredAverageProofOfWorkNonceTrialsPerByte
) / defaults.networkDefaultProofOfWorkNonceTrialsPerByte, ) / defaults.networkDefaultProofOfWorkNonceTrialsPerByte,
'Required small message difficulty:', 'Required small message difficulty:',
float( float(requiredPayloadLengthExtraBytes) / defaults.networkDefaultPayloadLengthExtraBytes,
requiredPayloadLengthExtraBytes
) / defaults.networkDefaultPayloadLengthExtraBytes,
) )
powStartTime = time.time() powStartTime = time.time()
initialHash = hashlib.sha512(encryptedPayload).digest() initialHash = hashlib.sha512(encryptedPayload).digest()
@ -1225,9 +1212,8 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
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), 'seconds.',
'seconds.', nonce / (time.time() - powStartTime), nonce / (time.time() - powStartTime), 'nonce trials per second.',
'nonce trials per second.',
) )
except BaseException: except BaseException:
pass pass
@ -1254,7 +1240,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
sqlExecute("UPDATE sent SET folder='trash' WHERE ackdata=?", ackdata) sqlExecute("UPDATE sent SET folder='trash' WHERE ackdata=?", ackdata)
return 'Trashed sent message (assuming message existed).' return 'Trashed sent message (assuming message existed).'
def HandleDissimatePubKey(self, params): def HandleDissimatePubKey(self, params): # pylint: disable=unused-argument
"""Handle a request to disseminate a public key""" """Handle a request to disseminate a public key"""
# The device issuing this command to PyBitmessage supplies a pubkey # The device issuing this command to PyBitmessage supplies a pubkey
@ -1283,6 +1269,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
pubkeyReadPosition += 8 pubkeyReadPosition += 8
else: else:
pubkeyReadPosition += 4 pubkeyReadPosition += 4
# pylint: disable=unused-variable
addressVersion, addressVersionLength = decodeVarint( addressVersion, addressVersionLength = decodeVarint(
payload[pubkeyReadPosition:pubkeyReadPosition + 10]) payload[pubkeyReadPosition:pubkeyReadPosition + 10])
pubkeyReadPosition += addressVersionLength pubkeyReadPosition += addressVersionLength
@ -1341,7 +1328,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
data += ']}' data += ']}'
return data return data
def HandleClientStatus(self, params): def HandleClientStatus(self, params): # pylint: disable=unused-argument
"""Handle a request to get the status of the client""" """Handle a request to get the status of the client"""
connections_num = len(network.stats.connectedHostsList()) connections_num = len(network.stats.connectedHostsList())

View File

@ -13,15 +13,15 @@ TODO: fix the following (currently ignored) violations:
""" """
import xmlrpclib
import datetime import datetime
import imghdr import imghdr
import json
import ntpath import ntpath
import os import json
import socket import socket
import sys
import time import time
import xmlrpclib import sys
import os
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser

View File

@ -1,6 +1,3 @@
"""
Bitmessage commandline interface
"""
# Copyright (c) 2014 Luke Montalvo <lukemontalvo@gmail.com> # Copyright (c) 2014 Luke Montalvo <lukemontalvo@gmail.com>
# This file adds a alternative commandline interface, feel free to critique and fork # This file adds a alternative commandline interface, feel free to critique and fork
# #
@ -10,30 +7,34 @@ Bitmessage commandline interface
# * python2-pythondialog # * python2-pythondialog
# * dialog # * dialog
import ConfigParser
import curses
import os import os
import sys import sys
import StringIO
from textwrap import *
import time import time
from textwrap import fill from time import strftime, localtime
from threading import Timer from threading import Timer
import curses
import dialog
from dialog import Dialog from dialog import Dialog
from helper_sql import *
from helper_ackPayload import genAckPayload
from addresses import *
import ConfigParser
from bmconfigparser import BMConfigParser
from inventory import Inventory
import l10n import l10n
import network.stats from pyelliptic.openssl import OpenSSL
import queues import queues
import shared import shared
import shutdown import shutdown
import network.stats
from addresses import addBMIfNotPresent, decodeAddress
from bmconfigparser import BMConfigParser
from helper_ackPayload import genAckPayload
from helper_sql import sqlExecute, sqlQuery
from inventory import Inventory
# pylint: disable=global-statement
quit_ = False quit = False
menutab = 1 menutab = 1
menu = ["Inbox", "Send", "Sent", "Your Identities", "Subscriptions", "Address Book", "Blacklist", "Network Status"] menu = ["Inbox", "Send", "Sent", "Your Identities", "Subscriptions", "Address Book", "Blacklist", "Network Status"]
naptime = 100 naptime = 100
@ -59,60 +60,37 @@ bwtype = "black"
BROADCAST_STR = "[Broadcast subscribers]" BROADCAST_STR = "[Broadcast subscribers]"
class printLog:
class printLog(object):
"""Printing logs"""
# pylint: disable=no-self-use
def write(self, output): def write(self, output):
"""Write logs"""
global log global log
log += output log += output
def flush(self): def flush(self):
"""Flush logs"""
pass pass
class errLog:
class errLog(object):
"""Error logs"""
# pylint: disable=no-self-use
def write(self, output): def write(self, output):
"""Write error logs"""
global log global log
log += "!"+output log += "!"+output
def flush(self): def flush(self):
"""Flush error logs"""
pass pass
printlog = printLog() printlog = printLog()
errlog = errLog() errlog = errLog()
def cpair(a): def cpair(a):
"""Color pairs"""
r = curses.color_pair(a) r = curses.color_pair(a)
if r not in range(1, curses.COLOR_PAIRS-1): if r not in range(1, curses.COLOR_PAIRS-1):
r = curses.color_pair(0) r = curses.color_pair(0)
return r return r
def ascii(s): def ascii(s):
"""ASCII values"""
r = "" r = ""
for c in s: for c in s:
if ord(c) in range(128): if ord(c) in range(128):
r += c r += c
return r return r
def drawmenu(stdscr): def drawmenu(stdscr):
"""Creating menu's"""
menustr = " " menustr = " "
for i, _ in enumerate(menu): for i in range(0, len(menu)):
if menutab == i+1: if menutab == i+1:
menustr = menustr[:-1] menustr = menustr[:-1]
menustr += "[" menustr += "["
@ -123,34 +101,24 @@ def drawmenu(stdscr):
menustr += " " menustr += " "
stdscr.addstr(2, 5, menustr, curses.A_UNDERLINE) stdscr.addstr(2, 5, menustr, curses.A_UNDERLINE)
def set_background_title(d, title): def set_background_title(d, title):
"""Setting background title"""
try: try:
d.set_background_title(title) d.set_background_title(title)
except: except:
d.add_persistent_args(("--backtitle", title)) d.add_persistent_args(("--backtitle", title))
def scrollbox(d, text, height=None, width=None): def scrollbox(d, text, height=None, width=None):
"""Setting scroll box"""
try: try:
d.scrollbox(text, height, width, exit_label = "Continue") d.scrollbox(text, height, width, exit_label = "Continue")
except: except:
d.msgbox(text, height or 0, width or 0, ok_label = "Continue") d.msgbox(text, height or 0, width or 0, ok_label = "Continue")
def resetlookups(): def resetlookups():
"""Reset the Inventory Lookups"""
global inventorydata global inventorydata
inventorydata = Inventory().numberOfInventoryLookupsPerformed inventorydata = Inventory().numberOfInventoryLookupsPerformed
Inventory().numberOfInventoryLookupsPerformed = 0 Inventory().numberOfInventoryLookupsPerformed = 0
Timer(1, resetlookups, ()).start() Timer(1, resetlookups, ()).start()
def drawtab(stdscr): def drawtab(stdscr):
"""Method for drawing different tabs"""
# pylint: disable=too-many-branches, too-many-statements
if menutab in range(1, len(menu)+1): if menutab in range(1, len(menu)+1):
if menutab == 1: # Inbox if menutab == 1: # Inbox
stdscr.addstr(3, 5, "To", curses.A_BOLD) stdscr.addstr(3, 5, "To", curses.A_BOLD)
@ -161,10 +129,9 @@ def drawtab(stdscr):
for i, item in enumerate(inbox[max(min(len(inbox)-curses.LINES+6, inboxcur-5), 0):]): for i, item in enumerate(inbox[max(min(len(inbox)-curses.LINES+6, inboxcur-5), 0):]):
if 6+i < curses.LINES: if 6+i < curses.LINES:
a = 0 a = 0
if i == inboxcur - max(min(len(inbox) - curses.LINES + 6, inboxcur - 5), 0): if i == inboxcur - max(min(len(inbox)-curses.LINES+6, inboxcur-5), 0): # Highlight current address
# Highlight current address
a = a | curses.A_REVERSE a = a | curses.A_REVERSE
if item[7] is False: # If not read, highlight if item[7] == False: # If not read, highlight
a = a | curses.A_BOLD a = a | curses.A_BOLD
stdscr.addstr(5+i, 5, item[1][:34], a) stdscr.addstr(5+i, 5, item[1][:34], a)
stdscr.addstr(5+i, 40, item[3][:39], a) stdscr.addstr(5+i, 40, item[3][:39], a)
@ -179,8 +146,7 @@ def drawtab(stdscr):
for i, item in enumerate(sentbox[max(min(len(sentbox)-curses.LINES+6, sentcur-5), 0):]): for i, item in enumerate(sentbox[max(min(len(sentbox)-curses.LINES+6, sentcur-5), 0):]):
if 6+i < curses.LINES: if 6+i < curses.LINES:
a = 0 a = 0
if i == sentcur - max(min(len(sentbox) - curses.LINES + 6, sentcur - 5), 0): if i == sentcur - max(min(len(sentbox)-curses.LINES+6, sentcur-5), 0): # Highlight current address
# Highlight current address
a = a | curses.A_REVERSE a = a | curses.A_REVERSE
stdscr.addstr(5+i, 5, item[0][:34], a) stdscr.addstr(5+i, 5, item[0][:34], a)
stdscr.addstr(5+i, 40, item[2][:39], a) stdscr.addstr(5+i, 40, item[2][:39], a)
@ -194,10 +160,9 @@ def drawtab(stdscr):
for i, item in enumerate(addresses[max(min(len(addresses)-curses.LINES+6, addrcur-5), 0):]): for i, item in enumerate(addresses[max(min(len(addresses)-curses.LINES+6, addrcur-5), 0):]):
if 6+i < curses.LINES: if 6+i < curses.LINES:
a = 0 a = 0
if i == addrcur - max(min(len(addresses) - curses.LINES + 6, addrcur - 5), 0): if i == addrcur - max(min(len(addresses)-curses.LINES+6, addrcur-5), 0): # Highlight current address
# Highlight current address
a = a | curses.A_REVERSE a = a | curses.A_REVERSE
if item[1] and item[3] not in [8, 9]: # Embolden enabled, non-special addresses if item[1] == True and item[3] not in [8,9]: # Embolden enabled, non-special addresses
a = a | curses.A_BOLD a = a | curses.A_BOLD
stdscr.addstr(5+i, 5, item[0][:34], a) stdscr.addstr(5+i, 5, item[0][:34], a)
stdscr.addstr(5+i, 40, item[2][:39], cpair(item[3]) | a) stdscr.addstr(5+i, 40, item[2][:39], cpair(item[3]) | a)
@ -210,10 +175,9 @@ def drawtab(stdscr):
for i, item in enumerate(subscriptions[max(min(len(subscriptions)-curses.LINES+6, subcur-5), 0):]): for i, item in enumerate(subscriptions[max(min(len(subscriptions)-curses.LINES+6, subcur-5), 0):]):
if 6+i < curses.LINES: if 6+i < curses.LINES:
a = 0 a = 0
if i == subcur - max(min(len(subscriptions) - curses.LINES + 6, subcur - 5), 0): if i == subcur - max(min(len(subscriptions)-curses.LINES+6, subcur-5), 0): # Highlight current address
# Highlight current address
a = a | curses.A_REVERSE a = a | curses.A_REVERSE
if item[2]: # Embolden enabled subscriptions if item[2] == True: # Embolden enabled subscriptions
a = a | curses.A_BOLD a = a | curses.A_BOLD
stdscr.addstr(5+i, 5, item[0][:74], a) stdscr.addstr(5+i, 5, item[0][:74], a)
stdscr.addstr(5+i, 80, item[1][:39], a) stdscr.addstr(5+i, 80, item[1][:39], a)
@ -225,8 +189,7 @@ def drawtab(stdscr):
for i, item in enumerate(addrbook[max(min(len(addrbook)-curses.LINES+6, abookcur-5), 0):]): for i, item in enumerate(addrbook[max(min(len(addrbook)-curses.LINES+6, abookcur-5), 0):]):
if 6+i < curses.LINES: if 6+i < curses.LINES:
a = 0 a = 0
if i == abookcur - max(min(len(addrbook) - curses.LINES + 6, abookcur - 5), 0): if i == abookcur - max(min(len(addrbook)-curses.LINES+6, abookcur-5), 0): # Highlight current address
# Highlight current address
a = a | curses.A_REVERSE a = a | curses.A_REVERSE
stdscr.addstr(5+i, 5, item[0][:34], a) stdscr.addstr(5+i, 5, item[0][:34], a)
stdscr.addstr(5+i, 40, item[1][:39], a) stdscr.addstr(5+i, 40, item[1][:39], a)
@ -239,10 +202,9 @@ def drawtab(stdscr):
for i, item in enumerate(blacklist[max(min(len(blacklist)-curses.LINES+6, blackcur-5), 0):]): for i, item in enumerate(blacklist[max(min(len(blacklist)-curses.LINES+6, blackcur-5), 0):]):
if 7+i < curses.LINES: if 7+i < curses.LINES:
a = 0 a = 0
if i == blackcur - max(min(len(blacklist) - curses.LINES + 6, blackcur - 5), 0): if i == blackcur - max(min(len(blacklist)-curses.LINES+6, blackcur-5), 0): # Highlight current address
# Highlight current address
a = a | curses.A_REVERSE a = a | curses.A_REVERSE
if item[2]: # Embolden enabled subscriptions if item[2] == True: # Embolden enabled subscriptions
a = a | curses.A_BOLD a = a | curses.A_BOLD
stdscr.addstr(6+i, 5, item[0][:74], a) stdscr.addstr(6+i, 5, item[0][:74], a)
stdscr.addstr(6+i, 80, item[1][:39], a) stdscr.addstr(6+i, 80, item[1][:39], a)
@ -273,12 +235,9 @@ 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.")
shared.numberOfMessagesProcessed).ljust(4) + " person-to-person messages.") stdscr.addstr(8, 40, "Processed "+str(shared.numberOfBroadcastsProcessed).ljust(4)+" broadcast messages.")
stdscr.addstr(8, 40, "Processed " + str( stdscr.addstr(9, 40, "Processed "+str(shared.numberOfPubkeysProcessed).ljust(4)+" public keys.")
shared.numberOfBroadcastsProcessed).ljust(4) + " broadcast messages.")
stdscr.addstr(9, 40, "Processed " + str(
shared.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))
@ -287,40 +246,30 @@ def drawtab(stdscr):
stdscr.addstr(13, 6, "Log", curses.A_BOLD) stdscr.addstr(13, 6, "Log", curses.A_BOLD)
n = log.count('\n') n = log.count('\n')
if n > 0: if n > 0:
lg = log.split('\n') l = log.split('\n')
if n > 512: if n > 512:
del lg[:(n - 256)] del l[:(n-256)]
logpad.erase() logpad.erase()
n = len(lg) n = len(l)
for i, item in enumerate(lg): for i, item in enumerate(l):
a = 0 a = 0
if item and item[0] == '!': if len(item) > 0 and item[0] == '!':
a = curses.color_pair(1) a = curses.color_pair(1)
item = item[1:] item = item[1:]
logpad.addstr(i, 0, item, a) logpad.addstr(i, 0, item, a)
logpad.refresh(n-curses.LINES+2, 0, 14, 6, curses.LINES-2, curses.COLS-7) logpad.refresh(n-curses.LINES+2, 0, 14, 6, curses.LINES-2, curses.COLS-7)
stdscr.refresh() stdscr.refresh()
def redraw(stdscr): def redraw(stdscr):
"""Redraw menu"""
stdscr.erase() stdscr.erase()
stdscr.border() stdscr.border()
drawmenu(stdscr) drawmenu(stdscr)
stdscr.refresh() stdscr.refresh()
def dialogreset(stdscr): def dialogreset(stdscr):
"""Resetting dialogue"""
stdscr.clear() stdscr.clear()
stdscr.keypad(1) stdscr.keypad(1)
curses.curs_set(0) curses.curs_set(0)
# pylint: disable=too-many-branches, too-many-statements
def handlech(c, stdscr): def handlech(c, stdscr):
"""Handle character given on the command-line interface"""
# pylint: disable=redefined-outer-name, too-many-nested-blocks, too-many-locals
if c != curses.ERR: if c != curses.ERR:
global inboxcur, addrcur, sentcur, subcur, abookcur, blackcur global inboxcur, addrcur, sentcur, subcur, abookcur, blackcur
if c in range(256): if c in range(256):
@ -328,17 +277,15 @@ def handlech(c, stdscr):
global menutab global menutab
menutab = int(chr(c)) menutab = int(chr(c))
elif chr(c) == 'q': elif chr(c) == 'q':
global quit_ global quit
quit_ = True quit = True
elif chr(c) == '\n': elif chr(c) == '\n':
curses.curs_set(1) curses.curs_set(1)
d = Dialog(dialog="dialog") d = Dialog(dialog="dialog")
if menutab == 1: if menutab == 1:
set_background_title(d, "Inbox Message Dialog Box") set_background_title(d, "Inbox Message Dialog Box")
r, t = d.menu( r, t = d.menu("Do what with \""+inbox[inboxcur][5]+"\" from \""+inbox[inboxcur][3]+"\"?",
"Do what with \"" + inbox[inboxcur][5] + "\" from \"" + inbox[inboxcur][3] + "\"?", choices=[("1", "View message"),
choices=[
("1", "View message"),
("2", "Mark message as unread"), ("2", "Mark message as unread"),
("3", "Reply"), ("3", "Reply"),
("4", "Add sender to Address Book"), ("4", "Add sender to Address Book"),
@ -346,16 +293,8 @@ def handlech(c, stdscr):
("6", "Move to trash")]) ("6", "Move to trash")])
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
if t == "1": # View if t == "1": # View
set_background_title( set_background_title(d, "\""+inbox[inboxcur][5]+"\" from \""+inbox[inboxcur][3]+"\" to \""+inbox[inboxcur][1]+"\"")
d, data = ""
"\"" +
inbox[inboxcur][5] +
"\" from \"" +
inbox[inboxcur][3] +
"\" to \"" +
inbox[inboxcur][1] +
"\"")
data = "" # pyint: disable=redefined-outer-name
ret = sqlQuery("SELECT message FROM inbox WHERE msgid=?", inbox[inboxcur][0]) ret = sqlQuery("SELECT message FROM inbox WHERE msgid=?", inbox[inboxcur][0])
if ret != []: if ret != []:
for row in ret: for row in ret:
@ -381,10 +320,8 @@ def handlech(c, stdscr):
if fromaddr == item[2] and item[3] != 0: if fromaddr == item[2] and item[3] != 0:
ischan = True ischan = True
break break
if not addresses[i][1]: # pylint: disable=undefined-loop-variable if not addresses[i][1]:
scrollbox(d, unicode( scrollbox(d, unicode("Sending address disabled, please either enable it or choose a different address."))
"Sending address disabled, please either enable it"
"or choose a different address."))
return return
toaddr = m[2] toaddr = m[2]
if ischan: if ischan:
@ -432,9 +369,7 @@ def handlech(c, stdscr):
elif t == "6": # Move to trash elif t == "6": # Move to trash
sqlExecute("UPDATE inbox SET folder='trash' WHERE msgid=?", inbox[inboxcur][0]) sqlExecute("UPDATE inbox SET folder='trash' WHERE msgid=?", inbox[inboxcur][0])
del inbox[inboxcur] del inbox[inboxcur]
scrollbox(d, unicode( scrollbox(d, unicode("Message moved to trash. There is no interface to view your trash, \nbut the message is still on disk if you are desperate to recover it."))
"Message moved to trash. There is no interface to view your trash,"
" \nbut the message is still on disk if you are desperate to recover it."))
elif menutab == 2: elif menutab == 2:
a = "" a = ""
if addresses[addrcur][3] != 0: # if current address is a chan if addresses[addrcur][3] != 0: # if current address is a chan
@ -442,27 +377,14 @@ def handlech(c, stdscr):
sendMessage(addresses[addrcur][2], a) sendMessage(addresses[addrcur][2], a)
elif menutab == 3: elif menutab == 3:
set_background_title(d, "Sent Messages Dialog Box") set_background_title(d, "Sent Messages Dialog Box")
r, t = d.menu( r, t = d.menu("Do what with \""+sentbox[sentcur][4]+"\" to \""+sentbox[sentcur][0]+"\"?",
"Do what with \"" + sentbox[sentcur][4] + "\" to \"" + sentbox[sentcur][0] + "\"?", choices=[("1", "View message"),
choices=[
("1", "View message"),
("2", "Move to trash")]) ("2", "Move to trash")])
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
if t == "1": # View if t == "1": # View
set_background_title( set_background_title(d, "\""+sentbox[sentcur][4]+"\" from \""+sentbox[sentcur][3]+"\" to \""+sentbox[sentcur][1]+"\"")
d,
"\"" +
sentbox[sentcur][4] +
"\" from \"" +
sentbox[sentcur][3] +
"\" to \"" +
sentbox[sentcur][1] +
"\"")
data = "" data = ""
ret = sqlQuery( ret = sqlQuery("SELECT message FROM sent WHERE subject=? AND ackdata=?", sentbox[sentcur][4], sentbox[sentcur][6])
"SELECT message FROM sent WHERE subject=? AND ackdata=?",
sentbox[sentcur][4],
sentbox[sentcur][6])
if ret != []: if ret != []:
for row in ret: for row in ret:
data, = row data, = row
@ -474,26 +396,17 @@ def handlech(c, stdscr):
else: else:
scrollbox(d, unicode("Could not fetch message.")) scrollbox(d, unicode("Could not fetch message."))
elif t == "2": # Move to trash elif t == "2": # Move to trash
sqlExecute( sqlExecute("UPDATE sent SET folder='trash' WHERE subject=? AND ackdata=?", sentbox[sentcur][4], sentbox[sentcur][6])
"UPDATE sent SET folder='trash' WHERE subject=? AND ackdata=?",
sentbox[sentcur][4],
sentbox[sentcur][6])
del sentbox[sentcur] del sentbox[sentcur]
scrollbox(d, unicode( scrollbox(d, unicode("Message moved to trash. There is no interface to view your trash, \nbut the message is still on disk if you are desperate to recover it."))
"Message moved to trash. There is no interface to view your trash"
" \nbut the message is still on disk if you are desperate to recover it."))
elif menutab == 4: elif menutab == 4:
set_background_title(d, "Your Identities Dialog Box") set_background_title(d, "Your Identities Dialog Box")
if len(addresses) <= addrcur: if len(addresses) <= addrcur:
r, t = d.menu( r, t = d.menu("Do what with addresses?",
"Do what with addresses?", choices=[("1", "Create new address")])
choices=[
("1", "Create new address")])
else: else:
r, t = d.menu( r, t = d.menu("Do what with \""+addresses[addrcur][0]+"\" : \""+addresses[addrcur][2]+"\"?",
"Do what with \"" + addresses[addrcur][0] + "\" : \"" + addresses[addrcur][2] + "\"?", choices=[("1", "Create new address"),
choices=[
("1", "Create new address"),
("2", "Send a message from this address"), ("2", "Send a message from this address"),
("3", "Rename"), ("3", "Rename"),
("4", "Enable"), ("4", "Enable"),
@ -503,39 +416,29 @@ def handlech(c, stdscr):
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
if t == "1": # Create new address if t == "1": # Create new address
set_background_title(d, "Create new address") set_background_title(d, "Create new address")
scrollbox( scrollbox(d, unicode("Here you may generate as many addresses as you like.\n"
d, unicode(
"Here you may generate as many addresses as you like.\n"
"Indeed, creating and abandoning addresses is encouraged.\n" "Indeed, creating and abandoning addresses is encouraged.\n"
"Deterministic addresses have several pros and cons:\n" "Deterministic addresses have several pros and cons:\n"
"\nPros:\n" "\nPros:\n"
" * You can recreate your addresses on any computer from memory\n" " * You can recreate your addresses on any computer from memory\n"
" * You need not worry about backing up your keys.dat file as long as you" " * You need not worry about backing up your keys.dat file as long as you \n can remember your passphrase\n"
" \n can remember your passphrase\n"
"Cons:\n" "Cons:\n"
" * You must remember (or write down) your passphrase in order to recreate" " * You must remember (or write down) your passphrase in order to recreate \n your keys if they are lost\n"
" \n your keys if they are lost\n"
" * You must also remember the address version and stream numbers\n" " * You must also remember the address version and stream numbers\n"
" * If you choose a weak passphrase someone may be able to brute-force it" " * If you choose a weak passphrase someone may be able to brute-force it \n and then send and receive messages as you"))
" \n and then send and receive messages as you")) r, t = d.menu("Choose an address generation technique",
r, t = d.menu( choices=[("1", "Use a random number generator"),
"Choose an address generation technique",
choices=[
("1", "Use a random number generator"),
("2", "Use a passphrase")]) ("2", "Use a passphrase")])
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
if t == "1": if t == "1":
set_background_title(d, "Randomly generate address") set_background_title(d, "Randomly generate address")
r, t = d.inputbox("Label (not shown to anyone except you)") r, t = d.inputbox("Label (not shown to anyone except you)")
label = "" label = ""
if r == d.DIALOG_OK and t: if r == d.DIALOG_OK and len(t) > 0:
label = t label = t
r, t = d.menu( r, t = d.menu("Choose a stream",
"Choose a stream", choices=[("1", "Use the most available stream"),("", "(Best if this is the first of many addresses you will create)"),
choices=[("1", "Use the most available stream"), ("2", "Use the same stream as an existing address"),("", "(Saves you some bandwidth and processing power)")])
("", "(Best if this is the first of many addresses you will create)"),
("2", "Use the same stream as an existing address"),
("", "(Saves you some bandwidth and processing power)")])
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
if t == "1": if t == "1":
stream = 1 stream = 1
@ -547,61 +450,34 @@ def handlech(c, stdscr):
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
stream = decodeAddress(addrs[int(t)][1])[2] stream = decodeAddress(addrs[int(t)][1])[2]
shorten = False shorten = False
r, t = d.checklist( r, t = d.checklist("Miscellaneous options",
"Miscellaneous options", choices=[("1", "Spend time shortening the address", 1 if shorten else 0)])
choices=[(
"1",
"Spend time shortening the address",
1 if shorten else 0)])
if r == d.DIALOG_OK and "1" in t: if r == d.DIALOG_OK and "1" in t:
shorten = True shorten = True
queues.addressGeneratorQueue.put(( queues.addressGeneratorQueue.put(("createRandomAddress", 4, stream, label, 1, "", shorten))
"createRandomAddress",
4,
stream,
label,
1,
"",
shorten))
elif t == "2": elif t == "2":
set_background_title(d, "Make deterministic addresses") set_background_title(d, "Make deterministic addresses")
r, t = d.passwordform( r, t = d.passwordform("Enter passphrase",
"Enter passphrase", [("Passphrase", 1, 1, "", 2, 1, 64, 128),
[
("Passphrase", 1, 1, "", 2, 1, 64, 128),
("Confirm passphrase", 3, 1, "", 4, 1, 64, 128)], ("Confirm passphrase", 3, 1, "", 4, 1, 64, 128)],
form_height=4, insecure=True) form_height=4, insecure=True)
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
if t[0] == t[1]: if t[0] == t[1]:
passphrase = t[0] passphrase = t[0]
r, t = d.rangebox( r, t = d.rangebox("Number of addresses to generate",
"Number of addresses to generate", width=48, min=1, max=99, init=8)
width=48,
min=1,
max=99,
init=8)
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
number = t number = t
stream = 1 stream = 1
shorten = False shorten = False
r, t = d.checklist( r, t = d.checklist("Miscellaneous options",
"Miscellaneous options", choices=[("1", "Spend time shortening the address", 1 if shorten else 0)])
choices=[(
"1",
"Spend time shortening the address",
1 if shorten else 0)])
if r == d.DIALOG_OK and "1" in t: if r == d.DIALOG_OK and "1" in t:
shorten = True shorten = True
scrollbox( scrollbox(d, unicode("In addition to your passphrase, be sure to remember the following numbers:\n"
d, unicode(
"In addition to your passphrase, be sure to remember the"
" following numbers:\n"
"\n * Address version number: "+str(4)+"\n" "\n * Address version number: "+str(4)+"\n"
" * Stream number: "+str(stream))) " * Stream number: "+str(stream)))
queues.addressGeneratorQueue.put( queues.addressGeneratorQueue.put(('createDeterministicAddresses', 4, stream, "unused deterministic address", number, str(passphrase), shorten))
('createDeterministicAddresses', 4, stream,
"unused deterministic address", number,
str(passphrase), shorten))
else: else:
scrollbox(d, unicode("Passphrases do not match")) scrollbox(d, unicode("Passphrases do not match"))
elif t == "2": # Send a message elif t == "2": # Send a message
@ -651,23 +527,20 @@ def handlech(c, stdscr):
a = addresses[addrcur][2] a = addresses[addrcur][2]
set_background_title(d, "Special address behavior") set_background_title(d, "Special address behavior")
if BMConfigParser().safeGetBoolean(a, "chan"): if BMConfigParser().safeGetBoolean(a, "chan"):
scrollbox(d, unicode( scrollbox(d, unicode("This is a chan address. You cannot use it as a pseudo-mailing list."))
"This is a chan address. You cannot use it as a pseudo-mailing list."))
else: else:
m = BMConfigParser().safeGetBoolean(a, "mailinglist") m = BMConfigParser().safeGetBoolean(a, "mailinglist")
r, t = d.radiolist( r, t = d.radiolist("Select address behavior",
"Select address behavior", choices=[("1", "Behave as a normal address", not m),
choices=[
("1", "Behave as a normal address", not m),
("2", "Behave as a pseudo-mailing-list address", m)]) ("2", "Behave as a pseudo-mailing-list address", m)])
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
if t == "1" and m: if t == "1" and m == True:
BMConfigParser().set(a, "mailinglist", "false") BMConfigParser().set(a, "mailinglist", "false")
if addresses[addrcur][1]: if addresses[addrcur][1]:
addresses[addrcur][3] = 0 # Set color to black addresses[addrcur][3] = 0 # Set color to black
else: else:
addresses[addrcur][3] = 8 # Set color to gray addresses[addrcur][3] = 8 # Set color to gray
elif t == "2" and m is False: elif t == "2" and m == False:
try: try:
mn = BMConfigParser().get(a, "mailinglistname") mn = BMConfigParser().get(a, "mailinglistname")
except ConfigParser.NoOptionError: except ConfigParser.NoOptionError:
@ -683,15 +556,11 @@ def handlech(c, stdscr):
elif menutab == 5: elif menutab == 5:
set_background_title(d, "Subscriptions Dialog Box") set_background_title(d, "Subscriptions Dialog Box")
if len(subscriptions) <= subcur: if len(subscriptions) <= subcur:
r, t = d.menu( r, t = d.menu("Do what with subscription to \""+subscriptions[subcur][0]+"\"?",
"Do what with subscription to \"" + subscriptions[subcur][0] + "\"?", choices=[("1", "Add new subscription")])
choices=[
("1", "Add new subscription")])
else: else:
r, t = d.menu( r, t = d.menu("Do what with subscription to \""+subscriptions[subcur][0]+"\"?",
"Do what with subscription to \"" + subscriptions[subcur][0] + "\"?", choices=[("1", "Add new subscription"),
choices=[
("1", "Add new subscription"),
("2", "Delete this subscription"), ("2", "Delete this subscription"),
("3", "Enable"), ("3", "Enable"),
("4", "Disable")]) ("4", "Disable")])
@ -712,39 +581,27 @@ def handlech(c, stdscr):
sqlExecute("INSERT INTO subscriptions VALUES (?,?,?)", label, addr, True) sqlExecute("INSERT INTO subscriptions VALUES (?,?,?)", label, addr, True)
shared.reloadBroadcastSendersForWhichImWatching() shared.reloadBroadcastSendersForWhichImWatching()
elif t == "2": elif t == "2":
r, t = d.inputbox("Type in \"I want to delete this subscription\"") r, t = d.inpuxbox("Type in \"I want to delete this subscription\"")
if r == d.DIALOG_OK and t == "I want to delete this subscription": if r == d.DIALOG_OK and t == "I want to delete this subscription":
sqlExecute( sqlExecute("DELETE FROM subscriptions WHERE label=? AND address=?", subscriptions[subcur][0], subscriptions[subcur][1])
"DELETE FROM subscriptions WHERE label=? AND address=?",
subscriptions[subcur][0],
subscriptions[subcur][1])
shared.reloadBroadcastSendersForWhichImWatching() shared.reloadBroadcastSendersForWhichImWatching()
del subscriptions[subcur] del subscriptions[subcur]
elif t == "3": elif t == "3":
sqlExecute( sqlExecute("UPDATE subscriptions SET enabled=1 WHERE label=? AND address=?", subscriptions[subcur][0], subscriptions[subcur][1])
"UPDATE subscriptions SET enabled=1 WHERE label=? AND address=?",
subscriptions[subcur][0],
subscriptions[subcur][1])
shared.reloadBroadcastSendersForWhichImWatching() shared.reloadBroadcastSendersForWhichImWatching()
subscriptions[subcur][2] = True subscriptions[subcur][2] = True
elif t == "4": elif t == "4":
sqlExecute( sqlExecute("UPDATE subscriptions SET enabled=0 WHERE label=? AND address=?", subscriptions[subcur][0], subscriptions[subcur][1])
"UPDATE subscriptions SET enabled=0 WHERE label=? AND address=?",
subscriptions[subcur][0],
subscriptions[subcur][1])
shared.reloadBroadcastSendersForWhichImWatching() shared.reloadBroadcastSendersForWhichImWatching()
subscriptions[subcur][2] = False subscriptions[subcur][2] = False
elif menutab == 6: elif menutab == 6:
set_background_title(d, "Address Book Dialog Box") set_background_title(d, "Address Book Dialog Box")
if len(addrbook) <= abookcur: if len(addrbook) <= abookcur:
r, t = d.menu( r, t = d.menu("Do what with addressbook?",
"Do what with addressbook?",
choices=[("3", "Add new address to Address Book")]) choices=[("3", "Add new address to Address Book")])
else: else:
r, t = d.menu( r, t = d.menu("Do what with \""+addrbook[abookcur][0]+"\" : \""+addrbook[abookcur][1]+"\"",
"Do what with \"" + addrbook[abookcur][0] + "\" : \"" + addrbook[abookcur][1] + "\"", choices=[("1", "Send a message to this address"),
choices=[
("1", "Send a message to this address"),
("2", "Subscribe to this address"), ("2", "Subscribe to this address"),
("3", "Add new address to Address Book"), ("3", "Add new address to Address Book"),
("4", "Delete this address")]) ("4", "Delete this address")])
@ -779,39 +636,25 @@ def handlech(c, stdscr):
elif t == "4": elif t == "4":
r, t = d.inputbox("Type in \"I want to delete this Address Book entry\"") r, t = d.inputbox("Type in \"I want to delete this Address Book entry\"")
if r == d.DIALOG_OK and t == "I want to delete this Address Book entry": if r == d.DIALOG_OK and t == "I want to delete this Address Book entry":
sqlExecute( sqlExecute("DELETE FROM addressbook WHERE label=? AND address=?", addrbook[abookcur][0], addrbook[abookcur][1])
"DELETE FROM addressbook WHERE label=? AND address=?",
addrbook[abookcur][0],
addrbook[abookcur][1])
del addrbook[abookcur] del addrbook[abookcur]
elif menutab == 7: elif menutab == 7:
set_background_title(d, "Blacklist Dialog Box") set_background_title(d, "Blacklist Dialog Box")
r, t = d.menu( r, t = d.menu("Do what with \""+blacklist[blackcur][0]+"\" : \""+blacklist[blackcur][1]+"\"?",
"Do what with \"" + blacklist[blackcur][0] + "\" : \"" + blacklist[blackcur][1] + "\"?", choices=[("1", "Delete"),
choices=[
("1", "Delete"),
("2", "Enable"), ("2", "Enable"),
("3", "Disable")]) ("3", "Disable")])
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
if t == "1": if t == "1":
r, t = d.inputbox("Type in \"I want to delete this Blacklist entry\"") r, t = d.inputbox("Type in \"I want to delete this Blacklist entry\"")
if r == d.DIALOG_OK and t == "I want to delete this Blacklist entry": if r == d.DIALOG_OK and t == "I want to delete this Blacklist entry":
sqlExecute( sqlExecute("DELETE FROM blacklist WHERE label=? AND address=?", blacklist[blackcur][0], blacklist[blackcur][1])
"DELETE FROM blacklist WHERE label=? AND address=?",
blacklist[blackcur][0],
blacklist[blackcur][1])
del blacklist[blackcur] del blacklist[blackcur]
elif t == "2": elif t == "2":
sqlExecute( sqlExecute("UPDATE blacklist SET enabled=1 WHERE label=? AND address=?", blacklist[blackcur][0], blacklist[blackcur][1])
"UPDATE blacklist SET enabled=1 WHERE label=? AND address=?",
blacklist[blackcur][0],
blacklist[blackcur][1])
blacklist[blackcur][2] = True blacklist[blackcur][2] = True
elif t== "3": elif t== "3":
sqlExecute( sqlExecute("UPDATE blacklist SET enabled=0 WHERE label=? AND address=?", blacklist[blackcur][0], blacklist[blackcur][1])
"UPDATE blacklist SET enabled=0 WHERE label=? AND address=?",
blacklist[blackcur][0],
blacklist[blackcur][1])
blacklist[blackcur][2] = False blacklist[blackcur][2] = False
dialogreset(stdscr) dialogreset(stdscr)
else: else:
@ -868,30 +711,21 @@ def handlech(c, stdscr):
if menutab == 7: if menutab == 7:
blackcur = len(blackcur)-1 blackcur = len(blackcur)-1
redraw(stdscr) redraw(stdscr)
# pylint: disable=too-many-locals, too-many-arguments
def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=False): def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=False):
"""Method for message sending"""
if sender == "": if sender == "":
return return
d = Dialog(dialog="dialog") d = Dialog(dialog="dialog")
set_background_title(d, "Send a message") set_background_title(d, "Send a message")
if recv == "": if recv == "":
r, t = d.inputbox( r, t = d.inputbox("Recipient address (Cancel to load from the Address Book or leave blank to broadcast)", 10, 60)
"Recipient address (Cancel to load from the Address Book or leave blank to broadcast)",
10,
60)
if r != d.DIALOG_OK: if r != d.DIALOG_OK:
global menutab global menutab
menutab = 6 menutab = 6
return return
recv = t recv = t
if broadcast is None and sender != recv: if broadcast == None and sender != recv:
r, t = d.radiolist( r, t = d.radiolist("How to send the message?",
"How to send the message?", choices=[("1", "Send to one or more specific people", 1),
choices=[
("1", "Send to one or more specific people", 1),
("2", "Broadcast to everyone who is subscribed to your address", 0)]) ("2", "Broadcast to everyone who is subscribed to your address", 0)])
if r != d.DIALOG_OK: if r != d.DIALOG_OK:
return return
@ -912,12 +746,11 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
if not broadcast: if not broadcast:
recvlist = [] recvlist = []
for _, item in enumerate(recv.replace(",", ";").split(";")): for i, item in enumerate(recv.replace(",", ";").split(";")):
recvlist.append(item.strip()) recvlist.append(item.strip())
list(set(recvlist)) # Remove exact duplicates list(set(recvlist)) # Remove exact duplicates
for addr in recvlist: for addr in recvlist:
if addr != "": if addr != "":
# pylint: disable=redefined-outer-name
status, version, stream, ripe = decodeAddress(addr) status, version, stream, ripe = decodeAddress(addr)
if status != "success": if status != "success":
set_background_title(d, "Recipient address error") set_background_title(d, "Recipient address error")
@ -929,17 +762,13 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
elif status == "invalidcharacters": elif status == "invalidcharacters":
err += "The address contains invalid characters." err += "The address contains invalid characters."
elif status == "versiontoohigh": elif status == "versiontoohigh":
err += ("The address version is too high. Either you need to upgrade your Bitmessage software" err += "The address version is too high. Either you need to upgrade your Bitmessage software or your acquaintance is doing something clever."
" or your acquaintance is doing something clever.")
elif status == "ripetooshort": elif status == "ripetooshort":
err += ("Some data encoded in the address is too short. There might be something wrong with" err += "Some data encoded in the address is too short. There might be something wrong with the software of your acquaintance."
" the software of your acquaintance.")
elif status == "ripetoolong": elif status == "ripetoolong":
err += ("Some data encoded in the address is too long. There might be something wrong with" err += "Some data encoded in the address is too long. There might be something wrong with the software of your acquaintance."
" the software of your acquaintance.")
elif status == "varintmalformed": elif status == "varintmalformed":
err += ("Some data encoded in the address is malformed. There might be something wrong with" err += "Some data encoded in the address is malformed. There might be something wrong with the software of your acquaintance."
" the software of your acquaintance.")
else: else:
err += "It is unknown what is wrong with the address." err += "It is unknown what is wrong with the address."
scrollbox(d, unicode(err)) scrollbox(d, unicode(err))
@ -947,24 +776,17 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
addr = addBMIfNotPresent(addr) addr = addBMIfNotPresent(addr)
if version > 4 or version <= 1: if version > 4 or version <= 1:
set_background_title(d, "Recipient address error") set_background_title(d, "Recipient address error")
scrollbox(d, unicode( scrollbox(d, unicode("Could not understand version number " + version + "of address" + addr + "."))
"Could not understand version number " +
version +
"of address" +
addr +
"."))
continue continue
if stream > 1 or stream == 0: if stream > 1 or stream == 0:
set_background_title(d, "Recipient address error") set_background_title(d, "Recipient address error")
scrollbox(d, unicode( scrollbox(d, unicode("Bitmessage currently only supports stream numbers of 1, unlike as requested for address " + addr + "."))
"Bitmessage currently only supports stream numbers of 1,"
"unlike as requested for address " + addr + "."))
continue continue
if not network.stats.connectedHostsList(): if not network.stats.connectedHostsList():
set_background_title(d, "Not connected warning") set_background_title(d, "Not connected warning")
scrollbox(d, unicode("Because you are not currently connected to the network, ")) scrollbox(d, unicode("Because you are not currently connected to the network, "))
stealthLevel = BMConfigParser().safeGetInt('bitmessagesettings', 'ackstealthlevel') stealthLevel = BMConfigParser().safeGetInt('bitmessagesettings', 'ackstealthlevel')
ackdata = genAckPayload(decodeAddress(addr)[2], stealthLevel) ackdata = genAckPayload(streamNumber, stealthLevel)
sqlExecute( sqlExecute(
"INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", "INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
"", "",
@ -989,7 +811,7 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
scrollbox(d, unicode("You must specify an address to send the message from.")) scrollbox(d, unicode("You must specify an address to send the message from."))
else: else:
# dummy ackdata, no need for stealth # dummy ackdata, no need for stealth
ackdata = genAckPayload(decodeAddress(addr)[2], 0) ackdata = genAckPayload(streamNumber, 0)
recv = BROADCAST_STR recv = BROADCAST_STR
ripe = "" ripe = ""
sqlExecute( sqlExecute(
@ -1011,12 +833,9 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
BMConfigParser().getint('bitmessagesettings', 'ttl')) BMConfigParser().getint('bitmessagesettings', 'ttl'))
queues.workerQueue.put(('sendbroadcast', '')) queues.workerQueue.put(('sendbroadcast', ''))
# pylint: disable=redefined-outer-name, too-many-locals
def loadInbox(): def loadInbox():
"""Load the list of messages"""
sys.stdout = sys.__stdout__ sys.stdout = sys.__stdout__
print "Loading inbox messages..." print("Loading inbox messages...")
sys.stdout = printlog sys.stdout = printlog
where = "toaddress || fromaddress || subject || message" where = "toaddress || fromaddress || subject || message"
@ -1060,15 +879,12 @@ def loadInbox():
fromlabel = shared.fixPotentiallyInvalidUTF8Data(fromlabel) fromlabel = shared.fixPotentiallyInvalidUTF8Data(fromlabel)
# Load into array # Load into array
inbox.append([msgid, tolabel, toaddr, fromlabel, fromaddr, subject, l10n.formatTimestamp( inbox.append([msgid, tolabel, toaddr, fromlabel, fromaddr, subject,
received, False), read]) l10n.formatTimestamp(received, False), read])
inbox.reverse() inbox.reverse()
def loadSent(): def loadSent():
"""Load the messages that sent"""
sys.stdout = sys.__stdout__ sys.stdout = sys.__stdout__
print "Loading sent messages..." print("Loading sent messages...")
sys.stdout = printlog sys.stdout = printlog
where = "toaddress || fromaddress || subject || message" where = "toaddress || fromaddress || subject || message"
@ -1139,22 +955,12 @@ def loadSent():
statstr = "Unknown status "+status+" at "+t+"." statstr = "Unknown status "+status+" at "+t+"."
# Load into array # Load into array
sentbox.append([ sentbox.append([tolabel, toaddr, fromlabel, fromaddr, subject, statstr, ackdata,
tolabel,
toaddr,
fromlabel,
fromaddr,
subject,
statstr,
ackdata,
l10n.formatTimestamp(lastactiontime, False)]) l10n.formatTimestamp(lastactiontime, False)])
sentbox.reverse() sentbox.reverse()
def loadAddrBook(): def loadAddrBook():
"""Load address book"""
sys.stdout = sys.__stdout__ sys.stdout = sys.__stdout__
print "Loading address book..." print("Loading address book...")
sys.stdout = printlog sys.stdout = printlog
ret = sqlQuery("SELECT label, address FROM addressbook") ret = sqlQuery("SELECT label, address FROM addressbook")
@ -1163,19 +969,13 @@ def loadAddrBook():
label = shared.fixPotentiallyInvalidUTF8Data(label) label = shared.fixPotentiallyInvalidUTF8Data(label)
addrbook.append([label, addr]) addrbook.append([label, addr])
addrbook.reverse() addrbook.reverse()
def loadSubscriptions(): def loadSubscriptions():
"""Load subscription functionality"""
ret = sqlQuery("SELECT label, address, enabled FROM subscriptions") ret = sqlQuery("SELECT label, address, enabled FROM subscriptions")
for row in ret: for row in ret:
label, address, enabled = row label, address, enabled = row
subscriptions.append([label, address, enabled]) subscriptions.append([label, address, enabled])
subscriptions.reverse() subscriptions.reverse()
def loadBlackWhiteList(): def loadBlackWhiteList():
"""load black/white list"""
global bwtype global bwtype
bwtype = BMConfigParser().get("bitmessagesettings", "blackwhitelist") bwtype = BMConfigParser().get("bitmessagesettings", "blackwhitelist")
if bwtype == "black": if bwtype == "black":
@ -1187,12 +987,11 @@ def loadBlackWhiteList():
blacklist.append([label, address, enabled]) blacklist.append([label, address, enabled])
blacklist.reverse() blacklist.reverse()
def runwrapper(): def runwrapper():
"""Main method"""
sys.stdout = printlog sys.stdout = printlog
#sys.stderr = errlog #sys.stderr = errlog
# Load messages from database
loadInbox() loadInbox()
loadSent() loadSent()
loadAddrBook() loadAddrBook()
@ -1211,9 +1010,7 @@ def runwrapper():
curses.wrapper(run) curses.wrapper(run)
doShutdown() doShutdown()
def run(stdscr): def run(stdscr):
"""Main loop"""
# Schedule inventory lookup data # Schedule inventory lookup data
resetlookups() resetlookups()
@ -1253,17 +1050,16 @@ def run(stdscr):
stdscr.clear() stdscr.clear()
redraw(stdscr) redraw(stdscr)
while quit_ is False: while quit == False:
drawtab(stdscr) drawtab(stdscr)
handlech(stdscr.getch(), stdscr) handlech(stdscr.getch(), stdscr)
def doShutdown(): def doShutdown():
"""Shutting the app down"""
sys.stdout = sys.__stdout__ sys.stdout = sys.__stdout__
print "Shutting down..." print("Shutting down...")
sys.stdout = printlog sys.stdout = printlog
shutdown.doCleanShutdown() shutdown.doCleanShutdown()
sys.stdout = sys.__stdout__ sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__ sys.stderr = sys.__stderr__
os._exit(0) # pylint: disable=protected-access
os._exit(0)

View File

@ -1,50 +0,0 @@
from pythonforandroid.toolchain import Recipe, shprint, shutil, current_directory
from os.path import exists, join
import os
import sys
from multiprocessing import cpu_count
import sh
class BitmsghashRecipe(Recipe):
# This could also inherit from PythonRecipe etc. if you want to
# use their pre-written build processes
url = 'https://github.com/surbhicis/bitmsghash/archive/master.zip'
# {version} will be replaced with self.version when downloading
depends = ['openssl']
conflicts = []
def get_recipe_env(self, arch=None):
env = super(BitmsghashRecipe, self).get_recipe_env(arch)
r = Recipe.get_recipe('openssl', self.ctx)
b = r.get_build_dir(arch.arch)
env['CCFLAGS'] = env['CFLAGS'] = \
env['CFLAGS'] + ' -I{openssl_build_path}/include ' \
'-I{openssl_build_path}/include/openssl'.format(
openssl_build_path=b)
env['LDFLAGS'] = \
env['LDFLAGS'] + ' -L{openssl_build_path} ' \
'-lcrypto{openssl_version} ' \
'-lssl{openssl_version}'.format(
openssl_build_path=b,
openssl_version=r.version)
return env
def should_build(self, arch=None):
super(BitmsghashRecipe, self).should_build(arch)
return not exists(
join(self.ctx.get_libs_dir(arch.arch), 'libbitmsghash.so'))
def build_arch(self, arch=None):
super(BitmsghashRecipe, self).build_arch(arch)
env = self.get_recipe_env(arch)
with current_directory(join(self.get_build_dir(arch.arch))):
dst_dir = join(self.get_build_dir(arch.arch))
shprint(sh.make, '-j', str(cpu_count()), _env=env)
self.install_libs(arch, '{}/libbitmsghash.so'.format(dst_dir),
'libbitmsghash.so')
recipe = BitmsghashRecipe()

View File

@ -1,41 +0,0 @@
"""
src/bitmessagekivy/android/python-for-android/recipes/kivymd/__init__.py
=================================
"""
# pylint: disable=import-error
from os.path import join
from pythonforandroid.recipe import PythonRecipe
# from pythonforandroid.util import ensure_dir
class KivyMDRecipe(PythonRecipe):
"""This recipe installs KivyMD into the android dist from source"""
version = 'master'
url = 'https://github.com/surbhicis/kivymd/archive/master.zip'
depends = ['kivy']
site_packages_name = 'kivymd'
call_hostpython_via_targetpython = False
def should_build(self, arch): # pylint: disable=no-self-use, unused-argument
"""Method helps to build the application"""
return True
def get_recipe_env(self, arch):
"""Method is used for getting all the env paths"""
env = super(KivyMDRecipe, self).get_recipe_env(arch)
env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
env['CFLAGS'] += ' -I' + env['PYTHON_ROOT'] + '/include/python2.7'
env['LDFLAGS'] += ' -L' + env['PYTHON_ROOT'] + '/lib' + \
' -lpython2.7'
if 'sdl2' in self.ctx.recipe_build_order:
env['USE_SDL2'] = '1'
env['KIVY_SDL2_PATH'] = ':'.join([
join(self.ctx.bootstrap.build_dir, 'jni', 'SDL', 'include'),
join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_image'),
join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_mixer'),
join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_ttf'), ])
return env
recipe = KivyMDRecipe()

View File

@ -1,36 +0,0 @@
diff -Naurp KivyMD.orig/kivymd/button.py KivyMD/kivymd/button.py
--- KivyMD.orig/kivymd/button.py 2017-08-25 13:12:34.000000000 +0200
+++ KivyMD/kivymd/button.py 2018-07-10 10:37:55.719440354 +0200
@@ -175,7 +175,8 @@ class BaseButton(ThemableBehavior, Butto
self._current_button_color = self.md_bg_color_disabled
else:
self._current_button_color = self.md_bg_color
- super(BaseButton, self).on_disabled(instance, value)
+ # To add compatibility to last kivy (disabled is now an Alias property)
+ # super(BaseButton, self).on_disabled(instance, value)
class BasePressedButton(BaseButton):
diff -Naurp KivyMD.orig/kivymd/selectioncontrols.py KivyMD/kivymd/selectioncontrols.py
--- KivyMD.orig/kivymd/selectioncontrols.py 2017-08-25 13:12:34.000000000 +0200
+++ KivyMD/kivymd/selectioncontrols.py 2018-07-10 10:40:06.971439102 +0200
@@ -45,6 +45,7 @@ Builder.load_string('''
pos: self.pos
<MDSwitch>:
+ _thumb_pos: (self.right - dp(12), self.center_y - dp(12)) if self.active else (self.x - dp(12), self.center_y - dp(12))
canvas.before:
Color:
rgba: self._track_color_disabled if self.disabled else \
diff -Naurp KivyMD.orig/kivymd/tabs.py KivyMD/kivymd/tabs.py
--- KivyMD.orig/kivymd/tabs.py 2017-08-25 13:12:34.000000000 +0200
+++ KivyMD/kivymd/tabs.py 2018-07-10 10:39:20.603439544 +0200
@@ -185,7 +185,7 @@ class MDBottomNavigationBar(ThemableBeha
class MDTabHeader(MDFlatButton):
""" Internal widget for headers based on MDFlatButton"""
-
+
width = BoundedNumericProperty(dp(0), min=dp(72), max=dp(264), errorhandler=lambda x: dp(72))
tab = ObjectProperty(None)
panel = ObjectProperty(None)

View File

@ -1,93 +0,0 @@
"""
Core classes for loading images and converting them to a Texture.
The raw image data can be keep in memory for further access
"""
import hashlib
from io import BytesIO
from PIL import Image
from kivy.core.image import Image as CoreImage
from kivy.uix.image import Image as kiImage
# pylint: disable=import-error
# constants
RESOLUTION = 128, 128
V_RESOLUTION = 7, 7
BACKGROUND_COLOR = 255, 255, 255, 255
MODE = "RGB"
def generate(Generate_string=None):
"""Generating string"""
hash_string = generate_hash(Generate_string)
color = random_color(hash_string)
image = Image.new(MODE, V_RESOLUTION, BACKGROUND_COLOR)
image = generate_image(image, color, hash_string)
image = image.resize(RESOLUTION, 0)
data = BytesIO()
image.save(data, format='png')
data.seek(0)
# yes you actually need this
im = CoreImage(BytesIO(data.read()), ext='png')
beeld = kiImage()
# only use this line in first code instance
beeld.texture = im.texture
return beeld
# image.show()
def generate_hash(string):
"""Generating hash"""
try:
# make input case insensitive
string = str.lower(string)
hash_object = hashlib.md5(str.encode(string))
print hash_object.hexdigest()
# returned object is a hex string
return hash_object.hexdigest()
except IndexError:
print "Error: Please enter a string as an argument."
def random_color(hash_string):
"""Getting random color"""
# remove first three digits from hex string
split = 6
rgb = hash_string[:split]
split = 2
r = rgb[:split]
g = rgb[split:2 * split]
b = rgb[2 * split:3 * split]
color = (int(r, 16), int(g, 16),
int(b, 16), 0xFF)
return color
def generate_image(image, color, hash_string):
"""Generating images"""
hash_string = hash_string[6:]
lower_x = 1
lower_y = 1
upper_x = int(V_RESOLUTION[0] / 2) + 1
upper_y = V_RESOLUTION[1] - 1
limit_x = V_RESOLUTION[0] - 1
index = 0
for x in range(lower_x, upper_x):
for y in range(lower_y, upper_y):
if int(hash_string[index], 16) % 2 == 0:
image.putpixel((x, y), color)
image.putpixel((limit_x - x, y), color)
index = index + 1
return image

View File

@ -1,30 +1,19 @@
""" from helper_sql import *
Sql queries for bitmessagekivy
"""
from helper_sql import sqlQuery
def search_sql( def search_sql(xAddress="toaddress", account=None, folder="inbox", where=None, what=None, unreadOnly=False):
xAddress="toaddress", account=None, folder="inbox", where=None,
what=None, unreadOnly=False, start_indx=0, end_indx=20):
"""Method helping for searching mails"""
# pylint: disable=too-many-arguments, too-many-branches
if what is not None and what != "": if what is not None and what != "":
what = "%" + what + "%" what = "%" + what + "%"
else: else:
what = None what = None
if folder == "sent" or folder == "draft": if folder == "sent":
sqlStatementBase = ( sqlStatementBase = '''
'''SELECT toaddress, fromaddress, subject, message, status,''' SELECT toaddress, fromaddress, subject, status, ackdata, lastactiontime
''' ackdata, lastactiontime FROM sent ''') FROM sent '''
elif folder == "addressbook":
sqlStatementBase = '''SELECT label, address From addressbook '''
else: else:
sqlStatementBase = ( sqlStatementBase = '''SELECT folder, msgid, toaddress, fromaddress, subject, received, read
'''SELECT folder, msgid, toaddress, message, fromaddress,''' FROM inbox '''
''' subject, received, read FROM inbox ''')
sqlStatementParts = [] sqlStatementParts = []
sqlArguments = [] sqlArguments = []
if account is not None: if account is not None:
@ -35,7 +24,6 @@ def search_sql(
else: else:
sqlStatementParts.append(xAddress + " = ? ") sqlStatementParts.append(xAddress + " = ? ")
sqlArguments.append(account) sqlArguments.append(account)
if folder != "addressbook":
if folder is not None: if folder is not None:
if folder == "new": if folder == "new":
folder = "inbox" folder = "inbox"
@ -46,28 +34,12 @@ def search_sql(
sqlStatementParts.append("folder != ?") sqlStatementParts.append("folder != ?")
sqlArguments.append("trash") sqlArguments.append("trash")
if what is not None: if what is not None:
for colmns in where: sqlStatementParts.append("%s LIKE ?" % (where))
if len(where) > 1:
if where[0] == colmns:
filter_col = "(%s LIKE ?" % (colmns)
else:
filter_col += " or %s LIKE ? )" % (colmns)
else:
filter_col = "%s LIKE ?" % (colmns)
sqlArguments.append(what) sqlArguments.append(what)
sqlStatementParts.append(filter_col)
if unreadOnly: if unreadOnly:
sqlStatementParts.append("read = 0") sqlStatementParts.append("read = 0")
if sqlStatementParts: if len(sqlStatementParts) > 0:
sqlStatementBase += "WHERE " + " AND ".join(sqlStatementParts) sqlStatementBase += "WHERE " + " AND ".join(sqlStatementParts)
if folder == "sent" or folder == "draft": if folder == "sent":
sqlStatementBase += \ sqlStatementBase += " ORDER BY lastactiontime"
" ORDER BY lastactiontime DESC limit {0}, {1}".format(
start_indx, end_indx)
elif folder == "inbox":
sqlStatementBase += \
" ORDER BY received DESC limit {0}, {1}".format(
start_indx, end_indx)
# elif folder == "addressbook":
# sqlStatementBase += " limit {0}, {1}".format(start_indx, end_indx)
return sqlQuery(sqlStatementBase, sqlArguments) return sqlQuery(sqlStatementBase, sqlArguments)

View File

@ -1,1332 +1,354 @@
#:import la kivy.adapters.listadapter
#:import factory kivy.factory
#:import mpybit bitmessagekivy.mpybit
#:import C kivy.utils.get_color_from_hex
#:import Toolbar kivymd.toolbar.Toolbar <Navigator>:
#:import NavigationLayout kivymd.navigationdrawer.NavigationLayout
#:import NavigationDrawerDivider kivymd.navigationdrawer.NavigationDrawerDivider
#:import NavigationDrawerSubheader kivymd.navigationdrawer.NavigationDrawerSubheader
#:import MDCheckbox kivymd.selectioncontrols.MDCheckbox
#:import MDList kivymd.list.MDList
#:import OneLineListItem kivymd.list.OneLineListItem
#:import MDTextField kivymd.textfields.MDTextField
#:import get_color_from_hex kivy.utils.get_color_from_hex
#:import colors kivymd.color_definitions.colors
#:import MDTabbedPanel kivymd.tabs.MDTabbedPanel
#:import MDTab kivymd.tabs.MDTab
#:import MDFloatingActionButton kivymd.button.MDFloatingActionButton
#:import Factory kivy.factory.Factory
#:import MDScrollViewRefreshLayout kivymd.refreshlayout.MDScrollViewRefreshLayout
#:import MDSpinner kivymd.spinner.MDSpinner
#:import NoTransition kivy.uix.screenmanager.NoTransition
#:import MDSeparator kivymd.card.MDSeparator
#:set color_button (0.784, 0.443, 0.216, 1) # brown
#:set color_button_pressed (0.659, 0.522, 0.431, 1) # darker brown
#:set color_font (0.957, 0.890, 0.843, 1) # off white
<MyNavigationDrawerIconButton@NavigationDrawerIconButton>:
icon: 'checkbox-blank-circle'
<MySpinnerOption@SpinnerOption>:
font_size: '12.5sp'
background_color: color_button if self.state == 'down' else color_button_pressed
background_down: 'atlas://data/images/defaulttheme/button'
color: color_font
<ContentNavigationDrawer@Navigatorss>:
drawer_logo: './images/drawer_logo1.png'
NavigationDrawerDivider:
NavigationDrawerSubheader:
text: "Accounts"
NavigationDrawerIconButton:
CustomSpinner:
id: btn
pos_hint:{"x":0,"y":.0}
option_cls: Factory.get("MySpinnerOption")
font_size: '11.9sp'
text: app.getDefaultAccData()
background_color: color_button if self.state == 'normal' else color_button_pressed
background_down: 'atlas://data/images/defaulttheme/spinner'
color: color_font
values: app.variable_1
on_text:app.getCurrentAccountData(self.text)
Image:
source: app.get_default_image()
x: self.width/6
y: self.parent.y + self.parent.height/4
size: self.parent.height/2, self.parent.height/2
ArrowImg:
NavigationDrawerIconButton:
id: inbox_cnt
icon: 'email-open'
text: "Inbox"
on_release: app.root.ids.scr_mngr.current = 'inbox'
badge_text: "0"
on_press: app.load_screen(self)
NavigationDrawerIconButton:
id: send_cnt
icon: 'send'
text: "Sent"
on_release: app.root.ids.scr_mngr.current = 'sent'
badge_text: "0"
NavigationDrawerIconButton:
id: draft_cnt
icon: 'message-draw'
text: "Draft"
on_release: app.root.ids.scr_mngr.current = 'draft'
badge_text: "0"
#NavigationDrawerIconButton:
#text: "Starred"
#icon:'star'
#on_release: app.root.ids.scr_mngr.current = 'starred'
#badge_text: "0"
#NavigationDrawerIconButton:
#icon: 'archive'
#text: "Archieve"
#on_release: app.root.ids.scr_mngr.current = 'archieve'
#badge_text: "0"
#NavigationDrawerIconButton:
#icon: 'email-open-outline'
#text: "Spam"
#on_release: app.root.ids.scr_mngr.current = 'spam'
#badge_text: "0"
NavigationDrawerIconButton:
id: trash_cnt
icon: 'delete'
text: "Trash"
on_release: app.root.ids.scr_mngr.current = 'trash'
badge_text: "0"
NavigationDrawerIconButton:
id: allmail_cnt
text: "All Mails"
icon:'contact-mail'
on_release: app.root.ids.scr_mngr.current = 'allmails'
badge_text: "0"
on_press: app.load_screen(self)
NavigationDrawerDivider:
NavigationDrawerSubheader:
text: "All labels"
NavigationDrawerIconButton:
text: "Address Book"
icon:'book-multiple'
on_release: app.root.ids.scr_mngr.current = 'addressbook'
NavigationDrawerIconButton:
text: "Settings"
icon:'settings'
on_release: app.root.ids.scr_mngr.current = 'set'
NavigationDrawerIconButton:
text: "Subscriptions/Payment"
icon:'bell'
on_release: app.root.ids.scr_mngr.current = 'payment'
NavigationDrawerIconButton:
text: "Credits"
icon:'wallet'
on_release: app.root.ids.scr_mngr.current = 'credits'
NavigationDrawerIconButton:
text: "new address"
icon:'account-plus'
on_release: app.root.ids.scr_mngr.current = 'login'
NavigationDrawerIconButton:
text: "Network Status"
icon:'server-network'
on_release: app.root.ids.scr_mngr.current = 'networkstat'
NavigationDrawerIconButton:
text: "My Addresses"
icon:'account-multiple'
on_release: app.root.ids.scr_mngr.current = 'myaddress'
NavigationLayout:
id: nav_layout
ContentNavigationDrawer:
id: nav_drawer id: nav_drawer
NavigationDrawerIconButton:
Spinner:
pos_hint:{"x":0,"y":.3}
id: btn
background_color: app.theme_cls.primary_dark
text: app.showmeaddresses(name='text')
values: app.showmeaddresses(name='values')
on_text:app.getCurrentAccountData(self.text)
NavigationDrawerIconButton:
icon: 'email-open'
text: "inbox"
on_release: app.root.ids.scr_mngr.current = 'inbox'
NavigationDrawerIconButton:
icon: 'mail-send'
text: "sent"
on_release: app.root.ids.scr_mngr.current = 'sent'
NavigationDrawerIconButton:
icon: 'dropbox'
text: "trash"
on_release: app.root.ids.scr_mngr.current = 'trash'
NavigationDrawerIconButton:
icon: 'email'
text: "drafts"
on_release: app.root.ids.scr_mngr.current = 'dialog'
NavigationDrawerIconButton:
icon: 'markunread-mailbox'
text: "test"
on_release: app.root.ids.scr_mngr.current = 'test'
NavigationDrawerIconButton:
text: "new identity"
icon:'accounts-add'
on_release: app.root.ids.scr_mngr.current = 'newidentity'
FloatLayout:
id: float_box
BoxLayout: BoxLayout:
id: box_layout
orientation: 'vertical' orientation: 'vertical'
Toolbar: Toolbar:
id: toolbar id: toolbar
title: app.current_address_label() title: app.getCurrentAccount()
opacity: 1 if app.addressexist() else 0 background_color: app.theme_cls.primary_dark
disabled: False if app.addressexist() else True left_action_items: [['menu', lambda x: app.nav_drawer.toggle()]]
md_bg_color: app.theme_cls.primary_color Button:
background_palette: 'Primary' text:"EXIT"
background_hue: '500' color: 0,0,0,1
left_action_items: [['menu', lambda x: app.root.toggle_nav_drawer()]] background_color: (0,0,0,0)
right_action_items: [['account-plus', lambda x: app.addingtoaddressbook()]] size_hint_y: 0.4
size_hint_x: 0.1
pos_hint: {'x': 0.8, 'y':0.4}
on_press: app.say_exit()
ScreenManager: ScreenManager:
id: scr_mngr id: scr_mngr
Inbox: Inbox:
id:sc1 id:sc1
Page:
id:sc2
Create:
id:sc3
Sent: Sent:
id:sc4 id:sc2
Trash: Trash:
id:sc3
Dialog:
id:sc4
Test:
id:sc5 id:sc5
Login: Create:
id:sc6 id:sc6
Random: NewIdentity:
id:sc7 id:sc7
Spam: Page:
id:sc8 id:sc8
Setting: AddressSuccessful:
id:sc9 id:sc9
MyAddress:
id:sc10 Button:
AddressBook: id:create
id:sc11 height:100
Payment: size_hint_y: 0.13
id:sc12 size_hint_x: 0.1
NetworkStat: pos_hint: {'x': 0.85, 'y': 0.5}
id:sc13 background_color: (0,0,0,0)
MailDetail: on_press: scr_mngr.current = 'create'
id:sc14 Image:
ShowQRCode: source: 'images/plus.png'
id:sc15 y: self.parent.y - 7.5
Draft: x: self.parent.x + self.parent.width - 50
id:sc16 size: 70, 70
Allmails:
id:sc17 <SwipeButton@Carousel>:
Credits: text: ''
id:sc18 size_hint_y: None
Starred: height: 48
id:sc19 ignore_perpendicular_swipes: True
Archieve: data_index: 0
id:sc20 min_move: 20 / self.width
on__offset: app.update_index(root.data_index, self.index)
canvas.before:
Color:
rgba: C('FFFFFF33')
Rectangle:
pos: self.pos
size: self.size
Line:
rectangle: self.pos + self.size
Button:
text: 'delete ({}:{})'.format(root.text, root.data_index)
on_press: app.delete(root.data_index)
Button:
text: root.text
on_press: app.getInboxMessageDetail(self.text)
Button:
text: 'archive'
on_press: app.archive(root.data_index)
<Inbox>: <Inbox>:
name: 'inbox' name: 'inbox'
transition: NoTransition() RecycleView:
BoxLayout: data: root.data
viewclass: 'SwipeButton'
do_scroll_x: False
scroll_timeout: 100
RecycleBoxLayout:
id:rc
orientation: 'vertical' orientation: 'vertical'
spacing: dp(5)
SearchBar:
GridLayout:
id: identi_tag
padding: [20, 0, 0, 5]
cols: 1
size_hint_y: None size_hint_y: None
height: self.minimum_height height: self.minimum_height
MDLabel: default_size_hint: 1, None
text: '' canvas.before:
font_style: 'Body1' Color:
bold: True rgba: 0,0,0, 1
#FloatLayout: Rectangle:
# MDScrollViewRefreshLayout: pos: self.pos
# id: refresh_layout size: self.size
# refresh_callback: root.refresh_callback
# root_layout: root.set_root_layout()
# MDList:
# id: ml
BoxLayout:
orientation:'vertical'
ScrollView:
id: scroll_y
do_scroll_x: False
MDList:
id: ml
Loader:
ComposerButton:
<Sent>: <Sent>:
name: 'sent' name: 'sent'
BoxLayout: RecycleView:
data: root.data
viewclass: 'SwipeButton'
do_scroll_x: False
scroll_timeout: 100
RecycleBoxLayout:
id:rc
orientation: 'vertical' orientation: 'vertical'
spacing: dp(5)
SearchBar:
GridLayout:
id: identi_tag
padding: [20, 0, 0, 5]
cols: 1
size_hint_y: None size_hint_y: None
height: self.minimum_height height: self.minimum_height
MDLabel: default_size_hint: 1, None
text: '' canvas.before:
font_style: 'Body1' Color:
bold: True rgba: 0,0,0, 1
BoxLayout: Rectangle:
orientation:'vertical' pos: self.pos
ScrollView: size: self.size
id: scroll_y
do_scroll_x: False
MDList:
id: ml
Loader:
ComposerButton:
<Trash>: <Trash>:
name: 'trash' name: 'trash'
BoxLayout: RecycleView:
data: root.data
viewclass: 'SwipeButton'
do_scroll_x: False
scroll_timeout: 100
RecycleBoxLayout:
id:rc
orientation: 'vertical' orientation: 'vertical'
spacing: dp(5)
GridLayout:
id: identi_tag
padding: [20, 20, 0, 5]
spacing: dp(5)
cols: 1
size_hint_y: None size_hint_y: None
height: self.minimum_height height: self.minimum_height
MDLabel: default_size_hint: 1, None
text: '' canvas.before:
font_style: 'Body1' Color:
bold: True rgba: 0,0,0, 1
BoxLayout: Rectangle:
orientation:'vertical' pos: self.pos
ScrollView: size: self.size
id: scroll_y
do_scroll_x: False
MDList:
id: ml
Loader:
ComposerButton:
<Draft>:
name: 'draft'
BoxLayout:
orientation: 'vertical'
spacing: dp(5)
GridLayout:
id: identi_tag
padding: [20, 20, 0, 5]
cols: 1
size_hint_y: None
height: self.minimum_height
MDLabel:
text: ''
font_style: 'Body1'
bold: True
BoxLayout:
orientation:'vertical'
ScrollView:
id: scroll_y
do_scroll_x: False
MDList:
id: ml
ComposerButton:
<Starred>:
name: 'starred'
ScrollView:
do_scroll_x: False
MDList:
id: ml
ComposerButton:
<Archieve>:
name: 'archieve'
ScrollView:
do_scroll_x: False
MDList:
id: ml
ComposerButton:
<Spam>:
name: 'spam'
ScrollView:
do_scroll_x: False
MDList:
id: ml
ComposerButton:
<Allmails>:
name: 'allmails'
#FloatLayout:
# MDScrollViewRefreshLayout:
# id: refresh_layout
# refresh_callback: root.refresh_callback
# root_layout: root.set_root_layout()
# MDList:
# id: ml
BoxLayout:
orientation: 'vertical'
spacing: dp(5)
GridLayout:
id: identi_tag
padding: [20, 20, 0, 5]
spacing: dp(5)
cols: 1
size_hint_y: None
height: self.minimum_height
MDLabel:
text: ''
font_style: 'Body1'
bold: True
BoxLayout:
orientation:'vertical'
ScrollView:
id: scroll_y
do_scroll_x: False
MDList:
id: ml
Loader:
ComposerButton:
<Dialog>:
name: 'dialog'
Label:
text:"I have a good dialox box"
color: 0,0,0,1
<Test>: <Test>:
name: 'test' name: 'test'
Label: Label:
text:"I am in test" text:"I am in test"
color: 0,0,0,1 color: 0,0,0,1
<Create>:
name: 'create'
GridLayout:
rows: 5
cols: 1
padding: 60,60,60,60
spacing: 50
BoxLayout:
size_hint_y: None
height: '32dp'
Label:
text: 'FROM'
color: 0,0,0,1
Spinner:
size_hint: 1,1
pos_hint: {"x":0,"top":1.}
pos: 10,10
id: spinner_id
text: app.showmeaddresses(name='text')
values: app.showmeaddresses(name='values')
BoxLayout:
size_hint_y: None
height: '32dp'
Label:
text: 'TO'
color: 0,0,0,1
TextInput:
id: recipent
hint_text: 'To'
BoxLayout:
size_hint_y: None
height: '32dp'
Label:
text: 'SUBJECT'
color: 0,0,0,1
TextInput:
id: subject
hint_text: 'SUBJECT'
BoxLayout:
size_hint_y: None
height: '32dp'
Label:
text: 'BODY'
color: 0,0,0,1
TextInput:
id: message
multiline:True
size_hint: 1,2
Button:
text: 'send'
size_hint_y: 0.1
size_hint_x: 0.2
height: '32dp'
pos_hint: {'x': .5, 'y': 0.1}
on_press: root.send()
Button:
text: 'cancel'
size_hint_y: 0.1
size_hint_x: 0.2
height: '32dp'
pos_hint: {'x': .72, 'y': 0.1}
on_press: root.cancel()
<NewIdentity>:
name: 'newidentity'
GridLayout:
padding: '120dp'
cols: 1
Label:
text:"""Here you may generate as many addresses as you like. Indeed, creating and abandoning addresses is encouraged."""
line_height:1.5
text_size:(700,None)
color: 0,0,0,1
BoxLayout:
CheckBox:
canvas.before:
Color:
rgb: 1,0,0
Ellipse:
pos:self.center_x-8, self.center_y-8
size:[16,16]
group: "money"
id:chk
text:"use a random number generator to make an address"
on_active:
root.checked = self.text
active:root.is_active
Label:
text: "use a random number generator to make an address"
color: 0,0,0,1
BoxLayout:
CheckBox:
canvas.before:
Color:
rgb: 1,0,0
Ellipse:
pos:self.center_x-8, self.center_y-8
size:[16,16]
group: "money"
id:chk
text:"use a pseudo number generator to make an address"
on_active:
root.checked = self.text
active:not root.is_active
Label:
text: "use a pseudo number generator to make an address"
color: 0,0,0,1
Label:
color: 0,0,0,1
size_hint_x: .35
markup: True
text: "[b]{}[/b]".format("Randomly generated addresses")
BoxLayout:
size_hint_y: None
height: '32dp'
Label:
text: "Label (not shown to anyone except you)"
color: 0,0,0,1
BoxLayout:
size_hint_y: None
height: '32dp'
TextInput:
id: label
Button:
text: 'Cancel'
size_hint_y: 0.1
size_hint_x: 0.3
height: '32dp'
pos_hint: {'x': .1, 'y': 0.1}
Button:
text: 'Ok'
size_hint_y: 0.1
size_hint_x: 0.3
height: '32dp'
pos_hint: {'x': .5, 'y': 0.1}
on_press: root.generateaddress()
<Page>: <Page>:
name: 'page' name: 'page'
Label: Label:
text:"I am on page" text: 'I am on description of my email yooooo'
color: 0,0,0,1 color: 0,0,0,1
<Create>: <AddressSuccessful>:
name: 'create' name: 'add_sucess'
Loader: Label:
text: 'Successfully created a new bit address'
<Credits>:
name: 'credits'
ScrollView:
do_scroll_x: False
MDList:
id: ml
size_hint_y: None
height: dp(200)
OneLineListItem:
text: "Available Credits"
BoxLayout:
AnchorLayout:
MDRaisedButton:
size_hint: .6, .35
height: dp(40)
MDLabel:
font_style: 'Title'
text: root.available_credits
font_size: '13sp'
color: (1,1,1,1)
halign: 'center'
<DropDownWidget>:
ScrollView:
BoxLayout:
orientation: 'vertical'
size_hint_y: None
height: self.minimum_height + 2 * self.parent.height/4
padding: dp(32)
spacing: 15
BoxLayout:
orientation: 'vertical'
MDTextField:
id: ti
hint_text: 'type or select sender address'
size_hint_y: None
height: 100
font_size: '13sp'
multiline: False
required: True
helper_text_mode: "on_error"
BoxLayout:
size_hint_y: None
height: dp(40)
CustomSpinner:
background_color: app.theme_cls.primary_dark
id: btn
values: app.variable_1
on_text: root.auto_fill_fromaddr() if self.text != 'Select' else ''
option_cls: Factory.get("MySpinnerOption")
background_color: color_button if self.state == 'normal' else color_button_pressed
background_down: 'atlas://data/images/defaulttheme/spinner'
color: color_font
font_size: '12.5sp'
ArrowImg:
BoxLayout:
orientation: 'vertical'
txt_input: txt_input
rv: rv
size : (890, 60)
size_hint: 1,1
MyTextInput:
id: txt_input
size_hint_y: None
font_size: '13sp'
height: self.parent.height/2
#hint_text: 'type or search recipients address starting with BM-'
hint_text: 'type, select or scan QR code for recipients address'
RV:
id: rv
MDTextField:
id: subject
hint_text: 'subject'
required: True
height: 100
font_size: '13sp'
size_hint_y: None
multiline: False
helper_text_mode: "on_error"
MDTextField:
id: body
multiline: True
hint_text: 'body'
size_hint_y: None
font_size: '13sp'
required: True
helper_text_mode: "on_error"
BoxLayout:
spacing:50
<MyTextInput>:
readonly: False
multiline: False
<SelectableLabel>:
# Draw a background to indicate selection
color: 0,0,0,1 color: 0,0,0,1
canvas.before:
Color:
rgba: app.theme_cls.primary_dark if self.selected else (1, 1, 1, 0)
Rectangle:
pos: self.pos
size: self.size
<RV>:
canvas:
Color:
rgba: 0,0,0,.2
Line:
rectangle: self.x +1 , self.y, self.width - 2, self.height -2
bar_width: 10
scroll_type:['bars']
viewclass: 'SelectableLabel'
SelectableRecycleBoxLayout:
default_size: None, dp(20)
default_size_hint: 1, None
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'
multiselect: False
<Login>:
name: 'login'
ScrollView:
do_scroll_x: False
BoxLayout:
orientation: 'vertical'
size_hint_y: None
height: dp(750)
padding: dp(10)
BoxLayout:
MDLabel:
font_style: 'Body1'
theme_text_color: 'Primary'
text: "You may generate addresses by using either random numbers or by using a passphrase If you use a passphrase, the address is called a deterministic; address The Random Number option is selected by default but deterministic addresses have several \n pros and cons:\n"
halign: 'center'
bold: True
color:app.theme_cls.primary_dark
BoxLayout:
MDLabel:
font_style: 'Caption'
theme_text_color: 'Primary'
text: "If talk about pros You can recreate your addresses on any computer from memory, You need-not worry about backing up your keys.dat file as long as you can remember your passphrase and aside talk about cons You must remember (or write down) your You must remember the address version number and the stream number along with your passphrase If you choose a weak passphrase and someone on the Internet can brute-force it, they can read your messages and send messages as you"
halign: 'center'
bold: True
color:app.theme_cls.primary_dark
MDCheckbox:
id: grp_chkbox_1
group: 'test'
active: True
allow_no_selection: False
MDLabel:
font_style: 'Caption'
theme_text_color: 'Primary'
text: "use a random number generator to make an address"
halign: 'center'
size_hint_y: None
bold: True
height: self.texture_size[1] + dp(4)
color: [0.941, 0, 0,1]
MDCheckbox:
id: grp_chkbox_1
group: 'test'
allow_no_selection: False
MDLabel:
font_style: 'Caption'
theme_text_color: 'Primary'
text: "use a pseudo number generator to make an address"
halign: 'center'
size_hint_y: None
bold: True
color: [0.941, 0, 0,1]
height: self.texture_size[1] + dp(4)
BoxLayout:
AnchorLayout:
MDRaisedButton:
height: dp(40)
on_press: app.root.ids.scr_mngr.current = 'random'
on_press: app.root.ids.sc7.reset_address_label()
MDLabel:
font_style: 'Title'
text: 'proceed'
font_size: '13sp'
color: (1,1,1,1)
halign: 'center'
<Random>:
name: 'random'
ScrollView:
BoxLayout:
orientation: 'vertical'
size_hint_y: None
height: self.minimum_height
padding: dp(20)
spacing: 100
MDLabel:
font_style: 'Body1'
theme_text_color: 'Primary'
text: "Random Addresses"
halign: 'center'
bold: True
color:app.theme_cls.primary_dark
MDLabel:
font_style: 'Body1'
theme_text_color: 'Primary'
text: "Here you may generate as many addresses as you like, Indeed creating and abandoning addresses is encouraged"
halign: 'center'
bold: True
color:app.theme_cls.primary_dark
MDTextField:
id: label
multiline: True
hint_text: "Label"
required: True
helper_text_mode: "on_error"
on_text: root.add_validation(self)
BoxLayout:
AnchorLayout:
MDRaisedButton:
height: dp(40)
on_release: root.generateaddress(app)
opposite_colors: True
MDLabel:
font_style: 'Title'
text: 'next'
font_size: '13sp'
color: (1,1,1,1)
halign: 'center'
<Setting>:
name: 'set'
ScrollView:
do_scroll_x: False
MDList:
id: ml
size_hint_y: None
height: dp(500)
OneLineListItem:
text: "SERVER SETTINGS"
BoxLayout:
AnchorLayout:
MDRaisedButton:
size_hint: .6, .55
height: dp(40)
MDLabel:
font_style: 'Title'
text: 'Server'
font_size: '13sp'
color: (1,1,1,1)
halign: 'center'
OneLineListItem:
text: "DATA SETTINGS"
BoxLayout:
AnchorLayout:
MDRaisedButton:
size_hint: .6, .55
height: dp(40)
MDLabel:
font_style: 'Title'
text: 'Import or export data'
font_size: '13sp'
color: (1,1,1,1)
halign: 'center'
OneLineListItem:
text: "OTHER SETTINGS"
BoxLayout:
AnchorLayout:
MDRaisedButton:
size_hint: .6, .55
height: dp(40)
MDLabel:
font_style: 'Title'
text: 'Restart background service'
font_size: '13sp'
color: (1,1,1,1)
halign: 'center'
BoxLayout:
AnchorLayout:
MDLabel:
font_style: 'Body1'
theme_text_color: 'Primary'
text: "bitmessage is 11 seconds behind the network"
halign: 'center'
bold: True
color: [0.941, 0, 0,1]
BoxLayout:
MDCheckbox:
id: chkbox
size_hint: None, None
size: dp(48), dp(64)
active: True
MDLabel:
font_style: 'Body1'
theme_text_color: 'Primary'
text: "show settings (for advanced users only)"
halign: 'left'
bold: True
color: app.theme_cls.primary_dark
<MyAddress>:
name: 'myaddress'
BoxLayout:
orientation: 'vertical'
spacing: dp(5)
SearchBar:
GridLayout:
id: identi_tag
padding: [20, 0, 0, 5]
cols: 1
size_hint_y: None
height: self.minimum_height
MDLabel:
text: 'My Addresses'
font_style: 'Body1'
bold: True
FloatLayout:
MDScrollViewRefreshLayout:
id: refresh_layout
refresh_callback: root.refresh_callback
root_layout: root.set_root_layout()
MDList:
id: ml
Loader:
ComposerButton:
<AddressBook>:
name: 'addressbook'
BoxLayout:
orientation: 'vertical'
spacing: dp(5)
SearchBar:
GridLayout:
id: identi_tag
padding: [20, 0, 0, 5]
cols: 1
size_hint_y: None
height: self.minimum_height
MDLabel:
text: ''
font_style: 'Body1'
bold: True
BoxLayout:
orientation:'vertical'
ScrollView:
id: scroll_y
do_scroll_x: False
MDList:
id: ml
Loader:
ComposerButton:
<Payment>:
name: 'payment'
ScrollView:
do_scroll_x: False
BoxLayout:
orientation: 'vertical'
padding: [dp(app.window_size[0]/16 if app.window_size[0] <= 720 else app.window_size[0]/6 if app.window_size[0] <= 800 else app.window_size[0]/18), dp(10)]
spacing: 12
size_hint_y: None
height: self.minimum_height + dp(app.window_size[1]) if app.window_size[1] > app.window_size[0] else dp(app.window_size[0])
BoxLayout:
orientation: 'vertical'
padding: dp(5)
canvas.before:
Color:
rgba: app.theme_cls.primary_dark
Rectangle:
# self here refers to the widget i.e FloatLayout
pos: self.pos
size: self.size
MDLabel:
size_hint_y: None
font_style: 'Headline'
theme_text_color: 'Primary'
text: 'Platinum'
halign: 'center'
color: 1,1,1,1
MDLabel:
font_style: 'Subhead'
theme_text_color: 'Primary'
text: 'We provide subscriptions for proof of work calculation for first month. '
halign: 'center'
color: 1,1,1,1
MDLabel:
id: free_pak
font_style: 'Headline'
theme_text_color: 'Primary'
text: '€ 50.0'
halign: 'center'
color: 1,1,1,1
MDRaisedButton:
canvas:
Color:
rgb: (0.93, 0.93, 0.93)
Rectangle:
pos: self.pos
size: self.size
size_hint: 1, None
height: dp(40)
on_press: root.get_available_credits(self)
MDLabel:
font_style: 'Title'
text: 'Get Free Credits'
font_size: '13sp'
color: (0,0,0,1)
halign: 'center'
BoxLayout:
orientation: 'vertical'
padding: dp(5)
canvas.before:
Color:
rgba: app.theme_cls.primary_dark
Rectangle:
# self here refers to the widget i.e FloatLayout
pos: self.pos
size: self.size
MDLabel:
size_hint_y: None
font_style: 'Headline'
theme_text_color: 'Primary'
text: 'Silver'
halign: 'center'
color: 1,1,1,1
MDLabel:
font_style: 'Subhead'
theme_text_color: 'Primary'
text: 'We provide for proof of work calculation for six month. '
halign: 'center'
color: 1,1,1,1
MDLabel:
font_style: 'Headline'
theme_text_color: 'Primary'
text: '€ 100.0'
halign: 'center'
color: 1,1,1,1
MDRaisedButton:
canvas:
Color:
rgb: (0.93, 0.93, 0.93)
Rectangle:
pos: self.pos
size: self.size
size_hint: 1, None
height: dp(40)
MDLabel:
font_style: 'Title'
text: 'Get Monthly Credits'
font_size: '13sp'
color: (0,0,0,1)
halign: 'center'
BoxLayout:
orientation: 'vertical'
padding: dp(5)
canvas.before:
Color:
rgba: app.theme_cls.primary_dark
Rectangle:
# self here refers to the widget i.e FloatLayout
pos: self.pos
size: self.size
MDLabel:
size_hint_y: None
font_style: 'Headline'
theme_text_color: 'Primary'
text: 'Gold'
halign: 'center'
color: 1,1,1,1
MDLabel:
font_style: 'Subhead'
theme_text_color: 'Primary'
text: 'We provide for proof of work calculation for 1years. '
halign: 'center'
color: 1,1,1,1
MDLabel:
font_style: 'Headline'
theme_text_color: 'Primary'
text: '€ 500.0'
halign: 'center'
color: 1,1,1,1
MDRaisedButton:
canvas:
Color:
rgb: (0.93, 0.93, 0.93)
Rectangle:
pos: self.pos
size: self.size
size_hint: 1, None
height: dp(40)
MDLabel:
font_style: 'Title'
text: 'Get Yearly Credits'
font_size: '13sp'
color: (0,0,0,1)
halign: 'center'
<GrashofPopup>:
id: popup
size_hint : (None,None)
height: 2*(label.height + address.height) + 10
width :app.window_size[0] - (app.window_size[0]/10 if app.app_platform == 'android' else app.window_size[0]/4)
title: 'add contact\'s'
background: './images/popup.jpeg'
title_size: sp(20)
title_color: 0.4, 0.3765, 0.3451, 1
auto_dismiss: False
separator_color: 0.3529, 0.3922, 0.102, 0.7
BoxLayout:
size_hint_y: 0.5
orientation: 'vertical'
spacing:dp(20)
id: popup_box
BoxLayout:
orientation: 'vertical'
MDTextField:
id: label
multiline: False
hint_text: "Label"
required: True
helper_text_mode: "on_error"
on_text: root.checkLabel_valid(self)
MDTextField:
id: address
hint_text: "Address"
required: True
helper_text_mode: "on_error"
on_text: root.checkAddress_valid(self)
BoxLayout:
spacing:5
orientation: 'horizontal'
MDRaisedButton:
id: save_addr
size_hint: 1.5, None
height: dp(40)
on_release:
root.savecontact()
MDLabel:
font_style: 'Title'
text: 'Save'
font_size: '13sp'
color: (1,1,1,1)
halign: 'center'
MDRaisedButton:
size_hint: 1.5, None
height: dp(40)
on_press: root.dismiss()
on_press: root.close_pop()
MDLabel:
font_style: 'Title'
text: 'Cancel'
font_size: '13sp'
color: (1,1,1,1)
halign: 'center'
MDRaisedButton:
size_hint: 2, None
height: dp(40)
MDLabel:
font_style: 'Title'
text: 'Scan QR code'
font_size: '13sp'
color: (1,1,1,1)
halign: 'center'
<NetworkStat>:
name: 'networkstat'
MDTabbedPanel:
id: tab_panel
tab_display_mode:'text'
MDTab:
name: 'connections'
text: "Total connections"
ScrollView:
do_scroll_x: False
MDList:
id: ml
size_hint_y: None
height: dp(200)
OneLineListItem:
text: "Total Connections"
BoxLayout:
AnchorLayout:
MDRaisedButton:
size_hint: .6, .35
height: dp(40)
MDLabel:
font_style: 'Title'
text: root.text_variable_1
font_size: '13sp'
color: (1,1,1,1)
halign: 'center'
MDTab:
name: 'processes'
text: 'Processes'
ScrollView:
do_scroll_x: False
MDList:
id: ml
size_hint_y: None
height: dp(500)
OneLineListItem:
text: "person-to-person"
BoxLayout:
AnchorLayout:
MDRaisedButton:
size_hint: .7, .6
height: dp(40)
MDLabel:
font_style: 'Title'
text: root.text_variable_2
font_size: '13sp'
color: (1,1,1,1)
halign: 'center'
OneLineListItem:
text: "Brodcast"
BoxLayout:
AnchorLayout:
MDRaisedButton:
size_hint: .7, .6
height: dp(40)
MDLabel:
font_style: 'Title'
text: root.text_variable_3
font_size: '13sp'
color: (1,1,1,1)
halign: 'center'
OneLineListItem:
text: "publickeys"
BoxLayout:
AnchorLayout:
MDRaisedButton:
size_hint: .7, .6
height: dp(40)
MDLabel:
font_style: 'Title'
text: root.text_variable_4
font_size: '13sp'
color: (1,1,1,1)
halign: 'center'
OneLineListItem:
text: "objects"
BoxLayout:
AnchorLayout:
MDRaisedButton:
size_hint: .7, .6
height: dp(40)
MDLabel:
font_style: 'Title'
text: root.text_variable_5
font_size: '13sp'
color: (1,1,1,1)
halign: 'center'
<MailDetail>:
name: 'mailDetail'
ScrollView:
do_scroll_x: False
BoxLayout:
orientation: 'vertical'
size_hint_y: None
height: dp(500) + self.minimum_height
padding: dp(32)
MDLabel:
font_style: 'Headline'
theme_text_color: 'Primary'
text: root.subject
halign: 'left'
font_size: '20sp'
CopyTextBtn:
MDLabel:
font_style: 'Subhead'
theme_text_color: 'Primary'
text: "From: " + root.from_addr
halign: 'left'
CopyTextBtn:
MDLabel:
font_style: 'Subhead'
theme_text_color: 'Primary'
text: "To: " + root.to_addr
halign: 'left'
CopyTextBtn:
MDLabel:
font_style: 'Subhead'
theme_text_color: 'Primary'
text: root.status
halign: 'left'
MDLabel:
font_style: 'Subhead'
theme_text_color: 'Primary'
text: root.message
halign: 'left'
bold: True
CopyTextBtn:
BoxLayout:
orientation: 'vertical'
size_hint_y: None
height: dp(100) + self.minimum_height
Loader:
<CopyTextBtn@Button>:
id: cpyButton
color: 0,0,0,1
background_color: (0,0,0,0)
center_x: self.parent.center_x * 2 - self.parent.parent.padding[0]/2
center_y: self.parent.center_y
on_press:app.root.ids.sc14.copy_composer_text(self)
Image:
source: './images/copy_text.png'
center_x: self.parent.center_x
center_y: self.parent.center_y
size: 20, 20
<ComposerButton@BoxLayout>:
size_hint_y: None
height: dp(56)
spacing: '10dp'
pos_hint: {'center_x':0.45, 'center_y': .1}
Widget:
MDFloatingActionButton:
icon: 'plus'
opposite_colors: True
elevation_normal: 8
md_bg_color: [0.941, 0, 0,1]
on_press: app.root.ids.scr_mngr.current = 'create'
on_press: app.clear_composer()
<MyaddDetailPopup>:
id: myadd_popup
size_hint : (None,None)
height: 4.5*(myaddr_label.height+ my_add_btn.children[0].height)
width :app.window_size[0] - (app.window_size[0]/10 if app.app_platform == 'android' else app.window_size[0]/4)
background: './images/popup.jpeg'
auto_dismiss: False
separator_height: 0
BoxLayout:
id: myadd_popup_box
size_hint_y: None
spacing:dp(70)
orientation: 'vertical'
BoxLayout:
size_hint_y: None
orientation: 'vertical'
spacing:dp(25)
MDLabel:
id: myaddr_label
font_style: 'Title'
theme_text_color: 'Primary'
text: "Label"
font_size: '17sp'
halign: 'left'
MDLabel:
font_style: 'Subhead'
theme_text_color: 'Primary'
text: root.address_label
font_size: '15sp'
halign: 'left'
MDLabel:
font_style: 'Title'
theme_text_color: 'Primary'
text: "Address"
font_size: '17sp'
halign: 'left'
MDLabel:
font_style: 'Subhead'
theme_text_color: 'Primary'
text: root.address
font_size: '15sp'
halign: 'left'
BoxLayout:
id: my_add_btn
spacing:5
orientation: 'horizontal'
MDRaisedButton:
size_hint: 2, None
height: dp(40)
on_press: root.send_message_from()
MDLabel:
font_style: 'Title'
text: 'Send message from'
font_size: '13sp'
color: (1,1,1,1)
halign: 'center'
MDRaisedButton:
size_hint: 1.5, None
height: dp(40)
on_press: root.dismiss()
on_press: app.root.ids.scr_mngr.current = 'showqrcode'
on_press: app.root.ids.sc15.qrdisplay()
MDLabel:
font_style: 'Title'
text: 'Show QR code'
font_size: '13sp'
color: (1,1,1,1)
halign: 'center'
MDRaisedButton:
size_hint: 1.5, None
height: dp(40)
on_press: root.dismiss()
on_press: root.close_pop()
MDLabel:
font_style: 'Title'
text: 'Cancel'
font_size: '13sp'
color: (1,1,1,1)
halign: 'center'
<AddbookDetailPopup>:
id: addbook_popup
size_hint : (None,None)
height: 4*(add_label.height)
width :app.window_size[0] - (app.window_size[0]/10 if app.app_platform == 'android' else app.window_size[0]/4)
background: './images/popup.jpeg'
separator_height: 0
auto_dismiss: False
BoxLayout:
size_hint_y: None
spacing:dp(70)
id: addbook_popup_box
orientation: 'vertical'
BoxLayout:
size_hint_y: None
orientation: 'vertical'
spacing:dp(20)
MDLabel:
font_style: 'Title'
theme_text_color: 'Primary'
text: "Label"
font_size: '17sp'
halign: 'left'
MDTextField:
id: add_label
font_style: 'Subhead'
font_size: '15sp'
halign: 'left'
text: root.address_label
theme_text_color: 'Primary'
required: True
helper_text_mode: "on_error"
on_text: root.checkLabel_valid(self)
MDLabel:
font_style: 'Title'
theme_text_color: 'Primary'
text: "Address"
font_size: '17sp'
halign: 'left'
MDLabel:
id: address
font_style: 'Subhead'
theme_text_color: 'Primary'
text: root.address
font_size: '15sp'
halign: 'left'
BoxLayout:
id: addbook_btn
spacing:5
orientation: 'horizontal'
MDRaisedButton:
size_hint: 2, None
height: dp(40)
on_press: root.send_message_to()
MDLabel:
font_style: 'Title'
text: 'Send message to'
font_size: '13sp'
color: (1,1,1,1)
halign: 'center'
MDRaisedButton:
size_hint: 1.5, None
height: dp(40)
font_size: '10sp'
on_press: root.update_addbook_label(root.address)
MDLabel:
font_style: 'Title'
text: 'Save'
font_size: '13sp'
color: (1,1,1,1)
halign: 'center'
MDRaisedButton:
size_hint: 1.5, None
height: dp(40)
on_press: root.dismiss()
on_press: root.close_pop()
MDLabel:
font_style: 'Title'
text: 'Cancel'
font_size: '13sp'
color: (1,1,1,1)
halign: 'center'
<ShowQRCode>:
name: 'showqrcode'
BoxLayout:
orientation: 'vertical'
id: qr
<ArrowImg@Image>:
source: './images/down-arrow.png' if self.parent.is_open == True else './images/right-arrow.png'
size: 15, 15
x: self.parent.x + self.parent.width - self.width - 5
y: self.parent.y + self.parent.height/2 - self.height + 5
<SearchBar@BoxLayout>:
id: search_bar
size_hint_y: None
height: self.minimum_height
MDIconButton:
icon: 'magnify'
MDTextField:
id: search_field
hint_text: 'Search'
on_text: app.searchQuery(self)
<LoadingPopup>:
separator_color: 1, 1, 1, 1
background: "White.png"
Button:
id: btn
disabled: True
background_disabled_normal: "White.png"
Image:
source: './images/loader.zip'
anim_delay: 0
#mipmap: True
size: root.size
<Loader@MDSpinner>:
id: spinner
size_hint: None, None
size: dp(46), dp(46)
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
active: False

View File

@ -1,613 +1,334 @@
"""
Bitmessage android(mobile) interface
"""
# pylint: disable=relative-import, import-error, no-name-in-module
# pylint: disable=too-few-public-methods, too-many-lines, unused-argument
import os
import time
from bmconfigparser import BMConfigParser
from functools import partial
from helper_sql import sqlExecute, sqlQuery
from kivy.app import App
from kivy.clock import Clock
from kivy.core.clipboard import Clipboard
from kivy.core.window import Window
from kivy.lang import Builder
from kivy.properties import (
BooleanProperty,
ListProperty,
NumericProperty,
ObjectProperty,
StringProperty
)
from kivy.uix.behaviors import FocusBehavior
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.carousel import Carousel
from kivy.uix.image import Image
from kivy.uix.label import Label
from kivy.uix.popup import Popup
from kivy.uix.recycleboxlayout import RecycleBoxLayout
from kivy.uix.recycleview import RecycleView
from kivy.uix.recycleview.layout import LayoutSelectionBehavior
from kivy.uix.recycleview.views import RecycleDataViewBehavior
from kivy.uix.screenmanager import Screen
from kivy.uix.spinner import Spinner
from kivy.uix.textinput import TextInput
from kivy.utils import platform
import kivy_helper_search import kivy_helper_search
from kivymd.button import MDIconButton import os
from kivymd.dialog import MDDialog
from kivymd.label import MDLabel
from kivymd.list import (
ILeftBody,
ILeftBodyTouch,
IRightBodyTouch,
TwoLineAvatarIconListItem,
TwoLineListItem
)
from kivymd.navigationdrawer import (
MDNavigationDrawer,
NavigationDrawerHeaderBase
)
from kivymd.selectioncontrols import MDCheckbox
from kivymd.theming import ThemeManager
import queues import queues
from semaphores import kivyuisignaler import shutdown
import state import state
from uikivysignaler import UIkivySignaler import time
import identiconGeneration from kivy.app import App
from addresses import addBMIfNotPresent, decodeAddress from kivy.lang import Builder
import helper_sent from kivy.properties import BooleanProperty
from kivy.clock import Clock
from navigationdrawer import NavigationDrawer
from kivy.properties import ObjectProperty, StringProperty, ListProperty
from kivy.uix.screenmanager import Screen
from kivy.uix.textinput import TextInput
from kivymd.theming import ThemeManager
from kivymd.toolbar import Toolbar
from bmconfigparser import BMConfigParser
from helper_ackPayload import genAckPayload
from addresses import decodeAddress, addBMIfNotPresent
from helper_sql import sqlExecute
statusIconColor = 'red'
def toast(text): class NavigateApp(App, TextInput):
"""Function displays toast message""" """Application uses kivy in which base Class of Navigate App inherits from the App class."""
# pylint: disable=redefined-outer-name
from kivymd.toast.kivytoast import toast theme_cls = ThemeManager()
toast(text) nav_drawer = ObjectProperty()
return
def build(self):
"""Return a main_widget as a root widget.
An application can be built if you return a widget on build(), or if you set
self.root.
"""
main_widget = Builder.load_file(
os.path.join(os.path.dirname(__file__), 'main.kv'))
self.nav_drawer = Navigator()
return main_widget
def getCurrentAccountData(self, text):
"""Get Current Address Account Data."""
state.association = text
self.root.ids.sc1.clear_widgets()
self.root.ids.sc2.clear_widgets()
self.root.ids.sc3.clear_widgets()
self.root.ids.sc1.add_widget(Inbox())
self.root.ids.sc2.add_widget(Sent())
self.root.ids.sc3.add_widget(Trash())
self.root.ids.toolbar.title = BMConfigParser().get(
state.association, 'label') + '({})'.format(state.association)
Inbox()
Sent()
Trash()
def say_exit(self):
"""Exit the application as uses shutdown PyBitmessage."""
print("**************************EXITING FROM APPLICATION*****************************")
App.get_running_app().stop()
shutdown.doCleanShutdown()
@staticmethod
def showmeaddresses(name="text"):
"""Show the addresses in spinner to make as dropdown."""
if name == "text":
return BMConfigParser().addresses()[0]
elif name == "values":
return BMConfigParser().addresses()
def update_index(self, data_index, index):
"""Update index after archieve message to trash."""
if self.root.ids.scr_mngr.current == 'inbox':
self.root.ids.sc1.data[data_index]['index'] = index
elif self.root.ids.scr_mngr.current == 'sent':
self.root.ids.sc2.data[data_index]['index'] = index
elif self.root.ids.scr_mngr.current == 'trash':
self.root.ids.sc3.data[data_index]['index'] = index
def delete(self, data_index):
"""It will make delete using remove function."""
print("delete {}".format(data_index))
self._remove(data_index)
def archive(self, data_index):
"""It will make archieve using remove function."""
print("archive {}".format(data_index))
self._remove(data_index)
def _remove(self, data_index):
"""It will remove message by resetting the values in recycleview data."""
if self.root.ids.scr_mngr.current == 'inbox':
self.root.ids.sc1.data.pop(data_index)
self.root.ids.sc1.data = [{
'data_index': i,
'index': d['index'],
'height': d['height'],
'text': d['text']}
for i, d in enumerate(self.root.ids.sc1.data)
]
elif self.root.ids.scr_mngr.current == 'sent':
self.root.ids.sc2.data.pop(data_index)
self.root.ids.sc2.data = [{
'data_index': i,
'index': d['index'],
'height': d['height'],
'text': d['text']}
for i, d in enumerate(self.root.ids.sc2.data)
]
elif self.root.ids.scr_mngr.current == 'trash':
self.root.ids.sc3.data.pop(data_index)
self.root.ids.sc3.data = [{
'data_index': i,
'index': d['index'],
'height': d['height'],
'text': d['text']}
for i, d in enumerate(self.root.ids.sc3.data)
]
def getInboxMessageDetail(self, instance):
"""It will get message detail after make selected message description."""
try:
self.root.ids.scr_mngr.current = 'page'
except AttributeError:
self.parent.manager.current = 'page'
print('Message Clicked {}'.format(instance))
@staticmethod
def getCurrentAccount():
"""It uses to get current account label."""
return BMConfigParser().get(state.association, 'label') + '({})'.format(state.association)
class CustomAvatarIconListItem(TwoLineAvatarIconListItem): class Navigator(NavigationDrawer):
"""Navigator class uses NavigationDrawer.
def __init__(self, **kwargs): It is an UI panel that shows our app's main navigation menu
super(CustomAvatarIconListItem, self).__init__(**kwargs) It is hidden when not in use, but appears when the user swipes
self.text_color=[0.12, 0.58, 0.95, 1] a finger from the left edge of the screen or, when at the top
level of the app, the user touches the drawer icon in the app bar
"""
class Navigatorss(MDNavigationDrawer):
"""Navigator class (image, title and logo)"""
image_source = StringProperty('images/qidenticon_two.png') image_source = StringProperty('images/qidenticon_two.png')
title = StringProperty('Navigation') title = StringProperty('Navigation')
drawer_logo = StringProperty()
class Inbox(Screen): class Inbox(Screen):
"""Inbox Screen uses screen to show widgets of screens.""" """Inbox Screen uses screen to show widgets of screens."""
queryreturn = ListProperty()
has_refreshed = True data = ListProperty()
account = StringProperty()
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
"""Method Parsing the address."""
super(Inbox, self).__init__(*args, **kwargs) super(Inbox, self).__init__(*args, **kwargs)
Clock.schedule_once(self.init_ui, 0)
@staticmethod
def set_defaultAddress():
"""This method set's default address"""
if state.association == '': if state.association == '':
if BMConfigParser().addresses(): state.association = Navigator().ids.btn.text
state.association = BMConfigParser().addresses()[0]
def init_ui(self, dt=0):
"""Clock schdule for method inbox accounts."""
self.loadMessagelist()
def loadMessagelist(self, where="", what=""):
"""Load Inbox list for Inbox messages."""
# pylint: disable=too-many-locals
self.set_defaultAddress()
self.account = state.association
if state.searcing_text:
self.children[2].children[0].children[0].scroll_y = 1.0
where = ['subject', 'message']
what = state.searcing_text
xAddress = 'toaddress'
data = []
self.inboxDataQuery(xAddress, where, what)
self.ids.identi_tag.children[0].text = ''
if self.queryreturn:
self.ids.identi_tag.children[0].text = 'Inbox'
state.kivyapp.get_inbox_count()
src_mng_obj = state.kivyapp.root.children[2].children[0].ids
src_mng_obj.inbox_cnt.badge_text = state.inbox_count
for mail in self.queryreturn:
# third_text = mail[3].replace('\n', ' ')
data.append({
'text': mail[4].strip(),
'secondary_text': mail[5][:50] + '........' if len(
mail[5]) >= 50 else (mail[5] + ',' + mail[3].replace(
'\n', ''))[0:50] + '........',
'msgid': mail[1]})
self.has_refreshed = True
self.set_mdList(data)
self.children[2].children[0].children[0].bind(
scroll_y=self.check_scroll_y)
else:
content = MDLabel(
font_style='Body1', theme_text_color='Primary',
text="No message found!" if state.searcing_text
else "yet no message for this account!!!!!!!!!!!!!",
halign='center', bold=True, size_hint_y=None, valign='top')
self.ids.ml.add_widget(content)
# pylint: disable=too-many-arguments
def inboxDataQuery(self, xAddress, where, what, start_indx=0, end_indx=20):
"""This method used for retrieving inbox data"""
self.queryreturn = kivy_helper_search.search_sql(
xAddress, self.account, "inbox", where, what,
False, start_indx, end_indx)
def set_mdList(self, data):
"""This method is used to create the mdList"""
total_message = len(self.ids.ml.children)
for item in data:
meny = CustomAvatarIconListItem(
text=item['text'], secondary_text=item['secondary_text'],
theme_text_color='Custom',
)
meny.add_widget(AvatarSampleWidget(
source='./images/text_images/{}.png'.format(
avatarImageFirstLetter(item['secondary_text'].strip()))))
meny.bind(on_press=partial(self.inbox_detail, item['msgid']))
carousel = Carousel(direction='right')
carousel.height = meny.height
carousel.size_hint_y = None
carousel.ignore_perpendicular_swipes = True
carousel.data_index = 0
carousel.min_move = 0.2
del_btn = Button(text='Delete')
del_btn.background_normal = ''
del_btn.background_color = (1, 0, 0, 1)
del_btn.bind(on_press=partial(self.delete, item['msgid']))
carousel.add_widget(del_btn)
carousel.add_widget(meny)
ach_btn = Button(text='Achieve')
ach_btn.background_color = (0, 1, 0, 1)
ach_btn.bind(on_press=partial(self.archive, item['msgid']))
carousel.add_widget(ach_btn)
carousel.index = 1
self.ids.ml.add_widget(carousel)
update_message = len(self.ids.ml.children)
self.has_refreshed = True if total_message != update_message else False
def check_scroll_y(self, instance, somethingelse):
"""Loads data on scroll"""
if self.children[2].children[0].children[
0].scroll_y <= -0.0 and self.has_refreshed:
self.children[2].children[0].children[0].scroll_y = 0.06
total_message = len(self.ids.ml.children)
self.update_inbox_screen_on_scroll(total_message)
else:
pass
def update_inbox_screen_on_scroll(self, total_message, where="", what=""):
"""This method is used to load more data on scroll down"""
data = []
if state.searcing_text:
where = ['subject', 'message']
what = state.searcing_text
self.inboxDataQuery('toaddress', where, what, total_message, 5)
for mail in self.queryreturn:
# third_text = mail[3].replace('\n', ' ')
data.append({
'text': mail[4].strip(),
'secondary_text': mail[5][:50] + '........' if len(
mail[5]) >= 50 else (mail[5] + ',' + mail[3].replace(
'\n', ''))[0:50] + '........',
'msgid': mail[1]})
self.set_mdList(data)
def inbox_detail(self, msg_id, *args):
"""Load inbox page details"""
state.detailPageType = 'inbox'
state.mail_id = msg_id
if self.manager:
src_mng_obj = self.manager
else:
src_mng_obj = self.parent.parent
src_mng_obj.screens[13].clear_widgets()
src_mng_obj.screens[13].add_widget(MailDetail())
src_mng_obj.current = 'mailDetail'
def delete(self, data_index, instance, *args):
"""Delete inbox mail from inbox listing"""
sqlExecute(
"UPDATE inbox SET folder = 'trash' WHERE msgid = ?;", str(
data_index))
try:
msg_count_objs = (
self.parent.parent.parent.parent.children[2].children[0].ids)
except Exception:
msg_count_objs = (
self.parent.parent.parent.parent.parent.children[
2].children[0].ids)
if int(state.inbox_count) > 0:
msg_count_objs.inbox_cnt.badge_text = str(
int(state.inbox_count) - 1)
msg_count_objs.trash_cnt.badge_text = str(
int(state.trash_count) + 1)
msg_count_objs.allmail_cnt.badge_text = str(
int(state.all_count) - 1)
state.inbox_count = str(
int(state.inbox_count) - 1)
state.trash_count = str(
int(state.trash_count) + 1)
state.all_count = str(
int(state.all_count) - 1)
if int(state.inbox_count) <= 0:
self.ids.identi_tag.children[0].text = ''
self.ids.ml.remove_widget(
instance.parent.parent)
toast('Deleted')
self.update_trash()
def archive(self, data_index, instance, *args):
"""Archive inbox mail from inbox listing"""
sqlExecute(
"UPDATE inbox SET folder = 'trash' WHERE msgid = ?;",
str(data_index))
self.ids.ml.remove_widget(instance.parent.parent)
self.update_trash()
def update_trash(self):
"""Update trash screen mails which is deleted from inbox"""
try:
self.parent.screens[4].clear_widgets()
self.parent.screens[4].add_widget(Trash())
except Exception:
self.parent.parent.screens[4].clear_widgets()
self.parent.parent.screens[4].add_widget(Trash())
# pylint: disable=attribute-defined-outside-init
def refresh_callback(self, *args):
"""Method updates the state of application,
While the spinner remains on the screen"""
def refresh_callback(interval):
"""Method used for loading the inbox screen data"""
state.searcing_text = ''
self.children[2].children[1].ids.search_field.text = ''
self.ids.ml.clear_widgets()
self.loadMessagelist(state.association)
self.has_refreshed = True
self.ids.refresh_layout.refresh_done()
self.tick = 0
Clock.schedule_once(refresh_callback, 1)
# def set_root_layout(self):
# """Setting root layout"""
# return self.parent.parent.parent
class MyAddress(Screen):
"""MyAddress screen uses screen to show widgets of screens."""
addresses_list = ListProperty()
has_refreshed = True
is_add_created = False
def __init__(self, *args, **kwargs):
"""Clock schdule for method Myaddress accounts."""
super(MyAddress, self).__init__(*args, **kwargs)
Clock.schedule_once(self.init_ui, 0) Clock.schedule_once(self.init_ui, 0)
def init_ui(self, dt=0): def init_ui(self, dt=0):
"""Clock schdule for method Myaddress accounts""" """Clock Schdule for method inbox accounts."""
self.addresses_list = state.kivyapp.variable_1 self.inboxaccounts()
if state.searcing_text: print(dt)
self.ids.refresh_layout.scroll_y = 1.0
# filtered_list = filter( def inboxaccounts(self):
# lambda addr: self.filter_address( """Load inbox accounts."""
# addr), BMConfigParser().addresses()) account = state.association
filtered_list = [ self.loadMessagelist(account, 'All', '')
x
for x in BMConfigParser().addresses() def loadMessagelist(self, account, where="", what=""):
if self.filter_address(x)] """Load Inbox list for inbox messages."""
self.addresses_list = filtered_list xAddress = "toaddress"
self.addresses_list = [obj for obj in reversed(self.addresses_list)] queryreturn = kivy_helper_search.search_sql(
self.ids.identi_tag.children[0].text = '' xAddress, account, 'inbox', where, what, False)
if self.addresses_list: if queryreturn:
self.ids.identi_tag.children[0].text = 'My Addresses' self.data = [{
self.has_refreshed = True 'data_index': i,
self.set_mdList(0, 15) 'index': 1,
self.ids.refresh_layout.bind(scroll_y=self.check_scroll_y) 'height': 48,
'text': row[4]}
for i, row in enumerate(queryreturn)
]
else: else:
content = MDLabel( self.data = [{
font_style='Body1', theme_text_color='Primary', 'data_index': 1,
text="No address found!" if state.searcing_text 'index': 1,
else "yet no address is created by user!!!!!!!!!!!!!", 'height': 48,
halign='center', bold=True, size_hint_y=None, valign='top') 'text': "yet no message for this account!!!!!!!!!!!!!"}
self.ids.ml.add_widget(content) ]
if not state.searcing_text and not self.is_add_created:
try:
self.manager.current = 'login' class Page(Screen):
except Exception:
pass pass
def set_mdList(self, first_index, last_index):
"""Creating the mdlist"""
data = []
for address in self.addresses_list[first_index:last_index]:
data.append({
'text': BMConfigParser().get(address, 'label'),
'secondary_text': address})
for item in data:
meny = CustomAvatarIconListItem(
text=item['text'], secondary_text=item['secondary_text'],
theme_text_color='Custom')
meny.add_widget(AvatarSampleWidget(
source='./images/text_images/{}.png'.format(
avatarImageFirstLetter(item['text'].strip()))))
meny.bind(on_press=partial(
self.myadd_detail, item['secondary_text'], item['text']))
self.ids.ml.add_widget(meny)
def check_scroll_y(self, instance, somethingelse): class AddressSuccessful(Screen):
"""Load data on scroll down"""
if self.ids.refresh_layout.scroll_y <= -0.0 and self.has_refreshed:
self.ids.refresh_layout.scroll_y = 0.06
my_addresses = len(self.ids.ml.children)
if my_addresses != len(self.addresses_list):
self.update_addressBook_on_scroll(my_addresses)
self.has_refreshed = True if my_addresses != len(
self.addresses_list) else False
else:
pass pass
def update_addressBook_on_scroll(self, my_addresses):
"""Loads more data on scroll down"""
self.set_mdList(my_addresses, my_addresses + 20)
@staticmethod class Sent(Screen):
def myadd_detail(fromaddress, label, *args): """Sent Screen uses screen to show widgets of screens."""
"""Load myaddresses details"""
p = MyaddDetailPopup()
p.open()
p.set_address(fromaddress, label)
# pylint: disable=attribute-defined-outside-init data = ListProperty()
def refresh_callback(self, *args):
"""Method updates the state of application,
While the spinner remains on the screen"""
def refresh_callback(interval):
"""Method used for loading the myaddress screen data"""
state.searcing_text = ''
state.kivyapp.root.ids.sc10.children[2].active = False
self.children[2].children[2].ids.search_field.text = ''
self.has_refreshed = True
self.ids.ml.clear_widgets()
self.init_ui()
self.ids.refresh_layout.refresh_done()
self.tick = 0
Clock.schedule_once(refresh_callback, 1)
@staticmethod
def filter_address(address):
"""Method will filter the my address list data"""
# if filter(lambda x: (state.searcing_text).lower() in x, [
# BMConfigParser().get(
# address, 'label').lower(), address.lower()]):
if [x for x in [BMConfigParser().get(
address, 'label').lower(), address.lower()] if (
state.searcing_text).lower() in x]:
return True
return False
def set_root_layout(self):
"""Setting root layout"""
return self.manager.parent.parent
class AddressBook(Screen):
"""AddressBook Screen uses screen to show widgets of screens"""
queryreturn = ListProperty()
has_refreshed = True
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
"""Getting AddressBook Details""" super(Sent, self).__init__(*args, **kwargs)
super(AddressBook, self).__init__(*args, **kwargs) if state.association == '':
state.association = Navigator().ids.btn.text
Clock.schedule_once(self.init_ui, 0) Clock.schedule_once(self.init_ui, 0)
def init_ui(self, dt=0): def init_ui(self, dt=0):
"""Clock Schdule for method AddressBook""" """Clock Schdule for method sent accounts."""
self.loadAddresslist(None, 'All', '') self.sentaccounts()
print dt print(dt)
def loadAddresslist(self, account, where="", what=""): def sentaccounts(self):
"""Clock Schdule for method AddressBook""" """Load sent accounts."""
if state.searcing_text: account = state.association
self.ids.scroll_y.scroll_y = 1.0 self.loadSent(account, 'All', '')
where = ['label', 'address']
what = state.searcing_text def loadSent(self, account, where="", what=""):
xAddress = '' """Load Sent list for Sent messages."""
self.ids.identi_tag.children[0].text = '' xAddress = 'fromaddress'
self.queryreturn = kivy_helper_search.search_sql( queryreturn = kivy_helper_search.search_sql(
xAddress, account, "addressbook", where, what, False) xAddress, account, "sent", where, what, False)
self.queryreturn = [obj for obj in reversed(self.queryreturn)] if queryreturn:
if self.queryreturn: self.data = [{
self.ids.identi_tag.children[0].text = 'Address Book' 'data_index': i,
self.has_refreshed = True 'index': 1,
self.set_mdList(0, 20) 'height': 48,
self.ids.scroll_y.bind(scroll_y=self.check_scroll_y) 'text': row[2]}
for i, row in enumerate(queryreturn)
]
else: else:
content = MDLabel( self.data = [{
font_style='Body1', theme_text_color='Primary', 'data_index': 1,
text="No contact found!" if state.searcing_text 'index': 1,
else "No contact found yet...... ", 'height': 48,
halign='center', bold=True, size_hint_y=None, valign='top') 'text': "yet no message for this account!!!!!!!!!!!!!"}
self.ids.ml.add_widget(content) ]
def set_mdList(self, start_index, end_index):
"""Creating the mdList"""
for item in self.queryreturn[start_index:end_index]:
meny = CustomAvatarIconListItem(
text=item[0], secondary_text=item[1], theme_text_color='Custom')
meny.add_widget(AvatarSampleWidget(
source='./images/text_images/{}.png'.format(
avatarImageFirstLetter(item[0].strip()))))
meny.bind(on_press=partial(
self.addBook_detail, item[1], item[0]))
carousel = Carousel(direction='right')
carousel.height = meny.height
carousel.size_hint_y = None
carousel.ignore_perpendicular_swipes = True
carousel.data_index = 0
carousel.min_move = 0.2
del_btn = Button(text='Delete')
del_btn.background_normal = ''
del_btn.background_color = (1, 0, 0, 1)
del_btn.bind(on_press=partial(self.delete_address, item[1]))
carousel.add_widget(del_btn)
carousel.add_widget(meny)
carousel.index = 1
self.ids.ml.add_widget(carousel)
def check_scroll_y(self, instance, somethingelse): class Trash(Screen):
"""Load data on scroll""" """Trash Screen uses screen to show widgets of screens."""
if self.ids.scroll_y.scroll_y <= -0.0 and self.has_refreshed:
self.ids.scroll_y.scroll_y = 0.06 data = ListProperty()
exist_addresses = len(self.ids.ml.children)
if exist_addresses != len(self.queryreturn): def __init__(self, *args, **kwargs):
self.update_addressBook_on_scroll(exist_addresses) super(Trash, self).__init__(*args, **kwargs)
self.has_refreshed = True if exist_addresses != len( if state.association == '':
self.queryreturn) else False state.association = Navigator().ids.btn.text
Clock.schedule_once(self.init_ui, 0)
def init_ui(self, dt=0):
"""Clock Schdule for method inbox accounts."""
self.inboxaccounts()
print(dt)
def inboxaccounts(self):
"""Load inbox accounts."""
account = state.association
self.loadTrashlist(account, 'All', '')
def loadTrashlist(self, account, where="", what=""):
"""Load Trash list for trashed messages."""
xAddress = "toaddress"
queryreturn = kivy_helper_search.search_sql(
xAddress, account, 'trash', where, what, False)
if queryreturn:
self.data = [{
'data_index': i,
'index': 1,
'height': 48,
'text': row[4]}
for i, row in enumerate(queryreturn)
]
else: else:
pass self.data = [{
'data_index': 1,
def update_addressBook_on_scroll(self, exist_addresses): 'index': 1,
"""Load more data on scroll down""" 'height': 48,
self.set_mdList(exist_addresses, exist_addresses + 5) 'text': "yet no message for this account!!!!!!!!!!!!!"}
]
@staticmethod
def refreshs(*args):
"""Refresh the Widget"""
# state.navinstance.ids.sc11.ids.ml.clear_widgets()
# state.navinstance.ids.sc11.loadAddresslist(None, 'All', '')
pass
@staticmethod
def addBook_detail(address, label, *args):
"""Addressbook details"""
p = AddbookDetailPopup()
p.open()
p.set_addbook_data(address, label)
def delete_address(self, address, instance, *args):
"""Delete inbox mail from inbox listing"""
self.ids.ml.remove_widget(instance.parent.parent)
if len(self.ids.ml.children) == 0:
self.ids.identi_tag.children[0].text = ''
sqlExecute(
"DELETE FROM addressbook WHERE address = '{}';".format(address))
class SelectableRecycleBoxLayout( class Dialog(Screen):
FocusBehavior, LayoutSelectionBehavior, RecycleBoxLayout): """Dialog Screen uses screen to show widgets of screens."""
"""Adds selection and focus behaviour to the view"""
# pylint: disable = too-many-ancestors, duplicate-bases
pass pass
class SelectableLabel(RecycleDataViewBehavior, Label): class Test(Screen):
"""Add selection support to the Label""" """Test Screen uses screen to show widgets of screens."""
index = None
selected = BooleanProperty(False)
selectable = BooleanProperty(True)
def refresh_view_attrs(self, rv, index, data): pass
"""Catch and handle the view changes"""
self.index = index
return super(SelectableLabel, self).refresh_view_attrs(
rv, index, data)
# pylint: disable=inconsistent-return-statements
def on_touch_down(self, touch):
"""Add selection on touch down"""
if super(SelectableLabel, self).on_touch_down(touch):
return True
if self.collide_point(*touch.pos) and self.selectable:
return self.parent.select_with_touch(self.index, touch)
def apply_selection(self, rv, index, is_selected):
"""Respond to the selection of items in the view"""
self.selected = is_selected
if is_selected:
print "selection changed to {0}".format(rv.data[index])
rv.parent.txt_input.text = rv.parent.txt_input.text.replace(
rv.parent.txt_input.text, rv.data[index]['text'])
class RV(RecycleView): class Create(Screen):
"""Recycling View""" """Create Screen uses screen to show widgets of screens."""
def __init__(self, **kwargs): # pylint: disable=useless-super-delegation def __init__(self, *args, **kwargs):
"""Recycling Method""" super(Create, self).__init__(*args, **kwargs)
super(RV, self).__init__(**kwargs)
def send(self):
class DropDownWidget(BoxLayout): """Send message from one address to another."""
"""Adding Dropdown Widget""" fromAddress = self.ids.spinner_id.text
# pylint: disable=too-many-statements, too-many-locals # For now we are using static address i.e we are not using recipent field value.
# pylint: disable=inconsistent-return-statements toAddress = "BM-2cWyUfBdY2FbgyuCb7abFZ49JYxSzUhNFe"
txt_input = ObjectProperty() message = self.ids.message.text
rv = ObjectProperty() subject = self.ids.subject.text
def send(self, navApp):
"""Send message from one address to another"""
fromAddress = str(self.ids.ti.text)
toAddress = str(self.ids.txt_input.text)
subject = self.ids.subject.text.encode('utf-8').strip()
message = self.ids.body.text.encode('utf-8').strip()
encoding = 3 encoding = 3
print "message: ", self.ids.body.text print("message: ", self.ids.message.text)
sendMessageToPeople = True sendMessageToPeople = True
if sendMessageToPeople: if sendMessageToPeople:
if toAddress != '' and subject and message: if toAddress != '':
status, addressVersionNumber, streamNumber, ripe = ( status, addressVersionNumber, streamNumber, ripe = decodeAddress(
decodeAddress(toAddress)) toAddress)
valid_from_add = True if fromAddress in state.kivyapp.variable_1 else False if status == 'success':
if status == 'success' and valid_from_add:
navApp.root.ids.sc3.children[0].active = True
if state.detailPageType == 'draft' \
and state.send_draft_mail:
sqlExecute(
"UPDATE sent SET toaddress = ?, fromaddress = ? ,"
" subject = ?, message = ?, folder = 'sent' WHERE"
" ackdata = ?;", toAddress, fromAddress, subject,
message, str(state.send_draft_mail))
self.parent.parent.screens[15].clear_widgets()
self.parent.parent.screens[15].add_widget(Draft())
else:
toAddress = addBMIfNotPresent(toAddress) toAddress = addBMIfNotPresent(toAddress)
statusIconColor = 'red'
if (addressVersionNumber > 4) or ( if addressVersionNumber > 4 or addressVersionNumber <= 1:
addressVersionNumber <= 1): print("addressVersionNumber > 4 or addressVersionNumber <= 1")
print "addressVersionNumber > 4"\
" or addressVersionNumber <= 1"
if streamNumber > 1 or streamNumber == 0: if streamNumber > 1 or streamNumber == 0:
print "streamNumber > 1 or streamNumber == 0" print("streamNumber > 1 or streamNumber == 0")
if statusIconColor == 'red': if statusIconColor == 'red':
print "shared.statusIconColor == 'red'" print("shared.statusIconColor == 'red'")
stealthLevel = BMConfigParser().safeGetInt( stealthLevel = BMConfigParser().safeGetInt(
'bitmessagesettings', 'ackstealthlevel') 'bitmessagesettings', 'ackstealthlevel')
from helper_ackPayload import genAckPayload
ackdata = genAckPayload(streamNumber, stealthLevel) ackdata = genAckPayload(streamNumber, stealthLevel)
t = ( t = ()
sqlExecute(
'''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''',
'', '',
toAddress, toAddress,
ripe, ripe,
@ -622,1902 +343,51 @@ class DropDownWidget(BoxLayout):
0, 0,
'sent', 'sent',
encoding, encoding,
BMConfigParser().getint('bitmessagesettings', 'ttl') BMConfigParser().getint('bitmessagesettings', 'ttl'))
) toLabel = ''
helper_sent.insert(t)
state.check_sent_acc = fromAddress
state.msg_counter_objs = self.parent.parent.parent.parent\
.parent.parent.children[2].children[0].ids
if state.detailPageType == 'draft' and state.send_draft_mail:
state.draft_count = str(int(state.draft_count) - 1)
state.msg_counter_objs.draft_cnt.badge_text = state.draft_count
state.detailPageType = ''
state.send_draft_mail = None
# self.parent.parent.screens[0].ids.ml.clear_widgets()
# self.parent.parent.screens[0].loadMessagelist(state.association)
self.parent.parent.screens[3].update_sent_messagelist()
# self.parent.parent.screens[16].clear_widgets()
# self.parent.parent.screens[16].add_widget(Allmails())
Clock.schedule_once(self.callback_for_msgsend, 3)
queues.workerQueue.put(('sendmessage', toAddress)) queues.workerQueue.put(('sendmessage', toAddress))
print "sqlExecute successfully #######################" print("sqlExecute successfully ##### ##################")
state.in_composer = True self.ids.message.text = ''
return self.ids.spinner_id.text = '<select>'
elif valid_from_add is False:
msg = 'Please enter valid sender address'
else:
msg = 'Enter a valid recipients address'
elif not toAddress:
msg = 'Please fill the form'
else:
msg = 'Please fill the form'
self.address_error_message(msg)
@staticmethod
def callback_for_msgsend(dt=0):
"""Callback method for messagesend"""
state.kivyapp.root.ids.sc3.children[0].active = False
state.in_sent_method = True
state.kivyapp.back_press()
toast('sent')
# pylint: disable=attribute-defined-outside-init
def address_error_message(self, msg):
"""Generates error message"""
width = .8 if platform == 'android' else .55
msg_dialog = MDDialog(
text=msg,
title='', size_hint=(width, .25), text_button_ok='Ok',
events_callback=self.callback_for_menu_items)
msg_dialog.open()
@staticmethod
def callback_for_menu_items(text_item):
"""Callback of alert box"""
toast(text_item)
def reset_composer(self):
"""Method will reset composer"""
self.ids.ti.text = ''
self.ids.btn.text = 'Select'
self.ids.txt_input.text = ''
self.ids.subject.text = '' self.ids.subject.text = ''
self.ids.body.text = '' self.ids.recipent.text = ''
toast("Reset message") return None
def auto_fill_fromaddr(self): def cancel(self):
"""Fill the text automatically From Address""" """Reset values for send message."""
self.ids.ti.text = self.ids.btn.text self.ids.message.text = ''
self.ids.ti.focus = True self.ids.spinner_id.text = '<select>'
self.ids.subject.text = ''
self.ids.recipent.text = ''
return None
class MyTextInput(TextInput): class NewIdentity(Screen):
"""Takes the text input in the field""" """Create new address for PyBitmessage."""
txt_input = ObjectProperty()
flt_list = ObjectProperty()
word_list = ListProperty()
starting_no = NumericProperty(3)
suggestion_text = ''
def __init__(self, **kwargs): # pylint: disable=useless-super-delegation
"""Getting Text Input"""
super(MyTextInput, self).__init__(**kwargs)
def on_text(self, instance, value):
"""Find all the occurrence of the word"""
self.parent.parent.parent.parent.ids.rv.data = []
matches = [self.word_list[i] for i in range(
len(self.word_list)) if self.word_list[
i][:self.starting_no] == value[:self.starting_no]]
display_data = []
for i in matches:
display_data.append({'text': i})
self.parent.parent.parent.parent.ids.rv.data = display_data
if len(matches) <= 10:
self.parent.height = (250 + (len(matches) * 20))
else:
self.parent.height = 400
def keyboard_on_key_down(self, window, keycode, text, modifiers):
"""Keyboard on key Down"""
if self.suggestion_text and keycode[1] == 'tab':
self.insert_text(self.suggestion_text + ' ')
return True
return super(MyTextInput, self).keyboard_on_key_down(
window, keycode, text, modifiers)
class Payment(Screen):
"""Payment module"""
def get_available_credits(self, instance): # pylint: disable=no-self-use
"""Get the available credits"""
state.availabe_credit = instance.parent.children[1].text
existing_credits = (
state.kivyapp.root.ids.sc18.ids.ml.children[0].children[
0].children[0].children[0].text)
if len(existing_credits.split(' ')) > 1:
toast(
'We already have added free coins'
' for the subscription to your account!')
else:
toast('Coins added to your account!')
state.kivyapp.root.ids.sc18.ids.ml.children[0].children[
0].children[0].children[0].text = '{0}'.format(
state.availabe_credit)
class Credits(Screen):
"""Module for screen screen"""
available_credits = StringProperty('{0}'.format('0'))
class Login(Screen):
"""Login Screeen"""
pass
class NetworkStat(Screen):
"""Method used to show network stat"""
text_variable_1 = StringProperty(
'{0}::{1}'.format('Total Connections', '0'))
text_variable_2 = StringProperty(
'Processed {0} per-to-per messages'.format('0'))
text_variable_3 = StringProperty(
'Processed {0} brodcast messages'.format('0'))
text_variable_4 = StringProperty(
'Processed {0} public keys'.format('0'))
text_variable_5 = StringProperty(
'Processed {0} object to be synced'.format('0'))
def __init__(self, *args, **kwargs):
"""Init method for network stat"""
super(NetworkStat, self).__init__(*args, **kwargs)
Clock.schedule_interval(self.init_ui, 1)
def init_ui(self, dt=0):
"""Clock Schdule for method networkstat screen"""
import network.stats
import shared
from network import objectracker
self.text_variable_1 = '{0} :: {1}'.format(
'Total Connections', str(len(network.stats.connectedHostsList())))
self.text_variable_2 = 'Processed {0} per-to-per messages'.format(
str(shared.numberOfMessagesProcessed))
self.text_variable_3 = 'Processed {0} brodcast messages'.format(
str(shared.numberOfBroadcastsProcessed))
self.text_variable_4 = 'Processed {0} public keys'.format(
str(shared.numberOfPubkeysProcessed))
self.text_variable_5 = '{0} object to be synced'.format(
len(objectracker.missingObjects))
class ContentNavigationDrawer(Navigatorss):
"""Navigate Content Drawer"""
pass
class Random(Screen):
"""Generates Random Address"""
is_active = BooleanProperty(False) is_active = BooleanProperty(False)
checked = StringProperty("") checked = StringProperty("")
# self.manager.parent.ids.create.children[0].source = 'images/plus-4-xxl.png'
def generateaddress(self, navApp): def generateaddress(self):
"""Method for Address Generator""" """Generate new address."""
entered_label = str(self.ids.label.text).strip() if self.checked == 'use a random number generator to make an address':
queues.apiAddressGeneratorReturnQueue.queue.clear()
streamNumberForAddress = 1 streamNumberForAddress = 1
label = self.ids.label.text label = self.ids.label.text
eighteenByteRipe = False eighteenByteRipe = False
nonceTrialsPerByte = 1000 nonceTrialsPerByte = 1000
payloadLengthExtraBytes = 1000 payloadLengthExtraBytes = 1000
lables = [BMConfigParser().get(obj, 'label')
for obj in BMConfigParser().addresses()]
if entered_label and entered_label not in lables:
toast('Address Creating...')
queues.addressGeneratorQueue.put(( queues.addressGeneratorQueue.put((
'createRandomAddress', 4, streamNumberForAddress, label, 1, 'createRandomAddress',
"", eighteenByteRipe, nonceTrialsPerByte, 4, streamNumberForAddress,
payloadLengthExtraBytes)) label, 1, "", eighteenByteRipe,
self.ids.label.text = '' nonceTrialsPerByte,
self.parent.parent.children[1].opacity = 1 payloadLengthExtraBytes)
self.parent.parent.children[1].disabled = False
state.kivyapp.root.ids.sc10.children[1].active = True
self.manager.current = 'myaddress'
Clock.schedule_once(self.address_created_callback, 6)
def address_created_callback(self, dt=0):
"""New address created"""
state.kivyapp.root.ids.sc10.children[1].active = False
state.kivyapp.root.ids.sc10.ids.ml.clear_widgets()
state.kivyapp.root.ids.sc10.is_add_created = True
state.kivyapp.root.ids.sc10.init_ui()
self.reset_address_spinner()
toast('New address created')
def reset_address_spinner(self):
"""reseting spinner address and UI"""
addresses = BMConfigParser().addresses()
self.manager.parent.parent.parent.parent.ids.nav_drawer.ids.btn.values = []
self.manager.parent.parent.parent.parent.ids.sc3.children[1].ids.btn.values = []
self.manager.parent.parent.parent.parent.ids.nav_drawer.ids.btn.values = addresses
self.manager.parent.parent.parent.parent.ids.sc3.children[1].ids.btn.values = addresses
def add_validation(self, instance):
"""Checking validation at address creation time"""
entered_label = str(instance.text.strip())
lables = [BMConfigParser().get(obj, 'label')
for obj in BMConfigParser().addresses()]
if entered_label in lables:
self.ids.label.error = True
self.ids.label.helper_text = 'Label name is already exist you'\
' can try this Ex. ( {0}_1, {0}_2 )'.format(
entered_label)
elif entered_label:
self.ids.label.error = False
else:
self.ids.label.error = False
self.ids.label.helper_text = 'This field is required'
def reset_address_label(self):
"""Resetting address labels"""
self.ids.label.text = ''
class Sent(Screen):
"""Sent Screen uses screen to show widgets of screens"""
queryreturn = ListProperty()
has_refreshed = True
account = StringProperty()
def __init__(self, *args, **kwargs):
"""Association with the screen."""
super(Sent, self).__init__(*args, **kwargs)
if state.association == '':
if BMConfigParser().addresses():
state.association = BMConfigParser().addresses()[0]
Clock.schedule_once(self.init_ui, 0)
def init_ui(self, dt=0):
"""Clock Schdule for method sent accounts"""
self.loadSent()
print dt
def loadSent(self, where="", what=""):
"""Load Sent list for Sent messages."""
self.account = state.association
if state.searcing_text:
self.ids.scroll_y.scroll_y = 1.0
where = ['subject', 'message']
what = state.searcing_text
xAddress = 'fromaddress'
data = []
self.ids.identi_tag.children[0].text = ''
self.sentDataQuery(xAddress, where, what)
if self.queryreturn:
self.ids.identi_tag.children[0].text = 'Sent'
self.set_sentCount(state.sent_count)
for mail in self.queryreturn:
data.append({
'text': mail[1].strip(),
'secondary_text': mail[2][:50] + '........' if len(
mail[2]) >= 50 else (mail[2] + ',' + mail[3].replace(
'\n', ''))[0:50] + '........',
'ackdata': mail[5]})
self.set_mdlist(data, 0)
self.has_refreshed = True
self.ids.scroll_y.bind(scroll_y=self.check_scroll_y)
else:
content = MDLabel(
font_style='Body1', theme_text_color='Primary',
text="No message found!" if state.searcing_text
else "yet no message for this account!!!!!!!!!!!!!",
halign='center', bold=True, size_hint_y=None, valign='top')
self.ids.ml.add_widget(content)
# pylint: disable=too-many-arguments
def sentDataQuery(self, xAddress, where, what, start_indx=0, end_indx=20):
"""This method is used to retrieving data from sent table"""
self.queryreturn = kivy_helper_search.search_sql(
xAddress, self.account, "sent", where, what,
False, start_indx, end_indx)
def set_mdlist(self, data, set_index=0):
"""This method is used to create the mdList"""
total_sent_msg = len(self.ids.ml.children)
for item in data:
meny = CustomAvatarIconListItem(
text=item['text'], secondary_text=item['secondary_text'],
theme_text_color='Custom')
meny.add_widget(AvatarSampleWidget(
source='./images/text_images/{}.png'.format(
avatarImageFirstLetter(item['secondary_text'].strip()))))
meny.bind(on_press=partial(self.sent_detail, item['ackdata']))
carousel = Carousel(direction='right')
carousel.height = meny.height
carousel.size_hint_y = None
carousel.ignore_perpendicular_swipes = True
carousel.data_index = 0
carousel.min_move = 0.2
del_btn = Button(text='Delete')
del_btn.background_normal = ''
del_btn.background_color = (1, 0, 0, 1)
del_btn.bind(on_press=partial(self.delete, item['ackdata']))
carousel.add_widget(del_btn)
carousel.add_widget(meny)
ach_btn = Button(text='Achieve')
ach_btn.background_color = (0, 1, 0, 1)
ach_btn.bind(on_press=partial(self.archive, item['ackdata']))
carousel.add_widget(ach_btn)
carousel.index = 1
self.ids.ml.add_widget(carousel, index=set_index)
updated_msgs = len(self.ids.ml.children)
self.has_refreshed = True if total_sent_msg != updated_msgs else False
def update_sent_messagelist(self):
"""This method is used to update screen when new mail is sent"""
self.account = state.association
if len(self.ids.ml.children) < 3:
self.ids.ml.clear_widgets()
self.loadSent()
total_sent = int(state.sent_count) + 1
self.set_sentCount(total_sent)
else:
data = []
self.sentDataQuery('fromaddress', '', '', 0, 1)
total_sent = int(state.sent_count) + 1
self.set_sentCount(total_sent)
for mail in self.queryreturn:
data.append({
'text': mail[1].strip(),
'secondary_text': mail[2][:50] + '........' if len(
mail[2]) >= 50 else (mail[2] + ',' + mail[3].replace(
'\n', ''))[0:50] + '........',
'ackdata': mail[5]})
self.set_mdlist(data, total_sent - 1)
if state.msg_counter_objs and state.association == (
state.check_sent_acc):
state.all_count = str(int(state.all_count) + 1)
state.msg_counter_objs.allmail_cnt.badge_text = state.all_count
state.check_sent_acc = None
def check_scroll_y(self, instance, somethingelse):
"""Load data on scroll down"""
if self.ids.scroll_y.scroll_y <= -0.0 and self.has_refreshed:
self.ids.scroll_y.scroll_y = 0.06
total_sent_msg = len(self.ids.ml.children)
self.update_sent_screen_on_scroll(total_sent_msg)
else:
pass
def update_sent_screen_on_scroll(self, total_sent_msg, where="", what=""):
"""This method is used to load more data on scroll down"""
if state.searcing_text:
where = ['subject', 'message']
what = state.searcing_text
self.sentDataQuery('fromaddress', where, what, total_sent_msg, 5)
data = []
for mail in self.queryreturn:
data.append({
'text': mail[1].strip(),
'secondary_text': mail[2][:50] + '........' if len(
mail[2]) >= 50 else (mail[2] + ',' + mail[3].replace(
'\n', ''))[0:50] + '........',
'ackdata': mail[5]})
self.set_mdlist(data, 0)
@staticmethod
def set_sentCount(total_sent):
"""Set the total no. of sent message count"""
src_mng_obj = state.kivyapp.root.children[2].children[0].ids
src_mng_obj.send_cnt.badge_text = str(total_sent)
state.sent_count = str(total_sent)
def sent_detail(self, ackdata, *args):
"""Load sent mail details"""
state.detailPageType = 'sent'
state.mail_id = ackdata
if self.manager:
src_mng_obj = self.manager
else:
src_mng_obj = self.parent.parent
src_mng_obj.screens[13].clear_widgets()
src_mng_obj.screens[13].add_widget(MailDetail())
src_mng_obj.current = 'mailDetail'
def delete(self, data_index, instance, *args):
"""Delete sent mail from sent mail listing"""
try:
msg_count_objs = self.parent.parent.parent.parent.children[
2].children[0].ids
except Exception:
msg_count_objs = self.parent.parent.parent.parent.parent.children[
2].children[0].ids
if int(state.sent_count) > 0:
msg_count_objs.send_cnt.badge_text = str(
int(state.sent_count) - 1)
msg_count_objs.trash_cnt.badge_text = str(
int(state.trash_count) + 1)
msg_count_objs.allmail_cnt.badge_text = str(
int(state.all_count) - 1)
state.sent_count = str(int(state.sent_count) - 1)
state.trash_count = str(int(state.trash_count) + 1)
state.all_count = str(int(state.all_count) - 1)
if int(state.sent_count) <= 0:
self.ids.identi_tag.children[0].text = ''
sqlExecute(
"UPDATE sent SET folder = 'trash'"
" WHERE ackdata = ?;", str(data_index))
self.ids.ml.remove_widget(instance.parent.parent)
toast('Deleted')
self.update_trash()
def archive(self, data_index, instance, *args):
"""Archive sent mail from sent mail listing"""
sqlExecute(
"UPDATE sent SET folder = 'trash' WHERE ackdata = ?;",
str(data_index))
self.ids.ml.remove_widget(instance.parent.parent)
self.update_trash()
def update_trash(self):
"""Update trash screen mails which is deleted from inbox"""
try:
self.parent.screens[4].clear_widgets()
self.parent.screens[4].add_widget(Trash())
self.parent.screens[16].clear_widgets()
self.parent.screens[16].add_widget(Allmails())
except Exception:
self.parent.parent.screens[4].clear_widgets()
self.parent.parent.screens[4].add_widget(Trash())
self.parent.parent.screens[16].clear_widgets()
self.parent.parent.screens[16].add_widget(Allmails())
class Trash(Screen):
"""Trash Screen uses screen to show widgets of screens"""
trash_messages = ListProperty()
has_refreshed = True
delete_index = StringProperty()
table_name = StringProperty()
def __init__(self, *args, **kwargs):
"""Trash method, delete sent message and add in Trash"""
super(Trash, self).__init__(*args, **kwargs)
Clock.schedule_once(self.init_ui, 0)
def init_ui(self, dt=0):
"""Clock Schdule for method trash screen."""
if state.association == '':
if BMConfigParser().addresses():
state.association = BMConfigParser().addresses()[0]
self.ids.identi_tag.children[0].text = ''
self.trashDataQuery(0, 20)
if self.trash_messages:
self.ids.identi_tag.children[0].text = 'Trash'
src_mng_obj = state.kivyapp.root.children[2].children[0].ids
src_mng_obj.trash_cnt.badge_text = state.trash_count
self.set_mdList()
self.ids.scroll_y.bind(scroll_y=self.check_scroll_y)
else:
content = MDLabel(
font_style='Body1', theme_text_color='Primary',
text="yet no trashed message for this account!!!!!!!!!!!!!",
halign='center', bold=True, size_hint_y=None, valign='top')
self.ids.ml.add_widget(content)
def trashDataQuery(self, start_indx, end_indx):
"""Trash message query"""
self.trash_messages = sqlQuery(
"SELECT toaddress, fromaddress, subject, message,"
" folder ||',' || 'sent' as folder, ackdata As"
" id, DATE(lastactiontime) As actionTime FROM sent"
" WHERE folder = 'trash' and fromaddress = '{0}' UNION"
" SELECT toaddress, fromaddress, subject, message,"
" folder ||',' || 'inbox' as folder, msgid As id,"
" DATE(received) As actionTime FROM inbox"
" WHERE folder = 'trash' and toaddress = '{0}'"
" ORDER BY actionTime DESC limit {1}, {2}".format(
state.association, start_indx, end_indx))
def set_mdList(self):
"""This method is used to create the mdlist"""
total_trash_msg = len(self.ids.ml.children)
for item in self.trash_messages:
meny = CustomAvatarIconListItem(
text=item[1],
secondary_text=item[2][:50] + '........' if len(
item[2]) >= 50 else (item[2] + ',' + item[3].replace(
'\n', ''))[0:50] + '........',
theme_text_color='Custom')
img_latter = './images/text_images/{}.png'.format(
item[2][0].upper() if (item[2][0].upper() >= 'A' and item[
2][0].upper() <= 'Z') else '!')
meny.add_widget(AvatarSampleWidget(source=img_latter))
carousel = Carousel(direction='right')
carousel.height = meny.height
carousel.size_hint_y = None
carousel.ignore_perpendicular_swipes = True
carousel.data_index = 0
carousel.min_move = 0.2
del_btn = Button(text='Delete')
del_btn.background_normal = ''
del_btn.background_color = (1, 0, 0, 1)
del_btn.bind(on_press=partial(
self.delete_permanently, item[5], item[4]))
carousel.add_widget(del_btn)
carousel.add_widget(meny)
carousel.index = 1
self.ids.ml.add_widget(carousel)
self.has_refreshed = True if total_trash_msg != len(
self.ids.ml.children) else False
def check_scroll_y(self, instance, somethingelse):
"""Load data on scroll"""
if self.ids.scroll_y.scroll_y <= -0.0 and self.has_refreshed:
self.ids.scroll_y.scroll_y = 0.06
total_trash_msg = len(self.ids.ml.children)
self.update_trash_screen_on_scroll(total_trash_msg)
else:
pass
def update_trash_screen_on_scroll(self, total_trash_msg):
"""Load more data on scroll down"""
self.trashDataQuery(total_trash_msg, 5)
self.set_mdList()
def delete_permanently(self, data_index, folder, instance, *args):
"""Deleting trash mail permanently"""
self.table_name = folder.split(',')[1]
self.delete_index = data_index
self.delete_confirmation()
def callback_for_screen_load(self, dt=0):
"""This methos is for loading screen"""
self.ids.ml.clear_widgets()
self.init_ui(0)
self.children[1].active = False
toast('Message is permanently deleted')
def delete_confirmation(self):
"""Show confirmation delete popup"""
width = .8 if platform == 'android' else .55
delete_msg_dialog = MDDialog(
text='Are you sure you want to delete this'
' message permanently from trash?', title='',
size_hint=(width, .25), text_button_ok='Yes',
text_button_cancel='No',
events_callback=self.callback_for_delete_msg)
delete_msg_dialog.open()
def callback_for_delete_msg(self, text_item):
"""Getting the callback of alert box"""
if text_item == 'Yes':
self.delete_message_from_trash()
else:
toast(text_item)
def delete_message_from_trash(self):
"""Deleting message from trash"""
self.children[1].active = True
if self.table_name == 'inbox':
sqlExecute(
"DELETE FROM inbox WHERE msgid = ?;",
str(self.delete_index))
elif self.table_name == 'sent':
sqlExecute(
"DELETE FROM sent WHERE ackdata = ?;",
str(self.delete_index))
msg_count_objs = state.kivyapp.root.children[2].children[0].ids
if int(state.trash_count) > 0:
msg_count_objs.trash_cnt.badge_text = str(
int(state.trash_count) - 1)
state.trash_count = str(int(state.trash_count) - 1)
Clock.schedule_once(self.callback_for_screen_load, 1)
class Page(Screen):
"""Page Screen show widgets of page"""
pass
class Create(Screen):
"""Creates the screen widgets"""
def __init__(self, **kwargs):
"""Getting Labels and address from addressbook"""
super(Create, self).__init__(**kwargs)
widget_1 = DropDownWidget()
widget_1.ids.txt_input.word_list = [
addr[1] for addr in sqlQuery(
"SELECT label, address from addressbook")]
widget_1.ids.txt_input.starting_no = 2
self.add_widget(widget_1)
class Setting(Screen):
"""Setting the Screen components"""
pass
class NavigateApp(App): # pylint: disable=too-many-public-methods
"""Navigation Layout of class"""
theme_cls = ThemeManager()
previous_date = ObjectProperty()
obj_1 = ObjectProperty()
variable_1 = ListProperty(BMConfigParser().addresses())
nav_drawer = ObjectProperty()
state.screen_density = Window.size
window_size = state.screen_density
app_platform = platform
title = "PyBitmessage"
imgstatus = False
count = 0
def build(self):
"""Method builds the widget"""
main_widget = Builder.load_file(
os.path.join(os.path.dirname(__file__), 'main.kv'))
self.nav_drawer = Navigatorss()
self.obj_1 = AddressBook()
kivysignalthread = UIkivySignaler()
kivysignalthread.daemon = True
kivysignalthread.start()
Window.bind(on_keyboard=self.on_key)
return main_widget
def run(self):
"""Running the widgets"""
kivyuisignaler.release()
super(NavigateApp, self).run()
# pylint: disable=inconsistent-return-statements
@staticmethod
def showmeaddresses(name="text"):
"""Show the addresses in spinner to make as dropdown"""
if name == "text":
if BMConfigParser().addresses():
return BMConfigParser().addresses()[0][:16] + '..'
return "textdemo"
elif name == "values":
if BMConfigParser().addresses():
return [address[:16] + '..'
for address in BMConfigParser().addresses()]
return "valuesdemo"
def getCurrentAccountData(self, text):
"""Get Current Address Account Data"""
self.set_identicon(text)
address_label = self.current_address_label(
BMConfigParser().get(text, 'label'), text)
self.root_window.children[1].ids.toolbar.title = address_label
state.association = text
state.searcing_text = ''
LoadingPopup().open()
self.set_message_count()
Clock.schedule_once(self.setCurrentAccountData, 0.5)
def setCurrentAccountData(self, dt=0):
"""This method set the current accout data on all the screens."""
self.root.ids.sc1.ids.ml.clear_widgets()
self.root.ids.sc1.loadMessagelist(state.association)
self.root.ids.sc4.ids.ml.clear_widgets()
self.root.ids.sc4.children[2].children[2].ids.search_field.text = ''
self.root.ids.sc4.loadSent(state.association)
self.root.ids.sc16.clear_widgets()
self.root.ids.sc16.add_widget(Draft())
self.root.ids.sc5.clear_widgets()
self.root.ids.sc5.add_widget(Trash())
self.root.ids.sc17.clear_widgets()
self.root.ids.sc17.add_widget(Allmails())
self.root.ids.scr_mngr.current = 'inbox'
@staticmethod
def getCurrentAccount():
"""It uses to get current account label"""
if state.association:
return state.association
return "Bitmessage Login"
@staticmethod
def addingtoaddressbook():
"""Adding to address Book"""
p = GrashofPopup()
p.open()
def getDefaultAccData(self):
"""Getting Default Account Data"""
if BMConfigParser().addresses():
img = identiconGeneration.generate(BMConfigParser().addresses()[0])
self.createFolder('./images/default_identicon/')
if platform == 'android':
# android_path = os.path.expanduser
# ("~/user/0/org.test.bitapp/files/app/")
android_path = os.path.join(
os.environ['ANDROID_PRIVATE'] + '/app/')
img.texture.save('{1}/images/default_identicon/{0}.png'.format(
BMConfigParser().addresses()[0], android_path))
else:
img.texture.save('./images/default_identicon/{}.png'.format(
BMConfigParser().addresses()[0]))
return BMConfigParser().addresses()[0]
return 'Select Address'
@staticmethod
def createFolder(directory):
"""Create directory when app starts"""
try:
if not os.path.exists(directory):
os.makedirs(directory)
except OSError:
print 'Error: Creating directory. ' + directory
@staticmethod
def get_default_image():
"""Getting default image on address"""
if BMConfigParser().addresses():
return './images/default_identicon/{}.png'.format(
BMConfigParser().addresses()[0])
return './images/no_identicons.png'
@staticmethod
def addressexist():
"""Checking address existence"""
if BMConfigParser().addresses():
return True
return False
def on_key(self, window, key, *args):
"""Method is used for going on previous screen"""
if key == 27:
if state.in_search_mode and self.root.ids.scr_mngr.current not in [
"mailDetail", "create"]:
self.closeSearchScreen()
elif self.root.ids.scr_mngr.current == "mailDetail":
self.root.ids.scr_mngr.current = 'sent'\
if state.detailPageType == 'sent' else 'inbox' \
if state.detailPageType == 'inbox' else 'draft'
self.back_press()
if state.in_search_mode and state.searcing_text:
toolbar_obj = self.root.ids.toolbar
toolbar_obj.left_action_items = [
['arrow-left', lambda x: self.closeSearchScreen()]]
toolbar_obj.right_action_items = []
self.root.ids.toolbar.title = ''
elif self.root.ids.scr_mngr.current == "create":
self.save_draft()
self.set_common_header()
state.in_composer = False
self.root.ids.scr_mngr.current = 'inbox'
elif self.root.ids.scr_mngr.current == "showqrcode":
self.root.ids.scr_mngr.current = 'myaddress'
elif self.root.ids.scr_mngr.current == "random":
self.root.ids.scr_mngr.current = 'login'
else:
if state.kivyapp.variable_1:
self.root.ids.scr_mngr.current = 'inbox'
self.root.ids.scr_mngr.transition.direction = 'right'
self.root.ids.scr_mngr.transition.bind(on_complete=self.reset)
return True
elif key == 13 and state.searcing_text and not state.in_composer:
if state.search_screen == 'inbox':
self.root.ids.sc1.children[1].active = True
Clock.schedule_once(self.search_callback, 0.5)
elif state.search_screen == 'addressbook':
self.root.ids.sc11.children[1].active = True
Clock.schedule_once(self.search_callback, 0.5)
elif state.search_screen == 'myaddress':
self.root.ids.sc10.children[1].active = True
Clock.schedule_once(self.search_callback, 0.5)
elif state.search_screen == 'sent':
self.root.ids.sc4.children[1].active = True
Clock.schedule_once(self.search_callback, 0.5)
def search_callback(self, dt=0):
"""Show data after loader is loaded"""
if state.search_screen == 'inbox':
self.root.ids.sc1.ids.ml.clear_widgets()
self.root.ids.sc1.loadMessagelist(state.association)
self.root.ids.sc1.children[1].active = False
elif state.search_screen == 'addressbook':
self.root.ids.sc11.ids.ml.clear_widgets()
self.root.ids.sc11.loadAddresslist(None, 'All', '')
self.root.ids.sc11.children[1].active = False
elif state.search_screen == 'myaddress':
self.root.ids.sc10.ids.ml.clear_widgets()
self.root.ids.sc10.init_ui()
self.root.ids.sc10.children[1].active = False
else:
self.root.ids.sc4.ids.ml.clear_widgets()
self.root.ids.sc4.loadSent(state.association)
self.root.ids.sc4.children[1].active = False
self.root.ids.scr_mngr.current = state.search_screen
def save_draft(self):
"""Saving drafts messages"""
composer_objs = self.root
from_addr = str(self.root.ids.sc3.children[1].ids.ti.text)
to_addr = str(self.root.ids.sc3.children[1].ids.txt_input.text)
if from_addr and to_addr and state.detailPageType != 'draft' \
and not state.in_sent_method:
Draft().draft_msg(composer_objs)
return
def reset(self, *args):
"""Set transition direction"""
self.root.ids.scr_mngr.transition.direction = 'left'
self.root.ids.scr_mngr.transition.unbind(on_complete=self.reset)
@staticmethod
def status_dispatching(data):
"""Dispatching Status acknowledgment"""
ackData, message = data
if state.ackdata == ackData:
state.status.status = message
def clear_composer(self):
"""If slow down, the new composer edit screen"""
self.set_navbar_for_composer()
composer_obj = self.root.ids.sc3.children[1].ids
composer_obj.ti.text = ''
composer_obj.btn.text = 'Select'
composer_obj.txt_input.text = ''
composer_obj.subject.text = ''
composer_obj.body.text = ''
state.in_composer = True
state.in_sent_method = False
def set_navbar_for_composer(self):
"""Clearing toolbar data when composer open"""
self.root.ids.toolbar.left_action_items = [
['arrow-left', lambda x: self.back_press()]]
self.root.ids.toolbar.right_action_items = [
['refresh',
lambda x: self.root.ids.sc3.children[1].reset_composer()],
['send',
lambda x: self.root.ids.sc3.children[1].send(self)]]
def set_common_header(self):
"""Common header for all window"""
self.root.ids.toolbar.right_action_items = [
['account-plus', lambda x: self.addingtoaddressbook()]]
self.root.ids.toolbar.left_action_items = [
['menu', lambda x: self.root.toggle_nav_drawer()]]
return
def back_press(self):
"""Method for, reverting composer to previous page"""
self.save_draft()
if self.root.ids.scr_mngr.current == \
'mailDetail' and state.in_search_mode:
toolbar_obj = self.root.ids.toolbar
toolbar_obj.left_action_items = [
['arrow-left', lambda x: self.closeSearchScreen()]]
toolbar_obj.right_action_items = []
self.root.ids.toolbar.title = ''
else:
self.set_common_header()
self.root.ids.scr_mngr.current = 'inbox' \
if state.in_composer else 'allmails'\
if state.is_allmail else state.detailPageType\
if state.detailPageType else 'inbox'
self.root.ids.scr_mngr.transition.direction = 'right'
self.root.ids.scr_mngr.transition.bind(on_complete=self.reset)
if state.is_allmail or state.detailPageType == 'draft':
state.is_allmail = False
state.detailPageType = ''
state.in_composer = False
@staticmethod
def get_inbox_count():
"""Getting inbox count"""
state.inbox_count = str(sqlQuery(
"SELECT COUNT(*) FROM inbox WHERE toaddress = '{}' and"
" folder = 'inbox' ;".format(state.association))[0][0])
@staticmethod
def get_sent_count():
"""Getting sent count"""
state.sent_count = str(sqlQuery(
"SELECT COUNT(*) FROM sent WHERE fromaddress = '{}' and"
" folder = 'sent' ;".format(state.association))[0][0])
def set_message_count(self):
"""Setting message count"""
try:
msg_counter_objs = (
self.root_window.children[0].children[2].children[0].ids)
except Exception:
msg_counter_objs = (
self.root_window.children[2].children[2].children[0].ids)
self.get_inbox_count()
self.get_sent_count()
state.trash_count = str(sqlQuery(
"SELECT (SELECT count(*) FROM sent"
" where fromaddress = '{0}' and folder = 'trash' )"
"+(SELECT count(*) FROM inbox where toaddress = '{0}' and"
" folder = 'trash') AS SumCount".format(state.association))[0][0])
state.draft_count = str(sqlQuery(
"SELECT COUNT(*) FROM sent WHERE fromaddress = '{}' and"
" folder = 'draft' ;".format(state.association))[0][0])
state.all_count = str(int(state.sent_count) + int(state.inbox_count))
if msg_counter_objs:
msg_counter_objs.send_cnt.badge_text = state.sent_count
msg_counter_objs.inbox_cnt.badge_text = state.inbox_count
msg_counter_objs.trash_cnt.badge_text = state.trash_count
msg_counter_objs.draft_cnt.badge_text = state.draft_count
msg_counter_objs.allmail_cnt.badge_text = state.all_count
def on_start(self):
"""Method activates on start"""
self.set_message_count()
@staticmethod
def on_stop():
"""On stop methos is used for stoping the runing script"""
print "*******************EXITING FROM APPLICATION*******************"
import shutdown
shutdown.doCleanShutdown()
@staticmethod
def current_address_label(current_add_label=None, current_addr=None):
"""Getting current address labels"""
if BMConfigParser().addresses():
if current_add_label:
first_name = current_add_label
addr = current_addr
else:
addr = BMConfigParser().addresses()[0]
first_name = BMConfigParser().get(addr, 'label')
f_name = first_name.split()
label = f_name[0][:14].capitalize() + '...' if len(
f_name[0]) > 15 else f_name[0].capitalize()
address = ' (' + addr + '...)'
return label + address
return ''
def searchQuery(self, instance):
"""Showing searched mails"""
state.search_screen = self.root.ids.scr_mngr.current
state.searcing_text = str(instance.text).strip()
if instance.focus and state.searcing_text:
toolbar_obj = self.root.ids.toolbar
toolbar_obj.left_action_items = [
['arrow-left', lambda x: self.closeSearchScreen()]]
toolbar_obj.right_action_items = []
self.root.ids.toolbar.title = ''
state.in_search_mode = True
def closeSearchScreen(self):
"""Function for close search screen"""
self.set_common_header()
if state.association:
address_label = self.current_address_label(
BMConfigParser().get(
state.association, 'label'), state.association)
self.root.ids.toolbar.title = address_label
state.searcing_text = ''
self.refreshScreen()
state.in_search_mode = False
def refreshScreen(self): # pylint: disable=unused-variable
"""Method show search button only on inbox or sent screen"""
state.searcing_text = ''
if state.search_screen == 'inbox':
try:
self.root.ids.sc1.children[
3].children[2].ids.search_field.text = ''
except Exception:
self.root.ids.sc1.children[
2].children[2].ids.search_field.text = ''
self.root.ids.sc1.children[1].active = True
Clock.schedule_once(self.search_callback, 0.5)
elif state.search_screen == 'addressbook':
self.root.ids.sc11.children[
2].children[2].ids.search_field.text = ''
self.root.ids.sc11.children[
1].active = True
Clock.schedule_once(self.search_callback, 0.5)
elif state.search_screen == 'myaddress':
try:
self.root.ids.sc10.children[
3].children[2].ids.search_field.text = ''
except Exception:
self.root.ids.sc10.children[
2].children[2].ids.search_field.text = ''
self.root.ids.sc10.children[1].active = True
Clock.schedule_once(self.search_callback, 0.5)
else:
self.root.ids.sc4.children[
2].children[2].ids.search_field.text = ''
self.root.ids.sc4.children[1].active = True
Clock.schedule_once(self.search_callback, 0.5)
return
def set_identicon(self, text):
"""Show identicon in address spinner"""
img = identiconGeneration.generate(text)
self.root.children[2].children[0].ids.btn.children[1].texture = (
img.texture)
def set_mail_detail_header(self):
"""Setting the details of the page"""
if state.association and state.in_search_mode:
address_label = self.current_address_label(
BMConfigParser().get(
state.association, 'label'), state.association)
self.root.ids.toolbar.title = address_label
toolbar_obj = self.root.ids.toolbar
toolbar_obj.left_action_items = [
['arrow-left', lambda x: self.back_press()]]
delete_btn = ['delete-forever',
lambda x: self.root.ids.sc14.delete_mail()]
dynamic_list = []
if state.detailPageType == 'inbox':
dynamic_list = [
['reply', lambda x: self.root.ids.sc14.inbox_reply()],
delete_btn]
elif state.detailPageType == 'sent':
dynamic_list = [delete_btn]
elif state.detailPageType == 'draft':
dynamic_list = [
['pencil', lambda x: self.root.ids.sc14.write_msg(self)],
delete_btn]
toolbar_obj.right_action_items = dynamic_list
def load_screen(self, instance):
"""This method is used for loading screen on every click"""
if instance.text == 'Inbox':
self.root.ids.scr_mngr.current = 'inbox'
self.root.ids.sc1.children[1].active = True
elif instance.text == 'All Mails':
self.root.ids.scr_mngr.current = 'allmails'
try:
self.root.ids.sc17.children[1].active = True
except Exception:
self.root.ids.sc17.children[0].children[1].active = True
Clock.schedule_once(partial(self.load_screen_callback, instance), 1)
def load_screen_callback(self, instance, dt=0):
"""This method is rotating loader for few seconds"""
if instance.text == 'Inbox':
self.root.ids.sc1.ids.ml.clear_widgets()
self.root.ids.sc1.loadMessagelist(state.association)
self.root.ids.sc1.children[1].active = False
elif instance.text == 'All Mails':
if len(self.root.ids.sc17.ids.ml.children) <= 2:
self.root.ids.sc17.clear_widgets()
self.root.ids.sc17.add_widget(Allmails())
else:
self.root.ids.sc17.ids.ml.clear_widgets()
self.root.ids.sc17.loadMessagelist()
try:
self.root.ids.sc17.children[1].active = False
except Exception:
self.root.ids.sc17.children[0].children[1].active = False
class GrashofPopup(Popup):
"""Moule for save contacts and error messages"""
valid = False
def __init__(self, **kwargs): # pylint: disable=useless-super-delegation
"""Grash of pop screen settings"""
super(GrashofPopup, self).__init__(**kwargs)
def savecontact(self):
"""Method is used for saving contacts"""
label = self.ids.label.text.strip()
address = self.ids.address.text.strip()
if label == '' and address == '':
self.ids.label.focus = True
self.ids.address.focus = True
elif address == '':
self.ids.address.focus = True
elif label == '':
self.ids.label.focus = True
stored_address = [addr[1] for addr in kivy_helper_search.search_sql(
folder="addressbook")]
stored_labels = [labels[0] for labels in kivy_helper_search.search_sql(
folder="addressbook")]
if label and address and address not in stored_address \
and label not in stored_labels and self.valid:
# state.navinstance = self.parent.children[1]
queues.UISignalQueue.put(('rerenderAddressBook', ''))
self.dismiss()
sqlExecute("INSERT INTO addressbook VALUES(?,?)", label, address)
self.parent.children[1].ids.sc11.ids.ml.clear_widgets()
self.parent.children[1].ids.sc11.loadAddresslist(None, 'All', '')
self.parent.children[1].ids.scr_mngr.current = 'addressbook'
toast('Saved')
@staticmethod
def close_pop():
"""Pop is Canceled"""
toast('Canceled')
def checkAddress_valid(self, instance):
"""Checking address is valid or not"""
my_addresses = (
self.parent.children[1].children[2].children[0].ids.btn.values)
add_book = [addr[1] for addr in kivy_helper_search.search_sql(
folder="addressbook")]
entered_text = str(instance.text).strip()
if entered_text in add_book:
text = 'Address is already in the addressbook.'
elif entered_text in my_addresses:
text = 'You can not save your own address.'
elif entered_text:
text = self.addressChanged(entered_text)
if entered_text in my_addresses or entered_text in add_book:
self.ids.address.error = True
self.ids.address.helper_text = text
elif entered_text and self.valid:
self.ids.address.error = False
elif entered_text:
self.ids.address.error = True
self.ids.address.helper_text = text
else:
self.ids.address.error = False
self.ids.address.helper_text = 'This field is required'
def checkLabel_valid(self, instance):
"""Checking address label is unique or not"""
entered_label = instance.text.strip()
addr_labels = [labels[0] for labels in kivy_helper_search.search_sql(
folder="addressbook")]
if entered_label in addr_labels:
self.ids.label.error = True
self.ids.label.helper_text = 'label name already exists.'
elif entered_label:
self.ids.label.error = False
else:
self.ids.label.error = False
self.ids.label.helper_text = 'This field is required'
def _onSuccess(self, addressVersion, streamNumber, ripe):
pass
def addressChanged(self, addr):
"""Address validation callback, performs validation and gives feedback"""
status, addressVersion, streamNumber, ripe = decodeAddress(
str(addr))
self.valid = status == 'success'
if self.valid:
text = "Address is valid."
self._onSuccess(addressVersion, streamNumber, ripe)
elif status == 'missingbm':
text = "The address should start with ''BM-''"
elif status == 'checksumfailed':
text = "The address is not typed or copied correctly(the checksum failed)."
elif status == 'versiontoohigh':
text = "The version number of this address is higher"\
" than this software can support. Please upgrade Bitmessage."
elif status == 'invalidcharacters':
text = "The address contains invalid characters."
elif status == 'ripetooshort':
text = "Some data encoded in the address is too short."
elif status == 'ripetoolong':
text = "Some data encoded in the address is too long."
elif status == 'varintmalformed':
text = "Some data encoded in the address is malformed."
return text
class AvatarSampleWidget(ILeftBody, Image):
"""Avatar Sample Widget"""
pass
class IconLeftSampleWidget(ILeftBodyTouch, MDIconButton):
"""Left icon sample widget"""
pass
class IconRightSampleWidget(IRightBodyTouch, MDCheckbox):
"""Right icon sample widget"""
pass
class NavigationDrawerTwoLineListItem(
TwoLineListItem, NavigationDrawerHeaderBase):
"""Navigation Drawer in Listitems"""
address_property = StringProperty()
def __init__(self, **kwargs):
"""Method for Navigation Drawer"""
super(NavigationDrawerTwoLineListItem, self).__init__(**kwargs)
Clock.schedule_once(lambda dt: self.setup())
def setup(self):
"""Bind Controller.current_account property"""
pass
def on_current_account(self, account):
"""Account detail"""
pass
def _update_specific_text_color(self, instance, value):
pass
def _set_active(self, active, list_):
pass
class MailDetail(Screen):
"""MailDetail Screen uses to show the detail of mails"""
to_addr = StringProperty()
from_addr = StringProperty()
subject = StringProperty()
message = StringProperty()
status = StringProperty()
page_type = StringProperty()
def __init__(self, *args, **kwargs):
"""Mail Details method"""
super(MailDetail, self).__init__(*args, **kwargs)
Clock.schedule_once(self.init_ui, 0)
def init_ui(self, dt=0):
"""Clock Schdule for method MailDetail mails"""
self.page_type = state.detailPageType if state.detailPageType else ''
if state.detailPageType == 'sent' or state.detailPageType == 'draft':
data = sqlQuery(
"select toaddress, fromaddress, subject, message, status,"
" ackdata from sent where ackdata = ?;", state.mail_id)
state.status = self
state.ackdata = data[0][5]
self.assign_mail_details(data)
state.kivyapp.set_mail_detail_header()
elif state.detailPageType == 'inbox':
data = sqlQuery(
"select toaddress, fromaddress, subject, message from inbox"
" where msgid = ?;", str(state.mail_id))
self.assign_mail_details(data)
state.kivyapp.set_mail_detail_header()
def assign_mail_details(self, data):
"""Assigning mail details"""
self.to_addr = data[0][0]
self.from_addr = data[0][1]
self.subject = data[0][2].upper(
) if data[0][2].upper() else '(no subject)'
self.message = data[0][3]
if len(data[0]) == 6:
self.status = data[0][4]
def delete_mail(self):
"""Method for mail delete"""
msg_count_objs = state.kivyapp.root.children[2].children[0].ids
state.searcing_text = ''
self.children[0].children[0].active = True
if state.detailPageType == 'sent':
state.kivyapp.root.ids.sc4.children[
2].children[2].ids.search_field.text = ''
sqlExecute(
"UPDATE sent SET folder = 'trash' WHERE"
" ackdata = ?;", str(state.mail_id))
msg_count_objs.send_cnt.badge_text = str(int(state.sent_count) - 1) if int(state.sent_count) else '0'
state.sent_count = str(int(state.sent_count) - 1) if int(state.sent_count) else '0'
self.parent.screens[3].ids.ml.clear_widgets()
self.parent.screens[3].loadSent(state.association)
elif state.detailPageType == 'inbox':
state.kivyapp.root.ids.sc1.children[
2].children[2].ids.search_field.text = ''
self.parent.screens[0].children[2].children[
2].ids.search_field.text = ''
sqlExecute(
"UPDATE inbox SET folder = 'trash' WHERE"
" msgid = ?;", str(state.mail_id))
msg_count_objs.inbox_cnt.badge_text = str(
int(state.inbox_count) - 1) if int(state.inbox_count) else '0'
state.inbox_count = str(int(state.inbox_count) - 1) if int(state.inbox_count) else '0'
self.parent.screens[0].ids.ml.clear_widgets()
self.parent.screens[0].loadMessagelist(state.association)
elif state.detailPageType == 'draft':
sqlExecute(
"DELETE FROM sent WHERE ackdata = ?;", str(state.mail_id))
msg_count_objs.draft_cnt.badge_text = str(
int(state.draft_count) - 1)
state.draft_count = str(int(state.draft_count) - 1)
self.parent.screens[15].clear_widgets()
self.parent.screens[15].add_widget(Draft())
# self.parent.current = 'allmails' \
# if state.is_allmail else state.detailPageType
if state.detailPageType != 'draft':
msg_count_objs.trash_cnt.badge_text = str(
int(state.trash_count) + 1)
msg_count_objs.allmail_cnt.badge_text = str(
int(state.all_count) - 1) if int(state.all_count) else '0'
state.trash_count = str(int(state.trash_count) + 1)
state.all_count = str(int(state.all_count) - 1) if int(state.all_count) else '0'
self.parent.screens[4].clear_widgets()
self.parent.screens[4].add_widget(Trash())
self.parent.screens[16].clear_widgets()
self.parent.screens[16].add_widget(Allmails())
Clock.schedule_once(self.callback_for_delete, 4)
def callback_for_delete(self, dt=0):
"""Delete method from allmails"""
self.children[0].children[0].active = False
state.kivyapp.set_common_header()
self.parent.current = 'allmails' \
if state.is_allmail else state.detailPageType
state.detailPageType = ''
toast('Deleted')
def inbox_reply(self):
"""Reply inbox messages"""
state.in_composer = True
data = sqlQuery(
"select toaddress, fromaddress, subject, message from inbox where"
" msgid = ?;", str(state.mail_id))
composer_obj = self.parent.screens[2].children[1].ids
composer_obj.ti.text = data[0][0]
composer_obj.btn.text = data[0][0]
composer_obj.txt_input.text = data[0][1]
composer_obj.subject.text = data[0][2]
composer_obj.body.text = ''
state.kivyapp.root.ids.sc3.children[1].ids.rv.data = ''
self.parent.current = 'create'
state.kivyapp.set_navbar_for_composer()
def write_msg(self, navApp):
"""Write on draft mail"""
state.send_draft_mail = state.mail_id
data = sqlQuery(
"select toaddress, fromaddress, subject, message from sent where"
" ackdata = ?;", str(state.mail_id))
composer_ids = (
self.parent.parent.parent.parent.parent.ids.sc3.children[1].ids)
composer_ids.ti.text = data[0][1]
composer_ids.btn.text = data[0][1]
composer_ids.txt_input.text = data[0][0]
composer_ids.subject.text = data[0][2] if data[0][2] != '(no subject)' else ''
composer_ids.body.text = data[0][3]
self.parent.current = 'create'
navApp.set_navbar_for_composer()
@staticmethod
def copy_composer_text(instance, *args):
"""Copy the data from mail detail page"""
if len(instance.parent.text.split(':')) > 1:
cpy_text = instance.parent.text.split(':')[1].strip()
else:
cpy_text = instance.parent.text
Clipboard.copy(cpy_text)
toast('Copied')
class MyaddDetailPopup(Popup):
"""MyaddDetailPopup pop is used for showing my address detail"""
address_label = StringProperty()
address = StringProperty()
def __init__(self, **kwargs): # pylint: disable=useless-super-delegation
"""My Address Details screen setting"""
super(MyaddDetailPopup, self).__init__(**kwargs)
def set_address(self, address, label):
"""Getting address for displaying details on popup"""
self.address_label = label
self.address = address
def send_message_from(self):
"""Method used to fill from address of composer autofield"""
state.kivyapp.set_navbar_for_composer()
window_obj = self.parent.children[1].ids
window_obj.sc3.children[1].ids.ti.text = self.address
window_obj.sc3.children[1].ids.btn.text = self.address
window_obj.sc3.children[1].ids.txt_input.text = ''
window_obj.sc3.children[1].ids.subject.text = ''
window_obj.sc3.children[1].ids.body.text = ''
window_obj.scr_mngr.current = 'create'
self.dismiss()
@staticmethod
def close_pop():
"""Pop is Canceled"""
toast('Canceled')
class AddbookDetailPopup(Popup):
"""AddbookDetailPopup pop is used for showing my address detail"""
address_label = StringProperty()
address = StringProperty()
def __init__(self, **kwargs):
"""Set screen of address detail page"""
# pylint: disable=useless-super-delegation
super(AddbookDetailPopup, self).__init__(**kwargs)
def set_addbook_data(self, address, label):
"""Getting address book data for detial dipaly"""
self.address_label = label
self.address = address
def update_addbook_label(self, address):
"""Updating the label of address book address"""
address_list = kivy_helper_search.search_sql(folder="addressbook")
stored_labels = [labels[0] for labels in address_list]
add_dict = dict(address_list)
label = str(self.ids.add_label.text)
if label in stored_labels and self.address == add_dict[label]:
stored_labels.remove(label)
if label and label not in stored_labels:
sqlExecute(
"UPDATE addressbook SET label = '{}' WHERE"
" address = '{}';".format(
str(self.ids.add_label.text), address))
self.parent.children[1].ids.sc11.ids.ml.clear_widgets()
self.parent.children[1].ids.sc11.loadAddresslist(None, 'All', '')
self.dismiss()
toast('Saved')
def send_message_to(self):
"""Method used to fill to_address of composer autofield"""
state.kivyapp.set_navbar_for_composer()
window_obj = self.parent.children[1].ids
window_obj.sc3.children[1].ids.txt_input.text = self.address
window_obj.sc3.children[1].ids.ti.text = ''
window_obj.sc3.children[1].ids.btn.text = 'Select'
window_obj.sc3.children[1].ids.subject.text = ''
window_obj.sc3.children[1].ids.body.text = ''
window_obj.scr_mngr.current = 'create'
self.dismiss()
@staticmethod
def close_pop():
"""Pop is Canceled"""
toast('Canceled')
def checkLabel_valid(self, instance):
"""Checking address label is unique of not"""
entered_label = str(instance.text.strip())
address_list = kivy_helper_search.search_sql(folder="addressbook")
addr_labels = [labels[0] for labels in address_list]
add_dict = dict(address_list)
if self.address and entered_label in addr_labels \
and self.address != add_dict[entered_label]:
self.ids.add_label.error = True
self.ids.add_label.helper_text = 'label name already exists.'
elif entered_label:
self.ids.add_label.error = False
else:
self.ids.add_label.error = False
self.ids.add_label.helper_text = 'This field is required'
class ShowQRCode(Screen):
"""ShowQRCode Screen uses to show the detail of mails"""
def qrdisplay(self):
"""Showing QR Code"""
# self.manager.parent.parent.parent.ids.search_bar.clear_widgets()
self.ids.qr.clear_widgets()
from kivy.garden.qrcode import QRCodeWidget
self.ids.qr.add_widget(QRCodeWidget(
data=self.manager.get_parent_window().children[0].address))
toast('Show QR code')
class Draft(Screen):
"""Draft screen is used to show the list of draft messages"""
data = ListProperty()
account = StringProperty()
queryreturn = ListProperty()
has_refreshed = True
def __init__(self, *args, **kwargs):
"""Method used for storing draft messages"""
super(Draft, self).__init__(*args, **kwargs)
if state.association == '':
if BMConfigParser().addresses():
state.association = BMConfigParser().addresses()[0]
Clock.schedule_once(self.init_ui, 0)
def init_ui(self, dt=0):
"""Clock Schdule for method draft accounts"""
self.sentaccounts()
print dt
def sentaccounts(self):
"""Load draft accounts."""
self.account = state.association
self.loadDraft()
def loadDraft(self, where="", what=""):
"""Load draft list for Draft messages."""
xAddress = 'fromaddress'
self.ids.identi_tag.children[0].text = ''
self.draftDataQuery(xAddress, where, what)
if state.msg_counter_objs:
state.msg_counter_objs.draft_cnt.badge_text = str(
len(self.queryreturn))
if self.queryreturn:
self.ids.identi_tag.children[0].text = 'Draft'
src_mng_obj = state.kivyapp.root.children[2].children[0].ids
src_mng_obj.draft_cnt.badge_text = state.draft_count
self.set_mdList()
self.ids.scroll_y.bind(scroll_y=self.check_scroll_y)
else:
content = MDLabel(
font_style='Body1', theme_text_color='Primary',
text="yet no message for this account!!!!!!!!!!!!!",
halign='center', bold=True, size_hint_y=None, valign='top')
self.ids.ml.add_widget(content)
# pylint: disable=too-many-arguments
def draftDataQuery(self, xAddress, where, what, start_indx=0, end_indx=20):
"""This methosd is for retrieving draft messages"""
self.queryreturn = kivy_helper_search.search_sql(
xAddress, self.account, "draft", where, what,
False, start_indx, end_indx)
def set_mdList(self):
"""This method is used to create mdlist"""
data = []
total_draft_msg = len(self.ids.ml.children)
for mail in self.queryreturn:
third_text = mail[3].replace('\n', ' ')
data.append({
'text': mail[1].strip(),
'secondary_text': mail[2][:10] + '...........' if len(
mail[2]) > 10 else mail[2] + '\n' + " " + (
third_text[:25] + '...!') if len(
third_text) > 25 else third_text,
'ackdata': mail[5]})
for item in data:
meny = CustomAvatarIconListItem(
text='Draft', secondary_text=item['text'],
theme_text_color='Custom')
meny.add_widget(AvatarSampleWidget(
source='./images/avatar.png'))
meny.bind(on_press=partial(
self.draft_detail, item['ackdata']))
carousel = Carousel(direction='right')
carousel.height = meny.height
carousel.size_hint_y = None
carousel.ignore_perpendicular_swipes = True
carousel.data_index = 0
carousel.min_move = 0.2
del_btn = Button(text='Delete')
del_btn.background_normal = ''
del_btn.background_color = (1, 0, 0, 1)
del_btn.bind(on_press=partial(self.delete_draft, item['ackdata']))
carousel.add_widget(del_btn)
carousel.add_widget(meny)
carousel.index = 1
self.ids.ml.add_widget(carousel)
updated_msg = len(self.ids.ml.children)
self.has_refreshed = True if total_draft_msg != updated_msg else False
def check_scroll_y(self, instance, somethingelse):
"""Load data on scroll"""
if self.ids.scroll_y.scroll_y <= -0.0 and self.has_refreshed:
self.ids.scroll_y.scroll_y = 0.06
total_draft_msg = len(self.ids.ml.children)
self.update_draft_screen_on_scroll(total_draft_msg)
else:
pass
def update_draft_screen_on_scroll(self, total_draft_msg, where='', what=''):
"""Load more data on scroll down"""
self.draftDataQuery('fromaddress', where, what, total_draft_msg, 5)
self.set_mdList()
def draft_detail(self, ackdata, *args):
"""Show draft Details"""
state.detailPageType = 'draft'
state.mail_id = ackdata
if self.manager:
src_mng_obj = self.manager
else:
src_mng_obj = self.parent.parent
src_mng_obj.screens[13].clear_widgets()
src_mng_obj.screens[13].add_widget(MailDetail())
src_mng_obj.current = 'mailDetail'
def delete_draft(self, data_index, instance, *args):
"""Delete draft message permanently"""
sqlExecute("DELETE FROM sent WHERE ackdata = ?;", str(
data_index))
try:
msg_count_objs = (
self.parent.parent.parent.parent.parent.parent.children[
2].children[0].ids)
except Exception:
msg_count_objs = self.parent.parent.parent.parent.parent.children[
2].children[0].ids
if int(state.draft_count) > 0:
msg_count_objs.draft_cnt.badge_text = str(
int(state.draft_count) - 1)
state.draft_count = str(int(state.draft_count) - 1)
if int(state.draft_count) <= 0:
self.ids.identi_tag.children[0].text = ''
self.ids.ml.remove_widget(instance.parent.parent)
toast('Deleted')
@staticmethod
def draft_msg(src_object): # pylint: disable=too-many-locals
"""Save draft mails"""
composer_object = state.kivyapp.root.ids.sc3.children[1].ids
fromAddress = str(composer_object.ti.text)
toAddress = str(composer_object.txt_input.text)
subject = str(composer_object.subject.text)
message = str(composer_object.body.text)
encoding = 3
sendMessageToPeople = True
if sendMessageToPeople:
streamNumber, ripe = decodeAddress(toAddress)[2:]
toAddress = addBMIfNotPresent(toAddress)
stealthLevel = BMConfigParser().safeGetInt(
'bitmessagesettings', 'ackstealthlevel')
from helper_ackPayload import genAckPayload
ackdata = genAckPayload(streamNumber, stealthLevel)
t = (
'',
toAddress,
ripe,
fromAddress,
subject,
message,
ackdata,
int(time.time()),
int(time.time()),
0,
'msgqueued',
0,
'draft',
encoding,
BMConfigParser().getint('bitmessagesettings', 'ttl')
) )
helper_sent.insert(t) self.manager.current = 'add_sucess'
state.msg_counter_objs = src_object.children[2].children[0].ids
state.draft_count = str(int(state.draft_count) + 1)
src_object.ids.sc16.clear_widgets()
src_object.ids.sc16.add_widget(Draft())
toast('Save draft')
return
class CustomSpinner(Spinner): if __name__ == '__main__':
"""This class is used for setting spinner size""" NavigateApp().run()
def __init__(self, *args, **kwargs):
"""Setting size of spinner"""
super(CustomSpinner, self).__init__(*args, **kwargs)
self.dropdown_cls.max_height = Window.size[1] / 3
class Allmails(Screen):
"""All mails Screen uses screen to show widgets of screens"""
data = ListProperty()
has_refreshed = True
all_mails = ListProperty()
account = StringProperty()
def __init__(self, *args, **kwargs):
"""Method Parsing the address."""
super(Allmails, self).__init__(*args, **kwargs)
if state.association == '':
if BMConfigParser().addresses():
state.association = BMConfigParser().addresses()[0]
Clock.schedule_once(self.init_ui, 0)
def init_ui(self, dt=0):
"""Clock Schdule for method all mails"""
self.loadMessagelist()
print dt
def loadMessagelist(self):
"""Load Inbox, Sent anf Draft list of messages."""
self.account = state.association
self.ids.identi_tag.children[0].text = ''
self.allMessageQuery(0, 20)
if self.all_mails:
self.ids.identi_tag.children[0].text = 'All Mails'
state.kivyapp.get_inbox_count()
state.kivyapp.get_sent_count()
state.all_count = str(
int(state.sent_count) + int(state.inbox_count))
state.kivyapp.root.children[2].children[
0].ids.allmail_cnt.badge_text = state.all_count
self.set_mdlist()
# self.ids.refresh_layout.bind(scroll_y=self.check_scroll_y)
self.ids.scroll_y.bind(scroll_y=self.check_scroll_y)
else:
content = MDLabel(
font_style='Body1', theme_text_color='Primary',
text="yet no message for this account!!!!!!!!!!!!!",
halign='center', bold=True, size_hint_y=None, valign='top')
self.ids.ml.add_widget(content)
def allMessageQuery(self, start_indx, end_indx):
"""Retrieving data from inbox or sent both tables"""
self.all_mails = sqlQuery(
"SELECT toaddress, fromaddress, subject, message, folder, ackdata"
" As id, DATE(lastactiontime) As actionTime FROM sent WHERE"
" folder = 'sent' and fromaddress = '{0}'"
" UNION SELECT toaddress, fromaddress, subject, message, folder,"
" msgid As id, DATE(received) As actionTime FROM inbox"
" WHERE folder = 'inbox' and toaddress = '{0}'"
" ORDER BY actionTime DESC limit {1}, {2}".format(
self.account, start_indx, end_indx))
def set_mdlist(self):
"""This method is used to create mdList for allmaills"""
data_exist = len(self.ids.ml.children)
for item in self.all_mails:
meny = CustomAvatarIconListItem(
text=item[1],
secondary_text=item[2][:50] + '........' if len(
item[2]) >= 50 else (
item[2] + ',' + item[3].replace(
'\n', ''))[0:50] + '........',
theme_text_color='Custom',
text_color=NavigateApp().theme_cls.primary_color)
meny.add_widget(AvatarSampleWidget(
source='./images/text_images/{}.png'.format(
avatarImageFirstLetter(item[2].strip()))))
meny.bind(on_press=partial(
self.mail_detail, item[5], item[4]))
carousel = Carousel(direction='right')
carousel.height = meny.height
carousel.size_hint_y = None
carousel.ignore_perpendicular_swipes = True
carousel.data_index = 0
carousel.min_move = 0.2
del_btn = Button(text='Delete')
del_btn.background_normal = ''
del_btn.background_color = (1, 0, 0, 1)
del_btn.bind(on_press=partial(
self.swipe_delete, item[5], item[4]))
carousel.add_widget(del_btn)
carousel.add_widget(meny)
carousel.index = 1
self.ids.ml.add_widget(carousel)
updated_data = len(self.ids.ml.children)
self.has_refreshed = True if data_exist != updated_data else False
def check_scroll_y(self, instance, somethingelse):
"""Scroll fixed length"""
if self.ids.scroll_y.scroll_y <= -0.00 and self.has_refreshed:
self.ids.scroll_y.scroll_y = .06
load_more = len(self.ids.ml.children)
self.updating_allmail(load_more)
else:
pass
def updating_allmail(self, load_more):
"""This method is used to update the all mail
listing value on the scroll of screen"""
self.allMessageQuery(load_more, 5)
self.set_mdlist()
def mail_detail(self, unique_id, folder, *args):
"""Load sent and inbox mail details"""
state.detailPageType = folder
state.is_allmail = True
state.mail_id = unique_id
if self.manager:
src_mng_obj = self.manager
else:
src_mng_obj = self.parent.parent
src_mng_obj.screens[13].clear_widgets()
src_mng_obj.screens[13].add_widget(MailDetail())
src_mng_obj.current = 'mailDetail'
def swipe_delete(self, unique_id, folder, instance, *args):
"""Delete inbox mail from all mail listing"""
if folder == 'inbox':
sqlExecute(
"UPDATE inbox SET folder = 'trash' WHERE msgid = ?;",
str(unique_id))
else:
sqlExecute(
"UPDATE sent SET folder = 'trash' WHERE ackdata = ?;",
str(unique_id))
self.ids.ml.remove_widget(instance.parent.parent)
try:
msg_count_objs = self.parent.parent.parent.parent.parent.children[
2].children[0].ids
nav_lay_obj = self.parent.parent.parent.parent.parent.ids
except Exception:
msg_count_objs = self.parent.parent.parent.parent.parent.parent.children[
2].children[0].ids
nav_lay_obj = self.parent.parent.parent.parent.parent.parent.ids
if folder == 'inbox':
msg_count_objs.inbox_cnt.badge_text = str(
int(state.inbox_count) - 1)
state.inbox_count = str(int(state.inbox_count) - 1)
nav_lay_obj.sc1.ids.ml.clear_widgets()
nav_lay_obj.sc1.loadMessagelist(state.association)
else:
msg_count_objs.send_cnt.badge_text = str(int(state.sent_count) - 1)
state.sent_count = str(int(state.sent_count) - 1)
nav_lay_obj.sc4.ids.ml.clear_widgets()
nav_lay_obj.sc4.loadSent(state.association)
msg_count_objs.trash_cnt.badge_text = str(int(state.trash_count) + 1)
msg_count_objs.allmail_cnt.badge_text = str(int(state.all_count) - 1)
state.trash_count = str(int(state.trash_count) + 1)
state.all_count = str(int(state.all_count) - 1)
if int(state.all_count) <= 0:
self.ids.identi_tag.children[0].text = ''
nav_lay_obj.sc5.clear_widgets()
nav_lay_obj.sc5.add_widget(Trash())
nav_lay_obj.sc17.remove_widget(instance.parent.parent)
# pylint: disable=attribute-defined-outside-init
def refresh_callback(self, *args):
"""Method updates the state of application,
While the spinner remains on the screen"""
def refresh_callback(interval):
"""Load the allmails screen data"""
self.ids.ml.clear_widgets()
self.remove_widget(self.children[1])
try:
screens_obj = self.parent.screens[16]
except Exception:
screens_obj = self.parent.parent.screens[16]
screens_obj.add_widget(Allmails())
self.ids.refresh_layout.refresh_done()
self.tick = 0
Clock.schedule_once(refresh_callback, 1)
def set_root_layout(self):
"""Setting root layout"""
try:
return self.manager.parent.parent
except Exception:
return state.kivyapp.root.ids.float_box
def avatarImageFirstLetter(letter_string):
"""This function is used to the first letter for the avatar image"""
try:
if letter_string[0].upper() >= 'A' and letter_string[0].upper() <= 'Z':
img_latter = letter_string[0].upper()
elif int(letter_string[0]) >= 0 and int(letter_string[0]) <= 9:
img_latter = letter_string[0]
else:
img_latter = '!'
except ValueError as e:
img_latter = '!'
return img_latter if img_latter else '!'
class Starred(Screen):
"""Starred Screen show widgets of page"""
pass
class Archieve(Screen):
"""Archieve Screen show widgets of page"""
pass
class Spam(Screen):
"""Spam Screen show widgets of page"""
pass
class LoadingPopup(Popup):
"""Class for loading Popup"""
def __init__(self, **kwargs):
super(LoadingPopup, self).__init__(**kwargs)
# call dismiss_popup in 2 seconds
Clock.schedule_once(self.dismiss_popup, 0.5)
def dismiss_popup(self, dt):
"""Dismiss popups"""
self.dismiss()

View File

@ -1,28 +0,0 @@
"""
Ui Singnaler for kivy interface
"""
from threading import Thread
import queues
import state
from semaphores import kivyuisignaler
class UIkivySignaler(Thread):
"""Kivy ui signaler"""
def run(self):
kivyuisignaler.acquire()
while state.shutdown == 0:
try:
command, data = queues.UISignalQueue.get()
if command == 'writeNewAddressToTable':
address = data[1]
state.kivyapp.variable_1.append(address)
# elif command == 'rerenderAddressBook':
# state.kivyapp.obj_1.refreshs()
# Need to discuss this
elif command == 'updateSentItemStatusByAckdata':
state.kivyapp.status_dispatching(data)
except Exception as e:
print e

View File

@ -1,16 +1,25 @@
#!/usr/bin/python2.7 #!/usr/bin/python2.7
"""
The PyBitmessage startup script
"""
# Copyright (c) 2012-2016 Jonathan Warren # Copyright (c) 2012-2016 Jonathan Warren
# Copyright (c) 2012-2020 The Bitmessage developers # Copyright (c) 2012-2019 The Bitmessage developers
# Distributed under the MIT/X11 software license. See the accompanying # Distributed under the MIT/X11 software license. See the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
# Right now, PyBitmessage only support connecting to stream 1. It doesn't # Right now, PyBitmessage only support connecting to stream 1. It doesn't
# yet contain logic to expand into further streams. # yet contain logic to expand into further streams.
# The software version variable is now held in shared.py
import os import os
import sys import sys
app_dir = os.path.dirname(os.path.abspath(__file__))
os.chdir(app_dir)
sys.path.insert(0, app_dir)
import depends
depends.check_dependencies()
import ctypes import ctypes
import getopt import getopt
import multiprocessing import multiprocessing
@ -22,40 +31,43 @@ import time
import traceback import traceback
from struct import pack from struct import pack
import defaults
import depends
import shared
import shutdown
import state
from bmconfigparser import BMConfigParser
from debug import logger # this should go before any threads
from helper_startup import ( from helper_startup import (
isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections, isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections
start_proxyconfig
)
from inventory import Inventory
from knownnodes import readKnownNodes
# Network objects and threads
from network import (
BMConnectionPool, Dandelion, AddrThread, AnnounceThread, BMNetworkThread,
InvThread, ReceiveQueueThread, DownloadThread, UploadThread
) )
from singleinstance import singleinstance from singleinstance import singleinstance
# Synchronous threads
from threads import (
set_thread_name, addressGenerator, objectProcessor, singleCleaner,
singleWorker, sqlThread
)
app_dir = os.path.dirname(os.path.abspath(__file__)) import defaults
os.chdir(app_dir) import shared
sys.path.insert(0, app_dir) import knownnodes
import state
import shutdown
from debug import logger
depends.check_dependencies() # Classes
from class_sqlThread import sqlThread
from class_singleCleaner import singleCleaner
from class_objectProcessor import objectProcessor
from class_singleWorker import singleWorker
from class_addressGenerator import addressGenerator
from bmconfigparser import BMConfigParser
from inventory import Inventory
from network.connectionpool import BMConnectionPool
from network.dandelion import Dandelion
from network.networkthread import BMNetworkThread
from network.receivequeuethread import ReceiveQueueThread
from network.announcethread import AnnounceThread
from network.invthread import InvThread
from network.addrthread import AddrThread
from network.downloadthread import DownloadThread
from network.uploadthread import UploadThread
# Helper Functions
import helper_threading
def connectToStream(streamNumber): def connectToStream(streamNumber):
"""Connect to a stream"""
state.streamsInWhichIAmParticipating.append(streamNumber) state.streamsInWhichIAmParticipating.append(streamNumber)
if isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections(): if isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections():
@ -72,6 +84,14 @@ def connectToStream(streamNumber):
except: except:
pass pass
with knownnodes.knownNodesLock:
if streamNumber not in knownnodes.knownNodes:
knownnodes.knownNodes[streamNumber] = {}
if streamNumber*2 not in knownnodes.knownNodes:
knownnodes.knownNodes[streamNumber*2] = {}
if streamNumber*2+1 not in knownnodes.knownNodes:
knownnodes.knownNodes[streamNumber*2+1] = {}
BMConnectionPool().connectToStream(streamNumber) BMConnectionPool().connectToStream(streamNumber)
@ -88,8 +108,6 @@ def _fixSocket():
addressToString = ctypes.windll.ws2_32.WSAAddressToStringA addressToString = ctypes.windll.ws2_32.WSAAddressToStringA
def inet_ntop(family, host): def inet_ntop(family, host):
"""Converting an IP address in packed
binary format to string format"""
if family == socket.AF_INET: if family == socket.AF_INET:
if len(host) != 4: if len(host) != 4:
raise ValueError("invalid IPv4 host") raise ValueError("invalid IPv4 host")
@ -111,8 +129,6 @@ def _fixSocket():
stringToAddress = ctypes.windll.ws2_32.WSAStringToAddressA stringToAddress = ctypes.windll.ws2_32.WSAStringToAddressA
def inet_pton(family, host): def inet_pton(family, host):
"""Converting an IP address in string format
to a packed binary format"""
buf = "\0" * 28 buf = "\0" * 28
lengthBuf = pack("I", len(buf)) lengthBuf = pack("I", len(buf))
if stringToAddress(str(host), if stringToAddress(str(host),
@ -153,32 +169,29 @@ def signal_handler(signum, frame):
if thread.name not in ("PyBitmessage", "MainThread"): if thread.name not in ("PyBitmessage", "MainThread"):
return return
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
# which should shutdown especially test-mode # especially test-mode
if shared.thisapp.daemon or not state.enableGUI: if shared.thisapp.daemon or not state.enableGUI:
shutdown.doCleanShutdown() shutdown.doCleanShutdown()
else: else:
print '# Thread: %s(%d)' % (thread.name, thread.ident) print('# Thread: %s(%d)' % (thread.name, thread.ident))
for filename, lineno, name, line in traceback.extract_stack(frame): for filename, lineno, name, line in traceback.extract_stack(frame):
print 'File: "%s", line %d, in %s' % (filename, lineno, name) print('File: "%s", line %d, in %s' % (filename, lineno, name))
if line: if line:
print ' %s' % line.strip() print(' %s' % line.strip())
print 'Unfortunately you cannot use Ctrl+C when running the UI \ print('Unfortunately you cannot use Ctrl+C when running the UI'
because the UI captures the signal.' ' because the UI captures the signal.')
class Main(object): class Main:
"""Main PyBitmessage class"""
def start(self): def start(self):
"""Start main application"""
# pylint: disable=too-many-statements,too-many-branches,too-many-locals
_fixSocket() _fixSocket()
config = BMConfigParser() daemon = BMConfigParser().safeGetBoolean(
daemon = config.safeGetBoolean('bitmessagesettings', 'daemon') 'bitmessagesettings', 'daemon')
try: try:
opts, _ = getopt.getopt( opts, args = getopt.getopt(
sys.argv[1:], "hcdt", sys.argv[1:], "hcdt",
["help", "curses", "daemon", "test"]) ["help", "curses", "daemon", "test"])
@ -186,7 +199,7 @@ class Main(object):
self.usage() self.usage()
sys.exit(2) sys.exit(2)
for opt, _ in opts: for opt, arg in opts:
if opt in ("-h", "--help"): if opt in ("-h", "--help"):
self.usage() self.usage()
sys.exit() sys.exit()
@ -203,6 +216,7 @@ class Main(object):
# Fallback: in case when no api command was issued # Fallback: in case when no api command was issued
state.last_api_response = time.time() state.last_api_response = time.time()
# Apply special settings # Apply special settings
config = BMConfigParser()
config.set( config.set(
'bitmessagesettings', 'apienabled', 'true') 'bitmessagesettings', 'apienabled', 'true')
config.set( config.set(
@ -217,8 +231,7 @@ class Main(object):
if daemon: if daemon:
state.enableGUI = False # run without a UI state.enableGUI = False # run without a UI
# is the application already running? If yes then exit. if state.enableGUI and not state.curses and not depends.check_pyqt():
if state.enableGUI and not state.curses and not state.kivy and not depends.check_pyqt():
sys.exit( sys.exit(
'PyBitmessage requires PyQt unless you want' 'PyBitmessage requires PyQt unless you want'
' to run it as a daemon and interact with it' ' to run it as a daemon and interact with it'
@ -232,36 +245,32 @@ 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:
shared.thisapp = singleinstance("", daemon) shared.thisapp = singleinstance("", daemon)
except Exception:
pass
if daemon: if daemon:
with shared.printLock: with shared.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()
self.setSignalHandler() self.setSignalHandler()
set_thread_name("PyBitmessage") helper_threading.set_thread_name("PyBitmessage")
state.dandelion = config.safeGetInt('network', 'dandelion') state.dandelion = BMConfigParser().safeGetInt('network', 'dandelion')
# dandelion requires outbound connections, without them, # dandelion requires outbound connections, without them,
# stem objects will get stuck forever # stem objects will get stuck forever
if state.dandelion and not config.safeGetBoolean( if state.dandelion and not BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'sendoutgoingconnections'): 'bitmessagesettings', 'sendoutgoingconnections'):
state.dandelion = 0 state.dandelion = 0
if state.testmode or config.safeGetBoolean( if state.testmode or BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'extralowdifficulty'): 'bitmessagesettings', 'extralowdifficulty'):
defaults.networkDefaultProofOfWorkNonceTrialsPerByte = int( defaults.networkDefaultProofOfWorkNonceTrialsPerByte = int(
defaults.networkDefaultProofOfWorkNonceTrialsPerByte / 100) defaults.networkDefaultProofOfWorkNonceTrialsPerByte / 100)
defaults.networkDefaultPayloadLengthExtraBytes = int( defaults.networkDefaultPayloadLengthExtraBytes = int(
defaults.networkDefaultPayloadLengthExtraBytes / 100) defaults.networkDefaultPayloadLengthExtraBytes / 100)
readKnownNodes() knownnodes.readKnownNodes()
# Not needed if objproc is disabled # Not needed if objproc is disabled
if state.enableObjProc: if state.enableObjProc:
@ -284,21 +293,24 @@ class Main(object):
# The closeEvent should command this thread to exit gracefully. # The closeEvent should command this thread to exit gracefully.
sqlLookup.daemon = False sqlLookup.daemon = False
sqlLookup.start() sqlLookup.start()
Inventory() # init Inventory() # init
# init, needs to be early because other thread may access it early # init, needs to be early because other thread may access it early
Dandelion() Dandelion()
# Enable object processor and SMTP only if objproc enabled # Enable object processor and SMTP only if objproc enabled
if state.enableObjProc: if state.enableObjProc:
# SMTP delivery thread # SMTP delivery thread
if daemon and config.safeGet( if daemon and BMConfigParser().safeGet(
'bitmessagesettings', 'smtpdeliver', '') != '': "bitmessagesettings", "smtpdeliver", '') != '':
from class_smtpDeliver import smtpDeliver from class_smtpDeliver import smtpDeliver
smtpDeliveryThread = smtpDeliver() smtpDeliveryThread = smtpDeliver()
smtpDeliveryThread.start() smtpDeliveryThread.start()
# SMTP daemon thread # SMTP daemon thread
if daemon and config.safeGetBoolean( if daemon and BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'smtpd'): "bitmessagesettings", "smtpd"):
from class_smtpServer import smtpServer from class_smtpServer import smtpServer
smtpServerThread = smtpServer() smtpServerThread = smtpServer()
smtpServerThread.start() smtpServerThread.start()
@ -310,30 +322,33 @@ class Main(object):
# each object. # each object.
objectProcessorThread.daemon = False objectProcessorThread.daemon = False
objectProcessorThread.start() objectProcessorThread.start()
# Start the cleanerThread # Start the cleanerThread
singleCleanerThread = singleCleaner() singleCleanerThread = singleCleaner()
# close the main program even if there are threads left # close the main program even if there are threads left
singleCleanerThread.daemon = True singleCleanerThread.daemon = True
singleCleanerThread.start() singleCleanerThread.start()
# Not needed if objproc disabled # Not needed if objproc disabled
if state.enableObjProc: if state.enableObjProc:
shared.reloadMyAddressHashes() shared.reloadMyAddressHashes()
shared.reloadBroadcastSendersForWhichImWatching() shared.reloadBroadcastSendersForWhichImWatching()
# API is also objproc dependent # API is also objproc dependent
if config.safeGetBoolean('bitmessagesettings', 'apienabled'): if BMConfigParser().safeGetBoolean('bitmessagesettings', 'apienabled'):
import api # pylint: disable=relative-import import api # pylint: disable=relative-import
singleAPIThread = api.singleAPI() singleAPIThread = api.singleAPI()
# close the main program even if there are threads left # close the main program even if there are threads left
singleAPIThread.daemon = True singleAPIThread.daemon = True
singleAPIThread.start() singleAPIThread.start()
# start network components if networking is enabled # start network components if networking is enabled
if state.enableNetwork: if state.enableNetwork:
start_proxyconfig()
BMConnectionPool() BMConnectionPool()
asyncoreThread = BMNetworkThread() asyncoreThread = BMNetworkThread()
asyncoreThread.daemon = True asyncoreThread.daemon = True
asyncoreThread.start() asyncoreThread.start()
for i in range(config.getint('threads', 'receive')): for i in range(BMConfigParser().getint("threads", "receive")):
receiveQueueThread = ReceiveQueueThread(i) receiveQueueThread = ReceiveQueueThread(i)
receiveQueueThread.daemon = True receiveQueueThread.daemon = True
receiveQueueThread.start() receiveQueueThread.start()
@ -354,43 +369,41 @@ class Main(object):
state.uploadThread.start() state.uploadThread.start()
connectToStream(1) connectToStream(1)
if config.safeGetBoolean('bitmessagesettings', 'upnp'):
if BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'upnp'):
import upnp import upnp
upnpThread = upnp.uPnPThread() upnpThread = upnp.uPnPThread()
upnpThread.start() upnpThread.start()
else: else:
# Populate with hardcoded value (same as connectToStream above) # Populate with hardcoded value (same as connectToStream above)
state.streamsInWhichIAmParticipating.append(1) state.streamsInWhichIAmParticipating.append(1)
if not daemon and state.enableGUI: if not daemon and state.enableGUI:
if state.curses: if state.curses:
if not depends.check_curses(): if not depends.check_curses():
sys.exit() sys.exit()
print 'Running with curses' print('Running with curses')
import bitmessagecurses import bitmessagecurses
bitmessagecurses.runwrapper() bitmessagecurses.runwrapper()
elif state.kivy: elif state.kivy:
config.remove_option('bitmessagesettings', 'dontconnect') BMConfigParser().remove_option('bitmessagesettings', 'dontconnect')
from bitmessagekivy.mpybit import NavigateApp from bitmessagekivy.mpybit import NavigateApp
state.kivyapp = NavigateApp() NavigateApp().run()
state.kivyapp.run()
else: else:
import bitmessageqt import bitmessageqt
bitmessageqt.run() bitmessageqt.run()
else: else:
config.remove_option('bitmessagesettings', 'dontconnect') BMConfigParser().remove_option('bitmessagesettings', 'dontconnect')
if daemon: if daemon:
while state.shutdown == 0: while state.shutdown == 0:
time.sleep(1) time.sleep(1)
if ( if (state.testmode and
state.testmode and time.time() - time.time() - state.last_api_response >= 30):
state.last_api_response >= 30
):
self.stop() self.stop()
elif not state.enableGUI: elif not state.enableGUI:
# pylint: disable=relative-import from tests import core as test_core # pylint: disable=relative-import
from tests import core as test_core
test_core_result = test_core.run() test_core_result = test_core.run()
state.enableGUI = True state.enableGUI = True
self.stop() self.stop()
@ -401,9 +414,7 @@ class Main(object):
else 0 else 0
) )
@staticmethod def daemonize(self):
def daemonize():
"""Running as a daemon. Send signal in end."""
grandfatherPid = os.getpid() grandfatherPid = os.getpid()
parentPid = None parentPid = None
try: try:
@ -413,8 +424,7 @@ class Main(object):
# wait until grandchild ready # wait until grandchild ready
while True: while True:
time.sleep(1) time.sleep(1)
os._exit(0)
os._exit(0) # pylint: disable=protected-access
except AttributeError: except AttributeError:
# fork not implemented # fork not implemented
pass pass
@ -435,7 +445,7 @@ class Main(object):
# wait until child ready # wait until child ready
while True: while True:
time.sleep(1) time.sleep(1)
os._exit(0) # pylint: disable=protected-access os._exit(0)
except AttributeError: except AttributeError:
# fork not implemented # fork not implemented
pass pass
@ -456,18 +466,14 @@ class Main(object):
os.kill(parentPid, signal.SIGTERM) os.kill(parentPid, signal.SIGTERM)
os.kill(grandfatherPid, signal.SIGTERM) os.kill(grandfatherPid, signal.SIGTERM)
@staticmethod def setSignalHandler(self):
def setSignalHandler():
"""Setting the Signal Handler"""
signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler) signal.signal(signal.SIGTERM, signal_handler)
# signal.signal(signal.SIGINT, signal.SIG_DFL) # signal.signal(signal.SIGINT, signal.SIG_DFL)
@staticmethod def usage(self):
def usage(): print 'Usage: ' + sys.argv[0] + ' [OPTIONS]'
"""Displaying the usages""" print '''
print('Usage: ' + sys.argv[0] + ' [OPTIONS]')
print('''
Options: Options:
-h, --help show this help message and exit -h, --help show this help message and exit
-c, --curses use curses (text mode) interface -c, --curses use curses (text mode) interface
@ -475,19 +481,15 @@ Options:
-t, --test dryrun, make testing -t, --test dryrun, make testing
All parameters are optional. All parameters are optional.
''') '''
@staticmethod def stop(self):
def stop():
"""Stop main application"""
with shared.printLock: with shared.printLock:
print 'Stopping Bitmessage Deamon.' print('Stopping Bitmessage Deamon.')
shutdown.doCleanShutdown() shutdown.doCleanShutdown()
# .. todo:: nice function but no one is using this # TODO: nice function but no one is using this
@staticmethod def getApiAddress(self):
def getApiAddress():
"""This function returns API address and port"""
if not BMConfigParser().safeGetBoolean( if not BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'apienabled'): 'bitmessagesettings', 'apienabled'):
return None return None
@ -497,7 +499,6 @@ All parameters are optional.
def main(): def main():
"""Triggers main module"""
mainprogram = Main() mainprogram = Main()
mainprogram.start() mainprogram.start()

View File

@ -23,6 +23,7 @@ from addresses import decodeAddress, addBMIfNotPresent
import shared import shared
from bitmessageui import Ui_MainWindow from bitmessageui import Ui_MainWindow
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
import defaults
import namecoin import namecoin
from messageview import MessageView from messageview import MessageView
from migrationwizard import Ui_MigrationWizard from migrationwizard import Ui_MigrationWizard
@ -30,12 +31,15 @@ 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)
from settings import Ui_settingsDialog
import settingsmixin import settingsmixin
import support import support
import debug
from helper_ackPayload import genAckPayload from helper_ackPayload import genAckPayload
from helper_sql import sqlQuery, sqlExecute, sqlExecuteChunked, sqlStoredProcedure from helper_sql import sqlQuery, sqlExecute, sqlExecuteChunked, sqlStoredProcedure
import helper_search import helper_search
import l10n import l10n
import openclpow
from utils import str_broadcast_subscribers, avatarize from utils import str_broadcast_subscribers, avatarize
from account import ( from account import (
getSortedAccounts, getSortedSubscriptions, accountClass, BMAccount, getSortedAccounts, getSortedSubscriptions, accountClass, BMAccount,
@ -43,15 +47,16 @@ from account import (
import dialogs import dialogs
from network.stats import pendingDownload, pendingUpload from network.stats import pendingDownload, pendingUpload
from uisignaler import UISignaler from uisignaler import UISignaler
import knownnodes
import paths import paths
from proofofwork import getPowType from proofofwork import getPowType
import queues import queues
import shutdown import shutdown
import state import state
from statusbar import BMStatusBar from statusbar import BMStatusBar
from network.asyncore_pollchoose import set_rates
import sound import sound
# This is needed for tray icon
import bitmessage_icons_rc # noqa:F401 pylint: disable=unused-import
try: try:
from plugins.plugin import get_plugin, get_plugins from plugins.plugin import get_plugin, get_plugins
@ -59,6 +64,49 @@ except ImportError:
get_plugins = False get_plugins = False
def change_translation(newlocale):
global qmytranslator, qsystranslator
try:
if not qmytranslator.isEmpty():
QtGui.QApplication.removeTranslator(qmytranslator)
except:
pass
try:
if not qsystranslator.isEmpty():
QtGui.QApplication.removeTranslator(qsystranslator)
except:
pass
qmytranslator = QtCore.QTranslator()
translationpath = os.path.join (paths.codePath(), 'translations', 'bitmessage_' + newlocale)
qmytranslator.load(translationpath)
QtGui.QApplication.installTranslator(qmytranslator)
qsystranslator = QtCore.QTranslator()
if paths.frozen:
translationpath = os.path.join (paths.codePath(), 'translations', 'qt_' + newlocale)
else:
translationpath = os.path.join (str(QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.TranslationsPath)), 'qt_' + newlocale)
qsystranslator.load(translationpath)
QtGui.QApplication.installTranslator(qsystranslator)
lang = locale.normalize(l10n.getTranslationLanguage())
langs = [lang.split(".")[0] + "." + l10n.encoding, lang.split(".")[0] + "." + 'UTF-8', lang]
if 'win32' in sys.platform or 'win64' in sys.platform:
langs = [l10n.getWindowsLocale(lang)]
for lang in langs:
try:
l10n.setlocale(locale.LC_ALL, lang)
if 'win32' not in sys.platform and 'win64' not in sys.platform:
l10n.encoding = locale.nl_langinfo(locale.CODESET)
else:
l10n.encoding = locale.getlocale()[1]
logger.info("Successfully set locale to %s", lang)
break
except:
logger.error("Failed to set locale to %s", lang, exc_info=True)
# TODO: rewrite # TODO: rewrite
def powQueueSize(): def powQueueSize():
"""Returns the size of queues.workerQueue including current unfinished work""" """Returns the size of queues.workerQueue including current unfinished work"""
@ -74,6 +122,9 @@ def powQueueSize():
class MyForm(settingsmixin.SMainWindow): class MyForm(settingsmixin.SMainWindow):
# the last time that a message arrival sound was played
lastSoundTime = datetime.now() - timedelta(days=1)
# the maximum frequency of message sounds in seconds # the maximum frequency of message sounds in seconds
maxSoundFrequencySec = 60 maxSoundFrequencySec = 60
@ -81,58 +132,6 @@ class MyForm(settingsmixin.SMainWindow):
REPLY_TYPE_CHAN = 1 REPLY_TYPE_CHAN = 1
REPLY_TYPE_UPD = 2 REPLY_TYPE_UPD = 2
def change_translation(self, newlocale=None):
"""Change translation language for the application"""
if newlocale is None:
newlocale = l10n.getTranslationLanguage()
try:
if not self.qmytranslator.isEmpty():
QtGui.QApplication.removeTranslator(self.qmytranslator)
except:
pass
try:
if not self.qsystranslator.isEmpty():
QtGui.QApplication.removeTranslator(self.qsystranslator)
except:
pass
self.qmytranslator = QtCore.QTranslator()
translationpath = os.path.join(
paths.codePath(), 'translations', 'bitmessage_' + newlocale)
self.qmytranslator.load(translationpath)
QtGui.QApplication.installTranslator(self.qmytranslator)
self.qsystranslator = QtCore.QTranslator()
if paths.frozen:
translationpath = os.path.join(
paths.codePath(), 'translations', 'qt_' + newlocale)
else:
translationpath = os.path.join(
str(QtCore.QLibraryInfo.location(
QtCore.QLibraryInfo.TranslationsPath)), 'qt_' + newlocale)
self.qsystranslator.load(translationpath)
QtGui.QApplication.installTranslator(self.qsystranslator)
lang = locale.normalize(l10n.getTranslationLanguage())
langs = [
lang.split(".")[0] + "." + l10n.encoding,
lang.split(".")[0] + "." + 'UTF-8',
lang
]
if 'win32' in sys.platform or 'win64' in sys.platform:
langs = [l10n.getWindowsLocale(lang)]
for lang in langs:
try:
l10n.setlocale(locale.LC_ALL, lang)
if 'win32' not in sys.platform and 'win64' not in sys.platform:
l10n.encoding = locale.nl_langinfo(locale.CODESET)
else:
l10n.encoding = locale.getlocale()[1]
logger.info("Successfully set locale to %s", lang)
break
except:
logger.error("Failed to set locale to %s", lang, exc_info=True)
def init_file_menu(self): def init_file_menu(self):
QtCore.QObject.connect(self.ui.actionExit, QtCore.SIGNAL( QtCore.QObject.connect(self.ui.actionExit, QtCore.SIGNAL(
"triggered()"), self.quit) "triggered()"), self.quit)
@ -606,13 +605,6 @@ class MyForm(settingsmixin.SMainWindow):
self.ui = Ui_MainWindow() self.ui = Ui_MainWindow()
self.ui.setupUi(self) self.ui.setupUi(self)
self.qmytranslator = self.qsystranslator = None
self.indicatorUpdate = None
self.actionStatus = None
# the last time that a message arrival sound was played
self.lastSoundTime = datetime.now() - timedelta(days=1)
# Ask the user if we may delete their old version 1 addresses if they # Ask the user if we may delete their old version 1 addresses if they
# have any. # have any.
for addressInKeysFile in getSortedAccounts(): for addressInKeysFile in getSortedAccounts():
@ -628,9 +620,22 @@ class MyForm(settingsmixin.SMainWindow):
BMConfigParser().remove_section(addressInKeysFile) BMConfigParser().remove_section(addressInKeysFile)
BMConfigParser().save() BMConfigParser().save()
self.updateStartOnLogon() # Configure Bitmessage to start on startup (or remove the
# configuration) based on the setting in the keys.dat file
self.change_translation() if 'win32' in sys.platform or 'win64' in sys.platform:
# Auto-startup for Windows
RUN_PATH = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"
self.settings = QtCore.QSettings(RUN_PATH, QtCore.QSettings.NativeFormat)
self.settings.remove(
"PyBitmessage") # In case the user moves the program and the registry entry is no longer valid, this will delete the old registry entry.
if BMConfigParser().getboolean('bitmessagesettings', 'startonlogon'):
self.settings.setValue("PyBitmessage", sys.argv[0])
elif 'darwin' in sys.platform:
# startup for mac
pass
elif 'linux' in sys.platform:
# startup for linux
pass
# e.g. for editing labels # e.g. for editing labels
self.recurDepth = 0 self.recurDepth = 0
@ -781,9 +786,6 @@ class MyForm(settingsmixin.SMainWindow):
self.ui.treeWidgetSubscriptions.keyPressEvent = self.treeWidgetKeyPressEvent self.ui.treeWidgetSubscriptions.keyPressEvent = self.treeWidgetKeyPressEvent
self.ui.treeWidgetChans.keyPressEvent = self.treeWidgetKeyPressEvent self.ui.treeWidgetChans.keyPressEvent = self.treeWidgetKeyPressEvent
# Key press in addressbook
self.ui.tableWidgetAddressBook.keyPressEvent = self.addressbookKeyPressEvent
# Key press in messagelist # Key press in messagelist
self.ui.tableWidgetInbox.keyPressEvent = self.tableWidgetKeyPressEvent self.ui.tableWidgetInbox.keyPressEvent = self.tableWidgetKeyPressEvent
self.ui.tableWidgetInboxSubscriptions.keyPressEvent = self.tableWidgetKeyPressEvent self.ui.tableWidgetInboxSubscriptions.keyPressEvent = self.tableWidgetKeyPressEvent
@ -826,28 +828,6 @@ class MyForm(settingsmixin.SMainWindow):
finally: finally:
self._contact_selected = None self._contact_selected = None
def updateStartOnLogon(self):
# Configure Bitmessage to start on startup (or remove the
# configuration) based on the setting in the keys.dat file
if 'win32' in sys.platform or 'win64' in sys.platform:
# Auto-startup for Windows
RUN_PATH = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"
self.settings = QtCore.QSettings(
RUN_PATH, QtCore.QSettings.NativeFormat)
# In case the user moves the program and the registry entry is
# no longer valid, this will delete the old registry entry.
self.settings.remove("PyBitmessage")
if BMConfigParser().getboolean(
'bitmessagesettings', 'startonlogon'
):
self.settings.setValue("PyBitmessage", sys.argv[0])
elif 'darwin' in sys.platform:
# startup for mac
pass
elif 'linux' in sys.platform:
# startup for linux
pass
def updateTTL(self, sliderPosition): def updateTTL(self, sliderPosition):
TTL = int(sliderPosition ** 3.199 + 3600) TTL = int(sliderPosition ** 3.199 + 3600)
self.updateHumanFriendlyTTLDescription(TTL) self.updateHumanFriendlyTTLDescription(TTL)
@ -1453,15 +1433,6 @@ class MyForm(settingsmixin.SMainWindow):
def treeWidgetKeyPressEvent(self, event): def treeWidgetKeyPressEvent(self, event):
return self.handleKeyPress(event, self.getCurrentTreeWidget()) return self.handleKeyPress(event, self.getCurrentTreeWidget())
# addressbook
def addressbookKeyPressEvent(self, event):
"""Handle keypress event in addressbook widget"""
if event.key() == QtCore.Qt.Key_Delete:
self.on_action_AddressBookDelete()
else:
return QtGui.QTableWidget.keyPressEvent(
self.ui.tableWidgetAddressBook, event)
# inbox / sent # inbox / sent
def tableWidgetKeyPressEvent(self, event): def tableWidgetKeyPressEvent(self, event):
return self.handleKeyPress(event, self.getCurrentMessagelist()) return self.handleKeyPress(event, self.getCurrentMessagelist())
@ -1471,7 +1442,6 @@ class MyForm(settingsmixin.SMainWindow):
return self.handleKeyPress(event, self.getCurrentMessageTextedit()) return self.handleKeyPress(event, self.getCurrentMessageTextedit())
def handleKeyPress(self, event, focus = None): def handleKeyPress(self, event, focus = None):
"""This method handles keypress events for all widgets on MyForm"""
messagelist = self.getCurrentMessagelist() messagelist = self.getCurrentMessagelist()
folder = self.getCurrentFolder() folder = self.getCurrentFolder()
if event.key() == QtCore.Qt.Key_Delete: if event.key() == QtCore.Qt.Key_Delete:
@ -1652,6 +1622,7 @@ class MyForm(settingsmixin.SMainWindow):
# The window state has just been changed to # The window state has just been changed to
# Normal/Maximised/FullScreen # Normal/Maximised/FullScreen
pass pass
# QtGui.QWidget.changeEvent(self, event)
def __icon_activated(self, reason): def __icon_activated(self, reason):
if reason == QtGui.QSystemTrayIcon.Trigger: if reason == QtGui.QSystemTrayIcon.Trigger:
@ -2463,7 +2434,225 @@ class MyForm(settingsmixin.SMainWindow):
dialogs.AboutDialog(self).exec_() dialogs.AboutDialog(self).exec_()
def click_actionSettings(self): def click_actionSettings(self):
dialogs.SettingsDialog(self, firstrun=self._firstrun).exec_() self.settingsDialogInstance = settingsDialog(self)
if self._firstrun:
self.settingsDialogInstance.ui.tabWidgetSettings.setCurrentIndex(1)
if self.settingsDialogInstance.exec_():
if self._firstrun:
BMConfigParser().remove_option(
'bitmessagesettings', 'dontconnect')
BMConfigParser().set('bitmessagesettings', 'startonlogon', str(
self.settingsDialogInstance.ui.checkBoxStartOnLogon.isChecked()))
BMConfigParser().set('bitmessagesettings', 'minimizetotray', str(
self.settingsDialogInstance.ui.checkBoxMinimizeToTray.isChecked()))
BMConfigParser().set('bitmessagesettings', 'trayonclose', str(
self.settingsDialogInstance.ui.checkBoxTrayOnClose.isChecked()))
BMConfigParser().set('bitmessagesettings', 'hidetrayconnectionnotifications', str(
self.settingsDialogInstance.ui.checkBoxHideTrayConnectionNotifications.isChecked()))
BMConfigParser().set('bitmessagesettings', 'showtraynotifications', str(
self.settingsDialogInstance.ui.checkBoxShowTrayNotifications.isChecked()))
BMConfigParser().set('bitmessagesettings', 'startintray', str(
self.settingsDialogInstance.ui.checkBoxStartInTray.isChecked()))
BMConfigParser().set('bitmessagesettings', 'willinglysendtomobile', str(
self.settingsDialogInstance.ui.checkBoxWillinglySendToMobile.isChecked()))
BMConfigParser().set('bitmessagesettings', 'useidenticons', str(
self.settingsDialogInstance.ui.checkBoxUseIdenticons.isChecked()))
BMConfigParser().set('bitmessagesettings', 'replybelow', str(
self.settingsDialogInstance.ui.checkBoxReplyBelow.isChecked()))
lang = str(self.settingsDialogInstance.ui.languageComboBox.itemData(self.settingsDialogInstance.ui.languageComboBox.currentIndex()).toString())
BMConfigParser().set('bitmessagesettings', 'userlocale', lang)
change_translation(l10n.getTranslationLanguage())
if int(BMConfigParser().get('bitmessagesettings', 'port')) != int(self.settingsDialogInstance.ui.lineEditTCPPort.text()):
if not BMConfigParser().safeGetBoolean('bitmessagesettings', 'dontconnect'):
QtGui.QMessageBox.about(self, _translate("MainWindow", "Restart"), _translate(
"MainWindow", "You must restart Bitmessage for the port number change to take effect."))
BMConfigParser().set('bitmessagesettings', 'port', str(
self.settingsDialogInstance.ui.lineEditTCPPort.text()))
if self.settingsDialogInstance.ui.checkBoxUPnP.isChecked() != BMConfigParser().safeGetBoolean('bitmessagesettings', 'upnp'):
BMConfigParser().set('bitmessagesettings', 'upnp', str(self.settingsDialogInstance.ui.checkBoxUPnP.isChecked()))
if self.settingsDialogInstance.ui.checkBoxUPnP.isChecked():
import upnp
upnpThread = upnp.uPnPThread()
upnpThread.start()
#print 'self.settingsDialogInstance.ui.comboBoxProxyType.currentText()', self.settingsDialogInstance.ui.comboBoxProxyType.currentText()
#print 'self.settingsDialogInstance.ui.comboBoxProxyType.currentText())[0:5]', self.settingsDialogInstance.ui.comboBoxProxyType.currentText()[0:5]
if BMConfigParser().get('bitmessagesettings', 'socksproxytype') == 'none' and self.settingsDialogInstance.ui.comboBoxProxyType.currentText()[0:5] == 'SOCKS':
if shared.statusIconColor != 'red':
QtGui.QMessageBox.about(self, _translate("MainWindow", "Restart"), _translate(
"MainWindow", "Bitmessage will use your proxy from now on but you may want to manually restart Bitmessage now to close existing connections (if any)."))
if BMConfigParser().get('bitmessagesettings', 'socksproxytype')[0:5] == 'SOCKS' and self.settingsDialogInstance.ui.comboBoxProxyType.currentText()[0:5] != 'SOCKS':
self.statusbar.clearMessage()
state.resetNetworkProtocolAvailability() # just in case we changed something in the network connectivity
if self.settingsDialogInstance.ui.comboBoxProxyType.currentText()[0:5] == 'SOCKS':
BMConfigParser().set('bitmessagesettings', 'socksproxytype', str(
self.settingsDialogInstance.ui.comboBoxProxyType.currentText()))
else:
BMConfigParser().set('bitmessagesettings', 'socksproxytype', 'none')
BMConfigParser().set('bitmessagesettings', 'socksauthentication', str(
self.settingsDialogInstance.ui.checkBoxAuthentication.isChecked()))
BMConfigParser().set('bitmessagesettings', 'sockshostname', str(
self.settingsDialogInstance.ui.lineEditSocksHostname.text()))
BMConfigParser().set('bitmessagesettings', 'socksport', str(
self.settingsDialogInstance.ui.lineEditSocksPort.text()))
BMConfigParser().set('bitmessagesettings', 'socksusername', str(
self.settingsDialogInstance.ui.lineEditSocksUsername.text()))
BMConfigParser().set('bitmessagesettings', 'sockspassword', str(
self.settingsDialogInstance.ui.lineEditSocksPassword.text()))
BMConfigParser().set('bitmessagesettings', 'sockslisten', str(
self.settingsDialogInstance.ui.checkBoxSocksListen.isChecked()))
try:
# Rounding to integers just for aesthetics
BMConfigParser().set('bitmessagesettings', 'maxdownloadrate', str(
int(float(self.settingsDialogInstance.ui.lineEditMaxDownloadRate.text()))))
BMConfigParser().set('bitmessagesettings', 'maxuploadrate', str(
int(float(self.settingsDialogInstance.ui.lineEditMaxUploadRate.text()))))
except ValueError:
QtGui.QMessageBox.about(self, _translate("MainWindow", "Number needed"), _translate(
"MainWindow", "Your maximum download and upload rate must be numbers. Ignoring what you typed."))
else:
set_rates(BMConfigParser().safeGetInt("bitmessagesettings", "maxdownloadrate"),
BMConfigParser().safeGetInt("bitmessagesettings", "maxuploadrate"))
BMConfigParser().set('bitmessagesettings', 'maxoutboundconnections', str(
int(float(self.settingsDialogInstance.ui.lineEditMaxOutboundConnections.text()))))
BMConfigParser().set('bitmessagesettings', 'namecoinrpctype',
self.settingsDialogInstance.getNamecoinType())
BMConfigParser().set('bitmessagesettings', 'namecoinrpchost', str(
self.settingsDialogInstance.ui.lineEditNamecoinHost.text()))
BMConfigParser().set('bitmessagesettings', 'namecoinrpcport', str(
self.settingsDialogInstance.ui.lineEditNamecoinPort.text()))
BMConfigParser().set('bitmessagesettings', 'namecoinrpcuser', str(
self.settingsDialogInstance.ui.lineEditNamecoinUser.text()))
BMConfigParser().set('bitmessagesettings', 'namecoinrpcpassword', str(
self.settingsDialogInstance.ui.lineEditNamecoinPassword.text()))
self.resetNamecoinConnection()
# Demanded difficulty tab
if float(self.settingsDialogInstance.ui.lineEditTotalDifficulty.text()) >= 1:
BMConfigParser().set('bitmessagesettings', 'defaultnoncetrialsperbyte', str(int(float(
self.settingsDialogInstance.ui.lineEditTotalDifficulty.text()) * defaults.networkDefaultProofOfWorkNonceTrialsPerByte)))
if float(self.settingsDialogInstance.ui.lineEditSmallMessageDifficulty.text()) >= 1:
BMConfigParser().set('bitmessagesettings', 'defaultpayloadlengthextrabytes', str(int(float(
self.settingsDialogInstance.ui.lineEditSmallMessageDifficulty.text()) * defaults.networkDefaultPayloadLengthExtraBytes)))
if self.settingsDialogInstance.ui.comboBoxOpenCL.currentText().toUtf8() != BMConfigParser().safeGet("bitmessagesettings", "opencl"):
BMConfigParser().set('bitmessagesettings', 'opencl', str(self.settingsDialogInstance.ui.comboBoxOpenCL.currentText()))
queues.workerQueue.put(('resetPoW', ''))
acceptableDifficultyChanged = False
if float(self.settingsDialogInstance.ui.lineEditMaxAcceptableTotalDifficulty.text()) >= 1 or float(self.settingsDialogInstance.ui.lineEditMaxAcceptableTotalDifficulty.text()) == 0:
if BMConfigParser().get('bitmessagesettings','maxacceptablenoncetrialsperbyte') != str(int(float(
self.settingsDialogInstance.ui.lineEditMaxAcceptableTotalDifficulty.text()) * defaults.networkDefaultProofOfWorkNonceTrialsPerByte)):
# the user changed the max acceptable total difficulty
acceptableDifficultyChanged = True
BMConfigParser().set('bitmessagesettings', 'maxacceptablenoncetrialsperbyte', str(int(float(
self.settingsDialogInstance.ui.lineEditMaxAcceptableTotalDifficulty.text()) * defaults.networkDefaultProofOfWorkNonceTrialsPerByte)))
if float(self.settingsDialogInstance.ui.lineEditMaxAcceptableSmallMessageDifficulty.text()) >= 1 or float(self.settingsDialogInstance.ui.lineEditMaxAcceptableSmallMessageDifficulty.text()) == 0:
if BMConfigParser().get('bitmessagesettings','maxacceptablepayloadlengthextrabytes') != str(int(float(
self.settingsDialogInstance.ui.lineEditMaxAcceptableSmallMessageDifficulty.text()) * defaults.networkDefaultPayloadLengthExtraBytes)):
# the user changed the max acceptable small message difficulty
acceptableDifficultyChanged = True
BMConfigParser().set('bitmessagesettings', 'maxacceptablepayloadlengthextrabytes', str(int(float(
self.settingsDialogInstance.ui.lineEditMaxAcceptableSmallMessageDifficulty.text()) * defaults.networkDefaultPayloadLengthExtraBytes)))
if acceptableDifficultyChanged:
# It might now be possible to send msgs which were previously marked as toodifficult.
# Let us change them to 'msgqueued'. The singleWorker will try to send them and will again
# mark them as toodifficult if the receiver's required difficulty is still higher than
# we are willing to do.
sqlExecute('''UPDATE sent SET status='msgqueued' WHERE status='toodifficult' ''')
queues.workerQueue.put(('sendmessage', ''))
#start: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.
if ((self.settingsDialogInstance.ui.lineEditDays.text()=='') and (self.settingsDialogInstance.ui.lineEditMonths.text()=='')):#We need to handle this special case. Bitmessage has its default behavior. The input is blank/blank
BMConfigParser().set('bitmessagesettings', 'stopresendingafterxdays', '')
BMConfigParser().set('bitmessagesettings', 'stopresendingafterxmonths', '')
shared.maximumLengthOfTimeToBotherResendingMessages = float('inf')
try:
float(self.settingsDialogInstance.ui.lineEditDays.text())
lineEditDaysIsValidFloat = True
except:
lineEditDaysIsValidFloat = False
try:
float(self.settingsDialogInstance.ui.lineEditMonths.text())
lineEditMonthsIsValidFloat = True
except:
lineEditMonthsIsValidFloat = False
if lineEditDaysIsValidFloat and not lineEditMonthsIsValidFloat:
self.settingsDialogInstance.ui.lineEditMonths.setText("0")
if lineEditMonthsIsValidFloat and not lineEditDaysIsValidFloat:
self.settingsDialogInstance.ui.lineEditDays.setText("0")
if lineEditDaysIsValidFloat or lineEditMonthsIsValidFloat:
if (float(self.settingsDialogInstance.ui.lineEditDays.text()) >=0 and float(self.settingsDialogInstance.ui.lineEditMonths.text()) >=0):
shared.maximumLengthOfTimeToBotherResendingMessages = (float(str(self.settingsDialogInstance.ui.lineEditDays.text())) * 24 * 60 * 60) + (float(str(self.settingsDialogInstance.ui.lineEditMonths.text())) * (60 * 60 * 24 *365)/12)
if shared.maximumLengthOfTimeToBotherResendingMessages < 432000: # If the time period is less than 5 hours, we give zero values to all fields. No message will be sent again.
QtGui.QMessageBox.about(self, _translate("MainWindow", "Will not resend ever"), _translate(
"MainWindow", "Note that the time limit you entered is less than the amount of time Bitmessage waits for the first resend attempt therefore your messages will never be resent."))
BMConfigParser().set('bitmessagesettings', 'stopresendingafterxdays', '0')
BMConfigParser().set('bitmessagesettings', 'stopresendingafterxmonths', '0')
shared.maximumLengthOfTimeToBotherResendingMessages = 0
else:
BMConfigParser().set('bitmessagesettings', 'stopresendingafterxdays', str(float(
self.settingsDialogInstance.ui.lineEditDays.text())))
BMConfigParser().set('bitmessagesettings', 'stopresendingafterxmonths', str(float(
self.settingsDialogInstance.ui.lineEditMonths.text())))
BMConfigParser().save()
if 'win32' in sys.platform or 'win64' in sys.platform:
# Auto-startup for Windows
RUN_PATH = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"
self.settings = QtCore.QSettings(RUN_PATH, QtCore.QSettings.NativeFormat)
if BMConfigParser().getboolean('bitmessagesettings', 'startonlogon'):
self.settings.setValue("PyBitmessage", sys.argv[0])
else:
self.settings.remove("PyBitmessage")
elif 'darwin' in sys.platform:
# startup for mac
pass
elif 'linux' in sys.platform:
# startup for linux
pass
if state.appdata != paths.lookupExeFolder() and self.settingsDialogInstance.ui.checkBoxPortableMode.isChecked(): # If we are NOT using portable mode now but the user selected that we should...
# Write the keys.dat file to disk in the new location
sqlStoredProcedure('movemessagstoprog')
with open(paths.lookupExeFolder() + 'keys.dat', 'wb') as configfile:
BMConfigParser().write(configfile)
# Write the knownnodes.dat file to disk in the new location
knownnodes.saveKnownNodes(paths.lookupExeFolder())
os.remove(state.appdata + 'keys.dat')
os.remove(state.appdata + 'knownnodes.dat')
previousAppdataLocation = state.appdata
state.appdata = paths.lookupExeFolder()
debug.resetLogging()
try:
os.remove(previousAppdataLocation + 'debug.log')
os.remove(previousAppdataLocation + 'debug.log.1')
except:
pass
if state.appdata == paths.lookupExeFolder() and not self.settingsDialogInstance.ui.checkBoxPortableMode.isChecked(): # If we ARE using portable mode now but the user selected that we shouldn't...
state.appdata = paths.lookupAppdataFolder()
if not os.path.exists(state.appdata):
os.makedirs(state.appdata)
sqlStoredProcedure('movemessagstoappdata')
# Write the keys.dat file to disk in the new location
BMConfigParser().save()
# Write the knownnodes.dat file to disk in the new location
knownnodes.saveKnownNodes(state.appdata)
os.remove(paths.lookupExeFolder() + 'keys.dat')
os.remove(paths.lookupExeFolder() + 'knownnodes.dat')
debug.resetLogging()
try:
os.remove(paths.lookupExeFolder() + 'debug.log')
os.remove(paths.lookupExeFolder() + 'debug.log.1')
except:
pass
def on_action_Send(self): def on_action_Send(self):
"""Send message to current selected address""" """Send message to current selected address"""
@ -3081,8 +3270,8 @@ class MyForm(settingsmixin.SMainWindow):
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
"UPDATE inbox SET folder='trash'") + "UPDATE inbox SET folder='trash'"
" WHERE msgid IN ({0})", idCount, *inventoryHashesToTrash) " 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)
@ -3204,7 +3393,8 @@ class MyForm(settingsmixin.SMainWindow):
0].row() 0].row()
item = self.ui.tableWidgetAddressBook.item(currentRow, 0) item = self.ui.tableWidgetAddressBook.item(currentRow, 0)
sqlExecute( sqlExecute(
'DELETE FROM addressbook WHERE address=?', item.address) 'DELETE FROM addressbook WHERE label=? AND address=?',
item.label, item.address)
self.ui.tableWidgetAddressBook.removeRow(currentRow) self.ui.tableWidgetAddressBook.removeRow(currentRow)
self.rerenderMessagelistFromLabels() self.rerenderMessagelistFromLabels()
self.rerenderMessagelistToLabels() self.rerenderMessagelistToLabels()
@ -4063,6 +4253,237 @@ class MyForm(settingsmixin.SMainWindow):
obj.loadSettings() obj.loadSettings()
class settingsDialog(QtGui.QDialog):
def __init__(self, parent):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_settingsDialog()
self.ui.setupUi(self)
self.parent = parent
self.ui.checkBoxStartOnLogon.setChecked(
BMConfigParser().getboolean('bitmessagesettings', 'startonlogon'))
self.ui.checkBoxMinimizeToTray.setChecked(
BMConfigParser().getboolean('bitmessagesettings', 'minimizetotray'))
self.ui.checkBoxTrayOnClose.setChecked(
BMConfigParser().safeGetBoolean('bitmessagesettings', 'trayonclose'))
self.ui.checkBoxHideTrayConnectionNotifications.setChecked(
BMConfigParser().getboolean("bitmessagesettings", "hidetrayconnectionnotifications"))
self.ui.checkBoxShowTrayNotifications.setChecked(
BMConfigParser().getboolean('bitmessagesettings', 'showtraynotifications'))
self.ui.checkBoxStartInTray.setChecked(
BMConfigParser().getboolean('bitmessagesettings', 'startintray'))
self.ui.checkBoxWillinglySendToMobile.setChecked(
BMConfigParser().safeGetBoolean('bitmessagesettings', 'willinglysendtomobile'))
self.ui.checkBoxUseIdenticons.setChecked(
BMConfigParser().safeGetBoolean('bitmessagesettings', 'useidenticons'))
self.ui.checkBoxReplyBelow.setChecked(
BMConfigParser().safeGetBoolean('bitmessagesettings', 'replybelow'))
if state.appdata == paths.lookupExeFolder():
self.ui.checkBoxPortableMode.setChecked(True)
else:
try:
import tempfile
tempfile.NamedTemporaryFile(
dir=paths.lookupExeFolder(), delete=True
).close() # should autodelete
except:
self.ui.checkBoxPortableMode.setDisabled(True)
if 'darwin' in sys.platform:
self.ui.checkBoxStartOnLogon.setDisabled(True)
self.ui.checkBoxStartOnLogon.setText(_translate(
"MainWindow", "Start-on-login not yet supported on your OS."))
self.ui.checkBoxMinimizeToTray.setDisabled(True)
self.ui.checkBoxMinimizeToTray.setText(_translate(
"MainWindow", "Minimize-to-tray not yet supported on your OS."))
self.ui.checkBoxShowTrayNotifications.setDisabled(True)
self.ui.checkBoxShowTrayNotifications.setText(_translate(
"MainWindow", "Tray notifications not yet supported on your OS."))
elif 'linux' in sys.platform:
self.ui.checkBoxStartOnLogon.setDisabled(True)
self.ui.checkBoxStartOnLogon.setText(_translate(
"MainWindow", "Start-on-login not yet supported on your OS."))
# On the Network settings tab:
self.ui.lineEditTCPPort.setText(str(
BMConfigParser().get('bitmessagesettings', 'port')))
self.ui.checkBoxUPnP.setChecked(
BMConfigParser().safeGetBoolean('bitmessagesettings', 'upnp'))
self.ui.checkBoxAuthentication.setChecked(BMConfigParser().getboolean(
'bitmessagesettings', 'socksauthentication'))
self.ui.checkBoxSocksListen.setChecked(BMConfigParser().getboolean(
'bitmessagesettings', 'sockslisten'))
if str(BMConfigParser().get('bitmessagesettings', 'socksproxytype')) == 'none':
self.ui.comboBoxProxyType.setCurrentIndex(0)
self.ui.lineEditSocksHostname.setEnabled(False)
self.ui.lineEditSocksPort.setEnabled(False)
self.ui.lineEditSocksUsername.setEnabled(False)
self.ui.lineEditSocksPassword.setEnabled(False)
self.ui.checkBoxAuthentication.setEnabled(False)
self.ui.checkBoxSocksListen.setEnabled(False)
elif str(BMConfigParser().get('bitmessagesettings', 'socksproxytype')) == 'SOCKS4a':
self.ui.comboBoxProxyType.setCurrentIndex(1)
elif str(BMConfigParser().get('bitmessagesettings', 'socksproxytype')) == 'SOCKS5':
self.ui.comboBoxProxyType.setCurrentIndex(2)
self.ui.lineEditSocksHostname.setText(str(
BMConfigParser().get('bitmessagesettings', 'sockshostname')))
self.ui.lineEditSocksPort.setText(str(
BMConfigParser().get('bitmessagesettings', 'socksport')))
self.ui.lineEditSocksUsername.setText(str(
BMConfigParser().get('bitmessagesettings', 'socksusername')))
self.ui.lineEditSocksPassword.setText(str(
BMConfigParser().get('bitmessagesettings', 'sockspassword')))
QtCore.QObject.connect(self.ui.comboBoxProxyType, QtCore.SIGNAL(
"currentIndexChanged(int)"), self.comboBoxProxyTypeChanged)
self.ui.lineEditMaxDownloadRate.setText(str(
BMConfigParser().get('bitmessagesettings', 'maxdownloadrate')))
self.ui.lineEditMaxUploadRate.setText(str(
BMConfigParser().get('bitmessagesettings', 'maxuploadrate')))
self.ui.lineEditMaxOutboundConnections.setText(str(
BMConfigParser().get('bitmessagesettings', 'maxoutboundconnections')))
# Demanded difficulty tab
self.ui.lineEditTotalDifficulty.setText(str((float(BMConfigParser().getint(
'bitmessagesettings', 'defaultnoncetrialsperbyte')) / defaults.networkDefaultProofOfWorkNonceTrialsPerByte)))
self.ui.lineEditSmallMessageDifficulty.setText(str((float(BMConfigParser().getint(
'bitmessagesettings', 'defaultpayloadlengthextrabytes')) / defaults.networkDefaultPayloadLengthExtraBytes)))
# Max acceptable difficulty tab
self.ui.lineEditMaxAcceptableTotalDifficulty.setText(str((float(BMConfigParser().getint(
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte')) / defaults.networkDefaultProofOfWorkNonceTrialsPerByte)))
self.ui.lineEditMaxAcceptableSmallMessageDifficulty.setText(str((float(BMConfigParser().getint(
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes')) / defaults.networkDefaultPayloadLengthExtraBytes)))
# OpenCL
if openclpow.openclAvailable():
self.ui.comboBoxOpenCL.setEnabled(True)
else:
self.ui.comboBoxOpenCL.setEnabled(False)
self.ui.comboBoxOpenCL.clear()
self.ui.comboBoxOpenCL.addItem("None")
self.ui.comboBoxOpenCL.addItems(openclpow.vendors)
self.ui.comboBoxOpenCL.setCurrentIndex(0)
for i in range(self.ui.comboBoxOpenCL.count()):
if self.ui.comboBoxOpenCL.itemText(i) == BMConfigParser().safeGet('bitmessagesettings', 'opencl'):
self.ui.comboBoxOpenCL.setCurrentIndex(i)
break
# Namecoin integration tab
nmctype = BMConfigParser().get('bitmessagesettings', 'namecoinrpctype')
self.ui.lineEditNamecoinHost.setText(str(
BMConfigParser().get('bitmessagesettings', 'namecoinrpchost')))
self.ui.lineEditNamecoinPort.setText(str(
BMConfigParser().get('bitmessagesettings', 'namecoinrpcport')))
self.ui.lineEditNamecoinUser.setText(str(
BMConfigParser().get('bitmessagesettings', 'namecoinrpcuser')))
self.ui.lineEditNamecoinPassword.setText(str(
BMConfigParser().get('bitmessagesettings', 'namecoinrpcpassword')))
if nmctype == "namecoind":
self.ui.radioButtonNamecoinNamecoind.setChecked(True)
elif nmctype == "nmcontrol":
self.ui.radioButtonNamecoinNmcontrol.setChecked(True)
self.ui.lineEditNamecoinUser.setEnabled(False)
self.ui.labelNamecoinUser.setEnabled(False)
self.ui.lineEditNamecoinPassword.setEnabled(False)
self.ui.labelNamecoinPassword.setEnabled(False)
else:
assert False
QtCore.QObject.connect(self.ui.radioButtonNamecoinNamecoind, QtCore.SIGNAL(
"toggled(bool)"), self.namecoinTypeChanged)
QtCore.QObject.connect(self.ui.radioButtonNamecoinNmcontrol, QtCore.SIGNAL(
"toggled(bool)"), self.namecoinTypeChanged)
QtCore.QObject.connect(self.ui.pushButtonNamecoinTest, QtCore.SIGNAL(
"clicked()"), self.click_pushButtonNamecoinTest)
#Message Resend tab
self.ui.lineEditDays.setText(str(
BMConfigParser().get('bitmessagesettings', 'stopresendingafterxdays')))
self.ui.lineEditMonths.setText(str(
BMConfigParser().get('bitmessagesettings', 'stopresendingafterxmonths')))
#'System' tab removed for now.
"""try:
maxCores = BMConfigParser().getint('bitmessagesettings', 'maxcores')
except:
maxCores = 99999
if maxCores <= 1:
self.ui.comboBoxMaxCores.setCurrentIndex(0)
elif maxCores == 2:
self.ui.comboBoxMaxCores.setCurrentIndex(1)
elif maxCores <= 4:
self.ui.comboBoxMaxCores.setCurrentIndex(2)
elif maxCores <= 8:
self.ui.comboBoxMaxCores.setCurrentIndex(3)
elif maxCores <= 16:
self.ui.comboBoxMaxCores.setCurrentIndex(4)
else:
self.ui.comboBoxMaxCores.setCurrentIndex(5)"""
QtGui.QWidget.resize(self, QtGui.QWidget.sizeHint(self))
def comboBoxProxyTypeChanged(self, comboBoxIndex):
if comboBoxIndex == 0:
self.ui.lineEditSocksHostname.setEnabled(False)
self.ui.lineEditSocksPort.setEnabled(False)
self.ui.lineEditSocksUsername.setEnabled(False)
self.ui.lineEditSocksPassword.setEnabled(False)
self.ui.checkBoxAuthentication.setEnabled(False)
self.ui.checkBoxSocksListen.setEnabled(False)
elif comboBoxIndex == 1 or comboBoxIndex == 2:
self.ui.lineEditSocksHostname.setEnabled(True)
self.ui.lineEditSocksPort.setEnabled(True)
self.ui.checkBoxAuthentication.setEnabled(True)
self.ui.checkBoxSocksListen.setEnabled(True)
if self.ui.checkBoxAuthentication.isChecked():
self.ui.lineEditSocksUsername.setEnabled(True)
self.ui.lineEditSocksPassword.setEnabled(True)
# Check status of namecoin integration radio buttons and translate
# it to a string as in the options.
def getNamecoinType(self):
if self.ui.radioButtonNamecoinNamecoind.isChecked():
return "namecoind"
if self.ui.radioButtonNamecoinNmcontrol.isChecked():
return "nmcontrol"
assert False
# Namecoin connection type was changed.
def namecoinTypeChanged(self, checked):
nmctype = self.getNamecoinType()
assert nmctype == "namecoind" or nmctype == "nmcontrol"
isNamecoind = (nmctype == "namecoind")
self.ui.lineEditNamecoinUser.setEnabled(isNamecoind)
self.ui.labelNamecoinUser.setEnabled(isNamecoind)
self.ui.lineEditNamecoinPassword.setEnabled(isNamecoind)
self.ui.labelNamecoinPassword.setEnabled(isNamecoind)
if isNamecoind:
self.ui.lineEditNamecoinPort.setText(defaults.namecoinDefaultRpcPort)
else:
self.ui.lineEditNamecoinPort.setText("9000")
def click_pushButtonNamecoinTest(self):
"""Test the namecoin settings specified in the settings dialog."""
self.ui.labelNamecoinTestResult.setText(_translate(
"MainWindow", "Testing..."))
options = {}
options["type"] = self.getNamecoinType()
options["host"] = str(self.ui.lineEditNamecoinHost.text().toUtf8())
options["port"] = str(self.ui.lineEditNamecoinPort.text().toUtf8())
options["user"] = str(self.ui.lineEditNamecoinUser.text().toUtf8())
options["password"] = str(self.ui.lineEditNamecoinPassword.text().toUtf8())
nc = namecoin.namecoinConnection(options)
status, text = nc.test()
self.ui.labelNamecoinTestResult.setText(text)
if status == 'success':
self.parent.namecoin = nc
# In order for the time columns on the Inbox and Sent tabs to be sorted # In order for the time columns on the Inbox and Sent tabs to be sorted
# correctly (rather than alphabetically), we need to overload the < # correctly (rather than alphabetically), we need to overload the <
# operator and use this class instead of QTableWidgetItem. # operator and use this class instead of QTableWidgetItem.
@ -4137,6 +4558,7 @@ def init():
def run(): def run():
global myapp global myapp
app = init() app = init()
change_translation(l10n.getTranslationLanguage())
app.setStyleSheet("QStatusBar::item { border: 0px solid black }") app.setStyleSheet("QStatusBar::item { border: 0px solid black }")
myapp = MyForm() myapp = MyForm()

View File

@ -46,7 +46,7 @@
<item alignment="Qt::AlignLeft"> <item alignment="Qt::AlignLeft">
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Copyright © 2012-2016 Jonathan Warren&lt;br/&gt;Copyright © 2012-2020 The Bitmessage Developers&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Copyright © 2012-2016 Jonathan Warren&lt;br/&gt;Copyright © 2012-2019 The Bitmessage Developers&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignLeft</set> <set>Qt::AlignLeft</set>

View File

@ -5,25 +5,22 @@ src/bitmessageqt/dialogs.py
from PyQt4 import QtGui from PyQt4 import QtGui
from version import softwareVersion
import paths import paths
import widgets import widgets
from address_dialogs import ( from address_dialogs import (
AddAddressDialog, EmailGatewayDialog, NewAddressDialog, AddAddressDialog, EmailGatewayDialog, NewAddressDialog, NewSubscriptionDialog, RegenerateAddressesDialog,
NewSubscriptionDialog, RegenerateAddressesDialog,
SpecialAddressBehaviorDialog SpecialAddressBehaviorDialog
) )
from newchandialog import NewChanDialog from newchandialog import NewChanDialog
from retranslateui import RetranslateMixin from retranslateui import RetranslateMixin
from settings import SettingsDialog
from tr import _translate from tr import _translate
from version import softwareVersion
__all__ = [ __all__ = [
"NewChanDialog", "AddAddressDialog", "NewAddressDialog", "NewChanDialog", "AddAddressDialog", "NewAddressDialog",
"NewSubscriptionDialog", "RegenerateAddressesDialog", "NewSubscriptionDialog", "RegenerateAddressesDialog",
"SpecialAddressBehaviorDialog", "EmailGatewayDialog", "SpecialAddressBehaviorDialog", "EmailGatewayDialog"
"SettingsDialog"
] ]
@ -47,7 +44,7 @@ class AboutDialog(QtGui.QDialog, RetranslateMixin):
try: try:
self.label_2.setText( self.label_2.setText(
self.label_2.text().replace( self.label_2.text().replace(
'2020', str(last_commit.get('time').year) '2019', str(last_commit.get('time').year)
)) ))
except AttributeError: except AttributeError:
pass pass

View File

@ -14,7 +14,7 @@ import network.stats
import shared import shared
import widgets import widgets
from inventory import Inventory from inventory import Inventory
from network import BMConnectionPool from network.connectionpool import BMConnectionPool
from retranslateui import RetranslateMixin from retranslateui import RetranslateMixin
from tr import _translate from tr import _translate
from uisignaler import UISignaler from uisignaler import UISignaler

View File

@ -1,18 +1,12 @@
"""Subclass of HTMLParser.HTMLParser for MessageView widget""" from HTMLParser import HTMLParser
import inspect import inspect
import re import re
from HTMLParser import HTMLParser from urllib import quote, quote_plus
from urllib import quote_plus
from urlparse import urlparse from urlparse import urlparse
class SafeHTMLParser(HTMLParser): class SafeHTMLParser(HTMLParser):
"""HTML parser with sanitisation"""
# from html5lib.sanitiser # from html5lib.sanitiser
acceptable_elements = ( acceptable_elements = ['a', 'abbr', 'acronym', 'address', 'area',
'a', 'abbr', 'acronym', 'address', 'area',
'article', 'aside', 'audio', 'b', 'big', 'blockquote', 'br', 'button', 'article', 'aside', 'audio', 'b', 'big', 'blockquote', 'br', 'button',
'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup',
'command', 'datagrid', 'datalist', 'dd', 'del', 'details', 'dfn', 'command', 'datagrid', 'datalist', 'dd', 'del', 'details', 'dfn',
@ -24,50 +18,34 @@ class SafeHTMLParser(HTMLParser):
'p', 'pre', 'progress', 'q', 's', 'samp', 'section', 'select', 'p', 'pre', 'progress', 'q', 's', 'samp', 'section', 'select',
'small', 'sound', 'source', 'spacer', 'span', 'strike', 'strong', 'small', 'sound', 'source', 'spacer', 'span', 'strike', 'strong',
'sub', 'sup', 'table', 'tbody', 'td', 'textarea', 'time', 'tfoot', 'sub', 'sup', 'table', 'tbody', 'td', 'textarea', 'time', 'tfoot',
'th', 'thead', 'tr', 'tt', 'u', 'ul', 'var', 'video' 'th', 'thead', 'tr', 'tt', 'u', 'ul', 'var', 'video']
) replaces_pre = [["&", "&amp;"], ["\"", "&quot;"], ["<", "&lt;"], [">", "&gt;"]]
replaces_pre = ( replaces_post = [["\n", "<br/>"], ["\t", "&nbsp;&nbsp;&nbsp;&nbsp;"], [" ", "&nbsp; "], [" ", "&nbsp; "], ["<br/> ", "<br/>&nbsp;"]]
("&", "&amp;"), ("\"", "&quot;"), ("<", "&lt;"), (">", "&gt;"))
replaces_post = (
("\n", "<br/>"), ("\t", "&nbsp;&nbsp;&nbsp;&nbsp;"),
(" ", "&nbsp; "), (" ", "&nbsp; "), ("<br/> ", "<br/>&nbsp;"))
src_schemes = [ "data" ] src_schemes = [ "data" ]
# uriregex1 = re.compile( #uriregex1 = re.compile(r'(?i)\b((?:(https?|ftp|bitcoin):(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?]))')
# r'(?i)\b((?:(https?|ftp|bitcoin):(?:/{1,3}|[a-z0-9%])' uriregex1 = re.compile(r'((https?|ftp|bitcoin):(?:/{1,3}|[a-z0-9%])(?:[a-zA-Z]|[0-9]|[$-_@.&+#]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+)')
# r'|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)'
# r'(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))'
# r'+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?]))')
uriregex1 = re.compile(
r'((https?|ftp|bitcoin):(?:/{1,3}|[a-z0-9%])'
r'(?:[a-zA-Z]|[0-9]|[$-_@.&+#]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+)'
)
uriregex2 = re.compile(r'<a href="([^"]+)&amp;') uriregex2 = re.compile(r'<a href="([^"]+)&amp;')
emailregex = re.compile( emailregex = re.compile(r'\b([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,})\b')
r'\b([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,})\b')
@staticmethod @staticmethod
def replace_pre(text): def replace_pre(text):
"""Perform substring replacement before regex replacements"""
for a in SafeHTMLParser.replaces_pre: for a in SafeHTMLParser.replaces_pre:
text = text.replace(*a) text = text.replace(a[0], a[1])
return text return text
@staticmethod @staticmethod
def replace_post(text): def replace_post(text):
"""Perform substring replacement after regex replacements"""
for a in SafeHTMLParser.replaces_post: for a in SafeHTMLParser.replaces_post:
text = text.replace(*a) text = text.replace(a[0], a[1])
if len(text) > 1 and text[0] == " ": if len(text) > 1 and text[0] == " ":
text = "&nbsp;" + text[1:] text = "&nbsp;" + text[1:]
return text return text
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
HTMLParser.__init__(self, *args, **kwargs) HTMLParser.__init__(self, *args, **kwargs)
self.reset()
self.reset_safe() self.reset_safe()
def reset_safe(self): def reset_safe(self):
"""Reset runtime variables specific to this class"""
self.elements = set() self.elements = set()
self.raw = u"" self.raw = u""
self.sanitised = u"" self.sanitised = u""
@ -76,8 +54,7 @@ class SafeHTMLParser(HTMLParser):
self.allow_external_src = False self.allow_external_src = False
def add_if_acceptable(self, tag, attrs = None): def add_if_acceptable(self, tag, attrs = None):
"""Add tag if it passes sanitisation""" if tag not in SafeHTMLParser.acceptable_elements:
if tag not in self.acceptable_elements:
return return
self.sanitised += "<" self.sanitised += "<"
if inspect.stack()[1][3] == "handle_endtag": if inspect.stack()[1][3] == "handle_endtag":
@ -89,7 +66,7 @@ class SafeHTMLParser(HTMLParser):
val = "" val = ""
elif attr == "src" and not self.allow_external_src: elif attr == "src" and not self.allow_external_src:
url = urlparse(val) url = urlparse(val)
if url.scheme not in self.src_schemes: if url.scheme not in SafeHTMLParser.src_schemes:
val = "" val = ""
self.sanitised += " " + quote_plus(attr) self.sanitised += " " + quote_plus(attr)
if not (val is None): if not (val is None):
@ -99,7 +76,7 @@ class SafeHTMLParser(HTMLParser):
self.sanitised += ">" self.sanitised += ">"
def handle_starttag(self, tag, attrs): def handle_starttag(self, tag, attrs):
if tag in self.acceptable_elements: if tag in SafeHTMLParser.acceptable_elements:
self.has_html = True self.has_html = True
self.add_if_acceptable(tag, attrs) self.add_if_acceptable(tag, attrs)
@ -107,7 +84,7 @@ class SafeHTMLParser(HTMLParser):
self.add_if_acceptable(tag) self.add_if_acceptable(tag)
def handle_startendtag(self, tag, attrs): def handle_startendtag(self, tag, attrs):
if tag in self.acceptable_elements: if tag in SafeHTMLParser.acceptable_elements:
self.has_html = True self.has_html = True
self.add_if_acceptable(tag, attrs) self.add_if_acceptable(tag, attrs)
@ -127,14 +104,15 @@ class SafeHTMLParser(HTMLParser):
data = unicode(data, 'utf-8', errors='replace') data = unicode(data, 'utf-8', errors='replace')
HTMLParser.feed(self, data) HTMLParser.feed(self, data)
tmp = SafeHTMLParser.replace_pre(data) tmp = SafeHTMLParser.replace_pre(data)
tmp = self.uriregex1.sub(r'<a href="\1">\1</a>', tmp) tmp = SafeHTMLParser.uriregex1.sub(
tmp = self.uriregex2.sub(r'<a href="\1&', tmp) r'<a href="\1">\1</a>',
tmp = self.emailregex.sub(r'<a href="mailto:\1">\1</a>', tmp) tmp)
tmp = SafeHTMLParser.uriregex2.sub(r'<a href="\1&', tmp)
tmp = SafeHTMLParser.emailregex.sub(r'<a href="mailto:\1">\1</a>', tmp)
tmp = SafeHTMLParser.replace_post(tmp) tmp = SafeHTMLParser.replace_post(tmp)
self.raw += tmp self.raw += tmp
def is_html(self, text = None, allow_picture = False): def is_html(self, text = None, allow_picture = False):
"""Detect if string contains HTML tags"""
if text: if text:
self.reset() self.reset()
self.reset_safe() self.reset_safe()

View File

@ -1,581 +1,630 @@
import ConfigParser # -*- coding: utf-8 -*-
import os # pylint: disable=too-many-instance-attributes,too-many-locals,too-many-statements,attribute-defined-outside-init
import sys """
src/bitmessageqt/settings.py
============================
Form implementation generated from reading ui file 'settings.ui'
Created: Thu Dec 25 23:21:20 2014
by: PyQt4 UI code generator 4.10.3
WARNING! All changes made in this file will be lost!
"""
from sys import platform
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
import debug from . import bitmessage_icons_rc # pylint: disable=unused-import
import defaults from .languagebox import LanguageBox
import knownnodes
import namecoin
import openclpow
import paths
import queues
import shared
import state
import tempfile
import widgets
from bmconfigparser import BMConfigParser
from helper_sql import sqlExecute, sqlStoredProcedure
from helper_startup import start_proxyconfig
from network.asyncore_pollchoose import set_rates
from tr import _translate
def getSOCKSProxyType(config):
"""Get user socksproxytype setting from *config*"""
try:
result = ConfigParser.SafeConfigParser.get(
config, 'bitmessagesettings', 'socksproxytype')
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
return
else:
if result.lower() in ('', 'none', 'false'):
result = None
return result
class SettingsDialog(QtGui.QDialog):
"""The "Settings" dialog"""
def __init__(self, parent=None, firstrun=False):
super(SettingsDialog, self).__init__(parent)
widgets.load('settings.ui', self)
self.parent = parent
self.firstrun = firstrun
self.config = BMConfigParser()
self.net_restart_needed = False
self.timer = QtCore.QTimer()
try: try:
import pkg_resources _fromUtf8 = QtCore.QString.fromUtf8
except ImportError: except AttributeError:
pass def _fromUtf8(s):
else: return s
# Append proxy types defined in plugins
for ep in pkg_resources.iter_entry_points(
'bitmessage.proxyconfig'):
self.comboBoxProxyType.addItem(ep.name)
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_settingsDialog(object):
"""Encapsulate a UI settings dialog object"""
def setupUi(self, settingsDialog):
"""Set up the UI"""
settingsDialog.setObjectName(_fromUtf8("settingsDialog"))
settingsDialog.resize(521, 413)
self.gridLayout = QtGui.QGridLayout(settingsDialog)
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.buttonBox = QtGui.QDialogButtonBox(settingsDialog)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel | QtGui.QDialogButtonBox.Ok)
self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
self.gridLayout.addWidget(self.buttonBox, 1, 0, 1, 1)
self.tabWidgetSettings = QtGui.QTabWidget(settingsDialog)
self.tabWidgetSettings.setObjectName(_fromUtf8("tabWidgetSettings"))
self.tabUserInterface = QtGui.QWidget()
self.tabUserInterface.setEnabled(True)
self.tabUserInterface.setObjectName(_fromUtf8("tabUserInterface"))
self.formLayout = QtGui.QFormLayout(self.tabUserInterface)
self.formLayout.setObjectName(_fromUtf8("formLayout"))
self.checkBoxStartOnLogon = QtGui.QCheckBox(self.tabUserInterface)
self.checkBoxStartOnLogon.setObjectName(_fromUtf8("checkBoxStartOnLogon"))
self.formLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.checkBoxStartOnLogon)
self.groupBoxTray = QtGui.QGroupBox(self.tabUserInterface)
self.groupBoxTray.setObjectName(_fromUtf8("groupBoxTray"))
self.formLayoutTray = QtGui.QFormLayout(self.groupBoxTray)
self.formLayoutTray.setObjectName(_fromUtf8("formLayoutTray"))
self.checkBoxStartInTray = QtGui.QCheckBox(self.groupBoxTray)
self.checkBoxStartInTray.setObjectName(_fromUtf8("checkBoxStartInTray"))
self.formLayoutTray.setWidget(0, QtGui.QFormLayout.SpanningRole, self.checkBoxStartInTray)
self.checkBoxMinimizeToTray = QtGui.QCheckBox(self.groupBoxTray)
self.checkBoxMinimizeToTray.setChecked(True)
self.checkBoxMinimizeToTray.setObjectName(_fromUtf8("checkBoxMinimizeToTray"))
self.formLayoutTray.setWidget(1, QtGui.QFormLayout.LabelRole, self.checkBoxMinimizeToTray)
self.checkBoxTrayOnClose = QtGui.QCheckBox(self.groupBoxTray)
self.checkBoxTrayOnClose.setChecked(True)
self.checkBoxTrayOnClose.setObjectName(_fromUtf8("checkBoxTrayOnClose"))
self.formLayoutTray.setWidget(2, QtGui.QFormLayout.LabelRole, self.checkBoxTrayOnClose)
self.formLayout.setWidget(1, QtGui.QFormLayout.SpanningRole, self.groupBoxTray)
self.checkBoxHideTrayConnectionNotifications = QtGui.QCheckBox(self.tabUserInterface)
self.checkBoxHideTrayConnectionNotifications.setChecked(False)
self.checkBoxHideTrayConnectionNotifications.setObjectName(
_fromUtf8("checkBoxHideTrayConnectionNotifications"))
self.formLayout.setWidget(2, QtGui.QFormLayout.LabelRole, self.checkBoxHideTrayConnectionNotifications)
self.checkBoxShowTrayNotifications = QtGui.QCheckBox(self.tabUserInterface)
self.checkBoxShowTrayNotifications.setObjectName(_fromUtf8("checkBoxShowTrayNotifications"))
self.formLayout.setWidget(3, QtGui.QFormLayout.LabelRole, self.checkBoxShowTrayNotifications)
self.checkBoxPortableMode = QtGui.QCheckBox(self.tabUserInterface)
self.checkBoxPortableMode.setObjectName(_fromUtf8("checkBoxPortableMode"))
self.formLayout.setWidget(4, QtGui.QFormLayout.LabelRole, self.checkBoxPortableMode)
self.PortableModeDescription = QtGui.QLabel(self.tabUserInterface)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.PortableModeDescription.sizePolicy().hasHeightForWidth())
self.PortableModeDescription.setSizePolicy(sizePolicy)
self.PortableModeDescription.setWordWrap(True)
self.PortableModeDescription.setObjectName(_fromUtf8("PortableModeDescription"))
self.formLayout.setWidget(5, QtGui.QFormLayout.SpanningRole, self.PortableModeDescription)
self.checkBoxWillinglySendToMobile = QtGui.QCheckBox(self.tabUserInterface)
self.checkBoxWillinglySendToMobile.setObjectName(_fromUtf8("checkBoxWillinglySendToMobile"))
self.formLayout.setWidget(6, QtGui.QFormLayout.SpanningRole, self.checkBoxWillinglySendToMobile)
self.checkBoxUseIdenticons = QtGui.QCheckBox(self.tabUserInterface)
self.checkBoxUseIdenticons.setObjectName(_fromUtf8("checkBoxUseIdenticons"))
self.formLayout.setWidget(7, QtGui.QFormLayout.LabelRole, self.checkBoxUseIdenticons)
self.checkBoxReplyBelow = QtGui.QCheckBox(self.tabUserInterface)
self.checkBoxReplyBelow.setObjectName(_fromUtf8("checkBoxReplyBelow"))
self.formLayout.setWidget(8, QtGui.QFormLayout.LabelRole, self.checkBoxReplyBelow)
self.groupBox = QtGui.QGroupBox(self.tabUserInterface)
self.groupBox.setObjectName(_fromUtf8("groupBox"))
self.formLayout_2 = QtGui.QFormLayout(self.groupBox)
self.formLayout_2.setObjectName(_fromUtf8("formLayout_2"))
self.languageComboBox = LanguageBox(self.groupBox)
self.languageComboBox.setMinimumSize(QtCore.QSize(100, 0))
self.languageComboBox.setObjectName(_fromUtf8("languageComboBox")) # pylint: disable=not-callable
self.formLayout_2.setWidget(0, QtGui.QFormLayout.LabelRole, self.languageComboBox)
self.formLayout.setWidget(9, QtGui.QFormLayout.FieldRole, self.groupBox)
self.tabWidgetSettings.addTab(self.tabUserInterface, _fromUtf8(""))
self.tabNetworkSettings = QtGui.QWidget()
self.tabNetworkSettings.setObjectName(_fromUtf8("tabNetworkSettings"))
self.gridLayout_4 = QtGui.QGridLayout(self.tabNetworkSettings)
self.gridLayout_4.setObjectName(_fromUtf8("gridLayout_4"))
self.groupBox1 = QtGui.QGroupBox(self.tabNetworkSettings)
self.groupBox1.setObjectName(_fromUtf8("groupBox1"))
self.gridLayout_3 = QtGui.QGridLayout(self.groupBox1)
self.gridLayout_3.setObjectName(_fromUtf8("gridLayout_3"))
self.label = QtGui.QLabel(self.groupBox1)
self.label.setObjectName(_fromUtf8("label"))
self.gridLayout_3.addWidget(self.label, 0, 0, 1, 1, QtCore.Qt.AlignRight)
self.lineEditTCPPort = QtGui.QLineEdit(self.groupBox1)
self.lineEditTCPPort.setMaximumSize(QtCore.QSize(70, 16777215))
self.lineEditTCPPort.setObjectName(_fromUtf8("lineEditTCPPort"))
self.gridLayout_3.addWidget(self.lineEditTCPPort, 0, 1, 1, 1, QtCore.Qt.AlignLeft)
self.labelUPnP = QtGui.QLabel(self.groupBox1)
self.labelUPnP.setObjectName(_fromUtf8("labelUPnP"))
self.gridLayout_3.addWidget(self.labelUPnP, 0, 2, 1, 1, QtCore.Qt.AlignRight)
self.checkBoxUPnP = QtGui.QCheckBox(self.groupBox1)
self.checkBoxUPnP.setObjectName(_fromUtf8("checkBoxUPnP"))
self.gridLayout_3.addWidget(self.checkBoxUPnP, 0, 3, 1, 1, QtCore.Qt.AlignLeft)
self.gridLayout_4.addWidget(self.groupBox1, 0, 0, 1, 1)
self.groupBox_3 = QtGui.QGroupBox(self.tabNetworkSettings)
self.groupBox_3.setObjectName(_fromUtf8("groupBox_3"))
self.gridLayout_9 = QtGui.QGridLayout(self.groupBox_3)
self.gridLayout_9.setObjectName(_fromUtf8("gridLayout_9"))
spacerItem1 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout_9.addItem(spacerItem1, 0, 0, 2, 1)
self.label_24 = QtGui.QLabel(self.groupBox_3)
self.label_24.setObjectName(_fromUtf8("label_24"))
self.gridLayout_9.addWidget(self.label_24, 0, 1, 1, 1)
self.lineEditMaxDownloadRate = QtGui.QLineEdit(self.groupBox_3)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lineEditMaxDownloadRate.sizePolicy().hasHeightForWidth())
self.lineEditMaxDownloadRate.setSizePolicy(sizePolicy)
self.lineEditMaxDownloadRate.setMaximumSize(QtCore.QSize(60, 16777215))
self.lineEditMaxDownloadRate.setObjectName(_fromUtf8("lineEditMaxDownloadRate"))
self.gridLayout_9.addWidget(self.lineEditMaxDownloadRate, 0, 2, 1, 1)
self.label_25 = QtGui.QLabel(self.groupBox_3)
self.label_25.setObjectName(_fromUtf8("label_25"))
self.gridLayout_9.addWidget(self.label_25, 1, 1, 1, 1)
self.lineEditMaxUploadRate = QtGui.QLineEdit(self.groupBox_3)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lineEditMaxUploadRate.sizePolicy().hasHeightForWidth())
self.lineEditMaxUploadRate.setSizePolicy(sizePolicy)
self.lineEditMaxUploadRate.setMaximumSize(QtCore.QSize(60, 16777215))
self.lineEditMaxUploadRate.setObjectName(_fromUtf8("lineEditMaxUploadRate"))
self.gridLayout_9.addWidget(self.lineEditMaxUploadRate, 1, 2, 1, 1)
self.label_26 = QtGui.QLabel(self.groupBox_3)
self.label_26.setObjectName(_fromUtf8("label_26"))
self.gridLayout_9.addWidget(self.label_26, 2, 1, 1, 1)
self.lineEditMaxOutboundConnections = QtGui.QLineEdit(self.groupBox_3)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lineEditMaxOutboundConnections.sizePolicy().hasHeightForWidth())
self.lineEditMaxOutboundConnections.setSizePolicy(sizePolicy)
self.lineEditMaxOutboundConnections.setMaximumSize(QtCore.QSize(60, 16777215))
self.lineEditMaxOutboundConnections.setObjectName(_fromUtf8("lineEditMaxOutboundConnections"))
self.lineEditMaxOutboundConnections.setValidator( self.lineEditMaxOutboundConnections.setValidator(
QtGui.QIntValidator(0, 8, self.lineEditMaxOutboundConnections)) QtGui.QIntValidator(0, 8, self.lineEditMaxOutboundConnections))
self.gridLayout_9.addWidget(self.lineEditMaxOutboundConnections, 2, 2, 1, 1)
self.adjust_from_config(self.config) self.gridLayout_4.addWidget(self.groupBox_3, 2, 0, 1, 1)
if firstrun: self.groupBox_2 = QtGui.QGroupBox(self.tabNetworkSettings)
# switch to "Network Settings" tab if user selected self.groupBox_2.setObjectName(_fromUtf8("groupBox_2"))
# "Let me configure special network settings first" on first run self.gridLayout_2 = QtGui.QGridLayout(self.groupBox_2)
self.tabWidgetSettings.setCurrentIndex( self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2"))
self.tabWidgetSettings.indexOf(self.tabNetworkSettings) self.label_2 = QtGui.QLabel(self.groupBox_2)
) self.label_2.setObjectName(_fromUtf8("label_2"))
QtGui.QWidget.resize(self, QtGui.QWidget.sizeHint(self)) self.gridLayout_2.addWidget(self.label_2, 0, 0, 1, 1)
self.label_3 = QtGui.QLabel(self.groupBox_2)
def adjust_from_config(self, config): self.label_3.setObjectName(_fromUtf8("label_3"))
"""Adjust all widgets state according to config settings""" self.gridLayout_2.addWidget(self.label_3, 1, 1, 1, 1)
# pylint: disable=too-many-branches,too-many-statements self.lineEditSocksHostname = QtGui.QLineEdit(self.groupBox_2)
if not self.parent.tray.isSystemTrayAvailable(): self.lineEditSocksHostname.setObjectName(_fromUtf8("lineEditSocksHostname"))
self.groupBoxTray.setEnabled(False) self.lineEditSocksHostname.setPlaceholderText(_fromUtf8("127.0.0.1"))
self.groupBoxTray.setTitle(_translate( self.gridLayout_2.addWidget(self.lineEditSocksHostname, 1, 2, 1, 2)
"MainWindow", "Tray (not available in your system)")) self.label_4 = QtGui.QLabel(self.groupBox_2)
for setting in ( self.label_4.setObjectName(_fromUtf8("label_4"))
'minimizetotray', 'trayonclose', 'startintray'): self.gridLayout_2.addWidget(self.label_4, 1, 4, 1, 1)
config.set('bitmessagesettings', setting, 'false') self.lineEditSocksPort = QtGui.QLineEdit(self.groupBox_2)
self.lineEditSocksPort.setObjectName(_fromUtf8("lineEditSocksPort"))
if platform in ['darwin', 'win32', 'win64']:
self.lineEditSocksPort.setPlaceholderText(_fromUtf8("9150"))
else: else:
self.checkBoxMinimizeToTray.setChecked( self.lineEditSocksPort.setPlaceholderText(_fromUtf8("9050"))
config.getboolean('bitmessagesettings', 'minimizetotray')) self.gridLayout_2.addWidget(self.lineEditSocksPort, 1, 5, 1, 1)
self.checkBoxTrayOnClose.setChecked( self.checkBoxAuthentication = QtGui.QCheckBox(self.groupBox_2)
config.safeGetBoolean('bitmessagesettings', 'trayonclose')) self.checkBoxAuthentication.setObjectName(_fromUtf8("checkBoxAuthentication"))
self.checkBoxStartInTray.setChecked( self.gridLayout_2.addWidget(self.checkBoxAuthentication, 2, 1, 1, 1)
config.getboolean('bitmessagesettings', 'startintray')) self.label_5 = QtGui.QLabel(self.groupBox_2)
self.label_5.setObjectName(_fromUtf8("label_5"))
self.checkBoxHideTrayConnectionNotifications.setChecked( self.gridLayout_2.addWidget(self.label_5, 2, 2, 1, 1)
config.getboolean( self.lineEditSocksUsername = QtGui.QLineEdit(self.groupBox_2)
'bitmessagesettings', 'hidetrayconnectionnotifications'))
self.checkBoxShowTrayNotifications.setChecked(
config.getboolean('bitmessagesettings', 'showtraynotifications'))
self.checkBoxStartOnLogon.setChecked(
config.getboolean('bitmessagesettings', 'startonlogon'))
self.checkBoxWillinglySendToMobile.setChecked(
config.safeGetBoolean(
'bitmessagesettings', 'willinglysendtomobile'))
self.checkBoxUseIdenticons.setChecked(
config.safeGetBoolean('bitmessagesettings', 'useidenticons'))
self.checkBoxReplyBelow.setChecked(
config.safeGetBoolean('bitmessagesettings', 'replybelow'))
if state.appdata == paths.lookupExeFolder():
self.checkBoxPortableMode.setChecked(True)
else:
try:
tempfile.NamedTemporaryFile(
dir=paths.lookupExeFolder(), delete=True
).close() # should autodelete
except:
self.checkBoxPortableMode.setDisabled(True)
if 'darwin' in sys.platform:
self.checkBoxStartOnLogon.setDisabled(True)
self.checkBoxStartOnLogon.setText(_translate(
"MainWindow", "Start-on-login not yet supported on your OS."))
self.checkBoxMinimizeToTray.setDisabled(True)
self.checkBoxMinimizeToTray.setText(_translate(
"MainWindow",
"Minimize-to-tray not yet supported on your OS."))
self.checkBoxShowTrayNotifications.setDisabled(True)
self.checkBoxShowTrayNotifications.setText(_translate(
"MainWindow",
"Tray notifications not yet supported on your OS."))
elif 'linux' in sys.platform:
self.checkBoxStartOnLogon.setDisabled(True)
self.checkBoxStartOnLogon.setText(_translate(
"MainWindow", "Start-on-login not yet supported on your OS."))
# On the Network settings tab:
self.lineEditTCPPort.setText(str(
config.get('bitmessagesettings', 'port')))
self.checkBoxUPnP.setChecked(
config.safeGetBoolean('bitmessagesettings', 'upnp'))
self.checkBoxAuthentication.setChecked(
config.getboolean('bitmessagesettings', 'socksauthentication'))
self.checkBoxSocksListen.setChecked(
config.getboolean('bitmessagesettings', 'sockslisten'))
self.checkBoxOnionOnly.setChecked(
config.safeGetBoolean('bitmessagesettings', 'onionservicesonly'))
self._proxy_type = getSOCKSProxyType(config)
self.comboBoxProxyType.setCurrentIndex(
0 if not self._proxy_type
else self.comboBoxProxyType.findText(self._proxy_type))
self.comboBoxProxyTypeChanged(self.comboBoxProxyType.currentIndex())
self.lineEditSocksHostname.setText(
config.get('bitmessagesettings', 'sockshostname'))
self.lineEditSocksPort.setText(str(
config.get('bitmessagesettings', 'socksport')))
self.lineEditSocksUsername.setText(
config.get('bitmessagesettings', 'socksusername'))
self.lineEditSocksPassword.setText(
config.get('bitmessagesettings', 'sockspassword'))
self.lineEditMaxDownloadRate.setText(str(
config.get('bitmessagesettings', 'maxdownloadrate')))
self.lineEditMaxUploadRate.setText(str(
config.get('bitmessagesettings', 'maxuploadrate')))
self.lineEditMaxOutboundConnections.setText(str(
config.get('bitmessagesettings', 'maxoutboundconnections')))
# Demanded difficulty tab
self.lineEditTotalDifficulty.setText(str((float(
config.getint(
'bitmessagesettings', 'defaultnoncetrialsperbyte')
) / defaults.networkDefaultProofOfWorkNonceTrialsPerByte)))
self.lineEditSmallMessageDifficulty.setText(str((float(
config.getint(
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
) / defaults.networkDefaultPayloadLengthExtraBytes)))
# Max acceptable difficulty tab
self.lineEditMaxAcceptableTotalDifficulty.setText(str((float(
config.getint(
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte')
) / defaults.networkDefaultProofOfWorkNonceTrialsPerByte)))
self.lineEditMaxAcceptableSmallMessageDifficulty.setText(str((float(
config.getint(
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes')
) / defaults.networkDefaultPayloadLengthExtraBytes)))
# OpenCL
self.comboBoxOpenCL.setEnabled(openclpow.openclAvailable())
self.comboBoxOpenCL.clear()
self.comboBoxOpenCL.addItem("None")
self.comboBoxOpenCL.addItems(openclpow.vendors)
self.comboBoxOpenCL.setCurrentIndex(0)
for i in range(self.comboBoxOpenCL.count()):
if self.comboBoxOpenCL.itemText(i) == config.safeGet(
'bitmessagesettings', 'opencl'):
self.comboBoxOpenCL.setCurrentIndex(i)
break
# Namecoin integration tab
nmctype = config.get('bitmessagesettings', 'namecoinrpctype')
self.lineEditNamecoinHost.setText(
config.get('bitmessagesettings', 'namecoinrpchost'))
self.lineEditNamecoinPort.setText(str(
config.get('bitmessagesettings', 'namecoinrpcport')))
self.lineEditNamecoinUser.setText(
config.get('bitmessagesettings', 'namecoinrpcuser'))
self.lineEditNamecoinPassword.setText(
config.get('bitmessagesettings', 'namecoinrpcpassword'))
if nmctype == "namecoind":
self.radioButtonNamecoinNamecoind.setChecked(True)
elif nmctype == "nmcontrol":
self.radioButtonNamecoinNmcontrol.setChecked(True)
self.lineEditNamecoinUser.setEnabled(False)
self.labelNamecoinUser.setEnabled(False)
self.lineEditNamecoinPassword.setEnabled(False)
self.labelNamecoinPassword.setEnabled(False)
else:
assert False
# Message Resend tab
self.lineEditDays.setText(str(
config.get('bitmessagesettings', 'stopresendingafterxdays')))
self.lineEditMonths.setText(str(
config.get('bitmessagesettings', 'stopresendingafterxmonths')))
def comboBoxProxyTypeChanged(self, comboBoxIndex):
"""A callback for currentIndexChanged event of comboBoxProxyType"""
if comboBoxIndex == 0:
self.lineEditSocksHostname.setEnabled(False)
self.lineEditSocksPort.setEnabled(False)
self.lineEditSocksUsername.setEnabled(False) self.lineEditSocksUsername.setEnabled(False)
self.lineEditSocksUsername.setObjectName(_fromUtf8("lineEditSocksUsername"))
self.gridLayout_2.addWidget(self.lineEditSocksUsername, 2, 3, 1, 1)
self.label_6 = QtGui.QLabel(self.groupBox_2)
self.label_6.setObjectName(_fromUtf8("label_6"))
self.gridLayout_2.addWidget(self.label_6, 2, 4, 1, 1)
self.lineEditSocksPassword = QtGui.QLineEdit(self.groupBox_2)
self.lineEditSocksPassword.setEnabled(False) self.lineEditSocksPassword.setEnabled(False)
self.checkBoxAuthentication.setEnabled(False) self.lineEditSocksPassword.setInputMethodHints(
self.checkBoxSocksListen.setEnabled(False) QtCore.Qt.ImhHiddenText | QtCore.Qt.ImhNoAutoUppercase | QtCore.Qt.ImhNoPredictiveText)
self.checkBoxOnionOnly.setEnabled(False) self.lineEditSocksPassword.setEchoMode(QtGui.QLineEdit.Password)
else: self.lineEditSocksPassword.setObjectName(_fromUtf8("lineEditSocksPassword"))
self.lineEditSocksHostname.setEnabled(True) self.gridLayout_2.addWidget(self.lineEditSocksPassword, 2, 5, 1, 1)
self.lineEditSocksPort.setEnabled(True) self.checkBoxSocksListen = QtGui.QCheckBox(self.groupBox_2)
self.checkBoxAuthentication.setEnabled(True) self.checkBoxSocksListen.setObjectName(_fromUtf8("checkBoxSocksListen"))
self.checkBoxSocksListen.setEnabled(True) self.gridLayout_2.addWidget(self.checkBoxSocksListen, 3, 1, 1, 4)
self.checkBoxOnionOnly.setEnabled(True) self.comboBoxProxyType = QtGui.QComboBox(self.groupBox_2)
if self.checkBoxAuthentication.isChecked(): self.comboBoxProxyType.setObjectName(_fromUtf8("comboBoxProxyType")) # pylint: disable=not-callable
self.lineEditSocksUsername.setEnabled(True) self.comboBoxProxyType.addItem(_fromUtf8(""))
self.lineEditSocksPassword.setEnabled(True) self.comboBoxProxyType.addItem(_fromUtf8(""))
self.comboBoxProxyType.addItem(_fromUtf8(""))
self.gridLayout_2.addWidget(self.comboBoxProxyType, 0, 1, 1, 1)
self.gridLayout_4.addWidget(self.groupBox_2, 1, 0, 1, 1)
spacerItem2 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.gridLayout_4.addItem(spacerItem2, 3, 0, 1, 1)
self.tabWidgetSettings.addTab(self.tabNetworkSettings, _fromUtf8(""))
self.tabDemandedDifficulty = QtGui.QWidget()
self.tabDemandedDifficulty.setObjectName(_fromUtf8("tabDemandedDifficulty"))
self.gridLayout_6 = QtGui.QGridLayout(self.tabDemandedDifficulty)
self.gridLayout_6.setObjectName(_fromUtf8("gridLayout_6"))
self.label_9 = QtGui.QLabel(self.tabDemandedDifficulty)
self.label_9.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
self.label_9.setObjectName(_fromUtf8("label_9"))
self.gridLayout_6.addWidget(self.label_9, 1, 1, 1, 1)
self.label_10 = QtGui.QLabel(self.tabDemandedDifficulty)
self.label_10.setWordWrap(True)
self.label_10.setObjectName(_fromUtf8("label_10"))
self.gridLayout_6.addWidget(self.label_10, 2, 0, 1, 3)
self.label_11 = QtGui.QLabel(self.tabDemandedDifficulty)
self.label_11.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
self.label_11.setObjectName(_fromUtf8("label_11"))
self.gridLayout_6.addWidget(self.label_11, 3, 1, 1, 1)
self.label_8 = QtGui.QLabel(self.tabDemandedDifficulty)
self.label_8.setWordWrap(True)
self.label_8.setObjectName(_fromUtf8("label_8"))
self.gridLayout_6.addWidget(self.label_8, 0, 0, 1, 3)
spacerItem3 = QtGui.QSpacerItem(203, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout_6.addItem(spacerItem3, 1, 0, 1, 1)
self.label_12 = QtGui.QLabel(self.tabDemandedDifficulty)
self.label_12.setWordWrap(True)
self.label_12.setObjectName(_fromUtf8("label_12"))
self.gridLayout_6.addWidget(self.label_12, 4, 0, 1, 3)
self.lineEditSmallMessageDifficulty = QtGui.QLineEdit(self.tabDemandedDifficulty)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lineEditSmallMessageDifficulty.sizePolicy().hasHeightForWidth())
self.lineEditSmallMessageDifficulty.setSizePolicy(sizePolicy)
self.lineEditSmallMessageDifficulty.setMaximumSize(QtCore.QSize(70, 16777215))
self.lineEditSmallMessageDifficulty.setObjectName(_fromUtf8("lineEditSmallMessageDifficulty"))
self.gridLayout_6.addWidget(self.lineEditSmallMessageDifficulty, 3, 2, 1, 1)
self.lineEditTotalDifficulty = QtGui.QLineEdit(self.tabDemandedDifficulty)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lineEditTotalDifficulty.sizePolicy().hasHeightForWidth())
self.lineEditTotalDifficulty.setSizePolicy(sizePolicy)
self.lineEditTotalDifficulty.setMaximumSize(QtCore.QSize(70, 16777215))
self.lineEditTotalDifficulty.setObjectName(_fromUtf8("lineEditTotalDifficulty"))
self.gridLayout_6.addWidget(self.lineEditTotalDifficulty, 1, 2, 1, 1)
spacerItem4 = QtGui.QSpacerItem(203, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout_6.addItem(spacerItem4, 3, 0, 1, 1)
spacerItem5 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.gridLayout_6.addItem(spacerItem5, 5, 0, 1, 1)
self.tabWidgetSettings.addTab(self.tabDemandedDifficulty, _fromUtf8(""))
self.tabMaxAcceptableDifficulty = QtGui.QWidget()
self.tabMaxAcceptableDifficulty.setObjectName(_fromUtf8("tabMaxAcceptableDifficulty"))
self.gridLayout_7 = QtGui.QGridLayout(self.tabMaxAcceptableDifficulty)
self.gridLayout_7.setObjectName(_fromUtf8("gridLayout_7"))
self.label_15 = QtGui.QLabel(self.tabMaxAcceptableDifficulty)
self.label_15.setWordWrap(True)
self.label_15.setObjectName(_fromUtf8("label_15"))
self.gridLayout_7.addWidget(self.label_15, 0, 0, 1, 3)
spacerItem6 = QtGui.QSpacerItem(102, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout_7.addItem(spacerItem6, 1, 0, 1, 1)
self.label_13 = QtGui.QLabel(self.tabMaxAcceptableDifficulty)
self.label_13.setLayoutDirection(QtCore.Qt.LeftToRight)
self.label_13.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
self.label_13.setObjectName(_fromUtf8("label_13"))
self.gridLayout_7.addWidget(self.label_13, 1, 1, 1, 1)
self.lineEditMaxAcceptableTotalDifficulty = QtGui.QLineEdit(self.tabMaxAcceptableDifficulty)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lineEditMaxAcceptableTotalDifficulty.sizePolicy().hasHeightForWidth())
self.lineEditMaxAcceptableTotalDifficulty.setSizePolicy(sizePolicy)
self.lineEditMaxAcceptableTotalDifficulty.setMaximumSize(QtCore.QSize(70, 16777215))
self.lineEditMaxAcceptableTotalDifficulty.setObjectName(_fromUtf8("lineEditMaxAcceptableTotalDifficulty"))
self.gridLayout_7.addWidget(self.lineEditMaxAcceptableTotalDifficulty, 1, 2, 1, 1)
spacerItem7 = QtGui.QSpacerItem(102, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout_7.addItem(spacerItem7, 2, 0, 1, 1)
self.label_14 = QtGui.QLabel(self.tabMaxAcceptableDifficulty)
self.label_14.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
self.label_14.setObjectName(_fromUtf8("label_14"))
self.gridLayout_7.addWidget(self.label_14, 2, 1, 1, 1)
self.lineEditMaxAcceptableSmallMessageDifficulty = QtGui.QLineEdit(self.tabMaxAcceptableDifficulty)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.lineEditMaxAcceptableSmallMessageDifficulty.sizePolicy().hasHeightForWidth())
self.lineEditMaxAcceptableSmallMessageDifficulty.setSizePolicy(sizePolicy)
self.lineEditMaxAcceptableSmallMessageDifficulty.setMaximumSize(QtCore.QSize(70, 16777215))
self.lineEditMaxAcceptableSmallMessageDifficulty.setObjectName(
_fromUtf8("lineEditMaxAcceptableSmallMessageDifficulty"))
self.gridLayout_7.addWidget(self.lineEditMaxAcceptableSmallMessageDifficulty, 2, 2, 1, 1)
spacerItem8 = QtGui.QSpacerItem(20, 147, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.gridLayout_7.addItem(spacerItem8, 3, 1, 1, 1)
self.labelOpenCL = QtGui.QLabel(self.tabMaxAcceptableDifficulty)
self.labelOpenCL.setObjectName(_fromUtf8("labelOpenCL"))
self.gridLayout_7.addWidget(self.labelOpenCL, 4, 0, 1, 1)
self.comboBoxOpenCL = QtGui.QComboBox(self.tabMaxAcceptableDifficulty)
self.comboBoxOpenCL.setObjectName = (_fromUtf8("comboBoxOpenCL"))
self.gridLayout_7.addWidget(self.comboBoxOpenCL, 4, 1, 1, 1)
self.tabWidgetSettings.addTab(self.tabMaxAcceptableDifficulty, _fromUtf8(""))
self.tabNamecoin = QtGui.QWidget()
self.tabNamecoin.setObjectName(_fromUtf8("tabNamecoin"))
self.gridLayout_8 = QtGui.QGridLayout(self.tabNamecoin)
self.gridLayout_8.setObjectName(_fromUtf8("gridLayout_8"))
spacerItem9 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout_8.addItem(spacerItem9, 2, 0, 1, 1)
self.label_16 = QtGui.QLabel(self.tabNamecoin)
self.label_16.setWordWrap(True)
self.label_16.setObjectName(_fromUtf8("label_16"))
self.gridLayout_8.addWidget(self.label_16, 0, 0, 1, 3)
self.label_17 = QtGui.QLabel(self.tabNamecoin)
self.label_17.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
self.label_17.setObjectName(_fromUtf8("label_17"))
self.gridLayout_8.addWidget(self.label_17, 2, 1, 1, 1)
self.lineEditNamecoinHost = QtGui.QLineEdit(self.tabNamecoin)
self.lineEditNamecoinHost.setObjectName(_fromUtf8("lineEditNamecoinHost"))
self.gridLayout_8.addWidget(self.lineEditNamecoinHost, 2, 2, 1, 1)
spacerItem10 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout_8.addItem(spacerItem10, 3, 0, 1, 1)
spacerItem11 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout_8.addItem(spacerItem11, 4, 0, 1, 1)
self.label_18 = QtGui.QLabel(self.tabNamecoin)
self.label_18.setEnabled(True)
self.label_18.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
self.label_18.setObjectName(_fromUtf8("label_18"))
self.gridLayout_8.addWidget(self.label_18, 3, 1, 1, 1)
self.lineEditNamecoinPort = QtGui.QLineEdit(self.tabNamecoin)
self.lineEditNamecoinPort.setObjectName(_fromUtf8("lineEditNamecoinPort"))
self.gridLayout_8.addWidget(self.lineEditNamecoinPort, 3, 2, 1, 1)
spacerItem12 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.gridLayout_8.addItem(spacerItem12, 8, 1, 1, 1)
self.labelNamecoinUser = QtGui.QLabel(self.tabNamecoin)
self.labelNamecoinUser.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
self.labelNamecoinUser.setObjectName(_fromUtf8("labelNamecoinUser"))
self.gridLayout_8.addWidget(self.labelNamecoinUser, 4, 1, 1, 1)
self.lineEditNamecoinUser = QtGui.QLineEdit(self.tabNamecoin)
self.lineEditNamecoinUser.setObjectName(_fromUtf8("lineEditNamecoinUser"))
self.gridLayout_8.addWidget(self.lineEditNamecoinUser, 4, 2, 1, 1)
spacerItem13 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout_8.addItem(spacerItem13, 5, 0, 1, 1)
self.labelNamecoinPassword = QtGui.QLabel(self.tabNamecoin)
self.labelNamecoinPassword.setAlignment(
QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
self.labelNamecoinPassword.setObjectName(_fromUtf8("labelNamecoinPassword"))
self.gridLayout_8.addWidget(self.labelNamecoinPassword, 5, 1, 1, 1)
self.lineEditNamecoinPassword = QtGui.QLineEdit(self.tabNamecoin)
self.lineEditNamecoinPassword.setInputMethodHints(
QtCore.Qt.ImhHiddenText | QtCore.Qt.ImhNoAutoUppercase | QtCore.Qt.ImhNoPredictiveText)
self.lineEditNamecoinPassword.setEchoMode(QtGui.QLineEdit.Password)
self.lineEditNamecoinPassword.setObjectName(_fromUtf8("lineEditNamecoinPassword"))
self.gridLayout_8.addWidget(self.lineEditNamecoinPassword, 5, 2, 1, 1)
self.labelNamecoinTestResult = QtGui.QLabel(self.tabNamecoin)
self.labelNamecoinTestResult.setText(_fromUtf8(""))
self.labelNamecoinTestResult.setObjectName(_fromUtf8("labelNamecoinTestResult"))
self.gridLayout_8.addWidget(self.labelNamecoinTestResult, 7, 0, 1, 2)
self.pushButtonNamecoinTest = QtGui.QPushButton(self.tabNamecoin)
self.pushButtonNamecoinTest.setObjectName(_fromUtf8("pushButtonNamecoinTest"))
self.gridLayout_8.addWidget(self.pushButtonNamecoinTest, 7, 2, 1, 1)
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.label_21 = QtGui.QLabel(self.tabNamecoin)
self.label_21.setObjectName(_fromUtf8("label_21"))
self.horizontalLayout.addWidget(self.label_21)
self.radioButtonNamecoinNamecoind = QtGui.QRadioButton(self.tabNamecoin)
self.radioButtonNamecoinNamecoind.setObjectName(_fromUtf8("radioButtonNamecoinNamecoind"))
self.horizontalLayout.addWidget(self.radioButtonNamecoinNamecoind)
self.radioButtonNamecoinNmcontrol = QtGui.QRadioButton(self.tabNamecoin)
self.radioButtonNamecoinNmcontrol.setObjectName(_fromUtf8("radioButtonNamecoinNmcontrol"))
self.horizontalLayout.addWidget(self.radioButtonNamecoinNmcontrol)
self.gridLayout_8.addLayout(self.horizontalLayout, 1, 0, 1, 3)
self.tabWidgetSettings.addTab(self.tabNamecoin, _fromUtf8(""))
self.tabResendsExpire = QtGui.QWidget()
self.tabResendsExpire.setObjectName(_fromUtf8("tabResendsExpire"))
self.gridLayout_5 = QtGui.QGridLayout(self.tabResendsExpire)
self.gridLayout_5.setObjectName(_fromUtf8("gridLayout_5"))
self.label_7 = QtGui.QLabel(self.tabResendsExpire)
self.label_7.setWordWrap(True)
self.label_7.setObjectName(_fromUtf8("label_7"))
self.gridLayout_5.addWidget(self.label_7, 0, 0, 1, 3)
spacerItem14 = QtGui.QSpacerItem(212, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout_5.addItem(spacerItem14, 1, 0, 1, 1)
self.widget = QtGui.QWidget(self.tabResendsExpire)
self.widget.setMinimumSize(QtCore.QSize(231, 75))
self.widget.setObjectName(_fromUtf8("widget"))
self.label_19 = QtGui.QLabel(self.widget)
self.label_19.setGeometry(QtCore.QRect(10, 20, 101, 20))
self.label_19.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
self.label_19.setObjectName(_fromUtf8("label_19"))
self.label_20 = QtGui.QLabel(self.widget)
self.label_20.setGeometry(QtCore.QRect(30, 40, 80, 16))
self.label_20.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
self.label_20.setObjectName(_fromUtf8("label_20"))
self.lineEditDays = QtGui.QLineEdit(self.widget)
self.lineEditDays.setGeometry(QtCore.QRect(113, 20, 51, 20))
self.lineEditDays.setObjectName(_fromUtf8("lineEditDays"))
self.lineEditMonths = QtGui.QLineEdit(self.widget)
self.lineEditMonths.setGeometry(QtCore.QRect(113, 40, 51, 20))
self.lineEditMonths.setObjectName(_fromUtf8("lineEditMonths"))
self.label_22 = QtGui.QLabel(self.widget)
self.label_22.setGeometry(QtCore.QRect(169, 23, 61, 16))
self.label_22.setObjectName(_fromUtf8("label_22"))
self.label_23 = QtGui.QLabel(self.widget)
self.label_23.setGeometry(QtCore.QRect(170, 41, 71, 16))
self.label_23.setObjectName(_fromUtf8("label_23"))
self.gridLayout_5.addWidget(self.widget, 1, 2, 1, 1)
spacerItem15 = QtGui.QSpacerItem(20, 129, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.gridLayout_5.addItem(spacerItem15, 2, 1, 1, 1)
self.tabWidgetSettings.addTab(self.tabResendsExpire, _fromUtf8(""))
self.gridLayout.addWidget(self.tabWidgetSettings, 0, 0, 1, 1)
def getNamecoinType(self): self.retranslateUi(settingsDialog)
""" self.tabWidgetSettings.setCurrentIndex(0)
Check status of namecoin integration radio buttons QtCore.QObject.connect( # pylint: disable=no-member
and translate it to a string as in the options. self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), settingsDialog.accept)
""" QtCore.QObject.connect( # pylint: disable=no-member
if self.radioButtonNamecoinNamecoind.isChecked(): self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), settingsDialog.reject)
return "namecoind" QtCore.QObject.connect( # pylint: disable=no-member
if self.radioButtonNamecoinNmcontrol.isChecked(): self.checkBoxAuthentication,
return "nmcontrol" QtCore.SIGNAL(
assert False _fromUtf8("toggled(bool)")),
self.lineEditSocksUsername.setEnabled)
QtCore.QObject.connect( # pylint: disable=no-member
self.checkBoxAuthentication,
QtCore.SIGNAL(
_fromUtf8("toggled(bool)")),
self.lineEditSocksPassword.setEnabled)
QtCore.QMetaObject.connectSlotsByName(settingsDialog)
settingsDialog.setTabOrder(self.tabWidgetSettings, self.checkBoxStartOnLogon)
settingsDialog.setTabOrder(self.checkBoxStartOnLogon, self.checkBoxStartInTray)
settingsDialog.setTabOrder(self.checkBoxStartInTray, self.checkBoxMinimizeToTray)
settingsDialog.setTabOrder(self.checkBoxMinimizeToTray, self.lineEditTCPPort)
settingsDialog.setTabOrder(self.lineEditTCPPort, self.comboBoxProxyType)
settingsDialog.setTabOrder(self.comboBoxProxyType, self.lineEditSocksHostname)
settingsDialog.setTabOrder(self.lineEditSocksHostname, self.lineEditSocksPort)
settingsDialog.setTabOrder(self.lineEditSocksPort, self.checkBoxAuthentication)
settingsDialog.setTabOrder(self.checkBoxAuthentication, self.lineEditSocksUsername)
settingsDialog.setTabOrder(self.lineEditSocksUsername, self.lineEditSocksPassword)
settingsDialog.setTabOrder(self.lineEditSocksPassword, self.checkBoxSocksListen)
settingsDialog.setTabOrder(self.checkBoxSocksListen, self.buttonBox)
# Namecoin connection type was changed. def retranslateUi(self, settingsDialog):
def namecoinTypeChanged(self, checked): # pylint: disable=unused-argument """Re-translate the UI into the supported languages"""
"""A callback for toggled event of radioButtonNamecoinNamecoind"""
nmctype = self.getNamecoinType()
assert nmctype == "namecoind" or nmctype == "nmcontrol"
isNamecoind = (nmctype == "namecoind") settingsDialog.setWindowTitle(_translate("settingsDialog", "Settings", None))
self.lineEditNamecoinUser.setEnabled(isNamecoind) self.checkBoxStartOnLogon.setText(_translate("settingsDialog", "Start Bitmessage on user login", None))
self.labelNamecoinUser.setEnabled(isNamecoind) self.groupBoxTray.setTitle(_translate("settingsDialog", "Tray", None))
self.lineEditNamecoinPassword.setEnabled(isNamecoind) self.checkBoxStartInTray.setText(
self.labelNamecoinPassword.setEnabled(isNamecoind)
if isNamecoind:
self.lineEditNamecoinPort.setText(defaults.namecoinDefaultRpcPort)
else:
self.lineEditNamecoinPort.setText("9000")
def click_pushButtonNamecoinTest(self):
"""Test the namecoin settings specified in the settings dialog."""
self.labelNamecoinTestResult.setText(
_translate("MainWindow", "Testing..."))
nc = namecoin.namecoinConnection({
'type': self.getNamecoinType(),
'host': str(self.lineEditNamecoinHost.text().toUtf8()),
'port': str(self.lineEditNamecoinPort.text().toUtf8()),
'user': str(self.lineEditNamecoinUser.text().toUtf8()),
'password': str(self.lineEditNamecoinPassword.text().toUtf8())
})
status, text = nc.test()
self.labelNamecoinTestResult.setText(text)
if status == 'success':
self.parent.namecoin = nc
def accept(self):
"""A callback for accepted event of buttonBox (OK button pressed)"""
# pylint: disable=too-many-branches,too-many-statements
super(SettingsDialog, self).accept()
if self.firstrun:
self.config.remove_option('bitmessagesettings', 'dontconnect')
self.config.set('bitmessagesettings', 'startonlogon', str(
self.checkBoxStartOnLogon.isChecked()))
self.config.set('bitmessagesettings', 'minimizetotray', str(
self.checkBoxMinimizeToTray.isChecked()))
self.config.set('bitmessagesettings', 'trayonclose', str(
self.checkBoxTrayOnClose.isChecked()))
self.config.set(
'bitmessagesettings', 'hidetrayconnectionnotifications',
str(self.checkBoxHideTrayConnectionNotifications.isChecked()))
self.config.set('bitmessagesettings', 'showtraynotifications', str(
self.checkBoxShowTrayNotifications.isChecked()))
self.config.set('bitmessagesettings', 'startintray', str(
self.checkBoxStartInTray.isChecked()))
self.config.set('bitmessagesettings', 'willinglysendtomobile', str(
self.checkBoxWillinglySendToMobile.isChecked()))
self.config.set('bitmessagesettings', 'useidenticons', str(
self.checkBoxUseIdenticons.isChecked()))
self.config.set('bitmessagesettings', 'replybelow', str(
self.checkBoxReplyBelow.isChecked()))
lang = str(self.languageComboBox.itemData(
self.languageComboBox.currentIndex()).toString())
self.config.set('bitmessagesettings', 'userlocale', lang)
self.parent.change_translation()
if int(self.config.get('bitmessagesettings', 'port')) != int(
self.lineEditTCPPort.text()):
self.config.set(
'bitmessagesettings', 'port', str(self.lineEditTCPPort.text()))
if not self.config.safeGetBoolean('bitmessagesettings', 'dontconnect'):
self.net_restart_needed = True
if self.checkBoxUPnP.isChecked() != self.config.safeGetBoolean(
'bitmessagesettings', 'upnp'):
self.config.set(
'bitmessagesettings', 'upnp',
str(self.checkBoxUPnP.isChecked()))
if self.checkBoxUPnP.isChecked():
import upnp
upnpThread = upnp.uPnPThread()
upnpThread.start()
proxytype_index = self.comboBoxProxyType.currentIndex()
if proxytype_index == 0:
if self._proxy_type and shared.statusIconColor != 'red':
self.net_restart_needed = True
elif self.comboBoxProxyType.currentText() != self._proxy_type:
self.net_restart_needed = True
self.parent.statusbar.clearMessage()
self.config.set(
'bitmessagesettings', 'socksproxytype',
'none' if self.comboBoxProxyType.currentIndex() == 0
else str(self.comboBoxProxyType.currentText())
)
if proxytype_index > 2: # last literal proxytype in ui
start_proxyconfig()
self.config.set('bitmessagesettings', 'socksauthentication', str(
self.checkBoxAuthentication.isChecked()))
self.config.set('bitmessagesettings', 'sockshostname', str(
self.lineEditSocksHostname.text()))
self.config.set('bitmessagesettings', 'socksport', str(
self.lineEditSocksPort.text()))
self.config.set('bitmessagesettings', 'socksusername', str(
self.lineEditSocksUsername.text()))
self.config.set('bitmessagesettings', 'sockspassword', str(
self.lineEditSocksPassword.text()))
self.config.set('bitmessagesettings', 'sockslisten', str(
self.checkBoxSocksListen.isChecked()))
if self.checkBoxOnionOnly.isChecked() \
and not self.config.safeGetBoolean('bitmessagesettings', 'onionservicesonly'):
self.net_restart_needed = True
self.config.set('bitmessagesettings', 'onionservicesonly', str(
self.checkBoxOnionOnly.isChecked()))
try:
# Rounding to integers just for aesthetics
self.config.set('bitmessagesettings', 'maxdownloadrate', str(
int(float(self.lineEditMaxDownloadRate.text()))))
self.config.set('bitmessagesettings', 'maxuploadrate', str(
int(float(self.lineEditMaxUploadRate.text()))))
except ValueError:
QtGui.QMessageBox.about(
self, _translate("MainWindow", "Number needed"),
_translate( _translate(
"MainWindow", "settingsDialog",
"Your maximum download and upload rate must be numbers." "Start Bitmessage in the tray (don\'t show main window)",
" Ignoring what you typed.") None))
) self.checkBoxMinimizeToTray.setText(_translate("settingsDialog", "Minimize to tray", None))
else: self.checkBoxTrayOnClose.setText(_translate("settingsDialog", "Close to tray", None))
set_rates( self.checkBoxHideTrayConnectionNotifications.setText(
self.config.safeGetInt('bitmessagesettings', 'maxdownloadrate'), _translate("settingsDialog", "Hide connection notifications", None))
self.config.safeGetInt('bitmessagesettings', 'maxuploadrate')) self.checkBoxShowTrayNotifications.setText(
self.config.set('bitmessagesettings', 'maxoutboundconnections', str(
int(float(self.lineEditMaxOutboundConnections.text()))))
self.config.set(
'bitmessagesettings', 'namecoinrpctype', self.getNamecoinType())
self.config.set('bitmessagesettings', 'namecoinrpchost', str(
self.lineEditNamecoinHost.text()))
self.config.set('bitmessagesettings', 'namecoinrpcport', str(
self.lineEditNamecoinPort.text()))
self.config.set('bitmessagesettings', 'namecoinrpcuser', str(
self.lineEditNamecoinUser.text()))
self.config.set('bitmessagesettings', 'namecoinrpcpassword', str(
self.lineEditNamecoinPassword.text()))
self.parent.resetNamecoinConnection()
# Demanded difficulty tab
if float(self.lineEditTotalDifficulty.text()) >= 1:
self.config.set(
'bitmessagesettings', 'defaultnoncetrialsperbyte',
str(int(
float(self.lineEditTotalDifficulty.text()) *
defaults.networkDefaultProofOfWorkNonceTrialsPerByte)))
if float(self.lineEditSmallMessageDifficulty.text()) >= 1:
self.config.set(
'bitmessagesettings', 'defaultpayloadlengthextrabytes',
str(int(
float(self.lineEditSmallMessageDifficulty.text()) *
defaults.networkDefaultPayloadLengthExtraBytes)))
if self.comboBoxOpenCL.currentText().toUtf8() != self.config.safeGet(
'bitmessagesettings', 'opencl'):
self.config.set(
'bitmessagesettings', 'opencl',
str(self.comboBoxOpenCL.currentText()))
queues.workerQueue.put(('resetPoW', ''))
acceptableDifficultyChanged = False
if (
float(self.lineEditMaxAcceptableTotalDifficulty.text()) >= 1 or
float(self.lineEditMaxAcceptableTotalDifficulty.text()) == 0
):
if self.config.get(
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte'
) != str(int(
float(self.lineEditMaxAcceptableTotalDifficulty.text()) *
defaults.networkDefaultProofOfWorkNonceTrialsPerByte)
):
# the user changed the max acceptable total difficulty
acceptableDifficultyChanged = True
self.config.set(
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte',
str(int(
float(self.lineEditMaxAcceptableTotalDifficulty.text()) *
defaults.networkDefaultProofOfWorkNonceTrialsPerByte))
)
if (
float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) >= 1 or
float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) == 0
):
if self.config.get(
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes'
) != str(int(
float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) *
defaults.networkDefaultPayloadLengthExtraBytes)
):
# the user changed the max acceptable small message difficulty
acceptableDifficultyChanged = True
self.config.set(
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes',
str(int(
float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) *
defaults.networkDefaultPayloadLengthExtraBytes))
)
if acceptableDifficultyChanged:
# It might now be possible to send msgs which were previously
# marked as toodifficult. Let us change them to 'msgqueued'.
# The singleWorker will try to send them and will again mark
# them as toodifficult if the receiver's required difficulty
# is still higher than we are willing to do.
sqlExecute(
"UPDATE sent SET status='msgqueued'"
" WHERE status='toodifficult'")
queues.workerQueue.put(('sendmessage', ''))
# 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.
if self.lineEditDays.text() == '' and self.lineEditMonths.text() == '':
# We need to handle this special case. Bitmessage has its
# default behavior. The input is blank/blank
self.config.set('bitmessagesettings', 'stopresendingafterxdays', '')
self.config.set('bitmessagesettings', 'stopresendingafterxmonths', '')
shared.maximumLengthOfTimeToBotherResendingMessages = float('inf')
try:
days = float(self.lineEditDays.text())
except ValueError:
self.lineEditDays.setText("0")
days = 0.0
try:
months = float(self.lineEditMonths.text())
except ValueError:
self.lineEditMonths.setText("0")
months = 0.0
if days >= 0 and months >= 0:
shared.maximumLengthOfTimeToBotherResendingMessages = \
days * 24 * 60 * 60 + months * 60 * 60 * 24 * 365 / 12
if shared.maximumLengthOfTimeToBotherResendingMessages < 432000:
# If the time period is less than 5 hours, we give
# zero values to all fields. No message will be sent again.
QtGui.QMessageBox.about(
self,
_translate("MainWindow", "Will not resend ever"),
_translate( _translate(
"MainWindow", "settingsDialog",
"Note that the time limit you entered is less" "Show notification when message received",
" than the amount of time Bitmessage waits for" None))
" the first resend attempt therefore your" self.checkBoxPortableMode.setText(_translate("settingsDialog", "Run in Portable Mode", None))
" messages will never be resent.") self.PortableModeDescription.setText(
) _translate(
self.config.set( "settingsDialog",
'bitmessagesettings', 'stopresendingafterxdays', '0') "In Portable Mode, messages and config files are stored in the same directory as the"
self.config.set( " program rather than the normal application-data folder. This makes it convenient to"
'bitmessagesettings', 'stopresendingafterxmonths', '0') " run Bitmessage from a USB thumb drive.",
shared.maximumLengthOfTimeToBotherResendingMessages = 0.0 None))
else: self.checkBoxWillinglySendToMobile.setText(
self.config.set( _translate(
'bitmessagesettings', 'stopresendingafterxdays', str(days)) "settingsDialog",
self.config.set( "Willingly include unencrypted destination address when sending to a mobile device",
'bitmessagesettings', 'stopresendingafterxmonths', None))
str(months)) self.checkBoxUseIdenticons.setText(_translate("settingsDialog", "Use Identicons", None))
self.checkBoxReplyBelow.setText(_translate("settingsDialog", "Reply below Quote", None))
self.config.save() self.groupBox.setTitle(_translate("settingsDialog", "Interface Language", None))
self.languageComboBox.setItemText(0, _translate("settingsDialog", "System Settings", "system"))
if self.net_restart_needed: self.tabWidgetSettings.setTabText(
self.net_restart_needed = False self.tabWidgetSettings.indexOf(
self.config.setTemp('bitmessagesettings', 'dontconnect', 'true') self.tabUserInterface),
self.timer.singleShot( _translate(
5000, lambda: "settingsDialog", "User Interface", None))
self.config.setTemp( self.groupBox1.setTitle(_translate("settingsDialog", "Listening port", None))
'bitmessagesettings', 'dontconnect', 'false') self.label.setText(_translate("settingsDialog", "Listen for connections on port:", None))
) self.labelUPnP.setText(_translate("settingsDialog", "UPnP:", None))
self.groupBox_3.setTitle(_translate("settingsDialog", "Bandwidth limit", None))
self.parent.updateStartOnLogon() self.label_24.setText(_translate("settingsDialog", "Maximum download rate (kB/s): [0: unlimited]", None))
self.label_25.setText(_translate("settingsDialog", "Maximum upload rate (kB/s): [0: unlimited]", None))
if ( self.label_26.setText(_translate("settingsDialog", "Maximum outbound connections: [0: none]", None))
state.appdata != paths.lookupExeFolder() and self.groupBox_2.setTitle(_translate("settingsDialog", "Proxy server / Tor", None))
self.checkBoxPortableMode.isChecked() self.label_2.setText(_translate("settingsDialog", "Type:", None))
): self.label_3.setText(_translate("settingsDialog", "Server hostname:", None))
# If we are NOT using portable mode now but the user selected self.label_4.setText(_translate("settingsDialog", "Port:", None))
# that we should... self.checkBoxAuthentication.setText(_translate("settingsDialog", "Authentication", None))
# Write the keys.dat file to disk in the new location self.label_5.setText(_translate("settingsDialog", "Username:", None))
sqlStoredProcedure('movemessagstoprog') self.label_6.setText(_translate("settingsDialog", "Pass:", None))
with open(paths.lookupExeFolder() + 'keys.dat', 'wb') as configfile: self.checkBoxSocksListen.setText(
self.config.write(configfile) _translate(
# Write the knownnodes.dat file to disk in the new location "settingsDialog",
knownnodes.saveKnownNodes(paths.lookupExeFolder()) "Listen for incoming connections when using proxy",
os.remove(state.appdata + 'keys.dat') None))
os.remove(state.appdata + 'knownnodes.dat') self.comboBoxProxyType.setItemText(0, _translate("settingsDialog", "none", None))
previousAppdataLocation = state.appdata self.comboBoxProxyType.setItemText(1, _translate("settingsDialog", "SOCKS4a", None))
state.appdata = paths.lookupExeFolder() self.comboBoxProxyType.setItemText(2, _translate("settingsDialog", "SOCKS5", None))
debug.resetLogging() self.tabWidgetSettings.setTabText(
try: self.tabWidgetSettings.indexOf(
os.remove(previousAppdataLocation + 'debug.log') self.tabNetworkSettings),
os.remove(previousAppdataLocation + 'debug.log.1') _translate(
except: "settingsDialog", "Network Settings", None))
pass self.label_9.setText(_translate("settingsDialog", "Total difficulty:", None))
self.label_10.setText(
if ( _translate(
state.appdata == paths.lookupExeFolder() and "settingsDialog",
not self.checkBoxPortableMode.isChecked() "The \'Total difficulty\' affects the absolute amount of work the sender must complete."
): " Doubling this value doubles the amount of work.",
# If we ARE using portable mode now but the user selected None))
# that we shouldn't... self.label_11.setText(_translate("settingsDialog", "Small message difficulty:", None))
state.appdata = paths.lookupAppdataFolder() self.label_8.setText(_translate(
if not os.path.exists(state.appdata): "settingsDialog",
os.makedirs(state.appdata) "When someone sends you a message, their computer must first complete some work. The difficulty of this"
sqlStoredProcedure('movemessagstoappdata') " work, by default, is 1. You may raise this default for new addresses you create by changing the values"
# Write the keys.dat file to disk in the new location " here. Any new addresses you create will require senders to meet the higher difficulty. There is one"
self.config.save() " exception: if you add a friend or acquaintance to your address book, Bitmessage will automatically"
# Write the knownnodes.dat file to disk in the new location " notify them when you next send a message that they need only complete the minimum amount of"
knownnodes.saveKnownNodes(state.appdata) " work: difficulty 1. ",
os.remove(paths.lookupExeFolder() + 'keys.dat') None))
os.remove(paths.lookupExeFolder() + 'knownnodes.dat') self.label_12.setText(
debug.resetLogging() _translate(
try: "settingsDialog",
os.remove(paths.lookupExeFolder() + 'debug.log') "The \'Small message difficulty\' mostly only affects the difficulty of sending small messages."
os.remove(paths.lookupExeFolder() + 'debug.log.1') " Doubling this value makes it almost twice as difficult to send a small message but doesn\'t really"
except: " affect large messages.",
pass None))
self.tabWidgetSettings.setTabText(
self.tabWidgetSettings.indexOf(
self.tabDemandedDifficulty),
_translate(
"settingsDialog", "Demanded difficulty", None))
self.label_15.setText(
_translate(
"settingsDialog",
"Here you may set the maximum amount of work you are willing to do to send a message to another"
" person. Setting these values to 0 means that any value is acceptable.",
None))
self.label_13.setText(_translate("settingsDialog", "Maximum acceptable total difficulty:", None))
self.label_14.setText(_translate("settingsDialog", "Maximum acceptable small message difficulty:", None))
self.tabWidgetSettings.setTabText(
self.tabWidgetSettings.indexOf(
self.tabMaxAcceptableDifficulty),
_translate(
"settingsDialog", "Max acceptable difficulty", None))
self.labelOpenCL.setText(_translate("settingsDialog", "Hardware GPU acceleration (OpenCL):", None))
self.label_16.setText(_translate(
"settingsDialog",
"<html><head/><body><p>Bitmessage can utilize a different Bitcoin-based program called Namecoin to make"
" addresses human-friendly. For example, instead of having to tell your friend your long Bitmessage"
" address, you can simply tell him to send a message to <span style=\" font-style:italic;\">test."
" </span></p><p>(Getting your own Bitmessage address into Namecoin is still rather difficult).</p>"
"<p>Bitmessage can use either namecoind directly or a running nmcontrol instance.</p></body></html>",
None))
self.label_17.setText(_translate("settingsDialog", "Host:", None))
self.label_18.setText(_translate("settingsDialog", "Port:", None))
self.labelNamecoinUser.setText(_translate("settingsDialog", "Username:", None))
self.labelNamecoinPassword.setText(_translate("settingsDialog", "Password:", None))
self.pushButtonNamecoinTest.setText(_translate("settingsDialog", "Test", None))
self.label_21.setText(_translate("settingsDialog", "Connect to:", None))
self.radioButtonNamecoinNamecoind.setText(_translate("settingsDialog", "Namecoind", None))
self.radioButtonNamecoinNmcontrol.setText(_translate("settingsDialog", "NMControl", None))
self.tabWidgetSettings.setTabText(
self.tabWidgetSettings.indexOf(
self.tabNamecoin),
_translate(
"settingsDialog", "Namecoin integration", None))
self.label_7.setText(_translate(
"settingsDialog",
"<html><head/><body><p>By default, if you send a message to someone and he is offline for more than two"
" days, Bitmessage will send the message again after an additional two days. This will be continued with"
" exponential backoff forever; messages will be resent after 5, 10, 20 days ect. until the receiver"
" acknowledges them. Here you may change that behavior by having Bitmessage give up after a certain"
" number of days or months.</p><p>Leave these input fields blank for the default behavior."
" </p></body></html>",
None))
self.label_19.setText(_translate("settingsDialog", "Give up after", None))
self.label_20.setText(_translate("settingsDialog", "and", None))
self.label_22.setText(_translate("settingsDialog", "days", None))
self.label_23.setText(_translate("settingsDialog", "months.", None))
self.tabWidgetSettings.setTabText(
self.tabWidgetSettings.indexOf(
self.tabResendsExpire),
_translate(
"settingsDialog", "Resends Expire", None))

View File

@ -37,18 +37,6 @@
<string>User Interface</string> <string>User Interface</string>
</attribute> </attribute>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
<property name="leftMargin">
<number>8</number>
</property>
<property name="topMargin">
<number>8</number>
</property>
<property name="rightMargin">
<number>8</number>
</property>
<property name="bottomMargin">
<number>8</number>
</property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QCheckBox" name="checkBoxStartOnLogon"> <widget class="QCheckBox" name="checkBoxStartOnLogon">
<property name="text"> <property name="text">
@ -56,43 +44,20 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0" colspan="2">
<widget class="QGroupBox" name="groupBoxTray">
<property name="title">
<string>Tray</string>
</property>
<layout class="QVBoxLayout" name="formLayoutTray">
<item>
<widget class="QCheckBox" name="checkBoxStartInTray"> <widget class="QCheckBox" name="checkBoxStartInTray">
<property name="text"> <property name="text">
<string>Start Bitmessage in the tray (don't show main window)</string> <string>Start Bitmessage in the tray (don't show main window)</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="2" column="0">
<widget class="QCheckBox" name="checkBoxMinimizeToTray"> <widget class="QCheckBox" name="checkBoxMinimizeToTray">
<property name="text"> <property name="text">
<string>Minimize to tray</string> <string>Minimize to tray</string>
</property> </property>
<property name="checked"> <property name="checked">
<bool>false</bool> <bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxTrayOnClose">
<property name="text">
<string>Close to tray</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="checkBoxHideTrayConnectionNotifications">
<property name="text">
<string>Hide connection notifications</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -152,15 +117,90 @@
<property name="title"> <property name="title">
<string>Interface Language</string> <string>Interface Language</string>
</property> </property>
<layout class="QVBoxLayout"> <layout class="QFormLayout" name="formLayout_2">
<item> <item row="0" column="0">
<widget class="LanguageBox" name="languageComboBox"> <widget class="QComboBox" name="languageComboBox">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>100</width> <width>100</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
<item>
<property name="text">
<string comment="system">System Settings</string>
</property>
</item>
<item>
<property name="text">
<string notr="true" comment="en">English</string>
</property>
</item>
<item>
<property name="text">
<string notr="true" comment="eo">Esperanto</string>
</property>
</item>
<item>
<property name="text">
<string notr="true" comment="fr">Français</string>
</property>
</item>
<item>
<property name="text">
<string notr="true" comment="de">Deutsch</string>
</property>
</item>
<item>
<property name="text">
<string notr="true" comment="es">Español</string>
</property>
</item>
<item>
<property name="text">
<string notr="true" comment="ru">русский</string>
</property>
</item>
<item>
<property name="text">
<string notr="true" comment="no">Norsk</string>
</property>
</item>
<item>
<property name="text">
<string notr="true" comment="ar">العربية</string>
</property>
</item>
<item>
<property name="text">
<string notr="true" comment="zh_cn">简体中文</string>
</property>
</item>
<item>
<property name="text">
<string notr="true" comment="ja">日本語</string>
</property>
</item>
<item>
<property name="text">
<string notr="true" comment="nl">Nederlands</string>
</property>
</item>
<item>
<property name="text">
<string notr="true" comment="cs">Česky</string>
</property>
</item>
<item>
<property name="text">
<string comment="en_pirate">Pirate English</string>
</property>
</item>
<item>
<property name="text">
<string comment="other">Other (set in keys.dat)</string>
</property>
</item>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -173,18 +213,6 @@
<string>Network Settings</string> <string>Network Settings</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_4"> <layout class="QGridLayout" name="gridLayout_4">
<property name="leftMargin">
<number>8</number>
</property>
<property name="topMargin">
<number>8</number>
</property>
<property name="rightMargin">
<number>8</number>
</property>
<property name="bottomMargin">
<number>8</number>
</property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QGroupBox" name="groupBox"> <widget class="QGroupBox" name="groupBox">
<property name="title"> <property name="title">
@ -192,13 +220,26 @@
</property> </property>
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0"> <item row="0" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>125</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
<string>Listen for connections on port:</string> <string>Listen for connections on port:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="2">
<widget class="QLineEdit" name="lineEditTCPPort"> <widget class="QLineEdit" name="lineEditTCPPort">
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
@ -208,26 +249,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="4">
<widget class="QCheckBox" name="checkBoxUPnP">
<property name="text">
<string>UPnP</string>
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -403,13 +424,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="1" colspan="4">
<widget class="QCheckBox" name="checkBoxOnionOnly">
<property name="text">
<string>Only connect to onion services (*.onion)</string>
</property>
</widget>
</item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QComboBox" name="comboBoxProxyType"> <widget class="QComboBox" name="comboBoxProxyType">
<item> <item>
@ -419,12 +433,12 @@
</item> </item>
<item> <item>
<property name="text"> <property name="text">
<string notr="true">SOCKS4a</string> <string>SOCKS4a</string>
</property> </property>
</item> </item>
<item> <item>
<property name="text"> <property name="text">
<string notr="true">SOCKS5</string> <string>SOCKS5</string>
</property> </property>
</item> </item>
</widget> </widget>
@ -452,18 +466,6 @@
<string>Demanded difficulty</string> <string>Demanded difficulty</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_6"> <layout class="QGridLayout" name="gridLayout_6">
<property name="leftMargin">
<number>8</number>
</property>
<property name="topMargin">
<number>8</number>
</property>
<property name="rightMargin">
<number>8</number>
</property>
<property name="bottomMargin">
<number>8</number>
</property>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QLabel" name="label_9"> <widget class="QLabel" name="label_9">
<property name="text"> <property name="text">
@ -592,18 +594,6 @@
<string>Max acceptable difficulty</string> <string>Max acceptable difficulty</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_7"> <layout class="QGridLayout" name="gridLayout_7">
<property name="leftMargin">
<number>8</number>
</property>
<property name="topMargin">
<number>8</number>
</property>
<property name="rightMargin">
<number>8</number>
</property>
<property name="bottomMargin">
<number>8</number>
</property>
<item row="0" column="0" colspan="3"> <item row="0" column="0" colspan="3">
<widget class="QLabel" name="label_15"> <widget class="QLabel" name="label_15">
<property name="text"> <property name="text">
@ -708,33 +698,6 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="4" column="0" colspan="3">
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="labelOpenCL">
<property name="text">
<string>Hardware GPU acceleration (OpenCL):</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBoxOpenCL"/>
</item>
<item>
<spacer name="horizontalSpacer_12">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="tabNamecoin"> <widget class="QWidget" name="tabNamecoin">
@ -742,18 +705,6 @@
<string>Namecoin integration</string> <string>Namecoin integration</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_8"> <layout class="QGridLayout" name="gridLayout_8">
<property name="leftMargin">
<number>8</number>
</property>
<property name="topMargin">
<number>8</number>
</property>
<property name="rightMargin">
<number>8</number>
</property>
<property name="bottomMargin">
<number>8</number>
</property>
<item row="2" column="0"> <item row="2" column="0">
<spacer name="horizontalSpacer_6"> <spacer name="horizontalSpacer_6">
<property name="orientation"> <property name="orientation">
@ -937,18 +888,6 @@
<string>Resends Expire</string> <string>Resends Expire</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_5"> <layout class="QGridLayout" name="gridLayout_5">
<property name="leftMargin">
<number>8</number>
</property>
<property name="topMargin">
<number>8</number>
</property>
<property name="rightMargin">
<number>8</number>
</property>
<property name="bottomMargin">
<number>8</number>
</property>
<item row="0" column="0" colspan="3"> <item row="0" column="0" colspan="3">
<widget class="QLabel" name="label_7"> <widget class="QLabel" name="label_7">
<property name="text"> <property name="text">
@ -973,16 +912,22 @@
</spacer> </spacer>
</item> </item>
<item row="1" column="2"> <item row="1" column="2">
<widget class="QGroupBox"> <widget class="QWidget" name="widget" native="true">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>231</width> <width>231</width>
<height>75</height> <height>75</height>
</size> </size>
</property> </property>
<layout class="QGridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_19"> <widget class="QLabel" name="label_19">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>101</width>
<height>20</height>
</rect>
</property>
<property name="text"> <property name="text">
<string>Give up after</string> <string>Give up after</string>
</property> </property>
@ -990,9 +935,15 @@
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
</widget> </widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_20"> <widget class="QLabel" name="label_20">
<property name="geometry">
<rect>
<x>30</x>
<y>40</y>
<width>80</width>
<height>16</height>
</rect>
</property>
<property name="text"> <property name="text">
<string>and</string> <string>and</string>
</property> </property>
@ -1000,42 +951,52 @@
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
</widget> </widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEditDays"> <widget class="QLineEdit" name="lineEditDays">
<property name="maximumSize"> <property name="geometry">
<size> <rect>
<width>55</width> <x>113</x>
<height>100</height> <y>20</y>
</size> <width>51</width>
<height>20</height>
</rect>
</property> </property>
</widget> </widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEditMonths"> <widget class="QLineEdit" name="lineEditMonths">
<property name="maximumSize"> <property name="geometry">
<size> <rect>
<width>55</width> <x>113</x>
<height>100</height> <y>40</y>
</size> <width>51</width>
<height>20</height>
</rect>
</property> </property>
</widget> </widget>
</item> <widget class="QLabel" name="label_22">
<item row="0" column="2"> <property name="geometry">
<widget class="QLabel"> <rect>
<x>169</x>
<y>23</y>
<width>61</width>
<height>16</height>
</rect>
</property>
<property name="text"> <property name="text">
<string>days</string> <string>days</string>
</property> </property>
</widget> </widget>
</item> <widget class="QLabel" name="label_23">
<item row="1" column="2"> <property name="geometry">
<widget class="QLabel"> <rect>
<x>170</x>
<y>41</y>
<width>71</width>
<height>16</height>
</rect>
</property>
<property name="text"> <property name="text">
<string>months.</string> <string>months.</string>
</property> </property>
</widget> </widget>
</item>
</layout>
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="2" column="1">
@ -1057,13 +1018,6 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>LanguageBox</class>
<extends>QComboBox</extends>
<header>bitmessageqt.languagebox</header>
</customwidget>
</customwidgets>
<tabstops> <tabstops>
<tabstop>tabWidgetSettings</tabstop> <tabstop>tabWidgetSettings</tabstop>
<tabstop>checkBoxStartOnLogon</tabstop> <tabstop>checkBoxStartOnLogon</tabstop>
@ -1147,53 +1101,5 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>comboBoxProxyType</sender>
<signal>currentIndexChanged(int)</signal>
<receiver>settingsDialog</receiver>
<slot>comboBoxProxyTypeChanged</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
<connection>
<sender>radioButtonNamecoinNamecoind</sender>
<signal>toggled(bool)</signal>
<receiver>settingsDialog</receiver>
<slot>namecoinTypeChanged</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
<connection>
<sender>pushButtonNamecoinTest</sender>
<signal>clicked()</signal>
<receiver>settingsDialog</receiver>
<slot>click_pushButtonNamecoinTest</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
</connections> </connections>
</ui> </ui>

View File

@ -15,7 +15,6 @@ from openclpow import openclAvailable, openclEnabled
import paths import paths
import proofofwork import proofofwork
from pyelliptic.openssl import OpenSSL from pyelliptic.openssl import OpenSSL
from settings import getSOCKSProxyType
import queues import queues
import network.stats import network.stats
import state import state
@ -119,7 +118,8 @@ def createSupportMessage(myapp):
BMConfigParser().safeGet('bitmessagesettings', 'opencl') BMConfigParser().safeGet('bitmessagesettings', 'opencl')
) if openclEnabled() else "None" ) if openclEnabled() else "None"
locale = getTranslationLanguage() locale = getTranslationLanguage()
socks = getSOCKSProxyType(BMConfigParser()) or "N/A" socks = BMConfigParser().safeGet(
'bitmessagesettings', 'socksproxytype', "N/A")
upnp = BMConfigParser().safeGet('bitmessagesettings', 'upnp', "N/A") upnp = BMConfigParser().safeGet('bitmessagesettings', 'upnp', "N/A")
connectedhosts = len(network.stats.connectedHostsList()) connectedhosts = len(network.stats.connectedHostsList())

View File

@ -3,8 +3,8 @@ BMConfigParser class definition and default configuration settings
""" """
import ConfigParser import ConfigParser
import os
import shutil import shutil
import os
from datetime import datetime from datetime import datetime
import state import state
@ -43,13 +43,8 @@ BMConfigDefaults = {
@Singleton @Singleton
class BMConfigParser(ConfigParser.SafeConfigParser): class BMConfigParser(ConfigParser.SafeConfigParser):
""" """Singleton class inherited from ConfigParser.SafeConfigParser
Singleton class inherited from :class:`ConfigParser.SafeConfigParser` with additional methods specific to bitmessage config."""
with additional methods specific to bitmessage config.
"""
# pylint: disable=too-many-ancestors
_temp = {}
def set(self, section, option, value=None): def set(self, section, option, value=None):
if self._optcre is self.OPTCRE or value: if self._optcre is self.OPTCRE or value:
@ -60,15 +55,10 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
return ConfigParser.ConfigParser.set(self, section, option, value) return ConfigParser.ConfigParser.set(self, section, option, value)
def get(self, section, option, raw=False, variables=None): def get(self, section, option, raw=False, variables=None):
# pylint: disable=arguments-differ
try: try:
if section == "bitmessagesettings" and option == "timeformat": if section == "bitmessagesettings" and option == "timeformat":
return ConfigParser.ConfigParser.get( return ConfigParser.ConfigParser.get(
self, section, option, raw, variables) self, section, option, raw, variables)
try:
return self._temp[section][option]
except KeyError:
pass
return ConfigParser.ConfigParser.get( return ConfigParser.ConfigParser.get(
self, section, option, True, variables) self, section, option, True, variables)
except ConfigParser.InterpolationError: except ConfigParser.InterpolationError:
@ -80,15 +70,7 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
except (KeyError, ValueError, AttributeError): except (KeyError, ValueError, AttributeError):
raise e raise e
def setTemp(self, section, option, value=None):
"""Temporary set option to value, not saving."""
try:
self._temp[section][option] = value
except KeyError:
self._temp[section] = {option: value}
def safeGetBoolean(self, section, field): def safeGetBoolean(self, section, field):
"""Return value as boolean, False on exceptions"""
try: try:
return self.getboolean(section, field) return self.getboolean(section, field)
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, except (ConfigParser.NoSectionError, ConfigParser.NoOptionError,
@ -96,8 +78,6 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
return False return False
def safeGetInt(self, section, field, default=0): def safeGetInt(self, section, field, default=0):
"""Return value as integer, default on exceptions,
0 if default missing"""
try: try:
return self.getint(section, field) return self.getint(section, field)
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, except (ConfigParser.NoSectionError, ConfigParser.NoOptionError,
@ -105,7 +85,6 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
return default return default
def safeGet(self, section, option, default=None): def safeGet(self, section, option, default=None):
"""Return value as is, default on exceptions, None if default missing"""
try: try:
return self.get(section, option) return self.get(section, option)
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError, except (ConfigParser.NoSectionError, ConfigParser.NoOptionError,
@ -113,16 +92,11 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
return default return default
def items(self, section, raw=False, variables=None): def items(self, section, raw=False, variables=None):
"""Return section variables as parent,
but override the "raw" argument to always True"""
# pylint: disable=arguments-differ
return ConfigParser.ConfigParser.items(self, section, True, variables) return ConfigParser.ConfigParser.items(self, section, True, variables)
@staticmethod def addresses(self):
def addresses(): return filter(
"""Return a list of local bitmessage addresses (from section labels)""" lambda x: x.startswith('BM-'), BMConfigParser().sections())
return [
x for x in BMConfigParser().sections() if x.startswith('BM-')]
def read(self, filenames): def read(self, filenames):
ConfigParser.ConfigParser.read(self, filenames) ConfigParser.ConfigParser.read(self, filenames)
@ -143,7 +117,6 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
continue continue
def save(self): def save(self):
"""Save the runtime config onto the filesystem"""
fileName = os.path.join(state.appdata, 'keys.dat') fileName = os.path.join(state.appdata, 'keys.dat')
fileNameBak = '.'.join([ fileNameBak = '.'.join([
fileName, datetime.now().strftime("%Y%j%H%M%S%f"), 'bak']) fileName, datetime.now().strftime("%Y%j%H%M%S%f"), 'bak'])
@ -165,15 +138,12 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
os.remove(fileNameBak) os.remove(fileNameBak)
def validate(self, section, option, value): def validate(self, section, option, value):
"""Input validator interface (using factory pattern)"""
try: try:
return getattr(self, 'validate_%s_%s' % (section, option))(value) return getattr(self, 'validate_%s_%s' % (section, option))(value)
except AttributeError: except AttributeError:
return True return True
@staticmethod def validate_bitmessagesettings_maxoutboundconnections(self, value):
def validate_bitmessagesettings_maxoutboundconnections(value):
"""Reject maxoutboundconnections that are too high or too low"""
try: try:
value = int(value) value = int(value)
except ValueError: except ValueError:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 640 B

View File

@ -1,6 +1,5 @@
"""Building osx."""
import os
from glob import glob from glob import glob
import os
from PyQt4 import QtCore from PyQt4 import QtCore
from setuptools import setup from setuptools import setup
@ -13,14 +12,8 @@ DATA_FILES = [
('bitmsghash', ['bitmsghash/bitmsghash.cl', 'bitmsghash/bitmsghash.so']), ('bitmsghash', ['bitmsghash/bitmsghash.cl', 'bitmsghash/bitmsghash.so']),
('translations', glob('translations/*.qm')), ('translations', glob('translations/*.qm')),
('ui', glob('bitmessageqt/*.ui')), ('ui', glob('bitmessageqt/*.ui')),
( ('translations', glob(str(QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.TranslationsPath)) + '/qt_??.qm')),
'translations', ('translations', glob(str(QtCore.QLibraryInfo.location(QtCore.QLibraryInfo.TranslationsPath)) + '/qt_??_??.qm')),
glob(os.path.join(str(QtCore.QLibraryInfo.location(
QtCore.QLibraryInfo.TranslationsPath)), 'qt_??.qm'))),
(
'translations',
glob(os.path.join(str(QtCore.QLibraryInfo.location(
QtCore.QLibraryInfo.TranslationsPath)), 'qt_??_??.qm'))),
] ]
setup( setup(

View File

@ -1,10 +1,10 @@
[app] [app]
# (str) Title of your application # (str) Title of your application
title = bitapp title = PyBitmessage
# (str) Package name # (str) Package name
package.name = bitapp package.name = PyBitmessage
# (str) Package domain (needed for android/ios packaging) # (str) Package domain (needed for android/ios packaging)
package.domain = org.test package.domain = org.test
@ -13,7 +13,7 @@ package.domain = org.test
source.dir = . source.dir = .
# (list) Source files to include (let empty to include all the files) # (list) Source files to include (let empty to include all the files)
source.include_exts = py,png,jpg,kv,atlas,gif,zip source.include_exts = py,png,jpg,kv,atlas
# (list) List of inclusions using pattern matching # (list) List of inclusions using pattern matching
#source.include_patterns = assets/*,images/*.png #source.include_patterns = assets/*,images/*.png
@ -35,25 +35,16 @@ version = 0.1
# version.filename = %(source.dir)s/main.py # version.filename = %(source.dir)s/main.py
# (list) Application requirements # (list) Application requirements
# comma separated e.g. requirements = sqlite3,kivy # comma seperated e.g. requirements = sqlite3,kivy
requirements = requirements = python2, sqlite3, kivy, openssl
openssl,
sqlite3,
python2,
kivy,
bitmsghash,
kivymd,
kivy-garden,
qrcode,
Pillow,
msgpack
# (str) Custom source folders for requirements # (str) Custom source folders for requirements
# Sets custom source for any requirements with recipes # Sets custom source for any requirements with recipes
# requirements.source.kivy = ../../kivy # requirements.source.kivy = ../../kivy
#requirements.source.sqlite3 =
# (list) Garden requirements # (list) Garden requirements
garden_requirements = qrcode #garden_requirements =
# (str) Presplash of the application # (str) Presplash of the application
#presplash.filename = %(source.dir)s/data/presplash.png #presplash.filename = %(source.dir)s/data/presplash.png
@ -75,7 +66,8 @@ orientation = portrait
# author = © Copyright Info # author = © Copyright Info
# change the major version of python used by the app # change the major version of python used by the app
osx.python_version = 3 #osx.python_version = 2
# Kivy version to use # Kivy version to use
osx.kivy_version = 1.9.1 osx.kivy_version = 1.9.1
@ -95,19 +87,19 @@ fullscreen = 0
#android.presplash_color = #FFFFFF #android.presplash_color = #FFFFFF
# (list) Permissions # (list) Permissions
android.permissions = INTERNET, WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE android.permissions = INTERNET
# (int) Android API to use # (int) Android API to use
android.api = 27 #android.api = 19
# (int) Minimum API required # (int) Minimum API required
android.minapi = 21 #android.minapi = 9
# (int) Android SDK version to use # (int) Android SDK version to use
android.sdk = 20 #android.sdk = 20
# (str) Android NDK version to use # (str) Android NDK version to use
android.ndk = 17c #android.ndk = 9c
# (bool) Use --private data storage (True) or --dir public storage (False) # (bool) Use --private data storage (True) or --dir public storage (False)
#android.private_storage = True #android.private_storage = True
@ -132,6 +124,9 @@ android.ndk = 17c
# (list) Pattern to whitelist for the whole project # (list) Pattern to whitelist for the whole project
#android.whitelist = #android.whitelist =
android.whitelist = /usr/lib/komodo-edit/python/lib/python2.7/lib-dynload/_sqlite3.so
# (str) Path to a custom whitelist file # (str) Path to a custom whitelist file
#android.whitelist_src = #android.whitelist_src =
@ -155,12 +150,9 @@ android.ndk = 17c
# (list) Gradle dependencies to add (currently works only with sdl2_gradle # (list) Gradle dependencies to add (currently works only with sdl2_gradle
# bootstrap) # bootstrap)
#android.gradle_dependencies = #android.gradle_dependencies =
, /home/cis/Downloads/libssl1.0.2_1.0.2l-2+deb9u2_amd64
# (list) Java classes to add as activities to the manifest.
#android.add_activites = com.example.ExampleActivity
# (str) python-for-android branch to use, defaults to stable # (str) python-for-android branch to use, defaults to stable
p4a.branch = release-2019.07.08 #p4a.branch = stable
# (str) OUYA Console category. Should be one of GAME or APP # (str) OUYA Console category. Should be one of GAME or APP
# If you leave this blank, OUYA support will not be enabled # If you leave this blank, OUYA support will not be enabled
@ -172,10 +164,7 @@ p4a.branch = release-2019.07.08
# (str) XML file to include as an intent filters in <activity> tag # (str) XML file to include as an intent filters in <activity> tag
#android.manifest.intent_filters = #android.manifest.intent_filters =
# (str) launchMode to set for the main activity # (list) Android additionnal libraries to copy into libs/armeabi
#android.manifest.launch_mode = standard
# (list) Android additional libraries to copy into libs/armeabi
#android.add_libs_armeabi = libs/android/*.so #android.add_libs_armeabi = libs/android/*.so
#android.add_libs_armeabi_v7a = libs/android-v7/*.so #android.add_libs_armeabi_v7a = libs/android-v7/*.so
#android.add_libs_x86 = libs/android-x86/*.so #android.add_libs_x86 = libs/android-x86/*.so
@ -209,7 +198,7 @@ android.arch = armeabi-v7a
#p4a.source_dir = #p4a.source_dir =
# (str) The directory in which python-for-android should look for your own build recipes (if any) # (str) The directory in which python-for-android should look for your own build recipes (if any)
p4a.local_recipes = /home/cis/navjotrepo/PyBitmessage/src/bitmessagekivy/android/python-for-android/recipes/ #p4a.local_recipes =
# (str) Filename to the hook for p4a # (str) Filename to the hook for p4a
#p4a.hook = #p4a.hook =
@ -217,9 +206,6 @@ p4a.local_recipes = /home/cis/navjotrepo/PyBitmessage/src/bitmessagekivy/android
# (str) Bootstrap to use for android builds # (str) Bootstrap to use for android builds
# p4a.bootstrap = sdl2 # p4a.bootstrap = sdl2
# (int) port number to specify an explicit --port= p4a argument (eg for bootstrap flask)
#p4a.port =
# #
# iOS specific # iOS specific

View File

@ -1,28 +1,30 @@
"""
A thread for creating addresses
"""
import hashlib
import time
from binascii import hexlify
import defaults import time
import highlevelcrypto import threading
import queues import hashlib
import shared from binascii import hexlify
import state
import tr
from addresses import decodeAddress, encodeAddress, encodeVarint
from bmconfigparser import BMConfigParser
from fallback import RIPEMD160Hash
from network import StoppableThread
from pyelliptic import arithmetic from pyelliptic import arithmetic
from pyelliptic.openssl import OpenSSL from pyelliptic.openssl import OpenSSL
import tr
import queues
import state
import shared
import defaults
import highlevelcrypto
from bmconfigparser import BMConfigParser
from debug import logger
from addresses import decodeAddress, encodeAddress, encodeVarint
from fallback import RIPEMD160Hash
from helper_threading import StoppableThread
class addressGenerator(StoppableThread):
"""A thread for creating addresses"""
name = "addressGenerator" class addressGenerator(threading.Thread, StoppableThread):
def __init__(self):
# QThread.__init__(self, parent)
threading.Thread.__init__(self, name="addressGenerator")
self.initStop()
def stopThread(self): def stopThread(self):
try: try:
@ -32,12 +34,6 @@ class addressGenerator(StoppableThread):
super(addressGenerator, self).stopThread() super(addressGenerator, self).stopThread()
def run(self): def run(self):
"""
Process the requests for addresses generation
from `.queues.addressGeneratorQueue`
"""
# pylint: disable=too-many-locals, too-many-branches
# pylint: disable=protected-access, too-many-statements
while state.shutdown == 0: while state.shutdown == 0:
queueValue = queues.addressGeneratorQueue.get() queueValue = queues.addressGeneratorQueue.get()
nonceTrialsPerByte = 0 nonceTrialsPerByte = 0
@ -93,12 +89,12 @@ class addressGenerator(StoppableThread):
elif queueValue[0] == 'stopThread': elif queueValue[0] == 'stopThread':
break break
else: else:
self.logger.error( logger.error(
'Programming error: A structure with the wrong number' 'Programming error: A structure with the wrong number'
' of values was passed into the addressGeneratorQueue.' ' of values was passed into the addressGeneratorQueue.'
' Here is the queueValue: %r\n', queueValue) ' Here is the queueValue: %r\n', queueValue)
if addressVersionNumber < 3 or addressVersionNumber > 4: if addressVersionNumber < 3 or addressVersionNumber > 4:
self.logger.error( logger.error(
'Program error: For some reason the address generator' 'Program error: For some reason the address generator'
' queue has been given a request to create at least' ' queue has been given a request to create at least'
' one version %s address which it cannot do.\n', ' one version %s address which it cannot do.\n',
@ -119,7 +115,9 @@ class addressGenerator(StoppableThread):
defaults.networkDefaultPayloadLengthExtraBytes defaults.networkDefaultPayloadLengthExtraBytes
if command == 'createRandomAddress': if command == 'createRandomAddress':
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateStatusBar', "" 'updateStatusBar',
tr._translate(
"MainWindow", "Generating one new address")
)) ))
# This next section is a little bit strange. We're going # This next section is a little bit strange. We're going
# to generate keys over and over until we find one # to generate keys over and over until we find one
@ -145,10 +143,10 @@ class addressGenerator(StoppableThread):
'\x00' * numberOfNullBytesDemandedOnFrontOfRipeHash '\x00' * numberOfNullBytesDemandedOnFrontOfRipeHash
): ):
break break
self.logger.info( logger.info(
'Generated address with ripe digest: %s', hexlify(ripe)) 'Generated address with ripe digest: %s', hexlify(ripe))
try: try:
self.logger.info( logger.info(
'Address generator calculated %s addresses at %s' 'Address generator calculated %s addresses at %s'
' addresses per second before finding one with' ' addresses per second before finding one with'
' the correct ripe-prefix.', ' the correct ripe-prefix.',
@ -176,6 +174,7 @@ class addressGenerator(StoppableThread):
privEncryptionKey).digest()).digest()[0:4] privEncryptionKey).digest()).digest()[0:4]
privEncryptionKeyWIF = arithmetic.changebase( privEncryptionKeyWIF = arithmetic.changebase(
privEncryptionKey + checksum, 256, 58) privEncryptionKey + checksum, 256, 58)
BMConfigParser().add_section(address) BMConfigParser().add_section(address)
BMConfigParser().set(address, 'label', label) BMConfigParser().set(address, 'label', label)
BMConfigParser().set(address, 'enabled', 'true') BMConfigParser().set(address, 'enabled', 'true')
@ -195,7 +194,11 @@ class addressGenerator(StoppableThread):
queues.apiAddressGeneratorReturnQueue.put(address) queues.apiAddressGeneratorReturnQueue.put(address)
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateStatusBar', "" 'updateStatusBar',
tr._translate(
"MainWindow",
"Done generating address. Doing work necessary"
" to broadcast it...")
)) ))
queues.UISignalQueue.put(('writeNewAddressToTable', ( queues.UISignalQueue.put(('writeNewAddressToTable', (
label, address, streamNumber))) label, address, streamNumber)))
@ -210,8 +213,8 @@ class addressGenerator(StoppableThread):
elif command == 'createDeterministicAddresses' \ elif command == 'createDeterministicAddresses' \
or command == 'getDeterministicAddress' \ or command == 'getDeterministicAddress' \
or command == 'createChan' or command == 'joinChan': or command == 'createChan' or command == 'joinChan':
if not deterministicPassphrase: if len(deterministicPassphrase) == 0:
self.logger.warning( logger.warning(
'You are creating deterministic' 'You are creating deterministic'
' address(es) using a blank passphrase.' ' address(es) using a blank passphrase.'
' Bitmessage will do it but it is rather stupid.') ' Bitmessage will do it but it is rather stupid.')
@ -264,10 +267,10 @@ class addressGenerator(StoppableThread):
): ):
break break
self.logger.info( logger.info(
'Generated address with ripe digest: %s', hexlify(ripe)) 'Generated address with ripe digest: %s', hexlify(ripe))
try: try:
self.logger.info( logger.info(
'Address generator calculated %s addresses' 'Address generator calculated %s addresses'
' at %s addresses per second before finding' ' at %s addresses per second before finding'
' one with the correct ripe-prefix.', ' one with the correct ripe-prefix.',
@ -317,7 +320,7 @@ class addressGenerator(StoppableThread):
addressAlreadyExists = True addressAlreadyExists = True
if addressAlreadyExists: if addressAlreadyExists:
self.logger.info( logger.info(
'%s already exists. Not adding it again.', '%s already exists. Not adding it again.',
address address
) )
@ -330,7 +333,7 @@ class addressGenerator(StoppableThread):
).arg(address) ).arg(address)
)) ))
else: else:
self.logger.debug('label: %s', label) logger.debug('label: %s', label)
BMConfigParser().set(address, 'label', label) BMConfigParser().set(address, 'label', label)
BMConfigParser().set(address, 'enabled', 'true') BMConfigParser().set(address, 'enabled', 'true')
BMConfigParser().set(address, 'decoy', 'false') BMConfigParser().set(address, 'decoy', 'false')

View File

@ -1,42 +1,32 @@
"""
The objectProcessor thread, of which there is only one,
processes the network objects
"""
# pylint: disable=too-many-locals,too-many-return-statements
# pylint: disable=too-many-branches,too-many-statements
import hashlib import hashlib
import logging
import random import random
import shared
import threading import threading
import time import time
from binascii import hexlify from binascii import hexlify
from subprocess import call # nosec from subprocess import call # nosec
import highlevelcrypto
import knownnodes
from addresses import (
calculateInventoryHash, decodeAddress, decodeVarint, encodeAddress,
encodeVarint, varintDecodeError
)
from bmconfigparser import BMConfigParser
import helper_bitcoin import helper_bitcoin
import helper_inbox import helper_inbox
import helper_msgcoding import helper_msgcoding
import helper_sent import helper_sent
import highlevelcrypto from helper_sql import SqlBulkExecute, sqlExecute, sqlQuery
import knownnodes from helper_ackPayload import genAckPayload
import l10n from network import bmproto
import protocol import protocol
import queues import queues
import shared
import state import state
import tr import tr
from addresses import ( from debug import logger
calculateInventoryHash, decodeAddress, decodeVarint,
encodeAddress, encodeVarint, varintDecodeError
)
from bmconfigparser import BMConfigParser
from fallback import RIPEMD160Hash from fallback import RIPEMD160Hash
from helper_ackPayload import genAckPayload import l10n
from helper_sql import SqlBulkExecute, sqlExecute, sqlQuery
from network import bmproto
from network.node import Peer
# pylint: disable=too-many-locals, too-many-return-statements, too-many-branches, too-many-statements
logger = logging.getLogger('default')
class objectProcessor(threading.Thread): class objectProcessor(threading.Thread):
@ -45,13 +35,12 @@ class objectProcessor(threading.Thread):
objects (msg, broadcast, pubkey, getpubkey) from the receiveDataThreads. objects (msg, broadcast, pubkey, getpubkey) from the receiveDataThreads.
""" """
def __init__(self): def __init__(self):
threading.Thread.__init__(self, name="objectProcessor")
random.seed()
# It may be the case that the last time Bitmessage was running, # It may be the case that the last time Bitmessage was running,
# the user closed it before it finished processing everything in the # the user closed it before it finished processing everything in the
# objectProcessorQueue. Assuming that Bitmessage wasn't closed # objectProcessorQueue. Assuming that Bitmessage wasn't closed
# forcefully, it should have saved the data in the queue into the # forcefully, it should have saved the data in the queue into the
# objectprocessorqueue table. Let's pull it out. # objectprocessorqueue table. Let's pull it out.
threading.Thread.__init__(self, name="objectProcessor")
queryreturn = sqlQuery( queryreturn = sqlQuery(
'''SELECT objecttype, data FROM objectprocessorqueue''') '''SELECT objecttype, data FROM objectprocessorqueue''')
for row in queryreturn: for row in queryreturn:
@ -65,7 +54,6 @@ class objectProcessor(threading.Thread):
self.successfullyDecryptMessageTimings = [] self.successfullyDecryptMessageTimings = []
def run(self): def run(self):
"""Process the objects from `.queues.objectProcessorQueue`"""
while True: while True:
objectType, data = queues.objectProcessorQueue.get() objectType, data = queues.objectProcessorQueue.get()
@ -129,10 +117,7 @@ class objectProcessor(threading.Thread):
state.shutdown = 2 state.shutdown = 2
break break
@staticmethod def checkackdata(self, data):
def checkackdata(data):
"""Checking Acknowledgement of message received or not?"""
# pylint: disable=protected-access
# Let's check whether this is a message acknowledgement bound for us. # Let's check whether this is a message acknowledgement bound for us.
if len(data) < 32: if len(data) < 32:
return return
@ -149,13 +134,11 @@ class objectProcessor(threading.Thread):
'ackreceived', int(time.time()), data[readPosition:]) 'ackreceived', int(time.time()), data[readPosition:])
queues.UISignalQueue.put(( queues.UISignalQueue.put((
'updateSentItemStatusByAckdata', 'updateSentItemStatusByAckdata',
( (data[readPosition:],
data[readPosition:],
tr._translate( tr._translate(
"MainWindow", "MainWindow",
"Acknowledgement of the message received %1" "Acknowledgement of the message received %1"
).arg(l10n.formatTimestamp()) ).arg(l10n.formatTimestamp()))
)
)) ))
else: else:
logger.debug('This object is not an acknowledgement bound for me.') logger.debug('This object is not an acknowledgement bound for me.')
@ -174,7 +157,7 @@ class objectProcessor(threading.Thread):
if not host: if not host:
return return
peer = Peer(host, port) peer = state.Peer(host, port)
with knownnodes.knownNodesLock: with knownnodes.knownNodesLock:
knownnodes.addKnownNode( knownnodes.addKnownNode(
stream, peer, is_self=state.ownAddresses.get(peer)) stream, peer, is_self=state.ownAddresses.get(peer))
@ -284,7 +267,6 @@ class objectProcessor(threading.Thread):
queues.workerQueue.put(('sendOutOrStoreMyV4Pubkey', myAddress)) queues.workerQueue.put(('sendOutOrStoreMyV4Pubkey', myAddress))
def processpubkey(self, data): def processpubkey(self, data):
"""Process a pubkey object"""
pubkeyProcessingStartTime = time.time() pubkeyProcessingStartTime = time.time()
shared.numberOfPubkeysProcessed += 1 shared.numberOfPubkeysProcessed += 1
queues.UISignalQueue.put(( queues.UISignalQueue.put((
@ -333,7 +315,6 @@ class objectProcessor(threading.Thread):
'\x04' + publicSigningKey + '\x04' + publicEncryptionKey) '\x04' + publicSigningKey + '\x04' + publicEncryptionKey)
ripe = RIPEMD160Hash(sha.digest()).digest() ripe = RIPEMD160Hash(sha.digest()).digest()
if logger.isEnabledFor(logging.DEBUG):
logger.debug( logger.debug(
'within recpubkey, addressVersion: %s, streamNumber: %s' 'within recpubkey, addressVersion: %s, streamNumber: %s'
'\nripe %s\npublicSigningKey in hex: %s' '\nripe %s\npublicSigningKey in hex: %s'
@ -398,7 +379,6 @@ class objectProcessor(threading.Thread):
sha.update(publicSigningKey + publicEncryptionKey) sha.update(publicSigningKey + publicEncryptionKey)
ripe = RIPEMD160Hash(sha.digest()).digest() ripe = RIPEMD160Hash(sha.digest()).digest()
if logger.isEnabledFor(logging.DEBUG):
logger.debug( logger.debug(
'within recpubkey, addressVersion: %s, streamNumber: %s' 'within recpubkey, addressVersion: %s, streamNumber: %s'
'\nripe %s\npublicSigningKey in hex: %s' '\nripe %s\npublicSigningKey in hex: %s'
@ -457,7 +437,6 @@ class objectProcessor(threading.Thread):
timeRequiredToProcessPubkey) timeRequiredToProcessPubkey)
def processmsg(self, data): def processmsg(self, data):
"""Process a message object"""
messageProcessingStartTime = time.time() messageProcessingStartTime = time.time()
shared.numberOfMessagesProcessed += 1 shared.numberOfMessagesProcessed += 1
queues.UISignalQueue.put(( queues.UISignalQueue.put((
@ -599,7 +578,6 @@ class objectProcessor(threading.Thread):
logger.debug('ECDSA verify failed') logger.debug('ECDSA verify failed')
return return
logger.debug('ECDSA verify passed') logger.debug('ECDSA verify passed')
if logger.isEnabledFor(logging.DEBUG):
logger.debug( logger.debug(
'As a matter of intellectual curiosity, here is the Bitcoin' 'As a matter of intellectual curiosity, here is the Bitcoin'
' address associated with the keys owned by the other person:' ' address associated with the keys owned by the other person:'
@ -647,8 +625,7 @@ class objectProcessor(threading.Thread):
if decodeAddress(toAddress)[1] >= 3 \ if decodeAddress(toAddress)[1] >= 3 \
and not BMConfigParser().safeGetBoolean(toAddress, 'chan'): and not BMConfigParser().safeGetBoolean(toAddress, 'chan'):
# If I'm not friendly with this person: # If I'm not friendly with this person:
if not shared.isAddressInMyAddressBookSubscriptionsListOrWhitelist( if not shared.isAddressInMyAddressBookSubscriptionsListOrWhitelist(fromAddress):
fromAddress):
requiredNonceTrialsPerByte = BMConfigParser().getint( requiredNonceTrialsPerByte = BMConfigParser().getint(
toAddress, 'noncetrialsperbyte') toAddress, 'noncetrialsperbyte')
requiredPayloadLengthExtraBytes = BMConfigParser().getint( requiredPayloadLengthExtraBytes = BMConfigParser().getint(
@ -806,7 +783,6 @@ class objectProcessor(threading.Thread):
) )
def processbroadcast(self, data): def processbroadcast(self, data):
"""Process a broadcast object"""
messageProcessingStartTime = time.time() messageProcessingStartTime = time.time()
shared.numberOfBroadcastsProcessed += 1 shared.numberOfBroadcastsProcessed += 1
queues.UISignalQueue.put(( queues.UISignalQueue.put((
@ -991,7 +967,7 @@ class objectProcessor(threading.Thread):
fromAddress = encodeAddress( fromAddress = encodeAddress(
sendersAddressVersion, sendersStream, calculatedRipe) sendersAddressVersion, sendersStream, calculatedRipe)
logger.info('fromAddress: %s', fromAddress) logger.info('fromAddress: %s' % fromAddress)
# Let's store the public key in case we want to reply to this person. # Let's store the public key in case we want to reply to this person.
sqlExecute('''INSERT INTO pubkeys VALUES (?,?,?,?,?)''', sqlExecute('''INSERT INTO pubkeys VALUES (?,?,?,?,?)''',
@ -1008,7 +984,7 @@ class objectProcessor(threading.Thread):
fromAddress = encodeAddress( fromAddress = encodeAddress(
sendersAddressVersion, sendersStream, calculatedRipe) sendersAddressVersion, sendersStream, calculatedRipe)
logger.debug('fromAddress: %s', fromAddress) logger.debug('fromAddress: ' + fromAddress)
try: try:
decodedMessage = helper_msgcoding.MsgDecode( decodedMessage = helper_msgcoding.MsgDecode(
@ -1069,18 +1045,17 @@ class objectProcessor(threading.Thread):
# for it. # for it.
elif addressVersion >= 4: elif addressVersion >= 4:
tag = hashlib.sha512(hashlib.sha512( tag = hashlib.sha512(hashlib.sha512(
encodeVarint(addressVersion) + encodeVarint(streamNumber) encodeVarint(addressVersion) + encodeVarint(streamNumber) + ripe
+ ripe
).digest()).digest()[32:] ).digest()).digest()[32:]
if tag in state.neededPubkeys: if tag in state.neededPubkeys:
del state.neededPubkeys[tag] del state.neededPubkeys[tag]
self.sendMessages(address) self.sendMessages(address)
@staticmethod def sendMessages(self, address):
def sendMessages(address):
""" """
This method is called by the `possibleNewPubkey` when it sees This function is called by the possibleNewPubkey function when
that we now have the necessary pubkey to send one or more messages. that function sees that we now have the necessary pubkey
to send one or more messages.
""" """
logger.info('We have been awaiting the arrival of this pubkey.') logger.info('We have been awaiting the arrival of this pubkey.')
sqlExecute( sqlExecute(
@ -1090,9 +1065,7 @@ class objectProcessor(threading.Thread):
" AND folder='sent'", address) " AND folder='sent'", address)
queues.workerQueue.put(('sendmessage', '')) queues.workerQueue.put(('sendmessage', ''))
@staticmethod def ackDataHasAValidHeader(self, ackData):
def ackDataHasAValidHeader(ackData):
"""Checking ackData with valid Header, not sending ackData when false"""
if len(ackData) < protocol.Header.size: if len(ackData) < protocol.Header.size:
logger.info( logger.info(
'The length of ackData is unreasonably short. Not sending' 'The length of ackData is unreasonably short. Not sending'
@ -1127,12 +1100,11 @@ class objectProcessor(threading.Thread):
return False return False
return True return True
@staticmethod def addMailingListNameToSubject(self, subject, mailingListName):
def addMailingListNameToSubject(subject, mailingListName):
"""Adding mailingListName to subject"""
subject = subject.strip() subject = subject.strip()
if subject[:3] == 'Re:' or subject[:3] == 'RE:': if subject[:3] == 'Re:' or subject[:3] == 'RE:':
subject = subject[3:].strip() subject = subject[3:].strip()
if '[' + mailingListName + ']' in subject: if '[' + mailingListName + ']' in subject:
return subject return subject
else:
return '[' + mailingListName + '] ' + subject return '[' + mailingListName + '] ' + subject

View File

@ -0,0 +1,24 @@
import Queue
import threading
import time
class ObjectProcessorQueue(Queue.Queue):
maxSize = 32000000
def __init__(self):
Queue.Queue.__init__(self)
self.sizeLock = threading.Lock()
self.curSize = 0 # in Bytes. We maintain this to prevent nodes from flooing us with objects which take up too much memory. If this gets too big we'll sleep before asking for further objects.
def put(self, item, block = True, timeout = None):
while self.curSize >= self.maxSize:
time.sleep(1)
with self.sizeLock:
self.curSize += len(item[1])
Queue.Queue.put(self, item, block, timeout)
def get(self, block = True, timeout = None):
item = Queue.Queue.get(self, block, timeout)
with self.sizeLock:
self.curSize -= len(item[1])
return item

View File

@ -1,58 +1,61 @@
""" """
The `singleCleaner` class is a timer-driven thread that cleans data structures The singleCleaner class is a timer-driven thread that cleans data structures
to free memory, resends messages when a remote node doesn't respond, and to free memory, resends messages when a remote node doesn't respond, and
sends pong messages to keep connections alive if the network isn't busy. sends pong messages to keep connections alive if the network isn't busy.
It cleans these data structures in memory: It cleans these data structures in memory:
- inventory (moves data to the on-disk sql database) inventory (moves data to the on-disk sql database)
- inventorySets (clears then reloads data out of sql database) inventorySets (clears then reloads data out of sql database)
It cleans these tables on the disk: It cleans these tables on the disk:
- inventory (clears expired objects) inventory (clears expired objects)
- pubkeys (clears pubkeys older than 4 weeks old which we have not used pubkeys (clears pubkeys older than 4 weeks old which we have not used
personally) personally)
- knownNodes (clears addresses which have not been online for over 3 days) knownNodes (clears addresses which have not been online for over 3 days)
It resends messages when there has been no response: It resends messages when there has been no response:
- resends getpubkey messages in 5 days (then 10 days, then 20 days, etc...) resends getpubkey messages in 5 days (then 10 days, then 20 days, etc...)
- resends msg messages in 5 days (then 10 days, then 20 days, etc...) resends msg messages in 5 days (then 10 days, then 20 days, etc...)
""" """
# pylint: disable=relative-import, protected-access
import gc import gc
import os import os
from datetime import datetime, timedelta
import time
import shared import shared
import threading
import time
import tr
from bmconfigparser import BMConfigParser
from helper_sql import sqlQuery, sqlExecute
from helper_threading import StoppableThread
from inventory import Inventory
from network.connectionpool import BMConnectionPool
from debug import logger
import knownnodes import knownnodes
import queues import queues
import state import state
import tr
from bmconfigparser import BMConfigParser
from helper_sql import sqlExecute, sqlQuery
from inventory import Inventory
from network import BMConnectionPool, StoppableThread
class singleCleaner(StoppableThread): class singleCleaner(threading.Thread, StoppableThread):
"""The singleCleaner thread class"""
name = "singleCleaner"
cycleLength = 300 cycleLength = 300
expireDiscoveredPeers = 300 expireDiscoveredPeers = 300
def run(self): # pylint: disable=too-many-branches def __init__(self):
threading.Thread.__init__(self, name="singleCleaner")
self.initStop()
def run(self):
gc.disable() gc.disable()
timeWeLastClearedInventoryAndPubkeysTables = 0 timeWeLastClearedInventoryAndPubkeysTables = 0
try: try:
shared.maximumLengthOfTimeToBotherResendingMessages = ( shared.maximumLengthOfTimeToBotherResendingMessages = (
float(BMConfigParser().get( float(BMConfigParser().get(
'bitmessagesettings', 'stopresendingafterxdays')) 'bitmessagesettings', 'stopresendingafterxdays')) *
* 24 * 60 * 60 24 * 60 * 60
) + ( ) + (
float(BMConfigParser().get( float(BMConfigParser().get(
'bitmessagesettings', 'stopresendingafterxmonths')) 'bitmessagesettings', 'stopresendingafterxmonths')) *
* (60 * 60 * 24 * 365) / 12) (60 * 60 * 24 * 365) / 12)
except: except:
# 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
@ -74,7 +77,7 @@ 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 shared.thisapp.daemon or not state.enableGUI:
queues.UISignalQueue.queue.clear() queues.UISignalQueue.queue.clear()
if timeWeLastClearedInventoryAndPubkeysTables < \ if timeWeLastClearedInventoryAndPubkeysTables < \
@ -94,12 +97,12 @@ class singleCleaner(StoppableThread):
"SELECT toaddress, ackdata, status FROM sent" "SELECT toaddress, ackdata, status FROM sent"
" 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 shared.maximumLengthOfTimeToBotherResendingMessages
) )
for row in queryreturn: for row in queryreturn:
if len(row) < 2: if len(row) < 2:
self.logger.error( logger.error(
'Something went wrong in the singleCleaner thread:' 'Something went wrong in the singleCleaner thread:'
' a query did not return the requested fields. %r', ' a query did not return the requested fields. %r',
row row
@ -108,18 +111,17 @@ class singleCleaner(StoppableThread):
break break
toAddress, ackData, status = row toAddress, ackData, status = row
if status == 'awaitingpubkey': if status == 'awaitingpubkey':
self.resendPubkeyRequest(toAddress) resendPubkeyRequest(toAddress)
elif status == 'msgsent': elif status == 'msgsent':
self.resendMsg(ackData) resendMsg(ackData)
deleteTrashMsgPermonantly()
try: try:
# Cleanup knownnodes and handle possible severe exception # Cleanup knownnodes and handle possible severe exception
# while writing it to disk # while writing it to disk
knownnodes.cleanupKnownNodes() knownnodes.cleanupKnownNodes()
except Exception as err: except Exception as err:
# pylint: disable=protected-access
if "Errno 28" in str(err): if "Errno 28" in str(err):
self.logger.fatal( logger.fatal(
'(while writing knownnodes to disk)' '(while writing knownnodes to disk)'
' Alert: Your disk or data storage volume is full.' ' Alert: Your disk or data storage volume is full.'
) )
@ -132,11 +134,19 @@ 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 shared.daemon or not state.enableGUI:
os._exit(1) os._exit(1)
# # clear download queues
# for thread in threading.enumerate():
# if thread.isAlive() and hasattr(thread, 'downloadQueue'):
# thread.downloadQueue.clear()
# inv/object tracking # inv/object tracking
for connection in BMConnectionPool().connections(): for connection in \
BMConnectionPool().inboundConnections.values() + \
BMConnectionPool().outboundConnections.values():
connection.clean() connection.clean()
# discovery tracking # discovery tracking
@ -147,17 +157,16 @@ class singleCleaner(StoppableThread):
del state.discoveredPeers[k] del state.discoveredPeers[k]
except KeyError: except KeyError:
pass pass
# TODO: cleanup pending upload / download
# ..todo:: cleanup pending upload / download
gc.collect() gc.collect()
if state.shutdown == 0: if state.shutdown == 0:
self.stop.wait(singleCleaner.cycleLength) self.stop.wait(singleCleaner.cycleLength)
def resendPubkeyRequest(self, address):
"""Resend pubkey request for address""" def resendPubkeyRequest(address):
self.logger.debug( logger.debug(
'It has been a long time and we haven\'t heard a response to our' 'It has been a long time and we haven\'t heard a response to our'
' getpubkey request. Sending again.' ' getpubkey request. Sending again.'
) )
@ -179,9 +188,9 @@ class singleCleaner(StoppableThread):
address) address)
queues.workerQueue.put(('sendmessage', '')) queues.workerQueue.put(('sendmessage', ''))
def resendMsg(self, ackdata):
"""Resend message by ackdata""" def resendMsg(ackdata):
self.logger.debug( logger.debug(
'It has been a long time and we haven\'t heard an acknowledgement' 'It has been a long time and we haven\'t heard an acknowledgement'
' to our msg. Sending again.' ' to our msg. Sending again.'
) )
@ -193,12 +202,3 @@ class singleCleaner(StoppableThread):
'updateStatusBar', 'updateStatusBar',
'Doing work necessary to again attempt to deliver a message...' 'Doing work necessary to again attempt to deliver a message...'
)) ))
def deleteTrashMsgPermonantly():
"""This method is used to delete old messages"""
ndays_before_time = datetime.now() - timedelta(days=30)
old_messages = time.mktime(ndays_before_time.timetuple())
sqlExecute("delete from sent where folder = 'trash' and lastactiontime <= ?;", int(old_messages))
sqlExecute("delete from inbox where folder = 'trash' and received <= ?;", int(old_messages))
return

View File

@ -1,13 +1,13 @@
""" """
Thread for performing PoW src/class_singleWorker.py
=========================
""" """
# pylint: disable=protected-access,too-many-branches,too-many-statements # pylint: disable=protected-access,too-many-branches,too-many-statements,no-self-use,too-many-lines,too-many-locals
# pylint: disable=no-self-use,too-many-lines,too-many-locals,relative-import
from __future__ import division from __future__ import division
import hashlib import hashlib
import threading
import time import time
from binascii import hexlify, unhexlify from binascii import hexlify, unhexlify
from struct import pack from struct import pack
@ -25,16 +25,12 @@ import queues
import shared import shared
import state import state
import tr import tr
from addresses import ( from addresses import calculateInventoryHash, decodeAddress, decodeVarint, encodeVarint
calculateInventoryHash, decodeAddress, decodeVarint, encodeVarint
)
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from debug import logger
from helper_sql import sqlExecute, sqlQuery from helper_sql import sqlExecute, sqlQuery
from helper_threading import StoppableThread
from inventory import Inventory from inventory import Inventory
from network import StoppableThread
# This thread, of which there is only one, does the heavy lifting:
# calculating POWs.
def sizeof_fmt(num, suffix='h/s'): def sizeof_fmt(num, suffix='h/s'):
@ -47,11 +43,12 @@ def sizeof_fmt(num, suffix='h/s'):
return "%.1f%s%s" % (num, 'Yi', suffix) return "%.1f%s%s" % (num, 'Yi', suffix)
class singleWorker(StoppableThread): class singleWorker(threading.Thread, StoppableThread):
"""Thread for performing PoW""" """Thread for performing PoW"""
def __init__(self): def __init__(self):
super(singleWorker, self).__init__(name="singleWorker") threading.Thread.__init__(self, name="singleWorker")
self.initStop()
proofofwork.init() proofofwork.init()
def stopThread(self): def stopThread(self):
@ -74,7 +71,7 @@ class singleWorker(StoppableThread):
# Initialize the neededPubkeys dictionary. # Initialize the neededPubkeys dictionary.
queryreturn = sqlQuery( queryreturn = sqlQuery(
'''SELECT DISTINCT toaddress FROM sent''' '''SELECT DISTINCT toaddress FROM sent'''
''' WHERE (status='awaitingpubkey' AND folder LIKE '%sent%')''') ''' WHERE (status='awaitingpubkey' AND folder='sent')''')
for row in queryreturn: for row in queryreturn:
toAddress, = row toAddress, = row
# toStatus # toStatus
@ -103,7 +100,7 @@ class singleWorker(StoppableThread):
'''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)) logger.info('Watching for ackdata %s', hexlify(ackdata))
shared.ackdataForWhichImWatching[ackdata] = 0 shared.ackdataForWhichImWatching[ackdata] = 0
# Fix legacy (headerless) watched ackdata to include header # Fix legacy (headerless) watched ackdata to include header
@ -178,14 +175,14 @@ class singleWorker(StoppableThread):
self.busy = 0 self.busy = 0
return return
else: else:
self.logger.error( logger.error(
'Probable programming error: The command sent' 'Probable programming error: The command sent'
' to the workerThread is weird. It is: %s\n', ' to the workerThread is weird. It is: %s\n',
command command
) )
queues.workerQueue.task_done() queues.workerQueue.task_done()
self.logger.info("Quitting...") logger.info("Quitting...")
def _getKeysForAddress(self, address): def _getKeysForAddress(self, address):
privSigningKeyBase58 = BMConfigParser().get( privSigningKeyBase58 = BMConfigParser().get(
@ -222,34 +219,33 @@ class singleWorker(StoppableThread):
)) / (2 ** 16)) )) / (2 ** 16))
)) ))
initialHash = hashlib.sha512(payload).digest() initialHash = hashlib.sha512(payload).digest()
self.logger.info( logger.info(
'%s Doing proof of work... TTL set to %s', log_prefix, TTL) '%s Doing proof of work... TTL set to %s', log_prefix, TTL)
if log_time: if log_time:
start_time = time.time() start_time = time.time()
trialValue, nonce = proofofwork.run(target, initialHash) trialValue, nonce = proofofwork.run(target, initialHash)
self.logger.info( logger.info(
'%s Found proof of work %s Nonce: %s', '%s Found proof of work %s Nonce: %s',
log_prefix, trialValue, nonce log_prefix, trialValue, nonce
) )
try: try:
delta = time.time() - start_time delta = time.time() - start_time
self.logger.info( logger.info(
'PoW took %.1f seconds, speed %s.', 'PoW took %.1f seconds, speed %s.',
delta, sizeof_fmt(nonce / delta) delta, sizeof_fmt(nonce / delta)
) )
except: # NameError except: # NameError
pass pass
payload = pack('>Q', nonce) + payload payload = pack('>Q', nonce) + payload
# inventoryHash = calculateInventoryHash(payload)
return payload return payload
def doPOWForMyV2Pubkey(self, adressHash): def doPOWForMyV2Pubkey(self, adressHash):
""" This function also broadcasts out the pubkey """ This function also broadcasts out the pubkey message once it is done with the POW"""
message once it is done with the POW"""
# Look up my stream number based on my address hash # Look up my stream number based on my address hash
myAddress = shared.myAddressesByHash[adressHash] myAddress = shared.myAddressesByHash[adressHash]
# status # status
_, addressVersionNumber, streamNumber, adressHash = ( _, addressVersionNumber, streamNumber, adressHash = decodeAddress(myAddress)
decodeAddress(myAddress))
# 28 days from now plus or minus five minutes # 28 days from now plus or minus five minutes
TTL = int(28 * 24 * 60 * 60 + helper_random.randomrandrange(-300, 300)) TTL = int(28 * 24 * 60 * 60 + helper_random.randomrandrange(-300, 300))
@ -266,7 +262,7 @@ class singleWorker(StoppableThread):
_, _, pubSigningKey, pubEncryptionKey = \ _, _, pubSigningKey, pubEncryptionKey = \
self._getKeysForAddress(myAddress) self._getKeysForAddress(myAddress)
except Exception as err: except Exception as err:
self.logger.error( logger.error(
'Error within doPOWForMyV2Pubkey. Could not read' 'Error within doPOWForMyV2Pubkey. Could not read'
' the keys from the keys.dat file for a requested' ' the keys from the keys.dat file for a requested'
' address. %s\n', err ' address. %s\n', err
@ -284,8 +280,7 @@ class singleWorker(StoppableThread):
Inventory()[inventoryHash] = ( Inventory()[inventoryHash] = (
objectType, streamNumber, payload, embeddedTime, '') objectType, streamNumber, payload, embeddedTime, '')
self.logger.info( logger.info('broadcasting inv with hash: %s', hexlify(inventoryHash))
'broadcasting inv with hash: %s', hexlify(inventoryHash))
queues.invQueue.put((streamNumber, inventoryHash)) queues.invQueue.put((streamNumber, inventoryHash))
queues.UISignalQueue.put(('updateStatusBar', '')) queues.UISignalQueue.put(('updateStatusBar', ''))
@ -310,7 +305,7 @@ class singleWorker(StoppableThread):
# The address has been deleted. # The address has been deleted.
return return
if BMConfigParser().safeGetBoolean(myAddress, 'chan'): if BMConfigParser().safeGetBoolean(myAddress, 'chan'):
self.logger.info('This is a chan address. Not sending pubkey.') logger.info('This is a chan address. Not sending pubkey.')
return return
_, addressVersionNumber, streamNumber, adressHash = decodeAddress( _, addressVersionNumber, streamNumber, adressHash = decodeAddress(
myAddress) myAddress)
@ -340,7 +335,7 @@ class singleWorker(StoppableThread):
privSigningKeyHex, _, pubSigningKey, pubEncryptionKey = \ privSigningKeyHex, _, pubSigningKey, pubEncryptionKey = \
self._getKeysForAddress(myAddress) self._getKeysForAddress(myAddress)
except Exception as err: except Exception as err:
self.logger.error( logger.error(
'Error within sendOutOrStoreMyV3Pubkey. Could not read' 'Error within sendOutOrStoreMyV3Pubkey. Could not read'
' the keys from the keys.dat file for a requested' ' the keys from the keys.dat file for a requested'
' address. %s\n', err ' address. %s\n', err
@ -367,8 +362,7 @@ class singleWorker(StoppableThread):
Inventory()[inventoryHash] = ( Inventory()[inventoryHash] = (
objectType, streamNumber, payload, embeddedTime, '') objectType, streamNumber, payload, embeddedTime, '')
self.logger.info( logger.info('broadcasting inv with hash: %s', hexlify(inventoryHash))
'broadcasting inv with hash: %s', hexlify(inventoryHash))
queues.invQueue.put((streamNumber, inventoryHash)) queues.invQueue.put((streamNumber, inventoryHash))
queues.UISignalQueue.put(('updateStatusBar', '')) queues.UISignalQueue.put(('updateStatusBar', ''))
@ -391,7 +385,7 @@ class singleWorker(StoppableThread):
# The address has been deleted. # The address has been deleted.
return return
if shared.BMConfigParser().safeGetBoolean(myAddress, 'chan'): if shared.BMConfigParser().safeGetBoolean(myAddress, 'chan'):
self.logger.info('This is a chan address. Not sending pubkey.') logger.info('This is a chan address. Not sending pubkey.')
return return
_, addressVersionNumber, streamNumber, addressHash = decodeAddress( _, addressVersionNumber, streamNumber, addressHash = decodeAddress(
myAddress) myAddress)
@ -410,7 +404,7 @@ class singleWorker(StoppableThread):
privSigningKeyHex, _, pubSigningKey, pubEncryptionKey = \ privSigningKeyHex, _, pubSigningKey, pubEncryptionKey = \
self._getKeysForAddress(myAddress) self._getKeysForAddress(myAddress)
except Exception as err: except Exception as err:
self.logger.error( logger.error(
'Error within sendOutOrStoreMyV4Pubkey. Could not read' 'Error within sendOutOrStoreMyV4Pubkey. Could not read'
' the keys from the keys.dat file for a requested' ' the keys from the keys.dat file for a requested'
' address. %s\n', err ' address. %s\n', err
@ -458,8 +452,7 @@ class singleWorker(StoppableThread):
doubleHashOfAddressData[32:] doubleHashOfAddressData[32:]
) )
self.logger.info( logger.info('broadcasting inv with hash: %s', hexlify(inventoryHash))
'broadcasting inv with hash: %s', hexlify(inventoryHash))
queues.invQueue.put((streamNumber, inventoryHash)) queues.invQueue.put((streamNumber, inventoryHash))
queues.UISignalQueue.put(('updateStatusBar', '')) queues.UISignalQueue.put(('updateStatusBar', ''))
@ -468,7 +461,7 @@ class singleWorker(StoppableThread):
myAddress, 'lastpubkeysendtime', str(int(time.time()))) myAddress, 'lastpubkeysendtime', str(int(time.time())))
BMConfigParser().save() BMConfigParser().save()
except Exception as err: except Exception as err:
self.logger.error( logger.error(
'Error: Couldn\'t add the lastpubkeysendtime' 'Error: Couldn\'t add the lastpubkeysendtime'
' to the keys.dat file. Error message: %s', err ' to the keys.dat file. Error message: %s', err
) )
@ -485,7 +478,7 @@ class singleWorker(StoppableThread):
embeddedTime = int(time.time() + TTL) embeddedTime = int(time.time() + TTL)
streamNumber = 1 # Don't know yet what should be here streamNumber = 1 # Don't know yet what should be here
objectType = protocol.OBJECT_ONIONPEER objectType = protocol.OBJECT_ONIONPEER
# ..FIXME: ideally the objectPayload should be signed # FIXME: ideally the objectPayload should be signed
objectPayload = encodeVarint(peer.port) + protocol.encodeHost(peer.host) objectPayload = encodeVarint(peer.port) + protocol.encodeHost(peer.host)
tag = calculateInventoryHash(objectPayload) tag = calculateInventoryHash(objectPayload)
@ -506,7 +499,7 @@ class singleWorker(StoppableThread):
objectType, streamNumber, buffer(payload), objectType, streamNumber, buffer(payload),
embeddedTime, buffer(tag) embeddedTime, buffer(tag)
) )
self.logger.info( logger.info(
'sending inv (within sendOnionPeerObj function) for object: %s', 'sending inv (within sendOnionPeerObj function) for object: %s',
hexlify(inventoryHash)) hexlify(inventoryHash))
queues.invQueue.put((streamNumber, inventoryHash)) queues.invQueue.put((streamNumber, inventoryHash))
@ -521,7 +514,7 @@ class singleWorker(StoppableThread):
queryreturn = sqlQuery( queryreturn = sqlQuery(
'''SELECT fromaddress, subject, message, ''' '''SELECT fromaddress, subject, message, '''
''' ackdata, ttl, encodingtype FROM sent ''' ''' ackdata, ttl, encodingtype FROM sent '''
''' WHERE status=? and folder LIKE '%sent%' ''', 'broadcastqueued') ''' WHERE status=? and folder='sent' ''', 'broadcastqueued')
for row in queryreturn: for row in queryreturn:
fromaddress, subject, body, ackdata, TTL, encoding = row fromaddress, subject, body, ackdata, TTL, encoding = row
@ -529,7 +522,7 @@ class singleWorker(StoppableThread):
_, addressVersionNumber, streamNumber, ripe = \ _, addressVersionNumber, streamNumber, ripe = \
decodeAddress(fromaddress) decodeAddress(fromaddress)
if addressVersionNumber <= 1: if addressVersionNumber <= 1:
self.logger.error( logger.error(
'Error: In the singleWorker thread, the ' 'Error: In the singleWorker thread, the '
' sendBroadcast function doesn\'t understand' ' sendBroadcast function doesn\'t understand'
' the address version.\n') ' the address version.\n')
@ -645,7 +638,7 @@ class singleWorker(StoppableThread):
# to not let the user try to send a message this large # to not let the user try to send a message this large
# until we implement message continuation. # until we implement message continuation.
if len(payload) > 2 ** 18: # 256 KiB if len(payload) > 2 ** 18: # 256 KiB
self.logger.critical( logger.critical(
'This broadcast object is too large to send.' 'This broadcast object is too large to send.'
' This should never happen. Object size: %s', ' This should never happen. Object size: %s',
len(payload) len(payload)
@ -656,7 +649,7 @@ class singleWorker(StoppableThread):
objectType = 3 objectType = 3
Inventory()[inventoryHash] = ( Inventory()[inventoryHash] = (
objectType, streamNumber, payload, embeddedTime, tag) objectType, streamNumber, payload, embeddedTime, tag)
self.logger.info( logger.info(
'sending inv (within sendBroadcast function)' 'sending inv (within sendBroadcast function)'
' for object: %s', ' for object: %s',
hexlify(inventoryHash) hexlify(inventoryHash)
@ -691,7 +684,7 @@ class singleWorker(StoppableThread):
'''SELECT toaddress, fromaddress, subject, message, ''' '''SELECT toaddress, fromaddress, subject, message, '''
''' ackdata, status, ttl, retrynumber, encodingtype FROM ''' ''' ackdata, status, ttl, retrynumber, encodingtype FROM '''
''' sent WHERE (status='msgqueued' or status='forcepow') ''' ''' sent WHERE (status='msgqueued' or status='forcepow') '''
''' and folder LIKE '%sent%' ''') ''' and folder='sent' ''')
# while we have a msg that needs some work # while we have a msg that needs some work
for row in queryreturn: for row in queryreturn:
toaddress, fromaddress, subject, message, \ toaddress, fromaddress, subject, message, \
@ -876,8 +869,8 @@ class singleWorker(StoppableThread):
"MainWindow", "MainWindow",
"Looking up the receiver\'s public key")) "Looking up the receiver\'s public key"))
)) ))
self.logger.info('Sending a message.') logger.info('Sending a message.')
self.logger.debug( logger.debug(
'First 150 characters of message: %s', 'First 150 characters of message: %s',
repr(message[:150]) repr(message[:150])
) )
@ -921,7 +914,7 @@ class singleWorker(StoppableThread):
if not shared.BMConfigParser().safeGetBoolean( if not shared.BMConfigParser().safeGetBoolean(
'bitmessagesettings', 'willinglysendtomobile' 'bitmessagesettings', 'willinglysendtomobile'
): ):
self.logger.info( logger.info(
'The receiver is a mobile user but the' 'The receiver is a mobile user but the'
' sender (you) has not selected that you' ' sender (you) has not selected that you'
' are willing to send to mobiles. Aborting' ' are willing to send to mobiles. Aborting'
@ -987,7 +980,7 @@ class singleWorker(StoppableThread):
defaults.networkDefaultPayloadLengthExtraBytes: defaults.networkDefaultPayloadLengthExtraBytes:
requiredPayloadLengthExtraBytes = \ requiredPayloadLengthExtraBytes = \
defaults.networkDefaultPayloadLengthExtraBytes defaults.networkDefaultPayloadLengthExtraBytes
self.logger.debug( logger.debug(
'Using averageProofOfWorkNonceTrialsPerByte: %s' 'Using averageProofOfWorkNonceTrialsPerByte: %s'
' and payloadLengthExtraBytes: %s.', ' and payloadLengthExtraBytes: %s.',
requiredAverageProofOfWorkNonceTrialsPerByte, requiredAverageProofOfWorkNonceTrialsPerByte,
@ -1052,9 +1045,8 @@ class singleWorker(StoppableThread):
l10n.formatTimestamp())))) l10n.formatTimestamp()))))
continue continue
else: # if we are sending a message to ourselves or a chan.. else: # if we are sending a message to ourselves or a chan..
self.logger.info('Sending a message.') logger.info('Sending a message.')
self.logger.debug( logger.debug('First 150 characters of message: %r', message[:150])
'First 150 characters of message: %r', message[:150])
behaviorBitfield = protocol.getBitfield(fromaddress) behaviorBitfield = protocol.getBitfield(fromaddress)
try: try:
@ -1073,7 +1065,7 @@ class singleWorker(StoppableThread):
" message. %1" " message. %1"
).arg(l10n.formatTimestamp())) ).arg(l10n.formatTimestamp()))
)) ))
self.logger.error( logger.error(
'Error within sendMsg. Could not read the keys' 'Error within sendMsg. Could not read the keys'
' from the keys.dat file for our own address. %s\n', ' from the keys.dat file for our own address. %s\n',
err) err)
@ -1149,14 +1141,14 @@ class singleWorker(StoppableThread):
payload += encodeVarint(encodedMessage.length) payload += encodeVarint(encodedMessage.length)
payload += encodedMessage.data payload += encodedMessage.data
if BMConfigParser().has_section(toaddress): if BMConfigParser().has_section(toaddress):
self.logger.info( logger.info(
'Not bothering to include ackdata because we are' 'Not bothering to include ackdata because we are'
' sending to ourselves or a chan.' ' sending to ourselves or a chan.'
) )
fullAckPayload = '' fullAckPayload = ''
elif not protocol.checkBitfield( elif not protocol.checkBitfield(
behaviorBitfield, protocol.BITFIELD_DOESACK): behaviorBitfield, protocol.BITFIELD_DOESACK):
self.logger.info( logger.info(
'Not bothering to include ackdata because' 'Not bothering to include ackdata because'
' the receiver said that they won\'t relay it anyway.' ' the receiver said that they won\'t relay it anyway.'
) )
@ -1209,7 +1201,7 @@ class singleWorker(StoppableThread):
requiredPayloadLengthExtraBytes requiredPayloadLengthExtraBytes
)) / (2 ** 16)) )) / (2 ** 16))
)) ))
self.logger.info( logger.info(
'(For msg message) Doing proof of work. Total required' '(For msg message) Doing proof of work. Total required'
' difficulty: %f. Required small message difficulty: %f.', ' difficulty: %f. Required small message difficulty: %f.',
float(requiredAverageProofOfWorkNonceTrialsPerByte) / float(requiredAverageProofOfWorkNonceTrialsPerByte) /
@ -1221,13 +1213,12 @@ class singleWorker(StoppableThread):
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)
print("nonce calculated value#############################", nonce) logger.info(
self.logger.info(
'(For msg message) Found proof of work %s Nonce: %s', '(For msg message) Found proof of work %s Nonce: %s',
trialValue, nonce trialValue, nonce
) )
try: try:
self.logger.info( logger.info(
'PoW took %.1f seconds, speed %s.', 'PoW took %.1f seconds, speed %s.',
time.time() - powStartTime, time.time() - powStartTime,
sizeof_fmt(nonce / (time.time() - powStartTime)) sizeof_fmt(nonce / (time.time() - powStartTime))
@ -1242,7 +1233,7 @@ class singleWorker(StoppableThread):
# in the code to not let the user try to send a message # in the code to not let the user try to send a message
# this large until we implement message continuation. # this large until we implement message continuation.
if len(encryptedPayload) > 2 ** 18: # 256 KiB if len(encryptedPayload) > 2 ** 18: # 256 KiB
self.logger.critical( logger.critical(
'This msg object is too large to send. This should' 'This msg object is too large to send. This should'
' never happen. Object size: %i', ' never happen. Object size: %i',
len(encryptedPayload) len(encryptedPayload)
@ -1273,7 +1264,7 @@ class singleWorker(StoppableThread):
" Sent on %1" " Sent on %1"
).arg(l10n.formatTimestamp())) ).arg(l10n.formatTimestamp()))
)) ))
self.logger.info( logger.info(
'Broadcasting inv for my msg(within sendmsg function): %s', 'Broadcasting inv for my msg(within sendmsg function): %s',
hexlify(inventoryHash) hexlify(inventoryHash)
) )
@ -1326,7 +1317,7 @@ class singleWorker(StoppableThread):
toStatus, addressVersionNumber, streamNumber, ripe = decodeAddress( toStatus, addressVersionNumber, streamNumber, ripe = decodeAddress(
toAddress) toAddress)
if toStatus != 'success': if toStatus != 'success':
self.logger.error( logger.error(
'Very abnormal error occurred in requestPubKey.' 'Very abnormal error occurred in requestPubKey.'
' toAddress is: %r. Please report this error to Atheros.', ' toAddress is: %r. Please report this error to Atheros.',
toAddress toAddress
@ -1340,7 +1331,7 @@ class singleWorker(StoppableThread):
toAddress toAddress
) )
if not queryReturn: if not queryReturn:
self.logger.critical( logger.critical(
'BUG: Why are we requesting the pubkey for %s' 'BUG: Why are we requesting the pubkey for %s'
' if there are no messages in the sent folder' ' if there are no messages in the sent folder'
' to that address?', toAddress ' to that address?', toAddress
@ -1388,11 +1379,11 @@ class singleWorker(StoppableThread):
payload += encodeVarint(streamNumber) payload += encodeVarint(streamNumber)
if addressVersionNumber <= 3: if addressVersionNumber <= 3:
payload += ripe payload += ripe
self.logger.info( logger.info(
'making request for pubkey with ripe: %s', hexlify(ripe)) 'making request for pubkey with ripe: %s', hexlify(ripe))
else: else:
payload += tag payload += tag
self.logger.info( logger.info(
'making request for v4 pubkey with tag: %s', hexlify(tag)) 'making request for v4 pubkey with tag: %s', hexlify(tag))
# print 'trial value', trialValue # print 'trial value', trialValue
@ -1413,7 +1404,7 @@ class singleWorker(StoppableThread):
objectType = 1 objectType = 1
Inventory()[inventoryHash] = ( Inventory()[inventoryHash] = (
objectType, streamNumber, payload, embeddedTime, '') objectType, streamNumber, payload, embeddedTime, '')
self.logger.info('sending inv (for the getpubkey message)') logger.info('sending inv (for the getpubkey message)')
queues.invQueue.put((streamNumber, inventoryHash)) queues.invQueue.put((streamNumber, inventoryHash))
# wait 10% past expiration # wait 10% past expiration

View File

@ -1,9 +1,12 @@
""" """
SMTP client thread for delivering emails src/class_smtpDeliver.py
========================
""" """
# pylint: disable=unused-variable # pylint: disable=unused-variable
import smtplib import smtplib
import sys
import threading
import urlparse import urlparse
from email.header import Header from email.header import Header
from email.mime.text import MIMEText from email.mime.text import MIMEText
@ -11,20 +14,23 @@ from email.mime.text import MIMEText
import queues import queues
import state import state
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from network.threads import StoppableThread from debug import logger
from helper_threading import StoppableThread
SMTPDOMAIN = "bmaddr.lan" SMTPDOMAIN = "bmaddr.lan"
class smtpDeliver(StoppableThread): class smtpDeliver(threading.Thread, StoppableThread):
"""SMTP client thread for delivery""" """SMTP client thread for delivery"""
name = "smtpDeliver"
_instance = None _instance = None
def __init__(self):
threading.Thread.__init__(self, name="smtpDeliver")
self.initStop()
def stopThread(self): def stopThread(self):
# pylint: disable=no-member
try: try:
queues.UISignallerQueue.put(("stopThread", "data")) queues.UISignallerQueue.put(("stopThread", "data")) # pylint: disable=no-member
except: except:
pass pass
super(smtpDeliver, self).stopThread() super(smtpDeliver, self).stopThread()
@ -38,7 +44,6 @@ class smtpDeliver(StoppableThread):
def run(self): def run(self):
# pylint: disable=too-many-branches,too-many-statements,too-many-locals # pylint: disable=too-many-branches,too-many-statements,too-many-locals
# pylint: disable=deprecated-lambda
while state.shutdown == 0: while state.shutdown == 0:
command, data = queues.UISignalQueue.get() command, data = queues.UISignalQueue.get()
if command == 'writeNewAddressToTable': if command == 'writeNewAddressToTable':
@ -61,9 +66,9 @@ class smtpDeliver(StoppableThread):
msg = MIMEText(body, 'plain', 'utf-8') msg = MIMEText(body, 'plain', 'utf-8')
msg['Subject'] = Header(subject, 'utf-8') msg['Subject'] = Header(subject, 'utf-8')
msg['From'] = fromAddress + '@' + SMTPDOMAIN msg['From'] = fromAddress + '@' + SMTPDOMAIN
toLabel = map( toLabel = map( # pylint: disable=deprecated-lambda
lambda y: BMConfigParser().safeGet(y, "label"), lambda y: BMConfigParser().safeGet(y, "label"),
filter( filter( # pylint: disable=deprecated-lambda
lambda x: x == toAddress, BMConfigParser().addresses()) lambda x: x == toAddress, BMConfigParser().addresses())
) )
if toLabel: if toLabel:
@ -74,12 +79,10 @@ class smtpDeliver(StoppableThread):
client.starttls() client.starttls()
client.ehlo() client.ehlo()
client.sendmail(msg['From'], [to], msg.as_string()) client.sendmail(msg['From'], [to], msg.as_string())
self.logger.info( logger.info("Delivered via SMTP to %s through %s:%i ...", to, u.hostname, u.port)
'Delivered via SMTP to %s through %s:%i ...',
to, u.hostname, u.port)
client.quit() client.quit()
except: except:
self.logger.error('smtp delivery error', exc_info=True) logger.error("smtp delivery error", exc_info=True)
elif command == 'displayNewSentMessage': elif command == 'displayNewSentMessage':
toAddress, fromLabel, fromAddress, subject, message, ackdata = data toAddress, fromLabel, fromAddress, subject, message, ackdata = data
elif command == 'updateNetworkStatusTab': elif command == 'updateNetworkStatusTab':
@ -113,5 +116,5 @@ class smtpDeliver(StoppableThread):
elif command == 'stopThread': elif command == 'stopThread':
break break
else: else:
self.logger.warning( sys.stderr.write(
'Command sent to smtpDeliver not recognized: %s', command) 'Command sent to smtpDeliver not recognized: %s\n' % command)

View File

@ -1,37 +1,28 @@
"""
SMTP server thread
"""
import asyncore import asyncore
import base64 import base64
import email import email
import logging from email.parser import Parser
from email.header import decode_header
import re import re
import signal import signal
import smtpd import smtpd
import threading import threading
import time import time
from email.header import decode_header
from email.parser import Parser
import queues
from addresses import decodeAddress from addresses import decodeAddress
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from helper_ackPayload import genAckPayload from debug import logger
from helper_sql import sqlExecute from helper_sql import sqlExecute
from network.threads import StoppableThread from helper_ackPayload import genAckPayload
from helper_threading import StoppableThread
import queues
from version import softwareVersion from version import softwareVersion
SMTPDOMAIN = "bmaddr.lan" SMTPDOMAIN = "bmaddr.lan"
LISTENPORT = 8425 LISTENPORT = 8425
logger = logging.getLogger('default')
# pylint: disable=attribute-defined-outside-init
class smtpServerChannel(smtpd.SMTPChannel): class smtpServerChannel(smtpd.SMTPChannel):
"""Asyncore channel for SMTP protocol (server)"""
def smtp_EHLO(self, arg): def smtp_EHLO(self, arg):
"""Process an EHLO"""
if not arg: if not arg:
self.push('501 Syntax: HELO hostname') self.push('501 Syntax: HELO hostname')
return return
@ -39,17 +30,15 @@ class smtpServerChannel(smtpd.SMTPChannel):
self.push('250 AUTH PLAIN') self.push('250 AUTH PLAIN')
def smtp_AUTH(self, arg): def smtp_AUTH(self, arg):
"""Process AUTH"""
if not arg or arg[0:5] not in ["PLAIN"]: if not arg or arg[0:5] not in ["PLAIN"]:
self.push('501 Syntax: AUTH PLAIN') self.push('501 Syntax: AUTH PLAIN')
return return
authstring = arg[6:] authstring = arg[6:]
try: try:
decoded = base64.b64decode(authstring) decoded = base64.b64decode(authstring)
correctauth = "\x00" + BMConfigParser().safeGet( correctauth = "\x00" + BMConfigParser().safeGet("bitmessagesettings", "smtpdusername", "") + \
"bitmessagesettings", "smtpdusername", "") + "\x00" + BMConfigParser().safeGet( "\x00" + BMConfigParser().safeGet("bitmessagesettings", "smtpdpassword", "")
"bitmessagesettings", "smtpdpassword", "") logger.debug("authstring: %s / %s", correctauth, decoded)
logger.debug('authstring: %s / %s', correctauth, decoded)
if correctauth == decoded: if correctauth == decoded:
self.auth = True self.auth = True
self.push('235 2.7.0 Authentication successful') self.push('235 2.7.0 Authentication successful')
@ -59,17 +48,14 @@ class smtpServerChannel(smtpd.SMTPChannel):
self.push('501 Authentication fail') self.push('501 Authentication fail')
def smtp_DATA(self, arg): def smtp_DATA(self, arg):
"""Process DATA"""
if not hasattr(self, "auth") or not self.auth: if not hasattr(self, "auth") or not self.auth:
self.push('530 Authentication required') self.push ("530 Authentication required")
return return
smtpd.SMTPChannel.smtp_DATA(self, arg) smtpd.SMTPChannel.smtp_DATA(self, arg)
class smtpServerPyBitmessage(smtpd.SMTPServer): class smtpServerPyBitmessage(smtpd.SMTPServer):
"""Asyncore SMTP server class"""
def handle_accept(self): def handle_accept(self):
"""Accept a connection"""
pair = self.accept() pair = self.accept()
if pair is not None: if pair is not None:
conn, addr = pair conn, addr = pair
@ -77,9 +63,7 @@ class smtpServerPyBitmessage(smtpd.SMTPServer):
self.channel = smtpServerChannel(self, conn, addr) self.channel = smtpServerChannel(self, conn, addr)
def send(self, fromAddress, toAddress, subject, message): def send(self, fromAddress, toAddress, subject, message):
"""Send a bitmessage""" status, addressVersionNumber, streamNumber, ripe = decodeAddress(toAddress)
# pylint: disable=arguments-differ
streamNumber, ripe = decodeAddress(toAddress)[2:]
stealthLevel = BMConfigParser().safeGetInt('bitmessagesettings', 'ackstealthlevel') stealthLevel = BMConfigParser().safeGetInt('bitmessagesettings', 'ackstealthlevel')
ackdata = genAckPayload(streamNumber, stealthLevel) ackdata = genAckPayload(streamNumber, stealthLevel)
sqlExecute( sqlExecute(
@ -98,14 +82,12 @@ class smtpServerPyBitmessage(smtpd.SMTPServer):
0, # retryNumber 0, # retryNumber
'sent', # folder 'sent', # folder
2, # encodingtype 2, # encodingtype
# not necessary to have a TTL higher than 2 days min(BMConfigParser().getint('bitmessagesettings', 'ttl'), 86400 * 2) # not necessary to have a TTL higher than 2 days
min(BMConfigParser().getint('bitmessagesettings', 'ttl'), 86400 * 2)
) )
queues.workerQueue.put(('sendmessage', toAddress)) queues.workerQueue.put(('sendmessage', toAddress))
def decode_header(self, hdr): def decode_header(self, hdr):
"""Email header decoding"""
ret = [] ret = []
for h in decode_header(self.msg_headers[hdr]): for h in decode_header(self.msg_headers[hdr]):
if h[1]: if h[1]:
@ -115,38 +97,37 @@ class smtpServerPyBitmessage(smtpd.SMTPServer):
return ret return ret
def process_message(self, peer, mailfrom, rcpttos, data): def process_message(self, peer, mailfrom, rcpttos, data):
"""Process an email"""
# pylint: disable=too-many-locals, too-many-branches
# print 'Receiving message from:', peer # print 'Receiving message from:', peer
p = re.compile(".*<([^>]+)>") p = re.compile(".*<([^>]+)>")
if not hasattr(self.channel, "auth") or not self.channel.auth: if not hasattr(self.channel, "auth") or not self.channel.auth:
logger.error('Missing or invalid auth') logger.error("Missing or invalid auth")
return return
try: try:
self.msg_headers = Parser().parsestr(data) self.msg_headers = Parser().parsestr(data)
except: except:
logger.error('Invalid headers') logger.error("Invalid headers")
return return
try: try:
sender, domain = p.sub(r'\1', mailfrom).split("@") sender, domain = p.sub(r'\1', mailfrom).split("@")
if domain != SMTPDOMAIN: if domain != SMTPDOMAIN:
raise Exception("Bad domain %s" % domain) raise Exception("Bad domain %s", domain)
if sender not in BMConfigParser().addresses(): if sender not in BMConfigParser().addresses():
raise Exception("Nonexisting user %s" % sender) raise Exception("Nonexisting user %s", sender)
except Exception as err: except Exception as err:
logger.debug('Bad envelope from %s: %r', mailfrom, err) logger.debug("Bad envelope from %s: %s", mailfrom, repr(err))
msg_from = self.decode_header("from") msg_from = self.decode_header("from")
try: try:
msg_from = p.sub(r'\1', self.decode_header("from")[0]) msg_from = p.sub(r'\1', self.decode_header("from")[0])
sender, domain = msg_from.split("@") sender, domain = msg_from.split("@")
if domain != SMTPDOMAIN: if domain != SMTPDOMAIN:
raise Exception("Bad domain %s" % domain) raise Exception("Bad domain %s", domain)
if sender not in BMConfigParser().addresses(): if sender not in BMConfigParser().addresses():
raise Exception("Nonexisting user %s" % sender) raise Exception("Nonexisting user %s", sender)
except Exception as err: except Exception as err:
logger.error('Bad headers from %s: %r', msg_from, err) logger.error("Bad headers from %s: %s", msg_from, repr(err))
return return
try: try:
@ -164,21 +145,19 @@ class smtpServerPyBitmessage(smtpd.SMTPServer):
try: try:
rcpt, domain = p.sub(r'\1', to).split("@") rcpt, domain = p.sub(r'\1', to).split("@")
if domain != SMTPDOMAIN: if domain != SMTPDOMAIN:
raise Exception("Bad domain %s" % domain) raise Exception("Bad domain %s", domain)
logger.debug( logger.debug("Sending %s to %s about %s", sender, rcpt, msg_subject)
'Sending %s to %s about %s', sender, rcpt, msg_subject)
self.send(sender, rcpt, msg_subject, body) self.send(sender, rcpt, msg_subject, body)
logger.info('Relayed %s to %s', sender, rcpt) logger.info("Relayed %s to %s", sender, rcpt)
except Exception as err: except Exception as err:
logger.error('Bad to %s: %r', to, err) logger.error( "Bad to %s: %s", to, repr(err))
continue continue
return return
class smtpServer(threading.Thread, StoppableThread):
class smtpServer(StoppableThread): def __init__(self, parent=None):
"""SMTP server thread""" threading.Thread.__init__(self, name="smtpServerThread")
def __init__(self, _=None): self.initStop()
super(smtpServer, self).__init__(name="smtpServerThread")
self.server = smtpServerPyBitmessage(('127.0.0.1', LISTENPORT), None) self.server = smtpServerPyBitmessage(('127.0.0.1', LISTENPORT), None)
def stopThread(self): def stopThread(self):
@ -189,26 +168,21 @@ class smtpServer(StoppableThread):
def run(self): def run(self):
asyncore.loop(1) asyncore.loop(1)
def signals(signal, frame):
def signals(_, __): print "Got signal, terminating"
"""Signal handler"""
logger.warning('Got signal, terminating')
for thread in threading.enumerate(): for thread in threading.enumerate():
if thread.isAlive() and isinstance(thread, StoppableThread): if thread.isAlive() and isinstance(thread, StoppableThread):
thread.stopThread() thread.stopThread()
def runServer(): def runServer():
"""Run SMTP server as a standalone python process""" print "Running SMTPd thread"
logger.warning('Running SMTPd thread')
smtpThread = smtpServer() smtpThread = smtpServer()
smtpThread.start() smtpThread.start()
signal.signal(signal.SIGINT, signals) signal.signal(signal.SIGINT, signals)
signal.signal(signal.SIGTERM, signals) signal.signal(signal.SIGTERM, signals)
logger.warning('Processing') print "Processing"
smtpThread.join() smtpThread.join()
logger.warning('The end') print "The end"
if __name__ == "__main__": if __name__ == "__main__":
runServer() runServer()

View File

@ -1,33 +1,29 @@
"""
sqlThread is defined here
"""
import os
import shutil # used for moving the messages.dat file
import sqlite3
import sys
import threading import threading
from bmconfigparser import BMConfigParser
import sqlite3
import time import time
import shutil # used for moving the messages.dat file
import sys
import os
from debug import logger
import helper_sql import helper_sql
import helper_startup import helper_startup
import paths import paths
import queues import queues
import state import state
import tr import tr
from bmconfigparser import BMConfigParser
from debug import logger # This thread exists because SQLITE3 is so un-threadsafe that we must
# pylint: disable=attribute-defined-outside-init,protected-access # submit queries to it and it puts results back in a different queue. They
# won't let us just use locks.
class sqlThread(threading.Thread): class sqlThread(threading.Thread):
"""A thread for all SQL operations"""
def __init__(self): def __init__(self):
threading.Thread.__init__(self, name="SQL") threading.Thread.__init__(self, name="SQL")
def run(self): # pylint: disable=too-many-locals, too-many-branches, too-many-statements def run(self):
"""Process SQL queries from `.helper_sql.sqlSubmitQueue`"""
self.conn = sqlite3.connect(state.appdata + 'messages.dat') self.conn = sqlite3.connect(state.appdata + 'messages.dat')
self.conn.text_factory = str self.conn.text_factory = str
self.cur = self.conn.cursor() self.cur = self.conn.cursor()
@ -36,13 +32,9 @@ class sqlThread(threading.Thread):
try: try:
self.cur.execute( self.cur.execute(
'''CREATE TABLE inbox (msgid blob, toaddress text, fromaddress text, subject text,''' '''CREATE TABLE inbox (msgid blob, toaddress text, fromaddress text, subject text, received text, message text, folder text, encodingtype int, read bool, sighash blob, UNIQUE(msgid) ON CONFLICT REPLACE)''' )
''' received text, message text, folder text, encodingtype int, read bool, sighash blob,'''
''' UNIQUE(msgid) ON CONFLICT REPLACE)''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE sent (msgid blob, toaddress text, toripe blob, fromaddress text, subject text,''' '''CREATE TABLE sent (msgid blob, toaddress text, toripe blob, fromaddress text, subject text, message text, ackdata blob, senttime integer, lastactiontime integer, sleeptill integer, status text, retrynumber integer, folder text, encodingtype int, ttl int)''' )
''' message text, ackdata blob, senttime integer, lastactiontime integer,'''
''' sleeptill integer, status text, retrynumber integer, folder text, encodingtype int, ttl int)''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE subscriptions (label text, address text, enabled bool)''' ) '''CREATE TABLE subscriptions (label text, address text, enabled bool)''' )
self.cur.execute( self.cur.execute(
@ -52,22 +44,18 @@ class sqlThread(threading.Thread):
self.cur.execute( self.cur.execute(
'''CREATE TABLE whitelist (label text, address text, enabled bool)''' ) '''CREATE TABLE whitelist (label text, address text, enabled bool)''' )
self.cur.execute( self.cur.execute(
'''CREATE TABLE pubkeys (address text, addressversion int, transmitdata blob, time int,''' '''CREATE TABLE pubkeys (address text, addressversion int, transmitdata blob, time int, usedpersonally text, UNIQUE(address) ON CONFLICT REPLACE)''' )
''' usedpersonally text, UNIQUE(address) ON CONFLICT REPLACE)''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE inventory (hash blob, objecttype int, streamnumber int, payload blob,''' '''CREATE TABLE inventory (hash blob, objecttype int, streamnumber int, payload blob, expirestime integer, tag blob, UNIQUE(hash) ON CONFLICT REPLACE)''' )
''' expirestime integer, tag blob, UNIQUE(hash) ON CONFLICT REPLACE)''')
self.cur.execute( self.cur.execute(
'''INSERT INTO subscriptions VALUES''' '''INSERT INTO subscriptions VALUES('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''')
'''('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE settings (key blob, value blob, UNIQUE(key) ON CONFLICT REPLACE)''' ) '''CREATE TABLE settings (key blob, value blob, UNIQUE(key) ON CONFLICT REPLACE)''' )
self.cur.execute( '''INSERT INTO settings VALUES('version','10')''') self.cur.execute( '''INSERT INTO settings VALUES('version','10')''')
self.cur.execute( '''INSERT INTO settings VALUES('lastvacuumtime',?)''', ( self.cur.execute( '''INSERT INTO settings VALUES('lastvacuumtime',?)''', (
int(time.time()),)) int(time.time()),))
self.cur.execute( self.cur.execute(
'''CREATE TABLE objectprocessorqueue''' '''CREATE TABLE objectprocessorqueue (objecttype int, data blob, UNIQUE(objecttype, data) ON CONFLICT REPLACE)''' )
''' (objecttype int, data blob, UNIQUE(objecttype, data) ON CONFLICT REPLACE)''')
self.conn.commit() self.conn.commit()
logger.info('Created messages database file') logger.info('Created messages database file')
except Exception as err: except Exception as err:
@ -138,28 +126,23 @@ class sqlThread(threading.Thread):
int(time.time()),)) int(time.time()),))
logger.debug('In messages.dat database, removing an obsolete field from the pubkeys table.') logger.debug('In messages.dat database, removing an obsolete field from the pubkeys table.')
self.cur.execute( self.cur.execute(
'''CREATE TEMPORARY TABLE pubkeys_backup(hash blob, transmitdata blob, time int,''' '''CREATE TEMPORARY TABLE pubkeys_backup(hash blob, transmitdata blob, time int, usedpersonally text, UNIQUE(hash) ON CONFLICT REPLACE);''')
''' usedpersonally text, UNIQUE(hash) ON CONFLICT REPLACE);''')
self.cur.execute( self.cur.execute(
'''INSERT INTO pubkeys_backup SELECT hash, transmitdata, time, usedpersonally FROM pubkeys;''') '''INSERT INTO pubkeys_backup SELECT hash, transmitdata, time, usedpersonally FROM pubkeys;''')
self.cur.execute( '''DROP TABLE pubkeys''') self.cur.execute( '''DROP TABLE pubkeys''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE pubkeys''' '''CREATE TABLE pubkeys (hash blob, transmitdata blob, time int, usedpersonally text, UNIQUE(hash) ON CONFLICT REPLACE)''' )
''' (hash blob, transmitdata blob, time int, usedpersonally text, UNIQUE(hash) ON CONFLICT REPLACE)''')
self.cur.execute( self.cur.execute(
'''INSERT INTO pubkeys SELECT hash, transmitdata, time, usedpersonally FROM pubkeys_backup;''') '''INSERT INTO pubkeys SELECT hash, transmitdata, time, usedpersonally FROM pubkeys_backup;''')
self.cur.execute( '''DROP TABLE pubkeys_backup;''') self.cur.execute( '''DROP TABLE pubkeys_backup;''')
logger.debug( logger.debug('Deleting all pubkeys from inventory. They will be redownloaded and then saved with the correct times.')
'Deleting all pubkeys from inventory.'
' They will be redownloaded and then saved with the correct times.')
self.cur.execute( self.cur.execute(
'''delete from inventory where objecttype = 'pubkey';''') '''delete from inventory where objecttype = 'pubkey';''')
logger.debug('replacing Bitmessage announcements mailing list with a new one.') logger.debug('replacing Bitmessage announcements mailing list with a new one.')
self.cur.execute( self.cur.execute(
'''delete from subscriptions where address='BM-BbkPSZbzPwpVcYZpU4yHwf9ZPEapN5Zx' ''') '''delete from subscriptions where address='BM-BbkPSZbzPwpVcYZpU4yHwf9ZPEapN5Zx' ''')
self.cur.execute( self.cur.execute(
'''INSERT INTO subscriptions VALUES''' '''INSERT INTO subscriptions VALUES('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''')
'''('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''')
logger.debug('Commiting.') logger.debug('Commiting.')
self.conn.commit() self.conn.commit()
logger.debug('Vacuuming message.dat. You might notice that the file size gets much smaller.') logger.debug('Vacuuming message.dat. You might notice that the file size gets much smaller.')
@ -187,20 +170,14 @@ class sqlThread(threading.Thread):
'In messages.dat database, removing an obsolete field from' 'In messages.dat database, removing an obsolete field from'
' the inventory table.') ' the inventory table.')
self.cur.execute( self.cur.execute(
'''CREATE TEMPORARY TABLE inventory_backup''' '''CREATE TEMPORARY TABLE inventory_backup(hash blob, objecttype text, streamnumber int, payload blob, receivedtime integer, UNIQUE(hash) ON CONFLICT REPLACE);''')
'''(hash blob, objecttype text, streamnumber int, payload blob,'''
''' receivedtime integer, UNIQUE(hash) ON CONFLICT REPLACE);''')
self.cur.execute( self.cur.execute(
'''INSERT INTO inventory_backup SELECT hash, objecttype, streamnumber, payload, receivedtime''' '''INSERT INTO inventory_backup SELECT hash, objecttype, streamnumber, payload, receivedtime FROM inventory;''')
''' FROM inventory;''')
self.cur.execute( '''DROP TABLE inventory''') self.cur.execute( '''DROP TABLE inventory''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE inventory''' '''CREATE TABLE inventory (hash blob, objecttype text, streamnumber int, payload blob, receivedtime integer, UNIQUE(hash) ON CONFLICT REPLACE)''' )
''' (hash blob, objecttype text, streamnumber int, payload blob, receivedtime integer,'''
''' UNIQUE(hash) ON CONFLICT REPLACE)''')
self.cur.execute( self.cur.execute(
'''INSERT INTO inventory SELECT hash, objecttype, streamnumber, payload, receivedtime''' '''INSERT INTO inventory SELECT hash, objecttype, streamnumber, payload, receivedtime FROM inventory_backup;''')
''' FROM inventory_backup;''')
self.cur.execute( '''DROP TABLE inventory_backup;''') self.cur.execute( '''DROP TABLE inventory_backup;''')
item = '''update settings set value=? WHERE key='version';''' item = '''update settings set value=? WHERE key='version';'''
parameters = (3,) parameters = (3,)
@ -231,8 +208,7 @@ class sqlThread(threading.Thread):
if currentVersion == 4: if currentVersion == 4:
self.cur.execute('''DROP TABLE pubkeys''') self.cur.execute('''DROP TABLE pubkeys''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE pubkeys (hash blob, addressversion int, transmitdata blob, time int,''' '''CREATE TABLE pubkeys (hash blob, addressversion int, transmitdata blob, time int, usedpersonally text, UNIQUE(hash, addressversion) ON CONFLICT REPLACE)''')
'''usedpersonally text, UNIQUE(hash, addressversion) ON CONFLICT REPLACE)''')
self.cur.execute( self.cur.execute(
'''delete from inventory where objecttype = 'pubkey';''') '''delete from inventory where objecttype = 'pubkey';''')
item = '''update settings set value=? WHERE key='version';''' item = '''update settings set value=? WHERE key='version';'''
@ -248,8 +224,7 @@ class sqlThread(threading.Thread):
if currentVersion == 5: if currentVersion == 5:
self.cur.execute('''DROP TABLE knownnodes''') self.cur.execute('''DROP TABLE knownnodes''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE objectprocessorqueue''' '''CREATE TABLE objectprocessorqueue (objecttype text, data blob, UNIQUE(objecttype, data) ON CONFLICT REPLACE)''')
''' (objecttype text, data blob, UNIQUE(objecttype, data) ON CONFLICT REPLACE)''')
item = '''update settings set value=? WHERE key='version';''' item = '''update settings set value=? WHERE key='version';'''
parameters = (6,) parameters = (6,)
self.cur.execute(item, parameters) self.cur.execute(item, parameters)
@ -266,14 +241,9 @@ class sqlThread(threading.Thread):
'In messages.dat database, dropping and recreating' 'In messages.dat database, dropping and recreating'
' the inventory table.') ' the inventory table.')
self.cur.execute( '''DROP TABLE inventory''') self.cur.execute( '''DROP TABLE inventory''')
self.cur.execute( self.cur.execute( '''CREATE TABLE inventory (hash blob, objecttype int, streamnumber int, payload blob, expirestime integer, tag blob, UNIQUE(hash) ON CONFLICT REPLACE)''' )
'''CREATE TABLE inventory'''
''' (hash blob, objecttype int, streamnumber int, payload blob, expirestime integer,'''
''' tag blob, UNIQUE(hash) ON CONFLICT REPLACE)''')
self.cur.execute( '''DROP TABLE objectprocessorqueue''') self.cur.execute( '''DROP TABLE objectprocessorqueue''')
self.cur.execute( self.cur.execute( '''CREATE TABLE objectprocessorqueue (objecttype int, data blob, UNIQUE(objecttype, data) ON CONFLICT REPLACE)''' )
'''CREATE TABLE objectprocessorqueue'''
''' (objecttype int, data blob, UNIQUE(objecttype, data) ON CONFLICT REPLACE)''')
item = '''update settings set value=? WHERE key='version';''' item = '''update settings set value=? WHERE key='version';'''
parameters = (7,) parameters = (7,)
self.cur.execute(item, parameters) self.cur.execute(item, parameters)
@ -335,23 +305,14 @@ class sqlThread(threading.Thread):
' fields into the retrynumber field and adding the' ' fields into the retrynumber field and adding the'
' sleeptill and ttl fields...') ' sleeptill and ttl fields...')
self.cur.execute( self.cur.execute(
'''CREATE TEMPORARY TABLE sent_backup''' '''CREATE TEMPORARY TABLE sent_backup (msgid blob, toaddress text, toripe blob, fromaddress text, subject text, message text, ackdata blob, lastactiontime integer, status text, retrynumber integer, folder text, encodingtype int)''' )
''' (msgid blob, toaddress text, toripe blob, fromaddress text, subject text, message text,'''
''' ackdata blob, lastactiontime integer, status text, retrynumber integer,'''
''' folder text, encodingtype int)''')
self.cur.execute( self.cur.execute(
'''INSERT INTO sent_backup SELECT msgid, toaddress, toripe, fromaddress,''' '''INSERT INTO sent_backup SELECT msgid, toaddress, toripe, fromaddress, subject, message, ackdata, lastactiontime, status, 0, folder, encodingtype FROM sent;''')
''' subject, message, ackdata, lastactiontime,'''
''' status, 0, folder, encodingtype FROM sent;''')
self.cur.execute( '''DROP TABLE sent''') self.cur.execute( '''DROP TABLE sent''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE sent''' '''CREATE TABLE sent (msgid blob, toaddress text, toripe blob, fromaddress text, subject text, message text, ackdata blob, senttime integer, lastactiontime integer, sleeptill int, status text, retrynumber integer, folder text, encodingtype int, ttl int)''' )
''' (msgid blob, toaddress text, toripe blob, fromaddress text, subject text, message text,'''
''' ackdata blob, senttime integer, lastactiontime integer, sleeptill int, status text,'''
''' retrynumber integer, folder text, encodingtype int, ttl int)''')
self.cur.execute( self.cur.execute(
'''INSERT INTO sent SELECT msgid, toaddress, toripe, fromaddress, subject, message, ackdata,''' '''INSERT INTO sent SELECT msgid, toaddress, toripe, fromaddress, subject, message, ackdata, lastactiontime, lastactiontime, 0, status, 0, folder, encodingtype, 216000 FROM sent_backup;''')
''' lastactiontime, lastactiontime, 0, status, 0, folder, encodingtype, 216000 FROM sent_backup;''')
self.cur.execute( '''DROP TABLE sent_backup''') self.cur.execute( '''DROP TABLE sent_backup''')
logger.info('In messages.dat database, finished making TTL-related changes.') logger.info('In messages.dat database, finished making TTL-related changes.')
logger.debug('In messages.dat database, adding address field to the pubkeys table.') logger.debug('In messages.dat database, adding address field to the pubkeys table.')
@ -369,24 +330,16 @@ class sqlThread(threading.Thread):
self.cur.execute(item, parameters) self.cur.execute(item, parameters)
# Now we can remove the hash field from the pubkeys table. # Now we can remove the hash field from the pubkeys table.
self.cur.execute( self.cur.execute(
'''CREATE TEMPORARY TABLE pubkeys_backup''' '''CREATE TEMPORARY TABLE pubkeys_backup (address text, addressversion int, transmitdata blob, time int, usedpersonally text, UNIQUE(address) ON CONFLICT REPLACE)''' )
''' (address text, addressversion int, transmitdata blob, time int,'''
''' usedpersonally text, UNIQUE(address) ON CONFLICT REPLACE)''')
self.cur.execute( self.cur.execute(
'''INSERT INTO pubkeys_backup''' '''INSERT INTO pubkeys_backup SELECT address, addressversion, transmitdata, time, usedpersonally FROM pubkeys;''')
''' SELECT address, addressversion, transmitdata, time, usedpersonally FROM pubkeys;''')
self.cur.execute( '''DROP TABLE pubkeys''') self.cur.execute( '''DROP TABLE pubkeys''')
self.cur.execute( self.cur.execute(
'''CREATE TABLE pubkeys''' '''CREATE TABLE pubkeys (address text, addressversion int, transmitdata blob, time int, usedpersonally text, UNIQUE(address) ON CONFLICT REPLACE)''' )
''' (address text, addressversion int, transmitdata blob, time int, usedpersonally text,'''
''' UNIQUE(address) ON CONFLICT REPLACE)''')
self.cur.execute( self.cur.execute(
'''INSERT INTO pubkeys SELECT''' '''INSERT INTO pubkeys SELECT address, addressversion, transmitdata, time, usedpersonally FROM pubkeys_backup;''')
''' address, addressversion, transmitdata, time, usedpersonally FROM pubkeys_backup;''')
self.cur.execute( '''DROP TABLE pubkeys_backup''') self.cur.execute( '''DROP TABLE pubkeys_backup''')
logger.debug( logger.debug('In messages.dat database, done adding address field to the pubkeys table and removing the hash field.')
'In messages.dat database, done adding address field to the pubkeys table'
' and removing the hash field.')
self.cur.execute('''update settings set value=10 WHERE key='version';''') self.cur.execute('''update settings set value=10 WHERE key='version';''')
# Are you hoping to add a new option to the keys.dat file of existing # Are you hoping to add a new option to the keys.dat file of existing
@ -406,29 +359,13 @@ class sqlThread(threading.Thread):
self.cur.execute('''DELETE FROM pubkeys WHERE address='1234' ''') self.cur.execute('''DELETE FROM pubkeys WHERE address='1234' ''')
self.conn.commit() self.conn.commit()
if transmitdata == '': if transmitdata == '':
logger.fatal( logger.fatal('Problem: The version of SQLite you have cannot store Null values. Please download and install the latest revision of your version of Python (for example, the latest Python 2.7 revision) and try again.\n')
'Problem: The version of SQLite you have cannot store Null values.' logger.fatal('PyBitmessage will now exit very abruptly. You may now see threading errors related to this abrupt exit but the problem you need to solve is related to SQLite.\n\n')
' Please download and install the latest revision of your version of Python'
' (for example, the latest Python 2.7 revision) and try again.\n')
logger.fatal(
'PyBitmessage will now exit very abruptly.'
' You may now see threading errors related to this abrupt exit'
' but the problem you need to solve is related to SQLite.\n\n')
os._exit(0) os._exit(0)
except Exception as err: except Exception as err:
if str(err) == 'database or disk is full': if str(err) == 'database or disk is full':
logger.fatal( logger.fatal('(While null value test) Alert: Your disk or data storage volume is full. sqlThread will now exit.')
'(While null value test) Alert: Your disk or data storage volume is full.' queues.UISignalQueue.put(('alert', (tr._translate("MainWindow", "Disk full"), tr._translate("MainWindow", 'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'), True)))
' sqlThread will now exit.')
queues.UISignalQueue.put((
'alert', (
tr._translate(
"MainWindow",
"Disk full"),
tr._translate(
"MainWindow",
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
True)))
os._exit(0) os._exit(0)
else: else:
logger.error(err) logger.error(err)
@ -447,18 +384,8 @@ class sqlThread(threading.Thread):
self.cur.execute( ''' VACUUM ''') self.cur.execute( ''' VACUUM ''')
except Exception as err: except Exception as err:
if str(err) == 'database or disk is full': if str(err) == 'database or disk is full':
logger.fatal( logger.fatal('(While VACUUM) Alert: Your disk or data storage volume is full. sqlThread will now exit.')
'(While VACUUM) Alert: Your disk or data storage volume is full.' queues.UISignalQueue.put(('alert', (tr._translate("MainWindow", "Disk full"), tr._translate("MainWindow", 'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'), True)))
' sqlThread will now exit.')
queues.UISignalQueue.put((
'alert', (
tr._translate(
"MainWindow",
"Disk full"),
tr._translate(
"MainWindow",
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
True)))
os._exit(0) os._exit(0)
item = '''update settings set value=? WHERE key='lastvacuumtime';''' item = '''update settings set value=? WHERE key='lastvacuumtime';'''
parameters = (int(time.time()),) parameters = (int(time.time()),)
@ -473,18 +400,8 @@ class sqlThread(threading.Thread):
self.conn.commit() self.conn.commit()
except Exception as err: except Exception as err:
if str(err) == 'database or disk is full': if str(err) == 'database or disk is full':
logger.fatal( logger.fatal('(While committing) Alert: Your disk or data storage volume is full. sqlThread will now exit.')
'(While committing) Alert: Your disk or data storage volume is full.' queues.UISignalQueue.put(('alert', (tr._translate("MainWindow", "Disk full"), tr._translate("MainWindow", 'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'), True)))
' sqlThread will now exit.')
queues.UISignalQueue.put((
'alert', (
tr._translate(
"MainWindow",
"Disk full"),
tr._translate(
"MainWindow",
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
True)))
os._exit(0) os._exit(0)
elif item == 'exit': elif item == 'exit':
self.conn.close() self.conn.close()
@ -498,18 +415,8 @@ class sqlThread(threading.Thread):
self.conn.commit() self.conn.commit()
except Exception as err: except Exception as err:
if str(err) == 'database or disk is full': if str(err) == 'database or disk is full':
logger.fatal( logger.fatal('(while movemessagstoprog) Alert: Your disk or data storage volume is full. sqlThread will now exit.')
'(while movemessagstoprog) Alert: Your disk or data storage volume is full.' queues.UISignalQueue.put(('alert', (tr._translate("MainWindow", "Disk full"), tr._translate("MainWindow", 'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'), True)))
' sqlThread will now exit.')
queues.UISignalQueue.put((
'alert', (
tr._translate(
"MainWindow",
"Disk full"),
tr._translate(
"MainWindow",
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
True)))
os._exit(0) os._exit(0)
self.conn.close() self.conn.close()
shutil.move( shutil.move(
@ -524,18 +431,8 @@ class sqlThread(threading.Thread):
self.conn.commit() self.conn.commit()
except Exception as err: except Exception as err:
if str(err) == 'database or disk is full': if str(err) == 'database or disk is full':
logger.fatal( logger.fatal('(while movemessagstoappdata) Alert: Your disk or data storage volume is full. sqlThread will now exit.')
'(while movemessagstoappdata) Alert: Your disk or data storage volume is full.' queues.UISignalQueue.put(('alert', (tr._translate("MainWindow", "Disk full"), tr._translate("MainWindow", 'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'), True)))
' sqlThread will now exit.')
queues.UISignalQueue.put((
'alert', (
tr._translate(
"MainWindow",
"Disk full"),
tr._translate(
"MainWindow",
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
True)))
os._exit(0) os._exit(0)
self.conn.close() self.conn.close()
shutil.move( shutil.move(
@ -551,18 +448,8 @@ class sqlThread(threading.Thread):
self.cur.execute( ''' VACUUM ''') self.cur.execute( ''' VACUUM ''')
except Exception as err: except Exception as err:
if str(err) == 'database or disk is full': if str(err) == 'database or disk is full':
logger.fatal( logger.fatal('(while deleteandvacuume) Alert: Your disk or data storage volume is full. sqlThread will now exit.')
'(while deleteandvacuume) Alert: Your disk or data storage volume is full.' queues.UISignalQueue.put(('alert', (tr._translate("MainWindow", "Disk full"), tr._translate("MainWindow", 'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'), True)))
' sqlThread will now exit.')
queues.UISignalQueue.put((
'alert', (
tr._translate(
"MainWindow",
"Disk full"),
tr._translate(
"MainWindow",
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
True)))
os._exit(0) os._exit(0)
else: else:
parameters = helper_sql.sqlSubmitQueue.get() parameters = helper_sql.sqlSubmitQueue.get()
@ -574,30 +461,11 @@ class sqlThread(threading.Thread):
rowcount = self.cur.rowcount rowcount = self.cur.rowcount
except Exception as err: except Exception as err:
if str(err) == 'database or disk is full': if str(err) == 'database or disk is full':
logger.fatal( logger.fatal('(while cur.execute) Alert: Your disk or data storage volume is full. sqlThread will now exit.')
'(while cur.execute) Alert: Your disk or data storage volume is full.' queues.UISignalQueue.put(('alert', (tr._translate("MainWindow", "Disk full"), tr._translate("MainWindow", 'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'), True)))
' sqlThread will now exit.')
queues.UISignalQueue.put((
'alert', (
tr._translate(
"MainWindow",
"Disk full"),
tr._translate(
"MainWindow",
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
True)))
os._exit(0) os._exit(0)
else: else:
logger.fatal( logger.fatal('Major error occurred when trying to execute a SQL statement within the sqlThread. Please tell Atheros about this error message or post it in the forum! Error occurred while trying to execute statement: "%s" Here are the parameters; you might want to censor this data with asterisks (***) as it can contain private information: %s. Here is the actual error message thrown by the sqlThread: %s', str(item), str(repr(parameters)), str(err))
'Major error occurred when trying to execute a SQL statement within the sqlThread.'
' Please tell Atheros about this error message or post it in the forum!'
' Error occurred while trying to execute statement: "%s" Here are the parameters;'
' you might want to censor this data with asterisks (***)'
' as it can contain private information: %s.'
' Here is the actual error message thrown by the sqlThread: %s',
str(item),
str(repr(parameters)),
str(err))
logger.fatal('This program shall now abruptly exit!') logger.fatal('This program shall now abruptly exit!')
os._exit(0) os._exit(0)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 650 B

View File

@ -1,6 +1,6 @@
""" """
Logging and debuging facility Logging and debuging facility
----------------------------- =============================
Levels: Levels:
@ -9,30 +9,18 @@ Levels:
INFO INFO
Confirmation that things are working as expected. Confirmation that things are working as expected.
WARNING WARNING
An indication that something unexpected happened, or indicative of An indication that something unexpected happened, or indicative of some problem in the
some problem in the near future (e.g. 'disk space low'). The software near future (e.g. 'disk space low'). The software is still working as expected.
is still working as expected.
ERROR ERROR
Due to a more serious problem, the software has not been able to Due to a more serious problem, the software has not been able to perform some function.
perform some function.
CRITICAL CRITICAL
A serious error, indicating that the program itself may be unable to A serious error, indicating that the program itself may be unable to continue running.
continue running.
There are three loggers by default: `console_only`, `file_only` and `both`. There are three loggers: `console_only`, `file_only` and `both`.
You can configure logging in the logging.dat in the appdata dir.
It's format is described in the :func:`logging.config.fileConfig` doc.
Use: Use: `from debug import logger` to import this facility into whatever module you wish to log messages from.
Logging is thread-safe so you don't have to worry about locks, just import and log.
>>> import logging
>>> logger = logging.getLogger('default')
The old form: ``from debug import logger`` is also may be used,
but only in the top level modules.
Logging is thread-safe so you don't have to worry about locks,
just import and log.
""" """
import ConfigParser import ConfigParser
@ -40,11 +28,11 @@ import logging
import logging.config import logging.config
import os import os
import sys import sys
import helper_startup import helper_startup
import state import state
helper_startup.loadConfig() helper_startup.loadConfig()
# Now can be overriden from a config file, which uses standard python # Now can be overriden from a config file, which uses standard python
# logging.config.fileConfig interface # logging.config.fileConfig interface
# examples are here: # examples are here:
@ -53,22 +41,14 @@ log_level = 'WARNING'
def log_uncaught_exceptions(ex_cls, ex, tb): def log_uncaught_exceptions(ex_cls, ex, tb):
"""The last resort logging function used for sys.excepthook"""
logging.critical('Unhandled exception', exc_info=(ex_cls, ex, tb)) logging.critical('Unhandled exception', exc_info=(ex_cls, ex, tb))
def configureLogging(): def configureLogging():
"""
Configure logging,
using either logging.dat file in the state.appdata dir
or dictionary with hardcoded settings.
"""
sys.excepthook = log_uncaught_exceptions
fail_msg = '' fail_msg = ''
try: try:
logging_config = os.path.join(state.appdata, 'logging.dat') logging_config = os.path.join(state.appdata, 'logging.dat')
logging.config.fileConfig( logging.config.fileConfig(logging_config)
logging_config, disable_existing_loggers=False)
return ( return (
False, False,
'Loaded logger configuration from %s' % logging_config 'Loaded logger configuration from %s' % logging_config
@ -80,11 +60,12 @@ def configureLogging():
' logging config\n%s' % \ ' logging config\n%s' % \
(logging_config, sys.exc_info()) (logging_config, sys.exc_info())
else: else:
# no need to confuse the user if the logger config # no need to confuse the user if the logger config is missing entirely
# is missing entirely
fail_msg = 'Using default logger configuration' fail_msg = 'Using default logger configuration'
logging_config = { sys.excepthook = log_uncaught_exceptions
logging.config.dictConfig({
'version': 1, 'version': 1,
'formatters': { 'formatters': {
'default': { 'default': {
@ -126,29 +107,34 @@ def configureLogging():
'level': log_level, 'level': log_level,
'handlers': ['console'], 'handlers': ['console'],
}, },
} })
logging_config['loggers']['default'] = logging_config['loggers'][
'file_only' if '-c' in sys.argv else 'both']
logging.config.dictConfig(logging_config)
return True, fail_msg return True, fail_msg
def initLogging():
preconfigured, msg = configureLogging()
if preconfigured:
if '-c' in sys.argv:
logger = logging.getLogger('file_only')
else:
logger = logging.getLogger('both')
else:
logger = logging.getLogger('default')
if msg:
logger.log(logging.WARNING if preconfigured else logging.INFO, msg)
return logger
def resetLogging(): def resetLogging():
"""Reconfigure logging in runtime when state.appdata dir changed"""
# pylint: disable=global-statement, used-before-assignment
global logger global logger
for i in logger.handlers: for i in logger.handlers.iterkeys():
logger.removeHandler(i) logger.removeHandler(i)
i.flush() i.flush()
i.close() i.close()
configureLogging() logger = initLogging()
logger = logging.getLogger('default')
# ! # !
preconfigured, msg = configureLogging() logger = initLogging()
logger = logging.getLogger('default')
if msg:
logger.log(logging.WARNING if preconfigured else logging.INFO, msg)

View File

@ -1,24 +1,24 @@
""" """
Common default values src/defaults.py
===============
""" """
#: sanity check, prevent doing ridiculous PoW # sanity check, prevent doing ridiculous PoW
#: 20 million PoWs equals approximately 2 days on dev's dual R9 290 # 20 million PoWs equals approximately 2 days on dev's dual R9 290
ridiculousDifficulty = 20000000 ridiculousDifficulty = 20000000
#: Remember here the RPC port read from namecoin.conf so we can restore to # Remember here the RPC port read from namecoin.conf so we can restore to
#: it as default whenever the user changes the "method" selection for # it as default whenever the user changes the "method" selection for
#: namecoin integration to "namecoind". # namecoin integration to "namecoind".
namecoinDefaultRpcPort = "8336" namecoinDefaultRpcPort = "8336"
# If changed, these values will cause particularly unexpected behavior: # If changed, these values will cause particularly unexpected behavior:
# You won't be able to either send or receive messages because the proof # You won't be able to either send or receive messages because the proof
# of work you do (or demand) won't match that done or demanded by others. # of work you do (or demand) won't match that done or demanded by others.
# Don't change them! # Don't change them!
#: The amount of work that should be performed (and demanded) per byte # The amount of work that should be performed (and demanded) per byte of the payload.
#: of the payload.
networkDefaultProofOfWorkNonceTrialsPerByte = 1000 networkDefaultProofOfWorkNonceTrialsPerByte = 1000
#: To make sending short messages a little more difficult, this value is # To make sending short messages a little more difficult, this value is
#: added to the payload length for use in calculating the proof of work # added to the payload length for use in calculating the proof of work
#: target. # target.
networkDefaultPayloadLengthExtraBytes = 1000 networkDefaultPayloadLengthExtraBytes = 1000

View File

@ -17,7 +17,7 @@ if not hasattr(sys, 'hexversion') or sys.hexversion < 0x20300F0:
import logging import logging
import os import os
from importlib import import_module from importlib import import_module
import state
# We can now use logging so set up a simple configuration # We can now use logging so set up a simple configuration
formatter = logging.Formatter('%(levelname)s: %(message)s') formatter = logging.Formatter('%(levelname)s: %(message)s')
handler = logging.StreamHandler(sys.stdout) handler = logging.StreamHandler(sys.stdout)
@ -113,7 +113,6 @@ PACKAGES = {
def detectOS(): def detectOS():
"""Finding out what Operating System is running"""
if detectOS.result is not None: if detectOS.result is not None:
return detectOS.result return detectOS.result
if sys.platform.startswith('openbsd'): if sys.platform.startswith('openbsd'):
@ -133,7 +132,6 @@ detectOS.result = None
def detectOSRelease(): def detectOSRelease():
"""Detecting the release of OS"""
with open("/etc/os-release", 'r') as osRelease: with open("/etc/os-release", 'r') as osRelease:
version = None version = None
for line in osRelease: for line in osRelease:
@ -150,7 +148,6 @@ def detectOSRelease():
def try_import(module, log_extra=False): def try_import(module, log_extra=False):
"""Try to import the non imported packages"""
try: try:
return import_module(module) return import_module(module)
except ImportError: except ImportError:
@ -211,8 +208,10 @@ def check_sqlite():
).fetchone()[0] ).fetchone()[0]
logger.info('SQLite Library Source ID: %s', sqlite_source_id) logger.info('SQLite Library Source ID: %s', sqlite_source_id)
if sqlite_version_number >= 3006023: if sqlite_version_number >= 3006023:
compile_options = ', '.join( compile_options = ', '.join(map(
[row[0] for row in conn.execute('PRAGMA compile_options;')]) lambda row: row[0],
conn.execute('PRAGMA compile_options;')
))
logger.info( logger.info(
'SQLite Library Compile Options: %s', compile_options) 'SQLite Library Compile Options: %s', compile_options)
# There is no specific version requirement as yet, so we just # There is no specific version requirement as yet, so we just
@ -237,8 +236,7 @@ def check_openssl():
Here we are checking for openssl with its all dependent libraries Here we are checking for openssl with its all dependent libraries
and version checking. and version checking.
""" """
# pylint: disable=too-many-branches, too-many-return-statements
# pylint: disable=protected-access, redefined-outer-name
ctypes = try_import('ctypes') ctypes = try_import('ctypes')
if not ctypes: if not ctypes:
logger.error('Unable to check OpenSSL.') logger.error('Unable to check OpenSSL.')
@ -250,11 +248,8 @@ def check_openssl():
if getattr(sys, 'frozen', False): if getattr(sys, 'frozen', False):
import os.path import os.path
paths.insert(0, os.path.join(sys._MEIPASS, 'libeay32.dll')) paths.insert(0, os.path.join(sys._MEIPASS, 'libeay32.dll'))
elif state.kivy:
return True
else: else:
paths = ['libcrypto.so', 'libcrypto.so.1.0.0'] paths = ['libcrypto.so', 'libcrypto.so.1.0.0']
if sys.platform == 'darwin': if sys.platform == 'darwin':
paths.extend([ paths.extend([
'libcrypto.dylib', 'libcrypto.dylib',
@ -305,7 +300,7 @@ def check_openssl():
' ECDH, and ECDSA enabled.') ' ECDH, and ECDSA enabled.')
return False return False
matches = cflags_regex.findall(openssl_cflags) matches = cflags_regex.findall(openssl_cflags)
if matches: if len(matches) > 0:
logger.error( logger.error(
'This OpenSSL library is missing the following required' 'This OpenSSL library is missing the following required'
' features: %s. PyBitmessage requires OpenSSL 0.9.8b' ' features: %s. PyBitmessage requires OpenSSL 0.9.8b'
@ -316,13 +311,13 @@ def check_openssl():
return False return False
# ..todo:: The minimum versions of pythondialog and dialog need to be determined # TODO: The minimum versions of pythondialog and dialog need to be determined
def check_curses(): def check_curses():
"""Do curses dependency check. """Do curses dependency check.
Here we are checking for curses if available or not with check as interface Here we are checking for curses if available or not with check
requires the `pythondialog <https://pypi.org/project/pythondialog>`_ package as interface requires the pythondialog\ package and the dialog
and the dialog utility. utility.
""" """
if sys.hexversion < 0x20600F0: if sys.hexversion < 0x20600F0:
logger.error( logger.error(
@ -430,6 +425,7 @@ def check_dependencies(verbose=False, optional=False):
check_functions = [check_ripemd160, check_sqlite, check_openssl] check_functions = [check_ripemd160, check_sqlite, check_openssl]
if optional: if optional:
check_functions.extend([check_msgpack, check_pyqt, check_curses]) check_functions.extend([check_msgpack, check_pyqt, check_curses])
# Unexpected exceptions are handled here # Unexpected exceptions are handled here
for check in check_functions: for check in check_functions:
try: try:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 651 B

View File

@ -1,19 +1,13 @@
""" """
Fallback expressions help PyBitmessage modules to run without some external .. todo:: hello world
dependencies.
RIPEMD160Hash
-------------
We need to check :mod:`hashlib` for RIPEMD-160, as it won't be available
if OpenSSL is not linked against or the linked OpenSSL has RIPEMD disabled.
Try to use `pycryptodome <https://pypi.org/project/pycryptodome/>`_
in that case.
""" """
import hashlib import hashlib
# We need to check hashlib for RIPEMD-160, as it won't be available
# if OpenSSL is not linked against or the linked OpenSSL has RIPEMD
# disabled.
try: try:
hashlib.new('ripemd160') hashlib.new('ripemd160')
except ValueError: except ValueError:

View File

@ -1,28 +1,22 @@
""" """This module is for generating ack payload."""
This module is for generating ack payload
"""
import highlevelcrypto
import helper_random
from binascii import hexlify from binascii import hexlify
from struct import pack from struct import pack
import helper_random
import highlevelcrypto
from addresses import encodeVarint from addresses import encodeVarint
# This function generates payload objects for message acknowledgements
# Several stealth levels are available depending on the privacy needs;
# a higher level means better stealth, but also higher cost (size+POW)
# - level 0: a random 32-byte sequence with a message header appended
# - level 1: a getpubkey request for a (random) dummy key hash
# - level 2: a standard message, encrypted to a random pubkey
def genAckPayload(streamNumber=1, stealthLevel=0): def genAckPayload(streamNumber=1, stealthLevel=0):
""" """Generate and return payload obj."""
Generate and return payload obj. if (stealthLevel == 2): # Generate privacy-enhanced payload
This function generates payload objects for message acknowledgements
Several stealth levels are available depending on the privacy needs;
a higher level means better stealth, but also higher cost (size+POW)
- level 0: a random 32-byte sequence with a message header appended
- level 1: a getpubkey request for a (random) dummy key hash
- level 2: a standard message, encrypted to a random pubkey
"""
if stealthLevel == 2: # Generate privacy-enhanced payload
# Generate a dummy privkey and derive the pubkey # Generate a dummy privkey and derive the pubkey
dummyPubKeyHex = highlevelcrypto.privToPub( dummyPubKeyHex = highlevelcrypto.privToPub(
hexlify(helper_random.randomBytes(32))) hexlify(helper_random.randomBytes(32)))
@ -35,7 +29,7 @@ def genAckPayload(streamNumber=1, stealthLevel=0):
acktype = 2 # message acktype = 2 # message
version = 1 version = 1
elif stealthLevel == 1: # Basic privacy payload (random getpubkey) elif (stealthLevel == 1): # Basic privacy payload (random getpubkey)
ackdata = helper_random.randomBytes(32) ackdata = helper_random.randomBytes(32)
acktype = 0 # getpubkey acktype = 0 # getpubkey
version = 4 version = 4

View File

@ -1,19 +1,10 @@
"""
Calculates bitcoin and testnet address from pubkey
"""
import hashlib import hashlib
from debug import logger
from pyelliptic import arithmetic from pyelliptic import arithmetic
# This function expects that pubkey begin with \x04
def calculateBitcoinAddressFromPubkey(pubkey): def calculateBitcoinAddressFromPubkey(pubkey):
"""Calculate bitcoin address from given pubkey (65 bytes long hex string)"""
if len(pubkey) != 65: if len(pubkey) != 65:
logger.error('Could not calculate Bitcoin address from pubkey because' print 'Could not calculate Bitcoin address from pubkey because function was passed a pubkey that was', len(pubkey), 'bytes long rather than 65.'
' function was passed a pubkey that was'
' %i bytes long rather than 65.', len(pubkey))
return "error" return "error"
ripe = hashlib.new('ripemd160') ripe = hashlib.new('ripemd160')
sha = hashlib.new('sha256') sha = hashlib.new('sha256')
@ -33,11 +24,8 @@ def calculateBitcoinAddressFromPubkey(pubkey):
def calculateTestnetAddressFromPubkey(pubkey): def calculateTestnetAddressFromPubkey(pubkey):
"""This function expects that pubkey begin with the testnet prefix"""
if len(pubkey) != 65: if len(pubkey) != 65:
logger.error('Could not calculate Bitcoin address from pubkey because' print 'Could not calculate Bitcoin address from pubkey because function was passed a pubkey that was', len(pubkey), 'bytes long rather than 65.'
' function was passed a pubkey that was'
' %i bytes long rather than 65.', len(pubkey))
return "error" return "error"
ripe = hashlib.new('ripemd160') ripe = hashlib.new('ripemd160')
sha = hashlib.new('sha256') sha = hashlib.new('sha256')

84
src/helper_bootstrap.py Normal file
View File

@ -0,0 +1,84 @@
import socket
import knownnodes
import socks
import state
from bmconfigparser import BMConfigParser
from debug import logger
def dns():
"""
DNS bootstrap. This could be programmed to use the SOCKS proxy to do the
DNS lookup some day but for now we will just rely on the entries in
defaultKnownNodes.py. Hopefully either they are up to date or the user
has run Bitmessage recently without SOCKS turned on and received good
bootstrap nodes using that method.
"""
def try_add_known_node(stream, addr, port, method=''):
try:
socket.inet_aton(addr)
except (TypeError, socket.error):
return
logger.info(
'Adding %s to knownNodes based on %s DNS bootstrap method',
addr, method)
knownnodes.addKnownNode(stream, state.Peer(addr, port))
proxy_type = BMConfigParser().get('bitmessagesettings', 'socksproxytype')
if proxy_type == 'none':
for port in [8080, 8444]:
try:
for item in socket.getaddrinfo(
'bootstrap%s.bitmessage.org' % port, 80):
try_add_known_node(1, item[4][0], port)
except:
logger.error(
'bootstrap%s.bitmessage.org DNS bootstrapping failed.',
port, exc_info=True
)
elif proxy_type == 'SOCKS5':
knownnodes.createDefaultKnownNodes(onion=True)
logger.debug('Adding default onion knownNodes.')
for port in [8080, 8444]:
logger.debug("Resolving %i through SOCKS...", port)
address_family = socket.AF_INET
sock = socks.socksocket(address_family, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.settimeout(20)
proxytype = socks.PROXY_TYPE_SOCKS5
sockshostname = BMConfigParser().get(
'bitmessagesettings', 'sockshostname')
socksport = BMConfigParser().getint(
'bitmessagesettings', 'socksport')
# Do domain name lookups through the proxy;
# though this setting doesn't really matter since we won't
# be doing any domain name lookups anyway.
rdns = True
if BMConfigParser().getboolean(
'bitmessagesettings', 'socksauthentication'):
socksusername = BMConfigParser().get(
'bitmessagesettings', 'socksusername')
sockspassword = BMConfigParser().get(
'bitmessagesettings', 'sockspassword')
sock.setproxy(
proxytype, sockshostname, socksport, rdns,
socksusername, sockspassword)
else:
sock.setproxy(
proxytype, sockshostname, socksport, rdns)
try:
ip = sock.resolve("bootstrap" + str(port) + ".bitmessage.org")
sock.shutdown(socket.SHUT_RDWR)
sock.close()
except:
logger.error("SOCKS DNS resolving failed", exc_info=True)
else:
try_add_known_node(1, ip, port, 'SOCKS')
else:
logger.info(
'DNS bootstrap skipped because the proxy type does not support'
' DNS resolution.'
)

View File

@ -1,114 +0,0 @@
"""
Helper Generic perform generic operations for threading.
Also perform some conversion operations.
"""
import socket
import sys
import threading
import traceback
try:
import multiprocessing
except Exception as e:
pass
from binascii import hexlify, unhexlify
import shared
import state
import queues
import shutdown
from debug import logger
def powQueueSize():
curWorkerQueue = queues.workerQueue.qsize()
for thread in threading.enumerate():
try:
if thread.name == "singleWorker":
curWorkerQueue += thread.busy
except Exception as err:
logger.info('Thread error %s', err)
return curWorkerQueue
def convertIntToString(n):
a = __builtins__.hex(n)
if a[-1:] == 'L':
a = a[:-1]
if (len(a) % 2) == 0:
return unhexlify(a[2:])
else:
return unhexlify('0' + a[2:])
def convertStringToInt(s):
return int(hexlify(s), 16)
def allThreadTraceback(frame):
id2name = dict([(th.ident, th.name) for th in threading.enumerate()])
code = []
for threadId, stack in sys._current_frames().items():
code.append(
'\n# Thread: %s(%d)' % (id2name.get(threadId, ''), threadId))
for filename, lineno, name, line in traceback.extract_stack(stack):
code.append(
'File: "%s", line %d, in %s' % (filename, lineno, name))
if line:
code.append(' %s' % (line.strip()))
print('\n'.join(code))
def signal_handler(signal, frame):
try:
process = multiprocessing.current_process()
except Exception as e:
process = threading.current_thread()
logger.error(
'Got signal %i in %s/%s',
signal, process.name, threading.current_thread().name
)
if process.name == "RegExParser":
# on Windows this isn't triggered, but it's fine,
# it has its own process termination thing
raise SystemExit
if "PoolWorker" in process.name:
raise SystemExit
if threading.current_thread().name not in ("PyBitmessage", "MainThread"):
return
logger.error("Got signal %i", signal)
if shared.thisapp.daemon or not state.enableGUI: # FIXME redundant?
shutdown.doCleanShutdown()
else:
allThreadTraceback(frame)
print('Unfortunately you cannot use Ctrl+C when running the UI'
' because the UI captures the signal.')
def isHostInPrivateIPRange(host):
if ":" in host: # IPv6
hostAddr = socket.inet_pton(socket.AF_INET6, host)
if hostAddr == ('\x00' * 15) + '\x01':
return False
if hostAddr[0] == '\xFE' and (ord(hostAddr[1]) & 0xc0) == 0x80:
return False
if (ord(hostAddr[0]) & 0xfe) == 0xfc:
return False
elif ".onion" not in host:
if host[:3] == '10.':
return True
if host[:4] == '172.':
if host[6] == '.':
if int(host[4:6]) >= 16 and int(host[4:6]) <= 31:
return True
if host[:8] == '192.168.':
return True
# Multicast
if host[:3] >= 224 and host[:3] <= 239 and host[4] == '.':
return True
return False
def addDataPadding(data, desiredMsgLength=12, paddingChar='\x00'):
return data + paddingChar * (desiredMsgLength - len(data))

View File

@ -1,11 +1,10 @@
"""Helper Inbox performs inbox messages related operations""" """Helper Inbox performs inbox messagese related operations."""
import queues
from helper_sql import sqlExecute, sqlQuery from helper_sql import sqlExecute, sqlQuery
import queues
def insert(t): def insert(t):
"""Perform an insert into the "inbox" table"""
sqlExecute('''INSERT INTO inbox VALUES (?,?,?,?,?,?,?,?,?,?)''', *t) sqlExecute('''INSERT INTO inbox VALUES (?,?,?,?,?,?,?,?,?,?)''', *t)
# shouldn't emit changedInboxUnread and displayNewInboxMessage # shouldn't emit changedInboxUnread and displayNewInboxMessage
# at the same time # at the same time
@ -13,13 +12,11 @@ def insert(t):
def trash(msgid): def trash(msgid):
"""Mark a message in the `inbox` as `trash`"""
sqlExecute('''UPDATE inbox SET folder='trash' WHERE msgid=?''', msgid) sqlExecute('''UPDATE inbox SET folder='trash' WHERE msgid=?''', msgid)
queues.UISignalQueue.put(('removeInboxRowByMsgid', msgid)) queues.UISignalQueue.put(('removeInboxRowByMsgid', msgid))
def isMessageAlreadyInInbox(sigHash): def isMessageAlreadyInInbox(sigHash):
"""Check for previous instances of this message"""
queryReturn = sqlQuery( queryReturn = sqlQuery(
'''SELECT COUNT(*) FROM inbox WHERE sighash=?''', sigHash) '''SELECT COUNT(*) FROM inbox WHERE sighash=?''', sigHash)
return queryReturn[0][0] != 0 return queryReturn[0][0] != 0

View File

@ -5,11 +5,6 @@ Message encoding end decoding functions
import string import string
import zlib import zlib
import messagetypes
from bmconfigparser import BMConfigParser
from debug import logger
from tr import _translate
try: try:
import msgpack import msgpack
except ImportError: except ImportError:
@ -18,6 +13,11 @@ except ImportError:
except ImportError: except ImportError:
import fallback.umsgpack.umsgpack as msgpack import fallback.umsgpack.umsgpack as msgpack
import messagetypes
from bmconfigparser import BMConfigParser
from debug import logger
from tr import _translate
BITMESSAGE_ENCODING_IGNORE = 0 BITMESSAGE_ENCODING_IGNORE = 0
BITMESSAGE_ENCODING_TRIVIAL = 1 BITMESSAGE_ENCODING_TRIVIAL = 1
BITMESSAGE_ENCODING_SIMPLE = 2 BITMESSAGE_ENCODING_SIMPLE = 2
@ -25,24 +25,19 @@ BITMESSAGE_ENCODING_EXTENDED = 3
class MsgEncodeException(Exception): class MsgEncodeException(Exception):
"""Exception during message encoding"""
pass pass
class MsgDecodeException(Exception): class MsgDecodeException(Exception):
"""Exception during message decoding"""
pass pass
class DecompressionSizeException(MsgDecodeException): class DecompressionSizeException(MsgDecodeException):
# pylint: disable=super-init-not-called
"""Decompression resulted in too much data (attack protection)"""
def __init__(self, size): def __init__(self, size):
self.size = size self.size = size
class MsgEncode(object): class MsgEncode(object):
"""Message encoder class"""
def __init__(self, message, encoding=BITMESSAGE_ENCODING_SIMPLE): def __init__(self, message, encoding=BITMESSAGE_ENCODING_SIMPLE):
self.data = None self.data = None
self.encoding = encoding self.encoding = encoding
@ -57,7 +52,6 @@ class MsgEncode(object):
raise MsgEncodeException("Unknown encoding %i" % (encoding)) raise MsgEncodeException("Unknown encoding %i" % (encoding))
def encodeExtended(self, message): def encodeExtended(self, message):
"""Handle extended encoding"""
try: try:
msgObj = messagetypes.message.Message() msgObj = messagetypes.message.Message()
self.data = zlib.compress(msgpack.dumps(msgObj.encode(message)), 9) self.data = zlib.compress(msgpack.dumps(msgObj.encode(message)), 9)
@ -70,18 +64,15 @@ class MsgEncode(object):
self.length = len(self.data) self.length = len(self.data)
def encodeSimple(self, message): def encodeSimple(self, message):
"""Handle simple encoding"""
self.data = 'Subject:%(subject)s\nBody:%(body)s' % message self.data = 'Subject:%(subject)s\nBody:%(body)s' % message
self.length = len(self.data) self.length = len(self.data)
def encodeTrivial(self, message): def encodeTrivial(self, message):
"""Handle trivial encoding"""
self.data = message['body'] self.data = message['body']
self.length = len(self.data) self.length = len(self.data)
class MsgDecode(object): class MsgDecode(object):
"""Message decoder class"""
def __init__(self, encoding, data): def __init__(self, encoding, data):
self.encoding = encoding self.encoding = encoding
if self.encoding == BITMESSAGE_ENCODING_EXTENDED: if self.encoding == BITMESSAGE_ENCODING_EXTENDED:
@ -97,7 +88,6 @@ class MsgDecode(object):
self.subject = _translate("MsgDecode", "Unknown encoding") self.subject = _translate("MsgDecode", "Unknown encoding")
def decodeExtended(self, data): def decodeExtended(self, data):
"""Handle extended encoding"""
dc = zlib.decompressobj() dc = zlib.decompressobj()
tmp = "" tmp = ""
while len(tmp) <= BMConfigParser().safeGetInt("zlib", "maxsize"): while len(tmp) <= BMConfigParser().safeGetInt("zlib", "maxsize"):
@ -141,7 +131,6 @@ class MsgDecode(object):
self.body = msgObj.body self.body = msgObj.body
def decodeSimple(self, data): def decodeSimple(self, data):
"""Handle simple encoding"""
bodyPositionIndex = string.find(data, '\nBody:') bodyPositionIndex = string.find(data, '\nBody:')
if bodyPositionIndex > 1: if bodyPositionIndex > 1:
subject = data[8:bodyPositionIndex] subject = data[8:bodyPositionIndex]

View File

@ -2,17 +2,10 @@
import os import os
import random import random
from pyelliptic.openssl import OpenSSL from pyelliptic.openssl import OpenSSL
NoneType = type(None) NoneType = type(None)
def seed():
"""Initialize random number generator"""
random.seed()
def randomBytes(n): def randomBytes(n):
"""Method randomBytes.""" """Method randomBytes."""
try: try:
@ -58,6 +51,7 @@ def randomrandrange(x, y=None):
""" """
if isinstance(y, NoneType): if isinstance(y, NoneType):
return random.randrange(x) # nosec return random.randrange(x) # nosec
else:
return random.randrange(x, y) # nosec return random.randrange(x, y) # nosec

View File

@ -1,6 +1,6 @@
"""Additional SQL helper for searching messages""" #!/usr/bin/python2.7
from helper_sql import sqlQuery from helper_sql import *
try: try:
from PyQt4 import QtGui from PyQt4 import QtGui
@ -8,17 +8,13 @@ try:
except ImportError: except ImportError:
haveQt = False haveQt = False
def search_translate (context, text): def search_translate (context, text):
"""Translation wrapper"""
if haveQt: if haveQt:
return QtGui.QApplication.translate(context, text) return QtGui.QApplication.translate(context, text)
else:
return text.lower() return text.lower()
def search_sql(xAddress = "toaddress", account = None, folder = "inbox", where = None, what = None, unreadOnly = False): def search_sql(xAddress = "toaddress", account = None, folder = "inbox", where = None, what = None, unreadOnly = False):
"""Perform a search in mailbox tables"""
# pylint: disable=too-many-arguments, too-many-branches
if what is not None and what != "": if what is not None and what != "":
what = "%" + what + "%" what = "%" + what + "%"
if where == search_translate("MainWindow", "To"): if where == search_translate("MainWindow", "To"):
@ -66,16 +62,13 @@ def search_sql(xAddress="toaddress", account=None, folder="inbox", where=None, w
sqlArguments.append(what) sqlArguments.append(what)
if unreadOnly: if unreadOnly:
sqlStatementParts.append("read = 0") sqlStatementParts.append("read = 0")
if sqlStatementParts: if len(sqlStatementParts) > 0:
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): 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)"""
# pylint: disable=too-many-arguments
if what is not None and what != "": if what is not None and what != "":
if where in (search_translate("MainWindow", "To"), search_translate("MainWindow", "All")): if where in (search_translate("MainWindow", "To"), search_translate("MainWindow", "All")):
if what.lower() not in toAddress.lower(): if what.lower() not in toAddress.lower():

View File

@ -1,15 +1,4 @@
""" from helper_sql import *
Insert values into sent table
"""
import uuid
from helper_sql import sqlExecute
def insert(t): def insert(t):
"""Perform an insert into the `sent` table"""
msgid = uuid.uuid4().bytes
temp = list(t)
temp[0] = msgid
t = tuple(temp)
sqlExecute('''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t) sqlExecute('''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t)

View File

@ -1,39 +1,17 @@
""" """Helper Sql performs sql operations."""
SQL-related functions defined here are really pass the queries (or other SQL
commands) to :class:`.threads.sqlThread` through `sqlSubmitQueue` queue and check
or return the result got from `sqlReturnQueue`.
This is done that way because :mod:`sqlite3` is so thread-unsafe that they
won't even let you call it from different threads using your own locks.
SQLite objects can only be used from one thread.
.. note:: This actually only applies for certain deployments, and/or
really old version of sqlite. I haven't actually seen it anywhere.
Current versions do have support for threading and multiprocessing.
I don't see an urgent reason to refactor this, but it should be noted
in the comment that the problem is mostly not valid. Sadly, last time
I checked, there is no reliable way to check whether the library is
or isn't thread-safe.
"""
import Queue
import threading import threading
import Queue
sqlSubmitQueue = Queue.Queue() sqlSubmitQueue = Queue.Queue()
"""the queue for SQL""" # SQLITE3 is so thread-unsafe that they won't even let you call it from different threads using your own locks.
# SQL objects #can only be called from one thread.
sqlReturnQueue = Queue.Queue() sqlReturnQueue = Queue.Queue()
"""the queue for results"""
sqlLock = threading.Lock() sqlLock = threading.Lock()
def sqlQuery(sqlStatement, *args): def sqlQuery(sqlStatement, *args):
""" """SQLLITE execute statement and return query."""
Query sqlite and return results
:param str sqlStatement: SQL statement string
:param list args: SQL query parameters
:rtype: list
"""
sqlLock.acquire() sqlLock.acquire()
sqlSubmitQueue.put(sqlStatement) sqlSubmitQueue.put(sqlStatement)
@ -50,7 +28,6 @@ def sqlQuery(sqlStatement, *args):
def sqlExecuteChunked(sqlStatement, idCount, *args): def sqlExecuteChunked(sqlStatement, idCount, *args):
"""Execute chunked SQL statement to avoid argument limit"""
# SQLITE_MAX_VARIABLE_NUMBER, # SQLITE_MAX_VARIABLE_NUMBER,
# unfortunately getting/setting isn't exposed to python # unfortunately getting/setting isn't exposed to python
sqlExecuteChunked.chunkSize = 999 sqlExecuteChunked.chunkSize = 999
@ -81,7 +58,6 @@ def sqlExecuteChunked(sqlStatement, idCount, *args):
def sqlExecute(sqlStatement, *args): def sqlExecute(sqlStatement, *args):
"""Execute SQL statement (optionally with arguments)"""
sqlLock.acquire() sqlLock.acquire()
sqlSubmitQueue.put(sqlStatement) sqlSubmitQueue.put(sqlStatement)
@ -94,15 +70,13 @@ def sqlExecute(sqlStatement, *args):
sqlLock.release() sqlLock.release()
return rowcount return rowcount
def sqlStoredProcedure(procName): def sqlStoredProcedure(procName):
"""Schedule procName to be run"""
sqlLock.acquire() sqlLock.acquire()
sqlSubmitQueue.put(procName) sqlSubmitQueue.put(procName)
sqlLock.release() sqlLock.release()
class SqlBulkExecute(object): class SqlBulkExecute:
"""This is used when you have to execute the same statement in a cycle.""" """This is used when you have to execute the same statement in a cycle."""
def __enter__(self): def __enter__(self):

View File

@ -1,13 +1,16 @@
""" """
Startup operations. src/helper_startup.py
=====================
Helper Start performs all the startup operations.
""" """
# pylint: disable=too-many-branches,too-many-statements # pylint: disable=too-many-branches,too-many-statements
from __future__ import print_function
import logging import ConfigParser
import os import os
import platform import platform
import sys import sys
import time
from distutils.version import StrictVersion from distutils.version import StrictVersion
import defaults import defaults
@ -16,37 +19,45 @@ import paths
import state import state
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
try:
from plugins.plugin import get_plugin
except ImportError:
get_plugin = None
logger = logging.getLogger('default')
# The user may de-select Portable Mode in the settings if they want # The user may de-select Portable Mode in the settings if they want
# the config files to stay in the application data folder. # the config files to stay in the application data folder.
StoreConfigFilesInSameDirectoryAsProgramByDefault = False StoreConfigFilesInSameDirectoryAsProgramByDefault = False
def _loadTrustedPeer():
try:
trustedPeer = BMConfigParser().get('bitmessagesettings', 'trustedpeer')
except ConfigParser.Error:
# This probably means the trusted peer wasn't specified so we
# can just leave it as None
return
try:
host, port = trustedPeer.split(':')
except ValueError:
sys.exit(
'Bad trustedpeer config setting! It should be set as'
' trustedpeer=<hostname>:<portnumber>'
)
state.trustedPeer = state.Peer(host, int(port))
def loadConfig(): def loadConfig():
"""Load the config""" """Load the config"""
config = BMConfigParser() config = BMConfigParser()
if state.appdata: if state.appdata:
config.read(state.appdata + 'keys.dat') config.read(state.appdata + 'keys.dat')
# state.appdata must have been specified as a startup option. # state.appdata must have been specified as a startup option.
needToCreateKeysFile = config.safeGet( needToCreateKeysFile = config.safeGet(
'bitmessagesettings', 'settingsversion') is None 'bitmessagesettings', 'settingsversion') is None
if not needToCreateKeysFile: if not needToCreateKeysFile:
logger.info( print(
'Loading config files from directory specified' 'Loading config files from directory specified'
' on startup: %s', state.appdata) ' on startup: %s' % state.appdata)
else: else:
config.read(paths.lookupExeFolder() + 'keys.dat') config.read(paths.lookupExeFolder() + 'keys.dat')
try: try:
config.get('bitmessagesettings', 'settingsversion') config.get('bitmessagesettings', 'settingsversion')
logger.info('Loading config files from same directory as program.') print('Loading config files from same directory as program.')
needToCreateKeysFile = False needToCreateKeysFile = False
state.appdata = paths.lookupExeFolder() state.appdata = paths.lookupExeFolder()
except: except:
@ -57,8 +68,7 @@ def loadConfig():
needToCreateKeysFile = config.safeGet( needToCreateKeysFile = config.safeGet(
'bitmessagesettings', 'settingsversion') is None 'bitmessagesettings', 'settingsversion') is None
if not needToCreateKeysFile: if not needToCreateKeysFile:
logger.info( print('Loading existing config files from', state.appdata)
'Loading existing config files from %s', state.appdata)
if needToCreateKeysFile: if needToCreateKeysFile:
@ -113,10 +123,9 @@ def loadConfig():
# Just use the same directory as the program and forget about # Just use the same directory as the program and forget about
# the appdata folder # the appdata folder
state.appdata = '' state.appdata = ''
logger.info( print('Creating new config files in same directory as program.')
'Creating new config files in same directory as program.')
else: else:
logger.info('Creating new config files in %s', state.appdata) print('Creating new config files in', state.appdata)
if not os.path.exists(state.appdata): if not os.path.exists(state.appdata):
os.makedirs(state.appdata) os.makedirs(state.appdata)
if not sys.platform.startswith('win'): if not sys.platform.startswith('win'):
@ -125,6 +134,8 @@ def loadConfig():
else: else:
updateConfig() updateConfig()
_loadTrustedPeer()
def updateConfig(): def updateConfig():
"""Save the config""" """Save the config"""
@ -266,7 +277,7 @@ def updateConfig():
'bitmessagesettings', 'hidetrayconnectionnotifications', 'false') 'bitmessagesettings', 'hidetrayconnectionnotifications', 'false')
if config.safeGetInt('bitmessagesettings', 'maxoutboundconnections') < 1: if config.safeGetInt('bitmessagesettings', 'maxoutboundconnections') < 1:
config.set('bitmessagesettings', 'maxoutboundconnections', '8') config.set('bitmessagesettings', 'maxoutboundconnections', '8')
logger.warning('Your maximum outbound connections must be a number.') print('WARNING: your maximum outbound connections must be a number.')
# TTL is now user-specifiable. Let's add an option to save # TTL is now user-specifiable. Let's add an option to save
# whatever the user selects. # whatever the user selects.
@ -289,26 +300,3 @@ def isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections():
return False return False
except Exception: except Exception:
pass pass
def start_proxyconfig():
"""Check socksproxytype and start any proxy configuration plugin"""
if not get_plugin:
return
config = BMConfigParser()
proxy_type = config.safeGet('bitmessagesettings', 'socksproxytype')
if proxy_type and proxy_type not in ('none', 'SOCKS4a', 'SOCKS5'):
try:
proxyconfig_start = time.time()
if not get_plugin('proxyconfig', name=proxy_type)(config):
raise TypeError()
except TypeError:
# cannot import shutdown here ):
logger.error(
'Failed to run proxy config plugin %s',
proxy_type, exc_info=True)
os._exit(0) # pylint: disable=protected-access
else:
logger.info(
'Started proxy config plugin %s in %s sec',
proxy_type, time.time() - proxyconfig_start)

46
src/helper_threading.py Normal file
View File

@ -0,0 +1,46 @@
"""Helper threading perform all the threading operations."""
from contextlib import contextmanager
import threading
try:
import prctl
except ImportError:
def set_thread_name(name):
"""Set the thread name for external use (visible from the OS)."""
threading.current_thread().name = name
else:
def set_thread_name(name):
"""Set a name for the thread for python internal use."""
prctl.set_name(name)
def _thread_name_hack(self):
set_thread_name(self.name)
threading.Thread.__bootstrap_original__(self)
threading.Thread.__bootstrap_original__ = threading.Thread._Thread__bootstrap
threading.Thread._Thread__bootstrap = _thread_name_hack
class StoppableThread(object):
def initStop(self):
self.stop = threading.Event()
self._stopped = False
def stopThread(self):
self._stopped = True
self.stop.set()
class BusyError(threading.ThreadError):
pass
@contextmanager
def nonBlocking(lock):
locked = lock.acquire(False)
if not locked:
raise BusyError
try:
yield
finally:
lock.release()

View File

@ -1,10 +1,6 @@
""" """
High level cryptographic functions based on `.pyelliptic` OpenSSL bindings. src/highlevelcrypto.py
======================
.. note::
Upstream pyelliptic was upgraded from SHA1 to SHA256 for signing.
We must upgrade PyBitmessage gracefully.
`More discussion. <https://github.com/yann2192/pyelliptic/issues/32>`_
""" """
from binascii import hexlify from binascii import hexlify
@ -16,13 +12,12 @@ from pyelliptic import arithmetic as a
def makeCryptor(privkey): def makeCryptor(privkey):
"""Return a private `.pyelliptic.ECC` instance""" """Return a private pyelliptic.ECC() instance"""
private_key = a.changebase(privkey, 16, 256, minlen=32) private_key = a.changebase(privkey, 16, 256, minlen=32)
public_key = pointMult(private_key) public_key = pointMult(private_key)
privkey_bin = '\x02\xca\x00\x20' + private_key privkey_bin = '\x02\xca\x00\x20' + private_key
pubkey_bin = '\x02\xca\x00\x20' + public_key[1:-32] + '\x00\x20' + public_key[-32:] pubkey_bin = '\x02\xca\x00\x20' + public_key[1:-32] + '\x00\x20' + public_key[-32:]
cryptor = pyelliptic.ECC( cryptor = pyelliptic.ECC(curve='secp256k1', privkey=privkey_bin, pubkey=pubkey_bin)
curve='secp256k1', privkey=privkey_bin, pubkey=pubkey_bin)
return cryptor return cryptor
@ -34,7 +29,7 @@ def hexToPubkey(pubkey):
def makePubCryptor(pubkey): def makePubCryptor(pubkey):
"""Return a public `.pyelliptic.ECC` instance""" """Return a public pyelliptic.ECC() instance"""
pubkey_bin = hexToPubkey(pubkey) pubkey_bin = hexToPubkey(pubkey)
return pyelliptic.ECC(curve='secp256k1', pubkey=pubkey_bin) return pyelliptic.ECC(curve='secp256k1', pubkey=pubkey_bin)
@ -48,8 +43,7 @@ def privToPub(privkey):
def encrypt(msg, hexPubkey): def encrypt(msg, hexPubkey):
"""Encrypts message with hex public key""" """Encrypts message with hex public key"""
return pyelliptic.ECC(curve='secp256k1').encrypt( return pyelliptic.ECC(curve='secp256k1').encrypt(msg, hexToPubkey(hexPubkey))
msg, hexToPubkey(hexPubkey))
def decrypt(msg, hexPrivkey): def decrypt(msg, hexPrivkey):
@ -58,38 +52,36 @@ def decrypt(msg, hexPrivkey):
def decryptFast(msg, cryptor): def decryptFast(msg, cryptor):
"""Decrypts message with an existing `.pyelliptic.ECC` object""" """Decrypts message with an existing pyelliptic.ECC.ECC object"""
return cryptor.decrypt(msg) return cryptor.decrypt(msg)
def sign(msg, hexPrivkey): def sign(msg, hexPrivkey):
""" """Signs with hex private key"""
Signs with hex private key using SHA1 or SHA256 depending on # pyelliptic is upgrading from SHA1 to SHA256 for signing. We must
"digestalg" setting # upgrade PyBitmessage gracefully.
""" # https://github.com/yann2192/pyelliptic/pull/33
digestAlg = BMConfigParser().safeGet( # More discussion: https://github.com/yann2192/pyelliptic/issues/32
'bitmessagesettings', 'digestalg', 'sha1') digestAlg = BMConfigParser().safeGet('bitmessagesettings', 'digestalg', 'sha1')
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(msg, digest_alg=OpenSSL.digest_ecdsa_sha1)
msg, digest_alg=OpenSSL.digest_ecdsa_sha1)
elif digestAlg == "sha256": elif digestAlg == "sha256":
# SHA256. Eventually this will become the default # SHA256. Eventually this will become the default
return makeCryptor(hexPrivkey).sign(msg, digest_alg=OpenSSL.EVP_sha256) return makeCryptor(hexPrivkey).sign(msg, digest_alg=OpenSSL.EVP_sha256)
else: else:
raise ValueError("Unknown digest algorithm %s" % digestAlg) raise ValueError("Unknown digest algorithm %s" % (digestAlg))
def verify(msg, sig, hexPubkey): def verify(msg, sig, hexPubkey):
"""Verifies with hex public key using SHA1 or SHA256""" """Verifies with hex public key"""
# As mentioned above, we must upgrade gracefully to use SHA256. So # As mentioned above, we must upgrade gracefully to use SHA256. So
# let us check the signature using both SHA1 and SHA256 and if one # let us check the signature using both SHA1 and SHA256 and if one
# of them passes then we will be satisfied. Eventually this can # of them passes then we will be satisfied. Eventually this can
# be simplified and we'll only check with SHA256. # be simplified and we'll only check with SHA256.
try: try:
# old SHA1 algorithm. # old SHA1 algorithm.
sigVerifyPassed = makePubCryptor(hexPubkey).verify( sigVerifyPassed = makePubCryptor(hexPubkey).verify(sig, msg, digest_alg=OpenSSL.digest_ecdsa_sha1)
sig, msg, digest_alg=OpenSSL.digest_ecdsa_sha1)
except: except:
sigVerifyPassed = False sigVerifyPassed = False
if sigVerifyPassed: if sigVerifyPassed:
@ -97,8 +89,7 @@ def verify(msg, sig, hexPubkey):
return True return True
# The signature check using SHA1 failed. Let us try it with SHA256. # The signature check using SHA1 failed. Let us try it with SHA256.
try: try:
return makePubCryptor(hexPubkey).verify( return makePubCryptor(hexPubkey).verify(sig, msg, digest_alg=OpenSSL.EVP_sha256)
sig, msg, digest_alg=OpenSSL.EVP_sha256)
except: except:
return False return False
@ -109,14 +100,13 @@ def pointMult(secret):
Evidently, this type of error can occur very rarely: Evidently, this type of error can occur very rarely:
>>> File "highlevelcrypto.py", line 54, in pointMult File "highlevelcrypto.py", line 54, in pointMult
>>> group = OpenSSL.EC_KEY_get0_group(k) group = OpenSSL.EC_KEY_get0_group(k)
>>> WindowsError: exception: access violation reading 0x0000000000000008 WindowsError: exception: access violation reading 0x0000000000000008
""" """
while True: while True:
try: try:
k = OpenSSL.EC_KEY_new_by_curve_name( k = OpenSSL.EC_KEY_new_by_curve_name(OpenSSL.get_curve('secp256k1'))
OpenSSL.get_curve('secp256k1'))
priv_key = OpenSSL.BN_bin2bn(secret, 32, None) priv_key = OpenSSL.BN_bin2bn(secret, 32, None)
group = OpenSSL.EC_KEY_get0_group(k) group = OpenSSL.EC_KEY_get0_group(k)
pub_key = OpenSSL.EC_POINT_new(group) pub_key = OpenSSL.EC_POINT_new(group)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 704 B

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Some files were not shown because too many files have changed in this diff Show More