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 @@
-
+
-
+
@@ -156,7 +156,7 @@
-
+
Enter new alias for friend {} or leave empty to use friend's name:
@@ -225,17 +225,17 @@
audioSettingsForm
-
+
Audio settings
-
+
Input device:
-
+
Output device:
@@ -243,12 +243,12 @@
incoming_call
-
+
Incoming video call
-
+
Incoming audio call
@@ -256,17 +256,17 @@
interfaceForm
-
+
-
+
-
+
@@ -322,22 +322,22 @@
notificationsForm
-
+
-
+
-
+
-
+
@@ -345,50 +345,80 @@
privacySettings
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
+
+
+
+ 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/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
-
+
L'Utilisateur {} veut vout rajouter à sa liste de contacts. Message : {}
-
+
Demande d'amis
@@ -155,7 +155,7 @@
Retirer un ami
-
+
@@ -224,17 +224,17 @@
audioSettingsForm
-
+
-
+
-
+
@@ -242,12 +242,12 @@
incoming_call
-
+
-
+
@@ -255,17 +255,17 @@
interfaceForm
-
+
Paramêtres de l'interface
-
+
Thème :
-
+
Langue :
@@ -321,22 +321,22 @@
notificationsForm
-
+
Paramêtres de notification
-
+
Activer les notifications
-
+
Activer les sons d'appel
-
+
Activer les sons de notifications
@@ -344,50 +344,80 @@
privacySettings
-
+
Paramêtres de confidentialité
-
+
Sauvegarder l'historique du chat
-
+
Autoriser les fichier automatiquement
-
+
Notifier la frappe
-
+
Chemin d'accès des fichiers acceptés automatiquement :
-
+
Modifier
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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 @@
О программе
-
+
Пользователь {} хочет добавить Вас в список контактов. Сообщение:
{}
-
+
Запрос на добавление в друзья
@@ -157,7 +157,7 @@
Удалить друга
-
+
Введите новый псевдоним для друга {} или оставьте пустым для использования его имени:
@@ -231,17 +231,17 @@
audioSettingsForm
-
+
Настройки аудио
-
+
Устройство ввода:
-
+
Устройство вывода:
@@ -249,12 +249,12 @@
incoming_call
-
+
Входящий видеозвонок
-
+
Входящий аудиозвонок
@@ -262,17 +262,17 @@
interfaceForm
-
+
Настройки интерфейса
-
+
Тема:
-
+
Язык:
@@ -328,22 +328,22 @@
notificationsForm
-
+
Настройки уведомлений
-
+
Включить уведомления
-
+
Включить звук звонка
-
+
Включить звуковые уведомления
@@ -352,50 +352,80 @@
privacySettings
-
+
Настройки приватности
-
+
Сохранять историю переписки
-
+
Разрешить автополучение файлов
-
+
Посылать уведомления о наборе текста
-
+
Путь автоприема файлов:
-
+
Изменить
-
+
Разрешать инлайны
-
+
История чата
-
+
История переписки будет очищена! Продолжить?
+
+
+
+ Заблокированные пользователи:
+
+
+
+
+ Разблокировать
+
+
+
+
+ Заблокировать пользователя
+
+
+
+
+ Добавить в список друзей
+
+
+
+
+ Добавить этого пользователя в список друзей?
+
+
+
+
+ Блокировать по TOX ID:
+
tray