fixes for messaging, contacts filtering etc

This commit is contained in:
ingvar1995 2018-08-11 00:30:33 +03:00
parent 4ecf666b2f
commit 85ea9ab6e8
7 changed files with 27 additions and 21 deletions

View file

@ -134,12 +134,13 @@ class App:
def _load_login_screen_translations(self): def _load_login_screen_translations(self):
current_language, supported_languages = self._get_languages() current_language, supported_languages = self._get_languages()
if current_language in supported_languages: if current_language not in supported_languages:
lang_path = supported_languages[current_language] return
translator = QtCore.QTranslator() lang_path = supported_languages[current_language]
translator.load(util.get_translations_directory() + lang_path) translator = QtCore.QTranslator()
self._app.installTranslator(translator) translator.load(util.get_translations_directory() + lang_path)
self._app.translator = translator self._app.installTranslator(translator)
self._app.translator = translator
def _load_icon(self): def _load_icon(self):
icon_file = os.path.join(util.get_images_directory(), 'icon.png') icon_file = os.path.join(util.get_images_directory(), 'icon.png')
@ -237,11 +238,11 @@ class App:
return ls.result return ls.result
def _load_existing_profile(self, profile_path): def _load_existing_profile(self, profile_path):
self._settings = Settings(self._toxes, profile_path.replace('.tox', '.json')) self._profile_manager = ProfileManager(self._toxes, profile_path)
self._profile_manager = ProfileManager(self._settings, self._toxes, profile_path)
data = self._profile_manager.open_profile() data = self._profile_manager.open_profile()
if self._toxes.is_data_encrypted(data): if self._toxes.is_data_encrypted(data):
data = self._enter_password(data) data = self._enter_password(data)
self._settings = Settings(self._toxes, profile_path.replace('.tox', '.json'))
self._tox = self._create_tox(data) self._tox = self._create_tox(data)
def _create_new_profile(self, profile_name): def _create_new_profile(self, profile_name):
@ -264,7 +265,7 @@ class App:
if result.password: if result.password:
self._toxes.set_password(result.password) self._toxes.set_password(result.password)
self._settings = Settings(self._toxes, self._path.replace('.tox', '.json')) 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: try:
self._save_profile() self._save_profile()
except Exception as ex: except Exception as ex:

View file

@ -163,7 +163,7 @@ class ContactsManager(ToxSave):
:param filter_str: show contacts which name contains this substring :param filter_str: show contacts which name contains this substring
""" """
filter_str = filter_str.lower() filter_str = filter_str.lower()
contact = self.get_curr_contact() current_contact = self.get_curr_contact()
if sorting > 5 or sorting < 0: if sorting > 5 or sorting < 0:
sorting = 0 sorting = 0
@ -189,7 +189,7 @@ class ContactsManager(ToxSave):
else: else:
self._contacts = sorted(self._contacts, key=lambda x: x.name.lower()) self._contacts = sorted(self._contacts, key=lambda x: x.name.lower())
# change item widgets # change item widgets
for index, contact in enumerate(self._contacts): for index, contact in enumerate(self._contacts):
list_item = self._screen.friends_list.item(index) list_item = self._screen.friends_list.item(index)
item_widget = self._screen.friends_list.itemWidget(list_item) item_widget = self._screen.friends_list.itemWidget(list_item)
@ -203,13 +203,15 @@ class ContactsManager(ToxSave):
item = self._screen.friends_list.item(index) item = self._screen.friends_list.item(index)
item_widget = self._screen.friends_list.itemWidget(item) item_widget = self._screen.friends_list.itemWidget(item)
item.setSizeHint(QtCore.QSize(250, item_widget.height() if friend.visibility else 0)) item.setSizeHint(QtCore.QSize(250, item_widget.height() if friend.visibility else 0))
# save soring results # save soring results
self._sorting, self._filter_string = sorting, filter_str self._sorting, self._filter_string = sorting, filter_str
self._settings['sorting'] = self._sorting self._settings['sorting'] = self._sorting
self._settings.save() self._settings.save()
# update active contact # update active contact
if contact is not None: if current_contact is not None:
index = self._contacts.index(contact) index = self._contacts.index(current_contact)
self.set_active(index) self.set_active(index)
def update_filtration(self): def update_filtration(self):

View file

@ -34,6 +34,7 @@ class GroupsService(tox_save.ToxSave):
self._add_new_group_by_number(group_number) self._add_new_group_by_number(group_number)
group = self._get_group_by_number(group_number) group = self._get_group_by_number(group_number)
group.status = constants.TOX_USER_STATUS['NONE'] group.status = constants.TOX_USER_STATUS['NONE']
self._contacts_manager.update_filtration()
def join_gc_by_id(self, chat_id, password, nick, status): def join_gc_by_id(self, chat_id, password, nick, status):
group_number = self._tox.group_join(chat_id, password, nick, status) group_number = self._tox.group_join(chat_id, password, nick, status)

View file

@ -28,7 +28,10 @@ class MessageAuthor:
def get_type(self): def get_type(self):
return self._type return self._type
type = property(get_type) def set_type(self, value):
self._type = value
type = property(get_type, set_type)
class Message: class Message:
@ -74,7 +77,7 @@ class Message:
self._widget = None self._widget = None
def mark_as_sent(self): def mark_as_sent(self):
self._author.author_type = MESSAGE_AUTHOR['ME'] self._author.type = MESSAGE_AUTHOR['ME']
if self._widget is not None: if self._widget is not None:
self._widget.mark_as_sent() self._widget.mark_as_sent()

View file

@ -654,7 +654,7 @@ class MainWindow(QtWidgets.QMainWindow):
clipboard.setText(text) clipboard.setText(text)
def clear_history(self, num): def clear_history(self, num):
self._contacts_manager.clear_history(num) self._history_loader.clear_history(num)
def auto_accept(self, num, value): def auto_accept(self, num, value):
tox_id = self._contacts_manager.friend_public_key(num) tox_id = self._contacts_manager.friend_public_key(num)

View file

@ -241,7 +241,7 @@ class ProfileSettings(CenteredWidget):
util_ui.tr('Use new path')) util_ui.tr('Use new path'))
self._settings.export(directory) self._settings.export(directory)
self._profile.export_db(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): def closeEvent(self, event):
self._profile.set_name(self.nick.text()) self._profile.set_name(self.nick.text())

View file

@ -7,8 +7,7 @@ class ProfileManager:
""" """
Class with methods for search, load and save profiles Class with methods for search, load and save profiles
""" """
def __init__(self, settings, toxes, path): def __init__(self, toxes, path):
self._settings = settings
self._toxes = toxes self._toxes = toxes
self._path = path self._path = path
self._directory = os.path.dirname(path) self._directory = os.path.dirname(path)
@ -38,7 +37,7 @@ class ProfileManager:
fl.write(data) fl.write(data)
print('Profile saved successfully') 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) path = new_path + os.path.basename(self._path)
with open(self._path, 'rb') as fin: with open(self._path, 'rb') as fin:
data = fin.read() data = fin.read()
@ -49,7 +48,7 @@ class ProfileManager:
if use_new_path: if use_new_path:
self._path = new_path + os.path.basename(self._path) self._path = new_path + os.path.basename(self._path)
self._directory = new_path self._directory = new_path
self._settings.update_path(new_path) settings.update_path(new_path)
@staticmethod @staticmethod
def find_profiles(): def find_profiles():