annotate src/core/sat_main.py @ 2134:f45250052846

primitivus: fixed display of error if a message can't be sent
author Goffi <goffi@goffi.org>
date Sun, 05 Feb 2017 14:55:21 +0100
parents 628c1c95f442
children 6e509ee853a8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1934
2daf7b4c6756 use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
1 #!/usr/bin/env python2
0
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
1766
d17772b0fe22 copyright update
Goffi <goffi@goffi.org>
parents: 1725
diff changeset
5 # Copyright (C) 2009-2016 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
1376
28fd9e838f8f core: getRepositoryData now get the module in argument
Goffi <goffi@goffi.org>
parents: 1375
diff changeset
20 import sat
1591
0df9c6247474 core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents: 1587
diff changeset
21 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
22 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
23 from twisted.internet import defer
1037
6e975c6b0faf core, memory, bridge, plugin misc_register_account: move registerNewAccount to a new plugin:
souliane <souliane@mailoo.org>
parents: 1032
diff changeset
24 from twisted.words.protocols.jabber import jid
0
goffi@necton2
parents:
diff changeset
25 from twisted.words.xish import domish
goffi@necton2
parents:
diff changeset
26 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
27 from wokkel.xmppim import RosterItem
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
1374
0befb14ecf62 renamed tools.misc to tools.trigger
Goffi <goffi@goffi.org>
parents: 1365
diff changeset
34 from sat.tools import trigger
1375
3a20312d4012 core: if we are in dev version and it's possible, repository data are now checked and added to SàT version
Goffi <goffi@goffi.org>
parents: 1374
diff changeset
35 from sat.tools import utils
2088
c02f96756d5c core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
36 from sat.tools.common import dynamic_import
1032
b262ae6d53af stdui: add ui_profile_manager to interact with frontends when profile authentication is needed
souliane <souliane@mailoo.org>
parents: 1030
diff changeset
37 from sat.stdui import ui_contact_list, ui_profile_manager
2105
c96fe007ca41 core(constants): added a constant for profile extension (PLUGIN_EXT):
Goffi <goffi@goffi.org>
parents: 2100
diff changeset
38 import sat.plugins
0
goffi@necton2
parents:
diff changeset
39 from glob import glob
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
40 from uuid import uuid4
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
41 import sys
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
42 import os.path
1467
ceba6fd77739 core, bridge: new signal actionNew to launch an action from the backend (e.g. display a dialog message):
Goffi <goffi@goffi.org>
parents: 1417
diff changeset
43 import uuid
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
44 import time
0
goffi@necton2
parents:
diff changeset
45
987
3a96920c07b7 core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents: 972
diff changeset
46 try:
3a96920c07b7 core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents: 972
diff changeset
47 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
48 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
49 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
50
0
goffi@necton2
parents:
diff changeset
51
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
52 class SAT(service.Service):
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
53
0
goffi@necton2
parents:
diff changeset
54 def __init__(self):
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
55 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
56 self._menus = OrderedDict() # dynamic menus. key: callback_id, value: menu data (dictionnary)
2126
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
57 self._menus_paths = {} # path to id. key: (menu_type, lower case tuple of path), value: menu id
1591
0df9c6247474 core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents: 1587
diff changeset
58 self.initialised = defer.Deferred()
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
59 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
60 self.plugins = {}
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
61
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
62 self.memory = Memory(self)
1374
0befb14ecf62 renamed tools.misc to tools.trigger
Goffi <goffi@goffi.org>
parents: 1365
diff changeset
63 self.trigger = 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
64
2088
c02f96756d5c core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
65 bridge_name = self.memory.getConfig('', 'bridge', 'dbus')
c02f96756d5c core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
66
c02f96756d5c core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
67 bridge_module = dynamic_import.bridge(bridge_name)
c02f96756d5c core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
68 if bridge_module is None:
c02f96756d5c core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
69 log.error(u"Can't find bridge module of name {}".format(bridge_name))
c02f96756d5c core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
70 sys.exit(1)
c02f96756d5c core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
71 log.info(u"using {} bridge".format(bridge_name))
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
72 try:
2088
c02f96756d5c core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
73 self.bridge = bridge_module.Bridge()
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
74 except exceptions.BridgeInitError:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
75 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
76 sys.exit(1)
2086
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
77 self.bridge.register_method("getReady", lambda: self.initialised)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
78 self.bridge.register_method("getVersion", lambda: self.full_version)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
79 self.bridge.register_method("getFeatures", self.getFeatures)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
80 self.bridge.register_method("getProfileName", self.memory.getProfileName)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
81 self.bridge.register_method("getProfilesList", self.memory.getProfilesList)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
82 self.bridge.register_method("getEntityData", lambda jid_, keys, profile: self.memory.getEntityData(jid.JID(jid_), keys, profile))
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
83 self.bridge.register_method("getEntitiesData", self.memory._getEntitiesData)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
84 self.bridge.register_method("asyncCreateProfile", self.memory.asyncCreateProfile)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
85 self.bridge.register_method("asyncDeleteProfile", self.memory.asyncDeleteProfile)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
86 self.bridge.register_method("profileStartSession", self.memory.startSession)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
87 self.bridge.register_method("profileIsSessionStarted", self.memory._isSessionStarted)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
88 self.bridge.register_method("profileSetDefault", self.memory.profileSetDefault)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
89 self.bridge.register_method("asyncConnect", self._asyncConnect)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
90 self.bridge.register_method("disconnect", self.disconnect)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
91 self.bridge.register_method("getContacts", self.getContacts)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
92 self.bridge.register_method("getContactsFromGroup", self.getContactsFromGroup)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
93 self.bridge.register_method("getMainResource", self.memory._getMainResource)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
94 self.bridge.register_method("getPresenceStatuses", self.memory._getPresenceStatuses)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
95 self.bridge.register_method("getWaitingSub", self.memory.getWaitingSub)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
96 self.bridge.register_method("messageSend", self._messageSend)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
97 self.bridge.register_method("getConfig", self._getConfig)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
98 self.bridge.register_method("setParam", self.setParam)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
99 self.bridge.register_method("getParamA", self.memory.getStringParamA)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
100 self.bridge.register_method("asyncGetParamA", self.memory.asyncGetStringParamA)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
101 self.bridge.register_method("asyncGetParamsValuesFromCategory", self.memory.asyncGetParamsValuesFromCategory)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
102 self.bridge.register_method("getParamsUI", self.memory.getParamsUI)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
103 self.bridge.register_method("getParamsCategories", self.memory.getParamsCategories)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
104 self.bridge.register_method("paramsRegisterApp", self.memory.paramsRegisterApp)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
105 self.bridge.register_method("historyGet", self.memory._historyGet)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
106 self.bridge.register_method("setPresence", self._setPresence)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
107 self.bridge.register_method("subscription", self.subscription)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
108 self.bridge.register_method("addContact", self._addContact)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
109 self.bridge.register_method("updateContact", self._updateContact)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
110 self.bridge.register_method("delContact", self._delContact)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
111 self.bridge.register_method("isConnected", self.isConnected)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
112 self.bridge.register_method("launchAction", self.launchCallback)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
113 self.bridge.register_method("actionsGet", self.actionsGet)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
114 self.bridge.register_method("progressGet", self._progressGet)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
115 self.bridge.register_method("progressGetAll", self._progressGetAll)
2126
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
116 self.bridge.register_method("menusGet", self.getMenus)
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
117 self.bridge.register_method("menuHelpGet", self.getMenuHelp)
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
118 self.bridge.register_method("menuLaunch", self._launchMenu)
2086
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
119 self.bridge.register_method("discoInfos", self.memory.disco._discoInfos)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
120 self.bridge.register_method("discoItems", self.memory.disco._discoItems)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
121 self.bridge.register_method("saveParamsTemplate", self.memory.save_xml)
4633cfcbcccb bridge (D-Bus): bad design fixes:
Goffi <goffi@goffi.org>
parents: 2050
diff changeset
122 self.bridge.register_method("loadParamsTemplate", self.memory.load_xml)
2113
9c861d07b5b6 core: added sessionGetInfos bridge method to retrieve various data on current profile session + client.started keep start time
Goffi <goffi@goffi.org>
parents: 2105
diff changeset
123 self.bridge.register_method("sessionInfosGet", self.getSessionInfos)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
124
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
125 self.memory.initialized.addCallback(self._postMemoryInit)
0
goffi@necton2
parents:
diff changeset
126
1550
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
127 @property
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
128 def version(self):
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
129 """Return the short version of SàT"""
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
130 return C.APP_VERSION
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
131
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
132 @property
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
133 def full_version(self):
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
134 """Return the full version of SàT (with extra data when in development mode)"""
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
135 version = self.version
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
136 if version[-1] == 'D':
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
137 # we are in debug version, we add extra data
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
138 try:
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
139 return self._version_cache
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
140 except AttributeError:
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
141 self._version_cache = u"{} ({})".format(version, utils.getRepositoryData(sat))
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
142 return self._version_cache
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
143 else:
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
144 return version
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
145
2088
c02f96756d5c core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
146 @property
c02f96756d5c core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
147 def bridge_name(self):
c02f96756d5c core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
148 return os.path.splitext(os.path.basename(self.bridge.__file__))[0]
c02f96756d5c core: bridge can now be changed in conf
Goffi <goffi@goffi.org>
parents: 2086
diff changeset
149
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
150 def _postMemoryInit(self, ignore):
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
151 """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
152 log.info(_("Memory initialised"))
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
153 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
154 ui_contact_list.ContactList(self)
1032
b262ae6d53af stdui: add ui_profile_manager to interact with frontends when profile authentication is needed
souliane <souliane@mailoo.org>
parents: 1030
diff changeset
155 ui_profile_manager.ProfileManager(self)
1591
0df9c6247474 core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents: 1587
diff changeset
156 self.initialised.callback(None)
2089
0931b5a6213c core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents: 2088
diff changeset
157 log.info(_(u"Backend is ready"))
0
goffi@necton2
parents:
diff changeset
158
goffi@necton2
parents:
diff changeset
159 def _import_plugins(self):
goffi@necton2
parents:
diff changeset
160 """Import all plugins found in plugins directory"""
2105
c96fe007ca41 core(constants): added a constant for profile extension (PLUGIN_EXT):
Goffi <goffi@goffi.org>
parents: 2100
diff changeset
161 plugins_path = os.path.dirname(sat.plugins.__file__)
c96fe007ca41 core(constants): added a constant for profile extension (PLUGIN_EXT):
Goffi <goffi@goffi.org>
parents: 2100
diff changeset
162 plugin_glob = "plugin*." + C.PLUGIN_EXT
2089
0931b5a6213c core, quick_frontends: android compatibility hacks:
Goffi <goffi@goffi.org>
parents: 2088
diff changeset
163 plug_lst = [os.path.splitext(plugin)[0] for plugin in map(os.path.basename, glob(os.path.join(plugins_path, plugin_glob)))]
1503
f681788097ba core (plugins): detect import_name conflicts
Goffi <goffi@goffi.org>
parents: 1491
diff changeset
164 plugins_to_import = {} # plugins we still have to import
0
goffi@necton2
parents:
diff changeset
165 for plug in plug_lst:
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
166 plugin_path = 'sat.plugins.' + plug
1145
4e1a0a1523f1 core: more robust plugins importation
Goffi <goffi@goffi.org>
parents: 1130
diff changeset
167 try:
4e1a0a1523f1 core: more robust plugins importation
Goffi <goffi@goffi.org>
parents: 1130
diff changeset
168 __import__(plugin_path)
1535
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
169 except exceptions.MissingModule as e:
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
170 try:
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
171 del sys.modules[plugin_path]
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
172 except KeyError:
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
173 pass
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
174 log.warning(u"Can't import plugin [{path}] because of an unavailale third party module:\n{msg}".format(
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
175 path=plugin_path, msg=e))
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
176 continue
2100
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
177 except exceptions.CancelError as e:
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
178 log.info(u"Plugin [{path}] cancelled its own import: {msg}".format(path=plugin_path, msg=e))
fbeeba721954 plugin android: first draft:
Goffi <goffi@goffi.org>
parents: 2089
diff changeset
179 continue
1535
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
180 except Exception as e:
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
181 import traceback
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
182 log.error(_(u"Can't import plugin [{path}]:\n{error}").format(path=plugin_path, error=traceback.format_exc()))
1145
4e1a0a1523f1 core: more robust plugins importation
Goffi <goffi@goffi.org>
parents: 1130
diff changeset
183 continue
287
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
184 mod = sys.modules[plugin_path]
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
185 plugin_info = mod.PLUGIN_INFO
1503
f681788097ba core (plugins): detect import_name conflicts
Goffi <goffi@goffi.org>
parents: 1491
diff changeset
186 import_name = plugin_info['import_name']
f681788097ba core (plugins): detect import_name conflicts
Goffi <goffi@goffi.org>
parents: 1491
diff changeset
187 if import_name in plugins_to_import:
f681788097ba core (plugins): detect import_name conflicts
Goffi <goffi@goffi.org>
parents: 1491
diff changeset
188 log.error(_(u"Name conflict for import name [{import_name}], can't import plugin [{name}]").format(**plugin_info))
f681788097ba core (plugins): detect import_name conflicts
Goffi <goffi@goffi.org>
parents: 1491
diff changeset
189 continue
f681788097ba core (plugins): detect import_name conflicts
Goffi <goffi@goffi.org>
parents: 1491
diff changeset
190 plugins_to_import[import_name] = (plugin_path, mod, plugin_info)
287
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
191 while True:
1535
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
192 try:
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
193 self._import_plugins_from_dict(plugins_to_import)
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
194 except ImportError:
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
195 pass
1503
f681788097ba core (plugins): detect import_name conflicts
Goffi <goffi@goffi.org>
parents: 1491
diff changeset
196 if not plugins_to_import:
287
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
197 break
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
198
925
5c78cefd233f core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents: 923
diff changeset
199 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
200 """Recursively import and their dependencies in the right order
925
5c78cefd233f core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents: 923
diff changeset
201
1535
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
202 @param plugins_to_import(dict): key=import_name and values=(plugin_path, module, plugin_info)
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
203 @param import_name(unicode, None): name of the plugin to import as found in PLUGIN_INFO['import_name']
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
204 @param optional(bool): if False and plugin is not found, an ImportError exception is raised
925
5c78cefd233f core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents: 923
diff changeset
205 """
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
206 if import_name in self.plugins:
1535
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
207 log.debug(u'Plugin {} already imported, passing'.format(import_name))
287
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
208 return
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
209 if not import_name:
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
210 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
211 else:
288
76247af9917c core: added plugin dependency not found import error
Goffi <goffi@goffi.org>
parents: 287
diff changeset
212 if not import_name in plugins_to_import:
925
5c78cefd233f core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents: 923
diff changeset
213 if optional:
1535
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
214 log.warning(_(u"Recommended plugin not found: {}").format(import_name))
925
5c78cefd233f core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents: 923
diff changeset
215 return
1535
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
216 msg = u"Dependency not found: {}".format(import_name)
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
217 log.error(msg)
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
218 raise ImportError(msg)
287
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
219 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
220 dependencies = plugin_info.setdefault("dependencies", [])
925
5c78cefd233f core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents: 923
diff changeset
221 recommendations = plugin_info.setdefault("recommendations", [])
5c78cefd233f core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents: 923
diff changeset
222 for to_import in dependencies + recommendations:
5c78cefd233f core: plugins now accepts recommendations:
Goffi <goffi@goffi.org>
parents: 923
diff changeset
223 if to_import not in self.plugins:
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
224 log.debug(u'Recursively import dependency of [%s]: [%s]' % (import_name, to_import))
1145
4e1a0a1523f1 core: more robust plugins importation
Goffi <goffi@goffi.org>
parents: 1130
diff changeset
225 try:
4e1a0a1523f1 core: more robust plugins importation
Goffi <goffi@goffi.org>
parents: 1130
diff changeset
226 self._import_plugins_from_dict(plugins_to_import, to_import, to_import not in dependencies)
4e1a0a1523f1 core: more robust plugins importation
Goffi <goffi@goffi.org>
parents: 1130
diff changeset
227 except ImportError as e:
1535
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
228 log.warning(_(u"Can't import plugin {name}: {error}").format(name=plugin_info['name'], error=e))
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
229 if optional:
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
230 return
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
231 raise e
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
232 log.info("importing plugin: {}".format(plugin_info['name']))
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
233 # we instanciate the plugin here
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
234 try:
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
235 self.plugins[import_name] = getattr(mod, plugin_info['main'])(self)
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
236 except Exception as e:
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
237 log.warning(u'Error while loading plugin "{name}", ignoring it: {error}'
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
238 .format(name=plugin_info['name'], error=e))
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
239 if optional:
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
240 return
c9ef16de3f13 core: more robust plugins loading:
Goffi <goffi@goffi.org>
parents: 1533
diff changeset
241 raise ImportError(u"Error during initiation")
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
242 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
243 self.plugins[import_name].is_handler = True
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
244 else:
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
245 self.plugins[import_name].is_handler = False
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
246 #TODO: test xmppclient presence and register handler parent
0
goffi@necton2
parents:
diff changeset
247
1550
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
248 def pluginsUnload(self):
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
249 """Call unload method on every loaded plugin, if exists
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
250
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
251 @return (D): A deferred which return None when all method have been called
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
252 """
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
253 # TODO: in the futur, it should be possible to hot unload a plugin
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
254 # pluging depending on the unloaded one should be unloaded too
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
255 # for now, just a basic call on plugin.unload is done
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
256 defers_list = []
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
257 for plugin in self.plugins.itervalues():
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
258 try:
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
259 unload = plugin.unload
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
260 except AttributeError:
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
261 continue
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
262 else:
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
263 defers_list.append(defer.maybeDeferred(unload))
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
264 return defers_list
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
265
1591
0df9c6247474 core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents: 1587
diff changeset
266 def _asyncConnect(self, profile_key, password=''):
0df9c6247474 core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents: 1587
diff changeset
267 profile = self.memory.getProfileName(profile_key)
0df9c6247474 core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents: 1587
diff changeset
268 return self.asyncConnect(profile, password)
0df9c6247474 core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents: 1587
diff changeset
269
1725
c1be6363bfab core, plugin misc_account: set XMPP connection max retries to 0 when checking if an external account exists
souliane <souliane@mailoo.org>
parents: 1694
diff changeset
270 def asyncConnect(self, profile, password='', max_retries=C.XMPP_MAX_RETRIES):
1030
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
271 """Retrieve the individual parameters, authenticate the profile
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
272 and initiate the connection to the associated XMPP server.
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
273
1725
c1be6363bfab core, plugin misc_account: set XMPP connection max retries to 0 when checking if an external account exists
souliane <souliane@mailoo.org>
parents: 1694
diff changeset
274 @param profile: %(doc_profile)s
1030
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
275 @param password (string): the SàT profile password
1725
c1be6363bfab core, plugin misc_account: set XMPP connection max retries to 0 when checking if an external account exists
souliane <souliane@mailoo.org>
parents: 1694
diff changeset
276 @param max_retries (int): max number of connection retries
1591
0df9c6247474 core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents: 1587
diff changeset
277 @return (D(bool)):
0df9c6247474 core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents: 1587
diff changeset
278 - True if the XMPP connection was already established
0df9c6247474 core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents: 1587
diff changeset
279 - False if the XMPP connection has been initiated (it may still fail)
0df9c6247474 core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents: 1587
diff changeset
280 @raise exceptions.PasswordError: Profile password is wrong
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
281 """
1591
0df9c6247474 core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents: 1587
diff changeset
282 def connectXMPPClient(dummy=None):
0df9c6247474 core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents: 1587
diff changeset
283 if self.isConnected(profile):
0df9c6247474 core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents: 1587
diff changeset
284 log.info(_("already connected !"))
0df9c6247474 core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents: 1587
diff changeset
285 return True
1725
c1be6363bfab core, plugin misc_account: set XMPP connection max retries to 0 when checking if an external account exists
souliane <souliane@mailoo.org>
parents: 1694
diff changeset
286 d = self._connectXMPPClient(profile, max_retries)
1591
0df9c6247474 core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents: 1587
diff changeset
287 return d.addCallback(lambda dummy: False)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
288
1591
0df9c6247474 core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents: 1587
diff changeset
289 d = self.memory.startSession(password, profile)
0df9c6247474 core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents: 1587
diff changeset
290 d.addCallback(connectXMPPClient)
0df9c6247474 core: profile session starting and connection are now separated. Moved profile session starting/authentication to memory module
Goffi <goffi@goffi.org>
parents: 1587
diff changeset
291 return d
1019
6a16ec17a458 better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1015
diff changeset
292
1030
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
293 @defer.inlineCallbacks
1725
c1be6363bfab core, plugin misc_account: set XMPP connection max retries to 0 when checking if an external account exists
souliane <souliane@mailoo.org>
parents: 1694
diff changeset
294 def _connectXMPPClient(self, profile, max_retries):
1030
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
295 """This part is called from asyncConnect when we have loaded individual parameters from memory"""
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
296 try:
1088
b29452cab50b core, memory, plugins, stdui, frontends: look for DNS SRV records when server is not specified:
souliane <souliane@mailoo.org>
parents: 1063
diff changeset
297 port = int(self.memory.getParamA(C.FORCE_PORT_PARAM, "Connection", profile_key=profile))
1030
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
298 except ValueError:
1096
77751f5b2242 core: use of debug log instead of error when port default value is used
Goffi <goffi@goffi.org>
parents: 1092
diff changeset
299 log.debug(_("Can't parse port value, using default value"))
1089
8e0072754413 core, plugins, stdui, frontends: fixes handling of "Force server" and "Force port" parameters:
souliane <souliane@mailoo.org>
parents: 1088
diff changeset
300 port = None # will use default value 5222 or be retrieved from a DNS SRV record
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
301
1030
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
302 password = yield self.memory.asyncGetParamA("Password", "Connection", profile_key=profile)
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
303 current = self.profiles[profile] = xmpp.SatXMPPClient(self, profile,
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
304 jid.JID(self.memory.getParamA("JabberID", "Connection", profile_key=profile)),
1725
c1be6363bfab core, plugin misc_account: set XMPP connection max retries to 0 when checking if an external account exists
souliane <souliane@mailoo.org>
parents: 1694
diff changeset
305 password, self.memory.getParamA(C.FORCE_SERVER_PARAM, "Connection", profile_key=profile),
c1be6363bfab core, plugin misc_account: set XMPP connection max retries to 0 when checking if an external account exists
souliane <souliane@mailoo.org>
parents: 1694
diff changeset
306 port, max_retries)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
307
1030
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
308 current.messageProt = xmpp.SatMessageProtocol(self)
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
309 current.messageProt.setHandlerParent(current)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
310
1030
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
311 current.roster = xmpp.SatRosterProtocol(self)
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
312 current.roster.setHandlerParent(current)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
313
1030
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
314 current.presence = xmpp.SatPresenceProtocol(self)
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
315 current.presence.setHandlerParent(current)
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
316
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
317 current.fallBack = xmpp.SatFallbackHandler(self)
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
318 current.fallBack.setHandlerParent(current)
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
319
1030
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
320 current.versionHandler = xmpp.SatVersionHandler(C.APP_NAME_FULL,
1375
3a20312d4012 core: if we are in dev version and it's possible, repository data are now checked and added to SàT version
Goffi <goffi@goffi.org>
parents: 1374
diff changeset
321 self.full_version)
1030
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
322 current.versionHandler.setHandlerParent(current)
14
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
323
1030
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
324 current.identityHandler = xmpp.SatIdentityHandler()
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
325 current.identityHandler.setHandlerParent(current)
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
326
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
327 log.debug(_("setting plugins parents"))
666
2a7185b8452c core: added SatIdentityHandler for Disco Identity, and set identity to "client/pc/Salut à Toi"
Goffi <goffi@goffi.org>
parents: 641
diff changeset
328
1030
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
329 plugin_conn_cb = []
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
330 for plugin in self.plugins.iteritems():
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
331 if plugin[1].is_handler:
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
332 plugin[1].getHandler(profile).setHandlerParent(current)
1316
8adcdf2cdfe1 core: added a "profileConnecting" method check:
Goffi <goffi@goffi.org>
parents: 1314
diff changeset
333 connected_cb = getattr(plugin[1], "profileConnected", None) # profile connected is called after client is ready and roster is got
1030
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
334 if connected_cb:
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
335 plugin_conn_cb.append((plugin[0], connected_cb))
1316
8adcdf2cdfe1 core: added a "profileConnecting" method check:
Goffi <goffi@goffi.org>
parents: 1314
diff changeset
336 try:
8adcdf2cdfe1 core: added a "profileConnecting" method check:
Goffi <goffi@goffi.org>
parents: 1314
diff changeset
337 yield plugin[1].profileConnecting(profile) # profile connecting is called before actually starting client
8adcdf2cdfe1 core: added a "profileConnecting" method check:
Goffi <goffi@goffi.org>
parents: 1314
diff changeset
338 except AttributeError:
8adcdf2cdfe1 core: added a "profileConnecting" method check:
Goffi <goffi@goffi.org>
parents: 1314
diff changeset
339 pass
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
340
1030
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
341 current.startService()
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
342
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
343 yield current.getConnectionDeferred()
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
344 yield current.roster.got_roster # we want to be sure that we got the roster
14
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
345
1030
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
346 # Call profileConnected callback for all plugins, and print error message if any of them fails
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
347 conn_cb_list = []
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
348 for dummy, callback in plugin_conn_cb:
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
349 conn_cb_list.append(defer.maybeDeferred(callback, profile))
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
350 list_d = defer.DeferredList(conn_cb_list)
972
07b817f5a197 core: better plugin initialisation sequence:
Goffi <goffi@goffi.org>
parents: 963
diff changeset
351
1030
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
352 def logPluginResults(results):
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
353 all_succeed = all([success for success, result in results])
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
354 if not all_succeed:
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
355 log.error(_(u"Plugins initialisation error"))
1030
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
356 for idx, (success, result) in enumerate(results):
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
357 if not success:
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
358 log.error(u"error (plugin %(name)s): %(failure)s" %
1030
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
359 {'name': plugin_conn_cb[idx][0], 'failure': result})
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
360
1189
7d640c303140 core (disco): added a timeout to get items
Goffi <goffi@goffi.org>
parents: 1148
diff changeset
361 yield list_d.addCallback(logPluginResults) # FIXME: we should have a timeout here, and a way to know if a plugin freeze
1316
8adcdf2cdfe1 core: added a "profileConnecting" method check:
Goffi <goffi@goffi.org>
parents: 1314
diff changeset
362 # TODO: mesure launch time of each plugin
1030
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
363
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
364 def disconnect(self, profile_key):
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
365 """disconnect from jabber server"""
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
366 if not self.isConnected(profile_key):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
367 log.info(_("not connected !"))
6
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
368 return
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
369 profile = self.memory.getProfileName(profile_key)
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
370 log.info(_("Disconnecting..."))
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
371 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
372 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
373 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
374 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
375 disconnected_cb(profile)
6
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
376
1482
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
377 def getFeatures(self, profile_key=C.PROF_KEY_NONE):
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
378 """Get available features
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
379
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
380 Return list of activated plugins and plugin specific data
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
381 @param profile_key: %(doc_profile_key)s
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
382 C.PROF_KEY_NONE can be used to have general plugins data (i.e. not profile dependent)
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
383 @return (dict)[Deferred]: features data where:
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
384 - key is plugin import name, present only for activated plugins
1650
b08b828a87c9 quick frontend (blog): fixed group blog panels (displaying only, sending is not working yet)
Goffi <goffi@goffi.org>
parents: 1644
diff changeset
385 - value is a an other dict, when meaning is specific to each plugin.
1482
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
386 this dict is return by plugin's getFeature method.
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
387 If this method doesn't exists, an empty dict is returned.
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
388 """
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
389 try:
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
390 # FIXME: there is no method yet to check profile session
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
391 # as soon as one is implemented, it should be used here
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
392 self.getClient(profile_key)
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
393 except KeyError:
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
394 log.warning("Requesting features for a profile outside a session")
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
395 profile_key = C.PROF_KEY_NONE
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
396 except exceptions.ProfileNotSetError:
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
397 pass
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
398
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
399 features = []
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
400 for import_name, plugin in self.plugins.iteritems():
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
401 try:
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
402 features_d = defer.maybeDeferred(plugin.getFeatures, profile_key)
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
403 except AttributeError:
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
404 features_d = defer.succeed({})
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
405 features.append(features_d)
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
406
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
407 d_list = defer.DeferredList(features)
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
408 def buildFeatures(result, import_names):
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
409 assert len(result) == len(import_names)
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
410 ret = {}
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
411 for name, (success, data) in zip (import_names, result):
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
412 if success:
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
413 ret[name] = data
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
414 else:
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
415 log.warning(u"Error while getting features for {name}: {failure}".format(
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
416 name=name, failure=data))
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
417 ret[name] = {}
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
418 return ret
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
419
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
420 d_list.addCallback(buildFeatures, self.plugins.keys())
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
421 return d_list
80cd55dd5b04 core, bridge: added getFeatures method:
Goffi <goffi@goffi.org>
parents: 1470
diff changeset
422
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 460
diff changeset
423 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
424 client = self.getClient(profile_key)
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1234
diff changeset
425 def got_roster(dummy):
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1234
diff changeset
426 ret = []
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1234
diff changeset
427 for item in client.roster.getItems(): # we get all items for client's roster
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1234
diff changeset
428 # and convert them to expected format
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1234
diff changeset
429 attr = client.roster.getAttributes(item)
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1234
diff changeset
430 ret.append([item.jid.userhost(), attr, item.groups])
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1234
diff changeset
431 return ret
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1234
diff changeset
432
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1234
diff changeset
433 return client.roster.got_roster.addCallback(got_roster)
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 460
diff changeset
434
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 489
diff changeset
435 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
436 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
437 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
438
416
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
439 def purgeClient(self, profile):
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
440 """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
441 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
442 try:
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
443 del self.profiles[profile]
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
444 except KeyError:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
445 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
446 self.memory.purgeProfileSession(profile)
416
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
447
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
448 def startService(self):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
449 log.info(u"Salut à toi ô mon frère !")
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
450
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
451 def stopService(self):
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 999
diff changeset
452 log.info(u"Salut aussi à Rantanplan")
1550
465d4d484e7c core: plugin unload:
Goffi <goffi@goffi.org>
parents: 1535
diff changeset
453 return self.pluginsUnload()
0
goffi@necton2
parents:
diff changeset
454
goffi@necton2
parents:
diff changeset
455 def run(self):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
456 log.debug(_("running app"))
0
goffi@necton2
parents:
diff changeset
457 reactor.run()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
458
0
goffi@necton2
parents:
diff changeset
459 def stop(self):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
460 log.debug(_("stopping app"))
0
goffi@necton2
parents:
diff changeset
461 reactor.stop()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
462
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
463 ## Misc methods ##
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
464
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
465 def getJidNStream(self, profile_key):
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
466 """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
467 @return: tuple (jid, xmlstream) from profile, can be None"""
1573
6338677f3a89 core (client): added a sendError method to easily build error response from <IQ\> stanza
Goffi <goffi@goffi.org>
parents: 1550
diff changeset
468 # TODO: deprecate this method (getClient is enough)
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
469 profile = self.memory.getProfileName(profile_key)
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
470 if not profile or not self.profiles[profile].isConnected():
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
471 return (None, None)
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
472 return (self.profiles[profile].jid, self.profiles[profile].xmlstream)
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
473
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
474 def getClient(self, profile_key):
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
475 """Convenient method to get client from profile key
1624
7e749e8eefd0 core: fixed launchAction:
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
476
7e749e8eefd0 core: fixed launchAction:
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
477 @return: client or None if it doesn't exist
7e749e8eefd0 core: fixed launchAction:
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
478 @raise exceptions.ProfileKeyUnknown: the profile or profile key doesn't exist
7e749e8eefd0 core: fixed launchAction:
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
479 @raise exceptions.NotFound: client is not available
7e749e8eefd0 core: fixed launchAction:
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
480 This happen if profile has not been use yet
7e749e8eefd0 core: fixed launchAction:
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
481 """
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
482 profile = self.memory.getProfileName(profile_key)
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
483 if not profile:
1624
7e749e8eefd0 core: fixed launchAction:
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
484 raise exceptions.ProfileKeyUnknown
7e749e8eefd0 core: fixed launchAction:
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
485 try:
7e749e8eefd0 core: fixed launchAction:
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
486 return self.profiles[profile]
7e749e8eefd0 core: fixed launchAction:
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
487 except KeyError:
7e749e8eefd0 core: fixed launchAction:
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
488 raise exceptions.NotFound
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
489
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents: 727
diff changeset
490 def getClients(self, profile_key):
1522
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
491 """Convenient method to get list of clients from profile key (manage list through profile_key like C.PROF_KEY_ALL)
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
492
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents: 727
diff changeset
493 @param profile_key: %(doc_profile_key)s
1522
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
494 @return: list of clients
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
495 """
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
496 try:
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
497 profile = self.memory.getProfileName(profile_key, True)
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
498 except exceptions.ProfileUnknownError:
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents: 727
diff changeset
499 return []
1522
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
500 if profile == C.PROF_KEY_ALL:
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents: 727
diff changeset
501 return self.profiles.values()
1522
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
502 elif profile.count('@') > 1:
1624
7e749e8eefd0 core: fixed launchAction:
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
503 raise exceptions.ProfileKeyUnknown
728
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents: 727
diff changeset
504 return [self.profiles[profile]]
e07afabc4a25 plugin XEP-0050: Ad-Hoc commands first draft (answering part)
Goffi <goffi@goffi.org>
parents: 727
diff changeset
505
1234
9c17bd37e6e5 core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents: 1189
diff changeset
506 def _getConfig(self, section, name):
9c17bd37e6e5 core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents: 1189
diff changeset
507 """Get the main configuration option
9c17bd37e6e5 core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents: 1189
diff changeset
508
9c17bd37e6e5 core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents: 1189
diff changeset
509 @param section: section of the config file (None or '' for DEFAULT)
9c17bd37e6e5 core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents: 1189
diff changeset
510 @param name: name of the option
9c17bd37e6e5 core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents: 1189
diff changeset
511 @return: unicode representation of the option
9c17bd37e6e5 core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents: 1189
diff changeset
512 """
9c17bd37e6e5 core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents: 1189
diff changeset
513 return unicode(self.memory.getConfig(section, name, ''))
9c17bd37e6e5 core: better management of default value in getConfig
Goffi <goffi@goffi.org>
parents: 1189
diff changeset
514
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
515 ## Client management ##
0
goffi@necton2
parents:
diff changeset
516
641
49587e170f53 core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents: 636
diff changeset
517 def setParam(self, name, value, category, security_limit, profile_key):
0
goffi@necton2
parents:
diff changeset
518 """set wanted paramater and notice observers"""
641
49587e170f53 core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents: 636
diff changeset
519 self.memory.setParam(name, value, category, security_limit, profile_key)
0
goffi@necton2
parents:
diff changeset
520
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
521 def isConnected(self, profile_key):
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
522 """Return connection status of profile
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
523 @param profile_key: key_word or profile name to determine profile name
1030
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
524 @return: True if connected
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
525 """
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
526 profile = self.memory.getProfileName(profile_key)
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
527 if not profile:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 991
diff changeset
528 log.error(_('asking connection status for a non-existant profile'))
1030
15f43b54d697 core, memory, bridge: added profile password + password encryption:
souliane <souliane@mailoo.org>
parents: 1027
diff changeset
529 raise exceptions.ProfileUnknownError(profile_key)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
530 if profile not in self.profiles:
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
531 return False
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
532 return self.profiles[profile].isConnected()
0
goffi@necton2
parents:
diff changeset
533
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
534
1052
e88bff4c8b77 core (XMPP): sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 1043
diff changeset
535 ## XMPP methods ##
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
536
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
537 def generateMessageXML(self, data):
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
538 """Generate <message/> stanza from message data
1052
e88bff4c8b77 core (XMPP): sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 1043
diff changeset
539
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
540 @param data(dict): message data
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
541 domish element will be put in data['xml']
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
542 following keys are needed:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
543 - from
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
544 - to
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
545 - uid: can be set to '' if uid attribute is not wanted
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
546 - message
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
547 - type
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
548 - subject
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
549 - extra
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
550 @return (dict) message data
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
551 """
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
552 data['xml'] = message_elt = domish.Element((None, 'message'))
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
553 message_elt["to"] = data["to"].full()
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
554 message_elt["from"] = data['from'].full()
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
555 message_elt["type"] = data["type"]
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
556 if data['uid']: # key must be present but can be set to ''
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
557 # by a plugin to avoid id on purpose
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
558 message_elt['id'] = data['uid']
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
559 for lang, subject in data["subject"].iteritems():
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
560 subject_elt = message_elt.addElement("subject", content=subject)
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
561 if lang:
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
562 subject_elt[(C.NS_XML, 'lang')] = lang
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
563 for lang, message in data["message"].iteritems():
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
564 body_elt = message_elt.addElement("body", content=message)
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
565 if lang:
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
566 body_elt[(C.NS_XML, 'lang')] = lang
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
567 try:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
568 thread = data['extra']['thread']
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
569 except KeyError:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
570 if 'thread_parent' in data['extra']:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
571 raise exceptions.InternalError(u"thread_parent found while there is not associated thread")
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
572 else:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
573 thread_elt = message_elt.addElement("thread", content=thread)
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
574 try:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
575 thread_elt["parent"] = data["extra"]["thread_parent"]
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
576 except KeyError:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
577 pass
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
578 return data
636
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents: 627
diff changeset
579
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
580 def _messageSend(self, to_jid_s, message, subject=None, mess_type='auto', extra=None, profile_key=C.PROF_KEY_NONE):
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
581 client = self.getClient(profile_key)
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
582 to_jid = jid.JID(to_jid_s)
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
583 #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
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
584 return self.messageSend(client, to_jid, message, subject, mess_type, {unicode(key): unicode(value) for key, value in extra.items()})
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
585
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
586 def messageSend(self, client, to_jid, message, subject=None, mess_type='auto', extra=None, uid=None, no_trigger=False):
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
587 """Send a message to an entity
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
588
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
589 @param to_jid(jid.JID): destinee of the message
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
590 @param message(dict): message body, key is the language (use '' when unknown)
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
591 @param subject(dict): message subject, key is the language (use '' when unknown)
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
592 @param mess_type(str): one of standard message type (cf RFC 6121 §5.2.2) or:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
593 - auto: for automatic type detection
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
594 - info: for information ("info_type" can be specified in extra)
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
595 @param extra(dict, None): extra data. Key can be:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
596 - info_type: information type, can be
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
597 TODO
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
598 @param uid(unicode, None): unique id:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
599 should be unique at least in this XMPP session
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
600 if None, an uuid will be generated
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
601 @param no_trigger (bool): if True, messageSend trigger will no be used
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
602 useful when a message need to be sent without any modification
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
603 """
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
604 profile = client.profile
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
605 if subject is None:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
606 subject = {}
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
607 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
608 extra = {}
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
609 data = { # dict is similar to the one used in client.onMessage
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
610 "from": client.jid,
602
6fd1095b2b7b core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 589
diff changeset
611 "to": to_jid,
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
612 "uid": uid or unicode(uuid.uuid4()),
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
613 "message": message,
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
614 "subject": subject,
636
7ea6d5a86e58 plugin XEP-0085: Chat State Notifications
souliane <souliane@mailoo.org>
parents: 627
diff changeset
615 "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
616 "extra": extra,
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
617 "timestamp": time.time(),
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
618 }
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
619 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
620 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
621
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
622 if data["type"] == "auto":
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
623 # we try to guess the type
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
624 if data["subject"]:
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
625 data["type"] = 'normal'
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
626 elif not data["to"].resource: # if to JID has a resource, the type is not 'groupchat'
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
627 # 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
628 try:
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
629 entity_type = self.memory.getEntityData(data["to"], ['type'], profile)["type"]
1290
faa1129559b8 core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
Goffi <goffi@goffi.org>
parents: 1262
diff changeset
630 #FIXME: should entity_type manage resources ?
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
631 except (exceptions.UnknownEntityError, KeyError):
489
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
632 entity_type = "contact"
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
633
489
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
634 if entity_type == "chatroom":
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
635 data["type"] = 'groupchat'
489
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
636 else:
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
637 data["type"] = 'chat'
489
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
638 else:
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
639 data["type"] == 'chat'
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
640 data["type"] == "chat" if data["subject"] else "normal"
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
641
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
642 # FIXME: send_only is used by libervia's OTR plugin to avoid
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
643 # the triggers from frontend, and no_trigger do the same
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
644 # thing internally, this could be unified
2128
aa94f33fd2ad plugin otr: various improvments:
Goffi <goffi@goffi.org>
parents: 2126
diff changeset
645 send_only = data['extra'].get('send_only', False)
1148
8cdb97e89d9b core: sendMessage handles the extra data key 'send_only' to skip triggers, storage and echo
souliane <souliane@mailoo.org>
parents: 1145
diff changeset
646
8cdb97e89d9b core: sendMessage handles the extra data key 'send_only' to skip triggers, storage and echo
souliane <souliane@mailoo.org>
parents: 1145
diff changeset
647 if not no_trigger and not send_only:
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
648 if not self.trigger.point("messageSend", client, data, pre_xml_treatments, post_xml_treatments):
752
f49945d728de core,bridge: sendMessage bridge method is now async
Goffi <goffi@goffi.org>
parents: 748
diff changeset
649 return defer.succeed(None)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
650
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
651 log.debug(_(u"Sending message (type {type}, to {to})").format(type=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
652
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
653 pre_xml_treatments.addCallback(lambda dummy: self.generateMessageXML(data))
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
654 pre_xml_treatments.chainDeferred(post_xml_treatments)
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
655 post_xml_treatments.addCallback(self.messageSendToStream, client)
1148
8cdb97e89d9b core: sendMessage handles the extra data key 'send_only' to skip triggers, storage and echo
souliane <souliane@mailoo.org>
parents: 1145
diff changeset
656 if send_only:
8cdb97e89d9b core: sendMessage handles the extra data key 'send_only' to skip triggers, storage and echo
souliane <souliane@mailoo.org>
parents: 1145
diff changeset
657 log.debug(_("Triggers, storage and echo have been inhibited by the 'send_only' parameter"))
8cdb97e89d9b core: sendMessage handles the extra data key 'send_only' to skip triggers, storage and echo
souliane <souliane@mailoo.org>
parents: 1145
diff changeset
658 else:
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
659 post_xml_treatments.addCallback(self.messageAddToHistory, client)
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
660 post_xml_treatments.addCallback(self.messageSendToBridge, client)
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
661 post_xml_treatments.addErrback(self._cancelErrorTrap)
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
662 pre_xml_treatments.callback(data)
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
663 return pre_xml_treatments
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
664
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
665 def _cancelErrorTrap(self, failure):
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
666 """A message sending can be cancelled by a plugin treatment"""
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
667 failure.trap(exceptions.CancelError)
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
668
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
669 def messageSendToStream(self, data, client):
1052
e88bff4c8b77 core (XMPP): sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 1043
diff changeset
670 """Actualy send the message to the server
e88bff4c8b77 core (XMPP): sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 1043
diff changeset
671
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
672 @param data: message data dictionnary
1052
e88bff4c8b77 core (XMPP): sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 1043
diff changeset
673 @param client: profile's client
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
674 """
2131
628c1c95f442 plugin XEP-0334: fixed and improved message processing hints:
Goffi <goffi@goffi.org>
parents: 2129
diff changeset
675 client.send(data[u'xml'])
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
676 return data
1052
e88bff4c8b77 core (XMPP): sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 1043
diff changeset
677
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
678 def messageAddToHistory(self, data, client):
1052
e88bff4c8b77 core (XMPP): sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 1043
diff changeset
679 """Store message into database (for local history)
e88bff4c8b77 core (XMPP): sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 1043
diff changeset
680
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
681 @param data: message data dictionnary
1052
e88bff4c8b77 core (XMPP): sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 1043
diff changeset
682 @param client: profile's client
e88bff4c8b77 core (XMPP): sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 1043
diff changeset
683 """
2131
628c1c95f442 plugin XEP-0334: fixed and improved message processing hints:
Goffi <goffi@goffi.org>
parents: 2129
diff changeset
684 if data[u"type"] != C.MESS_TYPE_GROUPCHAT:
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
685 # 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
686 # and they will be added then
2131
628c1c95f442 plugin XEP-0334: fixed and improved message processing hints:
Goffi <goffi@goffi.org>
parents: 2129
diff changeset
687 if data[u'message'] or data[u'subject']: # we need a message to store
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
688 self.memory.addToHistory(client, data)
1052
e88bff4c8b77 core (XMPP): sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 1043
diff changeset
689 else:
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
690 log.warning(u"No message found") # empty body should be managed by plugins before this point
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
691 return data
1052
e88bff4c8b77 core (XMPP): sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 1043
diff changeset
692
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
693 def messageSendToBridge(self, data, client):
1052
e88bff4c8b77 core (XMPP): sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 1043
diff changeset
694 """Send message to bridge, so frontends can display it
e88bff4c8b77 core (XMPP): sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 1043
diff changeset
695
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
696 @param data: message data dictionnary
1052
e88bff4c8b77 core (XMPP): sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 1043
diff changeset
697 @param client: profile's client
e88bff4c8b77 core (XMPP): sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 1043
diff changeset
698 """
2131
628c1c95f442 plugin XEP-0334: fixed and improved message processing hints:
Goffi <goffi@goffi.org>
parents: 2129
diff changeset
699 if data[u"type"] != C.MESS_TYPE_GROUPCHAT:
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
700 # we don't send groupchat message to bridge, as we get them back
1052
e88bff4c8b77 core (XMPP): sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 1043
diff changeset
701 # and they will be added the
2131
628c1c95f442 plugin XEP-0334: fixed and improved message processing hints:
Goffi <goffi@goffi.org>
parents: 2129
diff changeset
702 if data[u'message'] or data[u'subject']: # we need a message to send something
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
703 # We send back the message, so all frontends are aware of it
2131
628c1c95f442 plugin XEP-0334: fixed and improved message processing hints:
Goffi <goffi@goffi.org>
parents: 2129
diff changeset
704 self.bridge.messageNew(data[u'uid'], data[u'timestamp'], data[u'from'].full(), data[u'to'].full(), data[u'message'], data[u'subject'], data[u'type'], data[u'extra'], profile=client.profile)
1052
e88bff4c8b77 core (XMPP): sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 1043
diff changeset
705 else:
2131
628c1c95f442 plugin XEP-0334: fixed and improved message processing hints:
Goffi <goffi@goffi.org>
parents: 2129
diff changeset
706 log.warning(_(u"No message found"))
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
707 return data
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
708
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
709 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
710 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
711
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
712 def setPresence(self, to_jid=None, show="", statuses=None, profile_key=C.PROF_KEY_NONE):
0
goffi@necton2
parents:
diff changeset
713 """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
714 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
715 statuses = {}
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
716 profile = self.memory.getProfileName(profile_key)
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1234
diff changeset
717 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
718 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
719 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
720 #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
721 if '' in statuses:
1417
176de79c8c39 core, plugin XEP-0045, frontends: change frontend method "setStatusOnline" for "setPresenceStatus":
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
722 statuses[C.PRESENCE_STATUSES_DEFAULT] = statuses.pop('')
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
723 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
724 int(priority), statuses, profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
725
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
726 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
727 """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
728 @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
729 @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
730 @param profile_key: profile"""
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
731 profile = self.memory.getProfileName(profile_key)
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1234
diff changeset
732 assert profile
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
733 to_jid = jid.JID(raw_jid)
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
734 log.debug(_(u'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
735 if subs_type == "subscribe":
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
736 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
737 elif subs_type == "subscribed":
89
23caf1051099 multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents: 79
diff changeset
738 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
739 elif subs_type == "unsubscribe":
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
740 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
741 elif subs_type == "unsubscribed":
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
742 self.profiles[profile].presence.unsubscribed(to_jid)
0
goffi@necton2
parents:
diff changeset
743
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
744 def _addContact(self, to_jid_s, profile_key):
846
59d486726577 core: fix mispelled argument
souliane <souliane@mailoo.org>
parents: 834
diff changeset
745 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
746
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
747 def addContact(self, to_jid, profile_key):
0
goffi@necton2
parents:
diff changeset
748 """Add a contact in roster list"""
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
749 profile = self.memory.getProfileName(profile_key)
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1234
diff changeset
750 assert profile
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1234
diff changeset
751 # presence is sufficient, as a roster push will be sent according to RFC 6121 §3.1.2
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
752 self.profiles[profile].presence.subscribe(to_jid)
0
goffi@necton2
parents:
diff changeset
753
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
754 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
755 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
756
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
757 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
758 """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
759 profile = self.memory.getProfileName(profile_key)
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1234
diff changeset
760 assert profile
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
761 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
762 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
763 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
764 roster_item.groups = set(groups)
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1234
diff changeset
765 return self.profiles[profile].roster.setItem(roster_item)
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
766
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
767 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
768 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
769
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
770 def delContact(self, to_jid, profile_key):
0
goffi@necton2
parents:
diff changeset
771 """Remove contact from roster list"""
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
772 profile = self.memory.getProfileName(profile_key)
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1234
diff changeset
773 assert profile
1355
33a21f06551d core: fixes bug introduced by 1262 (f8a8434dbac7) in SAT.delContact
souliane <souliane@mailoo.org>
parents: 1325
diff changeset
774 self.profiles[profile].presence.unsubscribe(to_jid) # is not asynchronous
33a21f06551d core: fixes bug introduced by 1262 (f8a8434dbac7) in SAT.delContact
souliane <souliane@mailoo.org>
parents: 1325
diff changeset
775 return self.profiles[profile].roster.removeItem(to_jid)
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
776
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 943
diff changeset
777 ## Discovery ##
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 943
diff changeset
778 # discovery methods are shortcuts to self.memory.disco
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 943
diff changeset
779 # 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
780
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 943
diff changeset
781 def hasFeature(self, *args, **kwargs):
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 943
diff changeset
782 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
783
951
027a054c6dda core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents: 949
diff changeset
784 def checkFeature(self, *args, **kwargs):
027a054c6dda core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents: 949
diff changeset
785 return self.memory.disco.checkFeature(*args, **kwargs)
027a054c6dda core (disco): added checkFeature method + fixed hasFeature test
Goffi <goffi@goffi.org>
parents: 949
diff changeset
786
1491
704ca56f5ca9 core (disco): added checkFeatures to check several features at once + identities are now managed with a tuple in findFeaturesSet and checkFeatures
Goffi <goffi@goffi.org>
parents: 1482
diff changeset
787 def checkFeatures(self, *args, **kwargs):
704ca56f5ca9 core (disco): added checkFeatures to check several features at once + identities are now managed with a tuple in findFeaturesSet and checkFeatures
Goffi <goffi@goffi.org>
parents: 1482
diff changeset
788 return self.memory.disco.checkFeatures(*args, **kwargs)
704ca56f5ca9 core (disco): added checkFeatures to check several features at once + identities are now managed with a tuple in findFeaturesSet and checkFeatures
Goffi <goffi@goffi.org>
parents: 1482
diff changeset
789
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 943
diff changeset
790 def getDiscoInfos(self, *args, **kwargs):
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 943
diff changeset
791 return self.memory.disco.getInfos(*args, **kwargs)
0
goffi@necton2
parents:
diff changeset
792
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 943
diff changeset
793 def getDiscoItems(self, *args, **kwargs):
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 943
diff changeset
794 return self.memory.disco.getItems(*args, **kwargs)
0
goffi@necton2
parents:
diff changeset
795
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 943
diff changeset
796 def findServiceEntities(self, *args, **kwargs):
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 943
diff changeset
797 return self.memory.disco.findServiceEntities(*args, **kwargs)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
798
944
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 943
diff changeset
799 def findFeaturesSet(self, *args, **kwargs):
e1842ebcb2f3 core, plugin XEP-0115: discovery refactoring:
Goffi <goffi@goffi.org>
parents: 943
diff changeset
800 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
801
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents: 728
diff changeset
802
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
803 ## Generic HMI ##
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
804
1622
5b24d6bf5d15 core, bridge: actionsGet:
Goffi <goffi@goffi.org>
parents: 1603
diff changeset
805 def _killAction(self, keep_id, client):
5b24d6bf5d15 core, bridge: actionsGet:
Goffi <goffi@goffi.org>
parents: 1603
diff changeset
806 log.debug(u"Killing action {} for timeout".format(keep_id))
5b24d6bf5d15 core, bridge: actionsGet:
Goffi <goffi@goffi.org>
parents: 1603
diff changeset
807 client.actions[keep_id]
5b24d6bf5d15 core, bridge: actionsGet:
Goffi <goffi@goffi.org>
parents: 1603
diff changeset
808
5b24d6bf5d15 core, bridge: actionsGet:
Goffi <goffi@goffi.org>
parents: 1603
diff changeset
809 def actionNew(self, action_data, security_limit=C.NO_SECURITY_LIMIT, keep_id=None, profile=C.PROF_KEY_NONE):
5b24d6bf5d15 core, bridge: actionsGet:
Goffi <goffi@goffi.org>
parents: 1603
diff changeset
810 """Shortcut to bridge.actionNew which generate and id and keep for retrieval
1467
ceba6fd77739 core, bridge: new signal actionNew to launch an action from the backend (e.g. display a dialog message):
Goffi <goffi@goffi.org>
parents: 1417
diff changeset
811
ceba6fd77739 core, bridge: new signal actionNew to launch an action from the backend (e.g. display a dialog message):
Goffi <goffi@goffi.org>
parents: 1417
diff changeset
812 @param action_data(dict): action data (see bridge documentation)
1599
e2ed8009e66e backend, bridge, frontends: actionNew has now a security_limit argument + added some docstring to explain data argument
Goffi <goffi@goffi.org>
parents: 1598
diff changeset
813 @param security_limit: %(doc_security_limit)s
1622
5b24d6bf5d15 core, bridge: actionsGet:
Goffi <goffi@goffi.org>
parents: 1603
diff changeset
814 @param keep_id(None, unicode): if not None, used to keep action for differed retrieval
5b24d6bf5d15 core, bridge: actionsGet:
Goffi <goffi@goffi.org>
parents: 1603
diff changeset
815 must be set to the callback_id
5b24d6bf5d15 core, bridge: actionsGet:
Goffi <goffi@goffi.org>
parents: 1603
diff changeset
816 action will be deleted after 30 min.
1467
ceba6fd77739 core, bridge: new signal actionNew to launch an action from the backend (e.g. display a dialog message):
Goffi <goffi@goffi.org>
parents: 1417
diff changeset
817 @param profile: %(doc_profile)s
ceba6fd77739 core, bridge: new signal actionNew to launch an action from the backend (e.g. display a dialog message):
Goffi <goffi@goffi.org>
parents: 1417
diff changeset
818 """
ceba6fd77739 core, bridge: new signal actionNew to launch an action from the backend (e.g. display a dialog message):
Goffi <goffi@goffi.org>
parents: 1417
diff changeset
819 id_ = unicode(uuid.uuid4())
1622
5b24d6bf5d15 core, bridge: actionsGet:
Goffi <goffi@goffi.org>
parents: 1603
diff changeset
820 if keep_id is not None:
5b24d6bf5d15 core, bridge: actionsGet:
Goffi <goffi@goffi.org>
parents: 1603
diff changeset
821 client = self.getClient(profile)
1644
98a2eb768bb0 core: fixed session cleaning after actionNew timeout
Goffi <goffi@goffi.org>
parents: 1626
diff changeset
822 action_timer = reactor.callLater(60*30, self._killAction, keep_id, client)
1622
5b24d6bf5d15 core, bridge: actionsGet:
Goffi <goffi@goffi.org>
parents: 1603
diff changeset
823 client.actions[keep_id] = (action_data, id_, security_limit, action_timer)
5b24d6bf5d15 core, bridge: actionsGet:
Goffi <goffi@goffi.org>
parents: 1603
diff changeset
824
1599
e2ed8009e66e backend, bridge, frontends: actionNew has now a security_limit argument + added some docstring to explain data argument
Goffi <goffi@goffi.org>
parents: 1598
diff changeset
825 self.bridge.actionNew(action_data, id_, security_limit, profile)
1467
ceba6fd77739 core, bridge: new signal actionNew to launch an action from the backend (e.g. display a dialog message):
Goffi <goffi@goffi.org>
parents: 1417
diff changeset
826
1622
5b24d6bf5d15 core, bridge: actionsGet:
Goffi <goffi@goffi.org>
parents: 1603
diff changeset
827 def actionsGet(self, profile):
5b24d6bf5d15 core, bridge: actionsGet:
Goffi <goffi@goffi.org>
parents: 1603
diff changeset
828 """Return current non answered actions
5b24d6bf5d15 core, bridge: actionsGet:
Goffi <goffi@goffi.org>
parents: 1603
diff changeset
829
5b24d6bf5d15 core, bridge: actionsGet:
Goffi <goffi@goffi.org>
parents: 1603
diff changeset
830 @param profile: %(doc_profile)s
5b24d6bf5d15 core, bridge: actionsGet:
Goffi <goffi@goffi.org>
parents: 1603
diff changeset
831 """
5b24d6bf5d15 core, bridge: actionsGet:
Goffi <goffi@goffi.org>
parents: 1603
diff changeset
832 client = self.getClient(profile)
5b24d6bf5d15 core, bridge: actionsGet:
Goffi <goffi@goffi.org>
parents: 1603
diff changeset
833 return [action_tuple[:-1] for action_tuple in client.actions.itervalues()]
5b24d6bf5d15 core, bridge: actionsGet:
Goffi <goffi@goffi.org>
parents: 1603
diff changeset
834
1626
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
835 def registerProgressCb(self, progress_id, callback, metadata=None, profile=C.PROF_KEY_NONE):
0
goffi@necton2
parents:
diff changeset
836 """Register a callback called when progress is requested for id"""
1626
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
837 if metadata is None:
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
838 metadata = {}
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
839 client = self.getClient(profile)
1522
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
840 if progress_id in client._progress_cb:
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
841 raise exceptions.ConflictError(u"Progress ID is not unique !")
1626
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
842 client._progress_cb[progress_id] = (callback, metadata)
0
goffi@necton2
parents:
diff changeset
843
1522
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
844 def removeProgressCb(self, progress_id, profile):
0
goffi@necton2
parents:
diff changeset
845 """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
846 client = self.getClient(profile)
1522
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
847 try:
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
848 del client._progress_cb[progress_id]
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
849 except KeyError:
1585
846a39900fa6 plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents: 1573
diff changeset
850 log.error(_(u"Trying to remove an unknow progress callback"))
1522
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
851
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
852 def _progressGet(self, progress_id, profile):
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
853 data = self.progressGet(progress_id, profile)
1598
b144babc2658 core, plugin file: fixed progress id + data is now returned by getProgress, instead of being an argument to fill
Goffi <goffi@goffi.org>
parents: 1595
diff changeset
854 return {k: unicode(v) for k,v in data.iteritems()}
0
goffi@necton2
parents:
diff changeset
855
1522
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
856 def progressGet(self, progress_id, profile):
0
goffi@necton2
parents:
diff changeset
857 """Return a dict with progress information
1522
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
858
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
859 @param progress_id(unicode): unique id of the progressing element
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
860 @param profile: %(doc_profile)s
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
861 @return (dict): data with the following keys:
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
862 'position' (int): current possition
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
863 'size' (int): end_position
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
864 if id doesn't exists (may be a finished progression), and empty dict is returned
0
goffi@necton2
parents:
diff changeset
865 """
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
866 client = self.getClient(profile)
0
goffi@necton2
parents:
diff changeset
867 try:
1626
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
868 data = client._progress_cb[progress_id][0](progress_id, profile)
0
goffi@necton2
parents:
diff changeset
869 except KeyError:
1598
b144babc2658 core, plugin file: fixed progress id + data is now returned by getProgress, instead of being an argument to fill
Goffi <goffi@goffi.org>
parents: 1595
diff changeset
870 data = {}
0
goffi@necton2
parents:
diff changeset
871 return data
goffi@necton2
parents:
diff changeset
872
1522
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
873 def _progressGetAll(self, profile_key):
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
874 progress_all = self.progressGetAll(profile_key)
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
875 for profile, progress_dict in progress_all.iteritems():
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
876 for progress_id, data in progress_dict.iteritems():
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
877 for key, value in data.iteritems():
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
878 data[key] = unicode(value)
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
879 return progress_all
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
880
1626
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
881 def progressGetAllMetadata(self, profile_key):
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
882 """Return all progress metadata at once
1522
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
883
1626
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
884 @param profile_key: %(doc_profile)s
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
885 if C.PROF_KEY_ALL is used, all progress metadata from all profiles are returned
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
886 @return (dict[dict[dict]]): a dict which map profile to progress_dict
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
887 progress_dict map progress_id to progress_data
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
888 progress_metadata is the same dict as sent by [progressStarted]
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
889 """
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
890 clients = self.getClients(profile_key)
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
891 progress_all = {}
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
892 for client in clients:
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
893 profile = client.profile
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
894 progress_dict = {}
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
895 progress_all[profile] = progress_dict
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
896 for progress_id, (dummy, progress_metadata) in client._progress_cb.iteritems():
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
897 progress_dict[progress_id] = progress_metadata
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
898 return progress_all
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
899
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
900 def progressGetAll(self, profile_key):
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
901 """Return all progress status at once
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
902
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
903 @param profile_key: %(doc_profile)s
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
904 if C.PROF_KEY_ALL is used, all progress status from all profiles are returned
1598
b144babc2658 core, plugin file: fixed progress id + data is now returned by getProgress, instead of being an argument to fill
Goffi <goffi@goffi.org>
parents: 1595
diff changeset
905 @return (dict[dict[dict]]): a dict which map profile to progress_dict
b144babc2658 core, plugin file: fixed progress id + data is now returned by getProgress, instead of being an argument to fill
Goffi <goffi@goffi.org>
parents: 1595
diff changeset
906 progress_dict map progress_id to progress_data
b144babc2658 core, plugin file: fixed progress id + data is now returned by getProgress, instead of being an argument to fill
Goffi <goffi@goffi.org>
parents: 1595
diff changeset
907 progress_data is the same dict as returned by [progressGet]
1522
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
908 """
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
909 clients = self.getClients(profile_key)
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
910 progress_all = {}
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
911 for client in clients:
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
912 profile = client.profile
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
913 progress_dict = {}
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
914 progress_all[profile] = progress_dict
1626
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
915 for progress_id, (progress_cb, dummy) in client._progress_cb.iteritems():
63cef4dbf2a4 core, plugins file, XEP-0234, bridge: progression api enhancement:
Goffi <goffi@goffi.org>
parents: 1624
diff changeset
916 progress_dict[progress_id] = progress_cb(progress_id, profile)
1522
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
917 return progress_all
7d7e57a84792 core: progression handling improvments:
Goffi <goffi@goffi.org>
parents: 1503
diff changeset
918
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
919 def registerCallback(self, callback, *args, **kwargs):
1603
2b82d846848e core: added callback_id in DataError message of launchCallback
Goffi <goffi@goffi.org>
parents: 1599
diff changeset
920 """Register a callback.
2b82d846848e core: added callback_id in DataError message of launchCallback
Goffi <goffi@goffi.org>
parents: 1599
diff changeset
921
2126
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
922 @param callback(callable): method to call
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
923 @param kwargs: can contain:
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
924 with_data(bool): True if the callback use the optional data dict
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
925 force_id(unicode): id to avoid generated id. Can lead to name conflict, avoid if possible
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
926 one_shot(bool): True to delete callback once it have been called
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
927 @return: id of the registered callback
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
928 """
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
929 callback_id = kwargs.pop('force_id', None)
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
930 if callback_id is None:
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
931 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
932 else:
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
933 if callback_id in self._cb_map:
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
934 raise exceptions.ConflictError(_(u"id already registered"))
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
935 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
936
5d6c45d6ee1b core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents: 801
diff changeset
937 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
938 def purgeCallback():
5d6c45d6ee1b core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents: 801
diff changeset
939 try:
5d6c45d6ee1b core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents: 801
diff changeset
940 self.removeCallback(callback_id)
5d6c45d6ee1b core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents: 801
diff changeset
941 except KeyError:
5d6c45d6ee1b core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents: 801
diff changeset
942 pass
5d6c45d6ee1b core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents: 801
diff changeset
943 reactor.callLater(1800, purgeCallback)
5d6c45d6ee1b core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents: 801
diff changeset
944
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
945 return callback_id
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
946
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
947 def removeCallback(self, callback_id):
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
948 """ Remove a previously registered callback
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
949 @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
950 log.debug("Removing callback [%s]" % callback_id)
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
951 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
952
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 914
diff changeset
953 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
954 """Launch a specific callback
2126
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
955
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
956 @param callback_id: id of the action (callback) to launch
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
957 @param data: optional data
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
958 @profile_key: %(doc_profile_key)s
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
959 @return: a deferred which fire a dict where key can be:
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
960 - xmlui: a XMLUI need to be displayed
1262
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1234
diff changeset
961 - validated: if present, can be used to launch a callback, it can have the values
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1234
diff changeset
962 - C.BOOL_TRUE
f8a8434dbac7 core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents: 1234
diff changeset
963 - C.BOOL_FALSE
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
964 """
2126
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
965 # FIXME: security limit need to be checked here
1622
5b24d6bf5d15 core, bridge: actionsGet:
Goffi <goffi@goffi.org>
parents: 1603
diff changeset
966 try:
1624
7e749e8eefd0 core: fixed launchAction:
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
967 client = self.getClient(profile_key)
7e749e8eefd0 core: fixed launchAction:
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
968 except exceptions.NotFound:
7e749e8eefd0 core: fixed launchAction:
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
969 # client is not available yet
7e749e8eefd0 core: fixed launchAction:
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
970 profile = self.memory.getProfileName(profile_key)
7e749e8eefd0 core: fixed launchAction:
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
971 if not profile:
2126
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
972 raise exceptions.ProfileUnknownError(_(u'trying to launch action with a non-existant profile'))
1622
5b24d6bf5d15 core, bridge: actionsGet:
Goffi <goffi@goffi.org>
parents: 1603
diff changeset
973 else:
1624
7e749e8eefd0 core: fixed launchAction:
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
974 profile = client.profile
7e749e8eefd0 core: fixed launchAction:
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
975 # we check if the action is kept, and remove it
7e749e8eefd0 core: fixed launchAction:
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
976 try:
7e749e8eefd0 core: fixed launchAction:
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
977 action_tuple = client.actions[callback_id]
7e749e8eefd0 core: fixed launchAction:
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
978 except KeyError:
7e749e8eefd0 core: fixed launchAction:
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
979 pass
7e749e8eefd0 core: fixed launchAction:
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
980 else:
7e749e8eefd0 core: fixed launchAction:
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
981 action_tuple[-1].cancel() # the last item is the action timer
7e749e8eefd0 core: fixed launchAction:
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
982 del client.actions[callback_id]
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
983
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
984 try:
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
985 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
986 except KeyError:
1603
2b82d846848e core: added callback_id in DataError message of launchCallback
Goffi <goffi@goffi.org>
parents: 1599
diff changeset
987 raise exceptions.DataError(u"Unknown callback id {}".format(callback_id))
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
988
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
989 if kwargs.get("with_data", False):
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
990 if data is None:
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
991 raise exceptions.DataError("Required data for this callback is missing")
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
992 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
993 args.insert(0, data)
1624
7e749e8eefd0 core: fixed launchAction:
Goffi <goffi@goffi.org>
parents: 1622
diff changeset
994 kwargs["profile"] = profile
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
995 del kwargs["with_data"]
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
996
806
5d6c45d6ee1b core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents: 801
diff changeset
997 if kwargs.pop('one_shot', False):
5d6c45d6ee1b core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents: 801
diff changeset
998 self.removeCallback(callback_id)
5d6c45d6ee1b core: added "one_shot" option to registered callback:
Goffi <goffi@goffi.org>
parents: 801
diff changeset
999
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 755
diff changeset
1000 return defer.maybeDeferred(callback, *args, **kwargs)
0
goffi@necton2
parents:
diff changeset
1001
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
1002 #Menus management
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
1003
2126
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1004 def _getMenuCanonicalPath(self, path):
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1005 """give canonical form of path
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1006
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1007 canonical form is a tuple of the path were every element is stripped and lowercase
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1008 @param path(iterable[unicode]): untranslated path to menu
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1009 @return (tuple[unicode]): canonical form of path
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1010 """
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1011 return tuple((p.lower().strip() for p in path))
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1012
1092
0eefc74c346b core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents: 1089
diff changeset
1013 def importMenu(self, path, callback, security_limit=C.NO_SECURITY_LIMIT, help_string="", type_=C.MENU_GLOBAL):
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
1014 """register a new menu for frontends
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
1015
2126
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1016 @param path(iterable[unicode]): path to go to the menu (category/subcategory/.../item) (e.g.: ("File", "Open"))
773
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1017 /!\ use D_() instead of _() for translations (e.g. (D_("File"), D_("Open")))
2126
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1018 untranslated/lower case path can be used to identity a menu, for this reason it must be unique independently of case.
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1019 @param callback(callable): method to be called when menuitem is selected, callable or a callback id (string) as returned by [registerCallback]
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1020 @param security_limit(int): %(doc_security_limit)s
809
743b757777d3 core: security limit in menus
Goffi <goffi@goffi.org>
parents: 807
diff changeset
1021 /!\ security_limit MUST be added to data in launchCallback if used #TODO
2126
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1022 @param help_string(unicode): string used to indicate what the menu do (can be show as a tooltip).
773
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1023 /!\ use D_() instead of _() for translations
2126
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1024 @param type(unicode): one of:
1092
0eefc74c346b core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents: 1089
diff changeset
1025 - C.MENU_GLOBAL: classical menu, can be shown in a menubar on top (e.g. something like File/Open)
0eefc74c346b core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents: 1089
diff changeset
1026 - C.MENU_ROOM: like a global menu, but only shown in multi-user chat
0eefc74c346b core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents: 1089
diff changeset
1027 menu_data must contain a "room_jid" data
0eefc74c346b core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents: 1089
diff changeset
1028 - C.MENU_SINGLE: like a global menu, but only shown in one2one chat
0eefc74c346b core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents: 1089
diff changeset
1029 menu_data must contain a "jid" data
0eefc74c346b core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents: 1089
diff changeset
1030 - C.MENU_JID_CONTEXT: contextual menu, used with any jid (e.g.: ad hoc commands, jid is already filled)
0eefc74c346b core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents: 1089
diff changeset
1031 menu_data must contain a "jid" data
0eefc74c346b core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents: 1089
diff changeset
1032 - C.MENU_ROSTER_JID_CONTEXT: like JID_CONTEXT, but restricted to jids in roster.
0eefc74c346b core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents: 1089
diff changeset
1033 menu_data must contain a "room_jid" data
0eefc74c346b core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents: 1089
diff changeset
1034 - C.MENU_ROSTER_GROUP_CONTEXT: contextual menu, used with group (e.g.: publish microblog, group is already filled)
0eefc74c346b core (menus): constants are used for menu types
Goffi <goffi@goffi.org>
parents: 1089
diff changeset
1035 menu_data must contain a "group" data
2126
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1036 @return (unicode): 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
1037 """
773
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1038
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1039 if callable(callback):
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1040 callback_id = self.registerCallback(callback, with_data=True)
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1041 elif isinstance(callback, basestring):
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1042 # The callback is already registered
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1043 callback_id = callback
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1044 try:
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1045 callback, args, kwargs = self._cb_map[callback_id]
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1046 except KeyError:
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1047 raise exceptions.DataError("Unknown callback id")
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1048 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
1049 else:
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1050 raise exceptions.DataError("Unknown callback type")
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1051
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1052 for menu_data in self._menus.itervalues():
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1053 if menu_data['path'] == path and menu_data['type'] == type_:
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1054 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
1055
2126
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1056 path_canonical = self._getMenuCanonicalPath(path)
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1057 menu_key = (type_, path_canonical)
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1058
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1059 if menu_key in self._menus_paths:
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1060 raise exceptions.ConflictError(u"this menu path is already used: {path} ({menu_key})".format(
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1061 path=path_canonical, menu_key=menu_key))
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1062
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1063 menu_data = {'path': tuple(path),
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1064 'path_canonical': path_canonical,
773
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1065 'security_limit': security_limit,
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1066 'help_string': help_string,
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1067 'type': type_
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1068 }
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1069
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1070 self._menus[callback_id] = menu_data
2126
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1071 self._menus_paths[menu_key] = callback_id
773
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1072
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1073 return callback_id
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
1074
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
1075 def getMenus(self, language='', security_limit=C.NO_SECURITY_LIMIT):
773
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1076 """Return all menus registered
1365
ba87b940f07a core, quick_frontends: added an "extra" item in getMenus + use of new quick_menus module in QuickApp
Goffi <goffi@goffi.org>
parents: 1355
diff changeset
1077
773
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1078 @param language: language used for translation, or empty string for default
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1079 @param security_limit: %(doc_security_limit)s
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1080 @return: array of tuple with:
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1081 - menu id (same as callback_id)
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1082 - menu type
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1083 - raw menu path (array of strings)
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1084 - translated menu path
1365
ba87b940f07a core, quick_frontends: added an "extra" item in getMenus + use of new quick_menus module in QuickApp
Goffi <goffi@goffi.org>
parents: 1355
diff changeset
1085 - extra (dict(unicode, unicode)): extra data where key can be:
ba87b940f07a core, quick_frontends: added an "extra" item in getMenus + use of new quick_menus module in QuickApp
Goffi <goffi@goffi.org>
parents: 1355
diff changeset
1086 - icon: name of the icon to use (TODO)
ba87b940f07a core, quick_frontends: added an "extra" item in getMenus + use of new quick_menus module in QuickApp
Goffi <goffi@goffi.org>
parents: 1355
diff changeset
1087 - help_url: link to a page with more complete documentation (TODO)
773
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1088 """
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1089 ret = []
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1090 for menu_id, menu_data in self._menus.iteritems():
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1091 type_ = menu_data['type']
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1092 path = menu_data['path']
809
743b757777d3 core: security limit in menus
Goffi <goffi@goffi.org>
parents: 807
diff changeset
1093 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
1094 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
1095 continue
773
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1096 languageSwitch(language)
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1097 path_i18n = [_(elt) for elt in path]
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1098 languageSwitch()
1365
ba87b940f07a core, quick_frontends: added an "extra" item in getMenus + use of new quick_menus module in QuickApp
Goffi <goffi@goffi.org>
parents: 1355
diff changeset
1099 extra = {} # TODO: manage extra data like icon
ba87b940f07a core, quick_frontends: added an "extra" item in getMenus + use of new quick_menus module in QuickApp
Goffi <goffi@goffi.org>
parents: 1355
diff changeset
1100 ret.append((menu_id, type_, path, path_i18n, extra))
773
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1101
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1102 return ret
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1103
2126
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1104 def _launchMenu(self, menu_type, path, data=None, security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE):
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1105 client = self.getClient(profile_key)
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1106 return self.launchMenu(client, menu_type, path, data, security_limit)
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1107
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1108 def launchMenu(self, client, menu_type, path, data=None, security_limit=C.NO_SECURITY_LIMIT):
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1109 """launch action a menu action
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1110
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1111 @param menu_type(unicode): type of menu to launch
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1112 @param path(iterable[unicode]): canonical path of the menu
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1113 @params data(dict): menu data
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1114 @raise NotFound: this path is not known
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1115 """
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1116 # FIXME: manage security_limit here
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1117 # defaut security limit should be high instead of C.NO_SECURITY_LIMIT
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1118 canonical_path = self._getMenuCanonicalPath(path)
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1119 menu_key = (menu_type, canonical_path)
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1120 try:
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1121 callback_id = self._menus_paths[menu_key]
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1122 except KeyError:
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1123 raise exceptions.NotFound(u"Can't find menu {path} ({menu_type})".format(
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1124 path=canonical_path, menu_type=menu_type))
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1125 return self.launchCallback(callback_id, data, client.profile)
2f264f3df280 core (menus): improvments:
Goffi <goffi@goffi.org>
parents: 2113
diff changeset
1126
773
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1127 def getMenuHelp(self, menu_id, language=''):
2113
9c861d07b5b6 core: added sessionGetInfos bridge method to retrieve various data on current profile session + client.started keep start time
Goffi <goffi@goffi.org>
parents: 2105
diff changeset
1128 """return the help string of the menu
9c861d07b5b6 core: added sessionGetInfos bridge method to retrieve various data on current profile session + client.started keep start time
Goffi <goffi@goffi.org>
parents: 2105
diff changeset
1129
773
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1130 @param menu_id: id of the menu (same as callback_id)
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1131 @param language: language used for translation, or empty string for default
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1132 @param return: translated help
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1133
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1134 """
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
1135 try:
773
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1136 menu_data = self._menus[menu_id]
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
1137 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
1138 raise exceptions.DataError("Trying to access an unknown menu")
773
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1139 languageSwitch(language)
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1140 help_string = _(menu_data['help_string'])
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1141 languageSwitch()
eac23b1aad90 core: dynamics menus refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
1142 return help_string
2113
9c861d07b5b6 core: added sessionGetInfos bridge method to retrieve various data on current profile session + client.started keep start time
Goffi <goffi@goffi.org>
parents: 2105
diff changeset
1143
9c861d07b5b6 core: added sessionGetInfos bridge method to retrieve various data on current profile session + client.started keep start time
Goffi <goffi@goffi.org>
parents: 2105
diff changeset
1144 def getSessionInfos(self, profile_key):
9c861d07b5b6 core: added sessionGetInfos bridge method to retrieve various data on current profile session + client.started keep start time
Goffi <goffi@goffi.org>
parents: 2105
diff changeset
1145 """compile interesting data on current profile session"""
9c861d07b5b6 core: added sessionGetInfos bridge method to retrieve various data on current profile session + client.started keep start time
Goffi <goffi@goffi.org>
parents: 2105
diff changeset
1146 client = self.getClient(profile_key)
9c861d07b5b6 core: added sessionGetInfos bridge method to retrieve various data on current profile session + client.started keep start time
Goffi <goffi@goffi.org>
parents: 2105
diff changeset
1147 data = {
9c861d07b5b6 core: added sessionGetInfos bridge method to retrieve various data on current profile session + client.started keep start time
Goffi <goffi@goffi.org>
parents: 2105
diff changeset
1148 "jid": client.jid.full(),
9c861d07b5b6 core: added sessionGetInfos bridge method to retrieve various data on current profile session + client.started keep start time
Goffi <goffi@goffi.org>
parents: 2105
diff changeset
1149 "started": unicode(int(client.started)),
9c861d07b5b6 core: added sessionGetInfos bridge method to retrieve various data on current profile session + client.started keep start time
Goffi <goffi@goffi.org>
parents: 2105
diff changeset
1150 }
9c861d07b5b6 core: added sessionGetInfos bridge method to retrieve various data on current profile session + client.started keep start time
Goffi <goffi@goffi.org>
parents: 2105
diff changeset
1151 return defer.succeed(data)