Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gajim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mesonium
gajim
Commits
1f907bf7
Commit
1f907bf7
authored
4 years ago
by
Philipp Hörist
Browse files
Options
Downloads
Patches
Plain Diff
Settings: Add notification about changed settings
parent
8afca1d1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
gajim/common/contacts.py
+4
-0
4 additions, 0 deletions
gajim/common/contacts.py
gajim/common/settings.py
+41
-0
41 additions, 0 deletions
gajim/common/settings.py
with
45 additions
and
0 deletions
gajim/common/contacts.py
+
4
−
0
View file @
1f907bf7
...
...
@@ -193,6 +193,10 @@ def __init__(self, jid, account, name='', groups=None, show='', status='',
self
.
pep
=
{}
def
connect_signal
(
self
,
setting
,
func
):
app
.
settings
.
connect_signal
(
setting
,
func
,
self
.
account
.
name
,
self
.
jid
)
def
get_full_jid
(
self
):
if
self
.
resource
:
return
self
.
jid
+
'
/
'
+
self
.
resource
...
...
This diff is collapsed.
Click to expand it.
gajim/common/settings.py
+
41
−
0
View file @
1f907bf7
...
...
@@ -21,8 +21,11 @@
import
json
import
logging
import
sqlite3
import
inspect
import
weakref
from
pathlib
import
Path
from
collections
import
namedtuple
from
collections
import
defaultdict
from
gi.repository
import
GLib
...
...
@@ -74,6 +77,38 @@ def __init__(self):
self
.
_settings
=
{}
self
.
_account_settings
=
{}
self
.
_callbacks
=
defaultdict
(
list
)
def
connect_signal
(
self
,
setting
,
func
,
account
=
None
,
jid
=
None
):
if
not
inspect
.
ismethod
(
func
):
# static methods are not bound to an object so we can’t easily
# remove the func once it should not be called anymore
raise
ValueError
(
'
Only bound methods can be connected
'
)
func
=
weakref
.
WeakMethod
(
func
)
self
.
_callbacks
[(
setting
,
account
,
jid
)].
append
(
func
)
def
disconnect_signals
(
self
,
object_
):
for
_
,
handlers
in
self
.
_callbacks
.
items
():
for
handler
in
list
(
handlers
):
func
=
handler
()
if
func
is
None
or
func
.
__self__
is
object_
:
print
(
'
remove handler
'
,
handler
)
handlers
.
remove
(
handler
)
def
_notify
(
self
,
setting
,
account
=
None
,
jid
=
None
):
log
.
info
(
'
Signal: %s changed
'
,
setting
)
callbacks
=
self
.
_callbacks
[(
setting
,
account
,
jid
)]
for
func
in
list
(
callbacks
):
if
func
()
is
None
:
callbacks
.
remove
(
func
)
continue
try
:
func
()(
setting
,
account
,
jid
)
except
Exception
:
log
.
exception
(
'
Error while executing signal callback
'
)
def
init
(
self
)
->
None
:
self
.
_setup_installation_defaults
()
self
.
_connect_database
()
...
...
@@ -388,6 +423,8 @@ def set_app_setting(self, setting: str, value: SETTING_TYPE) -> None:
del
self
.
_settings
[
'
app
'
][
setting
]
except
KeyError
:
pass
self
.
_notify
(
setting
)
return
default
=
APP_SETTINGS
[
setting
]
...
...
@@ -398,6 +435,7 @@ def set_app_setting(self, setting: str, value: SETTING_TYPE) -> None:
self
.
_settings
[
'
app
'
][
setting
]
=
value
self
.
_commit_settings
(
'
app
'
)
self
.
_notify
(
setting
)
set
=
set_app_setting
...
...
@@ -506,6 +544,7 @@ def set_account_setting(self,
self
.
_account_settings
[
account
][
'
account
'
][
setting
]
=
value
self
.
_commit_account_settings
(
account
)
self
.
_notify
(
setting
,
account
)
def
get_group_chat_setting
(
self
,
account
:
str
,
...
...
@@ -568,6 +607,7 @@ def set_group_chat_setting(self,
group_chat_settings
[
jid
][
setting
]
=
value
self
.
_commit_account_settings
(
account
)
self
.
_notify
(
setting
,
account
,
jid
)
def
get_contact_setting
(
self
,
account
:
str
,
...
...
@@ -621,6 +661,7 @@ def set_contact_setting(self,
contact_settings
[
jid
][
setting
]
=
value
self
.
_commit_account_settings
(
account
)
self
.
_notify
(
setting
,
account
,
jid
)
def
set_soundevent_setting
(
self
,
event_name
:
str
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment