Philipp Hörist pushed to branch master at gajim / gajim
Commits:
-
29c24bdb
by Philipp Hörist at 2022-10-15T18:27:49+02:00
-
edac92a6
by Philipp Hörist at 2022-10-16T13:01:58+02:00
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:
| ... | ... | @@ -321,6 +321,7 @@ class _ACCOUNT_DEFAULT: |
| 321 | 321 | 'client_cert',
|
| 322 | 322 | 'custom_host',
|
| 323 | 323 | 'custom_type',
|
| 324 | + 'default_workspace',
|
|
| 324 | 325 | 'file_transfer_proxies',
|
| 325 | 326 | 'filetransfer_preference',
|
| 326 | 327 | 'gc_send_chatstate_default',
|
| ... | ... | @@ -426,6 +427,7 @@ class _ACCOUNT_DEFAULT: |
| 426 | 427 | 'custom_host': '',
|
| 427 | 428 | 'custom_port': 5222,
|
| 428 | 429 | 'custom_type': 'START TLS',
|
| 430 | + 'default_workspace': '',
|
|
| 429 | 431 | 'enable_gssapi': False,
|
| 430 | 432 | 'enable_security_labels': False,
|
| 431 | 433 | 'file_transfer_proxies': '',
|
| ... | ... | @@ -1259,6 +1259,9 @@ def get_workspace_setting(self, |
| 1259 | 1259 | except KeyError:
|
| 1260 | 1260 | return WORKSPACE_SETTINGS[setting]
|
| 1261 | 1261 | |
| 1262 | + def get_workspace_count(self) -> int:
|
|
| 1263 | + return len(self._settings['workspaces'].keys())
|
|
| 1264 | + |
|
| 1262 | 1265 | def get_workspaces(self) -> List[str]:
|
| 1263 | 1266 | workspace_order = app.settings.get_app_setting('workspace_order')
|
| 1264 | 1267 |
| ... | ... | @@ -645,6 +645,8 @@ class GeneralPage(GenericSettingPage): |
| 645 | 645 | |
| 646 | 646 | def __init__(self, account: str) -> None:
|
| 647 | 647 | |
| 648 | + workspaces = self._get_workspaces()
|
|
| 649 | + |
|
| 648 | 650 | settings = [
|
| 649 | 651 | Setting(SettingKind.ENTRY,
|
| 650 | 652 | _('Label'),
|
| ... | ... | @@ -652,6 +654,14 @@ def __init__(self, account: str) -> None: |
| 652 | 654 | 'account_label',
|
| 653 | 655 | callback=self._on_account_name_change),
|
| 654 | 656 | |
| 657 | + Setting(SettingKind.POPOVER,
|
|
| 658 | + _('Default Workspace'),
|
|
| 659 | + SettingType.ACCOUNT_CONFIG,
|
|
| 660 | + 'default_workspace',
|
|
| 661 | + props={'entries': workspaces},
|
|
| 662 | + desc=_('Chats from this account will use this workspace by '
|
|
| 663 | + 'default')),
|
|
| 664 | + |
|
| 655 | 665 | Setting(SettingKind.COLOR,
|
| 656 | 666 | _('Color'),
|
| 657 | 667 | SettingType.ACCOUNT_CONFIG,
|
| ... | ... | @@ -704,6 +714,14 @@ def __init__(self, account: str) -> None: |
| 704 | 714 | ]
|
| 705 | 715 | GenericSettingPage.__init__(self, account, settings)
|
| 706 | 716 | |
| 717 | + @staticmethod
|
|
| 718 | + def _get_workspaces() -> dict[str, str]:
|
|
| 719 | + workspaces: dict[str, str] = {'': _('Disabled')}
|
|
| 720 | + for workspace_id in app.settings.get_workspaces():
|
|
| 721 | + name = app.settings.get_workspace_setting(workspace_id, 'name')
|
|
| 722 | + workspaces[workspace_id] = name
|
|
| 723 | + return workspaces
|
|
| 724 | + |
|
| 707 | 725 | def _on_account_name_change(self, *args: Any) -> None:
|
| 708 | 726 | window = cast(AccountsWindow, get_app_window('AccountsWindow'))
|
| 709 | 727 | window.update_account_label(self.account)
|
| ... | ... | @@ -185,9 +185,6 @@ def _on_chat_order_changed(self, |
| 185 | 185 | |
| 186 | 186 | def show_chat_list(self, workspace_id: str) -> None:
|
| 187 | 187 | cur_workspace_id = self.get_visible_child_name()
|
| 188 | - if cur_workspace_id == workspace_id:
|
|
| 189 | - return
|
|
| 190 | - |
|
| 191 | 188 | if cur_workspace_id != 'default' and cur_workspace_id is not None:
|
| 192 | 189 | self._chat_lists[cur_workspace_id].unselect_all()
|
| 193 | 190 |
| ... | ... | @@ -388,8 +388,7 @@ def _on_roster_row_activated(self, |
| 388 | 388 | app.window.add_chat(self._contact.account,
|
| 389 | 389 | participant.real_jid,
|
| 390 | 390 | 'contact',
|
| 391 | - select=True,
|
|
| 392 | - workspace='current')
|
|
| 391 | + select=True)
|
|
| 393 | 392 | else:
|
| 394 | 393 | contact = self._contact.get_resource(nick)
|
| 395 | 394 | app.window.add_private_chat(self._contact.account,
|
| ... | ... | @@ -638,7 +638,7 @@ def _remove_workspace(self, |
| 638 | 638 | self.remove_workspace(workspace_id)
|
| 639 | 639 | |
| 640 | 640 | def remove_workspace(self, workspace_id: str) -> None:
|
| 641 | - if len(app.settings.get_workspaces()) == 1:
|
|
| 641 | + if app.settings.get_workspace_count() == 1:
|
|
| 642 | 642 | log.warning('Tried to remove the only workspace')
|
| 643 | 643 | return
|
| 644 | 644 | |
| ... | ... | @@ -714,6 +714,29 @@ def get_chat_list(self, workspace_id: str) -> ChatList: |
| 714 | 714 | chat_list_stack = self._chat_page.get_chat_list_stack()
|
| 715 | 715 | return chat_list_stack.get_chatlist(workspace_id)
|
| 716 | 716 | |
| 717 | + def _get_suitable_workspace(self,
|
|
| 718 | + account: str,
|
|
| 719 | + jid: JID,
|
|
| 720 | + private_chat: bool = False
|
|
| 721 | + ) -> str:
|
|
| 722 | + |
|
| 723 | + if private_chat:
|
|
| 724 | + # Try to add private chat to the same workspace the MUC resides in
|
|
| 725 | + chat_list_stack = self._chat_page.get_chat_list_stack()
|
|
| 726 | + chat_list = chat_list_stack.find_chat(account, jid.new_as_bare())
|
|
| 727 | + if chat_list is not None:
|
|
| 728 | + return chat_list.workspace_id
|
|
| 729 | + |
|
| 730 | + default = app.settings.get_account_setting(account, 'default_workspace')
|
|
| 731 | + workspaces = app.settings.get_workspaces()
|
|
| 732 | + if default in workspaces:
|
|
| 733 | + return default
|
|
| 734 | + |
|
| 735 | + workspace_id = self.get_active_workspace()
|
|
| 736 | + if workspace_id is not None:
|
|
| 737 | + return workspace_id
|
|
| 738 | + return self._workspace_side_bar.get_first_workspace()
|
|
| 739 | + |
|
| 717 | 740 | def _add_group_chat(self,
|
| 718 | 741 | _action: Gio.SimpleAction,
|
| 719 | 742 | param: GLib.Variant) -> None:
|
| ... | ... | @@ -721,11 +744,13 @@ def _add_group_chat(self, |
| 721 | 744 | account, jid, select = param.unpack()
|
| 722 | 745 | self.add_group_chat(account, JID.from_string(jid), select)
|
| 723 | 746 | |
| 724 | - def add_group_chat(self, account: str, jid: JID,
|
|
| 725 | - select: bool = False) -> None:
|
|
| 726 | - workspace_id = self.get_active_workspace()
|
|
| 727 | - if workspace_id is None:
|
|
| 728 | - workspace_id = self._workspace_side_bar.get_first_workspace()
|
|
| 747 | + def add_group_chat(self,
|
|
| 748 | + account: str,
|
|
| 749 | + jid: JID,
|
|
| 750 | + select: bool = False
|
|
| 751 | + ) -> None:
|
|
| 752 | + |
|
| 753 | + workspace_id = self._get_suitable_workspace(account, jid)
|
|
| 729 | 754 | self._chat_page.add_chat_for_workspace(workspace_id,
|
| 730 | 755 | account,
|
| 731 | 756 | jid,
|
| ... | ... | @@ -744,38 +769,26 @@ def add_chat(self, |
| 744 | 769 | jid: JID,
|
| 745 | 770 | type_: str,
|
| 746 | 771 | select: bool = False,
|
| 747 | - workspace: str = 'default',
|
|
| 748 | 772 | message: Optional[str] = None
|
| 749 | 773 | ) -> None:
|
| 750 | 774 | |
| 751 | - if workspace == 'current':
|
|
| 752 | - workspace_id = self.get_active_workspace()
|
|
| 753 | - if workspace_id is None:
|
|
| 754 | - workspace_id = self._workspace_side_bar.get_first_workspace()
|
|
| 755 | - else:
|
|
| 756 | - workspace_id = self._workspace_side_bar.get_first_workspace()
|
|
| 757 | - |
|
| 775 | + workspace_id = self._get_suitable_workspace(account, jid)
|
|
| 758 | 776 | self._chat_page.add_chat_for_workspace(workspace_id,
|
| 759 | 777 | account,
|
| 760 | 778 | jid,
|
| 761 | 779 | type_,
|
| 762 | 780 | select=select,
|
| 763 | 781 | message=message)
|
| 764 | - if select:
|
|
| 765 | - self.activate_workspace(workspace_id)
|
|
| 766 | 782 | |
| 767 | 783 | def add_private_chat(self,
|
| 768 | 784 | account: str,
|
| 769 | 785 | jid: JID,
|
| 770 | - select: bool = False) -> None:
|
|
| 771 | - # Try to add private chat to the same workspace the MUC resides in
|
|
| 772 | - chat_list_stack = self._chat_page.get_chat_list_stack()
|
|
| 773 | - chat_list = chat_list_stack.find_chat(account, jid.new_as_bare())
|
|
| 774 | - if chat_list is not None:
|
|
| 775 | - workspace_id = chat_list.workspace_id
|
|
| 776 | - else:
|
|
| 777 | - workspace_id = self._workspace_side_bar.get_first_workspace()
|
|
| 786 | + select: bool = False
|
|
| 787 | + ) -> None:
|
|
| 778 | 788 | |
| 789 | + workspace_id = self._get_suitable_workspace(account,
|
|
| 790 | + jid,
|
|
| 791 | + private_chat=True)
|
|
| 779 | 792 | self._chat_page.add_chat_for_workspace(workspace_id,
|
| 780 | 793 | account,
|
| 781 | 794 | jid,
|
| ... | ... | @@ -420,8 +420,7 @@ def get_chat_list_row_menu(workspace_id: str, |
| 420 | 420 | menu.add_item(toggle_label, 'win.toggle-chat-pinned', params)
|
| 421 | 421 | |
| 422 | 422 | submenu = menu.add_submenu(_('Move Chat'))
|
| 423 | - workspaces = app.settings.get_workspaces()
|
|
| 424 | - if len(workspaces) > 1:
|
|
| 423 | + if app.settings.get_workspace_count() > 1:
|
|
| 425 | 424 | for name, params in get_workspace_params(workspace_id, account, jid):
|
| 426 | 425 | submenu.add_item(name, 'win.move-chat-to-workspace', params)
|
| 427 | 426 | |
| ... | ... | @@ -589,7 +588,7 @@ def get_format_menu() -> GajimMenu: |
| 589 | 588 | |
| 590 | 589 | def get_workspace_menu(workspace_id: str) -> GajimMenu:
|
| 591 | 590 | remove_action = 'win.dummy'
|
| 592 | - if len(app.settings.get_workspaces()) > 1:
|
|
| 591 | + if app.settings.get_workspace_count() > 1:
|
|
| 593 | 592 | remove_action = 'win.remove-workspace'
|
| 594 | 593 | |
| 595 | 594 | menuitems: MenuItemListT = [
|
| ... | ... | @@ -371,7 +371,6 @@ def _start_new_chat(self, row: ContactRow) -> None: |
| 371 | 371 | jid,
|
| 372 | 372 | 'contact',
|
| 373 | 373 | select=True,
|
| 374 | - workspace='current',
|
|
| 375 | 374 | message=initial_message)
|
| 376 | 375 | self.ready_to_destroy = True
|
| 377 | 376 | self.destroy()
|
| ... | ... | @@ -54,7 +54,7 @@ def __init__(self, workspace_id: Optional[str] = None) -> None: |
| 54 | 54 | color: Optional[str] = None
|
| 55 | 55 | self._avatar_sha: Optional[str] = None
|
| 56 | 56 | |
| 57 | - if len(app.settings.get_workspaces()) == 1:
|
|
| 57 | + if app.settings.get_workspace_count() == 1:
|
|
| 58 | 58 | # Don't allow to remove last workspace
|
| 59 | 59 | self._ui.remove_workspace_button.set_sensitive(False)
|
| 60 | 60 |