Daniel Brötzmann pushed to branch newcontrol at gajim / gajim
Commits:
-
af97086e
by wurstsalat at 2022-07-12T16:31:37+02:00
4 changed files:
- gajim/gtk/chat_stack.py
- gajim/gtk/controls/base.py
- gajim/gtk/message_actions_box.py
- gajim/gui_interface.py
Changes:
| ... | ... | @@ -285,23 +285,14 @@ def _on_action(self, |
| 285 | 285 | elif action_name.startswith('send-file'):
|
| 286 | 286 | name = action.get_name()
|
| 287 | 287 | if 'httpupload' in name:
|
| 288 | - app.interface.send_httpupload(current_control)
|
|
| 288 | + app.interface.start_file_transfer(contact, method='httpupload')
|
|
| 289 | 289 | return
|
| 290 | 290 | |
| 291 | 291 | if 'jingle' in name:
|
| 292 | - app.interface.instances[
|
|
| 293 | - 'file_transfers'].show_file_send_request(account, contact)
|
|
| 292 | + app.interface.start_file_transfer(contact, method='jingle')
|
|
| 294 | 293 | return
|
| 295 | 294 | |
| 296 | - method = self._get_pref_ft_method(contact)
|
|
| 297 | - if method is None:
|
|
| 298 | - return
|
|
| 299 | - |
|
| 300 | - if method == 'httpupload':
|
|
| 301 | - app.interface.send_httpupload(current_control)
|
|
| 302 | - else:
|
|
| 303 | - app.interface.instances[
|
|
| 304 | - 'file_transfers'].show_file_send_request(account, contact)
|
|
| 295 | + app.interface.start_file_transfer(contact)
|
|
| 305 | 296 | |
| 306 | 297 | elif action_name == 'invite-contacts':
|
| 307 | 298 | open_window('AdhocMUC', account=account, contact=contact)
|
| ... | ... | @@ -449,27 +440,6 @@ def _on_send_message(self) -> None: |
| 449 | 440 | |
| 450 | 441 | self._message_action_box.msg_textview.clear()
|
| 451 | 442 | |
| 452 | - def _get_pref_ft_method(self, contact: ChatContactT) -> Optional[str]:
|
|
| 453 | - ft_pref = app.settings.get_account_setting(contact.account,
|
|
| 454 | - 'filetransfer_preference')
|
|
| 455 | - httpupload = app.window.get_action_enabled('send-file-httpupload')
|
|
| 456 | - jingle = app.window.get_action_enabled('send-file-jingle')
|
|
| 457 | - |
|
| 458 | - if isinstance(contact, GroupchatContact):
|
|
| 459 | - if httpupload:
|
|
| 460 | - return 'httpupload'
|
|
| 461 | - return None
|
|
| 462 | - |
|
| 463 | - if httpupload and jingle:
|
|
| 464 | - return ft_pref
|
|
| 465 | - |
|
| 466 | - if httpupload:
|
|
| 467 | - return 'httpupload'
|
|
| 468 | - |
|
| 469 | - if jingle:
|
|
| 470 | - return 'jingle'
|
|
| 471 | - return None
|
|
| 472 | - |
|
| 473 | 443 | def clear(self) -> None:
|
| 474 | 444 | self.set_visible_child_name('empty')
|
| 475 | 445 | self._control_stack.clear()
|
| ... | ... | @@ -34,12 +34,10 @@ |
| 34 | 34 | import sys
|
| 35 | 35 | import time
|
| 36 | 36 | import uuid
|
| 37 | -from functools import partial
|
|
| 38 | 37 | |
| 39 | 38 | from gi.repository import Gtk
|
| 40 | 39 | from gi.repository import Gdk
|
| 41 | 40 | from gi.repository import GLib
|
| 42 | -from gi.repository import Gio
|
|
| 43 | 41 | |
| 44 | 42 | from nbxmpp import JID
|
| 45 | 43 | from nbxmpp.modules.security_labels import Displaymarking
|
| ... | ... | @@ -62,7 +60,6 @@ |
| 62 | 60 | from gajim.gui.conversation.view import ConversationView
|
| 63 | 61 | from gajim.gui.conversation.scrolled import ScrolledView
|
| 64 | 62 | from gajim.gui.conversation.jump_to_end_button import JumpToEndButton
|
| 65 | -from gajim.gui.file_transfer_send import SendFileDialog
|
|
| 66 | 63 | from gajim.gui.util import get_hardware_key_codes
|
| 67 | 64 | from gajim.gui.builder import get_builder
|
| 68 | 65 | from gajim.gui.util import set_urgency_hint
|
| ... | ... | @@ -374,67 +371,6 @@ def shutdown(self) -> None: |
| 374 | 371 | def _on_scroll_to_end(self, _view: ConversationView) -> None:
|
| 375 | 372 | scroll_to_end(self._scrolled_view)
|
| 376 | 373 | |
| 377 | - def _get_pref_ft_method(self) -> Optional[str]:
|
|
| 378 | - ft_pref = app.settings.get_account_setting(self.account,
|
|
| 379 | - 'filetransfer_preference')
|
|
| 380 | - httpupload = app.window.lookup_action(
|
|
| 381 | - f'send-file-httpupload-{self.control_id}')
|
|
| 382 | - jingle = app.window.lookup_action(
|
|
| 383 | - f'send-file-jingle-{self.control_id}')
|
|
| 384 | - |
|
| 385 | - if self.is_groupchat:
|
|
| 386 | - if httpupload.get_enabled():
|
|
| 387 | - return 'httpupload'
|
|
| 388 | - return None
|
|
| 389 | - |
|
| 390 | - if httpupload.get_enabled() and jingle.get_enabled():
|
|
| 391 | - return ft_pref
|
|
| 392 | - |
|
| 393 | - if httpupload.get_enabled():
|
|
| 394 | - return 'httpupload'
|
|
| 395 | - |
|
| 396 | - if jingle.get_enabled():
|
|
| 397 | - return 'jingle'
|
|
| 398 | - return None
|
|
| 399 | - |
|
| 400 | - def _start_filetransfer(self, path: str) -> None:
|
|
| 401 | - method = self._get_pref_ft_method()
|
|
| 402 | - if method is None:
|
|
| 403 | - return
|
|
| 404 | - |
|
| 405 | - if method == 'httpupload':
|
|
| 406 | - app.interface.send_httpupload(self, path)
|
|
| 407 | - else:
|
|
| 408 | - send_callback = partial(
|
|
| 409 | - app.interface.instances['file_transfers'].send_file,
|
|
| 410 | - self.account,
|
|
| 411 | - self.contact)
|
|
| 412 | - SendFileDialog(self.contact, send_callback, app.window, [path])
|
|
| 413 | - |
|
| 414 | - def _on_send_file(self,
|
|
| 415 | - action: Gio.SimpleAction,
|
|
| 416 | - _param: Optional[GLib.Variant]
|
|
| 417 | - ) -> None:
|
|
| 418 | - name = action.get_name()
|
|
| 419 | - if 'httpupload' in name:
|
|
| 420 | - app.interface.send_httpupload(self)
|
|
| 421 | - return
|
|
| 422 | - |
|
| 423 | - if 'jingle' in name:
|
|
| 424 | - app.interface.instances['file_transfers'].show_file_send_request(
|
|
| 425 | - self.account, self.contact)
|
|
| 426 | - return
|
|
| 427 | - |
|
| 428 | - method = self._get_pref_ft_method()
|
|
| 429 | - if method is None:
|
|
| 430 | - return
|
|
| 431 | - |
|
| 432 | - if method == 'httpupload':
|
|
| 433 | - app.interface.send_httpupload(self)
|
|
| 434 | - else:
|
|
| 435 | - app.interface.instances['file_transfers'].show_file_send_request(
|
|
| 436 | - self.account, self.contact)
|
|
| 437 | - |
|
| 438 | 374 | def _on_autoscroll_changed(self,
|
| 439 | 375 | _widget: ScrolledView,
|
| 440 | 376 | autoscroll: bool
|
| ... | ... | @@ -494,7 +430,7 @@ def drag_data_file_transfer(self, selection: Gtk.SelectionData) -> None: |
| 494 | 430 | 'not uploaded: %s') % path)
|
| 495 | 431 | continue
|
| 496 | 432 | |
| 497 | - self._start_filetransfer(path)
|
|
| 433 | + app.interface.start_file_transfer(self.contact, path)
|
|
| 498 | 434 | |
| 499 | 435 | def get_our_nick(self) -> str:
|
| 500 | 436 | return app.nicks[self.account]
|
| ... | ... | @@ -578,23 +578,25 @@ def _on_paste_clipboard(self, |
| 578 | 578 | |
| 579 | 579 | clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
|
| 580 | 580 | image = clipboard.wait_for_image()
|
| 581 | - if image is not None:
|
|
| 582 | - if not app.settings.get('confirm_paste_image'):
|
|
| 583 | - self._paste_event_confirmed(True, image)
|
|
| 584 | - return
|
|
| 581 | + if image is None:
|
|
| 582 | + return
|
|
| 585 | 583 | |
| 586 | - PastePreviewDialog(
|
|
| 587 | - _('Paste Image'),
|
|
| 588 | - _('You are trying to paste an image'),
|
|
| 589 | - _('Are you sure you want to paste your '
|
|
| 590 | - 'clipboard\'s image into the chat window?'),
|
|
| 591 | - _('_Do not ask me again'),
|
|
| 592 | - image,
|
|
| 593 | - [DialogButton.make('Cancel'),
|
|
| 594 | - DialogButton.make('Accept',
|
|
| 595 | - text=_('_Paste'),
|
|
| 596 | - callback=self._paste_event_confirmed,
|
|
| 597 | - args=[image])]).show()
|
|
| 584 | + if not app.settings.get('confirm_paste_image'):
|
|
| 585 | + self._paste_event_confirmed(True, image)
|
|
| 586 | + return
|
|
| 587 | + |
|
| 588 | + PastePreviewDialog(
|
|
| 589 | + _('Paste Image'),
|
|
| 590 | + _('You are trying to paste an image'),
|
|
| 591 | + _('Are you sure you want to paste your '
|
|
| 592 | + 'clipboard\'s image into the chat window?'),
|
|
| 593 | + _('_Do not ask me again'),
|
|
| 594 | + image,
|
|
| 595 | + [DialogButton.make('Cancel'),
|
|
| 596 | + DialogButton.make('Accept',
|
|
| 597 | + text=_('_Paste'),
|
|
| 598 | + callback=self._paste_event_confirmed,
|
|
| 599 | + args=[image])]).show()
|
|
| 598 | 600 | |
| 599 | 601 | def _paste_event_confirmed(self,
|
| 600 | 602 | is_checked: bool,
|
| ... | ... | @@ -606,9 +608,10 @@ def _paste_event_confirmed(self, |
| 606 | 608 | dir_ = tempfile.gettempdir()
|
| 607 | 609 | path = os.path.join(dir_, f'{uuid.uuid4()}.png')
|
| 608 | 610 | if image is None:
|
| 609 | - self.add_info_message(_('Error: Could not process image'))
|
|
| 611 | + log.error('Could not process pasted image')
|
|
| 610 | 612 | return
|
| 611 | 613 | |
| 612 | 614 | image.savev(path, 'png', [], [])
|
| 613 | 615 | |
| 614 | - self._start_filetransfer(path) |
|
| 616 | + assert self._contact is not None
|
|
| 617 | + app.interface.start_file_transfer(self._contact, path) |
| ... | ... | @@ -67,16 +67,20 @@ |
| 67 | 67 | from gajim.common.events import FileHashError
|
| 68 | 68 | from gajim.common.events import FileProgress
|
| 69 | 69 | from gajim.common.events import FileError
|
| 70 | +from gajim.common.modules.contacts import BareContact
|
|
| 71 | +from gajim.common.modules.contacts import GroupchatContact
|
|
| 70 | 72 | from gajim.common.structs import OutgoingMessage
|
| 71 | 73 | from gajim.common.i18n import _
|
| 72 | 74 | from gajim.common.client import Client
|
| 73 | 75 | from gajim.common.const import FTState
|
| 74 | 76 | from gajim.common.file_props import FileProp
|
| 77 | +from gajim.common.types import ChatContactT
|
|
| 75 | 78 | |
| 76 | 79 | from gajim.common.modules.httpupload import HTTPFileTransfer
|
| 77 | 80 | |
| 78 | 81 | from gajim.gui.dialogs import ErrorDialog
|
| 79 | 82 | from gajim.gui.filechoosers import FileChooserDialog
|
| 83 | +from gajim.gui.file_transfer_send import SendFileDialog
|
|
| 80 | 84 | from gajim.gui.filetransfer import FileTransfersWindow
|
| 81 | 85 | from gajim.gui.menus import build_accounts_menu
|
| 82 | 86 | from gajim.gui.util import get_app_window
|
| ... | ... | @@ -368,6 +372,60 @@ def _on_cancel_upload(self, |
| 368 | 372 | client = app.get_client(transfer.account)
|
| 369 | 373 | client.get_module('HTTPUpload').cancel_transfer(transfer)
|
| 370 | 374 | |
| 375 | + def _get_pref_ft_method(self, contact: ChatContactT) -> Optional[str]:
|
|
| 376 | + ft_pref = app.settings.get_account_setting(contact.account,
|
|
| 377 | + 'filetransfer_preference')
|
|
| 378 | + httpupload = app.window.get_action_enabled('send-file-httpupload')
|
|
| 379 | + jingle = app.window.get_action_enabled('send-file-jingle')
|
|
| 380 | + |
|
| 381 | + if isinstance(contact, GroupchatContact):
|
|
| 382 | + if httpupload:
|
|
| 383 | + return 'httpupload'
|
|
| 384 | + return None
|
|
| 385 | + |
|
| 386 | + if httpupload and jingle:
|
|
| 387 | + return ft_pref
|
|
| 388 | + |
|
| 389 | + if httpupload:
|
|
| 390 | + return 'httpupload'
|
|
| 391 | + |
|
| 392 | + if jingle:
|
|
| 393 | + return 'jingle'
|
|
| 394 | + return None
|
|
| 395 | + |
|
| 396 | + def start_file_transfer(self,
|
|
| 397 | + contact: ChatContactT,
|
|
| 398 | + path: Optional[str] = None,
|
|
| 399 | + method: Optional[str] = None
|
|
| 400 | + ) -> None:
|
|
| 401 | + if method is None:
|
|
| 402 | + method = self._get_pref_ft_method(contact)
|
|
| 403 | + if method is None:
|
|
| 404 | + return
|
|
| 405 | + |
|
| 406 | + current_control = app.window.get_active_control()
|
|
| 407 | + if current_control is None:
|
|
| 408 | + return
|
|
| 409 | + |
|
| 410 | + if path is None:
|
|
| 411 | + if method == 'httpupload':
|
|
| 412 | + self.send_httpupload(current_control)
|
|
| 413 | + return
|
|
| 414 | + if method == 'jingle':
|
|
| 415 | + self.instances['file_transfers'].show_file_send_request(
|
|
| 416 | + contact.account, contact)
|
|
| 417 | + return
|
|
| 418 | + |
|
| 419 | + if method == 'httpupload':
|
|
| 420 | + self.send_httpupload(current_control, path)
|
|
| 421 | + else:
|
|
| 422 | + assert isinstance(contact, BareContact)
|
|
| 423 | + send_callback = partial(
|
|
| 424 | + self.instances['file_transfers'].send_file,
|
|
| 425 | + contact.account,
|
|
| 426 | + contact)
|
|
| 427 | + SendFileDialog(contact, send_callback, app.window, [path])
|
|
| 428 | + |
|
| 371 | 429 | @staticmethod
|
| 372 | 430 | def create_groupchat(account: str,
|
| 373 | 431 | room_jid: str,
|