Philipp Hörist pushed to branch mainwindow at gajim / gajim
Commits:
5 changed files:
- gajim/common/setting_values.py
- gajim/common/settings.py
- gajim/gtk/chat_list.py
- gajim/gtk/chat_list_stack.py
- gajim/gtk/main.py
Changes:
| 1 |
+import uuid
|
|
| 1 | 2 |
|
| 2 | 3 |
from gajim.common.i18n import _
|
| 3 | 4 |
|
| ... | ... | @@ -186,6 +187,7 @@ class _ACCOUNT_DEFAULT: |
| 186 | 187 |
'last_update_check': '',
|
| 187 | 188 |
'always_ask_for_status_message': False,
|
| 188 | 189 |
'show_send_message_button': False,
|
| 190 |
+ 'workspace_order': [],
|
|
| 189 | 191 |
}
|
| 190 | 192 |
|
| 191 | 193 |
ACCOUNT_SETTINGS = {
|
| ... | ... | @@ -283,6 +285,15 @@ class _ACCOUNT_DEFAULT: |
| 283 | 285 |
}
|
| 284 | 286 |
|
| 285 | 287 |
|
| 288 |
+WORKSPACE_SETTINGS = {
|
|
| 289 |
+ 'name': _('My Workspace'),
|
|
| 290 |
+ 'open_chats': [],
|
|
| 291 |
+}
|
|
| 292 |
+ |
|
| 293 |
+ |
|
| 294 |
+INITAL_WORKSPACE = {str(uuid.uuid4()): {}}
|
|
| 295 |
+ |
|
| 296 |
+ |
|
| 286 | 297 |
PLUGIN_SETTINGS = {
|
| 287 | 298 |
'active': False
|
| 288 | 299 |
}
|
| ... | ... | @@ -19,6 +19,7 @@ |
| 19 | 19 |
|
| 20 | 20 |
import sys
|
| 21 | 21 |
import json
|
| 22 |
+import uuid
|
|
| 22 | 23 |
import logging
|
| 23 | 24 |
import sqlite3
|
| 24 | 25 |
import inspect
|
| ... | ... | @@ -38,14 +39,16 @@ |
| 38 | 39 |
from gajim.common.setting_values import ACCOUNT_SETTINGS
|
| 39 | 40 |
from gajim.common.setting_values import PROXY_SETTINGS
|
| 40 | 41 |
from gajim.common.setting_values import PROXY_EXAMPLES
|
| 42 |
+from gajim.common.setting_values import INITAL_WORKSPACE
|
|
| 41 | 43 |
from gajim.common.setting_values import PLUGIN_SETTINGS
|
| 44 |
+from gajim.common.setting_values import WORKSPACE_SETTINGS
|
|
| 42 | 45 |
from gajim.common.setting_values import DEFAULT_SOUNDEVENT_SETTINGS
|
| 43 | 46 |
from gajim.common.setting_values import STATUS_PRESET_SETTINGS
|
| 44 | 47 |
from gajim.common.setting_values import STATUS_PRESET_EXAMPLES
|
| 45 | 48 |
from gajim.common.setting_values import HAS_APP_DEFAULT
|
| 46 | 49 |
from gajim.common.setting_values import HAS_ACCOUNT_DEFAULT
|
| 47 | 50 |
|
| 48 |
-SETTING_TYPE = Union[bool, int, str, object]
|
|
| 51 |
+SETTING_TYPE = Union[bool, int, str, object, list]
|
|
| 49 | 52 |
|
| 50 | 53 |
log = logging.getLogger('gajim.c.settings')
|
| 51 | 54 |
|
| ... | ... | @@ -65,10 +68,12 @@ |
| 65 | 68 |
INSERT INTO settings(name, settings) VALUES ('status_presets', '%s');
|
| 66 | 69 |
INSERT INTO settings(name, settings) VALUES ('proxies', '%s');
|
| 67 | 70 |
INSERT INTO settings(name, settings) VALUES ('plugins', '{}');
|
| 71 |
+ INSERT INTO settings(name, settings) VALUES ('workspaces', '%s');
|
|
| 68 | 72 |
|
| 69 |
- PRAGMA user_version=0;
|
|
| 73 |
+ PRAGMA user_version=1;
|
|
| 70 | 74 |
''' % (json.dumps(STATUS_PRESET_EXAMPLES),
|
| 71 |
- json.dumps(PROXY_EXAMPLES))
|
|
| 75 |
+ json.dumps(PROXY_EXAMPLES),
|
|
| 76 |
+ json.dumps(INITAL_WORKSPACE))
|
|
| 72 | 77 |
|
| 73 | 78 |
|
| 74 | 79 |
class Settings:
|
| ... | ... | @@ -235,7 +240,12 @@ def _migrate_database(self) -> None: |
| 235 | 240 |
sys.exit()
|
| 236 | 241 |
|
| 237 | 242 |
def _migrate(self) -> None:
|
| 238 |
- pass
|
|
| 243 |
+ version = self._get_user_version()
|
|
| 244 |
+ if version < 1:
|
|
| 245 |
+ sql = '''INSERT INTO settings(name, settings)
|
|
| 246 |
+ VALUES ('workspaces', ?)'''
|
|
| 247 |
+ self._con.execute(sql, (json.dumps(INITAL_WORKSPACE),))
|
|
| 248 |
+ self._set_user_version(2)
|
|
| 239 | 249 |
|
| 240 | 250 |
def _migrate_old_config(self) -> None:
|
| 241 | 251 |
config_file = configpaths.get('CONFIG_FILE')
|
| ... | ... | @@ -907,6 +917,68 @@ def remove_proxy(self, proxy_name: str) -> None: |
| 907 | 917 |
if self.get_account_setting(account, 'proxy') == proxy_name:
|
| 908 | 918 |
self.set_account_setting(account, 'proxy', None)
|
| 909 | 919 |
|
| 920 |
+ def set_workspace_setting(self,
|
|
| 921 |
+ workspace_id: str,
|
|
| 922 |
+ setting: str,
|
|
| 923 |
+ value: SETTING_TYPE) -> None:
|
|
| 924 |
+ |
|
| 925 |
+ if setting not in WORKSPACE_SETTINGS:
|
|
| 926 |
+ raise ValueError(f'Invalid workspace setting: {setting}')
|
|
| 927 |
+ |
|
| 928 |
+ if workspace_id not in self._settings['workspaces']:
|
|
| 929 |
+ raise ValueError(f'Workspace does not exists: {workspace_id}')
|
|
| 930 |
+ |
|
| 931 |
+ default = WORKSPACE_SETTINGS[setting]
|
|
| 932 |
+ if not isinstance(value, type(default)):
|
|
| 933 |
+ raise TypeError(f'Invalid type for {setting}: '
|
|
| 934 |
+ f'{value} {type(value)}')
|
|
| 935 |
+ |
|
| 936 |
+ self._settings['workspaces'][workspace_id][setting] = value
|
|
| 937 |
+ self._commit_settings('workspaces')
|
|
| 938 |
+ |
|
| 939 |
+ def get_workspace_setting(self,
|
|
| 940 |
+ workspace_id: str,
|
|
| 941 |
+ setting: str) -> SETTING_TYPE:
|
|
| 942 |
+ |
|
| 943 |
+ if setting not in WORKSPACE_SETTINGS:
|
|
| 944 |
+ raise ValueError(f'Invalid workspace setting: {setting}')
|
|
| 945 |
+ |
|
| 946 |
+ if workspace_id not in self._settings['workspaces']:
|
|
| 947 |
+ raise ValueError(f'Workspace does not exists: {workspace_id}')
|
|
| 948 |
+ |
|
| 949 |
+ try:
|
|
| 950 |
+ return self._settings['workspaces'][workspace_id][setting]
|
|
| 951 |
+ except KeyError:
|
|
| 952 |
+ return WORKSPACE_SETTINGS[setting]
|
|
| 953 |
+ |
|
| 954 |
+ def get_workspaces(self) -> None:
|
|
| 955 |
+ workspace_order = app.settings.get_app_setting('workspace_order')
|
|
| 956 |
+ |
|
| 957 |
+ def sort_workspaces(workspace_id):
|
|
| 958 |
+ try:
|
|
| 959 |
+ return workspace_order.index(workspace_id)
|
|
| 960 |
+ except ValueError:
|
|
| 961 |
+ # Handle the case that a workflow id is for some reason not
|
|
| 962 |
+ # in the workspace order list
|
|
| 963 |
+ return 10000
|
|
| 964 |
+ |
|
| 965 |
+ workspaces = list(self._settings['workspaces'].keys())
|
|
| 966 |
+ workspaces.sort(key=sort_workspaces)
|
|
| 967 |
+ return workspaces
|
|
| 968 |
+ |
|
| 969 |
+ def add_workspace(self, name: str) -> None:
|
|
| 970 |
+ id_ = str(uuid.uuid4())
|
|
| 971 |
+ self._settings['workspaces'][id_] = {
|
|
| 972 |
+ 'name': name,
|
|
| 973 |
+ }
|
|
| 974 |
+ self._commit_settings('workspaces')
|
|
| 975 |
+ return id_
|
|
| 976 |
+ |
|
| 977 |
+ def remove_workspace(self, id_: str) -> None:
|
|
| 978 |
+ del self._settings['workspaces'][id_]
|
|
| 979 |
+ self._commit_settings('workspaces')
|
|
| 980 |
+ |
|
| 981 |
+ |
|
| 910 | 982 |
|
| 911 | 983 |
class LegacyConfig:
|
| 912 | 984 |
|
| ... | ... | @@ -41,6 +41,9 @@ def _on_row_selected(self, _listbox, row): |
| 41 | 41 |
return
|
| 42 | 42 |
self._chat_stack.show_chat(row.account, row.jid)
|
| 43 | 43 |
|
| 44 |
+ def get_open_chats(self):
|
|
| 45 |
+ return list(self._chats.keys())
|
|
| 46 |
+ |
|
| 44 | 47 |
|
| 45 | 48 |
class ChatRow(Gtk.ListBoxRow):
|
| 46 | 49 |
def __init__(self, account, jid):
|
| 1 | 1 |
|
| 2 | 2 |
from gi.repository import Gtk
|
| 3 | 3 |
|
| 4 |
+from gajim.common import app
|
|
| 5 |
+ |
|
| 4 | 6 |
from gajim.gui.chat_list import ChatList
|
| 5 | 7 |
|
| 6 | 8 |
|
| ... | ... | @@ -21,19 +23,28 @@ def _on_search_changed(self, search_entry): |
| 21 | 23 |
chat_list = self.get_visible_child()
|
| 22 | 24 |
chat_list.set_filter_text(search_entry.get_text())
|
| 23 | 25 |
|
| 24 |
- def add_chat_list(self, name):
|
|
| 26 |
+ def add_chat_list(self, workspace_id):
|
|
| 25 | 27 |
chat_list = ChatList(self._ui, self._chat_stack)
|
| 26 |
- self._chat_lists[name] = chat_list
|
|
| 27 |
- self.add_named(chat_list, name)
|
|
| 28 |
+ self._chat_lists[workspace_id] = chat_list
|
|
| 29 |
+ self.add_named(chat_list, workspace_id)
|
|
| 30 |
+ return chat_list
|
|
| 28 | 31 |
|
| 29 |
- def show_chat_list(self, name):
|
|
| 30 |
- self.set_visible_child_name(name)
|
|
| 32 |
+ def show_chat_list(self, workspace_id):
|
|
| 33 |
+ self.set_visible_child_name(workspace_id)
|
|
| 31 | 34 |
|
| 32 |
- def add_chat(self, name, *args):
|
|
| 33 |
- chat_list = self._chat_lists.get(name)
|
|
| 35 |
+ def add_chat(self, workspace_id, *args):
|
|
| 36 |
+ chat_list = self._chat_lists.get(workspace_id)
|
|
| 37 |
+ if chat_list is None:
|
|
| 38 |
+ chat_list = self.add_chat_list(workspace_id)
|
|
| 34 | 39 |
chat_list.add_chat(*args)
|
| 35 | 40 |
|
| 36 |
- def select_chat(self, name, *args):
|
|
| 37 |
- self.show_chat_list(name)
|
|
| 38 |
- chat_list = self._chat_lists.get(name)
|
|
| 41 |
+ def select_chat(self, workspace_id, *args):
|
|
| 42 |
+ self.show_chat_list(workspace_id)
|
|
| 43 |
+ chat_list = self._chat_lists.get(workspace_id)
|
|
| 39 | 44 |
chat_list.select_chat(*args)
|
| 45 |
+ |
|
| 46 |
+ def store_open_chats(self, workspace_id):
|
|
| 47 |
+ chat_list = self._chat_lists[workspace_id]
|
|
| 48 |
+ open_chats = chat_list.get_open_chats()
|
|
| 49 |
+ app.settings.set_workspace_setting(
|
|
| 50 |
+ workspace_id, 'open_chats', open_chats)
|
| ... | ... | @@ -5,7 +5,6 @@ |
| 5 | 5 |
from gajim.gui.util import get_builder
|
| 6 | 6 |
from gajim.gui.chat_list_stack import ChatListStack
|
| 7 | 7 |
from gajim.gui.chat_stack import ChatStack
|
| 8 |
-from gajim.gui.util import get_app_window
|
|
| 9 | 8 |
|
| 10 | 9 |
|
| 11 | 10 |
class MainWindow(Gtk.ApplicationWindow):
|
| ... | ... | @@ -19,6 +18,10 @@ def __init__(self): |
| 19 | 18 |
self.window = self
|
| 20 | 19 |
app.window = self
|
| 21 | 20 |
|
| 21 |
+ self._active_workspace = None
|
|
| 22 |
+ |
|
| 23 |
+ self._startup_finished = False
|
|
| 24 |
+ |
|
| 22 | 25 |
self._ui = get_builder('main.ui')
|
| 23 | 26 |
|
| 24 | 27 |
self.add(self._ui.main_grid)
|
| ... | ... | @@ -30,8 +33,6 @@ def __init__(self): |
| 30 | 33 |
self._ui.right_grid.add(self._chat_stack)
|
| 31 | 34 |
self._ui.connect_signals(self)
|
| 32 | 35 |
|
| 33 |
- self._chat_list_stack.add_chat_list('default')
|
|
| 34 |
- |
|
| 35 | 36 |
self.show_all()
|
| 36 | 37 |
|
| 37 | 38 |
self._load_chats()
|
| ... | ... | @@ -51,20 +52,30 @@ def show_title(self, *args): |
| 51 | 52 |
def get_active_jid(self, *args):
|
| 52 | 53 |
pass
|
| 53 | 54 |
|
| 55 |
+ def get_active_workspace(self):
|
|
| 56 |
+ # TODO
|
|
| 57 |
+ return app.settings.get_workspaces()[0]
|
|
| 58 |
+ |
|
| 54 | 59 |
def add_chat(self, account, jid):
|
| 60 |
+ workspace_id = self.get_active_workspace()
|
|
| 61 |
+ self.add_chat_for_workspace(workspace_id, account, jid)
|
|
| 62 |
+ |
|
| 63 |
+ def add_chat_for_workspace(self, workspace_id, account, jid):
|
|
| 55 | 64 |
self._chat_stack.add_chat(account, jid)
|
| 56 |
- self._chat_list_stack.add_chat('default', account, jid)
|
|
| 57 |
- self._chat_list_stack.select_chat('default', account, jid)
|
|
| 65 |
+ self._chat_list_stack.add_chat(workspace_id, account, jid)
|
|
| 66 |
+ |
|
| 67 |
+ if self._startup_finished:
|
|
| 68 |
+ self._chat_list_stack.select_chat(workspace_id, account, jid)
|
|
| 69 |
+ self._chat_list_stack.store_open_chats(workspace_id)
|
|
| 58 | 70 |
|
| 59 | 71 |
def get_control(self, account, jid):
|
| 60 | 72 |
return self._chat_stack.get_control(account, jid)
|
| 61 | 73 |
|
| 62 | 74 |
def _load_chats(self):
|
| 63 |
- for account in app.settings.get_accounts():
|
|
| 64 |
- jids = app.settings.get_account_setting(
|
|
| 65 |
- account, 'opened_chat_controls')
|
|
| 66 |
- if not jids:
|
|
| 67 |
- continue
|
|
| 68 |
- |
|
| 69 |
- for jid in jids.split(','):
|
|
| 70 |
- self.add_chat(account, jid)
|
|
| 75 |
+ for workspace_id in app.settings.get_workspaces():
|
|
| 76 |
+ open_chats = app.settings.get_workspace_setting(workspace_id,
|
|
| 77 |
+ 'open_chats')
|
|
| 78 |
+ for account, jid in open_chats:
|
|
| 79 |
+ self.add_chat_for_workspace(workspace_id, account, jid)
|
|
| 80 |
+ |
|
| 81 |
+ self._startup_finished = True
|