diff --git a/toxygen/app.py b/toxygen/app.py index 05a38d7..29619fd 100644 --- a/toxygen/app.py +++ b/toxygen/app.py @@ -43,7 +43,7 @@ class App: self._tox = self._ms = self._init = self._main_loop = self._av_loop = None self._uri = self._toxes = self._tray = self._file_transfer_handler = self._contacts_provider = None self._friend_factory = self._calls_manager = self._contacts_manager = self._smiley_loader = self._tox_dns = None - self._group_factory = self._groups_service = None + self._group_factory = self._groups_service = self._profile = None if uri is not None and uri.startswith('tox:'): self._uri = uri[4:] self._path = path_to_profile @@ -192,7 +192,7 @@ class App: # Threads # ----------------------------------------------------------------------------------------------------------------- - def _start_threads(self): + def _start_threads(self, initial_start=True): # init thread self._init = threads.InitThread(self._tox, self._plugin_loader, self._settings) self._init.start() @@ -203,15 +203,17 @@ class App: self._av_loop = threads.ToxAVIterateThread(self._tox.AV) self._av_loop.start() - threads.start_file_transfer_thread() + if initial_start: + threads.start_file_transfer_thread() - def _stop_threads(self): + def _stop_threads(self, is_app_closing=True): self._init.stop_thread() self._av_loop.stop_thread() self._main_loop.stop_thread() - threads.stop_file_transfer_thread() + if is_app_closing: + threads.stop_file_transfer_thread() # ----------------------------------------------------------------------------------------------------------------- # Profiles @@ -304,21 +306,24 @@ class App: Create new tox instance (new network settings) :return: tox instance """ - self._stop_threads() + self._stop_threads(False) data = self._tox.get_savedata() self._save_profile(data) del self._tox # create new tox instance self._tox = self._create_tox(data) - self._start_threads() + self._start_threads(False) tox_savers = [self._friend_factory, self._group_factory, self._plugin_loader, self._contacts_manager, - self._contacts_provider, self._messenger, self._file_transfer_handler, self._groups_service] + self._contacts_provider, self._messenger, self._file_transfer_handler, self._groups_service, + self._profile] for tox_saver in tox_savers: tox_saver.set_tox(self._tox) - self._calls_manager.set_toxav(self._tox.AV) - return self._tox + self._calls_manager.set_toxav(self._tox.AV) + self._contacts_manager.update_friends_numbers() + + self._init_callbacks() def _create_dependencies(self): self._smiley_loader = SmileyLoader(self._settings) @@ -331,8 +336,8 @@ class App: self._tox, db, contact_items_factory) self._group_factory = GroupFactory(self._profile_manager, self._settings, self._tox, db, contact_items_factory) self._contacts_provider = ContactProvider(self._tox, self._friend_factory, self._group_factory) - profile = Profile(self._profile_manager, self._tox, self._ms, self._contacts_provider, self._reset) - self._plugin_loader = PluginLoader(self._tox, self._toxes, profile, self._settings) + self._profile = Profile(self._profile_manager, self._tox, self._ms, self._contacts_provider, self._reset) + self._plugin_loader = PluginLoader(self._tox, self._toxes, self._profile, self._settings) history = None messages_items_factory = MessagesItemsFactory(self._settings, self._plugin_loader, self._smiley_loader, self._ms, lambda m: history.delete_message(m)) @@ -343,28 +348,25 @@ class App: history.set_contacts_manager(self._contacts_manager) self._calls_manager = CallsManager(self._tox.AV, self._settings, self._ms, self._contacts_manager) self._messenger = Messenger(self._tox, self._plugin_loader, self._ms, self._contacts_manager, - self._contacts_provider, messages_items_factory, profile, self._calls_manager) + self._contacts_provider, messages_items_factory, self._profile, self._calls_manager) file_transfers_message_service = FileTransfersMessagesService(self._contacts_manager, messages_items_factory, - profile, self._ms) + self._profile, self._ms) self._file_transfer_handler = FileTransfersHandler(self._tox, self._settings, self._contacts_provider, - file_transfers_message_service, profile) + file_transfers_message_service, self._profile) messages_items_factory.set_file_transfers_handler(self._file_transfer_handler) self._groups_service = GroupsService(self._tox, self._contacts_manager, self._contacts_provider, self._ms) - widgets_factory = WidgetsFactory(self._settings, profile, self._profile_manager, self._contacts_manager, + widgets_factory = WidgetsFactory(self._settings, self._profile, self._profile_manager, self._contacts_manager, self._file_transfer_handler, self._smiley_loader, self._plugin_loader, self._toxes, self._version, self._groups_service, history) - self._tray = tray.init_tray(profile, self._settings, self._ms, self._toxes) - self._ms.set_dependencies(widgets_factory, self._tray, self._contacts_manager, self._messenger, profile, + self._tray = tray.init_tray(self._profile, self._settings, self._ms, self._toxes) + self._ms.set_dependencies(widgets_factory, self._tray, self._contacts_manager, self._messenger, self._profile, self._plugin_loader, self._file_transfer_handler, history, self._calls_manager, self._groups_service) self._tray.show() self._ms.show() - # callbacks initialization - callbacks.init_callbacks(self._tox, profile, self._settings, self._plugin_loader, self._contacts_manager, - self._calls_manager, self._file_transfer_handler, self._ms, self._tray, - self._messenger, self._groups_service, self._contacts_provider) + self._init_callbacks() def _try_to_update(self): updating = updater.start_update_if_needed(self._version, self._settings) @@ -376,3 +378,8 @@ class App: def _create_tox(self, data): return tox_factory(data, self._settings) + + def _init_callbacks(self): + callbacks.init_callbacks(self._tox, self._profile, self._settings, self._plugin_loader, self._contacts_manager, + self._calls_manager, self._file_transfer_handler, self._ms, self._tray, + self._messenger, self._groups_service, self._contacts_provider) diff --git a/toxygen/contacts/contacts_manager.py b/toxygen/contacts/contacts_manager.py index c99d439..546f04d 100644 --- a/toxygen/contacts/contacts_manager.py +++ b/toxygen/contacts/contacts_manager.py @@ -392,6 +392,15 @@ class ContactsManager(ToxSave): def can_send_typing_notification(self): return self._settings['typing_notifications'] and self._active_contact + 1 + # ----------------------------------------------------------------------------------------------------------------- + # Contacts numbers update + # ----------------------------------------------------------------------------------------------------------------- + + def update_friends_numbers(self): + for friend in self._contact_provider.get_all_friends(): + friend.number = self._tox.friend_by_public_key(friend.tox_id) + self.update_filtration() + # ----------------------------------------------------------------------------------------------------------------- # Private methods # ----------------------------------------------------------------------------------------------------------------- diff --git a/toxygen/contacts/profile.py b/toxygen/contacts/profile.py index 469b8fe..3529be4 100644 --- a/toxygen/contacts/profile.py +++ b/toxygen/contacts/profile.py @@ -1,9 +1,10 @@ from contacts import basecontact import random import threading +import common.tox_save as tox_save -class Profile(basecontact.BaseContact): +class Profile(basecontact.BaseContact, tox_save.ToxSave): """ Profile of current toxygen user. Contains friends list, tox instance """ @@ -18,9 +19,9 @@ class Profile(basecontact.BaseContact): tox.self_get_status_message(), screen.user_info, tox.self_get_address()) + tox_save.ToxSave.__init__(self, tox) self._screen = screen self._messages = screen.messages - self._tox = tox self._contacts_provider = contacts_provider self._reset_action = reset_action self._waiting_for_reconnection = False @@ -71,14 +72,13 @@ class Profile(basecontact.BaseContact): """ Recreate tox instance """ - del self._tox - self._tox = self._reset_action() self.status = None + self._reset_action() def _reconnect(self): self._waiting_for_reconnection = False - contacts = self._contacts_provider.get_all() - if self.status is None or all(list(map(lambda x: x.status is None, contacts))) and len(contacts): + 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)): self._waiting_for_reconnection = True self.restart() self._timer = threading.Timer(50, self._reconnect) diff --git a/toxygen/ui/main_screen.py b/toxygen/ui/main_screen.py index 415d8a5..652bbe3 100644 --- a/toxygen/ui/main_screen.py +++ b/toxygen/ui/main_screen.py @@ -212,6 +212,7 @@ class MainWindow(QtWidgets.QMainWindow): self.search_label.setPixmap(pixmap) self.contact_name = LineEdit(Form) + self.contact_name.setObjectName('contact_name') self.contact_name.setGeometry(QtCore.QRect(0, 0, 150, 25)) self.contact_name.textChanged.connect(self.filtering)