From 0dadde62ee8632e2488f0402d797be7e8232c15a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Br=C3=B6tzmann?= Date: Fri, 29 Jul 2022 11:21:47 +0200 Subject: feat: Refactor ChatWidgets so they are only created once MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously all ChatWidgets were created per Chat. Now we create them only once and load data into them when we switch chat. This should have a positive impact on memory and performance all around. - Improve text input undo logic - Improve text input enbaled logic - Don’t clear selection clipboard on chat switch - Add menu for triggering message correction - Improve text wrapping in conversation view - Make main window top row have a consistent height across columns Fixes #10987, #11038, #10973, #10119, #11052, #10945 --- gajim/gui_interface.py | 67 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 9 deletions(-) (limited to 'gajim/gui_interface.py') diff --git a/gajim/gui_interface.py b/gajim/gui_interface.py index cc0841bae..0f1d4b8f2 100644 --- a/gajim/gui_interface.py +++ b/gajim/gui_interface.py @@ -67,16 +67,20 @@ from gajim.common.events import FileCompleted from gajim.common.events import FileHashError from gajim.common.events import FileProgress from gajim.common.events import FileError +from gajim.common.modules.contacts import BareContact +from gajim.common.modules.contacts import GroupchatContact from gajim.common.structs import OutgoingMessage from gajim.common.i18n import _ from gajim.common.client import Client from gajim.common.const import FTState from gajim.common.file_props import FileProp +from gajim.common.types import ChatContactT from gajim.common.modules.httpupload import HTTPFileTransfer from gajim.gui.dialogs import ErrorDialog from gajim.gui.filechoosers import FileChooserDialog +from gajim.gui.file_transfer_send import SendFileDialog from gajim.gui.filetransfer import FileTransfersWindow from gajim.gui.menus import build_accounts_menu from gajim.gui.util import get_app_window @@ -125,7 +129,6 @@ class Interface: # pylint: disable=line-too-long self.handlers = { 'signed-in': [self.handle_event_signed_in], - 'presence-received': [self.handle_event_presence], 'message-sent': [self.handle_event_msgsent], 'message-not-sent': [self.handle_event_msgnotsent], } @@ -166,14 +169,6 @@ class Interface: if app.settings.get('ask_online_status'): app.window.show_account_page(account) - def handle_event_presence(self, event): - account = event.conn.name - jid = event.jid - - ctrl = app.window.get_control(account, jid) - if ctrl and ctrl.session and len(event.contact_list) > 1: - ctrl.remove_session(ctrl.session) - @staticmethod def handle_event_msgsent(event): if not event.play_sound: @@ -377,6 +372,60 @@ class Interface: client = app.get_client(transfer.account) client.get_module('HTTPUpload').cancel_transfer(transfer) + def _get_pref_ft_method(self, contact: ChatContactT) -> Optional[str]: + ft_pref = app.settings.get_account_setting(contact.account, + 'filetransfer_preference') + httpupload = app.window.get_action_enabled('send-file-httpupload') + jingle = app.window.get_action_enabled('send-file-jingle') + + if isinstance(contact, GroupchatContact): + if httpupload: + return 'httpupload' + return None + + if httpupload and jingle: + return ft_pref + + if httpupload: + return 'httpupload' + + if jingle: + return 'jingle' + return None + + def start_file_transfer(self, + contact: ChatContactT, + path: Optional[str] = None, + method: Optional[str] = None + ) -> None: + if method is None: + method = self._get_pref_ft_method(contact) + if method is None: + return + + current_control = app.window.get_active_control() + if current_control is None: + return + + if path is None: + if method == 'httpupload': + self.send_httpupload(current_control) + return + if method == 'jingle': + self.instances['file_transfers'].show_file_send_request( + contact.account, contact) + return + + if method == 'httpupload': + self.send_httpupload(current_control, path) + else: + assert isinstance(contact, BareContact) + send_callback = partial( + self.instances['file_transfers'].send_file, + contact.account, + contact) + SendFileDialog(contact, send_callback, app.window, [path]) + @staticmethod def create_groupchat(account: str, room_jid: str, -- cgit v1.2.3