Daniel Brötzmann pushed to branch master at gajim / gajim
Commits:
-
0ebc5ff9
by wurstsalat at 2022-01-07T23:51:53+01:00
-
020ae6f1
by wurstsalat at 2022-01-07T23:52:21+01:00
-
bd8d0a97
by wurstsalat at 2022-01-07T23:53:33+01:00
-
d161c1f0
by wurstsalat at 2022-01-07T23:55:10+01:00
4 changed files:
Changes:
| ... | ... | @@ -114,7 +114,7 @@ class BaseControl(ChatCommandProcessor, CommandTools, EventHelper): |
| 114 | 114 |
A base class containing a banner, ConversationView, MessageInputTextView
|
| 115 | 115 |
"""
|
| 116 | 116 |
|
| 117 |
- _type = None # type: ControlType
|
|
| 117 |
+ _type: Optional[ControlType] = None
|
|
| 118 | 118 |
|
| 119 | 119 |
def __init__(self, widget_name: str, account: str, jid: JID) -> None:
|
| 120 | 120 |
EventHelper.__init__(self)
|
| ... | ... | @@ -208,7 +208,7 @@ def __init__(self, widget_name: str, account: str, jid: JID) -> None: |
| 208 | 208 |
self.msg_textview.connect('key-press-event',
|
| 209 | 209 |
self._on_message_textview_key_press_event)
|
| 210 | 210 |
self.msg_textview.connect('populate-popup',
|
| 211 |
- self.on_msg_textview_populate_popup)
|
|
| 211 |
+ self._on_msg_textview_populate_popup)
|
|
| 212 | 212 |
self.msg_textview.get_buffer().connect(
|
| 213 | 213 |
'changed', self._on_message_tv_buffer_changed)
|
| 214 | 214 |
|
| ... | ... | @@ -255,7 +255,7 @@ def __init__(self, widget_name: str, account: str, jid: JID) -> None: |
| 255 | 255 |
|
| 256 | 256 |
# XEP-0172 User Nickname
|
| 257 | 257 |
# TODO:
|
| 258 |
- self.user_nick = None
|
|
| 258 |
+ self.user_nick: Optional[str] = None
|
|
| 259 | 259 |
|
| 260 | 260 |
self.command_hits: List[str] = []
|
| 261 | 261 |
self.last_key_tabs: bool = False
|
| ... | ... | @@ -264,7 +264,7 @@ def __init__(self, widget_name: str, account: str, jid: JID) -> None: |
| 264 | 264 |
|
| 265 | 265 |
self._client.get_module('Chatstate').set_active(self.contact)
|
| 266 | 266 |
|
| 267 |
- self.encryption = self.get_encryption_state()
|
|
| 267 |
+ self.encryption: Optional[str] = self.get_encryption_state()
|
|
| 268 | 268 |
self.conversation_view.encryption_enabled = self.encryption is not None
|
| 269 | 269 |
|
| 270 | 270 |
# PluginSystem: adding GUI extension point for BaseControl
|
| ... | ... | @@ -283,10 +283,10 @@ def __init__(self, widget_name: str, account: str, jid: JID) -> None: |
| 283 | 283 |
# to properly use the super, because of the old code.
|
| 284 | 284 |
CommandTools.__init__(self)
|
| 285 | 285 |
|
| 286 |
- def _connect_contact_signals(self):
|
|
| 286 |
+ def _connect_contact_signals(self) -> None:
|
|
| 287 | 287 |
raise NotImplementedError
|
| 288 | 288 |
|
| 289 |
- def _get_action(self, name: str) -> Gio.Action:
|
|
| 289 |
+ def _get_action(self, name: str) -> Gio.SimpleAction:
|
|
| 290 | 290 |
return app.window.lookup_action(f'{name}{self.control_id}')
|
| 291 | 291 |
|
| 292 | 292 |
def process_event(self, event):
|
| ... | ... | @@ -329,7 +329,10 @@ def _on_message_updated(self, event): |
| 329 | 329 |
self.conversation_view.show_message_retraction(
|
| 330 | 330 |
event.properties.moderation.stanza_id, text)
|
| 331 | 331 |
|
| 332 |
- def _on_conversation_view_key_press(self, _listbox, event):
|
|
| 332 |
+ def _on_conversation_view_key_press(self,
|
|
| 333 |
+ _listbox: ConversationView,
|
|
| 334 |
+ event: Gdk.EventKey
|
|
| 335 |
+ ) -> int:
|
|
| 333 | 336 |
if event.get_state() & Gdk.ModifierType.SHIFT_MASK:
|
| 334 | 337 |
if event.keyval in (Gdk.KEY_Page_Down, Gdk.KEY_Page_Up):
|
| 335 | 338 |
return Gdk.EVENT_PROPAGATE
|
| ... | ... | @@ -395,7 +398,7 @@ def allow_shutdown(self, method, on_response_yes, on_response_no): |
| 395 | 398 |
"""
|
| 396 | 399 |
on_response_yes(self)
|
| 397 | 400 |
|
| 398 |
- def focus(self):
|
|
| 401 |
+ def focus(self) -> None:
|
|
| 399 | 402 |
raise NotImplementedError
|
| 400 | 403 |
|
| 401 | 404 |
def draw_banner(self) -> None:
|
| ... | ... | @@ -432,22 +435,11 @@ def repaint_themed_widgets(self) -> None: |
| 432 | 435 |
"""
|
| 433 | 436 |
self.draw_banner()
|
| 434 | 437 |
|
| 435 |
- def _update_toolbar(self):
|
|
| 438 |
+ def _update_toolbar(self) -> None:
|
|
| 436 | 439 |
"""
|
| 437 | 440 |
Derived types MAY implement this
|
| 438 | 441 |
"""
|
| 439 | 442 |
|
| 440 |
- def get_tab_label(self, chatstate):
|
|
| 441 |
- """
|
|
| 442 |
- Return a suitable tab label string. Returns a tuple such as: (label_str,
|
|
| 443 |
- color) either of which can be None if chatstate is given that means we
|
|
| 444 |
- have HE SENT US a chatstate and we want it displayed
|
|
| 445 |
- |
|
| 446 |
- Derivded classes MUST implement this.
|
|
| 447 |
- """
|
|
| 448 |
- # Return a markup'd label and optional Gtk.Color in a tuple like:
|
|
| 449 |
- # return (label_str, None)
|
|
| 450 |
- |
|
| 451 | 443 |
def set_session(self, session):
|
| 452 | 444 |
oldsession = None
|
| 453 | 445 |
if hasattr(self, 'session'):
|
| ... | ... | @@ -577,7 +569,10 @@ def mark_as_read(self, send_marker: bool = True) -> None: |
| 577 | 569 |
self._type)
|
| 578 | 570 |
self.last_msg_id = None
|
| 579 | 571 |
|
| 580 |
- def change_encryption(self, action, param):
|
|
| 572 |
+ def change_encryption(self,
|
|
| 573 |
+ action: Gio.SimpleAction,
|
|
| 574 |
+ param: GLib.Variant
|
|
| 575 |
+ ) -> None:
|
|
| 581 | 576 |
encryption = param.get_string()
|
| 582 | 577 |
if encryption == 'disabled':
|
| 583 | 578 |
encryption = None
|
| ... | ... | @@ -622,16 +617,16 @@ def set_lock_image(self) -> None: |
| 622 | 617 |
self.xml.authentication_button.set_visible(visible)
|
| 623 | 618 |
self.xml.lock_image.set_sensitive(visible)
|
| 624 | 619 |
|
| 625 |
- def _on_authentication_button_clicked(self, _button):
|
|
| 620 |
+ def _on_authentication_button_clicked(self, _button: Gtk.Button) -> None:
|
|
| 626 | 621 |
app.plugin_manager.extension_point(
|
| 627 | 622 |
'encryption_dialog' + self.encryption, self)
|
| 628 | 623 |
|
| 629 |
- def set_encryption_state(self, encryption):
|
|
| 624 |
+ def set_encryption_state(self, encryption: Optional[str]) -> None:
|
|
| 630 | 625 |
self.encryption = encryption
|
| 631 | 626 |
self.conversation_view.encryption_enabled = encryption is not None
|
| 632 | 627 |
self.contact.settings.set('encryption', self.encryption or '')
|
| 633 | 628 |
|
| 634 |
- def get_encryption_state(self):
|
|
| 629 |
+ def get_encryption_state(self) -> Optional[str]:
|
|
| 635 | 630 |
state = self.contact.settings.get('encryption')
|
| 636 | 631 |
if not state:
|
| 637 | 632 |
return None
|
| ... | ... | @@ -668,7 +663,7 @@ def set_speller(self) -> None: |
| 668 | 663 |
|
| 669 | 664 |
spell_checker.connect('notify::language', self.on_language_changed)
|
| 670 | 665 |
|
| 671 |
- def get_speller_language(self):
|
|
| 666 |
+ def get_speller_language(self) -> Optional[Gspell.Language]:
|
|
| 672 | 667 |
lang = self.contact.settings.get('speller_language')
|
| 673 | 668 |
if not lang:
|
| 674 | 669 |
# use the default one
|
| ... | ... | @@ -680,7 +675,7 @@ def get_speller_language(self): |
| 680 | 675 |
gspell_lang = Gspell.language_get_default()
|
| 681 | 676 |
return gspell_lang
|
| 682 | 677 |
|
| 683 |
- def on_language_changed(self, checker, _param):
|
|
| 678 |
+ def on_language_changed(self, checker: Gspell.Checker, _param: Any) -> None:
|
|
| 684 | 679 |
gspell_lang = checker.get_language()
|
| 685 | 680 |
self.contact.settings.set('speller_language', gspell_lang.get_code())
|
| 686 | 681 |
|
| ... | ... | @@ -716,7 +711,10 @@ def shutdown(self) -> None: |
| 716 | 711 |
|
| 717 | 712 |
self.unregister_events()
|
| 718 | 713 |
|
| 719 |
- def on_msg_textview_populate_popup(self, _textview, menu):
|
|
| 714 |
+ def _on_msg_textview_populate_popup(self,
|
|
| 715 |
+ _textview: MessageInputTextView,
|
|
| 716 |
+ menu: Gtk.Widget
|
|
| 717 |
+ ) -> None:
|
|
| 720 | 718 |
"""
|
| 721 | 719 |
Override the default context menu and we prepend an option to switch
|
| 722 | 720 |
languages
|
| ... | ... | @@ -754,17 +752,19 @@ def paste_clipboard_as_quote(self, _item: Gtk.MenuItem) -> None: |
| 754 | 752 |
return
|
| 755 | 753 |
self.insert_as_quote(text)
|
| 756 | 754 |
|
| 757 |
- def on_quote(self, _widget, text):
|
|
| 755 |
+ def on_quote(self, _widget: Gtk.Widget, text: str) -> None:
|
|
| 758 | 756 |
self.insert_as_quote(text)
|
| 759 | 757 |
|
| 760 |
- def on_mention(self, _widget, name):
|
|
| 758 |
+ def on_mention(self, _widget: Gtk.Widget, name: str) -> None:
|
|
| 761 | 759 |
gc_refer_to_nick_char = app.settings.get('gc_refer_to_nick_char')
|
| 762 | 760 |
text = f'{name}{gc_refer_to_nick_char} '
|
| 763 | 761 |
message_buffer = self.msg_textview.get_buffer()
|
| 764 | 762 |
message_buffer.insert_at_cursor(text)
|
| 765 | 763 |
GLib.idle_add(self.msg_textview.grab_focus)
|
| 766 | 764 |
|
| 767 |
- def _on_message_textview_paste_event(self, _texview):
|
|
| 765 |
+ def _on_message_textview_paste_event(self,
|
|
| 766 |
+ _texview: MessageInputTextView
|
|
| 767 |
+ ) -> None:
|
|
| 768 | 768 |
clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
|
| 769 | 769 |
image = clipboard.wait_for_image()
|
| 770 | 770 |
if image is not None:
|
| ... | ... | @@ -824,7 +824,7 @@ def _get_pref_ft_method(self) -> Optional[str]: |
| 824 | 824 |
return 'jingle'
|
| 825 | 825 |
return None
|
| 826 | 826 |
|
| 827 |
- def _start_filetransfer(self, path):
|
|
| 827 |
+ def _start_filetransfer(self, path: str) -> None:
|
|
| 828 | 828 |
method = self._get_pref_ft_method()
|
| 829 | 829 |
if method is None:
|
| 830 | 830 |
return
|
| ... | ... | @@ -836,7 +836,10 @@ def _start_filetransfer(self, path): |
| 836 | 836 |
app.interface.instances['file_transfers'].send_file(
|
| 837 | 837 |
self.account, self.contact, path)
|
| 838 | 838 |
|
| 839 |
- def _on_send_file(self, action, _param):
|
|
| 839 |
+ def _on_send_file(self,
|
|
| 840 |
+ action: Gio.SimpleAction,
|
|
| 841 |
+ _param: Optional[GLib.Variant]
|
|
| 842 |
+ ) -> None:
|
|
| 840 | 843 |
name = action.get_name()
|
| 841 | 844 |
if 'httpupload' in name:
|
| 842 | 845 |
app.interface.send_httpupload(self)
|
| ... | ... | @@ -857,7 +860,10 @@ def _on_send_file(self, action, _param): |
| 857 | 860 |
app.interface.instances['file_transfers'].show_file_send_request(
|
| 858 | 861 |
self.account, self.contact)
|
| 859 | 862 |
|
| 860 |
- def _on_message_textview_key_press_event(self, textview, event):
|
|
| 863 |
+ def _on_message_textview_key_press_event(self,
|
|
| 864 |
+ textview: MessageInputTextView,
|
|
| 865 |
+ event: Gdk.EventKey
|
|
| 866 |
+ ) -> bool:
|
|
| 861 | 867 |
# pylint: disable=too-many-nested-blocks
|
| 862 | 868 |
if event.keyval == Gdk.KEY_space:
|
| 863 | 869 |
self.space_pressed = True
|
| ... | ... | @@ -978,7 +984,10 @@ def _on_message_textview_key_press_event(self, textview, event): |
| 978 | 984 |
|
| 979 | 985 |
return False
|
| 980 | 986 |
|
| 981 |
- def _on_autoscroll_changed(self, _widget, autoscroll):
|
|
| 987 |
+ def _on_autoscroll_changed(self,
|
|
| 988 |
+ _widget: ScrolledView,
|
|
| 989 |
+ autoscroll: bool
|
|
| 990 |
+ ) -> None:
|
|
| 982 | 991 |
if not autoscroll:
|
| 983 | 992 |
self._jump_to_end_button.toggle(True)
|
| 984 | 993 |
return
|
| ... | ... | @@ -986,23 +995,41 @@ def _on_autoscroll_changed(self, _widget, autoscroll): |
| 986 | 995 |
self._jump_to_end_button.toggle(False)
|
| 987 | 996 |
app.window.mark_as_read(self.account, self.contact.jid)
|
| 988 | 997 |
|
| 989 |
- def _on_jump_to_end(self, _button):
|
|
| 998 |
+ def _on_jump_to_end(self, _button: Gtk.Button) -> None:
|
|
| 990 | 999 |
self.scroll_to_end(force=True)
|
| 991 | 1000 |
self._jump_to_end_button.reset_unread_count()
|
| 992 | 1001 |
|
| 993 |
- def _on_drag_data_received(self, widget, context, x_coord, y_coord,
|
|
| 994 |
- selection, target_type, timestamp):
|
|
| 1002 |
+ def _on_drag_data_received(self,
|
|
| 1003 |
+ widget: Gtk.Widget,
|
|
| 1004 |
+ context: Gdk.DragContext,
|
|
| 1005 |
+ x_coord: int,
|
|
| 1006 |
+ y_coord: int,
|
|
| 1007 |
+ selection: Gtk.SelectionData,
|
|
| 1008 |
+ target_type: int,
|
|
| 1009 |
+ timestamp: int
|
|
| 1010 |
+ ) -> None:
|
|
| 995 | 1011 |
"""
|
| 996 | 1012 |
Derived types SHOULD implement this
|
| 997 | 1013 |
"""
|
| 998 | 1014 |
|
| 999 |
- def _on_drag_leave(self, *args):
|
|
| 1015 |
+ def _on_drag_leave(self,
|
|
| 1016 |
+ _widget: Gtk.Widget,
|
|
| 1017 |
+ _context: Gdk.DragContext,
|
|
| 1018 |
+ _time: int
|
|
| 1019 |
+ ) -> None:
|
|
| 1000 | 1020 |
self.xml.drop_area.set_no_show_all(True)
|
| 1001 | 1021 |
self.xml.drop_area.hide()
|
| 1002 | 1022 |
|
| 1003 |
- def _on_drag_motion(self, *args):
|
|
| 1023 |
+ def _on_drag_motion(self,
|
|
| 1024 |
+ _widget: Gtk.Widget,
|
|
| 1025 |
+ _context: Gdk.DragContext,
|
|
| 1026 |
+ _x_coord: int,
|
|
| 1027 |
+ _y_coord: int,
|
|
| 1028 |
+ _time: int
|
|
| 1029 |
+ ) -> bool:
|
|
| 1004 | 1030 |
self.xml.drop_area.set_no_show_all(False)
|
| 1005 | 1031 |
self.xml.drop_area.show_all()
|
| 1032 |
+ return True
|
|
| 1006 | 1033 |
|
| 1007 | 1034 |
def drag_data_file_transfer(self, selection: Gtk.SelectionData) -> None:
|
| 1008 | 1035 |
# we may have more than one file dropped
|
| ... | ... | @@ -1017,7 +1044,7 @@ def drag_data_file_transfer(self, selection: Gtk.SelectionData) -> None: |
| 1017 | 1044 |
|
| 1018 | 1045 |
self._start_filetransfer(path)
|
| 1019 | 1046 |
|
| 1020 |
- def get_seclabel(self):
|
|
| 1047 |
+ def get_seclabel(self) -> Optional[str]:
|
|
| 1021 | 1048 |
idx = self.xml.label_selector.get_active()
|
| 1022 | 1049 |
if idx == -1:
|
| 1023 | 1050 |
return None
|
| ... | ... | @@ -1032,7 +1059,7 @@ def get_seclabel(self): |
| 1032 | 1059 |
def get_our_nick(self) -> str:
|
| 1033 | 1060 |
return app.nicks[self.account]
|
| 1034 | 1061 |
|
| 1035 |
- def _on_send_message(self, *args):
|
|
| 1062 |
+ def _on_send_message(self, *args: Any) -> None:
|
|
| 1036 | 1063 |
self.msg_textview.replace_emojis()
|
| 1037 | 1064 |
message = self.msg_textview.get_text()
|
| 1038 | 1065 |
self.send_message(message)
|
| ... | ... | @@ -1086,7 +1113,9 @@ def send_message(self, |
| 1086 | 1113 |
|
| 1087 | 1114 |
self.msg_textview.clear()
|
| 1088 | 1115 |
|
| 1089 |
- def _on_message_tv_buffer_changed(self, textbuffer):
|
|
| 1116 |
+ def _on_message_tv_buffer_changed(self,
|
|
| 1117 |
+ textbuffer: Gtk.TextBuffer
|
|
| 1118 |
+ ) -> None:
|
|
| 1090 | 1119 |
has_text = self.msg_textview.has_text()
|
| 1091 | 1120 |
app.window.lookup_action(
|
| 1092 | 1121 |
f'send-message-{self.control_id}').set_enabled(has_text)
|
| ... | ... | @@ -1095,7 +1124,8 @@ def _on_message_tv_buffer_changed(self, textbuffer): |
| 1095 | 1124 |
app.plugin_manager.extension_point(
|
| 1096 | 1125 |
'typing' + self.encryption, self)
|
| 1097 | 1126 |
|
| 1098 |
- self._client.get_module('Chatstate').set_keyboard_activity(self.contact)
|
|
| 1127 |
+ self._client.get_module('Chatstate').set_keyboard_activity(
|
|
| 1128 |
+ self.contact)
|
|
| 1099 | 1129 |
if not has_text:
|
| 1100 | 1130 |
self._client.get_module('Chatstate').set_chatstate_delayed(
|
| 1101 | 1131 |
self.contact, Chatstate.ACTIVE)
|
| ... | ... | @@ -1301,7 +1331,7 @@ def set_emoticon_popover(self) -> None: |
| 1301 | 1331 |
self.xml.emoticons_button.connect('clicked',
|
| 1302 | 1332 |
self._on_emoticon_button_clicked)
|
| 1303 | 1333 |
|
| 1304 |
- def _on_emoticon_button_clicked(self, _widget):
|
|
| 1334 |
+ def _on_emoticon_button_clicked(self, _widget: Gtk.Button) -> None:
|
|
| 1305 | 1335 |
# Present GTK emoji chooser (not cross platform compatible)
|
| 1306 | 1336 |
self.msg_textview.emit('insert-emoji')
|
| 1307 | 1337 |
self.xml.emoticons_button.set_property('active', False)
|
| ... | ... | @@ -1315,7 +1345,7 @@ def _on_formatting_menuitem_activate(self, |
| 1315 | 1345 |
def _style_changed(self, *args):
|
| 1316 | 1346 |
self.update_text_tags()
|
| 1317 | 1347 |
|
| 1318 |
- def update_text_tags(self):
|
|
| 1348 |
+ def update_text_tags(self) -> None:
|
|
| 1319 | 1349 |
self.conversation_view.update_text_tags()
|
| 1320 | 1350 |
|
| 1321 | 1351 |
def set_control_active(self, state: bool) -> None:
|
| ... | ... | @@ -42,6 +42,7 @@ |
| 42 | 42 |
from gajim.common import app
|
| 43 | 43 |
from gajim.common import ged
|
| 44 | 44 |
from gajim.common import events
|
| 45 |
+from gajim.common.const import AvatarSize
|
|
| 45 | 46 |
from gajim.common.const import StyleAttr
|
| 46 | 47 |
from gajim.common.i18n import _
|
| 47 | 48 |
from gajim.common.helpers import allow_showing_notification
|
| ... | ... | @@ -239,7 +240,8 @@ def _get_avatar_for_notification(account: str, |
| 239 | 240 |
scale = get_monitor_scale_factor()
|
| 240 | 241 |
client = app.get_client(account)
|
| 241 | 242 |
contact = client.get_module('Contacts').get_contact(jid)
|
| 242 |
- return app.interface.get_avatar(contact, 32, scale, pixbuf=True)
|
|
| 243 |
+ return app.interface.get_avatar(
|
|
| 244 |
+ contact, AvatarSize.NOTIFICATION, scale, pixbuf=True)
|
|
| 243 | 245 |
|
| 244 | 246 |
def _on_popup_destroy(self, *args):
|
| 245 | 247 |
self._win32_active_popup = None
|
| ... | ... | @@ -18,6 +18,7 @@ |
| 18 | 18 |
from typing import TYPE_CHECKING
|
| 19 | 19 |
|
| 20 | 20 |
if TYPE_CHECKING:
|
| 21 |
+ from .controls.base import BaseControl
|
|
| 21 | 22 |
from .controls.chat import ChatControl
|
| 22 | 23 |
from .controls.private import PrivateChatControl
|
| 23 | 24 |
from .controls.groupchat import GroupchatControl
|
| ... | ... | @@ -38,6 +39,7 @@ |
| 38 | 39 |
|
| 39 | 40 |
|
| 40 | 41 |
ControlType = Union [
|
| 42 |
+ 'BaseControl',
|
|
| 41 | 43 |
'ChatControl',
|
| 42 | 44 |
'PrivateChatControl',
|
| 43 | 45 |
'GroupchatControl'
|
| ... | ... | @@ -57,32 +57,38 @@ |
| 57 | 57 |
from nbxmpp import Hashes2
|
| 58 | 58 |
from nbxmpp import JID
|
| 59 | 59 |
|
| 60 |
-from gajim.common import app
|
|
| 61 |
-from gajim.common.dbus import logind
|
|
| 62 |
-from gajim.common.dbus import music_track
|
|
| 63 |
-from gajim.common.events import AccountDisabled, AccountEnabled, FileCompleted, FileHashError
|
|
| 64 |
-from gajim.common.events import FileProgress
|
|
| 65 |
-from gajim.common.events import FileError
|
|
| 66 |
- |
|
| 67 |
-from gajim.gui import menus
|
|
| 68 | 60 |
from gajim.dialog_messages import get_dialog
|
| 69 | 61 |
|
| 62 |
+from gajim.common import app
|
|
| 63 |
+from gajim.common import ged
|
|
| 64 |
+from gajim.common import exceptions
|
|
| 70 | 65 |
from gajim.common import idle
|
| 71 |
-from gajim.common.zeroconf import connection_zeroconf
|
|
| 72 | 66 |
from gajim.common import proxy65_manager
|
| 73 | 67 |
from gajim.common import socks5
|
| 74 | 68 |
from gajim.common import helpers
|
| 75 | 69 |
from gajim.common import passwords
|
| 70 |
+ |
|
| 71 |
+from gajim.common.dbus import logind
|
|
| 72 |
+from gajim.common.dbus import music_track
|
|
| 73 |
+from gajim.common.events import AccountEnabled
|
|
| 74 |
+from gajim.common.events import AccountDisabled
|
|
| 75 |
+from gajim.common.events import FileCompleted
|
|
| 76 |
+from gajim.common.events import FileHashError
|
|
| 77 |
+from gajim.common.events import FileProgress
|
|
| 78 |
+from gajim.common.events import FileError
|
|
| 79 |
+from gajim.common.zeroconf import connection_zeroconf
|
|
| 76 | 80 |
from gajim.common.helpers import ask_for_status_message
|
| 77 | 81 |
from gajim.common.structs import OutgoingMessage
|
| 78 | 82 |
from gajim.common.i18n import _
|
| 79 | 83 |
from gajim.common.client import Client
|
| 80 | 84 |
from gajim.common.preview import PreviewManager
|
| 81 |
-from gajim.common.const import Display
|
|
| 85 |
+from gajim.common.const import Display, FTState
|
|
| 82 | 86 |
from gajim.common.file_props import FileProp
|
| 83 | 87 |
|
| 84 |
-from gajim.common import ged
|
|
| 85 |
-from gajim.common import exceptions
|
|
| 88 |
+from gajim.common.modules.contacts import GroupchatContact
|
|
| 89 |
+from gajim.common.modules.contacts import GroupchatParticipant
|
|
| 90 |
+from gajim.common.modules.contacts import BareContact
|
|
| 91 |
+from gajim.common.modules.httpupload import HTTPFileTransfer
|
|
| 86 | 92 |
|
| 87 | 93 |
from gajim.gui.avatar import AvatarStorage
|
| 88 | 94 |
from gajim.gui.notification import Notification
|
| ... | ... | @@ -95,13 +101,17 @@ |
| 95 | 101 |
from gajim.gui.filechoosers import FileChooserDialog
|
| 96 | 102 |
from gajim.gui.filetransfer import FileTransfersWindow
|
| 97 | 103 |
from gajim.gui.main import MainWindow
|
| 104 |
+from gajim.gui.menus import build_accounts_menu
|
|
| 98 | 105 |
from gajim.gui.util import get_app_window
|
| 99 | 106 |
from gajim.gui.util import get_app_windows
|
| 100 | 107 |
from gajim.gui.util import get_color_for_account
|
| 101 | 108 |
from gajim.gui.util import open_window
|
| 109 |
+from gajim.gui.types import ControlType
|
|
| 102 | 110 |
|
| 103 | 111 |
log = logging.getLogger('gajim.interface')
|
| 104 | 112 |
|
| 113 |
+ContactT = Union[BareContact, GroupchatContact, GroupchatParticipant]
|
|
| 114 |
+ |
|
| 105 | 115 |
|
| 106 | 116 |
class Interface:
|
| 107 | 117 |
def __init__(self):
|
| ... | ... | @@ -189,7 +199,7 @@ def __init__(self): |
| 189 | 199 |
self._network_status_changed)
|
| 190 | 200 |
self._network_state: bool = self._network_monitor.get_network_available()
|
| 191 | 201 |
|
| 192 |
- def _create_core_handlers_list(self):
|
|
| 202 |
+ def _create_core_handlers_list(self) -> None:
|
|
| 193 | 203 |
# pylint: disable=line-too-long
|
| 194 | 204 |
self.handlers = {
|
| 195 | 205 |
'information': [self.handle_event_information],
|
| ... | ... | @@ -209,7 +219,7 @@ def _create_core_handlers_list(self): |
| 209 | 219 |
}
|
| 210 | 220 |
# pylint: enable=line-too-long
|
| 211 | 221 |
|
| 212 |
- def _register_core_handlers(self):
|
|
| 222 |
+ def _register_core_handlers(self) -> None:
|
|
| 213 | 223 |
"""
|
| 214 | 224 |
Register core handlers in Global Events Dispatcher (GED).
|
| 215 | 225 |
|
| ... | ... | @@ -297,7 +307,7 @@ def handle_event_plain_connection(event): |
| 297 | 307 |
@staticmethod
|
| 298 | 308 |
def handle_event_http_auth(event):
|
| 299 | 309 |
# ('HTTP_AUTH', account, (method, url, transaction_id, iq_obj, msg))
|
| 300 |
- def _response(_account, answer):
|
|
| 310 |
+ def _response(answer: str) -> None:
|
|
| 301 | 311 |
event.conn.get_module('HTTPAuth').build_http_auth_answer(
|
| 302 | 312 |
event.stanza, answer)
|
| 303 | 313 |
|
| ... | ... | @@ -321,10 +331,10 @@ def _response(_account, answer): |
| 321 | 331 |
[DialogButton.make('Cancel',
|
| 322 | 332 |
text=_('_No'),
|
| 323 | 333 |
callback=_response,
|
| 324 |
- args=[event, 'no']),
|
|
| 334 |
+ args=['no']),
|
|
| 325 | 335 |
DialogButton.make('Accept',
|
| 326 | 336 |
callback=_response,
|
| 327 |
- args=[event, 'yes'])]).show()
|
|
| 337 |
+ args=['yes'])]).show()
|
|
| 328 | 338 |
|
| 329 | 339 |
@staticmethod
|
| 330 | 340 |
def handle_event_client_cert_passphrase(event):
|
| ... | ... | @@ -588,7 +598,10 @@ def __compare_hashes(account: str, file_props: FileProp) -> None: |
| 588 | 598 |
if session:
|
| 589 | 599 |
session.end_session()
|
| 590 | 600 |
|
| 591 |
- def send_httpupload(self, chat_control, path=None):
|
|
| 601 |
+ def send_httpupload(self,
|
|
| 602 |
+ chat_control: ControlType,
|
|
| 603 |
+ path: Optional[str] = None
|
|
| 604 |
+ ) -> None:
|
|
| 592 | 605 |
if path is not None:
|
| 593 | 606 |
self._send_httpupload(chat_control, path)
|
| 594 | 607 |
return
|
| ... | ... | @@ -598,11 +611,14 @@ def send_httpupload(self, chat_control, path=None): |
| 598 | 611 |
select_multiple=True,
|
| 599 | 612 |
transient_for=app.window)
|
| 600 | 613 |
|
| 601 |
- def _on_file_dialog_ok(self, chat_control, paths):
|
|
| 614 |
+ def _on_file_dialog_ok(self,
|
|
| 615 |
+ chat_control: ControlType,
|
|
| 616 |
+ paths: list[str]
|
|
| 617 |
+ ) -> None:
|
|
| 602 | 618 |
for path in paths:
|
| 603 | 619 |
self._send_httpupload(chat_control, path)
|
| 604 | 620 |
|
| 605 |
- def _send_httpupload(self, chat_control, path):
|
|
| 621 |
+ def _send_httpupload(self, chat_control: ControlType, path: str) -> None:
|
|
| 606 | 622 |
client = app.get_client(chat_control.account)
|
| 607 | 623 |
try:
|
| 608 | 624 |
transfer = client.get_module('HTTPUpload').make_transfer(
|
| ... | ... | @@ -620,7 +636,11 @@ def _send_httpupload(self, chat_control, path): |
| 620 | 636 |
chat_control.add_file_transfer(transfer)
|
| 621 | 637 |
client.get_module('HTTPUpload').start_transfer(transfer)
|
| 622 | 638 |
|
| 623 |
- def _on_http_upload_state_changed(self, transfer, _signal_name, state):
|
|
| 639 |
+ def _on_http_upload_state_changed(self,
|
|
| 640 |
+ transfer: HTTPFileTransfer,
|
|
| 641 |
+ _signal_name: str,
|
|
| 642 |
+ state: FTState
|
|
| 643 |
+ ) -> None:
|
|
| 624 | 644 |
# Note: This has to be a bound method in order to connect the signal
|
| 625 | 645 |
if state.is_finished:
|
| 626 | 646 |
uri = transfer.get_transformed_uri()
|
| ... | ... | @@ -638,7 +658,10 @@ def _on_http_upload_state_changed(self, transfer, _signal_name, state): |
| 638 | 658 |
client = app.get_client(transfer.account)
|
| 639 | 659 |
client.send_message(message)
|
| 640 | 660 |
|
| 641 |
- def _on_cancel_upload(self, transfer, _signal_name):
|
|
| 661 |
+ def _on_cancel_upload(self,
|
|
| 662 |
+ transfer: HTTPFileTransfer,
|
|
| 663 |
+ _signal_name: str
|
|
| 664 |
+ ) -> None:
|
|
| 642 | 665 |
# Note: This has to be a bound method in order to connect the signal
|
| 643 | 666 |
client = app.get_client(transfer.account)
|
| 644 | 667 |
client.get_module('HTTPUpload').cancel_transfer(transfer)
|
| ... | ... | @@ -648,7 +671,7 @@ def create_groupchat(account: str, |
| 648 | 671 |
room_jid: str,
|
| 649 | 672 |
config: Dict[str, Union[str, bool]]
|
| 650 | 673 |
) -> None:
|
| 651 |
- if app.window.chat_exists(account, room_jid):
|
|
| 674 |
+ if app.window.chat_exists(account, JID.from_string(room_jid)):
|
|
| 652 | 675 |
log.error('Trying to create groupchat '
|
| 653 | 676 |
'which is already added as chat')
|
| 654 | 677 |
return
|
| ... | ... | @@ -667,18 +690,18 @@ def show_add_join_groupchat(account: str, |
| 667 | 690 |
client.get_module('MUC').join(
|
| 668 | 691 |
jid, nick=nickname, password=password)
|
| 669 | 692 |
|
| 670 |
- app.window.add_group_chat(account, jid, select=True)
|
|
| 693 |
+ app.window.add_group_chat(account, JID.from_string(jid), select=True)
|
|
| 671 | 694 |
|
| 672 | 695 |
@staticmethod
|
| 673 | 696 |
def start_chat_from_jid(account: str,
|
| 674 | 697 |
jid: str,
|
| 675 | 698 |
message: Optional[str] = None
|
| 676 | 699 |
) -> None:
|
| 677 |
- jid = JID.from_string(jid)
|
|
| 678 |
- if app.window.chat_exists(account, jid):
|
|
| 679 |
- app.window.select_chat(account, jid)
|
|
| 700 |
+ jid_ = JID.from_string(jid)
|
|
| 701 |
+ if app.window.chat_exists(account, jid_):
|
|
| 702 |
+ app.window.select_chat(account, jid_)
|
|
| 680 | 703 |
if message is not None:
|
| 681 |
- control = app.window.get_control(account, jid)
|
|
| 704 |
+ control = app.window.get_control(account, jid_)
|
|
| 682 | 705 |
if control is None:
|
| 683 | 706 |
return
|
| 684 | 707 |
control.msg_textview.insert_text(message)
|
| ... | ... | @@ -779,7 +802,7 @@ def enable_account(self, account: str) -> None: |
| 779 | 802 |
app.block_signed_in_notifications[account] = True
|
| 780 | 803 |
|
| 781 | 804 |
app.settings.set_account_setting(account, 'active', True)
|
| 782 |
- menus.build_accounts_menu()
|
|
| 805 |
+ build_accounts_menu()
|
|
| 783 | 806 |
app.app.update_app_actions_state()
|
| 784 | 807 |
|
| 785 | 808 |
app.ged.raise_event(AccountEnabled(account=account))
|
| ... | ... | @@ -799,7 +822,7 @@ def disable_account(self, account: str) -> None: |
| 799 | 822 |
|
| 800 | 823 |
app.settings.set_account_setting(account, 'roster_version', '')
|
| 801 | 824 |
app.settings.set_account_setting(account, 'active', False)
|
| 802 |
- menus.build_accounts_menu()
|
|
| 825 |
+ build_accounts_menu()
|
|
| 803 | 826 |
app.app.update_app_actions_state()
|
| 804 | 827 |
|
| 805 | 828 |
app.ged.raise_event(AccountDisabled(account=account))
|
| ... | ... | @@ -954,12 +977,12 @@ def save_avatar(self, data: bytes) -> Optional[str]: |
| 954 | 977 |
return self.avatar_storage.save_avatar(data)
|
| 955 | 978 |
|
| 956 | 979 |
def get_avatar(self,
|
| 957 |
- contact,
|
|
| 958 |
- size,
|
|
| 959 |
- scale,
|
|
| 960 |
- show=None,
|
|
| 961 |
- pixbuf=False,
|
|
| 962 |
- style='circle'):
|
|
| 980 |
+ contact: ContactT,
|
|
| 981 |
+ size: int,
|
|
| 982 |
+ scale: int,
|
|
| 983 |
+ show: Optional[str] = None,
|
|
| 984 |
+ pixbuf: bool = False,
|
|
| 985 |
+ style: str = 'circle'):
|
|
| 963 | 986 |
if pixbuf:
|
| 964 | 987 |
return self.avatar_storage.get_pixbuf(
|
| 965 | 988 |
contact, size, scale, show, style=style)
|
| ... | ... | @@ -1010,7 +1033,10 @@ def _on_delete(win, _event): |
| 1010 | 1033 |
view.updateNamespace({'gajim': app})
|
| 1011 | 1034 |
app.ipython_window = window
|
| 1012 | 1035 |
|
| 1013 |
- def _network_status_changed(self, monitor, _param):
|
|
| 1036 |
+ def _network_status_changed(self,
|
|
| 1037 |
+ monitor: Gio.NetworkMonitor,
|
|
| 1038 |
+ _network_available: bool
|
|
| 1039 |
+ ) -> None:
|
|
| 1014 | 1040 |
connected = monitor.get_network_available()
|
| 1015 | 1041 |
if connected == self._network_state:
|
| 1016 | 1042 |
return
|