Daniel Brötzmann pushed to branch newcontrol at gajim / gajim
Commits: af97086e by wurstsalat at 2022-07-12T16:31:37+02:00 Add general start_file_transfer method to Interface
- - - - -
4 changed files:
- gajim/gtk/chat_stack.py - gajim/gtk/controls/base.py - gajim/gtk/message_actions_box.py - gajim/gui_interface.py
Changes:
===================================== gajim/gtk/chat_stack.py ===================================== @@ -285,23 +285,14 @@ def _on_action(self, elif action_name.startswith('send-file'): name = action.get_name() if 'httpupload' in name: - app.interface.send_httpupload(current_control) + app.interface.start_file_transfer(contact, method='httpupload') return
if 'jingle' in name: - app.interface.instances[ - 'file_transfers'].show_file_send_request(account, contact) + app.interface.start_file_transfer(contact, method='jingle') return
- method = self._get_pref_ft_method(contact) - if method is None: - return - - if method == 'httpupload': - app.interface.send_httpupload(current_control) - else: - app.interface.instances[ - 'file_transfers'].show_file_send_request(account, contact) + app.interface.start_file_transfer(contact)
elif action_name == 'invite-contacts': open_window('AdhocMUC', account=account, contact=contact) @@ -449,27 +440,6 @@ def _on_send_message(self) -> None:
self._message_action_box.msg_textview.clear()
- 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 clear(self) -> None: self.set_visible_child_name('empty') self._control_stack.clear()
===================================== gajim/gtk/controls/base.py ===================================== @@ -34,12 +34,10 @@ import sys import time import uuid -from functools import partial
from gi.repository import Gtk from gi.repository import Gdk from gi.repository import GLib -from gi.repository import Gio
from nbxmpp import JID from nbxmpp.modules.security_labels import Displaymarking @@ -62,7 +60,6 @@ from gajim.gui.conversation.view import ConversationView from gajim.gui.conversation.scrolled import ScrolledView from gajim.gui.conversation.jump_to_end_button import JumpToEndButton -from gajim.gui.file_transfer_send import SendFileDialog from gajim.gui.util import get_hardware_key_codes from gajim.gui.builder import get_builder from gajim.gui.util import set_urgency_hint @@ -374,67 +371,6 @@ def shutdown(self) -> None: def _on_scroll_to_end(self, _view: ConversationView) -> None: scroll_to_end(self._scrolled_view)
- def _get_pref_ft_method(self) -> Optional[str]: - ft_pref = app.settings.get_account_setting(self.account, - 'filetransfer_preference') - httpupload = app.window.lookup_action( - f'send-file-httpupload-{self.control_id}') - jingle = app.window.lookup_action( - f'send-file-jingle-{self.control_id}') - - if self.is_groupchat: - if httpupload.get_enabled(): - return 'httpupload' - return None - - if httpupload.get_enabled() and jingle.get_enabled(): - return ft_pref - - if httpupload.get_enabled(): - return 'httpupload' - - if jingle.get_enabled(): - return 'jingle' - return None - - def _start_filetransfer(self, path: str) -> None: - method = self._get_pref_ft_method() - if method is None: - return - - if method == 'httpupload': - app.interface.send_httpupload(self, path) - else: - send_callback = partial( - app.interface.instances['file_transfers'].send_file, - self.account, - self.contact) - SendFileDialog(self.contact, send_callback, app.window, [path]) - - def _on_send_file(self, - action: Gio.SimpleAction, - _param: Optional[GLib.Variant] - ) -> None: - name = action.get_name() - if 'httpupload' in name: - app.interface.send_httpupload(self) - return - - if 'jingle' in name: - app.interface.instances['file_transfers'].show_file_send_request( - self.account, self.contact) - return - - method = self._get_pref_ft_method() - if method is None: - return - - if method == 'httpupload': - app.interface.send_httpupload(self) - else: - app.interface.instances['file_transfers'].show_file_send_request( - self.account, self.contact) - def _on_autoscroll_changed(self, _widget: ScrolledView, autoscroll: bool @@ -494,7 +430,7 @@ def drag_data_file_transfer(self, selection: Gtk.SelectionData) -> None: 'not uploaded: %s') % path) continue
- self._start_filetransfer(path) + app.interface.start_file_transfer(self.contact, path)
def get_our_nick(self) -> str: return app.nicks[self.account]
===================================== gajim/gtk/message_actions_box.py ===================================== @@ -578,23 +578,25 @@ def _on_paste_clipboard(self,
clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) image = clipboard.wait_for_image() - if image is not None: - if not app.settings.get('confirm_paste_image'): - self._paste_event_confirmed(True, image) - return + if image is None: + return
- PastePreviewDialog( - _('Paste Image'), - _('You are trying to paste an image'), - _('Are you sure you want to paste your ' - 'clipboard's image into the chat window?'), - _('_Do not ask me again'), - image, - [DialogButton.make('Cancel'), - DialogButton.make('Accept', - text=_('_Paste'), - callback=self._paste_event_confirmed, - args=[image])]).show() + if not app.settings.get('confirm_paste_image'): + self._paste_event_confirmed(True, image) + return + + PastePreviewDialog( + _('Paste Image'), + _('You are trying to paste an image'), + _('Are you sure you want to paste your ' + 'clipboard's image into the chat window?'), + _('_Do not ask me again'), + image, + [DialogButton.make('Cancel'), + DialogButton.make('Accept', + text=_('_Paste'), + callback=self._paste_event_confirmed, + args=[image])]).show()
def _paste_event_confirmed(self, is_checked: bool, @@ -606,9 +608,10 @@ def _paste_event_confirmed(self, dir_ = tempfile.gettempdir() path = os.path.join(dir_, f'{uuid.uuid4()}.png') if image is None: - self.add_info_message(_('Error: Could not process image')) + log.error('Could not process pasted image') return
image.savev(path, 'png', [], [])
- self._start_filetransfer(path) + assert self._contact is not None + app.interface.start_file_transfer(self._contact, path)
===================================== gajim/gui_interface.py ===================================== @@ -67,16 +67,20 @@ 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 @@ -368,6 +372,60 @@ def _on_cancel_upload(self, 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,
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/af97086ec67236e3e3015a37f65f5791c...