contacts menu history fixes
This commit is contained in:
parent
531fa81bba
commit
6e07d3e3d4
@ -319,6 +319,7 @@ class App:
|
|||||||
self._stop_threads(False)
|
self._stop_threads(False)
|
||||||
data = self._tox.get_savedata()
|
data = self._tox.get_savedata()
|
||||||
self._save_profile(data)
|
self._save_profile(data)
|
||||||
|
self._calls_manager.set_toxav(None)
|
||||||
del self._tox
|
del self._tox
|
||||||
# create new tox instance
|
# create new tox instance
|
||||||
self._tox = self._create_tox(data)
|
self._tox = self._create_tox(data)
|
||||||
|
@ -87,9 +87,13 @@ class BaseContactMenuGenerator:
|
|||||||
def __init__(self, contact):
|
def __init__(self, contact):
|
||||||
self._contact = contact
|
self._contact = contact
|
||||||
|
|
||||||
def generate(self, plugin_loader, contacts_manager, main_screen, settings, number, groups_service):
|
def generate(self, plugin_loader, contacts_manager, main_screen, settings, number, groups_service, history_loader):
|
||||||
return ContactMenuBuilder().build()
|
return ContactMenuBuilder().build()
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
# Private methods
|
||||||
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
def _generate_copy_menu_builder(self, main_screen):
|
def _generate_copy_menu_builder(self, main_screen):
|
||||||
copy_menu_builder = ContactMenuBuilder()
|
copy_menu_builder = ContactMenuBuilder()
|
||||||
(copy_menu_builder
|
(copy_menu_builder
|
||||||
@ -101,11 +105,23 @@ class BaseContactMenuGenerator:
|
|||||||
|
|
||||||
return copy_menu_builder
|
return copy_menu_builder
|
||||||
|
|
||||||
|
def _generate_history_menu_builder(self, history_loader, main_screen):
|
||||||
|
history_menu_builder = ContactMenuBuilder()
|
||||||
|
(history_menu_builder
|
||||||
|
.with_name(util_ui.tr('Chat history'))
|
||||||
|
.with_action(util_ui.tr('Clear history'), lambda: history_loader.clear_history(self._contact)
|
||||||
|
and main_screen.messages.clear())
|
||||||
|
.with_action(util_ui.tr('Export as text'), lambda: history_loader.export_history(self._contact))
|
||||||
|
.with_action(util_ui.tr('Export as HTML'), lambda: history_loader.export_history(self._contact, False))
|
||||||
|
)
|
||||||
|
|
||||||
|
return history_menu_builder
|
||||||
|
|
||||||
|
|
||||||
class FriendMenuGenerator(BaseContactMenuGenerator):
|
class FriendMenuGenerator(BaseContactMenuGenerator):
|
||||||
|
|
||||||
def generate(self, plugin_loader, contacts_manager, main_screen, settings, number, groups_service):
|
def generate(self, plugin_loader, contacts_manager, main_screen, settings, number, groups_service, history_loader):
|
||||||
history_menu_builder = self._generate_history_menu_builder(main_screen, number)
|
history_menu_builder = self._generate_history_menu_builder(history_loader, main_screen)
|
||||||
copy_menu_builder = self._generate_copy_menu_builder(main_screen)
|
copy_menu_builder = self._generate_copy_menu_builder(main_screen)
|
||||||
plugins_menu_builder = self._generate_plugins_menu_builder(plugin_loader, number)
|
plugins_menu_builder = self._generate_plugins_menu_builder(plugin_loader, number)
|
||||||
groups_menu_builder = self._generate_groups_menu(contacts_manager, groups_service)
|
groups_menu_builder = self._generate_groups_menu(contacts_manager, groups_service)
|
||||||
@ -132,18 +148,6 @@ class FriendMenuGenerator(BaseContactMenuGenerator):
|
|||||||
# Private methods
|
# Private methods
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _generate_history_menu_builder(main_screen, number):
|
|
||||||
history_menu_builder = ContactMenuBuilder()
|
|
||||||
(history_menu_builder
|
|
||||||
.with_name(util_ui.tr('Chat history'))
|
|
||||||
.with_action(util_ui.tr('Clear history'), lambda: main_screen.clear_history(number))
|
|
||||||
.with_action(util_ui.tr('Export as text'), lambda: main_screen.export_history(number))
|
|
||||||
.with_action(util_ui.tr('Export as HTML'), lambda: main_screen.export_history(number, False))
|
|
||||||
)
|
|
||||||
|
|
||||||
return history_menu_builder
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _generate_plugins_menu_builder(plugin_loader, number):
|
def _generate_plugins_menu_builder(plugin_loader, number):
|
||||||
if plugin_loader is None:
|
if plugin_loader is None:
|
||||||
@ -174,13 +178,15 @@ class FriendMenuGenerator(BaseContactMenuGenerator):
|
|||||||
|
|
||||||
class GroupMenuGenerator(BaseContactMenuGenerator):
|
class GroupMenuGenerator(BaseContactMenuGenerator):
|
||||||
|
|
||||||
def generate(self, plugin_loader, contacts_manager, main_screen, settings, number, groups_service):
|
def generate(self, plugin_loader, contacts_manager, main_screen, settings, number, groups_service, history_loader):
|
||||||
copy_menu_builder = self._generate_copy_menu_builder(main_screen)
|
copy_menu_builder = self._generate_copy_menu_builder(main_screen)
|
||||||
|
history_menu_builder = self._generate_history_menu_builder(history_loader, main_screen)
|
||||||
|
|
||||||
builder = ContactMenuBuilder()
|
builder = ContactMenuBuilder()
|
||||||
menu = (builder
|
menu = (builder
|
||||||
.with_action(util_ui.tr('Set alias'), lambda: main_screen.set_alias(number))
|
.with_action(util_ui.tr('Set alias'), lambda: main_screen.set_alias(number))
|
||||||
.with_submenu(copy_menu_builder)
|
.with_submenu(copy_menu_builder)
|
||||||
|
.with_submenu(history_menu_builder)
|
||||||
.with_optional_action(util_ui.tr('Manage group'),
|
.with_optional_action(util_ui.tr('Manage group'),
|
||||||
lambda: groups_service.show_group_management_screen(self._contact),
|
lambda: groups_service.show_group_management_screen(self._contact),
|
||||||
self._contact.is_self_founder())
|
self._contact.is_self_founder())
|
||||||
@ -206,13 +212,15 @@ class GroupMenuGenerator(BaseContactMenuGenerator):
|
|||||||
|
|
||||||
class GroupPeerMenuGenerator(BaseContactMenuGenerator):
|
class GroupPeerMenuGenerator(BaseContactMenuGenerator):
|
||||||
|
|
||||||
def generate(self, plugin_loader, contacts_manager, main_screen, settings, number, groups_service):
|
def generate(self, plugin_loader, contacts_manager, main_screen, settings, number, groups_service, history_loader):
|
||||||
copy_menu_builder = self._generate_copy_menu_builder(main_screen)
|
copy_menu_builder = self._generate_copy_menu_builder(main_screen)
|
||||||
|
history_menu_builder = self._generate_history_menu_builder(history_loader, main_screen)
|
||||||
|
|
||||||
builder = ContactMenuBuilder()
|
builder = ContactMenuBuilder()
|
||||||
menu = (builder
|
menu = (builder
|
||||||
.with_action(util_ui.tr('Set alias'), lambda: main_screen.set_alias(number))
|
.with_action(util_ui.tr('Set alias'), lambda: main_screen.set_alias(number))
|
||||||
.with_submenu(copy_menu_builder)
|
.with_submenu(copy_menu_builder)
|
||||||
|
.with_submenu(history_menu_builder)
|
||||||
.with_action(util_ui.tr('Quit chat'),
|
.with_action(util_ui.tr('Quit chat'),
|
||||||
lambda: contacts_manager.remove_group_peer(self._contact))
|
lambda: contacts_manager.remove_group_peer(self._contact))
|
||||||
.with_action(util_ui.tr('Notes'), lambda: main_screen.show_note(self._contact))
|
.with_action(util_ui.tr('Notes'), lambda: main_screen.show_note(self._contact))
|
||||||
|
@ -290,10 +290,6 @@ class ContactsManager(ToxSave):
|
|||||||
def friend_public_key(self, num):
|
def friend_public_key(self, num):
|
||||||
return self._contacts[num].tox_id
|
return self._contacts[num].tox_id
|
||||||
|
|
||||||
def export_history(self, num, as_text):
|
|
||||||
contact = self._contacts[num]
|
|
||||||
return self._history.export_history(contact, as_text)
|
|
||||||
|
|
||||||
def delete_friend(self, num):
|
def delete_friend(self, num):
|
||||||
"""
|
"""
|
||||||
Removes friend from contact list
|
Removes friend from contact list
|
||||||
|
@ -46,6 +46,20 @@ class History:
|
|||||||
friend.clear_corr(save_unsent)
|
friend.clear_corr(save_unsent)
|
||||||
self._db.delete_friend_from_db(friend.tox_id)
|
self._db.delete_friend_from_db(friend.tox_id)
|
||||||
|
|
||||||
|
def export_history(self, contact, as_text=True):
|
||||||
|
extension = 'txt' if as_text else 'html'
|
||||||
|
file_name, _ = util_ui.save_file_dialog(util_ui.tr('Choose file name'), extension)
|
||||||
|
|
||||||
|
if not file_name:
|
||||||
|
return
|
||||||
|
|
||||||
|
if not file_name.endswith('.' + extension):
|
||||||
|
file_name += '.' + extension
|
||||||
|
|
||||||
|
history = self.generate_history(contact, as_text)
|
||||||
|
with open(file_name, 'wt') as fl:
|
||||||
|
fl.write(history)
|
||||||
|
|
||||||
def delete_message(self, message):
|
def delete_message(self, message):
|
||||||
contact = self._contacts_manager.get_curr_contact()
|
contact = self._contacts_manager.get_curr_contact()
|
||||||
if message.type in (MESSAGE_TYPE['TEXT'], MESSAGE_TYPE['ACTION']):
|
if message.type in (MESSAGE_TYPE['TEXT'], MESSAGE_TYPE['ACTION']):
|
||||||
@ -93,7 +107,7 @@ class History:
|
|||||||
self._db.add_friend_to_db(tox_id)
|
self._db.add_friend_to_db(tox_id)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def export_history(contact, as_text=True, _range=None):
|
def generate_history(contact, as_text=True, _range=None):
|
||||||
if _range is None:
|
if _range is None:
|
||||||
contact.load_all_corr()
|
contact.load_all_corr()
|
||||||
corr = contact.get_corr()
|
corr = contact.get_corr()
|
||||||
|
@ -606,7 +606,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
return
|
return
|
||||||
generator = contact.get_context_menu_generator()
|
generator = contact.get_context_menu_generator()
|
||||||
self.listMenu = generator.generate(self._plugins_loader, self._contacts_manager, self, self._settings, number,
|
self.listMenu = generator.generate(self._plugins_loader, self._contacts_manager, self, self._settings, number,
|
||||||
self._groups_service)
|
self._groups_service, self._history_loader)
|
||||||
parent_position = self.friends_list.mapToGlobal(QtCore.QPoint(0, 0))
|
parent_position = self.friends_list.mapToGlobal(QtCore.QPoint(0, 0))
|
||||||
self.listMenu.move(parent_position + pos)
|
self.listMenu.move(parent_position + pos)
|
||||||
self.listMenu.show()
|
self.listMenu.show()
|
||||||
@ -625,19 +625,6 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.note = MultilineEdit(user, note, save_note)
|
self.note = MultilineEdit(user, note, save_note)
|
||||||
self.note.show()
|
self.note.show()
|
||||||
|
|
||||||
def export_history(self, num, as_text=True):
|
|
||||||
s = self._contacts_manager.export_history(num, as_text)
|
|
||||||
extension = 'txt' if as_text else 'html'
|
|
||||||
file_name, _ = util_ui.save_file_dialog(util_ui.tr('Choose file name'), extension)
|
|
||||||
|
|
||||||
if not file_name:
|
|
||||||
return
|
|
||||||
|
|
||||||
if not file_name.endswith('.' + extension):
|
|
||||||
file_name += '.' + extension
|
|
||||||
with open(file_name, 'wt') as fl:
|
|
||||||
fl.write(s)
|
|
||||||
|
|
||||||
def set_alias(self, num):
|
def set_alias(self, num):
|
||||||
self._contacts_manager.set_alias(num)
|
self._contacts_manager.set_alias(num)
|
||||||
|
|
||||||
@ -652,9 +639,6 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
def copy_text(text):
|
def copy_text(text):
|
||||||
util_ui.copy_to_clipboard(text)
|
util_ui.copy_to_clipboard(text)
|
||||||
|
|
||||||
def clear_history(self, num):
|
|
||||||
self._history_loader.clear_history(num)
|
|
||||||
|
|
||||||
def auto_accept(self, num, value):
|
def auto_accept(self, num, value):
|
||||||
tox_id = self._contacts_manager.friend_public_key(num)
|
tox_id = self._contacts_manager.friend_public_key(num)
|
||||||
if value:
|
if value:
|
||||||
|
Loading…
Reference in New Issue
Block a user