Philipp Hörist pushed to branch mainwindow at gajim / gajim
Commits:
7df4170c by lovetox at 2021-02-28T13:27:46+01:00
Settings: Add json encoder/decoder
- - - - -
3 changed files:
- gajim/chat_control_base.py
- gajim/common/settings.py
- gajim/gtk/main.py
Changes:
=====================================
gajim/chat_control_base.py
=====================================
@@ -1045,6 +1045,8 @@ def _on_window_motion_notify(self, *args):
if not self.parent_win:
# when a groupchat is minimized there is no parent window
return
+ # TODO
+ return
if self.parent_win.get_active_jid() == self.contact.jid:
# if window is the active one, set last interaction
con = app.connections[self.account]
=====================================
gajim/common/settings.py
=====================================
@@ -29,6 +29,7 @@
from collections import defaultdict
from gi.repository import GLib
+from nbxmpp.protocol import JID
from gajim import IS_PORTABLE
from gajim.common import app
@@ -76,6 +77,22 @@
json.dumps(INITAL_WORKSPACE))
+class Encoder(json.JSONEncoder):
+ def default(self, obj):
+ if isinstance(obj, JID):
+ return {'__type': 'JID', 'value': str(obj)}
+ return json.JSONEncoder.default(self, obj)
+
+
+def json_decoder(dct):
+ type_ = dct.get('__type')
+ if type_ is None:
+ return dct
+ if type_ == 'JID':
+ return JID.from_string(dct['value'])
+ return dct
+
+
class Settings:
def __init__(self):
self._con = None
@@ -434,14 +451,17 @@ def _load_settings(self) -> None:
settings = self._con.execute('SELECT * FROM settings').fetchall()
for row in settings:
log.info('Load %s settings', row.name)
- self._settings[row.name] = json.loads(row.settings)
+ self._settings[row.name] = json.loads(row.settings,
+ object_hook=json_decoder)
def _load_account_settings(self) -> None:
account_settings = self._con.execute(
'SELECT * FROM account_settings').fetchall()
for row in account_settings:
log.info('Load account settings: %s', row.account)
- self._account_settings[row.account] = json.loads(row.settings)
+ self._account_settings[row.account] = json.loads(
+ row.settings,
+ object_hook=json_decoder)
def _commit_account_settings(self,
account: str,
@@ -449,7 +469,7 @@ def _commit_account_settings(self,
log.info('Set account settings: %s', account)
self._con.execute(
'UPDATE account_settings SET settings = ? WHERE account = ?',
- (json.dumps(self._account_settings[account]), account))
+ (json.dumps(self._account_settings[account], cls=Encoder),
account))
self._commit(schedule=schedule)
@@ -457,7 +477,7 @@ def _commit_settings(self, name: str, schedule: bool =
True) -> None:
log.info('Set settings: %s', name)
self._con.execute(
'UPDATE settings SET settings = ? WHERE name = ?',
- (json.dumps(self._settings[name]), name))
+ (json.dumps(self._settings[name], cls=Encoder), name))
self._commit(schedule=schedule)
=====================================
gajim/gtk/main.py
=====================================
@@ -482,8 +482,10 @@ def _load_chats(self):
self._chat_list_stack.add_chat_list(workspace_id)
open_chats = app.settings.get_workspace_setting(workspace_id,
'open_chats')
+
+ active_accounts = app.settings.get_active_accounts()
for account, jid, type_, pinned in open_chats:
- if account not in app.connections:
+ if account not in active_accounts:
continue
self.add_chat_for_workspace(workspace_id, account, jid, type_,
pinned=pinned)
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/7df4170c8029cde0320366adcd01f766bf6893f9
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/7df4170c8029cde0320366adcd01f766bf6893f9
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits