From 9a580824960aa255ea8986ddae943bae4544ee7f Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Thu, 13 Sep 2018 23:04:22 +0300 Subject: [PATCH] bug fixes --- toxygen/app.py | 10 ++-- toxygen/file_transfers/file_transfers.py | 2 +- .../file_transfers/file_transfers_handler.py | 6 +-- toxygen/messenger/messenger.py | 16 +++---- toxygen/middleware/callbacks.py | 47 ------------------- toxygen/wrapper/tox.py | 7 +-- toxygen/wrapper/toxav.py | 5 +- 7 files changed, 24 insertions(+), 69 deletions(-) diff --git a/toxygen/app.py b/toxygen/app.py index 4bca27c..18e5236 100644 --- a/toxygen/app.py +++ b/toxygen/app.py @@ -107,8 +107,8 @@ class App: self._tray.hide() self._save_profile() self._settings.close() - self._unset_callbacks() self._kill_toxav() + self._kill_tox() del self._tox # ----------------------------------------------------------------------------------------------------------------- @@ -320,8 +320,8 @@ class App: self._stop_threads(False) data = self._tox.get_savedata() self._save_profile(data) - self._unset_callbacks() self._kill_toxav() + self._kill_tox() del self._tox # create new tox instance self._tox = self._create_tox(data) @@ -410,9 +410,6 @@ class App: self._calls_manager, self._file_transfer_handler, self._ms, self._tray, self._messenger, self._groups_service, self._contacts_provider) - def _unset_callbacks(self): - callbacks.unset_callbacks(self._tox) - def _init_profile(self): if not self._profile.has_avatar(): self._profile.reset_avatar(self._settings['identicons']) @@ -420,3 +417,6 @@ class App: def _kill_toxav(self): self._calls_manager.set_toxav(None) self._tox.AV.kill() + + def _kill_tox(self): + self._tox.kill() diff --git a/toxygen/file_transfers/file_transfers.py b/toxygen/file_transfers/file_transfers.py index 46a777f..445dac9 100644 --- a/toxygen/file_transfers/file_transfers.py +++ b/toxygen/file_transfers/file_transfers.py @@ -29,7 +29,7 @@ SHOW_PROGRESS_BAR = (0, 1, 4) def is_inline(file_name): allowed_inlines = ('toxygen_inline.png', 'utox-inline.png', 'sticker.png') - return file_name in allowed_inlines or file_name.startswith('qTox_Screenshot_') + return file_name in allowed_inlines or file_name.startswith('qTox_Image_') class FileTransfer: diff --git a/toxygen/file_transfers/file_transfers_handler.py b/toxygen/file_transfers/file_transfers_handler.py index d462c89..cde1795 100644 --- a/toxygen/file_transfers/file_transfers_handler.py +++ b/toxygen/file_transfers/file_transfers_handler.py @@ -257,7 +257,7 @@ class FileTransfersHandler(ToxSave): elif not size: friend.reset_avatar(self._settings['identicons']) - def _send_avatar_to_contacts(self): + def _send_avatar_to_contacts(self, _): friends = self._get_all_friends() for friend in friends: self.send_avatar(friend.number) @@ -286,13 +286,13 @@ class FileTransfersHandler(ToxSave): path, file_name = os.path.split(path) new_file_name, i = file_name, 1 if not from_position: - while os.path.isfile(path + '/' + new_file_name): # file with same name already exists + while os.path.isfile(join_path(path, new_file_name)): # file with same name already exists if '.' in file_name: # has extension d = file_name.rindex('.') else: # no extension d = len(file_name) new_file_name = file_name[:d] + ' ({})'.format(i) + file_name[d:] i += 1 - path = os.path.join(path, new_file_name) + path = join_path(path, new_file_name) return path diff --git a/toxygen/messenger/messenger.py b/toxygen/messenger/messenger.py index 9ee86dd..e859135 100644 --- a/toxygen/messenger/messenger.py +++ b/toxygen/messenger/messenger.py @@ -224,7 +224,7 @@ class Messenger(tox_save.ToxSave): return message = util_ui.tr('User {} is now known as {}') message = message.format(old_name, new_name) - if self._contacts_manager.is_friend_active(friend.number): + if not self._contacts_manager.is_friend_active(friend.number): friend.actions = True self._add_info_message(friend.number, message) @@ -236,14 +236,14 @@ class Messenger(tox_save.ToxSave): def _split_message(message): messages = [] while len(message) > TOX_MAX_MESSAGE_LENGTH: - size = TOX_MAX_MESSAGE_LENGTH * 4 / 5 + size = TOX_MAX_MESSAGE_LENGTH * 4 // 5 last_part = message[size:TOX_MAX_MESSAGE_LENGTH] - if ' ' in last_part: - index = last_part.index(' ') - elif ',' in last_part: - index = last_part.index(',') - elif '.' in last_part: - index = last_part.index('.') + if b' ' in last_part: + index = last_part.index(b' ') + elif b',' in last_part: + index = last_part.index(b',') + elif b'.' in last_part: + index = last_part.index(b'.') else: index = TOX_MAX_MESSAGE_LENGTH - size - 1 index += size + 1 diff --git a/toxygen/middleware/callbacks.py b/toxygen/middleware/callbacks.py index 5fcce03..77a029d 100644 --- a/toxygen/middleware/callbacks.py +++ b/toxygen/middleware/callbacks.py @@ -604,50 +604,3 @@ def init_callbacks(tox, profile, settings, plugin_loader, contacts_manager, tox.callback_group_password(group_password(contacts_provider), 0) tox.callback_group_peer_limit(group_peer_limit(contacts_provider), 0) tox.callback_group_privacy_state(group_privacy_state(contacts_provider), 0) - - -def unset_callbacks(tox): - # self callbacks - tox.callback_self_connection_status(0) - - # friend callbacks - tox.callback_friend_status(0) - tox.callback_friend_message(0) - tox.callback_friend_connection_status(0) - tox.callback_friend_name(0) - tox.callback_friend_status_message(0) - tox.callback_friend_request(0) - tox.callback_friend_typing(0) - tox.callback_friend_read_receipt(0) - - # file transfer - tox.callback_file_recv(0) - tox.callback_file_recv_chunk(0) - tox.callback_file_chunk_request(0) - tox.callback_file_recv_control(0) - - # av - toxav = tox.AV - toxav.callback_call_state(0, 0) - toxav.callback_call(0, 0) - toxav.callback_audio_receive_frame(0, 0) - toxav.callback_video_receive_frame(0, 0) - - # custom packets - tox.callback_friend_lossless_packet(0) - tox.callback_friend_lossy_packet(0) - - # gc callbacks - tox.callback_group_message(0, 0) - tox.callback_group_private_message(0, 0) - tox.callback_group_invite(0, 0) - tox.callback_group_self_join(0, 0) - tox.callback_group_peer_join(0, 0) - tox.callback_group_peer_exit(0, 0) - tox.callback_group_peer_name(0, 0) - tox.callback_group_peer_status(0, 0) - tox.callback_group_topic(0, 0) - tox.callback_group_moderation(0, 0) - tox.callback_group_password(0, 0) - tox.callback_group_peer_limit(0, 0) - tox.callback_group_privacy_state(0, 0) diff --git a/toxygen/wrapper/tox.py b/toxygen/wrapper/tox.py index 1ba0bbc..21b0ebc 100644 --- a/toxygen/wrapper/tox.py +++ b/toxygen/wrapper/tox.py @@ -59,8 +59,9 @@ class Tox: self._tox_pointer = tox_pointer else: tox_err_new = c_int() - Tox.libtoxcore.tox_new.restype = POINTER(c_void_p) - self._tox_pointer = Tox.libtoxcore.tox_new(tox_options, byref(tox_err_new)) + f = Tox.libtoxcore.tox_new + f.restype = POINTER(c_void_p) + self._tox_pointer = f(tox_options, byref(tox_err_new)) tox_err_new = tox_err_new.value if tox_err_new == TOX_ERR_NEW['NULL']: raise ArgumentError('One of the arguments to the function was NULL when it was not expected.') @@ -120,7 +121,7 @@ class Tox: self.AV = ToxAV(self._tox_pointer) - def __del__(self): + def kill(self): del self.AV Tox.libtoxcore.tox_kill(self._tox_pointer) diff --git a/toxygen/wrapper/toxav.py b/toxygen/wrapper/toxav.py index be61309..98e1c73 100644 --- a/toxygen/wrapper/toxav.py +++ b/toxygen/wrapper/toxav.py @@ -24,8 +24,9 @@ class ToxAV: """ self.libtoxav = LibToxAV() toxav_err_new = c_int() - self.libtoxav.toxav_new.restype = POINTER(c_void_p) - self._toxav_pointer = self.libtoxav.toxav_new(tox_pointer, byref(toxav_err_new)) + f = self.libtoxav.toxav_new + f.restype = POINTER(c_void_p) + self._toxav_pointer = f(tox_pointer, byref(toxav_err_new)) toxav_err_new = toxav_err_new.value if toxav_err_new == TOXAV_ERR_NEW['NULL']: raise ArgumentError('One of the arguments to the function was NULL when it was not expected.')