2018-01-26 20:21:46 +00:00
|
|
|
from contacts import basecontact
|
2018-05-15 19:51:42 +00:00
|
|
|
import random
|
2018-05-17 12:20:47 +00:00
|
|
|
import threading
|
2018-05-24 18:43:34 +00:00
|
|
|
import common.tox_save as tox_save
|
2016-02-18 16:15:38 +00:00
|
|
|
|
|
|
|
|
2018-05-24 18:43:34 +00:00
|
|
|
class Profile(basecontact.BaseContact, tox_save.ToxSave):
|
2016-02-26 14:32:36 +00:00
|
|
|
"""
|
2018-07-16 18:29:15 +00:00
|
|
|
Profile of current toxygen user.
|
2016-02-26 14:32:36 +00:00
|
|
|
"""
|
2018-07-02 19:50:46 +00:00
|
|
|
def __init__(self, profile_manager, tox, screen, contacts_provider, reset_action):
|
2016-03-07 18:00:00 +00:00
|
|
|
"""
|
|
|
|
:param tox: tox instance
|
2016-03-09 18:11:36 +00:00
|
|
|
:param screen: ref to main screen
|
2016-03-07 18:00:00 +00:00
|
|
|
"""
|
2016-10-22 18:23:03 +00:00
|
|
|
basecontact.BaseContact.__init__(self,
|
2018-07-02 19:50:46 +00:00
|
|
|
profile_manager,
|
2016-10-22 18:23:03 +00:00
|
|
|
tox.self_get_name(),
|
|
|
|
tox.self_get_status_message(),
|
2018-07-28 21:06:33 +00:00
|
|
|
screen,
|
2016-10-22 18:23:03 +00:00
|
|
|
tox.self_get_address())
|
2018-05-24 18:43:34 +00:00
|
|
|
tox_save.ToxSave.__init__(self, tox)
|
2016-03-16 08:01:23 +00:00
|
|
|
self._screen = screen
|
2016-03-09 18:11:36 +00:00
|
|
|
self._messages = screen.messages
|
2018-05-17 21:06:14 +00:00
|
|
|
self._contacts_provider = contacts_provider
|
|
|
|
self._reset_action = reset_action
|
2017-03-03 19:09:45 +00:00
|
|
|
self._waiting_for_reconnection = False
|
2018-05-18 10:23:48 +00:00
|
|
|
self._timer = None
|
2018-03-10 15:42:53 +00:00
|
|
|
|
2016-03-04 19:03:20 +00:00
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
# Edit current user's data
|
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-02-28 21:33:35 +00:00
|
|
|
def change_status(self):
|
2016-03-09 19:46:00 +00:00
|
|
|
"""
|
|
|
|
Changes status of user (online, away, busy)
|
|
|
|
"""
|
2016-02-28 21:33:35 +00:00
|
|
|
if self._status is not None:
|
2016-05-24 18:08:52 +00:00
|
|
|
self.set_status((self._status + 1) % 3)
|
|
|
|
|
|
|
|
def set_status(self, status):
|
2018-05-01 13:39:09 +00:00
|
|
|
super().set_status(status)
|
2016-06-25 12:40:01 +00:00
|
|
|
if status is not None:
|
2016-05-30 18:38:21 +00:00
|
|
|
self._tox.self_set_status(status)
|
2017-03-08 10:19:41 +00:00
|
|
|
elif not self._waiting_for_reconnection:
|
2017-04-22 19:35:32 +00:00
|
|
|
self._waiting_for_reconnection = True
|
2018-05-18 10:23:48 +00:00
|
|
|
self._timer = threading.Timer(50, self._reconnect)
|
2018-05-17 12:20:47 +00:00
|
|
|
self._timer.start()
|
2016-02-29 16:39:43 +00:00
|
|
|
|
|
|
|
def set_name(self, value):
|
2016-06-23 19:50:17 +00:00
|
|
|
if self.name == value:
|
|
|
|
return
|
2018-05-19 16:38:54 +00:00
|
|
|
super().set_name(value)
|
2018-07-21 17:43:16 +00:00
|
|
|
self._tox.self_set_name(self._name)
|
2016-02-29 16:39:43 +00:00
|
|
|
|
|
|
|
def set_status_message(self, value):
|
2018-04-26 20:54:39 +00:00
|
|
|
super().set_status_message(value)
|
2018-07-21 17:43:16 +00:00
|
|
|
self._tox.self_set_status_message(self._status_message)
|
2016-02-28 21:33:35 +00:00
|
|
|
|
2018-05-17 21:06:14 +00:00
|
|
|
def set_new_nospam(self):
|
2016-06-08 15:35:40 +00:00
|
|
|
"""Sets new nospam part of tox id"""
|
2016-05-03 19:02:56 +00:00
|
|
|
self._tox.self_set_nospam(random.randint(0, 4294967295)) # no spam - uint32
|
|
|
|
self._tox_id = self._tox.self_get_address()
|
2018-04-26 20:54:39 +00:00
|
|
|
|
2016-05-03 19:02:56 +00:00
|
|
|
return self._tox_id
|
|
|
|
|
2016-03-14 19:30:51 +00:00
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
# Reset
|
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2018-05-20 12:57:08 +00:00
|
|
|
def restart(self):
|
2016-03-14 19:30:51 +00:00
|
|
|
"""
|
|
|
|
Recreate tox instance
|
|
|
|
"""
|
2016-03-15 17:05:19 +00:00
|
|
|
self.status = None
|
2018-05-24 18:43:34 +00:00
|
|
|
self._reset_action()
|
2016-03-14 19:30:51 +00:00
|
|
|
|
2018-05-17 21:06:14 +00:00
|
|
|
def _reconnect(self):
|
2017-03-03 19:09:45 +00:00
|
|
|
self._waiting_for_reconnection = False
|
2018-05-24 18:43:34 +00:00
|
|
|
contacts = self._contacts_provider.get_all_friends()
|
|
|
|
if self.status is None or (all(list(map(lambda x: x.status is None, contacts))) and len(contacts)):
|
2017-03-03 19:09:45 +00:00
|
|
|
self._waiting_for_reconnection = True
|
2018-05-20 12:57:08 +00:00
|
|
|
self.restart()
|
2018-05-18 10:23:48 +00:00
|
|
|
self._timer = threading.Timer(50, self._reconnect)
|
2018-05-17 12:20:47 +00:00
|
|
|
self._timer.start()
|