Daniel Brötzmann pushed to branch mainwindow at gajim / gajim
Commits: c1516f8e by wurstsalat at 2021-11-27T17:03:00+01:00 Main: Linting
- - - - - d50ccbb4 by wurstsalat at 2021-11-27T18:38:41+01:00 AccountWizard: Typing
- - - - - 20ca9875 by wurstsalat at 2021-11-27T18:38:53+01:00 SSLErrorDialog: Typing
- - - - - a74e581b by wurstsalat at 2021-11-27T18:39:13+01:00 CreateGroupchatWindow: Typing
- - - - - bfa221a9 by wurstsalat at 2021-11-27T18:39:30+01:00 Interface: Typing
- - - - -
5 changed files:
- gajim/gtk/account_wizard.py - gajim/gtk/groupchat_creation.py - gajim/gtk/main.py - gajim/gtk/ssl_error_dialog.py - gajim/gui_interface.py
Changes:
===================================== gajim/gtk/account_wizard.py ===================================== @@ -12,6 +12,11 @@ # You should have received a copy of the GNU General Public License # along with Gajim. If not, see http://www.gnu.org/licenses/.
+from typing import Optional +from typing import List +from typing import Tuple +from typing import Union + import logging
from gi.repository import Gdk @@ -54,10 +59,10 @@
class AccountWizard(Assistant): - def __init__(self): + def __init__(self) -> None: Assistant.__init__(self, height=500)
- self._destroyed = False + self._destroyed: bool = False
self.add_button('signup', _('Sign Up'), complete=True, css_class='suggested-action') @@ -88,10 +93,10 @@ def __init__(self):
self.update_proxy_list()
- self._client = None - self._method = 'login' + self._client: Optional[Client] = None + self._method: str = 'login'
- def get_currenct_method(self): + def get_currenct_method(self) -> str: return self._method
def _on_button_clicked(self, _page, button_name): @@ -190,15 +195,16 @@ def _on_page_changed(self, _assistant, page_name): elif page_name == 'form': self.get_page('form').focus()
- def update_proxy_list(self): + def update_proxy_list(self) -> None: self.get_page('advanced').update_proxy_list()
def _get_base_client(self, - domain, - username, - mode, - advanced, - ignore_all_errors): + domain: str, + username: str, + mode: Mode, + advanced: bool, + ignore_all_errors: bool + ) -> Client:
client = Client(log_context='Account Wizard') client.set_domain(domain) @@ -224,7 +230,7 @@ def _get_base_client(self, client.subscribe('stanza-received', self._on_stanza_received) return client
- def _disconnect(self): + def _disconnect(self) -> None: if self._client is None: return self._client.remove_subscriptions() @@ -243,7 +249,7 @@ def _on_stanza_received(_client, _signal_name, stanza): account='AccountWizard', stanza=stanza))
- def _test_credentials(self, ignore_all_errors=False): + def _test_credentials(self, ignore_all_errors: bool = False) -> None: self._show_progress_page(_('Connecting...'), _('Connecting to server...')) address, password = self.get_page('login').get_credentials() @@ -262,7 +268,7 @@ def _test_credentials(self, ignore_all_errors=False):
self._client.connect()
- def _test_anonymous_server(self, ignore_all_errors=False): + def _test_anonymous_server(self, ignore_all_errors: bool = False) -> None: self._show_progress_page(_('Connecting...'), _('Connecting to server...')) domain = self.get_page('signup').get_server() @@ -279,7 +285,7 @@ def _test_anonymous_server(self, ignore_all_errors=False): self._on_anonymous_supported) self._client.connect()
- def _register_with_server(self, ignore_all_errors=False): + def _register_with_server(self, ignore_all_errors: bool = False) -> None: self._show_progress_page(_('Connecting...'), _('Connecting to server...')) domain = self.get_page('signup').get_server() @@ -380,19 +386,19 @@ def _on_connection_failed(self, _client, _signal_name): self._client.destroy() self._client = None
- def _show_error_page(self, title, heading, text): + def _show_error_page(self, title: str, heading: str, text: str) -> None: self.get_page('error').set_title(title) self.get_page('error').set_heading(heading) self.get_page('error').set_text(text or '') self.show_page('error', Gtk.StackTransitionType.SLIDE_LEFT)
- def _show_progress_page(self, title, text): + def _show_progress_page(self, title: str, text: str) -> None: self._progress.set_title(title) self._progress.set_text(text) self.show_page('progress', Gtk.StackTransitionType.SLIDE_LEFT)
@staticmethod - def _generate_account_name(domain): + def _generate_account_name(domain: str) -> str: i = 1 while domain in app.settings.get_accounts(): domain = domain + str(i) @@ -429,7 +435,7 @@ def _on_register_form(self, task):
self.show_page('form', Gtk.StackTransitionType.SLIDE_LEFT)
- def _submit_form(self): + def _submit_form(self) -> None: self.get_page('progress').set_text(_('Account is being created')) self.show_page('progress', Gtk.StackTransitionType.SLIDE_LEFT)
@@ -486,7 +492,11 @@ def _on_register_result(self, task): self.get_page('form').remove_form() self._disconnect()
- def _set_error_text(self, error): + def _set_error_text(self, + error: Union[StanzaError, + RegisterStanzaError, + MalformedStanzaError] + ) -> None: error_text = error.get_text() if not error_text: error_text = _('The server rejected the registration ' @@ -504,7 +514,7 @@ class Login(Page): 'clicked': (GObject.SignalFlags.RUN_LAST, None, (str,)), }
- def __init__(self): + def __init__(self) -> None: Page.__init__(self) self.title = _('Add Account')
@@ -525,7 +535,7 @@ def __init__(self): self.pack_start(self._ui.login_box, True, True, 0) self.show_all()
- def focus(self): + def focus(self) -> None: self._ui.log_in_address_entry.grab_focus()
def _on_login(self, *args): @@ -534,7 +544,7 @@ def _on_login(self, *args): def _on_signup(self, *args): self.emit('clicked', 'signup')
- def _create_server_completion(self): + def _create_server_completion(self) -> None: # Parse servers.json file_path = configpaths.get('DATA') / 'other' / 'servers.json' self._servers = helpers.load_json(file_path, default=[]) @@ -561,9 +571,9 @@ def _update_completion(self, entry): model.clear()
for server in self._servers: - model.append(['%s@%s' % (text, server)]) + model.append([f'{text}@{server}'])
- def _show_icon(self, show): + def _show_icon(self, show: bool) -> None: icon = 'dialog-warning-symbolic' if show else None self._ui.log_in_address_entry.set_icon_from_icon_name( Gtk.EntryIconPosition.SECONDARY, icon) @@ -575,7 +585,7 @@ def _on_password_entry_activate(self, _widget): if self._ui.log_in_button.get_sensitive(): self._ui.log_in_button.activate()
- def _validate_jid(self, address): + def _validate_jid(self, address: str) -> bool: if not address: self._show_icon(False) return False @@ -598,10 +608,10 @@ def _set_complete(self, *args): password = self._ui.log_in_password_entry.get_text() self._ui.log_in_button.set_sensitive(address and password)
- def is_advanced(self): + def is_advanced(self) -> bool: return self._ui.login_advanced_checkbutton.get_active()
- def get_credentials(self): + def get_credentials(self) -> Tuple[str, str]: data = (self._ui.log_in_address_entry.get_text(), self._ui.log_in_password_entry.get_text()) return data @@ -610,8 +620,8 @@ def get_credentials(self): class Signup(Page): def __init__(self): Page.__init__(self) - self.complete = False - self.title = _('Create New Account') + self.complete: bool = False + self.title: str = _('Create New Account')
self._ui = get_builder('account_wizard.ui') self._ui.server_comboboxtext_sign_up_entry.set_activates_default(True) @@ -630,10 +640,10 @@ def __init__(self):
self.show_all()
- def focus(self): + def focus(self) -> None: self._ui.server_comboboxtext_sign_up_entry.grab_focus()
- def _create_server_completion(self): + def _create_server_completion(self) -> None: # Parse servers.json file_path = configpaths.get('DATA') / 'other' / 'servers.json' servers = helpers.load_json(file_path, default=[]) @@ -650,7 +660,7 @@ def _create_server_completion(self):
def _on_visit_server(self, _widget): server = self._ui.server_comboboxtext_sign_up_entry.get_text().strip() - server = 'https://' + server + server = f'https://%7Bserver%7D' open_uri(server) return Gdk.EVENT_STOP
@@ -666,13 +676,13 @@ def _set_complete(self, *args):
self.update_page_complete()
- def is_anonymous(self): + def is_anonymous(self) -> bool: return self._ui.sign_up_anonymously.get_active()
- def is_advanced(self): + def is_advanced(self) -> bool: return self._ui.sign_up_advanced_checkbutton.get_active()
- def get_server(self): + def get_server(self) -> str: return validate_domainpart( self._ui.server_comboboxtext_sign_up_entry.get_text())
@@ -683,18 +693,18 @@ def _on_activate_link(_label, uri): open_uri(uri) return Gdk.EVENT_STOP
- def get_visible_buttons(self): + def get_visible_buttons(self) -> List[str]: return ['back', 'signup']
- def get_default_button(self): + def get_default_button(self) -> str: return 'signup'
class AdvancedSettings(Page): def __init__(self): Page.__init__(self) - self.title = _('Advanced settings') - self.complete = False + self.title: str = _('Advanced settings') + self.complete: bool = False
self._ui = get_builder('account_wizard.ui') self._ui.manage_proxies_button.connect('clicked', @@ -710,7 +720,7 @@ def __init__(self): def _on_proxy_manager(_widget): app.app.activate_action('manage-proxies')
- def update_proxy_list(self): + def update_proxy_list(self) -> None: model = Gtk.ListStore(str) self._ui.proxies_combobox.set_model(model) proxies = app.settings.get_proxies() @@ -719,11 +729,13 @@ def update_proxy_list(self): model.append([proxy]) self._ui.proxies_combobox.set_active(0)
- def get_proxy(self): + def get_proxy(self) -> str: active = self._ui.proxies_combobox.get_active() return self._ui.proxies_combobox.get_model()[active][0]
- def get_custom_host(self): + def get_custom_host(self) -> Optional[Tuple[str, + ConnectionProtocol, + ConnectionType]]: host = self._ui.custom_host_entry.get_text() port = self._ui.custom_port_entry.get_text() if not host or not port: @@ -735,21 +747,19 @@ def get_custom_host(self): if host.startswith('ws://') or host.startswith('wss://'): protocol = ConnectionProtocol.WEBSOCKET
- return ('%s:%s' % (host, port), - protocol, - ConnectionType(con_type)) + return (f'{host}:{port}', protocol, ConnectionType(con_type))
- def _show_host_icon(self, show): + def _show_host_icon(self, show: bool) -> None: icon = 'dialog-warning-symbolic' if show else None self._ui.custom_host_entry.set_icon_from_icon_name( Gtk.EntryIconPosition.SECONDARY, icon)
- def _show_port_icon(self, show): + def _show_port_icon(self, show: bool) -> None: icon = 'dialog-warning-symbolic' if show else None self._ui.custom_port_entry.set_icon_from_icon_name( Gtk.EntryIconPosition.SECONDARY, icon)
- def _validate_host(self): + def _validate_host(self) -> bool: host = self._ui.custom_host_entry.get_text() if host.startswith('ws://') or host.startswith('wss://'): # We have no method for validating websocket URIs @@ -767,7 +777,7 @@ def _validate_host(self): self._show_host_icon(False) return True
- def _validate_port(self): + def _validate_port(self) -> bool: port = self._ui.custom_port_entry.get_text() if not port: self._show_port_icon(False) @@ -791,12 +801,12 @@ def _validate_port(self): self._show_port_icon(False) return True
- def _is_custom_host_set(self): + def _is_custom_host_set(self) -> bool: host = bool(self._ui.custom_host_entry.get_text()) port = bool(self._ui.custom_port_entry.get_text()) return host or port
- def _is_proxy_set(self): + def _is_proxy_set(self) -> bool: return self._ui.proxies_combobox.get_active() != 0
def _set_complete(self, *args): @@ -811,19 +821,19 @@ def _set_complete(self, *args):
self.update_page_complete()
- def get_visible_buttons(self): + def get_visible_buttons(self) -> List[str]: return ['back', self.get_toplevel().get_currenct_method()]
- def get_default_button(self): + def get_default_button(self) -> str: return self.get_toplevel().get_currenct_method()
class SecurityWarning(Page): - def __init__(self): + def __init__(self) -> None: Page.__init__(self) - self.title = _('Security Warning') - self._cert = None - self._domain = None + self.title: str = _('Security Warning') + self._cert: Optional[Gio.TlsCertificate] = None + self._domain: Optional[str] = None
self._ui = get_builder('account_wizard.ui') self.pack_start(self._ui.security_warning_box, True, True, 0) @@ -831,10 +841,14 @@ def __init__(self): self.show_all()
@property - def cert(self): + def cert(self) -> Optional[Gio.TlsCertificate]: return self._cert
- def set_warning(self, domain, cert, errors): + def set_warning(self, + domain: str, + cert: Gio.TlsCertificate, + errors: List[Gio.TlsCertificateFlags] + ) -> None: # Clear list self._cert = cert self._domain = domain @@ -866,22 +880,22 @@ def _on_view_cert(self, _button): cert=self._cert)
@property - def trust_certificate(self): + def trust_certificate(self) -> bool: return self._ui.trust_cert_checkbutton.get_active()
- def get_visible_buttons(self): + def get_visible_buttons(self) -> List[str]: return ['back', self.get_toplevel().get_currenct_method()]
- def get_default_button(self): + def get_default_button(self) -> str: return 'back'
class Form(Page): - def __init__(self): + def __init__(self) -> None: Page.__init__(self) self.set_valign(Gtk.Align.FILL) self.complete = False - self.title = _('Create Account') + self.title: str = _('Create Account') self._current_form = None
heading = Gtk.Label(label=_('Create Account')) @@ -895,7 +909,7 @@ def __init__(self): self.show_all()
@property - def has_form(self): + def has_form(self) -> bool: return self._current_form is not None
def _on_is_valid(self, _widget, is_valid): @@ -913,14 +927,14 @@ def add_form(self, form): self.pack_start(self._current_form, True, True, 0) self._current_form.show_all()
- def get_credentials(self): + def get_credentials(self) -> Tuple[str, str]: return (self._current_form.get_form()['username'].value, self._current_form.get_form()['password'].value)
def get_submit_form(self): return self._current_form.get_submit_form()
- def remove_form(self): + def remove_form(self) -> None: if self._current_form is None: return
@@ -928,28 +942,28 @@ def remove_form(self): self._current_form.destroy() self._current_form = None
- def focus(self): + def focus(self) -> None: self._current_form.focus_first_entry()
- def get_visible_buttons(self): + def get_visible_buttons(self) -> List[str]: return ['back', 'signup']
- def get_default_button(self): + def get_default_button(self) -> str: return 'signup'
class Redirect(Page): - def __init__(self): + def __init__(self) -> None: Page.__init__(self) - self.title = _('Redirect') - self._link = None + self.title: str = _('Redirect') + self._link: Optional[str] = None
self._ui = get_builder('account_wizard.ui') self.pack_start(self._ui.redirect_box, True, True, 0) self._ui.link_button.connect('clicked', self._on_link_button) self.show_all()
- def set_redirect(self, link, instructions): + def set_redirect(self, link: str, instructions: str) -> None: if instructions is None: instructions = _('Register on the Website') self._ui.instructions.set_text(instructions) @@ -958,33 +972,33 @@ def set_redirect(self, link, instructions): def _on_link_button(self, _button): open_uri(self._link)
- def get_visible_buttons(self): + def get_visible_buttons(self) -> List[str]: return ['back']
class Success(SuccessPage): - def __init__(self): + def __init__(self) -> None: SuccessPage.__init__(self) self.set_title(_('Account Added')) self.set_heading(_('Account has been added successfully'))
- self._account = None + self._account: Optional[str] = None
- def set_account(self, account): + def set_account(self, account: str) -> None: self._account = account
@property - def account(self): + def account(self) -> Optional[str]: return self._account
- def get_visible_buttons(self): + def get_visible_buttons(self) -> List[str]: return ['connect']
class Error(ErrorPage): - def __init__(self): + def __init__(self) -> None: ErrorPage.__init__(self) self.set_heading(_('An error occurred during account creation'))
- def get_visible_buttons(self): + def get_visible_buttons(self) -> List[str]: return ['back']
===================================== gajim/gtk/groupchat_creation.py ===================================== @@ -35,7 +35,7 @@
class CreateGroupchatWindow(Gtk.ApplicationWindow): - def __init__(self, account): + def __init__(self, account: str) -> None: Gtk.ApplicationWindow.__init__(self) self.set_name('CreateGroupchat') self.set_application(app.app) @@ -49,7 +49,7 @@ def __init__(self, account): self._ui = get_builder('groupchat_creation.ui') self.add(self._ui.create_group_chat)
- self._destroyed = False + self._destroyed: bool = False
self._account = self._fill_account_combo(account)
@@ -63,11 +63,11 @@ def __init__(self, account): self.show_all() self.set_focus(self._ui.address_entry)
- def _get_muc_service_jid(self): + def _get_muc_service_jid(self) -> str: con = app.connections[self._account] return str(con.get_module('MUC').service_jid or 'muc.example.com')
- def _fill_account_combo(self, account): + def _fill_account_combo(self, account: str) -> str: accounts = app.get_enabled_accounts_with_labels(connected_only=True) account_liststore = self._ui.account_combo.get_model() for acc in accounts: @@ -84,7 +84,7 @@ def _fill_account_combo(self, account): self._ui.account_combo.set_active_id(account) return account
- def _create_entry_completion(self): + def _create_entry_completion(self) -> None: entry_completion = Gtk.EntryCompletion() model = Gtk.ListStore(str) entry_completion.set_model(model) @@ -95,7 +95,7 @@ def _create_entry_completion(self):
self._ui.address_entry.set_completion(entry_completion)
- def _fill_placeholders(self): + def _fill_placeholders(self) -> None: placeholder = random.choice(MUC_CREATION_EXAMPLES) server = self._get_muc_service_jid()
@@ -104,7 +104,7 @@ def _fill_placeholders(self): self._ui.description_entry.set_placeholder_text( placeholder[1] + _(' (optional)...')) self._ui.address_entry.set_placeholder_text( - '%s@%s' % (placeholder[2], server)) + f'{placeholder[2]}@{server}')
def _on_key_press_event(self, _widget, event): if event.keyval == Gdk.KEY_Escape: @@ -123,9 +123,9 @@ def _update_entry_completion(self, entry, text): model.clear()
server = self._get_muc_service_jid() - model.append(['%s@%s' % (text, server)]) + model.append([f'{text}@{server}'])
- def _validate_jid(self, text): + def _validate_jid(self, text: str) -> None: if not text: self._set_warning_icon(False) self._ui.create_button.set_sensitive(False) @@ -142,7 +142,7 @@ def _validate_jid(self, text): self._set_warning_icon(False) self._ui.create_button.set_sensitive(True)
- def _set_processing_state(self, enabled): + def _set_processing_state(self, enabled: bool) -> None: if enabled: self._ui.spinner.start() self._ui.create_button.set_sensitive(False) @@ -150,28 +150,28 @@ def _set_processing_state(self, enabled): self._ui.spinner.stop() self._ui.grid.set_sensitive(not enabled)
- def _set_warning_icon(self, enabled): + def _set_warning_icon(self, enabled: bool) -> None: icon = 'dialog-warning-symbolic' if enabled else None self._ui.address_entry.set_icon_from_icon_name( Gtk.EntryIconPosition.SECONDARY, icon)
- def _set_warning_tooltip(self, text): + def _set_warning_tooltip(self, text: str) -> None: self._ui.address_entry.set_icon_tooltip_text( Gtk.EntryIconPosition.SECONDARY, text)
- def _set_warning(self, text): + def _set_warning(self, text: str) -> None: self._set_warning_icon(True) self._set_warning_tooltip(text) self._ui.create_button.set_sensitive(False)
- def _set_warning_from_error(self, error): + def _set_warning_from_error(self, error: StanzaError) -> None: condition = error.condition if condition == 'gone': condition = 'already-exists' text = MUC_DISCO_ERRORS.get(condition, to_user_string(error)) self._set_warning(text)
- def _set_warning_from_error_code(self, error_code): + def _set_warning_from_error_code(self, error_code: str) -> None: self._set_warning(MUC_DISCO_ERRORS[error_code])
def _on_address_entry_changed(self, entry): @@ -212,7 +212,7 @@ def _disco_info_received(self, task):
self._set_processing_state(False)
- def _create_muc(self, room_jid): + def _create_muc(self, room_jid: str) -> None: name = self._ui.name_entry.get_text() description = self._ui.description_entry.get_text() is_public = self._ui.public_switch.get_active()
===================================== gajim/gtk/main.py ===================================== @@ -222,7 +222,6 @@ def _on_action(self, action, _param): control = self.get_active_control() if control is None: return None - log.info('Activate action: %s, active control: %s', action.get_name(), control.contact.jid)
@@ -281,6 +280,8 @@ def _on_action(self, action, _param): self.select_chat_number(number) return None
+ return None + def _on_window_motion_notify(self, _widget, _event): control = self.get_active_control() if control is None:
===================================== gajim/gtk/ssl_error_dialog.py ===================================== @@ -12,11 +12,11 @@ # You should have received a copy of the GNU General Public License # along with Gajim. If not, see http://www.gnu.org/licenses/.
- -from gi.repository import Gtk from gi.repository import Gio +from gi.repository import Gtk
from gajim.common import app +from gajim.common.client import Client
from gajim.common.const import GIO_TLS_ERRORS from gajim.common.i18n import _ @@ -26,7 +26,12 @@
class SSLErrorDialog(Gtk.ApplicationWindow): - def __init__(self, account, client, cert, error): + def __init__(self, + account: str, + client: Client, + cert: Gio.TlsCertificate, + error: Gio.TlsCertificateFlags + ) -> None: Gtk.ApplicationWindow.__init__(self) self.set_name('SSLErrorDialog') self.set_application(app.app) @@ -50,7 +55,7 @@ def __init__(self, account, client, cert, error): self._ui.connect_signals(self) self.show_all()
- def _process_error(self): + def _process_error(self) -> None: self._ui.intro_text.set_text( _('There was an error while attempting to verify the SSL ' 'certificate of your XMPP server (%s).') % self._server)
===================================== gajim/gui_interface.py ===================================== @@ -31,6 +31,10 @@ # You should have received a copy of the GNU General Public License # along with Gajim. If not, see http://www.gnu.org/licenses/.
+from typing import Dict +from typing import Optional +from typing import Union + import os import sys import time @@ -72,6 +76,7 @@ from gajim.common.client import Client from gajim.common.preview import PreviewManager from gajim.common.const import Display +from gajim.common.file_props import FileProp
from gajim.common.connection_handlers_events import InformationEvent
@@ -123,7 +128,7 @@ def __init__(self): self.handle_event_file_progress, self.handle_event_file_error)
- self._last_ft_progress_update = 0 + self._last_ft_progress_update: float = 0
app.proxy65_manager = proxy65_manager.Proxy65Manager(app.idlequeue)
@@ -149,19 +154,19 @@ def __init__(self):
self.instances = {}
- for a in app.connections: - self.instances[a] = { + for acc in app.connections: + self.instances[acc] = { 'infos': {}, 'disco': {} } - app.contacts.add_account(a) - app.groups[a] = {} - app.gc_connected[a] = {} - app.automatic_rooms[a] = {} - app.newly_added[a] = [] - app.to_be_removed[a] = [] - app.nicks[a] = app.settings.get_account_setting(a, 'name') - app.block_signed_in_notifications[a] = True + app.contacts.add_account(acc) + app.groups[acc] = {} + app.gc_connected[acc] = {} + app.automatic_rooms[acc] = {} + app.newly_added[acc] = [] + app.to_be_removed[acc] = [] + app.nicks[acc] = app.settings.get_account_setting(acc, 'name') + app.block_signed_in_notifications[acc] = True
if sys.platform not in ('win32', 'darwin'): logind.enable() @@ -172,7 +177,7 @@ def __init__(self): idle.Monitor.set_interval(app.settings.get('autoawaytime') * 60, app.settings.get('autoxatime') * 60)
- self.systray_enabled = False + self.systray_enabled: bool = False
if not app.is_display(Display.WAYLAND): from gajim.gui.status_icon import StatusIcon @@ -185,10 +190,10 @@ def __init__(self): self._network_monitor = Gio.NetworkMonitor.get_default() self._network_monitor.connect('notify::network-available', self._network_status_changed) - self._network_state = self._network_monitor.get_network_available() + self._network_state: bool = self._network_monitor.get_network_available()
def _create_core_handlers_list(self): - # pyline: disable=line-too-long + # pylint: disable=line-too-long self.handlers = { 'information': [self.handle_event_information], 'iq-error-received': [self.handle_event_iq_error], @@ -225,7 +230,7 @@ def _register_core_handlers(self): prio, event_handler)
- def handle_event(self, account, jid, notif_detail): + def handle_event(self, account: str, jid: str, notif_detail: str) -> None: jid = JID.from_string(jid)
if notif_detail in ('connection-lost', 'connection-failed'): @@ -423,7 +428,7 @@ def handle_event_status(self, event): event.account)
@staticmethod - def _unblock_signed_in_notifications(account): + def _unblock_signed_in_notifications(account: str) -> None: app.block_signed_in_notifications[account] = False
@staticmethod @@ -489,11 +494,14 @@ def handle_event_roster_item_exchange(event):
# Jingle File Transfer @staticmethod - def handle_event_file_error(title, message): + def handle_event_file_error(title: str, message: str) -> None: # TODO: integrate this better ErrorDialog(title, message)
- def handle_event_file_progress(self, _account, file_props): + def handle_event_file_progress(self, + _account: str, + file_props: FileProp + ) -> None: if time.time() - self._last_ft_progress_update < 0.5: # Update progress every 500ms only return @@ -502,7 +510,10 @@ def handle_event_file_progress(self, _account, file_props): app.nec.push_incoming_event( NetworkEvent('file-progress', file_props=file_props))
- def handle_event_file_rcv_completed(self, account, file_props): + def handle_event_file_rcv_completed(self, + account: str, + file_props: FileProp + ) -> None: jid = JID.from_string(file_props.receiver) if file_props.error != 0: self.instances['file_transfers'].set_status(file_props, 'stop') @@ -560,7 +571,8 @@ def handle_event_file_rcv_completed(self, account, file_props): account=account, jid=jid.bare))
- def __compare_hashes(self, account, file_props): + @staticmethod + def __compare_hashes(account: str, file_props: FileProp) -> None: hashes = Hashes2() try: file_ = open(file_props.file_name, 'rb') @@ -651,7 +663,11 @@ def _on_cancel_upload(self, transfer, _signal_name): client = app.get_client(transfer.account) client.get_module('HTTPUpload').cancel_transfer(transfer)
- def create_groupchat(self, account, room_jid, config): + @staticmethod + def create_groupchat(account: str, + room_jid: str, + config: Dict[str, Union[str, bool]] + ) -> None: if app.window.chat_exists(account, room_jid): log.error('Trying to create groupchat ' 'which is already added as chat') @@ -660,18 +676,27 @@ def create_groupchat(self, account, room_jid, config): client = app.get_client(account) client.get_module('MUC').create(room_jid, config)
- def show_add_join_groupchat(self, account, jid, nickname=None, - password=None): - if not app.window.chat_exists(account, jid): + @staticmethod + def show_add_join_groupchat(account: str, + jid: str, + nickname: Optional[str] = None, + password: Optional[str] = None + ) -> None: + if not app.window.chat_exists(account, JID.from_string(jid)): client = app.get_client(account) client.get_module('MUC').join( jid, nick=nickname, password=password)
app.window.add_group_chat(account, jid, select=True)
- def start_chat_from_jid(self, account, jid, message=None): + @staticmethod + def start_chat_from_jid(account: str, + jid: str, + message: Optional[str] = None + ) -> None: + jid = JID.from_string(jid) if app.window.chat_exists(account, jid): - app.window.select_chat(account, JID.from_string(jid)) + app.window.select_chat(account, jid) if message is not None: control = app.window.get_control(account, jid) if control is None: @@ -680,7 +705,7 @@ def start_chat_from_jid(self, account, jid, message=None): return
# TODO: handle message arg in StartChat - app.app.activate_action('start-chat', GLib.Variant('s', jid)) + app.app.activate_action('start-chat', GLib.Variant('s', str(jid)))
@staticmethod def _on_muc_added(event): @@ -690,13 +715,14 @@ def _on_muc_added(event): app.window.add_group_chat(event.account, event.jid)
@staticmethod - def create_account(account, - username, - domain, - password, - proxy_name, - custom_host, - anonymous=False): + def create_account(account: str, + username: str, + domain: str, + password: str, + proxy_name: str, + custom_host: str, + anonymous:bool = False + ) -> None:
account_label = f'{username}@{domain}' if anonymous: @@ -706,10 +732,9 @@ def create_account(account, config = {} config['active'] = False config['name'] = username - config['resource'] = 'gajim.%s' % helpers.get_random_string(8) + config['resource'] = f'gajim.{helpers.get_random_string(8)}' config['account_label'] = account_label - config['account_color'] = get_color_for_account( - '%s@%s' % (username, domain)) + config['account_color'] = get_color_for_account(f'{username}@{domain}') config['hostname'] = domain config['savepass'] = True config['anonymous_auth'] = anonymous @@ -744,7 +769,7 @@ def create_account(account, if window is not None: window.add_account(account)
- def enable_account(self, account): + def enable_account(self, account: str) -> None: if account == app.ZEROCONF_ACC_NAME: app.connections[account] = connection_zeroconf.ConnectionZeroconf( account) @@ -789,7 +814,7 @@ def enable_account(self, account): if window is not None: GLib.idle_add(window.enable_account, account, True)
- def disable_account(self, account): + def disable_account(self, account: str) -> None: for win in get_app_windows(account): # Close all account specific windows, except the RemoveAccount # dialog. It shows if the removal was successful. @@ -820,7 +845,7 @@ def disable_account(self, account): del app.to_be_removed[account] del app.newly_added[account]
- def remove_account(self, account): + def remove_account(self, account: str) -> None: if app.settings.get_account_setting(account, 'active'): self.disable_account(account)
@@ -835,7 +860,7 @@ def remove_account(self, account): if window is not None: window.remove_account(account)
- def autoconnect(self): + def autoconnect(self) -> None: """ Auto connect at startup """ @@ -856,7 +881,10 @@ def autoconnect(self):
app.connections[account].change_status(status, status_message)
- def change_status(self, status, account=None): + def change_status(self, + status: str, + account: Optional[str] = None + ) -> None: ask = ask_for_status_message(status)
if status is None: @@ -880,7 +908,7 @@ def change_status(self, status, account=None):
self._change_status(acc, status)
- def change_account_status(self, account, status): + def change_account_status(self, account: str, status: str) -> None: ask = ask_for_status_message(status)
client = app.get_client(account) @@ -894,7 +922,7 @@ def change_account_status(self, account, status): self._change_status(account, status)
@staticmethod - def _change_status(account, status): + def _change_status(account: str, status: str) -> None: client = app.get_client(account) message = client.status_message if status != 'offline': @@ -911,17 +939,17 @@ def _change_status(account, status):
client.change_status(status, message)
- def show_systray(self): + def show_systray(self) -> None: if not app.is_display(Display.WAYLAND): self.systray_enabled = True self.systray.show_icon()
- def hide_systray(self): + def hide_systray(self) -> None: if not app.is_display(Display.WAYLAND): self.systray_enabled = False self.systray.hide_icon()
- def process_connections(self): + def process_connections(self) -> bool: """ Called each foo (200) milliseconds. Check for idlequeue timeouts """ @@ -949,10 +977,10 @@ def process_connections(self): return True # renew timeout (loop for ever)
@staticmethod - def save_config(): + def save_config() -> None: app.settings.save()
- def save_avatar(self, data): + def save_avatar(self, data: bytes) -> Optional[str]: return self.avatar_storage.save_avatar(data)
def get_avatar(self, @@ -968,11 +996,11 @@ def get_avatar(self, return self.avatar_storage.get_surface( contact, size, scale, show, style=style)
- def avatar_exists(self, filename): + def avatar_exists(self, filename: str) -> bool: return self.avatar_storage.get_avatar_path(filename) is not None
@staticmethod - def create_ipython_window(): + def create_ipython_window() -> None: # Check if IPython is installed ipython = find_spec('IPython') is_installed = ipython is not None @@ -1027,7 +1055,7 @@ def _network_status_changed(self, monitor, _param): connection.state.is_available): connection.disconnect(gracefully=False, reconnect=True)
- def create_zeroconf_default_config(self): + def create_zeroconf_default_config(self) -> None: if app.settings.get_account_setting(app.ZEROCONF_ACC_NAME, 'name'): return log.info('Creating zeroconf account') @@ -1057,7 +1085,7 @@ def create_zeroconf_default_config(self): 'active', False)
- def check_for_updates(self): + def check_for_updates(self) -> None: if not app.settings.get('check_for_update'): return
@@ -1073,10 +1101,10 @@ def check_for_updates(self):
self.get_latest_release()
- def get_latest_release(self): + def get_latest_release(self) -> None: log.info('Checking for Gajim updates') session = Soup.Session() - session.props.user_agent = 'Gajim %s' % app.version + session.props.user_agent = f'Gajim {app.version}' message = Soup.Message.new( 'GET', 'https://gajim.org/current-version.json') session.queue_message(message, self._on_update_checked)
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/09b4b7e9cccc082dd883fea9490bc0fe...