annotate libervia/frontends/quick_frontend/quick_app.py @ 4074:26b7ed2817da

refactoring: rename `sat_frontends` to `libervia.frontends`
author Goffi <goffi@goffi.org>
date Fri, 02 Jun 2023 14:12:38 +0200
parents sat_frontends/quick_frontend/quick_app.py@4b842c1fb686
children 6b581d4c249f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
1 #!/usr/bin/env python3
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
3 # helper class for making a SAT frontend
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3254
diff changeset
4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
0
goffi@necton2
parents:
diff changeset
5
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
6 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
9 # (at your option) any later version.
0
goffi@necton2
parents:
diff changeset
10
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
11 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
14 # GNU Affero General Public License for more details.
0
goffi@necton2
parents:
diff changeset
15
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
0
goffi@necton2
parents:
diff changeset
18
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4041
diff changeset
19 from libervia.backend.core.log import getLogger
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4041
diff changeset
20 from libervia.backend.core.i18n import _
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4041
diff changeset
21 from libervia.backend.core import exceptions
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4041
diff changeset
22 from libervia.backend.tools import trigger
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4041
diff changeset
23 from libervia.backend.tools.common import data_format
1331
7fa07c7b0761 quick_frontend (quick_app): addListener takes a profiles_filter argument to check the profile before calling a listener (profile must be passed right after the event type in callListeners)
souliane <souliane@mailoo.org>
parents: 1329
diff changeset
24
4074
26b7ed2817da refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
25 from libervia.frontends.tools import jid
26b7ed2817da refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
26 from libervia.frontends.quick_frontend import quick_widgets
26b7ed2817da refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
27 from libervia.frontends.quick_frontend import quick_menus
26b7ed2817da refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
28 from libervia.frontends.quick_frontend import quick_blog
26b7ed2817da refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
29 from libervia.frontends.quick_frontend import quick_chat, quick_games
26b7ed2817da refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
30 from libervia.frontends.quick_frontend import quick_contact_list
26b7ed2817da refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
31 from libervia.frontends.quick_frontend.constants import Const as C
510
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 507
diff changeset
32
1331
7fa07c7b0761 quick_frontend (quick_app): addListener takes a profiles_filter argument to check the profile before calling a listener (profile must be passed right after the event type in callListeners)
souliane <souliane@mailoo.org>
parents: 1329
diff changeset
33 import sys
1972
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
34 import time
906
1cbae66fa725 quick_app: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 811
diff changeset
35
3113
b067736d5099 quick frontend (app): removed workaround for pyjamas
Goffi <goffi@goffi.org>
parents: 3102
diff changeset
36
b067736d5099 quick frontend (app): removed workaround for pyjamas
Goffi <goffi@goffi.org>
parents: 3102
diff changeset
37 log = getLogger(__name__)
1326
88e40f31b17e quick_frontend (quick_app): fixes the call to a bridge method that was done with a JID instead of unicode
souliane <souliane@mailoo.org>
parents: 1325
diff changeset
38
88e40f31b17e quick_frontend (quick_app): fixes the call to a bridge method that was done with a JID instead of unicode
souliane <souliane@mailoo.org>
parents: 1325
diff changeset
39
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
40 class ProfileManager(object):
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
41 """Class managing all data relative to one profile, and plugging in mechanism"""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
42
2050
046449cc2bff core, bridge, frontends: removed deprecated bridge method askConfirmation, confirmationAnswer, actionResult, actionResultExt and getWaitingConf
Goffi <goffi@goffi.org>
parents: 2049
diff changeset
43 # TODO: handle waiting XMLUI requests: getWaitingConf doesn't exist anymore
046449cc2bff core, bridge, frontends: removed deprecated bridge method askConfirmation, confirmationAnswer, actionResult, actionResultExt and getWaitingConf
Goffi <goffi@goffi.org>
parents: 2049
diff changeset
44 # and a way to keep some XMLUI request between sessions is expected in backend
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
45 host = None
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
46 bridge = None
3254
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3232
diff changeset
47 cache_keys_to_get = ['avatar', 'nicknames']
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
48
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
49 def __init__(self, profile):
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
50 self.profile = profile
2091
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
51 self.connected = False
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
52 self.whoami = None
1972
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
53 self.notifications = {} # key: bare jid or '' for general, value: notif data
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
54
2091
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
55 @property
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
56 def autodisconnect(self):
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
57 try:
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
58 autodisconnect = self._autodisconnect
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
59 except AttributeError:
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
60 autodisconnect = False
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
61 return autodisconnect
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
62
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
63 def plug(self):
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
64 """Plug the profile to the host"""
2685
eb69ec549d05 quick frontend (app): create the contact list immediatly on plug
Goffi <goffi@goffi.org>
parents: 2669
diff changeset
65 # first of all we create the contact lists
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
66 self.host.contact_lists.add_profile(self.profile)
2685
eb69ec549d05 quick frontend (app): create the contact list immediatly on plug
Goffi <goffi@goffi.org>
parents: 2669
diff changeset
67
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
68 # we get the essential params
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
69 self.bridge.param_get_a_async(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
70 "JabberID",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
71 "Connection",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
72 profile_key=self.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
73 callback=self._plug_profile_jid,
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
74 errback=self._get_param_error,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
75 )
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
76
1435
7590bbf44eed bridge, quick_frontend: the JID that is assigned by the server can differ from the one we asked for (resource)
souliane <souliane@mailoo.org>
parents: 1429
diff changeset
77 def _plug_profile_jid(self, jid_s):
7590bbf44eed bridge, quick_frontend: the JID that is assigned by the server can differ from the one we asked for (resource)
souliane <souliane@mailoo.org>
parents: 1429
diff changeset
78 self.whoami = jid.JID(jid_s) # resource might change after the connection
3130
b9486a7f9b4f quick frontend (app): log own jid when received
Goffi <goffi@goffi.org>
parents: 3118
diff changeset
79 log.info(f"Our current jid is: {self.whoami}")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
80 self.bridge.is_connected(self.profile, callback=self._plug_profile_isconnected)
2091
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
81
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
82 def _autodisconnect_eb(self, failure_):
2167
4b78b4c7f805 core, frontends: various fixes for Libervia:
Goffi <goffi@goffi.org>
parents: 2142
diff changeset
83 # XXX: we ignore error on this parameter, as Libervia can't access it
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
84 log.warning(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
85 _("Error while trying to get autodisconnect param, ignoring: {}").format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
86 failure_
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
87 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
88 )
2167
4b78b4c7f805 core, frontends: various fixes for Libervia:
Goffi <goffi@goffi.org>
parents: 2142
diff changeset
89 self._plug_profile_autodisconnect("false")
4b78b4c7f805 core, frontends: various fixes for Libervia:
Goffi <goffi@goffi.org>
parents: 2142
diff changeset
90
2091
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
91 def _plug_profile_isconnected(self, connected):
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
92 self.connected = connected
3204
fc2bea41e402 quick frontend(app): new `QuickApp.profileConnected` method
Goffi <goffi@goffi.org>
parents: 3193
diff changeset
93 if connected:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
94 self.host.profile_connected(self.profile)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
95 self.bridge.param_get_a_async(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
96 "autodisconnect",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
97 "Connection",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
98 profile_key=self.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
99 callback=self._plug_profile_autodisconnect,
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
100 errback=self._autodisconnect_eb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
101 )
2091
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
102
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
103 def _plug_profile_autodisconnect(self, autodisconnect):
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
104 if C.bool(autodisconnect):
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
105 self._autodisconnect = True
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
106 self.bridge.param_get_a_async(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
107 "autoconnect",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
108 "Connection",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
109 profile_key=self.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
110 callback=self._plug_profile_autoconnect,
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
111 errback=self._get_param_error,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
112 )
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
113
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
114 def _plug_profile_autoconnect(self, value_str):
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
115 autoconnect = C.bool(value_str)
2091
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
116 if autoconnect and not self.connected:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
117 self.host.connect(
2765
378188abe941 misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents: 2685
diff changeset
118 self.profile, callback=lambda __: self._plug_profile_afterconnect()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
119 )
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
120 else:
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
121 self._plug_profile_afterconnect()
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
122
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
123 def _plug_profile_afterconnect(self):
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
124 # Profile can be connected or not
1318
6c7d89843f1b frontends (quick frontend): use of new getEntitiesData to get cached values for avatars on profile connection.
Goffi <goffi@goffi.org>
parents: 1290
diff changeset
125 # we get cached data
2091
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
126 self.connected = True
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
127 self.host.bridge.features_get(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
128 profile_key=self.profile,
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
129 callback=self._plug_profile_get_features_cb,
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
130 errback=self._plug_profile_get_features_eb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
131 )
1655
ad2ad28b8923 quick_frontend: getFeatures is called on profile plug, and saved in host.features
Goffi <goffi@goffi.org>
parents: 1636
diff changeset
132
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
133 def _plug_profile_get_features_eb(self, failure):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
134 log.error("Couldn't get features: {}".format(failure))
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
135 self._plug_profile_get_features_cb({})
1655
ad2ad28b8923 quick_frontend: getFeatures is called on profile plug, and saved in host.features
Goffi <goffi@goffi.org>
parents: 1636
diff changeset
136
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
137 def _plug_profile_get_features_cb(self, features):
1655
ad2ad28b8923 quick_frontend: getFeatures is called on profile plug, and saved in host.features
Goffi <goffi@goffi.org>
parents: 1636
diff changeset
138 self.host.features = features
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
139 self.host.bridge.entities_data_get([], ProfileManager.cache_keys_to_get,
3254
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3232
diff changeset
140 profile=self.profile,
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
141 callback=self._plug_profile_got_cached_values,
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
142 errback=self._plug_profile_failed_cached_values)
1318
6c7d89843f1b frontends (quick frontend): use of new getEntitiesData to get cached values for avatars on profile connection.
Goffi <goffi@goffi.org>
parents: 1290
diff changeset
143
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
144 def _plug_profile_failed_cached_values(self, failure):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
145 log.error("Couldn't get cached values: {}".format(failure))
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
146 self._plug_profile_got_cached_values({})
1318
6c7d89843f1b frontends (quick frontend): use of new getEntitiesData to get cached values for avatars on profile connection.
Goffi <goffi@goffi.org>
parents: 1290
diff changeset
147
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
148 def _plug_profile_got_cached_values(self, cached_values):
2685
eb69ec549d05 quick frontend (app): create the contact list immediatly on plug
Goffi <goffi@goffi.org>
parents: 2669
diff changeset
149 contact_list = self.host.contact_lists[self.profile]
1332
0f92b6a150ff quick_frontend, primitivus: use a listener to update the contact list when receiving a presence
souliane <souliane@mailoo.org>
parents: 1331
diff changeset
150 # add the contact list and its listener
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
151 for entity_s, data in cached_values.items():
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
152 for key, value in data.items():
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
153 self.host.entity_data_updated_handler(entity_s, key, value, self.profile)
1318
6c7d89843f1b frontends (quick frontend): use of new getEntitiesData to get cached values for avatars on profile connection.
Goffi <goffi@goffi.org>
parents: 1290
diff changeset
154
2091
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
155 if not self.connected:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
156 self.host.set_presence_status(C.PRESENCE_UNAVAILABLE, "", profile=self.profile)
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
157 else:
1429
798e5e38516b quick_frontend (quick_app): properly fixed roster loss:
Goffi <goffi@goffi.org>
parents: 1418
diff changeset
158
798e5e38516b quick_frontend (quick_app): properly fixed roster loss:
Goffi <goffi@goffi.org>
parents: 1418
diff changeset
159 contact_list.fill()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
160 self.host.set_presence_status(profile=self.profile)
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
161
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
162 # The waiting subscription requests
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
163 self.bridge.sub_waiting_get(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
164 self.profile, callback=self._plug_profile_got_waiting_sub
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
165 )
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
166
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
167 def _plug_profile_got_waiting_sub(self, waiting_sub):
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
168 for sub in waiting_sub:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
169 self.host.subscribe_handler(waiting_sub[sub], sub, self.profile)
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
170
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
171 self.bridge.muc_get_rooms_joined(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
172 self.profile, callback=self._plug_profile_got_rooms_joined
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
173 )
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
174
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
175 def _plug_profile_got_rooms_joined(self, rooms_args):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
176 # Now we open the MUC window where we already are:
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
177 for room_args in rooms_args:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
178 self.host.muc_room_joined_handler(*room_args, profile=self.profile)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
179 # Presence must be requested after rooms are filled
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
180 self.host.bridge.presence_statuses_get(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
181 self.profile, callback=self._plug_profile_got_presences
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
182 )
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
183
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
184 def _plug_profile_got_presences(self, presences):
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
185 for contact in presences:
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
186 for res in presences[contact]:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
187 jabber_id = ("%s/%s" % (jid.JID(contact).bare, res)) if res else contact
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
188 show = presences[contact][res][0]
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
189 priority = presences[contact][res][1]
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
190 statuses = presences[contact][res][2]
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
191 self.host.presence_update_handler(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
192 jabber_id, show, priority, statuses, self.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
193 )
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
194
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
195 # At this point, profile should be fully plugged
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
196 # and we launch frontend specific method
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
197 self.host.profile_plugged(self.profile)
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
198
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
199 def _get_param_error(self, failure):
2091
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
200 log.error(_("Can't get profile parameter: {msg}").format(msg=failure))
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
201
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
202
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
203 class ProfilesManager(object):
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
204 """Class managing collection of profiles"""
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
205
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
206 def __init__(self):
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
207 self._profiles = {}
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
208
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
209 def __contains__(self, profile):
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
210 return profile in self._profiles
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
211
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
212 def __iter__(self):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
213 return iter(self._profiles.keys())
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
214
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
215 def __getitem__(self, profile):
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
216 return self._profiles[profile]
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
217
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
218 def __len__(self):
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
219 return len(self._profiles)
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
220
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
221 def items(self):
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
222 return self._profiles.items()
2091
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
223
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
224 def values(self):
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
225 return self._profiles.values()
2590
bd9d92bc0d6c quick frontends (app): retrieve namespaces on startup
Goffi <goffi@goffi.org>
parents: 2586
diff changeset
226
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
227 def plug(self, profile):
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
228 if profile in self._profiles:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
229 raise exceptions.ConflictError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
230 "A profile of the name [{}] is already plugged".format(profile)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
231 )
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
232 self._profiles[profile] = ProfileManager(profile)
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
233 self._profiles[profile].plug()
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
234
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
235 def unplug(self, profile):
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
236 if profile not in self._profiles:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
237 raise ValueError("The profile [{}] is not plugged".format(profile))
1332
0f92b6a150ff quick_frontend, primitivus: use a listener to update the contact list when receiving a presence
souliane <souliane@mailoo.org>
parents: 1331
diff changeset
238
0f92b6a150ff quick_frontend, primitivus: use a listener to update the contact list when receiving a presence
souliane <souliane@mailoo.org>
parents: 1331
diff changeset
239 # remove the contact list and its listener
0f92b6a150ff quick_frontend, primitivus: use a listener to update the contact list when receiving a presence
souliane <souliane@mailoo.org>
parents: 1331
diff changeset
240 host = self._profiles[profile].host
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
241 host.contact_lists[profile].unplug()
1332
0f92b6a150ff quick_frontend, primitivus: use a listener to update the contact list when receiving a presence
souliane <souliane@mailoo.org>
parents: 1331
diff changeset
242
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
243 del self._profiles[profile]
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
244
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
245 def choose_one_profile(self):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
246 return list(self._profiles.keys())[0]
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
247
1332
0f92b6a150ff quick_frontend, primitivus: use a listener to update the contact list when receiving a presence
souliane <souliane@mailoo.org>
parents: 1331
diff changeset
248
524
0bb595eff25b primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents: 513
diff changeset
249 class QuickApp(object):
0
goffi@necton2
parents:
diff changeset
250 """This class contain the main methods needed for the frontend"""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
251
2846
58ea675d0f05 quick frontend (app): added AUTO_RESYNC attribute in QuickApp, when set (default) the resync method is called on all widgets automatically:
Goffi <goffi@goffi.org>
parents: 2845
diff changeset
252 MB_HANDLER = True #: Set to False if the frontend doesn't manage microblog
58ea675d0f05 quick frontend (app): added AUTO_RESYNC attribute in QuickApp, when set (default) the resync method is called on all widgets automatically:
Goffi <goffi@goffi.org>
parents: 2845
diff changeset
253 AVATARS_HANDLER = True #: set to False if avatars are not used
58ea675d0f05 quick frontend (app): added AUTO_RESYNC attribute in QuickApp, when set (default) the resync method is called on all widgets automatically:
Goffi <goffi@goffi.org>
parents: 2845
diff changeset
254 ENCRYPTION_HANDLERS = True #: set to False if encryption is handled separatly
58ea675d0f05 quick frontend (app): added AUTO_RESYNC attribute in QuickApp, when set (default) the resync method is called on all widgets automatically:
Goffi <goffi@goffi.org>
parents: 2845
diff changeset
255 #: if True, QuickApp will call resync itself, on all widgets at the same time
58ea675d0f05 quick frontend (app): added AUTO_RESYNC attribute in QuickApp, when set (default) the resync method is called on all widgets automatically:
Goffi <goffi@goffi.org>
parents: 2845
diff changeset
256 #: if False, frontend must call resync itself when suitable (e.g. widget is being
58ea675d0f05 quick frontend (app): added AUTO_RESYNC attribute in QuickApp, when set (default) the resync method is called on all widgets automatically:
Goffi <goffi@goffi.org>
parents: 2845
diff changeset
257 #: visible)
58ea675d0f05 quick frontend (app): added AUTO_RESYNC attribute in QuickApp, when set (default) the resync method is called on all widgets automatically:
Goffi <goffi@goffi.org>
parents: 2845
diff changeset
258 AUTO_RESYNC = True
0
goffi@necton2
parents:
diff changeset
259
2091
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
260 def __init__(self, bridge_factory, xmlui, check_options=None, connect_bridge=True):
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
261 """Create a frontend application
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
262
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
263 @param bridge_factory: method to use to create the bridge
1468
731fbed0b9cf quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents: 1461
diff changeset
264 @param xmlui: xmlui module
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
265 @param check_options: method to call to check options (usually command line
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
266 arguments)
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
267 """
1468
731fbed0b9cf quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents: 1461
diff changeset
268 self.xmlui = xmlui
1365
ba87b940f07a core, quick_frontends: added an "extra" item in getMenus + use of new quick_menus module in QuickApp
Goffi <goffi@goffi.org>
parents: 1363
diff changeset
269 self.menus = quick_menus.QuickMenusManager(self)
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
270 ProfileManager.host = self
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
271 self.profiles = ProfilesManager()
3065
f8e3789912d0 quick frontend (contact list): added "contactsFilled" event
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
272 # profiles currently being plugged, used to (un)lock contact list updates
f8e3789912d0 quick frontend (contact list): added "contactsFilled" event
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
273 self._plugs_in_progress = set()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
274 self.ready_profiles = set() # profiles which are connected and ready
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
275 self.signals_cache = {} # used to keep signal received between start of
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
276 # plug_profile and when the profile is actualy ready
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
277 self.contact_lists = quick_contact_list.QuickContactListHandler(self)
1365
ba87b940f07a core, quick_frontends: added an "extra" item in getMenus + use of new quick_menus module in QuickApp
Goffi <goffi@goffi.org>
parents: 1363
diff changeset
278 self.widgets = quick_widgets.QuickWidgetsManager(self)
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
279 if check_options is not None:
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
280 self.options = check_options()
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
281 else:
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
282 self.options = None
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
283
3159
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3158
diff changeset
284 # see selected_widget setter and getter
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3158
diff changeset
285 self._selected_widget = None
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
286
2862
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
287 # listeners are callable watching events
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
288 self._listeners = {} # key: listener type ("avatar", "selected", etc),
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
289 # value: list of callbacks
1319
781ee3539252 quick frontends(quick app): add a listeners (observer/observable) mechanism to call a callback when a event happen. Implemented an "avatar" event.
Goffi <goffi@goffi.org>
parents: 1318
diff changeset
290
1347
ba41a81d14c2 frontends (QuickApp), tools (TriggerManager): frontends can also use triggers + add those for sending and receiving a message
souliane <souliane@mailoo.org>
parents: 1345
diff changeset
291 # triggers
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
292 self.trigger = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
293 trigger.TriggerManager()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
294 ) # trigger are used to change the default behaviour
1347
ba41a81d14c2 frontends (QuickApp), tools (TriggerManager): frontends can also use triggers + add those for sending and receiving a message
souliane <souliane@mailoo.org>
parents: 1345
diff changeset
295
0
goffi@necton2
parents:
diff changeset
296 ## bridge ##
2091
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
297 self.bridge = bridge_factory()
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
298 ProfileManager.bridge = self.bridge
2091
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
299 if connect_bridge:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
300 self.connect_bridge()
2091
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
301
2862
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
302 # frontend notifications
2091
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
303 self._notif_id = 0
3166
122075ceaa53 quick frontend (app): replaced OrderedDict by regular dict:
Goffi <goffi@goffi.org>
parents: 3164
diff changeset
304 self._notifications = {}
2862
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
305 # watched progresses and associated callbacks
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
306 self._progress_ids = {}
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
307 # available features
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
308 # FIXME: features are profile specific, to be checked
2091
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
309 self.features = None
2862
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
310 #: map of short name to namespaces
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
311 self.ns_map = {}
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
312 #: available encryptions
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
313 self.encryption_plugins = []
2862
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
314 # state of synchronisation with backend
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
315 self._sync = True
2091
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
316
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
317 def connect_bridge(self):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
318 self.bridge.bridge_connect(callback=self._bridge_cb, errback=self._bridge_eb)
2091
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
319
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
320 def _namespaces_get_cb(self, ns_map):
2590
bd9d92bc0d6c quick frontends (app): retrieve namespaces on startup
Goffi <goffi@goffi.org>
parents: 2586
diff changeset
321 self.ns_map = ns_map
bd9d92bc0d6c quick frontends (app): retrieve namespaces on startup
Goffi <goffi@goffi.org>
parents: 2586
diff changeset
322
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
323 def _namespaces_get_eb(self, failure_):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
324 log.error(_("Can't get namespaces map: {msg}").format(msg=failure_))
2590
bd9d92bc0d6c quick frontends (app): retrieve namespaces on startup
Goffi <goffi@goffi.org>
parents: 2586
diff changeset
325
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
326 def _encryption_plugins_get_cb(self, plugins_ser):
3102
7574f795bd1e core, bridge: encryptionPluginsGet now returns a serialised list + added "directed" in metadata
Goffi <goffi@goffi.org>
parents: 3101
diff changeset
327 self.encryption_plugins = data_format.deserialise(plugins_ser, type_check=list)
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
328
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
329 def _encryption_plugins_get_eb(self, failure_):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
330 log.warning(_("Can't retrieve encryption plugins: {msg}").format(msg=failure_))
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
331
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
332 def on_bridge_connected(self):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
333 self.bridge.ready_get(self.on_backend_ready)
2097
4bc408b549cd quick_frontend(QuickApp): added onBridgeConnected method
Goffi <goffi@goffi.org>
parents: 2091
diff changeset
334
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
335 def _bridge_cb(self):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
336 self.register_signal("connected")
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
337 self.register_signal("disconnected")
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
338 self.register_signal("action_new")
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
339 self.register_signal("contact_new")
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
340 self.register_signal("message_new")
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
341 if self.ENCRYPTION_HANDLERS:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
342 self.register_signal("message_encryption_started")
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
343 self.register_signal("message_encryption_stopped")
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
344 self.register_signal("presence_update")
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
345 self.register_signal("subscribe")
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
346 self.register_signal("param_update")
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
347 self.register_signal("contact_deleted")
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
348 self.register_signal("entity_data_updated")
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
349 self.register_signal("progress_started")
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
350 self.register_signal("progress_finished")
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
351 self.register_signal("progress_error")
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
352 self.register_signal("muc_room_joined", iface="plugin")
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
353 self.register_signal("muc_room_left", iface="plugin")
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
354 self.register_signal("muc_room_user_changed_nick", iface="plugin")
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
355 self.register_signal("muc_room_new_subject", iface="plugin")
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
356 self.register_signal("chat_state_received", iface="plugin")
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
357 self.register_signal("message_state", iface="plugin")
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
358 self.register_signal("ps_event", iface="plugin")
2854
eb9fa72eb62b core: added a "_debug" signal:
Goffi <goffi@goffi.org>
parents: 2848
diff changeset
359 # useful for debugging
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
360 self.register_signal("_debug", iface="core")
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
361
1360
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1352
diff changeset
362 # FIXME: do it dynamically
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
363 quick_games.Tarot.register_signals(self)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
364 quick_games.Quiz.register_signals(self)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
365 quick_games.Radiocol.register_signals(self)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
366 self.on_bridge_connected()
1360
8ea8fa13c351 frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents: 1352
diff changeset
367
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
368 def _bridge_eb(self, failure):
2091
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
369 if isinstance(failure, exceptions.BridgeExceptionNoService):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
370 print((_("Can't connect to SàT backend, are you sure it's launched ?")))
3490
509f7a1c67dc frontends: use new EXIT_BACKEND_NOT_FOUND exit code:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
371 sys.exit(C.EXIT_BACKEND_NOT_FOUND)
2091
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
372 elif isinstance(failure, exceptions.BridgeInitError):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
373 print((_("Can't init bridge")))
3490
509f7a1c67dc frontends: use new EXIT_BACKEND_NOT_FOUND exit code:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
374 sys.exit(C.EXIT_BRIDGE_ERROR)
2091
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
375 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
376 print((_("Error while initialising bridge: {}".format(failure))))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
377
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
378 def on_backend_ready(self):
3118
02492db1ce39 quick frontend (app): call `getReady` once connected to bridge:
Goffi <goffi@goffi.org>
parents: 3113
diff changeset
379 log.info("backend is ready")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
380 self.bridge.namespaces_get(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
381 callback=self._namespaces_get_cb, errback=self._namespaces_get_eb)
3118
02492db1ce39 quick frontend (app): call `getReady` once connected to bridge:
Goffi <goffi@goffi.org>
parents: 3113
diff changeset
382 # we cache available encryption plugins, as we'll use them on each
02492db1ce39 quick frontend (app): call `getReady` once connected to bridge:
Goffi <goffi@goffi.org>
parents: 3113
diff changeset
383 # new chat widget
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
384 self.bridge.encryption_plugins_get(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
385 callback=self._encryption_plugins_get_cb,
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
386 errback=self._encryption_plugins_get_eb)
3118
02492db1ce39 quick frontend (app): call `getReady` once connected to bridge:
Goffi <goffi@goffi.org>
parents: 3113
diff changeset
387
02492db1ce39 quick frontend (app): call `getReady` once connected to bridge:
Goffi <goffi@goffi.org>
parents: 3113
diff changeset
388
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
389 @property
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
390 def current_profile(self):
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
391 """Profile that a user would expect to use"""
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
392 try:
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
393 return self.selected_widget.profile
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
394 except (TypeError, AttributeError):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
395 return self.profiles.choose_one_profile()
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
396
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
397 @property
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
398 def visible_widgets(self):
2790
19ab67e28822 quick frontends: visible_widgets can now keep any kind of widget, new visible_quick_widgets only iters on QuickWidgets
Goffi <goffi@goffi.org>
parents: 2789
diff changeset
399 """Widgets currently visible
2049
b67aece4a667 quick frontend (app): avatar filename is not requested anymore if value is empty
Goffi <goffi@goffi.org>
parents: 2042
diff changeset
400
2790
19ab67e28822 quick frontends: visible_widgets can now keep any kind of widget, new visible_quick_widgets only iters on QuickWidgets
Goffi <goffi@goffi.org>
parents: 2789
diff changeset
401 This must be implemented by frontend
19ab67e28822 quick frontends: visible_widgets can now keep any kind of widget, new visible_quick_widgets only iters on QuickWidgets
Goffi <goffi@goffi.org>
parents: 2789
diff changeset
402 @return (iter[object]): iterable on visible widgets
19ab67e28822 quick frontends: visible_widgets can now keep any kind of widget, new visible_quick_widgets only iters on QuickWidgets
Goffi <goffi@goffi.org>
parents: 2789
diff changeset
403 widgets can be QuickWidgets or not
2049
b67aece4a667 quick frontend (app): avatar filename is not requested anymore if value is empty
Goffi <goffi@goffi.org>
parents: 2042
diff changeset
404 """
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
405 raise NotImplementedError
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
406
2790
19ab67e28822 quick frontends: visible_widgets can now keep any kind of widget, new visible_quick_widgets only iters on QuickWidgets
Goffi <goffi@goffi.org>
parents: 2789
diff changeset
407 @property
19ab67e28822 quick frontends: visible_widgets can now keep any kind of widget, new visible_quick_widgets only iters on QuickWidgets
Goffi <goffi@goffi.org>
parents: 2789
diff changeset
408 def visible_quick_widgets(self):
19ab67e28822 quick frontends: visible_widgets can now keep any kind of widget, new visible_quick_widgets only iters on QuickWidgets
Goffi <goffi@goffi.org>
parents: 2789
diff changeset
409 """QuickWidgets currently visible
19ab67e28822 quick frontends: visible_widgets can now keep any kind of widget, new visible_quick_widgets only iters on QuickWidgets
Goffi <goffi@goffi.org>
parents: 2789
diff changeset
410
19ab67e28822 quick frontends: visible_widgets can now keep any kind of widget, new visible_quick_widgets only iters on QuickWidgets
Goffi <goffi@goffi.org>
parents: 2789
diff changeset
411 This generator iterate only on QuickWidgets, discarding other kinds of
19ab67e28822 quick frontends: visible_widgets can now keep any kind of widget, new visible_quick_widgets only iters on QuickWidgets
Goffi <goffi@goffi.org>
parents: 2789
diff changeset
412 widget the frontend may have.
19ab67e28822 quick frontends: visible_widgets can now keep any kind of widget, new visible_quick_widgets only iters on QuickWidgets
Goffi <goffi@goffi.org>
parents: 2789
diff changeset
413 @return (iter[object]): iterable on visible widgets
19ab67e28822 quick frontends: visible_widgets can now keep any kind of widget, new visible_quick_widgets only iters on QuickWidgets
Goffi <goffi@goffi.org>
parents: 2789
diff changeset
414 """
19ab67e28822 quick frontends: visible_widgets can now keep any kind of widget, new visible_quick_widgets only iters on QuickWidgets
Goffi <goffi@goffi.org>
parents: 2789
diff changeset
415 for w in self.visisble_widgets:
19ab67e28822 quick frontends: visible_widgets can now keep any kind of widget, new visible_quick_widgets only iters on QuickWidgets
Goffi <goffi@goffi.org>
parents: 2789
diff changeset
416 if isinstance(w, quick_widgets.QuickWidget):
19ab67e28822 quick frontends: visible_widgets can now keep any kind of widget, new visible_quick_widgets only iters on QuickWidgets
Goffi <goffi@goffi.org>
parents: 2789
diff changeset
417 return w
19ab67e28822 quick frontends: visible_widgets can now keep any kind of widget, new visible_quick_widgets only iters on QuickWidgets
Goffi <goffi@goffi.org>
parents: 2789
diff changeset
418
3159
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3158
diff changeset
419 @property
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3158
diff changeset
420 def selected_widget(self):
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3158
diff changeset
421 """widget currently selected
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3158
diff changeset
422
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3158
diff changeset
423 This must be set by frontend using setter.
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3158
diff changeset
424 """
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3158
diff changeset
425 return self._selected_widget
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3158
diff changeset
426
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3158
diff changeset
427 @selected_widget.setter
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3158
diff changeset
428 def selected_widget(self, wid):
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3158
diff changeset
429 """Set the currently selected widget
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3158
diff changeset
430
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3158
diff changeset
431 Must be set by frontend
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3158
diff changeset
432 """
3164
9dc170635bee quick frontend(app): added listener for selected widget
Goffi <goffi@goffi.org>
parents: 3159
diff changeset
433 if self._selected_widget == wid:
9dc170635bee quick frontend(app): added listener for selected widget
Goffi <goffi@goffi.org>
parents: 3159
diff changeset
434 return
3159
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3158
diff changeset
435 self._selected_widget = wid
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3158
diff changeset
436 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
437 on_selected = wid.on_selected
3159
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3158
diff changeset
438 except AttributeError:
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3158
diff changeset
439 pass
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3158
diff changeset
440 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
441 on_selected()
3159
30e08d904208 quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected:
Goffi <goffi@goffi.org>
parents: 3158
diff changeset
442
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
443 self.call_listeners("selected", wid)
3164
9dc170635bee quick frontend(app): added listener for selected widget
Goffi <goffi@goffi.org>
parents: 3159
diff changeset
444
2845
42380a4f6433 quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents: 2829
diff changeset
445 # backend state management
42380a4f6433 quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents: 2829
diff changeset
446
42380a4f6433 quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents: 2829
diff changeset
447 @property
42380a4f6433 quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents: 2829
diff changeset
448 def sync(self):
2862
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
449 """Synchronization flag
2845
42380a4f6433 quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents: 2829
diff changeset
450
42380a4f6433 quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents: 2829
diff changeset
451 True if this frontend is synchronised with backend
42380a4f6433 quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents: 2829
diff changeset
452 """
42380a4f6433 quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents: 2829
diff changeset
453 return self._sync
42380a4f6433 quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents: 2829
diff changeset
454
42380a4f6433 quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents: 2829
diff changeset
455 @sync.setter
42380a4f6433 quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents: 2829
diff changeset
456 def sync(self, state):
42380a4f6433 quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents: 2829
diff changeset
457 """Called when backend is desynchronised or resynchronising
42380a4f6433 quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents: 2829
diff changeset
458
42380a4f6433 quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents: 2829
diff changeset
459 @param state(bool): True: if the backend is resynchronising
42380a4f6433 quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents: 2829
diff changeset
460 False when we lose synchronisation, for instance if frontend is going to sleep
42380a4f6433 quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents: 2829
diff changeset
461 or if connection has been lost and a reconnection is needed
42380a4f6433 quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents: 2829
diff changeset
462 """
42380a4f6433 quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents: 2829
diff changeset
463 if state:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
464 log.debug("we are synchronised with server")
2846
58ea675d0f05 quick frontend (app): added AUTO_RESYNC attribute in QuickApp, when set (default) the resync method is called on all widgets automatically:
Goffi <goffi@goffi.org>
parents: 2845
diff changeset
465 if self.AUTO_RESYNC:
58ea675d0f05 quick frontend (app): added AUTO_RESYNC attribute in QuickApp, when set (default) the resync method is called on all widgets automatically:
Goffi <goffi@goffi.org>
parents: 2845
diff changeset
466 # we are resynchronising all widgets
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
467 log.debug("doing a full widgets resynchronisation")
2846
58ea675d0f05 quick frontend (app): added AUTO_RESYNC attribute in QuickApp, when set (default) the resync method is called on all widgets automatically:
Goffi <goffi@goffi.org>
parents: 2845
diff changeset
468 for w in self.widgets:
58ea675d0f05 quick frontend (app): added AUTO_RESYNC attribute in QuickApp, when set (default) the resync method is called on all widgets automatically:
Goffi <goffi@goffi.org>
parents: 2845
diff changeset
469 try:
58ea675d0f05 quick frontend (app): added AUTO_RESYNC attribute in QuickApp, when set (default) the resync method is called on all widgets automatically:
Goffi <goffi@goffi.org>
parents: 2845
diff changeset
470 resync = w.resync
58ea675d0f05 quick frontend (app): added AUTO_RESYNC attribute in QuickApp, when set (default) the resync method is called on all widgets automatically:
Goffi <goffi@goffi.org>
parents: 2845
diff changeset
471 except AttributeError:
58ea675d0f05 quick frontend (app): added AUTO_RESYNC attribute in QuickApp, when set (default) the resync method is called on all widgets automatically:
Goffi <goffi@goffi.org>
parents: 2845
diff changeset
472 pass
58ea675d0f05 quick frontend (app): added AUTO_RESYNC attribute in QuickApp, when set (default) the resync method is called on all widgets automatically:
Goffi <goffi@goffi.org>
parents: 2845
diff changeset
473 else:
58ea675d0f05 quick frontend (app): added AUTO_RESYNC attribute in QuickApp, when set (default) the resync method is called on all widgets automatically:
Goffi <goffi@goffi.org>
parents: 2845
diff changeset
474 resync()
2898
fc78d53f0ffa quick frontend (app): added debug logs on sync state change + refill contact lists on resync when AUTO_RESYNC is set
Goffi <goffi@goffi.org>
parents: 2894
diff changeset
475 self.contact_lists.fill()
fc78d53f0ffa quick frontend (app): added debug logs on sync state change + refill contact lists on resync when AUTO_RESYNC is set
Goffi <goffi@goffi.org>
parents: 2894
diff changeset
476
2845
42380a4f6433 quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents: 2829
diff changeset
477 self._sync = state
42380a4f6433 quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents: 2829
diff changeset
478 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
479 log.debug("we have lost synchronisation with server")
2845
42380a4f6433 quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents: 2829
diff changeset
480 self._sync = state
2846
58ea675d0f05 quick frontend (app): added AUTO_RESYNC attribute in QuickApp, when set (default) the resync method is called on all widgets automatically:
Goffi <goffi@goffi.org>
parents: 2845
diff changeset
481 # we've lost synchronisation, all widgets must be notified
58ea675d0f05 quick frontend (app): added AUTO_RESYNC attribute in QuickApp, when set (default) the resync method is called on all widgets automatically:
Goffi <goffi@goffi.org>
parents: 2845
diff changeset
482 # note: this is always called independently of AUTO_RESYNC
2845
42380a4f6433 quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents: 2829
diff changeset
483 for w in self.widgets:
42380a4f6433 quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents: 2829
diff changeset
484 try:
42380a4f6433 quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents: 2829
diff changeset
485 w.sync = False
42380a4f6433 quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents: 2829
diff changeset
486 except AttributeError:
42380a4f6433 quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents: 2829
diff changeset
487 pass
42380a4f6433 quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents: 2829
diff changeset
488
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
489 def register_signal(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
490 self, function_name, handler=None, iface="core", with_profile=True
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
491 ):
1103
a096b8579a3c frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents: 1093
diff changeset
492 """Register a handler for a signal
a096b8579a3c frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents: 1093
diff changeset
493
1345
b26dd78de495 quick frontends: signal cache: if a signal arrives between the beginning of profile plugging, and the when the profile is actually ready, it is cached and replayed when the profile is ready.
Goffi <goffi@goffi.org>
parents: 1342
diff changeset
494 @param function_name (str): name of the signal to handle
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
495 @param handler (instancemethod): method to call when the signal arrive,
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
496 None for calling an automatically named handler (function_name + 'Handler')
1117
6053fb8a6466 quick_frontend: fixes an issue with the profile in the signal handler
souliane <souliane@mailoo.org>
parents: 1103
diff changeset
497 @param iface (str): interface of the bridge to use ('core' or 'plugin')
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
498 @param with_profile (boolean): True if the signal concerns a specific profile,
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
499 in that case the profile name has to be passed by the caller
1103
a096b8579a3c frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents: 1093
diff changeset
500 """
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
501 log.debug("registering signal {name}".format(name=function_name))
1103
a096b8579a3c frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents: 1093
diff changeset
502 if handler is None:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
503 handler = getattr(self, "{}{}".format(function_name, "_handler"))
1117
6053fb8a6466 quick_frontend: fixes an issue with the profile in the signal handler
souliane <souliane@mailoo.org>
parents: 1103
diff changeset
504 if not with_profile:
2086
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2067
diff changeset
505 self.bridge.register_signal(function_name, handler, iface)
1117
6053fb8a6466 quick_frontend: fixes an issue with the profile in the signal handler
souliane <souliane@mailoo.org>
parents: 1103
diff changeset
506 return
6053fb8a6466 quick_frontend: fixes an issue with the profile in the signal handler
souliane <souliane@mailoo.org>
parents: 1103
diff changeset
507
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
508 def signal_received(*args, **kwargs):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
509 profile = kwargs.get("profile")
1117
6053fb8a6466 quick_frontend: fixes an issue with the profile in the signal handler
souliane <souliane@mailoo.org>
parents: 1103
diff changeset
510 if profile is None:
6053fb8a6466 quick_frontend: fixes an issue with the profile in the signal handler
souliane <souliane@mailoo.org>
parents: 1103
diff changeset
511 if not args:
6053fb8a6466 quick_frontend: fixes an issue with the profile in the signal handler
souliane <souliane@mailoo.org>
parents: 1103
diff changeset
512 raise exceptions.ProfileNotSetError
6053fb8a6466 quick_frontend: fixes an issue with the profile in the signal handler
souliane <souliane@mailoo.org>
parents: 1103
diff changeset
513 profile = args[-1]
1345
b26dd78de495 quick frontends: signal cache: if a signal arrives between the beginning of profile plugging, and the when the profile is actually ready, it is cached and replayed when the profile is ready.
Goffi <goffi@goffi.org>
parents: 1342
diff changeset
514 if profile is not None:
b26dd78de495 quick frontends: signal cache: if a signal arrives between the beginning of profile plugging, and the when the profile is actually ready, it is cached and replayed when the profile is ready.
Goffi <goffi@goffi.org>
parents: 1342
diff changeset
515 if not self.check_profile(profile):
b26dd78de495 quick frontends: signal cache: if a signal arrives between the beginning of profile plugging, and the when the profile is actually ready, it is cached and replayed when the profile is ready.
Goffi <goffi@goffi.org>
parents: 1342
diff changeset
516 if profile in self.profiles:
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
517 # profile is not ready but is in self.profiles, that's mean that
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
518 # it's being connecting and we need to cache the signal
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
519 self.signals_cache.setdefault(profile, []).append(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
520 (function_name, handler, args, kwargs)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
521 )
1345
b26dd78de495 quick frontends: signal cache: if a signal arrives between the beginning of profile plugging, and the when the profile is actually ready, it is cached and replayed when the profile is ready.
Goffi <goffi@goffi.org>
parents: 1342
diff changeset
522 return # we ignore signal for profiles we don't manage
1103
a096b8579a3c frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents: 1093
diff changeset
523 handler(*args, **kwargs)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
524
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
525 self.bridge.register_signal(function_name, signal_received, iface)
1103
a096b8579a3c frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents: 1093
diff changeset
526
1331
7fa07c7b0761 quick_frontend (quick_app): addListener takes a profiles_filter argument to check the profile before calling a listener (profile must be passed right after the event type in callListeners)
souliane <souliane@mailoo.org>
parents: 1329
diff changeset
527 def addListener(self, type_, callback, profiles_filter=None):
1323
a599b6a70dc0 frontends (quick_frontend): fixes a typo (listerner --> listener)
souliane <souliane@mailoo.org>
parents: 1319
diff changeset
528 """Add a listener for an event
1319
781ee3539252 quick frontends(quick app): add a listeners (observer/observable) mechanism to call a callback when a event happen. Implemented an "avatar" event.
Goffi <goffi@goffi.org>
parents: 1318
diff changeset
529
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
530 /!\ don't forget to remove listener when not used anymore (e.g. if you delete a
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
531 widget)
1319
781ee3539252 quick frontends(quick app): add a listeners (observer/observable) mechanism to call a callback when a event happen. Implemented an "avatar" event.
Goffi <goffi@goffi.org>
parents: 1318
diff changeset
532 @param type_: type of event, can be:
3065
f8e3789912d0 quick frontend (contact list): added "contactsFilled" event
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
533 - contactsFilled: called when contact have been fully filled for a profiles
f8e3789912d0 quick frontend (contact list): added "contactsFilled" event
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
534 kwargs: profile
1319
781ee3539252 quick frontends(quick app): add a listeners (observer/observable) mechanism to call a callback when a event happen. Implemented an "avatar" event.
Goffi <goffi@goffi.org>
parents: 1318
diff changeset
535 - avatar: called when avatar data is updated
3254
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3232
diff changeset
536 args: (entity, avatar_data, profile)
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3232
diff changeset
537 - nicknames: called when nicknames data is updated
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3232
diff changeset
538 args: (entity, nicknames, profile)
1331
7fa07c7b0761 quick_frontend (quick_app): addListener takes a profiles_filter argument to check the profile before calling a listener (profile must be passed right after the event type in callListeners)
souliane <souliane@mailoo.org>
parents: 1329
diff changeset
539 - presence: called when a presence is received
1363
fa77e40eb17b quick_frontends: added "menu" listeners, which is called when a menu is added or removed.
Goffi <goffi@goffi.org>
parents: 1361
diff changeset
540 args: (entity, show, priority, statuses, profile)
3164
9dc170635bee quick frontend(app): added listener for selected widget
Goffi <goffi@goffi.org>
parents: 3159
diff changeset
541 - selected: called when a widget is selected
9dc170635bee quick frontend(app): added listener for selected widget
Goffi <goffi@goffi.org>
parents: 3159
diff changeset
542 args: (selected_widget,)
1972
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
543 - notification: called when a new notification is emited
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
544 args: (entity, notification_data, profile)
3168
1cb232c9e845 quick frontends (widgets): added widgetNew and widgetDelete listeners:
Goffi <goffi@goffi.org>
parents: 3167
diff changeset
545 - notificationsClear: called when notifications are cleared
1972
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
546 args: (entity, type_, profile)
3168
1cb232c9e845 quick frontends (widgets): added widgetNew and widgetDelete listeners:
Goffi <goffi@goffi.org>
parents: 3167
diff changeset
547 - widgetNew: a new QuickWidget has been created
1cb232c9e845 quick frontends (widgets): added widgetNew and widgetDelete listeners:
Goffi <goffi@goffi.org>
parents: 3167
diff changeset
548 args: (widget,)
1cb232c9e845 quick frontends (widgets): added widgetNew and widgetDelete listeners:
Goffi <goffi@goffi.org>
parents: 3167
diff changeset
549 - widgetDeleted: all instances of a widget with specific hash have been
1cb232c9e845 quick frontends (widgets): added widgetNew and widgetDelete listeners:
Goffi <goffi@goffi.org>
parents: 3167
diff changeset
550 deleted
1cb232c9e845 quick frontends (widgets): added widgetNew and widgetDelete listeners:
Goffi <goffi@goffi.org>
parents: 3167
diff changeset
551 args: (widget_deleted,)
1363
fa77e40eb17b quick_frontends: added "menu" listeners, which is called when a menu is added or removed.
Goffi <goffi@goffi.org>
parents: 1361
diff changeset
552 - menu: called when a menu item is added or removed
fa77e40eb17b quick_frontends: added "menu" listeners, which is called when a menu is added or removed.
Goffi <goffi@goffi.org>
parents: 1361
diff changeset
553 args: (type_, path, path_i18n, item) were values are:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
554 type_: same as in [sat.core.sat_main.SAT.import_menu]
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
555 path: same as in [sat.core.sat_main.SAT.import_menu]
1363
fa77e40eb17b quick_frontends: added "menu" listeners, which is called when a menu is added or removed.
Goffi <goffi@goffi.org>
parents: 1361
diff changeset
556 path_i18n: translated path (or None if the item is removed)
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
557 item: instance of quick_menus.MenuItemBase or None if the item is
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
558 removed
1363
fa77e40eb17b quick_frontends: added "menu" listeners, which is called when a menu is added or removed.
Goffi <goffi@goffi.org>
parents: 1361
diff changeset
559 - gotMenus: called only once when menu are available (no arg)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
560 - progress_finished: called when a progressing action has just finished
2103
b44558286bbb quick frontend (quick app): added progressFinished and progressError listeners
Goffi <goffi@goffi.org>
parents: 2102
diff changeset
561 args: (progress_id, metadata, profile)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
562 - progress_error: called when a progressing action failed
2103
b44558286bbb quick frontend (quick app): added progressFinished and progressError listeners
Goffi <goffi@goffi.org>
parents: 2102
diff changeset
563 args: (progress_id, error_msg, profile):
1319
781ee3539252 quick frontends(quick app): add a listeners (observer/observable) mechanism to call a callback when a event happen. Implemented an "avatar" event.
Goffi <goffi@goffi.org>
parents: 1318
diff changeset
564 @param callback: method to call on event
1331
7fa07c7b0761 quick_frontend (quick_app): addListener takes a profiles_filter argument to check the profile before calling a listener (profile must be passed right after the event type in callListeners)
souliane <souliane@mailoo.org>
parents: 1329
diff changeset
565 @param profiles_filter (set[unicode]): if set and not empty, the
7fa07c7b0761 quick_frontend (quick_app): addListener takes a profiles_filter argument to check the profile before calling a listener (profile must be passed right after the event type in callListeners)
souliane <souliane@mailoo.org>
parents: 1329
diff changeset
566 listener will be callable only by one of the given profiles.
1319
781ee3539252 quick frontends(quick app): add a listeners (observer/observable) mechanism to call a callback when a event happen. Implemented an "avatar" event.
Goffi <goffi@goffi.org>
parents: 1318
diff changeset
567 """
781ee3539252 quick frontends(quick app): add a listeners (observer/observable) mechanism to call a callback when a event happen. Implemented an "avatar" event.
Goffi <goffi@goffi.org>
parents: 1318
diff changeset
568 assert type_ in C.LISTENERS
3166
122075ceaa53 quick frontend (app): replaced OrderedDict by regular dict:
Goffi <goffi@goffi.org>
parents: 3164
diff changeset
569 self._listeners.setdefault(type_, {})[callback] = profiles_filter
1319
781ee3539252 quick frontends(quick app): add a listeners (observer/observable) mechanism to call a callback when a event happen. Implemented an "avatar" event.
Goffi <goffi@goffi.org>
parents: 1318
diff changeset
570
3167
d0fb79f97466 quick frontends (app): added an "ignore_missing" argument to RemoveListener:
Goffi <goffi@goffi.org>
parents: 3166
diff changeset
571 def removeListener(self, type_, callback, ignore_missing=False):
1319
781ee3539252 quick frontends(quick app): add a listeners (observer/observable) mechanism to call a callback when a event happen. Implemented an "avatar" event.
Goffi <goffi@goffi.org>
parents: 1318
diff changeset
572 """Remove a callback from listeners
781ee3539252 quick frontends(quick app): add a listeners (observer/observable) mechanism to call a callback when a event happen. Implemented an "avatar" event.
Goffi <goffi@goffi.org>
parents: 1318
diff changeset
573
3167
d0fb79f97466 quick frontends (app): added an "ignore_missing" argument to RemoveListener:
Goffi <goffi@goffi.org>
parents: 3166
diff changeset
574 @param type_(str): same as for [addListener]
d0fb79f97466 quick frontends (app): added an "ignore_missing" argument to RemoveListener:
Goffi <goffi@goffi.org>
parents: 3166
diff changeset
575 @param callback(callable): callback to remove
d0fb79f97466 quick frontends (app): added an "ignore_missing" argument to RemoveListener:
Goffi <goffi@goffi.org>
parents: 3166
diff changeset
576 @param ignore_missing(bool): if True, don't log error if the listener doesn't
d0fb79f97466 quick frontends (app): added an "ignore_missing" argument to RemoveListener:
Goffi <goffi@goffi.org>
parents: 3166
diff changeset
577 exist
1319
781ee3539252 quick frontends(quick app): add a listeners (observer/observable) mechanism to call a callback when a event happen. Implemented an "avatar" event.
Goffi <goffi@goffi.org>
parents: 1318
diff changeset
578 """
781ee3539252 quick frontends(quick app): add a listeners (observer/observable) mechanism to call a callback when a event happen. Implemented an "avatar" event.
Goffi <goffi@goffi.org>
parents: 1318
diff changeset
579 assert type_ in C.LISTENERS
3077
ab8be8f1c92d quick frontend(app): catch exception when trying to remove a missing listener, and log it
Goffi <goffi@goffi.org>
parents: 3065
diff changeset
580 try:
ab8be8f1c92d quick frontend(app): catch exception when trying to remove a missing listener, and log it
Goffi <goffi@goffi.org>
parents: 3065
diff changeset
581 self._listeners[type_].pop(callback)
ab8be8f1c92d quick frontend(app): catch exception when trying to remove a missing listener, and log it
Goffi <goffi@goffi.org>
parents: 3065
diff changeset
582 except KeyError:
3167
d0fb79f97466 quick frontends (app): added an "ignore_missing" argument to RemoveListener:
Goffi <goffi@goffi.org>
parents: 3166
diff changeset
583 if not ignore_missing:
d0fb79f97466 quick frontends (app): added an "ignore_missing" argument to RemoveListener:
Goffi <goffi@goffi.org>
parents: 3166
diff changeset
584 log.error(
d0fb79f97466 quick frontends (app): added an "ignore_missing" argument to RemoveListener:
Goffi <goffi@goffi.org>
parents: 3166
diff changeset
585 f"Trying to remove an inexisting listener (type = {type_}): "
d0fb79f97466 quick frontends (app): added an "ignore_missing" argument to RemoveListener:
Goffi <goffi@goffi.org>
parents: 3166
diff changeset
586 f"{callback}")
1319
781ee3539252 quick frontends(quick app): add a listeners (observer/observable) mechanism to call a callback when a event happen. Implemented an "avatar" event.
Goffi <goffi@goffi.org>
parents: 1318
diff changeset
587
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
588 def call_listeners(self, type_, *args, **kwargs):
1331
7fa07c7b0761 quick_frontend (quick_app): addListener takes a profiles_filter argument to check the profile before calling a listener (profile must be passed right after the event type in callListeners)
souliane <souliane@mailoo.org>
parents: 1329
diff changeset
589 """Call the methods which listen type_ event. If a profiles filter has
7fa07c7b0761 quick_frontend (quick_app): addListener takes a profiles_filter argument to check the profile before calling a listener (profile must be passed right after the event type in callListeners)
souliane <souliane@mailoo.org>
parents: 1329
diff changeset
590 been register with a listener and profile argument is not None, the
7fa07c7b0761 quick_frontend (quick_app): addListener takes a profiles_filter argument to check the profile before calling a listener (profile must be passed right after the event type in callListeners)
souliane <souliane@mailoo.org>
parents: 1329
diff changeset
591 listener will be called only if profile is in the profiles filter list.
1319
781ee3539252 quick frontends(quick app): add a listeners (observer/observable) mechanism to call a callback when a event happen. Implemented an "avatar" event.
Goffi <goffi@goffi.org>
parents: 1318
diff changeset
592
1323
a599b6a70dc0 frontends (quick_frontend): fixes a typo (listerner --> listener)
souliane <souliane@mailoo.org>
parents: 1319
diff changeset
593 @param type_: same as for [addListener]
1319
781ee3539252 quick frontends(quick app): add a listeners (observer/observable) mechanism to call a callback when a event happen. Implemented an "avatar" event.
Goffi <goffi@goffi.org>
parents: 1318
diff changeset
594 @param *args: arguments sent to callback
1338
139263ee85c5 quick frontends: fixed use of profile for listeners
Goffi <goffi@goffi.org>
parents: 1337
diff changeset
595 @param **kwargs: keywords argument, mainly used to pass "profile" when needed
1319
781ee3539252 quick frontends(quick app): add a listeners (observer/observable) mechanism to call a callback when a event happen. Implemented an "avatar" event.
Goffi <goffi@goffi.org>
parents: 1318
diff changeset
596 """
781ee3539252 quick frontends(quick app): add a listeners (observer/observable) mechanism to call a callback when a event happen. Implemented an "avatar" event.
Goffi <goffi@goffi.org>
parents: 1318
diff changeset
597 assert type_ in C.LISTENERS
781ee3539252 quick frontends(quick app): add a listeners (observer/observable) mechanism to call a callback when a event happen. Implemented an "avatar" event.
Goffi <goffi@goffi.org>
parents: 1318
diff changeset
598 try:
781ee3539252 quick frontends(quick app): add a listeners (observer/observable) mechanism to call a callback when a event happen. Implemented an "avatar" event.
Goffi <goffi@goffi.org>
parents: 1318
diff changeset
599 listeners = self._listeners[type_]
781ee3539252 quick frontends(quick app): add a listeners (observer/observable) mechanism to call a callback when a event happen. Implemented an "avatar" event.
Goffi <goffi@goffi.org>
parents: 1318
diff changeset
600 except KeyError:
781ee3539252 quick frontends(quick app): add a listeners (observer/observable) mechanism to call a callback when a event happen. Implemented an "avatar" event.
Goffi <goffi@goffi.org>
parents: 1318
diff changeset
601 pass
781ee3539252 quick frontends(quick app): add a listeners (observer/observable) mechanism to call a callback when a event happen. Implemented an "avatar" event.
Goffi <goffi@goffi.org>
parents: 1318
diff changeset
602 else:
1338
139263ee85c5 quick frontends: fixed use of profile for listeners
Goffi <goffi@goffi.org>
parents: 1337
diff changeset
603 profile = kwargs.get("profile")
3193
65d89a339dd3 quick frontend (app): avoid crash when a listener is removed while being called
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
604 for listener, profiles_filter in list(listeners.items()):
1331
7fa07c7b0761 quick_frontend (quick_app): addListener takes a profiles_filter argument to check the profile before calling a listener (profile must be passed right after the event type in callListeners)
souliane <souliane@mailoo.org>
parents: 1329
diff changeset
605 if profile is None or not profiles_filter or profile in profiles_filter:
1339
18cd46a264e9 quick frontends, primitivus: fixed listener calls (kwargs where forgotten) + fixed presence listener + renamed updatePresence to onPresenceUpdate for consistency with oter listeners
Goffi <goffi@goffi.org>
parents: 1338
diff changeset
606 listener(*args, **kwargs)
1319
781ee3539252 quick frontends(quick app): add a listeners (observer/observable) mechanism to call a callback when a event happen. Implemented an "avatar" event.
Goffi <goffi@goffi.org>
parents: 1318
diff changeset
607
125
8d611eb9ae48 primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents: 124
diff changeset
608 def check_profile(self, profile):
1345
b26dd78de495 quick frontends: signal cache: if a signal arrives between the beginning of profile plugging, and the when the profile is actually ready, it is cached and replayed when the profile is ready.
Goffi <goffi@goffi.org>
parents: 1342
diff changeset
609 """Tell if the profile is currently followed by the application, and ready"""
b26dd78de495 quick frontends: signal cache: if a signal arrives between the beginning of profile plugging, and the when the profile is actually ready, it is cached and replayed when the profile is ready.
Goffi <goffi@goffi.org>
parents: 1342
diff changeset
610 return profile in self.ready_profiles
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
611
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
612 def post_init(self, profile_manager):
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
613 """Must be called after initialization is done, do all automatic task
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
614
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
615 (auto plug profile)
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
616 @param profile_manager: instance of a subclass of
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
617 Quick_frontend.QuickProfileManager
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
618 """
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
619 if self.options and self.options.profile:
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
620 profile_manager.autoconnect([self.options.profile])
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 117
diff changeset
621
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
622 def profile_plugged(self, profile):
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
623 """Method called when the profile is fully plugged
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
624
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
625 This will launch frontend specific workflow
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
626
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
627 /!\ if you override the method and don't call the parent, be sure to add the
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
628 profile to ready_profiles ! if you don't, all signals will stay in cache
1345
b26dd78de495 quick frontends: signal cache: if a signal arrives between the beginning of profile plugging, and the when the profile is actually ready, it is cached and replayed when the profile is ready.
Goffi <goffi@goffi.org>
parents: 1342
diff changeset
629
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
630 @param profile(unicode): %(doc_profile)s
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
631 """
1939
e68483c5a999 quick app (contact list): when a new profile is plugged, updates are locked until the end of the process, this avoid many useless refreshes
Goffi <goffi@goffi.org>
parents: 1938
diff changeset
632 self._plugs_in_progress.remove(profile)
1345
b26dd78de495 quick frontends: signal cache: if a signal arrives between the beginning of profile plugging, and the when the profile is actually ready, it is cached and replayed when the profile is ready.
Goffi <goffi@goffi.org>
parents: 1342
diff changeset
633 self.ready_profiles.add(profile)
b26dd78de495 quick frontends: signal cache: if a signal arrives between the beginning of profile plugging, and the when the profile is actually ready, it is cached and replayed when the profile is ready.
Goffi <goffi@goffi.org>
parents: 1342
diff changeset
634
b26dd78de495 quick frontends: signal cache: if a signal arrives between the beginning of profile plugging, and the when the profile is actually ready, it is cached and replayed when the profile is ready.
Goffi <goffi@goffi.org>
parents: 1342
diff changeset
635 # profile is ready, we can call send signals that where is cache
b26dd78de495 quick frontends: signal cache: if a signal arrives between the beginning of profile plugging, and the when the profile is actually ready, it is cached and replayed when the profile is ready.
Goffi <goffi@goffi.org>
parents: 1342
diff changeset
636 cached_signals = self.signals_cache.pop(profile, [])
b26dd78de495 quick frontends: signal cache: if a signal arrives between the beginning of profile plugging, and the when the profile is actually ready, it is cached and replayed when the profile is ready.
Goffi <goffi@goffi.org>
parents: 1342
diff changeset
637 for function_name, handler, args, kwargs in cached_signals:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
638 log.debug(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
639 "Calling cached signal [%s] with args %s and kwargs %s"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
640 % (function_name, args, kwargs)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
641 )
1393
50d5d6325f62 quick_frontend, primitivus: various fixes (MUC and cached signals):
souliane <souliane@mailoo.org>
parents: 1391
diff changeset
642 handler(*args, **kwargs)
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
643
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
644 self.call_listeners("profile_plugged", profile=profile)
1939
e68483c5a999 quick app (contact list): when a new profile is plugged, updates are locked until the end of the process, this avoid many useless refreshes
Goffi <goffi@goffi.org>
parents: 1938
diff changeset
645 if not self._plugs_in_progress:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
646 self.contact_lists.lock_update(False)
1348
a39d2db03c80 frontends: add listeners 'profilePlugged', 'disconnect' and 'gotMenus' (the last one to be removed when the menus are refactored to quick_app)
souliane <souliane@mailoo.org>
parents: 1347
diff changeset
647
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
648 def profile_connected(self, profile):
3204
fc2bea41e402 quick frontend(app): new `QuickApp.profileConnected` method
Goffi <goffi@goffi.org>
parents: 3193
diff changeset
649 """Called when a plugged profile is connected
fc2bea41e402 quick frontend(app): new `QuickApp.profileConnected` method
Goffi <goffi@goffi.org>
parents: 3193
diff changeset
650
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
651 it is called independently of profile_plugged (may be called before or after
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
652 profile_plugged)
3204
fc2bea41e402 quick frontend(app): new `QuickApp.profileConnected` method
Goffi <goffi@goffi.org>
parents: 3193
diff changeset
653 """
fc2bea41e402 quick frontend(app): new `QuickApp.profileConnected` method
Goffi <goffi@goffi.org>
parents: 3193
diff changeset
654 pass
fc2bea41e402 quick frontend(app): new `QuickApp.profileConnected` method
Goffi <goffi@goffi.org>
parents: 3193
diff changeset
655
2142
be96beb7ca14 core, bridge, frontends: renamed asyncConnect to connect, and added options parameters (not used yet)
Goffi <goffi@goffi.org>
parents: 2135
diff changeset
656 def connect(self, profile, callback=None, errback=None):
1060
aa15453ec54d core (xmpp), stdui (profile_manager), bridge, frontends: raise an exception if the XMPP connection failed instead of sending a signal
souliane <souliane@mailoo.org>
parents: 1058
diff changeset
657 if not callback:
2765
378188abe941 misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents: 2685
diff changeset
658 callback = lambda __: None
1060
aa15453ec54d core (xmpp), stdui (profile_manager), bridge, frontends: raise an exception if the XMPP connection failed instead of sending a signal
souliane <souliane@mailoo.org>
parents: 1058
diff changeset
659 if not errback:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
660
1060
aa15453ec54d core (xmpp), stdui (profile_manager), bridge, frontends: raise an exception if the XMPP connection failed instead of sending a signal
souliane <souliane@mailoo.org>
parents: 1058
diff changeset
661 def errback(failure):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
662 log.error(_("Can't connect profile [%s]") % failure)
2089
0931b5a6213c core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
663 try:
0931b5a6213c core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
664 module = failure.module
0931b5a6213c core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
665 except AttributeError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
666 module = ""
2089
0931b5a6213c core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
667 try:
0931b5a6213c core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
668 message = failure.message
0931b5a6213c core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
669 except AttributeError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
670 message = "error"
2089
0931b5a6213c core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
671 try:
0931b5a6213c core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
672 fullname = failure.fullname
0931b5a6213c core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
673 except AttributeError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
674 fullname = "error"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
675 if (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
676 module.startswith("twisted.words.protocols.jabber")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
677 and failure.condition == "not-authorized"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
678 ):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
679 self.action_launch(C.CHANGE_XMPP_PASSWD_ID, {}, profile=profile)
1074
a47995155e55 frontends (quick_frontend): fixes the handling of asyncConnect failure
souliane <souliane@mailoo.org>
parents: 1063
diff changeset
680 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
681 self.show_dialog(message, fullname, "error")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
682
2142
be96beb7ca14 core, bridge, frontends: renamed asyncConnect to connect, and added options parameters (not used yet)
Goffi <goffi@goffi.org>
parents: 2135
diff changeset
683 self.bridge.connect(profile, callback=callback, errback=errback)
1060
aa15453ec54d core (xmpp), stdui (profile_manager), bridge, frontends: raise an exception if the XMPP connection failed instead of sending a signal
souliane <souliane@mailoo.org>
parents: 1058
diff changeset
684
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
685 def plug_profiles(self, profiles):
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
686 """Tell application which profiles must be used
0
goffi@necton2
parents:
diff changeset
687
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
688 @param profiles: list of valid profile names
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
689 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
690 self.contact_lists.lock_update()
1939
e68483c5a999 quick app (contact list): when a new profile is plugged, updates are locked until the end of the process, this avoid many useless refreshes
Goffi <goffi@goffi.org>
parents: 1938
diff changeset
691 self._plugs_in_progress.update(profiles)
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
692 self.plugging_profiles()
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
693 for profile in profiles:
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
694 self.profiles.plug(profile)
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
695
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
696 def plugging_profiles(self):
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
697 """Method to subclass to manage frontend specific things to do
0
goffi@necton2
parents:
diff changeset
698
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
699 will be called when profiles are choosen and are to be plugged soon
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
700 """
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1265
diff changeset
701 pass
542
3eeb6c865e4d frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents: 538
diff changeset
702
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
703 def unplug_profile(self, profile):
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
704 """Tell the application to not follow anymore the profile"""
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
705 if not profile in self.profiles:
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
706 raise ValueError("The profile [{}] is not plugged".format(profile))
1332
0f92b6a150ff quick_frontend, primitivus: use a listener to update the contact list when receiving a presence
souliane <souliane@mailoo.org>
parents: 1331
diff changeset
707 self.profiles.unplug(profile)
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
708
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
709 def clear_profile(self):
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
710 self.profiles.clear()
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
711
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
712 def new_widget(self, widget):
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
713 raise NotImplementedError
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
714
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2126
diff changeset
715 # bridge signals hanlers
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2126
diff changeset
716
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
717 def connected_handler(self, jid_s, profile):
1435
7590bbf44eed bridge, quick_frontend: the JID that is assigned by the server can differ from the one we asked for (resource)
souliane <souliane@mailoo.org>
parents: 1429
diff changeset
718 """Called when the connection is made.
7590bbf44eed bridge, quick_frontend: the JID that is assigned by the server can differ from the one we asked for (resource)
souliane <souliane@mailoo.org>
parents: 1429
diff changeset
719
7590bbf44eed bridge, quick_frontend: the JID that is assigned by the server can differ from the one we asked for (resource)
souliane <souliane@mailoo.org>
parents: 1429
diff changeset
720 @param jid_s (unicode): the JID that we were assigned by the server,
7590bbf44eed bridge, quick_frontend: the JID that is assigned by the server can differ from the one we asked for (resource)
souliane <souliane@mailoo.org>
parents: 1429
diff changeset
721 as the resource might differ from the JID we asked for.
7590bbf44eed bridge, quick_frontend: the JID that is assigned by the server can differ from the one we asked for (resource)
souliane <souliane@mailoo.org>
parents: 1429
diff changeset
722 """
1009
d1084f7e56a5 quick_frontend: use of new logging system
Goffi <goffi@goffi.org>
parents: 955
diff changeset
723 log.debug(_("Connected"))
1435
7590bbf44eed bridge, quick_frontend: the JID that is assigned by the server can differ from the one we asked for (resource)
souliane <souliane@mailoo.org>
parents: 1429
diff changeset
724 self.profiles[profile].whoami = jid.JID(jid_s)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
725 self.set_presence_status(profile=profile)
2899
5b0f897689b7 quick frontend (app): (un)set sync state on (dis)connect:
Goffi <goffi@goffi.org>
parents: 2898
diff changeset
726 # FIXME: fill() is already called for all profiles when doing self.sync = True
5b0f897689b7 quick frontend (app): (un)set sync state on (dis)connect:
Goffi <goffi@goffi.org>
parents: 2898
diff changeset
727 # a per-profile fill() should be done once, see below note
1418
6adf1b0be609 quick_frontend: ask for the roster in connectedHandler instead of in ProfileManager, because we need it also when reconnecting after a disconnection whithout restarting the frontend
souliane <souliane@mailoo.org>
parents: 1417
diff changeset
728 self.contact_lists[profile].fill()
2899
5b0f897689b7 quick frontend (app): (un)set sync state on (dis)connect:
Goffi <goffi@goffi.org>
parents: 2898
diff changeset
729 # if we were already displaying widgets, they must be resynchronized
5b0f897689b7 quick frontend (app): (un)set sync state on (dis)connect:
Goffi <goffi@goffi.org>
parents: 2898
diff changeset
730 # FIXME: self.sync is for all profiles
5b0f897689b7 quick frontend (app): (un)set sync state on (dis)connect:
Goffi <goffi@goffi.org>
parents: 2898
diff changeset
731 # while (dis)connection is per-profile.
5b0f897689b7 quick frontend (app): (un)set sync state on (dis)connect:
Goffi <goffi@goffi.org>
parents: 2898
diff changeset
732 # A mechanism similar to sync should be available
5b0f897689b7 quick frontend (app): (un)set sync state on (dis)connect:
Goffi <goffi@goffi.org>
parents: 2898
diff changeset
733 # on a per-profile basis
5b0f897689b7 quick frontend (app): (un)set sync state on (dis)connect:
Goffi <goffi@goffi.org>
parents: 2898
diff changeset
734 self.sync = True
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
735 self.profile_connected(profile)
52
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
736
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
737 def disconnected_handler(self, profile):
52
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
738 """called when the connection is closed"""
1009
d1084f7e56a5 quick_frontend: use of new logging system
Goffi <goffi@goffi.org>
parents: 955
diff changeset
739 log.debug(_("Disconnected"))
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
740 self.contact_lists[profile].disconnect()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
741 # FIXME: see note on connected_handler
2899
5b0f897689b7 quick frontend (app): (un)set sync state on (dis)connect:
Goffi <goffi@goffi.org>
parents: 2898
diff changeset
742 self.sync = False
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
743 self.set_presence_status(C.PRESENCE_UNAVAILABLE, "", profile=profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
744
4041
2594e1951cf7 core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
745 def action_new_handler(self, action_data_s, id_, security_limit, profile):
2594e1951cf7 core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
746 self.action_manager(
2594e1951cf7 core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
747 data_format.deserialise(action_data_s), user_action=False, profile=profile
2594e1951cf7 core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
748 )
1468
731fbed0b9cf quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents: 1461
diff changeset
749
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
750 def contact_new_handler(self, jid_s, attributes, groups, profile):
1435
7590bbf44eed bridge, quick_frontend: the JID that is assigned by the server can differ from the one we asked for (resource)
souliane <souliane@mailoo.org>
parents: 1429
diff changeset
751 entity = jid.JID(jid_s)
1938
011eff37e21d quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
752 groups = list(groups)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
753 self.contact_lists[profile].set_contact(entity, groups, attributes, in_roster=True)
510
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 507
diff changeset
754
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
755 def message_new_handler(
3170
39d7327583e1 core: use serialised dict for `extra` in messageNew and historyGet
Goffi <goffi@goffi.org>
parents: 3168
diff changeset
756 self, uid, timestamp, from_jid_s, to_jid_s, msg, subject, type_, extra_s,
39d7327583e1 core: use serialised dict for `extra` in messageNew and historyGet
Goffi <goffi@goffi.org>
parents: 3168
diff changeset
757 profile):
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
758 from_jid = jid.JID(from_jid_s)
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
759 to_jid = jid.JID(to_jid_s)
3170
39d7327583e1 core: use serialised dict for `extra` in messageNew and historyGet
Goffi <goffi@goffi.org>
parents: 3168
diff changeset
760 extra = data_format.deserialise(extra_s)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
761 if not self.trigger.point(
2848
b9da74c9d46e quick_frontend(app): fixed use of bare jid for target when getting a new message:
Goffi <goffi@goffi.org>
parents: 2846
diff changeset
762 "messageNewTrigger", uid, timestamp, from_jid, to_jid, msg, subject, type_,
b9da74c9d46e quick_frontend(app): fixed use of bare jid for target when getting a new message:
Goffi <goffi@goffi.org>
parents: 2846
diff changeset
763 extra, profile=profile,):
1347
ba41a81d14c2 frontends (QuickApp), tools (TriggerManager): frontends can also use triggers + add those for sending and receiving a message
souliane <souliane@mailoo.org>
parents: 1345
diff changeset
764 return
ba41a81d14c2 frontends (QuickApp), tools (TriggerManager): frontends can also use triggers + add those for sending and receiving a message
souliane <souliane@mailoo.org>
parents: 1345
diff changeset
765
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
766 from_me = from_jid.bare == self.profiles[profile].whoami.bare
2848
b9da74c9d46e quick_frontend(app): fixed use of bare jid for target when getting a new message:
Goffi <goffi@goffi.org>
parents: 2846
diff changeset
767 mess_to_jid = to_jid if from_me else from_jid
b9da74c9d46e quick_frontend(app): fixed use of bare jid for target when getting a new message:
Goffi <goffi@goffi.org>
parents: 2846
diff changeset
768 target = mess_to_jid.bare
1336
2ecc07a8f91b primitivus, quick_frontends: moved newMessage signal handler to quick_frontend
Goffi <goffi@goffi.org>
parents: 1319
diff changeset
769 contact_list = self.contact_lists[profile]
2792
441b536e28ed quick frontend (chat): use right type in getOrCreateWidget on new message
Goffi <goffi@goffi.org>
parents: 2790
diff changeset
770
441b536e28ed quick frontend (chat): use right type in getOrCreateWidget on new message
Goffi <goffi@goffi.org>
parents: 2790
diff changeset
771 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
772 is_room = contact_list.is_room(target)
2792
441b536e28ed quick frontend (chat): use right type in getOrCreateWidget on new message
Goffi <goffi@goffi.org>
parents: 2790
diff changeset
773 except exceptions.NotFound:
441b536e28ed quick frontend (chat): use right type in getOrCreateWidget on new message
Goffi <goffi@goffi.org>
parents: 2790
diff changeset
774 is_room = False
441b536e28ed quick frontend (chat): use right type in getOrCreateWidget on new message
Goffi <goffi@goffi.org>
parents: 2790
diff changeset
775
441b536e28ed quick frontend (chat): use right type in getOrCreateWidget on new message
Goffi <goffi@goffi.org>
parents: 2790
diff changeset
776 if target.resource and not is_room:
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
777 # we avoid resource locking, but we must keep resource for private MUC
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
778 # messages
2848
b9da74c9d46e quick_frontend(app): fixed use of bare jid for target when getting a new message:
Goffi <goffi@goffi.org>
parents: 2846
diff changeset
779 target = target
2040
f607349a01a4 quick frontend (chat): fixed messageNew signal dispatching when several widgets are handling the target
Goffi <goffi@goffi.org>
parents: 2036
diff changeset
780 # we want to be sure to have at least one QuickChat instance
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
781 self.widgets.get_or_create_widget(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
782 quick_chat.QuickChat,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
783 target,
2792
441b536e28ed quick frontend (chat): use right type in getOrCreateWidget on new message
Goffi <goffi@goffi.org>
parents: 2790
diff changeset
784 type_ = C.CHAT_GROUP if is_room else C.CHAT_ONE2ONE,
441b536e28ed quick frontend (chat): use right type in getOrCreateWidget on new message
Goffi <goffi@goffi.org>
parents: 2790
diff changeset
785 on_new_widget = None,
441b536e28ed quick frontend (chat): use right type in getOrCreateWidget on new message
Goffi <goffi@goffi.org>
parents: 2790
diff changeset
786 profile = profile,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
787 )
510
886754295efe quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents: 507
diff changeset
788
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
789 if (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
790 not from_jid in contact_list
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
791 and from_jid.bare != self.profiles[profile].whoami.bare
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
792 ):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
793 # XXX: needed to show entities which haven't sent any
1336
2ecc07a8f91b primitivus, quick_frontends: moved newMessage signal handler to quick_frontend
Goffi <goffi@goffi.org>
parents: 1319
diff changeset
794 # presence information and which are not in roster
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
795 contact_list.set_contact(from_jid)
1336
2ecc07a8f91b primitivus, quick_frontends: moved newMessage signal handler to quick_frontend
Goffi <goffi@goffi.org>
parents: 1319
diff changeset
796
2040
f607349a01a4 quick frontend (chat): fixed messageNew signal dispatching when several widgets are handling the target
Goffi <goffi@goffi.org>
parents: 2036
diff changeset
797 # we dispatch the message in the widgets
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
798 for widget in self.widgets.get_widgets(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
799 quick_chat.QuickChat, target=target, profiles=(profile,)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
800 ):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
801 widget.message_new(
2848
b9da74c9d46e quick_frontend(app): fixed use of bare jid for target when getting a new message:
Goffi <goffi@goffi.org>
parents: 2846
diff changeset
802 uid, timestamp, from_jid, mess_to_jid, msg, subject, type_, extra, profile
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
803 )
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
804
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
805 def message_encryption_started_handler(self, destinee_jid_s, plugin_data, profile):
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
806 destinee_jid = jid.JID(destinee_jid_s)
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
807 plugin_data = data_format.deserialise(plugin_data)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
808 for widget in self.widgets.get_widgets(quick_chat.QuickChat,
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
809 target=destinee_jid.bare,
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
810 profiles=(profile,)):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
811 widget.message_encryption_started(plugin_data)
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
812
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
813 def message_encryption_stopped_handler(self, destinee_jid_s, plugin_data, profile):
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
814 destinee_jid = jid.JID(destinee_jid_s)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
815 for widget in self.widgets.get_widgets(quick_chat.QuickChat,
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
816 target=destinee_jid.bare,
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
817 profiles=(profile,)):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
818 widget.message_encryption_stopped(plugin_data)
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
819
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
820 def message_state_handler(self, uid, status, profile):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
821 for widget in self.widgets.get_widgets(quick_chat.QuickChat, profiles=(profile,)):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
822 widget.on_message_state(uid, status, profile)
2024
01aff34e8873 quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents: 2016
diff changeset
823
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
824 def message_send(self, to_jid, message, subject=None, mess_type="auto", extra=None, callback=None, errback=None, profile_key=C.PROF_KEY_NONE):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
825 if not subject and not extra and (not message or message == {'': ''}):
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
826 log.debug("Not sending empty message")
2829
649cb3fd7711 quick frontend(app): avoid sending empty messages
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
827 return
649cb3fd7711 quick frontend(app): avoid sending empty messages
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
828
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1939
diff changeset
829 if subject is None:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1939
diff changeset
830 subject = {}
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1939
diff changeset
831 if extra is None:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1939
diff changeset
832 extra = {}
776
f89173f44850 frontends: fixed sendMessage calls, sendMessage is now async so callback and errback need to be specified + redraw in PrimivitusApp.notify
Goffi <goffi@goffi.org>
parents: 771
diff changeset
833 if callback is None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
834 callback = (
2765
378188abe941 misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents: 2685
diff changeset
835 lambda __=None: None
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
836 ) # FIXME: optional argument is here because pyjamas doesn't support callback
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
837 # without arg with json proxy
776
f89173f44850 frontends: fixed sendMessage calls, sendMessage is now async so callback and errback need to be specified + redraw in PrimivitusApp.notify
Goffi <goffi@goffi.org>
parents: 771
diff changeset
838 if errback is None:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
839 errback = lambda failure: self.show_dialog(
3232
f3c99e96ac03 quick frontend (app): fixed argument order in `messageSend` default errback
Goffi <goffi@goffi.org>
parents: 3204
diff changeset
840 message=failure.message, title=failure.fullname, type="error"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
841 )
1347
ba41a81d14c2 frontends (QuickApp), tools (TriggerManager): frontends can also use triggers + add those for sending and receiving a message
souliane <souliane@mailoo.org>
parents: 1345
diff changeset
842
2829
649cb3fd7711 quick frontend(app): avoid sending empty messages
Goffi <goffi@goffi.org>
parents: 2807
diff changeset
843 if not self.trigger.point("messageSendTrigger", to_jid, message, subject, mess_type, extra, callback, errback, profile_key=profile_key):
1347
ba41a81d14c2 frontends (QuickApp), tools (TriggerManager): frontends can also use triggers + add those for sending and receiving a message
souliane <souliane@mailoo.org>
parents: 1345
diff changeset
844 return
ba41a81d14c2 frontends (QuickApp), tools (TriggerManager): frontends can also use triggers + add those for sending and receiving a message
souliane <souliane@mailoo.org>
parents: 1345
diff changeset
845
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
846 self.bridge.message_send(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
847 str(to_jid),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
848 message,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
849 subject,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
850 mess_type,
3179
84a94b385760 bridge: messageSend's extra is now serialised
Goffi <goffi@goffi.org>
parents: 3170
diff changeset
851 data_format.serialise(extra),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
852 profile_key,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
853 callback=callback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
854 errback=errback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
855 )
0
goffi@necton2
parents:
diff changeset
856
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
857 def set_presence_status(self, show="", status=None, profile=C.PROF_KEY_NONE):
737
378af36155c2 frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents: 736
diff changeset
858 raise NotImplementedError
0
goffi@necton2
parents:
diff changeset
859
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
860 def presence_update_handler(self, entity_s, show, priority, statuses, profile):
2976
49458e12e414 quick frontends (app, chat): disabled the 2 most verbose logs, as they are barely useful and make reading logs difficult.
Goffi <goffi@goffi.org>
parents: 2899
diff changeset
861 # XXX: this log is commented because it's really too verbose even for DEBUG logs
49458e12e414 quick frontends (app, chat): disabled the 2 most verbose logs, as they are barely useful and make reading logs difficult.
Goffi <goffi@goffi.org>
parents: 2899
diff changeset
862 # but it is kept here as it may still be useful for troubleshooting
49458e12e414 quick frontends (app, chat): disabled the 2 most verbose logs, as they are barely useful and make reading logs difficult.
Goffi <goffi@goffi.org>
parents: 2899
diff changeset
863 # log.debug(
49458e12e414 quick frontends (app, chat): disabled the 2 most verbose logs, as they are barely useful and make reading logs difficult.
Goffi <goffi@goffi.org>
parents: 2899
diff changeset
864 # _(
49458e12e414 quick frontends (app, chat): disabled the 2 most verbose logs, as they are barely useful and make reading logs difficult.
Goffi <goffi@goffi.org>
parents: 2899
diff changeset
865 # u"presence update for %(entity)s (show=%(show)s, priority=%(priority)s, "
49458e12e414 quick frontends (app, chat): disabled the 2 most verbose logs, as they are barely useful and make reading logs difficult.
Goffi <goffi@goffi.org>
parents: 2899
diff changeset
866 # u"statuses=%(statuses)s) [profile:%(profile)s]"
49458e12e414 quick frontends (app, chat): disabled the 2 most verbose logs, as they are barely useful and make reading logs difficult.
Goffi <goffi@goffi.org>
parents: 2899
diff changeset
867 # )
49458e12e414 quick frontends (app, chat): disabled the 2 most verbose logs, as they are barely useful and make reading logs difficult.
Goffi <goffi@goffi.org>
parents: 2899
diff changeset
868 # % {
49458e12e414 quick frontends (app, chat): disabled the 2 most verbose logs, as they are barely useful and make reading logs difficult.
Goffi <goffi@goffi.org>
parents: 2899
diff changeset
869 # "entity": entity_s,
49458e12e414 quick frontends (app, chat): disabled the 2 most verbose logs, as they are barely useful and make reading logs difficult.
Goffi <goffi@goffi.org>
parents: 2899
diff changeset
870 # C.PRESENCE_SHOW: show,
49458e12e414 quick frontends (app, chat): disabled the 2 most verbose logs, as they are barely useful and make reading logs difficult.
Goffi <goffi@goffi.org>
parents: 2899
diff changeset
871 # C.PRESENCE_PRIORITY: priority,
49458e12e414 quick frontends (app, chat): disabled the 2 most verbose logs, as they are barely useful and make reading logs difficult.
Goffi <goffi@goffi.org>
parents: 2899
diff changeset
872 # C.PRESENCE_STATUSES: statuses,
49458e12e414 quick frontends (app, chat): disabled the 2 most verbose logs, as they are barely useful and make reading logs difficult.
Goffi <goffi@goffi.org>
parents: 2899
diff changeset
873 # "profile": profile,
49458e12e414 quick frontends (app, chat): disabled the 2 most verbose logs, as they are barely useful and make reading logs difficult.
Goffi <goffi@goffi.org>
parents: 2899
diff changeset
874 # }
49458e12e414 quick frontends (app, chat): disabled the 2 most verbose logs, as they are barely useful and make reading logs difficult.
Goffi <goffi@goffi.org>
parents: 2899
diff changeset
875 # )
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
876 entity = jid.JID(entity_s)
0
goffi@necton2
parents:
diff changeset
877
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
878 if entity == self.profiles[profile].whoami:
1417
176de79c8c39 core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
879 if show == C.PRESENCE_UNAVAILABLE:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
880 self.set_presence_status(C.PRESENCE_UNAVAILABLE, "", profile=profile)
735
682933ca304c frontends: presence update in quick app:
souliane <souliane@mailoo.org>
parents: 698
diff changeset
881 else:
1417
176de79c8c39 core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
882 # FIXME: try to retrieve user language status before fallback to default
176de79c8c39 core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
883 status = statuses.get(C.PRESENCE_STATUSES_DEFAULT, None)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
884 self.set_presence_status(show, status, profile=profile)
0
goffi@necton2
parents:
diff changeset
885 return
goffi@necton2
parents:
diff changeset
886
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
887 self.call_listeners("presence", entity, show, priority, statuses, profile=profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
888
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
889 def muc_room_joined_handler(
3101
ab7e8ade848a plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents: 3077
diff changeset
890 self, room_jid_s, occupants, user_nick, subject, statuses, profile):
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 71
diff changeset
891 """Called when a MUC room is joined"""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
892 log.debug(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
893 "Room [{room_jid}] joined by {profile}, users presents:{users}".format(
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
894 room_jid=room_jid_s, profile=profile, users=list(occupants.keys())
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
895 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
896 )
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
897 room_jid = jid.JID(room_jid_s)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
898 self.contact_lists[profile].set_special(room_jid, C.CONTACT_SPECIAL_GROUP)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
899 self.widgets.get_or_create_widget(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
900 quick_chat.QuickChat,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
901 room_jid,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
902 type_=C.CHAT_GROUP,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
903 nick=user_nick,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
904 occupants=occupants,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
905 subject=subject,
3101
ab7e8ade848a plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents: 3077
diff changeset
906 statuses=statuses,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
907 profile=profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
908 )
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 71
diff changeset
909
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
910 def muc_room_left_handler(self, room_jid_s, profile):
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
911 """Called when a MUC room is left"""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
912 log.debug(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
913 "Room [%(room_jid)s] left by %(profile)s"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
914 % {"room_jid": room_jid_s, "profile": profile}
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
915 )
1351
ec43552f5f8b quick_frontend: replace last occurences of QuickApp.chat_wins with QuickApp.widgets
souliane <souliane@mailoo.org>
parents: 1348
diff changeset
916 room_jid = jid.JID(room_jid_s)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
917 chat_widget = self.widgets.get_widget(quick_chat.QuickChat, room_jid, profile)
1351
ec43552f5f8b quick_frontend: replace last occurences of QuickApp.chat_wins with QuickApp.widgets
souliane <souliane@mailoo.org>
parents: 1348
diff changeset
918 if chat_widget:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
919 self.widgets.delete_widget(
3158
6032245c927e quick frontend (app): added "explicit_close" to deleteWidget, and use it on mucRoomLeftHandler:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
920 chat_widget, all_instances=True, explicit_close=True)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
921 self.contact_lists[profile].remove_contact(room_jid)
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 71
diff changeset
922
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
923 def muc_room_user_changed_nick_handler(self, room_jid_s, old_nick, new_nick, profile):
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
924 """Called when an user joined a MUC room"""
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
925 room_jid = jid.JID(room_jid_s)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
926 chat_widget = self.widgets.get_or_create_widget(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
927 quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, profile=profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
928 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
929 chat_widget.change_user_nick(old_nick, new_nick)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
930 log.debug(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
931 "user [%(old_nick)s] is now known as [%(new_nick)s] in room [%(room_jid)s]"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
932 % {"old_nick": old_nick, "new_nick": new_nick, "room_jid": room_jid}
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
933 )
507
f98bef71a918 frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents: 504
diff changeset
934
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
935 def muc_room_new_subject_handler(self, room_jid_s, subject, profile):
76
8becde8a967c MUC: added subject management
Goffi <goffi@goffi.org>
parents: 75
diff changeset
936 """Called when subject of MUC room change"""
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
937 room_jid = jid.JID(room_jid_s)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
938 chat_widget = self.widgets.get_or_create_widget(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
939 quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, profile=profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
940 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
941 chat_widget.set_subject(subject)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
942 log.debug(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
943 "new subject for room [%(room_jid)s]: %(subject)s"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
944 % {"room_jid": room_jid, "subject": subject}
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
945 )
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
946
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
947 def chat_state_received_handler(self, from_jid_s, state, profile):
1378
3dae6964c071 quick_frontends, primitivus: move the chat states logic to quick_frontend
souliane <souliane@mailoo.org>
parents: 1377
diff changeset
948 """Called when a new chat state (XEP-0085) is received.
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
949
1378
3dae6964c071 quick_frontends, primitivus: move the chat states logic to quick_frontend
souliane <souliane@mailoo.org>
parents: 1377
diff changeset
950 @param from_jid_s (unicode): JID of a contact or C.ENTITY_ALL
3dae6964c071 quick_frontends, primitivus: move the chat states logic to quick_frontend
souliane <souliane@mailoo.org>
parents: 1377
diff changeset
951 @param state (unicode): new state
3dae6964c071 quick_frontends, primitivus: move the chat states logic to quick_frontend
souliane <souliane@mailoo.org>
parents: 1377
diff changeset
952 @param profile (unicode): current profile
907
cd02f5ef30df primitivus: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 906
diff changeset
953 """
2007
19b9d3f8a6c7 plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents: 1972
diff changeset
954 from_jid = jid.JID(from_jid_s)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
955 for widget in self.widgets.get_widgets(quick_chat.QuickChat, target=from_jid.bare,
2789
d350f4571d82 quick frontend (app): fixed filtering for chat state notifications
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
956 profiles=(profile,)):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
957 widget.on_chat_state(from_jid, state, profile)
907
cd02f5ef30df primitivus: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents: 906
diff changeset
958
2861
e9e33e05d143 quick frontend (app): fixed notifications ids
Goffi <goffi@goffi.org>
parents: 2854
diff changeset
959 def notify(self, type_, entity=None, message=None, subject=None, callback=None,
e9e33e05d143 quick frontend (app): fixed notifications ids
Goffi <goffi@goffi.org>
parents: 2854
diff changeset
960 cb_args=None, widget=None, profile=C.PROF_KEY_NONE):
1972
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
961 """Trigger an event notification
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
962
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
963 @param type_(unicode): notifation kind,
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
964 one of C.NOTIFY_* constant or any custom type specific to frontend
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
965 @param entity(jid.JID, None): entity involved in the notification
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
966 if entity is in contact list, a indicator may be added in front of it
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
967 @param message(unicode, None): message of the notification
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
968 @param subject(unicode, None): subject of the notification
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
969 @param callback(callable, None): method to call when notification is selected
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
970 @param cb_args(list, None): list of args for callback
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
971 @param widget(object, None): widget where the notification happened
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
972 """
2135
4e67d6ffea66 quick app: check type in notify
Goffi <goffi@goffi.org>
parents: 2128
diff changeset
973 assert type_ in C.NOTIFY_ALL
1972
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
974 notif_dict = self.profiles[profile].notifications
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
975 key = "" if entity is None else entity.bare
1972
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
976 type_notifs = notif_dict.setdefault(key, {}).setdefault(type_, [])
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
977 notif_data = {
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
978 "id": self._notif_id,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
979 "time": time.time(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
980 "entity": entity,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
981 "callback": callback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
982 "cb_args": cb_args,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
983 "message": message,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
984 "subject": subject,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
985 }
1972
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
986 if widget is not None:
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
987 notif_data[widget] = widget
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
988 type_notifs.append(notif_data)
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
989 self._notifications[self._notif_id] = notif_data
2861
e9e33e05d143 quick frontend (app): fixed notifications ids
Goffi <goffi@goffi.org>
parents: 2854
diff changeset
990 self._notif_id += 1
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
991 self.call_listeners("notification", entity, notif_data, profile=profile)
1972
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
992
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
993 def get_notifs(self, entity=None, type_=None, exact_jid=None, profile=C.PROF_KEY_NONE):
1972
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
994 """return notifications for given entity
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
995
2016
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
996 @param entity(jid.JID, None, C.ENTITY_ALL): jid of the entity to check
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
997 bare jid to get all notifications, full jid to filter on resource
1972
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
998 None to get general notifications
2009
90134b2e3dc4 primitivus, quick_frontends: show global notifications counter in contact_list + method to get these notifications in QuickApp
Goffi <goffi@goffi.org>
parents: 2007
diff changeset
999 C.ENTITY_ALL to get all notifications
1972
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
1000 @param type_(unicode, None): notification type to filter
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
1001 None to get all notifications
2016
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1002 @param exact_jid(bool, None): if True, only return notifications from
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1003 exact entity jid (i.e. not including other resources)
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1004 None for automatic selection (True for full jid, False else)
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1005 False to get resources notifications
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1006 False doesn't do anything if entity is not a bare jid
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1007 @return (iter[dict]): notifications
1972
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
1008 """
2016
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1009 main_notif_dict = self.profiles[profile].notifications
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1010
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1011 if entity is C.ENTITY_ALL:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
1012 selected_notifs = iter(main_notif_dict.values())
2016
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1013 exact_jid = False
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1014 else:
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1015 if entity is None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1016 key = ""
2016
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1017 exact_jid = False
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1018 else:
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1019 key = entity.bare
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1020 if exact_jid is None:
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1021 exact_jid = bool(entity.resource)
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1022 selected_notifs = (main_notif_dict.setdefault(key, {}),)
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1023
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1024 for notifs_from_select in selected_notifs:
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1025
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1026 if type_ is None:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
1027 type_notifs = iter(notifs_from_select.values())
2016
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1028 else:
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1029 type_notifs = (notifs_from_select.get(type_, []),)
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1030
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1031 for notifs in type_notifs:
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1032 for notif in notifs:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1033 if exact_jid and notif["entity"] != entity:
2016
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1034 continue
f09562b0704d quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents: 2009
diff changeset
1035 yield notif
1972
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
1036
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1037 def clear_notifs(self, entity, type_=None, profile=C.PROF_KEY_NONE):
1972
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
1038 """return notifications for given entity
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
1039
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
1040 @param entity(jid.JID, None): bare jid of the entity to check
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
1041 None to clear general notifications (but keep entities ones)
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
1042 @param type_(unicode, None): notification type to filter
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
1043 None to clear all notifications
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
1044 @return (list[dict]): list of notifications
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
1045 """
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
1046 notif_dict = self.profiles[profile].notifications
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1047 key = "" if entity is None else entity.bare
1972
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
1048 try:
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
1049 if type_ is None:
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
1050 del notif_dict[key]
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
1051 else:
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
1052 del notif_dict[key][type_]
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
1053 except KeyError:
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
1054 return
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1055 self.call_listeners("notificationsClear", entity, type_, profile=profile)
1972
02d21a589be2 quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents: 1970
diff changeset
1056
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1057 def ps_event_handler(self, category, service_s, node, event_type, data, profile):
1461
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents: 1442
diff changeset
1058 """Called when a PubSub event is received.
1352
56c14cb29e0f quick_frontend: register the 'personalEvent' signal
souliane <souliane@mailoo.org>
parents: 1351
diff changeset
1059
1461
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents: 1442
diff changeset
1060 @param category(unicode): event category (e.g. "PEP", "MICROBLOG")
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents: 1442
diff changeset
1061 @param service_s (unicode): pubsub service
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents: 1442
diff changeset
1062 @param node (unicode): pubsub node
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents: 1442
diff changeset
1063 @param event_type (unicode): event type (one of C.PUBLISH, C.RETRACT, C.DELETE)
2807
0b7ce5daee9b plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents: 2792
diff changeset
1064 @param data (serialised_dict): event data
1352
56c14cb29e0f quick_frontend: register the 'personalEvent' signal
souliane <souliane@mailoo.org>
parents: 1351
diff changeset
1065 """
2807
0b7ce5daee9b plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents: 2792
diff changeset
1066 data = data_format.deserialise(data)
1461
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents: 1442
diff changeset
1067 service_s = jid.JID(service_s)
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents: 1442
diff changeset
1068
2067
7834743705f0 quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents: 2066
diff changeset
1069 if category == C.PS_MICROBLOG and self.MB_HANDLER:
1461
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents: 1442
diff changeset
1070 if event_type == C.PS_PUBLISH:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1071 if not "content" in data:
1461
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents: 1442
diff changeset
1072 log.warning("No content found in microblog data")
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents: 1442
diff changeset
1073 return
2807
0b7ce5daee9b plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents: 2792
diff changeset
1074
0b7ce5daee9b plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents: 2792
diff changeset
1075 # FIXME: check if [] make sense (instead of None)
0b7ce5daee9b plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents: 2792
diff changeset
1076 _groups = data.get("group")
1461
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents: 1442
diff changeset
1077
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1078 for wid in self.widgets.get_widgets(quick_blog.QuickBlog):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1079 wid.add_entry_if_accepted(service_s, node, data, _groups, profile)
1461
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents: 1442
diff changeset
1080
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents: 1442
diff changeset
1081 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1082 comments_node, comments_service = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1083 data["comments_node"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1084 data["comments_service"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1085 )
1461
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents: 1442
diff changeset
1086 except KeyError:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents: 1442
diff changeset
1087 pass
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents: 1442
diff changeset
1088 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1089 self.bridge.mb_get(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1090 comments_service,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1091 comments_node,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1092 C.NO_LIMIT,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1093 [],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1094 {"subscribe": C.BOOL_TRUE},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1095 profile=profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1096 )
1461
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents: 1442
diff changeset
1097 elif event_type == C.PS_RETRACT:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1098 for wid in self.widgets.get_widgets(quick_blog.QuickBlog):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1099 wid.delete_entry_if_present(service_s, node, data["id"], profile)
1461
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents: 1442
diff changeset
1100 pass
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents: 1442
diff changeset
1101 else:
9fce331ba0fd quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents: 1442
diff changeset
1102 log.warning("Unmanaged PubSub event type {}".format(event_type))
1352
56c14cb29e0f quick_frontend: register the 'personalEvent' signal
souliane <souliane@mailoo.org>
parents: 1351
diff changeset
1103
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1104 def register_progress_cbs(self, progress_id, callback, errback):
2862
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1105 """Register progression callbacks
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1106
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1107 @param progress_id(unicode): id of the progression to check
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1108 @param callback(callable, None): method to call when progressing action
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1109 successfuly finished.
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1110 None to ignore
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1111 @param errback(callable, None): method to call when progressions action failed
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1112 None to ignore
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1113 """
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1114 callbacks = self._progress_ids.setdefault(progress_id, [])
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1115 callbacks.append((callback, errback))
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1116
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1117 def progress_started_handler(self, pid, metadata, profile):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
1118 log.info("Progress {} started".format(pid))
1636
e00f450c25fc primitivus: fixed progress panel
Goffi <goffi@goffi.org>
parents: 1633
diff changeset
1119
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1120 def progress_finished_handler(self, pid, metadata, profile):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
1121 log.info("Progress {} finished".format(pid))
2862
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1122 try:
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1123 callbacks = self._progress_ids.pop(pid)
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1124 except KeyError:
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1125 pass
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1126 else:
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1127 for callback, __ in callbacks:
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1128 if callback is not None:
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1129 callback(metadata, profile=profile)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1130 self.call_listeners("progress_finished", pid, metadata, profile=profile)
1636
e00f450c25fc primitivus: fixed progress panel
Goffi <goffi@goffi.org>
parents: 1633
diff changeset
1131
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1132 def progress_error_handler(self, pid, err_msg, profile):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
1133 log.warning("Progress {pid} error: {err_msg}".format(pid=pid, err_msg=err_msg))
2862
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1134 try:
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1135 callbacks = self._progress_ids.pop(pid)
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1136 except KeyError:
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1137 pass
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1138 else:
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1139 for __, errback in callbacks:
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1140 if errback is not None:
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1141 errback(err_msg, profile=profile)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1142 self.call_listeners("progress_error", pid, err_msg, profile=profile)
1636
e00f450c25fc primitivus: fixed progress panel
Goffi <goffi@goffi.org>
parents: 1633
diff changeset
1143
182
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 165
diff changeset
1144 def _subscribe_cb(self, answer, data):
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 165
diff changeset
1145 entity, profile = data
1326
88e40f31b17e quick_frontend (quick_app): fixes the call to a bridge method that was done with a JID instead of unicode
souliane <souliane@mailoo.org>
parents: 1325
diff changeset
1146 type_ = "subscribed" if answer else "unsubscribed"
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
1147 self.bridge.subscription(type_, str(entity.bare), profile_key=profile)
182
556c2bd7c344 Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents: 165
diff changeset
1148
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1149 def subscribe_handler(self, type, raw_jid, profile):
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
1150 """Called when a subsciption management signal is received"""
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
1151 entity = jid.JID(raw_jid)
906
1cbae66fa725 quick_app: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 811
diff changeset
1152 if type == "subscribed":
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
1153 # this is a subscription confirmation, we just have to inform user
1436
e27963c9c219 quick_frontend: add a couple of TODOs
souliane <souliane@mailoo.org>
parents: 1435
diff changeset
1154 # TODO: call self.getEntityMBlog to add the new contact blogs
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1155 self.show_dialog(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
1156 _("The contact {contact} has accepted your subscription").format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1157 contact=entity.bare
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1158 ),
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
1159 _("Subscription confirmation"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1160 )
906
1cbae66fa725 quick_app: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 811
diff changeset
1161 elif type == "unsubscribed":
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
1162 # this is a subscription refusal, we just have to inform user
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1163 self.show_dialog(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
1164 _("The contact {contact} has refused your subscription").format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1165 contact=entity.bare
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1166 ),
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
1167 _("Subscription refusal"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1168 "error",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1169 )
906
1cbae66fa725 quick_app: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 811
diff changeset
1170 elif type == "subscribe":
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
1171 # this is a subscriptionn request, we have to ask for user confirmation
1436
e27963c9c219 quick_frontend: add a couple of TODOs
souliane <souliane@mailoo.org>
parents: 1435
diff changeset
1172 # TODO: use sat.stdui.ui_contact_list to display the groups selector
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1173 self.show_dialog(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1174 _(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
1175 "The contact {contact} wants to subscribe to your presence"
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
1176 ".\nDo you accept ?"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1177 ).format(contact=entity.bare),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1178 _("Subscription confirmation"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1179 "yes/no",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1180 answer_cb=self._subscribe_cb,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1181 answer_data=(entity, profile),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1182 )
0
goffi@necton2
parents:
diff changeset
1183
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1184 def _debug_handler(self, action, parameters, profile):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
1185 if action == "widgets_dump":
2854
eb9fa72eb62b core: added a "_debug" signal:
Goffi <goffi@goffi.org>
parents: 2848
diff changeset
1186 from pprint import pformat
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
1187 log.info("Widgets dump:\n{data}".format(data=pformat(self.widgets._widgets)))
2854
eb9fa72eb62b core: added a "_debug" signal:
Goffi <goffi@goffi.org>
parents: 2848
diff changeset
1188 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
1189 log.warning("Unknown debug action: {action}".format(action=action))
2854
eb9fa72eb62b core: added a "_debug" signal:
Goffi <goffi@goffi.org>
parents: 2848
diff changeset
1190
eb9fa72eb62b core: added a "_debug" signal:
Goffi <goffi@goffi.org>
parents: 2848
diff changeset
1191
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1192 def show_dialog(self, message, title, type="info", answer_cb=None, answer_data=None):
2618
fe9888d3fcb6 quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents: 2590
diff changeset
1193 """Show a dialog to user
fe9888d3fcb6 quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents: 2590
diff changeset
1194
fe9888d3fcb6 quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents: 2590
diff changeset
1195 Frontends must override this method
fe9888d3fcb6 quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents: 2590
diff changeset
1196 @param message(unicode): body of the dialog
fe9888d3fcb6 quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents: 2590
diff changeset
1197 @param title(unicode): title of the dialog
fe9888d3fcb6 quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents: 2590
diff changeset
1198 @param type(unicode): one of:
fe9888d3fcb6 quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents: 2590
diff changeset
1199 - "info": information dialog (callbacks not used)
fe9888d3fcb6 quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents: 2590
diff changeset
1200 - "warning": important information to notice (callbacks not used)
fe9888d3fcb6 quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents: 2590
diff changeset
1201 - "error": something went wrong (callbacks not used)
fe9888d3fcb6 quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents: 2590
diff changeset
1202 - "yes/no": a dialog with 2 choices (yes and no)
fe9888d3fcb6 quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents: 2590
diff changeset
1203 @param answer_cb(callable): method to call on answer.
fe9888d3fcb6 quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents: 2590
diff changeset
1204 Arguments depend on dialog type:
fe9888d3fcb6 quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents: 2590
diff changeset
1205 - "yes/no": argument is a boolean (True for yes)
fe9888d3fcb6 quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents: 2590
diff changeset
1206 @param answer_data(object): data to link on callback
fe9888d3fcb6 quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents: 2590
diff changeset
1207 """
fe9888d3fcb6 quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents: 2590
diff changeset
1208 # FIXME: misnamed method + types are not well chosen. Need to be rethought
0
goffi@necton2
parents:
diff changeset
1209 raise NotImplementedError
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
1210
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1211 def show_alert(self, message):
2618
fe9888d3fcb6 quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents: 2590
diff changeset
1212 # FIXME: doesn't seems used anymore, to remove?
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1213 pass # FIXME
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 585
diff changeset
1214
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1215 def dialog_failure(self, failure):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
1216 log.warning("Failure: {}".format(failure))
1468
731fbed0b9cf quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents: 1461
diff changeset
1217
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1218 def progress_id_handler(self, progress_id, profile):
1633
2071d5cec5d6 quick frontend: added progressIdHandler to managed progress id on action result + ignore meta_* action results
Goffi <goffi@goffi.org>
parents: 1599
diff changeset
1219 """Callback used when an action result in a progress id"""
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
1220 log.info("Progress ID received: {}".format(progress_id))
1633
2071d5cec5d6 quick frontend: added progressIdHandler to managed progress id on action result + ignore meta_* action results
Goffi <goffi@goffi.org>
parents: 1599
diff changeset
1221
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1222 def is_hidden(self):
1787
d678b723460b quick_frontend, primitivus: mechanism to signal a new message reception when the window is hidden (even if the message is actually displayed):
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
1223 """Tells if the frontend window is hidden.
1442
6ce18c4e5708 quick_frontend: display over whole alerts counter
souliane <souliane@mailoo.org>
parents: 1436
diff changeset
1224
1787
d678b723460b quick_frontend, primitivus: mechanism to signal a new message reception when the window is hidden (even if the message is actually displayed):
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
1225 @return bool
d678b723460b quick_frontend, primitivus: mechanism to signal a new message reception when the window is hidden (even if the message is actually displayed):
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
1226 """
d678b723460b quick_frontend, primitivus: mechanism to signal a new message reception when the window is hidden (even if the message is actually displayed):
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
1227 raise NotImplementedError
d678b723460b quick_frontend, primitivus: mechanism to signal a new message reception when the window is hidden (even if the message is actually displayed):
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
1228
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1229 def param_update_handler(self, name, value, namespace, profile):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1230 log.debug(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
1231 _("param update: [%(namespace)s] %(name)s = %(value)s")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1232 % {"namespace": namespace, "name": name, "value": value}
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1233 )
906
1cbae66fa725 quick_app: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 811
diff changeset
1234 if (namespace, name) == ("Connection", "JabberID"):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
1235 log.debug(_("Changing JID to %s") % value)
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
1236 self.profiles[profile].whoami = jid.JID(value)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1237 elif (namespace, name) == ("General", C.SHOW_OFFLINE_CONTACTS):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1238 self.contact_lists[profile].show_offline_contacts(C.bool(value))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1239 elif (namespace, name) == ("General", C.SHOW_EMPTY_GROUPS):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1240 self.contact_lists[profile].show_empty_groups(C.bool(value))
0
goffi@necton2
parents:
diff changeset
1241
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1242 def contact_deleted_handler(self, jid_s, profile):
1325
49f967fc87aa core, quick_frontends: fixes one typo and a variable naming issue
souliane <souliane@mailoo.org>
parents: 1323
diff changeset
1243 target = jid.JID(jid_s)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1244 self.contact_lists[profile].remove_contact(target)
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
1245
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1246 def entity_data_updated_handler(self, entity_s, key, value_raw, profile):
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
1247 entity = jid.JID(entity_s)
3254
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3232
diff changeset
1248 value = data_format.deserialise(value_raw, type_check=None)
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3232
diff changeset
1249 if key == "nicknames":
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3232
diff changeset
1250 assert isinstance(value, list) or value is None
1265
e3a9ea76de35 quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents: 1241
diff changeset
1251 if entity in self.contact_lists[profile]:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1252 self.contact_lists[profile].set_cache(entity, "nicknames", value)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1253 self.call_listeners("nicknames", entity, value, profile=profile)
2123
c42aab22c2c0 plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents: 2103
diff changeset
1254 elif key == "avatar" and self.AVATARS_HANDLER:
3254
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3232
diff changeset
1255 assert isinstance(value, dict) or value is None
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1256 self.contact_lists[profile].set_cache(entity, "avatar", value)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1257 self.call_listeners("avatar", entity, value, profile=profile)
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
1258
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1259 def action_manager(self, action_data, callback=None, ui_show_cb=None, user_action=True,
2862
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1260 progress_cb=None, progress_eb=None, profile=C.PROF_KEY_NONE):
1930
70ce9421c4d3 quick frontend (QuickApp): added ui_show_cb in actionManager, so frontend can handle the display of the XMLUI itself
Goffi <goffi@goffi.org>
parents: 1787
diff changeset
1261 """Handle backend action
70ce9421c4d3 quick frontend (QuickApp): added ui_show_cb in actionManager, so frontend can handle the display of the XMLUI itself
Goffi <goffi@goffi.org>
parents: 1787
diff changeset
1262
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1263 @param action_data(dict): action dict as sent by action_launch or returned by an
2664
e35a265ec174 quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents: 2626
diff changeset
1264 UI action
1930
70ce9421c4d3 quick frontend (QuickApp): added ui_show_cb in actionManager, so frontend can handle the display of the XMLUI itself
Goffi <goffi@goffi.org>
parents: 1787
diff changeset
1265 @param callback(None, callback): if not None, callback to use on XMLUI answer
70ce9421c4d3 quick frontend (QuickApp): added ui_show_cb in actionManager, so frontend can handle the display of the XMLUI itself
Goffi <goffi@goffi.org>
parents: 1787
diff changeset
1266 @param ui_show_cb(None, callback): if not None, method to call to show the XMLUI
2036
db3bbbd745e4 frontends (xmlui): added a user_action attribute:
Goffi <goffi@goffi.org>
parents: 2034
diff changeset
1267 @param user_action(bool): if True, the action is a result of a user interaction
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1268 else the action come from backend direclty (i.e. action_new).
2862
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1269 This is useful to know if the frontend can display a popup immediately (if
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1270 True) or if it should add it to a queue that the user can activate later.
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1271 @param progress_cb(None, callable): method to call when progression is finished.
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1272 Only make sense if a progress is expected in this action
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1273 @param progress_eb(None, callable): method to call when something went wrong
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1274 during progression.
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1275 Only make sense if a progress is expected in this action
1930
70ce9421c4d3 quick frontend (QuickApp): added ui_show_cb in actionManager, so frontend can handle the display of the XMLUI itself
Goffi <goffi@goffi.org>
parents: 1787
diff changeset
1276 """
1489
039d96e131be frontends: callback are now always used in QuickApp launchAction (before it was only used if validated is present):
Goffi <goffi@goffi.org>
parents: 1481
diff changeset
1277 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1278 xmlui = action_data.pop("xmlui")
1489
039d96e131be frontends: callback are now always used in QuickApp launchAction (before it was only used if validated is present):
Goffi <goffi@goffi.org>
parents: 1481
diff changeset
1279 except KeyError:
039d96e131be frontends: callback are now always used in QuickApp launchAction (before it was only used if validated is present):
Goffi <goffi@goffi.org>
parents: 1481
diff changeset
1280 pass
039d96e131be frontends: callback are now always used in QuickApp launchAction (before it was only used if validated is present):
Goffi <goffi@goffi.org>
parents: 1481
diff changeset
1281 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1282 ui = self.xmlui.create(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1283 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1284 xml_data=xmlui,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1285 flags=("FROM_BACKEND",) if not user_action else None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1286 callback=callback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1287 profile=profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1288 )
1930
70ce9421c4d3 quick frontend (QuickApp): added ui_show_cb in actionManager, so frontend can handle the display of the XMLUI itself
Goffi <goffi@goffi.org>
parents: 1787
diff changeset
1289 if ui_show_cb is None:
70ce9421c4d3 quick frontend (QuickApp): added ui_show_cb in actionManager, so frontend can handle the display of the XMLUI itself
Goffi <goffi@goffi.org>
parents: 1787
diff changeset
1290 ui.show()
70ce9421c4d3 quick frontend (QuickApp): added ui_show_cb in actionManager, so frontend can handle the display of the XMLUI itself
Goffi <goffi@goffi.org>
parents: 1787
diff changeset
1291 else:
70ce9421c4d3 quick frontend (QuickApp): added ui_show_cb in actionManager, so frontend can handle the display of the XMLUI itself
Goffi <goffi@goffi.org>
parents: 1787
diff changeset
1292 ui_show_cb(ui)
1633
2071d5cec5d6 quick frontend: added progressIdHandler to managed progress id on action result + ignore meta_* action results
Goffi <goffi@goffi.org>
parents: 1599
diff changeset
1293
2071d5cec5d6 quick frontend: added progressIdHandler to managed progress id on action result + ignore meta_* action results
Goffi <goffi@goffi.org>
parents: 1599
diff changeset
1294 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1295 progress_id = action_data.pop("progress")
1633
2071d5cec5d6 quick frontend: added progressIdHandler to managed progress id on action result + ignore meta_* action results
Goffi <goffi@goffi.org>
parents: 1599
diff changeset
1296 except KeyError:
2071d5cec5d6 quick frontend: added progressIdHandler to managed progress id on action result + ignore meta_* action results
Goffi <goffi@goffi.org>
parents: 1599
diff changeset
1297 pass
2071d5cec5d6 quick frontend: added progressIdHandler to managed progress id on action result + ignore meta_* action results
Goffi <goffi@goffi.org>
parents: 1599
diff changeset
1298 else:
2862
b2e898384c25 quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents: 2861
diff changeset
1299 if progress_cb or progress_eb:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1300 self.register_progress_cbs(progress_id, progress_cb, progress_eb)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1301 self.progress_id_handler(progress_id, profile)
1633
2071d5cec5d6 quick frontend: added progressIdHandler to managed progress id on action result + ignore meta_* action results
Goffi <goffi@goffi.org>
parents: 1599
diff changeset
1302
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1303 def _action_cb(self, data, callback, callback_id, profile):
2126
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2123
diff changeset
1304 if callback is None:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1305 self.action_manager(data, profile=profile)
2126
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2123
diff changeset
1306 else:
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2123
diff changeset
1307 callback(data=data, cb_id=callback_id, profile=profile)
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2123
diff changeset
1308
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1309 def action_launch(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1310 self, callback_id, data=None, callback=None, profile=C.PROF_KEY_NONE
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1311 ):
2126
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2123
diff changeset
1312 """Launch a dynamic action
1468
731fbed0b9cf quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents: 1461
diff changeset
1313
1060
aa15453ec54d core (xmpp), stdui (profile_manager), bridge, frontends: raise an exception if the XMPP connection failed instead of sending a signal
souliane <souliane@mailoo.org>
parents: 1058
diff changeset
1314 @param callback_id: id of the action to launch
aa15453ec54d core (xmpp), stdui (profile_manager), bridge, frontends: raise an exception if the XMPP connection failed instead of sending a signal
souliane <souliane@mailoo.org>
parents: 1058
diff changeset
1315 @param data: data needed only for certain actions
1489
039d96e131be frontends: callback are now always used in QuickApp launchAction (before it was only used if validated is present):
Goffi <goffi@goffi.org>
parents: 1481
diff changeset
1316 @param callback(callable, None): will be called with the resut
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1317 if None, self.action_manager will be called
1489
039d96e131be frontends: callback are now always used in QuickApp launchAction (before it was only used if validated is present):
Goffi <goffi@goffi.org>
parents: 1481
diff changeset
1318 else the callable will be called with the following kw parameters:
039d96e131be frontends: callback are now always used in QuickApp launchAction (before it was only used if validated is present):
Goffi <goffi@goffi.org>
parents: 1481
diff changeset
1319 - data: action_data
039d96e131be frontends: callback are now always used in QuickApp launchAction (before it was only used if validated is present):
Goffi <goffi@goffi.org>
parents: 1481
diff changeset
1320 - cb_id: callback id
039d96e131be frontends: callback are now always used in QuickApp launchAction (before it was only used if validated is present):
Goffi <goffi@goffi.org>
parents: 1481
diff changeset
1321 - profile: %(doc_profile)s
1468
731fbed0b9cf quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents: 1461
diff changeset
1322 @param profile: %(doc_profile)s
1060
aa15453ec54d core (xmpp), stdui (profile_manager), bridge, frontends: raise an exception if the XMPP connection failed instead of sending a signal
souliane <souliane@mailoo.org>
parents: 1058
diff changeset
1323
aa15453ec54d core (xmpp), stdui (profile_manager), bridge, frontends: raise an exception if the XMPP connection failed instead of sending a signal
souliane <souliane@mailoo.org>
parents: 1058
diff changeset
1324 """
1468
731fbed0b9cf quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents: 1461
diff changeset
1325 if data is None:
731fbed0b9cf quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents: 1461
diff changeset
1326 data = dict()
4041
2594e1951cf7 core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1327 action_cb = lambda data: self._action_cb(
2594e1951cf7 core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1328 data_format.deserialise(data), callback, callback_id, profile
2594e1951cf7 core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1329 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1330 self.bridge.action_launch(
4041
2594e1951cf7 core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1331 callback_id, data_format.serialise(data), profile, callback=action_cb,
2594e1951cf7 core (bridge): `action_new` now use serialised dict for extra data.
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
1332 errback=self.dialog_failure
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1333 )
1468
731fbed0b9cf quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents: 1461
diff changeset
1334
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1335 def launch_menu(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1336 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1337 menu_type,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1338 path,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1339 data=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1340 callback=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1341 security_limit=C.SECURITY_LIMIT_MAX,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1342 profile=C.PROF_KEY_NONE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1343 ):
2126
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2123
diff changeset
1344 """Launch a menu manually
1580
641cfd2faefe Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents: 1513
diff changeset
1345
2126
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2123
diff changeset
1346 @param menu_type(unicode): type of the menu to launch
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2123
diff changeset
1347 @param path(iterable[unicode]): path to the menu
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2123
diff changeset
1348 @param data: data needed only for certain actions
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2123
diff changeset
1349 @param callback(callable, None): will be called with the resut
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1350 if None, self.action_manager will be called
2126
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2123
diff changeset
1351 else the callable will be called with the following kw parameters:
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2123
diff changeset
1352 - data: action_data
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2123
diff changeset
1353 - cb_id: (menu_type, path) tuple
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2123
diff changeset
1354 - profile: %(doc_profile)s
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2123
diff changeset
1355 @param profile: %(doc_profile)s
1468
731fbed0b9cf quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents: 1461
diff changeset
1356
2126
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2123
diff changeset
1357 """
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2123
diff changeset
1358 if data is None:
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2123
diff changeset
1359 data = dict()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1360 action_cb = lambda data: self._action_cb(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1361 data, callback, (menu_type, path), profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1362 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1363 self.bridge.menu_launch(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1364 menu_type,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1365 path,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1366 data,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1367 security_limit,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1368 profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1369 callback=action_cb,
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1370 errback=self.dialog_failure,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1371 )
1060
aa15453ec54d core (xmpp), stdui (profile_manager), bridge, frontends: raise an exception if the XMPP connection failed instead of sending a signal
souliane <souliane@mailoo.org>
parents: 1058
diff changeset
1372
1348
a39d2db03c80 frontends: add listeners 'profilePlugged', 'disconnect' and 'gotMenus' (the last one to be removed when the menus are refactored to quick_app)
souliane <souliane@mailoo.org>
parents: 1347
diff changeset
1373 def disconnect(self, profile):
a39d2db03c80 frontends: add listeners 'profilePlugged', 'disconnect' and 'gotMenus' (the last one to be removed when the menus are refactored to quick_app)
souliane <souliane@mailoo.org>
parents: 1347
diff changeset
1374 log.info("disconnecting")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1375 self.call_listeners("disconnect", profile=profile)
1348
a39d2db03c80 frontends: add listeners 'profilePlugged', 'disconnect' and 'gotMenus' (the last one to be removed when the menus are refactored to quick_app)
souliane <souliane@mailoo.org>
parents: 1347
diff changeset
1376 self.bridge.disconnect(profile)
a39d2db03c80 frontends: add listeners 'profilePlugged', 'disconnect' and 'gotMenus' (the last one to be removed when the menus are refactored to quick_app)
souliane <souliane@mailoo.org>
parents: 1347
diff changeset
1377
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3490
diff changeset
1378 def on_exit(self):
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 182
diff changeset
1379 """Must be called when the frontend is terminating"""
1332
0f92b6a150ff quick_frontend, primitivus: use a listener to update the contact list when receiving a presence
souliane <souliane@mailoo.org>
parents: 1331
diff changeset
1380 to_unplug = []
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 3017
diff changeset
1381 for profile, profile_manager in self.profiles.items():
2102
071423b3a413 quick frontend (quick app): fixed use of profile_manager.connected
Goffi <goffi@goffi.org>
parents: 2097
diff changeset
1382 if profile_manager.connected and profile_manager.autodisconnect:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2618
diff changeset
1383 # The user wants autodisconnection
2091
f413bfc24458 bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
1384 self.disconnect(profile)
1332
0f92b6a150ff quick_frontend, primitivus: use a listener to update the contact list when receiving a presence
souliane <souliane@mailoo.org>
parents: 1331
diff changeset
1385 to_unplug.append(profile)
0f92b6a150ff quick_frontend, primitivus: use a listener to update the contact list when receiving a presence
souliane <souliane@mailoo.org>
parents: 1331
diff changeset
1386 for profile in to_unplug:
0f92b6a150ff quick_frontend, primitivus: use a listener to update the contact list when receiving a presence
souliane <souliane@mailoo.org>
parents: 1331
diff changeset
1387 self.unplug_profile(profile)