Philipp Hörist pushed to branch master at gajim / gajim
Commits: 29c24bdb by Philipp Hörist at 2022-10-15T18:27:49+02:00 new: Settings: Add get_workspace_count()
- - - - - edac92a6 by Philipp Hörist at 2022-10-16T13:01:58+02:00 feat: Accounts: Add setting for default workspace
Fixes #11208
- - - - -
9 changed files:
- gajim/common/setting_values.py - gajim/common/settings.py - gajim/gtk/accounts.py - gajim/gtk/chat_list_stack.py - gajim/gtk/groupchat_roster.py - gajim/gtk/main.py - gajim/gtk/menus.py - gajim/gtk/start_chat.py - gajim/gtk/workspace_dialog.py
Changes:
===================================== gajim/common/setting_values.py ===================================== @@ -321,6 +321,7 @@ class _ACCOUNT_DEFAULT: 'client_cert', 'custom_host', 'custom_type', + 'default_workspace', 'file_transfer_proxies', 'filetransfer_preference', 'gc_send_chatstate_default', @@ -426,6 +427,7 @@ class _ACCOUNT_DEFAULT: 'custom_host': '', 'custom_port': 5222, 'custom_type': 'START TLS', + 'default_workspace': '', 'enable_gssapi': False, 'enable_security_labels': False, 'file_transfer_proxies': '',
===================================== gajim/common/settings.py ===================================== @@ -1259,6 +1259,9 @@ def get_workspace_setting(self, except KeyError: return WORKSPACE_SETTINGS[setting]
+ def get_workspace_count(self) -> int: + return len(self._settings['workspaces'].keys()) + def get_workspaces(self) -> List[str]: workspace_order = app.settings.get_app_setting('workspace_order')
===================================== gajim/gtk/accounts.py ===================================== @@ -645,6 +645,8 @@ class GeneralPage(GenericSettingPage):
def __init__(self, account: str) -> None:
+ workspaces = self._get_workspaces() + settings = [ Setting(SettingKind.ENTRY, _('Label'), @@ -652,6 +654,14 @@ def __init__(self, account: str) -> None: 'account_label', callback=self._on_account_name_change),
+ Setting(SettingKind.POPOVER, + _('Default Workspace'), + SettingType.ACCOUNT_CONFIG, + 'default_workspace', + props={'entries': workspaces}, + desc=_('Chats from this account will use this workspace by ' + 'default')), + Setting(SettingKind.COLOR, _('Color'), SettingType.ACCOUNT_CONFIG, @@ -704,6 +714,14 @@ def __init__(self, account: str) -> None: ] GenericSettingPage.__init__(self, account, settings)
+ @staticmethod + def _get_workspaces() -> dict[str, str]: + workspaces: dict[str, str] = {'': _('Disabled')} + for workspace_id in app.settings.get_workspaces(): + name = app.settings.get_workspace_setting(workspace_id, 'name') + workspaces[workspace_id] = name + return workspaces + def _on_account_name_change(self, *args: Any) -> None: window = cast(AccountsWindow, get_app_window('AccountsWindow')) window.update_account_label(self.account)
===================================== gajim/gtk/chat_list_stack.py ===================================== @@ -185,9 +185,6 @@ def _on_chat_order_changed(self,
def show_chat_list(self, workspace_id: str) -> None: cur_workspace_id = self.get_visible_child_name() - if cur_workspace_id == workspace_id: - return - if cur_workspace_id != 'default' and cur_workspace_id is not None: self._chat_lists[cur_workspace_id].unselect_all()
===================================== gajim/gtk/groupchat_roster.py ===================================== @@ -388,8 +388,7 @@ def _on_roster_row_activated(self, app.window.add_chat(self._contact.account, participant.real_jid, 'contact', - select=True, - workspace='current') + select=True) else: contact = self._contact.get_resource(nick) app.window.add_private_chat(self._contact.account,
===================================== gajim/gtk/main.py ===================================== @@ -638,7 +638,7 @@ def _remove_workspace(self, self.remove_workspace(workspace_id)
def remove_workspace(self, workspace_id: str) -> None: - if len(app.settings.get_workspaces()) == 1: + if app.settings.get_workspace_count() == 1: log.warning('Tried to remove the only workspace') return
@@ -714,6 +714,29 @@ def get_chat_list(self, workspace_id: str) -> ChatList: chat_list_stack = self._chat_page.get_chat_list_stack() return chat_list_stack.get_chatlist(workspace_id)
+ def _get_suitable_workspace(self, + account: str, + jid: JID, + private_chat: bool = False + ) -> str: + + if private_chat: + # Try to add private chat to the same workspace the MUC resides in + chat_list_stack = self._chat_page.get_chat_list_stack() + chat_list = chat_list_stack.find_chat(account, jid.new_as_bare()) + if chat_list is not None: + return chat_list.workspace_id + + default = app.settings.get_account_setting(account, 'default_workspace') + workspaces = app.settings.get_workspaces() + if default in workspaces: + return default + + workspace_id = self.get_active_workspace() + if workspace_id is not None: + return workspace_id + return self._workspace_side_bar.get_first_workspace() + def _add_group_chat(self, _action: Gio.SimpleAction, param: GLib.Variant) -> None: @@ -721,11 +744,13 @@ def _add_group_chat(self, account, jid, select = param.unpack() self.add_group_chat(account, JID.from_string(jid), select)
- def add_group_chat(self, account: str, jid: JID, - select: bool = False) -> None: - workspace_id = self.get_active_workspace() - if workspace_id is None: - workspace_id = self._workspace_side_bar.get_first_workspace() + def add_group_chat(self, + account: str, + jid: JID, + select: bool = False + ) -> None: + + workspace_id = self._get_suitable_workspace(account, jid) self._chat_page.add_chat_for_workspace(workspace_id, account, jid, @@ -744,38 +769,26 @@ def add_chat(self, jid: JID, type_: str, select: bool = False, - workspace: str = 'default', message: Optional[str] = None ) -> None:
- if workspace == 'current': - workspace_id = self.get_active_workspace() - if workspace_id is None: - workspace_id = self._workspace_side_bar.get_first_workspace() - else: - workspace_id = self._workspace_side_bar.get_first_workspace() - + workspace_id = self._get_suitable_workspace(account, jid) self._chat_page.add_chat_for_workspace(workspace_id, account, jid, type_, select=select, message=message) - if select: - self.activate_workspace(workspace_id)
def add_private_chat(self, account: str, jid: JID, - select: bool = False) -> None: - # Try to add private chat to the same workspace the MUC resides in - chat_list_stack = self._chat_page.get_chat_list_stack() - chat_list = chat_list_stack.find_chat(account, jid.new_as_bare()) - if chat_list is not None: - workspace_id = chat_list.workspace_id - else: - workspace_id = self._workspace_side_bar.get_first_workspace() + select: bool = False + ) -> None:
+ workspace_id = self._get_suitable_workspace(account, + jid, + private_chat=True) self._chat_page.add_chat_for_workspace(workspace_id, account, jid,
===================================== gajim/gtk/menus.py ===================================== @@ -420,8 +420,7 @@ def get_chat_list_row_menu(workspace_id: str, menu.add_item(toggle_label, 'win.toggle-chat-pinned', params)
submenu = menu.add_submenu(_('Move Chat')) - workspaces = app.settings.get_workspaces() - if len(workspaces) > 1: + if app.settings.get_workspace_count() > 1: for name, params in get_workspace_params(workspace_id, account, jid): submenu.add_item(name, 'win.move-chat-to-workspace', params)
@@ -589,7 +588,7 @@ def get_format_menu() -> GajimMenu:
def get_workspace_menu(workspace_id: str) -> GajimMenu: remove_action = 'win.dummy' - if len(app.settings.get_workspaces()) > 1: + if app.settings.get_workspace_count() > 1: remove_action = 'win.remove-workspace'
menuitems: MenuItemListT = [
===================================== gajim/gtk/start_chat.py ===================================== @@ -371,7 +371,6 @@ def _start_new_chat(self, row: ContactRow) -> None: jid, 'contact', select=True, - workspace='current', message=initial_message) self.ready_to_destroy = True self.destroy()
===================================== gajim/gtk/workspace_dialog.py ===================================== @@ -54,7 +54,7 @@ def __init__(self, workspace_id: Optional[str] = None) -> None: color: Optional[str] = None self._avatar_sha: Optional[str] = None
- if len(app.settings.get_workspaces()) == 1: + if app.settings.get_workspace_count() == 1: # Don't allow to remove last workspace self._ui.remove_workspace_button.set_sensitive(False)
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/c9a229c3e2395920466d3a20b3c24593...