Mercurial > libervia-backend
annotate frontends/src/quick_frontend/quick_app.py @ 2097:4bc408b549cd
quick_frontend(QuickApp): added onBridgeConnected method
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 18 Dec 2016 16:28:46 +0100 |
parents | f413bfc24458 |
children | 071423b3a413 |
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 |
1766 | 5 # Copyright (C) 2009-2016 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 |
d1084f7e56a5
quick_frontend: use of new logging system
Goffi <goffi@goffi.org>
parents:
955
diff
changeset
|
21 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
|
22 |
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 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
|
24 from sat.core import exceptions |
1374
0befb14ecf62
renamed tools.misc to tools.trigger
Goffi <goffi@goffi.org>
parents:
1365
diff
changeset
|
25 from sat.tools import trigger |
2034
3f745370a39a
quick frontend (app): fixed regression in groups handling
Goffi <goffi@goffi.org>
parents:
2031
diff
changeset
|
26 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
|
27 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
28 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
|
29 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
|
30 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
|
31 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
|
32 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
|
33 from sat_frontends.quick_frontend import quick_contact_list |
1019 | 34 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
|
35 |
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
|
36 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
|
37 from collections import OrderedDict |
1972
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
38 import time |
906
1cbae66fa725
quick_app: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
39 |
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
|
40 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
|
41 # FIXME: to be removed when an acceptable solution is here |
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 unicode('') # XXX: unicode doesn't exist in pyjamas |
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
|
43 except (TypeError, AttributeError): # Error raised is not the same depending on pyjsbuild options |
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
|
44 unicode = str |
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
|
45 |
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
|
46 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
47 class ProfileManager(object): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
48 """Class managing all data relative to one profile, and plugging in mechanism""" |
2050
046449cc2bff
core, bridge, frontends: removed deprecated bridge method askConfirmation, confirmationAnswer, actionResult, actionResultExt and getWaitingConf
Goffi <goffi@goffi.org>
parents:
2049
diff
changeset
|
49 # 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
|
50 # 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
|
51 host = None |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
52 bridge = None |
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
|
53 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
|
54 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
55 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
|
56 self.profile = profile |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
57 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
|
58 self.whoami = None |
1972
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
59 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
|
60 |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
61 @property |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
62 def autodisconnect(self): |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
63 try: |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
64 autodisconnect = self._autodisconnect |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
65 except AttributeError: |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
66 autodisconnect = False |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
67 return autodisconnect |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
68 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
69 def plug(self): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
70 """Plug the profile to the host""" |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
71 # we get the essential params |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
72 self.bridge.asyncGetParamA("JabberID", "Connection", profile_key=self.profile, |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
73 callback=self._plug_profile_jid, errback=self._getParamError) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
74 |
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
|
75 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
|
76 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
|
77 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
|
78 |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
79 def _plug_profile_isconnected(self, connected): |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
80 self.connected = connected |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
81 self.bridge.asyncGetParamA("autodisconnect", "Connection", profile_key=self.profile, |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
82 callback=self._plug_profile_autodisconnect, errback=self._getParamError) |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
83 |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
84 def _plug_profile_autodisconnect(self, autodisconnect): |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
85 if C.bool(autodisconnect): |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
86 self._autodisconnect = True |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
87 self.bridge.asyncGetParamA("autoconnect", "Connection", profile_key=self.profile, |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
88 callback=self._plug_profile_autoconnect, errback=self._getParamError) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
89 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
90 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
|
91 autoconnect = C.bool(value_str) |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
92 if autoconnect and not self.connected: |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
93 self.host.asyncConnect(self.profile, callback=lambda dummy: 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
|
94 else: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
95 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
|
96 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
97 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
|
98 # 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
|
99 # we get cached data |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
100 self.connected = True |
1655
ad2ad28b8923
quick_frontend: getFeatures is called on profile plug, and saved in host.features
Goffi <goffi@goffi.org>
parents:
1636
diff
changeset
|
101 self.host.bridge.getFeatures(profile_key=self.profile, callback=self._plug_profile_getFeaturesCb, errback=self._plug_profile_getFeaturesEb) |
ad2ad28b8923
quick_frontend: getFeatures is called on profile plug, and saved in host.features
Goffi <goffi@goffi.org>
parents:
1636
diff
changeset
|
102 |
ad2ad28b8923
quick_frontend: getFeatures is called on profile plug, and saved in host.features
Goffi <goffi@goffi.org>
parents:
1636
diff
changeset
|
103 def _plug_profile_getFeaturesEb(self, failure): |
ad2ad28b8923
quick_frontend: getFeatures is called on profile plug, and saved in host.features
Goffi <goffi@goffi.org>
parents:
1636
diff
changeset
|
104 log.error(u"Couldn't get features: {}".format(failure)) |
ad2ad28b8923
quick_frontend: getFeatures is called on profile plug, and saved in host.features
Goffi <goffi@goffi.org>
parents:
1636
diff
changeset
|
105 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
|
106 |
ad2ad28b8923
quick_frontend: getFeatures is called on profile plug, and saved in host.features
Goffi <goffi@goffi.org>
parents:
1636
diff
changeset
|
107 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
|
108 self.host.features = features |
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
|
109 self.host.bridge.getEntitiesData([], ProfileManager.cache_keys_to_get, profile=self.profile, callback=self._plug_profile_gotCachedValues, errback=self._plug_profile_failedCachedValues) |
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
|
110 |
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
|
111 def _plug_profile_failedCachedValues(self, failure): |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1397
diff
changeset
|
112 log.error(u"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
|
113 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
|
114 |
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
|
115 def _plug_profile_gotCachedValues(self, cached_values): |
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
|
116 # add the contact list and its listener |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
117 contact_list = self.host.contact_lists.addProfile(self.profile) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
118 |
2059
9dd76a5b63ba
quick app(app): call entityDataUpdateHandler on profile plug instead of setCache directly
Goffi <goffi@goffi.org>
parents:
2056
diff
changeset
|
119 for entity_s, data in cached_values.iteritems(): |
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
|
120 for key, value in data.iteritems(): |
2059
9dd76a5b63ba
quick app(app): call entityDataUpdateHandler on profile plug instead of setCache directly
Goffi <goffi@goffi.org>
parents:
2056
diff
changeset
|
121 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
|
122 |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
123 if not self.connected: |
1417
176de79c8c39
core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
124 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
|
125 else: |
1429
798e5e38516b
quick_frontend (quick_app): properly fixed roster loss:
Goffi <goffi@goffi.org>
parents:
1418
diff
changeset
|
126 |
798e5e38516b
quick_frontend (quick_app): properly fixed roster loss:
Goffi <goffi@goffi.org>
parents:
1418
diff
changeset
|
127 contact_list.fill() |
1417
176de79c8c39
core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
128 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
|
129 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
130 #The waiting subscription requests |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
131 self.bridge.getWaitingSub(self.profile, callback=self._plug_profile_gotWaitingSub) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
132 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
133 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
|
134 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
|
135 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
|
136 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
137 self.bridge.mucGetRoomsJoined(self.profile, callback=self._plug_profile_gotRoomsJoined) |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
138 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
139 def _plug_profile_gotRoomsJoined(self, rooms_args): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
140 #Now we open the MUC window where we already are: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
141 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
|
142 self.host.mucRoomJoinedHandler(*room_args, profile=self.profile) |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
143 #Presence must be requested after rooms are filled |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
144 self.host.bridge.getPresenceStatuses(self.profile, callback=self._plug_profile_gotPresences) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
145 |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
146 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
|
147 def gotEntityData(data, contact): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
148 for key in ('avatar', 'nick'): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
149 if key in data: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
150 self.host.entityDataUpdatedHandler(contact, key, data[key], self.profile) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
151 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
152 for contact in presences: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
153 for res in presences[contact]: |
2031
48a61879f9ef
quick frontend (QuickApp): unicode string fix
Goffi <goffi@goffi.org>
parents:
2024
diff
changeset
|
154 jabber_id = (u'%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
|
155 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
|
156 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
|
157 statuses = presences[contact][res][2] |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
158 self.host.presenceUpdateHandler(jabber_id, show, priority, statuses, self.profile) |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1397
diff
changeset
|
159 self.host.bridge.getEntityData(contact, ['avatar', 'nick'], self.profile, callback=lambda data, contact=contact: gotEntityData(data, contact), errback=lambda failure, contact=contact: log.debug(u"No cache data for {}".format(contact))) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
160 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
161 # 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
|
162 # 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
|
163 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
|
164 |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
165 def _getParamError(self, failure): |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
166 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
|
167 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
168 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
169 class ProfilesManager(object): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
170 """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
|
171 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
172 def __init__(self): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
173 self._profiles = {} |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
174 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
175 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
|
176 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
|
177 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
178 def __iter__(self): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
179 return self._profiles.iterkeys() |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
180 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
181 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
|
182 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
|
183 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
184 def __len__(self): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
185 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
|
186 |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
187 def iteritems(self): |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
188 return self._profiles.iteritems() |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
189 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
190 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
|
191 if 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
|
192 raise exceptions.ConflictError('A profile of the name [{}] is already plugged'.format(profile)) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
193 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
|
194 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
|
195 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
196 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
|
197 if profile not in self._profiles: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
198 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
|
199 |
0f92b6a150ff
quick_frontend, primitivus: use a listener to update the contact list when receiving a presence
souliane <souliane@mailoo.org>
parents:
1331
diff
changeset
|
200 # 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
|
201 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
|
202 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
|
203 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
204 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
|
205 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
206 def chooseOneProfile(self): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
207 return self._profiles.keys()[0] |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
208 |
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
|
209 |
524
0bb595eff25b
primitivus: Primitivus is now modal (vi-like behaviour):
Goffi <goffi@goffi.org>
parents:
513
diff
changeset
|
210 class QuickApp(object): |
0 | 211 """This class contain the main methods needed for the frontend""" |
2067
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
212 MB_HANDLER = True # Set to False if the frontend doesn't manage microblog |
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
213 AVATARS_HANDLER = True # set to False if avatars are not used |
0 | 214 |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
215 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
|
216 """Create a frontend application |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
217 |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
218 @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
|
219 @param xmlui: xmlui module |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
220 @param check_options: method to call to check options (usually command line arguments) |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
221 """ |
1468
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1461
diff
changeset
|
222 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
|
223 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
|
224 ProfileManager.host = self |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
225 self.profiles = ProfilesManager() |
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
|
226 self._plugs_in_progress = set() # profiles currently being plugged, used to (un)lock contact list updates |
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
|
227 self.ready_profiles = set() # profiles which are connected 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
|
228 self.signals_cache = {} # used to keep signal received between start of 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
|
229 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
|
230 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
|
231 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
|
232 self.options = check_options() |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
233 else: |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
234 self.options = None |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
235 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
236 # widgets |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
237 self.selected_widget = None # widget currently selected (must be filled by frontend) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
238 |
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
|
239 # listeners |
1323
a599b6a70dc0
frontends (quick_frontend): fixes a typo (listerner --> listener)
souliane <souliane@mailoo.org>
parents:
1319
diff
changeset
|
240 self._listeners = {} # key: listener type ("avatar", "selected", etc), 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
|
241 |
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
|
242 # triggers |
1374
0befb14ecf62
renamed tools.misc to tools.trigger
Goffi <goffi@goffi.org>
parents:
1365
diff
changeset
|
243 self.trigger = trigger.TriggerManager() # 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
|
244 |
0 | 245 ## bridge ## |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
246 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
|
247 ProfileManager.bridge = self.bridge |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
248 if connect_bridge: |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
249 self.connectBridge() |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
250 |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
251 self._notif_id = 0 |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
252 self._notifications = OrderedDict() |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
253 self.features = None |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
254 |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
255 def connectBridge(self): |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
256 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
|
257 |
2097
4bc408b549cd
quick_frontend(QuickApp): added onBridgeConnected method
Goffi <goffi@goffi.org>
parents:
2091
diff
changeset
|
258 def onBridgeConnected(self): |
4bc408b549cd
quick_frontend(QuickApp): added onBridgeConnected method
Goffi <goffi@goffi.org>
parents:
2091
diff
changeset
|
259 pass |
4bc408b549cd
quick_frontend(QuickApp): added onBridgeConnected method
Goffi <goffi@goffi.org>
parents:
2091
diff
changeset
|
260 |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
261 def _bridgeCb(self): |
1103
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
262 self.registerSignal("connected") |
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
263 self.registerSignal("disconnected") |
1468
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1461
diff
changeset
|
264 self.registerSignal("actionNew") |
1103
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
265 self.registerSignal("newContact") |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1939
diff
changeset
|
266 self.registerSignal("messageNew") |
1103
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
267 self.registerSignal("presenceUpdate") |
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
268 self.registerSignal("subscribe") |
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
269 self.registerSignal("paramUpdate") |
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
270 self.registerSignal("contactDeleted") |
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
271 self.registerSignal("entityDataUpdated") |
1636 | 272 self.registerSignal("progressStarted") |
273 self.registerSignal("progressFinished") | |
274 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
|
275 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
|
276 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
|
277 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
|
278 self.registerSignal("mucRoomNewSubject", iface="plugin") |
1103
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
279 self.registerSignal("chatStateReceived", iface="plugin") |
2024
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2016
diff
changeset
|
280 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
|
281 self.registerSignal("psEvent", iface="plugin") |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
282 |
1360
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1352
diff
changeset
|
283 # FIXME: do it dynamically |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1352
diff
changeset
|
284 quick_games.Tarot.registerSignals(self) |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1352
diff
changeset
|
285 quick_games.Quiz.registerSignals(self) |
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1352
diff
changeset
|
286 quick_games.Radiocol.registerSignals(self) |
2097
4bc408b549cd
quick_frontend(QuickApp): added onBridgeConnected method
Goffi <goffi@goffi.org>
parents:
2091
diff
changeset
|
287 self.onBridgeConnected() |
1360
8ea8fa13c351
frontends (quick_frontend, primitivus): fixes room games:
souliane <souliane@mailoo.org>
parents:
1352
diff
changeset
|
288 |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
289 def _bridgeEb(self, failure): |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
290 if isinstance(failure, exceptions.BridgeExceptionNoService): |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
291 print(_(u"Can't connect to SàT backend, are you sure it's launched ?")) |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
292 sys.exit(1) |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
293 elif isinstance(failure, exceptions.BridgeInitError): |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
294 print(_(u"Can't init bridge")) |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
295 sys.exit(1) |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
296 else: |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
297 print(_(u"Error while initialising bridge: {}".format(failure))) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
298 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
299 @property |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
300 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
|
301 """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
|
302 try: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
303 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
|
304 except (TypeError, AttributeError): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
305 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
|
306 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
307 @property |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
308 def visible_widgets(self): |
2049
b67aece4a667
quick frontend (app): avatar filename is not requested anymore if value is empty
Goffi <goffi@goffi.org>
parents:
2042
diff
changeset
|
309 """widgets currently visible (must be implemented by frontend) |
b67aece4a667
quick frontend (app): avatar filename is not requested anymore if value is empty
Goffi <goffi@goffi.org>
parents:
2042
diff
changeset
|
310 |
b67aece4a667
quick frontend (app): avatar filename is not requested anymore if value is empty
Goffi <goffi@goffi.org>
parents:
2042
diff
changeset
|
311 @return (iter[QuickWidget]): iterable on visible widgets |
b67aece4a667
quick frontend (app): avatar filename is not requested anymore if value is empty
Goffi <goffi@goffi.org>
parents:
2042
diff
changeset
|
312 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
313 raise NotImplementedError |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
314 |
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
|
315 def registerSignal(self, function_name, handler=None, iface="core", with_profile=True): |
1103
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
316 """Register a handler for a signal |
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
317 |
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
|
318 @param function_name (str): name of the signal to handle |
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
|
319 @param handler (instancemethod): method to call when the signal arrive, 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
|
320 @param iface (str): interface of the bridge to use ('core' or 'plugin') |
6053fb8a6466
quick_frontend: fixes an issue with the profile in the signal handler
souliane <souliane@mailoo.org>
parents:
1103
diff
changeset
|
321 @param with_profile (boolean): True if the signal concerns a specific profile, 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
|
322 """ |
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
323 if handler is None: |
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
|
324 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
|
325 if not with_profile: |
2086 | 326 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
|
327 return |
6053fb8a6466
quick_frontend: fixes an issue with the profile in the signal handler
souliane <souliane@mailoo.org>
parents:
1103
diff
changeset
|
328 |
1103
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
329 def signalReceived(*args, **kwargs): |
1117
6053fb8a6466
quick_frontend: fixes an issue with the profile in the signal handler
souliane <souliane@mailoo.org>
parents:
1103
diff
changeset
|
330 profile = kwargs.get('profile') |
6053fb8a6466
quick_frontend: fixes an issue with the profile in the signal handler
souliane <souliane@mailoo.org>
parents:
1103
diff
changeset
|
331 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
|
332 if not args: |
6053fb8a6466
quick_frontend: fixes an issue with the profile in the signal handler
souliane <souliane@mailoo.org>
parents:
1103
diff
changeset
|
333 raise exceptions.ProfileNotSetError |
6053fb8a6466
quick_frontend: fixes an issue with the profile in the signal handler
souliane <souliane@mailoo.org>
parents:
1103
diff
changeset
|
334 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
|
335 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
|
336 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
|
337 if profile in self.profiles: |
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
|
338 # profile is not ready but is in self.profiles, that's mean that it's being connecting and we need to cache the signal |
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
|
339 self.signals_cache.setdefault(profile, []).append((function_name, handler, args, kwargs)) |
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
|
340 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
|
341 handler(*args, **kwargs) |
2086 | 342 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
|
343 |
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
|
344 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
|
345 """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
|
346 |
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
|
347 /!\ don't forget to remove listener when not used anymore (e.g. if you delete a widget) |
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
|
348 @param type_: type of event, can be: |
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
|
349 - 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
|
350 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
|
351 - 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
|
352 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
|
353 - 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
|
354 args: (entity, show, priority, statuses, profile) |
1972
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
355 - notification: called when a new notification is emited |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
356 args: (entity, notification_data, profile) |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
357 - notification_clear: called when notifications are cleared |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
358 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
|
359 - 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
|
360 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
|
361 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
|
362 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
|
363 path_i18n: translated path (or None if the item is 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
|
364 item: instance of quick_menus.MenuItemBase or None if the item is 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
|
365 - gotMenus: called only once when menu are available (no arg) |
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
|
366 @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
|
367 @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
|
368 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
|
369 """ |
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
|
370 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
|
371 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
|
372 |
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
|
373 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
|
374 """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
|
375 |
1323
a599b6a70dc0
frontends (quick_frontend): fixes a typo (listerner --> listener)
souliane <souliane@mailoo.org>
parents:
1319
diff
changeset
|
376 @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
|
377 @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
|
378 """ |
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
|
379 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
|
380 self._listeners[type_].pop(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
|
381 |
1338
139263ee85c5
quick frontends: fixed use of profile for listeners
Goffi <goffi@goffi.org>
parents:
1337
diff
changeset
|
382 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
|
383 """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
|
384 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
|
385 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
|
386 |
1323
a599b6a70dc0
frontends (quick_frontend): fixes a typo (listerner --> listener)
souliane <souliane@mailoo.org>
parents:
1319
diff
changeset
|
387 @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
|
388 @param *args: arguments sent to callback |
1338
139263ee85c5
quick frontends: fixed use of profile for listeners
Goffi <goffi@goffi.org>
parents:
1337
diff
changeset
|
389 @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
|
390 """ |
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
|
391 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
|
392 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
|
393 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
|
394 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
|
395 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
|
396 else: |
1338
139263ee85c5
quick frontends: fixed use of profile for listeners
Goffi <goffi@goffi.org>
parents:
1337
diff
changeset
|
397 profile = kwargs.get("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
|
398 for listener, profiles_filter in listeners.iteritems(): |
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
|
399 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
|
400 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
|
401 |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
402 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
|
403 """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
|
404 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
|
405 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
406 def postInit(self, profile_manager): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
407 """Must be called after initialization is done, do all automatic task (auto plug profile) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
408 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
409 @param profile_manager: instance of a subclass of Quick_frontend.QuickProfileManager |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
410 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
411 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
|
412 profile_manager.autoconnect([self.options.profile]) |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
117
diff
changeset
|
413 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
414 def profilePlugged(self, profile): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
415 """Method called when the profile is fully plugged, to launch frontend specific workflow |
91 | 416 |
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
|
417 /!\ if you override the method and don't call the parent, be sure to add the profile to ready_profiles ! |
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
|
418 if you don't, all signals will stay in 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
|
419 |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
420 @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
|
421 """ |
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
|
422 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
|
423 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
|
424 |
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
|
425 # 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
|
426 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
|
427 for function_name, handler, args, kwargs in cached_signals: |
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
|
428 log.debug(u"Calling cached signal [%s] with args %s and kwargs %s" % (function_name, args, kwargs)) |
1393
50d5d6325f62
quick_frontend, primitivus: various fixes (MUC and cached signals):
souliane <souliane@mailoo.org>
parents:
1391
diff
changeset
|
429 handler(*args, **kwargs) |
91 | 430 |
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
|
431 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
|
432 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
|
433 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
|
434 |
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
|
435 def asyncConnect(self, profile, callback=None, errback=None): |
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
|
436 if not callback: |
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
|
437 callback = lambda dummy: None |
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
|
438 if not errback: |
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
|
439 def errback(failure): |
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
|
440 log.error(_(u"Can't connect profile [%s]") % failure) |
2089
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
441 try: |
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
442 module = failure.module |
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
443 except AttributeError: |
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
444 module = '' |
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
445 try: |
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
446 message = failure.message |
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
447 except AttributeError: |
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
448 message = 'error' |
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
449 try: |
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
450 fullname = failure.fullname |
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
451 except AttributeError: |
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
452 fullname = 'error' |
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
453 if module.startswith('twisted.words.protocols.jabber') and failure.condition == "not-authorized": |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
454 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
|
455 else: |
2089
0931b5a6213c
core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents:
2086
diff
changeset
|
456 self.showDialog(message, fullname, 'error') |
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
|
457 self.bridge.asyncConnect(profile, callback=callback, errback=errback) |
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
|
458 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
459 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
|
460 """Tell application which profiles must be used |
0 | 461 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
462 @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
|
463 """ |
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
|
464 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
|
465 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
|
466 self.plugging_profiles() |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
467 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
|
468 self.profiles.plug(profile) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
469 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
470 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
|
471 """Method to subclass to manage frontend specific things to do |
0 | 472 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
473 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
|
474 """ |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
475 pass |
542
3eeb6c865e4d
frontends: incoming files transfer management:
Goffi <goffi@goffi.org>
parents:
538
diff
changeset
|
476 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
477 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
|
478 """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
|
479 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
|
480 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
|
481 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
|
482 |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
483 def clear_profile(self): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
484 self.profiles.clear() |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
485 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
486 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
|
487 raise NotImplementedError |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
488 |
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
|
489 def connectedHandler(self, profile, 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
|
490 """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
|
491 |
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
|
492 @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
|
493 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
|
494 """ |
1009
d1084f7e56a5
quick_frontend: use of new logging system
Goffi <goffi@goffi.org>
parents:
955
diff
changeset
|
495 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
|
496 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
|
497 self.setPresenceStatus(profile=profile) |
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
|
498 self.contact_lists[profile].fill() |
52 | 499 |
1103
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
500 def disconnectedHandler(self, profile): |
52 | 501 """called when the connection is closed""" |
1009
d1084f7e56a5
quick_frontend: use of new logging system
Goffi <goffi@goffi.org>
parents:
955
diff
changeset
|
502 log.debug(_("Disconnected")) |
1938
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
503 self.contact_lists[profile].disconnect() |
1417
176de79c8c39
core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
504 self.setPresenceStatus(C.PRESENCE_UNAVAILABLE, '', profile=profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
505 |
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
|
506 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
|
507 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
|
508 |
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
|
509 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
|
510 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
|
511 groups = list(groups) |
011eff37e21d
quick frontend, primitivus: quickContactList refactored to handle several profiles at once
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
512 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
|
513 |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1939
diff
changeset
|
514 def messageNewHandler(self, uid, timestamp, from_jid_s, to_jid_s, msg, subject, type_, extra, profile): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
515 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
|
516 to_jid = jid.JID(to_jid_s) |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1939
diff
changeset
|
517 if not self.trigger.point("messageNewTrigger", uid, timestamp, from_jid, to_jid, msg, subject, type_, 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
|
518 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
|
519 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
520 from_me = from_jid.bare == self.profiles[profile].whoami.bare |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
521 target = to_jid if from_me else from_jid |
1336
2ecc07a8f91b
primitivus, quick_frontends: moved newMessage signal handler to quick_frontend
Goffi <goffi@goffi.org>
parents:
1319
diff
changeset
|
522 contact_list = self.contact_lists[profile] |
2040
f607349a01a4
quick frontend (chat): fixed messageNew signal dispatching when several widgets are handling the target
Goffi <goffi@goffi.org>
parents:
2036
diff
changeset
|
523 # we want to be sure to have at least one QuickChat instance |
f607349a01a4
quick frontend (chat): fixed messageNew signal dispatching when several widgets are handling the target
Goffi <goffi@goffi.org>
parents:
2036
diff
changeset
|
524 self.widgets.getOrCreateWidget(quick_chat.QuickChat, target, type_=C.CHAT_ONE2ONE, on_new_widget=None, profile=profile) |
510
886754295efe
quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
507
diff
changeset
|
525 |
1336
2ecc07a8f91b
primitivus, quick_frontends: moved newMessage signal handler to quick_frontend
Goffi <goffi@goffi.org>
parents:
1319
diff
changeset
|
526 if not from_jid in contact_list and from_jid.bare != self.profiles[profile].whoami.bare: |
2ecc07a8f91b
primitivus, quick_frontends: moved newMessage signal handler to quick_frontend
Goffi <goffi@goffi.org>
parents:
1319
diff
changeset
|
527 #XXX: needed to show entities which haven't sent any |
2ecc07a8f91b
primitivus, quick_frontends: moved newMessage signal handler to quick_frontend
Goffi <goffi@goffi.org>
parents:
1319
diff
changeset
|
528 # 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
|
529 contact_list.setContact(from_jid) |
2ecc07a8f91b
primitivus, quick_frontends: moved newMessage signal handler to quick_frontend
Goffi <goffi@goffi.org>
parents:
1319
diff
changeset
|
530 |
2040
f607349a01a4
quick frontend (chat): fixed messageNew signal dispatching when several widgets are handling the target
Goffi <goffi@goffi.org>
parents:
2036
diff
changeset
|
531 # we dispatch the message in the widgets |
f607349a01a4
quick frontend (chat): fixed messageNew signal dispatching when several widgets are handling the target
Goffi <goffi@goffi.org>
parents:
2036
diff
changeset
|
532 for widget in self.widgets.getWidgets(quick_chat.QuickChat, target=target, profiles=(profile,)): |
f607349a01a4
quick frontend (chat): fixed messageNew signal dispatching when several widgets are handling the target
Goffi <goffi@goffi.org>
parents:
2036
diff
changeset
|
533 widget.messageNew(uid, timestamp, from_jid, target, msg, subject, type_, extra, profile) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
534 |
2024
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2016
diff
changeset
|
535 def messageStateHandler(self, uid, status, profile): |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2016
diff
changeset
|
536 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
|
537 widget.onMessageState(uid, status, profile) |
01aff34e8873
quick frontends, primitivus: messageState signal handling
Goffi <goffi@goffi.org>
parents:
2016
diff
changeset
|
538 |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1939
diff
changeset
|
539 def messageSend(self, to_jid, message, subject=None, mess_type="auto", extra=None, callback=None, errback=None, profile_key=C.PROF_KEY_NONE): |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1939
diff
changeset
|
540 if subject is None: |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1939
diff
changeset
|
541 subject = {} |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1939
diff
changeset
|
542 if extra is None: |
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1939
diff
changeset
|
543 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
|
544 if callback is None: |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
545 callback = lambda dummy=None: None # FIXME: optional argument is here because pyjamas doesn't support callback 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
|
546 if errback is None: |
1063
6ec513ad92c2
frontends: async failures are more detailed (full class name + error message)
souliane <souliane@mailoo.org>
parents:
1060
diff
changeset
|
547 errback = lambda failure: self.showDialog(failure.fullname, failure.message, "error") |
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
|
548 |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1939
diff
changeset
|
549 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
|
550 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
|
551 |
1955
633b5c21aefd
backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents:
1939
diff
changeset
|
552 self.bridge.messageSend(unicode(to_jid), message, subject, mess_type, extra, profile_key, callback=callback, errback=errback) |
0 | 553 |
1417
176de79c8c39
core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
554 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
|
555 raise NotImplementedError |
0 | 556 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
557 def presenceUpdateHandler(self, entity_s, show, priority, statuses, profile): |
737
378af36155c2
frontends: set and retrieve your own presence and status
souliane <souliane@mailoo.org>
parents:
736
diff
changeset
|
558 |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1397
diff
changeset
|
559 log.debug(_(u"presence update for %(entity)s (show=%(show)s, priority=%(priority)s, statuses=%(statuses)s) [profile:%(profile)s]") |
1417
176de79c8c39
core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
560 % {'entity': entity_s, C.PRESENCE_SHOW: show, C.PRESENCE_PRIORITY: priority, C.PRESENCE_STATUSES: statuses, 'profile': profile}) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
561 entity = jid.JID(entity_s) |
0 | 562 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
563 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
|
564 if show == C.PRESENCE_UNAVAILABLE: |
176de79c8c39
core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
565 self.setPresenceStatus(C.PRESENCE_UNAVAILABLE, '', profile=profile) |
735
682933ca304c
frontends: presence update in quick app:
souliane <souliane@mailoo.org>
parents:
698
diff
changeset
|
566 else: |
1417
176de79c8c39
core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
567 # 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
|
568 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
|
569 self.setPresenceStatus(show, status, profile=profile) |
0 | 570 return |
571 | |
1338
139263ee85c5
quick frontends: fixed use of profile for listeners
Goffi <goffi@goffi.org>
parents:
1337
diff
changeset
|
572 self.callListeners('presence', entity, show, priority, statuses, profile=profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
573 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
574 def mucRoomJoinedHandler(self, room_jid_s, occupants, user_nick, subject, profile): |
72 | 575 """Called when a MUC room is joined""" |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
576 log.debug(u"Room [{room_jid}] joined by {profile}, users presents:{users}".format(room_jid=room_jid_s, profile=profile, users=occupants.keys())) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
577 room_jid = jid.JID(room_jid_s) |
2066
09c18fcd8225
plugin XEP-0045, quick frontend (app,chat): various chat improvments:
Goffi <goffi@goffi.org>
parents:
2061
diff
changeset
|
578 self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, nick=user_nick, occupants=occupants, subject=subject, profile=profile) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
579 self.contact_lists[profile].setSpecial(room_jid, C.CONTACT_SPECIAL_GROUP) |
1963
a2bc5089c2eb
backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents:
1955
diff
changeset
|
580 # chat_widget.update() |
72 | 581 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
582 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
|
583 """Called when a MUC room is left""" |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1397
diff
changeset
|
584 log.debug(u"Room [%(room_jid)s] left by %(profile)s" % {'room_jid': room_jid_s, 'profile': profile}) |
1351
ec43552f5f8b
quick_frontend: replace last occurences of QuickApp.chat_wins with QuickApp.widgets
souliane <souliane@mailoo.org>
parents:
1348
diff
changeset
|
585 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
|
586 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
|
587 if chat_widget: |
ec43552f5f8b
quick_frontend: replace last occurences of QuickApp.chat_wins with QuickApp.widgets
souliane <souliane@mailoo.org>
parents:
1348
diff
changeset
|
588 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
|
589 self.contact_lists[profile].removeContact(room_jid) |
72 | 590 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
591 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
|
592 """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
|
593 room_jid = jid.JID(room_jid_s) |
1351
ec43552f5f8b
quick_frontend: replace last occurences of QuickApp.chat_wins with QuickApp.widgets
souliane <souliane@mailoo.org>
parents:
1348
diff
changeset
|
594 chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, profile=profile) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
595 chat_widget.changeUserNick(old_nick, new_nick) |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1397
diff
changeset
|
596 log.debug(u"user [%(old_nick)s] is now known as [%(new_nick)s] in room [%(room_jid)s]" % {'old_nick': old_nick, 'new_nick': new_nick, 'room_jid': room_jid}) |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
504
diff
changeset
|
597 |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1963
diff
changeset
|
598 def mucRoomNewSubjectHandler(self, room_jid_s, subject, profile): |
76 | 599 """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
|
600 room_jid = jid.JID(room_jid_s) |
1351
ec43552f5f8b
quick_frontend: replace last occurences of QuickApp.chat_wins with QuickApp.widgets
souliane <souliane@mailoo.org>
parents:
1348
diff
changeset
|
601 chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, profile=profile) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
602 chat_widget.setSubject(subject) |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1397
diff
changeset
|
603 log.debug(u"new subject for room [%(room_jid)s]: %(subject)s" % {'room_jid': room_jid, "subject": subject}) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
604 |
1103
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
605 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
|
606 """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
|
607 |
1378
3dae6964c071
quick_frontends, primitivus: move the chat states logic to quick_frontend
souliane <souliane@mailoo.org>
parents:
1377
diff
changeset
|
608 @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
|
609 @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
|
610 @param profile (unicode): current profile |
907
cd02f5ef30df
primitivus: display chat states (with symbols) for MUC participants
souliane <souliane@mailoo.org>
parents:
906
diff
changeset
|
611 """ |
2007
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1972
diff
changeset
|
612 from_jid = jid.JID(from_jid_s) |
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1972
diff
changeset
|
613 for widget in self.widgets.getWidgets(quick_chat.QuickChat, profiles=(profile,)): |
19b9d3f8a6c7
plugin XEP-0085, quick_frontends, primitivus: chat states are working again
Goffi <goffi@goffi.org>
parents:
1972
diff
changeset
|
614 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
|
615 |
1972
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
616 def notify(self, type_, entity=None, message=None, subject=None, callback=None, cb_args=None, widget=None, profile=C.PROF_KEY_NONE): |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
617 """Trigger an event notification |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
618 |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
619 @param type_(unicode): notifation kind, |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
620 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
|
621 @param entity(jid.JID, None): entity involved in the notification |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
622 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
|
623 @param message(unicode, None): message of the notification |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
624 @param subject(unicode, None): subject of the notification |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
625 @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
|
626 @param cb_args(list, None): list of args for callback |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
627 @param widget(object, None): widget where the notification happened |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
628 """ |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
629 notif_dict = self.profiles[profile].notifications |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
630 key = '' if entity is None else entity.bare |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
631 type_notifs = notif_dict.setdefault(key, {}).setdefault(type_, []) |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
632 notif_data = { |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
633 'id': self._notif_id, |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
634 'time': time.time(), |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
635 'entity': entity, |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
636 'callback': callback, |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
637 'cb_args': cb_args, |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
638 'message': message, |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
639 'subject': subject, |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
640 } |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
641 if widget is not None: |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
642 notif_data[widget] = widget |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
643 type_notifs.append(notif_data) |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
644 self._notifications[self._notif_id] = notif_data |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
645 self.callListeners('notification', entity, notif_data, profile=profile) |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
646 |
2016
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
647 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
|
648 """return notifications for given entity |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
649 |
2016
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
650 @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
|
651 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
|
652 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
|
653 C.ENTITY_ALL to get all notifications |
1972
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
654 @param type_(unicode, None): notification type to filter |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
655 None to get all notifications |
2016
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
656 @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
|
657 exact entity jid (i.e. not including other resources) |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
658 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
|
659 False to get resources notifications |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
660 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
|
661 @return (iter[dict]): notifications |
1972
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
662 """ |
2016
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
663 main_notif_dict = self.profiles[profile].notifications |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
664 |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
665 if entity is C.ENTITY_ALL: |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
666 selected_notifs = main_notif_dict.itervalues() |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
667 exact_jid = False |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
668 else: |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
669 if entity is None: |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
670 key = '' |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
671 exact_jid = False |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
672 else: |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
673 key = entity.bare |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
674 if exact_jid is None: |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
675 exact_jid = bool(entity.resource) |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
676 selected_notifs = (main_notif_dict.setdefault(key, {}),) |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
677 |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
678 for notifs_from_select in selected_notifs: |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
679 |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
680 if type_ is None: |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
681 type_notifs = notifs_from_select.itervalues() |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
682 else: |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
683 type_notifs = (notifs_from_select.get(type_, []),) |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
684 |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
685 for notifs in type_notifs: |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
686 for notif in notifs: |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
687 if exact_jid and notif['entity'] != entity: |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
688 continue |
f09562b0704d
quick_frontend, primitivus: better notifications handling
Goffi <goffi@goffi.org>
parents:
2009
diff
changeset
|
689 yield notif |
1972
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
690 |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
691 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
|
692 """return notifications for given entity |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
693 |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
694 @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
|
695 None to clear general notifications (but keep entities ones) |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
696 @param type_(unicode, None): notification type to filter |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
697 None to clear all notifications |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
698 @return (list[dict]): list of notifications |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
699 """ |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
700 notif_dict = self.profiles[profile].notifications |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
701 key = '' if entity is None else entity.bare |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
702 try: |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
703 if type_ is None: |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
704 del notif_dict[key] |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
705 else: |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
706 del notif_dict[key][type_] |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
707 except KeyError: |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
708 return |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
709 self.callListeners('notificationsClear', entity, type_, profile=profile) |
02d21a589be2
quick_frontend, primitivus: notifications refactoring
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
710 |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
711 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
|
712 """Called when a PubSub event is received. |
1352
56c14cb29e0f
quick_frontend: register the 'personalEvent' signal
souliane <souliane@mailoo.org>
parents:
1351
diff
changeset
|
713 |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
714 @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
|
715 @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
|
716 @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
|
717 @param event_type (unicode): event type (one of C.PUBLISH, C.RETRACT, C.DELETE) |
1352
56c14cb29e0f
quick_frontend: register the 'personalEvent' signal
souliane <souliane@mailoo.org>
parents:
1351
diff
changeset
|
718 @param data (dict): event data |
56c14cb29e0f
quick_frontend: register the 'personalEvent' signal
souliane <souliane@mailoo.org>
parents:
1351
diff
changeset
|
719 """ |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
720 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
|
721 |
2067
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
722 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
|
723 if event_type == C.PS_PUBLISH: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
724 if not 'content' in data: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
725 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
|
726 return |
2034
3f745370a39a
quick frontend (app): fixed regression in groups handling
Goffi <goffi@goffi.org>
parents:
2031
diff
changeset
|
727 _groups = set(data_format.dict2iter('group', data)) or None # FIXME: check if [] make sense (instead of None) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
728 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
729 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
|
730 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
|
731 |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
732 try: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
733 comments_node, comments_service = data['comments_node'], data['comments_service'] |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
734 except KeyError: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
735 pass |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
736 else: |
1513
955221487a3e
plugin XEP-0277, quick_frontend: rename mbGetLast to mbGet and add it the parameter "item_ids"
souliane <souliane@mailoo.org>
parents:
1489
diff
changeset
|
737 self.bridge.mbGet(comments_service, comments_node, C.NO_LIMIT, [], {"subscribe":C.BOOL_TRUE}, profile=profile) |
1461
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
738 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
|
739 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
|
740 wid.deleteEntryIfPresent(service_s, node, data['id'], profile) |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
741 pass |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
742 else: |
9fce331ba0fd
quick_frontend (constants, quick_app, quick_contact_list): blogging refactoring (not finished):
Goffi <goffi@goffi.org>
parents:
1442
diff
changeset
|
743 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
|
744 |
1636 | 745 def progressStartedHandler(self, pid, metadata, profile): |
746 log.info(u"Progress {} started".format(pid)) | |
747 | |
748 def progressFinishedHandler(self, pid, metadata, profile): | |
749 log.info(u"Progress {} finished".format(pid)) | |
750 | |
751 def progressErrorHandler(self, pid, err_msg, profile): | |
752 log.warning(u"Progress {pid} error: {err_msg}".format(pid=pid, err_msg=err_msg)) | |
753 | |
182
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
754 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
|
755 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
|
756 type_ = "subscribed" if answer else "unsubscribed" |
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
|
757 self.bridge.subscription(type_, unicode(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
|
758 |
1103
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
759 def subscribeHandler(self, type, raw_jid, profile): |
87 | 760 """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
|
761 entity = jid.JID(raw_jid) |
906
1cbae66fa725
quick_app: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
762 if type == "subscribed": |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
763 # 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
|
764 # TODO: call self.getEntityMBlog to add the new contact blogs |
688
f7878ad3c846
tools: renamed tools.jid.JID attribute "short" to "bare"
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
765 self.showDialog(_("The contact %s has accepted your subscription") % entity.bare, _('Subscription confirmation')) |
906
1cbae66fa725
quick_app: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
766 elif type == "unsubscribed": |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
767 # this is a subscription refusal, we just have to inform user |
688
f7878ad3c846
tools: renamed tools.jid.JID attribute "short" to "bare"
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
768 self.showDialog(_("The contact %s has refused your subscription") % entity.bare, _('Subscription refusal'), 'error') |
906
1cbae66fa725
quick_app: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
769 elif type == "subscribe": |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
770 # 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
|
771 # TODO: use sat.stdui.ui_contact_list to display the groups selector |
943
71926ec2114d
core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents:
917
diff
changeset
|
772 self.showDialog(_("The contact %s wants to subscribe to your presence.\nDo you accept ?") % entity.bare, _('Subscription confirmation'), 'yes/no', answer_cb=self._subscribe_cb, answer_data=(entity, profile)) |
0 | 773 |
1325
49f967fc87aa
core, quick_frontends: fixes one typo and a variable naming issue
souliane <souliane@mailoo.org>
parents:
1323
diff
changeset
|
774 def showDialog(self, message, title, type="info", answer_cb=None, answer_data=None): |
0 | 775 raise NotImplementedError |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
776 |
0 | 777 def showAlert(self, message): |
778 pass #FIXME | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
585
diff
changeset
|
779 |
1468
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1461
diff
changeset
|
780 def dialogFailure(self, failure): |
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1461
diff
changeset
|
781 log.warning(u"Failure: {}".format(failure)) |
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1461
diff
changeset
|
782 |
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
|
783 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
|
784 """Callback used when an action result in a progress id""" |
2071d5cec5d6
quick frontend: added progressIdHandler to managed progress id on action result + ignore meta_* action results
Goffi <goffi@goffi.org>
parents:
1599
diff
changeset
|
785 log.info(u"Progress ID received: {}".format(progress_id)) |
2071d5cec5d6
quick frontend: added progressIdHandler to managed progress id on action result + ignore meta_* action results
Goffi <goffi@goffi.org>
parents:
1599
diff
changeset
|
786 |
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
|
787 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
|
788 """Tells if the frontend window is hidden. |
1442
6ce18c4e5708
quick_frontend: display over whole alerts counter
souliane <souliane@mailoo.org>
parents:
1436
diff
changeset
|
789 |
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
|
790 @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
|
791 """ |
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
|
792 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
|
793 |
1103
a096b8579a3c
frontends: signals are managed in a more generic way
Goffi <goffi@goffi.org>
parents:
1093
diff
changeset
|
794 def paramUpdateHandler(self, name, value, namespace, profile): |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1397
diff
changeset
|
795 log.debug(_(u"param update: [%(namespace)s] %(name)s = %(value)s") % {'namespace': namespace, 'name': name, 'value': value}) |
906
1cbae66fa725
quick_app: better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
796 if (namespace, name) == ("Connection", "JabberID"): |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1397
diff
changeset
|
797 log.debug(_(u"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
|
798 self.profiles[profile].whoami = jid.JID(value) |
1229
03661d1b216a
primitivus: implement "Show offline contacts" parameter (sync with "DISCONNECTED_HIDE" action key)
souliane <souliane@mailoo.org>
parents:
1223
diff
changeset
|
799 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
|
800 self.contact_lists[profile].showOfflineContacts(C.bool(value)) |
1230
3abc6563a0d2
primitivus: implement parameter "Show empty groups"
souliane <souliane@mailoo.org>
parents:
1229
diff
changeset
|
801 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
|
802 self.contact_lists[profile].showEmptyGroups(C.bool(value)) |
0 | 803 |
1325
49f967fc87aa
core, quick_frontends: fixes one typo and a variable naming issue
souliane <souliane@mailoo.org>
parents:
1323
diff
changeset
|
804 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
|
805 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
|
806 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
|
807 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
808 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
|
809 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
|
810 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
|
811 if entity in self.contact_lists[profile]: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1241
diff
changeset
|
812 self.contact_lists[profile].setCache(entity, 'nick', value) |
1342
e31a07a5614d
quick_frontends, primitivus (contact list): added nick observer + implemented onNickUpdate
Goffi <goffi@goffi.org>
parents:
1339
diff
changeset
|
813 self.callListeners('nick', entity, value, profile=profile) |
504
65ecbb473cbb
core, quick frontend, plugin xep-0054, bridge: use of memory's entities data for vcard:
Goffi <goffi@goffi.org>
parents:
503
diff
changeset
|
814 elif key == "avatar": |
2061
748e539c5feb
quick frontend (contat list/cache): workaround for avatar issue in MUC. Need to be reworked properly in the future (TODO)
Goffi <goffi@goffi.org>
parents:
2059
diff
changeset
|
815 if value: # and entity in self.contact_lists[profile]: |
748e539c5feb
quick frontend (contat list/cache): workaround for avatar issue in MUC. Need to be reworked properly in the future (TODO)
Goffi <goffi@goffi.org>
parents:
2059
diff
changeset
|
816 # FIXME: contact_list check is removed to work around 'avatar' issues |
748e539c5feb
quick frontend (contat list/cache): workaround for avatar issue in MUC. Need to be reworked properly in the future (TODO)
Goffi <goffi@goffi.org>
parents:
2059
diff
changeset
|
817 # (avatar can't be requested if we don't save them here) |
748e539c5feb
quick frontend (contat list/cache): workaround for avatar issue in MUC. Need to be reworked properly in the future (TODO)
Goffi <goffi@goffi.org>
parents:
2059
diff
changeset
|
818 # avatar need to be refactored properly in backend and here |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
819 def gotFilename(filename): |
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
820 self.contact_lists[profile].setCache(entity, 'avatar', filename) |
1338
139263ee85c5
quick frontends: fixed use of profile for listeners
Goffi <goffi@goffi.org>
parents:
1337
diff
changeset
|
821 self.callListeners('avatar', entity, filename, profile=profile) |
1290
faa1129559b8
core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
822 self.bridge.getAvatarFile(value, callback=gotFilename) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
823 |
2036
db3bbbd745e4
frontends (xmlui): added a user_action attribute:
Goffi <goffi@goffi.org>
parents:
2034
diff
changeset
|
824 def actionManager(self, action_data, callback=None, ui_show_cb=None, user_action=True, 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
|
825 """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
|
826 |
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
|
827 @param action_data(dict): action dict as sent by launchAction or returned by an UI 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
|
828 @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
|
829 @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
|
830 @param user_action(bool): if True, the action is a result of a user interaction |
db3bbbd745e4
frontends (xmlui): added a user_action attribute:
Goffi <goffi@goffi.org>
parents:
2034
diff
changeset
|
831 else the action come from backend direclty (i.e. actionNew) |
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
|
832 """ |
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
|
833 try: |
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
|
834 xmlui = action_data.pop('xmlui') |
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
|
835 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
|
836 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
|
837 else: |
2036
db3bbbd745e4
frontends (xmlui): added a user_action attribute:
Goffi <goffi@goffi.org>
parents:
2034
diff
changeset
|
838 ui = self.xmlui.create(self, xml_data=xmlui, flags=("FROM_BACKEND",) if not user_action else None, callback=callback, profile=profile) |
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
|
839 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
|
840 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
|
841 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
|
842 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
|
843 |
2071d5cec5d6
quick frontend: added progressIdHandler to managed progress id on action result + ignore meta_* action results
Goffi <goffi@goffi.org>
parents:
1599
diff
changeset
|
844 try: |
2071d5cec5d6
quick frontend: added progressIdHandler to managed progress id on action result + ignore meta_* action results
Goffi <goffi@goffi.org>
parents:
1599
diff
changeset
|
845 progress_id = action_data.pop('progress') |
2071d5cec5d6
quick frontend: added progressIdHandler to managed progress id on action result + ignore meta_* action results
Goffi <goffi@goffi.org>
parents:
1599
diff
changeset
|
846 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
|
847 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
|
848 else: |
2071d5cec5d6
quick frontend: added progressIdHandler to managed progress id on action result + ignore meta_* action results
Goffi <goffi@goffi.org>
parents:
1599
diff
changeset
|
849 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
|
850 |
2071d5cec5d6
quick frontend: added progressIdHandler to managed progress id on action result + ignore meta_* action results
Goffi <goffi@goffi.org>
parents:
1599
diff
changeset
|
851 # we ignore metadata |
2071d5cec5d6
quick frontend: added progressIdHandler to managed progress id on action result + ignore meta_* action results
Goffi <goffi@goffi.org>
parents:
1599
diff
changeset
|
852 action_data = {k:v for k,v in action_data.iteritems() if not k.startswith("meta_")} |
2071d5cec5d6
quick frontend: added progressIdHandler to managed progress id on action result + ignore meta_* action results
Goffi <goffi@goffi.org>
parents:
1599
diff
changeset
|
853 |
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
|
854 if 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
|
855 raise exceptions.DataError(u"Not all keys in action_data are managed ({keys})".format(keys=', '.join(action_data.keys()))) |
1468
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1461
diff
changeset
|
856 |
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
|
857 def launchAction(self, callback_id, data=None, callback=None, profile=C.PROF_KEY_NONE): |
1468
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1461
diff
changeset
|
858 """ Launch a dynamic action |
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1461
diff
changeset
|
859 |
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
|
860 @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
|
861 @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
|
862 @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
|
863 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
|
864 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
|
865 - 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
|
866 - 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
|
867 - profile: %(doc_profile)s |
1468
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1461
diff
changeset
|
868 @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
|
869 |
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
|
870 """ |
1468
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1461
diff
changeset
|
871 if data is None: |
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1461
diff
changeset
|
872 data = dict() |
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1461
diff
changeset
|
873 |
1580
641cfd2faefe
Primitivus: better popups handling:
Goffi <goffi@goffi.org>
parents:
1513
diff
changeset
|
874 |
1468
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1461
diff
changeset
|
875 def action_cb(data): |
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
|
876 if callback is None: |
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
|
877 self.actionManager(data, profile=profile) |
1468
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1461
diff
changeset
|
878 else: |
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
|
879 callback(data=data, cb_id=callback_id, profile=profile) |
1468
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1461
diff
changeset
|
880 |
731fbed0b9cf
quick_frontend, primitivus: handling of actionNew signal
Goffi <goffi@goffi.org>
parents:
1461
diff
changeset
|
881 self.bridge.launchAction(callback_id, data, profile, callback=action_cb, errback=self.dialogFailure) |
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
|
882 |
2067
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
883 def getAvatar(self, entity, profile): |
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
884 """return avatar path for an entity""" |
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
885 contact_list = self.contact_lists[profile] |
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
886 avatar = contact_list.getCache(entity, "avatar") |
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
887 if avatar is None: |
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
888 self.bridge.getCard(unicode(entity), profile) |
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
889 contact_list.setCache(entity, "avatar", "") |
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
890 if not avatar: |
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
891 avatar = self.getDefaultAvatar(entity) |
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
892 return avatar |
7834743705f0
quich frontend, primivius (chat): better avatar handling:
Goffi <goffi@goffi.org>
parents:
2066
diff
changeset
|
893 |
2056
7bfa97e533ac
quick frontend(QuickApp): added getDefaultAvatar method:
Goffi <goffi@goffi.org>
parents:
2050
diff
changeset
|
894 def getDefaultAvatar(self, entity=None): |
7bfa97e533ac
quick frontend(QuickApp): added getDefaultAvatar method:
Goffi <goffi@goffi.org>
parents:
2050
diff
changeset
|
895 """return default avatar to use with given entity |
7bfa97e533ac
quick frontend(QuickApp): added getDefaultAvatar method:
Goffi <goffi@goffi.org>
parents:
2050
diff
changeset
|
896 |
7bfa97e533ac
quick frontend(QuickApp): added getDefaultAvatar method:
Goffi <goffi@goffi.org>
parents:
2050
diff
changeset
|
897 must be implemented by frontend |
7bfa97e533ac
quick frontend(QuickApp): added getDefaultAvatar method:
Goffi <goffi@goffi.org>
parents:
2050
diff
changeset
|
898 @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
|
899 """ |
7bfa97e533ac
quick frontend(QuickApp): added getDefaultAvatar method:
Goffi <goffi@goffi.org>
parents:
2050
diff
changeset
|
900 raise NotImplementedError |
7bfa97e533ac
quick frontend(QuickApp): added getDefaultAvatar method:
Goffi <goffi@goffi.org>
parents:
2050
diff
changeset
|
901 |
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
|
902 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
|
903 log.info("disconnecting") |
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
|
904 self.callListeners('disconnect', profile=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
|
905 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
|
906 |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
907 def onExit(self): |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
908 """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
|
909 to_unplug = [] |
2091
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
910 for profile, profile_manager in self.profiles.iteritems(): |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
911 if profile_manager.connected(profile) and profile_manager.autodisconnect: |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
912 #The user wants autodisconnection |
f413bfc24458
bridge, quick_frontend: preparation for async bridge
Goffi <goffi@goffi.org>
parents:
2089
diff
changeset
|
913 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
|
914 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
|
915 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
|
916 self.unplug_profile(profile) |