Mercurial > libervia-backend
annotate sat_frontends/quick_frontend/quick_app.py @ 3101:ab7e8ade848a
plugin XEP-0045: added room statuses to metadata:
room statuses are now sent with other metadata on bridge signals, and saved in Room
instance. They give useful data on the room, for instance they can be used to know if a
full jid is used in this room.
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 30 Dec 2019 20:44:02 +0100 |
parents | ab8be8f1c92d |
children | 7574f795bd1e |
rev | line source |
---|---|
1934
2daf7b4c6756
use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents:
1930
diff
changeset
|
1 #!/usr/bin/env python2 |
0 | 2 # -*- coding: utf-8 -*- |
3 | |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
4 # helper class for making a SAT frontend |
2771 | 5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) |
0 | 6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
7 # 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
|
8 # 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
|
9 # 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
|
10 # (at your option) any later version. |
0 | 11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
12 # 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
|
13 # 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
|
14 # 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
|
15 # GNU Affero General Public License for more details. |
0 | 16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
17 # 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
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
0 | 19 |
1009
d1084f7e56a5
quick_frontend: use of new logging system
Goffi <goffi@goffi.org>
parents:
955
diff
changeset
|
20 from sat.core.log import getLogger |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
21 |
1009
d1084f7e56a5
quick_frontend: use of new logging system
Goffi <goffi@goffi.org>
parents:
955
diff
changeset
|
22 log = getLogger(__name__) |
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
|
23 |
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 from sat.core.i18n import _ |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
25 from sat.core import exceptions |
1374
0befb14ecf62
renamed tools.misc to tools.trigger
Goffi <goffi@goffi.org>
parents:
1365
diff
changeset
|
26 from sat.tools import trigger |
2034
3f745370a39a
quick frontend (app): fixed regression in groups handling
Goffi <goffi@goffi.org>
parents:
2031
diff
changeset
|
27 from sat.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
|
28 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
29 from sat_frontends.tools import jid |
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
|
30 from sat_frontends.quick_frontend import quick_widgets |
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
|
31 from sat_frontends.quick_frontend import quick_menus |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
32 from sat_frontends.quick_frontend import quick_blog |
1360
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1352
diff
changeset
|
33 from sat_frontends.quick_frontend import quick_chat, quick_games |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
34 from sat_frontends.quick_frontend import quick_contact_list |
1019 | 35 from sat_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
|
36 |
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
|
37 import sys |
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
|
38 from collections import OrderedDict |
1972
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
39 import time |
906
1cbae66fa725
quick_app: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
40 |
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
|
41 try: |
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
|
42 # FIXME: to be removed when an acceptable solution is here |
3028 | 43 str("") # XXX: unicode doesn't exist in pyjamas |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
44 except ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
45 TypeError, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
46 AttributeError, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
47 ): # Error raised is not the same depending on pyjsbuild options |
3028 | 48 str = str |
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
|
49 |
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
|
50 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
51 class ProfileManager(object): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
52 """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
|
53 |
2050
046449cc2bff
core, bridge, frontends: removed deprecated bridge method askConfirmation, confirmationAnswer, actionResult, actionResultExt and getWaitingConf
Goffi <goffi@goffi.org>
parents:
2049
diff
changeset
|
54 # 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
|
55 # 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
|
56 host = None |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
57 bridge = None |
2123
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2103
diff
changeset
|
58 # cache_keys_to_get = ['avatar'] |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
59 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
60 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
|
61 self.profile = profile |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
62 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
|
63 self.whoami = None |
1972
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
64 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
|
65 |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
66 @property |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
67 def autodisconnect(self): |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
68 try: |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
69 autodisconnect = self._autodisconnect |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
70 except AttributeError: |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
71 autodisconnect = False |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
72 return autodisconnect |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
73 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
74 def plug(self): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
75 """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
|
76 # first of all we create the contact lists |
eb69ec549d05
quick frontend (app): create the contact list immediatly on plug
Goffi <goffi@goffi.org>
parents:
2669
diff
changeset
|
77 self.host.contact_lists.addProfile(self.profile) |
eb69ec549d05
quick frontend (app): create the contact list immediatly on plug
Goffi <goffi@goffi.org>
parents:
2669
diff
changeset
|
78 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
79 # we get the essential params |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
80 self.bridge.asyncGetParamA( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
81 "JabberID", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
82 "Connection", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
83 profile_key=self.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
84 callback=self._plug_profile_jid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
85 errback=self._getParamError, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
86 ) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
87 |
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
|
88 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
|
89 self.whoami = jid.JID(jid_s) # resource might change after the connection |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
90 self.bridge.isConnected(self.profile, callback=self._plug_profile_isconnected) |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
91 |
2167
4b78b4c7f805
core, frontends: various fixes for Libervia:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
92 def _autodisconnectEb(self, failure_): |
4b78b4c7f805
core, frontends: various fixes for Libervia:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
93 # 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
|
94 log.warning( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
95 _("Error while trying to get autodisconnect param, ignoring: {}").format( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
96 failure_ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
97 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
98 ) |
2167
4b78b4c7f805
core, frontends: various fixes for Libervia:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
99 self._plug_profile_autodisconnect("false") |
4b78b4c7f805
core, frontends: various fixes for Libervia:
Goffi <goffi@goffi.org>
parents:
2142
diff
changeset
|
100 |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
101 def _plug_profile_isconnected(self, connected): |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
102 self.connected = connected |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
103 self.bridge.asyncGetParamA( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
104 "autodisconnect", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
105 "Connection", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
106 profile_key=self.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
107 callback=self._plug_profile_autodisconnect, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
108 errback=self._autodisconnectEb, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
109 ) |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
110 |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
111 def _plug_profile_autodisconnect(self, autodisconnect): |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
112 if C.bool(autodisconnect): |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
113 self._autodisconnect = True |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
114 self.bridge.asyncGetParamA( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
115 "autoconnect", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
116 "Connection", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
117 profile_key=self.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
118 callback=self._plug_profile_autoconnect, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
119 errback=self._getParamError, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
120 ) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
121 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
122 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
|
123 autoconnect = C.bool(value_str) |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
124 if autoconnect and not self.connected: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
125 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
|
126 self.profile, callback=lambda __: self._plug_profile_afterconnect() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
127 ) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
128 else: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
129 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
|
130 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
131 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
|
132 # 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
|
133 # we get cached data |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
134 self.connected = True |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
135 self.host.bridge.getFeatures( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
136 profile_key=self.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
137 callback=self._plug_profile_getFeaturesCb, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
138 errback=self._plug_profile_getFeaturesEb, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
139 ) |
1655
ad2ad28b8923
quick_frontend: getFeatures is called on profile plug, and saved in host.features
Goffi <goffi@goffi.org>
parents:
1636
diff
changeset
|
140 |
ad2ad28b8923
quick_frontend: getFeatures is called on profile plug, and saved in host.features
Goffi <goffi@goffi.org>
parents:
1636
diff
changeset
|
141 def _plug_profile_getFeaturesEb(self, failure): |
3028 | 142 log.error("Couldn't get features: {}".format(failure)) |
1655
ad2ad28b8923
quick_frontend: getFeatures is called on profile plug, and saved in host.features
Goffi <goffi@goffi.org>
parents:
1636
diff
changeset
|
143 self._plug_profile_getFeaturesCb({}) |
ad2ad28b8923
quick_frontend: getFeatures is called on profile plug, and saved in host.features
Goffi <goffi@goffi.org>
parents:
1636
diff
changeset
|
144 |
ad2ad28b8923
quick_frontend: getFeatures is called on profile plug, and saved in host.features
Goffi <goffi@goffi.org>
parents:
1636
diff
changeset
|
145 def _plug_profile_getFeaturesCb(self, features): |
ad2ad28b8923
quick_frontend: getFeatures is called on profile plug, and saved in host.features
Goffi <goffi@goffi.org>
parents:
1636
diff
changeset
|
146 self.host.features = features |
2123
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2103
diff
changeset
|
147 # FIXME: we don't use cached value at the moment, but keep the code for later use |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
148 # it was previously used for avatars, but as we don't get full path here, |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
149 # it's better to request later |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
150 # self.host.bridge.getEntitiesData([], ProfileManager.cache_keys_to_get, |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
151 # profile=self.profile, |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
152 # callback=self._plug_profile_gotCachedValues, |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
153 # errback=self._plug_profile_failedCachedValues) |
2123
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2103
diff
changeset
|
154 self._plug_profile_gotCachedValues({}) |
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
|
155 |
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
|
156 def _plug_profile_failedCachedValues(self, failure): |
3028 | 157 log.error("Couldn't get cached values: {}".format(failure)) |
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
|
158 self._plug_profile_gotCachedValues({}) |
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
|
159 |
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
|
160 def _plug_profile_gotCachedValues(self, cached_values): |
2685
eb69ec549d05
quick frontend (app): create the contact list immediatly on plug
Goffi <goffi@goffi.org>
parents:
2669
diff
changeset
|
161 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
|
162 # add the contact list and its listener |
3028 | 163 for entity_s, data in cached_values.items(): |
164 for key, value in data.items(): | |
2059
9dd76a5b63ba
quick app(app): call entityDataUpdateHandler on profile plug instead of setCache directly
Goffi <goffi@goffi.org>
parents:
2056
diff
changeset
|
165 self.host.entityDataUpdatedHandler(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
|
166 |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
167 if not self.connected: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
168 self.host.setPresenceStatus(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
|
169 else: |
1429
798e5e38516b
quick_frontend (quick_app): properly fixed roster loss:
Goffi <goffi@goffi.org>
parents:
1418
diff
changeset
|
170 |
798e5e38516b
quick_frontend (quick_app): properly fixed roster loss:
Goffi <goffi@goffi.org>
parents:
1418
diff
changeset
|
171 contact_list.fill() |
1417
176de79c8c39
core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
172 self.host.setPresenceStatus(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
|
173 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
174 # The waiting subscription requests |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
175 self.bridge.getWaitingSub( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
176 self.profile, callback=self._plug_profile_gotWaitingSub |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
177 ) |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
178 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
179 def _plug_profile_gotWaitingSub(self, waiting_sub): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
180 for sub in waiting_sub: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
181 self.host.subscribeHandler(waiting_sub[sub], sub, self.profile) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
182 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
183 self.bridge.mucGetRoomsJoined( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
184 self.profile, callback=self._plug_profile_gotRoomsJoined |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
185 ) |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
186 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
187 def _plug_profile_gotRoomsJoined(self, rooms_args): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
188 # 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
|
189 for room_args in rooms_args: |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
190 self.host.mucRoomJoinedHandler(*room_args, profile=self.profile) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
191 # Presence must be requested after rooms are filled |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
192 self.host.bridge.getPresenceStatuses( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
193 self.profile, callback=self._plug_profile_gotPresences |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
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 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
196 def _plug_profile_gotPresences(self, presences): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
197 def gotEntityData(data, contact): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
198 for key in ("avatar", "nick"): |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
199 if key in data: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
200 self.host.entityDataUpdatedHandler( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
201 contact, key, data[key], self.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
202 ) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
203 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
204 for contact in presences: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
205 for res in presences[contact]: |
3028 | 206 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
|
207 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
|
208 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
|
209 statuses = presences[contact][res][2] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
210 self.host.presenceUpdateHandler( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
211 jabber_id, show, priority, statuses, self.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
212 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
213 self.host.bridge.getEntityData( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
214 contact, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
215 ["avatar", "nick"], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
216 self.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
217 callback=lambda data, contact=contact: gotEntityData(data, contact), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
218 errback=lambda failure, contact=contact: log.debug( |
3028 | 219 "No cache data for {}".format(contact) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
220 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
221 ) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
222 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
223 # 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
|
224 # and we launch frontend specific method |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
225 self.host.profilePlugged(self.profile) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
226 |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
227 def _getParamError(self, failure): |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
228 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
|
229 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
230 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
231 class ProfilesManager(object): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
232 """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
|
233 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
234 def __init__(self): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
235 self._profiles = {} |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
236 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
237 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
|
238 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
|
239 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
240 def __iter__(self): |
3028 | 241 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
|
242 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
243 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
|
244 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
|
245 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
246 def __len__(self): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
247 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
|
248 |
3028 | 249 def items(self): |
250 return self._profiles.items() | |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
251 |
3028 | 252 def values(self): |
253 return self._profiles.values() | |
2590
bd9d92bc0d6c
quick frontends (app): retrieve namespaces on startup
Goffi <goffi@goffi.org>
parents:
2586
diff
changeset
|
254 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
255 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
|
256 if profile in self._profiles: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
257 raise exceptions.ConflictError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
258 "A profile of the name [{}] is already plugged".format(profile) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
259 ) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
260 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
|
261 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
|
262 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
263 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
|
264 if profile not in self._profiles: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
265 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
|
266 |
0f92b6a150ff
quick_frontend, primitivus: use a listener to update the contact list when receiving a presence
souliane <souliane@mailoo.org>
parents:
1331
diff
changeset
|
267 # 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
|
268 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
|
269 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
|
270 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
271 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
|
272 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
273 def chooseOneProfile(self): |
3028 | 274 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
|
275 |
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
|
276 |
524
0bb595eff25b
primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents:
513
diff
changeset
|
277 class QuickApp(object): |
0 | 278 """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
|
279 |
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
|
280 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
|
281 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
|
282 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
|
283 #: 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
|
284 #: 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
|
285 #: 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
|
286 AUTO_RESYNC = True |
0 | 287 |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
288 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
|
289 """Create a frontend application |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
290 |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
291 @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
|
292 @param xmlui: xmlui module |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
293 @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
|
294 arguments) |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
295 """ |
1468
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1461
diff
changeset
|
296 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
|
297 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
|
298 ProfileManager.host = self |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
299 self.profiles = ProfilesManager() |
3065
f8e3789912d0
quick frontend (contact list): added "contactsFilled" event
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
300 # 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
|
301 self._plugs_in_progress = set() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
302 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
|
303 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
|
304 # 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
|
305 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
|
306 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
|
307 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
|
308 self.options = check_options() |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
309 else: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
310 self.options = None |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
311 |
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
|
312 # widget currently selected (must be filled 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
|
313 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
|
314 |
2862
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
315 # listeners are callable watching events |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
316 self._listeners = {} # key: listener type ("avatar", "selected", etc), |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
317 # 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
|
318 |
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
|
319 # triggers |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
320 self.trigger = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
321 trigger.TriggerManager() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
322 ) # 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
|
323 |
0 | 324 ## bridge ## |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
325 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
|
326 ProfileManager.bridge = self.bridge |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
327 if connect_bridge: |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
328 self.connectBridge() |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
329 |
2862
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
330 # frontend notifications |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
331 self._notif_id = 0 |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
332 self._notifications = OrderedDict() |
2862
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
333 # watched progresses and associated callbacks |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
334 self._progress_ids = {} |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
335 # available features |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
336 # 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
|
337 self.features = None |
2862
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
338 #: map of short name to namespaces |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
339 self.ns_map = {} |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
340 #: available encryptions |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
341 self.encryption_plugins = [] |
2862
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
342 # state of synchronisation with backend |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
343 self._sync = True |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
344 |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
345 def connectBridge(self): |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
346 self.bridge.bridgeConnect(callback=self._bridgeCb, errback=self._bridgeEb) |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
347 |
2590
bd9d92bc0d6c
quick frontends (app): retrieve namespaces on startup
Goffi <goffi@goffi.org>
parents:
2586
diff
changeset
|
348 def _namespacesGetCb(self, ns_map): |
bd9d92bc0d6c
quick frontends (app): retrieve namespaces on startup
Goffi <goffi@goffi.org>
parents:
2586
diff
changeset
|
349 self.ns_map = ns_map |
bd9d92bc0d6c
quick frontends (app): retrieve namespaces on startup
Goffi <goffi@goffi.org>
parents:
2586
diff
changeset
|
350 |
bd9d92bc0d6c
quick frontends (app): retrieve namespaces on startup
Goffi <goffi@goffi.org>
parents:
2586
diff
changeset
|
351 def _namespacesGetEb(self, failure_): |
3028 | 352 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
|
353 |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
354 def _encryptionPluginsGetCb(self, plugins): |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
355 self.encryption_plugins = plugins |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
356 |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
357 def _encryptionPluginsGetEb(self, failure_): |
3028 | 358 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
|
359 |
2097
4bc408b549cd
quick_frontend(QuickApp): added onBridgeConnected method
Goffi <goffi@goffi.org>
parents:
2091
diff
changeset
|
360 def onBridgeConnected(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
361 self.bridge.namespacesGet( |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
362 callback=self._namespacesGetCb, errback=self._namespacesGetEb) |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
363 # we cache available encryption plugins, as we'll use them on earch |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
364 # new chat widget |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
365 self.bridge.encryptionPluginsGet( |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
366 callback=self._encryptionPluginsGetCb, |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
367 errback=self._encryptionPluginsGetEb) |
2097
4bc408b549cd
quick_frontend(QuickApp): added onBridgeConnected method
Goffi <goffi@goffi.org>
parents:
2091
diff
changeset
|
368 |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
369 def _bridgeCb(self): |
1103
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
370 self.registerSignal("connected") |
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
371 self.registerSignal("disconnected") |
1468
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1461
diff
changeset
|
372 self.registerSignal("actionNew") |
1103
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
373 self.registerSignal("newContact") |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1939
diff
changeset
|
374 self.registerSignal("messageNew") |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
375 if self.ENCRYPTION_HANDLERS: |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
376 self.registerSignal("messageEncryptionStarted") |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
377 self.registerSignal("messageEncryptionStopped") |
1103
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
378 self.registerSignal("presenceUpdate") |
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
379 self.registerSignal("subscribe") |
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
380 self.registerSignal("paramUpdate") |
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
381 self.registerSignal("contactDeleted") |
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
382 self.registerSignal("entityDataUpdated") |
1636 | 383 self.registerSignal("progressStarted") |
384 self.registerSignal("progressFinished") | |
385 self.registerSignal("progressError") | |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
386 self.registerSignal("mucRoomJoined", iface="plugin") |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
387 self.registerSignal("mucRoomLeft", iface="plugin") |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
388 self.registerSignal("mucRoomUserChangedNick", iface="plugin") |
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
389 self.registerSignal("mucRoomNewSubject", iface="plugin") |
1103
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
390 self.registerSignal("chatStateReceived", iface="plugin") |
2024
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2016
diff
changeset
|
391 self.registerSignal("messageState", iface="plugin") |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
392 self.registerSignal("psEvent", iface="plugin") |
2854 | 393 # useful for debugging |
394 self.registerSignal("_debug", iface="core") | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
395 |
1360
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1352
diff
changeset
|
396 # FIXME: do it dynamically |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1352
diff
changeset
|
397 quick_games.Tarot.registerSignals(self) |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1352
diff
changeset
|
398 quick_games.Quiz.registerSignals(self) |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1352
diff
changeset
|
399 quick_games.Radiocol.registerSignals(self) |
2097
4bc408b549cd
quick_frontend(QuickApp): added onBridgeConnected method
Goffi <goffi@goffi.org>
parents:
2091
diff
changeset
|
400 self.onBridgeConnected() |
1360
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1352
diff
changeset
|
401 |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
402 def _bridgeEb(self, failure): |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
403 if isinstance(failure, exceptions.BridgeExceptionNoService): |
3028 | 404 print((_("Can't connect to SàT backend, are you sure it's launched ?"))) |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
405 sys.exit(1) |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
406 elif isinstance(failure, exceptions.BridgeInitError): |
3028 | 407 print((_("Can't init bridge"))) |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
408 sys.exit(1) |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
409 else: |
3028 | 410 print((_("Error while initialising bridge: {}".format(failure)))) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
411 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
412 @property |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
413 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
|
414 """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
|
415 try: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
416 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
|
417 except (TypeError, AttributeError): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
418 return self.profiles.chooseOneProfile() |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
419 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
420 @property |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
421 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
|
422 """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
|
423 |
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
|
424 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
|
425 @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
|
426 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
|
427 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
428 raise NotImplementedError |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
429 |
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
|
430 @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
|
431 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
|
432 """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
|
433 |
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
|
434 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
|
435 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
|
436 @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
|
437 """ |
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
|
438 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
|
439 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
|
440 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
|
441 |
2845
42380a4f6433
quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents:
2829
diff
changeset
|
442 # backend state management |
42380a4f6433
quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents:
2829
diff
changeset
|
443 |
42380a4f6433
quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents:
2829
diff
changeset
|
444 @property |
42380a4f6433
quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents:
2829
diff
changeset
|
445 def sync(self): |
2862
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
446 """Synchronization flag |
2845
42380a4f6433
quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents:
2829
diff
changeset
|
447 |
42380a4f6433
quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents:
2829
diff
changeset
|
448 True if this frontend is synchronised with backend |
42380a4f6433
quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents:
2829
diff
changeset
|
449 """ |
42380a4f6433
quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents:
2829
diff
changeset
|
450 return self._sync |
42380a4f6433
quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents:
2829
diff
changeset
|
451 |
42380a4f6433
quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents:
2829
diff
changeset
|
452 @sync.setter |
42380a4f6433
quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents:
2829
diff
changeset
|
453 def sync(self, state): |
42380a4f6433
quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents:
2829
diff
changeset
|
454 """Called when backend is desynchronised or resynchronising |
42380a4f6433
quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents:
2829
diff
changeset
|
455 |
42380a4f6433
quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents:
2829
diff
changeset
|
456 @param state(bool): True: if the backend is resynchronising |
42380a4f6433
quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents:
2829
diff
changeset
|
457 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
|
458 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
|
459 """ |
42380a4f6433
quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents:
2829
diff
changeset
|
460 if state: |
3028 | 461 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
|
462 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
|
463 # we are resynchronising all widgets |
3028 | 464 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
|
465 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
|
466 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
|
467 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
|
468 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
|
469 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
|
470 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
|
471 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
|
472 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
|
473 |
2845
42380a4f6433
quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents:
2829
diff
changeset
|
474 self._sync = state |
42380a4f6433
quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents:
2829
diff
changeset
|
475 else: |
3028 | 476 log.debug("we have lost synchronisation with server") |
2845
42380a4f6433
quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents:
2829
diff
changeset
|
477 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
|
478 # 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
|
479 # 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
|
480 for w in self.widgets: |
42380a4f6433
quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents:
2829
diff
changeset
|
481 try: |
42380a4f6433
quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents:
2829
diff
changeset
|
482 w.sync = False |
42380a4f6433
quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents:
2829
diff
changeset
|
483 except AttributeError: |
42380a4f6433
quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents:
2829
diff
changeset
|
484 pass |
42380a4f6433
quick frontend (app): new synchronisation mechanism:
Goffi <goffi@goffi.org>
parents:
2829
diff
changeset
|
485 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
486 def registerSignal( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
487 self, function_name, handler=None, iface="core", with_profile=True |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
488 ): |
1103
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
489 """Register a handler for a signal |
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
490 |
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
|
491 @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
|
492 @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
|
493 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
|
494 @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
|
495 @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
|
496 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
|
497 """ |
3028 | 498 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
|
499 if handler is None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
500 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
|
501 if not with_profile: |
2086 | 502 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
|
503 return |
6053fb8a6466
quick_frontend: fixes an issue with the profile in the signal handler
souliane <souliane@mailoo.org>
parents:
1103
diff
changeset
|
504 |
1103
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
505 def signalReceived(*args, **kwargs): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
506 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
|
507 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
|
508 if not args: |
6053fb8a6466
quick_frontend: fixes an issue with the profile in the signal handler
souliane <souliane@mailoo.org>
parents:
1103
diff
changeset
|
509 raise exceptions.ProfileNotSetError |
6053fb8a6466
quick_frontend: fixes an issue with the profile in the signal handler
souliane <souliane@mailoo.org>
parents:
1103
diff
changeset
|
510 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
|
511 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
|
512 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
|
513 if profile in self.profiles: |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
514 # 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
|
515 # 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
|
516 self.signals_cache.setdefault(profile, []).append( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
517 (function_name, handler, args, kwargs) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
518 ) |
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
|
519 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
|
520 handler(*args, **kwargs) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
521 |
2086 | 522 self.bridge.register_signal(function_name, signalReceived, iface) |
1103
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
523 |
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
|
524 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
|
525 """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
|
526 |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
527 /!\ 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
|
528 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
|
529 @param type_: type of event, can be: |
3065
f8e3789912d0
quick frontend (contact list): added "contactsFilled" event
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
530 - 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
|
531 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
|
532 - avatar: called when avatar data is updated |
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
|
533 args: (entity, avatar file, profile) |
1342
e31a07a5614d
quick_frontends, primitivus (contact list): added nick observer + implemented onNickUpdate
Goffi <goffi@goffi.org>
parents:
1339
diff
changeset
|
534 - nick: called when nick data is updated |
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
|
535 args: (entity, new_nick, 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
|
536 - 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
|
537 args: (entity, show, priority, statuses, profile) |
1972
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
538 - notification: called when a new notification is emited |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
539 args: (entity, notification_data, profile) |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
540 - notification_clear: called when notifications are cleared |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
541 args: (entity, type_, profile) |
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
|
542 - 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
|
543 args: (type_, path, path_i18n, item) were values are: |
fa77e40eb17b
quick_frontends: added "menu" listeners, which is called when a menu is added or removed.
Goffi <goffi@goffi.org>
parents:
1361
diff
changeset
|
544 type_: same as in [sat.core.sat_main.SAT.importMenu] |
fa77e40eb17b
quick_frontends: added "menu" listeners, which is called when a menu is added or removed.
Goffi <goffi@goffi.org>
parents:
1361
diff
changeset
|
545 path: same as in [sat.core.sat_main.SAT.importMenu] |
fa77e40eb17b
quick_frontends: added "menu" listeners, which is called when a menu is added or removed.
Goffi <goffi@goffi.org>
parents:
1361
diff
changeset
|
546 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
|
547 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
|
548 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
|
549 - gotMenus: called only once when menu are available (no arg) |
2103
b44558286bbb
quick frontend (quick app): added progressFinished and progressError listeners
Goffi <goffi@goffi.org>
parents:
2102
diff
changeset
|
550 - progressFinished: called when a progressing action has just finished |
b44558286bbb
quick frontend (quick app): added progressFinished and progressError listeners
Goffi <goffi@goffi.org>
parents:
2102
diff
changeset
|
551 args: (progress_id, metadata, profile) |
b44558286bbb
quick frontend (quick app): added progressFinished and progressError listeners
Goffi <goffi@goffi.org>
parents:
2102
diff
changeset
|
552 - progressError: called when a progressing action failed |
b44558286bbb
quick frontend (quick app): added progressFinished and progressError listeners
Goffi <goffi@goffi.org>
parents:
2102
diff
changeset
|
553 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
|
554 @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
|
555 @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
|
556 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
|
557 """ |
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
|
558 assert type_ in C.LISTENERS |
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
|
559 self._listeners.setdefault(type_, OrderedDict())[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
|
560 |
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
|
561 def removeListener(self, type_, callback): |
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
|
562 """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
|
563 |
1323
a599b6a70dc0
frontends (quick_frontend): fixes a typo (listerner --> listener)
souliane <souliane@mailoo.org>
parents:
1319
diff
changeset
|
564 @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
|
565 @param callback: callback to remove |
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
|
566 """ |
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 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
|
568 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
|
569 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
|
570 except KeyError: |
ab8be8f1c92d
quick frontend(app): catch exception when trying to remove a missing listener, and log it
Goffi <goffi@goffi.org>
parents:
3065
diff
changeset
|
571 log.error( |
ab8be8f1c92d
quick frontend(app): catch exception when trying to remove a missing listener, and log it
Goffi <goffi@goffi.org>
parents:
3065
diff
changeset
|
572 f"Trying to remove an inexisting listener (type = {type_}): {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
|
573 |
1338
139263ee85c5
quick frontends: fixed use of profile for listeners
Goffi <goffi@goffi.org>
parents:
1337
diff
changeset
|
574 def callListeners(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
|
575 """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
|
576 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
|
577 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
|
578 |
1323
a599b6a70dc0
frontends (quick_frontend): fixes a typo (listerner --> listener)
souliane <souliane@mailoo.org>
parents:
1319
diff
changeset
|
579 @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
|
580 @param *args: arguments sent to callback |
1338
139263ee85c5
quick frontends: fixed use of profile for listeners
Goffi <goffi@goffi.org>
parents:
1337
diff
changeset
|
581 @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
|
582 """ |
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
|
583 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
|
584 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
|
585 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
|
586 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
|
587 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
|
588 else: |
1338
139263ee85c5
quick frontends: fixed use of profile for listeners
Goffi <goffi@goffi.org>
parents:
1337
diff
changeset
|
589 profile = kwargs.get("profile") |
3028 | 590 for listener, profiles_filter in 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
|
591 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
|
592 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
|
593 |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
594 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
|
595 """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
|
596 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
|
597 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
598 def postInit(self, profile_manager): |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
599 """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
|
600 |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
601 (auto plug profile) |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
602 @param profile_manager: instance of a subclass of |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
603 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
|
604 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
605 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
|
606 profile_manager.autoconnect([self.options.profile]) |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
117
diff
changeset
|
607 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
608 def profilePlugged(self, profile): |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
609 """Method called when the profile is fully plugged |
91 | 610 |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
611 This will launch frontend specific workflow |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
612 |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
613 /!\ 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
|
614 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
|
615 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
616 @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
|
617 """ |
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
|
618 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
|
619 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
|
620 |
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
|
621 # 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
|
622 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
|
623 for function_name, handler, args, kwargs in cached_signals: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
624 log.debug( |
3028 | 625 "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
|
626 % (function_name, args, kwargs) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
627 ) |
1393
50d5d6325f62
quick_frontend, primitivus: various fixes (MUC and cached signals):
souliane <souliane@mailoo.org>
parents:
1391
diff
changeset
|
628 handler(*args, **kwargs) |
91 | 629 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
630 self.callListeners("profilePlugged", 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
|
631 if not self._plugs_in_progress: |
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.contact_lists.lockUpdate(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
|
633 |
2142
be96beb7ca14
core, bridge, frontends: renamed asyncConnect to connect, and added options parameters (not used yet)
Goffi <goffi@goffi.org>
parents:
2135
diff
changeset
|
634 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
|
635 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
|
636 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
|
637 if not errback: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
638 |
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
|
639 def errback(failure): |
3028 | 640 log.error(_("Can't connect profile [%s]") % failure) |
2089
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
641 try: |
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
642 module = failure.module |
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
643 except AttributeError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
644 module = "" |
2089
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
645 try: |
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
646 message = failure.message |
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
647 except AttributeError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
648 message = "error" |
2089
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
649 try: |
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
650 fullname = failure.fullname |
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
651 except AttributeError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
652 fullname = "error" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
653 if ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
654 module.startswith("twisted.words.protocols.jabber") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
655 and failure.condition == "not-authorized" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
656 ): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
657 self.launchAction(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
|
658 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
659 self.showDialog(message, fullname, "error") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
660 |
2142
be96beb7ca14
core, bridge, frontends: renamed asyncConnect to connect, and added options parameters (not used yet)
Goffi <goffi@goffi.org>
parents:
2135
diff
changeset
|
661 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
|
662 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
663 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
|
664 """Tell application which profiles must be used |
0 | 665 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
666 @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
|
667 """ |
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
|
668 self.contact_lists.lockUpdate() |
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
|
669 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
|
670 self.plugging_profiles() |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
671 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
|
672 self.profiles.plug(profile) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
673 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
674 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
|
675 """Method to subclass to manage frontend specific things to do |
0 | 676 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
677 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
|
678 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
679 pass |
542
3eeb6c865e4d
frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents:
538
diff
changeset
|
680 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
681 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
|
682 """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
|
683 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
|
684 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
|
685 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
|
686 |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
687 def clear_profile(self): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
688 self.profiles.clear() |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
689 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
690 def newWidget(self, widget): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
691 raise NotImplementedError |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
692 |
2128 | 693 # bridge signals hanlers |
694 | |
2894
c7c52c0dc13a
core, quick_frontend(app): fixed connected signal handling
Goffi <goffi@goffi.org>
parents:
2862
diff
changeset
|
695 def connectedHandler(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
|
696 """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
|
697 |
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
|
698 @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
|
699 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
|
700 """ |
1009
d1084f7e56a5
quick_frontend: use of new logging system
Goffi <goffi@goffi.org>
parents:
955
diff
changeset
|
701 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
|
702 self.profiles[profile].whoami = jid.JID(jid_s) |
1417
176de79c8c39
core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
703 self.setPresenceStatus(profile=profile) |
2899
5b0f897689b7
quick frontend (app): (un)set sync state on (dis)connect:
Goffi <goffi@goffi.org>
parents:
2898
diff
changeset
|
704 # 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
|
705 # 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
|
706 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
|
707 # 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
|
708 # 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
|
709 # 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
|
710 # 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
|
711 # on a per-profile basis |
5b0f897689b7
quick frontend (app): (un)set sync state on (dis)connect:
Goffi <goffi@goffi.org>
parents:
2898
diff
changeset
|
712 self.sync = True |
52 | 713 |
1103
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
714 def disconnectedHandler(self, profile): |
52 | 715 """called when the connection is closed""" |
1009
d1084f7e56a5
quick_frontend: use of new logging system
Goffi <goffi@goffi.org>
parents:
955
diff
changeset
|
716 log.debug(_("Disconnected")) |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
717 self.contact_lists[profile].disconnect() |
2899
5b0f897689b7
quick frontend (app): (un)set sync state on (dis)connect:
Goffi <goffi@goffi.org>
parents:
2898
diff
changeset
|
718 # FIXME: see note on connectedHandler |
5b0f897689b7
quick frontend (app): (un)set sync state on (dis)connect:
Goffi <goffi@goffi.org>
parents:
2898
diff
changeset
|
719 self.sync = False |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
720 self.setPresenceStatus(C.PRESENCE_UNAVAILABLE, "", profile=profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
721 |
1599
e2ed8009e66e
backend, bridge, frontends: actionNew has now a security_limit argument + added some docstring to explain data argument
Goffi <goffi@goffi.org>
parents:
1580
diff
changeset
|
722 def actionNewHandler(self, action_data, id_, security_limit, profile): |
2042
2e948c228643
quick frontend (quick_app): fixed user_action from action coming from backend
Goffi <goffi@goffi.org>
parents:
2040
diff
changeset
|
723 self.actionManager(action_data, user_action=False, profile=profile) |
1468
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1461
diff
changeset
|
724 |
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
|
725 def newContactHandler(self, jid_s, attributes, groups, profile): |
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
|
726 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
|
727 groups = list(groups) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
728 self.contact_lists[profile].setContact(entity, groups, attributes, in_roster=True) |
510
886754295efe
quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
507
diff
changeset
|
729 |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
730 def messageNewHandler(self, uid, timestamp, from_jid_s, to_jid_s, msg, subject, type_, |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
731 extra, profile): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
732 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
|
733 to_jid = jid.JID(to_jid_s) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
734 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
|
735 "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
|
736 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
|
737 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
|
738 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
739 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
|
740 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
|
741 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
|
742 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
|
743 |
441b536e28ed
quick frontend (chat): use right type in getOrCreateWidget on new message
Goffi <goffi@goffi.org>
parents:
2790
diff
changeset
|
744 try: |
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
|
745 is_room = contact_list.isRoom(target) |
2792
441b536e28ed
quick frontend (chat): use right type in getOrCreateWidget on new message
Goffi <goffi@goffi.org>
parents:
2790
diff
changeset
|
746 except exceptions.NotFound: |
441b536e28ed
quick frontend (chat): use right type in getOrCreateWidget on new message
Goffi <goffi@goffi.org>
parents:
2790
diff
changeset
|
747 is_room = False |
441b536e28ed
quick frontend (chat): use right type in getOrCreateWidget on new message
Goffi <goffi@goffi.org>
parents:
2790
diff
changeset
|
748 |
441b536e28ed
quick frontend (chat): use right type in getOrCreateWidget on new message
Goffi <goffi@goffi.org>
parents:
2790
diff
changeset
|
749 if target.resource and not is_room: |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
750 # 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
|
751 # 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
|
752 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
|
753 # we want to be sure to have at least one QuickChat instance |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
754 self.widgets.getOrCreateWidget( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
755 quick_chat.QuickChat, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
756 target, |
2792
441b536e28ed
quick frontend (chat): use right type in getOrCreateWidget on new message
Goffi <goffi@goffi.org>
parents:
2790
diff
changeset
|
757 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
|
758 on_new_widget = None, |
441b536e28ed
quick frontend (chat): use right type in getOrCreateWidget on new message
Goffi <goffi@goffi.org>
parents:
2790
diff
changeset
|
759 profile = profile, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
760 ) |
510
886754295efe
quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
507
diff
changeset
|
761 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
762 if ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
763 not from_jid in contact_list |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
764 and from_jid.bare != self.profiles[profile].whoami.bare |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
765 ): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
766 # 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
|
767 # presence information and which are not in roster |
2ecc07a8f91b
primitivus, quick_frontends: moved newMessage signal handler to quick_frontend
Goffi <goffi@goffi.org>
parents:
1319
diff
changeset
|
768 contact_list.setContact(from_jid) |
2ecc07a8f91b
primitivus, quick_frontends: moved newMessage signal handler to quick_frontend
Goffi <goffi@goffi.org>
parents:
1319
diff
changeset
|
769 |
2040
f607349a01a4
quick frontend (chat): fixed messageNew signal dispatching when several widgets are handling the target
Goffi <goffi@goffi.org>
parents:
2036
diff
changeset
|
770 # we dispatch the message in the widgets |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
771 for widget in self.widgets.getWidgets( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
772 quick_chat.QuickChat, target=target, profiles=(profile,) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
773 ): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
774 widget.messageNew( |
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
|
775 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
|
776 ) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
777 |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
778 def messageEncryptionStartedHandler(self, destinee_jid_s, plugin_data, profile): |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
779 destinee_jid = jid.JID(destinee_jid_s) |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
780 plugin_data = data_format.deserialise(plugin_data) |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
781 for widget in self.widgets.getWidgets(quick_chat.QuickChat, |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
782 target=destinee_jid.bare, |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
783 profiles=(profile,)): |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
784 widget.messageEncryptionStarted(plugin_data) |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
785 |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
786 def messageEncryptionStoppedHandler(self, destinee_jid_s, plugin_data, profile): |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
787 destinee_jid = jid.JID(destinee_jid_s) |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
788 for widget in self.widgets.getWidgets(quick_chat.QuickChat, |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
789 target=destinee_jid.bare, |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
790 profiles=(profile,)): |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
791 widget.messageEncryptionStopped(plugin_data) |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
792 |
2024
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2016
diff
changeset
|
793 def messageStateHandler(self, uid, status, profile): |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2016
diff
changeset
|
794 for widget in self.widgets.getWidgets(quick_chat.QuickChat, profiles=(profile,)): |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2016
diff
changeset
|
795 widget.onMessageState(uid, status, profile) |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2016
diff
changeset
|
796 |
2829
649cb3fd7711
quick frontend(app): avoid sending empty messages
Goffi <goffi@goffi.org>
parents:
2807
diff
changeset
|
797 def messageSend(self, to_jid, message, subject=None, mess_type="auto", extra=None, callback=None, errback=None, profile_key=C.PROF_KEY_NONE): |
3028 | 798 if not subject and not extra and (not message or message == {'': ''}): |
799 log.debug("Not sending empty message") | |
2829
649cb3fd7711
quick frontend(app): avoid sending empty messages
Goffi <goffi@goffi.org>
parents:
2807
diff
changeset
|
800 return |
649cb3fd7711
quick frontend(app): avoid sending empty messages
Goffi <goffi@goffi.org>
parents:
2807
diff
changeset
|
801 |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1939
diff
changeset
|
802 if subject is None: |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1939
diff
changeset
|
803 subject = {} |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1939
diff
changeset
|
804 if extra is None: |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1939
diff
changeset
|
805 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
|
806 if callback is None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
807 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
|
808 lambda __=None: None |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
809 ) # 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
|
810 # 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
|
811 if errback is None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
812 errback = lambda failure: self.showDialog( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
813 failure.fullname, failure.message, "error" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
814 ) |
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
|
815 |
2829
649cb3fd7711
quick frontend(app): avoid sending empty messages
Goffi <goffi@goffi.org>
parents:
2807
diff
changeset
|
816 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
|
817 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
|
818 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
819 self.bridge.messageSend( |
3028 | 820 str(to_jid), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
821 message, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
822 subject, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
823 mess_type, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
824 extra, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
825 profile_key, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
826 callback=callback, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
827 errback=errback, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
828 ) |
0 | 829 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
830 def setPresenceStatus(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
|
831 raise NotImplementedError |
0 | 832 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
833 def presenceUpdateHandler(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
|
834 # 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
|
835 # 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
|
836 # 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
|
837 # _( |
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
|
838 # 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
|
839 # 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
|
840 # ) |
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
|
841 # % { |
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
|
842 # "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
|
843 # 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
|
844 # 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
|
845 # 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
|
846 # "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
|
847 # } |
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
|
848 # ) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
849 entity = jid.JID(entity_s) |
0 | 850 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
851 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
|
852 if show == C.PRESENCE_UNAVAILABLE: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
853 self.setPresenceStatus(C.PRESENCE_UNAVAILABLE, "", profile=profile) |
735
682933ca304c
frontends: presence update in quick app:
souliane <souliane@mailoo.org>
parents:
698
diff
changeset
|
854 else: |
1417
176de79c8c39
core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
855 # 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
|
856 status = statuses.get(C.PRESENCE_STATUSES_DEFAULT, None) |
176de79c8c39
core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
857 self.setPresenceStatus(show, status, profile=profile) |
0 | 858 return |
859 | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
860 self.callListeners("presence", entity, show, priority, statuses, profile=profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
861 |
3101
ab7e8ade848a
plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents:
3077
diff
changeset
|
862 def mucRoomJoinedHandler( |
ab7e8ade848a
plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents:
3077
diff
changeset
|
863 self, room_jid_s, occupants, user_nick, subject, statuses, profile): |
72 | 864 """Called when a MUC room is joined""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
865 log.debug( |
3028 | 866 "Room [{room_jid}] joined by {profile}, users presents:{users}".format( |
867 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
|
868 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
869 ) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
870 room_jid = jid.JID(room_jid_s) |
3006
ba9aaf7d6cd0
quick frontends (app): setSpecial is now called before getOrCreateWidget in mucRoomJoinedHandler:
Goffi <goffi@goffi.org>
parents:
2976
diff
changeset
|
871 self.contact_lists[profile].setSpecial(room_jid, C.CONTACT_SPECIAL_GROUP) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
872 self.widgets.getOrCreateWidget( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
873 quick_chat.QuickChat, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
874 room_jid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
875 type_=C.CHAT_GROUP, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
876 nick=user_nick, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
877 occupants=occupants, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
878 subject=subject, |
3101
ab7e8ade848a
plugin XEP-0045: added room statuses to metadata:
Goffi <goffi@goffi.org>
parents:
3077
diff
changeset
|
879 statuses=statuses, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
880 profile=profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
881 ) |
72 | 882 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
883 def mucRoomLeftHandler(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
|
884 """Called when a MUC room is left""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
885 log.debug( |
3028 | 886 "Room [%(room_jid)s] left by %(profile)s" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
887 % {"room_jid": room_jid_s, "profile": profile} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
888 ) |
1351
ec43552f5f8b
quick_frontend: replace last occurences of QuickApp.chat_wins with QuickApp.widgets
souliane <souliane@mailoo.org>
parents:
1348
diff
changeset
|
889 room_jid = jid.JID(room_jid_s) |
ec43552f5f8b
quick_frontend: replace last occurences of QuickApp.chat_wins with QuickApp.widgets
souliane <souliane@mailoo.org>
parents:
1348
diff
changeset
|
890 chat_widget = self.widgets.getWidget(quick_chat.QuickChat, room_jid, profile) |
ec43552f5f8b
quick_frontend: replace last occurences of QuickApp.chat_wins with QuickApp.widgets
souliane <souliane@mailoo.org>
parents:
1348
diff
changeset
|
891 if chat_widget: |
ec43552f5f8b
quick_frontend: replace last occurences of QuickApp.chat_wins with QuickApp.widgets
souliane <souliane@mailoo.org>
parents:
1348
diff
changeset
|
892 self.widgets.deleteWidget(chat_widget) |
1397
96dd0ae1a850
quick_frontend (contact_list): rename QuickContactList.remove to QuickContactList.removeContact + remove the contact from _roster attribute (and not only from _cache)
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
893 self.contact_lists[profile].removeContact(room_jid) |
72 | 894 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
895 def mucRoomUserChangedNickHandler(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
|
896 """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
|
897 room_jid = jid.JID(room_jid_s) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
898 chat_widget = self.widgets.getOrCreateWidget( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
899 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
|
900 ) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
901 chat_widget.changeUserNick(old_nick, new_nick) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
902 log.debug( |
3028 | 903 "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
|
904 % {"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
|
905 ) |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
504
diff
changeset
|
906 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
907 def mucRoomNewSubjectHandler(self, room_jid_s, subject, profile): |
76 | 908 """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
|
909 room_jid = jid.JID(room_jid_s) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
910 chat_widget = self.widgets.getOrCreateWidget( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
911 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
|
912 ) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
913 chat_widget.setSubject(subject) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
914 log.debug( |
3028 | 915 "new subject for room [%(room_jid)s]: %(subject)s" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
916 % {"room_jid": room_jid, "subject": subject} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
917 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
918 |
1103
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
919 def chatStateReceivedHandler(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
|
920 """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
|
921 |
1378
3dae6964c071
quick_frontends, primitivus: move the chat states logic to quick_frontend
souliane <souliane@mailoo.org>
parents:
1377
diff
changeset
|
922 @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
|
923 @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
|
924 @param profile (unicode): current profile |
907
cd02f5ef30df
primitivus: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
906
diff
changeset
|
925 """ |
2007
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1972
diff
changeset
|
926 from_jid = jid.JID(from_jid_s) |
2789
d350f4571d82
quick frontend (app): fixed filtering for chat state notifications
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
927 for widget in self.widgets.getWidgets(quick_chat.QuickChat, target=from_jid.bare, |
d350f4571d82
quick frontend (app): fixed filtering for chat state notifications
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
928 profiles=(profile,)): |
2007
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1972
diff
changeset
|
929 widget.onChatState(from_jid, state, profile) |
907
cd02f5ef30df
primitivus: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
906
diff
changeset
|
930 |
2861
e9e33e05d143
quick frontend (app): fixed notifications ids
Goffi <goffi@goffi.org>
parents:
2854
diff
changeset
|
931 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
|
932 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
|
933 """Trigger an event notification |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
934 |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
935 @param type_(unicode): notifation kind, |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
936 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
|
937 @param entity(jid.JID, None): entity involved in the notification |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
938 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
|
939 @param message(unicode, None): message of the notification |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
940 @param subject(unicode, None): subject of the notification |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
941 @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
|
942 @param cb_args(list, None): list of args for callback |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
943 @param widget(object, None): widget where the notification happened |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
944 """ |
2135 | 945 assert type_ in C.NOTIFY_ALL |
1972
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
946 notif_dict = self.profiles[profile].notifications |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
947 key = "" if entity is None else entity.bare |
1972
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
948 type_notifs = notif_dict.setdefault(key, {}).setdefault(type_, []) |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
949 notif_data = { |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
950 "id": self._notif_id, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
951 "time": time.time(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
952 "entity": entity, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
953 "callback": callback, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
954 "cb_args": cb_args, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
955 "message": message, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
956 "subject": subject, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
957 } |
1972
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
958 if widget is not None: |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
959 notif_data[widget] = widget |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
960 type_notifs.append(notif_data) |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
961 self._notifications[self._notif_id] = notif_data |
2861
e9e33e05d143
quick frontend (app): fixed notifications ids
Goffi <goffi@goffi.org>
parents:
2854
diff
changeset
|
962 self._notif_id += 1 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
963 self.callListeners("notification", entity, notif_data, profile=profile) |
1972
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
964 |
2016
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
965 def getNotifs(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
|
966 """return notifications for given entity |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
967 |
2016
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
968 @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
|
969 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
|
970 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
|
971 C.ENTITY_ALL to get all notifications |
1972
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
972 @param type_(unicode, None): notification type to filter |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
973 None to get all notifications |
2016
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
974 @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
|
975 exact entity jid (i.e. not including other resources) |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
976 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
|
977 False to get resources notifications |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
978 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
|
979 @return (iter[dict]): notifications |
1972
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
980 """ |
2016
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
981 main_notif_dict = self.profiles[profile].notifications |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
982 |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
983 if entity is C.ENTITY_ALL: |
3028 | 984 selected_notifs = iter(main_notif_dict.values()) |
2016
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
985 exact_jid = False |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
986 else: |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
987 if entity is None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
988 key = "" |
2016
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
989 exact_jid = False |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
990 else: |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
991 key = entity.bare |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
992 if exact_jid is None: |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
993 exact_jid = bool(entity.resource) |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
994 selected_notifs = (main_notif_dict.setdefault(key, {}),) |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
995 |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
996 for notifs_from_select in selected_notifs: |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
997 |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
998 if type_ is None: |
3028 | 999 type_notifs = iter(notifs_from_select.values()) |
2016
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
1000 else: |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
1001 type_notifs = (notifs_from_select.get(type_, []),) |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
1002 |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
1003 for notifs in type_notifs: |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
1004 for notif in notifs: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1005 if exact_jid and notif["entity"] != entity: |
2016
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
1006 continue |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
1007 yield notif |
1972
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
1008 |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
1009 def clearNotifs(self, entity, type_=None, profile=C.PROF_KEY_NONE): |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
1010 """return notifications for given entity |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
1011 |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
1012 @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
|
1013 None to clear general notifications (but keep entities ones) |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
1014 @param type_(unicode, None): notification type to filter |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
1015 None to clear all notifications |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
1016 @return (list[dict]): list of notifications |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
1017 """ |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
1018 notif_dict = self.profiles[profile].notifications |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1019 key = "" if entity is None else entity.bare |
1972
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
1020 try: |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
1021 if type_ is None: |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
1022 del notif_dict[key] |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
1023 else: |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
1024 del notif_dict[key][type_] |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
1025 except KeyError: |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
1026 return |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1027 self.callListeners("notificationsClear", entity, type_, profile=profile) |
1972
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
1028 |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
1029 def psEventHandler(self, category, service_s, node, event_type, data, profile): |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
1030 """Called when a PubSub event is received. |
1352
56c14cb29e0f
quick_frontend: register the 'personalEvent' signal
souliane <souliane@mailoo.org>
parents:
1351
diff
changeset
|
1031 |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
1032 @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
|
1033 @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
|
1034 @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
|
1035 @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
|
1036 @param data (serialised_dict): event data |
1352
56c14cb29e0f
quick_frontend: register the 'personalEvent' signal
souliane <souliane@mailoo.org>
parents:
1351
diff
changeset
|
1037 """ |
2807
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2792
diff
changeset
|
1038 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
|
1039 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
|
1040 |
2067
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
1041 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
|
1042 if event_type == C.PS_PUBLISH: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1043 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
|
1044 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
|
1045 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
|
1046 |
0b7ce5daee9b
plugin XEP-0277: blog items data are now entirely serialised before going to bridge:
Goffi <goffi@goffi.org>
parents:
2792
diff
changeset
|
1047 # 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
|
1048 _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
|
1049 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
1050 for wid in self.widgets.getWidgets(quick_blog.QuickBlog): |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
1051 wid.addEntryIfAccepted(service_s, node, data, _groups, profile) |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
1052 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
1053 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1054 comments_node, comments_service = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1055 data["comments_node"], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1056 data["comments_service"], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1057 ) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
1058 except KeyError: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
1059 pass |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
1060 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1061 self.bridge.mbGet( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1062 comments_service, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1063 comments_node, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1064 C.NO_LIMIT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1065 [], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1066 {"subscribe": C.BOOL_TRUE}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1067 profile=profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1068 ) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
1069 elif event_type == C.PS_RETRACT: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
1070 for wid in self.widgets.getWidgets(quick_blog.QuickBlog): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1071 wid.deleteEntryIfPresent(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
|
1072 pass |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
1073 else: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
1074 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
|
1075 |
2862
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1076 def registerProgressCbs(self, progress_id, callback, errback): |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1077 """Register progression callbacks |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1078 |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1079 @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
|
1080 @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
|
1081 successfuly finished. |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1082 None to ignore |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1083 @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
|
1084 None to ignore |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1085 """ |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1086 callbacks = self._progress_ids.setdefault(progress_id, []) |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1087 callbacks.append((callback, errback)) |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1088 |
1636 | 1089 def progressStartedHandler(self, pid, metadata, profile): |
3028 | 1090 log.info("Progress {} started".format(pid)) |
1636 | 1091 |
1092 def progressFinishedHandler(self, pid, metadata, profile): | |
3028 | 1093 log.info("Progress {} finished".format(pid)) |
2862
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1094 try: |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1095 callbacks = self._progress_ids.pop(pid) |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1096 except KeyError: |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1097 pass |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1098 else: |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1099 for callback, __ in callbacks: |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1100 if callback is not None: |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1101 callback(metadata, profile=profile) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1102 self.callListeners("progressFinished", pid, metadata, profile=profile) |
1636 | 1103 |
1104 def progressErrorHandler(self, pid, err_msg, profile): | |
3028 | 1105 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
|
1106 try: |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1107 callbacks = self._progress_ids.pop(pid) |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1108 except KeyError: |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1109 pass |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1110 else: |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1111 for __, errback in callbacks: |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1112 if errback is not None: |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1113 errback(err_msg, profile=profile) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1114 self.callListeners("progressError", pid, err_msg, profile=profile) |
1636 | 1115 |
182
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
1116 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
|
1117 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
|
1118 type_ = "subscribed" if answer else "unsubscribed" |
3028 | 1119 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
|
1120 |
1103
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
1121 def subscribeHandler(self, type, raw_jid, profile): |
87 | 1122 """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
|
1123 entity = jid.JID(raw_jid) |
906
1cbae66fa725
quick_app: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
1124 if type == "subscribed": |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
1125 # 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
|
1126 # TODO: call self.getEntityMBlog to add the new contact blogs |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1127 self.showDialog( |
3028 | 1128 _("The contact {contact} has accepted your subscription").format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1129 contact=entity.bare |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1130 ), |
3028 | 1131 _("Subscription confirmation"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1132 ) |
906
1cbae66fa725
quick_app: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
1133 elif type == "unsubscribed": |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
1134 # this is a subscription refusal, we just have to inform user |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1135 self.showDialog( |
3028 | 1136 _("The contact {contact} has refused your subscription").format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1137 contact=entity.bare |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1138 ), |
3028 | 1139 _("Subscription refusal"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1140 "error", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1141 ) |
906
1cbae66fa725
quick_app: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
1142 elif type == "subscribe": |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
1143 # 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
|
1144 # TODO: use sat.stdui.ui_contact_list to display the groups selector |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1145 self.showDialog( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1146 _( |
3028 | 1147 "The contact {contact} wants to subscribe to your presence" |
1148 ".\nDo you accept ?" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1149 ).format(contact=entity.bare), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1150 _("Subscription confirmation"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1151 "yes/no", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1152 answer_cb=self._subscribe_cb, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1153 answer_data=(entity, profile), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1154 ) |
0 | 1155 |
2854 | 1156 def _debugHandler(self, action, parameters, profile): |
3028 | 1157 if action == "widgets_dump": |
2854 | 1158 from pprint import pformat |
3028 | 1159 log.info("Widgets dump:\n{data}".format(data=pformat(self.widgets._widgets))) |
2854 | 1160 else: |
3028 | 1161 log.warning("Unknown debug action: {action}".format(action=action)) |
2854 | 1162 |
1163 | |
1325
49f967fc87aa
core, quick_frontends: fixes one typo and a variable naming issue
souliane <souliane@mailoo.org>
parents:
1323
diff
changeset
|
1164 def showDialog(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
|
1165 """Show a dialog to user |
fe9888d3fcb6
quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents:
2590
diff
changeset
|
1166 |
fe9888d3fcb6
quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents:
2590
diff
changeset
|
1167 Frontends must override this method |
fe9888d3fcb6
quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents:
2590
diff
changeset
|
1168 @param message(unicode): body of the dialog |
fe9888d3fcb6
quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents:
2590
diff
changeset
|
1169 @param title(unicode): title of the dialog |
fe9888d3fcb6
quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents:
2590
diff
changeset
|
1170 @param type(unicode): one of: |
fe9888d3fcb6
quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents:
2590
diff
changeset
|
1171 - "info": information dialog (callbacks not used) |
fe9888d3fcb6
quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents:
2590
diff
changeset
|
1172 - "warning": important information to notice (callbacks not used) |
fe9888d3fcb6
quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents:
2590
diff
changeset
|
1173 - "error": something went wrong (callbacks not used) |
fe9888d3fcb6
quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents:
2590
diff
changeset
|
1174 - "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
|
1175 @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
|
1176 Arguments depend on dialog type: |
fe9888d3fcb6
quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents:
2590
diff
changeset
|
1177 - "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
|
1178 @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
|
1179 """ |
fe9888d3fcb6
quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents:
2590
diff
changeset
|
1180 # FIXME: misnamed method + types are not well chosen. Need to be rethought |
0 | 1181 raise NotImplementedError |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
1182 |
0 | 1183 def showAlert(self, message): |
2618
fe9888d3fcb6
quick app: added missing docstring in showDialog
Goffi <goffi@goffi.org>
parents:
2590
diff
changeset
|
1184 # FIXME: doesn't seems used anymore, to remove? |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1185 pass # FIXME |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
1186 |
1468
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1461
diff
changeset
|
1187 def dialogFailure(self, failure): |
3028 | 1188 log.warning("Failure: {}".format(failure)) |
1468
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1461
diff
changeset
|
1189 |
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
|
1190 def progressIdHandler(self, progress_id, profile): |
2071d5cec5d6
quick frontend: added progressIdHandler to managed progress id on action result + ignore meta_* action results
Goffi <goffi@goffi.org>
parents:
1599
diff
changeset
|
1191 """Callback used when an action result in a progress id""" |
3028 | 1192 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
|
1193 |
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
|
1194 def isHidden(self): |
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
|
1195 """Tells if the frontend window is hidden. |
1442
6ce18c4e5708
quick_frontend: display over whole alerts counter
souliane <souliane@mailoo.org>
parents:
1436
diff
changeset
|
1196 |
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
|
1197 @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
|
1198 """ |
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
|
1199 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
|
1200 |
1103
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
1201 def paramUpdateHandler(self, name, value, namespace, profile): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1202 log.debug( |
3028 | 1203 _("param update: [%(namespace)s] %(name)s = %(value)s") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1204 % {"namespace": namespace, "name": name, "value": value} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1205 ) |
906
1cbae66fa725
quick_app: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
1206 if (namespace, name) == ("Connection", "JabberID"): |
3028 | 1207 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
|
1208 self.profiles[profile].whoami = jid.JID(value) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1209 elif (namespace, name) == ("General", C.SHOW_OFFLINE_CONTACTS): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
1210 self.contact_lists[profile].showOfflineContacts(C.bool(value)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1211 elif (namespace, name) == ("General", C.SHOW_EMPTY_GROUPS): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
1212 self.contact_lists[profile].showEmptyGroups(C.bool(value)) |
0 | 1213 |
1325
49f967fc87aa
core, quick_frontends: fixes one typo and a variable naming issue
souliane <souliane@mailoo.org>
parents:
1323
diff
changeset
|
1214 def contactDeletedHandler(self, jid_s, profile): |
49f967fc87aa
core, quick_frontends: fixes one typo and a variable naming issue
souliane <souliane@mailoo.org>
parents:
1323
diff
changeset
|
1215 target = 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
|
1216 self.contact_lists[profile].removeContact(target) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
1217 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
1218 def entityDataUpdatedHandler(self, entity_s, key, value, profile): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
1219 entity = jid.JID(entity_s) |
1386
1f3513cfb246
quick_frontend, primivitus: remove QuickChat.getUserNick + primivitus ChatText gets the user nick directly from parent Chat instance
souliane <souliane@mailoo.org>
parents:
1382
diff
changeset
|
1220 if key == "nick": # this is the roster nick, not the MUC nick |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
1221 if entity in self.contact_lists[profile]: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1222 self.contact_lists[profile].setCache(entity, "nick", value) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1223 self.callListeners("nick", entity, value, profile=profile) |
2123
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2103
diff
changeset
|
1224 elif key == "avatar" and self.AVATARS_HANDLER: |
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2103
diff
changeset
|
1225 if value and entity in self.contact_lists[profile]: |
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2103
diff
changeset
|
1226 self.getAvatar(entity, ignore_cache=True, profile=profile) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
1227 |
2669
bdb8276fd2da
frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents:
2664
diff
changeset
|
1228 def actionManager(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
|
1229 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
|
1230 """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
|
1231 |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
1232 @param action_data(dict): action dict as sent by launchAction or returned by an |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
1233 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
|
1234 @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
|
1235 @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
|
1236 @param user_action(bool): if True, the action is a result of a user interaction |
2862
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1237 else the action come from backend direclty (i.e. actionNew). |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1238 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
|
1239 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
|
1240 @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
|
1241 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
|
1242 @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
|
1243 during progression. |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1244 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
|
1245 """ |
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
|
1246 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1247 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
|
1248 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
|
1249 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
|
1250 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1251 ui = self.xmlui.create( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1252 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1253 xml_data=xmlui, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1254 flags=("FROM_BACKEND",) if not user_action else None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1255 callback=callback, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1256 profile=profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1257 ) |
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
|
1258 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
|
1259 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
|
1260 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
|
1261 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
|
1262 |
2071d5cec5d6
quick frontend: added progressIdHandler to managed progress id on action result + ignore meta_* action results
Goffi <goffi@goffi.org>
parents:
1599
diff
changeset
|
1263 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1264 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
|
1265 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
|
1266 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
|
1267 else: |
2862
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1268 if progress_cb or progress_eb: |
b2e898384c25
quick_frontend (app): progress callbacks handling:
Goffi <goffi@goffi.org>
parents:
2861
diff
changeset
|
1269 self.registerProgressCbs(progress_id, progress_cb, progress_eb) |
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
|
1270 self.progressIdHandler(progress_id, profile) |
2071d5cec5d6
quick frontend: added progressIdHandler to managed progress id on action result + ignore meta_* action results
Goffi <goffi@goffi.org>
parents:
1599
diff
changeset
|
1271 |
2071d5cec5d6
quick frontend: added progressIdHandler to managed progress id on action result + ignore meta_* action results
Goffi <goffi@goffi.org>
parents:
1599
diff
changeset
|
1272 # we ignore metadata |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1273 action_data = { |
3028 | 1274 k: v for k, v in action_data.items() if not k.startswith("meta_") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1275 } |
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
|
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 if action_data: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1278 raise exceptions.DataError( |
3028 | 1279 "Not all keys in action_data are managed ({keys})".format( |
1280 keys=", ".join(list(action_data.keys())) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1281 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1282 ) |
2126 | 1283 |
1284 def _actionCb(self, data, callback, callback_id, profile): | |
1285 if callback is None: | |
1286 self.actionManager(data, profile=profile) | |
1287 else: | |
1288 callback(data=data, cb_id=callback_id, profile=profile) | |
1289 | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1290 def launchAction( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1291 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
|
1292 ): |
2126 | 1293 """Launch a dynamic action |
1468
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1461
diff
changeset
|
1294 |
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
|
1295 @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
|
1296 @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
|
1297 @param callback(callable, None): will be called with the resut |
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
|
1298 if None, self.actionManager will be called |
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
|
1299 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
|
1300 - 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
|
1301 - 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
|
1302 - profile: %(doc_profile)s |
1468
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1461
diff
changeset
|
1303 @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
|
1304 |
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
|
1305 """ |
1468
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1461
diff
changeset
|
1306 if data is None: |
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1461
diff
changeset
|
1307 data = dict() |
2126 | 1308 action_cb = lambda data: self._actionCb(data, callback, callback_id, profile) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1309 self.bridge.launchAction( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1310 callback_id, data, profile, callback=action_cb, errback=self.dialogFailure |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1311 ) |
1468
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1461
diff
changeset
|
1312 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1313 def launchMenu( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1314 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1315 menu_type, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1316 path, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1317 data=None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1318 callback=None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1319 security_limit=C.SECURITY_LIMIT_MAX, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1320 profile=C.PROF_KEY_NONE, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1321 ): |
2126 | 1322 """Launch a menu manually |
1580
641cfd2faefe
Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents:
1513
diff
changeset
|
1323 |
2126 | 1324 @param menu_type(unicode): type of the menu to launch |
1325 @param path(iterable[unicode]): path to the menu | |
1326 @param data: data needed only for certain actions | |
1327 @param callback(callable, None): will be called with the resut | |
1328 if None, self.actionManager will be called | |
1329 else the callable will be called with the following kw parameters: | |
1330 - data: action_data | |
1331 - cb_id: (menu_type, path) tuple | |
1332 - profile: %(doc_profile)s | |
1333 @param profile: %(doc_profile)s | |
1468
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1461
diff
changeset
|
1334 |
2126 | 1335 """ |
1336 if data is None: | |
1337 data = dict() | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1338 action_cb = lambda data: self._actionCb( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1339 data, callback, (menu_type, path), profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1340 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1341 self.bridge.menuLaunch( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1342 menu_type, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1343 path, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1344 data, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1345 security_limit, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1346 profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1347 callback=action_cb, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1348 errback=self.dialogFailure, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1349 ) |
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
|
1350 |
2123
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2103
diff
changeset
|
1351 def _avatarGetCb(self, avatar_path, entity, contact_list, profile): |
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2103
diff
changeset
|
1352 path = avatar_path or self.getDefaultAvatar(entity) |
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2103
diff
changeset
|
1353 contact_list.setCache(entity, "avatar", path) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1354 self.callListeners("avatar", entity, path, profile=profile) |
2123
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2103
diff
changeset
|
1355 |
3017
e7cbe662838b
quick frontend (app): show an info log if avatar is not found instead of raising exception
Goffi <goffi@goffi.org>
parents:
3006
diff
changeset
|
1356 def _avatarGetEb(self, failure_, entity, contact_list): |
e7cbe662838b
quick frontend (app): show an info log if avatar is not found instead of raising exception
Goffi <goffi@goffi.org>
parents:
3006
diff
changeset
|
1357 # FIXME: bridge needs a proper error handling |
3028 | 1358 if "NotFound" in str(failure_): |
1359 log.info("No avatar found for {entity}".format(entity=entity)) | |
3017
e7cbe662838b
quick frontend (app): show an info log if avatar is not found instead of raising exception
Goffi <goffi@goffi.org>
parents:
3006
diff
changeset
|
1360 else: |
3028 | 1361 log.warning("Can't get avatar: {}".format(failure_)) |
2123
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2103
diff
changeset
|
1362 contact_list.setCache(entity, "avatar", self.getDefaultAvatar(entity)) |
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2103
diff
changeset
|
1363 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1364 def getAvatar( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1365 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1366 entity, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1367 cache_only=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1368 hash_only=False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1369 ignore_cache=False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1370 profile=C.PROF_KEY_NONE, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1371 ): |
2123
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2103
diff
changeset
|
1372 """return avatar path for an entity |
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2103
diff
changeset
|
1373 |
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2103
diff
changeset
|
1374 @param entity(jid.JID): entity to get avatar from |
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2103
diff
changeset
|
1375 @param cache_only(bool): if False avatar will be requested if not in cache |
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2103
diff
changeset
|
1376 with current vCard based implementation, it's better to keep True |
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2103
diff
changeset
|
1377 except if we request avatars for roster items |
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2103
diff
changeset
|
1378 @param hash_only(bool): if True avatar hash is returned, else full path |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
1379 @param ignore_cache(bool): if False, won't check local cache and will request |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
1380 backend in every case |
2123
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2103
diff
changeset
|
1381 @return (unicode, None): avatar full path (None if no avatar found) |
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2103
diff
changeset
|
1382 """ |
2067
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
1383 contact_list = self.contact_lists[profile] |
2123
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2103
diff
changeset
|
1384 if ignore_cache: |
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2103
diff
changeset
|
1385 avatar = None |
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2103
diff
changeset
|
1386 else: |
2626
6ef2b4fa90a5
quick_frontend (QuickApp): fixed getCache handling after changes in QuickContactList
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1387 try: |
6ef2b4fa90a5
quick_frontend (QuickApp): fixed getCache handling after changes in QuickContactList
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1388 avatar = contact_list.getCache(entity, "avatar", bare_default=None) |
6ef2b4fa90a5
quick_frontend (QuickApp): fixed getCache handling after changes in QuickContactList
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1389 except exceptions.NotFound: |
6ef2b4fa90a5
quick_frontend (QuickApp): fixed getCache handling after changes in QuickContactList
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
1390 avatar = None |
2067
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
1391 if avatar is None: |
2123
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2103
diff
changeset
|
1392 self.bridge.avatarGet( |
3028 | 1393 str(entity), |
2123
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2103
diff
changeset
|
1394 cache_only, |
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2103
diff
changeset
|
1395 hash_only, |
c42aab22c2c0
plugin XEP-0054, quick frontend(app): various improvments:
Goffi <goffi@goffi.org>
parents:
2103
diff
changeset
|
1396 profile=profile, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1397 callback=lambda path: self._avatarGetCb( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1398 path, entity, contact_list, profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1399 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1400 errback=lambda failure: self._avatarGetEb(failure, entity, contact_list), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1401 ) |
2664
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
1402 # we set avatar to empty string to avoid requesting several time the same |
e35a265ec174
quick frontend (app, chat): encryption handling:
Goffi <goffi@goffi.org>
parents:
2626
diff
changeset
|
1403 # avatar while we are waiting for avatarGet result |
2067
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
1404 contact_list.setCache(entity, "avatar", "") |
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
1405 return avatar |
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
1406 |
2056
7bfa97e533ac
quick frontend(QuickApp): added getDefaultAvatar method:
Goffi <goffi@goffi.org>
parents:
2050
diff
changeset
|
1407 def getDefaultAvatar(self, entity=None): |
7bfa97e533ac
quick frontend(QuickApp): added getDefaultAvatar method:
Goffi <goffi@goffi.org>
parents:
2050
diff
changeset
|
1408 """return default avatar to use with given entity |
7bfa97e533ac
quick frontend(QuickApp): added getDefaultAvatar method:
Goffi <goffi@goffi.org>
parents:
2050
diff
changeset
|
1409 |
7bfa97e533ac
quick frontend(QuickApp): added getDefaultAvatar method:
Goffi <goffi@goffi.org>
parents:
2050
diff
changeset
|
1410 must be implemented by frontend |
7bfa97e533ac
quick frontend(QuickApp): added getDefaultAvatar method:
Goffi <goffi@goffi.org>
parents:
2050
diff
changeset
|
1411 @param entity(jid.JID): entity for which a default avatar is needed |
7bfa97e533ac
quick frontend(QuickApp): added getDefaultAvatar method:
Goffi <goffi@goffi.org>
parents:
2050
diff
changeset
|
1412 """ |
7bfa97e533ac
quick frontend(QuickApp): added getDefaultAvatar method:
Goffi <goffi@goffi.org>
parents:
2050
diff
changeset
|
1413 raise NotImplementedError |
7bfa97e533ac
quick frontend(QuickApp): added getDefaultAvatar method:
Goffi <goffi@goffi.org>
parents:
2050
diff
changeset
|
1414 |
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
|
1415 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
|
1416 log.info("disconnecting") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1417 self.callListeners("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
|
1418 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
|
1419 |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
1420 def onExit(self): |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
1421 """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
|
1422 to_unplug = [] |
3028 | 1423 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
|
1424 if profile_manager.connected and profile_manager.autodisconnect: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2618
diff
changeset
|
1425 # The user wants autodisconnection |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
1426 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
|
1427 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
|
1428 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
|
1429 self.unplug_profile(profile) |