diff --git a/src/callbacks.py b/src/callbacks.py index 0102af6..5e813ba 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -130,9 +130,12 @@ def friend_request(tox, public_key, message, message_size, user_data): """ Called when user get new friend request """ + print 'Friend request' profile = Profile.get_instance() - tox_id = bin_to_string(public_key, TOX_PUBLIC_KEY_SIZE) - invoke_in_main_thread(profile.process_friend_request, tox_id, message.decode('utf-8')) + key = ''.join(chr(x) for x in public_key[:TOX_PUBLIC_KEY_SIZE]) + tox_id = bin_to_string(key, TOX_PUBLIC_KEY_SIZE) + if tox_id not in Settings.get_instance()['blocked']: + invoke_in_main_thread(profile.process_friend_request, tox_id, message.decode('utf-8')) # ----------------------------------------------------------------------------------------------------------------- # Callbacks - file transfers diff --git a/src/calls.py b/src/calls.py index 61bf361..7c4bbe8 100644 --- a/src/calls.py +++ b/src/calls.py @@ -67,7 +67,7 @@ class AV(object): rate=self._audio_rate, channels=self._audio_channels, input=True, - input_device_index=settings.Settings().get_instance().audio['input'], + input_device_index=settings.Settings.get_instance().audio['input'], frames_per_buffer=self._audio_sample_count * 10) self._audio_thread = threading.Thread(target=self.send_audio) @@ -100,7 +100,7 @@ class AV(object): self._out_stream = self._audio.open(format=pyaudio.paInt16, channels=channels_count, rate=rate, - output_device_index=settings.Settings().get_instance().audio['output'], + output_device_index=settings.Settings.get_instance().audio['output'], output=True) self._out_stream.write(samples) diff --git a/src/menu.py b/src/menu.py index 29e4d78..234741a 100644 --- a/src/menu.py +++ b/src/menu.py @@ -255,9 +255,9 @@ class PrivacySettings(CenteredWidget): def initUI(self): self.setObjectName("privacySettings") - self.resize(350, 400) - self.setMinimumSize(QtCore.QSize(350, 400)) - self.setMaximumSize(QtCore.QSize(350, 400)) + self.resize(350, 550) + self.setMinimumSize(QtCore.QSize(350, 550)) + self.setMaximumSize(QtCore.QSize(350, 550)) self.saveHistory = QtGui.QCheckBox(self) self.saveHistory.setGeometry(QtCore.QRect(40, 20, 291, 22)) self.saveHistory.setObjectName("saveHistory") @@ -275,10 +275,9 @@ class PrivacySettings(CenteredWidget): self.auto_path = QtGui.QLabel(self) self.auto_path.setGeometry(QtCore.QRect(40, 190, 350, 30)) self.path = QtGui.QPlainTextEdit(self) - self.path.setGeometry(QtCore.QRect(10, 240, 330, 30)) + self.path.setGeometry(QtCore.QRect(10, 225, 330, 45)) self.change_path = QtGui.QPushButton(self) - self.change_path.setGeometry(QtCore.QRect(125, 280, 100, 30)) - self.retranslateUi() + self.change_path.setGeometry(QtCore.QRect(10, 280, 330, 30)) settings = Settings.get_instance() self.typingNotifications.setChecked(settings['typing_notifications']) self.fileautoaccept.setChecked(settings['allow_auto_accept']) @@ -286,6 +285,22 @@ class PrivacySettings(CenteredWidget): self.inlines.setChecked(settings['allow_inline']) self.path.setPlainText(settings['auto_accept_path'] or curr_directory()) self.change_path.clicked.connect(self.new_path) + self.block_user_label = QtGui.QLabel(self) + self.block_user_label.setGeometry(QtCore.QRect(10, 320, 330, 30)) + self.block_id = QtGui.QPlainTextEdit(self) + self.block_id.setGeometry(QtCore.QRect(10, 350, 330, 30)) + self.block = QtGui.QPushButton(self) + self.block.setGeometry(QtCore.QRect(10, 390, 330, 30)) + self.block.clicked.connect(lambda: Profile.get_instance().block_user(self.block_id.toPlainText()) or self.close()) + self.blocked_users_label = QtGui.QLabel(self) + self.blocked_users_label.setGeometry(QtCore.QRect(10, 430, 330, 30)) + self.comboBox = QtGui.QComboBox(self) + self.comboBox.setGeometry(QtCore.QRect(10, 460, 330, 30)) + self.comboBox.addItems(settings['blocked']) + self.unblock = QtGui.QPushButton(self) + self.unblock.setGeometry(QtCore.QRect(10, 500, 330, 30)) + self.unblock.clicked.connect(lambda: self.unblock_user()) + self.retranslateUi() QtCore.QMetaObject.connectSlotsByName(self) def retranslateUi(self): @@ -296,6 +311,19 @@ class PrivacySettings(CenteredWidget): self.auto_path.setText(QtGui.QApplication.translate("privacySettings", "Auto accept default path:", None, QtGui.QApplication.UnicodeUTF8)) self.change_path.setText(QtGui.QApplication.translate("privacySettings", "Change", None, QtGui.QApplication.UnicodeUTF8)) self.inlines.setText(QtGui.QApplication.translate("privacySettings", "Allow inlines", None, QtGui.QApplication.UnicodeUTF8)) + self.block_user_label.setText(QtGui.QApplication.translate("privacySettings", "Block by TOX ID:", None, QtGui.QApplication.UnicodeUTF8)) + self.blocked_users_label.setText(QtGui.QApplication.translate("privacySettings", "Blocked users:", None, QtGui.QApplication.UnicodeUTF8)) + self.unblock.setText(QtGui.QApplication.translate("privacySettings", "Unblock", None, QtGui.QApplication.UnicodeUTF8)) + self.block.setText(QtGui.QApplication.translate("privacySettings", "Block user", None, QtGui.QApplication.UnicodeUTF8)) + + def unblock_user(self): + if not self.comboBox.count(): + return + title = QtGui.QApplication.translate("privacySettings", "Add to friend list", None, QtGui.QApplication.UnicodeUTF8) + info = QtGui.QApplication.translate("privacySettings", "Do you want to add this user to friend list?", None, QtGui.QApplication.UnicodeUTF8) + reply = QtGui.QMessageBox.question(None, title, info, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) + Profile.get_instance().unblock_user(self.comboBox.currentText(), reply == QtGui.QMessageBox.Yes) + self.close() def closeEvent(self, event): settings = Settings.get_instance() diff --git a/src/profile.py b/src/profile.py index 7bc5d98..51c5561 100644 --- a/src/profile.py +++ b/src/profile.py @@ -144,7 +144,8 @@ class Friend(Contact): def __del__(self): self.set_visibility(False) del self._widget - del self._message_getter + if hasattr(self, '_message_getter'): + del self._message_getter # ----------------------------------------------------------------------------------------------------------------- # History support @@ -626,7 +627,7 @@ class Profile(Contact, Singleton): self._messages.setItemWidget(elem, item) # ----------------------------------------------------------------------------------------------------------------- - # Work with friends (remove, set alias, get public key) + # Work with friends (remove, block, set alias, get public key) # ----------------------------------------------------------------------------------------------------------------- def set_alias(self, num): @@ -686,6 +687,40 @@ class Profile(Contact, Singleton): else: self.set_active(0) + def add_friend(self, tox_id): + num = self._tox.friend_add_norequest(tox_id) # num - friend number + item = self.create_friend_item() + try: + if not self._history.friend_exists_in_db(tox_id): + self._history.add_friend_to_db(tox_id) + message_getter = self._history.messages_getter(tox_id) + except Exception as ex: # something is wrong + log('Accept friend request failed! ' + str(ex)) + message_getter = None + friend = Friend(message_getter, num, tox_id, '', item, tox_id) + self._friends.append(friend) + + def block_user(self, tox_id): + tox_id = tox_id[:TOX_PUBLIC_KEY_SIZE * 2] + if tox_id == self.tox_id[:TOX_PUBLIC_KEY_SIZE * 2]: + return + settings = Settings.get_instance() + if tox_id not in settings['blocked']: + settings['blocked'].append(tox_id) + settings.save() + try: + num = self._tox.friend_by_public_key(tox_id) + self.delete_friend(num) + except: # not in friend list + pass + + def unblock_user(self, tox_id, add_to_friend_list): + s = Settings.get_instance() + s['blocked'].remove(tox_id) + s.save() + if add_to_friend_list: + self.add_friend(tox_id) + # ----------------------------------------------------------------------------------------------------------------- # Friend requests # ----------------------------------------------------------------------------------------------------------------- @@ -728,16 +763,7 @@ class Profile(Contact, Singleton): fr_req = QtGui.QApplication.translate('MainWindow', 'Friend request', None, QtGui.QApplication.UnicodeUTF8) reply = QtGui.QMessageBox.question(None, fr_req, info, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) if reply == QtGui.QMessageBox.Yes: # accepted - num = self._tox.friend_add_norequest(tox_id) # num - friend number - item = self.create_friend_item() - try: - if not self._history.friend_exists_in_db(tox_id): - self._history.add_friend_to_db(tox_id) - message_getter = self._history.messages_getter(tox_id) - except Exception as ex: # something is wrong - log('Accept friend request failed! ' + str(ex)) - friend = Friend(message_getter, num, tox_id, '', item, tox_id) - self._friends.append(friend) + self.add_friend(tox_id) except Exception as ex: # something is wrong log('Accept friend request failed! ' + str(ex)) diff --git a/src/settings.py b/src/settings.py index f6bbc40..e1b6986 100644 --- a/src/settings.py +++ b/src/settings.py @@ -8,7 +8,7 @@ import pyaudio class Settings(Singleton, dict): - def __init__(self, name=''): + def __init__(self, name): self.path = ProfileHelper.get_path() + str(name) + '.json' self.name = name if os.path.isfile(self.path): @@ -79,6 +79,7 @@ class Settings(Singleton, dict): default = Settings.get_default_settings() for key in default: if key not in self: + print key self[key] = default[key] self.save() diff --git a/src/tox.py b/src/tox.py index 3752842..da18b7e 100644 --- a/src/tox.py +++ b/src/tox.py @@ -984,13 +984,13 @@ class Tox(object): This event is triggered when a friend request is received. :param callback: Python function. Should take pointer (c_void_p) to Tox object, - The Public Key (c_char_p) of the user who sent the friend request, + The Public Key (c_uint8 array) of the user who sent the friend request, The message (c_char_p) they sent along with the request, The size (c_size_t) of the message byte array, pointer (c_void_p) to user_data :param user_data: pointer (c_void_p) to user data """ - c_callback = CFUNCTYPE(None, c_void_p, c_char_p, c_char_p, c_size_t, c_void_p) + c_callback = CFUNCTYPE(None, c_void_p, POINTER(c_uint8), c_char_p, c_size_t, c_void_p) self.friend_request_cb = c_callback(callback) Tox.libtoxcore.tox_callback_friend_request(self._tox_pointer, self.friend_request_cb, c_void_p(user_data)) diff --git a/src/translations/en_GB.qm b/src/translations/en_GB.qm index 74be0c1..a1c614f 100644 Binary files a/src/translations/en_GB.qm and b/src/translations/en_GB.qm differ diff --git a/src/translations/en_GB.ts b/src/translations/en_GB.ts index 0cce13e..ee1a663 100644 --- a/src/translations/en_GB.ts +++ b/src/translations/en_GB.ts @@ -105,13 +105,13 @@ - + User {} wants to add you to contact list. Message: {} - + Friend request @@ -156,7 +156,7 @@ - + Enter new alias for friend {} or leave empty to use friend's name: Enter new alias for friend {} or leave empty to use friend's name: @@ -225,17 +225,17 @@ audioSettingsForm - + Audio settings Audio settings - + Input device: Input device: - + Output device: Output device: @@ -243,12 +243,12 @@ incoming_call - + Incoming video call Incoming video call - + Incoming audio call Incoming audio call @@ -256,17 +256,17 @@ interfaceForm - + Interface settings - + Theme: - + Language: @@ -322,22 +322,22 @@ notificationsForm - + Notification settings - + Enable notifications - + Enable call's sound - + Enable sound notifications @@ -345,50 +345,80 @@ privacySettings - + Privacy settings - + Save chat history - + Allow file auto accept - + Send typing notifications - + Auto accept default path: - + Change - + Allow inlines - + Chat history - + History will be cleaned! Continue? + + + Blocked users: + Blocked users: + + + + Unblock + Unblock + + + + Block user + Block user + + + + Add to friend list + Add to friend list + + + + Do you want to add this user to friend list? + Do you want to add this user to friend list? + + + + Block by TOX ID: + Block by TOX ID: + tray diff --git a/src/translations/fr_FR.ts b/src/translations/fr_FR.ts index 95f4a8a..5e5ef6d 100644 --- a/src/translations/fr_FR.ts +++ b/src/translations/fr_FR.ts @@ -104,13 +104,13 @@ À propos du programme - + User {} wants to add you to contact list. Message: {} L'Utilisateur {} veut vout rajouter à sa liste de contacts. Message : {} - + Friend request Demande d'amis @@ -155,7 +155,7 @@ Retirer un ami - + Enter new alias for friend {} or leave empty to use friend's name: @@ -224,17 +224,17 @@ audioSettingsForm - + Audio settings - + Input device: - + Output device: @@ -242,12 +242,12 @@ incoming_call - + Incoming video call - + Incoming audio call @@ -255,17 +255,17 @@ interfaceForm - + Interface settings Paramêtres de l'interface - + Theme: Thème : - + Language: Langue : @@ -321,22 +321,22 @@ notificationsForm - + Notification settings Paramêtres de notification - + Enable notifications Activer les notifications - + Enable call's sound Activer les sons d'appel - + Enable sound notifications Activer les sons de notifications @@ -344,50 +344,80 @@ privacySettings - + Privacy settings Paramêtres de confidentialité - + Save chat history Sauvegarder l'historique du chat - + Allow file auto accept Autoriser les fichier automatiquement - + Send typing notifications Notifier la frappe - + Auto accept default path: Chemin d'accès des fichiers acceptés automatiquement : - + Change Modifier - + Allow inlines - + Chat history - + History will be cleaned! Continue? + + + Blocked users: + + + + + Unblock + + + + + Block user + + + + + Add to friend list + + + + + Do you want to add this user to friend list? + + + + + Block by TOX ID: + + tray diff --git a/src/translations/ru_RU.qm b/src/translations/ru_RU.qm index cc95d76..fbdc886 100644 Binary files a/src/translations/ru_RU.qm and b/src/translations/ru_RU.qm differ diff --git a/src/translations/ru_RU.ts b/src/translations/ru_RU.ts index 434fb92..8b5844f 100644 --- a/src/translations/ru_RU.ts +++ b/src/translations/ru_RU.ts @@ -105,14 +105,14 @@ О программе - + User {} wants to add you to contact list. Message: {} Пользователь {} хочет добавить Вас в список контактов. Сообщение: {} - + Friend request Запрос на добавление в друзья @@ -157,7 +157,7 @@ Удалить друга - + Enter new alias for friend {} or leave empty to use friend's name: Введите новый псевдоним для друга {} или оставьте пустым для использования его имени: @@ -231,17 +231,17 @@ audioSettingsForm - + Audio settings Настройки аудио - + Input device: Устройство ввода: - + Output device: Устройство вывода: @@ -249,12 +249,12 @@ incoming_call - + Incoming video call Входящий видеозвонок - + Incoming audio call Входящий аудиозвонок @@ -262,17 +262,17 @@ interfaceForm - + Interface settings Настройки интерфейса - + Theme: Тема: - + Language: Язык: @@ -328,22 +328,22 @@ notificationsForm - + Notification settings Настройки уведомлений - + Enable notifications Включить уведомления - + Enable call's sound Включить звук звонка - + Enable sound notifications Включить звуковые уведомления @@ -352,50 +352,80 @@ privacySettings - + Privacy settings Настройки приватности - + Save chat history Сохранять историю переписки - + Allow file auto accept Разрешить автополучение файлов - + Send typing notifications Посылать уведомления о наборе текста - + Auto accept default path: Путь автоприема файлов: - + Change Изменить - + Allow inlines Разрешать инлайны - + Chat history История чата - + History will be cleaned! Continue? История переписки будет очищена! Продолжить? + + + Blocked users: + Заблокированные пользователи: + + + + Unblock + Разблокировать + + + + Block user + Заблокировать пользователя + + + + Add to friend list + Добавить в список друзей + + + + Do you want to add this user to friend list? + Добавить этого пользователя в список друзей? + + + + Block by TOX ID: + Блокировать по TOX ID: + tray