chat menu
This commit is contained in:
parent
8e6d37e23c
commit
19893c5c28
2 changed files with 67 additions and 19 deletions
|
@ -590,6 +590,8 @@ class MainWindow(QtWidgets.QMainWindow, Singleton):
|
||||||
auto = QtWidgets.QApplication.translate("MainWindow", 'Disallow auto accept') if allowed else QtWidgets.QApplication.translate("MainWindow", 'Allow auto accept')
|
auto = QtWidgets.QApplication.translate("MainWindow", 'Disallow auto accept') if allowed else QtWidgets.QApplication.translate("MainWindow", 'Allow auto accept')
|
||||||
if item is not None:
|
if item is not None:
|
||||||
self.listMenu = QtWidgets.QMenu()
|
self.listMenu = QtWidgets.QMenu()
|
||||||
|
is_friend = type(friend) is Friend
|
||||||
|
if is_friend:
|
||||||
set_alias_item = self.listMenu.addAction(QtWidgets.QApplication.translate("MainWindow", 'Set alias'))
|
set_alias_item = self.listMenu.addAction(QtWidgets.QApplication.translate("MainWindow", 'Set alias'))
|
||||||
|
|
||||||
history_menu = self.listMenu.addMenu(QtWidgets.QApplication.translate("MainWindow", 'Chat history'))
|
history_menu = self.listMenu.addMenu(QtWidgets.QApplication.translate("MainWindow", 'Chat history'))
|
||||||
|
@ -600,6 +602,7 @@ class MainWindow(QtWidgets.QMainWindow, Singleton):
|
||||||
copy_menu = self.listMenu.addMenu(QtWidgets.QApplication.translate("MainWindow", 'Copy'))
|
copy_menu = self.listMenu.addMenu(QtWidgets.QApplication.translate("MainWindow", 'Copy'))
|
||||||
copy_name_item = copy_menu.addAction(QtWidgets.QApplication.translate("MainWindow", 'Name'))
|
copy_name_item = copy_menu.addAction(QtWidgets.QApplication.translate("MainWindow", 'Name'))
|
||||||
copy_status_item = copy_menu.addAction(QtWidgets.QApplication.translate("MainWindow", 'Status message'))
|
copy_status_item = copy_menu.addAction(QtWidgets.QApplication.translate("MainWindow", 'Status message'))
|
||||||
|
if is_friend:
|
||||||
copy_key_item = copy_menu.addAction(QtWidgets.QApplication.translate("MainWindow", 'Public key'))
|
copy_key_item = copy_menu.addAction(QtWidgets.QApplication.translate("MainWindow", 'Public key'))
|
||||||
|
|
||||||
auto_accept_item = self.listMenu.addAction(auto)
|
auto_accept_item = self.listMenu.addAction(auto)
|
||||||
|
@ -614,12 +617,17 @@ class MainWindow(QtWidgets.QMainWindow, Singleton):
|
||||||
plug = self.listMenu.addMenu(QtWidgets.QApplication.translate("MainWindow", 'Plugins'))
|
plug = self.listMenu.addMenu(QtWidgets.QApplication.translate("MainWindow", 'Plugins'))
|
||||||
plug.addActions(submenu)
|
plug.addActions(submenu)
|
||||||
set_alias_item.triggered.connect(lambda: self.set_alias(num))
|
set_alias_item.triggered.connect(lambda: self.set_alias(num))
|
||||||
|
copy_key_item.triggered.connect(lambda: self.copy_friend_key(num))
|
||||||
remove_item.triggered.connect(lambda: self.remove_friend(num))
|
remove_item.triggered.connect(lambda: self.remove_friend(num))
|
||||||
block_item.triggered.connect(lambda: self.block_friend(num))
|
block_item.triggered.connect(lambda: self.block_friend(num))
|
||||||
copy_key_item.triggered.connect(lambda: self.copy_friend_key(num))
|
|
||||||
clear_history_item.triggered.connect(lambda: self.clear_history(num))
|
|
||||||
auto_accept_item.triggered.connect(lambda: self.auto_accept(num, not allowed))
|
auto_accept_item.triggered.connect(lambda: self.auto_accept(num, not allowed))
|
||||||
notes_item.triggered.connect(lambda: self.show_note(friend))
|
notes_item.triggered.connect(lambda: self.show_note(friend))
|
||||||
|
else:
|
||||||
|
leave_item = self.listMenu.addAction(QtWidgets.QApplication.translate("MainWindow", 'Leave chat'))
|
||||||
|
set_title_item = self.listMenu.addAction(QtWidgets.QApplication.translate("MainWindow", 'Set title'))
|
||||||
|
leave_item.triggered.connect(lambda: self.leave_gc(num))
|
||||||
|
set_title_item.triggered.connect(lambda: self.set_title(num))
|
||||||
|
clear_history_item.triggered.connect(lambda: self.clear_history(num))
|
||||||
copy_name_item.triggered.connect(lambda: self.copy_name(friend))
|
copy_name_item.triggered.connect(lambda: self.copy_name(friend))
|
||||||
copy_status_item.triggered.connect(lambda: self.copy_status(friend))
|
copy_status_item.triggered.connect(lambda: self.copy_status(friend))
|
||||||
export_to_text_item.triggered.connect(lambda: self.export_history(num))
|
export_to_text_item.triggered.connect(lambda: self.export_history(num))
|
||||||
|
@ -682,6 +690,12 @@ class MainWindow(QtWidgets.QMainWindow, Singleton):
|
||||||
def clear_history(self, num):
|
def clear_history(self, num):
|
||||||
self.profile.clear_history(num)
|
self.profile.clear_history(num)
|
||||||
|
|
||||||
|
def leave_gc(self, num):
|
||||||
|
self.profile.leave_gc(num)
|
||||||
|
|
||||||
|
def set_title(self, num):
|
||||||
|
self.profile.set_title(num)
|
||||||
|
|
||||||
def auto_accept(self, num, value):
|
def auto_accept(self, num, value):
|
||||||
settings = Settings.get_instance()
|
settings = Settings.get_instance()
|
||||||
tox_id = self.profile.friend_public_key(num)
|
tox_id = self.profile.friend_public_key(num)
|
||||||
|
|
|
@ -883,7 +883,7 @@ class Profile(basecontact.BaseContact, Singleton):
|
||||||
QtCore.QTimer.singleShot(50000, self.reconnect)
|
QtCore.QTimer.singleShot(50000, self.reconnect)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
for friend in self._contacts:
|
for friend in map(lambda x: type(x) is Friend, self._contacts):
|
||||||
self.friend_exit(friend.number)
|
self.friend_exit(friend.number)
|
||||||
for i in range(len(self._contacts)):
|
for i in range(len(self._contacts)):
|
||||||
del self._contacts[0]
|
del self._contacts[0]
|
||||||
|
@ -1305,6 +1305,17 @@ class Profile(basecontact.BaseContact, Singleton):
|
||||||
number = self._tox.add_av_groupchat()
|
number = self._tox.add_av_groupchat()
|
||||||
self.add_gc(number)
|
self.add_gc(number)
|
||||||
|
|
||||||
|
def leave_gc(self, num):
|
||||||
|
gc = self._contacts[num]
|
||||||
|
self._tox.del_groupchat(gc.number)
|
||||||
|
del self._contacts[num]
|
||||||
|
self._screen.friends_list.takeItem(num)
|
||||||
|
if num == self._active_friend: # active friend was deleted
|
||||||
|
if not len(self._contacts): # last friend was deleted
|
||||||
|
self.set_active(-1)
|
||||||
|
else:
|
||||||
|
self.set_active(0)
|
||||||
|
|
||||||
def group_invite(self, friend_number, gc_type, data):
|
def group_invite(self, friend_number, gc_type, data):
|
||||||
text = QtWidgets.QApplication.translate('MainWindow', 'User {} invites you to group chat. Accept?')
|
text = QtWidgets.QApplication.translate('MainWindow', 'User {} invites you to group chat. Accept?')
|
||||||
title = QtWidgets.QApplication.translate('MainWindow', 'Group chat invite')
|
title = QtWidgets.QApplication.translate('MainWindow', 'Group chat invite')
|
||||||
|
@ -1353,6 +1364,29 @@ class Profile(basecontact.BaseContact, Singleton):
|
||||||
self._tox.group_message_send(group_number, text.encode('utf-8'))
|
self._tox.group_message_send(group_number, text.encode('utf-8'))
|
||||||
self._screen.messageEdit.clear()
|
self._screen.messageEdit.clear()
|
||||||
|
|
||||||
|
def set_title(self, num):
|
||||||
|
"""
|
||||||
|
Set new title for gc
|
||||||
|
"""
|
||||||
|
gc = self._contacts[num]
|
||||||
|
name = gc.name
|
||||||
|
dialog = QtWidgets.QApplication.translate('MainWindow',
|
||||||
|
"Enter new title for group {}:")
|
||||||
|
dialog = dialog.format(name)
|
||||||
|
title = QtWidgets.QApplication.translate('MainWindow',
|
||||||
|
'Set title')
|
||||||
|
text, ok = QtWidgets.QInputDialog.getText(None,
|
||||||
|
title,
|
||||||
|
dialog,
|
||||||
|
QtWidgets.QLineEdit.Normal,
|
||||||
|
name)
|
||||||
|
if ok:
|
||||||
|
text = text.encode('utf-8')
|
||||||
|
self._tox.group_set_title(gc.number, text)
|
||||||
|
self.new_gc_title(gc.number, text)
|
||||||
|
if num == self.get_active_number() and not self.is_active_a_friend():
|
||||||
|
self.update()
|
||||||
|
|
||||||
|
|
||||||
def tox_factory(data=None, settings=None):
|
def tox_factory(data=None, settings=None):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue