Compare commits

..

79 commits

Author SHA1 Message Date
emdee@spm.plastiras.org
8c9d53903f updates 2024-03-08 04:01:31 +00:00
emdee@spm.plastiras.org
ef68b7e2e2 fixes 2024-02-26 08:04:47 +00:00
emdee@spm.plastiras.org
affaa3814b update 2024-02-18 18:25:29 +00:00
emdee@spm.plastiras.org
9c1014ee5e update 2024-02-17 20:02:30 +00:00
emdee@spm.plastiras.org
ec79c0d6ae update 2024-02-14 03:02:09 +00:00
emdee@spm.plastiras.org
2717f4f6e5 updates 2024-02-13 21:00:45 +00:00
emdee@spm.plastiras.org
f7e260a355 AudioQThread 2024-02-12 13:14:59 +00:00
emdee@spm.plastiras.org
d9ef18631d QThread 2024-02-12 09:21:55 +00:00
emdee@spm.plastiras.org
76ad2ccd44 sound fixes 2024-02-11 08:10:36 +00:00
emdee@spm.plastiras.org
dda2a9147a sound fixes 2024-02-10 23:54:53 +00:00
emdee@spm.plastiras.org
d936663591 sound fixes 2024-02-10 23:53:28 +00:00
emdee@spm.plastiras.org
ac6999924f sound fixes 2024-02-10 23:52:50 +00:00
emdee@spm.plastiras.org
31bed51455 qt6 fixes 2024-02-10 20:33:12 +00:00
emdee@spm.plastiras.org
dd8ed70958 qt6 fixed 2024-02-10 20:32:31 +00:00
emdee@spm.plastiras.org
d1c8d445bc qt6 fixes 2024-02-09 09:38:24 +00:00
emdee@spm.plastiras.org
4d2d4034f9 final qtpy 2024-02-08 08:37:57 +00:00
emdee@spm.plastiras.org
c70c501fdd fixed json overwrite 2024-02-08 07:39:15 +00:00
emdee@spm.plastiras.org
e778108834 fixed pyqtSignal 2024-02-07 15:34:15 +00:00
emdee@spm.plastiras.org
1c56b5b25a update 2024-02-06 19:53:28 +00:00
emdee@spm.plastiras.org
ea454e27a1 update 2024-02-06 18:07:32 +00:00
emdee@spm.plastiras.org
f62e28f5b4 qtpy 2024-02-05 17:15:29 +00:00
emdee@spm.plastiras.org
7cebe9cd9f update 2024-02-05 14:58:00 +00:00
emdee@spm.plastiras.org
3ce822fc27 update 2024-02-03 04:34:10 +00:00
emdee@spm.plastiras.org
e4b1b9c4d8 updates 2023-12-18 06:25:24 +00:00
emdee@macaw.me
68f28fdac5 fixes 2023-12-17 00:00:38 +00:00
emdee
99136cd4e3 grouppeer status fixes 2023-12-11 16:00:54 +00:00
emdee
65d593cd20 status-message 2023-12-11 15:39:28 +00:00
emdee
9f32dc3f8a EOL 2023-12-11 02:18:11 +00:00
emdee
48efb5a44e bugfix 2023-12-10 18:20:04 +00:00
emdee
ba013b6a81 bugfixes 2023-12-10 04:43:53 +00:00
emdee
4109c822b3 rm toxygen/wrapper*/* 2023-12-10 02:42:43 +00:00
emdee
4e77ddc2de simple updates 2023-12-10 02:39:58 +00:00
emdee
dcde8e3d1e Misc fixes 2023-07-14 14:46:18 +00:00
emdee
948335c8a0 fixed qweechat 2022-11-23 19:23:21 +00:00
emdee
0b1eaa1391 Added toxygen/third_party/qweechat 2022-11-20 18:44:17 +00:00
emdee
424e15b31c add third_party 2022-11-20 18:16:31 +00:00
emdee
db37d29dc8 add third_party 2022-11-20 18:15:46 +00:00
emdee
f1d8ce105c Added qweechat 2022-11-20 01:11:51 +00:00
emdee
1e5618060a isort 2022-11-17 15:26:55 +00:00
emdee
1b8b26eafc Fixes 2022-11-05 01:16:25 +00:00
emdee
a073dd9bc9 Oops 2022-10-27 07:18:09 +00:00
emdee
5df00c3ccd Fixed 2022-10-27 07:07:28 +00:00
emdee
0819fd4088 Fixes 2022-10-26 09:01:50 +00:00
emdee
5f1b7d8d93 Update README 2022-10-18 01:15:22 +00:00
emdee
cf5c5b1608 Fixes 2022-10-18 00:23:39 +00:00
emdee
90e379a6de bugfixes 2022-10-13 13:55:56 +00:00
emdee
a92bbbbcbf Bugfixes 2022-10-12 19:51:08 +00:00
emdee
d2fe721072 Bugfixes 2022-10-12 09:17:53 +00:00
emdee
fd7f2620ba Fixed history database 2022-10-11 16:36:09 +00:00
emdee
b75aafe638 Added type field in user list entries 2022-10-11 09:32:39 +00:00
emdee
f7c0e7ce23 Fix profile settings 2022-10-10 14:04:09 +00:00
emdee
633b8f9561 trying to fix group addition 2022-10-08 17:59:45 +00:00
emdee
fb520357e9 group fixes 2022-10-08 03:22:09 +00:00
emdee
be6eb0e2a9 fixes 2022-10-08 02:46:23 +00:00
emdee
9e037f13c0 bugfix and bulletproof nodes 2022-10-07 04:45:05 +00:00
emdee
ca9c6fc091 small fixes 2022-10-03 07:18:24 +00:00
emdee
2916d0cb04 add ToDo.md 2022-10-01 19:46:18 +00:00
emdee
695d8e2cf9 Broke out wrapper_tests to toxygen_wrapper 2022-10-01 18:44:31 +00:00
emdee
c5edc1f01b Fix tests 2022-09-29 06:49:32 +00:00
emdee
a7c07ffdf7 update README 2022-09-27 18:39:33 +00:00
emdee
cdb0db5b4b update wrapper 2022-09-27 16:37:35 +00:00
emdee
a365b7d54c Updated 2022-09-27 16:02:36 +00:00
emdee
870e3125ad update big NGC 2022-09-27 13:51:50 +00:00
emdee
675bf1b2b9 update big NGC 2022-09-27 13:51:16 +00:00
emdee
cab3b4d9af update docs 2022-09-27 13:32:53 +00:00
emdee
9008bcdb7f update docs 2022-09-27 13:17:48 +00:00
emdee
61b926fe50 update gifs 2022-09-27 12:58:40 +00:00
emdee
39f2638931 next_gen branch README 2022-09-27 12:52:32 +00:00
emdee
6f0c1a444e merge in next_gen branch 2022-09-27 12:41:23 +00:00
emdee
b51ec9bd71 merge in next_gen branch 2022-09-27 12:38:39 +00:00
emdee
fda07698db merge in next_gen branch 2022-09-27 12:36:20 +00:00
ingvar1995
0a54012cf5 Fixed bug with auto accept if dir doesn't exist 2020-05-24 22:01:09 +03:00
ingvar1995
021ec52e3d Fixed travis build 2020-05-23 18:43:52 +03:00
ingvar1995
5019535c0d Fixed bug with loading old messages for groups 2020-03-21 22:05:17 +03:00
ingvar1995
1554d9e53a Fixed bug with sending faux offline inlines 2020-03-14 15:33:57 +03:00
ingvar1995
a984b624b5 Added ability to paste image 2020-03-04 00:34:10 +03:00
ingvar1995
2aea5df33c proper fix for gc history 2018-09-15 22:50:25 +03:00
ingvar1995
1fa13db4e4 fixed bug with history loading and qtox screenshots autoaccept 2018-09-15 22:29:30 +03:00
ingvar1995
3582722faa fixed 2 bugs with gc 2018-09-13 23:23:25 +03:00
1342 changed files with 12503 additions and 5936 deletions

43
.github/workflows/ci.yml vendored Normal file
View file

@ -0,0 +1,43 @@
name: CI
on:
- push
- pull_request
jobs:
build:
strategy:
matrix:
python-version:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
name: Python ${{ matrix.python-version }}
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install bandit flake8 pylint
- name: Lint with flake8
run: make flake8
# - name: Lint with pylint
# run: make pylint
- name: Lint with bandit
run: make bandit

17
.gitignore vendored
View file

@ -1,15 +1,27 @@
.pylint.err
.pylint.out
*.pyc
*.pyo
*.zip
*.bak
*.lis
*.dst
*.so
toxygen/toxcore
tests/tests
tests/libs
toxygen/libs
tests/.cache
tests/__pycache__
tests/avatars
toxygen/libs
.idea
*~
#*
*.iml
*.junk
*.so
*.log
toxygen/build
@ -25,4 +37,5 @@ Toxygen.egg-info
*.tox
.cache
*.db
*~
Makefile

23
.pre-commit-config.yaml Normal file
View file

@ -0,0 +1,23 @@
# -*- mode: yaml; indent-tabs-mode: nil; tab-width: 2; coding: utf-8-unix -*-
---
default_language_version:
python: python3.11
default_stages: [pre-commit]
fail_fast: true
repos:
- repo: local
hooks:
- id: pylint
name: pylint
entry: env PYTHONPATH=/mnt/o/var/local/src/toxygen.git/toxygen toxcore_pylint.bash
language: system
types: [python]
args:
[
"--source-roots=/mnt/o/var/local/src/toxygen.git/toxygen",
"-rn", # Only display messages
"-sn", # Don't display the score
"--rcfile=/usr/local/etc/testforge/pylint.rc", # Link to your config file
"-E"
]

4
.pylintrc Normal file
View file

@ -0,0 +1,4 @@
[pre-commit-hook]
command=env PYTHONPATH=/mnt/o/var/local/src/toxygen.git/toxygen /usr/local/bin/toxcore_pylint.bash
params= -E --exit-zero
limit=8

8
.rsync.sh Normal file
View file

@ -0,0 +1,8 @@
#!/bin/sh
#find * -name \*.py | xargs grep -l '[ ]*$' | xargs sed -i -e 's/[ ]*$//'
rsync "$@" -vaxL --include \*.py \
--exclude Toxygen.egg-info --exclude build \
--exclude \*.pyc --exclude .pyl\* --exclude \*.so --exclude \*~ \
--exclude __pycache__ --exclude \*.egg-info --exclude \*.new \
./ ../toxygen.git/|grep -v /$

127
README.md
View file

@ -1,19 +1,17 @@
# Toxygen
Toxygen is powerful cross-platform [Tox](https://tox.chat/) client written in pure Python3.
Toxygen is powerful cross-platform [Tox](https://tox.chat/) client
for Tox and IRC/weechat written in pure Python3.
[![Release](https://img.shields.io/github/release/toxygen-project/toxygen.svg?style=flat)](https://github.com/toxygen-project/toxygen/releases/latest)
[![Stars](https://img.shields.io/github/stars/toxygen-project/toxygen.svg?style=flat)](https://github.com/toxygen-project/toxygen/stargazers)
[![Open issues](https://img.shields.io/github/issues/toxygen-project/toxygen.svg?style=flat)](https://github.com/toxygen-project/toxygen/issues)
[![License](https://img.shields.io/badge/license-GPLv3-blue.svg?style=flat)](https://raw.githubusercontent.com/toxygen-project/toxygen/master/LICENSE.md)
[![Build Status](https://travis-ci.org/toxygen-project/toxygen.svg?branch=master)](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)
### [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 (only Linux is tested at the moment)
### Features:
- PyQt5, PyQt6, and maybe PySide2, PySide6 via qtpy
- IRC via weechat /relay
- NGC groups
- 1v1 messages
- File transfers
- Audio calls
@ -25,14 +23,13 @@ Toxygen is powerful cross-platform [Tox](https://tox.chat/) client written in pu
- Emoticons
- Stickers
- Screenshots
- Name lookups (toxme.io support)
- Save file encryption
- Profile import and export
- Faux offline messaging
- Faux offline file transfers
- Inline images
- Message splitting
- Proxy support
- Proxy support - runs over tor, without DNS leaks
- Avatars
- Multiprofile
- Multilingual
@ -43,22 +40,108 @@ Toxygen is powerful cross-platform [Tox](https://tox.chat/) client written in pu
- Changing nospam
- File resuming
- Read receipts
### 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)
- uses gevent
### Screenshots
*Toxygen on Ubuntu and Windows*
![Ubuntu](/docs/ubuntu.png)
![Windows](/docs/windows.png)
### Docs
[Check /docs/ for more info](/docs/)
Windows was working but is not currently being tested. AV is working
but the video is garbled: we're unsure of naming the AV devices
from the commandline. We need to get a working echobot that supports SOCKS5;
we were working on one in https://git.plastiras.org/emdee/toxygen_wrapper
Also visit [pythonhosted.org/Toxygen/](http://pythonhosted.org/Toxygen/)
## Forked
[Wiki](https://wiki.tox.chat/clients/toxygen)
This hard-forked from the dead https://github.com/toxygen-project/toxygen
```next_gen``` branch.
See ToDo.md to the current ToDo list.
## IRC Weechat
You can have a [weechat](https://github.com/weechat/qweechat)
console so that you can have IRC and jabber in a window as well as Tox.
There's a copy of qweechat in https://git.plastiras.org/emdee/qweechat
that you must install first, which was backported to PyQt5 now to qtpy
(PyQt5 PyQt6 and PySide2 and PySide6) and integrated into toxygen.
Follow the normal instructions for adding a ```relay``` to
[weechat](https://github.com/weechat/weechat)
```
/relay add weechat 9000
/relay start weechat
```
or
```
weechat -r '/relay add weechat 9000;/relay start weechat'
```
and use the Plugins -> Weechat Console to start weechat under Toxygen.
Then use the File/Connect menu item of the Console to connect to weechat.
Weechat has a Jabber plugin to enable XMPP:
```
/python load jabber.el
/help jabber
```
so you can have Tox, IRC and XMPP in the same application! See docs/ToxygenWeechat.md
## Install
To install read the requirements.txt and look at the comments; there
are things that need installing by hand or decisions to be made
on supported alternatives.
https://git.plastiras.org/emdee/toxygen_wrapper needs installing as it is a
dependency. Just download and install it from
https://git.plastiras.org/emdee/toxygen_wrapper The same with
https://git.plastiras.org/emdee/qweechat
This is being ported to Qt6 using qtpy https://github.com/spyder-ide/qtpy
It now runs on PyQt5 and PyQt6, and may run on PySide2 and PySide6 - YMMV.
You will be able to choose between them by setting the environment variable
```QT_API``` to one of: ```pyqt5 pyqt6 pyside2 pyside6```.
It's currently tested mainly on PyQt5.
To install it, look in the Makefile for the install target and type
```
make install
```
You should set the PIP_EXE_MSYS and PYTHON_EXE_MSYS variables and it does
```
${PIP_EXE_MSYS} --python ${PYTHON_EXE_MSYS} install \
--no-deps \
--target ${PREFIX}/lib/python${PYTHON_MINOR}/site-packages/ \
--upgrade .
```
and installs into PREFIX which is usually /usr/local
## Updates
Up-to-date code is on https://git.plastiras.org/emdee/toxygen
Tox works over Tor, and the c-toxcore library can leak DNS requests
due to a 6-year old known security issue:
https://github.com/TokTok/c-toxcore/issues/469 but toxygen looksup
addresses before calling c-toxcore. This also allows us to use onion
addresses in the DHTnodes.json file. Still for anonymous communication
we recommend having a TCP and UDP firewall in place.
Although Tox works with multi-user group chat, there are no checks
against impersonation of a screen nickname, so you may not be chatting
with the person you think. For the Toxic client, the (closed) issue is:
https://github.com/JFreegman/toxic/issues/622#issuecomment-1922116065
Solving this might best be done with a solution to MultiDevice q.v.
The Tox project does not follow semantic versioning of its main structures
in C so the project may break the underlying ctypes wrapper at any time;
it's not possible to use Tox version numbers to tell what the API will be.
The last git version this code was tested with is
``1623e3ee5c3a5837a92f959f289fcef18bfa9c959``` of Feb 12 10:06:37 2024.
In which case you may need to go into the tox.py file in
https://git.plastiras.org/emdee/toxygen_wrapper to fix it yourself.
## MultiDevice
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!

70
ToDo.md Normal file
View file

@ -0,0 +1,70 @@
# 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. this may be
fixed already
2. The tray icon is flaky and has been disabled - look in app.py
for bSHOW_TRAY
## Fix history
## 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.
## NGC 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.
## Migration
Migrate PyQt5 to qtpy - done, but I'm not sure qtpy supports PyQt6.
https://github.com/spyder-ide/qtpy/
Maybe migrate gevent to asyncio, and migrate to
[qasync](https://github.com/CabbageDevelopment/qasync)
(see https://git.plastiras.org/emdee/phantompy ).
(Also look at https://pypi.org/project/asyncio-gevent/ but it's dead).
## Standards
There's a standard for Tox clients that this has not been tested against:
https://tox.gitbooks.io/tox-client-standard/content/general_requirements/general_requirements.html
https://github.com/Tox/Tox-Client-Standard

130
_Bugs/segv.err Normal file
View file

@ -0,0 +1,130 @@
0
TRAC> network.c#1748:net_connect connecting socket 58 to 127.0.0.1:9050
TRAC> Messenger.c#2709:do_messenger Friend num in DHT 2 != friend num in msger 14
TRAC> Messenger.c#2723:do_messenger F[--: 0] D3385007C28852C5398393E3338E6AABE5F86EF249BF724E7404233207D4D927
TRAC> Messenger.c#2723:do_messenger F[--: 1] 98984E104B8A97CC43AF03A27BE159AC1F4CF35FADCC03D6CD5F8D67B5942A56
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] =>T 2= 185.87.49.189:3389 (0: OK) | 0000000000000000...00
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 10= 185.87.49.189:3389 (0: OK) | 010001b95731bd0d...3d
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] =>T 2= 37.221.66.161:443 (0: OK) | 0000000000000000...00
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 10= 37.221.66.161:443 (0: OK) | 01000125dd42a101...bb
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 3= 172.93.52.70:33445 (0: OK) | 0000000000000000...00
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 2 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 3= 139.162.110.188:33445 (0: OK) | 0000000000000000...00
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 2 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 3= 37.59.63.150:33445 (0: OK) | 0000000000000000...00
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 2 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 3= 130.133.110.14:33445 (0: OK) | 0000000000000000...00
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 2 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 3= 37.97.185.116:33445 (0: OK) | 0000000000000000...00
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 2 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 3= 85.143.221.42:33445 (0: OK) | 0000000000000000...00
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 2 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 3= 104.244.74.69:38445 (0: OK) | 0000000000000000...00
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 2 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 3= 49.12.229.145:3389 (0: OK) | 0000000000000000...00
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 2 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 3= 168.119.209.10:33445 (0: OK) | 0000000000000000...00
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 2 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 3= 81.169.136.229:33445 (0: OK) | 0000000000000000...00
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 2 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 3= 91.219.59.156:33445 (0: OK) | 0000000000000000...00
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 2 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 3= 46.101.197.175:3389 (0: OK) | 0000000000000000...00
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 2 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 3= 198.199.98.108:33445 (0: OK) | 0000000000000000...00
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 2 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 3= 130.133.110.14:33445 (0: OK) | 0000000000000000...00
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 2 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 3= 49.12.229.145:3389 (0: OK) | 0000000000000000...00
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 2 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 3= 188.225.9.167:33445 (0: OK) | 0000000000000000...00
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 2 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 3= 5.19.249.240:38296 (0: OK) | 0000000000000000...00
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 2 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 3= 94.156.35.247:3389 (0: OK) | 0000000000000000...00
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 2 bytes
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] =>T 2= 172.93.52.70:33445 (0: OK) | 0000000000000000...00
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 10= 172.93.52.70:33445 (0: OK) | 010001ac5d344682...a5
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] =>T 2= 139.162.110.188:33445 (0: OK) | 0000000000000000...00
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 10= 139.162.110.188:33445 (0: OK) | 0100018ba26ebc82...a5
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] =>T 2= 37.59.63.150:33445 (0: OK) | 0000000000000000...00
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 10= 37.59.63.150:33445 (0: OK) | 010001253b3f9682...a5
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] =>T 2= 130.133.110.14:33445 (0: OK) | 0000000000000000...00
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 10= 130.133.110.14:33445 (0: OK) | 01000182856e0e82...a5
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] =>T 2= 37.97.185.116:33445 (0: OK) | 0000000000000000...00
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 10= 37.97.185.116:33445 (0: OK) | 0100012561b97482...a5
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] =>T 2= 85.143.221.42:33445 (0: OK) | 0000000000000000...00
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 10= 85.143.221.42:33445 (0: OK) | 010001558fdd2a82...a5
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] =>T 2= 104.244.74.69:38445 (0: OK) | 0000000000000000...00
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 10= 104.244.74.69:38445 (0: OK) | 01000168f44a4596...2d
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] =>T 2= 49.12.229.145:3389 (0: OK) | 0000000000000000...00
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 10= 49.12.229.145:3389 (0: OK) | 010001310ce5910d...3d
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] =>T 2= 168.119.209.10:33445 (0: OK) | 0000000000000000...00
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 10= 168.119.209.10:33445 (0: OK) | 010001a877d10a82...a5
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] =>T 2= 81.169.136.229:33445 (0: OK) | 0000000000000000...00
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 10= 81.169.136.229:33445 (0: OK) | 01000151a988e582...a5
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] =>T 2= 91.219.59.156:33445 (0: OK) | 0000000000000000...00
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 10= 91.219.59.156:33445 (0: OK) | 0100015bdb3b9c82...a5
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] =>T 2= 46.101.197.175:3389 (0: OK) | 0000000000000000...00
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 10= 46.101.197.175:3389 (0: OK) | 0100012e65c5af0d...3d
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] =>T 2= 198.199.98.108:33445 (0: OK) | 0000000000000000...00
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 10= 198.199.98.108:33445 (0: OK) | 010001c6c7626c82...a5
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] =>T 2= 130.133.110.14:33445 (0: OK) | 0000000000000000...00
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 10= 130.133.110.14:33445 (0: OK) | 01000182856e0e82...a5
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] =>T 2= 49.12.229.145:3389 (0: OK) | 0000000000000000...00
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 10= 49.12.229.145:3389 (0: OK) | 010001310ce5910d...3d
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] =>T 2= 188.225.9.167:33445 (0: OK) | 0000000000000000...00
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 10= 188.225.9.167:33445 (0: OK) | 010001bce109a782...a5
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] =>T 2= 5.19.249.240:38296 (0: OK) | 0000000000000000...00
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 10= 5.19.249.240:38296 (0: OK) | 0100010513f9f095...98
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> network.c#789:loglogdata [05 = <unknown> ] =>T 2= 94.156.35.247:3389 (0: OK) | 0000000000000000...00
TRAC> network.c#789:loglogdata [05 = <unknown> ] T=> 10= 94.156.35.247:3389 (0: OK) | 0100015e9c23f70d...3d
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
TRAC> TCP_common.c#203:read_TCP_packet recv buffer has 0 bytes, but requested 10 bytes
app.contacts.contacts_manager INFO update_groups_numbers len(groups)={len(groups)}
Thread 76 "ToxIterateThrea" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffedcb6b640 (LWP 2950427)]

View file

@ -0,0 +1,11 @@
ping tox.abilinski.com
ping: socket: Address family not supported by protocol
PING tox.abilinski.com (172.103.226.229) 56(84) bytes of data.
64 bytes from 172.103.226.229.cable.tpia.cipherkey.com (172.103.226.229): icmp_seq=1 ttl=48 time=86.6 ms
64 bytes from 172.103.226.229.cable.tpia.cipherkey.com (172.103.226.229): icmp_seq=2 ttl=48 time=83.1 ms
64 bytes from 172.103.226.229.cable.tpia.cipherkey.com (172.103.226.229): icmp_seq=3 ttl=48 time=82.9 ms
64 bytes from 172.103.226.229.cable.tpia.cipherkey.com (172.103.226.229): icmp_seq=4 ttl=48 time=83.4 ms
64 bytes from 172.103.226.229.cable.tpia.cipherkey.com (172.103.226.229): icmp_seq=5 ttl=48 time=102 ms
64 bytes from 172.103.226.229.cable.tpia.cipherkey.com (172.103.226.229): icmp_seq=6 ttl=48 time=87.4 ms
64 bytes from 172.103.226.229.cable.tpia.cipherkey.com (172.103.226.229): icmp_seq=7 ttl=48 time=84.9 ms
^C

View file

@ -1,13 +0,0 @@
FROM ubuntu:16.04
RUN apt-get update && \
apt-get install build-essential libtool autotools-dev automake checkinstall cmake check git yasm libsodium-dev libopus-dev libvpx-dev pkg-config -y && \
git clone https://github.com/ingvar1995/toxcore.git --branch=ngc_rebase && \
cd toxcore && mkdir _build && cd _build && \
cmake .. && make && make install
RUN apt-get install portaudio19-dev python3-pyqt5 python3-pyaudio python3-pip -y && \
pip3 install numpy pydenticon opencv-python pyinstaller
RUN useradd -ms /bin/bash toxygen
USER toxygen

View file

@ -1,33 +0,0 @@
#!/usr/bin/env bash
cd ~
git clone https://github.com/toxygen-project/toxygen.git --branch=next_gen
cd toxygen/toxygen
pyinstaller --windowed --icon=images/icon.ico main.py
cp -r styles dist/main/
find . -type f ! -name '*.qss' -delete
cp -r plugins dist/main/
mkdir -p dist/main/ui/views
cp -r ui/views dist/main/ui/
cp -r sounds dist/main/
cp -r smileys dist/main/
cp -r stickers dist/main/
cp -r bootstrap dist/main/
find . -type f ! -name '*.json' -delete
cp -r images dist/main/
cp -r translations dist/main/
find . -name "*.ts" -type f -delete
cd dist
mv main toxygen
cd toxygen
mv main toxygen
wget -O updater https://github.com/toxygen-project/toxygen_updater/releases/download/v0.1/toxygen_updater_linux_64
echo "[Paths]" >> qt.conf
echo "Prefix = PyQt5/Qt" >> qt.conf
cd ..
tar -zcvf toxygen_linux_64.tar.gz toxygen > /dev/null
rm -rf toxygen

171
docs/ToxygenWeechat.md Normal file
View file

@ -0,0 +1,171 @@
## Toxygen Weechat
You can have a [weechat](https://github.com/weechat/qweechat)
console so that you can have IRC and jabber in a window as well as Tox.
There's a copy of qweechat in ```thirdparty/qweechat``` backported to
PyQt5 and integrated into toxygen. Follow the normal instructions for
adding a ```relay``` to [weechat](https://github.com/weechat/weechat)
```
/relay add ipv4.ssl.weechat 9000
/relay start ipv4.ssl.weechat
```
or
```
/set relay.network.ipv6 off
/set relay.network.password password
/relay add weechat 9000
/relay start weechat
```
and use the Plugins/Weechat Console to start weechat under Toxygen.
Then use the File/Connect menu item of the Console to connect to weechat.
Weechat has a Jabber plugin to enable XMPP:
```
/python load jabber.el
/help jabber
```
so you can have Tox, IRC and XMPP in the same application!
### Creating servers for IRC over Tor
Create a proxy called tor
```
/proxy add tor socks5 127.0.0.1 9050
```
It should now show up in the list of proxies.
```
/proxy list
```
```
/nick NickName
```
## TLS certificates
[Create a Self-signed Certificate](https://www.oftc.net/NickServ/CertFP/)
Choose a NickName you will identify as.
Create a directory for your certificates ~/.config/weechat/ssl/
and make a subdirectory for each server ~/.config/weechat/ssl/irc.oftc.net/
Change to the server directory and use openssl to make a keypair and answer the questions:
```
openssl req -nodes -newkey rsa:2048 -keyout NickName.key -x509 -days 3650 -out NickName.cer
chmod 400 NickName.key
```
We now combine certificate and key to a single file NickName.pem
```
cat NickName.cer NickName.key > NickName.pem
chmod 400 NickName.pem
```
Do this for each server you want to connect to, or just use one for all of them.
### Libera TokTok channel
The main discussion forum for Tox is the #TokTok channel on libera.
https://mox.sh/sysadmin/secure-irc-connection-to-freenode-with-tor-and-weechat/
We have to create an account without Tor, this is a requirement to use TOR:
Connect to irc.libera.chat without Tor and register
```
/msg NickServ identify NickName password
/msg NickServ REGISTER mypassword mycoolemail@example.com
/msg NickServ SET PRIVATE ON
```
You'll get an email with a registration code.
Confirm registration after getting the mail with the code:
```
/msg NickServ VERIFY REGISTER NickName code1235678
```
Libera has an onion server so we can map an address in tor. Add this
to your /etc/tor/torrc
```
MapAddress palladium.libera.chat libera75jm6of4wxpxt4aynol3xjmbtxgfyjpu34ss4d7r7q2v5zrpyd.onion
```
Or without the MapAddress just use
libera75jm6of4wxpxt4aynol3xjmbtxgfyjpu34ss4d7r7q2v5zrpyd.onion
as the server address below, but set tls_verify to off.
Define the server in weechat
https://www.weechat.org/files/doc/stable/weechat_user.en.html#irc_sasl_authentication
```
/server remove libera
/server add libera palladium.libera.chat/6697 -tls -tls_verify
/set irc.server.libera.ipv6 off
/set irc.server.libera.proxy tor
/set irc.server.libera.username NickName
/set irc.server.libera.password password
/set irc.server.libera.nicks NickName
/set irc.server.libera.tls on
/set irc.server.libera.tls_cert "${weechat_config_dir}/ssl/libera.chat/NickName.pem"
```
```
/set irc.server.libera.sasl_mechanism ecdsa-nist256p-challenge
/set irc.server.libera.sasl_username "NickName"
/set irc.server.libera.sasl_key "${weechat_config_dir}/ssl/libera.chat/NickName.pem"
```
Disconnect and connect back to the server.
```
/disconnect libera
/connect libera
```
/msg nickserv identify password NickName
### oftc.net
To use oftc.net over tor, you need to authenticate by SSL certificates.
Define the server in weechat
```
/server remove irc.oftc.net
/server add OFTC irc.oftc.net/6697 -tls -tls_verify
/set irc.server.OFTC.ipv6 off
/set irc.server.OFTC.proxy tor
/set irc.server.OFTC.username NickName
/set irc.server.OFTC.nicks NickName
/set irc.server.OFTC.tls on
/set irc.server.OFTC.tls_cert "${weechat_config_dir}/ssl/irc.oftc.chat/NickName.pem"
# Disconnect and connect back to the server.
/disconnect OFTC
/connect OFTC
```
You must be identified in order to validate using certs
```
/msg nickserv identify password NickName
```
To allow NickServ to identify you based on this certificate you need
to associate the certificate fingerprint with your nick. To do this
issue the command cert add to Nickserv (try /msg nickserv helpcert).
```
/msg nickserv cert add
```
### Privacy
[Add somes settings bellow to weechat](https://szorfein.github.io/weechat/tor/configure-weechat/).
Detail from [faq](https://weechat.org/files/doc/weechat_faq.en.html#security).
```
/set irc.server_default.msg_part ""
/set irc.server_default.msg_quit ""
/set irc.ctcp.clientinfo ""
/set irc.ctcp.finger ""
/set irc.ctcp.source ""
/set irc.ctcp.time ""
/set irc.ctcp.userinfo ""
/set irc.ctcp.version ""
/set irc.ctcp.ping ""
/plugin unload xfer
/set weechat.plugin.autoload "*,!xfer"
```

View file

@ -21,8 +21,8 @@ Note: 32-bit Python isn't supported due to bug with videocalls. It is strictly r
3. Install PyAudio: ``pip install pyaudio``
4. Install numpy: ``pip install numpy``
5. Install OpenCV: ``pip install opencv-python``
6. [Download toxygen](https://github.com/toxygen-project/toxygen/archive/master.zip)
7. Unpack archive
6. git clone --depth=1 https://git.plastiras.org/emdee/toxygen/
7. I don't know
8. Download latest libtox.dll build, download latest libsodium.a build, put it into \toxygen\libs\
9. Run \toxygen\main.py.
@ -30,15 +30,22 @@ Note: 32-bit Python isn't supported due to bug with videocalls. It is strictly r
1. Install latest 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``
3. Install [toxcore](https://github.com/TokTok/c-toxcore) with toxav support)
4. 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``
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/)
8. Unpack archive
4. Install PyAudio: ``sudo apt-get install portaudio19-dev python3-pyaudio`` (or ``sudo pip3 install pyaudio``)
5. Install toxygen_wrapper https://git.plastiras.org/emdee/toxygen_wrapper
6. Install the rest of the requirements: ``sudo pip3 install -m requirements.txt``
7. git clone --depth=1 [toxygen](https://git.plastiras.org/emdee/toxygen/)
8. Look in the Makefile for the install target and type
``
make install
``
You should set the PIP_EXE_MSYS and PYTHON_EXE_MSYS variables and it does
``
${PIP_EXE_MSYS} --python ${PYTHON_EXE_MSYS} install \
--target ${PREFIX}/lib/python${PYTHON_MINOR}/site-packages/ \
--upgrade .
``
9. Run app:
``python3 main.py``
``python3 ${PREFIX}/lib/python${PYTHON_MINOR}/site-packages/bin/toxygen``
Optional: install toxygen using setup.py: ``python3 setup.py install``

View file

@ -53,5 +53,5 @@ Plugin's methods MUST NOT raise exceptions.
# Examples
You can find examples in [official repo](https://github.com/toxygen-project/toxygen_plugins)
You can find examples in [official repo](https://git.plastiras.org/emdee/toxygen_plugins)

70
docs/todo.md Normal file
View file

@ -0,0 +1,70 @@
# 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. this may be
fixed already
2. The tray icon is flaky and has been disabled - look in app.py
for bSHOW_TRAY
## Fix history
## 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.
## NGC 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.
## Migration
Migrate PyQt5 to qtpy - done, but I'm not sure qtpy supports PyQt6.
https://github.com/spyder-ide/qtpy/
Maybe migrate gevent to asyncio, and migrate to
[qasync](https://github.com/CabbageDevelopment/qasync)
(see https://git.plastiras.org/emdee/phantompy ).
(Also look at https://pypi.org/project/asyncio-gevent/ but it's dead).
## Standards
There's a standard for Tox clients that this has not been tested against:
https://tox.gitbooks.io/tox-client-standard/content/general_requirements/general_requirements.html
https://github.com/Tox/Tox-Client-Standard

56
pyproject.toml Normal file
View file

@ -0,0 +1,56 @@
[project]
name = "toxygen"
description = "examples of using stem"
authors = [{ name = "emdee", email = "emdee@spm.plastiras.org" } ]
requires-python = ">=3.7"
keywords = ["stem", "python3", "tox"]
classifiers = [
# How mature is this project? Common values are
# 3 - Alpha
# 4 - Beta
# 5 - Production/Stable
"Development Status :: 4 - Beta",
# Indicate who your project is intended for
"Intended Audience :: Developers",
# Specify the Python versions you support here.
"Programming Language :: Python :: 3",
"License :: OSI Approved",
"Operating System :: POSIX :: BSD :: FreeBSD",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: Implementation :: CPython",
]
#
dynamic = ["version", "readme", "dependencies"] # cannot be dynamic ['license']
[project.gui-scripts]
toxygen = "toxygen.__main__:main"
[project.optional-dependencies]
weechat = ["weechat"]
#[project.license]
#file = "LICENSE.md"
[project.urls]
repository = "https://git.plastiras.org/emdee/toxygen"
[build-system]
requires = ["setuptools >= 61.0"]
build-backend = "setuptools.build_meta"
[tool.setuptools.dynamic]
version = {attr = "toxygen.app.__version__"}
readme = {file = ["README.md", "ToDo.txt"]}
dependencies = {file = ["requirements.txt"]}
[tool.setuptools]
packages = ["toxygen"]

26
requirements.txt Normal file
View file

@ -0,0 +1,26 @@
# the versions are the current ones tested - may work with earlier versions
# choose one of PyQt5 PyQt6 PySide2 PySide6
# for now PyQt5 and PyQt6 is working, and most of the testing is PyQt5
# usually this is installed by your OS package manager and pip may not
# detect the right version, so we leave these commented
# PyQt5 >= 5.15.10
# this is not on pypi yet but is required - get it from
# https://git.plastiras.org/emdee/toxygen_wrapper
# toxygen_wrapper == 1.0.0
QtPy >= 2.4.1
PyAudio >= 0.2.13
numpy >= 1.26.1
opencv_python >= 4.8.0
pillow >= 10.2.0
gevent >= 23.9.1
pydenticon >= 0.3.1
greenlet >= 2.0.2
sounddevice >= 0.3.15
# this is optional
coloredlogs >= 15.0.1
# this is optional
# qtconsole >= 5.4.3
# this is not on pypi yet but is optional for qweechat - get it from
# https://git.plastiras.org/emdee/qweechat
# qweechat_wrapper == 0.0.1

54
setup.cfg Normal file
View file

@ -0,0 +1,54 @@
[metadata]
classifiers =
License :: OSI Approved
License :: OSI Approved :: BSD 1-clause
Intended Audience :: Web Developers
Operating System :: Microsoft :: Windows
Operating System :: POSIX :: BSD :: FreeBSD
Operating System :: POSIX :: Linux
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: Implementation :: CPython
[options]
zip_safe = false
python_requires = ~=3.7
include_package_data =
"*" = ["*.ui", "*.txt", "*.png", "*.ico", "*.gif", "*.wav"]
[options.entry_points]
console_scripts =
toxygen = toxygen.__main__:iMain
[easy_install]
zip_ok = false
[flake8]
jobs = 1
max-line-length = 88
ignore =
E111
E114
E128
E225
E261
E302
E305
E402
E501
E502
E541
E701
E702
E704
E722
E741
F508
F541
W503
W601

View file

@ -1,93 +0,0 @@
from setuptools import setup
from setuptools.command.install import install
from platform import system
from subprocess import call
import main
import sys
import os
from utils.util import curr_directory, join_path
version = main.__version__ + '.0'
if system() == 'Windows':
MODULES = ['PyQt5', 'PyAudio', 'numpy', 'opencv-python', 'pydenticon']
else:
MODULES = []
try:
import pyaudio
except ImportError:
MODULES.append('PyAudio')
try:
import PyQt5
except ImportError:
MODULES.append('PyQt5')
try:
import numpy
except ImportError:
MODULES.append('numpy')
try:
import cv2
except ImportError:
MODULES.append('opencv-python')
try:
import pydenticon
except ImportError:
MODULES.append('pydenticon')
def get_packages():
directory = join_path(curr_directory(__file__), 'toxygen')
for root, dirs, files in os.walk(directory):
packages = map(lambda d: 'toxygen.' + d, dirs)
packages = ['toxygen'] + list(packages)
return packages
class InstallScript(install):
"""This class configures Toxygen after installation"""
def run(self):
install.run(self)
try:
if system() != 'Windows':
call(["toxygen", "--clean"])
except:
try:
params = list(filter(lambda x: x.startswith('--prefix='), sys.argv))
if params:
path = params[0][len('--prefix='):]
if path[-1] not in ('/', '\\'):
path += '/'
path += 'bin/toxygen'
if system() != 'Windows':
call([path, "--clean"])
except:
pass
setup(name='Toxygen',
version=version,
description='Toxygen - Tox client',
long_description='Toxygen is powerful Tox client written in Python3',
url='https://github.com/toxygen-project/toxygen/',
keywords='toxygen tox messenger',
author='Ingvar',
maintainer='Ingvar',
license='GPL3',
packages=get_packages(),
install_requires=MODULES,
include_package_data=True,
classifiers=[
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
],
entry_points={
'console_scripts': ['toxygen=toxygen.main:main']
},
cmdclass={
'install': InstallScript
})

53
setup.py.dst Normal file
View file

@ -0,0 +1,53 @@
import sys
import os
from setuptools import setup
from setuptools.command.install import install
version = '1.0.0'
MODULES = open('requirements.txt', 'rt').readlines()
def get_packages():
directory = os.path.join(os.path.dirname(__file__), 'tox_wrapper')
for root, dirs, files in os.walk(directory):
packages = map(lambda d: 'toxygen.' + d, dirs)
packages = ['toxygen'] + list(packages)
return packages
class InstallScript(install):
"""This class configures Toxygen after installation"""
def run(self):
install.run(self)
setup(name='Toxygen',
version=version,
description='Toxygen - Tox client',
long_description='Toxygen is powerful Tox client written in Python3',
url='https://git.plastiras.org/emdee/toxygen/',
keywords='toxygen Tox messenger',
author='Ingvar',
maintainer='',
license='GPL3',
packages=get_packages(),
install_requires=MODULES,
include_package_data=True,
classifiers=[
'Programming Language :: Python :: 3 :: Only',
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
'Programming Language :: Python :: 3.11',
],
entry_points={
'console_scripts': ['toxygen=toxygen.main:main']
},
package_data={"": ["*.ui"],},
cmdclass={
'install': InstallScript,
},
zip_safe=False
)

View file

@ -1,4 +1,4 @@
class TestToxygen:
def test_main(self):
import toxygen.main # check for syntax errors
import toxygen.__main__ # check for syntax errors

14
toxygen/.pylint.sh Executable file
View file

@ -0,0 +1,14 @@
#!/bin/sh
ROLE=logging
/var/local/bin/pydev_pylint.bash -E -f text *py [a-nr-z]*/*py >.pylint.err
/var/local/bin/pydev_pylint.bash *py [a-nr-z]*/*py >.pylint.out
sed -e "/Module 'os' has no/d" \
-e "/Undefined variable 'app'/d" \
-e '/tests\//d' \
-e "/Instance of 'Curl' has no /d" \
-e "/No name 'path' in module 'os' /d" \
-e "/ in module 'os'/d" \
-e "/.bak\//d" \
-i .pylint.err .pylint.out

View file

@ -1,8 +1,3 @@
import os
import sys
path = os.path.dirname(os.path.realpath(__file__)) # curr dir
sys.path.insert(0, os.path.join(path, 'styles'))
sys.path.insert(0, os.path.join(path, 'plugins'))
sys.path.insert(0, path)

378
toxygen/__main__.py Normal file
View file

@ -0,0 +1,378 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
import sys
import os
import logging
import signal
import time
import warnings
import faulthandler
from gevent import monkey; monkey.patch_all(); del monkey # noqa
faulthandler.enable()
warnings.filterwarnings('ignore')
import toxygen_wrapper.tests.support_testing as ts
try:
from trepan.interfaces import server as Mserver
from trepan.api import debug
except Exception as e:
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
import app
from user_data.settings import *
from user_data.settings import Settings
from user_data import settings
import utils.util as util
with ts.ignoreStderr():
import pyaudio
__maintainer__ = 'Ingvar'
__version__ = '1.0.0' # was 0.5.0+
path = os.path.dirname(os.path.realpath(__file__)) # curr dir
sys.path.insert(0, os.path.join(path, 'styles'))
sys.path.insert(0, os.path.join(path, 'plugins'))
# sys.path.insert(0, os.path.join(path, 'third_party'))
sys.path.insert(0, path)
sleep = time.sleep
os.environ['QT_API'] = os.environ.get('QT_API', 'pyqt5')
def reset() -> None:
Settings.reset_auto_profile()
def clean() -> None:
"""Removes libs folder"""
directory = util.get_libs_directory()
util.remove(directory)
def print_toxygen_version() -> None:
print('toxygen ' + __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):
video = setup_default_video()
# this is messed up - no video_input in oArgs
# parser.add_argument('--video_input', type=str,)
print(video)
if not video or not video['output_devices']:
video['device'] = -1
if not hasattr(oArgs, 'video_input'):
video['device'] = video['output_devices'][0]
elif 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}")
video = {'device': -1, 'width': 320, 'height': 240, 'x': 0, 'y': 0}
video['output_devices'] = default_video
return video
def main_parser(_=None, iMode=2):
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()['output_devices']
parser = ts.oMainArgparser()
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('--reset', action='store_true', help='Reset default profile')
parser.add_argument('--uri', type=str, default='',
help='Add specified Tox ID to friends')
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=iMode,
# 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('--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('--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('--video_input', type=str,
default=-1,
choices=default_video,
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
lKEEP_SETTINGS = ['uri',
'profile',
'loglevel',
'logfile',
'mode',
# dunno
'audio_input',
'audio_output',
'audio',
'video',
'ipv6_enabled',
'udp_enabled',
'local_discovery_enabled',
'trace_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=None) -> int:
global oPYA
from argparse import Namespace
if lArgs is None:
lArgs = sys.argv[1:]
parser = main_parser()
default_ns = parser.parse_args([])
oArgs = parser.parse_args(lArgs)
if oArgs.version:
print_toxygen_version()
return 0
if oArgs.clean:
clean()
return 0
if oArgs.reset:
reset()
return 0
# if getattr(oArgs, 'network') in ['newlocal', 'localnew']: oArgs.network = 'new'
# 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
oApp = app.App(__version__, oArgs)
# for pyqtconsole
try:
setattr(__builtins__, 'app', oApp)
except Exception as e:
pass
i = oApp.iMain()
return i
if __name__ == '__main__':
iRet = 0
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)

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,4 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
class Call:
@ -17,9 +17,7 @@ class Call:
is_active = property(get_is_active, set_is_active)
# -----------------------------------------------------------------------------------------------------------------
# Audio
# -----------------------------------------------------------------------------------------------------------------
def get_in_audio(self):
return self._in_audio
@ -37,9 +35,7 @@ class Call:
out_audio = property(get_out_audio, set_out_audio)
# -----------------------------------------------------------------------------------------------------------------
# Video
# -----------------------------------------------------------------------------------------------------------------
def get_in_video(self):
return self._in_video

View file

@ -1,21 +1,80 @@
import pyaudio
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
import time
import threading
from wrapper.toxav_enums import *
import cv2
import logging
import itertools
import numpy as np
from toxygen_wrapper.toxav_enums import *
from toxygen_wrapper.tests import support_testing as ts
from toxygen_wrapper.tests.support_testing import LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG, LOG_TRACE
with ts.ignoreStderr():
import pyaudio
from av import screen_sharing
from av.call import Call
import common.tox_save
from middleware.threads import BaseQThread
from utils import ui as util_ui
from middleware.threads import invoke_in_main_thread
# from middleware.threads import BaseThread
sleep = time.sleep
global LOG
LOG = logging.getLogger('app.'+__name__)
TIMER_TIMEOUT = 30.0
iFPS = 25
class AudioThread(BaseQThread):
def __init__(self, av, name=''):
super().__init__()
self.av = av
self._name = name
def join(self, ito=ts.iTHREAD_TIMEOUT):
LOG_DEBUG(f"AudioThread join {self}")
# dunno
def run(self) -> None:
LOG_DEBUG('AudioThread run: ')
# maybe not needed
while not self._stop_thread:
self.av.send_audio()
sleep(100.0 / 1000.0)
class VideoThread(BaseQThread):
def __init__(self, av, name=''):
super().__init__()
self.av = av
self._name = name
def join(self, ito=ts.iTHREAD_TIMEOUT):
LOG_DEBUG(f"VideoThread join {self}")
# dunno
def run(self) -> None:
LOG_DEBUG('VideoThread run: ')
# maybe not needed
while not self._stop_thread:
self.av.send_video()
sleep(100.0 / 1000.0)
class AV(common.tox_save.ToxAvSave):
def __init__(self, toxav, settings):
super().__init__(toxav)
self._toxav = toxav
self._settings = settings
self._running = True
s = settings
if 'video' not in s:
LOG.warn("AV.__init__ 'video' not in s" )
LOG.debug(f"AV.__init__ {s}" )
elif 'device' not in s['video']:
LOG.warn("AV.__init__ 'device' not in s.video" )
LOG.debug(f"AV.__init__ {s['video']}" )
self._calls = {} # dict: key - friend number, value - Call instance
@ -25,65 +84,125 @@ class AV(common.tox_save.ToxAvSave):
self._audio_running = False
self._out_stream = None
self._audio_rate = 8000
self._audio_channels = 1
self._audio_duration = 60
self._audio_sample_count = self._audio_rate * self._audio_channels * self._audio_duration // 1000
self._audio_rate_pa = 48000
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_thread = None
self._video_running = False
self._video_running = None
self._video_width = 640
self._video_height = 480
self._video_width = 320
self._video_height = 240
def stop(self):
# 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) -> None:
LOG_DEBUG(f"AV.CA stop {self._video_thread}")
self._running = False
self.stop_audio_thread()
self.stop_video_thread()
def __contains__(self, friend_number):
def __contains__(self, friend_number:int) -> bool:
return friend_number in self._calls
# -----------------------------------------------------------------------------------------------------------------
# Calls
# -----------------------------------------------------------------------------------------------------------------
def __call__(self, friend_number, audio, video):
"""Call friend with specified number"""
self._toxav.call(friend_number, 32 if audio else 0, 5000 if video else 0)
if friend_number in self._calls:
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 Exception as e:
LOG.warn(f"_toxav.call already has {friend_number}")
return
self._calls[friend_number] = Call(audio, video)
threading.Timer(30.0, lambda: self.finish_not_started_call(friend_number)).start()
threading.Timer(TIMER_TIMEOUT,
lambda: self.finish_not_started_call(friend_number)).start()
def accept_call(self, friend_number, audio_enabled, video_enabled):
# obsolete
self.call_accept_call(friend_number, audio_enabled, video_enabled)
def call_accept_call(self, friend_number, audio_enabled, video_enabled) -> None:
# called from CM.accept_call in a try:
LOG.debug(f"call_accept_call from F={friend_number} R={self._running}" +
f" A={audio_enabled} V={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:
self._calls[friend_number] = Call(audio_enabled, video_enabled)
self._toxav.answer(friend_number, 32 if audio_enabled else 0, 5000 if video_enabled else 0)
if audio_enabled:
self.start_audio_thread()
# audio_bit_rate: Audio bit rate in Kb/sec. Set this to 0 to disable audio sending.
# 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 Exception as e:
LOG.error(f"AV accept_call error from {friend_number} {self._running} {e}")
raise
if video_enabled:
# may raise
self.start_video_thread()
if audio_enabled:
LOG.debug(f"calls accept_call calling start_audio_thread F={friend_number}")
# may raise
self.start_audio_thread()
def finish_call(self, friend_number, by_friend=False):
if not by_friend:
self._toxav.call_control(friend_number, TOXAV_CALL_CONTROL['CANCEL'])
def finish_call(self, friend_number, by_friend=False) -> None:
LOG.debug(f"finish_call {friend_number}")
if friend_number in self._calls:
del self._calls[friend_number]
if not len(list(filter(lambda c: c.out_audio, self._calls))):
try:
# 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()
if not len(list(filter(lambda c: c.out_video, self._calls))):
self.stop_video_thread()
if not by_friend:
LOG.debug(f"finish_call before call_control {friend_number}")
self._toxav.call_control(friend_number, TOXAV_CALL_CONTROL['CANCEL'])
LOG.debug(f"finish_call after call_control {friend_number}")
def finish_not_started_call(self, friend_number):
def finish_not_started_call(self, friend_number:int) -> None:
if friend_number in self:
call = self._calls[friend_number]
if not call.is_active:
self.finish_call(friend_number)
def toxav_call_state_cb(self, friend_number, state):
def toxav_call_state_cb(self, friend_number, state) -> None:
"""
New call state
"""
LOG.debug(f"toxav_call_state_cb {friend_number}")
call = self._calls[friend_number]
call.is_active = True
@ -96,41 +215,108 @@ class AV(common.tox_save.ToxAvSave):
if state | TOXAV_FRIEND_CALL_STATE['ACCEPTING_V'] and call.out_video:
self.start_video_thread()
def is_video_call(self, number):
def is_video_call(self, number) -> bool:
return number in self and self._calls[number].in_video
# -----------------------------------------------------------------------------------------------------------------
# Threads
# -----------------------------------------------------------------------------------------------------------------
def start_audio_thread(self):
def start_audio_thread(self, bSTREAM_CALLBACK=False) -> None:
"""
Start audio sending
from a callback
"""
# called from call_accept_call in an try: from CM.accept_call
global oPYA
# was iInput = self._settings._args.audio['input']
iInput = self._settings['audio']['input']
if self._audio_thread is not None:
LOG_WARN(f"start_audio_thread device={iInput}")
return
LOG_DEBUG(f"start_audio_thread device={iInput}")
lPaSamplerates = ts.lSdSamplerates(iInput)
if not(len(lPaSamplerates)):
e = f"No sample rates for device: audio[input]={iInput}"
LOG_WARN(f"start_audio_thread {e}")
#?? dunno - cancel call? - no let the user do it
# return
# just guessing here in case that's a false negative
lPaSamplerates = [round(oPYA.get_device_info_by_index(iInput)['defaultSampleRate'])]
if lPaSamplerates and self._audio_rate_pa in lPaSamplerates:
pass
elif lPaSamplerates:
LOG_WARN(f"Setting audio_rate to: {lPaSamplerates[0]}")
self._audio_rate_pa = lPaSamplerates[0]
elif 'defaultSampleRate' in oPYA.get_device_info_by_index(iInput):
self._audio_rate_pa = oPYA.get_device_info_by_index(iInput)['defaultSampleRate']
LOG_WARN(f"setting to defaultSampleRate")
else:
LOG_WARN(f"{self._audio_rate_pa} not in {lPaSamplerates}")
# a float is in here - must it be int?
if type(self._audio_rate_pa) == float:
self._audio_rate_pa = round(self._audio_rate_pa)
try:
if self._audio_rate_pa not in lPaSamplerates:
LOG_WARN(f"PAudio sampling rate was {self._audio_rate_pa} changed to {lPaSamplerates[0]}")
LOG_DEBUG(f"lPaSamplerates={lPaSamplerates}")
self._audio_rate_pa = lPaSamplerates[0]
else:
LOG_DEBUG( f"start_audio_thread framerate: {self._audio_rate_pa}" \
+f" device: {iInput}"
+f" supported: {lPaSamplerates}")
self._audio_running = True
if bSTREAM_CALLBACK:
# why would you not call a thread?
self._audio_stream = oPYA.open(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,
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:
LOG_DEBUG( f"start_audio_thread starting thread {self._audio_rate_pa}")
self._audio_stream = oPYA.open(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)
self._audio_running = True
self._audio_thread = AudioThread(self,
name='_audio_thread')
self._audio_thread.start()
LOG_DEBUG( f"start_audio_thread started thread name='_audio_thread'")
self._audio = pyaudio.PyAudio()
self._audio_stream = self._audio.open(format=pyaudio.paInt16,
rate=self._audio_rate,
channels=self._audio_channels,
input=True,
input_device_index=self._settings.audio['input'],
frames_per_buffer=self._audio_sample_count * 10)
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? yes accept_call
# calls_manager._call.toxav_call_state_cb(friend_number, mask)
invoke_in_main_thread(util_ui.message_box,
str(e),
util_ui.tr("Starting self._audio.open"))
return
else:
LOG_DEBUG(f"start_audio_thread {self._audio_stream}")
self._audio_thread = threading.Thread(target=self.send_audio)
self._audio_thread.start()
def stop_audio_thread(self):
def stop_audio_thread(self) -> None:
LOG_DEBUG(f"stop_audio_thread {self._audio_stream}")
if self._audio_thread is None:
return
self._audio_running = False
self._audio_thread.join()
self._audio_thread._stop_thread = True
self._audio_thread = None
self._audio_stream = None
@ -141,99 +327,215 @@ class AV(common.tox_save.ToxAvSave):
self._out_stream.close()
self._out_stream = None
def start_video_thread(self):
def start_video_thread(self) -> None:
if self._video_thread is not None:
return
s = self._settings
if 'video' not in s:
LOG.warn("AV.__init__ 'video' not in s" )
LOG.debug(f"start_video_thread {s}" )
raise RuntimeError("start_video_thread not 'video' in s)" )
if 'device' not in s['video']:
LOG.error("start_video_thread not 'device' in s['video']" )
LOG.debug(f"start_video_thread {s['video']}" )
raise RuntimeError("start_video_thread not 'device' ins s['video']" )
self._video_width = s['video']['width']
self._video_height = s['video']['height']
self._video_running = True
self._video_width = s.video['width']
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'])
# dunno
if s['video']['device'] == -1:
self._video = screen_sharing.DesktopGrabber(s['video']['x'],
s['video']['y'],
s['video']['width'],
s['video']['height'])
else:
self._video = cv2.VideoCapture(self._settings.video['device'])
self._video.set(cv2.CAP_PROP_FPS, 25)
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_thread = threading.Thread(target=self.send_video)
self._video_running = True
self._video_thread = VideoThread(self,
name='_video_thread')
self._video_thread.start()
def stop_video_thread(self):
def stop_video_thread(self) -> None:
LOG_DEBUG(f"stop_video_thread {self._video_thread}")
if self._video_thread is None:
return
self._video_thread._stop_thread = True
self._video_running = False
self._video_thread.join()
i = 0
while i < ts.iTHREAD_JOINS:
self._video_thread.join(ts.iTHREAD_TIMEOUT)
try:
if not self._video_thread.is_alive(): break
except:
break
i = i + 1
else:
LOG.warn("self._video_thread.is_alive BLOCKED")
self._video_thread = None
self._video = None
# -----------------------------------------------------------------------------------------------------------------
# Incoming chunks
# -----------------------------------------------------------------------------------------------------------------
def audio_chunk(self, samples, channels_count, rate):
def audio_chunk(self, samples, channels_count, rate) -> None:
"""
Incoming chunk
"""
# from callback
if self._out_stream is None:
self._out_stream = self._audio.open(format=pyaudio.paInt16,
channels=channels_count,
rate=rate,
output_device_index=self._settings.audio['output'],
output=True)
self._out_stream.write(samples)
# was iOutput = self._settings._args.audio['output']
iOutput = self._settings['audio']['output']
if self.lPaSampleratesO and rate in self.lPaSampleratesO:
LOG_DEBUG(f"Using rate {rate} in self.lPaSampleratesO")
elif self.lPaSampleratesO:
LOG_WARN(f"{rate} not in {self.lPaSampleratesO}")
LOG_WARN(f"Setting audio_rate to: {self.lPaSampleratesO[0]}")
rate = self.lPaSampleratesO[0]
elif 'defaultSampleRate' in oPYA.get_device_info_by_index(iOutput):
rate = round(oPYA.get_device_info_by_index(iOutput)['defaultSampleRate'])
LOG_WARN(f"Setting rate to {rate} empty self.lPaSampleratesO")
else:
LOG_WARN(f"Using rate {rate} empty self.lPaSampleratesO")
if type(rate) == float:
rate = round(rate)
# test output device?
# [Errno -9985] Device unavailable
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 output_device_index={iOutput} {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']
#trace LOG_DEBUG(f"audio_chunk output_device_index={iOutput} rate={rate} channels={channels_count}")
try:
self._out_stream.write(samples)
except Exception as e:
# OSError: [Errno -9999] Unanticipated host error
LOG_WARN(f"audio_chunk output_device_index={iOutput} {e}")
# -----------------------------------------------------------------------------------------------------------------
# AV sending
# -----------------------------------------------------------------------------------------------------------------
def send_audio(self):
def send_audio_data(self, data, count, *largs, **kwargs) -> None:
# callback
pcm = data
# :param sampling_rate: Audio sampling rate used in this frame.
try:
if self._toxav is None:
LOG_ERROR("_toxav not initialized")
return
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:
# 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_data audio_send_frame: {e}")
LOG.debug(f"send_audio_data self._audio_rate_tox={self._audio_rate_tox} self._audio_channels={self._audio_channels}")
self.stop_audio_thread()
invoke_in_main_thread(util_ui.message_box,
str(e),
util_ui.tr("Error send_audio_data audio_send_frame"))
#? stop ? endcall?
def send_audio(self) -> None:
"""
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:
try:
pcm = self._audio_stream.read(self._audio_sample_count)
if pcm:
for friend_num in self._calls:
if self._calls[friend_num].out_audio:
try:
self._toxav.audio_send_frame(friend_num, pcm, self._audio_sample_count,
self._audio_channels, self._audio_rate)
except:
pass
pcm = self._audio_stream.read(count, exception_on_overflow=False)
if not pcm:
sleep(0.1)
else:
self.send_audio_data(pcm, count)
except:
pass
LOG_DEBUG(f"error send_audio {i}")
else:
LOG_TRACE(f"send_audio {i}")
i += 1
sleep(0.01)
time.sleep(0.01)
def send_video(self):
def send_video(self) -> None:
"""
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:
try:
result, frame = self._video.read()
if result:
height, width, channels = frame.shape
for friend_num in self._calls:
if self._calls[friend_num].out_video:
try:
y, u, v = self.convert_bgr_to_yuv(frame)
self._toxav.video_send_frame(friend_num, width, height, y, u, v)
except:
pass
except:
if not 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
LOG_TRACE(f"send_video video_send_frame _video.read result={result}")
height, width, channels = frame.shape
friends = []
for friend_num in self._calls:
if self._calls[friend_num].out_video:
friends.append(friend_num)
if len(friends) == 0:
LOG_WARN(f"send_video video_send_frame no friends")
else:
LOG_TRACE(f"send_video video_send_frame {friends}")
friend_num = friends[0]
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_WARN(f"send_video video_send_frame ERROR {e}")
pass
except Exception as e:
LOG_ERROR(f"send_video video_send_frame {e}")
pass
time.sleep(0.01)
sleep( 1.0/iFPS)
def convert_bgr_to_yuv(self, frame):
def convert_bgr_to_yuv(self, frame) -> tuple:
"""
:param frame: input bgr frame
:return y, u, v: y, u, v values of frame
@ -264,16 +566,20 @@ class AV(common.tox_save.ToxAvSave):
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
"""
with ts.ignoreStdout():
import cv2
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2YUV_I420)
y = frame[:self._video_height, :]
y = list(itertools.chain.from_iterable(y))
u = np.zeros((self._video_height // 2, self._video_width // 2), dtype=np.int)
import numpy as np
# was np.int
u = np.zeros((self._video_height // 2, self._video_width // 2), dtype=np.int32)
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 = list(itertools.chain.from_iterable(u))
v = np.zeros((self._video_height // 2, self._video_width // 2), dtype=np.int)
v = np.zeros((self._video_height // 2, self._video_width // 2), dtype=np.int32)
v[::2, :] = frame[self._video_height * 5 // 4:, :self._video_width // 2]
v[1::2, :] = frame[self._video_height * 5 // 4:, self._video_width // 2:]
v = list(itertools.chain.from_iterable(v))

View file

@ -1,29 +1,40 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
import sys
import threading
import cv2
import traceback
import logging
from qtpy import QtCore
import av.calls
from messenger.messages import *
from ui import av_widgets
import common.event as event
import utils.ui as util_ui
from toxygen_wrapper.tests import support_testing as ts
global LOG
LOG = logging.getLogger('app.'+__name__)
class CallsManager:
def __init__(self, toxav, settings, screen, contacts_manager):
self._call = av.calls.AV(toxav, settings) # object with data about calls
def __init__(self, toxav, settings, main_screen, contacts_manager, app=None):
self._callav = av.calls.AV(toxav, settings) # object with data about calls
self._call = self._callav
self._call_widgets = {} # dict of incoming call widgets
self._incoming_calls = set()
self._settings = settings
self._screen = screen
self._main_screen = main_screen
self._contacts_manager = contacts_manager
self._call_started_event = event.Event() # friend_number, audio, video, is_outgoing
self._call_finished_event = event.Event() # friend_number, is_declined
self._app = app
def set_toxav(self, toxav):
self._call.set_toxav(toxav)
def set_toxav(self, toxav) -> None:
self._callav.set_toxav(toxav)
# -----------------------------------------------------------------------------------------------------------------
# Events
# -----------------------------------------------------------------------------------------------------------------
def get_call_started_event(self):
return self._call_started_event
@ -35,35 +46,33 @@ class CallsManager:
call_finished_event = property(get_call_finished_event)
# -----------------------------------------------------------------------------------------------------------------
# AV support
# -----------------------------------------------------------------------------------------------------------------
def call_click(self, audio=True, video=False):
def call_click(self, audio=True, video=False) -> None:
"""User clicked audio button in main window"""
num = self._contacts_manager.get_active_number()
if not self._contacts_manager.is_active_a_friend():
return
if num not in self._call and self._contacts_manager.is_active_online(): # start call
if not self._settings.audio['enabled']:
if num not in self._callav and self._contacts_manager.is_active_online(): # start call
if not self._settings['audio']['enabled']:
return
self._call(num, audio, video)
self._screen.active_call()
self._callav(num, audio, video)
self._main_screen.active_call()
self._call_started_event(num, audio, video, True)
elif num in self._call: # finish or cancel call if you call with active friend
elif num in self._callav: # finish or cancel call if you call with active friend
self.stop_call(num, False)
def incoming_call(self, audio, video, friend_number):
def incoming_call(self, audio, video, friend_number) -> None:
"""
Incoming call from friend.
"""
if not self._settings.audio['enabled']:
return
LOG.debug(f"CM incoming_call {friend_number}")
# if not self._settings['audio']['enabled']: return
friend = self._contacts_manager.get_friend_by_number(friend_number)
self._call_started_event(friend_number, audio, video, False)
self._incoming_calls.add(friend_number)
if friend_number == self._contacts_manager.get_active_number():
self._screen.incoming_call()
self._main_screen.incoming_call()
else:
friend.actions = True
text = util_ui.tr("Incoming video call") if video else util_ui.tr("Incoming audio call")
@ -71,46 +80,105 @@ class CallsManager:
self._call_widgets[friend_number].set_pixmap(friend.get_pixmap())
self._call_widgets[friend_number].show()
def accept_call(self, friend_number, audio, video):
def accept_call(self, friend_number, audio, video) -> None:
"""
Accept incoming call with audio or video
Called from a thread
"""
self._call.accept_call(friend_number, audio, video)
self._screen.active_call()
if friend_number in self._incoming_calls:
self._incoming_calls.remove(friend_number)
del self._call_widgets[friend_number]
def stop_call(self, friend_number, by_friend):
LOG.debug(f"CM accept_call from friend_number={friend_number} {audio} {video}")
sys.stdout.flush()
try:
self._main_screen.active_call()
# failsafe added somewhere this was being left up
self.close_call(friend_number)
QtCore.QCoreApplication.processEvents()
self._callav.call_accept_call(friend_number, audio, video)
LOG.debug(f"accept_call _call.accept_call CALLED f={friend_number}")
except Exception as e:
#
LOG.error(f"accept_call _call.accept_call ERROR for {friend_number} {e}")
LOG.debug(traceback.print_exc())
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}")
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}")
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}'))
finally:
# does not terminate call - just the av_widget
LOG.debug(f"CM.accept_call close av_widget")
self.close_call(friend_number)
LOG.debug(f" closed self._call_widgets[{friend_number}]")
def close_call(self, friend_number:int) -> None:
# refactored out from above because the accept window not getting
# taken down in some accept audio calls
LOG.debug(f"close_call {friend_number}")
try:
if friend_number in self._call_widgets:
self._call_widgets[friend_number].close()
del self._call_widgets[friend_number]
if friend_number in self._incoming_calls:
self._incoming_calls.remove(friend_number)
except Exception as e:
# RuntimeError: wrapped C/C++ object of type IncomingCallWidget has been deleted
LOG.warn(f" closed self._call_widgets[{friend_number}] {e}")
# invoke_in_main_thread(QtCore.QCoreApplication.processEvents)
QtCore.QCoreApplication.processEvents()
def stop_call(self, friend_number, by_friend) -> None:
"""
Stop call with friend
"""
LOG.debug(f"CM.stop_call friend={friend_number}")
if friend_number in self._incoming_calls:
self._incoming_calls.remove(friend_number)
is_declined = True
else:
is_declined = False
self._screen.call_finished()
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:
self._call_widgets[friend_number].close()
del self._call_widgets[friend_number]
LOG.debug(f"CM.stop_call _call_widgets close")
self.close_call(friend_number)
def destroy_window():
if is_video:
LOG.debug(f"CM.stop_call _main_screen.call_finished")
self._main_screen.call_finished()
self._callav.finish_call(friend_number, by_friend) # finish or decline call
is_video = self._callav.is_video_call(friend_number)
if is_video:
def destroy_window():
#??? FixMe
with ts.ignoreStdout(): import cv2
cv2.destroyWindow(str(friend_number))
LOG.debug(f"CM.stop_call destroy_window")
threading.Timer(2.0, destroy_window).start()
threading.Timer(2.0, destroy_window).start()
LOG.debug(f"CM.stop_call _call_finished_event")
self._call_finished_event(friend_number, is_declined)
def friend_exit(self, friend_number):
if friend_number in self._call:
self._call.finish_call(friend_number, True)
def friend_exit(self, friend_number:int) -> None:
if friend_number in self._callav:
self._callav.finish_call(friend_number, True)
# -----------------------------------------------------------------------------------------------------------------
# Private methods
# -----------------------------------------------------------------------------------------------------------------
def _get_incoming_call_widget(self, friend_number, text, friend_name):
return av_widgets.IncomingCallWidget(self._settings, self, friend_number, text, friend_name)

View file

@ -1,6 +1,6 @@
import numpy as np
from PyQt5 import QtWidgets
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
from qtpy import QtWidgets
class DesktopGrabber:
@ -13,10 +13,11 @@ class DesktopGrabber:
self._height -= height % 4
self._screen = QtWidgets.QApplication.primaryScreen()
def read(self):
def read(self) -> tuple:
pixmap = self._screen.grabWindow(0, self._x, self._y, self._width, self._height)
image = pixmap.toImage()
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))
return True, arr

View file

@ -1,83 +1,48 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
import random
import urllib.request
import logging
from qtpy import QtCore
try:
import certifi
from io import BytesIO
except ImportError:
certifi = None
from user_data.settings import get_user_config_path
from utils.util import *
from PyQt5 import QtNetwork, QtCore
import json
from toxygen_wrapper.tests.support_testing import _get_nodes_path
from toxygen_wrapper.tests.support_http import download_url
import toxygen_wrapper.tests.support_testing as ts
DEFAULT_NODES_COUNT = 4
global LOG
LOG = logging.getLogger('app.'+'bootstrap')
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'
def download_nodes_list(settings, oArgs) -> str:
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
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):
def _save_nodes(nodes, app) -> None:
if not nodes:
return
print('Saving nodes...')
with open(_get_nodes_path(), 'wb') as fl:
with open(_get_nodes_path(app._args), 'wb') as fl:
LOG.info("Saving nodes to " +_get_nodes_path(app._args))
fl.write(nodes)

View file

@ -1,4 +1,4 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
class Event:

View file

@ -1,4 +1,4 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
class Provider:

View file

@ -1,4 +1,4 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
class ToxSave:

View file

@ -1,6 +1,7 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
from user_data.settings import *
from PyQt5 import QtCore, QtGui
from wrapper.toxcore_enums_and_consts import TOX_PUBLIC_KEY_SIZE
from qtpy import QtCore, QtGui
from toxygen_wrapper.toxcore_enums_and_consts import TOX_PUBLIC_KEY_SIZE
import utils.util as util
import common.event as event
import contacts.common as common
@ -14,26 +15,27 @@ class BaseContact:
Base class for all contacts.
"""
def __init__(self, profile_manager, name, status_message, widget, tox_id):
def __init__(self, profile_manager, name, status_message, widget, tox_id, kind=''):
"""
:param name: name, example: 'Toxygen user'
:param status_message: status message, example: 'Toxing on Toxygen'
:param widget: ContactItem instance
:param tox_id: tox id of contact
:param kind: one of ['bot', 'friend', 'group', 'invite', 'grouppeer', '']
"""
self._profile_manager = profile_manager
self._name, self._status_message = name, status_message
self._kind = kind
self._status, self._widget = None, widget
self._tox_id = tox_id
self._name_changed_event = event.Event()
self._status_message_changed_event = event.Event()
self._status_changed_event = event.Event()
self._avatar_changed_event = event.Event()
self.init_widget()
# -----------------------------------------------------------------------------------------------------------------
# Name - current name or alias of user
# -----------------------------------------------------------------------------------------------------------------
def get_name(self):
return self._name
@ -53,9 +55,7 @@ class BaseContact:
name_changed_event = property(get_name_changed_event)
# -----------------------------------------------------------------------------------------------------------------
# Status message
# -----------------------------------------------------------------------------------------------------------------
def get_status_message(self):
return self._status_message
@ -75,9 +75,7 @@ class BaseContact:
status_message_changed_event = property(get_status_message_changed_event)
# -----------------------------------------------------------------------------------------------------------------
# Status
# -----------------------------------------------------------------------------------------------------------------
def get_status(self):
return self._status
@ -96,30 +94,29 @@ class BaseContact:
status_changed_event = property(get_status_changed_event)
# -----------------------------------------------------------------------------------------------------------------
# TOX ID. WARNING: for friend it will return public key, for profile - full address
# -----------------------------------------------------------------------------------------------------------------
def get_tox_id(self):
return self._tox_id
tox_id = property(get_tox_id)
# -----------------------------------------------------------------------------------------------------------------
# Avatars
# -----------------------------------------------------------------------------------------------------------------
def load_avatar(self):
"""
Tries to load avatar of contact or uses default avatar
"""
avatar_path = self.get_avatar_path()
width = self._widget.avatar_label.width()
pixmap = QtGui.QPixmap(avatar_path)
self._widget.avatar_label.setPixmap(pixmap.scaled(width, width, QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation))
self._widget.avatar_label.repaint()
self._avatar_changed_event(avatar_path)
try:
avatar_path = self.get_avatar_path()
width = self._widget.avatar_label.width()
pixmap = QtGui.QPixmap(avatar_path)
self._widget.avatar_label.setPixmap(pixmap.scaled(width, width, QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation))
self._widget.avatar_label.repaint()
self._avatar_changed_event(avatar_path)
except Exception as e:
pass
def reset_avatar(self, generate_new):
avatar_path = self.get_avatar_path()
@ -161,19 +158,23 @@ class BaseContact:
avatar_changed_event = property(get_avatar_changed_event)
# -----------------------------------------------------------------------------------------------------------------
# Widgets
# -----------------------------------------------------------------------------------------------------------------
def init_widget(self):
# File "/mnt/o/var/local/src/toxygen/toxygen/contacts/contacts_manager.py", line 252, in filtration_and_sorting
# contact.set_widget(item_widget)
# File "/mnt/o/var/local/src/toxygen/toxygen/contacts/contact.py", line 320, in set_widget
if not self._widget:
LOG.warn("BC.init_widget self._widget is NULL")
return
self._widget.name.setText(self._name)
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.load_avatar()
# -----------------------------------------------------------------------------------------------------------------
# Private methods
# -----------------------------------------------------------------------------------------------------------------
@staticmethod
def _get_default_avatar_path():

View file

@ -1,10 +1,10 @@
from pydenticon import Generator
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
import hashlib
from pydenticon import Generator
# -----------------------------------------------------------------------------------------------------------------
# Typing notifications
# -----------------------------------------------------------------------------------------------------------------
class BaseTypingNotificationHandler:
@ -19,7 +19,7 @@ class BaseTypingNotificationHandler:
class FriendTypingNotificationHandler(BaseTypingNotificationHandler):
def __init__(self, friend_number):
def __init__(self, friend_number:int):
super().__init__()
self._friend_number = friend_number
@ -30,9 +30,7 @@ class FriendTypingNotificationHandler(BaseTypingNotificationHandler):
BaseTypingNotificationHandler.DEFAULT_HANDLER = BaseTypingNotificationHandler()
# -----------------------------------------------------------------------------------------------------------------
# Identicons support
# -----------------------------------------------------------------------------------------------------------------
def generate_avatar(public_key):

View file

@ -1,10 +1,17 @@
from history.database import *
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
from history.database import TIMEOUT, \
SAVE_MESSAGES, MESSAGE_AUTHOR
from contacts import basecontact, common
from messenger.messages import *
from contacts.contact_menu import *
from file_transfers import file_transfers as ft
import re
# LOG=util.log
global LOG
import logging
LOG = logging.getLogger('app.'+__name__)
class Contact(basecontact.BaseContact):
"""
@ -35,9 +42,7 @@ class Contact(basecontact.BaseContact):
if hasattr(self, '_message_getter'):
del self._message_getter
# -----------------------------------------------------------------------------------------------------------------
# History support
# -----------------------------------------------------------------------------------------------------------------
def load_corr(self, first_time=True):
"""
@ -114,9 +119,7 @@ class Contact(basecontact.BaseContact):
return TextMessage(message, author, unix_time, message_type, unique_id)
# -----------------------------------------------------------------------------------------------------------------
# Unsent messages
# -----------------------------------------------------------------------------------------------------------------
def get_unsent_messages(self):
"""
@ -129,8 +132,11 @@ class Contact(basecontact.BaseContact):
"""
:return list of unsent messages for saving
"""
messages = filter(lambda m: m.type in (MESSAGE_TYPE['TEXT'], MESSAGE_TYPE['ACTION'])
and m.author.type == MESSAGE_AUTHOR['NOT_SENT'], self._corr)
# and m.tox_message_id == tox_message_id,
messages = filter(lambda m: m.author is not None
and m.author.type == MESSAGE_AUTHOR['NOT_SENT'],
self._corr)
# was message = list(...)[0]
return list(messages)
def mark_as_sent(self, tox_message_id):
@ -139,11 +145,10 @@ class Contact(basecontact.BaseContact):
and m.tox_message_id == tox_message_id, self._corr))[0]
message.mark_as_sent()
except Exception as ex:
util.log('Mark as sent ex: ' + str(ex))
# wrapped C/C++ object of type QLabel has been deleted
LOG.error(f"Mark as sent: {ex}")
# -----------------------------------------------------------------------------------------------------------------
# Message deletion
# -----------------------------------------------------------------------------------------------------------------
def delete_message(self, message_id):
elem = list(filter(lambda m: m.message_id == message_id, self._corr))[0]
@ -189,9 +194,7 @@ class Contact(basecontact.BaseContact):
self._corr))
self._unsaved_messages = len(self.get_unsent_messages())
# -----------------------------------------------------------------------------------------------------------------
# Chat history search
# -----------------------------------------------------------------------------------------------------------------
def search_string(self, search_string):
self._search_string, self._search_index = search_string, 0
@ -224,9 +227,7 @@ class Contact(basecontact.BaseContact):
return i
return None # not found
# -----------------------------------------------------------------------------------------------------------------
# Current text - text from message area
# -----------------------------------------------------------------------------------------------------------------
def get_curr_text(self):
return self._curr_text
@ -236,9 +237,7 @@ class Contact(basecontact.BaseContact):
curr_text = property(get_curr_text, set_curr_text)
# -----------------------------------------------------------------------------------------------------------------
# Alias support
# -----------------------------------------------------------------------------------------------------------------
def set_name(self, value):
"""
@ -254,9 +253,7 @@ class Contact(basecontact.BaseContact):
def has_alias(self):
return self._alias
# -----------------------------------------------------------------------------------------------------------------
# Visibility in friends' list
# -----------------------------------------------------------------------------------------------------------------
def get_visibility(self):
return self._visible
@ -266,9 +263,7 @@ class Contact(basecontact.BaseContact):
visibility = property(get_visibility, set_visibility)
# -----------------------------------------------------------------------------------------------------------------
# Unread messages and other actions from friend
# -----------------------------------------------------------------------------------------------------------------
def get_actions(self):
return self._new_actions
@ -296,9 +291,7 @@ class Contact(basecontact.BaseContact):
messages = property(get_messages)
# -----------------------------------------------------------------------------------------------------------------
# Friend's or group's number (can be used in toxcore)
# -----------------------------------------------------------------------------------------------------------------
def get_number(self):
return self._number
@ -308,25 +301,19 @@ class Contact(basecontact.BaseContact):
number = property(get_number, set_number)
# -----------------------------------------------------------------------------------------------------------------
# Typing notifications
# -----------------------------------------------------------------------------------------------------------------
def get_typing_notification_handler(self):
return common.BaseTypingNotificationHandler.DEFAULT_HANDLER
typing_notification_handler = property(get_typing_notification_handler)
# -----------------------------------------------------------------------------------------------------------------
# Context menu support
# -----------------------------------------------------------------------------------------------------------------
def get_context_menu_generator(self):
return BaseContactMenuGenerator(self)
# -----------------------------------------------------------------------------------------------------------------
# Filtration support
# -----------------------------------------------------------------------------------------------------------------
def set_widget(self, widget):
self._widget = widget

View file

@ -1,10 +1,14 @@
from PyQt5 import QtWidgets
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
from qtpy import QtWidgets
import utils.ui as util_ui
from toxygen_wrapper.toxcore_enums_and_consts import *
global LOG
import logging
LOG = logging.getLogger('app')
# -----------------------------------------------------------------------------------------------------------------
# Builder
# -----------------------------------------------------------------------------------------------------------------
def _create_menu(menu_name, parent):
menu_name = menu_name or ''
@ -77,9 +81,7 @@ class ContactMenuBuilder:
self._actions[self._index] = (text, handler)
self._index += 1
# -----------------------------------------------------------------------------------------------------------------
# Generators
# -----------------------------------------------------------------------------------------------------------------
class BaseContactMenuGenerator:
@ -90,17 +92,15 @@ class BaseContactMenuGenerator:
def generate(self, plugin_loader, contacts_manager, main_screen, settings, number, groups_service, history_loader):
return ContactMenuBuilder().build()
# -----------------------------------------------------------------------------------------------------------------
# Private methods
# -----------------------------------------------------------------------------------------------------------------
def _generate_copy_menu_builder(self, main_screen):
copy_menu_builder = ContactMenuBuilder()
(copy_menu_builder
.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('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("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))
)
return copy_menu_builder
@ -108,11 +108,11 @@ class BaseContactMenuGenerator:
def _generate_history_menu_builder(self, history_loader, main_screen):
history_menu_builder = ContactMenuBuilder()
(history_menu_builder
.with_name(util_ui.tr('Chat history'))
.with_action(util_ui.tr('Clear history'), lambda: history_loader.clear_history(self._contact)
.with_name(util_ui.tr("Chat history"))
.with_action(util_ui.tr("Clear history"), lambda: history_loader.clear_history(self._contact)
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 HTML'), lambda: history_loader.export_history(self._contact, False))
.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))
)
return history_menu_builder
@ -127,16 +127,16 @@ class FriendMenuGenerator(BaseContactMenuGenerator):
groups_menu_builder = self._generate_groups_menu(contacts_manager, groups_service)
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()
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(copy_menu_builder)
.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('Block friend'), lambda: main_screen.block_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('Notes'), lambda: main_screen.show_note(self._contact))
.with_optional_submenu(plugins_menu_builder)
.with_optional_submenu(groups_menu_builder)
@ -144,9 +144,7 @@ class FriendMenuGenerator(BaseContactMenuGenerator):
return menu
# -----------------------------------------------------------------------------------------------------------------
# Private methods
# -----------------------------------------------------------------------------------------------------------------
@staticmethod
def _generate_plugins_menu_builder(plugin_loader, number):
@ -165,11 +163,13 @@ class FriendMenuGenerator(BaseContactMenuGenerator):
def _generate_groups_menu(self, contacts_manager, groups_service):
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:
return None
#? return None
pass
groups_menu_builder = ContactMenuBuilder()
(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])
)
@ -184,26 +184,26 @@ class GroupMenuGenerator(BaseContactMenuGenerator):
builder = ContactMenuBuilder()
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(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),
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),
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),
self._contact.is_self_moderator_or_founder())
.with_action(util_ui.tr('Bans list'),
lambda: groups_service.show_bans_list(self._contact))
.with_action(util_ui.tr('Reconnect to group'),
# .with_action(util_ui.tr("Bans list"),
# lambda: groups_service.show_bans_list(self._contact))
.with_action(util_ui.tr("Reconnect to group"),
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),
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))
).build()
@ -218,10 +218,10 @@ class GroupPeerMenuGenerator(BaseContactMenuGenerator):
builder = ContactMenuBuilder()
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(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))
.with_action(util_ui.tr('Notes'), lambda: main_screen.show_note(self._contact))
).build()

View file

@ -1,22 +1,32 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
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
from av.calls import LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG, LOG_TRACE
class ContactProvider(tox_save.ToxSave):
def __init__(self, tox, friend_factory, group_factory, group_peer_factory):
def __init__(self, tox, friend_factory, group_factory, group_peer_factory, app=None):
super().__init__(tox)
self._friend_factory = friend_factory
self._group_factory = group_factory
self._group_peer_factory = group_peer_factory
self._cache = {} # key - contact's public key, value - contact instance
self._app = app
# -----------------------------------------------------------------------------------------------------------------
# Friends
# -----------------------------------------------------------------------------------------------------------------
def get_friend_by_number(self, friend_number):
public_key = self._tox.friend_get_public_key(friend_number)
def get_friend_by_number(self, friend_number:int):
try:
public_key = self._tox.friend_get_public_key(friend_number)
except Exception as e:
LOG_WARN(f"CP.get_friend_by_number NO {friend_number} {e} ")
return None
return self.get_friend_by_public_key(public_key)
def get_friend_by_public_key(self, public_key):
@ -24,67 +34,118 @@ class ContactProvider(tox_save.ToxSave):
if friend is not None:
return friend
friend = self._friend_factory.create_friend_by_public_key(public_key)
self._add_to_cache(public_key, friend)
if friend is None:
LOG_WARN(f"CP.get_friend_by_public_key NULL {friend} ")
else:
self._add_to_cache(public_key, friend)
LOG_DEBUG(f"CP.get_friend_by_public_key ADDED {friend} ")
return friend
def get_all_friends(self):
friend_numbers = self._tox.self_get_friend_list()
def get_all_friends(self) -> list:
if self._app and self._app.bAppExiting:
return []
try:
friend_numbers = self._tox.self_get_friend_list()
except Exception as e:
LOG_WARN(f"CP.get_all_friends EXCEPTION {e} ")
return []
friends = map(lambda n: self.get_friend_by_number(n), friend_numbers)
return list(friends)
# -----------------------------------------------------------------------------------------------------------------
# Groups
# -----------------------------------------------------------------------------------------------------------------
def get_all_groups(self):
group_numbers = range(self._tox.group_get_number_groups())
groups = map(lambda n: self.get_group_by_number(n), group_numbers)
return list(groups)
"""from callbacks"""
try:
len_groups = self._tox.group_get_number_groups()
group_numbers = range(len_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"CP.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):
public_key = self._tox.group_get_chat_id(group_number)
group = None
try:
# LOG_DEBUG(f"CP.CP.group_get_number {group_number} ")
# original code
chat_id = self._tox.group_get_chat_id(group_number)
if chat_id is None:
LOG_ERROR(f"get_group_by_number NULL chat_id ({group_number})")
elif chat_id == '-1':
LOG_ERROR(f"get_group_by_number <0 chat_id ({group_number})")
else:
LOG_INFO(f"CP.group_get_number {group_number} {chat_id}")
group = self.get_group_by_chat_id(chat_id)
if group is None or group == '-1':
LOG_WARN(f"CP.get_group_by_number leaving {group} ({group_number})")
#? 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"CP.group_get_number {group_number} {e}")
return None
return self.get_group_by_public_key(public_key)
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):
group = self._get_contact_from_cache(public_key)
if group is not None:
return group
group = self._group_factory.create_group_by_public_key(public_key)
self._add_to_cache(public_key, group)
if group is None:
LOG_WARN(f"get_group_by_public_key NULL group public_key={public_key}")
else:
self._add_to_cache(public_key, group)
return group
# -----------------------------------------------------------------------------------------------------------------
# Group peers
# -----------------------------------------------------------------------------------------------------------------
def get_all_group_peers(self):
return list()
return []
def get_group_peer_by_id(self, group, peer_id):
peer = group.get_peer_by_id(peer_id)
return self._get_group_peer(group, peer)
if peer is not None:
return self._get_group_peer(group, peer)
LOG_WARN(f"get_group_peer_by_id peer_id={peer_id}")
return None
def get_group_peer_by_public_key(self, group, public_key):
peer = group.get_peer_by_public_key(public_key)
if peer is not None:
return self._get_group_peer(group, peer)
LOG_WARN(f"get_group_peer_by_public_key public_key={public_key}")
return None
return self._get_group_peer(group, peer)
# -----------------------------------------------------------------------------------------------------------------
# All contacts
# -----------------------------------------------------------------------------------------------------------------
def get_all(self):
return self.get_all_friends() + self.get_all_groups() + self.get_all_group_peers()
# -----------------------------------------------------------------------------------------------------------------
# Caching
# -----------------------------------------------------------------------------------------------------------------
def clear_cache(self):
self._cache.clear()
@ -93,9 +154,7 @@ class ContactProvider(tox_save.ToxSave):
if contact_public_key in self._cache:
del self._cache[contact_public_key]
# -----------------------------------------------------------------------------------------------------------------
# Private methods
# -----------------------------------------------------------------------------------------------------------------
def _get_contact_from_cache(self, public_key):
return self._cache[public_key] if public_key in self._cache else None

View file

@ -1,9 +1,36 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
import logging
from contacts.friend import Friend
from contacts.group_chat import GroupChat
from messenger.messages import *
from common.tox_save import ToxSave
from contacts.group_peer_contact import GroupPeerContact
from groups.group_peer import GroupChatPeer
from middleware.callbacks import LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG, LOG_TRACE
import toxygen_wrapper.toxcore_enums_and_consts as enums
# LOG=util.log
global LOG
LOG = logging.getLogger('app.'+__name__)
UINT32_MAX = 2 ** 32 -1
def set_contact_kind(contact) -> None:
bInvite = len(contact.name) == enums.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):
"""
@ -15,12 +42,14 @@ class ContactsManager(ToxSave):
super().__init__(tox)
self._settings = settings
self._screen = screen
self._ms = screen
self._profile_manager = profile_manager
self._contact_provider = contact_provider
self._tox_dns = tox_dns
self._messages_items_factory = messages_items_factory
self._messages = screen.messages
self._contacts, self._active_contact = [], -1
self._contacts = []
self._active_contact = -1
self._active_contact_changed = Event()
self._sorting = settings['sorting']
self._filter_string = ''
@ -28,6 +57,11 @@ class ContactsManager(ToxSave):
self._history = history
self._load_contacts()
def _log(self, s) -> None:
try:
self._ms._log(s)
except: pass
def get_contact(self, num):
if num < 0 or num >= len(self._contacts):
return None
@ -36,36 +70,46 @@ class ContactsManager(ToxSave):
def get_curr_contact(self):
return self._contacts[self._active_contact] if self._active_contact + 1 else None
def save_profile(self):
def save_profile(self) -> None:
data = self._tox.get_savedata()
self._profile_manager.save_profile(data)
def is_friend_active(self, friend_number):
def is_friend_active(self, friend_number:int) -> bool:
if not self.is_active_a_friend():
return False
return self.get_curr_contact().number == friend_number
def is_group_active(self, group_number):
def is_group_active(self, group_number) -> bool:
if self.is_active_a_friend():
return False
return self.get_curr_contact().number == group_number
def is_contact_active(self, contact):
def is_contact_active(self, contact) -> bool:
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
if not hasattr(contact, 'tox_id'):
LOG.warn(f"ERROR is_contact_active no contact.tox_id {type(contact)} contact={contact}")
return False
return self._contacts[self._active_contact].tox_id == contact.tox_id
# -----------------------------------------------------------------------------------------------------------------
# Reconnection support
# -----------------------------------------------------------------------------------------------------------------
def reset_contacts_statuses(self):
def reset_contacts_statuses(self) -> None:
for contact in self._contacts:
contact.status = None
# -----------------------------------------------------------------------------------------------------------------
# Work with active friend
# -----------------------------------------------------------------------------------------------------------------
def get_active(self):
return self._active_contact
@ -95,11 +139,16 @@ class ContactsManager(ToxSave):
current_contact.remove_messages_widgets() # TODO: if required
self._unsubscribe_from_events(current_contact)
if self._active_contact + 1 and self._active_contact != value:
if self._active_contact >= 0 and self._active_contact != value:
try:
current_contact.curr_text = self._screen.messageEdit.toPlainText()
except:
pass
# IndexError: list index out of range
if value >= len(self._contacts):
LOG.warn("CM.set_active value too big: {{self._contacts}}")
return
contact = self._contacts[value]
self._subscribe_to_events(contact)
contact.remove_invalid_unsent_files()
@ -128,10 +177,9 @@ class ContactsManager(ToxSave):
# self._screen.call_finished()
self._set_current_contact_data(contact)
self._active_contact_changed(contact)
except Exception as ex: # no friend found. ignore
util.log('Friend value: ' + str(value))
util.log('Error in set active: ' + str(ex))
raise
except Exception as e: # no friend found. ignore
LOG.warn(f"CM.set_active EXCEPTION value:{value} len={len(self._contacts)} {e}")
# gulp raise
active_contact = property(get_active, set_active)
@ -153,21 +201,23 @@ class ContactsManager(ToxSave):
def is_active_a_group_chat_peer(self):
return type(self.get_curr_contact()) is GroupPeerContact
# -----------------------------------------------------------------------------------------------------------------
# Filtration
# -----------------------------------------------------------------------------------------------------------------
def filtration_and_sorting(self, sorting=0, filter_str=''):
"""
Filtration of friends list
: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
4 - online and by name, 5 - online first and by name, 6 kind
:param filter_str: show contacts which name contains this substring
"""
filter_str = filter_str.lower()
current_contact = self.get_curr_contact()
if sorting > 5 or sorting < 0:
for index, contact in enumerate(self._contacts):
if not contact._kind:
set_contact_kind(contact)
if sorting > 6 or sorting < 0:
sorting = 0
if sorting in (1, 2, 4, 5): # online first
@ -183,18 +233,30 @@ class ContactsManager(ToxSave):
part2 = sorted(part2, key=key_lambda)
self._contacts = part1 + part2
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)
friends = filter(lambda c: type(c) is Friend, contacts)
groups = filter(lambda c: type(c) is GroupChat, contacts)
group_peers = filter(lambda c: type(c) is GroupPeerContact, contacts)
self._contacts = list(friends) + list(groups) + list(group_peers)
elif sorting == 6:
self._contacts = sorted(self._contacts, key=lambda x: x._kind)
else:
self._contacts = sorted(self._contacts, key=lambda x: x.name.lower())
# change item widgets
for index, contact in enumerate(self._contacts):
list_item = self._screen.friends_list.item(index)
item_widget = self._screen.friends_list.itemWidget(list_item)
if not item_widget:
LOG_WARN("CM.filtration_and_sorting( item_widget is NULL")
continue
contact.set_widget(item_widget)
for index, friend in enumerate(self._contacts):
@ -222,9 +284,7 @@ class ContactsManager(ToxSave):
"""
self.filtration_and_sorting(self._sorting, self._filter_string)
# -----------------------------------------------------------------------------------------------------------------
# Contact getters
# -----------------------------------------------------------------------------------------------------------------
def get_friend_by_number(self, number):
return list(filter(lambda c: c.number == number and type(c) is Friend, self._contacts))[0]
@ -235,9 +295,15 @@ class ContactsManager(ToxSave):
def get_or_create_group_peer_contact(self, group_number, peer_id):
group = self.get_group_by_number(group_number)
peer = group.get_peer_by_id(peer_id)
if peer is None:
LOG.warn(f'get_or_create_group_peer_contact group_number={group_number} peer_id={peer_id} peer={peer}')
return None
LOG.debug(f'get_or_create_group_peer_contact group_number={group_number} peer_id={peer_id} peer={peer}')
if not self.check_if_contact_exists(peer.public_key):
self.add_group_peer(group, peer)
contact = self.add_group_peer(group, peer)
# dunno
return contact
# me - later wrong kind of object?
return self.get_contact_by_tox_id(peer.public_key)
def check_if_contact_exists(self, tox_id):
@ -255,9 +321,7 @@ class ContactsManager(ToxSave):
def is_active_online(self):
return self._active_contact + 1 and self.get_curr_contact().status is not None
# -----------------------------------------------------------------------------------------------------------------
# Work with friends (remove, block, set alias, get public key)
# -----------------------------------------------------------------------------------------------------------------
def set_alias(self, num):
"""
@ -299,7 +363,10 @@ class ContactsManager(ToxSave):
"""
friend = self._contacts[num]
self._cleanup_contact_data(friend)
self._tox.friend_delete(friend.number)
try:
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)
def add_friend(self, tox_id):
@ -314,8 +381,8 @@ class ContactsManager(ToxSave):
"""
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]
if tox_id == self._tox.self_get_address[:TOX_PUBLIC_KEY_SIZE * 2]:
tox_id = tox_id[:enums.TOX_PUBLIC_KEY_SIZE * 2]
if tox_id == self._tox.self_get_address()[:enums.TOX_PUBLIC_KEY_SIZE * 2]:
return
if tox_id not in self._settings['blocked']:
self._settings['blocked'].append(tox_id)
@ -339,21 +406,27 @@ class ContactsManager(ToxSave):
self.add_friend(tox_id)
self.save_profile()
# -----------------------------------------------------------------------------------------------------------------
# Groups support
# -----------------------------------------------------------------------------------------------------------------
def get_group_chats(self):
return list(filter(lambda c: type(c) is GroupChat, self._contacts))
def add_group(self, group_number):
group = self._contact_provider.get_group_by_number(group_number)
index = len(self._contacts)
self._contacts.append(group)
group.reset_avatar(self._settings['identicons'])
self._save_profile()
self.set_active(index)
self.update_filtration()
group = self._contact_provider.get_group_by_number(group_number)
if group is None:
LOG.warn(f"CM.add_group: NULL group from group_number={group_number}")
elif type(group) == int and group < 0:
LOG.warn(f"CM.add_group: NO group from group={group} group_number={group_number}")
else:
LOG.info(f"CM.add_group: Adding group {group._name}")
self._contacts.append(group)
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):
group = self.get_group_by_number(group_number)
@ -361,30 +434,32 @@ class ContactsManager(ToxSave):
num = self._contacts.index(group)
self._delete_contact(num)
# -----------------------------------------------------------------------------------------------------------------
# Groups private messaging
# -----------------------------------------------------------------------------------------------------------------
def add_group_peer(self, group, peer):
contact = self._contact_provider.get_group_peer_by_id(group, peer.id)
if self.check_if_contact_exists(contact.tox_id):
return
return contact
contact._kind = 'grouppeer'
self._contacts.append(contact)
contact.reset_avatar(self._settings['identicons'])
self._save_profile()
return contact
def remove_group_peer_by_id(self, group, peer_id):
peer = group.get_peer_by_id(peer_id)
if not self.check_if_contact_exists(peer.public_key):
return
contact = self.get_contact_by_tox_id(peer.public_key)
self.remove_group_peer(contact)
if peer: # broken
if not self.check_if_contact_exists(peer.public_key):
return
contact = self.get_contact_by_tox_id(peer.public_key)
self.remove_group_peer(contact)
def remove_group_peer(self, group_peer_contact):
contact = self.get_contact_by_tox_id(group_peer_contact.tox_id)
self._cleanup_contact_data(contact)
num = self._contacts.index(contact)
self._delete_contact(num)
if contact:
self._cleanup_contact_data(contact)
num = self._contacts.index(contact)
self._delete_contact(num)
def get_gc_peer_name(self, name):
group = self.get_curr_contact()
@ -402,38 +477,48 @@ class ContactsManager(ToxSave):
return suggested_names[0]
# -----------------------------------------------------------------------------------------------------------------
# Friend requests
# -----------------------------------------------------------------------------------------------------------------
def send_friend_request(self, tox_id, message):
def send_friend_request(self, sToxPkOrId, message):
"""
Function tries to send request to contact with specified id
:param tox_id: id of new contact or tox dns 4 value
:param sToxPkOrId: id of new contact or tox dns 4 value
:param message: additional message
:return: True on success else error string
"""
retval = ''
try:
message = message or 'Hello! Add me to your contact list please'
if '@' in tox_id: # value like groupbot@toxme.io
tox_id = self._tox_dns.lookup(tox_id)
if tox_id is None:
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)
if len(sToxPkOrId) == enums.TOX_PUBLIC_KEY_SIZE * 2: # public key
self.add_friend(sToxPkOrId)
title = 'Friend added'
text = 'Friend added without sending friend request'
else:
self._tox.friend_add(tox_id, message.encode('utf-8'))
tox_id = tox_id[:TOX_PUBLIC_KEY_SIZE * 2]
self._add_friend(tox_id)
self.update_filtration()
self.save_profile()
return True
num = self._tox.friend_add(sToxPkOrId, message.encode('utf-8'))
if num < UINT32_MAX:
tox_pk = sToxPkOrId[:enums.TOX_PUBLIC_KEY_SIZE * 2]
self._add_friend(tox_pk)
self.update_filtration()
title = 'Friend added'
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
util.log('Friend request failed with ' + str(ex))
return str(ex)
title = 'Friend add exception'
text = 'Friend request exception with ' + 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):
"""
@ -451,14 +536,12 @@ class ContactsManager(ToxSave):
data = self._tox.get_savedata()
self._profile_manager.save_profile(data)
except Exception as ex: # something is wrong
util.log('Accept friend request failed! ' + str(ex))
LOG.error('Accept friend request failed! ' + str(ex))
def can_send_typing_notification(self):
return self._settings['typing_notifications'] and not self.is_active_a_group_chat_peer()
# -----------------------------------------------------------------------------------------------------------------
# Contacts numbers update
# -----------------------------------------------------------------------------------------------------------------
def update_friends_numbers(self):
for friend in self._contact_provider.get_all_friends():
@ -467,9 +550,17 @@ class ContactsManager(ToxSave):
def update_groups_numbers(self):
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)):
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)
if not group:
LOG.warn(f"update_groups_numbers {i} group")
continue
group.number = i
self.update_filtration()
@ -478,16 +569,22 @@ class ContactsManager(ToxSave):
for group in groups:
group.remove_all_peers_except_self()
# -----------------------------------------------------------------------------------------------------------------
# Private methods
# -----------------------------------------------------------------------------------------------------------------
def _load_contacts(self):
self._load_friends()
self._load_groups()
if len(self._contacts):
self.set_active(0)
for contact in filter(lambda c: not c.has_avatar(), self._contacts):
# 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'])
self.update_filtration()
@ -497,9 +594,7 @@ class ContactsManager(ToxSave):
def _load_groups(self):
self._contacts.extend(self._contact_provider.get_all_groups())
# -----------------------------------------------------------------------------------------------------------------
# Current contact subscriptions
# -----------------------------------------------------------------------------------------------------------------
def _subscribe_to_events(self, contact):
contact.name_changed_event.add_callback(self._current_contact_name_changed)
@ -554,7 +649,7 @@ class ContactsManager(ToxSave):
try:
index = list(map(lambda x: x[0], self._settings['friends_aliases'])).index(contact.tox_id)
del self._settings['friends_aliases'][index]
except:
except Exception as e:
pass
if contact.tox_id in self._settings['notes']:
del self._settings['notes'][contact.tox_id]

View file

@ -1,9 +1,11 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
import os
from contacts import contact, common
from messenger.messages import *
import os
from contacts.contact_menu import *
class Friend(contact.Contact):
"""
Friend in list of friends.
@ -14,9 +16,7 @@ class Friend(contact.Contact):
self._receipts = 0
self._typing_notification_handler = common.FriendTypingNotificationHandler(number)
# -----------------------------------------------------------------------------------------------------------------
# File transfers support
# -----------------------------------------------------------------------------------------------------------------
def insert_inline(self, before_message_id, inline):
"""
@ -29,7 +29,7 @@ class Friend(contact.Contact):
self._corr.insert(i, inline)
return i - len(self._corr)
except:
pass
return -1
def get_unsent_files(self):
messages = filter(lambda m: type(m) is UnsentFileMessage, self._corr)
@ -52,23 +52,17 @@ class Friend(contact.Contact):
self._corr = list(filter(lambda m: not (type(m) is UnsentFileMessage and m.message_id == message_id),
self._corr))
# -----------------------------------------------------------------------------------------------------------------
# Full status
# -----------------------------------------------------------------------------------------------------------------
def get_full_status(self):
return self._status_message
# -----------------------------------------------------------------------------------------------------------------
# Typing notifications
# -----------------------------------------------------------------------------------------------------------------
def get_typing_notification_handler(self):
return self._typing_notification_handler
# -----------------------------------------------------------------------------------------------------------------
# Context menu support
# -----------------------------------------------------------------------------------------------------------------
def get_context_menu_generator(self):
return FriendMenuGenerator(self)

View file

@ -1,7 +1,8 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
from contacts.friend import Friend
from common.tox_save import ToxSave
class FriendFactory(ToxSave):
def __init__(self, profile_manager, settings, tox, db, items_factory):
@ -13,28 +14,26 @@ class FriendFactory(ToxSave):
def create_friend_by_public_key(self, public_key):
friend_number = self._tox.friend_by_public_key(public_key)
return self.create_friend_by_number(friend_number)
def create_friend_by_number(self, friend_number):
def create_friend_by_number(self, friend_number:int):
aliases = self._settings['friends_aliases']
tox_id = self._tox.friend_get_public_key(friend_number)
sToxPk = self._tox.friend_get_public_key(friend_number)
assert sToxPk, sToxPk
try:
alias = list(filter(lambda x: x[0] == tox_id, aliases))[0][1]
alias = list(filter(lambda x: x[0] == sToxPk, aliases))[0][1]
except:
alias = ''
item = self._create_friend_item()
name = alias or self._tox.friend_get_name(friend_number) or tox_id
name = alias or self._tox.friend_get_name(friend_number) or sToxPk
status_message = self._tox.friend_get_status_message(friend_number)
message_getter = self._db.messages_getter(tox_id)
friend = Friend(self._profile_manager, message_getter, friend_number, name, status_message, item, tox_id)
message_getter = self._db.messages_getter(sToxPk)
friend = Friend(self._profile_manager, message_getter, friend_number, name, status_message, item, sToxPk)
friend.set_alias(alias)
return friend
# -----------------------------------------------------------------------------------------------------------------
# Private methods
# -----------------------------------------------------------------------------------------------------------------
def _create_friend_item(self):
"""

View file

@ -1,11 +1,17 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
from contacts import contact
from contacts.contact_menu import GroupMenuGenerator
import utils.util as util
from groups.group_peer import GroupChatPeer
from wrapper import toxcore_enums_and_consts as constants
from toxygen_wrapper import toxcore_enums_and_consts as constants
from common.tox_save import ToxSave
from groups.group_ban import GroupBan
global LOG
import logging
LOG = logging.getLogger(__name__)
from av.calls import LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG, LOG_TRACE
class GroupChat(contact.Contact, ToxSave):
@ -25,9 +31,7 @@ class GroupChat(contact.Contact, ToxSave):
def get_context_menu_generator(self):
return GroupMenuGenerator(self)
# -----------------------------------------------------------------------------------------------------------------
# Properties
# -----------------------------------------------------------------------------------------------------------------
def get_is_private(self):
return self._is_private
@ -53,9 +57,7 @@ class GroupChat(contact.Contact, ToxSave):
peers_limit = property(get_peers_limit, set_peers_limit)
# -----------------------------------------------------------------------------------------------------------------
# Peers methods
# -----------------------------------------------------------------------------------------------------------------
def get_self_peer(self):
return self._peers[0]
@ -73,12 +75,20 @@ class GroupChat(contact.Contact, ToxSave):
return self.get_self_role() == constants.TOX_GROUP_ROLE['FOUNDER']
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
status_message = f"Private in {self.name}"
LOG_TRACE(f"GC.add_peer id={peer_id} status_message={status_message}")
peer = GroupChatPeer(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_role(self._number, peer_id),
self._tox.group_peer_get_public_key(self._number, peer_id),
is_current_user)
is_current_user,
status_message=status_message)
self._peers.append(peer)
def remove_peer(self, peer_id):
@ -86,25 +96,40 @@ class GroupChat(contact.Contact, ToxSave):
self.remove_all_peers_except_self()
else:
peer = self.get_peer_by_id(peer_id)
self._peers.remove(peer)
if peer: # broken
self._peers.remove(peer)
else:
LOG_WARN(f"remove_peer empty peers for {peer_id}")
def get_peer_by_id(self, peer_id):
peers = list(filter(lambda p: p.id == peer_id, self._peers))
return peers[0]
if peers:
return peers[0]
else:
LOG_WARN(f"get_peer_by_id empty peers for {peer_id}")
return None
def get_peer_by_public_key(self, public_key):
peers = list(filter(lambda p: p.public_key == public_key, self._peers))
return peers[0]
# DEBUGc: group_moderation #0 mod_id=4294967295 event_type=3
# WARN_: get_peer_by_id empty peers for 4294967295
if peers:
return peers[0]
else:
LOG_WARN(f"get_peer_by_public_key empty peers for {public_key}")
return None
def remove_all_peers_except_self(self):
self._peers = self._peers[:1]
def get_peers_names(self):
peers_names = map(lambda p: p.name, self._peers)
return list(peers_names)
if peers_names: # broken
return list(peers_names)
else:
LOG_WARN(f"get_peers_names empty peers")
#? broken
return []
def get_peers(self):
return self._peers[:]
@ -112,21 +137,20 @@ class GroupChat(contact.Contact, ToxSave):
peers = property(get_peers)
def get_bans(self):
ban_ids = self._tox.group_ban_get_list(self._number)
bans = []
for ban_id in ban_ids:
ban = GroupBan(ban_id,
self._tox.group_ban_get_target(self._number, ban_id),
self._tox.group_ban_get_time_set(self._number, ban_id))
bans.append(ban)
return bans
return []
# ban_ids = self._tox.group_ban_get_list(self._number)
# bans = []
# for ban_id in ban_ids:
# ban = GroupBan(ban_id,
# self._tox.group_ban_get_target(self._number, ban_id),
# self._tox.group_ban_get_time_set(self._number, ban_id))
# bans.append(ban)
#
# return bans
#
bans = property(get_bans)
# -----------------------------------------------------------------------------------------------------------------
# Private methods
# -----------------------------------------------------------------------------------------------------------------
@staticmethod
def _get_default_avatar_path():

View file

@ -1,7 +1,12 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
from contacts.group_chat import GroupChat
from common.tox_save import ToxSave
import wrapper.toxcore_enums_and_consts as constants
import toxygen_wrapper.toxcore_enums_and_consts as constants
global LOG
import logging
LOG = logging.getLogger(__name__)
class GroupFactory(ToxSave):
@ -12,12 +17,15 @@ class GroupFactory(ToxSave):
self._db = db
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):
group_number = self._get_group_number_by_chat_id(public_key)
return self.create_group_by_number(group_number)
def create_group_by_number(self, group_number):
LOG.info(f"create_group_by_number {group_number}")
aliases = self._settings['friends_aliases']
tox_id = self._tox.group_get_chat_id(group_number)
try:
@ -35,9 +43,7 @@ class GroupFactory(ToxSave):
return group
# -----------------------------------------------------------------------------------------------------------------
# Private methods
# -----------------------------------------------------------------------------------------------------------------
def _create_group_item(self):
"""
@ -47,7 +53,7 @@ class GroupFactory(ToxSave):
return self._items_factory.create_contact_item()
def _get_group_number_by_chat_id(self, chat_id):
for i in range(self._tox.group_get_number_groups()):
for i in range(self._tox.group_get_number_groups()+100):
if self._tox.group_get_chat_id(i) == chat_id:
return i
return -1

View file

@ -1,11 +1,13 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
import contacts.contact
from contacts.contact_menu import GroupPeerMenuGenerator
class GroupPeerContact(contacts.contact.Contact):
def __init__(self, profile_manager, message_getter, peer_number, name, widget, tox_id, group_pk):
super().__init__(profile_manager, message_getter, peer_number, name, str(), widget, tox_id)
def __init__(self, profile_manager, message_getter, peer_number, name, widget, tox_id, group_pk, status_message=None):
if status_message is None: status_message=str()
super().__init__(profile_manager, message_getter, peer_number, name, status_message, widget, tox_id)
self._group_pk = group_pk
def get_group_pk(self):

View file

@ -1,7 +1,7 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
from common.tox_save import ToxSave
from contacts.group_peer_contact import GroupPeerContact
class GroupPeerFactory(ToxSave):
def __init__(self, tox, profile_manager, db, items_factory):
@ -14,7 +14,10 @@ class GroupPeerFactory(ToxSave):
item = self._create_group_peer_item()
message_getter = self._db.messages_getter(peer.public_key)
group_peer_contact = GroupPeerContact(self._profile_manager, message_getter, peer.id, peer.name,
item, peer.public_key, group.tox_id)
item,
peer.public_key,
group.tox_id,
status_message=peer.status_message)
group_peer_contact.status = peer.status
return group_peer_contact

View file

@ -1,19 +1,27 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
from contacts import basecontact
import random
import threading
import common.tox_save as tox_save
from middleware.threads import invoke_in_main_thread
iUMAXINT = 4294967295
iRECONNECT = 50
global LOG
import logging
LOG = logging.getLogger('app.'+__name__)
class Profile(basecontact.BaseContact, tox_save.ToxSave):
"""
Profile of current toxygen user.
"""
def __init__(self, profile_manager, tox, screen, contacts_provider, reset_action):
def __init__(self, profile_manager, tox, screen, contacts_provider, reset_action, app=None):
"""
:param tox: tox instance
:param screen: ref to main screen
"""
assert tox
basecontact.BaseContact.__init__(self,
profile_manager,
tox.self_get_name(),
@ -27,61 +35,73 @@ class Profile(basecontact.BaseContact, tox_save.ToxSave):
self._reset_action = reset_action
self._waiting_for_reconnection = False
self._timer = None
self._app = app
# -----------------------------------------------------------------------------------------------------------------
# Edit current user's data
# -----------------------------------------------------------------------------------------------------------------
def change_status(self):
def change_status(self) -> None:
"""
Changes status of user (online, away, busy)
"""
if self._status is not None:
self.set_status((self._status + 1) % 3)
def set_status(self, status):
def set_status(self, status) -> None:
super().set_status(status)
if status is not None:
self._tox.self_set_status(status)
elif not self._waiting_for_reconnection:
self._waiting_for_reconnection = True
self._timer = threading.Timer(50, self._reconnect)
self._timer = threading.Timer(iRECONNECT, self._reconnect)
self._timer.start()
def set_name(self, value):
def set_name(self, value) -> None:
if self.name == value:
return
super().set_name(value)
self._tox.self_set_name(self._name)
def set_status_message(self, value):
def set_status_message(self, value) -> None:
super().set_status_message(value)
self._tox.self_set_status_message(self._status_message)
def set_new_nospam(self):
"""Sets new nospam part of tox id"""
self._tox.self_set_nospam(random.randint(0, 4294967295)) # no spam - uint32
self._tox.self_set_nospam(random.randint(0, iUMAXINT)) # no spam - uint32
self._tox_id = self._tox.self_get_address()
self._sToxId = self._tox.self_get_address()
return self._sToxId
return self._tox_id
# -----------------------------------------------------------------------------------------------------------------
# Reset
# -----------------------------------------------------------------------------------------------------------------
def restart(self):
def restart(self) -> None:
"""
Recreate tox instance
"""
self.status = None
invoke_in_main_thread(self._reset_action)
def _reconnect(self):
def _reconnect(self) -> None:
self._waiting_for_reconnection = False
if self._app and self._app.bAppExiting:
# dont do anything after the app has been shipped
# there's a segv that results
return
contacts = self._contacts_provider.get_all_friends()
all_friends_offline = all(list(map(lambda x: x.status is None, contacts)))
if self.status is None or (all_friends_offline and len(contacts)):
self._waiting_for_reconnection = True
self.restart()
self._timer = threading.Timer(50, self._reconnect)
self._timer = threading.Timer(iRECONNECT, self._reconnect)
self._timer.start()
# Current thread 0x00007901a13ccb80 (most recent call first):
# File "/usr/local/lib/python3.11/site-packages/toxygen_wrapper/tox.py", line 826 in self_get_friend_list_size
# File "/usr/local/lib/python3.11/site-packages/toxygen_wrapper/tox.py", line 838 in self_get_friend_list
# File "/mnt/o/var/local/src/toxygen/toxygen/contacts/contact_provider.py", line 45 in get_all_friends
# File "/mnt/o/var/local/src/toxygen/toxygen/contacts/profile.py", line 90 in _reconnect
# File "/usr/lib/python3.11/threading.py", line 1401 in run
# File "/usr/lib/python3.11/threading.py", line 1045 in _bootstrap_inner
# File "/usr/lib/python3.11/threading.py", line 1002 in _bootstrap
#

View file

@ -1,11 +1,15 @@
from wrapper.toxcore_enums_and_consts import TOX_FILE_KIND, TOX_FILE_CONTROL
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
import os
from os import chdir, remove, rename
from os.path import basename, getsize, exists, dirname
from os import remove, rename, chdir
from time import time
from wrapper.tox import Tox
from common.event import Event
from middleware.threads import invoke_in_main_thread
from toxygen_wrapper.tox import Tox
from toxygen_wrapper.toxcore_enums_and_consts import TOX_FILE_KIND, TOX_FILE_CONTROL
from middleware.callbacks import LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG, LOG_TRACE
FILE_TRANSFER_STATE = {
'RUNNING': 0,
@ -78,6 +82,7 @@ class FileTransfer:
def get_file_id(self):
return self._file_id
#? return self._tox.file_get_file_id(self._friend_number, self._file_number)
file_id = property(get_file_id)
@ -112,9 +117,6 @@ class FileTransfer:
if self._tox.file_control(self._friend_number, self._file_number, control):
self.set_state(control)
def get_file_id(self):
return self._tox.file_get_file_id(self._friend_number, self._file_number)
def _signal(self):
percentage = self._done / self._size if self._size else 0
if self._creation_time is None or not percentage:
@ -126,9 +128,7 @@ class FileTransfer:
def _finished(self):
self._finished_event(self._friend_number, self._file_number)
# -----------------------------------------------------------------------------------------------------------------
# Send file
# -----------------------------------------------------------------------------------------------------------------
class SendTransfer(FileTransfer):
@ -174,11 +174,14 @@ class SendAvatar(SendTransfer):
"""
def __init__(self, path, tox, friend_number):
if path is None:
LOG_DEBUG(f"SendAvatar path={path} friend_number={friend_number}")
if path is None or not os.path.exists(path):
avatar_hash = None
else:
with open(path, 'rb') as fl:
avatar_hash = Tox.hash(fl.read())
data=fl.read()
LOG_DEBUG(f"SendAvatar data={data} type={type(data)}")
avatar_hash = tox.hash(data, None)
super().__init__(path, tox, friend_number, TOX_FILE_KIND['AVATAR'], avatar_hash)
@ -220,12 +223,10 @@ class SendFromFileBuffer(SendTransfer):
def send_chunk(self, position, size):
super().send_chunk(position, size)
if not size:
chdir(dirname(self._path))
remove(self._path)
os.chdir(dirname(self._path))
os.remove(self._path)
# -----------------------------------------------------------------------------------------------------------------
# Receive file
# -----------------------------------------------------------------------------------------------------------------
class ReceiveTransfer(FileTransfer):
@ -315,7 +316,6 @@ class ReceiveAvatar(ReceiveTransfer):
Get friend's avatar. Doesn't need file transfer item
"""
MAX_AVATAR_SIZE = 512 * 1024
def __init__(self, path, tox, friend_number, size, file_number):
full_path = path + '.tmp'
super().__init__(full_path, tox, friend_number, size, file_number)
@ -328,11 +328,11 @@ class ReceiveAvatar(ReceiveTransfer):
self._file.close()
remove(full_path)
elif exists(path):
hash = self.get_file_id()
ihash = self.get_file_id()
with open(path, 'rb') as fl:
data = fl.read()
existing_hash = Tox.hash(data)
if hash == existing_hash:
if ihash == existing_hash:
self.send_control(TOX_FILE_CONTROL['CANCEL'])
self._file.close()
remove(full_path)

View file

@ -1,11 +1,22 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
import logging
from messenger.messages import *
from file_transfers.file_transfers import SendAvatar, is_inline
from ui.contact_items import *
import utils.util as util
from common.tox_save import ToxSave
from middleware.callbacks import LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG, LOG_TRACE
# LOG=util.log
global LOG
LOG = logging.getLogger('app.'+__name__)
log = lambda x: LOG.info(x)
class FileTransfersHandler(ToxSave):
lBlockAvatars = []
def __init__(self, tox, settings, contact_provider, file_transfers_message_service, profile):
super().__init__(tox)
self._settings = settings
@ -19,16 +30,16 @@ class FileTransfersHandler(ToxSave):
# key = (friend number, file number), value - message id
profile.avatar_changed_event.add_callback(self._send_avatar_to_contacts)
def stop(self):
self. lBlockAvatars = []
def stop(self) -> None:
self._settings['paused_file_transfers'] = self._paused_file_transfers if self._settings['resend_files'] else {}
self._settings.save()
# -----------------------------------------------------------------------------------------------------------------
# File transfers support
# -----------------------------------------------------------------------------------------------------------------
def incoming_file_transfer(self, friend_number, file_number, size, file_name):
def incoming_file_transfer(self, friend_number, file_number, size, file_name) -> None:
# main thread
"""
New transfer
:param friend_number: number of friend who sent file
@ -37,11 +48,15 @@ class FileTransfersHandler(ToxSave):
:param file_name: file name without path
"""
friend = self._get_friend_by_number(friend_number)
if friend is None:
LOG.info(f'incoming_file_handler Friend NULL friend_number={friend_number}')
return
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 = False # ?is_inline(file_name) and self._settings['allow_inline']
file_id = self._tox.file_get_file_id(friend_number, file_number)
accepted = True
if file_id in self._paused_file_transfers:
LOG_INFO(f'incoming_file_handler paused friend_number={friend_number}')
(path, ft_friend_number, is_incoming, start_position) = self._paused_file_transfers[file_id]
pos = start_position if os.path.exists(path) else 0
if pos >= size:
@ -52,26 +67,33 @@ class FileTransfersHandler(ToxSave):
friend, accepted, size, file_name, file_number)
self.accept_transfer(path, friend_number, file_number, size, False, pos)
elif inline and size < 1024 * 1024:
LOG_INFO(f'incoming_file_handler small friend_number={friend_number}')
self._file_transfers_message_service.add_incoming_transfer_message(
friend, accepted, size, file_name, file_number)
self.accept_transfer('', friend_number, file_number, size, True)
elif auto:
# accepted is really started
LOG_INFO(f'incoming_file_handler auto friend_number={friend_number}')
path = self._settings['auto_accept_path'] or util.curr_directory()
self._file_transfers_message_service.add_incoming_transfer_message(
friend, accepted, size, file_name, file_number)
self.accept_transfer(path + '/' + file_name, friend_number, file_number, size)
else:
LOG_INFO(f'incoming_file_handler reject friend_number={friend_number}')
accepted = False
# FixME: need GUI ask
# accepted is really started
self._file_transfers_message_service.add_incoming_transfer_message(
friend, accepted, size, file_name, file_number)
def cancel_transfer(self, friend_number, file_number, already_cancelled=False):
def cancel_transfer(self, friend_number, file_number, already_cancelled=False) -> None:
"""
Stop transfer
:param friend_number: number of friend
:param file_number: file number
:param already_cancelled: was cancelled by friend
"""
# callback
if (friend_number, file_number) in self._file_transfers:
tr = self._file_transfers[(friend_number, file_number)]
if not already_cancelled:
@ -84,17 +106,19 @@ class FileTransfersHandler(ToxSave):
elif not already_cancelled:
self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['CANCEL'])
def cancel_not_started_transfer(self, friend_number, message_id):
self._get_friend_by_number(friend_number).delete_one_unsent_file(message_id)
def cancel_not_started_transfer(self, friend_number, message_id) -> None:
friend = self._get_friend_by_number(friend_number)
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) -> None:
"""
Pause transfer with specified data
"""
tr = self._file_transfers[(friend_number, file_number)]
tr.pause(by_friend)
def resume_transfer(self, friend_number, file_number, by_friend=False):
def resume_transfer(self, friend_number, file_number, by_friend=False) -> None:
"""
Resume transfer with specified data
"""
@ -104,7 +128,7 @@ class FileTransfersHandler(ToxSave):
else:
tr.send_control(TOX_FILE_CONTROL['RESUME'])
def accept_transfer(self, path, friend_number, file_number, size, inline=False, from_position=0):
def accept_transfer(self, path, friend_number, file_number, size, inline=False, from_position=0) -> None:
"""
:param path: path for saving
:param friend_number: friend number
@ -115,6 +139,7 @@ class FileTransfersHandler(ToxSave):
"""
path = self._generate_valid_path(path, from_position)
friend = self._get_friend_by_number(friend_number)
if friend is None: return None
if not inline:
rt = ReceiveTransfer(path, self._tox, friend_number, size, file_number, from_position)
else:
@ -130,7 +155,7 @@ class FileTransfersHandler(ToxSave):
if inline:
self._insert_inline_before[(friend_number, file_number)] = message.message_id
def send_screenshot(self, data, friend_number):
def send_screenshot(self, data, friend_number) -> None:
"""
Send screenshot
:param data: raw data - png format
@ -138,22 +163,26 @@ class FileTransfersHandler(ToxSave):
"""
self.send_inline(data, 'toxygen_inline.png', friend_number)
def send_sticker(self, path, friend_number):
def send_sticker(self, path, friend_number) -> None:
with open(path, 'rb') as fl:
data = fl.read()
self.send_inline(data, 'sticker.png', friend_number)
def send_inline(self, data, file_name, friend_number, is_resend=False):
def send_inline(self, data, file_name, friend_number, is_resend=False) -> None:
friend = self._get_friend_by_number(friend_number)
if friend is None:
LOG_WARN("fsend_inline Error friend is None file_name: {file_name}")
return
if friend.status is None and not is_resend:
self._file_transfers_message_service.add_unsent_file_message(friend, file_name, data)
return
elif friend.status is None and is_resend:
raise RuntimeError()
LOG_WARN("fsend_inline Error friend.status is None file_name: {file_name}")
return
st = SendFromBuffer(self._tox, friend.number, data, file_name)
self._send_file_add_set_handlers(st, friend, file_name, True)
def send_file(self, path, friend_number, is_resend=False, file_id=None):
def send_file(self, path, friend_number, is_resend=False, file_id=None) -> None:
"""
Send file to current active friend
:param path: file path
@ -162,47 +191,52 @@ class FileTransfersHandler(ToxSave):
:param file_id: file id of transfer
"""
friend = self._get_friend_by_number(friend_number)
if friend is None: return None
if friend.status is None and not is_resend:
self._file_transfers_message_service.add_unsent_file_message(friend, path, None)
return
elif friend.status is None and is_resend:
print('Error in sending')
LOG_WARN('Error in sending')
return
st = SendTransfer(path, self._tox, friend_number, TOX_FILE_KIND['DATA'], file_id)
file_name = os.path.basename(path)
self._send_file_add_set_handlers(st, friend, file_name)
def incoming_chunk(self, friend_number, file_number, position, data):
def incoming_chunk(self, friend_number, file_number, position, data) -> None:
"""
Incoming chunk
"""
self._file_transfers[(friend_number, file_number)].write_chunk(position, data)
def outgoing_chunk(self, friend_number, file_number, position, size):
def outgoing_chunk(self, friend_number, file_number, position, size) -> None:
"""
Outgoing chunk
"""
self._file_transfers[(friend_number, file_number)].send_chunk(position, size)
def transfer_finished(self, friend_number, file_number):
def transfer_finished(self, friend_number, file_number) -> None:
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)
if t is ReceiveAvatar:
self._get_friend_by_number(friend_number).load_avatar()
friend.load_avatar()
elif t is ReceiveToBuffer or (t is SendFromBuffer and self._settings['allow_inline']): # inline image
print('inline')
LOG.debug('inline')
inline = InlineImageMessage(transfer.data)
message_id = self._insert_inline_before[(friend_number, file_number)]
del self._insert_inline_before[(friend_number, file_number)]
index = self._get_friend_by_number(friend_number).insert_inline(message_id, inline)
if friend is None: return None
index = friend.insert_inline(message_id, inline)
self._file_transfers_message_service.add_inline_message(transfer, index)
del self._file_transfers[(friend_number, file_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()
def send_files(self, friend_number:int) -> None:
try:
friend = self._get_friend_by_number(friend_number)
if friend is None: return
friend.remove_invalid_unsent_files()
files = friend.get_unsent_files()
for fl in files:
data, path = fl.data, fl.path
if data is not None:
@ -211,6 +245,7 @@ class FileTransfersHandler(ToxSave):
self.send_file(path, friend_number, True)
friend.clear_unsent_files()
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]
if not os.path.exists(path):
del self._paused_file_transfers[key]
@ -218,32 +253,63 @@ class FileTransfersHandler(ToxSave):
self.send_file(path, friend_number, True, key)
del self._paused_file_transfers[key]
except Exception as ex:
print('Exception in file sending: ' + str(ex))
LOG_ERROR('send_files EXCEPTION in file sending: ' + str(ex))
def friend_exit(self, friend_number):
for friend_num, file_num in self._file_transfers.keys():
def friend_exit(self, friend_number:int) -> None:
# RuntimeError: dictionary changed size during iteration
lMayChangeDynamically = self._file_transfers.copy()
for friend_num, file_num in lMayChangeDynamically:
if friend_num != friend_number:
continue
if (friend_num, file_num) not in self._file_transfers:
continue
ft = self._file_transfers[(friend_num, file_num)]
if type(ft) is SendTransfer:
self._paused_file_transfers[ft.file_id] = [ft.path, friend_num, False, -1]
try:
file_id = ft.file_id
except Exception as e:
LOG_WARN("friend_exit SendTransfer Error getting file_id: {e}")
# drop through
else:
self._paused_file_transfers[file_id] = [ft.path, friend_num, False, -1]
elif type(ft) is ReceiveTransfer and ft.state != FILE_TRANSFER_STATE['INCOMING_NOT_STARTED']:
self._paused_file_transfers[ft.file_id] = [ft.path, friend_num, True, ft.total_size()]
try:
file_id = ft.file_id
except Exception as e:
LOG_WARN("friend_exit ReceiveTransfer Error getting file_id: {e}")
# drop through
else:
self._paused_file_transfers[file_id] = [ft.path, friend_num, True, ft.total_size()]
self.cancel_transfer(friend_num, file_num, True)
# -----------------------------------------------------------------------------------------------------------------
# Avatars support
# -----------------------------------------------------------------------------------------------------------------
def send_avatar(self, friend_number, avatar_path=None):
def send_avatar(self, friend_number, avatar_path=None) -> None:
"""
:param friend_number: number of friend who should get new avatar
:param avatar_path: path to avatar or None if reset
"""
sa = SendAvatar(avatar_path, self._tox, friend_number)
self._file_transfers[(friend_number, sa.file_number)] = sa
return
if (avatar_path, friend_number,) in self.lBlockAvatars:
return
if friend_number is None:
LOG_WARN(f"send_avatar friend_number NULL {friend_number}")
return
if avatar_path and type(avatar_path) != str:
LOG_WARN(f"send_avatar avatar_path type {type(avatar_path)}")
return
LOG_INFO(f"send_avatar avatar_path={avatar_path} friend_number={friend_number}")
try:
# self NOT missing - who's self?
sa = SendAvatar(avatar_path, self._tox, friend_number)
LOG_INFO(f"send_avatar avatar_path={avatar_path} sa={sa}")
self._file_transfers[(friend_number, sa.file_number)] = sa
except Exception as e:
# ArgumentError('This client is currently not connected to the friend.')
LOG_WARN(f"send_avatar EXCEPTION {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) -> None:
"""
Friend changed avatar
:param friend_number: friend number
@ -251,6 +317,7 @@ class FileTransfersHandler(ToxSave):
:param size: size of avatar or 0 (default avatar)
"""
friend = self._get_friend_by_number(friend_number)
if friend is None: return
ra = ReceiveAvatar(friend.get_contact_avatar_path(), self._tox, friend_number, size, file_number)
if ra.state != FILE_TRANSFER_STATE['CANCELLED']:
self._file_transfers[(friend_number, file_number)] = ra
@ -258,21 +325,21 @@ class FileTransfersHandler(ToxSave):
elif not size:
friend.reset_avatar(self._settings['identicons'])
def _send_avatar_to_contacts(self, _):
def _send_avatar_to_contacts(self, _) -> None:
# from a callback
friends = self._get_all_friends()
for friend in filter(self._is_friend_online, friends):
self.send_avatar(friend.number)
# -----------------------------------------------------------------------------------------------------------------
# Private methods
# -----------------------------------------------------------------------------------------------------------------
def _is_friend_online(self, friend_number):
def _is_friend_online(self, friend_number:int) -> bool:
friend = self._get_friend_by_number(friend_number)
if friend is None: return None
return friend.status is not None
def _get_friend_by_number(self, friend_number):
def _get_friend_by_number(self, friend_number:int):
return self._contact_provider.get_friend_by_number(friend_number)
def _get_all_friends(self):

View file

@ -1,7 +1,15 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
import logging
from messenger.messenger import *
import utils.util as util
from file_transfers.file_transfers import *
global LOG
LOG = logging.getLogger('app.'+__name__)
from av.calls import LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG, LOG_TRACE
class FileTransfersMessagesService:
@ -12,7 +20,9 @@ class FileTransfersMessagesService:
self._messages = main_screen.messages
def add_incoming_transfer_message(self, friend, accepted, size, file_name, file_number):
assert friend
author = MessageAuthor(friend.name, MESSAGE_AUTHOR['FRIEND'])
# accepted is really 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)
@ -27,6 +37,7 @@ class FileTransfersMessagesService:
return tm
def add_outgoing_transfer_message(self, friend, size, file_name, file_number):
assert friend
author = MessageAuthor(self._profile.name, MESSAGE_AUTHOR['ME'])
status = FILE_TRANSFER_STATE['OUTGOING_NOT_STARTED']
tm = TransferMessage(author, util.get_unix_time(), status, size, file_name, friend.number, file_number)
@ -39,14 +50,21 @@ class FileTransfersMessagesService:
return tm
def add_inline_message(self, transfer, index):
def add_inline_message(self, transfer, index) -> None:
"""callback"""
if not self._is_friend_active(transfer.friend_number):
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()
if count + index + 1 >= 0:
self._create_inline_item(transfer.data, count + index + 1)
# assumes .data
self._create_inline_item(transfer, count + index + 1)
def add_unsent_file_message(self, friend, file_path, data):
assert friend
author = MessageAuthor(self._profile.name, MESSAGE_AUTHOR['ME'])
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)
@ -58,11 +76,9 @@ class FileTransfersMessagesService:
return tm
# -----------------------------------------------------------------------------------------------------------------
# Private methods
# -----------------------------------------------------------------------------------------------------------------
def _is_friend_active(self, friend_number):
def _is_friend_active(self, friend_number:int) -> bool:
if not self._contacts_manager.is_active_a_friend():
return False

View file

@ -1,4 +1,4 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
class GroupBan:

View file

@ -1,4 +1,4 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
class GroupInvite:

View file

@ -1,22 +1,22 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
class GroupChatPeer:
"""
Represents peer in group chat.
"""
def __init__(self, peer_id, name, status, role, public_key, is_current_user=False, is_muted=False):
def __init__(self, peer_id, name, status, role, public_key, is_current_user=False, is_muted=False, status_message=None):
self._peer_id = peer_id
self._name = name
self._status = status
self._status_message = status_message
self._role = role
self._public_key = public_key
self._is_current_user = is_current_user
self._is_muted = is_muted
self._kind = 'grouppeer'
# -----------------------------------------------------------------------------------------------------------------
# Readonly properties
# -----------------------------------------------------------------------------------------------------------------
def get_id(self):
return self._peer_id
@ -33,9 +33,12 @@ class GroupChatPeer:
is_current_user = property(get_is_current_user)
# -----------------------------------------------------------------------------------------------------------------
def get_status_message(self):
return self._status_message
status_message = property(get_status_message)
# Read-write properties
# -----------------------------------------------------------------------------------------------------------------
def get_name(self):
return self._name

View file

@ -1,9 +1,16 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
import logging
import common.tox_save as tox_save
import utils.ui as util_ui
from groups.peers_list import PeersListGenerator
from groups.group_invite import GroupInvite
import wrapper.toxcore_enums_and_consts as constants
import toxygen_wrapper.toxcore_enums_and_consts as constants
from toxygen_wrapper.toxcore_enums_and_consts import *
from toxygen_wrapper.tox import UINT32_MAX
global LOG
LOG = logging.getLogger('app.'+'gs')
class GroupsService(tox_save.ToxSave):
@ -16,18 +23,22 @@ class GroupsService(tox_save.ToxSave):
self._widgets_factory_provider = widgets_factory_provider
self._group_invites = []
self._screen = None
# maybe just use self
self._tox = tox
def set_tox(self, tox):
def set_tox(self, tox) -> None:
super().set_tox(tox)
for group in self._get_all_groups():
group.set_tox(tox)
# -----------------------------------------------------------------------------------------------------------------
# Groups creation
# -----------------------------------------------------------------------------------------------------------------
def create_new_gc(self, name, privacy_state, nick, status):
group_number = self._tox.group_new(privacy_state, name, nick, status)
def create_new_gc(self, name, privacy_state, nick, status) -> None:
try:
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:
return
@ -36,51 +47,82 @@ class GroupsService(tox_save.ToxSave):
group.status = constants.TOX_USER_STATUS['NONE']
self._contacts_manager.update_filtration()
def join_gc_by_id(self, chat_id, password, nick, status):
group_number = self._tox.group_join(chat_id, password, nick, status)
def join_gc_by_id(self, chat_id, password, nick, status) -> None:
try:
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)
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
# -----------------------------------------------------------------------------------------------------------------
def leave_group(self, group_number):
self._tox.group_leave(group_number)
self._contacts_manager.delete_group(group_number)
def leave_group(self, group_number) -> None:
if type(group_number) == int:
self._tox.group_leave(group_number)
self._contacts_manager.delete_group(group_number)
def disconnect_from_group(self, group_number):
def disconnect_from_group(self, group_number) -> None:
self._tox.group_disconnect(group_number)
group = self._get_group_by_number(group_number)
group.status = None
self._clear_peers_list(group)
def reconnect_to_group(self, group_number):
def reconnect_to_group(self, group_number) -> None:
self._tox.group_reconnect(group_number)
group = self._get_group_by_number(group_number)
group.status = constants.TOX_USER_STATUS['NONE']
self._clear_peers_list(group)
# -----------------------------------------------------------------------------------------------------------------
# Group invites
# -----------------------------------------------------------------------------------------------------------------
def invite_friend(self, friend_number, group_number):
self._tox.group_invite_friend(group_number, friend_number)
def invite_friend(self, friend_number, group_number) -> None:
if self._tox.friend_get_connection_status(friend_number) == TOX_CONNECTION['NONE']:
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
def process_group_invite(self, friend_number, group_name, invite_data):
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) -> None:
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)
self._group_invites.append(invite)
self._update_invites_button_state()
def accept_group_invite(self, invite, name, status, password):
def accept_group_invite(self, invite, name, status, password) -> None:
pk = invite.friend_public_key
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._delete_group_invite(invite)
self._update_invites_button_state()
def decline_group_invite(self, invite):
def decline_group_invite(self, invite) -> None:
self._delete_group_invite(invite)
self._main_screen.update_gc_invites_button_state()
@ -94,15 +136,13 @@ class GroupsService(tox_save.ToxSave):
group_invites_count = property(get_group_invites_count)
# -----------------------------------------------------------------------------------------------------------------
# Group info methods
# -----------------------------------------------------------------------------------------------------------------
def update_group_info(self, group):
group.name = self._tox.group_get_name(group.number)
group.status_message = self._tox.group_get_topic(group.number)
def set_group_topic(self, group):
def set_group_topic(self, group) -> None:
if not group.is_self_moderator_or_founder():
return
text = util_ui.tr('New topic for group "{}":'.format(group.name))
@ -113,46 +153,44 @@ class GroupsService(tox_save.ToxSave):
self._tox.group_set_topic(group.number, topic)
group.status_message = topic
def show_group_management_screen(self, group):
def show_group_management_screen(self, group) -> None:
widgets_factory = self._get_widgets_factory()
self._screen = widgets_factory.create_group_management_screen(group)
self._screen.show()
def show_group_settings_screen(self, group):
def show_group_settings_screen(self, group) -> None:
widgets_factory = self._get_widgets_factory()
self._screen = widgets_factory.create_group_settings_screen(group)
self._screen.show()
def set_group_password(self, group, password):
def set_group_password(self, group, password) -> None:
if group.password == password:
return
self._tox.group_founder_set_password(group.number, password)
group.password = password
def set_group_peers_limit(self, group, peers_limit):
def set_group_peers_limit(self, group, peers_limit) -> None:
if group.peers_limit == peers_limit:
return
self._tox.group_founder_set_peer_limit(group.number, peers_limit)
group.peers_limit = peers_limit
def set_group_privacy_state(self, group, privacy_state):
def set_group_privacy_state(self, group, privacy_state) -> None:
is_private = privacy_state == constants.TOX_GROUP_PRIVACY_STATE['PRIVATE']
if group.is_private == is_private:
return
self._tox.group_founder_set_privacy_state(group.number, privacy_state)
group.is_private = is_private
# -----------------------------------------------------------------------------------------------------------------
# Peers list
# -----------------------------------------------------------------------------------------------------------------
def generate_peers_list(self):
def generate_peers_list(self) -> None:
if not self._contacts_manager.is_active_a_group():
return
group = self._contacts_manager.get_curr_contact()
PeersListGenerator().generate(group.peers, self, self._peers_list_widget, group.tox_id)
def peer_selected(self, chat_id, peer_id):
def peer_selected(self, chat_id, peer_id) -> None:
widgets_factory = self._get_widgets_factory()
group = self._get_group_by_public_key(chat_id)
self_peer = group.get_self_peer()
@ -162,20 +200,18 @@ class GroupsService(tox_save.ToxSave):
self._screen = widgets_factory.create_self_peer_screen_window(group)
self._screen.show()
# -----------------------------------------------------------------------------------------------------------------
# Peers actions
# -----------------------------------------------------------------------------------------------------------------
def set_new_peer_role(self, group, peer, role):
def set_new_peer_role(self, group, peer, role) -> None:
self._tox.group_mod_set_role(group.number, peer.id, role)
peer.role = role
self.generate_peers_list()
def toggle_ignore_peer(self, group, peer, ignore):
def toggle_ignore_peer(self, group, peer, ignore) -> None:
self._tox.group_toggle_ignore(group.number, peer.id, ignore)
peer.is_muted = ignore
def set_self_info(self, group, name, status):
def set_self_info(self, group, name, status) -> None:
self._tox.group_self_set_name(group.number, name)
self._tox.group_self_set_status(group.number, status)
self_peer = group.get_self_peer()
@ -183,29 +219,27 @@ class GroupsService(tox_save.ToxSave):
self_peer.status = status
self.generate_peers_list()
# -----------------------------------------------------------------------------------------------------------------
# Bans support
# -----------------------------------------------------------------------------------------------------------------
def show_bans_list(self, group):
def show_bans_list(self, group) -> None:
return
widgets_factory = self._get_widgets_factory()
self._screen = widgets_factory.create_groups_bans_screen(group)
self._screen.show()
def ban_peer(self, group, peer_id, ban_type):
def ban_peer(self, group, peer_id, ban_type) -> None:
self._tox.group_mod_ban_peer(group.number, peer_id, ban_type)
def kick_peer(self, group, peer_id):
def kick_peer(self, group, peer_id) -> None:
self._tox.group_mod_remove_peer(group.number, peer_id)
def cancel_ban(self, group_number, ban_id):
def cancel_ban(self, group_number, ban_id) -> None:
self._tox.group_mod_remove_ban(group_number, ban_id)
# -----------------------------------------------------------------------------------------------------------------
# Private methods
# -----------------------------------------------------------------------------------------------------------------
def _add_new_group_by_number(self, group_number):
def _add_new_group_by_number(self, group_number) -> None:
LOG.debug(f"_add_new_group_by_number group_number={group_number}")
self._contacts_manager.add_group(group_number)
def _get_group_by_number(self, group_number):
@ -217,26 +251,41 @@ class GroupsService(tox_save.ToxSave):
def _get_all_groups(self):
return self._contacts_provider.get_all_groups()
def _get_friend_by_number(self, friend_number):
def _get_friend_by_number(self, friend_number:int):
return self._contacts_provider.get_friend_by_number(friend_number)
def _get_friend_by_public_key(self, public_key):
return self._contacts_provider.get_friend_by_public_key(public_key)
def _clear_peers_list(self, group):
def _clear_peers_list(self, group) -> None:
group.remove_all_peers_except_self()
self.generate_peers_list()
def _delete_group_invite(self, invite):
def _delete_group_invite(self, invite) -> None:
if invite in self._group_invites:
self._group_invites.remove(invite)
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)
self._add_new_group_by_number(group_number)
# status should be dropped
def _join_gc_via_invite(self, invite_data, friend_number, nick, status='', password='') -> None:
LOG.debug(f"_join_gc_via_invite friend_number={friend_number} nick={nick} datalen={len(invite_data)}")
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) -> None:
self._main_screen.update_gc_invites_button_state()
def _get_widgets_factory(self):
def _get_widgets_factory(self) -> None:
return self._widgets_factory_provider.get_item()

View file

@ -1,11 +1,10 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
from ui.group_peers_list import PeerItem, PeerTypeItem
from wrapper.toxcore_enums_and_consts import *
from toxygen_wrapper.toxcore_enums_and_consts import *
from ui.widgets import *
# -----------------------------------------------------------------------------------------------------------------
# Builder
# -----------------------------------------------------------------------------------------------------------------
class PeerListBuilder:
@ -63,9 +62,7 @@ class PeerListBuilder:
self._peers[self._index] = peer
self._index += 1
# -----------------------------------------------------------------------------------------------------------------
# Generators
# -----------------------------------------------------------------------------------------------------------------
class PeersListGenerator:

View file

@ -1,19 +1,20 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
from sqlite3 import connect
import os.path
import utils.util as util
global LOG
import logging
LOG = logging.getLogger('h.database')
TIMEOUT = 11
SAVE_MESSAGES = 500
MESSAGE_AUTHOR = {
'ME': 0,
'FRIEND': 1,
'NOT_SENT': 2,
'GC_PEER': 3
}
CONTACT_TYPE = {
'FRIEND': 0,
'GC_PEER': 1,
@ -24,23 +25,33 @@ CONTACT_TYPE = {
class Database:
def __init__(self, path, toxes):
self._path, self._toxes = path, toxes
self._path = path
self._toxes = toxes
self._name = os.path.basename(path)
if os.path.exists(path):
try:
with open(path, 'rb') as fin:
data = fin.read()
if toxes.is_data_encrypted(data):
data = toxes.pass_decrypt(data)
with open(path, 'wb') as fout:
fout.write(data)
except Exception as ex:
util.log('Db reading error: ' + str(ex))
os.remove(path)
# -----------------------------------------------------------------------------------------------------------------
def open(self):
path = self._path
toxes = self._toxes
if not os.path.exists(path):
LOG.warn('Db not found: ' +path)
return
try:
with open(path, 'rb') as fin:
data = fin.read()
except Exception as ex:
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
# -----------------------------------------------------------------------------------------------------------------
def save(self):
if self._toxes.has_password():
@ -58,6 +69,7 @@ class Database:
data = self._toxes.pass_encrypt(data)
with open(new_path, 'wb') as fout:
fout.write(data)
LOG.info('Db exported: ' +new_path)
def add_friend_to_db(self, tox_id):
db = self._connect()
@ -72,11 +84,14 @@ class Database:
' message_type INTEGER'
')')
db.commit()
except:
print('Database is locked!')
return True
except Exception as e:
LOG.error("dd_friend_to_db " +self._name +f" Database exception! {e}")
db.rollback()
return False
finally:
db.close()
LOG.debug(f"add_friend_to_db {tox_id}")
def delete_friend_from_db(self, tox_id):
db = self._connect()
@ -84,11 +99,14 @@ class Database:
cursor = db.cursor()
cursor.execute('DROP TABLE id' + tox_id + ';')
db.commit()
except:
print('Database is locked!')
return True
except Exception as e:
LOG.error("delete_friend_from_db " +self._name +f" Database exception! {e}")
db.rollback()
return False
finally:
db.close()
LOG.debug(f"delete_friend_from_db {tox_id}")
def save_messages_to_db(self, tox_id, messages_iter):
db = self._connect()
@ -96,13 +114,16 @@ class Database:
cursor = db.cursor()
cursor.executemany('INSERT INTO id' + tox_id +
'(message, author_name, author_type, unix_time, message_type) ' +
'VALUES (?, ?, ?, ?, ?, ?);', messages_iter)
'VALUES (?, ?, ?, ?, ?);', messages_iter)
db.commit()
except:
print('Database is locked!')
return True
except Exception as e:
LOG.error("save_messages_to_db" +self._name +f" Database exception! {e}")
db.rollback()
return False
finally:
db.close()
LOG.debug(f"save_messages_to_db {tox_id}")
def update_messages(self, tox_id, message_id):
db = self._connect()
@ -111,11 +132,14 @@ class Database:
cursor.execute('UPDATE id' + tox_id + ' SET author = 0 '
'WHERE id = ' + str(message_id) + ' AND author = 2;')
db.commit()
except:
print('Database is locked!')
return True
except Exception as e:
LOG.error("update_messages" +self._name +f" Database exception! {e}")
db.rollback()
return False
finally:
db.close()
LOG.debug(f"update_messages {tox_id}")
def delete_message(self, tox_id, unique_id):
db = self._connect()
@ -123,11 +147,14 @@ class Database:
cursor = db.cursor()
cursor.execute('DELETE FROM id' + tox_id + ' WHERE id = ' + str(unique_id) + ';')
db.commit()
except:
print('Database is locked!')
return True
except Exception as e:
LOG.error("delete_message" +self._name +f" Database exception! {e}")
db.rollback()
return False
finally:
db.close()
LOG.debug(f"delete_message {tox_id}")
def delete_messages(self, tox_id):
db = self._connect()
@ -135,20 +162,21 @@ class Database:
cursor = db.cursor()
cursor.execute('DELETE FROM id' + tox_id + ';')
db.commit()
except:
print('Database is locked!')
return True
except Exception as e:
LOG.error("delete_messages" +self._name +f" Database exception! {e}")
db.rollback()
return False
finally:
db.close()
LOG.debug(f"delete_messages {tox_id}")
def messages_getter(self, tox_id):
self.add_friend_to_db(tox_id)
return Database.MessageGetter(self._path, tox_id)
# -----------------------------------------------------------------------------------------------------------------
# Messages loading
# -----------------------------------------------------------------------------------------------------------------
class MessageGetter:
@ -193,9 +221,7 @@ class Database:
def _disconnect(self):
self._db.close()
# -----------------------------------------------------------------------------------------------------------------
# Private methods
# -----------------------------------------------------------------------------------------------------------------
def _connect(self):
return connect(self._path, timeout=TIMEOUT)

View file

@ -1,5 +1,9 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
from history.history_logs_generators import *
global LOG
import logging
LOG = logging.getLogger('app.db')
class History:
@ -11,22 +15,21 @@ class History:
self._messages_items_factory = messages_items_factory
self._is_loading = False
self._contacts_manager = None
def __del__(self):
del self._db
def set_contacts_manager(self, contacts_manager):
self._contacts_manager = contacts_manager
# -----------------------------------------------------------------------------------------------------------------
# History support
# -----------------------------------------------------------------------------------------------------------------
def save_history(self):
"""
Save history to db
"""
if self._settings['save_db']:
# me a mistake? was _db not _history
if self._settings['save_history']:
for friend in self._contact_provider.get_all_friends():
self._db.add_friend_to_db(friend.tox_id)
if not self._settings['save_unsent_only']:
@ -57,8 +60,10 @@ class History:
file_name += '.' + extension
history = self.generate_history(contact, as_text)
assert history
with open(file_name, 'wt') as fl:
fl.write(history)
LOG.info(f"wrote history to {file_name}")
def delete_message(self, message):
contact = self._contacts_manager.get_curr_contact()
@ -121,9 +126,7 @@ class History:
return generator.generate()
# -----------------------------------------------------------------------------------------------------------------
# Items creation
# -----------------------------------------------------------------------------------------------------------------
def _create_message_item(self, message):
return self._messages_items_factory.create_message_item(message, False)

View file

@ -1,5 +1,7 @@
from messenger.messages import *
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
import utils.util as util
from messenger.messages import *
class HistoryLogsGenerator:

BIN
toxygen/images/accept.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 114 KiB

After

Width:  |  Height:  |  Size: 116 KiB

BIN
toxygen/images/accept_audio.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

BIN
toxygen/images/accept_video.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 12 KiB

BIN
toxygen/images/avatar.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 329 B

After

Width:  |  Height:  |  Size: 433 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 609 B

After

Width:  |  Height:  |  Size: 556 B

BIN
toxygen/images/call.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 816 B

BIN
toxygen/images/call_video.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
toxygen/images/decline.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 118 KiB

After

Width:  |  Height:  |  Size: 119 KiB

BIN
toxygen/images/decline_call.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 10 KiB

BIN
toxygen/images/file.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
toxygen/images/finish_call.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 816 B

BIN
toxygen/images/finish_call_video.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3 KiB

After

Width:  |  Height:  |  Size: 461 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 11 KiB

BIN
toxygen/images/icon.xcf Normal file

Binary file not shown.

BIN
toxygen/images/icon_new_messages.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 911 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 231 B

After

Width:  |  Height:  |  Size: 400 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 405 B

After

Width:  |  Height:  |  Size: 474 B

BIN
toxygen/images/incoming_call.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 816 B

BIN
toxygen/images/incoming_call_video.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3 KiB

After

Width:  |  Height:  |  Size: 461 B

BIN
toxygen/images/menu.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 159 B

After

Width:  |  Height:  |  Size: 325 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 445 B

After

Width:  |  Height:  |  Size: 489 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 201 B

After

Width:  |  Height:  |  Size: 376 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 351 B

After

Width:  |  Height:  |  Size: 454 B

BIN
toxygen/images/pause.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 306 B

After

Width:  |  Height:  |  Size: 427 B

BIN
toxygen/images/resume.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
toxygen/images/screenshot.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 481 B

After

Width:  |  Height:  |  Size: 656 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 865 B

BIN
toxygen/images/send.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
toxygen/images/smiley.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

BIN
toxygen/images/sticker.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 94 KiB

After

Width:  |  Height:  |  Size: 94 KiB

BIN
toxygen/images/typing.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View file

@ -1,51 +0,0 @@
import app
from user_data.settings import *
import utils.util as util
import argparse
__maintainer__ = 'Ingvar'
__version__ = '0.5.0'
def clean():
"""Removes libs folder"""
directory = util.get_libs_directory()
util.remove(directory)
def reset():
Settings.reset_auto_profile()
def print_toxygen_version():
print('Toxygen v' + __version__)
def main():
parser = argparse.ArgumentParser()
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('--reset', action='store_true', help='Reset default profile')
parser.add_argument('--uri', help='Add specified Tox ID to friends')
parser.add_argument('profile', nargs='?', default=None, help='Path to Tox profile')
args = parser.parse_args()
if args.version:
print_toxygen_version()
return
if args.clean:
clean()
return
if args.reset:
reset()
return
toxygen = app.App(__version__, args.profile, args.uri)
toxygen.main()
if __name__ == '__main__':
main()

View file

@ -1,7 +1,9 @@
from history.database import MESSAGE_AUTHOR
import os.path
from ui.messages_widgets import *
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
import os.path
from history.database import MESSAGE_AUTHOR
from ui.messages_widgets import *
MESSAGE_TYPE = {
'TEXT': 0,
@ -38,8 +40,8 @@ class Message:
MESSAGE_ID = 0
def __init__(self, message_type, author, time):
self._time = time
def __init__(self, message_type, author, iTime):
self._time = iTime
self._type = message_type
self._author = author
self._widget = None
@ -66,7 +68,8 @@ class Message:
message_id = property(get_message_id)
def get_widget(self, *args):
self._widget = self._create_widget(*args)
# FixMe
self._widget = self._create_widget(*args) # pylint: disable=assignment-from-none
return self._widget
@ -81,10 +84,11 @@ class Message:
self._widget.mark_as_sent()
def _create_widget(self, *args):
pass
# overridden
return None
@staticmethod
def _get_id():
def _get_id() -> int:
Message.MESSAGE_ID += 1
return int(Message.MESSAGE_ID)
@ -95,12 +99,12 @@ class TextMessage(Message):
Plain text or action message
"""
def __init__(self, message, owner, time, message_type, message_id=0):
super().__init__(message_type, owner, time)
def __init__(self, message, owner, iTime, message_type, message_id=0):
super().__init__(message_type, owner, iTime)
self._message = message
self._id = message_id
def get_text(self):
def get_text(self) -> str:
return self._message
text = property(get_text)
@ -119,8 +123,8 @@ class TextMessage(Message):
class OutgoingTextMessage(TextMessage):
def __init__(self, message, owner, time, message_type, tox_message_id=0):
super().__init__(message, owner, time, message_type)
def __init__(self, message, owner, iTime, message_type, tox_message_id=0):
super().__init__(message, owner, iTime, message_type)
self._tox_message_id = tox_message_id
def get_tox_message_id(self):
@ -134,8 +138,8 @@ class OutgoingTextMessage(TextMessage):
class GroupChatMessage(TextMessage):
def __init__(self, id, message, owner, time, message_type, name):
super().__init__(id, message, owner, time, message_type)
def __init__(self, cid, message, owner, iTime, message_type, name):
super().__init__(cid, message, owner, iTime, message_type)
self._user_name = name
@ -144,20 +148,20 @@ class TransferMessage(Message):
Message with info about file transfer
"""
def __init__(self, author, time, state, size, file_name, friend_number, file_number):
super().__init__(MESSAGE_TYPE['FILE_TRANSFER'], author, time)
def __init__(self, author, iTime, state, size, file_name, friend_number, file_number):
super().__init__(MESSAGE_TYPE['FILE_TRANSFER'], author, iTime)
self._state = state
self._size = size
self._file_name = file_name
self._friend_number, self._file_number = friend_number, file_number
def is_active(self, file_number):
def is_active(self, file_number) -> bool:
if self._file_number != file_number:
return False
return self._state not in (FILE_TRANSFER_STATE['FINISHED'], FILE_TRANSFER_STATE['CANCELLED'])
def get_friend_number(self):
def get_friend_number(self) -> int:
return self._friend_number
friend_number = property(get_friend_number)
@ -185,10 +189,10 @@ class TransferMessage(Message):
file_name = property(get_file_name)
def transfer_updated(self, state, percentage, time):
def transfer_updated(self, state, percentage, iTime):
self._state = state
if self._widget is not None:
self._widget.update_transfer_state(state, percentage, time)
self._widget.update_transfer_state(state, percentage, iTime)
def _create_widget(self, *args):
return FileTransferItem(self, *args)
@ -196,9 +200,9 @@ class TransferMessage(Message):
class UnsentFileMessage(TransferMessage):
def __init__(self, path, data, time, author, size, friend_number):
def __init__(self, path, data, iTime, author, size, friend_number):
file_name = os.path.basename(path)
super().__init__(author, time, FILE_TRANSFER_STATE['UNSENT'], size, file_name, friend_number, -1)
super().__init__(author, iTime, FILE_TRANSFER_STATE['UNSENT'], size, file_name, friend_number, -1)
self._data, self._path = data, path
def get_data(self):
@ -235,5 +239,5 @@ class InlineImageMessage(Message):
class InfoMessage(TextMessage):
def __init__(self, message, time):
super().__init__(message, None, time, MESSAGE_TYPE['INFO_MESSAGE'])
def __init__(self, message, iTime):
super().__init__(message, None, iTime, MESSAGE_TYPE['INFO_MESSAGE'])

View file

@ -1,6 +1,15 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
import logging
import common.tox_save as tox_save
from messenger.messages import *
import utils.ui as util_ui
from messenger.messages import *
from toxygen_wrapper.tests.support_testing import assert_main_thread
from toxygen_wrapper.toxcore_enums_and_consts import TOX_MAX_MESSAGE_LENGTH
global LOG
LOG = logging.getLogger('app.'+__name__)
log = lambda x: LOG.info(x)
class Messenger(tox_save.ToxSave):
@ -19,18 +28,19 @@ class Messenger(tox_save.ToxSave):
calls_manager.call_started_event.add_callback(self._on_call_started)
calls_manager.call_finished_event.add_callback(self._on_call_finished)
def get_last_message(self):
def __repr__(self):
return "<Messenger>"
def get_last_message(self) -> str:
contact = self._contacts_manager.get_curr_contact()
if contact is None:
return str()
return contact.get_last_message_text()
# -----------------------------------------------------------------------------------------------------------------
# Messaging - friends
# -----------------------------------------------------------------------------------------------------------------
def new_message(self, friend_number, message_type, message):
def new_message(self, friend_number, message_type, message) -> None:
"""
Current user gets new message
:param friend_number: friend_num of friend who sent message
@ -42,7 +52,7 @@ class Messenger(tox_save.ToxSave):
text_message = TextMessage(message, MessageAuthor(friend.name, MESSAGE_AUTHOR['FRIEND']), t, message_type)
self._add_message(text_message, friend)
def send_message(self):
def send_message(self) -> None:
text = self._screen.messageEdit.toPlainText()
plugin_command_prefix = '/plugin '
@ -51,33 +61,53 @@ class Messenger(tox_save.ToxSave):
self._screen.messageEdit.clear()
return
action_message_prefix = '/me '
if text.startswith(action_message_prefix):
message_type = TOX_MESSAGE_TYPE['ACTION']
text = text[len(action_message_prefix):]
else:
message_type = TOX_MESSAGE_TYPE['NORMAL']
message_type = TOX_MESSAGE_TYPE['NORMAL']
if False: # undocumented
action_message_prefix = '/me '
if text.startswith(action_message_prefix):
message_type = TOX_MESSAGE_TYPE['ACTION']
text = text[len(action_message_prefix):]
if self._contacts_manager.is_active_a_friend():
self.send_message_to_friend(text, message_type)
elif self._contacts_manager.is_active_a_group():
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)
if len(text) > TOX_MAX_MESSAGE_LENGTH:
text = text[:TOX_MAX_MESSAGE_LENGTH] # 1372
try:
if self._contacts_manager.is_active_a_friend():
self.send_message_to_friend(text, message_type)
elif self._contacts_manager.is_active_a_group():
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) -> None:
"""
Send message
:param text: message text
:param friend_number: number of friend
from Qt callback
"""
if not text:
return
if friend_number is None:
friend_number = self._contacts_manager.get_active_number()
if not text or friend_number < 0:
if friend_number is None or friend_number < 0:
LOG.error(f"No _contacts_manager.get_active_number")
return
assert_main_thread()
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'))
t = util.get_unix_time()
for message in messages:
@ -94,7 +124,7 @@ class Messenger(tox_save.ToxSave):
self._screen.messageEdit.clear()
self._screen.messages.scrollToBottom()
def send_messages(self, friend_number):
def send_messages(self, friend_number:int) -> None:
"""
Send 'offline' messages to friend
"""
@ -106,13 +136,11 @@ class Messenger(tox_save.ToxSave):
message_id = self._tox.friend_send_message(friend_number, message.type, message.text.encode('utf-8'))
message.tox_message_id = message_id
except Exception as ex:
util.log('Sending pending messages failed with ' + str(ex))
LOG.warn('Sending pending messages failed with ' + str(ex))
# -----------------------------------------------------------------------------------------------------------------
# Messaging - groups
# -----------------------------------------------------------------------------------------------------------------
def send_message_to_group(self, text, message_type, group_number=None):
def send_message_to_group(self, text, message_type, group_number=None) -> None:
if group_number is None:
group_number = self._contacts_manager.get_active_number()
@ -133,7 +161,7 @@ class Messenger(tox_save.ToxSave):
self._screen.messageEdit.clear()
self._screen.messages.scrollToBottom()
def new_group_message(self, group_number, message_type, message, peer_id):
def new_group_message(self, group_number, message_type, message, peer_id) -> None:
"""
Current user gets new message
:param message_type: message type - plain text or action message (/me)
@ -141,40 +169,63 @@ class Messenger(tox_save.ToxSave):
"""
t = util.get_unix_time()
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)
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)
self._add_message(text_message, group)
# -----------------------------------------------------------------------------------------------------------------
# Messaging - group peers
# -----------------------------------------------------------------------------------------------------------------
def send_message_to_group_peer(self, text, message_type, group_number=None, peer_id=None):
def send_message_to_group_peer(self, text, message_type, group_number=None, peer_id=None) -> None:
if group_number is None or peer_id is None:
group_peer_contact = self._contacts_manager.get_curr_contact()
peer_id = group_peer_contact.number
group = self._get_group_by_public_key(group_peer_contact.group_pk)
group_number = group.number
if not text or group_number < 0 or peer_id < 0:
if not text:
return
if group.number < 0:
return
if peer_id is not None and peer_id < 0:
return
group_peer_contact = self._contacts_manager.get_or_create_group_peer_contact(group_number, peer_id)
assert_main_thread()
group = self._get_group_by_number(group_number)
messages = self._split_message(text.encode('utf-8'))
# FixMe: peer_id is None?
group_peer_contact = self._contacts_manager.get_or_create_group_peer_contact(group_number, peer_id)
if group_peer_contact is None:
LOG.warn("M.group_send_private_message group_peer_contact is None")
return
# group_peer_contact now may be None
t = util.get_unix_time()
for message in messages:
self._tox.group_send_private_message(group_number, peer_id, message_type, message)
bRet = self._tox.group_send_private_message(group_number, peer_id, message_type, message)
if not bRet:
LOG.warn("M.group_send_private_messag failed")
continue
message_author = MessageAuthor(group.get_self_name(), MESSAGE_AUTHOR['GC_PEER'])
message = OutgoingTextMessage(text, message_author, t, message_type)
group_peer_contact.append_message(message)
# AttributeError: 'GroupChatPeer' object has no attribute 'append_message'
if not hasattr(group_peer_contact, 'append_message'):
LOG.warn("M. group_peer_contact has no append_message group_peer_contact={group_peer_contact}")
else:
group_peer_contact.append_message(message)
if not self._contacts_manager.is_contact_active(group_peer_contact):
return
self._create_message_item(message)
self._screen.messageEdit.clear()
self._screen.messages.scrollToBottom()
def new_group_private_message(self, group_number, message_type, message, peer_id):
def new_group_private_message(self, group_number, message_type, message, peer_id) -> None:
"""
Current user gets new message
:param message: text of message
@ -182,24 +233,26 @@ class Messenger(tox_save.ToxSave):
t = util.get_unix_time()
group = self._get_group_by_number(group_number)
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']),
t, message_type)
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)
# -----------------------------------------------------------------------------------------------------------------
# Message receipts
# -----------------------------------------------------------------------------------------------------------------
def receipt(self, friend_number, message_id):
def receipt(self, friend_number, message_id) -> None:
friend = self._get_friend_by_number(friend_number)
friend.mark_as_sent(message_id)
# -----------------------------------------------------------------------------------------------------------------
# Typing notifications
# -----------------------------------------------------------------------------------------------------------------
def send_typing(self, typing):
def send_typing(self, typing) -> None:
"""
Send typing notification to a friend
"""
@ -208,18 +261,16 @@ class Messenger(tox_save.ToxSave):
contact = self._contacts_manager.get_curr_contact()
contact.typing_notification_handler.send(self._tox, typing)
def friend_typing(self, friend_number, typing):
def friend_typing(self, friend_number, typing) -> None:
"""
Display incoming typing notification
"""
if self._contacts_manager.is_friend_active(friend_number):
self._screen.typing.setVisible(typing)
# -----------------------------------------------------------------------------------------------------------------
# Contact info updated
# -----------------------------------------------------------------------------------------------------------------
def new_friend_name(self, friend, old_name, new_name):
def new_friend_name(self, friend, old_name, new_name) -> None:
if old_name == new_name or friend.has_alias():
return
message = util_ui.tr('User {} is now known as {}')
@ -228,12 +279,10 @@ class Messenger(tox_save.ToxSave):
friend.actions = True
self._add_info_message(friend.number, message)
# -----------------------------------------------------------------------------------------------------------------
# Private methods
# -----------------------------------------------------------------------------------------------------------------
@staticmethod
def _split_message(message):
def _split_message(message) -> list:
messages = []
while len(message) > TOX_MAX_MESSAGE_LENGTH:
size = TOX_MAX_MESSAGE_LENGTH * 4 // 5
@ -254,7 +303,7 @@ class Messenger(tox_save.ToxSave):
return messages
def _get_friend_by_number(self, friend_number):
def _get_friend_by_number(self, friend_number:int):
return self._contacts_provider.get_friend_by_number(friend_number)
def _get_group_by_number(self, group_number):
@ -263,7 +312,7 @@ class Messenger(tox_save.ToxSave):
def _get_group_by_public_key(self, public_key):
return self._contacts_provider.get_group_by_public_key( public_key)
def _on_profile_name_changed(self, new_name):
def _on_profile_name_changed(self, new_name) -> None:
if self._profile_name == new_name:
return
message = util_ui.tr('User {} is now known as {}')
@ -272,39 +321,47 @@ class Messenger(tox_save.ToxSave):
self._add_info_message(friend.number, message)
self._profile_name = new_name
def _on_call_started(self, friend_number, audio, video, is_outgoing):
def _on_call_started(self, friend_number, audio, video, is_outgoing) -> None:
if is_outgoing:
text = util_ui.tr("Outgoing video call") if video else util_ui.tr("Outgoing audio call")
else:
text = util_ui.tr("Incoming video call") if video else util_ui.tr("Incoming audio call")
self._add_info_message(friend_number, text)
def _on_call_finished(self, friend_number, is_declined):
def _on_call_finished(self, friend_number, is_declined) -> None:
text = util_ui.tr("Call declined") if is_declined else util_ui.tr("Call finished")
self._add_info_message(friend_number, text)
def _add_info_message(self, friend_number, text):
def _add_info_message(self, friend_number, text) -> None:
friend = self._get_friend_by_number(friend_number)
assert friend
message = InfoMessage(text, util.get_unix_time())
friend.append_message(message)
if self._contacts_manager.is_friend_active(friend_number):
self._create_info_message_item(message)
def _create_info_message_item(self, message):
def _create_info_message_item(self, message) -> None:
assert_main_thread()
self._items_factory.create_message_item(message)
self._screen.messages.scrollToBottom()
def _add_message(self, text_message, contact):
def _add_message(self, text_message, contact) -> None:
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
# LOG.debug("_add_message is_contact_active(contact)")
self._create_message_item(text_message)
self._screen.messages.scrollToBottom()
self._contacts_manager.get_curr_contact().append_message(text_message)
else:
# LOG.debug("_add_message not is_contact_active(contact)")
contact.inc_messages()
contact.append_message(text_message)
if not contact.visibility:
self._contacts_manager.update_filtration()
def _create_message_item(self, text_message):
def _create_message_item(self, text_message) -> None:
# pixmap = self._contacts_manager.get_curr_contact().get_pixmap()
self._items_factory.create_message_item(text_message)

View file

@ -1,48 +1,113 @@
from PyQt5 import QtGui
from wrapper.toxcore_enums_and_consts import *
from wrapper.toxav_enums import *
from wrapper.tox import bin_to_string
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
import sys
import os
import threading
from qtpy import QtGui
from toxygen_wrapper.toxcore_enums_and_consts import *
from toxygen_wrapper.toxav_enums import *
from toxygen_wrapper.tox import bin_to_string
import utils.ui as util_ui
import utils.util as util
import cv2
import numpy as np
from middleware.threads import invoke_in_main_thread, execute
from notifications.tray import tray_notification
from notifications.sound import *
import threading
from datetime import datetime
iMAX_INT32 = 4294967295
# callbacks can be called in any thread so were being careful
def LOG_ERROR(l): print(f"EROR. {l}")
def LOG_WARN(l): print(f"WARN. {l}")
def LOG_INFO(l):
bIsVerbose = not hasattr(__builtins__, 'app') or app.oArgs.loglevel <= 20-1 # pylint dusable=undefined-variable
if bIsVerbose: print(f"INFO. {l}")
def LOG_DEBUG(l):
bIsVerbose = not hasattr(__builtins__, 'app') or app.oArgs.loglevel <= 10-1 # pylint dusable=undefined-variable
if bIsVerbose: print(f"DBUG. {l}")
def LOG_TRACE(l):
bIsVerbose = not hasattr(__builtins__, 'app') or app.oArgs.loglevel < 10-1 # pylint dusable=undefined-variable
pass # print(f"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
# -----------------------------------------------------------------------------------------------------------------
# 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):
"""
Current user changed connection status (offline, TCP, UDP)
"""
sSlot = 'self connection status'
def wrapped(tox_link, connection, user_data):
print('Connection status: ', str(connection))
status = tox.self_get_status() if connection != TOX_CONNECTION['NONE'] else None
invoke_in_main_thread(profile.set_status, status)
key = f"connection {connection}"
if bTooSoon(key, sSlot, 10): return
s = sProcBytes()
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
# -----------------------------------------------------------------------------------------------------------------
# Callbacks - friends
# -----------------------------------------------------------------------------------------------------------------
def friend_status(contacts_manager, file_transfer_handler, profile, settings):
sSlot = 'friend status'
def wrapped(tox, friend_number, new_status, user_data):
"""
Check friend's status (none, busy, away)
"""
print("Friend's #{} status changed!".format(friend_number))
LOG_INFO(f"Friend's #{friend_number} status changed")
key = f"friend_number {friend_number}"
if bTooSoon(key, sSlot, 10): return
friend = contacts_manager.get_friend_by_number(friend_number)
if friend.status is None and settings['sound_notifications'] and profile.status != TOX_USER_STATUS['BUSY']:
if friend.status is None and settings['sound_notifications'] and \
profile.status != TOX_USER_STATUS['BUSY']:
sound_notification(SOUND_NOTIFICATION['FRIEND_CONNECTION_STATUS'])
invoke_in_main_thread(friend.set_status, new_status)
@ -61,7 +126,7 @@ def friend_connection_status(contacts_manager, profile, settings, plugin_loader,
"""
Check friend's connection status (offline, udp, tcp)
"""
print("Friend #{} connection status: {}".format(friend_number, new_status))
LOG_DEBUG(f"Friend #{friend_number} connection status: {new_status}")
friend = contacts_manager.get_friend_by_number(friend_number)
if new_status == TOX_CONNECTION['NONE']:
invoke_in_main_thread(friend.set_status, None)
@ -79,29 +144,35 @@ def friend_connection_status(contacts_manager, profile, settings, plugin_loader,
def friend_name(contacts_provider, messenger):
sSlot = 'friend_name'
def wrapped(tox, friend_number, name, size, user_data):
"""
Friend changed his name
"""
print('New name friend #' + str(friend_number))
key = f"friend_number={friend_number}"
if bTooSoon(key, sSlot, 60): return
friend = contacts_provider.get_friend_by_number(friend_number)
old_name = friend.name
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(messenger.new_friend_name, friend, old_name, new_name)
return wrapped
def friend_status_message(contacts_manager, messenger):
sSlot = 'status_message'
def wrapped(tox, friend_number, status_message, size, user_data):
"""
:return: function for callback friend_status_message. It updates friend's status message
and calls window repaint
"""
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'))
print('User #{} has new status message'.format(friend_number))
LOG_DEBUG(f'User #{friend_number} has new status message')
invoke_in_main_thread(messenger.send_messages, friend_number)
return wrapped
@ -112,16 +183,20 @@ def friend_message(messenger, contacts_manager, profile, settings, window, tray)
"""
New message from friend
"""
LOG_DEBUG(f"friend_message #{friend_number}")
message = str(message, 'utf-8')
invoke_in_main_thread(messenger.new_message, friend_number, message_type, message)
if not window.isActiveWindow():
friend = contacts_manager.get_friend_by_number(friend_number)
if settings['notifications'] and profile.status != TOX_USER_STATUS['BUSY'] and not settings.locked:
if settings['notifications'] \
and profile.status != TOX_USER_STATUS['BUSY'] \
and not settings.locked:
invoke_in_main_thread(tray_notification, friend.name, message, tray, window)
if settings['sound_notifications'] and profile.status != TOX_USER_STATUS['BUSY']:
sound_notification(SOUND_NOTIFICATION['MESSAGE'])
icon = os.path.join(util.get_images_directory(), 'icon_new_messages.png')
invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon))
if tray:
invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon))
return wrapped
@ -131,7 +206,7 @@ def friend_request(contacts_manager):
"""
Called when user get new friend request
"""
print('Friend request')
LOG_DEBUG(f'Friend request')
key = ''.join(chr(x) for x in public_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'))
@ -140,9 +215,12 @@ def friend_request(contacts_manager):
def friend_typing(messenger):
sSlot = "friend_typing"
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)
return wrapped
@ -153,9 +231,7 @@ def friend_read_receipt(messenger):
return wrapped
# -----------------------------------------------------------------------------------------------------------------
# Callbacks - file transfers
# -----------------------------------------------------------------------------------------------------------------
def tox_file_recv(window, tray, profile, file_transfer_handler, contacts_manager, settings):
@ -164,7 +240,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):
if file_type == TOX_FILE_KIND['DATA']:
print('File')
LOG_INFO(f'file_transfer_handler File friend_number={friend_number}')
try:
file_name = str(file_name[:file_name_size], 'utf-8')
except:
@ -176,15 +252,18 @@ def tox_file_recv(window, tray, profile, file_transfer_handler, contacts_manager
file_name)
if not window.isActiveWindow():
friend = contacts_manager.get_friend_by_number(friend_number)
if settings['notifications'] and profile.status != TOX_USER_STATUS['BUSY'] and not settings.locked:
if settings['notifications'] \
and profile.status != TOX_USER_STATUS['BUSY'] \
and not settings.locked:
file_from = util_ui.tr("File from")
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']:
sound_notification(SOUND_NOTIFICATION['FILE_TRANSFER'])
icon = util.join_path(util.get_images_directory(), 'icon_new_messages.png')
invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon))
if tray:
icon = util.join_path(util.get_images_directory(), 'icon_new_messages.png')
invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon))
else: # avatar
print('Avatar')
LOG_DEBUG(f'file_transfer_handler Avatar')
invoke_in_main_thread(file_transfer_handler.incoming_avatar,
friend_number,
file_number,
@ -227,9 +306,7 @@ def file_recv_control(file_transfer_handler):
return wrapped
# -----------------------------------------------------------------------------------------------------------------
# Callbacks - custom packets
# -----------------------------------------------------------------------------------------------------------------
def lossless_packet(plugin_loader):
@ -254,20 +331,20 @@ def lossy_packet(plugin_loader):
return wrapped
# -----------------------------------------------------------------------------------------------------------------
# Callbacks - audio
# -----------------------------------------------------------------------------------------------------------------
def call_state(calls_manager):
def wrapped(toxav, friend_number, mask, user_data):
def wrapped(iToxav, friend_number, mask, user_data):
"""
New call state
"""
print(friend_number, mask)
LOG_DEBUG(f"call_state #{friend_number}")
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)
else:
calls_manager.toxav_call_state_cb(friend_number, mask)
# guessing was calls_manager.
#? incoming_call
calls_manager._call.toxav_call_state_cb(friend_number, mask)
return wrapped
@ -277,7 +354,7 @@ def call(calls_manager):
"""
Incoming call from friend
"""
print(friend_number, audio, video)
LOG_DEBUG(f"Incoming call from {friend_number} {audio} {video}")
invoke_in_main_thread(calls_manager.incoming_call, audio, video, friend_number)
return wrapped
@ -288,16 +365,16 @@ def callback_audio(calls_manager):
"""
New audio chunk
"""
calls_manager.call.audio_chunk(
#trace LOG_DEBUG(f"callback_audio #{friend_number}")
# dunno was .call
calls_manager._call.audio_chunk(
bytes(samples[:audio_samples_per_channel * 2 * audio_channels_count]),
audio_channels_count,
rate)
return wrapped
# -----------------------------------------------------------------------------------------------------------------
# Callbacks - video
# -----------------------------------------------------------------------------------------------------------------
def video_receive_frame(toxav, friend_number, width, height, y, u, v, ystride, ustride, vstride, user_data):
@ -324,6 +401,9 @@ 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
"""
LOG_DEBUG(f"video_receive_frame from toxav_video_receive_frame_cb={friend_number}")
with ts.ignoreStdout(): import cv2
import numpy as np
try:
y_size = abs(max(width, abs(ystride)))
u_size = abs(max(width // 2, abs(ustride)))
@ -345,15 +425,14 @@ def video_receive_frame(toxav, friend_number, width, height, y, u, v, ystride, u
frame[height * 5 // 4:, :width // 2] = v[:height // 2:2, :width // 2]
frame[height * 5 // 4:, width // 2:] = v[1:height // 2:2, :width // 2]
frame = cv2.cvtColor(frame, cv2.COLOR_YUV2BGR_I420)
invoke_in_main_thread(cv2.imshow, str(friend_number), frame)
frame = cv2.cvtColor(frame, cv2.COLOR_YUV2BGR_I420) # pylint: disable=no-member
# imshow
invoke_in_main_thread(cv2.imshow, str(friend_number), frame) # pylint: disable=no-member
except Exception as ex:
print(ex)
LOG_ERROR(f"video_receive_frame {ex} #{friend_number}")
pass
# -----------------------------------------------------------------------------------------------------------------
# Callbacks - groups
# -----------------------------------------------------------------------------------------------------------------
def group_message(window, tray, tox, messenger, settings, profile):
@ -361,18 +440,24 @@ def group_message(window, tray, tox, messenger, settings, profile):
New message in group chat
"""
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')
invoke_in_main_thread(messenger.new_group_message, group_number, message_type, message, peer_id)
if window.isActiveWindow():
return
bl = settings['notify_all_gc'] or profile.name in message
name = tox.group_peer_get_name(group_number, peer_id)
if settings['notifications'] and profile.status != TOX_USER_STATUS['BUSY'] and (not settings.locked) and bl:
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'])
icon = util.join_path(util.get_images_directory(), 'icon_new_messages.png')
invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon))
if False and settings['tray_icon'] and tray:
if settings['notifications'] and \
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
@ -382,54 +467,87 @@ def group_private_message(window, tray, tox, messenger, settings, profile):
New private message in group chat
"""
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')
invoke_in_main_thread(messenger.new_group_private_message, group_number, message_type, message, peer_id)
if window.isActiveWindow():
return
bl = settings['notify_all_gc'] or profile.name in message
name = tox.group_peer_get_name(group_number, peer_id)
if settings['notifications'] and profile.status != TOX_USER_STATUS['BUSY'] and (not settings.locked) and bl:
try:
name = tox.group_peer_get_name(group_number, peer_id)
except Exception as e:
LOG_WARN("tox.group_peer_get_name {group_number} {peer_id}")
name = ''
if settings['notifications'] and settings['tray_icon'] \
and profile.status != TOX_USER_STATUS['BUSY'] \
and (not settings.locked) and bl:
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'])
icon = util.join_path(util.get_images_directory(), 'icon_new_messages.png')
invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon))
if tray and hasattr(tray, 'setIcon'):
invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon))
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 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')
invoke_in_main_thread(groups_service.process_group_invite,
friend_number, group_name,
bytes(invite_data[:length]))
if window.isActiveWindow():
return
if settings['notifications'] and profile.status != TOX_USER_STATUS['BUSY'] and not settings.locked:
bHasTray = tray and settings['tray_icon']
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)
title = util_ui.tr('New invite to group chat')
text = util_ui.tr('{} invites you to group "{}"').format(friend.name, group_name)
invoke_in_main_thread(tray_notification, title, text, tray, window)
icon = util.join_path(util.get_images_directory(), 'icon_new_messages.png')
invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon))
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
def group_self_join(contacts_provider, contacts_manager, groups_service):
sSlot = 'group_self_join'
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)
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(groups_service.update_group_info, group)
invoke_in_main_thread(contacts_manager.update_filtration)
return wrapped
def group_peer_join(contacts_provider, groups_service):
sSlot = "group_peer_join"
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)
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)
invoke_in_main_thread(groups_service.generate_peers_list)
invoke_in_main_thread(groups_service.update_group_info, group)
@ -438,29 +556,49 @@ def group_peer_join(contacts_provider, groups_service):
def group_peer_exit(contacts_provider, groups_service, contacts_manager):
def wrapped(tox, group_number, peer_id, message, length, user_data):
def wrapped(tox,
group_number, peer_id,
exit_type, name, name_length,
message, length,
user_data):
group = contacts_provider.get_group_by_number(group_number)
group.remove_peer(peer_id)
invoke_in_main_thread(groups_service.generate_peers_list)
if group:
LOG_DEBUG(f"group_peer_exit #{group_number} peer_id={peer_id} exit_type={exit_type}")
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
def group_peer_name(contacts_provider, groups_service):
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)
peer = group.get_peer_by_id(peer_id)
peer.name = str(name[:length], 'utf-8')
invoke_in_main_thread(groups_service.generate_peers_list)
if peer:
peer.name = str(name[:length], 'utf-8')
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} has no peer_id={peer_id} in _peers!r")
return
return wrapped
def group_peer_status(contacts_provider, groups_service):
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)
peer = group.get_peer_by_id(peer_id)
peer.status = peer_status
if peer:
peer.status = peer_status
else:
# _peers = [(p._name, p._peer_id) for p in group.get_peers()]
LOG_TRACE(f"remove_peer group {group} has no peer_id={peer_id} in _peers!r")
# TODO: add info message
invoke_in_main_thread(groups_service.generate_peers_list)
return wrapped
@ -468,32 +606,62 @@ def group_peer_status(contacts_provider, groups_service):
def group_topic(contacts_provider):
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)
topic = str(topic[:length], 'utf-8')
invoke_in_main_thread(group.set_status_message, topic)
if group:
topic = str(topic[:length], 'utf-8')
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} has no peer_id={peer_id} in {_peers}")
# TODO: add info message
return wrapped
def group_moderation(groups_service, contacts_provider, contacts_manager, messenger):
def update_peer_role(group, mod_peer_id, peer_id, new_role):
peer = group.get_peer_by_id(peer_id)
peer.role = new_role
if peer:
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} has no peer_id={peer_id} in _peers!r")
# TODO: add info message
def remove_peer(group, mod_peer_id, peer_id, is_ban):
contacts_manager.remove_group_peer_by_id(group, peer_id)
group.remove_peer(peer_id)
peer = group.get_peer_by_id(peer_id)
if peer:
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} has no peer_id={peer_id} in _peers!r")
# TODO: add info message
# source_peer_number, target_peer_number,
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)
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} 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} has no peer_id={peer_id} in _peers!r")
return
if event_type == TOX_GROUP_MOD_EVENT['KICK']:
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']:
update_peer_role(group, mod_peer_id, peer_id, TOX_GROUP_ROLE['OBSERVER'])
elif event_type == TOX_GROUP_MOD_EVENT['USER']:
@ -509,6 +677,7 @@ def group_moderation(groups_service, contacts_provider, contacts_manager, messen
def group_password(contacts_provider):
def wrapped(tox_link, group_number, password, length, user_data):
LOG_DEBUG(f"group_password #{group_number}")
password = str(password[:length], 'utf-8')
group = contacts_provider.get_group_by_number(group_number)
group.password = password
@ -519,6 +688,7 @@ def group_password(contacts_provider):
def group_peer_limit(contacts_provider):
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.peer_limit = peer_limit
@ -528,19 +698,18 @@ def group_peer_limit(contacts_provider):
def group_privacy_state(contacts_provider):
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.is_private = privacy_state == TOX_GROUP_PRIVACY_STATE['PRIVATE']
return wrapped
# -----------------------------------------------------------------------------------------------------------------
# Callbacks - initialization
# -----------------------------------------------------------------------------------------------------------------
def init_callbacks(tox, profile, settings, plugin_loader, contacts_manager,
calls_manager, file_transfer_handler, main_window, tray, messenger, groups_service,
contacts_provider):
contacts_provider, ms=None):
"""
Initialization of all callbacks.
:param tox: Tox instance
@ -557,6 +726,7 @@ def init_callbacks(tox, profile, settings, plugin_loader, contacts_manager,
:param groups_service: GroupsService instance
:param contacts_provider: ContactsProvider instance
"""
# self callbacks
tox.callback_self_connection_status(self_connection_status(tox, profile))

View file

@ -1,115 +1,170 @@
from bootstrap.bootstrap import *
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
import sys
import threading
import queue
from qtpy import QtCore
from bootstrap.bootstrap import *
from bootstrap.bootstrap import download_nodes_list
from toxygen_wrapper.toxcore_enums_and_consts import TOX_USER_STATUS, TOX_CONNECTION
import toxygen_wrapper.tests.support_testing as ts
from utils import util
import time
from PyQt5 import QtCore
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('TRAC+ '+l)
iLAST_CONN = 0
iLAST_DELTA = 60
# -----------------------------------------------------------------------------------------------------------------
# Base threads
# -----------------------------------------------------------------------------------------------------------------
class BaseThread(threading.Thread):
def __init__(self):
super().__init__()
def __init__(self, name=None, target=None):
self._stop_thread = False
if name:
super().__init__(name=name, target=target)
else:
super().__init__(target=target)
def stop_thread(self):
def stop_thread(self, timeout=-1):
self._stop_thread = True
self.join()
if timeout < 0:
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):
def __init__(self):
def __init__(self, name=None):
# NO name=name
super().__init__()
self._stop_thread = False
self.name = str(id(self))
def stop_thread(self):
def stop_thread(self, timeout=-1):
self._stop_thread = True
self.wait()
if timeout < 0:
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
# -----------------------------------------------------------------------------------------------------------------
class InitThread(BaseThread):
def __init__(self, tox, plugin_loader, settings, is_first_start):
super().__init__()
self._tox, self._plugin_loader, self._settings = tox, plugin_loader, settings
def __init__(self, tox, plugin_loader, settings, app, is_first_start):
super().__init__(name='InitThread')
self._tox = tox
self._plugin_loader = plugin_loader
self._settings = settings
self._app = app
self._is_first_start = is_first_start
def run(self):
if self._is_first_start:
# download list of nodes if needed
download_nodes_list(self._settings)
# start plugins
self._plugin_loader.load()
# bootstrap
# DBUG+ InitThread run: ERROR name 'ts' is not defined
import toxygen_wrapper.tests.support_testing as ts
LOG_DEBUG('InitThread run: ')
try:
for data in generate_nodes():
if self._stop_thread:
return
self._tox.bootstrap(*data)
self._tox.add_tcp_relay(*data)
except:
if self._is_first_start and ts.bAreWeConnected() and \
self._settings['download_nodes_list']:
LOG_INFO(f"downloading list of nodes {self._settings['download_nodes_list']}")
download_nodes_list(self._settings, oArgs=self._app._args)
if ts.bAreWeConnected():
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
for _ in range(10):
for _ in range(ts.iTHREAD_JOINS):
if self._stop_thread:
return
time.sleep(1)
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)
sleep(ts.iTHREAD_SLEEP)
return
class ToxIterateThread(BaseQThread):
def __init__(self, tox):
def __init__(self, tox, app=None):
super().__init__()
self._tox = tox
self._app = app
def run(self):
LOG_DEBUG('ToxIterateThread run: ')
while not self._stop_thread:
self._tox.iterate()
time.sleep(self._tox.iteration_interval() / 1000)
try:
iMsec = self._tox.iteration_interval()
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):
def __init__(self, toxav):
super().__init__()
self._toxav = toxav
def run(self):
LOG_DEBUG('ToxAVIterateThread run: ')
while not self._stop_thread:
self._toxav.iterate()
time.sleep(self._toxav.iteration_interval() / 1000)
sleep(self._toxav.iteration_interval() / 1000)
# -----------------------------------------------------------------------------------------------------------------
# File transfers thread
# -----------------------------------------------------------------------------------------------------------------
class FileTransfersThread(BaseQThread):
def __init__(self):
super().__init__()
super().__init__('FileTransfers')
self._queue = queue.Queue()
self._timeout = 0.01
@ -124,14 +179,12 @@ class FileTransfersThread(BaseQThread):
except queue.Empty:
pass
except queue.Full:
util.log('Queue is full in _thread')
LOG_WARN('Queue is full in _thread')
except Exception as ex:
util.log('Exception in _thread: ' + str(ex))
LOG_ERROR('in _thread: ' + str(ex))
_thread = FileTransfersThread()
def start_file_transfer_thread():
_thread.start()
@ -144,9 +197,7 @@ def execute(func, *args, **kwargs):
_thread.execute(func, *args, **kwargs)
# -----------------------------------------------------------------------------------------------------------------
# Invoking in main thread
# -----------------------------------------------------------------------------------------------------------------
class InvokeEvent(QtCore.QEvent):
EVENT_TYPE = QtCore.QEvent.Type(QtCore.QEvent.registerEventType())

View file

@ -1,34 +1,89 @@
import user_data.settings
import wrapper.tox
import wrapper.toxcore_enums_and_consts as enums
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
import ctypes
import traceback
import os
from ctypes import *
import user_data.settings
import toxygen_wrapper.tox
import toxygen_wrapper.toxcore_enums_and_consts as enums
from toxygen_wrapper.tests import support_testing as ts
# callbacks can be called in any thread so were being careful
# tox.py can be called by callbacks
from toxygen_wrapper.tests.support_testing import LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG, LOG_TRACE
global LOG
import logging
LOG = logging.getLogger('app.'+'tox_factory')
from utils import util
from utils import ui as util_ui
def tox_factory(data=None, settings=None):
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 settings: current profile settings. None = default settings will be used
:return: new tox instance
"""
if settings is None:
if not settings:
LOG_WARN("tox_factory using get_default_settings")
settings = user_data.settings.Settings.get_default_settings()
else:
user_data.settings.clean_settings(settings)
tox_options = wrapper.tox.Tox.options_new()
tox_options.contents.udp_enabled = settings['udp_enabled']
tox_options.contents.proxy_type = settings['proxy_type']
tox_options.contents.proxy_host = bytes(settings['proxy_host'], 'UTF-8')
tox_options.contents.proxy_port = settings['proxy_port']
tox_options.contents.start_port = settings['start_port']
tox_options.contents.end_port = settings['end_port']
tox_options.contents.tcp_port = settings['tcp_port']
tox_options.contents.local_discovery_enabled = settings['lan_discovery']
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
try:
tox_options = toxygen_wrapper.tox.Tox.options_new()
tox_options.contents.ipv6_enabled = settings['ipv6_enabled']
tox_options.contents.udp_enabled = settings['udp_enabled']
tox_options.contents.proxy_type = int(settings['proxy_type'])
if type(settings['proxy_host']) == str:
tox_options.contents.proxy_host = bytes(settings['proxy_host'],'UTF-8')
elif type(settings['proxy_host']) == bytes:
tox_options.contents.proxy_host = settings['proxy_host']
else:
tox_options.contents.proxy_host = b''
tox_options.contents.proxy_port = int(settings['proxy_port'])
tox_options.contents.start_port = settings['start_port']
tox_options.contents.end_port = settings['end_port']
tox_options.contents.tcp_port = settings['tcp_port']
tox_options.contents.local_discovery_enabled = settings['local_discovery_enabled']
tox_options.contents.dht_announcements_enabled = settings['dht_announcements_enabled']
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
return wrapper.tox.Tox(tox_options)
# overrides
tox_options.contents.local_discovery_enabled = False
tox_options.contents.ipv6_enabled = False
tox_options.contents.hole_punching_enabled = False
LOG.debug("toxygen_wrapper.tox.Tox settings: " +repr(settings))
if 'trace_enabled' in settings and not settings['trace_enabled']:
LOG_DEBUG("settings['trace_enabled' disabled" )
elif tox_options._options_pointer and \
'trace_enabled' in settings and settings['trace_enabled']:
ts.vAddLoggerCallback(tox_options)
LOG_INFO("c-toxcore trace_enabled enabled" )
else:
LOG_WARN("No tox_options._options_pointer to add self_logger_cb" )
retval = toxygen_wrapper.tox.Tox(tox_options)
except Exception as e:
if app and hasattr(app, '_log'):
pass
LOG_ERROR(f"toxygen_wrapper.tox.Tox failed: {e}")
LOG_WARN(traceback.format_exc())
raise
if app and hasattr(app, '_log'):
app._log("DEBUG: toxygen_wrapper.tox.Tox succeeded")
return retval

View file

@ -1,20 +1,44 @@
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
import json
import urllib.request
import utils.util as util
from PyQt5 import QtNetwork, QtCore
import logging
try:
import requests
except ImportError:
requests = None
from qtpy import QtNetwork, QtCore
import utils.util as util
global LOG
iTIMEOUT=60
LOG = logging.getLogger('app.'+__name__)
class ToxDns:
def __init__(self, settings):
def __init__(self, settings, log=None):
self._settings = settings
self._log = log
@staticmethod
def _send_request(url, data):
req = urllib.request.Request(url)
req.add_header('Content-Type', 'application/json')
response = urllib.request.urlopen(req, bytes(json.dumps(data), 'utf-8'))
res = json.loads(str(response.read(), 'utf-8'))
if requests:
LOG.info('send_request loading with requests: ' + str(url))
headers = dict()
headers['Content-Type'] = 'application/json'
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']:
return res['tox_id']
else:
@ -29,12 +53,25 @@ class ToxDns:
site = email.split('@')[1]
data = {"action": 3, "name": "{}".format(email)}
urls = ('https://{}/api'.format(site), 'http://{}/api'.format(site))
if not self._settings['proxy_type']: # no proxy
if requests:
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, timeout=iTIMEOUT)
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:
try:
return self._send_request(url, data)
except Exception as ex:
util.log('TOX DNS ERROR: ' + str(ex))
LOG.error('ERROR: TOX DNS ' + str(ex))
else: # proxy
netman = QtNetwork.QNetworkAccessManager()
proxy = QtNetwork.QNetworkProxy()
@ -60,6 +97,6 @@ class ToxDns:
if not result['c']:
return result['tox_id']
except Exception as ex:
util.log('TOX DNS ERROR: ' + str(ex))
LOG.error('ERROR: TOX DNS ' + str(ex))
return None # error

View file

@ -1,8 +1,17 @@
import utils.util
import wave
import pyaudio
import os.path
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
import os.path
import wave
import utils.util
import toxygen_wrapper.tests.support_testing as ts
with ts.ignoreStderr():
import pyaudio
global LOG
import logging
LOG = logging.getLogger('app.'+__name__)
SOUND_NOTIFICATION = {
'MESSAGE': 0,
@ -25,9 +34,19 @@ class AudioFile:
def play(self):
data = self.wf.readframes(self.chunk)
while data:
self.stream.write(data)
data = self.wf.readframes(self.chunk)
try:
while data:
self.stream.write(data)
data = self.wf.readframes(self.chunk)
except Exception as e:
LOG.error(f"Error during AudioFile play {e}")
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):
self.stream.close()

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