From f8eb1462e135d89ad443a05bbb107f2c17531a39 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Mon, 25 Apr 2016 15:48:56 +0300 Subject: [PATCH] contact blocking, friend requests fix, translations update --- src/callbacks.py | 7 +++- src/calls.py | 4 +- src/menu.py | 40 ++++++++++++++++--- src/profile.py | 50 ++++++++++++++++++------ src/settings.py | 3 +- src/tox.py | 4 +- src/translations/en_GB.qm | Bin 4585 -> 5176 bytes src/translations/en_GB.ts | 78 ++++++++++++++++++++++++++------------ src/translations/fr_FR.ts | 78 ++++++++++++++++++++++++++------------ src/translations/ru_RU.qm | Bin 6792 -> 7483 bytes src/translations/ru_RU.ts | 78 ++++++++++++++++++++++++++------------ 11 files changed, 245 insertions(+), 97 deletions(-) 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 74be0c1d52396271e29e5b10efbb1ff96d9ba399..a1c614f1a192d53c3d80d13c547137cca1f3541c 100644 GIT binary patch delta 662 zcmZvaJ!lhQ7{~wb5sZns+$D|e;_yN`v{Kw!VzezSap>SDE!09wbGZvS8gg(Sw&_p@ z9UK#1{6Nuc4vG%O!KrlVREk4CC=MNpP@ROLOF{6ts~)Y$amRD-J-_GwfBxLJ?8lx) zrgs6jmIv?#xZMEQDk7gEKx!J1{l|2^j@aNXy)QNght8`@Si776Vm}yb9|C6%n7#7> zkZ-W%covB6Nl&jV0?Av=M;8^b{fx@5k(c+k0A--LbtkRvM`xx=H1;5RFXIyUT1>Mp z_C? eEmdOlV<3qMGNS#>FB})0sA+zB!4mIMmwp4Bw3`_A8W 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 cc95d76db3379e4811d196f334ef050b28eebe90..fbdc886a13323b5e66f86b70d06c9d18af3318a1 100644 GIT binary patch delta 688 zcmZ{gOK1~O6o&sB4yMhcP12;3RIwK-_@I`yW=uMoNo^w%sslU9L0KFDHT3VCyU2W}}FO;!go|%(tV87|F$Y4QSVjBA zxnF>GE-$;@7aJ6BJh8p$@eY%pOd6qK8l@;r&}s4B8Q34DahjwE=`_|MZ^SP7_)b_B zuM~N%l+P9{KA$gF#9l4bDD;NesX_A6F$ppxWL(Zs36wB!ijxVBG*XzBGl>L@HqtXO zU!1$jXBT-oHO-R=Ljn84q{;NiPCRkj83?4>496y;TF#bKdcfEr9itdck**pk!tUsn z9$hU)*5Zm%ZnY3A+EV{EH8OifUS-k|b<-w?rIfJAEy56QcN zPD(6>;j|480|Q?SBje^@3=D$X82520Gca)9nz+=GeO}8|1_n`^iEqoa#8uhjqLP8e zF|ap_lrS)eaIjA}{*!@$osE6!g;F5x#L>9+F;Kj2axbG9li04wXBq9dM9X+Agy%Cb z2ppU&%cLhHx{o*H*A<{4GkE8w-2y7UI60O{gEfJ{VU!!i{B7jZlp 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