Compare commits
139 Commits
f1d8ce105c
...
next_gen
Author | SHA1 | Date | |
---|---|---|---|
62c6dbfb34 | |||
cf4cfa979c | |||
ae4eae92ae | |||
ad3bbb5e45 | |||
02b2d07b6d | |||
9f7de204d4 | |||
9a58082496 | |||
5e788a543d | |||
a4ceeccfd8 | |||
ee994973db | |||
6e07d3e3d4 | |||
531fa81bba | |||
0f9aa4f515 | |||
ce19efe340 | |||
c0a34d3e14 | |||
0ee8a0ec21 | |||
85ea9ab6e8 | |||
4ecf666b2f | |||
318c9c942d | |||
1a0bd9deee | |||
741adcdf18 | |||
37541db07d | |||
33052f8a98 | |||
8f9b573253 | |||
9f702339dd | |||
bc9dfd1bc4 | |||
5f56d630ce | |||
25de4fa2ef | |||
c7a83055b1 | |||
dd323e3cbb | |||
c66dcb0ca2 | |||
250551e752 | |||
f38df24947 | |||
10a77960dc | |||
603dfd40b5 | |||
184ba55aed | |||
1728a45cf3 | |||
3272617403 | |||
850c3b1ca3 | |||
27d24ecaf4 | |||
20f36e06ad | |||
5e1f060fac | |||
eba7e0c0dc | |||
5521b768bc | |||
e15620c3ad | |||
7e08be71e0 | |||
820b5a0253 | |||
6538cedcf2 | |||
329ab23f89 | |||
9c742d10de | |||
2a97beb5af | |||
7aac248bf9 | |||
d09609a5e5 | |||
e8193afedf | |||
bc48537209 | |||
0adb9c1e52 | |||
595c35a6b8 | |||
a0cae14727 | |||
04f0aef3df | |||
8411f08348 | |||
47c115e699 | |||
b2ecf5314e | |||
8809ef1f6e | |||
41de315496 | |||
56731be79d | |||
1c80b4fd7d | |||
fa3529f5f2 | |||
74a5f95a56 | |||
03e2fa4cb8 | |||
423bda93c6 | |||
238f7e367a | |||
13b2d17786 | |||
370716015b | |||
439ce30e6e | |||
486c13a3d3 | |||
c97fb6b467 | |||
eb9ab56c6e | |||
43302b0130 | |||
0a9939f33b | |||
c6b67452ed | |||
b8fa8df41a | |||
02af0f7671 | |||
dcc3a3dcfa | |||
f67de1ba91 | |||
77bdabb993 | |||
206c5c4905 | |||
6495aa9920 | |||
b591ac13ba | |||
a935d602f8 | |||
ef4a1b18fd | |||
eed31bf61b | |||
dfe7601dc1 | |||
acf75a6818 | |||
88786b0398 | |||
a575312167 | |||
42049d6a44 | |||
ec5bcbddec | |||
e8a0a3f5be | |||
bde69bd417 | |||
1b8241eee9 | |||
a3103f6fb9 | |||
9365ca2913 | |||
bfa91df927 | |||
0b1e899931 | |||
bcefe9bc79 | |||
9294c3e779 | |||
a96f6d2928 | |||
c0a143c817 | |||
f3aa0aeda3 | |||
bfd2a92dde | |||
7209dfae72 | |||
2883ce5c4c | |||
eef02a1173 | |||
f1c63bb4e8 | |||
98dbe6a493 | |||
e21a9355e7 | |||
c6192de9dd | |||
7898363dcb | |||
25dbb85ef0 | |||
729bd84d2b | |||
ae903cf405 | |||
c8443b56dd | |||
ad351030d9 | |||
6ebafbda44 | |||
ddf6cd8328 | |||
c81d9a3696 | |||
5ebfa702ec | |||
e9272eee2a | |||
a9d2d3d809 | |||
68328d9846 | |||
dec4990d32 | |||
0ba1aadf70 | |||
8a2665ed4d | |||
91d3f885c0 | |||
85467e1885 | |||
1bead7d55d | |||
20bb694c7e | |||
593e25efe5 | |||
2de4eea357 |
38
README.md
@ -2,7 +2,13 @@
|
|||||||
|
|
||||||
Toxygen is powerful cross-platform [Tox](https://tox.chat/) client written in pure Python3.
|
Toxygen is powerful cross-platform [Tox](https://tox.chat/) client written in pure Python3.
|
||||||
|
|
||||||
### [Install](/docs/install.md) - [Contribute](/docs/contributing.md) - [Plugins](/docs/plugins.md) - [Compile](/docs/compile.md) - [Contact](/docs/contact.md)
|
[](https://github.com/toxygen-project/toxygen/releases/latest)
|
||||||
|
[](https://github.com/toxygen-project/toxygen/stargazers)
|
||||||
|
[](https://github.com/toxygen-project/toxygen/issues)
|
||||||
|
[](https://raw.githubusercontent.com/toxygen-project/toxygen/master/LICENSE.md)
|
||||||
|
[](https://travis-ci.org/toxygen-project/toxygen)
|
||||||
|
|
||||||
|
### [Install](/docs/install.md) - [Contribute](/docs/contributing.md) - [Plugins](/docs/plugins.md) - [Compile](/docs/compile.md) - [Contact](/docs/contact.md) - [Updater](https://github.com/toxygen-project/toxygen_updater)
|
||||||
|
|
||||||
### Supported OS: Linux and Windows
|
### Supported OS: Linux and Windows
|
||||||
|
|
||||||
@ -37,30 +43,22 @@ Toxygen is powerful cross-platform [Tox](https://tox.chat/) client written in pu
|
|||||||
- Changing nospam
|
- Changing nospam
|
||||||
- File resuming
|
- File resuming
|
||||||
- Read receipts
|
- Read receipts
|
||||||
- NGC groups
|
|
||||||
|
### Downloads
|
||||||
|
[Releases](https://github.com/toxygen-project/toxygen/releases)
|
||||||
|
|
||||||
|
[Download last stable version](https://github.com/toxygen-project/toxygen/archive/master.zip)
|
||||||
|
|
||||||
|
[Download develop version](https://github.com/toxygen-project/toxygen/archive/develop.zip)
|
||||||
|
|
||||||
### Screenshots
|
### Screenshots
|
||||||
*Toxygen on Ubuntu and Windows*
|
*Toxygen on Ubuntu and Windows*
|
||||||

|

|
||||||

|

|
||||||
|
|
||||||
## Forked
|
### Docs
|
||||||
|
[Check /docs/ for more info](/docs/)
|
||||||
|
|
||||||
This hard-forked from https://github.com/toxygen-project/toxygen
|
Also visit [pythonhosted.org/Toxygen/](http://pythonhosted.org/Toxygen/)
|
||||||
```next_gen``` branch.
|
|
||||||
|
|
||||||
https://git.plastiras.org/emdee/toxygen_wrapper needs packaging
|
|
||||||
is making a dependency. Just download it and copy the two directories
|
|
||||||
```wrapper``` and ```wrapper_tests``` into ```toxygen/toxygen```.
|
|
||||||
|
|
||||||
See ToDo.md to the current ToDo list.
|
[Wiki](https://wiki.tox.chat/clients/toxygen)
|
||||||
|
|
||||||
If you install https://github.com/weechat/qweechat
|
|
||||||
you can have IRC and jabber in a window too. Start
|
|
||||||
[weechat](https://github.com/weechat/weechat) and
|
|
||||||
```
|
|
||||||
/relay weechat 9000 password
|
|
||||||
```
|
|
||||||
|
|
||||||
Work on this project is suspended until the
|
|
||||||
[MultiDevice](https://git.plastiras.org/emdee/tox_profile/wiki/MultiDevice-Announcements-POC) problem is solved. Fork me!
|
|
||||||
|
52
ToDo.md
@ -1,52 +0,0 @@
|
|||||||
# Toxygen ToDo List
|
|
||||||
|
|
||||||
## Bugs
|
|
||||||
|
|
||||||
1. There is an agravating bug where new messages are not put in the
|
|
||||||
current window, and a messages waiting indicator appears. You have
|
|
||||||
to focus out of the window and then back in the window.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Fix history
|
|
||||||
|
|
||||||
The code is in there but it's not working.
|
|
||||||
|
|
||||||
## Fix Audio
|
|
||||||
|
|
||||||
The code is in there but it's not working. It looks like audio input
|
|
||||||
is working but not output. The code is all in there; I may have broken
|
|
||||||
it trying to wire up the ability to set the audio device from the
|
|
||||||
command line.
|
|
||||||
|
|
||||||
## Fix Video
|
|
||||||
|
|
||||||
The code is in there but it's not working. I may have broken it
|
|
||||||
trying to wire up the ability to set the video device from the command
|
|
||||||
line.
|
|
||||||
|
|
||||||
## Groups
|
|
||||||
|
|
||||||
1. peer_id There has been a change of API on a field named
|
|
||||||
```group.peer_id``` The code is broken in places because I have not
|
|
||||||
seen the path to change from the old API ro the new one.
|
|
||||||
|
|
||||||
|
|
||||||
## Plugin system
|
|
||||||
|
|
||||||
1. Needs better documentation and checking.
|
|
||||||
|
|
||||||
2. There's something broken in the way some of them plug into Qt menus.
|
|
||||||
|
|
||||||
3. Should the plugins be in toxygen or a separate repo?
|
|
||||||
|
|
||||||
4. There needs to be a uniform way for plugins to wire into callbacks.
|
|
||||||
|
|
||||||
## check toxygen_wrapper
|
|
||||||
|
|
||||||
1. I've broken out toxygen_wrapper to be standalone,
|
|
||||||
https://git.plastiras.org/emdee/toxygen_wrapper but the tox.py
|
|
||||||
needs each call double checking.
|
|
||||||
|
|
||||||
2. https://git.plastiras.org/emdee/toxygen_wrapper needs packaging
|
|
||||||
and making a dependency.
|
|
@ -1,6 +1,5 @@
|
|||||||
# Contact us:
|
# Contact us:
|
||||||
|
|
||||||
1) https://git.plastiras.org/emdee/toxygen/issues
|
1) Using GitHub - open issue
|
||||||
|
|
||||||
2) Use Toxygen Tox Group (NGC) -
|
2) Use Toxygen Tox Group (NGC) - ID: 59D68B2709E81A679CF91416CB0E3692851C6CFCABEFF98B7131E3805A6D75FA
|
||||||
ID: 59D68B2709E81A679CF91416CB0E3692851C6CFCABEFF98B7131E3805A6D75FA
|
|
||||||
|
@ -7,15 +7,12 @@ Help us find all bugs in Toxygen! Please provide following info:
|
|||||||
- Toxygen executable info - python executable (.py), precompiled binary, from package etc.
|
- Toxygen executable info - python executable (.py), precompiled binary, from package etc.
|
||||||
- Steps to reproduce the bug
|
- Steps to reproduce the bug
|
||||||
|
|
||||||
Want to see new feature in Toxygen?
|
Want to see new feature in Toxygen? [Ask for it!](https://github.com/toxygen-project/toxygen/issues)
|
||||||
[Ask for it!](https://git.plastiras.org/emdee/toxygen/issues)
|
|
||||||
|
|
||||||
# Pull requests
|
# Pull requests
|
||||||
|
|
||||||
Developer? Feel free to open pull request. Our dev team is small so we glad to get help.
|
Developer? Feel free to open pull request. Our dev team is small so we glad to get help.
|
||||||
Don't know what to do? Improve UI, fix
|
Don't know what to do? Improve UI, fix [issues](https://github.com/toxygen-project/toxygen/issues) or implement features from our TODO list.
|
||||||
[issues](https://git.plastiras.org/emdee/toxygen/issues)
|
|
||||||
or implement features from our TODO list.
|
|
||||||
You can find our TODO's in code, issues list and [here](/README.md). Also you can implement [plugins](/docs/plugins.md) for Toxygen.
|
You can find our TODO's in code, issues list and [here](/README.md). Also you can implement [plugins](/docs/plugins.md) for Toxygen.
|
||||||
|
|
||||||
Note that we have a lot of branches for different purposes. Master branch is for stable versions (releases) only, so I recommend to open PR's to develop branch. Development of next Toxygen version usually goes there. Other branches used for implementing different tasks such as file transfers improvements or audio calls implementation etc.
|
Note that we have a lot of branches for different purposes. Master branch is for stable versions (releases) only, so I recommend to open PR's to develop branch. Development of next Toxygen version usually goes there. Other branches used for implementing different tasks such as file transfers improvements or audio calls implementation etc.
|
||||||
|
@ -1,15 +1,33 @@
|
|||||||
# How to install Toxygen
|
# How to install Toxygen
|
||||||
|
|
||||||
|
## Use precompiled binary (recommended for users):
|
||||||
|
[Check our releases page](https://github.com/toxygen-project/toxygen/releases)
|
||||||
|
|
||||||
|
## Using pip3
|
||||||
|
|
||||||
|
### Windows
|
||||||
|
|
||||||
|
``pip install toxygen``
|
||||||
|
|
||||||
|
Run app using ``toxygen`` command.
|
||||||
|
|
||||||
### Linux
|
### Linux
|
||||||
|
|
||||||
1. Install [c-toxcore](https://github.com/TokTok/c-toxcore/)
|
1. Install [toxcore](https://github.com/irungentoo/toxcore/blob/master/INSTALL.md) with toxav support in your system (install in /usr/lib/)
|
||||||
2. Install PortAudio:
|
2. Install PortAudio:
|
||||||
``sudo apt-get install portaudio19-dev``
|
``sudo apt-get install portaudio19-dev``
|
||||||
3. For 32-bit Linux install PyQt5: ``sudo apt-get install python3-pyqt5``
|
3. For 32-bit Linux install PyQt5: ``sudo apt-get install python3-pyqt5``
|
||||||
4. Install [OpenCV](http://docs.opencv.org/trunk/d7/d9f/tutorial_linux_install.html) or via ``sudo pip3 install opencv-python``
|
4. Install [OpenCV](http://docs.opencv.org/trunk/d7/d9f/tutorial_linux_install.html) or via ``sudo pip3 install opencv-python``
|
||||||
5. Install [toxygen](https://git.plastiras.org/emdee/toxygen/)
|
5. Install toxygen:
|
||||||
|
``sudo pip3 install toxygen``
|
||||||
6. Run toxygen using ``toxygen`` command.
|
6. Run toxygen using ``toxygen`` command.
|
||||||
|
|
||||||
|
## Packages
|
||||||
|
|
||||||
|
Arch Linux: [AUR](https://aur.archlinux.org/packages/toxygen-git/)
|
||||||
|
|
||||||
|
Debian/Ubuntu: [tox.chat](https://tox.chat/download.html#gnulinux)
|
||||||
|
|
||||||
## From source code (recommended for developers)
|
## From source code (recommended for developers)
|
||||||
|
|
||||||
### Windows
|
### Windows
|
||||||
@ -26,17 +44,27 @@ Note: 32-bit Python isn't supported due to bug with videocalls. It is strictly r
|
|||||||
8. Download latest libtox.dll build, download latest libsodium.a build, put it into \toxygen\libs\
|
8. Download latest libtox.dll build, download latest libsodium.a build, put it into \toxygen\libs\
|
||||||
9. Run \toxygen\main.py.
|
9. Run \toxygen\main.py.
|
||||||
|
|
||||||
|
Optional: install toxygen using setup.py: ``python setup.py install``
|
||||||
|
|
||||||
|
[libtox.dll for 32-bit Python](https://build.tox.chat/view/libtoxcore/job/libtoxcore_build_windows_x86_shared_release/lastSuccessfulBuild/artifact/libtoxcore_build_windows_x86_shared_release.zip)
|
||||||
|
|
||||||
|
[libtox.dll for 64-bit Python](https://build.tox.chat/view/libtoxcore/job/libtoxcore_build_windows_x86-64_shared_release/lastSuccessfulBuild/artifact/libtoxcore_build_windows_x86-64_shared_release.zip)
|
||||||
|
|
||||||
|
[libsodium.a for 32-bit Python](https://build.tox.chat/view/libsodium/job/libsodium_build_windows_x86_static_release/lastSuccessfulBuild/artifact/libsodium_build_windows_x86_static_release.zip)
|
||||||
|
|
||||||
|
[libsodium.a for 64-bit Python](https://build.tox.chat/view/libsodium/job/libsodium_build_windows_x86-64_static_release/lastSuccessfulBuild/artifact/libsodium_build_windows_x86-64_static_release.zip)
|
||||||
|
|
||||||
### Linux
|
### Linux
|
||||||
|
|
||||||
1. Install latest Python3:
|
1. Install latest Python3:
|
||||||
``sudo apt-get install python3``
|
``sudo apt-get install python3``
|
||||||
2. Install PyQt5: ``sudo apt-get install python3-pyqt5`` or ``sudo pip3 install pyqt5``
|
2. Install PyQt5: ``sudo apt-get install python3-pyqt5`` or ``sudo pip3 install pyqt5``
|
||||||
3. Install [toxcore](https://github.com/TokTok/c-toxcore) with toxav support)
|
3. Install [toxcore](https://github.com/irungentoo/toxcore/blob/master/INSTALL.md) with toxav support in your system (install in /usr/lib/)
|
||||||
4. Install PyAudio:
|
4. Install PyAudio:
|
||||||
``sudo apt-get install portaudio19-dev`` and ``sudo apt-get install python3-pyaudio`` (or ``sudo pip3 install pyaudio``)
|
``sudo apt-get install portaudio19-dev`` and ``sudo apt-get install python3-pyaudio`` (or ``sudo pip3 install pyaudio``)
|
||||||
5. Install NumPy: ``sudo pip3 install numpy``
|
5. Install NumPy: ``sudo pip3 install numpy``
|
||||||
6. Install [OpenCV](http://docs.opencv.org/trunk/d7/d9f/tutorial_linux_install.html) or via ``sudo pip3 install opencv-python``
|
6. Install [OpenCV](http://docs.opencv.org/trunk/d7/d9f/tutorial_linux_install.html) or via ``sudo pip3 install opencv-python``
|
||||||
7. [Download toxygen](https://git.plastiras.org/emdee/toxygen/)
|
7. [Download toxygen](https://github.com/toxygen-project/toxygen/archive/master.zip)
|
||||||
8. Unpack archive
|
8. Unpack archive
|
||||||
9. Run app:
|
9. Run app:
|
||||||
``python3 main.py``
|
``python3 main.py``
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Plugins API
|
# Plugins API
|
||||||
|
|
||||||
In Toxygen plugin is single python module (.py file) and directory with data associated with it.
|
In Toxygen plugin is single python (supported Python 3.4 - 3.6) module (.py file) and directory with data associated with it.
|
||||||
Every module must contain one class derived from PluginSuperClass defined in [plugin_super_class.py](/src/plugins/plugin_super_class.py). Instance of this class will be created by PluginLoader class (defined in [plugin_support.py](/src/plugin_support.py) ). This class can enable/disable plugins and send data to it.
|
Every module must contain one class derived from PluginSuperClass defined in [plugin_super_class.py](/src/plugins/plugin_super_class.py). Instance of this class will be created by PluginLoader class (defined in [plugin_support.py](/src/plugin_support.py) ). This class can enable/disable plugins and send data to it.
|
||||||
|
|
||||||
Every plugin has its own full name and unique short name (1-5 symbols). Main app can get it using special methods.
|
Every plugin has its own full name and unique short name (1-5 symbols). Main app can get it using special methods.
|
||||||
|
BIN
docs/ubuntu.png
Normal file → Executable file
Before Width: | Height: | Size: 107 KiB After Width: | Height: | Size: 109 KiB |
BIN
docs/windows.png
Normal file → Executable file
Before Width: | Height: | Size: 71 KiB After Width: | Height: | Size: 81 KiB |
32
setup.py
@ -12,14 +12,17 @@ version = main.__version__ + '.0'
|
|||||||
|
|
||||||
|
|
||||||
if system() == 'Windows':
|
if system() == 'Windows':
|
||||||
MODULES = ['PyQt5', 'PyAudio', 'numpy', 'opencv-python', 'pydenticon', 'cv2']
|
MODULES = ['PyQt5', 'PyAudio', 'numpy', 'opencv-python', 'pydenticon']
|
||||||
else:
|
else:
|
||||||
MODULES = ['pydenticon']
|
MODULES = []
|
||||||
MODULES.append('PyQt5')
|
|
||||||
try:
|
try:
|
||||||
import pyaudio
|
import pyaudio
|
||||||
except ImportError:
|
except ImportError:
|
||||||
MODULES.append('PyAudio')
|
MODULES.append('PyAudio')
|
||||||
|
try:
|
||||||
|
import PyQt5
|
||||||
|
except ImportError:
|
||||||
|
MODULES.append('PyQt5')
|
||||||
try:
|
try:
|
||||||
import numpy
|
import numpy
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -29,13 +32,9 @@ else:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
MODULES.append('opencv-python')
|
MODULES.append('opencv-python')
|
||||||
try:
|
try:
|
||||||
import coloredlogs
|
import pydenticon
|
||||||
except ImportError:
|
except ImportError:
|
||||||
MODULES.append('coloredlogs')
|
MODULES.append('pydenticon')
|
||||||
try:
|
|
||||||
import pyqtconsole
|
|
||||||
except ImportError:
|
|
||||||
MODULES.append('pyqtconsole')
|
|
||||||
|
|
||||||
|
|
||||||
def get_packages():
|
def get_packages():
|
||||||
@ -43,8 +42,10 @@ def get_packages():
|
|||||||
for root, dirs, files in os.walk(directory):
|
for root, dirs, files in os.walk(directory):
|
||||||
packages = map(lambda d: 'toxygen.' + d, dirs)
|
packages = map(lambda d: 'toxygen.' + d, dirs)
|
||||||
packages = ['toxygen'] + list(packages)
|
packages = ['toxygen'] + list(packages)
|
||||||
|
|
||||||
return packages
|
return packages
|
||||||
|
|
||||||
|
|
||||||
class InstallScript(install):
|
class InstallScript(install):
|
||||||
"""This class configures Toxygen after installation"""
|
"""This class configures Toxygen after installation"""
|
||||||
|
|
||||||
@ -71,23 +72,22 @@ setup(name='Toxygen',
|
|||||||
version=version,
|
version=version,
|
||||||
description='Toxygen - Tox client',
|
description='Toxygen - Tox client',
|
||||||
long_description='Toxygen is powerful Tox client written in Python3',
|
long_description='Toxygen is powerful Tox client written in Python3',
|
||||||
url='https://git.plastiras.org/emdee/toxygen/',
|
url='https://github.com/toxygen-project/toxygen/',
|
||||||
keywords='toxygen Tox messenger',
|
keywords='toxygen tox messenger',
|
||||||
author='Ingvar',
|
author='Ingvar',
|
||||||
maintainer='',
|
maintainer='Ingvar',
|
||||||
license='GPL3',
|
license='GPL3',
|
||||||
packages=get_packages(),
|
packages=get_packages(),
|
||||||
install_requires=MODULES,
|
install_requires=MODULES,
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
classifiers=[
|
classifiers=[
|
||||||
'Programming Language :: Python :: 3 :: Only',
|
'Programming Language :: Python :: 3 :: Only',
|
||||||
'Programming Language :: Python :: 3.9',
|
'Programming Language :: Python :: 3.5',
|
||||||
|
'Programming Language :: Python :: 3.6',
|
||||||
],
|
],
|
||||||
entry_points={
|
entry_points={
|
||||||
'console_scripts': ['toxygen=toxygen.main:main']
|
'console_scripts': ['toxygen=toxygen.main:main']
|
||||||
},
|
},
|
||||||
cmdclass={
|
cmdclass={
|
||||||
'install': InstallScript
|
'install': InstallScript
|
||||||
},
|
})
|
||||||
zip_safe=False
|
|
||||||
)
|
|
||||||
|
842
toxygen/app.py
@ -1,54 +1,21 @@
|
|||||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
|
||||||
import pyaudio
|
import pyaudio
|
||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
import itertools
|
|
||||||
|
|
||||||
from wrapper.toxav_enums import *
|
from wrapper.toxav_enums import *
|
||||||
|
import cv2
|
||||||
|
import itertools
|
||||||
|
import numpy as np
|
||||||
from av import screen_sharing
|
from av import screen_sharing
|
||||||
from av.call import Call
|
from av.call import Call
|
||||||
import common.tox_save
|
import common.tox_save
|
||||||
|
|
||||||
from utils import ui as util_ui
|
|
||||||
import wrapper_tests.support_testing as ts
|
|
||||||
from middleware.threads import invoke_in_main_thread
|
|
||||||
from main import sleep
|
|
||||||
from middleware.threads import BaseThread
|
|
||||||
|
|
||||||
global LOG
|
|
||||||
import logging
|
|
||||||
LOG = logging.getLogger('app.'+__name__)
|
|
||||||
# callbacks can be called in any thread so were being careful
|
|
||||||
def LOG_ERROR(l): print('EROR< '+l)
|
|
||||||
def LOG_WARN(l): print('WARN< '+l)
|
|
||||||
def LOG_INFO(l):
|
|
||||||
bIsVerbose = hasattr(__builtins__, 'app') and app.oArgs.loglevel <= 20-1
|
|
||||||
if bIsVerbose: print('INFO< '+l)
|
|
||||||
def LOG_DEBUG(l):
|
|
||||||
bIsVerbose = hasattr(__builtins__, 'app') and app.oArgs.loglevel <= 10-1
|
|
||||||
if bIsVerbose: print('DBUG< '+l)
|
|
||||||
def LOG_TRACE(l):
|
|
||||||
bIsVerbose = hasattr(__builtins__, 'app') and app.oArgs.loglevel < 10-1
|
|
||||||
pass # print('TRACE+ '+l)
|
|
||||||
|
|
||||||
TIMER_TIMEOUT = 30.0
|
|
||||||
bSTREAM_CALLBACK = False
|
|
||||||
iFPS = 25
|
|
||||||
|
|
||||||
class AV(common.tox_save.ToxAvSave):
|
class AV(common.tox_save.ToxAvSave):
|
||||||
|
|
||||||
def __init__(self, toxav, settings):
|
def __init__(self, toxav, settings):
|
||||||
super().__init__(toxav)
|
super().__init__(toxav)
|
||||||
self._toxav = toxav
|
|
||||||
self._settings = settings
|
self._settings = settings
|
||||||
self._running = True
|
self._running = True
|
||||||
s = settings
|
|
||||||
if 'video' not in s:
|
|
||||||
LOG.warn("AV.__init__ 'video' not in s" )
|
|
||||||
LOG.debug(f"AV.__init__ {s!r}" )
|
|
||||||
elif 'device' not in s['video']:
|
|
||||||
LOG.warn("AV.__init__ 'device' not in s.video" )
|
|
||||||
LOG.debug(f"AV.__init__ {s['video']!r}" )
|
|
||||||
|
|
||||||
self._calls = {} # dict: key - friend number, value - Call instance
|
self._calls = {} # dict: key - friend number, value - Call instance
|
||||||
|
|
||||||
@ -58,30 +25,17 @@ class AV(common.tox_save.ToxAvSave):
|
|||||||
self._audio_running = False
|
self._audio_running = False
|
||||||
self._out_stream = None
|
self._out_stream = None
|
||||||
|
|
||||||
|
self._audio_rate = 8000
|
||||||
self._audio_channels = 1
|
self._audio_channels = 1
|
||||||
self._audio_duration = 60
|
self._audio_duration = 60
|
||||||
self._audio_rate_pa = 48000
|
self._audio_sample_count = self._audio_rate * self._audio_channels * self._audio_duration // 1000
|
||||||
self._audio_rate_tox = 48000
|
|
||||||
self._audio_rate_pa = 48000
|
|
||||||
self._audio_krate_tox_audio = self._audio_rate_tox // 1000
|
|
||||||
self._audio_krate_tox_video = 5000
|
|
||||||
self._audio_sample_count_pa = self._audio_rate_pa * self._audio_channels * self._audio_duration // 1000
|
|
||||||
self._audio_sample_count_tox = self._audio_rate_tox * self._audio_channels * self._audio_duration // 1000
|
|
||||||
|
|
||||||
self._video = None
|
self._video = None
|
||||||
self._video_thread = None
|
self._video_thread = None
|
||||||
self._video_running = None
|
self._video_running = False
|
||||||
|
|
||||||
self._video_width = 320
|
self._video_width = 640
|
||||||
self._video_height = 240
|
self._video_height = 480
|
||||||
|
|
||||||
# was iOutput = self._settings._args.audio['output']
|
|
||||||
iInput = self._settings['audio']['input']
|
|
||||||
self.lPaSampleratesI = ts.lSdSamplerates(iInput)
|
|
||||||
iOutput = self._settings['audio']['output']
|
|
||||||
self.lPaSampleratesO = ts.lSdSamplerates(iOutput)
|
|
||||||
global oPYA
|
|
||||||
oPYA = self._audio = pyaudio.PyAudio()
|
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self._running = False
|
self._running = False
|
||||||
@ -97,70 +51,27 @@ class AV(common.tox_save.ToxAvSave):
|
|||||||
|
|
||||||
def __call__(self, friend_number, audio, video):
|
def __call__(self, friend_number, audio, video):
|
||||||
"""Call friend with specified number"""
|
"""Call friend with specified number"""
|
||||||
if friend_number in self._calls:
|
self._toxav.call(friend_number, 32 if audio else 0, 5000 if video else 0)
|
||||||
LOG.warn(f"__call__ already has {friend_number}")
|
|
||||||
return
|
|
||||||
if self._audio_krate_tox_audio not in ts.lToxSampleratesK:
|
|
||||||
LOG.warn(f"__call__ {self._audio_krate_tox_audio} not in {ts.lToxSampleratesK}")
|
|
||||||
|
|
||||||
try:
|
|
||||||
self._toxav.call(friend_number,
|
|
||||||
self._audio_krate_tox_audio if audio else 0,
|
|
||||||
self._audio_krate_tox_video if video else 0)
|
|
||||||
except ArgumentError as e:
|
|
||||||
LOG.warn(f"_toxav.call already has {friend_number}")
|
|
||||||
return
|
|
||||||
self._calls[friend_number] = Call(audio, video)
|
self._calls[friend_number] = Call(audio, video)
|
||||||
threading.Timer(TIMER_TIMEOUT,
|
threading.Timer(30.0, lambda: self.finish_not_started_call(friend_number)).start()
|
||||||
lambda: self.finish_not_started_call(friend_number)).start()
|
|
||||||
|
|
||||||
def accept_call(self, friend_number, audio_enabled, video_enabled):
|
def accept_call(self, friend_number, audio_enabled, video_enabled):
|
||||||
# obsolete
|
|
||||||
return call_accept_call(self, friend_number, audio_enabled, video_enabled)
|
|
||||||
|
|
||||||
def call_accept_call(self, friend_number, audio_enabled, video_enabled):
|
|
||||||
LOG.debug(f"call_accept_call from {friend_number} {self._running}" +
|
|
||||||
f"{audio_enabled} {video_enabled}")
|
|
||||||
# import pdb; pdb.set_trace() - gets into q Qt exec_ problem
|
|
||||||
# ts.trepan_handler()
|
|
||||||
|
|
||||||
if self._audio_krate_tox_audio not in ts.lToxSampleratesK:
|
|
||||||
LOG.warn(f"__call__ {self._audio_krate_tox_audio} not in {ts.lToxSampleratesK}")
|
|
||||||
if self._running:
|
if self._running:
|
||||||
self._calls[friend_number] = Call(audio_enabled, video_enabled)
|
self._calls[friend_number] = Call(audio_enabled, video_enabled)
|
||||||
# audio_bit_rate: Audio bit rate in Kb/sec. Set this to 0 to disable audio sending.
|
self._toxav.answer(friend_number, 32 if audio_enabled else 0, 5000 if video_enabled else 0)
|
||||||
# video_bit_rate: Video bit rate in Kb/sec. Set this to 0 to disable video sending.
|
|
||||||
try:
|
|
||||||
self._toxav.answer(friend_number,
|
|
||||||
self._audio_krate_tox_audio if audio_enabled else 0,
|
|
||||||
self._audio_krate_tox_video if video_enabled else 0)
|
|
||||||
except ArgumentError as e:
|
|
||||||
LOG.debug(f"AV accept_call error from {friend_number} {self._running}" +
|
|
||||||
f"{e}")
|
|
||||||
raise
|
|
||||||
if audio_enabled:
|
if audio_enabled:
|
||||||
# may raise
|
|
||||||
self.start_audio_thread()
|
self.start_audio_thread()
|
||||||
if video_enabled:
|
if video_enabled:
|
||||||
# may raise
|
|
||||||
self.start_video_thread()
|
self.start_video_thread()
|
||||||
|
|
||||||
def finish_call(self, friend_number, by_friend=False):
|
def finish_call(self, friend_number, by_friend=False):
|
||||||
LOG.debug(f"finish_call {friend_number}")
|
|
||||||
if not by_friend:
|
if not by_friend:
|
||||||
self._toxav.call_control(friend_number, TOXAV_CALL_CONTROL['CANCEL'])
|
self._toxav.call_control(friend_number, TOXAV_CALL_CONTROL['CANCEL'])
|
||||||
if friend_number in self._calls:
|
if friend_number in self._calls:
|
||||||
del self._calls[friend_number]
|
del self._calls[friend_number]
|
||||||
try:
|
if not len(list(filter(lambda c: c.out_audio, self._calls))):
|
||||||
# AttributeError: 'int' object has no attribute 'out_audio'
|
|
||||||
if not len(list(filter(lambda c: c.out_audio, self._calls))):
|
|
||||||
self.stop_audio_thread()
|
|
||||||
if not len(list(filter(lambda c: c.out_video, self._calls))):
|
|
||||||
self.stop_video_thread()
|
|
||||||
except Exception as e:
|
|
||||||
LOG.error(f"finish_call FixMe: {e}")
|
|
||||||
# dunno
|
|
||||||
self.stop_audio_thread()
|
self.stop_audio_thread()
|
||||||
|
if not len(list(filter(lambda c: c.out_video, self._calls))):
|
||||||
self.stop_video_thread()
|
self.stop_video_thread()
|
||||||
|
|
||||||
def finish_not_started_call(self, friend_number):
|
def finish_not_started_call(self, friend_number):
|
||||||
@ -173,7 +84,6 @@ class AV(common.tox_save.ToxAvSave):
|
|||||||
"""
|
"""
|
||||||
New call state
|
New call state
|
||||||
"""
|
"""
|
||||||
LOG.debug(f"toxav_call_state_cb {friend_number}")
|
|
||||||
call = self._calls[friend_number]
|
call = self._calls[friend_number]
|
||||||
call.is_active = True
|
call.is_active = True
|
||||||
|
|
||||||
@ -196,85 +106,32 @@ class AV(common.tox_save.ToxAvSave):
|
|||||||
def start_audio_thread(self):
|
def start_audio_thread(self):
|
||||||
"""
|
"""
|
||||||
Start audio sending
|
Start audio sending
|
||||||
from a callback
|
|
||||||
"""
|
"""
|
||||||
global oPYA
|
|
||||||
# was iInput = self._settings._args.audio['input']
|
|
||||||
iInput = self._settings['audio']['input']
|
|
||||||
if self._audio_thread is not None:
|
if self._audio_thread is not None:
|
||||||
LOG_WARN(f"start_audio_thread device={iInput}")
|
|
||||||
return
|
return
|
||||||
LOG_DEBUG(f"start_audio_thread device={iInput}")
|
|
||||||
lPaSamplerates = ts.lSdSamplerates(iInput)
|
|
||||||
if not(len(lPaSamplerates)):
|
|
||||||
e = f"No supported sample rates for device: audio[input]={iInput!r}"
|
|
||||||
LOG_ERROR(f"start_audio_thread {e}")
|
|
||||||
#?? dunno - cancel call?
|
|
||||||
return
|
|
||||||
if not self._audio_rate_pa in lPaSamplerates:
|
|
||||||
LOG_WARN(f"{self._audio_rate_pa} not in {lPaSamplerates!r}")
|
|
||||||
if False:
|
|
||||||
self._audio_rate_pa = oPYA.get_device_info_by_index(iInput)['defaultSampleRate']
|
|
||||||
else:
|
|
||||||
LOG_WARN(f"Setting audio_rate to: {lPaSamplerates[0]}")
|
|
||||||
self._audio_rate_pa = lPaSamplerates[0]
|
|
||||||
|
|
||||||
try:
|
self._audio_running = True
|
||||||
LOG_DEBUG( f"start_audio_thread framerate: {self._audio_rate_pa}" \
|
|
||||||
+f" device: {iInput}"
|
|
||||||
+f" supported: {lPaSamplerates!r}")
|
|
||||||
if self._audio_rate_pa not in lPaSamplerates:
|
|
||||||
LOG_WARN(f"PAudio sampling rate was {self._audio_rate_pa} changed to {lPaSamplerates[0]}")
|
|
||||||
self._audio_rate_pa = lPaSamplerates[0]
|
|
||||||
|
|
||||||
if bSTREAM_CALLBACK:
|
self._audio = pyaudio.PyAudio()
|
||||||
self._audio_stream = oPYA.open(format=pyaudio.paInt16,
|
self._audio_stream = self._audio.open(format=pyaudio.paInt16,
|
||||||
rate=self._audio_rate_pa,
|
rate=self._audio_rate,
|
||||||
channels=self._audio_channels,
|
channels=self._audio_channels,
|
||||||
input=True,
|
input=True,
|
||||||
input_device_index=iInput,
|
input_device_index=self._settings.audio['input'],
|
||||||
frames_per_buffer=self._audio_sample_count_pa * 10,
|
frames_per_buffer=self._audio_sample_count * 10)
|
||||||
stream_callback=self.send_audio_data)
|
|
||||||
self._audio_running = True
|
|
||||||
self._audio_stream.start_stream()
|
|
||||||
while self._audio_stream.is_active():
|
|
||||||
sleep(0.1)
|
|
||||||
self._audio_stream.stop_stream()
|
|
||||||
self._audio_stream.close()
|
|
||||||
|
|
||||||
else:
|
self._audio_thread = threading.Thread(target=self.send_audio)
|
||||||
self._audio_stream = oPYA.open(format=pyaudio.paInt16,
|
self._audio_thread.start()
|
||||||
rate=self._audio_rate_pa,
|
|
||||||
channels=self._audio_channels,
|
|
||||||
input=True,
|
|
||||||
input_device_index=iInput,
|
|
||||||
frames_per_buffer=self._audio_sample_count_pa * 10)
|
|
||||||
self._audio_running = True
|
|
||||||
self._audio_thread = BaseThread(target=self.send_audio,
|
|
||||||
name='_audio_thread')
|
|
||||||
self._audio_thread.start()
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
LOG.error(f"Starting self._audio.open {e}")
|
|
||||||
LOG.debug(repr(dict(format=pyaudio.paInt16,
|
|
||||||
rate=self._audio_rate_pa,
|
|
||||||
channels=self._audio_channels,
|
|
||||||
input=True,
|
|
||||||
input_device_index=iInput,
|
|
||||||
frames_per_buffer=self._audio_sample_count_pa * 10)))
|
|
||||||
# catcher in place in calls_manager? not if from a callback
|
|
||||||
# calls_manager._call.toxav_call_state_cb(friend_number, mask)
|
|
||||||
# raise RuntimeError(e)
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
LOG_DEBUG(f"start_audio_thread {self._audio_stream!r}")
|
|
||||||
|
|
||||||
def stop_audio_thread(self):
|
def stop_audio_thread(self):
|
||||||
|
|
||||||
if self._audio_thread is None:
|
if self._audio_thread is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
self._audio_running = False
|
self._audio_running = False
|
||||||
|
|
||||||
|
self._audio_thread.join()
|
||||||
|
|
||||||
self._audio_thread = None
|
self._audio_thread = None
|
||||||
self._audio_stream = None
|
self._audio_stream = None
|
||||||
self._audio = None
|
self._audio = None
|
||||||
@ -287,48 +144,21 @@ class AV(common.tox_save.ToxAvSave):
|
|||||||
def start_video_thread(self):
|
def start_video_thread(self):
|
||||||
if self._video_thread is not None:
|
if self._video_thread is not None:
|
||||||
return
|
return
|
||||||
s = self._settings
|
|
||||||
if 'video' not in s:
|
|
||||||
LOG.warn("AV.__init__ 'video' not in s" )
|
|
||||||
LOG.debug(f"start_video_thread {s!r}" )
|
|
||||||
raise RuntimeError("start_video_thread not 'video' in s)" )
|
|
||||||
elif 'device' not in s['video']:
|
|
||||||
LOG.error("start_video_thread not 'device' in s['video']" )
|
|
||||||
LOG.debug(f"start_video_thread {s['video']!r}" )
|
|
||||||
raise RuntimeError("start_video_thread not 'device' ins s['video']" )
|
|
||||||
self._video_width = s['video']['width']
|
|
||||||
self._video_height = s['video']['height']
|
|
||||||
|
|
||||||
# dunno
|
|
||||||
if True or s['video']['device'] == -1:
|
|
||||||
self._video = screen_sharing.DesktopGrabber(s['video']['x'],
|
|
||||||
s['video']['y'],
|
|
||||||
s['video']['width'],
|
|
||||||
s['video']['height'])
|
|
||||||
else:
|
|
||||||
with ts.ignoreStdout():
|
|
||||||
import cv2
|
|
||||||
if s['video']['device'] == 0:
|
|
||||||
# webcam
|
|
||||||
self._video = cv2.VideoCapture(s['video']['device'], cv2.DSHOW)
|
|
||||||
else:
|
|
||||||
self._video = cv2.VideoCapture(s['video']['device'])
|
|
||||||
self._video.set(cv2.CAP_PROP_FPS, iFPS)
|
|
||||||
self._video.set(cv2.CAP_PROP_FRAME_WIDTH, self._video_width)
|
|
||||||
self._video.set(cv2.CAP_PROP_FRAME_HEIGHT, self._video_height)
|
|
||||||
# self._video.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'))
|
|
||||||
if self._video is None:
|
|
||||||
LOG.error("start_video_thread " \
|
|
||||||
+f" device: {s['video']['device']}" \
|
|
||||||
+f" supported: {s['video']['width']} {s['video']['height']}")
|
|
||||||
return
|
|
||||||
LOG.info("start_video_thread " \
|
|
||||||
+f" device: {s['video']['device']}" \
|
|
||||||
+f" supported: {s['video']['width']} {s['video']['height']}")
|
|
||||||
|
|
||||||
self._video_running = True
|
self._video_running = True
|
||||||
self._video_thread = BaseThread(target=self.send_video,
|
self._video_width = s.video['width']
|
||||||
name='_video_thread')
|
self._video_height = s.video['height']
|
||||||
|
|
||||||
|
if s.video['device'] == -1:
|
||||||
|
self._video = screen_sharing.DesktopGrabber(self._settings.video['x'], self._settings.video['y'],
|
||||||
|
self._settings.video['width'], self._settings.video['height'])
|
||||||
|
else:
|
||||||
|
self._video = cv2.VideoCapture(self._settings.video['device'])
|
||||||
|
self._video.set(cv2.CAP_PROP_FPS, 25)
|
||||||
|
self._video.set(cv2.CAP_PROP_FRAME_WIDTH, self._video_width)
|
||||||
|
self._video.set(cv2.CAP_PROP_FRAME_HEIGHT, self._video_height)
|
||||||
|
|
||||||
|
self._video_thread = threading.Thread(target=self.send_video)
|
||||||
self._video_thread.start()
|
self._video_thread.start()
|
||||||
|
|
||||||
def stop_video_thread(self):
|
def stop_video_thread(self):
|
||||||
@ -336,17 +166,7 @@ class AV(common.tox_save.ToxAvSave):
|
|||||||
return
|
return
|
||||||
|
|
||||||
self._video_running = False
|
self._video_running = False
|
||||||
i = 0
|
self._video_thread.join()
|
||||||
while i < ts.iTHREAD_JOINS:
|
|
||||||
self._video_thread.join(ts.iTHREAD_TIMEOUT)
|
|
||||||
try:
|
|
||||||
if not self._video_thread.is_alive(): break
|
|
||||||
except:
|
|
||||||
# AttributeError: 'NoneType' object has no attribute 'join'
|
|
||||||
break
|
|
||||||
i = i + 1
|
|
||||||
else:
|
|
||||||
LOG.warn("self._video_thread.is_alive BLOCKED")
|
|
||||||
self._video_thread = None
|
self._video_thread = None
|
||||||
self._video = None
|
self._video = None
|
||||||
|
|
||||||
@ -360,126 +180,58 @@ class AV(common.tox_save.ToxAvSave):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
if self._out_stream is None:
|
if self._out_stream is None:
|
||||||
# was iOutput = self._settings._args.audio['output']
|
self._out_stream = self._audio.open(format=pyaudio.paInt16,
|
||||||
iOutput = self._settings['audio']['output']
|
channels=channels_count,
|
||||||
if not rate in self.lPaSampleratesO:
|
rate=rate,
|
||||||
LOG.warn(f"{rate} not in {self.lPaSampleratesO!r}")
|
output_device_index=self._settings.audio['output'],
|
||||||
if False:
|
output=True)
|
||||||
rate = oPYA.get_device_info_by_index(iOutput)['defaultSampleRate']
|
|
||||||
LOG.warn(f"Setting audio_rate to: {self.lPaSampleratesO[0]}")
|
|
||||||
rate = self.lPaSampleratesO[0]
|
|
||||||
try:
|
|
||||||
with ts.ignoreStderr():
|
|
||||||
self._out_stream = oPYA.open(format=pyaudio.paInt16,
|
|
||||||
channels=channels_count,
|
|
||||||
rate=rate,
|
|
||||||
output_device_index=iOutput,
|
|
||||||
output=True)
|
|
||||||
except Exception as e:
|
|
||||||
LOG.error(f"Error playing audio_chunk creating self._out_stream {e}")
|
|
||||||
invoke_in_main_thread(util_ui.message_box,
|
|
||||||
str(e),
|
|
||||||
util_ui.tr("Error Chunking audio"))
|
|
||||||
# dunno
|
|
||||||
self.stop()
|
|
||||||
return
|
|
||||||
|
|
||||||
iOutput = self._settings['audio']['output']
|
|
||||||
LOG.debug(f"audio_chunk output_device_index={iOutput} rate={rate} channels={channels_count}")
|
|
||||||
self._out_stream.write(samples)
|
self._out_stream.write(samples)
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
# AV sending
|
# AV sending
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
def send_audio_data(self, data, count, *largs, **kwargs):
|
|
||||||
pcm = data
|
|
||||||
# :param sampling_rate: Audio sampling rate used in this frame.
|
|
||||||
if self._toxav is None:
|
|
||||||
raise RuntimeError("_toxav not initialized")
|
|
||||||
if self._audio_rate_tox not in ts.lToxSamplerates:
|
|
||||||
LOG.warn(f"ToxAudio sampling rate was {self._audio_rate_tox} changed to {ts.lToxSamplerates[0]}")
|
|
||||||
self._audio_rate_tox = ts.lToxSamplerates[0]
|
|
||||||
|
|
||||||
for friend_num in self._calls:
|
|
||||||
if self._calls[friend_num].out_audio:
|
|
||||||
try:
|
|
||||||
# app.av.calls ERROR Error send_audio: One of the frame parameters was invalid. E.g. the resolution may be too small or too large, or the audio sampling rate may be unsupported
|
|
||||||
# app.av.calls ERROR Error send_audio audio_send_frame: This client is currently not in a call with the friend.
|
|
||||||
self._toxav.audio_send_frame(friend_num,
|
|
||||||
pcm,
|
|
||||||
count,
|
|
||||||
self._audio_channels,
|
|
||||||
self._audio_rate_tox)
|
|
||||||
except Exception as e:
|
|
||||||
LOG.error(f"Error send_audio audio_send_frame: {e}")
|
|
||||||
LOG.debug(f"send_audio self._audio_rate_tox={self._audio_rate_tox} self._audio_channels={self._audio_channels}")
|
|
||||||
# invoke_in_main_thread(util_ui.message_box,
|
|
||||||
# str(e),
|
|
||||||
# util_ui.tr("Error send_audio audio_send_frame"))
|
|
||||||
pass
|
|
||||||
|
|
||||||
def send_audio(self):
|
def send_audio(self):
|
||||||
"""
|
"""
|
||||||
This method sends audio to friends
|
This method sends audio to friends
|
||||||
"""
|
"""
|
||||||
i=0
|
|
||||||
count = self._audio_sample_count_tox
|
|
||||||
LOG.debug(f"send_audio stream={self._audio_stream}")
|
|
||||||
while self._audio_running:
|
while self._audio_running:
|
||||||
try:
|
try:
|
||||||
pcm = self._audio_stream.read(count, exception_on_overflow=False)
|
pcm = self._audio_stream.read(self._audio_sample_count)
|
||||||
if not pcm:
|
if pcm:
|
||||||
sleep(0.1)
|
for friend_num in self._calls:
|
||||||
else:
|
if self._calls[friend_num].out_audio:
|
||||||
self.send_audio_data(pcm, count)
|
try:
|
||||||
|
self._toxav.audio_send_frame(friend_num, pcm, self._audio_sample_count,
|
||||||
|
self._audio_channels, self._audio_rate)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
except:
|
except:
|
||||||
LOG_DEBUG(f"error send_audio {i}")
|
pass
|
||||||
else:
|
|
||||||
LOG_TRACE(f"send_audio {i}")
|
time.sleep(0.01)
|
||||||
i += 1
|
|
||||||
sleep(0.01)
|
|
||||||
|
|
||||||
def send_video(self):
|
def send_video(self):
|
||||||
"""
|
"""
|
||||||
This method sends video to friends
|
This method sends video to friends
|
||||||
"""
|
"""
|
||||||
LOG.debug(f"send_video thread={threading.current_thread().name}"
|
|
||||||
+f" self._video_running={self._video_running}"
|
|
||||||
+f" device: {self._settings['video']['device']}" )
|
|
||||||
while self._video_running:
|
while self._video_running:
|
||||||
try:
|
try:
|
||||||
result, frame = self._video.read()
|
result, frame = self._video.read()
|
||||||
if not result:
|
if result:
|
||||||
LOG.warn(f"send_video video_send_frame _video.read result={result}")
|
|
||||||
break
|
|
||||||
if frame is None:
|
|
||||||
LOG.warn(f"send_video video_send_frame _video.read result={result} frame={frame}")
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
LOG_TRACE(f"send_video video_send_frame _video.read result={result}")
|
|
||||||
height, width, channels = frame.shape
|
height, width, channels = frame.shape
|
||||||
friends = []
|
|
||||||
for friend_num in self._calls:
|
for friend_num in self._calls:
|
||||||
if self._calls[friend_num].out_video:
|
if self._calls[friend_num].out_video:
|
||||||
friends.append(friend_num)
|
try:
|
||||||
if len(friends) == 0:
|
y, u, v = self.convert_bgr_to_yuv(frame)
|
||||||
LOG.warn(f"send_video video_send_frame no friends")
|
self._toxav.video_send_frame(friend_num, width, height, y, u, v)
|
||||||
else:
|
except:
|
||||||
LOG_TRACE(f"send_video video_send_frame {friends}")
|
pass
|
||||||
friend_num = friends[0]
|
except:
|
||||||
try:
|
|
||||||
y, u, v = self.convert_bgr_to_yuv(frame)
|
|
||||||
self._toxav.video_send_frame(friend_num, width, height, y, u, v)
|
|
||||||
except Exception as e:
|
|
||||||
LOG.debug(f"send_video video_send_frame ERROR {e}")
|
|
||||||
pass
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
LOG.error(f"send_video video_send_frame {e}")
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
sleep( 1.0/iFPS)
|
time.sleep(0.01)
|
||||||
|
|
||||||
def convert_bgr_to_yuv(self, frame):
|
def convert_bgr_to_yuv(self, frame):
|
||||||
"""
|
"""
|
||||||
@ -512,14 +264,11 @@ class AV(common.tox_save.ToxAvSave):
|
|||||||
Y, U, V can be extracted using slices and joined in one list using itertools.chain.from_iterable()
|
Y, U, V can be extracted using slices and joined in one list using itertools.chain.from_iterable()
|
||||||
Function returns bytes(y), bytes(u), bytes(v), because it is required for ctypes
|
Function returns bytes(y), bytes(u), bytes(v), because it is required for ctypes
|
||||||
"""
|
"""
|
||||||
with ts.ignoreStdout():
|
|
||||||
import cv2
|
|
||||||
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2YUV_I420)
|
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2YUV_I420)
|
||||||
|
|
||||||
y = frame[:self._video_height, :]
|
y = frame[:self._video_height, :]
|
||||||
y = list(itertools.chain.from_iterable(y))
|
y = list(itertools.chain.from_iterable(y))
|
||||||
|
|
||||||
import numpy as np
|
|
||||||
u = np.zeros((self._video_height // 2, self._video_width // 2), dtype=np.int)
|
u = np.zeros((self._video_height // 2, self._video_width // 2), dtype=np.int)
|
||||||
u[::2, :] = frame[self._video_height:self._video_height * 5 // 4, :self._video_width // 2]
|
u[::2, :] = frame[self._video_height:self._video_height * 5 // 4, :self._video_width // 2]
|
||||||
u[1::2, :] = frame[self._video_height:self._video_height * 5 // 4, self._video_width // 2:]
|
u[1::2, :] = frame[self._video_height:self._video_height * 5 // 4, self._video_width // 2:]
|
||||||
|
@ -1,34 +1,25 @@
|
|||||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import threading
|
import threading
|
||||||
|
import cv2
|
||||||
import av.calls
|
import av.calls
|
||||||
from messenger.messages import *
|
from messenger.messages import *
|
||||||
from ui import av_widgets
|
from ui import av_widgets
|
||||||
import common.event as event
|
import common.event as event
|
||||||
import utils.ui as util_ui
|
|
||||||
|
|
||||||
global LOG
|
|
||||||
import logging
|
|
||||||
LOG = logging.getLogger('app.'+__name__)
|
|
||||||
|
|
||||||
class CallsManager:
|
class CallsManager:
|
||||||
|
|
||||||
def __init__(self, toxav, settings, main_screen, contacts_manager, app=None):
|
def __init__(self, toxav, settings, screen, contacts_manager):
|
||||||
self._callav = av.calls.AV(toxav, settings) # object with data about calls
|
self._call = av.calls.AV(toxav, settings) # object with data about calls
|
||||||
self._call = self._callav
|
|
||||||
self._call_widgets = {} # dict of incoming call widgets
|
self._call_widgets = {} # dict of incoming call widgets
|
||||||
self._incoming_calls = set()
|
self._incoming_calls = set()
|
||||||
self._settings = settings
|
self._settings = settings
|
||||||
self._main_screen = main_screen
|
self._screen = screen
|
||||||
self._contacts_manager = contacts_manager
|
self._contacts_manager = contacts_manager
|
||||||
self._call_started_event = event.Event() # friend_number, audio, video, is_outgoing
|
self._call_started_event = event.Event() # friend_number, audio, video, is_outgoing
|
||||||
self._call_finished_event = event.Event() # friend_number, is_declined
|
self._call_finished_event = event.Event() # friend_number, is_declined
|
||||||
self._app = app
|
|
||||||
|
|
||||||
def set_toxav(self, toxav):
|
def set_toxav(self, toxav):
|
||||||
self._callav.set_toxav(toxav)
|
self._call.set_toxav(toxav)
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
# Events
|
# Events
|
||||||
@ -53,26 +44,26 @@ class CallsManager:
|
|||||||
num = self._contacts_manager.get_active_number()
|
num = self._contacts_manager.get_active_number()
|
||||||
if not self._contacts_manager.is_active_a_friend():
|
if not self._contacts_manager.is_active_a_friend():
|
||||||
return
|
return
|
||||||
if num not in self._callav and self._contacts_manager.is_active_online(): # start call
|
if num not in self._call and self._contacts_manager.is_active_online(): # start call
|
||||||
if not self._settings['audio']['enabled']:
|
if not self._settings.audio['enabled']:
|
||||||
return
|
return
|
||||||
self._callav(num, audio, video)
|
self._call(num, audio, video)
|
||||||
self._main_screen.active_call()
|
self._screen.active_call()
|
||||||
self._call_started_event(num, audio, video, True)
|
self._call_started_event(num, audio, video, True)
|
||||||
elif num in self._callav: # finish or cancel call if you call with active friend
|
elif num in self._call: # finish or cancel call if you call with active friend
|
||||||
self.stop_call(num, False)
|
self.stop_call(num, False)
|
||||||
|
|
||||||
def incoming_call(self, audio, video, friend_number):
|
def incoming_call(self, audio, video, friend_number):
|
||||||
"""
|
"""
|
||||||
Incoming call from friend.
|
Incoming call from friend.
|
||||||
"""
|
"""
|
||||||
LOG.debug(__name__ +f" incoming_call {friend_number}")
|
if not self._settings.audio['enabled']:
|
||||||
# if not self._settings['audio']['enabled']: return
|
return
|
||||||
friend = self._contacts_manager.get_friend_by_number(friend_number)
|
friend = self._contacts_manager.get_friend_by_number(friend_number)
|
||||||
self._call_started_event(friend_number, audio, video, False)
|
self._call_started_event(friend_number, audio, video, False)
|
||||||
self._incoming_calls.add(friend_number)
|
self._incoming_calls.add(friend_number)
|
||||||
if friend_number == self._contacts_manager.get_active_number():
|
if friend_number == self._contacts_manager.get_active_number():
|
||||||
self._main_screen.incoming_call()
|
self._screen.incoming_call()
|
||||||
else:
|
else:
|
||||||
friend.actions = True
|
friend.actions = True
|
||||||
text = util_ui.tr("Incoming video call") if video else util_ui.tr("Incoming audio call")
|
text = util_ui.tr("Incoming video call") if video else util_ui.tr("Incoming audio call")
|
||||||
@ -83,81 +74,39 @@ class CallsManager:
|
|||||||
def accept_call(self, friend_number, audio, video):
|
def accept_call(self, friend_number, audio, video):
|
||||||
"""
|
"""
|
||||||
Accept incoming call with audio or video
|
Accept incoming call with audio or video
|
||||||
Called from a thread
|
|
||||||
"""
|
"""
|
||||||
|
self._call.accept_call(friend_number, audio, video)
|
||||||
LOG.debug(f"CM accept_call from {friend_number} {audio} {video}")
|
self._screen.active_call()
|
||||||
sys.stdout.flush()
|
if friend_number in self._incoming_calls:
|
||||||
|
self._incoming_calls.remove(friend_number)
|
||||||
try:
|
del self._call_widgets[friend_number]
|
||||||
self._callav.call_accept_call(friend_number, audio, video)
|
|
||||||
except Exception as e:
|
|
||||||
LOG.error(f"accept_call _call.accept_call ERROR for {friend_number} {e}")
|
|
||||||
self._main_screen.call_finished()
|
|
||||||
if hasattr(self._main_screen, '_settings') and \
|
|
||||||
'audio' in self._main_screen._settings and \
|
|
||||||
'input' in self._main_screen._settings['audio']:
|
|
||||||
iInput = self._settings['audio']['input']
|
|
||||||
iOutput = self._settings['audio']['output']
|
|
||||||
iVideo = self._settings['video']['device']
|
|
||||||
LOG.debug(f"iInput={iInput} iOutput={iOutput} iVideo={iVideo}")
|
|
||||||
elif hasattr(self._main_screen, '_settings') and \
|
|
||||||
hasattr(self._main_screen._settings, 'audio') and \
|
|
||||||
'input' not in self._main_screen._settings['audio']:
|
|
||||||
LOG.warn(f"'audio' not in {self._main_screen._settings!r}")
|
|
||||||
elif hasattr(self._main_screen, '_settings') and \
|
|
||||||
hasattr(self._main_screen._settings, 'audio') and \
|
|
||||||
'input' not in self._main_screen._settings['audio']:
|
|
||||||
LOG.warn(f"'audio' not in {self._main_screen._settings!r}")
|
|
||||||
else:
|
|
||||||
LOG.warn(f"_settings not in self._main_screen")
|
|
||||||
util_ui.message_box(str(e),
|
|
||||||
util_ui.tr('ERROR Accepting call from {friend_number}'))
|
|
||||||
else:
|
|
||||||
self._main_screen.active_call()
|
|
||||||
|
|
||||||
finally:
|
|
||||||
# does not terminate call - just the av_widget
|
|
||||||
if friend_number in self._incoming_calls:
|
|
||||||
self._incoming_calls.remove(friend_number)
|
|
||||||
try:
|
|
||||||
self._call_widgets[friend_number].close()
|
|
||||||
del self._call_widgets[friend_number]
|
|
||||||
except:
|
|
||||||
# RuntimeError: wrapped C/C++ object of type IncomingCallWidget has been deleted
|
|
||||||
|
|
||||||
pass
|
|
||||||
LOG.debug(f" closed self._call_widgets[{friend_number}]")
|
|
||||||
|
|
||||||
def stop_call(self, friend_number, by_friend):
|
def stop_call(self, friend_number, by_friend):
|
||||||
"""
|
"""
|
||||||
Stop call with friend
|
Stop call with friend
|
||||||
"""
|
"""
|
||||||
LOG.debug(__name__+f" stop_call {friend_number}")
|
|
||||||
if friend_number in self._incoming_calls:
|
if friend_number in self._incoming_calls:
|
||||||
self._incoming_calls.remove(friend_number)
|
self._incoming_calls.remove(friend_number)
|
||||||
is_declined = True
|
is_declined = True
|
||||||
else:
|
else:
|
||||||
is_declined = False
|
is_declined = False
|
||||||
self._main_screen.call_finished()
|
self._screen.call_finished()
|
||||||
self._callav.finish_call(friend_number, by_friend) # finish or decline call
|
is_video = self._call.is_video_call(friend_number)
|
||||||
|
self._call.finish_call(friend_number, by_friend) # finish or decline call
|
||||||
if friend_number in self._call_widgets:
|
if friend_number in self._call_widgets:
|
||||||
self._call_widgets[friend_number].close()
|
self._call_widgets[friend_number].close()
|
||||||
del self._call_widgets[friend_number]
|
del self._call_widgets[friend_number]
|
||||||
|
|
||||||
def destroy_window():
|
def destroy_window():
|
||||||
#??? FixMed
|
|
||||||
is_video = self._callav.is_video_call(friend_number)
|
|
||||||
if is_video:
|
if is_video:
|
||||||
import cv2
|
|
||||||
cv2.destroyWindow(str(friend_number))
|
cv2.destroyWindow(str(friend_number))
|
||||||
|
|
||||||
threading.Timer(2.0, destroy_window).start()
|
threading.Timer(2.0, destroy_window).start()
|
||||||
self._call_finished_event(friend_number, is_declined)
|
self._call_finished_event(friend_number, is_declined)
|
||||||
|
|
||||||
def friend_exit(self, friend_number):
|
def friend_exit(self, friend_number):
|
||||||
if friend_number in self._callav:
|
if friend_number in self._call:
|
||||||
self._callav.finish_call(friend_number, True)
|
self._call.finish_call(friend_number, True)
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
# Private methods
|
# Private methods
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import numpy as np
|
||||||
from PyQt5 import QtWidgets
|
from PyQt5 import QtWidgets
|
||||||
|
|
||||||
|
|
||||||
@ -16,7 +17,6 @@ class DesktopGrabber:
|
|||||||
pixmap = self._screen.grabWindow(0, self._x, self._y, self._width, self._height)
|
pixmap = self._screen.grabWindow(0, self._x, self._y, self._width, self._height)
|
||||||
image = pixmap.toImage()
|
image = pixmap.toImage()
|
||||||
s = image.bits().asstring(self._width * self._height * 4)
|
s = image.bits().asstring(self._width * self._height * 4)
|
||||||
import numpy as np
|
|
||||||
arr = np.fromstring(s, dtype=np.uint8).reshape((self._height, self._width, 4))
|
arr = np.fromstring(s, dtype=np.uint8).reshape((self._height, self._width, 4))
|
||||||
|
|
||||||
return True, arr
|
return True, arr
|
||||||
|
@ -1,48 +1,83 @@
|
|||||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
|
||||||
import random
|
import random
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from utils.util import *
|
from utils.util import *
|
||||||
from PyQt5 import QtNetwork
|
from PyQt5 import QtNetwork, QtCore
|
||||||
from PyQt5 import QtCore
|
import json
|
||||||
try:
|
|
||||||
import certifi
|
|
||||||
from io import BytesIO
|
|
||||||
except ImportError:
|
|
||||||
certifi = None
|
|
||||||
|
|
||||||
from user_data.settings import get_user_config_path
|
|
||||||
from wrapper_tests.support_testing import _get_nodes_path
|
|
||||||
from wrapper_tests.support_http import download_url
|
|
||||||
import wrapper_tests.support_testing as ts
|
|
||||||
|
|
||||||
global LOG
|
DEFAULT_NODES_COUNT = 4
|
||||||
import logging
|
|
||||||
LOG = logging.getLogger('app.'+'bootstrap')
|
|
||||||
|
|
||||||
def download_nodes_list(settings, oArgs):
|
|
||||||
|
class Node:
|
||||||
|
|
||||||
|
def __init__(self, node):
|
||||||
|
self._ip, self._port, self._tox_key = node['ipv4'], node['port'], node['public_key']
|
||||||
|
self._priority = random.randint(1, 1000000) if node['status_tcp'] and node['status_udp'] else 0
|
||||||
|
|
||||||
|
def get_priority(self):
|
||||||
|
return self._priority
|
||||||
|
|
||||||
|
priority = property(get_priority)
|
||||||
|
|
||||||
|
def get_data(self):
|
||||||
|
return self._ip, self._port, self._tox_key
|
||||||
|
|
||||||
|
|
||||||
|
def generate_nodes(nodes_count=DEFAULT_NODES_COUNT):
|
||||||
|
with open(_get_nodes_path(), 'rt') as fl:
|
||||||
|
json_nodes = json.loads(fl.read())['nodes']
|
||||||
|
nodes = map(lambda json_node: Node(json_node), json_nodes)
|
||||||
|
nodes = filter(lambda n: n.priority > 0, nodes)
|
||||||
|
sorted_nodes = sorted(nodes, key=lambda x: x.priority)
|
||||||
|
if nodes_count is not None:
|
||||||
|
sorted_nodes = sorted_nodes[-DEFAULT_NODES_COUNT:]
|
||||||
|
for node in sorted_nodes:
|
||||||
|
yield node.get_data()
|
||||||
|
|
||||||
|
|
||||||
|
def download_nodes_list(settings):
|
||||||
|
url = 'https://nodes.tox.chat/json'
|
||||||
if not settings['download_nodes_list']:
|
if not settings['download_nodes_list']:
|
||||||
return ''
|
return
|
||||||
if not ts.bAreWeConnected():
|
|
||||||
return ''
|
|
||||||
url = settings['download_nodes_url']
|
|
||||||
path = _get_nodes_path(oArgs=oArgs)
|
|
||||||
# dont download blindly so we can edit the file and not block on startup
|
|
||||||
if os.path.isfile(path):
|
|
||||||
with open(path, 'rt') as fl:
|
|
||||||
result = fl.read()
|
|
||||||
return result
|
|
||||||
LOG.debug("downloading list of nodes")
|
|
||||||
result = download_url(url, settings._app._settings)
|
|
||||||
if not result:
|
|
||||||
LOG.warn("failed downloading list of nodes")
|
|
||||||
return ''
|
|
||||||
LOG.info("downloaded list of nodes")
|
|
||||||
_save_nodes(result, settings._app)
|
|
||||||
return result
|
|
||||||
|
|
||||||
def _save_nodes(nodes, app):
|
if not settings['proxy_type']: # no proxy
|
||||||
|
try:
|
||||||
|
req = urllib.request.Request(url)
|
||||||
|
req.add_header('Content-Type', 'application/json')
|
||||||
|
response = urllib.request.urlopen(req)
|
||||||
|
result = response.read()
|
||||||
|
_save_nodes(result)
|
||||||
|
except Exception as ex:
|
||||||
|
log('TOX nodes loading error: ' + str(ex))
|
||||||
|
else: # proxy
|
||||||
|
netman = QtNetwork.QNetworkAccessManager()
|
||||||
|
proxy = QtNetwork.QNetworkProxy()
|
||||||
|
proxy.setType(
|
||||||
|
QtNetwork.QNetworkProxy.Socks5Proxy if settings['proxy_type'] == 2 else QtNetwork.QNetworkProxy.HttpProxy)
|
||||||
|
proxy.setHostName(settings['proxy_host'])
|
||||||
|
proxy.setPort(settings['proxy_port'])
|
||||||
|
netman.setProxy(proxy)
|
||||||
|
try:
|
||||||
|
request = QtNetwork.QNetworkRequest()
|
||||||
|
request.setUrl(QtCore.QUrl(url))
|
||||||
|
reply = netman.get(request)
|
||||||
|
|
||||||
|
while not reply.isFinished():
|
||||||
|
QtCore.QThread.msleep(1)
|
||||||
|
QtCore.QCoreApplication.processEvents()
|
||||||
|
data = bytes(reply.readAll().data())
|
||||||
|
_save_nodes(data)
|
||||||
|
except Exception as ex:
|
||||||
|
log('TOX nodes loading error: ' + str(ex))
|
||||||
|
|
||||||
|
|
||||||
|
def _get_nodes_path():
|
||||||
|
return join_path(curr_directory(__file__), 'nodes.json')
|
||||||
|
|
||||||
|
|
||||||
|
def _save_nodes(nodes):
|
||||||
if not nodes:
|
if not nodes:
|
||||||
return
|
return
|
||||||
with open(_get_nodes_path(oArgs=app._args), 'wb') as fl:
|
print('Saving nodes...')
|
||||||
LOG.info("Saving nodes to " +_get_nodes_path())
|
with open(_get_nodes_path(), 'wb') as fl:
|
||||||
fl.write(nodes)
|
fl.write(nodes)
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
|
||||||
from user_data.settings import *
|
from user_data.settings import *
|
||||||
from PyQt5 import QtCore, QtGui
|
from PyQt5 import QtCore, QtGui
|
||||||
from wrapper.toxcore_enums_and_consts import TOX_PUBLIC_KEY_SIZE
|
from wrapper.toxcore_enums_and_consts import TOX_PUBLIC_KEY_SIZE
|
||||||
@ -15,20 +14,17 @@ class BaseContact:
|
|||||||
Base class for all contacts.
|
Base class for all contacts.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, profile_manager, name, status_message, widget, tox_id, kind=''):
|
def __init__(self, profile_manager, name, status_message, widget, tox_id):
|
||||||
"""
|
"""
|
||||||
:param name: name, example: 'Toxygen user'
|
:param name: name, example: 'Toxygen user'
|
||||||
:param status_message: status message, example: 'Toxing on Toxygen'
|
:param status_message: status message, example: 'Toxing on Toxygen'
|
||||||
:param widget: ContactItem instance
|
:param widget: ContactItem instance
|
||||||
:param tox_id: tox id of contact
|
:param tox_id: tox id of contact
|
||||||
:param kind: one of ['bot', 'friend', 'group', 'invite', 'grouppeer', '']
|
|
||||||
"""
|
"""
|
||||||
self._profile_manager = profile_manager
|
self._profile_manager = profile_manager
|
||||||
self._name, self._status_message = name, status_message
|
self._name, self._status_message = name, status_message
|
||||||
self._kind = kind
|
|
||||||
self._status, self._widget = None, widget
|
self._status, self._widget = None, widget
|
||||||
self._tox_id = tox_id
|
self._tox_id = tox_id
|
||||||
|
|
||||||
self._name_changed_event = event.Event()
|
self._name_changed_event = event.Event()
|
||||||
self._status_message_changed_event = event.Event()
|
self._status_message_changed_event = event.Event()
|
||||||
self._status_changed_event = event.Event()
|
self._status_changed_event = event.Event()
|
||||||
@ -172,8 +168,6 @@ class BaseContact:
|
|||||||
def init_widget(self):
|
def init_widget(self):
|
||||||
self._widget.name.setText(self._name)
|
self._widget.name.setText(self._name)
|
||||||
self._widget.status_message.setText(self._status_message)
|
self._widget.status_message.setText(self._status_message)
|
||||||
if hasattr(self._widget, 'kind'):
|
|
||||||
self._widget.kind.setText(self._kind)
|
|
||||||
self._widget.connection_status.update(self._status)
|
self._widget.connection_status.update(self._status)
|
||||||
self.load_avatar()
|
self.load_avatar()
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
from pydenticon import Generator
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
from pydenticon import Generator
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
# Typing notifications
|
# Typing notifications
|
||||||
|
@ -1,17 +1,10 @@
|
|||||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
from history.database import *
|
||||||
from history.database import TIMEOUT, \
|
|
||||||
SAVE_MESSAGES, MESSAGE_AUTHOR
|
|
||||||
|
|
||||||
from contacts import basecontact, common
|
from contacts import basecontact, common
|
||||||
from messenger.messages import *
|
from messenger.messages import *
|
||||||
from contacts.contact_menu import *
|
from contacts.contact_menu import *
|
||||||
from file_transfers import file_transfers as ft
|
from file_transfers import file_transfers as ft
|
||||||
import re
|
import re
|
||||||
|
|
||||||
# LOG=util.log
|
|
||||||
global LOG
|
|
||||||
import logging
|
|
||||||
LOG = logging.getLogger('app.'+__name__)
|
|
||||||
|
|
||||||
class Contact(basecontact.BaseContact):
|
class Contact(basecontact.BaseContact):
|
||||||
"""
|
"""
|
||||||
@ -141,15 +134,12 @@ class Contact(basecontact.BaseContact):
|
|||||||
return list(messages)
|
return list(messages)
|
||||||
|
|
||||||
def mark_as_sent(self, tox_message_id):
|
def mark_as_sent(self, tox_message_id):
|
||||||
message = list(filter(lambda m: m.author is not None
|
|
||||||
and m.author.type == MESSAGE_AUTHOR['NOT_SENT']
|
|
||||||
and m.tox_message_id == tox_message_id,
|
|
||||||
self._corr))[0]
|
|
||||||
try:
|
try:
|
||||||
|
message = list(filter(lambda m: m.author is not None and m.author.type == MESSAGE_AUTHOR['NOT_SENT']
|
||||||
|
and m.tox_message_id == tox_message_id, self._corr))[0]
|
||||||
message.mark_as_sent()
|
message.mark_as_sent()
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
# wrapped C/C++ object of type QLabel has been deleted
|
util.log('Mark as sent ex: ' + str(ex))
|
||||||
LOG.error(f"Mark as sent: {ex!s}")
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
# Message deletion
|
# Message deletion
|
||||||
|
@ -1,12 +1,6 @@
|
|||||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
|
||||||
from PyQt5 import QtWidgets
|
from PyQt5 import QtWidgets
|
||||||
|
|
||||||
import utils.ui as util_ui
|
import utils.ui as util_ui
|
||||||
from wrapper.toxcore_enums_and_consts import *
|
|
||||||
|
|
||||||
global LOG
|
|
||||||
import logging
|
|
||||||
LOG = logging.getLogger('app')
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
# Builder
|
# Builder
|
||||||
@ -105,8 +99,8 @@ class BaseContactMenuGenerator:
|
|||||||
(copy_menu_builder
|
(copy_menu_builder
|
||||||
.with_name(util_ui.tr('Copy'))
|
.with_name(util_ui.tr('Copy'))
|
||||||
.with_action(util_ui.tr('Name'), lambda: main_screen.copy_text(self._contact.name))
|
.with_action(util_ui.tr('Name'), lambda: main_screen.copy_text(self._contact.name))
|
||||||
.with_action(util_ui.tr("Status message"), lambda: main_screen.copy_text(self._contact.status_message))
|
.with_action(util_ui.tr('Status message'), lambda: main_screen.copy_text(self._contact.status_message))
|
||||||
.with_action(util_ui.tr("Public key"), lambda: main_screen.copy_text(self._contact.tox_id))
|
.with_action(util_ui.tr('Public key'), lambda: main_screen.copy_text(self._contact.tox_id))
|
||||||
)
|
)
|
||||||
|
|
||||||
return copy_menu_builder
|
return copy_menu_builder
|
||||||
@ -114,11 +108,11 @@ class BaseContactMenuGenerator:
|
|||||||
def _generate_history_menu_builder(self, history_loader, main_screen):
|
def _generate_history_menu_builder(self, history_loader, main_screen):
|
||||||
history_menu_builder = ContactMenuBuilder()
|
history_menu_builder = ContactMenuBuilder()
|
||||||
(history_menu_builder
|
(history_menu_builder
|
||||||
.with_name(util_ui.tr("Chat history"))
|
.with_name(util_ui.tr('Chat history'))
|
||||||
.with_action(util_ui.tr("Clear history"), lambda: history_loader.clear_history(self._contact)
|
.with_action(util_ui.tr('Clear history'), lambda: history_loader.clear_history(self._contact)
|
||||||
or main_screen.messages.clear())
|
or main_screen.messages.clear())
|
||||||
.with_action(util_ui.tr("Export as text"), lambda: history_loader.export_history(self._contact))
|
.with_action(util_ui.tr('Export as text'), lambda: history_loader.export_history(self._contact))
|
||||||
.with_action(util_ui.tr("Export as HTML"), lambda: history_loader.export_history(self._contact, False))
|
.with_action(util_ui.tr('Export as HTML'), lambda: history_loader.export_history(self._contact, False))
|
||||||
)
|
)
|
||||||
|
|
||||||
return history_menu_builder
|
return history_menu_builder
|
||||||
@ -133,16 +127,16 @@ class FriendMenuGenerator(BaseContactMenuGenerator):
|
|||||||
groups_menu_builder = self._generate_groups_menu(contacts_manager, groups_service)
|
groups_menu_builder = self._generate_groups_menu(contacts_manager, groups_service)
|
||||||
|
|
||||||
allowed = self._contact.tox_id in settings['auto_accept_from_friends']
|
allowed = self._contact.tox_id in settings['auto_accept_from_friends']
|
||||||
auto = util_ui.tr("Disallow auto accept") if allowed else util_ui.tr('Allow auto accept')
|
auto = util_ui.tr('Disallow auto accept') if allowed else util_ui.tr('Allow auto accept')
|
||||||
|
|
||||||
builder = ContactMenuBuilder()
|
builder = ContactMenuBuilder()
|
||||||
menu = (builder
|
menu = (builder
|
||||||
.with_action(util_ui.tr("Set alias"), lambda: main_screen.set_alias(number))
|
.with_action(util_ui.tr('Set alias'), lambda: main_screen.set_alias(number))
|
||||||
.with_submenu(history_menu_builder)
|
.with_submenu(history_menu_builder)
|
||||||
.with_submenu(copy_menu_builder)
|
.with_submenu(copy_menu_builder)
|
||||||
.with_action(auto, lambda: main_screen.auto_accept(number, not allowed))
|
.with_action(auto, lambda: main_screen.auto_accept(number, not allowed))
|
||||||
.with_action(util_ui.tr("Remove friend"), lambda: main_screen.remove_friend(number))
|
.with_action(util_ui.tr('Remove friend'), lambda: main_screen.remove_friend(number))
|
||||||
.with_action(util_ui.tr("Block friend"), lambda: main_screen.block_friend(number))
|
.with_action(util_ui.tr('Block friend'), lambda: main_screen.block_friend(number))
|
||||||
.with_action(util_ui.tr('Notes'), lambda: main_screen.show_note(self._contact))
|
.with_action(util_ui.tr('Notes'), lambda: main_screen.show_note(self._contact))
|
||||||
.with_optional_submenu(plugins_menu_builder)
|
.with_optional_submenu(plugins_menu_builder)
|
||||||
.with_optional_submenu(groups_menu_builder)
|
.with_optional_submenu(groups_menu_builder)
|
||||||
@ -171,13 +165,11 @@ class FriendMenuGenerator(BaseContactMenuGenerator):
|
|||||||
|
|
||||||
def _generate_groups_menu(self, contacts_manager, groups_service):
|
def _generate_groups_menu(self, contacts_manager, groups_service):
|
||||||
chats = contacts_manager.get_group_chats()
|
chats = contacts_manager.get_group_chats()
|
||||||
LOG.debug(f"_generate_groups_menu len(chats)={len(chats)} or self._contact.status={self._contact.status}")
|
|
||||||
if not len(chats) or self._contact.status is None:
|
if not len(chats) or self._contact.status is None:
|
||||||
#? return None
|
return None
|
||||||
pass
|
|
||||||
groups_menu_builder = ContactMenuBuilder()
|
groups_menu_builder = ContactMenuBuilder()
|
||||||
(groups_menu_builder
|
(groups_menu_builder
|
||||||
.with_name(util_ui.tr("Invite to group"))
|
.with_name(util_ui.tr('Invite to group'))
|
||||||
.with_actions([(g.name, lambda: groups_service.invite_friend(self._contact.number, g.number)) for g in chats])
|
.with_actions([(g.name, lambda: groups_service.invite_friend(self._contact.number, g.number)) for g in chats])
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -192,26 +184,26 @@ class GroupMenuGenerator(BaseContactMenuGenerator):
|
|||||||
|
|
||||||
builder = ContactMenuBuilder()
|
builder = ContactMenuBuilder()
|
||||||
menu = (builder
|
menu = (builder
|
||||||
.with_action(util_ui.tr("Set alias"), lambda: main_screen.set_alias(number))
|
.with_action(util_ui.tr('Set alias'), lambda: main_screen.set_alias(number))
|
||||||
.with_submenu(copy_menu_builder)
|
.with_submenu(copy_menu_builder)
|
||||||
.with_submenu(history_menu_builder)
|
.with_submenu(history_menu_builder)
|
||||||
.with_optional_action(util_ui.tr("Manage group"),
|
.with_optional_action(util_ui.tr('Manage group'),
|
||||||
lambda: groups_service.show_group_management_screen(self._contact),
|
lambda: groups_service.show_group_management_screen(self._contact),
|
||||||
self._contact.is_self_founder())
|
self._contact.is_self_founder())
|
||||||
.with_optional_action(util_ui.tr("Group settings"),
|
.with_optional_action(util_ui.tr('Group settings'),
|
||||||
lambda: groups_service.show_group_settings_screen(self._contact),
|
lambda: groups_service.show_group_settings_screen(self._contact),
|
||||||
not self._contact.is_self_founder())
|
not self._contact.is_self_founder())
|
||||||
.with_optional_action(util_ui.tr("Set topic"),
|
.with_optional_action(util_ui.tr('Set topic'),
|
||||||
lambda: groups_service.set_group_topic(self._contact),
|
lambda: groups_service.set_group_topic(self._contact),
|
||||||
self._contact.is_self_moderator_or_founder())
|
self._contact.is_self_moderator_or_founder())
|
||||||
# .with_action(util_ui.tr("Bans list"),
|
.with_action(util_ui.tr('Bans list'),
|
||||||
# lambda: groups_service.show_bans_list(self._contact))
|
lambda: groups_service.show_bans_list(self._contact))
|
||||||
.with_action(util_ui.tr("Reconnect to group"),
|
.with_action(util_ui.tr('Reconnect to group'),
|
||||||
lambda: groups_service.reconnect_to_group(self._contact.number))
|
lambda: groups_service.reconnect_to_group(self._contact.number))
|
||||||
.with_optional_action(util_ui.tr("Disconnect from group"),
|
.with_optional_action(util_ui.tr('Disconnect from group'),
|
||||||
lambda: groups_service.disconnect_from_group(self._contact.number),
|
lambda: groups_service.disconnect_from_group(self._contact.number),
|
||||||
self._contact.status is not None)
|
self._contact.status is not None)
|
||||||
.with_action(util_ui.tr("Leave group"), lambda: groups_service.leave_group(self._contact.number))
|
.with_action(util_ui.tr('Leave group'), lambda: groups_service.leave_group(self._contact.number))
|
||||||
.with_action(util_ui.tr('Notes'), lambda: main_screen.show_note(self._contact))
|
.with_action(util_ui.tr('Notes'), lambda: main_screen.show_note(self._contact))
|
||||||
).build()
|
).build()
|
||||||
|
|
||||||
@ -226,10 +218,10 @@ class GroupPeerMenuGenerator(BaseContactMenuGenerator):
|
|||||||
|
|
||||||
builder = ContactMenuBuilder()
|
builder = ContactMenuBuilder()
|
||||||
menu = (builder
|
menu = (builder
|
||||||
.with_action(util_ui.tr("Set alias"), lambda: main_screen.set_alias(number))
|
.with_action(util_ui.tr('Set alias'), lambda: main_screen.set_alias(number))
|
||||||
.with_submenu(copy_menu_builder)
|
.with_submenu(copy_menu_builder)
|
||||||
.with_submenu(history_menu_builder)
|
.with_submenu(history_menu_builder)
|
||||||
.with_action(util_ui.tr("Quit chat"),
|
.with_action(util_ui.tr('Quit chat'),
|
||||||
lambda: contacts_manager.remove_group_peer(self._contact))
|
lambda: contacts_manager.remove_group_peer(self._contact))
|
||||||
.with_action(util_ui.tr('Notes'), lambda: main_screen.show_note(self._contact))
|
.with_action(util_ui.tr('Notes'), lambda: main_screen.show_note(self._contact))
|
||||||
).build()
|
).build()
|
||||||
|
@ -1,23 +1,5 @@
|
|||||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
|
||||||
|
|
||||||
import common.tox_save as tox_save
|
import common.tox_save as tox_save
|
||||||
|
|
||||||
global LOG
|
|
||||||
import logging
|
|
||||||
LOG = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
# callbacks can be called in any thread so were being careful
|
|
||||||
def LOG_ERROR(l): print('EROR< '+l)
|
|
||||||
def LOG_WARN(l): print('WARN< '+l)
|
|
||||||
def LOG_INFO(l):
|
|
||||||
bIsVerbose = hasattr(__builtins__, 'app') and app.oArgs.loglevel <= 20-1
|
|
||||||
if bIsVerbose: print('INFO< '+l)
|
|
||||||
def LOG_DEBUG(l):
|
|
||||||
bIsVerbose = hasattr(__builtins__, 'app') and app.oArgs.loglevel <= 10-1
|
|
||||||
if bIsVerbose: print('DBUG< '+l)
|
|
||||||
def LOG_TRACE(l):
|
|
||||||
bIsVerbose = hasattr(__builtins__, 'app') and app.oArgs.loglevel < 10-1
|
|
||||||
pass # print('TRACE+ '+l)
|
|
||||||
|
|
||||||
class ContactProvider(tox_save.ToxSave):
|
class ContactProvider(tox_save.ToxSave):
|
||||||
|
|
||||||
@ -33,11 +15,8 @@ class ContactProvider(tox_save.ToxSave):
|
|||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
def get_friend_by_number(self, friend_number):
|
def get_friend_by_number(self, friend_number):
|
||||||
try:
|
public_key = self._tox.friend_get_public_key(friend_number)
|
||||||
public_key = self._tox.friend_get_public_key(friend_number)
|
|
||||||
except Exception as e:
|
|
||||||
LOG_WARN(f"get_friend_by_number NO {friend_number} {e} ")
|
|
||||||
return None
|
|
||||||
return self.get_friend_by_public_key(public_key)
|
return self.get_friend_by_public_key(public_key)
|
||||||
|
|
||||||
def get_friend_by_public_key(self, public_key):
|
def get_friend_by_public_key(self, public_key):
|
||||||
@ -46,16 +25,11 @@ class ContactProvider(tox_save.ToxSave):
|
|||||||
return friend
|
return friend
|
||||||
friend = self._friend_factory.create_friend_by_public_key(public_key)
|
friend = self._friend_factory.create_friend_by_public_key(public_key)
|
||||||
self._add_to_cache(public_key, friend)
|
self._add_to_cache(public_key, friend)
|
||||||
LOG_INFO(f"get_friend_by_public_key ADDED {friend} ")
|
|
||||||
|
|
||||||
return friend
|
return friend
|
||||||
|
|
||||||
def get_all_friends(self):
|
def get_all_friends(self):
|
||||||
try:
|
friend_numbers = self._tox.self_get_friend_list()
|
||||||
friend_numbers = self._tox.self_get_friend_list()
|
|
||||||
except Exception as e:
|
|
||||||
LOG_WARN(f"get_all_friends NO {friend_numbers} {e} ")
|
|
||||||
return None
|
|
||||||
friends = map(lambda n: self.get_friend_by_number(n), friend_numbers)
|
friends = map(lambda n: self.get_friend_by_number(n), friend_numbers)
|
||||||
|
|
||||||
return list(friends)
|
return list(friends)
|
||||||
@ -65,70 +39,22 @@ class ContactProvider(tox_save.ToxSave):
|
|||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
def get_all_groups(self):
|
def get_all_groups(self):
|
||||||
"""from callbacks"""
|
group_numbers = range(self._tox.group_get_number_groups())
|
||||||
try:
|
groups = map(lambda n: self.get_group_by_number(n), group_numbers)
|
||||||
len_groups = self._tox.group_get_number_groups()
|
|
||||||
group_numbers = range(len_groups)
|
return list(groups)
|
||||||
except Exception as e:
|
|
||||||
return None
|
|
||||||
groups = list(map(lambda n: self.get_group_by_number(n), group_numbers))
|
|
||||||
# failsafe in case there are bogus None groups?
|
|
||||||
fgroups = list(filter(lambda x: x, groups))
|
|
||||||
if len(fgroups) != len_groups:
|
|
||||||
LOG_WARN(f"are there are bogus None groups in libtoxcore? {len(fgroups)} != {len_groups}")
|
|
||||||
for group_num in group_numbers:
|
|
||||||
group = self.get_group_by_number(group_num)
|
|
||||||
if group is None:
|
|
||||||
LOG_ERROR(f"there are bogus None groups in libtoxcore {group_num}!")
|
|
||||||
# fixme: do something
|
|
||||||
groups = fgroups
|
|
||||||
return groups
|
|
||||||
|
|
||||||
def get_group_by_number(self, group_number):
|
def get_group_by_number(self, group_number):
|
||||||
group = None
|
public_key = self._tox.group_get_chat_id(group_number)
|
||||||
try:
|
|
||||||
LOG_INFO(f"group_get_number {group_number} ")
|
|
||||||
# original code
|
|
||||||
chat_id = self._tox.group_get_chat_id(group_number)
|
|
||||||
if not chat_id:
|
|
||||||
LOG_ERROR(f"get_group_by_number NULL number ({group_number})")
|
|
||||||
else:
|
|
||||||
LOG_INFO(f"group_get_number {group_number} {chat_id}")
|
|
||||||
group = self.get_group_by_chat_id(chat_id)
|
|
||||||
if not group:
|
|
||||||
LOG_ERROR(f"get_group_by_number NULL group ({chat_id})")
|
|
||||||
if group is None:
|
|
||||||
|
|
||||||
LOG_WARN(f"get_group_by_number leaving ({group_number})")
|
return self.get_group_by_public_key(public_key)
|
||||||
#? iRet = self._tox.group_leave(group_number)
|
|
||||||
# invoke in main thread?
|
|
||||||
# self._contacts_manager.delete_group(group_number)
|
|
||||||
return group
|
|
||||||
except Exception as e:
|
|
||||||
LOG_WARN(f"group_get_number {group_number} {e}")
|
|
||||||
return None
|
|
||||||
|
|
||||||
def get_group_by_chat_id(self, chat_id):
|
|
||||||
group = self._get_contact_from_cache(chat_id)
|
|
||||||
if group is not None:
|
|
||||||
return group
|
|
||||||
group = self._group_factory.create_group_by_chat_id(chat_id)
|
|
||||||
if group is None:
|
|
||||||
LOG_ERROR(f"get_group_by_chat_id NULL chat_id={chat_id}")
|
|
||||||
else:
|
|
||||||
self._add_to_cache(chat_id, group)
|
|
||||||
|
|
||||||
return group
|
|
||||||
|
|
||||||
def get_group_by_public_key(self, public_key):
|
def get_group_by_public_key(self, public_key):
|
||||||
group = self._get_contact_from_cache(public_key)
|
group = self._get_contact_from_cache(public_key)
|
||||||
if group is not None:
|
if group is not None:
|
||||||
return group
|
return group
|
||||||
group = self._group_factory.create_group_by_public_key(public_key)
|
group = self._group_factory.create_group_by_public_key(public_key)
|
||||||
if group is None:
|
self._add_to_cache(public_key, group)
|
||||||
LOG_ERROR(f"get_group_by_public_key NULL group public_key={get_group_by_chat_id}")
|
|
||||||
else:
|
|
||||||
self._add_to_cache(public_key, group)
|
|
||||||
|
|
||||||
return group
|
return group
|
||||||
|
|
||||||
@ -141,8 +67,8 @@ class ContactProvider(tox_save.ToxSave):
|
|||||||
|
|
||||||
def get_group_peer_by_id(self, group, peer_id):
|
def get_group_peer_by_id(self, group, peer_id):
|
||||||
peer = group.get_peer_by_id(peer_id)
|
peer = group.get_peer_by_id(peer_id)
|
||||||
if peer:
|
|
||||||
return self._get_group_peer(group, peer)
|
return self._get_group_peer(group, peer)
|
||||||
|
|
||||||
def get_group_peer_by_public_key(self, group, public_key):
|
def get_group_peer_by_public_key(self, group, public_key):
|
||||||
peer = group.get_peer_by_public_key(public_key)
|
peer = group.get_peer_by_public_key(public_key)
|
||||||
|
@ -1,42 +1,9 @@
|
|||||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
|
||||||
|
|
||||||
import traceback
|
|
||||||
|
|
||||||
from contacts.friend import Friend
|
from contacts.friend import Friend
|
||||||
from contacts.group_chat import GroupChat
|
from contacts.group_chat import GroupChat
|
||||||
from messenger.messages import *
|
from messenger.messages import *
|
||||||
from common.tox_save import ToxSave
|
from common.tox_save import ToxSave
|
||||||
from contacts.group_peer_contact import GroupPeerContact
|
from contacts.group_peer_contact import GroupPeerContact
|
||||||
from groups.group_peer import GroupChatPeer
|
|
||||||
|
|
||||||
# LOG=util.log
|
|
||||||
global LOG
|
|
||||||
import logging
|
|
||||||
LOG = logging.getLogger('app.'+__name__)
|
|
||||||
|
|
||||||
def LOG_ERROR(l): print('ERROR_: '+l)
|
|
||||||
def LOG_WARN(l): print('WARN_: '+l)
|
|
||||||
def LOG_INFO(l): print('INFO_: '+l)
|
|
||||||
def LOG_DEBUG(l): print('DEBUG_: '+l)
|
|
||||||
def LOG_TRACE(l): pass # print('TRACE+ '+l)
|
|
||||||
|
|
||||||
|
|
||||||
UINT32_MAX = 2 ** 32 -1
|
|
||||||
|
|
||||||
def set_contact_kind(contact):
|
|
||||||
bInvite = len(contact.name) == TOX_PUBLIC_KEY_SIZE * 2 and \
|
|
||||||
contact.status_message == ''
|
|
||||||
bBot = not bInvite and contact.name.lower().endswith(' bot')
|
|
||||||
if type(contact) == Friend and bInvite:
|
|
||||||
contact._kind = 'invite'
|
|
||||||
elif type(contact) == Friend and bBot:
|
|
||||||
contact._kind = 'bot'
|
|
||||||
elif type(contact) == Friend:
|
|
||||||
contact._kind = 'friend'
|
|
||||||
elif type(contact) == GroupChat:
|
|
||||||
contact._kind = 'group'
|
|
||||||
elif type(contact) == GroupChatPeer:
|
|
||||||
contact._kind = 'grouppeer'
|
|
||||||
|
|
||||||
class ContactsManager(ToxSave):
|
class ContactsManager(ToxSave):
|
||||||
"""
|
"""
|
||||||
@ -48,14 +15,12 @@ class ContactsManager(ToxSave):
|
|||||||
super().__init__(tox)
|
super().__init__(tox)
|
||||||
self._settings = settings
|
self._settings = settings
|
||||||
self._screen = screen
|
self._screen = screen
|
||||||
self._ms = screen
|
|
||||||
self._profile_manager = profile_manager
|
self._profile_manager = profile_manager
|
||||||
self._contact_provider = contact_provider
|
self._contact_provider = contact_provider
|
||||||
self._tox_dns = tox_dns
|
self._tox_dns = tox_dns
|
||||||
self._messages_items_factory = messages_items_factory
|
self._messages_items_factory = messages_items_factory
|
||||||
self._messages = screen.messages
|
self._messages = screen.messages
|
||||||
self._contacts = []
|
self._contacts, self._active_contact = [], -1
|
||||||
self._active_contact = -1
|
|
||||||
self._active_contact_changed = Event()
|
self._active_contact_changed = Event()
|
||||||
self._sorting = settings['sorting']
|
self._sorting = settings['sorting']
|
||||||
self._filter_string = ''
|
self._filter_string = ''
|
||||||
@ -63,11 +28,6 @@ class ContactsManager(ToxSave):
|
|||||||
self._history = history
|
self._history = history
|
||||||
self._load_contacts()
|
self._load_contacts()
|
||||||
|
|
||||||
def _log(self, s):
|
|
||||||
try:
|
|
||||||
self._ms._log(s)
|
|
||||||
except: pass
|
|
||||||
|
|
||||||
def get_contact(self, num):
|
def get_contact(self, num):
|
||||||
if num < 0 or num >= len(self._contacts):
|
if num < 0 or num >= len(self._contacts):
|
||||||
return None
|
return None
|
||||||
@ -93,16 +53,6 @@ class ContactsManager(ToxSave):
|
|||||||
return self.get_curr_contact().number == group_number
|
return self.get_curr_contact().number == group_number
|
||||||
|
|
||||||
def is_contact_active(self, contact):
|
def is_contact_active(self, contact):
|
||||||
if self._active_contact == -1:
|
|
||||||
# LOG.debug("No self._active_contact")
|
|
||||||
return False
|
|
||||||
if self._active_contact >= len(self._contacts):
|
|
||||||
LOG.warn(f"ERROR _active_contact={self._active_contact} >= contacts len={len(self._contacts)}")
|
|
||||||
return False
|
|
||||||
if not self._contacts[self._active_contact]:
|
|
||||||
LOG.warn(f"ERROR NULL {self._contacts[self._active_contact]} {contact.tox_id}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
return self._contacts[self._active_contact].tox_id == contact.tox_id
|
return self._contacts[self._active_contact].tox_id == contact.tox_id
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
@ -145,12 +95,11 @@ class ContactsManager(ToxSave):
|
|||||||
current_contact.remove_messages_widgets() # TODO: if required
|
current_contact.remove_messages_widgets() # TODO: if required
|
||||||
self._unsubscribe_from_events(current_contact)
|
self._unsubscribe_from_events(current_contact)
|
||||||
|
|
||||||
if self._active_contact >= 0 and self._active_contact != value:
|
if self._active_contact + 1 and self._active_contact != value:
|
||||||
try:
|
try:
|
||||||
current_contact.curr_text = self._screen.messageEdit.toPlainText()
|
current_contact.curr_text = self._screen.messageEdit.toPlainText()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
# IndexError: list index out of range
|
|
||||||
contact = self._contacts[value]
|
contact = self._contacts[value]
|
||||||
self._subscribe_to_events(contact)
|
self._subscribe_to_events(contact)
|
||||||
contact.remove_invalid_unsent_files()
|
contact.remove_invalid_unsent_files()
|
||||||
@ -180,9 +129,9 @@ class ContactsManager(ToxSave):
|
|||||||
self._set_current_contact_data(contact)
|
self._set_current_contact_data(contact)
|
||||||
self._active_contact_changed(contact)
|
self._active_contact_changed(contact)
|
||||||
except Exception as ex: # no friend found. ignore
|
except Exception as ex: # no friend found. ignore
|
||||||
LOG.warn(f"no friend found. Friend value: {value!s}")
|
util.log('Friend value: ' + str(value))
|
||||||
LOG.error('in set active: ' + str(ex))
|
util.log('Error in set active: ' + str(ex))
|
||||||
# gulp raise
|
raise
|
||||||
|
|
||||||
active_contact = property(get_active, set_active)
|
active_contact = property(get_active, set_active)
|
||||||
|
|
||||||
@ -212,17 +161,13 @@ class ContactsManager(ToxSave):
|
|||||||
"""
|
"""
|
||||||
Filtration of friends list
|
Filtration of friends list
|
||||||
:param sorting: 0 - no sorting, 1 - online only, 2 - online first, 3 - by name,
|
:param sorting: 0 - no sorting, 1 - online only, 2 - online first, 3 - by name,
|
||||||
4 - online and by name, 5 - online first and by name, 6 kind
|
4 - online and by name, 5 - online first and by name
|
||||||
:param filter_str: show contacts which name contains this substring
|
:param filter_str: show contacts which name contains this substring
|
||||||
"""
|
"""
|
||||||
filter_str = filter_str.lower()
|
filter_str = filter_str.lower()
|
||||||
current_contact = self.get_curr_contact()
|
current_contact = self.get_curr_contact()
|
||||||
|
|
||||||
for index, contact in enumerate(self._contacts):
|
if sorting > 5 or sorting < 0:
|
||||||
if not contact._kind:
|
|
||||||
set_contact_kind(contact)
|
|
||||||
|
|
||||||
if sorting > 6 or sorting < 0:
|
|
||||||
sorting = 0
|
sorting = 0
|
||||||
|
|
||||||
if sorting in (1, 2, 4, 5): # online first
|
if sorting in (1, 2, 4, 5): # online first
|
||||||
@ -238,23 +183,14 @@ class ContactsManager(ToxSave):
|
|||||||
part2 = sorted(part2, key=key_lambda)
|
part2 = sorted(part2, key=key_lambda)
|
||||||
self._contacts = part1 + part2
|
self._contacts = part1 + part2
|
||||||
elif sorting == 0:
|
elif sorting == 0:
|
||||||
# AttributeError: 'NoneType' object has no attribute 'number'
|
|
||||||
for (i, contact) in enumerate(self._contacts):
|
|
||||||
if contact is None or not hasattr(contact, 'number'):
|
|
||||||
LOG.error(f"Contact {i} is None or not hasattr 'number'")
|
|
||||||
del self._contacts[i]
|
|
||||||
continue
|
|
||||||
contacts = sorted(self._contacts, key=lambda c: c.number)
|
contacts = sorted(self._contacts, key=lambda c: c.number)
|
||||||
friends = filter(lambda c: type(c) is Friend, contacts)
|
friends = filter(lambda c: type(c) is Friend, contacts)
|
||||||
groups = filter(lambda c: type(c) is GroupChat, contacts)
|
groups = filter(lambda c: type(c) is GroupChat, contacts)
|
||||||
group_peers = filter(lambda c: type(c) is GroupPeerContact, contacts)
|
group_peers = filter(lambda c: type(c) is GroupPeerContact, contacts)
|
||||||
self._contacts = list(friends) + list(groups) + list(group_peers)
|
self._contacts = list(friends) + list(groups) + list(group_peers)
|
||||||
elif sorting == 6:
|
|
||||||
self._contacts = sorted(self._contacts, key=lambda x: x._kind)
|
|
||||||
else:
|
else:
|
||||||
self._contacts = sorted(self._contacts, key=lambda x: x.name.lower())
|
self._contacts = sorted(self._contacts, key=lambda x: x.name.lower())
|
||||||
|
|
||||||
|
|
||||||
# change item widgets
|
# change item widgets
|
||||||
for index, contact in enumerate(self._contacts):
|
for index, contact in enumerate(self._contacts):
|
||||||
list_item = self._screen.friends_list.item(index)
|
list_item = self._screen.friends_list.item(index)
|
||||||
@ -299,15 +235,10 @@ class ContactsManager(ToxSave):
|
|||||||
def get_or_create_group_peer_contact(self, group_number, peer_id):
|
def get_or_create_group_peer_contact(self, group_number, peer_id):
|
||||||
group = self.get_group_by_number(group_number)
|
group = self.get_group_by_number(group_number)
|
||||||
peer = group.get_peer_by_id(peer_id)
|
peer = group.get_peer_by_id(peer_id)
|
||||||
if peer: # broken?
|
if not self.check_if_contact_exists(peer.public_key):
|
||||||
if not hasattr(peer, 'public_key') or not peer.public_key:
|
self.add_group_peer(group, peer)
|
||||||
LOG.error(f'no peer public_key ' + repr(dir(peer)))
|
|
||||||
else:
|
return self.get_contact_by_tox_id(peer.public_key)
|
||||||
if not self.check_if_contact_exists(peer.public_key):
|
|
||||||
self.add_group_peer(group, peer)
|
|
||||||
return self.get_contact_by_tox_id(peer.public_key)
|
|
||||||
else:
|
|
||||||
LOG.warn(f'no peer group_number={group_number} peer_id={peer_id}')
|
|
||||||
|
|
||||||
def check_if_contact_exists(self, tox_id):
|
def check_if_contact_exists(self, tox_id):
|
||||||
return any(filter(lambda c: c.tox_id == tox_id, self._contacts))
|
return any(filter(lambda c: c.tox_id == tox_id, self._contacts))
|
||||||
@ -368,10 +299,7 @@ class ContactsManager(ToxSave):
|
|||||||
"""
|
"""
|
||||||
friend = self._contacts[num]
|
friend = self._contacts[num]
|
||||||
self._cleanup_contact_data(friend)
|
self._cleanup_contact_data(friend)
|
||||||
try:
|
self._tox.friend_delete(friend.number)
|
||||||
self._tox.friend_delete(friend.number)
|
|
||||||
except Exception as e:
|
|
||||||
LOG.warn(f"'There was no friend with the given friend number {e}")
|
|
||||||
self._delete_contact(num)
|
self._delete_contact(num)
|
||||||
|
|
||||||
def add_friend(self, tox_id):
|
def add_friend(self, tox_id):
|
||||||
@ -387,7 +315,7 @@ class ContactsManager(ToxSave):
|
|||||||
Block user with specified tox id (or public key) - delete from friends list and ignore friend requests
|
Block user with specified tox id (or public key) - delete from friends list and ignore friend requests
|
||||||
"""
|
"""
|
||||||
tox_id = tox_id[:TOX_PUBLIC_KEY_SIZE * 2]
|
tox_id = tox_id[:TOX_PUBLIC_KEY_SIZE * 2]
|
||||||
if tox_id == self._tox.self_get_address()[:TOX_PUBLIC_KEY_SIZE * 2]:
|
if tox_id == self._tox.self_get_address[:TOX_PUBLIC_KEY_SIZE * 2]:
|
||||||
return
|
return
|
||||||
if tox_id not in self._settings['blocked']:
|
if tox_id not in self._settings['blocked']:
|
||||||
self._settings['blocked'].append(tox_id)
|
self._settings['blocked'].append(tox_id)
|
||||||
@ -419,20 +347,13 @@ class ContactsManager(ToxSave):
|
|||||||
return list(filter(lambda c: type(c) is GroupChat, self._contacts))
|
return list(filter(lambda c: type(c) is GroupChat, self._contacts))
|
||||||
|
|
||||||
def add_group(self, group_number):
|
def add_group(self, group_number):
|
||||||
index = len(self._contacts)
|
|
||||||
group = self._contact_provider.get_group_by_number(group_number)
|
group = self._contact_provider.get_group_by_number(group_number)
|
||||||
# group num >= 0?
|
index = len(self._contacts)
|
||||||
if group is None:
|
self._contacts.append(group)
|
||||||
LOG.warn(f"CM.add_group: NO group {group_number}")
|
group.reset_avatar(self._settings['identicons'])
|
||||||
else:
|
self._save_profile()
|
||||||
LOG.info(f"CM.add_group: Adding group {group._name}")
|
self.set_active(index)
|
||||||
self._contacts.append(group)
|
self.update_filtration()
|
||||||
LOG.info(f"contacts_manager.add_group: saving profile")
|
|
||||||
self._save_profile()
|
|
||||||
group.reset_avatar(self._settings['identicons'])
|
|
||||||
LOG.info(f"contacts_manager.add_group: setting active")
|
|
||||||
self.set_active(index)
|
|
||||||
self.update_filtration()
|
|
||||||
|
|
||||||
def delete_group(self, group_number):
|
def delete_group(self, group_number):
|
||||||
group = self.get_group_by_number(group_number)
|
group = self.get_group_by_number(group_number)
|
||||||
@ -448,25 +369,22 @@ class ContactsManager(ToxSave):
|
|||||||
contact = self._contact_provider.get_group_peer_by_id(group, peer.id)
|
contact = self._contact_provider.get_group_peer_by_id(group, peer.id)
|
||||||
if self.check_if_contact_exists(contact.tox_id):
|
if self.check_if_contact_exists(contact.tox_id):
|
||||||
return
|
return
|
||||||
contact._kind = 'grouppeer'
|
|
||||||
self._contacts.append(contact)
|
self._contacts.append(contact)
|
||||||
contact.reset_avatar(self._settings['identicons'])
|
contact.reset_avatar(self._settings['identicons'])
|
||||||
self._save_profile()
|
self._save_profile()
|
||||||
|
|
||||||
def remove_group_peer_by_id(self, group, peer_id):
|
def remove_group_peer_by_id(self, group, peer_id):
|
||||||
peer = group.get_peer_by_id(peer_id)
|
peer = group.get_peer_by_id(peer_id)
|
||||||
if peer: # broken
|
if not self.check_if_contact_exists(peer.public_key):
|
||||||
if not self.check_if_contact_exists(peer.public_key):
|
return
|
||||||
return
|
contact = self.get_contact_by_tox_id(peer.public_key)
|
||||||
contact = self.get_contact_by_tox_id(peer.public_key)
|
self.remove_group_peer(contact)
|
||||||
self.remove_group_peer(contact)
|
|
||||||
|
|
||||||
def remove_group_peer(self, group_peer_contact):
|
def remove_group_peer(self, group_peer_contact):
|
||||||
contact = self.get_contact_by_tox_id(group_peer_contact.tox_id)
|
contact = self.get_contact_by_tox_id(group_peer_contact.tox_id)
|
||||||
if contact:
|
self._cleanup_contact_data(contact)
|
||||||
self._cleanup_contact_data(contact)
|
num = self._contacts.index(contact)
|
||||||
num = self._contacts.index(contact)
|
self._delete_contact(num)
|
||||||
self._delete_contact(num)
|
|
||||||
|
|
||||||
def get_gc_peer_name(self, name):
|
def get_gc_peer_name(self, name):
|
||||||
group = self.get_curr_contact()
|
group = self.get_curr_contact()
|
||||||
@ -488,46 +406,34 @@ class ContactsManager(ToxSave):
|
|||||||
# Friend requests
|
# Friend requests
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
def send_friend_request(self, sToxPkOrId, message):
|
def send_friend_request(self, tox_id, message):
|
||||||
"""
|
"""
|
||||||
Function tries to send request to contact with specified id
|
Function tries to send request to contact with specified id
|
||||||
:param sToxPkOrId: id of new contact or tox dns 4 value
|
:param tox_id: id of new contact or tox dns 4 value
|
||||||
:param message: additional message
|
:param message: additional message
|
||||||
:return: True on success else error string
|
:return: True on success else error string
|
||||||
"""
|
"""
|
||||||
retval = ''
|
|
||||||
try:
|
try:
|
||||||
message = message or 'Hello! Add me to your contact list please'
|
message = message or 'Hello! Add me to your contact list please'
|
||||||
if len(sToxPkOrId) == TOX_PUBLIC_KEY_SIZE * 2: # public key
|
if '@' in tox_id: # value like groupbot@toxme.io
|
||||||
self.add_friend(sToxPkOrId)
|
tox_id = self._tox_dns.lookup(tox_id)
|
||||||
title = 'Friend added'
|
if tox_id is None:
|
||||||
text = 'Friend added without sending friend request'
|
raise Exception('TOX DNS lookup failed')
|
||||||
|
if len(tox_id) == TOX_PUBLIC_KEY_SIZE * 2: # public key
|
||||||
|
self.add_friend(tox_id)
|
||||||
|
title = util_ui.tr('Friend added')
|
||||||
|
text = util_ui.tr('Friend added without sending friend request')
|
||||||
|
util_ui.message_box(text, title)
|
||||||
else:
|
else:
|
||||||
num = self._tox.friend_add(sToxPkOrId, message.encode('utf-8'))
|
self._tox.friend_add(tox_id, message.encode('utf-8'))
|
||||||
if num < UINT32_MAX:
|
tox_id = tox_id[:TOX_PUBLIC_KEY_SIZE * 2]
|
||||||
tox_pk = sToxPkOrId[:TOX_PUBLIC_KEY_SIZE * 2]
|
self._add_friend(tox_id)
|
||||||
self._add_friend(tox_pk)
|
self.update_filtration()
|
||||||
self.update_filtration()
|
self.save_profile()
|
||||||
title = 'Friend added'
|
return True
|
||||||
text = 'Friend added by sending friend request'
|
|
||||||
self.save_profile()
|
|
||||||
retval = True
|
|
||||||
else:
|
|
||||||
title = 'Friend failed'
|
|
||||||
text = 'Friend failed sending friend request'
|
|
||||||
retval = text
|
|
||||||
|
|
||||||
except Exception as ex: # wrong data
|
except Exception as ex: # wrong data
|
||||||
title = 'Friend add exception'
|
util.log('Friend request failed with ' + str(ex))
|
||||||
text = 'Friend request exception with ' + str(ex)
|
return str(ex)
|
||||||
self._log(text)
|
|
||||||
LOG.exception(text)
|
|
||||||
LOG.warn(f"DELETE {sToxPkOrId} ?")
|
|
||||||
retval = str(ex)
|
|
||||||
title = util_ui.tr(title)
|
|
||||||
text = util_ui.tr(text)
|
|
||||||
util_ui.message_box(text, title)
|
|
||||||
return retval
|
|
||||||
|
|
||||||
def process_friend_request(self, tox_id, message):
|
def process_friend_request(self, tox_id, message):
|
||||||
"""
|
"""
|
||||||
@ -545,7 +451,7 @@ class ContactsManager(ToxSave):
|
|||||||
data = self._tox.get_savedata()
|
data = self._tox.get_savedata()
|
||||||
self._profile_manager.save_profile(data)
|
self._profile_manager.save_profile(data)
|
||||||
except Exception as ex: # something is wrong
|
except Exception as ex: # something is wrong
|
||||||
LOG.error('Accept friend request failed! ' + str(ex))
|
util.log('Accept friend request failed! ' + str(ex))
|
||||||
|
|
||||||
def can_send_typing_notification(self):
|
def can_send_typing_notification(self):
|
||||||
return self._settings['typing_notifications'] and not self.is_active_a_group_chat_peer()
|
return self._settings['typing_notifications'] and not self.is_active_a_group_chat_peer()
|
||||||
@ -561,17 +467,9 @@ class ContactsManager(ToxSave):
|
|||||||
|
|
||||||
def update_groups_numbers(self):
|
def update_groups_numbers(self):
|
||||||
groups = self._contact_provider.get_all_groups()
|
groups = self._contact_provider.get_all_groups()
|
||||||
LOG.info(f"update_groups_numbers len(groups)={len(groups)}")
|
|
||||||
# Thread 76 "ToxIterateThrea" received signal SIGSEGV, Segmentation fault.
|
|
||||||
for i in range(len(groups)):
|
for i in range(len(groups)):
|
||||||
chat_id = self._tox.group_get_chat_id(i)
|
chat_id = self._tox.group_get_chat_id(i)
|
||||||
if not chat_id:
|
|
||||||
LOG.warn(f"update_groups_numbers {i} chat_id")
|
|
||||||
continue
|
|
||||||
group = self.get_contact_by_tox_id(chat_id)
|
group = self.get_contact_by_tox_id(chat_id)
|
||||||
if not group:
|
|
||||||
LOG.warn(f"update_groups_numbers {i} group")
|
|
||||||
continue
|
|
||||||
group.number = i
|
group.number = i
|
||||||
self.update_filtration()
|
self.update_filtration()
|
||||||
|
|
||||||
@ -589,15 +487,7 @@ class ContactsManager(ToxSave):
|
|||||||
self._load_groups()
|
self._load_groups()
|
||||||
if len(self._contacts):
|
if len(self._contacts):
|
||||||
self.set_active(0)
|
self.set_active(0)
|
||||||
# filter(lambda c: not c.has_avatar(), self._contacts)
|
for contact in filter(lambda c: not c.has_avatar(), self._contacts):
|
||||||
for (i, contact) in enumerate(self._contacts):
|
|
||||||
if contact is None:
|
|
||||||
LOG.warn(f"_load_contacts NULL contact {i}")
|
|
||||||
LOG.info(f"_load_contacts deleting NULL {self._contacts[i]}")
|
|
||||||
del self._contacts[i]
|
|
||||||
#? self.save_profile()
|
|
||||||
continue
|
|
||||||
if contact.has_avatar(): continue
|
|
||||||
contact.reset_avatar(self._settings['identicons'])
|
contact.reset_avatar(self._settings['identicons'])
|
||||||
self.update_filtration()
|
self.update_filtration()
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from common.tox_save import ToxSave
|
|
||||||
from contacts.friend import Friend
|
from contacts.friend import Friend
|
||||||
|
from common.tox_save import ToxSave
|
||||||
|
|
||||||
|
|
||||||
class FriendFactory(ToxSave):
|
class FriendFactory(ToxSave):
|
||||||
@ -13,21 +13,21 @@ class FriendFactory(ToxSave):
|
|||||||
|
|
||||||
def create_friend_by_public_key(self, public_key):
|
def create_friend_by_public_key(self, public_key):
|
||||||
friend_number = self._tox.friend_by_public_key(public_key)
|
friend_number = self._tox.friend_by_public_key(public_key)
|
||||||
|
|
||||||
return self.create_friend_by_number(friend_number)
|
return self.create_friend_by_number(friend_number)
|
||||||
|
|
||||||
def create_friend_by_number(self, friend_number):
|
def create_friend_by_number(self, friend_number):
|
||||||
aliases = self._settings['friends_aliases']
|
aliases = self._settings['friends_aliases']
|
||||||
sToxPk = self._tox.friend_get_public_key(friend_number)
|
tox_id = self._tox.friend_get_public_key(friend_number)
|
||||||
assert sToxPk, sToxPk
|
|
||||||
try:
|
try:
|
||||||
alias = list(filter(lambda x: x[0] == sToxPk, aliases))[0][1]
|
alias = list(filter(lambda x: x[0] == tox_id, aliases))[0][1]
|
||||||
except:
|
except:
|
||||||
alias = ''
|
alias = ''
|
||||||
item = self._create_friend_item()
|
item = self._create_friend_item()
|
||||||
name = alias or self._tox.friend_get_name(friend_number) or sToxPk
|
name = alias or self._tox.friend_get_name(friend_number) or tox_id
|
||||||
status_message = self._tox.friend_get_status_message(friend_number)
|
status_message = self._tox.friend_get_status_message(friend_number)
|
||||||
message_getter = self._db.messages_getter(sToxPk)
|
message_getter = self._db.messages_getter(tox_id)
|
||||||
friend = Friend(self._profile_manager, message_getter, friend_number, name, status_message, item, sToxPk)
|
friend = Friend(self._profile_manager, message_getter, friend_number, name, status_message, item, tox_id)
|
||||||
friend.set_alias(alias)
|
friend.set_alias(alias)
|
||||||
|
|
||||||
return friend
|
return friend
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
|
||||||
|
|
||||||
from contacts import contact
|
from contacts import contact
|
||||||
from contacts.contact_menu import GroupMenuGenerator
|
from contacts.contact_menu import GroupMenuGenerator
|
||||||
import utils.util as util
|
import utils.util as util
|
||||||
@ -8,14 +6,6 @@ from wrapper import toxcore_enums_and_consts as constants
|
|||||||
from common.tox_save import ToxSave
|
from common.tox_save import ToxSave
|
||||||
from groups.group_ban import GroupBan
|
from groups.group_ban import GroupBan
|
||||||
|
|
||||||
global LOG
|
|
||||||
import logging
|
|
||||||
LOG = logging.getLogger(__name__)
|
|
||||||
def LOG_ERROR(l): print('ERROR_: '+l)
|
|
||||||
def LOG_WARN(l): print('WARN_: '+l)
|
|
||||||
def LOG_INFO(l): print('INFO_: '+l)
|
|
||||||
def LOG_DEBUG(l): print('DEBUG_: '+l)
|
|
||||||
def LOG_TRACE(l): pass # print('TRACE+ '+l)
|
|
||||||
|
|
||||||
class GroupChat(contact.Contact, ToxSave):
|
class GroupChat(contact.Contact, ToxSave):
|
||||||
|
|
||||||
@ -83,12 +73,6 @@ class GroupChat(contact.Contact, ToxSave):
|
|||||||
return self.get_self_role() == constants.TOX_GROUP_ROLE['FOUNDER']
|
return self.get_self_role() == constants.TOX_GROUP_ROLE['FOUNDER']
|
||||||
|
|
||||||
def add_peer(self, peer_id, is_current_user=False):
|
def add_peer(self, peer_id, is_current_user=False):
|
||||||
"called from callbacks"
|
|
||||||
if peer_id > self._peers_limit:
|
|
||||||
LOG_WARN(f"add_peer id={peer_id} > {self._peers_limit}")
|
|
||||||
return
|
|
||||||
|
|
||||||
LOG_TRACE(f"add_peer id={peer_id}")
|
|
||||||
peer = GroupChatPeer(peer_id,
|
peer = GroupChatPeer(peer_id,
|
||||||
self._tox.group_peer_get_name(self._number, peer_id),
|
self._tox.group_peer_get_name(self._number, peer_id),
|
||||||
self._tox.group_peer_get_status(self._number, peer_id),
|
self._tox.group_peer_get_status(self._number, peer_id),
|
||||||
@ -102,40 +86,25 @@ class GroupChat(contact.Contact, ToxSave):
|
|||||||
self.remove_all_peers_except_self()
|
self.remove_all_peers_except_self()
|
||||||
else:
|
else:
|
||||||
peer = self.get_peer_by_id(peer_id)
|
peer = self.get_peer_by_id(peer_id)
|
||||||
if peer: # broken
|
self._peers.remove(peer)
|
||||||
self._peers.remove(peer)
|
|
||||||
else:
|
|
||||||
LOG_WARN(f"remove_peer empty peers for {peer_id}")
|
|
||||||
|
|
||||||
def get_peer_by_id(self, peer_id):
|
def get_peer_by_id(self, peer_id):
|
||||||
peers = list(filter(lambda p: p.id == peer_id, self._peers))
|
peers = list(filter(lambda p: p.id == peer_id, self._peers))
|
||||||
if peers:
|
|
||||||
return peers[0]
|
return peers[0]
|
||||||
else:
|
|
||||||
LOG_WARN(f"get_peer_by_id empty peers for {peer_id}")
|
|
||||||
return []
|
|
||||||
|
|
||||||
def get_peer_by_public_key(self, public_key):
|
def get_peer_by_public_key(self, public_key):
|
||||||
peers = list(filter(lambda p: p.public_key == public_key, self._peers))
|
peers = list(filter(lambda p: p.public_key == public_key, self._peers))
|
||||||
# DEBUGc: group_moderation #0 mod_id=4294967295 event_type=3
|
|
||||||
# WARN_: get_peer_by_id empty peers for 4294967295
|
return peers[0]
|
||||||
if peers:
|
|
||||||
return peers[0]
|
|
||||||
else:
|
|
||||||
LOG_WARN(f"get_peer_by_public_key empty peers for {public_key}")
|
|
||||||
return []
|
|
||||||
|
|
||||||
def remove_all_peers_except_self(self):
|
def remove_all_peers_except_self(self):
|
||||||
self._peers = self._peers[:1]
|
self._peers = self._peers[:1]
|
||||||
|
|
||||||
def get_peers_names(self):
|
def get_peers_names(self):
|
||||||
peers_names = map(lambda p: p.name, self._peers)
|
peers_names = map(lambda p: p.name, self._peers)
|
||||||
if peers_names: # broken
|
|
||||||
return list(peers_names)
|
return list(peers_names)
|
||||||
else:
|
|
||||||
LOG_WARN(f"get_peers_names empty peers")
|
|
||||||
#? broken
|
|
||||||
return []
|
|
||||||
|
|
||||||
def get_peers(self):
|
def get_peers(self):
|
||||||
return self._peers[:]
|
return self._peers[:]
|
||||||
@ -143,17 +112,16 @@ class GroupChat(contact.Contact, ToxSave):
|
|||||||
peers = property(get_peers)
|
peers = property(get_peers)
|
||||||
|
|
||||||
def get_bans(self):
|
def get_bans(self):
|
||||||
return []
|
ban_ids = self._tox.group_ban_get_list(self._number)
|
||||||
# ban_ids = self._tox.group_ban_get_list(self._number)
|
bans = []
|
||||||
# bans = []
|
for ban_id in ban_ids:
|
||||||
# for ban_id in ban_ids:
|
ban = GroupBan(ban_id,
|
||||||
# ban = GroupBan(ban_id,
|
self._tox.group_ban_get_target(self._number, ban_id),
|
||||||
# self._tox.group_ban_get_target(self._number, ban_id),
|
self._tox.group_ban_get_time_set(self._number, ban_id))
|
||||||
# self._tox.group_ban_get_time_set(self._number, ban_id))
|
bans.append(ban)
|
||||||
# bans.append(ban)
|
|
||||||
#
|
return bans
|
||||||
# return bans
|
|
||||||
#
|
|
||||||
bans = property(get_bans)
|
bans = property(get_bans)
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -1,12 +1,7 @@
|
|||||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
|
||||||
|
|
||||||
from contacts.group_chat import GroupChat
|
from contacts.group_chat import GroupChat
|
||||||
from common.tox_save import ToxSave
|
from common.tox_save import ToxSave
|
||||||
import wrapper.toxcore_enums_and_consts as constants
|
import wrapper.toxcore_enums_and_consts as constants
|
||||||
|
|
||||||
global LOG
|
|
||||||
import logging
|
|
||||||
LOG = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
class GroupFactory(ToxSave):
|
class GroupFactory(ToxSave):
|
||||||
|
|
||||||
@ -17,15 +12,12 @@ class GroupFactory(ToxSave):
|
|||||||
self._db = db
|
self._db = db
|
||||||
self._items_factory = items_factory
|
self._items_factory = items_factory
|
||||||
|
|
||||||
def create_group_by_chat_id(self, chat_id):
|
|
||||||
return self.create_group_by_public_key(chat_id)
|
|
||||||
|
|
||||||
def create_group_by_public_key(self, public_key):
|
def create_group_by_public_key(self, public_key):
|
||||||
group_number = self._get_group_number_by_chat_id(public_key)
|
group_number = self._get_group_number_by_chat_id(public_key)
|
||||||
|
|
||||||
return self.create_group_by_number(group_number)
|
return self.create_group_by_number(group_number)
|
||||||
|
|
||||||
def create_group_by_number(self, group_number):
|
def create_group_by_number(self, group_number):
|
||||||
LOG.info(f"create_group_by_number {group_number}")
|
|
||||||
aliases = self._settings['friends_aliases']
|
aliases = self._settings['friends_aliases']
|
||||||
tox_id = self._tox.group_get_chat_id(group_number)
|
tox_id = self._tox.group_get_chat_id(group_number)
|
||||||
try:
|
try:
|
||||||
|
@ -1,15 +1,9 @@
|
|||||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
|
||||||
from contacts import basecontact
|
from contacts import basecontact
|
||||||
import random
|
import random
|
||||||
import threading
|
import threading
|
||||||
import common.tox_save as tox_save
|
import common.tox_save as tox_save
|
||||||
from middleware.threads import invoke_in_main_thread
|
from middleware.threads import invoke_in_main_thread
|
||||||
|
|
||||||
iUMAXINT = 4294967295
|
|
||||||
|
|
||||||
global LOG
|
|
||||||
import logging
|
|
||||||
LOG = logging.getLogger('app.'+__name__)
|
|
||||||
|
|
||||||
class Profile(basecontact.BaseContact, tox_save.ToxSave):
|
class Profile(basecontact.BaseContact, tox_save.ToxSave):
|
||||||
"""
|
"""
|
||||||
@ -20,7 +14,6 @@ class Profile(basecontact.BaseContact, tox_save.ToxSave):
|
|||||||
:param tox: tox instance
|
:param tox: tox instance
|
||||||
:param screen: ref to main screen
|
:param screen: ref to main screen
|
||||||
"""
|
"""
|
||||||
assert tox
|
|
||||||
basecontact.BaseContact.__init__(self,
|
basecontact.BaseContact.__init__(self,
|
||||||
profile_manager,
|
profile_manager,
|
||||||
tox.self_get_name(),
|
tox.self_get_name(),
|
||||||
@ -67,10 +60,10 @@ class Profile(basecontact.BaseContact, tox_save.ToxSave):
|
|||||||
|
|
||||||
def set_new_nospam(self):
|
def set_new_nospam(self):
|
||||||
"""Sets new nospam part of tox id"""
|
"""Sets new nospam part of tox id"""
|
||||||
self._tox.self_set_nospam(random.randint(0, iUMAXINT)) # no spam - uint32
|
self._tox.self_set_nospam(random.randint(0, 4294967295)) # no spam - uint32
|
||||||
self._tox_id = self._tox.self_get_address()
|
self._tox_id = self._tox.self_get_address()
|
||||||
self._sToxId = self._tox.self_get_address()
|
|
||||||
return self._sToxId
|
return self._tox_id
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
# Reset
|
# Reset
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
from os import chdir, remove, rename
|
from wrapper.toxcore_enums_and_consts import TOX_FILE_KIND, TOX_FILE_CONTROL
|
||||||
from os.path import basename, dirname, exists, getsize
|
from os.path import basename, getsize, exists, dirname
|
||||||
|
from os import remove, rename, chdir
|
||||||
from time import time
|
from time import time
|
||||||
|
from wrapper.tox import Tox
|
||||||
from common.event import Event
|
from common.event import Event
|
||||||
from middleware.threads import invoke_in_main_thread
|
from middleware.threads import invoke_in_main_thread
|
||||||
from wrapper.tox import Tox
|
|
||||||
from wrapper.toxcore_enums_and_consts import TOX_FILE_CONTROL, TOX_FILE_KIND
|
|
||||||
|
|
||||||
FILE_TRANSFER_STATE = {
|
FILE_TRANSFER_STATE = {
|
||||||
'RUNNING': 0,
|
'RUNNING': 0,
|
||||||
|
@ -1,19 +1,11 @@
|
|||||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
|
||||||
from messenger.messages import *
|
from messenger.messages import *
|
||||||
from ui.contact_items import *
|
from ui.contact_items import *
|
||||||
import utils.util as util
|
import utils.util as util
|
||||||
from common.tox_save import ToxSave
|
from common.tox_save import ToxSave
|
||||||
from wrapper_tests.support_testing import assert_main_thread
|
|
||||||
from copy import deepcopy
|
|
||||||
|
|
||||||
# LOG=util.log
|
|
||||||
global LOG
|
|
||||||
import logging
|
|
||||||
LOG = logging.getLogger('app.'+__name__)
|
|
||||||
log = lambda x: LOG.info(x)
|
|
||||||
|
|
||||||
class FileTransfersHandler(ToxSave):
|
class FileTransfersHandler(ToxSave):
|
||||||
lBlockAvatars = []
|
|
||||||
def __init__(self, tox, settings, contact_provider, file_transfers_message_service, profile):
|
def __init__(self, tox, settings, contact_provider, file_transfers_message_service, profile):
|
||||||
super().__init__(tox)
|
super().__init__(tox)
|
||||||
self._settings = settings
|
self._settings = settings
|
||||||
@ -27,8 +19,7 @@ class FileTransfersHandler(ToxSave):
|
|||||||
# key = (friend number, file number), value - message id
|
# key = (friend number, file number), value - message id
|
||||||
|
|
||||||
profile.avatar_changed_event.add_callback(self._send_avatar_to_contacts)
|
profile.avatar_changed_event.add_callback(self._send_avatar_to_contacts)
|
||||||
self. lBlockAvatars = []
|
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self._settings['paused_file_transfers'] = self._paused_file_transfers if self._settings['resend_files'] else {}
|
self._settings['paused_file_transfers'] = self._paused_file_transfers if self._settings['resend_files'] else {}
|
||||||
self._settings.save()
|
self._settings.save()
|
||||||
@ -46,7 +37,6 @@ class FileTransfersHandler(ToxSave):
|
|||||||
:param file_name: file name without path
|
:param file_name: file name without path
|
||||||
"""
|
"""
|
||||||
friend = self._get_friend_by_number(friend_number)
|
friend = self._get_friend_by_number(friend_number)
|
||||||
if friend is None: return None
|
|
||||||
auto = self._settings['allow_auto_accept'] and friend.tox_id in self._settings['auto_accept_from_friends']
|
auto = self._settings['allow_auto_accept'] and friend.tox_id in self._settings['auto_accept_from_friends']
|
||||||
inline = is_inline(file_name) and self._settings['allow_inline']
|
inline = is_inline(file_name) and self._settings['allow_inline']
|
||||||
file_id = self._tox.file_get_file_id(friend_number, file_number)
|
file_id = self._tox.file_get_file_id(friend_number, file_number)
|
||||||
@ -95,9 +85,7 @@ class FileTransfersHandler(ToxSave):
|
|||||||
self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['CANCEL'])
|
self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['CANCEL'])
|
||||||
|
|
||||||
def cancel_not_started_transfer(self, friend_number, message_id):
|
def cancel_not_started_transfer(self, friend_number, message_id):
|
||||||
friend = self._get_friend_by_number(friend_number)
|
self._get_friend_by_number(friend_number).delete_one_unsent_file(message_id)
|
||||||
if friend is None: return None
|
|
||||||
friend.delete_one_unsent_file(message_id)
|
|
||||||
|
|
||||||
def pause_transfer(self, friend_number, file_number, by_friend=False):
|
def pause_transfer(self, friend_number, file_number, by_friend=False):
|
||||||
"""
|
"""
|
||||||
@ -127,7 +115,6 @@ class FileTransfersHandler(ToxSave):
|
|||||||
"""
|
"""
|
||||||
path = self._generate_valid_path(path, from_position)
|
path = self._generate_valid_path(path, from_position)
|
||||||
friend = self._get_friend_by_number(friend_number)
|
friend = self._get_friend_by_number(friend_number)
|
||||||
if friend is None: return None
|
|
||||||
if not inline:
|
if not inline:
|
||||||
rt = ReceiveTransfer(path, self._tox, friend_number, size, file_number, from_position)
|
rt = ReceiveTransfer(path, self._tox, friend_number, size, file_number, from_position)
|
||||||
else:
|
else:
|
||||||
@ -158,7 +145,6 @@ class FileTransfersHandler(ToxSave):
|
|||||||
|
|
||||||
def send_inline(self, data, file_name, friend_number, is_resend=False):
|
def send_inline(self, data, file_name, friend_number, is_resend=False):
|
||||||
friend = self._get_friend_by_number(friend_number)
|
friend = self._get_friend_by_number(friend_number)
|
||||||
if friend is None: return None
|
|
||||||
if friend.status is None and not is_resend:
|
if friend.status is None and not is_resend:
|
||||||
self._file_transfers_message_service.add_unsent_file_message(friend, file_name, data)
|
self._file_transfers_message_service.add_unsent_file_message(friend, file_name, data)
|
||||||
return
|
return
|
||||||
@ -176,12 +162,11 @@ class FileTransfersHandler(ToxSave):
|
|||||||
:param file_id: file id of transfer
|
:param file_id: file id of transfer
|
||||||
"""
|
"""
|
||||||
friend = self._get_friend_by_number(friend_number)
|
friend = self._get_friend_by_number(friend_number)
|
||||||
if friend is None: return None
|
|
||||||
if friend.status is None and not is_resend:
|
if friend.status is None and not is_resend:
|
||||||
self._file_transfers_message_service.add_unsent_file_message(friend, path, None)
|
self._file_transfers_message_service.add_unsent_file_message(friend, path, None)
|
||||||
return
|
return
|
||||||
elif friend.status is None and is_resend:
|
elif friend.status is None and is_resend:
|
||||||
LOG.error('Error in sending')
|
print('Error in sending')
|
||||||
return
|
return
|
||||||
st = SendTransfer(path, self._tox, friend_number, TOX_FILE_KIND['DATA'], file_id)
|
st = SendTransfer(path, self._tox, friend_number, TOX_FILE_KIND['DATA'], file_id)
|
||||||
file_name = os.path.basename(path)
|
file_name = os.path.basename(path)
|
||||||
@ -201,27 +186,23 @@ class FileTransfersHandler(ToxSave):
|
|||||||
|
|
||||||
def transfer_finished(self, friend_number, file_number):
|
def transfer_finished(self, friend_number, file_number):
|
||||||
transfer = self._file_transfers[(friend_number, file_number)]
|
transfer = self._file_transfers[(friend_number, file_number)]
|
||||||
friend = self._get_friend_by_number(friend_number)
|
|
||||||
if friend is None: return None
|
|
||||||
t = type(transfer)
|
t = type(transfer)
|
||||||
if t is ReceiveAvatar:
|
if t is ReceiveAvatar:
|
||||||
friend.load_avatar()
|
self._get_friend_by_number(friend_number).load_avatar()
|
||||||
elif t is ReceiveToBuffer or (t is SendFromBuffer and self._settings['allow_inline']): # inline image
|
elif t is ReceiveToBuffer or (t is SendFromBuffer and self._settings['allow_inline']): # inline image
|
||||||
LOG.debug('inline')
|
print('inline')
|
||||||
inline = InlineImageMessage(transfer.data)
|
inline = InlineImageMessage(transfer.data)
|
||||||
message_id = self._insert_inline_before[(friend_number, file_number)]
|
message_id = self._insert_inline_before[(friend_number, file_number)]
|
||||||
del self._insert_inline_before[(friend_number, file_number)]
|
del self._insert_inline_before[(friend_number, file_number)]
|
||||||
if friend is None: return None
|
index = self._get_friend_by_number(friend_number).insert_inline(message_id, inline)
|
||||||
index = friend.insert_inline(message_id, inline)
|
|
||||||
self._file_transfers_message_service.add_inline_message(transfer, index)
|
self._file_transfers_message_service.add_inline_message(transfer, index)
|
||||||
del self._file_transfers[(friend_number, file_number)]
|
del self._file_transfers[(friend_number, file_number)]
|
||||||
|
|
||||||
def send_files(self, friend_number):
|
def send_files(self, friend_number):
|
||||||
|
friend = self._get_friend_by_number(friend_number)
|
||||||
|
friend.remove_invalid_unsent_files()
|
||||||
|
files = friend.get_unsent_files()
|
||||||
try:
|
try:
|
||||||
friend = self._get_friend_by_number(friend_number)
|
|
||||||
if friend is None: return None
|
|
||||||
friend.remove_invalid_unsent_files()
|
|
||||||
files = friend.get_unsent_files()
|
|
||||||
for fl in files:
|
for fl in files:
|
||||||
data, path = fl.data, fl.path
|
data, path = fl.data, fl.path
|
||||||
if data is not None:
|
if data is not None:
|
||||||
@ -230,7 +211,6 @@ class FileTransfersHandler(ToxSave):
|
|||||||
self.send_file(path, friend_number, True)
|
self.send_file(path, friend_number, True)
|
||||||
friend.clear_unsent_files()
|
friend.clear_unsent_files()
|
||||||
for key in self._paused_file_transfers.keys():
|
for key in self._paused_file_transfers.keys():
|
||||||
# RuntimeError: dictionary changed size during iteration
|
|
||||||
(path, ft_friend_number, is_incoming, start_position) = self._paused_file_transfers[key]
|
(path, ft_friend_number, is_incoming, start_position) = self._paused_file_transfers[key]
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
del self._paused_file_transfers[key]
|
del self._paused_file_transfers[key]
|
||||||
@ -238,16 +218,12 @@ class FileTransfersHandler(ToxSave):
|
|||||||
self.send_file(path, friend_number, True, key)
|
self.send_file(path, friend_number, True, key)
|
||||||
del self._paused_file_transfers[key]
|
del self._paused_file_transfers[key]
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
LOG.error('Exception in file sending: ' + str(ex))
|
print('Exception in file sending: ' + str(ex))
|
||||||
|
|
||||||
def friend_exit(self, friend_number):
|
def friend_exit(self, friend_number):
|
||||||
# RuntimeError: dictionary changed size during iteration
|
for friend_num, file_num in self._file_transfers.keys():
|
||||||
lMayChangeDynamically = self._file_transfers.copy()
|
|
||||||
for friend_num, file_num in lMayChangeDynamically:
|
|
||||||
if friend_num != friend_number:
|
if friend_num != friend_number:
|
||||||
continue
|
continue
|
||||||
if (friend_num, file_num) not in self._file_transfers:
|
|
||||||
continue
|
|
||||||
ft = self._file_transfers[(friend_num, file_num)]
|
ft = self._file_transfers[(friend_num, file_num)]
|
||||||
if type(ft) is SendTransfer:
|
if type(ft) is SendTransfer:
|
||||||
self._paused_file_transfers[ft.file_id] = [ft.path, friend_num, False, -1]
|
self._paused_file_transfers[ft.file_id] = [ft.path, friend_num, False, -1]
|
||||||
@ -264,16 +240,8 @@ class FileTransfersHandler(ToxSave):
|
|||||||
:param friend_number: number of friend who should get new avatar
|
:param friend_number: number of friend who should get new avatar
|
||||||
:param avatar_path: path to avatar or None if reset
|
:param avatar_path: path to avatar or None if reset
|
||||||
"""
|
"""
|
||||||
if (avatar_path, friend_number,) in self.lBlockAvatars:
|
sa = SendAvatar(avatar_path, self._tox, friend_number)
|
||||||
return
|
self._file_transfers[(friend_number, sa.file_number)] = sa
|
||||||
|
|
||||||
try:
|
|
||||||
sa = SendAvatar(avatar_path, self._tox, friend_number)
|
|
||||||
self._file_transfers[(friend_number, sa.file_number)] = sa
|
|
||||||
except Exception as e:
|
|
||||||
# ArgumentError('This client is currently not connected to the friend.')
|
|
||||||
LOG.error(f"send_avatar {e}")
|
|
||||||
self.lBlockAvatars.append( (avatar_path, friend_number,) )
|
|
||||||
|
|
||||||
def incoming_avatar(self, friend_number, file_number, size):
|
def incoming_avatar(self, friend_number, file_number, size):
|
||||||
"""
|
"""
|
||||||
@ -283,7 +251,6 @@ class FileTransfersHandler(ToxSave):
|
|||||||
:param size: size of avatar or 0 (default avatar)
|
:param size: size of avatar or 0 (default avatar)
|
||||||
"""
|
"""
|
||||||
friend = self._get_friend_by_number(friend_number)
|
friend = self._get_friend_by_number(friend_number)
|
||||||
if friend is None: return None
|
|
||||||
ra = ReceiveAvatar(friend.get_contact_avatar_path(), self._tox, friend_number, size, file_number)
|
ra = ReceiveAvatar(friend.get_contact_avatar_path(), self._tox, friend_number, size, file_number)
|
||||||
if ra.state != FILE_TRANSFER_STATE['CANCELLED']:
|
if ra.state != FILE_TRANSFER_STATE['CANCELLED']:
|
||||||
self._file_transfers[(friend_number, file_number)] = ra
|
self._file_transfers[(friend_number, file_number)] = ra
|
||||||
@ -292,7 +259,6 @@ class FileTransfersHandler(ToxSave):
|
|||||||
friend.reset_avatar(self._settings['identicons'])
|
friend.reset_avatar(self._settings['identicons'])
|
||||||
|
|
||||||
def _send_avatar_to_contacts(self, _):
|
def _send_avatar_to_contacts(self, _):
|
||||||
# from a callback
|
|
||||||
friends = self._get_all_friends()
|
friends = self._get_all_friends()
|
||||||
for friend in filter(self._is_friend_online, friends):
|
for friend in filter(self._is_friend_online, friends):
|
||||||
self.send_avatar(friend.number)
|
self.send_avatar(friend.number)
|
||||||
@ -303,7 +269,6 @@ class FileTransfersHandler(ToxSave):
|
|||||||
|
|
||||||
def _is_friend_online(self, friend_number):
|
def _is_friend_online(self, friend_number):
|
||||||
friend = self._get_friend_by_number(friend_number)
|
friend = self._get_friend_by_number(friend_number)
|
||||||
if friend is None: return None
|
|
||||||
|
|
||||||
return friend.status is not None
|
return friend.status is not None
|
||||||
|
|
||||||
|
@ -2,15 +2,6 @@ from messenger.messenger import *
|
|||||||
import utils.util as util
|
import utils.util as util
|
||||||
from file_transfers.file_transfers import *
|
from file_transfers.file_transfers import *
|
||||||
|
|
||||||
global LOG
|
|
||||||
import logging
|
|
||||||
LOG = logging.getLogger('app.'+__name__)
|
|
||||||
|
|
||||||
def LOG_ERROR(l): print('ERROR_: '+l)
|
|
||||||
def LOG_WARN(l): print('WARN_: '+l)
|
|
||||||
def LOG_INFO(l): print('INFO_: '+l)
|
|
||||||
def LOG_DEBUG(l): print('DEBUG_: '+l)
|
|
||||||
def LOG_TRACE(l): pass # print('TRACE+ '+l)
|
|
||||||
|
|
||||||
class FileTransfersMessagesService:
|
class FileTransfersMessagesService:
|
||||||
|
|
||||||
@ -21,7 +12,6 @@ class FileTransfersMessagesService:
|
|||||||
self._messages = main_screen.messages
|
self._messages = main_screen.messages
|
||||||
|
|
||||||
def add_incoming_transfer_message(self, friend, accepted, size, file_name, file_number):
|
def add_incoming_transfer_message(self, friend, accepted, size, file_name, file_number):
|
||||||
assert friend
|
|
||||||
author = MessageAuthor(friend.name, MESSAGE_AUTHOR['FRIEND'])
|
author = MessageAuthor(friend.name, MESSAGE_AUTHOR['FRIEND'])
|
||||||
status = FILE_TRANSFER_STATE['RUNNING'] if accepted else FILE_TRANSFER_STATE['INCOMING_NOT_STARTED']
|
status = FILE_TRANSFER_STATE['RUNNING'] if accepted else FILE_TRANSFER_STATE['INCOMING_NOT_STARTED']
|
||||||
tm = TransferMessage(author, util.get_unix_time(), status, size, file_name, friend.number, file_number)
|
tm = TransferMessage(author, util.get_unix_time(), status, size, file_name, friend.number, file_number)
|
||||||
@ -37,7 +27,6 @@ class FileTransfersMessagesService:
|
|||||||
return tm
|
return tm
|
||||||
|
|
||||||
def add_outgoing_transfer_message(self, friend, size, file_name, file_number):
|
def add_outgoing_transfer_message(self, friend, size, file_name, file_number):
|
||||||
assert friend
|
|
||||||
author = MessageAuthor(self._profile.name, MESSAGE_AUTHOR['ME'])
|
author = MessageAuthor(self._profile.name, MESSAGE_AUTHOR['ME'])
|
||||||
status = FILE_TRANSFER_STATE['OUTGOING_NOT_STARTED']
|
status = FILE_TRANSFER_STATE['OUTGOING_NOT_STARTED']
|
||||||
tm = TransferMessage(author, util.get_unix_time(), status, size, file_name, friend.number, file_number)
|
tm = TransferMessage(author, util.get_unix_time(), status, size, file_name, friend.number, file_number)
|
||||||
@ -51,19 +40,13 @@ class FileTransfersMessagesService:
|
|||||||
return tm
|
return tm
|
||||||
|
|
||||||
def add_inline_message(self, transfer, index):
|
def add_inline_message(self, transfer, index):
|
||||||
"""callback"""
|
|
||||||
if not self._is_friend_active(transfer.friend_number):
|
if not self._is_friend_active(transfer.friend_number):
|
||||||
return
|
return
|
||||||
if transfer is None or not hasattr(transfer, 'data') or \
|
|
||||||
not transfer.data:
|
|
||||||
LOG_ERROR(f"add_inline_message empty data")
|
|
||||||
return
|
|
||||||
count = self._messages.count()
|
count = self._messages.count()
|
||||||
if count + index + 1 >= 0:
|
if count + index + 1 >= 0:
|
||||||
self._create_inline_item(transfer.data, count + index + 1)
|
self._create_inline_item(transfer.data, count + index + 1)
|
||||||
|
|
||||||
def add_unsent_file_message(self, friend, file_path, data):
|
def add_unsent_file_message(self, friend, file_path, data):
|
||||||
assert friend
|
|
||||||
author = MessageAuthor(self._profile.name, MESSAGE_AUTHOR['ME'])
|
author = MessageAuthor(self._profile.name, MESSAGE_AUTHOR['ME'])
|
||||||
size = os.path.getsize(file_path) if data is None else len(data)
|
size = os.path.getsize(file_path) if data is None else len(data)
|
||||||
tm = UnsentFileMessage(file_path, data, util.get_unix_time(), author, size, friend.number)
|
tm = UnsentFileMessage(file_path, data, util.get_unix_time(), author, size, friend.number)
|
||||||
|
@ -13,8 +13,7 @@ class GroupChatPeer:
|
|||||||
self._public_key = public_key
|
self._public_key = public_key
|
||||||
self._is_current_user = is_current_user
|
self._is_current_user = is_current_user
|
||||||
self._is_muted = is_muted
|
self._is_muted = is_muted
|
||||||
# unused?
|
|
||||||
self._kind = 'grouppeer'
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
# Readonly properties
|
# Readonly properties
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -1,16 +1,9 @@
|
|||||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
|
||||||
|
|
||||||
import common.tox_save as tox_save
|
import common.tox_save as tox_save
|
||||||
import utils.ui as util_ui
|
import utils.ui as util_ui
|
||||||
from groups.peers_list import PeersListGenerator
|
from groups.peers_list import PeersListGenerator
|
||||||
from groups.group_invite import GroupInvite
|
from groups.group_invite import GroupInvite
|
||||||
import wrapper.toxcore_enums_and_consts as constants
|
import wrapper.toxcore_enums_and_consts as constants
|
||||||
from wrapper.toxcore_enums_and_consts import *
|
|
||||||
from wrapper.tox import UINT32_MAX
|
|
||||||
|
|
||||||
global LOG
|
|
||||||
import logging
|
|
||||||
LOG = logging.getLogger('app.'+'gs')
|
|
||||||
|
|
||||||
class GroupsService(tox_save.ToxSave):
|
class GroupsService(tox_save.ToxSave):
|
||||||
|
|
||||||
@ -23,8 +16,6 @@ class GroupsService(tox_save.ToxSave):
|
|||||||
self._widgets_factory_provider = widgets_factory_provider
|
self._widgets_factory_provider = widgets_factory_provider
|
||||||
self._group_invites = []
|
self._group_invites = []
|
||||||
self._screen = None
|
self._screen = None
|
||||||
# maybe just use self
|
|
||||||
self._tox = tox
|
|
||||||
|
|
||||||
def set_tox(self, tox):
|
def set_tox(self, tox):
|
||||||
super().set_tox(tox)
|
super().set_tox(tox)
|
||||||
@ -36,11 +27,7 @@ class GroupsService(tox_save.ToxSave):
|
|||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
def create_new_gc(self, name, privacy_state, nick, status):
|
def create_new_gc(self, name, privacy_state, nick, status):
|
||||||
try:
|
group_number = self._tox.group_new(privacy_state, name, nick, status)
|
||||||
group_number = self._tox.group_new(privacy_state, name, nick, status)
|
|
||||||
except Exception as e:
|
|
||||||
LOG.error(f"create_new_gc {e}")
|
|
||||||
return
|
|
||||||
if group_number == -1:
|
if group_number == -1:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -50,38 +37,16 @@ class GroupsService(tox_save.ToxSave):
|
|||||||
self._contacts_manager.update_filtration()
|
self._contacts_manager.update_filtration()
|
||||||
|
|
||||||
def join_gc_by_id(self, chat_id, password, nick, status):
|
def join_gc_by_id(self, chat_id, password, nick, status):
|
||||||
try:
|
group_number = self._tox.group_join(chat_id, password, nick, status)
|
||||||
group_number = self._tox.group_join(chat_id, password, nick, status)
|
|
||||||
assert type(group_number) == int, group_number
|
|
||||||
assert group_number < UINT32_MAX, group_number
|
|
||||||
except Exception as e:
|
|
||||||
# gui
|
|
||||||
title = f"join_gc_by_id {chat_id}"
|
|
||||||
util_ui.message_box(title +'\n' +str(e), title)
|
|
||||||
LOG.error(f"_join_gc_via_id {e}")
|
|
||||||
return
|
|
||||||
LOG.debug(f"_join_gc_via_id {group_number}")
|
|
||||||
self._add_new_group_by_number(group_number)
|
self._add_new_group_by_number(group_number)
|
||||||
group = self._get_group_by_number(group_number)
|
|
||||||
try:
|
|
||||||
assert group and hasattr(group, 'status')
|
|
||||||
except Exception as e:
|
|
||||||
# gui
|
|
||||||
title = f"join_gc_by_id {chat_id}"
|
|
||||||
util_ui.message_box(title +'\n' +str(e), title)
|
|
||||||
LOG.error(f"_join_gc_via_id {e}")
|
|
||||||
return
|
|
||||||
group.status = constants.TOX_USER_STATUS['NONE']
|
|
||||||
self._contacts_manager.update_filtration()
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
# Groups reconnect and leaving
|
# Groups reconnect and leaving
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
def leave_group(self, group_number):
|
def leave_group(self, group_number):
|
||||||
if type(group_number) == int:
|
self._tox.group_leave(group_number)
|
||||||
self._tox.group_leave(group_number)
|
self._contacts_manager.delete_group(group_number)
|
||||||
self._contacts_manager.delete_group(group_number)
|
|
||||||
|
|
||||||
def disconnect_from_group(self, group_number):
|
def disconnect_from_group(self, group_number):
|
||||||
self._tox.group_disconnect(group_number)
|
self._tox.group_disconnect(group_number)
|
||||||
@ -100,22 +65,10 @@ class GroupsService(tox_save.ToxSave):
|
|||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
def invite_friend(self, friend_number, group_number):
|
def invite_friend(self, friend_number, group_number):
|
||||||
if self._tox.friend_get_connection_status(friend_number) == TOX_CONNECTION['NONE']:
|
self._tox.group_invite_friend(group_number, friend_number)
|
||||||
title = f"Error in group_invite_friend {friend_number}"
|
|
||||||
e = f"Friend not connected friend_number={friend_number}"
|
|
||||||
util_ui.message_box(title +'\n' +str(e), title)
|
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
|
||||||
self._tox.group_invite_friend(group_number, friend_number)
|
|
||||||
except Exception as e:
|
|
||||||
title = f"Error in group_invite_friend {group_number} {friend_number}"
|
|
||||||
util_ui.message_box(title +'\n' +str(e), title)
|
|
||||||
|
|
||||||
def process_group_invite(self, friend_number, group_name, invite_data):
|
def process_group_invite(self, friend_number, group_name, invite_data):
|
||||||
friend = self._get_friend_by_number(friend_number)
|
friend = self._get_friend_by_number(friend_number)
|
||||||
# binary {invite_data}
|
|
||||||
LOG.debug(f"process_group_invite {friend_number} {group_name}")
|
|
||||||
invite = GroupInvite(friend.tox_id, group_name, invite_data)
|
invite = GroupInvite(friend.tox_id, group_name, invite_data)
|
||||||
self._group_invites.append(invite)
|
self._group_invites.append(invite)
|
||||||
self._update_invites_button_state()
|
self._update_invites_button_state()
|
||||||
@ -123,7 +76,6 @@ class GroupsService(tox_save.ToxSave):
|
|||||||
def accept_group_invite(self, invite, name, status, password):
|
def accept_group_invite(self, invite, name, status, password):
|
||||||
pk = invite.friend_public_key
|
pk = invite.friend_public_key
|
||||||
friend = self._get_friend_by_public_key(pk)
|
friend = self._get_friend_by_public_key(pk)
|
||||||
LOG.debug(f"accept_group_invite {name}")
|
|
||||||
self._join_gc_via_invite(invite.invite_data, friend.number, name, status, password)
|
self._join_gc_via_invite(invite.invite_data, friend.number, name, status, password)
|
||||||
self._delete_group_invite(invite)
|
self._delete_group_invite(invite)
|
||||||
self._update_invites_button_state()
|
self._update_invites_button_state()
|
||||||
@ -236,7 +188,6 @@ class GroupsService(tox_save.ToxSave):
|
|||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
def show_bans_list(self, group):
|
def show_bans_list(self, group):
|
||||||
return
|
|
||||||
widgets_factory = self._get_widgets_factory()
|
widgets_factory = self._get_widgets_factory()
|
||||||
self._screen = widgets_factory.create_groups_bans_screen(group)
|
self._screen = widgets_factory.create_groups_bans_screen(group)
|
||||||
self._screen.show()
|
self._screen.show()
|
||||||
@ -255,7 +206,6 @@ class GroupsService(tox_save.ToxSave):
|
|||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
def _add_new_group_by_number(self, group_number):
|
def _add_new_group_by_number(self, group_number):
|
||||||
LOG.debug(f"_add_new_group_by_number {group_number}")
|
|
||||||
self._contacts_manager.add_group(group_number)
|
self._contacts_manager.add_group(group_number)
|
||||||
|
|
||||||
def _get_group_by_number(self, group_number):
|
def _get_group_by_number(self, group_number):
|
||||||
@ -281,24 +231,9 @@ class GroupsService(tox_save.ToxSave):
|
|||||||
if invite in self._group_invites:
|
if invite in self._group_invites:
|
||||||
self._group_invites.remove(invite)
|
self._group_invites.remove(invite)
|
||||||
|
|
||||||
# status should be dropped
|
def _join_gc_via_invite(self, invite_data, friend_number, nick, status, password):
|
||||||
def _join_gc_via_invite(self, invite_data, friend_number, nick, status='', password=''):
|
group_number = self._tox.group_invite_accept(invite_data, friend_number, nick, status, password)
|
||||||
LOG.debug(f"_join_gc_via_invite friend_number={friend_number} nick={nick} datalen={len(invite_data)}")
|
self._add_new_group_by_number(group_number)
|
||||||
if nick is None:
|
|
||||||
nick = ''
|
|
||||||
if invite_data is None:
|
|
||||||
invite_data = b''
|
|
||||||
try:
|
|
||||||
# status should be dropped
|
|
||||||
group_number = self._tox.group_invite_accept(invite_data, friend_number, nick, password=password)
|
|
||||||
except Exception as e:
|
|
||||||
LOG.error(f"_join_gc_via_invite ERROR {e}")
|
|
||||||
return
|
|
||||||
try:
|
|
||||||
self._add_new_group_by_number(group_number)
|
|
||||||
except Exception as e:
|
|
||||||
LOG.error(f"_join_gc_via_invite group_number={group_number} {e}")
|
|
||||||
return
|
|
||||||
|
|
||||||
def _update_invites_button_state(self):
|
def _update_invites_button_state(self):
|
||||||
self._main_screen.update_gc_invites_button_state()
|
self._main_screen.update_gc_invites_button_state()
|
||||||
|
@ -1,20 +1,19 @@
|
|||||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
|
||||||
from sqlite3 import connect
|
from sqlite3 import connect
|
||||||
import os.path
|
import os.path
|
||||||
import utils.util as util
|
import utils.util as util
|
||||||
|
|
||||||
global LOG
|
|
||||||
import logging
|
|
||||||
LOG = logging.getLogger('app.db')
|
|
||||||
|
|
||||||
TIMEOUT = 11
|
TIMEOUT = 11
|
||||||
|
|
||||||
SAVE_MESSAGES = 500
|
SAVE_MESSAGES = 500
|
||||||
|
|
||||||
MESSAGE_AUTHOR = {
|
MESSAGE_AUTHOR = {
|
||||||
'ME': 0,
|
'ME': 0,
|
||||||
'FRIEND': 1,
|
'FRIEND': 1,
|
||||||
'NOT_SENT': 2,
|
'NOT_SENT': 2,
|
||||||
'GC_PEER': 3
|
'GC_PEER': 3
|
||||||
}
|
}
|
||||||
|
|
||||||
CONTACT_TYPE = {
|
CONTACT_TYPE = {
|
||||||
'FRIEND': 0,
|
'FRIEND': 0,
|
||||||
'GC_PEER': 1,
|
'GC_PEER': 1,
|
||||||
@ -25,31 +24,19 @@ CONTACT_TYPE = {
|
|||||||
class Database:
|
class Database:
|
||||||
|
|
||||||
def __init__(self, path, toxes):
|
def __init__(self, path, toxes):
|
||||||
self._path = path
|
self._path, self._toxes = path, toxes
|
||||||
self._toxes = toxes
|
|
||||||
self._name = os.path.basename(path)
|
self._name = os.path.basename(path)
|
||||||
|
if os.path.exists(path):
|
||||||
def open(self):
|
try:
|
||||||
path = self._path
|
with open(path, 'rb') as fin:
|
||||||
toxes = self._toxes
|
data = fin.read()
|
||||||
if not os.path.exists(path):
|
if toxes.is_data_encrypted(data):
|
||||||
LOG.warn('Db not found: ' +path)
|
data = toxes.pass_decrypt(data)
|
||||||
return
|
with open(path, 'wb') as fout:
|
||||||
try:
|
fout.write(data)
|
||||||
with open(path, 'rb') as fin:
|
except Exception as ex:
|
||||||
data = fin.read()
|
util.log('Db reading error: ' + str(ex))
|
||||||
except Exception as ex:
|
os.remove(path)
|
||||||
LOG.error('Db reading error: ' +path +' ' +str(ex))
|
|
||||||
raise
|
|
||||||
try:
|
|
||||||
if toxes.is_data_encrypted(data):
|
|
||||||
data = toxes.pass_decrypt(data)
|
|
||||||
with open(path, 'wb') as fout:
|
|
||||||
fout.write(data)
|
|
||||||
except Exception as ex:
|
|
||||||
LOG.error('Db writing error: ' +path +' ' + str(ex))
|
|
||||||
os.remove(path)
|
|
||||||
LOG.info('Db opened: ' +path)
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
# Public methods
|
# Public methods
|
||||||
@ -71,7 +58,6 @@ class Database:
|
|||||||
data = self._toxes.pass_encrypt(data)
|
data = self._toxes.pass_encrypt(data)
|
||||||
with open(new_path, 'wb') as fout:
|
with open(new_path, 'wb') as fout:
|
||||||
fout.write(data)
|
fout.write(data)
|
||||||
LOG.info('Db exported: ' +new_path)
|
|
||||||
|
|
||||||
def add_friend_to_db(self, tox_id):
|
def add_friend_to_db(self, tox_id):
|
||||||
db = self._connect()
|
db = self._connect()
|
||||||
@ -86,14 +72,11 @@ class Database:
|
|||||||
' message_type INTEGER'
|
' message_type INTEGER'
|
||||||
')')
|
')')
|
||||||
db.commit()
|
db.commit()
|
||||||
return True
|
except:
|
||||||
except Exception as e:
|
print('Database is locked!')
|
||||||
LOG.error("dd_friend_to_db " +self._name +' Database exception! ' +str(e))
|
|
||||||
db.rollback()
|
db.rollback()
|
||||||
return False
|
|
||||||
finally:
|
finally:
|
||||||
db.close()
|
db.close()
|
||||||
LOG.debug(f"add_friend_to_db {tox_id}")
|
|
||||||
|
|
||||||
def delete_friend_from_db(self, tox_id):
|
def delete_friend_from_db(self, tox_id):
|
||||||
db = self._connect()
|
db = self._connect()
|
||||||
@ -101,14 +84,11 @@ class Database:
|
|||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute('DROP TABLE id' + tox_id + ';')
|
cursor.execute('DROP TABLE id' + tox_id + ';')
|
||||||
db.commit()
|
db.commit()
|
||||||
return True
|
except:
|
||||||
except Exception as e:
|
print('Database is locked!')
|
||||||
LOG.error("delete_friend_from_db " +self._name +' Database exception! ' +str(e))
|
|
||||||
db.rollback()
|
db.rollback()
|
||||||
return False
|
|
||||||
finally:
|
finally:
|
||||||
db.close()
|
db.close()
|
||||||
LOG.debug(f"delete_friend_from_db {tox_id}")
|
|
||||||
|
|
||||||
def save_messages_to_db(self, tox_id, messages_iter):
|
def save_messages_to_db(self, tox_id, messages_iter):
|
||||||
db = self._connect()
|
db = self._connect()
|
||||||
@ -116,16 +96,13 @@ class Database:
|
|||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.executemany('INSERT INTO id' + tox_id +
|
cursor.executemany('INSERT INTO id' + tox_id +
|
||||||
'(message, author_name, author_type, unix_time, message_type) ' +
|
'(message, author_name, author_type, unix_time, message_type) ' +
|
||||||
'VALUES (?, ?, ?, ?, ?);', messages_iter)
|
'VALUES (?, ?, ?, ?, ?, ?);', messages_iter)
|
||||||
db.commit()
|
db.commit()
|
||||||
return True
|
except:
|
||||||
except Exception as e:
|
print('Database is locked!')
|
||||||
LOG.error("" +self._name +' Database exception! ' +str(e))
|
|
||||||
db.rollback()
|
db.rollback()
|
||||||
return False
|
|
||||||
finally:
|
finally:
|
||||||
db.close()
|
db.close()
|
||||||
LOG.debug(f"save_messages_to_db {tox_id}")
|
|
||||||
|
|
||||||
def update_messages(self, tox_id, message_id):
|
def update_messages(self, tox_id, message_id):
|
||||||
db = self._connect()
|
db = self._connect()
|
||||||
@ -134,14 +111,11 @@ class Database:
|
|||||||
cursor.execute('UPDATE id' + tox_id + ' SET author = 0 '
|
cursor.execute('UPDATE id' + tox_id + ' SET author = 0 '
|
||||||
'WHERE id = ' + str(message_id) + ' AND author = 2;')
|
'WHERE id = ' + str(message_id) + ' AND author = 2;')
|
||||||
db.commit()
|
db.commit()
|
||||||
return True
|
except:
|
||||||
except Exception as e:
|
print('Database is locked!')
|
||||||
LOG.error("" +self._name +' Database exception! ' +str(e))
|
|
||||||
db.rollback()
|
db.rollback()
|
||||||
return False
|
|
||||||
finally:
|
finally:
|
||||||
db.close()
|
db.close()
|
||||||
LOG.debug(f"update_messages {tox_id}")
|
|
||||||
|
|
||||||
def delete_message(self, tox_id, unique_id):
|
def delete_message(self, tox_id, unique_id):
|
||||||
db = self._connect()
|
db = self._connect()
|
||||||
@ -149,14 +123,11 @@ class Database:
|
|||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute('DELETE FROM id' + tox_id + ' WHERE id = ' + str(unique_id) + ';')
|
cursor.execute('DELETE FROM id' + tox_id + ' WHERE id = ' + str(unique_id) + ';')
|
||||||
db.commit()
|
db.commit()
|
||||||
return True
|
except:
|
||||||
except Exception as e:
|
print('Database is locked!')
|
||||||
LOG.error("" +self._name +' Database exception! ' +str(e))
|
|
||||||
db.rollback()
|
db.rollback()
|
||||||
return False
|
|
||||||
finally:
|
finally:
|
||||||
db.close()
|
db.close()
|
||||||
LOG.debug(f"delete_message {tox_id}")
|
|
||||||
|
|
||||||
def delete_messages(self, tox_id):
|
def delete_messages(self, tox_id):
|
||||||
db = self._connect()
|
db = self._connect()
|
||||||
@ -164,14 +135,11 @@ class Database:
|
|||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute('DELETE FROM id' + tox_id + ';')
|
cursor.execute('DELETE FROM id' + tox_id + ';')
|
||||||
db.commit()
|
db.commit()
|
||||||
return True
|
except:
|
||||||
except Exception as e:
|
print('Database is locked!')
|
||||||
LOG.error("" +self._name +' Database exception! ' +str(e))
|
|
||||||
db.rollback()
|
db.rollback()
|
||||||
return False
|
|
||||||
finally:
|
finally:
|
||||||
db.close()
|
db.close()
|
||||||
LOG.debug(f"delete_messages {tox_id}")
|
|
||||||
|
|
||||||
def messages_getter(self, tox_id):
|
def messages_getter(self, tox_id):
|
||||||
self.add_friend_to_db(tox_id)
|
self.add_friend_to_db(tox_id)
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
|
||||||
from history.history_logs_generators import *
|
from history.history_logs_generators import *
|
||||||
|
|
||||||
global LOG
|
|
||||||
import logging
|
|
||||||
LOG = logging.getLogger('app.db')
|
|
||||||
|
|
||||||
class History:
|
class History:
|
||||||
|
|
||||||
@ -15,7 +11,7 @@ class History:
|
|||||||
self._messages_items_factory = messages_items_factory
|
self._messages_items_factory = messages_items_factory
|
||||||
self._is_loading = False
|
self._is_loading = False
|
||||||
self._contacts_manager = None
|
self._contacts_manager = None
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
del self._db
|
del self._db
|
||||||
|
|
||||||
@ -30,8 +26,7 @@ class History:
|
|||||||
"""
|
"""
|
||||||
Save history to db
|
Save history to db
|
||||||
"""
|
"""
|
||||||
# me a mistake? was _db not _history
|
if self._settings['save_db']:
|
||||||
if self._settings['save_history']:
|
|
||||||
for friend in self._contact_provider.get_all_friends():
|
for friend in self._contact_provider.get_all_friends():
|
||||||
self._db.add_friend_to_db(friend.tox_id)
|
self._db.add_friend_to_db(friend.tox_id)
|
||||||
if not self._settings['save_unsent_only']:
|
if not self._settings['save_unsent_only']:
|
||||||
@ -62,10 +57,8 @@ class History:
|
|||||||
file_name += '.' + extension
|
file_name += '.' + extension
|
||||||
|
|
||||||
history = self.generate_history(contact, as_text)
|
history = self.generate_history(contact, as_text)
|
||||||
assert history
|
|
||||||
with open(file_name, 'wt') as fl:
|
with open(file_name, 'wt') as fl:
|
||||||
fl.write(history)
|
fl.write(history)
|
||||||
LOG.info(f"wrote history to {file_name}")
|
|
||||||
|
|
||||||
def delete_message(self, message):
|
def delete_message(self, message):
|
||||||
contact = self._contacts_manager.get_curr_contact()
|
contact = self._contacts_manager.get_curr_contact()
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import utils.util as util
|
|
||||||
from messenger.messages import *
|
from messenger.messages import *
|
||||||
|
import utils.util as util
|
||||||
|
|
||||||
|
|
||||||
class HistoryLogsGenerator:
|
class HistoryLogsGenerator:
|
||||||
|
BIN
toxygen/images/accept.png
Normal file → Executable file
Before Width: | Height: | Size: 116 KiB After Width: | Height: | Size: 114 KiB |
BIN
toxygen/images/accept_audio.png
Normal file → Executable file
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 13 KiB |
BIN
toxygen/images/accept_video.png
Normal file → Executable file
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 13 KiB |
BIN
toxygen/images/avatar.png
Normal file → Executable file
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 433 B After Width: | Height: | Size: 329 B |
Before Width: | Height: | Size: 556 B After Width: | Height: | Size: 609 B |
BIN
toxygen/images/call.png
Normal file → Executable file
Before Width: | Height: | Size: 816 B After Width: | Height: | Size: 3.5 KiB |
BIN
toxygen/images/call_video.png
Normal file → Executable file
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 3.5 KiB |
BIN
toxygen/images/decline.png
Normal file → Executable file
Before Width: | Height: | Size: 119 KiB After Width: | Height: | Size: 118 KiB |
BIN
toxygen/images/decline_call.png
Normal file → Executable file
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 12 KiB |
BIN
toxygen/images/file.png
Normal file → Executable file
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 3.4 KiB |
BIN
toxygen/images/finish_call.png
Normal file → Executable file
Before Width: | Height: | Size: 816 B After Width: | Height: | Size: 3.5 KiB |
BIN
toxygen/images/finish_call_video.png
Normal file → Executable file
Before Width: | Height: | Size: 461 B After Width: | Height: | Size: 3.0 KiB |
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.0 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 2.5 KiB |
BIN
toxygen/images/icon_new_messages.png
Normal file → Executable file
Before Width: | Height: | Size: 911 B After Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 400 B After Width: | Height: | Size: 231 B |
Before Width: | Height: | Size: 474 B After Width: | Height: | Size: 405 B |
BIN
toxygen/images/incoming_call.png
Normal file → Executable file
Before Width: | Height: | Size: 816 B After Width: | Height: | Size: 3.5 KiB |
BIN
toxygen/images/incoming_call_video.png
Normal file → Executable file
Before Width: | Height: | Size: 461 B After Width: | Height: | Size: 3.0 KiB |
BIN
toxygen/images/menu.png
Normal file → Executable file
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 325 B After Width: | Height: | Size: 159 B |
Before Width: | Height: | Size: 489 B After Width: | Height: | Size: 445 B |
Before Width: | Height: | Size: 376 B After Width: | Height: | Size: 201 B |
Before Width: | Height: | Size: 454 B After Width: | Height: | Size: 351 B |
BIN
toxygen/images/pause.png
Normal file → Executable file
Before Width: | Height: | Size: 427 B After Width: | Height: | Size: 306 B |
BIN
toxygen/images/resume.png
Normal file → Executable file
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 2.6 KiB |
BIN
toxygen/images/screenshot.png
Normal file → Executable file
Before Width: | Height: | Size: 656 B After Width: | Height: | Size: 481 B |
Before Width: | Height: | Size: 865 B After Width: | Height: | Size: 3.7 KiB |
BIN
toxygen/images/send.png
Normal file → Executable file
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.1 KiB |
BIN
toxygen/images/smiley.png
Normal file → Executable file
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 5.6 KiB |
BIN
toxygen/images/sticker.png
Normal file → Executable file
Before Width: | Height: | Size: 94 KiB After Width: | Height: | Size: 94 KiB |
BIN
toxygen/images/typing.png
Normal file → Executable file
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 5.6 KiB |
390
toxygen/main.py
@ -1,397 +1,51 @@
|
|||||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
import app
|
import app
|
||||||
import argparse
|
|
||||||
import logging
|
|
||||||
import signal
|
|
||||||
|
|
||||||
import faulthandler
|
|
||||||
faulthandler.enable()
|
|
||||||
|
|
||||||
import warnings
|
|
||||||
warnings.filterwarnings('ignore')
|
|
||||||
|
|
||||||
import wrapper_tests.support_testing as ts
|
|
||||||
try:
|
|
||||||
from trepan.interfaces import server as Mserver
|
|
||||||
from trepan.api import debug
|
|
||||||
except:
|
|
||||||
print('trepan3 TCP server NOT enabled.')
|
|
||||||
else:
|
|
||||||
import signal
|
|
||||||
try:
|
|
||||||
signal.signal(signal.SIGUSR1, ts.trepan_handler)
|
|
||||||
print('trepan3 TCP server enabled on port 6666.')
|
|
||||||
except: pass
|
|
||||||
|
|
||||||
from user_data.settings import *
|
from user_data.settings import *
|
||||||
from user_data.settings import Settings
|
|
||||||
from user_data import settings
|
|
||||||
import utils.util as util
|
import utils.util as util
|
||||||
with ts.ignoreStderr():
|
import argparse
|
||||||
import pyaudio
|
|
||||||
|
|
||||||
__maintainer__ = 'Ingvar'
|
__maintainer__ = 'Ingvar'
|
||||||
__version__ = '0.5.0+'
|
__version__ = '0.5.0'
|
||||||
|
|
||||||
import time
|
|
||||||
sleep = time.sleep
|
|
||||||
|
|
||||||
def reset():
|
|
||||||
Settings.reset_auto_profile()
|
|
||||||
|
|
||||||
def clean():
|
def clean():
|
||||||
"""Removes libs folder"""
|
"""Removes libs folder"""
|
||||||
directory = util.get_libs_directory()
|
directory = util.get_libs_directory()
|
||||||
util.remove(directory)
|
util.remove(directory)
|
||||||
|
|
||||||
|
|
||||||
|
def reset():
|
||||||
|
Settings.reset_auto_profile()
|
||||||
|
|
||||||
|
|
||||||
def print_toxygen_version():
|
def print_toxygen_version():
|
||||||
print('Toxygen ' + __version__)
|
print('Toxygen v' + __version__)
|
||||||
|
|
||||||
def setup_default_audio():
|
|
||||||
# need:
|
|
||||||
audio = ts.get_audio()
|
|
||||||
# unfinished
|
|
||||||
global oPYA
|
|
||||||
oPYA = pyaudio.PyAudio()
|
|
||||||
audio['output_devices'] = dict()
|
|
||||||
i = oPYA.get_device_count()
|
|
||||||
while i > 0:
|
|
||||||
i -= 1
|
|
||||||
if oPYA.get_device_info_by_index(i)['maxOutputChannels'] == 0:
|
|
||||||
continue
|
|
||||||
audio['output_devices'][i] = oPYA.get_device_info_by_index(i)['name']
|
|
||||||
i = oPYA.get_device_count()
|
|
||||||
audio['input_devices'] = dict()
|
|
||||||
while i > 0:
|
|
||||||
i -= 1
|
|
||||||
if oPYA.get_device_info_by_index(i)['maxInputChannels'] == 0:
|
|
||||||
continue
|
|
||||||
audio['input_devices'][i] = oPYA.get_device_info_by_index(i)['name']
|
|
||||||
return audio
|
|
||||||
|
|
||||||
def setup_video(oArgs):
|
def main():
|
||||||
video = setup_default_video()
|
|
||||||
if oArgs.video_input == '-1':
|
|
||||||
video['device'] = video['output_devices'][1]
|
|
||||||
else:
|
|
||||||
video['device'] = oArgs.video_input
|
|
||||||
return video
|
|
||||||
|
|
||||||
def setup_audio(oArgs):
|
|
||||||
global oPYA
|
|
||||||
audio = setup_default_audio()
|
|
||||||
for k,v in audio['input_devices'].items():
|
|
||||||
if v == 'default' and 'input' not in audio:
|
|
||||||
audio['input'] = k
|
|
||||||
if v == getattr(oArgs, 'audio_input'):
|
|
||||||
audio['input'] = k
|
|
||||||
LOG.debug(f"Setting audio['input'] {k} = {v} {k}")
|
|
||||||
break
|
|
||||||
for k,v in audio['output_devices'].items():
|
|
||||||
if v == 'default' and 'output' not in audio:
|
|
||||||
audio['output'] = k
|
|
||||||
if v == getattr(oArgs, 'audio_output'):
|
|
||||||
audio['output'] = k
|
|
||||||
LOG.debug(f"Setting audio['output'] {k} = {v} " +str(k))
|
|
||||||
break
|
|
||||||
|
|
||||||
if hasattr(oArgs, 'mode') and getattr(oArgs, 'mode') > 1:
|
|
||||||
audio['enabled'] = True
|
|
||||||
audio['audio_enabled'] = True
|
|
||||||
audio['video_enabled'] = True
|
|
||||||
elif hasattr(oArgs, 'mode') and getattr(oArgs, 'mode') > 0:
|
|
||||||
audio['enabled'] = True
|
|
||||||
audio['audio_enabled'] = False
|
|
||||||
audio['video_enabled'] = True
|
|
||||||
else:
|
|
||||||
audio['enabled'] = False
|
|
||||||
audio['audio_enabled'] = False
|
|
||||||
audio['video_enabled'] = False
|
|
||||||
|
|
||||||
return audio
|
|
||||||
|
|
||||||
i = getattr(oArgs, 'audio_output')
|
|
||||||
if i >= 0:
|
|
||||||
try:
|
|
||||||
elt = oPYA.get_device_info_by_index(i)
|
|
||||||
if i >= 0 and ( 'maxOutputChannels' not in elt or \
|
|
||||||
elt['maxOutputChannels'] == 0):
|
|
||||||
LOG.warn(f"Audio output device has no output channels: {i}")
|
|
||||||
oArgs.audio_output = -1
|
|
||||||
except OSError as e:
|
|
||||||
LOG.warn("Audio output device error looking for maxOutputChannels: " \
|
|
||||||
+str(i) +' ' +str(e))
|
|
||||||
oArgs.audio_output = -1
|
|
||||||
|
|
||||||
if getattr(oArgs, 'audio_output') < 0:
|
|
||||||
LOG.info("Choose an output device:")
|
|
||||||
i = oPYA.get_device_count()
|
|
||||||
while i > 0:
|
|
||||||
i -= 1
|
|
||||||
if oPYA.get_device_info_by_index(i)['maxOutputChannels'] == 0:
|
|
||||||
continue
|
|
||||||
LOG.info(str(i) \
|
|
||||||
+' ' +oPYA.get_device_info_by_index(i)['name'] \
|
|
||||||
+' ' +str(oPYA.get_device_info_by_index(i)['defaultSampleRate'])
|
|
||||||
)
|
|
||||||
return 0
|
|
||||||
|
|
||||||
i = getattr(oArgs, 'audio_input')
|
|
||||||
if i >= 0:
|
|
||||||
try:
|
|
||||||
elt = oPYA.get_device_info_by_index(i)
|
|
||||||
if i >= 0 and ( 'maxInputChannels' not in elt or \
|
|
||||||
elt['maxInputChannels'] == 0):
|
|
||||||
LOG.warn(f"Audio input device has no input channels: {i}")
|
|
||||||
setattr(oArgs, 'audio_input', -1)
|
|
||||||
except OSError as e:
|
|
||||||
LOG.warn("Audio input device error looking for maxInputChannels: " \
|
|
||||||
+str(i) +' ' +str(e))
|
|
||||||
setattr(oArgs, 'audio_input', -1)
|
|
||||||
if getattr(oArgs, 'audio_input') < 0:
|
|
||||||
LOG.info("Choose an input device:")
|
|
||||||
i = oPYA.get_device_count()
|
|
||||||
while i > 0:
|
|
||||||
i -= 1
|
|
||||||
if oPYA.get_device_info_by_index(i)['maxInputChannels'] == 0:
|
|
||||||
continue
|
|
||||||
LOG.info(str(i) \
|
|
||||||
+' ' +oPYA.get_device_info_by_index(i)['name']
|
|
||||||
+' ' +str(oPYA.get_device_info_by_index(i)['defaultSampleRate'])
|
|
||||||
)
|
|
||||||
return 0
|
|
||||||
|
|
||||||
def setup_default_video():
|
|
||||||
default_video = ["-1"]
|
|
||||||
default_video.extend(ts.get_video_indexes())
|
|
||||||
LOG.info(f"Video input choices: {default_video!r}")
|
|
||||||
video = {'device': -1, 'width': 320, 'height': 240, 'x': 0, 'y': 0}
|
|
||||||
video['output_devices'] = default_video
|
|
||||||
return video
|
|
||||||
|
|
||||||
def main_parser():
|
|
||||||
import cv2
|
|
||||||
if not os.path.exists('/proc/sys/net/ipv6'):
|
|
||||||
bIpV6 = 'False'
|
|
||||||
else:
|
|
||||||
bIpV6 = 'True'
|
|
||||||
lIpV6Choices=[bIpV6, 'False']
|
|
||||||
|
|
||||||
audio = setup_default_audio()
|
|
||||||
default_video = setup_default_video()
|
|
||||||
|
|
||||||
logfile = os.path.join(os.environ.get('TMPDIR', '/tmp'), 'toxygen.log')
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--version', action='store_true', help='Prints Toxygen version')
|
parser.add_argument('--version', action='store_true', help='Prints Toxygen version')
|
||||||
parser.add_argument('--clean', action='store_true', help='Delete toxcore libs from libs folder')
|
parser.add_argument('--clean', action='store_true', help='Delete toxcore libs from libs folder')
|
||||||
parser.add_argument('--reset', action='store_true', help='Reset default profile')
|
parser.add_argument('--reset', action='store_true', help='Reset default profile')
|
||||||
parser.add_argument('--uri', type=str, default='',
|
parser.add_argument('--uri', help='Add specified Tox ID to friends')
|
||||||
help='Add specified Tox ID to friends')
|
parser.add_argument('profile', nargs='?', default=None, help='Path to Tox profile')
|
||||||
parser.add_argument('--logfile', default=logfile,
|
args = parser.parse_args()
|
||||||
help='Filename for logging')
|
|
||||||
parser.add_argument('--loglevel', type=int, default=logging.INFO,
|
|
||||||
help='Threshold for logging (lower is more) default: 20')
|
|
||||||
parser.add_argument('--proxy_host', '--proxy-host', type=str,
|
|
||||||
# oddball - we want to use '' as a setting
|
|
||||||
default='0.0.0.0',
|
|
||||||
help='proxy host')
|
|
||||||
parser.add_argument('--proxy_port', '--proxy-port', default=0, type=int,
|
|
||||||
help='proxy port')
|
|
||||||
parser.add_argument('--proxy_type', '--proxy-type', default=0, type=int,
|
|
||||||
choices=[0,1,2],
|
|
||||||
help='proxy type 1=https, 2=socks')
|
|
||||||
parser.add_argument('--tcp_port', '--tcp-port', default=0, type=int,
|
|
||||||
help='tcp port')
|
|
||||||
parser.add_argument('--auto_accept_path', '--auto-accept-path', type=str,
|
|
||||||
default=os.path.join(os.environ['HOME'], 'Downloads'),
|
|
||||||
help="auto_accept_path")
|
|
||||||
parser.add_argument('--mode', type=int, default=2,
|
|
||||||
help='Mode: 0=chat 1=chat+audio 2=chat+audio+video default: 0')
|
|
||||||
parser.add_argument('--font', type=str, default="Courier",
|
|
||||||
help='Message font')
|
|
||||||
parser.add_argument('--message_font_size', type=int, default=15,
|
|
||||||
help='Font size in pixels')
|
|
||||||
parser.add_argument('--local_discovery_enabled',type=str,
|
|
||||||
default='False', choices=['True','False'],
|
|
||||||
help='Look on the local lan')
|
|
||||||
parser.add_argument('--udp_enabled',type=str,
|
|
||||||
default='True', choices=['True','False'],
|
|
||||||
help='En/Disable udp')
|
|
||||||
parser.add_argument('--trace_enabled',type=str,
|
|
||||||
default='False', choices=['True','False'],
|
|
||||||
help='Debugging from toxcore logger_trace')
|
|
||||||
parser.add_argument('--ipv6_enabled',type=str,
|
|
||||||
default=bIpV6, choices=lIpV6Choices,
|
|
||||||
help='En/Disable ipv6')
|
|
||||||
parser.add_argument('--compact_mode',type=str,
|
|
||||||
default='True', choices=['True','False'],
|
|
||||||
help='Compact mode')
|
|
||||||
parser.add_argument('--allow_inline',type=str,
|
|
||||||
default='False', choices=['True','False'],
|
|
||||||
help='Dis/Enable allow_inline')
|
|
||||||
parser.add_argument('--notifications',type=str,
|
|
||||||
default='True', choices=['True','False'],
|
|
||||||
help='Dis/Enable notifications')
|
|
||||||
parser.add_argument('--sound_notifications',type=str,
|
|
||||||
default='True', choices=['True','False'],
|
|
||||||
help='Enable sound notifications')
|
|
||||||
parser.add_argument('--calls_sound',type=str,
|
|
||||||
default='True', choices=['True','False'],
|
|
||||||
help='Enable calls_sound')
|
|
||||||
parser.add_argument('--core_logging',type=str,
|
|
||||||
default='False', choices=['True','False'],
|
|
||||||
help='Dis/Enable Toxcore notifications')
|
|
||||||
parser.add_argument('--hole_punching_enabled',type=str,
|
|
||||||
default='False', choices=['True','False'],
|
|
||||||
help='En/Enable hole punching')
|
|
||||||
parser.add_argument('--dht_announcements_enabled',type=str,
|
|
||||||
default='True', choices=['True','False'],
|
|
||||||
help='En/Disable DHT announcements')
|
|
||||||
parser.add_argument('--save_history',type=str,
|
|
||||||
default='True', choices=['True','False'],
|
|
||||||
help='En/Disable save history')
|
|
||||||
parser.add_argument('--update', type=int, default=0,
|
|
||||||
choices=[0,0],
|
|
||||||
help='Update program (broken)')
|
|
||||||
parser.add_argument('--download_nodes_list',type=str,
|
|
||||||
default='False', choices=['True','False'],
|
|
||||||
help='Download nodes list')
|
|
||||||
parser.add_argument('--nodes_json', type=str,
|
|
||||||
default='')
|
|
||||||
parser.add_argument('--download_nodes_url', type=str,
|
|
||||||
default='https://nodes.tox.chat/json')
|
|
||||||
parser.add_argument('--network', type=str,
|
|
||||||
choices=['old', 'main', 'new', 'local', 'newlocal'],
|
|
||||||
default='old')
|
|
||||||
parser.add_argument('--video_input', type=str,
|
|
||||||
default=-1,
|
|
||||||
choices=default_video['output_devices'],
|
|
||||||
help="Video input device number - /dev/video?")
|
|
||||||
parser.add_argument('--audio_input', type=str,
|
|
||||||
default=oPYA.get_default_input_device_info()['name'],
|
|
||||||
choices=audio['input_devices'].values(),
|
|
||||||
help="Audio input device name - aplay -L for help")
|
|
||||||
parser.add_argument('--audio_output', type=str,
|
|
||||||
default=oPYA.get_default_output_device_info()['index'],
|
|
||||||
choices=audio['output_devices'].values(),
|
|
||||||
help="Audio output device number - -1 for help")
|
|
||||||
parser.add_argument('--theme', type=str, default='default',
|
|
||||||
choices=['dark', 'default'],
|
|
||||||
help='Theme - style of UI')
|
|
||||||
parser.add_argument('--sleep', type=str, default='time',
|
|
||||||
# could expand this to tk, gtk, gevent...
|
|
||||||
choices=['qt','gevent','time'],
|
|
||||||
help='Sleep method - one of qt, gevent , time')
|
|
||||||
supported_languages = settings.supported_languages()
|
|
||||||
parser.add_argument('--language', type=str, default='English',
|
|
||||||
choices=supported_languages,
|
|
||||||
help='Languages')
|
|
||||||
parser.add_argument('profile', type=str, nargs='?', default=None,
|
|
||||||
help='Path to Tox profile')
|
|
||||||
return parser
|
|
||||||
|
|
||||||
# clean out the unchanged settings so these can override the profile
|
if args.version:
|
||||||
lKEEP_SETTINGS = ['uri',
|
|
||||||
'profile',
|
|
||||||
'loglevel',
|
|
||||||
'logfile',
|
|
||||||
'mode',
|
|
||||||
|
|
||||||
# dunno
|
|
||||||
'audio_input',
|
|
||||||
'audio_output',
|
|
||||||
'audio',
|
|
||||||
'video',
|
|
||||||
|
|
||||||
'ipv6_enabled',
|
|
||||||
'udp_enabled',
|
|
||||||
'local_discovery_enabled',
|
|
||||||
'theme',
|
|
||||||
'network',
|
|
||||||
'message_font_size',
|
|
||||||
'font',
|
|
||||||
'save_history',
|
|
||||||
'language',
|
|
||||||
'update',
|
|
||||||
'proxy_host',
|
|
||||||
'proxy_type',
|
|
||||||
'proxy_port',
|
|
||||||
'core_logging',
|
|
||||||
'audio',
|
|
||||||
'video'
|
|
||||||
] # , 'nodes_json'
|
|
||||||
|
|
||||||
class A(): pass
|
|
||||||
|
|
||||||
def main(lArgs):
|
|
||||||
global oPYA
|
|
||||||
from argparse import Namespace
|
|
||||||
parser = main_parser()
|
|
||||||
default_ns = parser.parse_args([])
|
|
||||||
oArgs = parser.parse_args(lArgs)
|
|
||||||
|
|
||||||
if oArgs.version:
|
|
||||||
print_toxygen_version()
|
print_toxygen_version()
|
||||||
return 0
|
return
|
||||||
|
|
||||||
if oArgs.clean:
|
if args.clean:
|
||||||
clean()
|
clean()
|
||||||
return 0
|
return
|
||||||
|
|
||||||
if oArgs.reset:
|
if args.reset:
|
||||||
reset()
|
reset()
|
||||||
return 0
|
return
|
||||||
|
|
||||||
# if getattr(oArgs, 'network') in ['newlocal', 'localnew']: oArgs.network = 'new'
|
toxygen = app.App(__version__, args.profile, args.uri)
|
||||||
|
toxygen.main()
|
||||||
|
|
||||||
# clean out the unchanged settings so these can override the profile
|
|
||||||
for key in default_ns.__dict__.keys():
|
|
||||||
if key in lKEEP_SETTINGS: continue
|
|
||||||
if not hasattr(oArgs, key): continue
|
|
||||||
if getattr(default_ns, key) == getattr(oArgs, key):
|
|
||||||
delattr(oArgs, key)
|
|
||||||
|
|
||||||
ts.clean_booleans(oArgs)
|
|
||||||
|
|
||||||
aArgs = A()
|
|
||||||
for key in oArgs.__dict__.keys():
|
|
||||||
setattr(aArgs, key, getattr(oArgs, key))
|
|
||||||
#setattr(aArgs, 'video', setup_video(oArgs))
|
|
||||||
aArgs.video = setup_video(oArgs)
|
|
||||||
assert 'video' in aArgs.__dict__
|
|
||||||
|
|
||||||
#setattr(aArgs, 'audio', setup_audio(oArgs))
|
|
||||||
aArgs.audio = setup_audio(oArgs)
|
|
||||||
assert 'audio' in aArgs.__dict__
|
|
||||||
oArgs = aArgs
|
|
||||||
|
|
||||||
toxygen = app.App(__version__, oArgs)
|
|
||||||
# for pyqtconsole
|
|
||||||
__builtins__.app = toxygen
|
|
||||||
i = toxygen.iMain()
|
|
||||||
return i
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
iRet = 0
|
main()
|
||||||
try:
|
|
||||||
iRet = main(sys.argv[1:])
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
iRet = 0
|
|
||||||
except SystemExit as e:
|
|
||||||
iRet = e
|
|
||||||
except Exception as e:
|
|
||||||
import traceback
|
|
||||||
sys.stderr.write(f"Exception from main {e}" \
|
|
||||||
+'\n' + traceback.format_exc() +'\n' )
|
|
||||||
iRet = 1
|
|
||||||
|
|
||||||
# Exception ignored in: <module 'threading' from '/usr/lib/python3.9/threading.py'>
|
|
||||||
# File "/usr/lib/python3.9/threading.py", line 1428, in _shutdown
|
|
||||||
# lock.acquire()
|
|
||||||
# gevent.exceptions.LoopExit as e:
|
|
||||||
# This operation would block forever
|
|
||||||
sys.stderr.write('Calling sys.exit' +'\n')
|
|
||||||
with ts.ignoreStdout():
|
|
||||||
sys.exit(iRet)
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import os.path
|
|
||||||
|
|
||||||
from history.database import MESSAGE_AUTHOR
|
from history.database import MESSAGE_AUTHOR
|
||||||
|
import os.path
|
||||||
from ui.messages_widgets import *
|
from ui.messages_widgets import *
|
||||||
|
|
||||||
|
|
||||||
MESSAGE_TYPE = {
|
MESSAGE_TYPE = {
|
||||||
'TEXT': 0,
|
'TEXT': 0,
|
||||||
'ACTION': 1,
|
'ACTION': 1,
|
||||||
@ -38,8 +38,8 @@ class Message:
|
|||||||
|
|
||||||
MESSAGE_ID = 0
|
MESSAGE_ID = 0
|
||||||
|
|
||||||
def __init__(self, message_type, author, iTime):
|
def __init__(self, message_type, author, time):
|
||||||
self._time = iTime
|
self._time = time
|
||||||
self._type = message_type
|
self._type = message_type
|
||||||
self._author = author
|
self._author = author
|
||||||
self._widget = None
|
self._widget = None
|
||||||
@ -66,7 +66,6 @@ class Message:
|
|||||||
message_id = property(get_message_id)
|
message_id = property(get_message_id)
|
||||||
|
|
||||||
def get_widget(self, *args):
|
def get_widget(self, *args):
|
||||||
# FixMe
|
|
||||||
self._widget = self._create_widget(*args)
|
self._widget = self._create_widget(*args)
|
||||||
|
|
||||||
return self._widget
|
return self._widget
|
||||||
@ -82,7 +81,6 @@ class Message:
|
|||||||
self._widget.mark_as_sent()
|
self._widget.mark_as_sent()
|
||||||
|
|
||||||
def _create_widget(self, *args):
|
def _create_widget(self, *args):
|
||||||
# overridden
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -97,8 +95,8 @@ class TextMessage(Message):
|
|||||||
Plain text or action message
|
Plain text or action message
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, message, owner, iTime, message_type, message_id=0):
|
def __init__(self, message, owner, time, message_type, message_id=0):
|
||||||
super().__init__(message_type, owner, iTime)
|
super().__init__(message_type, owner, time)
|
||||||
self._message = message
|
self._message = message
|
||||||
self._id = message_id
|
self._id = message_id
|
||||||
|
|
||||||
@ -121,8 +119,8 @@ class TextMessage(Message):
|
|||||||
|
|
||||||
class OutgoingTextMessage(TextMessage):
|
class OutgoingTextMessage(TextMessage):
|
||||||
|
|
||||||
def __init__(self, message, owner, iTime, message_type, tox_message_id=0):
|
def __init__(self, message, owner, time, message_type, tox_message_id=0):
|
||||||
super().__init__(message, owner, iTime, message_type)
|
super().__init__(message, owner, time, message_type)
|
||||||
self._tox_message_id = tox_message_id
|
self._tox_message_id = tox_message_id
|
||||||
|
|
||||||
def get_tox_message_id(self):
|
def get_tox_message_id(self):
|
||||||
@ -136,8 +134,8 @@ class OutgoingTextMessage(TextMessage):
|
|||||||
|
|
||||||
class GroupChatMessage(TextMessage):
|
class GroupChatMessage(TextMessage):
|
||||||
|
|
||||||
def __init__(self, id, message, owner, iTime, message_type, name):
|
def __init__(self, id, message, owner, time, message_type, name):
|
||||||
super().__init__(id, message, owner, iTime, message_type)
|
super().__init__(id, message, owner, time, message_type)
|
||||||
self._user_name = name
|
self._user_name = name
|
||||||
|
|
||||||
|
|
||||||
@ -146,8 +144,8 @@ class TransferMessage(Message):
|
|||||||
Message with info about file transfer
|
Message with info about file transfer
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, author, iTime, state, size, file_name, friend_number, file_number):
|
def __init__(self, author, time, state, size, file_name, friend_number, file_number):
|
||||||
super().__init__(MESSAGE_TYPE['FILE_TRANSFER'], author, iTime)
|
super().__init__(MESSAGE_TYPE['FILE_TRANSFER'], author, time)
|
||||||
self._state = state
|
self._state = state
|
||||||
self._size = size
|
self._size = size
|
||||||
self._file_name = file_name
|
self._file_name = file_name
|
||||||
@ -187,10 +185,10 @@ class TransferMessage(Message):
|
|||||||
|
|
||||||
file_name = property(get_file_name)
|
file_name = property(get_file_name)
|
||||||
|
|
||||||
def transfer_updated(self, state, percentage, iTime):
|
def transfer_updated(self, state, percentage, time):
|
||||||
self._state = state
|
self._state = state
|
||||||
if self._widget is not None:
|
if self._widget is not None:
|
||||||
self._widget.update_transfer_state(state, percentage, iTime)
|
self._widget.update_transfer_state(state, percentage, time)
|
||||||
|
|
||||||
def _create_widget(self, *args):
|
def _create_widget(self, *args):
|
||||||
return FileTransferItem(self, *args)
|
return FileTransferItem(self, *args)
|
||||||
@ -198,9 +196,9 @@ class TransferMessage(Message):
|
|||||||
|
|
||||||
class UnsentFileMessage(TransferMessage):
|
class UnsentFileMessage(TransferMessage):
|
||||||
|
|
||||||
def __init__(self, path, data, iTime, author, size, friend_number):
|
def __init__(self, path, data, time, author, size, friend_number):
|
||||||
file_name = os.path.basename(path)
|
file_name = os.path.basename(path)
|
||||||
super().__init__(author, iTime, FILE_TRANSFER_STATE['UNSENT'], size, file_name, friend_number, -1)
|
super().__init__(author, time, FILE_TRANSFER_STATE['UNSENT'], size, file_name, friend_number, -1)
|
||||||
self._data, self._path = data, path
|
self._data, self._path = data, path
|
||||||
|
|
||||||
def get_data(self):
|
def get_data(self):
|
||||||
@ -237,5 +235,5 @@ class InlineImageMessage(Message):
|
|||||||
|
|
||||||
class InfoMessage(TextMessage):
|
class InfoMessage(TextMessage):
|
||||||
|
|
||||||
def __init__(self, message, iTime):
|
def __init__(self, message, time):
|
||||||
super().__init__(message, None, iTime, MESSAGE_TYPE['INFO_MESSAGE'])
|
super().__init__(message, None, time, MESSAGE_TYPE['INFO_MESSAGE'])
|
||||||
|
@ -1,15 +1,6 @@
|
|||||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
|
||||||
import common.tox_save as tox_save
|
import common.tox_save as tox_save
|
||||||
import utils.ui as util_ui
|
|
||||||
|
|
||||||
from messenger.messages import *
|
from messenger.messages import *
|
||||||
from wrapper_tests.support_testing import assert_main_thread
|
|
||||||
from wrapper.toxcore_enums_and_consts import TOX_MAX_MESSAGE_LENGTH
|
|
||||||
|
|
||||||
global LOG
|
|
||||||
import logging
|
|
||||||
LOG = logging.getLogger('app.'+__name__)
|
|
||||||
log = lambda x: LOG.info(x)
|
|
||||||
|
|
||||||
class Messenger(tox_save.ToxSave):
|
class Messenger(tox_save.ToxSave):
|
||||||
|
|
||||||
@ -28,9 +19,6 @@ class Messenger(tox_save.ToxSave):
|
|||||||
calls_manager.call_started_event.add_callback(self._on_call_started)
|
calls_manager.call_started_event.add_callback(self._on_call_started)
|
||||||
calls_manager.call_finished_event.add_callback(self._on_call_finished)
|
calls_manager.call_finished_event.add_callback(self._on_call_finished)
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return "<Messenger>"
|
|
||||||
|
|
||||||
def get_last_message(self):
|
def get_last_message(self):
|
||||||
contact = self._contacts_manager.get_curr_contact()
|
contact = self._contacts_manager.get_curr_contact()
|
||||||
if contact is None:
|
if contact is None:
|
||||||
@ -63,53 +51,33 @@ class Messenger(tox_save.ToxSave):
|
|||||||
self._screen.messageEdit.clear()
|
self._screen.messageEdit.clear()
|
||||||
return
|
return
|
||||||
|
|
||||||
message_type = TOX_MESSAGE_TYPE['NORMAL']
|
action_message_prefix = '/me '
|
||||||
if False: # undocumented
|
if text.startswith(action_message_prefix):
|
||||||
action_message_prefix = '/me '
|
message_type = TOX_MESSAGE_TYPE['ACTION']
|
||||||
if text.startswith(action_message_prefix):
|
text = text[len(action_message_prefix):]
|
||||||
message_type = TOX_MESSAGE_TYPE['ACTION']
|
else:
|
||||||
text = text[len(action_message_prefix):]
|
message_type = TOX_MESSAGE_TYPE['NORMAL']
|
||||||
|
|
||||||
if len(text) > TOX_MAX_MESSAGE_LENGTH:
|
if self._contacts_manager.is_active_a_friend():
|
||||||
text = text[:TOX_MAX_MESSAGE_LENGTH] # 1372
|
self.send_message_to_friend(text, message_type)
|
||||||
try:
|
elif self._contacts_manager.is_active_a_group():
|
||||||
if self._contacts_manager.is_active_a_friend():
|
self.send_message_to_group(text, message_type)
|
||||||
self.send_message_to_friend(text, message_type)
|
elif self._contacts_manager.is_active_a_group_chat_peer():
|
||||||
elif self._contacts_manager.is_active_a_group():
|
self.send_message_to_group_peer(text, message_type)
|
||||||
self.send_message_to_group('~'+text, message_type)
|
|
||||||
elif self._contacts_manager.is_active_a_group_chat_peer():
|
|
||||||
self.send_message_to_group_peer(text, message_type)
|
|
||||||
else:
|
|
||||||
LOG.warn(f'Unknown friend type for Messenger send_message')
|
|
||||||
except Exception as e:
|
|
||||||
LOG.error(f'Messenger send_message {e}')
|
|
||||||
import traceback
|
|
||||||
LOG.warn(traceback.format_exc())
|
|
||||||
title = 'Messenger send_message Error'
|
|
||||||
text = 'Error: ' + str(e)
|
|
||||||
assert_main_thread()
|
|
||||||
util_ui.message_box(text, title)
|
|
||||||
|
|
||||||
def send_message_to_friend(self, text, message_type, friend_number=None):
|
def send_message_to_friend(self, text, message_type, friend_number=None):
|
||||||
"""
|
"""
|
||||||
Send message
|
Send message
|
||||||
:param text: message text
|
:param text: message text
|
||||||
:param friend_number: number of friend
|
:param friend_number: number of friend
|
||||||
from Qt callback
|
|
||||||
"""
|
"""
|
||||||
if not text:
|
|
||||||
return
|
|
||||||
if friend_number is None:
|
if friend_number is None:
|
||||||
friend_number = self._contacts_manager.get_active_number()
|
friend_number = self._contacts_manager.get_active_number()
|
||||||
if friend_number is None or friend_number < 0:
|
|
||||||
LOG.error(f"No _contacts_manager.get_active_number")
|
if not text or friend_number < 0:
|
||||||
return
|
return
|
||||||
assert_main_thread()
|
|
||||||
|
|
||||||
friend = self._get_friend_by_number(friend_number)
|
friend = self._get_friend_by_number(friend_number)
|
||||||
if not friend:
|
|
||||||
LOG.error(f"No self._get_friend_by_number")
|
|
||||||
return
|
|
||||||
messages = self._split_message(text.encode('utf-8'))
|
messages = self._split_message(text.encode('utf-8'))
|
||||||
t = util.get_unix_time()
|
t = util.get_unix_time()
|
||||||
for message in messages:
|
for message in messages:
|
||||||
@ -138,7 +106,7 @@ class Messenger(tox_save.ToxSave):
|
|||||||
message_id = self._tox.friend_send_message(friend_number, message.type, message.text.encode('utf-8'))
|
message_id = self._tox.friend_send_message(friend_number, message.type, message.text.encode('utf-8'))
|
||||||
message.tox_message_id = message_id
|
message.tox_message_id = message_id
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
LOG.warn('Sending pending messages failed with ' + str(ex))
|
util.log('Sending pending messages failed with ' + str(ex))
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
# Messaging - groups
|
# Messaging - groups
|
||||||
@ -173,13 +141,7 @@ class Messenger(tox_save.ToxSave):
|
|||||||
"""
|
"""
|
||||||
t = util.get_unix_time()
|
t = util.get_unix_time()
|
||||||
group = self._get_group_by_number(group_number)
|
group = self._get_group_by_number(group_number)
|
||||||
if not group:
|
|
||||||
LOG.error(f"FixMe new_group_message _get_group_by_number({group_number})")
|
|
||||||
return
|
|
||||||
peer = group.get_peer_by_id(peer_id)
|
peer = group.get_peer_by_id(peer_id)
|
||||||
if not peer:
|
|
||||||
LOG.error('FixMe new_group_message group.get_peer_by_id ' + str(peer_id))
|
|
||||||
return
|
|
||||||
text_message = TextMessage(message, MessageAuthor(peer.name, MESSAGE_AUTHOR['GC_PEER']), t, message_type)
|
text_message = TextMessage(message, MessageAuthor(peer.name, MESSAGE_AUTHOR['GC_PEER']), t, message_type)
|
||||||
self._add_message(text_message, group)
|
self._add_message(text_message, group)
|
||||||
|
|
||||||
@ -194,17 +156,10 @@ class Messenger(tox_save.ToxSave):
|
|||||||
group = self._get_group_by_public_key(group_peer_contact.group_pk)
|
group = self._get_group_by_public_key(group_peer_contact.group_pk)
|
||||||
group_number = group.number
|
group_number = group.number
|
||||||
|
|
||||||
if not text:
|
if not text or group_number < 0 or peer_id < 0:
|
||||||
return
|
|
||||||
if group.number < 0:
|
|
||||||
return
|
|
||||||
if peer_id and peer_id < 0:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
assert_main_thread()
|
|
||||||
# FixMe: peer_id is None?
|
|
||||||
group_peer_contact = self._contacts_manager.get_or_create_group_peer_contact(group_number, peer_id)
|
group_peer_contact = self._contacts_manager.get_or_create_group_peer_contact(group_number, peer_id)
|
||||||
# group_peer_contact now may be None
|
|
||||||
group = self._get_group_by_number(group_number)
|
group = self._get_group_by_number(group_number)
|
||||||
messages = self._split_message(text.encode('utf-8'))
|
messages = self._split_message(text.encode('utf-8'))
|
||||||
t = util.get_unix_time()
|
t = util.get_unix_time()
|
||||||
@ -227,15 +182,9 @@ class Messenger(tox_save.ToxSave):
|
|||||||
t = util.get_unix_time()
|
t = util.get_unix_time()
|
||||||
group = self._get_group_by_number(group_number)
|
group = self._get_group_by_number(group_number)
|
||||||
peer = group.get_peer_by_id(peer_id)
|
peer = group.get_peer_by_id(peer_id)
|
||||||
if not peer:
|
|
||||||
LOG.warn('FixMe new_group_private_message group.get_peer_by_id ' + str(peer_id))
|
|
||||||
return
|
|
||||||
text_message = TextMessage(message, MessageAuthor(peer.name, MESSAGE_AUTHOR['GC_PEER']),
|
text_message = TextMessage(message, MessageAuthor(peer.name, MESSAGE_AUTHOR['GC_PEER']),
|
||||||
t, message_type)
|
t, message_type)
|
||||||
group_peer_contact = self._contacts_manager.get_or_create_group_peer_contact(group_number, peer_id)
|
group_peer_contact = self._contacts_manager.get_or_create_group_peer_contact(group_number, peer_id)
|
||||||
if not group_peer_contact:
|
|
||||||
LOG.warn('FixMe new_group_private_message group_peer_contact ' + str(peer_id))
|
|
||||||
return
|
|
||||||
self._add_message(text_message, group_peer_contact)
|
self._add_message(text_message, group_peer_contact)
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
@ -336,29 +285,21 @@ class Messenger(tox_save.ToxSave):
|
|||||||
|
|
||||||
def _add_info_message(self, friend_number, text):
|
def _add_info_message(self, friend_number, text):
|
||||||
friend = self._get_friend_by_number(friend_number)
|
friend = self._get_friend_by_number(friend_number)
|
||||||
assert friend
|
|
||||||
message = InfoMessage(text, util.get_unix_time())
|
message = InfoMessage(text, util.get_unix_time())
|
||||||
friend.append_message(message)
|
friend.append_message(message)
|
||||||
if self._contacts_manager.is_friend_active(friend_number):
|
if self._contacts_manager.is_friend_active(friend_number):
|
||||||
self._create_info_message_item(message)
|
self._create_info_message_item(message)
|
||||||
|
|
||||||
def _create_info_message_item(self, message):
|
def _create_info_message_item(self, message):
|
||||||
assert_main_thread()
|
|
||||||
self._items_factory.create_message_item(message)
|
self._items_factory.create_message_item(message)
|
||||||
self._screen.messages.scrollToBottom()
|
self._screen.messages.scrollToBottom()
|
||||||
|
|
||||||
def _add_message(self, text_message, contact):
|
def _add_message(self, text_message, contact):
|
||||||
assert_main_thread()
|
|
||||||
if not contact:
|
|
||||||
LOG.warn("_add_message null contact")
|
|
||||||
return
|
|
||||||
if self._contacts_manager.is_contact_active(contact): # add message to list
|
if self._contacts_manager.is_contact_active(contact): # add message to list
|
||||||
# LOG.debug("_add_message is_contact_active(contact)")
|
|
||||||
self._create_message_item(text_message)
|
self._create_message_item(text_message)
|
||||||
self._screen.messages.scrollToBottom()
|
self._screen.messages.scrollToBottom()
|
||||||
self._contacts_manager.get_curr_contact().append_message(text_message)
|
self._contacts_manager.get_curr_contact().append_message(text_message)
|
||||||
else:
|
else:
|
||||||
# LOG.debug("_add_message not is_contact_active(contact)")
|
|
||||||
contact.inc_messages()
|
contact.inc_messages()
|
||||||
contact.append_message(text_message)
|
contact.append_message(text_message)
|
||||||
if not contact.visibility:
|
if not contact.visibility:
|
||||||
|
@ -1,48 +1,15 @@
|
|||||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
import threading
|
|
||||||
from PyQt5 import QtGui
|
from PyQt5 import QtGui
|
||||||
from wrapper.toxcore_enums_and_consts import *
|
from wrapper.toxcore_enums_and_consts import *
|
||||||
from wrapper.toxav_enums import *
|
from wrapper.toxav_enums import *
|
||||||
from wrapper.tox import bin_to_string
|
from wrapper.tox import bin_to_string
|
||||||
import utils.ui as util_ui
|
import utils.ui as util_ui
|
||||||
import utils.util as util
|
import utils.util as util
|
||||||
|
import cv2
|
||||||
|
import numpy as np
|
||||||
from middleware.threads import invoke_in_main_thread, execute
|
from middleware.threads import invoke_in_main_thread, execute
|
||||||
from notifications.tray import tray_notification
|
from notifications.tray import tray_notification
|
||||||
from notifications.sound import *
|
from notifications.sound import *
|
||||||
from datetime import datetime
|
import threading
|
||||||
|
|
||||||
iMAX_INT32 = 4294967295
|
|
||||||
# callbacks can be called in any thread so were being careful
|
|
||||||
def LOG_ERROR(l): print('EROR< '+l)
|
|
||||||
def LOG_WARN(l): print('WARN< '+l)
|
|
||||||
def LOG_INFO(l):
|
|
||||||
bIsVerbose = hasattr(__builtins__, 'app') and app.oArgs.loglevel <= 20-1
|
|
||||||
if bIsVerbose: print('INFO< '+l)
|
|
||||||
def LOG_DEBUG(l):
|
|
||||||
bIsVerbose = hasattr(__builtins__, 'app') and app.oArgs.loglevel <= 10-1
|
|
||||||
if bIsVerbose: print('DBUG< '+l)
|
|
||||||
def LOG_TRACE(l):
|
|
||||||
bIsVerbose = hasattr(__builtins__, 'app') and app.oArgs.loglevel < 10-1
|
|
||||||
pass # print('TRACE+ '+l)
|
|
||||||
|
|
||||||
global aTIMES
|
|
||||||
aTIMES=dict()
|
|
||||||
def bTooSoon(key, sSlot, fSec=10.0):
|
|
||||||
# rate limiting
|
|
||||||
global aTIMES
|
|
||||||
if sSlot not in aTIMES:
|
|
||||||
aTIMES[sSlot] = dict()
|
|
||||||
OTIME = aTIMES[sSlot]
|
|
||||||
now = datetime.now()
|
|
||||||
if key not in OTIME:
|
|
||||||
OTIME[key] = now
|
|
||||||
return False
|
|
||||||
delta = now - OTIME[key]
|
|
||||||
OTIME[key] = now
|
|
||||||
if delta.total_seconds() < fSec: return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
# TODO: refactoring. Use contact provider instead of manager
|
# TODO: refactoring. Use contact provider instead of manager
|
||||||
|
|
||||||
@ -50,47 +17,15 @@ def bTooSoon(key, sSlot, fSec=10.0):
|
|||||||
# Callbacks - current user
|
# Callbacks - current user
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
global iBYTES
|
|
||||||
iBYTES=0
|
|
||||||
def sProcBytes(sFile=None):
|
|
||||||
if sys.platform == 'win32': return ''
|
|
||||||
global iBYTES
|
|
||||||
if sFile is None:
|
|
||||||
pid = os.getpid()
|
|
||||||
sFile = f"/proc/{pid}/net/softnet_stat"
|
|
||||||
if os.path.exists(sFile):
|
|
||||||
total = 0
|
|
||||||
with open(sFile, 'r') as iFd:
|
|
||||||
for elt in iFd.readlines():
|
|
||||||
i = elt.find(' ')
|
|
||||||
p = int(elt[:i], 16)
|
|
||||||
total = total + p
|
|
||||||
if iBYTES == 0:
|
|
||||||
iBYTES = total
|
|
||||||
return ''
|
|
||||||
diff = total - iBYTES
|
|
||||||
s = f' {diff // 1024} Kbytes'
|
|
||||||
else:
|
|
||||||
s = ''
|
|
||||||
return s
|
|
||||||
|
|
||||||
def self_connection_status(tox, profile):
|
def self_connection_status(tox, profile):
|
||||||
"""
|
"""
|
||||||
Current user changed connection status (offline, TCP, UDP)
|
Current user changed connection status (offline, TCP, UDP)
|
||||||
"""
|
"""
|
||||||
sSlot = 'self connection status'
|
|
||||||
def wrapped(tox_link, connection, user_data):
|
def wrapped(tox_link, connection, user_data):
|
||||||
key = f"connection {connection}"
|
print('Connection status: ', str(connection))
|
||||||
if bTooSoon(key, sSlot, 10): return
|
status = tox.self_get_status() if connection != TOX_CONNECTION['NONE'] else None
|
||||||
s = sProcBytes()
|
invoke_in_main_thread(profile.set_status, status)
|
||||||
try:
|
|
||||||
status = tox.self_get_status() if connection != TOX_CONNECTION['NONE'] else None
|
|
||||||
if status:
|
|
||||||
LOG_DEBUG(f"self_connection_status: connection={connection} status={status}" +' '+s)
|
|
||||||
invoke_in_main_thread(profile.set_status, status)
|
|
||||||
except Exception as e:
|
|
||||||
LOG_ERROR(f"self_connection_status: {e}")
|
|
||||||
pass
|
|
||||||
|
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
@ -101,17 +36,13 @@ def self_connection_status(tox, profile):
|
|||||||
|
|
||||||
|
|
||||||
def friend_status(contacts_manager, file_transfer_handler, profile, settings):
|
def friend_status(contacts_manager, file_transfer_handler, profile, settings):
|
||||||
sSlot = 'friend status'
|
|
||||||
def wrapped(tox, friend_number, new_status, user_data):
|
def wrapped(tox, friend_number, new_status, user_data):
|
||||||
"""
|
"""
|
||||||
Check friend's status (none, busy, away)
|
Check friend's status (none, busy, away)
|
||||||
"""
|
"""
|
||||||
LOG_DEBUG(f"Friend's #{friend_number} status changed")
|
print("Friend's #{} status changed!".format(friend_number))
|
||||||
key = f"friend_number {friend_number}"
|
|
||||||
if bTooSoon(key, sSlot, 10): return
|
|
||||||
friend = contacts_manager.get_friend_by_number(friend_number)
|
friend = contacts_manager.get_friend_by_number(friend_number)
|
||||||
if friend.status is None and settings['sound_notifications'] and \
|
if friend.status is None and settings['sound_notifications'] and profile.status != TOX_USER_STATUS['BUSY']:
|
||||||
profile.status != TOX_USER_STATUS['BUSY']:
|
|
||||||
sound_notification(SOUND_NOTIFICATION['FRIEND_CONNECTION_STATUS'])
|
sound_notification(SOUND_NOTIFICATION['FRIEND_CONNECTION_STATUS'])
|
||||||
invoke_in_main_thread(friend.set_status, new_status)
|
invoke_in_main_thread(friend.set_status, new_status)
|
||||||
|
|
||||||
@ -130,7 +61,7 @@ def friend_connection_status(contacts_manager, profile, settings, plugin_loader,
|
|||||||
"""
|
"""
|
||||||
Check friend's connection status (offline, udp, tcp)
|
Check friend's connection status (offline, udp, tcp)
|
||||||
"""
|
"""
|
||||||
LOG_DEBUG(f"Friend #{friend_number} connection status: {new_status}")
|
print("Friend #{} connection status: {}".format(friend_number, new_status))
|
||||||
friend = contacts_manager.get_friend_by_number(friend_number)
|
friend = contacts_manager.get_friend_by_number(friend_number)
|
||||||
if new_status == TOX_CONNECTION['NONE']:
|
if new_status == TOX_CONNECTION['NONE']:
|
||||||
invoke_in_main_thread(friend.set_status, None)
|
invoke_in_main_thread(friend.set_status, None)
|
||||||
@ -148,35 +79,29 @@ def friend_connection_status(contacts_manager, profile, settings, plugin_loader,
|
|||||||
|
|
||||||
|
|
||||||
def friend_name(contacts_provider, messenger):
|
def friend_name(contacts_provider, messenger):
|
||||||
sSlot = 'friend_name'
|
|
||||||
def wrapped(tox, friend_number, name, size, user_data):
|
def wrapped(tox, friend_number, name, size, user_data):
|
||||||
"""
|
"""
|
||||||
Friend changed his name
|
Friend changed his name
|
||||||
"""
|
"""
|
||||||
key = f"friend_number={friend_number}"
|
print('New name friend #' + str(friend_number))
|
||||||
if bTooSoon(key, sSlot, 60): return
|
|
||||||
friend = contacts_provider.get_friend_by_number(friend_number)
|
friend = contacts_provider.get_friend_by_number(friend_number)
|
||||||
old_name = friend.name
|
old_name = friend.name
|
||||||
new_name = str(name, 'utf-8')
|
new_name = str(name, 'utf-8')
|
||||||
LOG_DEBUG(f"get_friend_by_number #{friend_number} {new_name}")
|
|
||||||
invoke_in_main_thread(friend.set_name, new_name)
|
invoke_in_main_thread(friend.set_name, new_name)
|
||||||
invoke_in_main_thread(messenger.new_friend_name, friend, old_name, new_name)
|
invoke_in_main_thread(messenger.new_friend_name, friend, old_name, new_name)
|
||||||
|
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
|
|
||||||
def friend_status_message(contacts_manager, messenger):
|
def friend_status_message(contacts_manager, messenger):
|
||||||
sSlot = 'status_message'
|
|
||||||
def wrapped(tox, friend_number, status_message, size, user_data):
|
def wrapped(tox, friend_number, status_message, size, user_data):
|
||||||
"""
|
"""
|
||||||
:return: function for callback friend_status_message. It updates friend's status message
|
:return: function for callback friend_status_message. It updates friend's status message
|
||||||
and calls window repaint
|
and calls window repaint
|
||||||
"""
|
"""
|
||||||
friend = contacts_manager.get_friend_by_number(friend_number)
|
friend = contacts_manager.get_friend_by_number(friend_number)
|
||||||
key = f"friend_number={friend_number}"
|
|
||||||
if bTooSoon(key, sSlot, 10): return
|
|
||||||
|
|
||||||
invoke_in_main_thread(friend.set_status_message, str(status_message, 'utf-8'))
|
invoke_in_main_thread(friend.set_status_message, str(status_message, 'utf-8'))
|
||||||
LOG_DEBUG(f'User #{friend_number} has new status message')
|
print('User #{} has new status message'.format(friend_number))
|
||||||
invoke_in_main_thread(messenger.send_messages, friend_number)
|
invoke_in_main_thread(messenger.send_messages, friend_number)
|
||||||
|
|
||||||
return wrapped
|
return wrapped
|
||||||
@ -187,20 +112,16 @@ def friend_message(messenger, contacts_manager, profile, settings, window, tray)
|
|||||||
"""
|
"""
|
||||||
New message from friend
|
New message from friend
|
||||||
"""
|
"""
|
||||||
LOG_DEBUG(f"friend_message #{friend_number}")
|
|
||||||
message = str(message, 'utf-8')
|
message = str(message, 'utf-8')
|
||||||
invoke_in_main_thread(messenger.new_message, friend_number, message_type, message)
|
invoke_in_main_thread(messenger.new_message, friend_number, message_type, message)
|
||||||
if not window.isActiveWindow():
|
if not window.isActiveWindow():
|
||||||
friend = contacts_manager.get_friend_by_number(friend_number)
|
friend = contacts_manager.get_friend_by_number(friend_number)
|
||||||
if settings['notifications'] \
|
if settings['notifications'] and profile.status != TOX_USER_STATUS['BUSY'] and not settings.locked:
|
||||||
and profile.status != TOX_USER_STATUS['BUSY'] \
|
|
||||||
and not settings.locked:
|
|
||||||
invoke_in_main_thread(tray_notification, friend.name, message, tray, window)
|
invoke_in_main_thread(tray_notification, friend.name, message, tray, window)
|
||||||
if settings['sound_notifications'] and profile.status != TOX_USER_STATUS['BUSY']:
|
if settings['sound_notifications'] and profile.status != TOX_USER_STATUS['BUSY']:
|
||||||
sound_notification(SOUND_NOTIFICATION['MESSAGE'])
|
sound_notification(SOUND_NOTIFICATION['MESSAGE'])
|
||||||
icon = os.path.join(util.get_images_directory(), 'icon_new_messages.png')
|
icon = os.path.join(util.get_images_directory(), 'icon_new_messages.png')
|
||||||
if tray:
|
invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon))
|
||||||
invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon))
|
|
||||||
|
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
@ -210,7 +131,7 @@ def friend_request(contacts_manager):
|
|||||||
"""
|
"""
|
||||||
Called when user get new friend request
|
Called when user get new friend request
|
||||||
"""
|
"""
|
||||||
LOG_DEBUG(f'Friend request')
|
print('Friend request')
|
||||||
key = ''.join(chr(x) for x in public_key[:TOX_PUBLIC_KEY_SIZE])
|
key = ''.join(chr(x) for x in public_key[:TOX_PUBLIC_KEY_SIZE])
|
||||||
tox_id = bin_to_string(key, TOX_PUBLIC_KEY_SIZE)
|
tox_id = bin_to_string(key, TOX_PUBLIC_KEY_SIZE)
|
||||||
invoke_in_main_thread(contacts_manager.process_friend_request, tox_id, str(message, 'utf-8'))
|
invoke_in_main_thread(contacts_manager.process_friend_request, tox_id, str(message, 'utf-8'))
|
||||||
@ -219,12 +140,9 @@ def friend_request(contacts_manager):
|
|||||||
|
|
||||||
|
|
||||||
def friend_typing(messenger):
|
def friend_typing(messenger):
|
||||||
sSlot = "friend_typing"
|
|
||||||
def wrapped(tox, friend_number, typing, user_data):
|
def wrapped(tox, friend_number, typing, user_data):
|
||||||
key = f"friend_number={friend_number}"
|
|
||||||
if bTooSoon(key, sSlot, 10): return
|
|
||||||
LOG_DEBUG(f"friend_typing #{friend_number}")
|
|
||||||
invoke_in_main_thread(messenger.friend_typing, friend_number, typing)
|
invoke_in_main_thread(messenger.friend_typing, friend_number, typing)
|
||||||
|
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
|
|
||||||
@ -246,7 +164,7 @@ def tox_file_recv(window, tray, profile, file_transfer_handler, contacts_manager
|
|||||||
"""
|
"""
|
||||||
def wrapped(tox, friend_number, file_number, file_type, size, file_name, file_name_size, user_data):
|
def wrapped(tox, friend_number, file_number, file_type, size, file_name, file_name_size, user_data):
|
||||||
if file_type == TOX_FILE_KIND['DATA']:
|
if file_type == TOX_FILE_KIND['DATA']:
|
||||||
LOG_DEBUG(f'file_transfer_handler File')
|
print('File')
|
||||||
try:
|
try:
|
||||||
file_name = str(file_name[:file_name_size], 'utf-8')
|
file_name = str(file_name[:file_name_size], 'utf-8')
|
||||||
except:
|
except:
|
||||||
@ -258,18 +176,15 @@ def tox_file_recv(window, tray, profile, file_transfer_handler, contacts_manager
|
|||||||
file_name)
|
file_name)
|
||||||
if not window.isActiveWindow():
|
if not window.isActiveWindow():
|
||||||
friend = contacts_manager.get_friend_by_number(friend_number)
|
friend = contacts_manager.get_friend_by_number(friend_number)
|
||||||
if settings['notifications'] \
|
if settings['notifications'] and profile.status != TOX_USER_STATUS['BUSY'] and not settings.locked:
|
||||||
and profile.status != TOX_USER_STATUS['BUSY'] \
|
|
||||||
and not settings.locked:
|
|
||||||
file_from = util_ui.tr("File from")
|
file_from = util_ui.tr("File from")
|
||||||
invoke_in_main_thread(tray_notification, file_from + ' ' + friend.name, file_name, tray, window)
|
invoke_in_main_thread(tray_notification, file_from + ' ' + friend.name, file_name, tray, window)
|
||||||
if settings['sound_notifications'] and profile.status != TOX_USER_STATUS['BUSY']:
|
if settings['sound_notifications'] and profile.status != TOX_USER_STATUS['BUSY']:
|
||||||
sound_notification(SOUND_NOTIFICATION['FILE_TRANSFER'])
|
sound_notification(SOUND_NOTIFICATION['FILE_TRANSFER'])
|
||||||
if tray:
|
icon = util.join_path(util.get_images_directory(), 'icon_new_messages.png')
|
||||||
icon = util.join_path(util.get_images_directory(), 'icon_new_messages.png')
|
invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon))
|
||||||
invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon))
|
|
||||||
else: # avatar
|
else: # avatar
|
||||||
LOG_DEBUG(f'file_transfer_handler Avatar')
|
print('Avatar')
|
||||||
invoke_in_main_thread(file_transfer_handler.incoming_avatar,
|
invoke_in_main_thread(file_transfer_handler.incoming_avatar,
|
||||||
friend_number,
|
friend_number,
|
||||||
file_number,
|
file_number,
|
||||||
@ -344,17 +259,15 @@ def lossy_packet(plugin_loader):
|
|||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
def call_state(calls_manager):
|
def call_state(calls_manager):
|
||||||
def wrapped(iToxav, friend_number, mask, user_data):
|
def wrapped(toxav, friend_number, mask, user_data):
|
||||||
"""
|
"""
|
||||||
New call state
|
New call state
|
||||||
"""
|
"""
|
||||||
LOG_DEBUG(f"call_state #{friend_number}")
|
print(friend_number, mask)
|
||||||
if mask == TOXAV_FRIEND_CALL_STATE['FINISHED'] or mask == TOXAV_FRIEND_CALL_STATE['ERROR']:
|
if mask == TOXAV_FRIEND_CALL_STATE['FINISHED'] or mask == TOXAV_FRIEND_CALL_STATE['ERROR']:
|
||||||
invoke_in_main_thread(calls_manager.stop_call, friend_number, True)
|
invoke_in_main_thread(calls_manager.stop_call, friend_number, True)
|
||||||
else:
|
else:
|
||||||
# guessing was calls_manager.
|
calls_manager.toxav_call_state_cb(friend_number, mask)
|
||||||
#? incoming_call
|
|
||||||
calls_manager._call.toxav_call_state_cb(friend_number, mask)
|
|
||||||
|
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
@ -364,7 +277,7 @@ def call(calls_manager):
|
|||||||
"""
|
"""
|
||||||
Incoming call from friend
|
Incoming call from friend
|
||||||
"""
|
"""
|
||||||
LOG_DEBUG(f"Incoming call from {friend_number} {audio} {video}")
|
print(friend_number, audio, video)
|
||||||
invoke_in_main_thread(calls_manager.incoming_call, audio, video, friend_number)
|
invoke_in_main_thread(calls_manager.incoming_call, audio, video, friend_number)
|
||||||
|
|
||||||
return wrapped
|
return wrapped
|
||||||
@ -375,9 +288,7 @@ def callback_audio(calls_manager):
|
|||||||
"""
|
"""
|
||||||
New audio chunk
|
New audio chunk
|
||||||
"""
|
"""
|
||||||
LOG_DEBUG(f"callback_audio #{friend_number}")
|
calls_manager.call.audio_chunk(
|
||||||
# dunno was .call
|
|
||||||
calls_manager._call.audio_chunk(
|
|
||||||
bytes(samples[:audio_samples_per_channel * 2 * audio_channels_count]),
|
bytes(samples[:audio_samples_per_channel * 2 * audio_channels_count]),
|
||||||
audio_channels_count,
|
audio_channels_count,
|
||||||
rate)
|
rate)
|
||||||
@ -413,9 +324,6 @@ def video_receive_frame(toxav, friend_number, width, height, y, u, v, ystride, u
|
|||||||
|
|
||||||
It can be created from initial y, u, v using slices
|
It can be created from initial y, u, v using slices
|
||||||
"""
|
"""
|
||||||
LOG_DEBUG(f"video_receive_frame from toxav_video_receive_frame_cb={friend_number}")
|
|
||||||
import cv2
|
|
||||||
import numpy as np
|
|
||||||
try:
|
try:
|
||||||
y_size = abs(max(width, abs(ystride)))
|
y_size = abs(max(width, abs(ystride)))
|
||||||
u_size = abs(max(width // 2, abs(ustride)))
|
u_size = abs(max(width // 2, abs(ustride)))
|
||||||
@ -441,8 +349,7 @@ def video_receive_frame(toxav, friend_number, width, height, y, u, v, ystride, u
|
|||||||
|
|
||||||
invoke_in_main_thread(cv2.imshow, str(friend_number), frame)
|
invoke_in_main_thread(cv2.imshow, str(friend_number), frame)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
LOG_ERROR(f"video_receive_frame {ex} #{friend_number}")
|
print(ex)
|
||||||
pass
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
# Callbacks - groups
|
# Callbacks - groups
|
||||||
@ -454,24 +361,18 @@ def group_message(window, tray, tox, messenger, settings, profile):
|
|||||||
New message in group chat
|
New message in group chat
|
||||||
"""
|
"""
|
||||||
def wrapped(tox_link, group_number, peer_id, message_type, message, length, user_data):
|
def wrapped(tox_link, group_number, peer_id, message_type, message, length, user_data):
|
||||||
LOG_DEBUG(f"group_message #{group_number}")
|
|
||||||
message = str(message[:length], 'utf-8')
|
message = str(message[:length], 'utf-8')
|
||||||
invoke_in_main_thread(messenger.new_group_message, group_number, message_type, message, peer_id)
|
invoke_in_main_thread(messenger.new_group_message, group_number, message_type, message, peer_id)
|
||||||
if window.isActiveWindow():
|
if window.isActiveWindow():
|
||||||
return
|
return
|
||||||
bl = settings['notify_all_gc'] or profile.name in message
|
bl = settings['notify_all_gc'] or profile.name in message
|
||||||
name = tox.group_peer_get_name(group_number, peer_id)
|
name = tox.group_peer_get_name(group_number, peer_id)
|
||||||
if settings['sound_notifications'] and bl and \
|
if settings['notifications'] and profile.status != TOX_USER_STATUS['BUSY'] and (not settings.locked) and bl:
|
||||||
profile.status != TOX_USER_STATUS['BUSY']:
|
invoke_in_main_thread(tray_notification, name, message, tray, window)
|
||||||
|
if settings['sound_notifications'] and bl and profile.status != TOX_USER_STATUS['BUSY']:
|
||||||
sound_notification(SOUND_NOTIFICATION['MESSAGE'])
|
sound_notification(SOUND_NOTIFICATION['MESSAGE'])
|
||||||
if False and settings['tray_icon'] and tray:
|
icon = util.join_path(util.get_images_directory(), 'icon_new_messages.png')
|
||||||
if settings['notifications'] and \
|
invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon))
|
||||||
profile.status != TOX_USER_STATUS['BUSY'] and \
|
|
||||||
(not settings.locked) and bl:
|
|
||||||
invoke_in_main_thread(tray_notification, name, message, tray, window)
|
|
||||||
if tray:
|
|
||||||
icon = util.join_path(util.get_images_directory(), 'icon_new_messages.png')
|
|
||||||
invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon))
|
|
||||||
|
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
@ -481,83 +382,54 @@ def group_private_message(window, tray, tox, messenger, settings, profile):
|
|||||||
New private message in group chat
|
New private message in group chat
|
||||||
"""
|
"""
|
||||||
def wrapped(tox_link, group_number, peer_id, message_type, message, length, user_data):
|
def wrapped(tox_link, group_number, peer_id, message_type, message, length, user_data):
|
||||||
LOG_DEBUG(f"group_private_message #{group_number}")
|
|
||||||
message = str(message[:length], 'utf-8')
|
message = str(message[:length], 'utf-8')
|
||||||
invoke_in_main_thread(messenger.new_group_private_message, group_number, message_type, message, peer_id)
|
invoke_in_main_thread(messenger.new_group_private_message, group_number, message_type, message, peer_id)
|
||||||
if window.isActiveWindow():
|
if window.isActiveWindow():
|
||||||
return
|
return
|
||||||
bl = settings['notify_all_gc'] or profile.name in message
|
bl = settings['notify_all_gc'] or profile.name in message
|
||||||
name = tox.group_peer_get_name(group_number, peer_id)
|
name = tox.group_peer_get_name(group_number, peer_id)
|
||||||
if settings['notifications'] and settings['tray_icon'] \
|
if settings['notifications'] and profile.status != TOX_USER_STATUS['BUSY'] and (not settings.locked) and bl:
|
||||||
and profile.status != TOX_USER_STATUS['BUSY'] \
|
|
||||||
and (not settings.locked) and bl:
|
|
||||||
invoke_in_main_thread(tray_notification, name, message, tray, window)
|
invoke_in_main_thread(tray_notification, name, message, tray, window)
|
||||||
if settings['sound_notifications'] and bl and profile.status != TOX_USER_STATUS['BUSY']:
|
if settings['sound_notifications'] and bl and profile.status != TOX_USER_STATUS['BUSY']:
|
||||||
sound_notification(SOUND_NOTIFICATION['MESSAGE'])
|
sound_notification(SOUND_NOTIFICATION['MESSAGE'])
|
||||||
icon = util.join_path(util.get_images_directory(), 'icon_new_messages.png')
|
icon = util.join_path(util.get_images_directory(), 'icon_new_messages.png')
|
||||||
if tray and hasattr(tray, 'setIcon'):
|
invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon))
|
||||||
invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon))
|
|
||||||
|
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
# Exception ignored on calling ctypes callback function: <function group_invite.<locals>.wrapped at 0x7ffede910700>
|
|
||||||
def group_invite(window, settings, tray, profile, groups_service, contacts_provider):
|
def group_invite(window, settings, tray, profile, groups_service, contacts_provider):
|
||||||
def wrapped(tox, friend_number, invite_data, length, group_name, group_name_length, user_data):
|
def wrapped(tox, friend_number, invite_data, length, group_name, group_name_length, user_data):
|
||||||
LOG_DEBUG(f"group_invite friend_number={friend_number}")
|
|
||||||
group_name = str(bytes(group_name[:group_name_length]), 'utf-8')
|
group_name = str(bytes(group_name[:group_name_length]), 'utf-8')
|
||||||
invoke_in_main_thread(groups_service.process_group_invite,
|
invoke_in_main_thread(groups_service.process_group_invite,
|
||||||
friend_number, group_name,
|
friend_number, group_name,
|
||||||
bytes(invite_data[:length]))
|
bytes(invite_data[:length]))
|
||||||
if window.isActiveWindow():
|
if window.isActiveWindow():
|
||||||
return
|
return
|
||||||
bHasTray = tray and settings['tray_icon']
|
if settings['notifications'] and profile.status != TOX_USER_STATUS['BUSY'] and not settings.locked:
|
||||||
if settings['notifications'] \
|
|
||||||
and bHasTray \
|
|
||||||
and profile.status != TOX_USER_STATUS['BUSY'] \
|
|
||||||
and not settings.locked:
|
|
||||||
friend = contacts_provider.get_friend_by_number(friend_number)
|
friend = contacts_provider.get_friend_by_number(friend_number)
|
||||||
title = util_ui.tr('New invite to group chat')
|
title = util_ui.tr('New invite to group chat')
|
||||||
text = util_ui.tr('{} invites you to group "{}"').format(friend.name, group_name)
|
text = util_ui.tr('{} invites you to group "{}"').format(friend.name, group_name)
|
||||||
invoke_in_main_thread(tray_notification, title, text, tray, window)
|
invoke_in_main_thread(tray_notification, title, text, tray, window)
|
||||||
if tray:
|
icon = util.join_path(util.get_images_directory(), 'icon_new_messages.png')
|
||||||
icon = util.join_path(util.get_images_directory(), 'icon_new_messages.png')
|
invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon))
|
||||||
invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon))
|
|
||||||
|
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
|
|
||||||
def group_self_join(contacts_provider, contacts_manager, groups_service):
|
def group_self_join(contacts_provider, contacts_manager, groups_service):
|
||||||
sSlot = 'group_self_join'
|
|
||||||
def wrapped(tox, group_number, user_data):
|
def wrapped(tox, group_number, user_data):
|
||||||
if group_number is None:
|
|
||||||
LOG_ERROR(f"group_self_join NULL group_number #{group_number}")
|
|
||||||
return
|
|
||||||
LOG_DEBUG(f"group_self_join #{group_number}")
|
|
||||||
key = f"group_number {group_number}"
|
|
||||||
if bTooSoon(key, sSlot, 10): return
|
|
||||||
group = contacts_provider.get_group_by_number(group_number)
|
group = contacts_provider.get_group_by_number(group_number)
|
||||||
if group is None:
|
|
||||||
LOG_ERROR(f"group_self_join NULL group #{group}")
|
|
||||||
return
|
|
||||||
invoke_in_main_thread(group.set_status, TOX_USER_STATUS['NONE'])
|
invoke_in_main_thread(group.set_status, TOX_USER_STATUS['NONE'])
|
||||||
invoke_in_main_thread(groups_service.update_group_info, group)
|
invoke_in_main_thread(groups_service.update_group_info, group)
|
||||||
invoke_in_main_thread(contacts_manager.update_filtration)
|
invoke_in_main_thread(contacts_manager.update_filtration)
|
||||||
|
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
|
|
||||||
def group_peer_join(contacts_provider, groups_service):
|
def group_peer_join(contacts_provider, groups_service):
|
||||||
sSlot = "group_peer_join"
|
|
||||||
def wrapped(tox, group_number, peer_id, user_data):
|
def wrapped(tox, group_number, peer_id, user_data):
|
||||||
key = f"group_peer_join #{group_number} peer_id={peer_id}"
|
|
||||||
if bTooSoon(key, sSlot, 20): return
|
|
||||||
group = contacts_provider.get_group_by_number(group_number)
|
group = contacts_provider.get_group_by_number(group_number)
|
||||||
if group is None:
|
|
||||||
LOG_ERROR(f"group_peer_join NULL group #{group} group_number={group_number}")
|
|
||||||
return
|
|
||||||
if peer_id > group._peers_limit:
|
|
||||||
LOG_ERROR(key +f" {peer_id} > {group._peers_limit}")
|
|
||||||
return
|
|
||||||
LOG_DEBUG(f"group_peer_join group={group}")
|
|
||||||
group.add_peer(peer_id)
|
group.add_peer(peer_id)
|
||||||
invoke_in_main_thread(groups_service.generate_peers_list)
|
invoke_in_main_thread(groups_service.generate_peers_list)
|
||||||
invoke_in_main_thread(groups_service.update_group_info, group)
|
invoke_in_main_thread(groups_service.update_group_info, group)
|
||||||
@ -566,49 +438,29 @@ def group_peer_join(contacts_provider, groups_service):
|
|||||||
|
|
||||||
|
|
||||||
def group_peer_exit(contacts_provider, groups_service, contacts_manager):
|
def group_peer_exit(contacts_provider, groups_service, contacts_manager):
|
||||||
def wrapped(tox,
|
def wrapped(tox, group_number, peer_id, message, length, user_data):
|
||||||
group_number, peer_id,
|
|
||||||
exit_type, name, name_length,
|
|
||||||
message, length,
|
|
||||||
user_data):
|
|
||||||
group = contacts_provider.get_group_by_number(group_number)
|
group = contacts_provider.get_group_by_number(group_number)
|
||||||
if group:
|
group.remove_peer(peer_id)
|
||||||
LOG_DEBUG(f"group_peer_exit #{group_number} peer_id={peer_id} exit_type={exit_type}")
|
invoke_in_main_thread(groups_service.generate_peers_list)
|
||||||
group.remove_peer(peer_id)
|
|
||||||
invoke_in_main_thread(groups_service.generate_peers_list)
|
|
||||||
else:
|
|
||||||
LOG_WARN(f"group_peer_exit group not found #{group_number} peer_id={peer_id}")
|
|
||||||
|
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
|
|
||||||
def group_peer_name(contacts_provider, groups_service):
|
def group_peer_name(contacts_provider, groups_service):
|
||||||
def wrapped(tox, group_number, peer_id, name, length, user_data):
|
def wrapped(tox, group_number, peer_id, name, length, user_data):
|
||||||
LOG_DEBUG(f"group_peer_name #{group_number} peer_id={peer_id}")
|
|
||||||
group = contacts_provider.get_group_by_number(group_number)
|
group = contacts_provider.get_group_by_number(group_number)
|
||||||
peer = group.get_peer_by_id(peer_id)
|
peer = group.get_peer_by_id(peer_id)
|
||||||
if peer:
|
peer.name = str(name[:length], 'utf-8')
|
||||||
peer.name = str(name[:length], 'utf-8')
|
invoke_in_main_thread(groups_service.generate_peers_list)
|
||||||
invoke_in_main_thread(groups_service.generate_peers_list)
|
|
||||||
else:
|
|
||||||
# FixMe: known signal to revalidate roles...
|
|
||||||
#_peers = [(p._name, p._peer_id) for p in group.get_peers()]
|
|
||||||
LOG_TRACE(f"remove_peer group {group!r} has no peer_id={peer_id} in _peers!r")
|
|
||||||
return
|
|
||||||
|
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
|
|
||||||
def group_peer_status(contacts_provider, groups_service):
|
def group_peer_status(contacts_provider, groups_service):
|
||||||
def wrapped(tox, group_number, peer_id, peer_status, user_data):
|
def wrapped(tox, group_number, peer_id, peer_status, user_data):
|
||||||
LOG_DEBUG(f"group_peer_status #{group_number} peer_id={peer_id}")
|
|
||||||
group = contacts_provider.get_group_by_number(group_number)
|
group = contacts_provider.get_group_by_number(group_number)
|
||||||
peer = group.get_peer_by_id(peer_id)
|
peer = group.get_peer_by_id(peer_id)
|
||||||
if peer:
|
peer.status = peer_status
|
||||||
peer.status = peer_status
|
|
||||||
else:
|
|
||||||
# _peers = [(p._name, p._peer_id) for p in group.get_peers()]
|
|
||||||
LOG_TRACE(f"remove_peer group {group!r} has no peer_id={peer_id} in _peers!r")
|
|
||||||
# TODO: add info message
|
|
||||||
invoke_in_main_thread(groups_service.generate_peers_list)
|
invoke_in_main_thread(groups_service.generate_peers_list)
|
||||||
|
|
||||||
return wrapped
|
return wrapped
|
||||||
@ -616,62 +468,32 @@ def group_peer_status(contacts_provider, groups_service):
|
|||||||
|
|
||||||
def group_topic(contacts_provider):
|
def group_topic(contacts_provider):
|
||||||
def wrapped(tox, group_number, peer_id, topic, length, user_data):
|
def wrapped(tox, group_number, peer_id, topic, length, user_data):
|
||||||
LOG_DEBUG(f"group_topic #{group_number} peer_id={peer_id}")
|
|
||||||
group = contacts_provider.get_group_by_number(group_number)
|
group = contacts_provider.get_group_by_number(group_number)
|
||||||
if group:
|
topic = str(topic[:length], 'utf-8')
|
||||||
topic = str(topic[:length], 'utf-8')
|
invoke_in_main_thread(group.set_status_message, topic)
|
||||||
invoke_in_main_thread(group.set_status_message, topic)
|
|
||||||
else:
|
|
||||||
_peers = [(p._name, p._peer_id) for p in group.get_peers()]
|
|
||||||
LOG_WARN(f"group_topic {group!r} has no peer_id={peer_id} in {_peers!r}")
|
|
||||||
# TODO: add info message
|
|
||||||
|
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
|
|
||||||
def group_moderation(groups_service, contacts_provider, contacts_manager, messenger):
|
def group_moderation(groups_service, contacts_provider, contacts_manager, messenger):
|
||||||
|
|
||||||
def update_peer_role(group, mod_peer_id, peer_id, new_role):
|
def update_peer_role(group, mod_peer_id, peer_id, new_role):
|
||||||
peer = group.get_peer_by_id(peer_id)
|
peer = group.get_peer_by_id(peer_id)
|
||||||
if peer:
|
peer.role = new_role
|
||||||
peer.role = new_role
|
|
||||||
# TODO: add info message
|
|
||||||
else:
|
|
||||||
# FixMe: known signal to revalidate roles...
|
|
||||||
# _peers = [(p._name, p._peer_id) for p in group.get_peers()]
|
|
||||||
LOG_TRACE(f"update_peer_role group {group!r} has no peer_id={peer_id} in _peers!r")
|
|
||||||
# TODO: add info message
|
# TODO: add info message
|
||||||
|
|
||||||
def remove_peer(group, mod_peer_id, peer_id, is_ban):
|
def remove_peer(group, mod_peer_id, peer_id, is_ban):
|
||||||
peer = group.get_peer_by_id(peer_id)
|
contacts_manager.remove_group_peer_by_id(group, peer_id)
|
||||||
if peer:
|
group.remove_peer(peer_id)
|
||||||
contacts_manager.remove_group_peer_by_id(group, peer_id)
|
|
||||||
group.remove_peer(peer_id)
|
|
||||||
else:
|
|
||||||
# FixMe: known signal to revalidate roles...
|
|
||||||
#_peers = [(p._name, p._peer_id) for p in group.get_peers()]
|
|
||||||
LOG_TRACE(f"remove_peer group {group!r} has no peer_id={peer_id} in _peers!r")
|
|
||||||
# TODO: add info message
|
# TODO: add info message
|
||||||
|
|
||||||
# source_peer_number, target_peer_number,
|
|
||||||
def wrapped(tox, group_number, mod_peer_id, peer_id, event_type, user_data):
|
def wrapped(tox, group_number, mod_peer_id, peer_id, event_type, user_data):
|
||||||
if mod_peer_id == iMAX_INT32 or peer_id == iMAX_INT32:
|
|
||||||
# FixMe: known signal to revalidate roles...
|
|
||||||
return
|
|
||||||
LOG_DEBUG(f"group_moderation #{group_number} mod_id={mod_peer_id} peer_id={peer_id} event_type={event_type}")
|
|
||||||
group = contacts_provider.get_group_by_number(group_number)
|
group = contacts_provider.get_group_by_number(group_number)
|
||||||
mod_peer = group.get_peer_by_id(mod_peer_id)
|
|
||||||
if not mod_peer:
|
|
||||||
#_peers = [(p._name, p._peer_id) for p in group.get_peers()]
|
|
||||||
LOG_TRACE(f"remove_peer group {group!r} has no mod_peer_id={mod_peer_id} in _peers!r")
|
|
||||||
return
|
|
||||||
peer = group.get_peer_by_id(peer_id)
|
|
||||||
if not peer:
|
|
||||||
# FixMe: known signal to revalidate roles...
|
|
||||||
#_peers = [(p._name, p._peer_id) for p in group.get_peers()]
|
|
||||||
LOG_TRACE(f"remove_peer group {group!r} has no peer_id={peer_id} in _peers!r")
|
|
||||||
return
|
|
||||||
|
|
||||||
if event_type == TOX_GROUP_MOD_EVENT['KICK']:
|
if event_type == TOX_GROUP_MOD_EVENT['KICK']:
|
||||||
remove_peer(group, mod_peer_id, peer_id, False)
|
remove_peer(group, mod_peer_id, peer_id, False)
|
||||||
|
elif event_type == TOX_GROUP_MOD_EVENT['BAN']:
|
||||||
|
remove_peer(group, mod_peer_id, peer_id, True)
|
||||||
elif event_type == TOX_GROUP_MOD_EVENT['OBSERVER']:
|
elif event_type == TOX_GROUP_MOD_EVENT['OBSERVER']:
|
||||||
update_peer_role(group, mod_peer_id, peer_id, TOX_GROUP_ROLE['OBSERVER'])
|
update_peer_role(group, mod_peer_id, peer_id, TOX_GROUP_ROLE['OBSERVER'])
|
||||||
elif event_type == TOX_GROUP_MOD_EVENT['USER']:
|
elif event_type == TOX_GROUP_MOD_EVENT['USER']:
|
||||||
@ -687,7 +509,6 @@ def group_moderation(groups_service, contacts_provider, contacts_manager, messen
|
|||||||
def group_password(contacts_provider):
|
def group_password(contacts_provider):
|
||||||
|
|
||||||
def wrapped(tox_link, group_number, password, length, user_data):
|
def wrapped(tox_link, group_number, password, length, user_data):
|
||||||
LOG_DEBUG(f"group_password #{group_number}")
|
|
||||||
password = str(password[:length], 'utf-8')
|
password = str(password[:length], 'utf-8')
|
||||||
group = contacts_provider.get_group_by_number(group_number)
|
group = contacts_provider.get_group_by_number(group_number)
|
||||||
group.password = password
|
group.password = password
|
||||||
@ -698,7 +519,6 @@ def group_password(contacts_provider):
|
|||||||
def group_peer_limit(contacts_provider):
|
def group_peer_limit(contacts_provider):
|
||||||
|
|
||||||
def wrapped(tox_link, group_number, peer_limit, user_data):
|
def wrapped(tox_link, group_number, peer_limit, user_data):
|
||||||
LOG_DEBUG(f"group_peer_limit #{group_number}")
|
|
||||||
group = contacts_provider.get_group_by_number(group_number)
|
group = contacts_provider.get_group_by_number(group_number)
|
||||||
group.peer_limit = peer_limit
|
group.peer_limit = peer_limit
|
||||||
|
|
||||||
@ -708,7 +528,6 @@ def group_peer_limit(contacts_provider):
|
|||||||
def group_privacy_state(contacts_provider):
|
def group_privacy_state(contacts_provider):
|
||||||
|
|
||||||
def wrapped(tox_link, group_number, privacy_state, user_data):
|
def wrapped(tox_link, group_number, privacy_state, user_data):
|
||||||
LOG_DEBUG(f"group_privacy_state #{group_number}")
|
|
||||||
group = contacts_provider.get_group_by_number(group_number)
|
group = contacts_provider.get_group_by_number(group_number)
|
||||||
group.is_private = privacy_state == TOX_GROUP_PRIVACY_STATE['PRIVATE']
|
group.is_private = privacy_state == TOX_GROUP_PRIVACY_STATE['PRIVATE']
|
||||||
|
|
||||||
@ -721,7 +540,7 @@ def group_privacy_state(contacts_provider):
|
|||||||
|
|
||||||
def init_callbacks(tox, profile, settings, plugin_loader, contacts_manager,
|
def init_callbacks(tox, profile, settings, plugin_loader, contacts_manager,
|
||||||
calls_manager, file_transfer_handler, main_window, tray, messenger, groups_service,
|
calls_manager, file_transfer_handler, main_window, tray, messenger, groups_service,
|
||||||
contacts_provider, ms=None):
|
contacts_provider):
|
||||||
"""
|
"""
|
||||||
Initialization of all callbacks.
|
Initialization of all callbacks.
|
||||||
:param tox: Tox instance
|
:param tox: Tox instance
|
||||||
@ -738,7 +557,6 @@ def init_callbacks(tox, profile, settings, plugin_loader, contacts_manager,
|
|||||||
:param groups_service: GroupsService instance
|
:param groups_service: GroupsService instance
|
||||||
:param contacts_provider: ContactsProvider instance
|
:param contacts_provider: ContactsProvider instance
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# self callbacks
|
# self callbacks
|
||||||
tox.callback_self_connection_status(self_connection_status(tox, profile))
|
tox.callback_self_connection_status(self_connection_status(tox, profile))
|
||||||
|
|
||||||
|
@ -1,32 +1,10 @@
|
|||||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
from bootstrap.bootstrap import *
|
||||||
import sys
|
|
||||||
import threading
|
import threading
|
||||||
import queue
|
import queue
|
||||||
|
from utils import util
|
||||||
|
import time
|
||||||
from PyQt5 import QtCore
|
from PyQt5 import QtCore
|
||||||
|
|
||||||
from bootstrap.bootstrap import *
|
|
||||||
from bootstrap.bootstrap import download_nodes_list
|
|
||||||
from wrapper.toxcore_enums_and_consts import TOX_USER_STATUS, TOX_CONNECTION
|
|
||||||
import wrapper_tests.support_testing as ts
|
|
||||||
from utils import util
|
|
||||||
|
|
||||||
import time
|
|
||||||
sleep = time.sleep
|
|
||||||
|
|
||||||
# LOG=util.log
|
|
||||||
global LOG
|
|
||||||
import logging
|
|
||||||
LOG = logging.getLogger('app.'+'threads')
|
|
||||||
# log = lambda x: LOG.info(x)
|
|
||||||
|
|
||||||
def LOG_ERROR(l): print('EROR+ '+l)
|
|
||||||
def LOG_WARN(l): print('WARN+ '+l)
|
|
||||||
def LOG_INFO(l): print('INFO+ '+l)
|
|
||||||
def LOG_DEBUG(l): print('DBUG+ '+l)
|
|
||||||
def LOG_TRACE(l): pass # print('TRACE+ '+l)
|
|
||||||
|
|
||||||
iLAST_CONN = 0
|
|
||||||
iLAST_DELTA = 60
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
# Base threads
|
# Base threads
|
||||||
@ -34,45 +12,25 @@ iLAST_DELTA = 60
|
|||||||
|
|
||||||
class BaseThread(threading.Thread):
|
class BaseThread(threading.Thread):
|
||||||
|
|
||||||
def __init__(self, name=None, target=None):
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
self._stop_thread = False
|
self._stop_thread = False
|
||||||
if name:
|
|
||||||
super().__init__(name=name, target=target)
|
|
||||||
else:
|
|
||||||
super().__init__(target=target)
|
|
||||||
|
|
||||||
def stop_thread(self, timeout=-1):
|
def stop_thread(self):
|
||||||
self._stop_thread = True
|
self._stop_thread = True
|
||||||
if timeout < 0:
|
self.join()
|
||||||
timeout = ts.iTHREAD_TIMEOUT
|
|
||||||
i = 0
|
|
||||||
while i < ts.iTHREAD_JOINS:
|
|
||||||
self.join(timeout)
|
|
||||||
if not self.is_alive(): break
|
|
||||||
i = i + 1
|
|
||||||
else:
|
|
||||||
LOG_WARN(f"BaseThread {self.name} BLOCKED after {ts.iTHREAD_JOINS}")
|
|
||||||
|
|
||||||
class BaseQThread(QtCore.QThread):
|
class BaseQThread(QtCore.QThread):
|
||||||
|
|
||||||
def __init__(self, name=None):
|
def __init__(self):
|
||||||
# NO name=name
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._stop_thread = False
|
self._stop_thread = False
|
||||||
self.name = str(id(self))
|
|
||||||
|
|
||||||
def stop_thread(self, timeout=-1):
|
def stop_thread(self):
|
||||||
self._stop_thread = True
|
self._stop_thread = True
|
||||||
if timeout < 0:
|
self.wait()
|
||||||
timeout = ts.iTHREAD_TIMEOUT
|
|
||||||
i = 0
|
|
||||||
while i < ts.iTHREAD_JOINS:
|
|
||||||
self.wait(timeout)
|
|
||||||
if not self.isRunning(): break
|
|
||||||
i = i + 1
|
|
||||||
sleep(ts.iTHREAD_TIMEOUT)
|
|
||||||
else:
|
|
||||||
LOG_WARN(f"BaseQThread {self.name} BLOCKED")
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
# Toxcore threads
|
# Toxcore threads
|
||||||
@ -80,87 +38,68 @@ class BaseQThread(QtCore.QThread):
|
|||||||
|
|
||||||
class InitThread(BaseThread):
|
class InitThread(BaseThread):
|
||||||
|
|
||||||
def __init__(self, tox, plugin_loader, settings, app, is_first_start):
|
def __init__(self, tox, plugin_loader, settings, is_first_start):
|
||||||
super().__init__(name='InitThread')
|
super().__init__()
|
||||||
self._tox = tox
|
self._tox, self._plugin_loader, self._settings = tox, plugin_loader, settings
|
||||||
self._plugin_loader = plugin_loader
|
|
||||||
self._settings = settings
|
|
||||||
self._app = app
|
|
||||||
self._is_first_start = is_first_start
|
self._is_first_start = is_first_start
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
# DBUG+ InitThread run: ERROR name 'ts' is not defined
|
if self._is_first_start:
|
||||||
import wrapper_tests.support_testing as ts
|
# download list of nodes if needed
|
||||||
LOG_DEBUG('InitThread run: ')
|
download_nodes_list(self._settings)
|
||||||
|
# start plugins
|
||||||
|
self._plugin_loader.load()
|
||||||
|
|
||||||
|
# bootstrap
|
||||||
try:
|
try:
|
||||||
if self._is_first_start and ts.bAreWeConnected() and \
|
for data in generate_nodes():
|
||||||
self._settings['download_nodes_list']:
|
if self._stop_thread:
|
||||||
LOG_INFO(f"downloading list of nodes {self._settings['download_nodes_list']}")
|
return
|
||||||
download_nodes_list(self._settings, oArgs=self._app._args)
|
self._tox.bootstrap(*data)
|
||||||
|
self._tox.add_tcp_relay(*data)
|
||||||
if ts.bAreWeConnected():
|
except:
|
||||||
LOG_INFO(f"calling test_net nodes")
|
|
||||||
self._app.test_net(oThread=self, iMax=4)
|
|
||||||
|
|
||||||
if self._is_first_start:
|
|
||||||
LOG_INFO('starting plugins')
|
|
||||||
self._plugin_loader.load()
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
LOG_DEBUG(f"InitThread run: ERROR {e}")
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
for _ in range(ts.iTHREAD_JOINS):
|
for _ in range(10):
|
||||||
if self._stop_thread:
|
if self._stop_thread:
|
||||||
return
|
return
|
||||||
sleep(ts.iTHREAD_SLEEP)
|
time.sleep(1)
|
||||||
return
|
|
||||||
|
while not self._tox.self_get_connection_status():
|
||||||
|
try:
|
||||||
|
for data in generate_nodes(None):
|
||||||
|
if self._stop_thread:
|
||||||
|
return
|
||||||
|
self._tox.bootstrap(*data)
|
||||||
|
self._tox.add_tcp_relay(*data)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
|
|
||||||
class ToxIterateThread(BaseQThread):
|
class ToxIterateThread(BaseQThread):
|
||||||
|
|
||||||
def __init__(self, tox, app=None):
|
def __init__(self, tox):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._tox = tox
|
self._tox = tox
|
||||||
self._app = app
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
LOG_DEBUG('ToxIterateThread run: ')
|
|
||||||
while not self._stop_thread:
|
while not self._stop_thread:
|
||||||
try:
|
self._tox.iterate()
|
||||||
iMsec = self._tox.iteration_interval()
|
time.sleep(self._tox.iteration_interval() / 1000)
|
||||||
self._tox.iterate()
|
|
||||||
except Exception as e:
|
|
||||||
# Fatal Python error: Segmentation fault
|
|
||||||
LOG_ERROR(f"ToxIterateThread run: {e}")
|
|
||||||
else:
|
|
||||||
sleep(iMsec / 1000.0)
|
|
||||||
|
|
||||||
global iLAST_CONN
|
|
||||||
if not iLAST_CONN:
|
|
||||||
iLAST_CONN = time.time()
|
|
||||||
# TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
|
|
||||||
|
|
||||||
# and segv
|
|
||||||
if time.time() - iLAST_CONN > iLAST_DELTA and \
|
|
||||||
ts.bAreWeConnected() and \
|
|
||||||
self._tox.self_get_status() == TOX_USER_STATUS['NONE'] and \
|
|
||||||
self._tox.self_get_connection_status() == TOX_CONNECTION['NONE']:
|
|
||||||
iLAST_CONN = time.time()
|
|
||||||
LOG_INFO(f"ToxIterateThread calling test_net")
|
|
||||||
invoke_in_main_thread(
|
|
||||||
self._app.test_net, oThread=self, iMax=2)
|
|
||||||
|
|
||||||
|
|
||||||
class ToxAVIterateThread(BaseQThread):
|
class ToxAVIterateThread(BaseQThread):
|
||||||
|
|
||||||
def __init__(self, toxav):
|
def __init__(self, toxav):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._toxav = toxav
|
self._toxav = toxav
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
LOG_DEBUG('ToxAVIterateThread run: ')
|
|
||||||
while not self._stop_thread:
|
while not self._stop_thread:
|
||||||
self._toxav.iterate()
|
self._toxav.iterate()
|
||||||
sleep(self._toxav.iteration_interval() / 1000)
|
time.sleep(self._toxav.iteration_interval() / 1000)
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
@ -170,7 +109,7 @@ class ToxAVIterateThread(BaseQThread):
|
|||||||
class FileTransfersThread(BaseQThread):
|
class FileTransfersThread(BaseQThread):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__('FileTransfers')
|
super().__init__()
|
||||||
self._queue = queue.Queue()
|
self._queue = queue.Queue()
|
||||||
self._timeout = 0.01
|
self._timeout = 0.01
|
||||||
|
|
||||||
@ -185,12 +124,14 @@ class FileTransfersThread(BaseQThread):
|
|||||||
except queue.Empty:
|
except queue.Empty:
|
||||||
pass
|
pass
|
||||||
except queue.Full:
|
except queue.Full:
|
||||||
LOG_WARN('Queue is full in _thread')
|
util.log('Queue is full in _thread')
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
LOG_ERROR('in _thread: ' + str(ex))
|
util.log('Exception in _thread: ' + str(ex))
|
||||||
|
|
||||||
|
|
||||||
_thread = FileTransfersThread()
|
_thread = FileTransfersThread()
|
||||||
|
|
||||||
|
|
||||||
def start_file_transfer_thread():
|
def start_file_transfer_thread():
|
||||||
_thread.start()
|
_thread.start()
|
||||||
|
|
||||||
|
@ -1,125 +1,34 @@
|
|||||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
|
||||||
import user_data.settings
|
import user_data.settings
|
||||||
import wrapper.tox
|
import wrapper.tox
|
||||||
import wrapper.toxcore_enums_and_consts as enums
|
import wrapper.toxcore_enums_and_consts as enums
|
||||||
import ctypes
|
import ctypes
|
||||||
import traceback
|
|
||||||
import os
|
|
||||||
|
|
||||||
global LOG
|
|
||||||
import logging
|
|
||||||
LOG = logging.getLogger('app.'+'tox_factory')
|
|
||||||
|
|
||||||
from ctypes import *
|
def tox_factory(data=None, settings=None):
|
||||||
from utils import util
|
|
||||||
from utils import ui as util_ui
|
|
||||||
|
|
||||||
# callbacks can be called in any thread so were being careful
|
|
||||||
# tox.py can be called by callbacks
|
|
||||||
def LOG_ERROR(a): print('EROR> '+a)
|
|
||||||
def LOG_WARN(a): print('WARN> '+a)
|
|
||||||
def LOG_INFO(a):
|
|
||||||
bVERBOSE = hasattr(__builtins__, 'app') and app.oArgs.loglevel <= 20
|
|
||||||
if bVERBOSE: print('INFO> '+a)
|
|
||||||
def LOG_DEBUG(a):
|
|
||||||
bVERBOSE = hasattr(__builtins__, 'app') and app.oArgs.loglevel <= 10
|
|
||||||
if bVERBOSE: print('DBUG> '+a)
|
|
||||||
def LOG_TRACE(a):
|
|
||||||
bVERBOSE = hasattr(__builtins__, 'app') and app.oArgs.loglevel < 10
|
|
||||||
if bVERBOSE: print('TRAC> '+a)
|
|
||||||
def LOG_LOG(a): print('TRAC> '+a)
|
|
||||||
|
|
||||||
def tox_log_cb(iTox, level, file, line, func, message, *args):
|
|
||||||
"""
|
|
||||||
* @param level The severity of the log message.
|
|
||||||
* @param file The source file from which the message originated.
|
|
||||||
* @param line The source line from which the message originated.
|
|
||||||
* @param func The function from which the message originated.
|
|
||||||
* @param message The log message.
|
|
||||||
* @param user_data The user data pointer passed to tox_new in options.
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
file = str(file, 'UTF-8')
|
|
||||||
# root WARNING 3network.c#944:b'send_packet'attempted to send message with network family 10 (probably IPv6) on IPv4 socket
|
|
||||||
if file == 'network.c' and line in [944, 660]: return
|
|
||||||
func = str(func, 'UTF-8')
|
|
||||||
message = str(message, 'UTF-8')
|
|
||||||
message = f"{file}#{line}:{func} {message}"
|
|
||||||
LOG_LOG(message)
|
|
||||||
except Exception as e:
|
|
||||||
LOG_ERROR(f"tox_log_cb {e}")
|
|
||||||
|
|
||||||
#tox_log_handler (context=0x24763d0,
|
|
||||||
# level=LOGGER_LEVEL_TRACE, file=0x7fffe599fb99 "TCP_common.c", line=203,
|
|
||||||
# func=0x7fffe599fc50 <__func__.2> "read_TCP_packet",
|
|
||||||
# message=0x7fffba7fabd0 "recv buffer has 0 bytes, but requested 10 bytes",
|
|
||||||
# userdata=0x0) at /var/local/src/c-toxcore/toxcore/tox.c:78
|
|
||||||
|
|
||||||
def tox_factory(data=None, settings=None, args=None, app=None):
|
|
||||||
"""
|
"""
|
||||||
:param data: user data from .tox file. None = no saved data, create new profile
|
:param data: user data from .tox file. None = no saved data, create new profile
|
||||||
:param settings: current profile settings. None = default settings will be used
|
:param settings: current profile settings. None = default settings will be used
|
||||||
:return: new tox instance
|
:return: new tox instance
|
||||||
"""
|
"""
|
||||||
if not settings:
|
if settings is None:
|
||||||
LOG_WARN("tox_factory using get_default_settings")
|
|
||||||
settings = user_data.settings.Settings.get_default_settings()
|
settings = user_data.settings.Settings.get_default_settings()
|
||||||
else:
|
|
||||||
user_data.settings.clean_settings(settings)
|
|
||||||
|
|
||||||
try:
|
tox_options = wrapper.tox.Tox.options_new()
|
||||||
tox_options = wrapper.tox.Tox.options_new()
|
tox_options.contents.udp_enabled = settings['udp_enabled']
|
||||||
tox_options.contents.ipv6_enabled = settings['ipv6_enabled']
|
tox_options.contents.proxy_type = settings['proxy_type']
|
||||||
tox_options.contents.udp_enabled = settings['udp_enabled']
|
tox_options.contents.proxy_host = bytes(settings['proxy_host'], 'UTF-8')
|
||||||
tox_options.contents.proxy_type = int(settings['proxy_type'])
|
tox_options.contents.proxy_port = settings['proxy_port']
|
||||||
if type(settings['proxy_host']) == str:
|
tox_options.contents.start_port = settings['start_port']
|
||||||
tox_options.contents.proxy_host = bytes(settings['proxy_host'],'UTF-8')
|
tox_options.contents.end_port = settings['end_port']
|
||||||
elif type(settings['proxy_host']) == bytes:
|
tox_options.contents.tcp_port = settings['tcp_port']
|
||||||
tox_options.contents.proxy_host = settings['proxy_host']
|
tox_options.contents.local_discovery_enabled = settings['lan_discovery']
|
||||||
else:
|
if data: # load existing profile
|
||||||
tox_options.contents.proxy_host = b''
|
tox_options.contents.savedata_type = enums.TOX_SAVEDATA_TYPE['TOX_SAVE']
|
||||||
tox_options.contents.proxy_port = int(settings['proxy_port'])
|
tox_options.contents.savedata_data = ctypes.c_char_p(data)
|
||||||
tox_options.contents.start_port = settings['start_port']
|
tox_options.contents.savedata_length = len(data)
|
||||||
tox_options.contents.end_port = settings['end_port']
|
else: # create new profile
|
||||||
tox_options.contents.tcp_port = settings['tcp_port']
|
tox_options.contents.savedata_type = enums.TOX_SAVEDATA_TYPE['NONE']
|
||||||
tox_options.contents.local_discovery_enabled = settings['local_discovery_enabled']
|
tox_options.contents.savedata_data = None
|
||||||
tox_options.contents.dht_announcements_enabled = settings['dht_announcements_enabled']
|
tox_options.contents.savedata_length = 0
|
||||||
tox_options.contents.hole_punching_enabled = settings['hole_punching_enabled']
|
|
||||||
if data: # load existing profile
|
|
||||||
tox_options.contents.savedata_type = enums.TOX_SAVEDATA_TYPE['TOX_SAVE']
|
|
||||||
tox_options.contents.savedata_data = ctypes.c_char_p(data)
|
|
||||||
tox_options.contents.savedata_length = len(data)
|
|
||||||
else: # create new profile
|
|
||||||
tox_options.contents.savedata_type = enums.TOX_SAVEDATA_TYPE['NONE']
|
|
||||||
tox_options.contents.savedata_data = None
|
|
||||||
tox_options.contents.savedata_length = 0
|
|
||||||
|
|
||||||
# overrides
|
return wrapper.tox.Tox(tox_options)
|
||||||
tox_options.contents.local_discovery_enabled = False
|
|
||||||
tox_options.contents.ipv6_enabled = False
|
|
||||||
tox_options.contents.hole_punching_enabled = False
|
|
||||||
|
|
||||||
LOG.debug("wrapper.tox.Tox settings: " +repr(settings))
|
|
||||||
|
|
||||||
if 'trace_enabled' in settings and settings['trace_enabled']:
|
|
||||||
LOG_INFO("settings['trace_enabled' disabled" )
|
|
||||||
elif tox_options._options_pointer:
|
|
||||||
c_callback = CFUNCTYPE(None, c_void_p, c_int, c_char_p, c_int, c_char_p, c_char_p, c_void_p)
|
|
||||||
tox_options.self_logger_cb = c_callback(tox_log_cb)
|
|
||||||
wrapper.tox.Tox.libtoxcore.tox_options_set_log_callback(
|
|
||||||
tox_options._options_pointer,
|
|
||||||
tox_options.self_logger_cb)
|
|
||||||
else:
|
|
||||||
LOG_WARN("No tox_options._options_pointer to add self_logger_cb" )
|
|
||||||
|
|
||||||
retval = wrapper.tox.Tox(tox_options)
|
|
||||||
except Exception as e:
|
|
||||||
if app and hasattr(app, '_log'):
|
|
||||||
pass
|
|
||||||
LOG_ERROR(f"wrapper.tox.Tox failed: {e}")
|
|
||||||
LOG_WARN(traceback.format_exc())
|
|
||||||
raise
|
|
||||||
|
|
||||||
if app and hasattr(app, '_log'):
|
|
||||||
app._log("DEBUG: wrapper.tox.Tox succeeded")
|
|
||||||
return retval
|
|
||||||
|
@ -1,40 +1,20 @@
|
|||||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
|
||||||
import json
|
import json
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import utils.util as util
|
import utils.util as util
|
||||||
from PyQt5 import QtNetwork, QtCore
|
from PyQt5 import QtNetwork, QtCore
|
||||||
try:
|
|
||||||
import requests
|
|
||||||
except ImportError:
|
|
||||||
requests = None
|
|
||||||
|
|
||||||
global LOG
|
|
||||||
import logging
|
|
||||||
LOG = logging.getLogger('app.'+__name__)
|
|
||||||
|
|
||||||
class ToxDns:
|
class ToxDns:
|
||||||
|
|
||||||
def __init__(self, settings, log=None):
|
def __init__(self, settings):
|
||||||
self._settings = settings
|
self._settings = settings
|
||||||
self._log = log
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _send_request(url, data):
|
def _send_request(url, data):
|
||||||
if requests:
|
req = urllib.request.Request(url)
|
||||||
LOG.info('send_request loading with requests: ' + str(url))
|
req.add_header('Content-Type', 'application/json')
|
||||||
headers = dict()
|
response = urllib.request.urlopen(req, bytes(json.dumps(data), 'utf-8'))
|
||||||
headers['Content-Type'] = 'application/json'
|
res = json.loads(str(response.read(), 'utf-8'))
|
||||||
req = requests.get(url, headers=headers)
|
|
||||||
if req.status_code < 300:
|
|
||||||
retval = req.content
|
|
||||||
else:
|
|
||||||
raise LookupError(str(req.status_code))
|
|
||||||
else:
|
|
||||||
req = urllib.request.Request(url)
|
|
||||||
req.add_header('Content-Type', 'application/json')
|
|
||||||
response = urllib.request.urlopen(req, bytes(json.dumps(data), 'utf-8'))
|
|
||||||
retval = response.read()
|
|
||||||
res = json.loads(str(retval, 'utf-8'))
|
|
||||||
if not res['c']:
|
if not res['c']:
|
||||||
return res['tox_id']
|
return res['tox_id']
|
||||||
else:
|
else:
|
||||||
@ -49,25 +29,12 @@ class ToxDns:
|
|||||||
site = email.split('@')[1]
|
site = email.split('@')[1]
|
||||||
data = {"action": 3, "name": "{}".format(email)}
|
data = {"action": 3, "name": "{}".format(email)}
|
||||||
urls = ('https://{}/api'.format(site), 'http://{}/api'.format(site))
|
urls = ('https://{}/api'.format(site), 'http://{}/api'.format(site))
|
||||||
if requests:
|
if not self._settings['proxy_type']: # no proxy
|
||||||
for url in urls:
|
|
||||||
LOG.info('TOX nodes loading with requests: ' + str(url))
|
|
||||||
try:
|
|
||||||
headers = dict()
|
|
||||||
headers['Content-Type'] = 'application/json'
|
|
||||||
req = requests.get(url, headers=headers)
|
|
||||||
if req.status_code < 300:
|
|
||||||
result = req.content
|
|
||||||
return result
|
|
||||||
except Exception as ex:
|
|
||||||
LOG.error('ERROR: TOX DNS loading error with requests: ' + str(ex))
|
|
||||||
|
|
||||||
elif not self._settings['proxy_type']: # no proxy
|
|
||||||
for url in urls:
|
for url in urls:
|
||||||
try:
|
try:
|
||||||
return self._send_request(url, data)
|
return self._send_request(url, data)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
LOG.error('ERROR: TOX DNS ' + str(ex))
|
util.log('TOX DNS ERROR: ' + str(ex))
|
||||||
else: # proxy
|
else: # proxy
|
||||||
netman = QtNetwork.QNetworkAccessManager()
|
netman = QtNetwork.QNetworkAccessManager()
|
||||||
proxy = QtNetwork.QNetworkProxy()
|
proxy = QtNetwork.QNetworkProxy()
|
||||||
@ -93,6 +60,6 @@ class ToxDns:
|
|||||||
if not result['c']:
|
if not result['c']:
|
||||||
return result['tox_id']
|
return result['tox_id']
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
LOG.error('ERROR: TOX DNS ' + str(ex))
|
util.log('TOX DNS ERROR: ' + str(ex))
|
||||||
|
|
||||||
return None # error
|
return None # error
|
||||||
|
@ -3,9 +3,6 @@ import wave
|
|||||||
import pyaudio
|
import pyaudio
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
global LOG
|
|
||||||
import logging
|
|
||||||
LOG = logging.getLogger('app.'+__name__)
|
|
||||||
|
|
||||||
SOUND_NOTIFICATION = {
|
SOUND_NOTIFICATION = {
|
||||||
'MESSAGE': 0,
|
'MESSAGE': 0,
|
||||||
@ -28,19 +25,9 @@ class AudioFile:
|
|||||||
|
|
||||||
def play(self):
|
def play(self):
|
||||||
data = self.wf.readframes(self.chunk)
|
data = self.wf.readframes(self.chunk)
|
||||||
try:
|
while data:
|
||||||
while data:
|
self.stream.write(data)
|
||||||
self.stream.write(data)
|
data = self.wf.readframes(self.chunk)
|
||||||
data = self.wf.readframes(self.chunk)
|
|
||||||
except Exception as e:
|
|
||||||
LOG.error(f"Error during AudioFile play {e!s}")
|
|
||||||
LOG.debug("Error during AudioFile play " \
|
|
||||||
+' rate=' +str(self.wf.getframerate()) \
|
|
||||||
+ 'format=' +str(self.p.get_format_from_width(self.wf.getsampwidth())) \
|
|
||||||
+' channels=' +str(self.wf.getnchannels()) \
|
|
||||||
)
|
|
||||||
|
|
||||||
raise
|
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.stream.close()
|
self.stream.close()
|
||||||
|
@ -10,7 +10,7 @@ def tray_notification(title, text, tray, window):
|
|||||||
:param tray: ref to tray icon
|
:param tray: ref to tray icon
|
||||||
:param window: main window
|
:param window: main window
|
||||||
"""
|
"""
|
||||||
if tray and QtWidgets.QSystemTrayIcon.isSystemTrayAvailable():
|
if QtWidgets.QSystemTrayIcon.isSystemTrayAvailable():
|
||||||
if len(text) > 30:
|
if len(text) > 30:
|
||||||
text = text[:27] + '...'
|
text = text[:27] + '...'
|
||||||
tray.showMessage(title, text, QtWidgets.QSystemTrayIcon.NoIcon, 3000)
|
tray.showMessage(title, text, QtWidgets.QSystemTrayIcon.NoIcon, 3000)
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
|
||||||
import utils.util as util
|
import utils.util as util
|
||||||
import os
|
import os
|
||||||
import importlib
|
import importlib
|
||||||
@ -6,14 +5,6 @@ import inspect
|
|||||||
import plugins.plugin_super_class as pl
|
import plugins.plugin_super_class as pl
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# LOG=util.log
|
|
||||||
global LOG
|
|
||||||
import logging
|
|
||||||
LOG = logging.getLogger('plugin_support')
|
|
||||||
def trace(msg, *args, **kwargs): LOG._log(0, msg, [])
|
|
||||||
LOG.trace = trace
|
|
||||||
|
|
||||||
log = lambda x: LOG.info(x)
|
|
||||||
|
|
||||||
class Plugin:
|
class Plugin:
|
||||||
|
|
||||||
@ -55,49 +46,38 @@ class PluginLoader:
|
|||||||
"""
|
"""
|
||||||
path = util.get_plugins_directory()
|
path = util.get_plugins_directory()
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
self._app._LOG('WARN: Plugin directory not found: ' + path)
|
util.log('Plugin dir not found')
|
||||||
return
|
return
|
||||||
|
else:
|
||||||
sys.path.append(path)
|
sys.path.append(path)
|
||||||
files = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f))]
|
files = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f))]
|
||||||
for fl in files:
|
for fl in files:
|
||||||
if fl in ('plugin_super_class.py', '__init__.py') or not fl.endswith('.py'):
|
if fl in ('plugin_super_class.py', '__init__.py') or not fl.endswith('.py'):
|
||||||
continue
|
continue
|
||||||
base_name = fl[:-3] # module name without .py
|
name = fl[:-3] # module name without .py
|
||||||
try:
|
try:
|
||||||
module = importlib.import_module(base_name) # import plugin
|
module = importlib.import_module(name) # import plugin
|
||||||
LOG.trace('Imported module: ' +base_name +' file: ' +fl)
|
except ImportError:
|
||||||
except ImportError as e:
|
util.log('Import error in module ' + name)
|
||||||
LOG.warn(f"Import error: {e}" +' file: ' +fl)
|
|
||||||
continue
|
continue
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
LOG.error('importing ' + base_name + ' Exception: ' + str(ex))
|
util.log('Exception in module ' + name + ' Exception: ' + str(ex))
|
||||||
continue
|
continue
|
||||||
for elem in dir(module):
|
for elem in dir(module):
|
||||||
obj = getattr(module, elem)
|
obj = getattr(module, elem)
|
||||||
# looking for plugin class in module
|
# looking for plugin class in module
|
||||||
if not inspect.isclass(obj) or not hasattr(obj, 'is_plugin') or not obj.is_plugin:
|
if not inspect.isclass(obj) or not hasattr(obj, 'is_plugin') or not obj.is_plugin:
|
||||||
continue
|
continue
|
||||||
|
print('Plugin', elem)
|
||||||
try: # create instance of plugin class
|
try: # create instance of plugin class
|
||||||
instance = obj(self._app) # name, short_name, app
|
instance = obj(self._app)
|
||||||
# needed by bday...
|
is_active = instance.get_short_name() in self._settings['plugins']
|
||||||
instance._profile=self._app._ms._profile
|
|
||||||
instance._settings=self._settings
|
|
||||||
short_name = instance.get_short_name()
|
|
||||||
is_active = short_name in self._settings['plugins']
|
|
||||||
if is_active:
|
if is_active:
|
||||||
try:
|
instance.start()
|
||||||
instance.start()
|
|
||||||
self._app.LOG('INFO: Started Plugin ' +short_name)
|
|
||||||
except Exception as e:
|
|
||||||
self._app.LOG.error(f"Starting Plugin ' +short_name +' {e}")
|
|
||||||
# else: LOG.info('Defined Plugin ' +short_name)
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
LOG.error('in module ' + short_name + ' Exception: ' + str(ex))
|
util.log('Exception in module ' + name + ' Exception: ' + str(ex))
|
||||||
continue
|
continue
|
||||||
short_name = instance.get_short_name()
|
self._plugins[instance.get_short_name()] = Plugin(instance, is_active)
|
||||||
self._plugins[short_name] = Plugin(instance, is_active)
|
|
||||||
LOG.info('Added plugin: ' +short_name +' from file: ' +fl)
|
|
||||||
break
|
break
|
||||||
|
|
||||||
def callback_lossless(self, friend_number, data):
|
def callback_lossless(self, friend_number, data):
|
||||||
@ -134,7 +114,7 @@ class PluginLoader:
|
|||||||
for plugin in self._plugins.values():
|
for plugin in self._plugins.values():
|
||||||
try:
|
try:
|
||||||
result.append([plugin.instance.get_name(), # plugin full name
|
result.append([plugin.instance.get_name(), # plugin full name
|
||||||
plugin.is_active, # is enabled
|
plugin.is_active, # is enabled
|
||||||
plugin.instance.get_description(), # plugin description
|
plugin.instance.get_description(), # plugin description
|
||||||
plugin.instance.get_short_name()]) # key - short unique name
|
plugin.instance.get_short_name()]) # key - short unique name
|
||||||
except:
|
except:
|
||||||
@ -146,13 +126,7 @@ class PluginLoader:
|
|||||||
"""
|
"""
|
||||||
Return window or None for specified plugin
|
Return window or None for specified plugin
|
||||||
"""
|
"""
|
||||||
try:
|
return self._plugins[key].instance.get_window()
|
||||||
if key in self._plugins and hasattr(self._plugins[key], 'instance'):
|
|
||||||
return self._plugins[key].instance.get_window()
|
|
||||||
except Exception as e:
|
|
||||||
self._app.LOG('WARN: ' +key +' _plugins no slot instance: ' +str(e))
|
|
||||||
|
|
||||||
return None
|
|
||||||
|
|
||||||
def toggle_plugin(self, key):
|
def toggle_plugin(self, key):
|
||||||
"""
|
"""
|
||||||
@ -188,7 +162,6 @@ class PluginLoader:
|
|||||||
for plugin in self._plugins.values():
|
for plugin in self._plugins.values():
|
||||||
if not plugin.is_active:
|
if not plugin.is_active:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result.extend(plugin.instance.get_menu(num))
|
result.extend(plugin.instance.get_menu(num))
|
||||||
except:
|
except:
|
||||||
@ -200,10 +173,6 @@ class PluginLoader:
|
|||||||
for plugin in self._plugins.values():
|
for plugin in self._plugins.values():
|
||||||
if not plugin.is_active:
|
if not plugin.is_active:
|
||||||
continue
|
continue
|
||||||
if not hasattr(plugin.instance, 'get_message_menu'):
|
|
||||||
name = plugin.instance.get_short_name()
|
|
||||||
self._app.LOG('WARN: get_message_menu not found: ' + name)
|
|
||||||
continue
|
|
||||||
try:
|
try:
|
||||||
result.extend(plugin.instance.get_message_menu(menu, selected_text))
|
result.extend(plugin.instance.get_message_menu(menu, selected_text))
|
||||||
except:
|
except:
|
||||||
@ -220,11 +189,6 @@ class PluginLoader:
|
|||||||
del self._plugins[key]
|
del self._plugins[key]
|
||||||
|
|
||||||
def reload(self):
|
def reload(self):
|
||||||
path = util.get_plugins_directory()
|
print('Reloading plugins')
|
||||||
if not os.path.exists(path):
|
|
||||||
self._app.LOG('WARN: Plugin directory not found: ' + path)
|
|
||||||
return
|
|
||||||
|
|
||||||
self.stop()
|
self.stop()
|
||||||
self._app.LOG('INFO: Reloading plugins from ' +path)
|
|
||||||
self.load()
|
self.load()
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from PyQt5 import QtCore, QtWidgets
|
from PyQt5 import QtCore, QtWidgets
|
||||||
|
|
||||||
import common.tox_save as tox_save
|
|
||||||
import utils.ui as util_ui
|
import utils.ui as util_ui
|
||||||
|
import common.tox_save as tox_save
|
||||||
|
|
||||||
|
|
||||||
MAX_SHORT_NAME_LENGTH = 5
|
MAX_SHORT_NAME_LENGTH = 5
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |