Philipp Hörist pushed to branch master at gajim / gajim
Commits:
-
1f907bf7
by lovetox at 2020-09-03T22:39:39+02:00
-
bb6ae459
by lovetox at 2020-09-03T22:39:45+02:00
-
1a151478
by lovetox at 2020-09-03T22:39:45+02:00
5 changed files:
- gajim/common/contacts.py
- gajim/common/settings.py
- gajim/groupchat_control.py
- gajim/gtk/preferences.py
- gajim/gtk/settings.py
Changes:
| ... | ... | @@ -193,6 +193,10 @@ class Contact(CommonContact): |
| 193 | 193 |
|
| 194 | 194 |
self.pep = {}
|
| 195 | 195 |
|
| 196 |
+ def connect_signal(self, setting, func):
|
|
| 197 |
+ app.settings.connect_signal(
|
|
| 198 |
+ setting, func, self.account.name, self.jid)
|
|
| 199 |
+ |
|
| 196 | 200 |
def get_full_jid(self):
|
| 197 | 201 |
if self.resource:
|
| 198 | 202 |
return self.jid + '/' + self.resource
|
| ... | ... | @@ -21,8 +21,11 @@ import sys |
| 21 | 21 |
import json
|
| 22 | 22 |
import logging
|
| 23 | 23 |
import sqlite3
|
| 24 |
+import inspect
|
|
| 25 |
+import weakref
|
|
| 24 | 26 |
from pathlib import Path
|
| 25 | 27 |
from collections import namedtuple
|
| 28 |
+from collections import defaultdict
|
|
| 26 | 29 |
|
| 27 | 30 |
from gi.repository import GLib
|
| 28 | 31 |
|
| ... | ... | @@ -74,6 +77,38 @@ class _Settings: |
| 74 | 77 |
self._settings = {}
|
| 75 | 78 |
self._account_settings = {}
|
| 76 | 79 |
|
| 80 |
+ self._callbacks = defaultdict(list)
|
|
| 81 |
+ |
|
| 82 |
+ def connect_signal(self, setting, func, account=None, jid=None):
|
|
| 83 |
+ if not inspect.ismethod(func):
|
|
| 84 |
+ # static methods are not bound to an object so we can’t easily
|
|
| 85 |
+ # remove the func once it should not be called anymore
|
|
| 86 |
+ raise ValueError('Only bound methods can be connected')
|
|
| 87 |
+ |
|
| 88 |
+ func = weakref.WeakMethod(func)
|
|
| 89 |
+ self._callbacks[(setting, account, jid)].append(func)
|
|
| 90 |
+ |
|
| 91 |
+ def disconnect_signals(self, object_):
|
|
| 92 |
+ for _, handlers in self._callbacks.items():
|
|
| 93 |
+ for handler in list(handlers):
|
|
| 94 |
+ func = handler()
|
|
| 95 |
+ if func is None or func.__self__ is object_:
|
|
| 96 |
+ print('remove handler', handler)
|
|
| 97 |
+ handlers.remove(handler)
|
|
| 98 |
+ |
|
| 99 |
+ def _notify(self, setting, account=None, jid=None):
|
|
| 100 |
+ log.info('Signal: %s changed', setting)
|
|
| 101 |
+ |
|
| 102 |
+ callbacks = self._callbacks[(setting, account, jid)]
|
|
| 103 |
+ for func in list(callbacks):
|
|
| 104 |
+ if func() is None:
|
|
| 105 |
+ callbacks.remove(func)
|
|
| 106 |
+ continue
|
|
| 107 |
+ try:
|
|
| 108 |
+ func()(setting, account, jid)
|
|
| 109 |
+ except Exception:
|
|
| 110 |
+ log.exception('Error while executing signal callback')
|
|
| 111 |
+ |
|
| 77 | 112 |
def init(self) -> None:
|
| 78 | 113 |
self._setup_installation_defaults()
|
| 79 | 114 |
self._connect_database()
|
| ... | ... | @@ -388,6 +423,8 @@ class _Settings: |
| 388 | 423 |
del self._settings['app'][setting]
|
| 389 | 424 |
except KeyError:
|
| 390 | 425 |
pass
|
| 426 |
+ |
|
| 427 |
+ self._notify(setting)
|
|
| 391 | 428 |
return
|
| 392 | 429 |
|
| 393 | 430 |
default = APP_SETTINGS[setting]
|
| ... | ... | @@ -398,6 +435,7 @@ class _Settings: |
| 398 | 435 |
self._settings['app'][setting] = value
|
| 399 | 436 |
|
| 400 | 437 |
self._commit_settings('app')
|
| 438 |
+ self._notify(setting)
|
|
| 401 | 439 |
|
| 402 | 440 |
set = set_app_setting
|
| 403 | 441 |
|
| ... | ... | @@ -506,6 +544,7 @@ class _Settings: |
| 506 | 544 |
self._account_settings[account]['account'][setting] = value
|
| 507 | 545 |
|
| 508 | 546 |
self._commit_account_settings(account)
|
| 547 |
+ self._notify(setting, account)
|
|
| 509 | 548 |
|
| 510 | 549 |
def get_group_chat_setting(self,
|
| 511 | 550 |
account: str,
|
| ... | ... | @@ -568,6 +607,7 @@ class _Settings: |
| 568 | 607 |
group_chat_settings[jid][setting] = value
|
| 569 | 608 |
|
| 570 | 609 |
self._commit_account_settings(account)
|
| 610 |
+ self._notify(setting, account, jid)
|
|
| 571 | 611 |
|
| 572 | 612 |
def get_contact_setting(self,
|
| 573 | 613 |
account: str,
|
| ... | ... | @@ -621,6 +661,7 @@ class _Settings: |
| 621 | 661 |
contact_settings[jid][setting] = value
|
| 622 | 662 |
|
| 623 | 663 |
self._commit_account_settings(account)
|
| 664 |
+ self._notify(setting, account, jid)
|
|
| 624 | 665 |
|
| 625 | 666 |
def set_soundevent_setting(self,
|
| 626 | 667 |
event_name: str,
|
| ... | ... | @@ -223,6 +223,10 @@ class GroupchatControl(ChatControlBase): |
| 223 | 223 |
('message-error', ged.GUI1, self._on_message_error),
|
| 224 | 224 |
('bookmarks-received', ged.GUI2, self._on_bookmarks_received),
|
| 225 | 225 |
])
|
| 226 |
+ |
|
| 227 |
+ app.settings.connect_signal('gc_print_join_left_default', self.update_actions)
|
|
| 228 |
+ app.settings.connect_signal('gc_print_status_default', self.update_actions)
|
|
| 229 |
+ |
|
| 226 | 230 |
# pylint: enable=line-too-long
|
| 227 | 231 |
|
| 228 | 232 |
self.is_connected = False
|
| ... | ... | @@ -358,7 +362,7 @@ class GroupchatControl(ChatControlBase): |
| 358 | 362 |
act.connect('change-state', self._on_sync_threshold)
|
| 359 | 363 |
self.parent_win.window.add_action(act)
|
| 360 | 364 |
|
| 361 |
- def update_actions(self):
|
|
| 365 |
+ def update_actions(self, *args):
|
|
| 362 | 366 |
if self.parent_win is None:
|
| 363 | 367 |
return
|
| 364 | 368 |
|
| ... | ... | @@ -1661,6 +1665,8 @@ class GroupchatControl(ChatControlBase): |
| 1661 | 1665 |
del win._controls[self.account][self.contact.jid]
|
| 1662 | 1666 |
|
| 1663 | 1667 |
def shutdown(self, reason=None):
|
| 1668 |
+ app.settings.disconnect_signals(self)
|
|
| 1669 |
+ |
|
| 1664 | 1670 |
# Leave MUC if we are still joined
|
| 1665 | 1671 |
if self._muc_data.state != MUCJoinedState.NOT_JOINED:
|
| 1666 | 1672 |
self.got_disconnected()
|
| ... | ... | @@ -522,13 +522,9 @@ class Preferences(Gtk.ApplicationWindow): |
| 522 | 522 |
|
| 523 | 523 |
def _on_join_leave_toggled(self, widget):
|
| 524 | 524 |
self.on_checkbutton_toggled(widget, 'gc_print_join_left_default')
|
| 525 |
- for control in self._get_all_muc_controls():
|
|
| 526 |
- control.update_actions()
|
|
| 527 | 525 |
|
| 528 | 526 |
def _on_show_status_change_toggled(self, widget):
|
| 529 | 527 |
self.on_checkbutton_toggled(widget, 'gc_print_status_default')
|
| 530 |
- for control in self._get_all_muc_controls():
|
|
| 531 |
- control.update_actions()
|
|
| 532 | 528 |
|
| 533 | 529 |
def on_show_chatstate_in_tabs_toggled(self, widget):
|
| 534 | 530 |
self.on_checkbutton_toggled(widget, 'show_chatstate_in_tabs')
|
| ... | ... | @@ -23,6 +23,7 @@ from gi.repository import Pango |
| 23 | 23 |
from gajim.common import app
|
| 24 | 24 |
from gajim.common import passwords
|
| 25 | 25 |
from gajim.common.i18n import _
|
| 26 |
+from gajim.common.i18n import Q_
|
|
| 26 | 27 |
|
| 27 | 28 |
from gajim import gtkgui_helpers
|
| 28 | 29 |
|
| ... | ... | @@ -321,7 +322,7 @@ class SwitchSetting(GenericSetting): |
| 321 | 322 |
self._set_label(value)
|
| 322 | 323 |
|
| 323 | 324 |
def _set_label(self, active):
|
| 324 |
- text = _('On') if active else _('Off')
|
|
| 325 |
+ text = Q_('?switch:On') if active else Q_('?switch:Off')
|
|
| 325 | 326 |
self._switch_state_label.set_text(text)
|
| 326 | 327 |
|
| 327 | 328 |
|