Philipp Hörist pushed to branch master at gajim / gajim
Commits: 5dd99a3f by Philipp Hörist at 2022-10-29T12:46:04+02:00 refactor: Move show_add_join_groupchat() to main
- - - - - 59ff9cfa by Philipp Hörist at 2022-10-29T13:41:11+02:00 refactor: Config: Disable saving legacy config
- - - - - 30e4ac5f by Philipp Hörist at 2022-10-29T13:41:11+02:00 refactor: Move start_chat_from_jid() to main
- - - - - ead3290f by Philipp Hörist at 2022-10-29T13:41:11+02:00 refactor: Move change_status() to application
- - - - - 7e3ce334 by Philipp Hörist at 2022-10-29T13:49:23+02:00 refactor: Move autoconnect() to application
- - - - - 57cb2888 by Philipp Hörist at 2022-10-29T14:30:17+02:00 refactor: Move more init code into application
- - - - -
12 changed files:
- gajim/common/application.py - gajim/common/config.py - gajim/common/helpers.py - gajim/gtk/application.py - gajim/gtk/discovery.py - gajim/gtk/groupchat_invitation.py - gajim/gtk/groupchat_join.py - gajim/gtk/main.py - gajim/gtk/start_chat.py - gajim/gtk/status_icon.py - gajim/gtk/status_selector.py - gajim/gui_interface.py
Changes:
===================================== gajim/common/application.py ===================================== @@ -50,6 +50,8 @@ from gajim.common.client import Client from gajim.common.helpers import make_http_request from gajim.common.helpers import get_random_string +from gajim.common.helpers import get_global_show +from gajim.common.helpers import from_one_line from gajim.common.storage.events import EventStorage from gajim.common.task_manager import TaskManager from gajim.common.settings import Settings @@ -59,6 +61,9 @@ from gajim.common.storage.draft import DraftStorage from gajim.common.storage.archive import MessageArchiveStorage
+from gajim.plugins import PluginManager +from gajim.plugins.repository import PluginRepository +
class CoreApplication(ged.EventHelper): def __init__(self) -> None: @@ -113,6 +118,15 @@ def _init_core(self) -> None: for account in app.settings.get_active_accounts(): app.connections[account] = Client(account)
+ app.plugin_manager = PluginManager() + app.plugin_manager.init_plugins() + app.plugin_repository = PluginRepository() + + for client in app.get_clients(): + client.get_module('Roster').load_roster() + + GLib.timeout_add_seconds(5, self._remote_init) + self.register_events([ ('signed-in', ged.CORE, self._on_signed_in), ]) @@ -153,6 +167,35 @@ def _core_command_line(self, options: GLib.VariantDict) -> None: if options.contains('warnings'): self._show_warnings()
+ def _auto_connect(self) -> None: + for client in app.get_clients(): + account = client.account + if not app.settings.get_account_setting(account, + 'autoconnect'): + continue + + status = 'online' + status_message = '' + + if app.settings.get_account_setting(account, 'restore_last_status'): + status = app.settings.get_account_setting( + account, 'last_status') + status_message = app.settings.get_account_setting( + account, 'last_status_msg') + status_message = from_one_line(status_message) + + client.change_status(status, status_message) + + def _remote_init(self) -> None: + if not app.settings.get('remote_control'): + return + + try: + from gajim.common.dbus import remote_control + remote_control.GajimRemote() + except Exception: + self._log.exception('Failed to init remote control') + def start_profiling(self) -> None: self._log.info('Start profiling') self._profiling_session = cProfile.Profile() @@ -376,3 +419,34 @@ def _on_signed_in(self, event: SignedIn) -> None:
if client.get_module('MAM').available: client.get_module('MAM').request_archive_on_signin() + + def change_status(self, + status: str, + account: Optional[str] = None + ) -> None: + + if status is None: + status = get_global_show() + + if account is not None: + self._change_status(account, status) + return + + for client in app.get_clients(): + if not app.settings.get_account_setting(client.account, + 'sync_with_global_status'): + continue + + self._change_status(client.account, status) + + @staticmethod + def _change_status(account: str, status: str) -> None: + client = app.get_client(account) + message = client.status_message + + if status == 'offline': + # TODO delete pep + # self.delete_pep(app.get_jid_from_account(account), account) + pass + + client.change_status(status, message)
===================================== gajim/common/config.py ===================================== @@ -415,7 +415,6 @@ def set(self, optname, value): return
self.__options[1][optname] = value - self._timeout_save()
def get(self, optname=None): if not optname: @@ -457,7 +456,6 @@ def add_per(self, typename, name): # per_group_of_option opt[1][name] = {} for o in opt[0]: opt[1][name][o] = opt[0][o][Option.VAL] - self._timeout_save()
def del_per(self, typename, name, subname=None): # per_group_of_option if typename not in self.__options_per_key: @@ -469,7 +467,6 @@ def del_per(self, typename, name, subname=None): # per_group_of_option # if subname is specified, delete the item in the group. elif subname in opt[1][name]: del opt[1][name][subname] - self._timeout_save()
def del_all_per(self, typename, subname): # Deletes all settings per typename @@ -483,7 +480,6 @@ def del_all_per(self, typename, subname): del opt[1][name][subname] except KeyError: pass - self._timeout_save()
def set_per(self, optname, key, subname, value): # per_group_of_option if optname not in self.__options_per_key: @@ -501,7 +497,6 @@ def set_per(self, optname, key, subname, value): # per_group_of_option if value is None: return obj[subname] = value - self._timeout_save()
def get_per(self, optname, key=None, subname=None, default=None): # per_group_of_option if optname not in self.__options_per_key: @@ -591,11 +586,6 @@ def _really_save(self): self.save_timeout_id = None return False
- def _timeout_save(self): - if self.save_timeout_id: - return - self.save_timeout_id = GLib.timeout_add(1000, self._really_save) - def __init__(self): #init default values self._init_options()
===================================== gajim/common/helpers.py ===================================== @@ -1033,7 +1033,7 @@ def open_uri(uri: Union[URI, str], account: Optional[str] = None) -> None: Gio.AppInfo.launch_default_for_uri(uri.data)
elif uri.type == URIType.AT: - app.interface.start_chat_from_jid(account, uri.data) + app.window.start_chat_from_jid(account, uri.data)
elif uri.type == URIType.XMPP: if account is None: @@ -1052,7 +1052,7 @@ def open_uri(uri: Union[URI, str], account: Optional[str] = None) -> None: 'groupchat-join', GLib.Variant('as', [account, jid])) elif uri.action == URIAction.MESSAGE: - app.interface.start_chat_from_jid(account, jid, message=message) + app.window.start_chat_from_jid(account, jid, message=message) else: log.warning('Cant open URI: %s', uri)
===================================== gajim/gtk/application.py ===================================== @@ -274,6 +274,8 @@ def _startup(self) -> None: from gajim.gui.main import MainWindow MainWindow()
+ GLib.timeout_add(100, self._auto_connect) + def _open_uris(self, uris: list[str]) -> None: accounts = app.settings.get_active_accounts() if not accounts: @@ -326,7 +328,7 @@ def _open_uris(self, uris: list[str]) -> None: except Exception: app.log('uri_handler').error('Invalid URI: %s', cmd)
- app.interface.start_chat_from_jid(accounts[0], jid, message) + app.window.start_chat_from_jid(accounts[0], jid, message)
def _shutdown(self, _application: GajimApplication) -> None: self._shutdown_core() @@ -737,7 +739,7 @@ def _on_join_support_chat(_action: Gio.SimpleAction, _param: Optional[GLib.Variant]) -> None: accounts = app.settings.get_active_accounts() if len(accounts) == 1: - app.interface.show_add_join_groupchat( + app.window.show_add_join_groupchat( accounts[0], GAJIM_SUPPORT_JID) return open_window('StartChatDialog', initial_jid=GAJIM_SUPPORT_JID) @@ -827,7 +829,7 @@ def _on_copy_text_action(_action: Gio.SimpleAction, def _on_open_chat_action(_action: Gio.SimpleAction, param: GLib.Variant) -> None: account, jid = param.get_strv() - app.interface.start_chat_from_jid(account, jid) + app.window.start_chat_from_jid(account, jid)
@staticmethod @structs.actionfunction
===================================== gajim/gtk/discovery.py ===================================== @@ -1358,7 +1358,7 @@ def _on_join_button_clicked(self, widget): if not iter_: return service = model[iter_][0] - app.interface.show_add_join_groupchat(self.account, service) + app.window.show_add_join_groupchat(self.account, service)
def update_actions(self): if self.execute_button: @@ -1720,7 +1720,7 @@ def _on_join_button_clicked(self, *args): if not iter_: return service = model[iter_][0] - app.interface.show_add_join_groupchat(self.account, service) + app.window.show_add_join_groupchat(self.account, service)
def update_actions(self): sens = \
===================================== gajim/gtk/groupchat_invitation.py ===================================== @@ -116,7 +116,7 @@ def _on_key_press(self, _widget: Gtk.Widget, event: Gdk.EventKey) -> None:
def _on_join(self, _button: Gtk.Button) -> None: nickname = self._nick_chooser.get_text() - app.interface.show_add_join_groupchat( + app.window.show_add_join_groupchat( self.account, self._room_jid, nickname=nickname) self.destroy()
===================================== gajim/gtk/groupchat_join.py ===================================== @@ -150,7 +150,7 @@ def _set_error_from_code(self, error_code: str) -> None: def _on_join(self, _button: Gtk.Button) -> None: nickname = self._nick_chooser.get_text()
- app.interface.show_add_join_groupchat( + app.window.show_add_join_groupchat( self.account, self.jid, nickname=nickname) self.destroy()
===================================== gajim/gtk/main.py ===================================== @@ -947,6 +947,37 @@ def _on_window_active(self, if control.get_autoscroll(): self.mark_as_read(control.contact.account, control.contact.jid)
+ def show_add_join_groupchat(self, + account: str, + jid: str, + nickname: Optional[str] = None, + password: Optional[str] = None + ) -> None: + + if not self.chat_exists(account, JID.from_string(jid)): + client = app.get_client(account) + client.get_module('MUC').join( + jid, nick=nickname, password=password) + + self.add_group_chat(account, JID.from_string(jid), select=True) + + def start_chat_from_jid(self, + account: str, + jid: str, + message: Optional[str] = None + ) -> None: + + jid_ = JID.from_string(jid) + if self.chat_exists(account, jid_): + self.select_chat(account, jid_) + if message is not None: + message_input = self.get_chat_stack().get_message_input() + message_input.insert_text(message) + return + + app.app.activate_action( + 'start-chat', GLib.Variant('as', [str(jid), message or ''])) + @staticmethod def contact_info(account: str, jid: str) -> None: client = app.get_client(account)
===================================== gajim/gtk/start_chat.py ===================================== @@ -478,7 +478,7 @@ def _on_join_clicked(self, *args: Any) -> None: jid = self._muc_info_box.get_jid() nickname = self._nick_chooser.get_text() assert account - app.interface.show_add_join_groupchat( + app.window.show_add_join_groupchat( account, str(jid), nickname=nickname)
self.ready_to_destroy = True
===================================== gajim/gtk/status_icon.py ===================================== @@ -203,7 +203,7 @@ def _on_quit(_widget: Gtk.MenuItem) -> None:
@staticmethod def _on_show(_widget: Gtk.MenuItem, show: str) -> None: - app.interface.change_status(status=show) + app.app.change_status(status=show)
class GtkStatusIcon(GtkMenuBackend):
===================================== gajim/gtk/status_selector.py ===================================== @@ -132,7 +132,7 @@ def _create_popover(self) -> None: def _on_change_status(self, button: Gtk.Button) -> None: self._status_popover.popdown() new_status = button.get_name() - app.interface.change_status(status=new_status, account=self._account) + app.app.change_status(status=new_status, account=self._account)
def update(self) -> None: if self._account is None:
===================================== gajim/gui_interface.py ===================================== @@ -53,7 +53,6 @@ from gajim.common import exceptions from gajim.common import proxy65_manager from gajim.common import socks5 -from gajim.common import helpers
from gajim.common.events import FileCompleted from gajim.common.events import FileHashError @@ -74,7 +73,7 @@ from gajim.gui.file_transfer_send import SendFileDialog from gajim.gui.filetransfer import FileTransfersWindow from gajim.gui.control import ChatControl -from gajim.plugins.repository import PluginRepository +
log = logging.getLogger('gajim.interface')
@@ -332,90 +331,6 @@ def start_file_transfer(self, contact) SendFileDialog(contact, send_callback, app.window, [path])
- @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.from_string(jid), select=True) - - @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_) - if message is not None: - message_input = app.window.get_chat_stack().get_message_input() - message_input.insert_text(message) - return - - app.app.activate_action( - 'start-chat', GLib.Variant('as', [str(jid), message or ''])) - - def autoconnect(self) -> None: - ''' - Auto connect at startup - ''' - - for client in app.get_clients(): - account = client.account - if not app.settings.get_account_setting(account, - 'autoconnect'): - continue - - status = 'online' - status_message = '' - - if app.settings.get_account_setting(account, 'restore_last_status'): - status = app.settings.get_account_setting( - account, 'last_status') - status_message = app.settings.get_account_setting( - account, 'last_status_msg') - status_message = helpers.from_one_line(status_message) - - client.change_status(status, status_message) - - def change_status(self, - status: str, - account: Optional[str] = None - ) -> None: - - if status is None: - status = helpers.get_global_show() - - if account is not None: - self._change_status(account, status) - return - - for client in app.get_clients(): - if not app.settings.get_account_setting(client.account, - 'sync_with_global_status'): - continue - - self._change_status(client.account, status) - - @staticmethod - def _change_status(account: str, status: str) -> None: - client = app.get_client(account) - message = client.status_message - - if status == 'offline': - # TODO delete pep - # self.delete_pep(app.get_jid_from_account(account), account) - pass - - client.change_status(status, message) - def process_connections(self) -> bool: ''' Called each foo (200) milliseconds. Check for idlequeue timeouts @@ -443,10 +358,6 @@ def process_connections(self) -> bool: raise return True # renew timeout (loop for ever)
- @staticmethod - def save_config() -> None: - app.settings.save() - def save_avatar(self, data: bytes) -> Optional[str]: return app.app.avatar_storage.save_avatar(data)
@@ -454,20 +365,9 @@ def avatar_exists(self, filename: str) -> bool: return app.app.avatar_storage.get_avatar_path(filename) is not None
def run(self, _application: Gtk.Application) -> None: - # Creating plugin manager - from gajim import plugins - app.plugin_manager = plugins.PluginManager() - app.plugin_manager.init_plugins() - - app.plugin_repository = PluginRepository() - - for client in app.get_clients(): - client.get_module('Roster').load_roster() - # get instances for windows/dialogs that will show_all()/hide() self.instances['file_transfers'] = FileTransfersWindow()
- GLib.timeout_add(100, self.autoconnect) if sys.platform == 'win32': timeout, in_seconds = 20, None else: @@ -478,16 +378,6 @@ def run(self, _application: Gtk.Application) -> None: else: GLib.timeout_add(timeout, self.process_connections)
- def remote_init(): - if app.settings.get('remote_control'): - try: - from gajim.common.dbus import remote_control - remote_control.GajimRemote() - except Exception: - log.exception('Failed to init remote control') - - GLib.timeout_add_seconds(5, remote_init) -
class ThreadInterface: def __init__(self, func, func_args=(), callback=None, callback_args=()):
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/9fa15859f623598141ebff4db3791bb8...