annotate src/core/sat_main.py @ 1027:ee46515a12f2

core: fixed typo
author Goffi <goffi@goffi.org>
date Thu, 15 May 2014 20:25:52 +0200
parents 71fdc327b318
children 15f43b54d697
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
goffi@necton2
parents:
diff changeset
1 #!/usr/bin/python
goffi@necton2
parents:
diff changeset
2 # -*- coding: utf-8 -*-
goffi@necton2
parents:
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 605
diff changeset
4 # SAT: a jabber client
811
1fe00f0c9a91 dates update
Goffi <goffi@goffi.org>
parents: 809
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org)
0
goffi@necton2
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 605
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: 605
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: 605
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: 605
diff changeset
10 # (at your option) any later version.
0
goffi@necton2
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 605
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: 605
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: 605
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: 605
diff changeset
15 # GNU Affero General Public License for more details.
0
goffi@necton2
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 605
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: 605
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
0
goffi@necton2
parents:
diff changeset
19
773
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
20 from sat.core.i18n import _, languageSwitch
331
0a8eb0461f31 core: main SAT class now moved in its own module core.sat_main
Goffi <goffi@goffi.org>
parents: 330
diff changeset
21 from twisted.application import service
0a8eb0461f31 core: main SAT class now moved in its own module core.sat_main
Goffi <goffi@goffi.org>
parents: 330
diff changeset
22 from twisted.internet import defer
39
2e3411a6baad Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents: 37
diff changeset
23 from twisted.words.protocols.jabber import jid, xmlstream
0
goffi@necton2
parents:
diff changeset
24 from twisted.words.xish import domish
goffi@necton2
parents:
diff changeset
25 from twisted.internet import reactor
346
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
26 from wokkel.xmppim import RosterItem
223
86d249b6d9b7 Files reorganisation
Goffi <goffi@goffi.org>
parents: 213
diff changeset
27 from sat.bridge.DBus import DBusBridge
332
8c9b9ef13ba1 core: minor refactoring
Goffi <goffi@goffi.org>
parents: 331
diff changeset
28 from sat.core import xmpp
627
d207c2186519 core, bridge, jp, quick_frontend: SàT stop more gracefully if bridge can't be initialised:
Goffi <goffi@goffi.org>
parents: 609
diff changeset
29 from sat.core import exceptions
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
30 from sat.core.log import getLogger
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
31 log = getLogger(__name__)
914
1a3ba959f0ab core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents: 909
diff changeset
32 from sat.core.constants import Const as C
1a3ba959f0ab core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents: 909
diff changeset
33 from sat.memory.memory import Memory
252
c09aa319712e Core: Trigger implementation + version number update
Goffi <goffi@goffi.org>
parents: 245
diff changeset
34 from sat.tools.misc import TriggerManager
987
3a96920c07b7 core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents: 972
diff changeset
35 from sat.stdui import ui_contact_list
0
goffi@necton2
parents:
diff changeset
36 from glob import glob
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
37 from uuid import uuid4
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
38 import sys
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
39 import os.path
0
goffi@necton2
parents:
diff changeset
40
987
3a96920c07b7 core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents: 972
diff changeset
41 try:
3a96920c07b7 core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents: 972
diff changeset
42 from collections import OrderedDict # only available from python 2.7
3a96920c07b7 core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents: 972
diff changeset
43 except ImportError:
3a96920c07b7 core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents: 972
diff changeset
44 from ordereddict import OrderedDict
3a96920c07b7 core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents: 972
diff changeset
45
0
goffi@necton2
parents:
diff changeset
46
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
47 sat_id = 0
0
goffi@necton2
parents:
diff changeset
48
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
49
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
50 def sat_next_id():
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
51 global sat_id
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
52 sat_id += 1
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
53 return "sat_id_" + str(sat_id)
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
54
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
55
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
56 class MessageSentAndStored(Exception):
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
57 """ Exception to raise if the message has been already sent and stored in the
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
58 history by the trigger, so the rest of the process should be stopped. This
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
59 should normally be raised by the trigger with the minimal priority """
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 777
diff changeset
60 def __init__(self, reason, mess_data):
999
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 993
diff changeset
61 Exception.__init__(self, reason)
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 777
diff changeset
62 self.mess_data = mess_data # added for testing purpose
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
63
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
64
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
65 class AbortSendMessage(Exception):
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
66 """ Exception to raise if sending the message should be aborted. This can be
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
67 raised by any trigger but a side action should be planned by the trigger
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
68 to inform the user about what happened """
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
69 pass
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
70
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
71
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
72 class SAT(service.Service):
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
73
853
c2f6ada7858f core (sqlite): automatic database update:
Goffi <goffi@goffi.org>
parents: 846
diff changeset
74 @property
c2f6ada7858f core (sqlite): automatic database update:
Goffi <goffi@goffi.org>
parents: 846
diff changeset
75 def __version__(self):
923
e77948faaef3 core: removed default_config:
Goffi <goffi@goffi.org>
parents: 922
diff changeset
76 return C.APP_VERSION
853
c2f6ada7858f core (sqlite): automatic database update:
Goffi <goffi@goffi.org>
parents: 846
diff changeset
77
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
78 def get_next_id(self):
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
79 return sat_next_id()
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
80
0
goffi@necton2
parents:
diff changeset
81 def __init__(self):
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
82 self._cb_map = {} # map from callback_id to callbacks
987
3a96920c07b7 core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents: 972
diff changeset
83 self._menus = OrderedDict() # dynamic menus. key: callback_id, value: menu data (dictionnary)
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
84 self.__private_data = {} # used for internal callbacks (key = id) FIXME: to be removed
1026
71fdc327b318 core: getReady and asyncConnect now wait full initialisation, not only memory
Goffi <goffi@goffi.org>
parents: 1023
diff changeset
85 self._initialised = defer.Deferred()
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
86 self.profiles = {}
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
87 self.plugins = {}
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
88
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
89 self.memory = Memory(self)
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
90 self.trigger = TriggerManager() # trigger are used to change SàT behaviour
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
91
627
d207c2186519 core, bridge, jp, quick_frontend: SàT stop more gracefully if bridge can't be initialised:
Goffi <goffi@goffi.org>
parents: 609
diff changeset
92 try:
d207c2186519 core, bridge, jp, quick_frontend: SàT stop more gracefully if bridge can't be initialised:
Goffi <goffi@goffi.org>
parents: 609
diff changeset
93 self.bridge = DBusBridge()
d207c2186519 core, bridge, jp, quick_frontend: SàT stop more gracefully if bridge can't be initialised:
Goffi <goffi@goffi.org>
parents: 609
diff changeset
94 except exceptions.BridgeInitError:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
95 log.error(u"Bridge can't be initialised, can't start SàT core")
627
d207c2186519 core, bridge, jp, quick_frontend: SàT stop more gracefully if bridge can't be initialised:
Goffi <goffi@goffi.org>
parents: 609
diff changeset
96 sys.exit(1)
1027
ee46515a12f2 core: fixed typo
Goffi <goffi@goffi.org>
parents: 1026
diff changeset
97 self.bridge.register("getReady", lambda: self._initialised)
923
e77948faaef3 core: removed default_config:
Goffi <goffi@goffi.org>
parents: 922
diff changeset
98 self.bridge.register("getVersion", lambda: C.APP_VERSION)
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 65
diff changeset
99 self.bridge.register("getProfileName", self.memory.getProfileName)
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 58
diff changeset
100 self.bridge.register("getProfilesList", self.memory.getProfilesList)
550
f25eef861b43 core: asyncConnect is now fired when roster is available
Goffi <goffi@goffi.org>
parents: 541
diff changeset
101 self.bridge.register("getEntityData", lambda _jid, keys, profile: self.memory.getEntityData(jid.JID(_jid), keys, profile))
420
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 416
diff changeset
102 self.bridge.register("asyncCreateProfile", self.memory.asyncCreateProfile)
893
308a96bc7c1b core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents: 853
diff changeset
103 self.bridge.register("asyncDeleteProfile", self.memory.asyncDeleteProfile)
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
104 self.bridge.register("registerNewAccount", self.registerNewAccount)
0
goffi@necton2
parents:
diff changeset
105 self.bridge.register("connect", self.connect)
341
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
106 self.bridge.register("asyncConnect", self.asyncConnect)
1
a06a151fc31f Disconnect first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
107 self.bridge.register("disconnect", self.disconnect)
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 460
diff changeset
108 self.bridge.register("getContacts", self.getContacts)
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 489
diff changeset
109 self.bridge.register("getContactsFromGroup", self.getContactsFromGroup)
919
ed9841e6d84a core: added IQ_SET to core.constants + getLastResource now manage correctly jid.JID
Goffi <goffi@goffi.org>
parents: 917
diff changeset
110 self.bridge.register("getLastResource", self.memory._getLastResource)
943
71926ec2114d core (memory): entities cache improvments:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
111 self.bridge.register("getPresenceStatuses", self.memory._getPresenceStatuses)
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
112 self.bridge.register("getWaitingSub", self.memory.getWaitingSub)
541
8b116fa42a31 core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents: 538
diff changeset
113 self.bridge.register("getWaitingConf", self.getWaitingConf)
602
6fd1095b2b7b core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 589
diff changeset
114 self.bridge.register("sendMessage", self._sendMessage)
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 358
diff changeset
115 self.bridge.register("getConfig", self.memory.getConfig)
0
goffi@necton2
parents:
diff changeset
116 self.bridge.register("setParam", self.setParam)
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
117 self.bridge.register("getParamA", self.memory.getStringParamA)
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
118 self.bridge.register("asyncGetParamA", self.memory.asyncGetStringParamA)
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 103
diff changeset
119 self.bridge.register("getParamsUI", self.memory.getParamsUI)
0
goffi@necton2
parents:
diff changeset
120 self.bridge.register("getParams", self.memory.getParams)
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
121 self.bridge.register("getParamsForCategory", self.memory.getParamsForCategory)
0
goffi@necton2
parents:
diff changeset
122 self.bridge.register("getParamsCategories", self.memory.getParamsCategories)
777
5642939d254e core, bridge: new method paramsRegisterApp to register frontend's specific parameters
souliane <souliane@mailoo.org>
parents: 773
diff changeset
123 self.bridge.register("paramsRegisterApp", self.memory.paramsRegisterApp)
0
goffi@necton2
parents:
diff changeset
124 self.bridge.register("getHistory", self.memory.getHistory)
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 806
diff changeset
125 self.bridge.register("setPresence", self._setPresence)
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
126 self.bridge.register("subscription", self.subscription)
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 806
diff changeset
127 self.bridge.register("addContact", self._addContact)
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 806
diff changeset
128 self.bridge.register("updateContact", self._updateContact)
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 806
diff changeset
129 self.bridge.register("delContact", self._delContact)
0
goffi@necton2
parents:
diff changeset
130 self.bridge.register("isConnected", self.isConnected)
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
131 self.bridge.register("launchAction", self.launchCallback)
0
goffi@necton2
parents:
diff changeset
132 self.bridge.register("confirmationAnswer", self.confirmationAnswer)
goffi@necton2
parents:
diff changeset
133 self.bridge.register("getProgress", self.getProgress)
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
134 self.bridge.register("getMenus", self.getMenus)
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
135 self.bridge.register("getMenuHelp", self.getMenuHelp)
963
723f28cd15c7 core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents: 951
diff changeset
136 self.bridge.register("discoInfos", self.memory.disco._discoInfos)
723f28cd15c7 core (disco): added discoInfos and discoItems bridge methods
Goffi <goffi@goffi.org>
parents: 951
diff changeset
137 self.bridge.register("discoItems", self.memory.disco._discoItems)
1015
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents: 1007
diff changeset
138 self.bridge.register("saveParamsTemplate", self.memory.save_xml)
fee00f2e11c2 memory, jp: added jp commands to load/save parameters template
souliane <souliane@mailoo.org>
parents: 1007
diff changeset
139 self.bridge.register("loadParamsTemplate", self.memory.load_xml)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
140
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
141 self.memory.initialized.addCallback(self._postMemoryInit)
0
goffi@necton2
parents:
diff changeset
142
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
143 def _postMemoryInit(self, ignore):
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
144 """Method called after memory initialization is done"""
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
145 log.info(_("Memory initialised"))
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
146 self._import_plugins()
987
3a96920c07b7 core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents: 972
diff changeset
147 ui_contact_list.ContactList(self)
1026
71fdc327b318 core: getReady and asyncConnect now wait full initialisation, not only memory
Goffi <goffi@goffi.org>
parents: 1023
diff changeset
148 self._initialised.callback(None)
0
goffi@necton2
parents:
diff changeset
149
goffi@necton2
parents:
diff changeset
150 def _import_plugins(self):
goffi@necton2
parents:
diff changeset
151 """Import all plugins found in plugins directory"""
226
d8bb72f00eec distutils install: fixed plugin import and log file path
Goffi <goffi@goffi.org>
parents: 225
diff changeset
152 import sat.plugins
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
153 plugins_path = os.path.dirname(sat.plugins.__file__)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
154 plug_lst = [os.path.splitext(plugin)[0] for plugin in map(os.path.basename, glob(os.path.join(plugins_path, "plugin*.py")))]
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
155 __plugins_to_import = {} # plugins we still have to import
0
goffi@necton2
parents:
diff changeset
156 for plug in plug_lst:
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
157 plugin_path = 'sat.plugins.' + plug
287
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
158 __import__(plugin_path)
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
159 mod = sys.modules[plugin_path]
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
160 plugin_info = mod.PLUGIN_INFO
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
161 __plugins_to_import[plugin_info['import_name']] = (plugin_path, mod, plugin_info)
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
162 while True:
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
163 self._import_plugins_from_dict(__plugins_to_import)
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
164 if not __plugins_to_import:
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
165 break
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
166
925
5c78cefd233f core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents: 923
diff changeset
167 def _import_plugins_from_dict(self, plugins_to_import, import_name=None, optional=False):
287
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
168 """Recursively import and their dependencies in the right order
925
5c78cefd233f core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents: 923
diff changeset
169 @param plugins_to_import: dict where key=import_name and values= (plugin_path, module, plugin_info)
5c78cefd233f core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents: 923
diff changeset
170 @param import_name: name of the plugin to import as found in PLUGIN_INFO['import_name']
5c78cefd233f core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents: 923
diff changeset
171 @param optional: if False and plugin is not found, an ImportError exception is raised
5c78cefd233f core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents: 923
diff changeset
172
5c78cefd233f core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents: 923
diff changeset
173 """
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
174 if import_name in self.plugins:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
175 log.debug('Plugin [%s] already imported, passing' % import_name)
287
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
176 return
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
177 if not import_name:
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
178 import_name, (plugin_path, mod, plugin_info) = plugins_to_import.popitem()
287
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
179 else:
288
76247af9917c core: added plugin dependency not found import error
Goffi <goffi@goffi.org>
parents: 287
diff changeset
180 if not import_name in plugins_to_import:
925
5c78cefd233f core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents: 923
diff changeset
181 if optional:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
182 log.warning(_("Recommended plugin not found: %s") % import_name)
925
5c78cefd233f core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents: 923
diff changeset
183 return
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
184 log.error(_("Dependency not found: %s") % import_name)
288
76247af9917c core: added plugin dependency not found import error
Goffi <goffi@goffi.org>
parents: 287
diff changeset
185 raise ImportError(_('Dependency plugin not found: [%s]') % import_name)
287
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
186 plugin_path, mod, plugin_info = plugins_to_import.pop(import_name)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
187 dependencies = plugin_info.setdefault("dependencies", [])
925
5c78cefd233f core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents: 923
diff changeset
188 recommendations = plugin_info.setdefault("recommendations", [])
5c78cefd233f core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents: 923
diff changeset
189 for to_import in dependencies + recommendations:
5c78cefd233f core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents: 923
diff changeset
190 if to_import not in self.plugins:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
191 log.debug('Recursively import dependency of [%s]: [%s]' % (import_name, to_import))
925
5c78cefd233f core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents: 923
diff changeset
192 self._import_plugins_from_dict(plugins_to_import, to_import, to_import not in dependencies)
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
193 log.info(_("importing plugin: %s") % plugin_info['name'])
287
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
194 self.plugins[import_name] = getattr(mod, plugin_info['main'])(self)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
195 if 'handler' in plugin_info and plugin_info['handler'] == 'yes':
287
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
196 self.plugins[import_name].is_handler = True
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
197 else:
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
198 self.plugins[import_name].is_handler = False
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
199 #TODO: test xmppclient presence and register handler parent
0
goffi@necton2
parents:
diff changeset
200
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 914
diff changeset
201 def connect(self, profile_key=C.PROF_KEY_NONE):
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
202 """Connect to jabber server"""
341
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
203 self.asyncConnect(profile_key)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
204
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 914
diff changeset
205 def asyncConnect(self, profile_key=C.PROF_KEY_NONE):
341
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
206 """Connect to jabber server with asynchronous reply
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
207 @param profile_key: %(doc_profile)s
423
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 420
diff changeset
208 """
1026
71fdc327b318 core: getReady and asyncConnect now wait full initialisation, not only memory
Goffi <goffi@goffi.org>
parents: 1023
diff changeset
209 def backendInitialised(dummy):
1023
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
210 profile = self.memory.getProfileName(profile_key)
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
211 if not profile:
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
212 log.error(_('Trying to connect a non-existant profile'))
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
213 raise exceptions.ProfileUnknownError(profile_key)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
214
1023
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
215 if self.isConnected(profile):
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
216 log.info(_("already connected !"))
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
217 return defer.succeed("None")
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
218
1023
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
219 def afterMemoryInit(ignore):
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
220 """This part must be called when we have loaded individual parameters from memory"""
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
221 try:
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
222 port = int(self.memory.getParamA("Port", "Connection", profile_key=profile))
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
223 except ValueError:
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
224 log.error(_("Can't parse port value, using default value"))
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
225 port = 5222
1019
6a16ec17a458 better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1015
diff changeset
226
1023
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
227 current = self.profiles[profile] = xmpp.SatXMPPClient(
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
228 self, profile,
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
229 jid.JID(self.memory.getParamA("JabberID", "Connection", profile_key=profile), profile),
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
230 self.memory.getParamA("Password", "Connection", profile_key=profile),
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
231 self.memory.getParamA("Server", "Connection", profile_key=profile),
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
232 port)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
233
1023
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
234 current.messageProt = xmpp.SatMessageProtocol(self)
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
235 current.messageProt.setHandlerParent(current)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
236
1023
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
237 current.roster = xmpp.SatRosterProtocol(self)
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
238 current.roster.setHandlerParent(current)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
239
1023
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
240 current.presence = xmpp.SatPresenceProtocol(self)
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
241 current.presence.setHandlerParent(current)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
242
1023
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
243 current.fallBack = xmpp.SatFallbackHandler(self)
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
244 current.fallBack.setHandlerParent(current)
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
245
1023
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
246 current.versionHandler = xmpp.SatVersionHandler(C.APP_NAME_FULL,
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
247 C.APP_VERSION)
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
248 current.versionHandler.setHandlerParent(current)
14
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
249
1023
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
250 current.identityHandler = xmpp.SatIdentityHandler()
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
251 current.identityHandler.setHandlerParent(current)
666
2a7185b8452c core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents: 641
diff changeset
252
1023
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
253 log.debug(_("setting plugins parents"))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
254
1023
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
255 plugin_conn_cb = []
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
256 for plugin in self.plugins.iteritems():
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
257 if plugin[1].is_handler:
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
258 plugin[1].getHandler(profile).setHandlerParent(current)
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
259 connected_cb = getattr(plugin[1], "profileConnected", None)
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
260 if connected_cb:
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
261 plugin_conn_cb.append((plugin[0], connected_cb))
14
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
262
1023
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
263 current.startService()
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
264
1023
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
265 d = current.getConnectionDeferred()
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
266 d.addCallback(lambda dummy: current.roster.got_roster) # we want to be sure that we got the roster
972
07b817f5a197 core: better plugin initialisation sequence:
Goffi <goffi@goffi.org>
parents: 963
diff changeset
267
1023
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
268 def pluginsConnection(dummy):
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
269 """Call profileConnected callback for all plugins, and print error message if any of them fails"""
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
270 conn_cb_list = []
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
271 for dummy, callback in plugin_conn_cb:
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
272 conn_cb_list.append(defer.maybeDeferred(callback, profile))
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
273 list_d = defer.DeferredList(conn_cb_list)
972
07b817f5a197 core: better plugin initialisation sequence:
Goffi <goffi@goffi.org>
parents: 963
diff changeset
274
1023
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
275 def logPluginResults(results):
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
276 all_succeed = all([success for success, result in results])
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
277 if not all_succeed:
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
278 log.error(_("Plugins initialisation error"))
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
279 for idx, (success, result) in enumerate(results):
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
280 if not success:
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
281 log.error("error (plugin %(name)s): %(failure)s" % {'name': plugin_conn_cb[idx][0],
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
282 'failure': result})
972
07b817f5a197 core: better plugin initialisation sequence:
Goffi <goffi@goffi.org>
parents: 963
diff changeset
283
1023
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
284 list_d.addCallback(logPluginResults)
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
285 return list_d
972
07b817f5a197 core: better plugin initialisation sequence:
Goffi <goffi@goffi.org>
parents: 963
diff changeset
286
1023
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
287 d.addCallback(pluginsConnection)
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
288 return d
423
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 420
diff changeset
289
1023
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
290 self.memory.startProfileSession(profile)
8bae81e254a2 core: added a getReady method which can be called by frontends to ensure that backend is fully initialised before doing anything + this ckeck is automatically done in asyncConnect
Goffi <goffi@goffi.org>
parents: 1019
diff changeset
291 return self.memory.loadIndividualParams(profile).addCallback(afterMemoryInit)
1026
71fdc327b318 core: getReady and asyncConnect now wait full initialisation, not only memory
Goffi <goffi@goffi.org>
parents: 1023
diff changeset
292 return self._initialised.addCallback(backendInitialised)
341
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
293
346
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
294 def disconnect(self, profile_key):
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
295 """disconnect from jabber server"""
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
296 if not self.isConnected(profile_key):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
297 log.info(_("not connected !"))
6
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
298 return
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
299 profile = self.memory.getProfileName(profile_key)
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
300 log.info(_("Disconnecting..."))
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
301 self.profiles[profile].stopService()
438
62145e50eae5 core: plugins can now have profileConnected/profileDisconnected method to initialise/free profile dependant resources
Goffi <goffi@goffi.org>
parents: 434
diff changeset
302 for plugin in self.plugins.iteritems():
62145e50eae5 core: plugins can now have profileConnected/profileDisconnected method to initialise/free profile dependant resources
Goffi <goffi@goffi.org>
parents: 434
diff changeset
303 disconnected_cb = getattr(plugin[1], "profileDisconnected", None)
62145e50eae5 core: plugins can now have profileConnected/profileDisconnected method to initialise/free profile dependant resources
Goffi <goffi@goffi.org>
parents: 434
diff changeset
304 if disconnected_cb:
62145e50eae5 core: plugins can now have profileConnected/profileDisconnected method to initialise/free profile dependant resources
Goffi <goffi@goffi.org>
parents: 434
diff changeset
305 disconnected_cb(profile)
6
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
306
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 460
diff changeset
307 def getContacts(self, profile_key):
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 460
diff changeset
308 client = self.getClient(profile_key)
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 460
diff changeset
309 ret = []
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
310 for item in client.roster.getItems(): # we get all items for client's roster
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
311 # and convert them to expected format
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 460
diff changeset
312 attr = client.roster.getAttributes(item)
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 460
diff changeset
313 ret.append([item.jid.userhost(), attr, item.groups])
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 460
diff changeset
314 return ret
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 460
diff changeset
315
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 489
diff changeset
316 def getContactsFromGroup(self, group, profile_key):
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 489
diff changeset
317 client = self.getClient(profile_key)
941
c6d8fc63b1db core, plugins: host.getClient now raise an exception instead of returning None when no profile is found, plugins have been adapted consequently and a bit cleaned
Goffi <goffi@goffi.org>
parents: 930
diff changeset
318 return [jid_.full() for jid_ in client.roster.getJidsFromGroup(group)]
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 489
diff changeset
319
416
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
320 def purgeClient(self, profile):
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
321 """Remove reference to a profile client and purge cache
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
322 the garbage collector can then free the memory"""
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
323 try:
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
324 del self.profiles[profile]
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
325 except KeyError:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
326 log.error(_("Trying to remove reference to a client not referenced"))
484
23cbdf0a0777 core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents: 480
diff changeset
327 self.memory.purgeProfileSession(profile)
416
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
328
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
329 def startService(self):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
330 log.info(u"Salut à toi ô mon frère !")
213
5c420b1f1df4 removed connect on statService, this was causing issue on first launch
Goffi <goffi@goffi.org>
parents: 210
diff changeset
331 #TODO: manage autoconnect
5c420b1f1df4 removed connect on statService, this was causing issue on first launch
Goffi <goffi@goffi.org>
parents: 210
diff changeset
332 #self.connect()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
333
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
334 def stopService(self):
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 999
diff changeset
335 log.info(u"Salut aussi à Rantanplan")
0
goffi@necton2
parents:
diff changeset
336
goffi@necton2
parents:
diff changeset
337 def run(self):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
338 log.debug(_("running app"))
0
goffi@necton2
parents:
diff changeset
339 reactor.run()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
340
0
goffi@necton2
parents:
diff changeset
341 def stop(self):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
342 log.debug(_("stopping app"))
0
goffi@necton2
parents:
diff changeset
343 reactor.stop()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
344
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
345 ## Misc methods ##
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
346
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
347 def getJidNStream(self, profile_key):
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
348 """Convenient method to get jid and stream from profile key
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
349 @return: tuple (jid, xmlstream) from profile, can be None"""
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
350 profile = self.memory.getProfileName(profile_key)
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
351 if not profile or not self.profiles[profile].isConnected():
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
352 return (None, None)
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
353 return (self.profiles[profile].jid, self.profiles[profile].xmlstream)
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
354
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
355 def getClient(self, profile_key):
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
356 """Convenient method to get client from profile key
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
357 @return: client or None if it doesn't exist"""
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
358 profile = self.memory.getProfileName(profile_key)
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
359 if not profile:
941
c6d8fc63b1db core, plugins: host.getClient now raise an exception instead of returning None when no profile is found, plugins have been adapted consequently and a bit cleaned
Goffi <goffi@goffi.org>
parents: 930
diff changeset
360 raise exceptions.ProfileKeyUnknownError
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
361 return self.profiles[profile]
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
362
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents: 727
diff changeset
363 def getClients(self, profile_key):
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents: 727
diff changeset
364 """Convenient method to get list of clients from profile key (manage list through profile_key like @ALL@)
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents: 727
diff changeset
365 @param profile_key: %(doc_profile_key)s
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents: 727
diff changeset
366 @return: list of clients"""
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents: 727
diff changeset
367 profile = self.memory.getProfileName(profile_key, True)
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents: 727
diff changeset
368 if not profile:
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents: 727
diff changeset
369 return []
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents: 727
diff changeset
370 if profile == "@ALL@":
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents: 727
diff changeset
371 return self.profiles.values()
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents: 727
diff changeset
372 if profile.count('@') > 1:
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents: 727
diff changeset
373 raise exceptions.ProfileKeyUnknownError
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents: 727
diff changeset
374 return [self.profiles[profile]]
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents: 727
diff changeset
375
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 914
diff changeset
376 def registerNewAccount(self, login, password, email, server, port=5222, id_=None, profile_key=C.PROF_KEY_NONE):
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
377 """Connect to a server and create a new account using in-band registration"""
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
378 profile = self.memory.getProfileName(profile_key)
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
379 assert(profile)
0
goffi@necton2
parents:
diff changeset
380
813
1a1600491d9d core: registerNewAccount partial fix
Goffi <goffi@goffi.org>
parents: 811
diff changeset
381 next_id = id_ or self.get_next_id() # the id is used to send server's answer
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
382 serverRegistrer = xmlstream.XmlStreamFactory(xmpp.RegisteringAuthenticator(self, server, login, password, email, next_id, profile))
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
383 connector = reactor.connectTCP(server, port, serverRegistrer)
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
384 serverRegistrer.clientConnectionLost = lambda conn, reason: connector.disconnect()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
385
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
386 return next_id
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
387
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
388 def registerNewAccountCB(self, data, profile):
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
389 # FIXME: to be removed/redone elsewhere
135
7452ac3818e7 Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents: 119
diff changeset
390 user = jid.parse(self.memory.getParamA("JabberID", "Connection", profile_key=profile))[0]
7452ac3818e7 Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents: 119
diff changeset
391 password = self.memory.getParamA("Password", "Connection", profile_key=profile)
7452ac3818e7 Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents: 119
diff changeset
392 server = self.memory.getParamA("Server", "Connection", profile_key=profile)
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
393
23
925ab466c5ec better presentation for register new account
Goffi <goffi@goffi.org>
parents: 22
diff changeset
394 if not user or not password or not server:
813
1a1600491d9d core: registerNewAccount partial fix
Goffi <goffi@goffi.org>
parents: 811
diff changeset
395 raise exceptions.DataError(_("No user, password or server given, can't register new account."))
23
925ab466c5ec better presentation for register new account
Goffi <goffi@goffi.org>
parents: 22
diff changeset
396
813
1a1600491d9d core: registerNewAccount partial fix
Goffi <goffi@goffi.org>
parents: 811
diff changeset
397 # FIXME: to be fixed with XMLUI dialogs once their implemented
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
398 confirm_id = sat_next_id()
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
399 self.__private_data[confirm_id] = (id, profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
400
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
401 self.askConfirmation(
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
402 confirm_id, "YES/NO",
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
403 {"message": _("Are you sure to register new account [%(user)s] to server %(server)s ?") % {'user': user, 'server': server, 'profile': profile}},
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
404 self.regisConfirmCB, profile)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
405 print "===============+++++++++++ REGISTER NEW ACCOUNT++++++++++++++============"
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
406
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
407 def regisConfirmCB(self, id, accepted, data, profile):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
408 print _("register Confirmation CB ! (%s)") % str(accepted)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
409 action_id, profile = self.__private_data[id]
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
410 del self.__private_data[id]
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
411 if accepted:
135
7452ac3818e7 Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents: 119
diff changeset
412 user = jid.parse(self.memory.getParamA("JabberID", "Connection", profile_key=profile))[0]
7452ac3818e7 Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents: 119
diff changeset
413 password = self.memory.getParamA("Password", "Connection", profile_key=profile)
7452ac3818e7 Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents: 119
diff changeset
414 server = self.memory.getParamA("Server", "Connection", profile_key=profile)
336
953536246d9d core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents: 332
diff changeset
415 self.registerNewAccount(user, password, None, server, id=action_id)
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
416 else:
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
417 self.actionResult(action_id, "SUPPRESS", {}, profile)
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
418
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
419 ## Client management ##
0
goffi@necton2
parents:
diff changeset
420
641
49587e170f53 core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents: 636
diff changeset
421 def setParam(self, name, value, category, security_limit, profile_key):
0
goffi@necton2
parents:
diff changeset
422 """set wanted paramater and notice observers"""
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
423 log.info(_("setting param: %(name)s=%(value)s in category %(category)s") % {'name': name, 'value': value, 'category': category})
641
49587e170f53 core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents: 636
diff changeset
424 self.memory.setParam(name, value, category, security_limit, profile_key)
0
goffi@necton2
parents:
diff changeset
425
346
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
426 def isConnected(self, profile_key):
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
427 """Return connection status of profile
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
428 @param profile_key: key_word or profile name to determine profile name
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
429 @return True if connected
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
430 """
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
431 profile = self.memory.getProfileName(profile_key)
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
432 if not profile:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
433 log.error(_('asking connection status for a non-existant profile'))
213
5c420b1f1df4 removed connect on statService, this was causing issue on first launch
Goffi <goffi@goffi.org>
parents: 210
diff changeset
434 return
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
435 if profile not in self.profiles:
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
436 return False
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
437 return self.profiles[profile].isConnected()
0
goffi@necton2
parents:
diff changeset
438
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
439
0
goffi@necton2
parents:
diff changeset
440 ## jabber methods ##
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
441
541
8b116fa42a31 core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents: 538
diff changeset
442 def getWaitingConf(self, profile_key=None):
8b116fa42a31 core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents: 538
diff changeset
443 assert(profile_key)
8b116fa42a31 core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents: 538
diff changeset
444 client = self.getClient(profile_key)
8b116fa42a31 core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents: 538
diff changeset
445 ret = []
8b116fa42a31 core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents: 538
diff changeset
446 for conf_id in client._waiting_conf:
8b116fa42a31 core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents: 538
diff changeset
447 conf_type, data = client._waiting_conf[conf_id][:2]
8b116fa42a31 core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents: 538
diff changeset
448 ret.append((conf_id, conf_type, data))
8b116fa42a31 core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents: 538
diff changeset
449 return ret
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
450
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 914
diff changeset
451 def _sendMessage(self, to_s, msg, subject=None, mess_type='auto', extra={}, profile_key=C.PROF_KEY_NONE):
602
6fd1095b2b7b core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 589
diff changeset
452 to_jid = jid.JID(to_s)
698
d731ae066158 core: sendMessage's options parameter has been renamed to extra to be consistent with newMessage
Goffi <goffi@goffi.org>
parents: 697
diff changeset
453 #XXX: we need to use the dictionary comprehension because D-Bus return its own types, and pickle can't manage them. TODO: Need to find a better way
752
f49945d728de core,bridge: sendMessage bridge method is now async
Goffi <goffi@goffi.org>
parents: 748
diff changeset
454 return self.sendMessage(to_jid, msg, subject, mess_type, {unicode(key): unicode(value) for key, value in extra.items()}, profile_key=profile_key)
636
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents: 627
diff changeset
455
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 914
diff changeset
456 def sendMessage(self, to_jid, msg, subject=None, mess_type='auto', extra={}, no_trigger=False, profile_key=C.PROF_KEY_NONE):
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
457 #FIXME: check validity of recipient
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
458 profile = self.memory.getProfileName(profile_key)
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
459 assert(profile)
489
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
460 client = self.profiles[profile]
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
461 current_jid = client.jid
698
d731ae066158 core: sendMessage's options parameter has been renamed to extra to be consistent with newMessage
Goffi <goffi@goffi.org>
parents: 697
diff changeset
462 if extra is None:
d731ae066158 core: sendMessage's options parameter has been renamed to extra to be consistent with newMessage
Goffi <goffi@goffi.org>
parents: 697
diff changeset
463 extra = {}
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
464 mess_data = { # we put data in a dict, so trigger methods can change them
602
6fd1095b2b7b core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 589
diff changeset
465 "to": to_jid,
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
466 "message": msg,
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
467 "subject": subject,
636
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents: 627
diff changeset
468 "type": mess_type,
698
d731ae066158 core: sendMessage's options parameter has been renamed to extra to be consistent with newMessage
Goffi <goffi@goffi.org>
parents: 697
diff changeset
469 "extra": extra,
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
470 }
922
c897c8d321b3 core: sendMessageTrigger now manage pre and post treatments, which happen before or after XML generation
Goffi <goffi@goffi.org>
parents: 919
diff changeset
471 pre_xml_treatments = defer.Deferred() # XXX: plugin can add their pre XML treatments to this deferred
c897c8d321b3 core: sendMessageTrigger now manage pre and post treatments, which happen before or after XML generation
Goffi <goffi@goffi.org>
parents: 919
diff changeset
472 post_xml_treatments = defer.Deferred() # XXX: plugin can add their post XML treatments to this deferred
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
473
489
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
474 if mess_data["type"] == "auto":
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
475 # we try to guess the type
489
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
476 if mess_data["subject"]:
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
477 mess_data["type"] = 'normal'
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
478 elif not mess_data["to"].resource: # if to JID has a resource, the type is not 'groupchat'
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
479 # we may have a groupchat message, we check if the we know this jid
489
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
480 try:
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
481 entity_type = self.memory.getEntityData(mess_data["to"], ['type'], profile)["type"]
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
482 #FIXME: should entity_type manage ressources ?
627
d207c2186519 core, bridge, jp, quick_frontend: SàT stop more gracefully if bridge can't be initialised:
Goffi <goffi@goffi.org>
parents: 609
diff changeset
483 except (exceptions.UnknownEntityError, KeyError):
489
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
484 entity_type = "contact"
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
485
489
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
486 if entity_type == "chatroom":
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
487 mess_data["type"] = 'groupchat'
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
488 else:
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
489 mess_data["type"] = 'chat'
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
490 else:
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
491 mess_data["type"] == 'chat'
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
492 mess_data["type"] == "chat" if mess_data["subject"] else "normal"
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
493
602
6fd1095b2b7b core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 589
diff changeset
494 if not no_trigger:
922
c897c8d321b3 core: sendMessageTrigger now manage pre and post treatments, which happen before or after XML generation
Goffi <goffi@goffi.org>
parents: 919
diff changeset
495 if not self.trigger.point("sendMessage", mess_data, pre_xml_treatments, post_xml_treatments, profile):
752
f49945d728de core,bridge: sendMessage bridge method is now async
Goffi <goffi@goffi.org>
parents: 748
diff changeset
496 return defer.succeed(None)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
497
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
498 log.debug(_("Sending jabber message of type [%(type)s] to %(to)s...") % {"type": mess_data["type"], "to": to_jid.full()})
922
c897c8d321b3 core: sendMessageTrigger now manage pre and post treatments, which happen before or after XML generation
Goffi <goffi@goffi.org>
parents: 919
diff changeset
499
c897c8d321b3 core: sendMessageTrigger now manage pre and post treatments, which happen before or after XML generation
Goffi <goffi@goffi.org>
parents: 919
diff changeset
500 def generateXML(mess_data):
c897c8d321b3 core: sendMessageTrigger now manage pre and post treatments, which happen before or after XML generation
Goffi <goffi@goffi.org>
parents: 919
diff changeset
501 mess_data['xml'] = domish.Element((None, 'message'))
c897c8d321b3 core: sendMessageTrigger now manage pre and post treatments, which happen before or after XML generation
Goffi <goffi@goffi.org>
parents: 919
diff changeset
502 mess_data['xml']["to"] = mess_data["to"].full()
c897c8d321b3 core: sendMessageTrigger now manage pre and post treatments, which happen before or after XML generation
Goffi <goffi@goffi.org>
parents: 919
diff changeset
503 mess_data['xml']["from"] = current_jid.full()
c897c8d321b3 core: sendMessageTrigger now manage pre and post treatments, which happen before or after XML generation
Goffi <goffi@goffi.org>
parents: 919
diff changeset
504 mess_data['xml']["type"] = mess_data["type"]
c897c8d321b3 core: sendMessageTrigger now manage pre and post treatments, which happen before or after XML generation
Goffi <goffi@goffi.org>
parents: 919
diff changeset
505 if mess_data["subject"]:
c897c8d321b3 core: sendMessageTrigger now manage pre and post treatments, which happen before or after XML generation
Goffi <goffi@goffi.org>
parents: 919
diff changeset
506 mess_data['xml'].addElement("subject", None, subject)
c897c8d321b3 core: sendMessageTrigger now manage pre and post treatments, which happen before or after XML generation
Goffi <goffi@goffi.org>
parents: 919
diff changeset
507 # message without body are used to send chat states
c897c8d321b3 core: sendMessageTrigger now manage pre and post treatments, which happen before or after XML generation
Goffi <goffi@goffi.org>
parents: 919
diff changeset
508 if mess_data["message"]:
c897c8d321b3 core: sendMessageTrigger now manage pre and post treatments, which happen before or after XML generation
Goffi <goffi@goffi.org>
parents: 919
diff changeset
509 mess_data['xml'].addElement("body", None, mess_data["message"])
c897c8d321b3 core: sendMessageTrigger now manage pre and post treatments, which happen before or after XML generation
Goffi <goffi@goffi.org>
parents: 919
diff changeset
510 return mess_data
697
0c84fb112d70 core: sendMessage triggers now use a treatments deferred;
Goffi <goffi@goffi.org>
parents: 677
diff changeset
511
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
512 def sendErrback(e):
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
513 text = '%s: %s' % (e.value.__class__.__name__, e.getErrorMessage())
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
514 if e.check(MessageSentAndStored):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
515 log.debug(text)
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
516 elif e.check(AbortSendMessage):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
517 log.warning(text)
752
f49945d728de core,bridge: sendMessage bridge method is now async
Goffi <goffi@goffi.org>
parents: 748
diff changeset
518 return e
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
519 else:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
520 log.error("Unmanaged exception: %s" % text)
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
521 return e
922
c897c8d321b3 core: sendMessageTrigger now manage pre and post treatments, which happen before or after XML generation
Goffi <goffi@goffi.org>
parents: 919
diff changeset
522 pre_xml_treatments.addCallback(generateXML)
c897c8d321b3 core: sendMessageTrigger now manage pre and post treatments, which happen before or after XML generation
Goffi <goffi@goffi.org>
parents: 919
diff changeset
523 pre_xml_treatments.chainDeferred(post_xml_treatments)
c897c8d321b3 core: sendMessageTrigger now manage pre and post treatments, which happen before or after XML generation
Goffi <goffi@goffi.org>
parents: 919
diff changeset
524 post_xml_treatments.addCallback(self.sendAndStoreMessage, False, profile)
c897c8d321b3 core: sendMessageTrigger now manage pre and post treatments, which happen before or after XML generation
Goffi <goffi@goffi.org>
parents: 919
diff changeset
525 post_xml_treatments.addErrback(sendErrback)
c897c8d321b3 core: sendMessageTrigger now manage pre and post treatments, which happen before or after XML generation
Goffi <goffi@goffi.org>
parents: 919
diff changeset
526 pre_xml_treatments.callback(mess_data)
c897c8d321b3 core: sendMessageTrigger now manage pre and post treatments, which happen before or after XML generation
Goffi <goffi@goffi.org>
parents: 919
diff changeset
527 return pre_xml_treatments
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
528
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
529 def sendAndStoreMessage(self, mess_data, skip_send=False, profile=None):
909
fab49a1d5ea2 core: minor docstring fixes
Goffi <goffi@goffi.org>
parents: 893
diff changeset
530 """Actually send and store the message to history, after all the treatments have been done.
fab49a1d5ea2 core: minor docstring fixes
Goffi <goffi@goffi.org>
parents: 893
diff changeset
531 This has been moved outside the main sendMessage method because it is used by XEP-0033 to complete a server-side feature not yet
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
532 implemented by the prosody plugin.
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
533 @param mess_data: message data dictionary
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
534 @param skip_send: set to True to skip sending the message to only store it
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
535 @param profile: profile
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
536 """
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
537 try:
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
538 client = self.profiles[profile]
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
539 except KeyError:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
540 log.error(_("Trying to send a message with no profile"))
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
541 return
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
542 current_jid = client.jid
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
543 if not skip_send:
697
0c84fb112d70 core: sendMessage triggers now use a treatments deferred;
Goffi <goffi@goffi.org>
parents: 677
diff changeset
544 client.xmlstream.send(mess_data['xml'])
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
545 if mess_data["type"] != "groupchat":
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
546 # we don't add groupchat message to history, as we get them back
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
547 # and they will be added then
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
548 if mess_data['message']: # we need a message to save something
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
549 self.memory.addToHistory(current_jid, mess_data['to'],
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
550 unicode(mess_data["message"]),
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
551 unicode(mess_data["type"]),
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
552 mess_data['extra'],
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
553 profile=profile)
697
0c84fb112d70 core: sendMessage triggers now use a treatments deferred;
Goffi <goffi@goffi.org>
parents: 677
diff changeset
554 # We send back the message, so all clients are aware of it
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
555 self.bridge.newMessage(mess_data['xml']['from'],
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
556 unicode(mess_data["message"]),
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
557 mess_type=mess_data["type"],
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
558 to_jid=mess_data['xml']['to'],
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
559 extra=mess_data['extra'],
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
560 profile=profile)
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
561
917
a9401694d2dc bridge, frontends: display presence with the highest priority + reset your own presence when you (dis)connect
souliane <souliane@mailoo.org>
parents: 916
diff changeset
562 def _setPresence(self, to="", show="", statuses=None, profile_key=C.PROF_KEY_NONE):
a9401694d2dc bridge, frontends: display presence with the highest priority + reset your own presence when you (dis)connect
souliane <souliane@mailoo.org>
parents: 916
diff changeset
563 return self.setPresence(jid.JID(to) if to else None, show, statuses, profile_key)
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 806
diff changeset
564
917
a9401694d2dc bridge, frontends: display presence with the highest priority + reset your own presence when you (dis)connect
souliane <souliane@mailoo.org>
parents: 916
diff changeset
565 def setPresence(self, to_jid=None, show="", statuses=None, profile_key=C.PROF_KEY_NONE):
0
goffi@necton2
parents:
diff changeset
566 """Send our presence information"""
727
c1cd6c0c2c38 core: fixed statuses parameter in setPresence, and using @NONE@ instead of @DEFAULT@ for default profile_key
Goffi <goffi@goffi.org>
parents: 700
diff changeset
567 if statuses is None:
c1cd6c0c2c38 core: fixed statuses parameter in setPresence, and using @NONE@ instead of @DEFAULT@ for default profile_key
Goffi <goffi@goffi.org>
parents: 700
diff changeset
568 statuses = {}
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
569 profile = self.memory.getProfileName(profile_key)
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
570 assert(profile)
917
a9401694d2dc bridge, frontends: display presence with the highest priority + reset your own presence when you (dis)connect
souliane <souliane@mailoo.org>
parents: 916
diff changeset
571 priority = int(self.memory.getParamA("Priority", "Connection", profile_key=profile))
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
572 self.profiles[profile].presence.available(to_jid, show, statuses, priority)
313
cc8ffbfe938c QnD workaround for presence broadcast openfire bug
Goffi <goffi@goffi.org>
parents: 305
diff changeset
573 #XXX: FIXME: temporary fix to work around openfire 3.7.0 bug (presence is not broadcasted to generating resource)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
574 if '' in statuses:
313
cc8ffbfe938c QnD workaround for presence broadcast openfire bug
Goffi <goffi@goffi.org>
parents: 305
diff changeset
575 statuses['default'] = statuses['']
cc8ffbfe938c QnD workaround for presence broadcast openfire bug
Goffi <goffi@goffi.org>
parents: 305
diff changeset
576 del statuses['']
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
577 self.bridge.presenceUpdate(self.profiles[profile].jid.full(), show,
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
578 int(priority), statuses, profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
579
346
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
580 def subscription(self, subs_type, raw_jid, profile_key):
187
12544ea2951f Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents: 155
diff changeset
581 """Called to manage subscription
12544ea2951f Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents: 155
diff changeset
582 @param subs_type: subsciption type (cf RFC 3921)
12544ea2951f Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents: 155
diff changeset
583 @param raw_jid: unicode entity's jid
12544ea2951f Core: removed addItem for roster list, according to http://wokkel.ik.nu/ticket/56
Goffi <goffi@goffi.org>
parents: 155
diff changeset
584 @param profile_key: profile"""
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
585 profile = self.memory.getProfileName(profile_key)
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
586 assert(profile)
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
587 to_jid = jid.JID(raw_jid)
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
588 log.debug(_('subsciption request [%(subs_type)s] for %(jid)s') % {'subs_type': subs_type, 'jid': to_jid.full()})
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
589 if subs_type == "subscribe":
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
590 self.profiles[profile].presence.subscribe(to_jid)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
591 elif subs_type == "subscribed":
89
23caf1051099 multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents: 79
diff changeset
592 self.profiles[profile].presence.subscribed(to_jid)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
593 elif subs_type == "unsubscribe":
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
594 self.profiles[profile].presence.unsubscribe(to_jid)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
595 elif subs_type == "unsubscribed":
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
596 self.profiles[profile].presence.unsubscribed(to_jid)
0
goffi@necton2
parents:
diff changeset
597
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 806
diff changeset
598 def _addContact(self, to_jid_s, profile_key):
846
59d486726577 core: fix mispelled argument
souliane <souliane@mailoo.org>
parents: 834
diff changeset
599 return self.addContact(jid.JID(to_jid_s), profile_key)
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 806
diff changeset
600
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 806
diff changeset
601 def addContact(self, to_jid, profile_key):
0
goffi@necton2
parents:
diff changeset
602 """Add a contact in roster list"""
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
603 profile = self.memory.getProfileName(profile_key)
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
604 assert(profile)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
605 #self.profiles[profile].roster.addItem(to_jid) #XXX: disabled (cf http://wokkel.ik.nu/ticket/56))
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
606 self.profiles[profile].presence.subscribe(to_jid)
0
goffi@necton2
parents:
diff changeset
607
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 806
diff changeset
608 def _updateContact(self, to_jid_s, name, groups, profile_key):
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 806
diff changeset
609 return self.updateContact(jid.JID(to_jid_s), name, groups, profile_key)
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 806
diff changeset
610
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 806
diff changeset
611 def updateContact(self, to_jid, name, groups, profile_key):
346
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
612 """update a contact in roster list"""
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
613 profile = self.memory.getProfileName(profile_key)
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
614 assert(profile)
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
615 groups = set(groups)
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
616 roster_item = RosterItem(to_jid)
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
617 roster_item.name = name or None
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
618 roster_item.groups = set(groups)
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
619 self.profiles[profile].roster.updateItem(roster_item)
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
620
807
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 806
diff changeset
621 def _delContact(self, to_jid_s, profile_key):
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 806
diff changeset
622 return self.delContact(jid.JID(to_jid_s), profile_key)
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 806
diff changeset
623
be4c5e24dab9 plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents: 806
diff changeset
624 def delContact(self, to_jid, profile_key):
0
goffi@necton2
parents:
diff changeset
625 """Remove contact from roster list"""
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
626 profile = self.memory.getProfileName(profile_key)
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
627 assert(profile)
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
628 self.profiles[profile].roster.removeItem(to_jid)
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
629 self.profiles[profile].presence.unsubscribe(to_jid)
0
goffi@necton2
parents:
diff changeset
630
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
631
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 943
diff changeset
632 ## Discovery ##
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 943
diff changeset
633 # discovery methods are shortcuts to self.memory.disco
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 943
diff changeset
634 # the main difference with client.disco is that self.memory.disco manage cache
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
635
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 943
diff changeset
636 def hasFeature(self, *args, **kwargs):
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 943
diff changeset
637 return self.memory.disco.hasFeature(*args, **kwargs)
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
638
951
027a054c6dda core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents: 949
diff changeset
639 def checkFeature(self, *args, **kwargs):
027a054c6dda core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents: 949
diff changeset
640 return self.memory.disco.checkFeature(*args, **kwargs)
027a054c6dda core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents: 949
diff changeset
641
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 943
diff changeset
642 def getDiscoInfos(self, *args, **kwargs):
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 943
diff changeset
643 return self.memory.disco.getInfos(*args, **kwargs)
0
goffi@necton2
parents:
diff changeset
644
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 943
diff changeset
645 def getDiscoItems(self, *args, **kwargs):
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 943
diff changeset
646 return self.memory.disco.getItems(*args, **kwargs)
0
goffi@necton2
parents:
diff changeset
647
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 943
diff changeset
648 def findServiceEntities(self, *args, **kwargs):
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 943
diff changeset
649 return self.memory.disco.findServiceEntities(*args, **kwargs)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
650
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 943
diff changeset
651 def findFeaturesSet(self, *args, **kwargs):
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 943
diff changeset
652 return self.memory.disco.findFeaturesSet(*args, **kwargs)
397
ccfd69d090c3 core: workaround to avoid a bug in item detection on jabber.fr. Need more investigation with jabber.fr admins (may be a bug in ejabberd)
Goffi <goffi@goffi.org>
parents: 391
diff changeset
653
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
654
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
655 ## Generic HMI ##
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
656
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
657 def actionResult(self, action_id, action_type, data, profile):
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
658 """Send the result of an action
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
659 @param action_id: same action_id used with action
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
660 @param action_type: result action_type ("PARAM", "SUCCESS", "ERROR", "XMLUI")
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
661 @param data: dictionary
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
662 """
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
663 self.bridge.actionResult(action_type, action_id, data, profile)
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
664
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
665 def actionResultExt(self, action_id, action_type, data, profile):
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
666 """Send the result of an action, extended version
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
667 @param action_id: same action_id used with action
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
668 @param action_type: result action_type /!\ only "DICT_DICT" for this method
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
669 @param data: dictionary of dictionaries
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
670 """
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
671 if action_type != "DICT_DICT":
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
672 log.error(_("action_type for actionResultExt must be DICT_DICT, fixing it"))
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
673 action_type = "DICT_DICT"
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
674 self.bridge.actionResultExt(action_type, action_id, data, profile)
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
675
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
676 def askConfirmation(self, conf_id, conf_type, data, cb, profile):
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
677 """Add a confirmation callback
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
678 @param conf_id: conf_id used to get answer
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
679 @param conf_type: confirmation conf_type ("YES/NO", "FILE_TRANSFER")
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
680 @param data: data (depend of confirmation conf_type)
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
681 @param cb: callback called with the answer
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
682 """
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
683 # FIXME: use XMLUI and *callback methods for dialog
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
684 client = self.getClient(profile)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
685 if conf_id in client._waiting_conf:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
686 log.error(_("Attempt to register two callbacks for the same confirmation"))
0
goffi@necton2
parents:
diff changeset
687 else:
541
8b116fa42a31 core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents: 538
diff changeset
688 client._waiting_conf[conf_id] = (conf_type, data, cb)
8b116fa42a31 core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents: 538
diff changeset
689 self.bridge.askConfirmation(conf_id, conf_type, data, profile)
0
goffi@necton2
parents:
diff changeset
690
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
691 def confirmationAnswer(self, conf_id, accepted, data, profile):
0
goffi@necton2
parents:
diff changeset
692 """Called by frontends to answer confirmation requests"""
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
693 client = self.getClient(profile)
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
694 log.debug(_("Received confirmation answer for conf_id [%(conf_id)s]: %(success)s") % {'conf_id': conf_id, 'success': _("accepted") if accepted else _("refused")})
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
695 if conf_id not in client._waiting_conf:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
696 log.error(_("Received an unknown confirmation (%(id)s for %(profile)s)") % {'id': conf_id, 'profile': profile})
0
goffi@necton2
parents:
diff changeset
697 else:
541
8b116fa42a31 core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents: 538
diff changeset
698 cb = client._waiting_conf[conf_id][-1]
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
699 del client._waiting_conf[conf_id]
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
700 cb(conf_id, accepted, data, profile)
0
goffi@necton2
parents:
diff changeset
701
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
702 def registerProgressCB(self, progress_id, CB, profile):
0
goffi@necton2
parents:
diff changeset
703 """Register a callback called when progress is requested for id"""
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
704 client = self.getClient(profile)
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
705 client._progress_cb_map[progress_id] = CB
0
goffi@necton2
parents:
diff changeset
706
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
707 def removeProgressCB(self, progress_id, profile):
0
goffi@necton2
parents:
diff changeset
708 """Remove a progress callback"""
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
709 client = self.getClient(profile)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
710 if progress_id not in client._progress_cb_map:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
711 log.error(_("Trying to remove an unknow progress callback"))
0
goffi@necton2
parents:
diff changeset
712 else:
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
713 del client._progress_cb_map[progress_id]
0
goffi@necton2
parents:
diff changeset
714
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
715 def getProgress(self, progress_id, profile):
0
goffi@necton2
parents:
diff changeset
716 """Return a dict with progress information
goffi@necton2
parents:
diff changeset
717 data['position'] : current possition
goffi@necton2
parents:
diff changeset
718 data['size'] : end_position
goffi@necton2
parents:
diff changeset
719 """
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
720 client = self.getClient(profile)
0
goffi@necton2
parents:
diff changeset
721 data = {}
goffi@necton2
parents:
diff changeset
722 try:
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
723 client._progress_cb_map[progress_id](progress_id, data, profile)
0
goffi@necton2
parents:
diff changeset
724 except KeyError:
goffi@necton2
parents:
diff changeset
725 pass
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
726 #log.debug("Requested progress for unknown progress_id")
0
goffi@necton2
parents:
diff changeset
727 return data
goffi@necton2
parents:
diff changeset
728
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
729 def registerCallback(self, callback, *args, **kwargs):
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
730 """ Register a callback.
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
731 Use with_data=True in kwargs if the callback use the optional data dict
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
732 use force_id=id to avoid generated id. Can lead to name conflict, avoid if possible
806
5d6c45d6ee1b core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents: 801
diff changeset
733 use one_shot=True to delete callback once it have been called
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
734 @param callback: any callable
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
735 @return: id of the registered callback
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
736 """
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
737 callback_id = kwargs.pop('force_id', None)
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
738 if callback_id is None:
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
739 callback_id = str(uuid4())
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
740 else:
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
741 if callback_id in self._cb_map:
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
742 raise exceptions.ConflictError(_(u"id already registered"))
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
743 self._cb_map[callback_id] = (callback, args, kwargs)
806
5d6c45d6ee1b core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents: 801
diff changeset
744
5d6c45d6ee1b core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents: 801
diff changeset
745 if "one_shot" in kwargs: # One Shot callback are removed after 30 min
5d6c45d6ee1b core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents: 801
diff changeset
746 def purgeCallback():
5d6c45d6ee1b core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents: 801
diff changeset
747 try:
5d6c45d6ee1b core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents: 801
diff changeset
748 self.removeCallback(callback_id)
5d6c45d6ee1b core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents: 801
diff changeset
749 except KeyError:
5d6c45d6ee1b core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents: 801
diff changeset
750 pass
5d6c45d6ee1b core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents: 801
diff changeset
751 reactor.callLater(1800, purgeCallback)
5d6c45d6ee1b core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents: 801
diff changeset
752
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
753 return callback_id
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
754
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
755 def removeCallback(self, callback_id):
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
756 """ Remove a previously registered callback
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
757 @param callback_id: id returned by [registerCallback] """
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
758 log.debug("Removing callback [%s]" % callback_id)
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
759 del self._cb_map[callback_id]
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
760
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 914
diff changeset
761 def launchCallback(self, callback_id, data=None, profile_key=C.PROF_KEY_NONE):
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
762 """Launch a specific callback
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
763 @param callback_id: id of the action (callback) to launch
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
764 @param data: optional data
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
765 @profile_key: %(doc_profile_key)s
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
766 @return: a deferred which fire a dict where key can be:
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
767 - xmlui: a XMLUI need to be displayed
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
768 """
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
769 profile = self.memory.getProfileName(profile_key)
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
770 if not profile:
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
771 raise exceptions.ProfileUnknownError(_('trying to launch action with a non-existant profile'))
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
772
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
773 try:
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
774 callback, args, kwargs = self._cb_map[callback_id]
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
775 except KeyError:
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
776 raise exceptions.DataError("Unknown callback id")
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
777
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
778 if kwargs.get("with_data", False):
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
779 if data is None:
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
780 raise exceptions.DataError("Required data for this callback is missing")
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
781 args,kwargs=list(args)[:],kwargs.copy() # we don't want to modify the original (kw)args
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
782 args.insert(0, data)
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
783 kwargs["profile"] = profile
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
784 del kwargs["with_data"]
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
785
806
5d6c45d6ee1b core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents: 801
diff changeset
786 if kwargs.pop('one_shot', False):
5d6c45d6ee1b core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents: 801
diff changeset
787 self.removeCallback(callback_id)
5d6c45d6ee1b core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents: 801
diff changeset
788
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
789 return defer.maybeDeferred(callback, *args, **kwargs)
0
goffi@necton2
parents:
diff changeset
790
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
791 #Menus management
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
792
914
1a3ba959f0ab core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents: 909
diff changeset
793 def importMenu(self, path, callback, security_limit=C.NO_SECURITY_LIMIT, help_string="", type_="NORMAL"):
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
794 """register a new menu for frontends
773
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
795 @param path: path to go to the menu (category/subcategory/.../item), must be an iterable (e.g.: ("File", "Open"))
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
796 /!\ use D_() instead of _() for translations (e.g. (D_("File"), D_("Open")))
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
797 @param callback: method to be called when menuitem is selected, callable or a callback id (string) as returned by [registerCallback]
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
798 @param security_limit: %(doc_security_limit)s
809
743b757777d3 core: security limit in menus
Goffi <goffi@goffi.org>
parents: 807
diff changeset
799 /!\ security_limit MUST be added to data in launchCallback if used #TODO
773
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
800 @param help_string: string used to indicate what the menu do (can be show as a tooltip).
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
801 /!\ use D_() instead of _() for translations
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
802 @param type: one of:
801
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 787
diff changeset
803 - GLOBAL: classical menu, can be shown in a menubar on top (e.g. something like File/Open)
02ee9ef95277 plugin XEP-0045, primitivus: added MUC configuration
Goffi <goffi@goffi.org>
parents: 787
diff changeset
804 - ROOM: like a global menu, but only shown in multi-user chat
773
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
805 - JID_CONTEXT: contextual menu, used with any jid (e.g.: ad hoc commands, jid is already filled)
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
806 - ROSTER_JID_CONTEXT: like JID_CONTEXT, but restricted to jids in roster.
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
807 - ROSTER_GROUP_CONTEXT: contextual menu, used with group (e.g.: publish microblog, group is already filled)
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
808 @return: menu_id (same as callback_id)
755
e3ad48a2aab2 core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents: 752
diff changeset
809 """
773
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
810
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
811 if callable(callback):
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
812 callback_id = self.registerCallback(callback, with_data=True)
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
813 elif isinstance(callback, basestring):
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
814 # The callback is already registered
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
815 callback_id = callback
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
816 try:
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
817 callback, args, kwargs = self._cb_map[callback_id]
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
818 except KeyError:
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
819 raise exceptions.DataError("Unknown callback id")
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
820 kwargs["with_data"] = True # we have to be sure that we use extra data
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
821 else:
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
822 raise exceptions.DataError("Unknown callback type")
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
823
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
824 for menu_data in self._menus.itervalues():
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
825 if menu_data['path'] == path and menu_data['type'] == type_:
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
826 raise exceptions.ConflictError(_("A menu with the same path and type already exists"))
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
827
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
828 menu_data = {'path': path,
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
829 'security_limit': security_limit,
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
830 'help_string': help_string,
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
831 'type': type_
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
832 }
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
833
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
834 self._menus[callback_id] = menu_data
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
835
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
836 return callback_id
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
837
914
1a3ba959f0ab core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents: 909
diff changeset
838 def getMenus(self, language='', security_limit=C.NO_SECURITY_LIMIT):
773
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
839 """Return all menus registered
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
840 @param language: language used for translation, or empty string for default
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
841 @param security_limit: %(doc_security_limit)s
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
842 @return: array of tuple with:
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
843 - menu id (same as callback_id)
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
844 - menu type
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
845 - raw menu path (array of strings)
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
846 - translated menu path
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
847
773
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
848 """
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
849 ret = []
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
850 for menu_id, menu_data in self._menus.iteritems():
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
851 type_ = menu_data['type']
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
852 path = menu_data['path']
809
743b757777d3 core: security limit in menus
Goffi <goffi@goffi.org>
parents: 807
diff changeset
853 menu_security_limit = menu_data['security_limit']
914
1a3ba959f0ab core (memory): moved Params in its own module + introduced a new core/constants module, and moved some constants there
Goffi <goffi@goffi.org>
parents: 909
diff changeset
854 if security_limit!=C.NO_SECURITY_LIMIT and (menu_security_limit==C.NO_SECURITY_LIMIT or menu_security_limit>security_limit):
809
743b757777d3 core: security limit in menus
Goffi <goffi@goffi.org>
parents: 807
diff changeset
855 continue
773
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
856 languageSwitch(language)
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
857 path_i18n = [_(elt) for elt in path]
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
858 languageSwitch()
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
859 ret.append((menu_id, type_, path, path_i18n))
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
860
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
861 return ret
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
862
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
863 def getMenuHelp(self, menu_id, language=''):
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
864 """
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
865 return the help string of the menu
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
866 @param menu_id: id of the menu (same as callback_id)
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
867 @param language: language used for translation, or empty string for default
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
868 @param return: translated help
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
869
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
870 """
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
871 try:
773
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
872 menu_data = self._menus[menu_id]
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
873 except KeyError:
755
e3ad48a2aab2 core, frontends: callMenu is now async and don't use callback_id anymore
Goffi <goffi@goffi.org>
parents: 752
diff changeset
874 raise exceptions.DataError("Trying to access an unknown menu")
773
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
875 languageSwitch(language)
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
876 help_string = _(menu_data['help_string'])
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
877 languageSwitch()
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
878 return help_string