From 85ea9ab6e815a44017fc577a8537b74cc4e800e0 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Sat, 11 Aug 2018 00:30:33 +0300 Subject: [PATCH] fixes for messaging, contacts filtering etc --- toxygen/app.py | 19 ++++++++++--------- toxygen/contacts/contacts_manager.py | 10 ++++++---- toxygen/groups/groups_service.py | 1 + toxygen/messenger/messages.py | 7 +++++-- toxygen/ui/main_screen.py | 2 +- toxygen/ui/menu.py | 2 +- toxygen/user_data/profile_manager.py | 7 +++---- 7 files changed, 27 insertions(+), 21 deletions(-) diff --git a/toxygen/app.py b/toxygen/app.py index cfdac4f..a370a91 100644 --- a/toxygen/app.py +++ b/toxygen/app.py @@ -134,12 +134,13 @@ class App: def _load_login_screen_translations(self): current_language, supported_languages = self._get_languages() - if current_language in supported_languages: - lang_path = supported_languages[current_language] - translator = QtCore.QTranslator() - translator.load(util.get_translations_directory() + lang_path) - self._app.installTranslator(translator) - self._app.translator = translator + if current_language not in supported_languages: + return + lang_path = supported_languages[current_language] + translator = QtCore.QTranslator() + translator.load(util.get_translations_directory() + lang_path) + self._app.installTranslator(translator) + self._app.translator = translator def _load_icon(self): icon_file = os.path.join(util.get_images_directory(), 'icon.png') @@ -237,11 +238,11 @@ class App: return ls.result def _load_existing_profile(self, profile_path): - self._settings = Settings(self._toxes, profile_path.replace('.tox', '.json')) - self._profile_manager = ProfileManager(self._settings, self._toxes, profile_path) + self._profile_manager = ProfileManager(self._toxes, profile_path) data = self._profile_manager.open_profile() if self._toxes.is_data_encrypted(data): data = self._enter_password(data) + self._settings = Settings(self._toxes, profile_path.replace('.tox', '.json')) self._tox = self._create_tox(data) def _create_new_profile(self, profile_name): @@ -264,7 +265,7 @@ class App: if result.password: self._toxes.set_password(result.password) self._settings = Settings(self._toxes, self._path.replace('.tox', '.json')) - self._profile_manager = ProfileManager(self._settings, self._toxes, profile_path) + self._profile_manager = ProfileManager(self._toxes, profile_path) try: self._save_profile() except Exception as ex: diff --git a/toxygen/contacts/contacts_manager.py b/toxygen/contacts/contacts_manager.py index 757bfb0..48038ca 100644 --- a/toxygen/contacts/contacts_manager.py +++ b/toxygen/contacts/contacts_manager.py @@ -163,7 +163,7 @@ class ContactsManager(ToxSave): :param filter_str: show contacts which name contains this substring """ filter_str = filter_str.lower() - contact = self.get_curr_contact() + current_contact = self.get_curr_contact() if sorting > 5 or sorting < 0: sorting = 0 @@ -189,7 +189,7 @@ class ContactsManager(ToxSave): else: self._contacts = sorted(self._contacts, key=lambda x: x.name.lower()) - # change item widgets + # 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) @@ -203,13 +203,15 @@ class ContactsManager(ToxSave): item = self._screen.friends_list.item(index) item_widget = self._screen.friends_list.itemWidget(item) item.setSizeHint(QtCore.QSize(250, item_widget.height() if friend.visibility else 0)) + # save soring results self._sorting, self._filter_string = sorting, filter_str self._settings['sorting'] = self._sorting self._settings.save() + # update active contact - if contact is not None: - index = self._contacts.index(contact) + if current_contact is not None: + index = self._contacts.index(current_contact) self.set_active(index) def update_filtration(self): diff --git a/toxygen/groups/groups_service.py b/toxygen/groups/groups_service.py index 19b53cf..941ee1b 100644 --- a/toxygen/groups/groups_service.py +++ b/toxygen/groups/groups_service.py @@ -34,6 +34,7 @@ class GroupsService(tox_save.ToxSave): self._add_new_group_by_number(group_number) group = self._get_group_by_number(group_number) 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) diff --git a/toxygen/messenger/messages.py b/toxygen/messenger/messages.py index 57ed9bb..d5882b8 100644 --- a/toxygen/messenger/messages.py +++ b/toxygen/messenger/messages.py @@ -28,7 +28,10 @@ class MessageAuthor: def get_type(self): return self._type - type = property(get_type) + def set_type(self, value): + self._type = value + + type = property(get_type, set_type) class Message: @@ -74,7 +77,7 @@ class Message: self._widget = None def mark_as_sent(self): - self._author.author_type = MESSAGE_AUTHOR['ME'] + self._author.type = MESSAGE_AUTHOR['ME'] if self._widget is not None: self._widget.mark_as_sent() diff --git a/toxygen/ui/main_screen.py b/toxygen/ui/main_screen.py index 7b2b17d..3df3162 100644 --- a/toxygen/ui/main_screen.py +++ b/toxygen/ui/main_screen.py @@ -654,7 +654,7 @@ class MainWindow(QtWidgets.QMainWindow): clipboard.setText(text) def clear_history(self, num): - self._contacts_manager.clear_history(num) + self._history_loader.clear_history(num) def auto_accept(self, num, value): tox_id = self._contacts_manager.friend_public_key(num) diff --git a/toxygen/ui/menu.py b/toxygen/ui/menu.py index 96067fb..75db280 100644 --- a/toxygen/ui/menu.py +++ b/toxygen/ui/menu.py @@ -241,7 +241,7 @@ class ProfileSettings(CenteredWidget): util_ui.tr('Use new path')) self._settings.export(directory) self._profile.export_db(directory) - self._profile_manager.export_profile(directory, reply) + self._profile_manager.export_profile(self._settings, directory, reply) def closeEvent(self, event): self._profile.set_name(self.nick.text()) diff --git a/toxygen/user_data/profile_manager.py b/toxygen/user_data/profile_manager.py index 12e998f..e49f5f4 100644 --- a/toxygen/user_data/profile_manager.py +++ b/toxygen/user_data/profile_manager.py @@ -7,8 +7,7 @@ class ProfileManager: """ Class with methods for search, load and save profiles """ - def __init__(self, settings, toxes, path): - self._settings = settings + def __init__(self, toxes, path): self._toxes = toxes self._path = path self._directory = os.path.dirname(path) @@ -38,7 +37,7 @@ class ProfileManager: fl.write(data) print('Profile saved successfully') - def export_profile(self, new_path, use_new_path): + def export_profile(self, settings, new_path, use_new_path): path = new_path + os.path.basename(self._path) with open(self._path, 'rb') as fin: data = fin.read() @@ -49,7 +48,7 @@ class ProfileManager: if use_new_path: self._path = new_path + os.path.basename(self._path) self._directory = new_path - self._settings.update_path(new_path) + settings.update_path(new_path) @staticmethod def find_profiles():