annotate src/core/sat_main.py @ 609:84a6e83157c2

fixed licences in docstrings (they are now in comments)
author Goffi <goffi@goffi.org>
date Fri, 08 Mar 2013 00:36:22 +0100
parents c8b129a3c209
children d207c2186519
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
goffi@necton2
parents:
diff changeset
1 #!/usr/bin/python
goffi@necton2
parents:
diff changeset
2 # -*- coding: utf-8 -*-
goffi@necton2
parents:
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 605
diff changeset
4 # SAT: a jabber client
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 605
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013 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
331
0a8eb0461f31 core: main SAT class now moved in its own module core.sat_main
Goffi <goffi@goffi.org>
parents: 330
diff changeset
20 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
21 from twisted.internet import defer
0
goffi@necton2
parents:
diff changeset
22
39
2e3411a6baad Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents: 37
diff changeset
23 from twisted.words.protocols.jabber import jid, xmlstream
0
goffi@necton2
parents:
diff changeset
24 from twisted.words.xish import domish
goffi@necton2
parents:
diff changeset
25
goffi@necton2
parents:
diff changeset
26 from twisted.internet import reactor
goffi@necton2
parents:
diff changeset
27
331
0a8eb0461f31 core: main SAT class now moved in its own module core.sat_main
Goffi <goffi@goffi.org>
parents: 330
diff changeset
28 from wokkel import compat
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
29 from wokkel.xmppim import RosterItem
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
30
223
86d249b6d9b7 Files reorganisation
Goffi <goffi@goffi.org>
parents: 213
diff changeset
31 from sat.bridge.DBus import DBusBridge
0
goffi@necton2
parents:
diff changeset
32 import logging
460
fb1abc0f8c6a backend: added warning message when jabberfr workaround is used + fixed missing warning method
Goffi <goffi@goffi.org>
parents: 459
diff changeset
33 from logging import debug, info, warning, error
0
goffi@necton2
parents:
diff changeset
34
331
0a8eb0461f31 core: main SAT class now moved in its own module core.sat_main
Goffi <goffi@goffi.org>
parents: 330
diff changeset
35 import sys
0
goffi@necton2
parents:
diff changeset
36 import os.path
goffi@necton2
parents:
diff changeset
37
579
133078b82ca8 removed CONST from sat_main as it is already in default_config
Goffi <goffi@goffi.org>
parents: 572
diff changeset
38 from sat.core.default_config import CONST
332
8c9b9ef13ba1 core: minor refactoring
Goffi <goffi@goffi.org>
parents: 331
diff changeset
39 from sat.core import xmpp
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
40 from sat.core.exceptions import ProfileUnknownError, UnknownEntityError, ProfileNotInCacheError
434
d7e5df876a04 core: path update for Memory import
Goffi <goffi@goffi.org>
parents: 427
diff changeset
41 from sat.memory.memory import Memory
223
86d249b6d9b7 Files reorganisation
Goffi <goffi@goffi.org>
parents: 213
diff changeset
42 from sat.tools.xml_tools import tupleList2dataForm
252
c09aa319712e Core: Trigger implementation + version number update
Goffi <goffi@goffi.org>
parents: 245
diff changeset
43 from sat.tools.misc import TriggerManager
0
goffi@necton2
parents:
diff changeset
44 from glob import glob
goffi@necton2
parents:
diff changeset
45
15
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
46 try:
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
47 from twisted.words.protocols.xmlstream import XMPPHandler
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
48 except ImportError:
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
49 from wokkel.subprotocols import XMPPHandler
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
50
0
goffi@necton2
parents:
diff changeset
51 ### logging configuration FIXME: put this elsewhere ###
goffi@necton2
parents:
diff changeset
52 logging.basicConfig(level=logging.DEBUG,
goffi@necton2
parents:
diff changeset
53 format='%(message)s')
goffi@necton2
parents:
diff changeset
54 ###
goffi@necton2
parents:
diff changeset
55
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
56 sat_id = 0
0
goffi@necton2
parents:
diff changeset
57
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
58
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
59 def sat_next_id():
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
60 global sat_id
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
61 sat_id += 1
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
62 return "sat_id_" + str(sat_id)
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
63
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
64
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
65 class SAT(service.Service):
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
66
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
67 def get_next_id(self):
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
68 return sat_next_id()
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
69
41
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 39
diff changeset
70 def get_const(self, name):
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 39
diff changeset
71 """Return a constant"""
358
f147b778511a core: local_dir can now be overrided (usefull to launch 2 instances at the same time)
Goffi <goffi@goffi.org>
parents: 357
diff changeset
72 try:
f147b778511a core: local_dir can now be overrided (usefull to launch 2 instances at the same time)
Goffi <goffi@goffi.org>
parents: 357
diff changeset
73 _const = os.environ['SAT_CONST_%s' % name]
f147b778511a core: local_dir can now be overrided (usefull to launch 2 instances at the same time)
Goffi <goffi@goffi.org>
parents: 357
diff changeset
74 if _const:
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
75 debug(_("Constant %(name)s overrided with [%(value)s]") % {'name': name, 'value': _const})
358
f147b778511a core: local_dir can now be overrided (usefull to launch 2 instances at the same time)
Goffi <goffi@goffi.org>
parents: 357
diff changeset
76 return _const
f147b778511a core: local_dir can now be overrided (usefull to launch 2 instances at the same time)
Goffi <goffi@goffi.org>
parents: 357
diff changeset
77 except KeyError:
f147b778511a core: local_dir can now be overrided (usefull to launch 2 instances at the same time)
Goffi <goffi@goffi.org>
parents: 357
diff changeset
78 pass
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
79 if name not in CONST:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
80 error(_('Trying to access an undefined constant'))
41
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 39
diff changeset
81 raise Exception
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 39
diff changeset
82 return CONST[name]
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 39
diff changeset
83
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 39
diff changeset
84 def set_const(self, name, value):
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 39
diff changeset
85 """Save a constant"""
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
86 if name in CONST:
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
87 error(_('Trying to redefine a constant'))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
88 raise Exception
41
d24629c631fc SàT: new constant management, a local dir (~/.sat) is now used
Goffi <goffi@goffi.org>
parents: 39
diff changeset
89 CONST[name] = value
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
90
0
goffi@necton2
parents:
diff changeset
91 def __init__(self):
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
92 #TODO: standardize callback system
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
93
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
94 self.__general_cb_map = {} # callback called for general reasons (key = name)
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
95 self.__private_data = {} # used for internal callbacks (key = id)
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
96 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
97 self.plugins = {}
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
98 self.menus = {} # used to know which new menus are wanted by plugins
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
99
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
100 self.memory = Memory(self)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
101
365
efbfccfed623 core: local_dir moved to config file
Goffi <goffi@goffi.org>
parents: 364
diff changeset
102 local_dir = self.memory.getConfig('', 'local_dir')
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 358
diff changeset
103 if not os.path.exists(local_dir):
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 358
diff changeset
104 os.makedirs(local_dir)
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 358
diff changeset
105
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
106 self.trigger = TriggerManager() # trigger are used to change SàT behaviour
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
107
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
108 self.bridge = DBusBridge()
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 107
diff changeset
109 self.bridge.register("getVersion", lambda: self.get_const('client_version'))
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 65
diff changeset
110 self.bridge.register("getProfileName", self.memory.getProfileName)
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 58
diff changeset
111 self.bridge.register("getProfilesList", self.memory.getProfilesList)
550
f25eef861b43 core: asyncConnect is now fired when roster is available
Goffi <goffi@goffi.org>
parents: 541
diff changeset
112 self.bridge.register("getEntityData", lambda _jid, keys, profile: self.memory.getEntityData(jid.JID(_jid), keys, profile))
60
9764e027ecc0 SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents: 58
diff changeset
113 self.bridge.register("createProfile", self.memory.createProfile)
420
acd908528ef7 core: profile creation/deletion through database
Goffi <goffi@goffi.org>
parents: 416
diff changeset
114 self.bridge.register("asyncCreateProfile", self.memory.asyncCreateProfile)
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 67
diff changeset
115 self.bridge.register("deleteProfile", self.memory.deleteProfile)
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
116 self.bridge.register("registerNewAccount", self.registerNewAccount)
0
goffi@necton2
parents:
diff changeset
117 self.bridge.register("connect", self.connect)
341
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
118 self.bridge.register("asyncConnect", self.asyncConnect)
1
a06a151fc31f Disconnect first draft
Goffi <goffi@goffi.org>
parents: 0
diff changeset
119 self.bridge.register("disconnect", self.disconnect)
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 460
diff changeset
120 self.bridge.register("getContacts", self.getContacts)
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 489
diff changeset
121 self.bridge.register("getContactsFromGroup", self.getContactsFromGroup)
399
3ed53803b3b3 core: added getLastResource method
Goffi <goffi@goffi.org>
parents: 397
diff changeset
122 self.bridge.register("getLastResource", self.memory.getLastResource)
0
goffi@necton2
parents:
diff changeset
123 self.bridge.register("getPresenceStatus", self.memory.getPresenceStatus)
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
124 self.bridge.register("getWaitingSub", self.memory.getWaitingSub)
541
8b116fa42a31 core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents: 538
diff changeset
125 self.bridge.register("getWaitingConf", self.getWaitingConf)
602
6fd1095b2b7b core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 589
diff changeset
126 self.bridge.register("sendMessage", self._sendMessage)
364
312ca6f9d84a core: configuration file
Goffi <goffi@goffi.org>
parents: 358
diff changeset
127 self.bridge.register("getConfig", self.memory.getConfig)
0
goffi@necton2
parents:
diff changeset
128 self.bridge.register("setParam", self.setParam)
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
129 self.bridge.register("getParamA", self.memory.getStringParamA)
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
130 self.bridge.register("asyncGetParamA", self.memory.asyncGetStringParamA)
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 103
diff changeset
131 self.bridge.register("getParamsUI", self.memory.getParamsUI)
0
goffi@necton2
parents:
diff changeset
132 self.bridge.register("getParams", self.memory.getParams)
18
6928e3cb73a8 refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents: 17
diff changeset
133 self.bridge.register("getParamsForCategory", self.memory.getParamsForCategory)
0
goffi@necton2
parents:
diff changeset
134 self.bridge.register("getParamsCategories", self.memory.getParamsCategories)
goffi@necton2
parents:
diff changeset
135 self.bridge.register("getHistory", self.memory.getHistory)
goffi@necton2
parents:
diff changeset
136 self.bridge.register("setPresence", self.setPresence)
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
137 self.bridge.register("subscription", self.subscription)
0
goffi@necton2
parents:
diff changeset
138 self.bridge.register("addContact", self.addContact)
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
139 self.bridge.register("updateContact", self.updateContact)
0
goffi@necton2
parents:
diff changeset
140 self.bridge.register("delContact", self.delContact)
goffi@necton2
parents:
diff changeset
141 self.bridge.register("isConnected", self.isConnected)
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
142 self.bridge.register("launchAction", self.launchAction)
0
goffi@necton2
parents:
diff changeset
143 self.bridge.register("confirmationAnswer", self.confirmationAnswer)
goffi@necton2
parents:
diff changeset
144 self.bridge.register("getProgress", self.getProgress)
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
145 self.bridge.register("getMenus", self.getMenus)
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
146 self.bridge.register("getMenuHelp", self.getMenuHelp)
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
147 self.bridge.register("callMenu", self.callMenu)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
148
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
149 self.memory.initialized.addCallback(self._postMemoryInit)
0
goffi@necton2
parents:
diff changeset
150
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
151 def _postMemoryInit(self, ignore):
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
152 """Method called after memory initialization is done"""
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
153 info(_("Memory initialised"))
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
154 self._import_plugins()
0
goffi@necton2
parents:
diff changeset
155
goffi@necton2
parents:
diff changeset
156 def _import_plugins(self):
goffi@necton2
parents:
diff changeset
157 """Import all plugins found in plugins directory"""
226
d8bb72f00eec distutils install: fixed plugin import and log file path
Goffi <goffi@goffi.org>
parents: 225
diff changeset
158 import sat.plugins
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
159 plugins_path = os.path.dirname(sat.plugins.__file__)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
160 plug_lst = [os.path.splitext(plugin)[0] for plugin in map(os.path.basename, glob(os.path.join(plugins_path, "plugin*.py")))]
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
161 __plugins_to_import = {} # plugins we still have to import
0
goffi@necton2
parents:
diff changeset
162 for plug in plug_lst:
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
163 plugin_path = 'sat.plugins.' + plug
287
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
164 __import__(plugin_path)
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
165 mod = sys.modules[plugin_path]
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
166 plugin_info = mod.PLUGIN_INFO
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
167 __plugins_to_import[plugin_info['import_name']] = (plugin_path, mod, plugin_info)
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
168 while True:
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
169 self._import_plugins_from_dict(__plugins_to_import)
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
170 if not __plugins_to_import:
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
171 break
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
172
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
173 def _import_plugins_from_dict(self, plugins_to_import, import_name=None):
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
174 """Recursively import and their dependencies in the right order
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
175 @param plugins_to_import: dict where key=import_name and values= (plugin_path, module, plugin_info)"""
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
176 if import_name in self.plugins:
287
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
177 debug('Plugin [%s] already imported, passing' % import_name)
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
178 return
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
179 if not import_name:
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
180 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
181 else:
288
76247af9917c core: added plugin dependency not found import error
Goffi <goffi@goffi.org>
parents: 287
diff changeset
182 if not import_name in plugins_to_import:
76247af9917c core: added plugin dependency not found import error
Goffi <goffi@goffi.org>
parents: 287
diff changeset
183 raise ImportError(_('Dependency plugin not found: [%s]') % import_name)
287
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
184 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
185 dependencies = plugin_info.setdefault("dependencies", [])
287
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
186 for dependency in dependencies:
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
187 if dependency not in self.plugins:
287
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
188 debug('Recursively import dependency of [%s]: [%s]' % (import_name, dependency))
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
189 self._import_plugins_from_dict(plugins_to_import, dependency)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
190 info(_("importing plugin: %s"), plugin_info['name'])
287
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
191 self.plugins[import_name] = getattr(mod, plugin_info['main'])(self)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
192 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
193 self.plugins[import_name].is_handler = True
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
194 else:
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
195 self.plugins[import_name].is_handler = False
2720536b5a22 core: added plugin dependency management
Goffi <goffi@goffi.org>
parents: 282
diff changeset
196 #TODO: test xmppclient presence and register handler parent
0
goffi@necton2
parents:
diff changeset
197
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
198 def connect(self, profile_key='@DEFAULT@'):
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
199 """Connect to jabber server"""
341
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
200 self.asyncConnect(profile_key)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
201
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
202 def asyncConnect(self, profile_key='@DEFAULT@'):
341
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
203 """Connect to jabber server with asynchronous reply
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
204 @param profile_key: %(doc_profile)s
423
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 420
diff changeset
205 """
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
206
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
207 profile = self.memory.getProfileName(profile_key)
324
b069055320b1 core: fixed bad profile check in connect method
Goffi <goffi@goffi.org>
parents: 313
diff changeset
208 if not profile:
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
209 error(_('Trying to connect a non-exsitant profile'))
471
6cd04adddaea core: exceptions moved to core
Goffi <goffi@goffi.org>
parents: 466
diff changeset
210 raise ProfileUnknownError(profile_key)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
211
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
212 if self.isConnected(profile):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
213 info(_("already connected !"))
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
214 return defer.succeed("None")
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
215
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
216 def afterMemoryInit(ignore):
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
217 """This part must be called when we have loaded individual parameters from memory"""
558
626e85e46d7c core: port parameter is used
Goffi <goffi@goffi.org>
parents: 550
diff changeset
218 try:
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
219 port = int(self.memory.getParamA("Port", "Connection", profile_key=profile))
558
626e85e46d7c core: port parameter is used
Goffi <goffi@goffi.org>
parents: 550
diff changeset
220 except ValueError:
626e85e46d7c core: port parameter is used
Goffi <goffi@goffi.org>
parents: 550
diff changeset
221 error(_("Can't parse port value, using default value"))
626e85e46d7c core: port parameter is used
Goffi <goffi@goffi.org>
parents: 550
diff changeset
222 port = 5222
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
223 current = self.profiles[profile] = xmpp.SatXMPPClient(
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
224 self, profile,
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
225 jid.JID(self.memory.getParamA("JabberID", "Connection", profile_key=profile), profile),
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
226 self.memory.getParamA("Password", "Connection", profile_key=profile),
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
227 self.memory.getParamA("Server", "Connection", profile_key=profile),
558
626e85e46d7c core: port parameter is used
Goffi <goffi@goffi.org>
parents: 550
diff changeset
228 port)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
229
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
230 current.messageProt = xmpp.SatMessageProtocol(self)
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
231 current.messageProt.setHandlerParent(current)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
232
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
233 current.roster = xmpp.SatRosterProtocol(self)
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
234 current.roster.setHandlerParent(current)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
235
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
236 current.presence = xmpp.SatPresenceProtocol(self)
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
237 current.presence.setHandlerParent(current)
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
238
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
239 current.fallBack = xmpp.SatFallbackHandler(self)
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
240 current.fallBack.setHandlerParent(current)
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
241
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
242 current.versionHandler = xmpp.SatVersionHandler(self.get_const('client_name'),
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
243 self.get_const('client_version'))
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
244 current.versionHandler.setHandlerParent(current)
14
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
245
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
246 debug(_("setting plugins parents"))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
247
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
248 for plugin in self.plugins.iteritems():
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
249 if plugin[1].is_handler:
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
250 plugin[1].getHandler(profile).setHandlerParent(current)
438
62145e50eae5 core: plugins can now have profileConnected/profileDisconnected method to initialise/free profile dependant resources
Goffi <goffi@goffi.org>
parents: 434
diff changeset
251 connected_cb = getattr(plugin[1], "profileConnected", None)
62145e50eae5 core: plugins can now have profileConnected/profileDisconnected method to initialise/free profile dependant resources
Goffi <goffi@goffi.org>
parents: 434
diff changeset
252 if connected_cb:
62145e50eae5 core: plugins can now have profileConnected/profileDisconnected method to initialise/free profile dependant resources
Goffi <goffi@goffi.org>
parents: 434
diff changeset
253 connected_cb(profile)
14
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
254
412
62b17854254e database integration: first draft
Goffi <goffi@goffi.org>
parents: 399
diff changeset
255 current.startService()
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
256
550
f25eef861b43 core: asyncConnect is now fired when roster is available
Goffi <goffi@goffi.org>
parents: 541
diff changeset
257 d = current.getConnectionDeferred()
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
258 d.addCallback(lambda x: current.roster.got_roster) # we want to be sure that we got the roster
550
f25eef861b43 core: asyncConnect is now fired when roster is available
Goffi <goffi@goffi.org>
parents: 541
diff changeset
259 return d
423
6c20c76abdcc backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents: 420
diff changeset
260
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
261 self.memory.startProfileSession(profile)
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
262 return self.memory.loadIndividualParams(profile).addCallback(afterMemoryInit)
341
9eebdc655b8b code: added asyncConnect
Goffi <goffi@goffi.org>
parents: 336
diff changeset
263
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
264 def disconnect(self, profile_key):
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
265 """disconnect from jabber server"""
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
266 if not self.isConnected(profile_key):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
267 info(_("not connected !"))
6
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
268 return
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
269 profile = self.memory.getProfileName(profile_key)
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
270 info(_("Disconnecting..."))
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
271 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
272 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
273 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
274 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
275 disconnected_cb(profile)
6
5799493fa548 connection and disconnection management
Goffi <goffi@goffi.org>
parents: 5
diff changeset
276
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 460
diff changeset
277 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
278 client = self.getClient(profile_key)
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 460
diff changeset
279 if not client:
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 489
diff changeset
280 raise ProfileUnknownError(_('Asking contacts for a non-existant profile'))
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 460
diff changeset
281 ret = []
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
282 for item in client.roster.getItems(): # we get all items for client's roster
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
283 # and convert them to expected format
466
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 460
diff changeset
284 attr = client.roster.getAttributes(item)
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 460
diff changeset
285 ret.append([item.jid.userhost(), attr, item.groups])
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 460
diff changeset
286 return ret
448ce3c9e2ac core: Roster cache refactoring: cache is now managed by client's SatRosterProtocol instance.
Goffi <goffi@goffi.org>
parents: 460
diff changeset
287
501
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 489
diff changeset
288 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
289 client = self.getClient(profile_key)
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 489
diff changeset
290 if not client:
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 489
diff changeset
291 raise ProfileUnknownError(_("Asking group's contacts for a non-existant profile"))
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 489
diff changeset
292 return client.roster.getJidsFromGroup(group)
e9634d2e7b38 core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents: 489
diff changeset
293
416
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
294 def purgeClient(self, profile):
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
295 """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
296 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
297 try:
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
298 del self.profiles[profile]
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
299 except KeyError:
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
300 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
301 self.memory.purgeProfileSession(profile)
416
32dc8b18c2ae core: param loading/purging on profile connection/disconnection
Goffi <goffi@goffi.org>
parents: 413
diff changeset
302
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
303 def startService(self):
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
304 info("Salut à toi ô mon frère !")
213
5c420b1f1df4 removed connect on statService, this was causing issue on first launch
Goffi <goffi@goffi.org>
parents: 210
diff changeset
305 #TODO: manage autoconnect
5c420b1f1df4 removed connect on statService, this was causing issue on first launch
Goffi <goffi@goffi.org>
parents: 210
diff changeset
306 #self.connect()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
307
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
308 def stopService(self):
15
218ec9984fa5 wokkel integration part III + memory saved again
Goffi <goffi@goffi.org>
parents: 14
diff changeset
309 self.memory.save()
13
bd9e9997d540 wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents: 12
diff changeset
310 info("Salut aussi à Rantanplan")
0
goffi@necton2
parents:
diff changeset
311
goffi@necton2
parents:
diff changeset
312 def run(self):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
313 debug(_("running app"))
0
goffi@necton2
parents:
diff changeset
314 reactor.run()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
315
0
goffi@necton2
parents:
diff changeset
316 def stop(self):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
317 debug(_("stopping app"))
0
goffi@necton2
parents:
diff changeset
318 reactor.stop()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
319
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
320 ## Misc methods ##
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
321
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
322 def getJidNStream(self, profile_key):
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
323 """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
324 @return: tuple (jid, xmlstream) from profile, can be None"""
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
325 profile = self.memory.getProfileName(profile_key)
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
326 if not profile or not self.profiles[profile].isConnected():
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
327 return (None, None)
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
328 return (self.profiles[profile].jid, self.profiles[profile].xmlstream)
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
329
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
330 def getClient(self, profile_key):
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
331 """Convenient method to get client from profile key
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
332 @return: client or None if it doesn't exist"""
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
333 profile = self.memory.getProfileName(profile_key)
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
334 if not profile:
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
335 return None
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
336 return self.profiles[profile]
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 63
diff changeset
337
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
338 def registerNewAccount(self, login, password, email, server, port=5222, id=None, profile_key='@DEFAULT@'):
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
339 """Connect to a server and create a new account using in-band registration"""
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
340 profile = self.memory.getProfileName(profile_key)
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
341 assert(profile)
0
goffi@necton2
parents:
diff changeset
342
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
343 next_id = id or sat_next_id() # the id is used to send server's answer
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
344 serverRegistrer = xmlstream.XmlStreamFactory(xmpp.RegisteringAuthenticator(self, server, login, password, email, next_id, profile))
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
345 connector = reactor.connectTCP(server, port, serverRegistrer)
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
346 serverRegistrer.clientConnectionLost = lambda conn, reason: connector.disconnect()
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
347
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
348 return next_id
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
349
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
350 def registerNewAccountCB(self, id, data, profile):
135
7452ac3818e7 Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents: 119
diff changeset
351 user = jid.parse(self.memory.getParamA("JabberID", "Connection", profile_key=profile))[0]
7452ac3818e7 Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents: 119
diff changeset
352 password = self.memory.getParamA("Password", "Connection", profile_key=profile)
7452ac3818e7 Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents: 119
diff changeset
353 server = self.memory.getParamA("Server", "Connection", profile_key=profile)
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
354
23
925ab466c5ec better presentation for register new account
Goffi <goffi@goffi.org>
parents: 22
diff changeset
355 if not user or not password or not server:
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
356 info(_('No user or server given'))
23
925ab466c5ec better presentation for register new account
Goffi <goffi@goffi.org>
parents: 22
diff changeset
357 #TODO: a proper error message must be sent to frontend
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
358 self.actionResult(id, "ERROR", {'message': _("No user, password or server given, can't register new account.")}, profile)
23
925ab466c5ec better presentation for register new account
Goffi <goffi@goffi.org>
parents: 22
diff changeset
359 return
925ab466c5ec better presentation for register new account
Goffi <goffi@goffi.org>
parents: 22
diff changeset
360
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
361 confirm_id = sat_next_id()
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
362 self.__private_data[confirm_id] = (id, profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
363
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
364 self.askConfirmation(
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
365 confirm_id, "YES/NO",
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
366 {"message": _("Are you sure to register new account [%(user)s] to server %(server)s ?") % {'user': user, 'server': server, 'profile': profile}},
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
367 self.regisConfirmCB, profile)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
368 print "===============+++++++++++ REGISTER NEW ACCOUNT++++++++++++++============"
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
369 print "id=", id
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
370 print "data=", data
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
371
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
372 def regisConfirmCB(self, id, accepted, data, profile):
69
86f1f7f6d332 i18n first draft
Goffi <goffi@goffi.org>
parents: 68
diff changeset
373 print _("register Confirmation CB ! (%s)") % str(accepted)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
374 action_id, profile = self.__private_data[id]
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
375 del self.__private_data[id]
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
376 if accepted:
135
7452ac3818e7 Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents: 119
diff changeset
377 user = jid.parse(self.memory.getParamA("JabberID", "Connection", profile_key=profile))[0]
7452ac3818e7 Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents: 119
diff changeset
378 password = self.memory.getParamA("Password", "Connection", profile_key=profile)
7452ac3818e7 Core, wix: added profile management for RegisterNewAccount method, and LaunchAction
Goffi <goffi@goffi.org>
parents: 119
diff changeset
379 server = self.memory.getParamA("Server", "Connection", profile_key=profile)
336
953536246d9d core: added email in registerNewAccount
Goffi <goffi@goffi.org>
parents: 332
diff changeset
380 self.registerNewAccount(user, password, None, server, id=action_id)
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
381 else:
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
382 self.actionResult(action_id, "SUPPRESS", {}, profile)
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
383
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
384 def submitForm(self, action, target, fields, profile_key):
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
385 """submit a form
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
386 @param target: target jid where we are submitting
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
387 @param fields: list of tuples (name, value)
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
388 @return: tuple: (id, deferred)
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
389 """
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
390
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
391 profile = self.memory.getProfileName(profile_key)
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
392 assert(profile)
36
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 33
diff changeset
393 to_jid = jid.JID(target)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
394
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
395 iq = compat.IQ(self.profiles[profile].xmlstream, 'set')
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
396 iq["to"] = target
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
397 iq["from"] = self.profiles[profile].jid.full()
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
398 query = iq.addElement(('jabber:iq:register', 'query'))
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
399 if action == 'SUBMIT':
102
94011f553cd0 misc bugfixes
Goffi <goffi@goffi.org>
parents: 101
diff changeset
400 form = tupleList2dataForm(fields)
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
401 query.addChild(form.toElement())
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
402 elif action == 'CANCEL':
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
403 query.addElement('remove')
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
404 else:
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
405 error(_("FIXME FIXME FIXME: Unmanaged action (%s) in submitForm") % action)
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
406 raise NotImplementedError
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
407
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
408 deferred = iq.send(target)
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
409 return (iq['id'], deferred)
36
6491b7956c80 wix: Form submitting, first draft
Goffi <goffi@goffi.org>
parents: 33
diff changeset
410
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
411 ## Client management ##
0
goffi@necton2
parents:
diff changeset
412
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
413 def setParam(self, name, value, category, profile_key):
0
goffi@necton2
parents:
diff changeset
414 """set wanted paramater and notice observers"""
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
415 info(_("setting param: %(name)s=%(value)s in category %(category)s") % {'name': name, 'value': value, 'category': category})
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
416 self.memory.setParam(name, value, category, profile_key)
0
goffi@necton2
parents:
diff changeset
417
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
418 def isConnected(self, profile_key):
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
419 """Return connection status of profile
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
420 @param profile_key: key_word or profile name to determine profile name
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
421 @return True if connected
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
422 """
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
423 profile = self.memory.getProfileName(profile_key)
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
424 if not profile:
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
425 error(_('asking connection status for a non-existant profile'))
213
5c420b1f1df4 removed connect on statService, this was causing issue on first launch
Goffi <goffi@goffi.org>
parents: 210
diff changeset
426 return
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
427 if profile not in self.profiles:
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
428 return False
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
429 return self.profiles[profile].isConnected()
0
goffi@necton2
parents:
diff changeset
430
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
431 def launchAction(self, type, data, profile_key):
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
432 """Launch a specific action asked by client
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
433 @param type: action type (button)
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
434 @param data: needed data to launch the action
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
435
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
436 @return: action id for result, or empty string in case or error
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
437 """
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
438 profile = self.memory.getProfileName(profile_key)
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
439 if not profile:
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
440 error(_('trying to launch action with a non-existant profile'))
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
441 raise Exception # TODO: raise a proper exception
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
442 if type == "button":
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
443 try:
106
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
444 cb_name = data['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
445 except KeyError:
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
446 error(_("Incomplete data"))
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
447 return ""
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
448 id = sat_next_id()
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
449 self.callGeneralCB(cb_name, id, data, profile=profile)
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
450 return id
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
451 else:
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
452 error(_("Unknown action type"))
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
453 return ""
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
454
0
goffi@necton2
parents:
diff changeset
455 ## jabber methods ##
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
456
541
8b116fa42a31 core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents: 538
diff changeset
457 def getWaitingConf(self, profile_key=None):
8b116fa42a31 core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents: 538
diff changeset
458 assert(profile_key)
8b116fa42a31 core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents: 538
diff changeset
459 client = self.getClient(profile_key)
8b116fa42a31 core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents: 538
diff changeset
460 if not client:
8b116fa42a31 core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents: 538
diff changeset
461 raise ProfileNotInCacheError
8b116fa42a31 core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents: 538
diff changeset
462 ret = []
8b116fa42a31 core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents: 538
diff changeset
463 for conf_id in client._waiting_conf:
8b116fa42a31 core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents: 538
diff changeset
464 conf_type, data = client._waiting_conf[conf_id][:2]
8b116fa42a31 core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents: 538
diff changeset
465 ret.append((conf_id, conf_type, data))
8b116fa42a31 core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents: 538
diff changeset
466 return ret
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
467
602
6fd1095b2b7b core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 589
diff changeset
468 def _sendMessage(self, to_s, msg, subject=None, mess_type='auto', profile_key='@NONE@'):
6fd1095b2b7b core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 589
diff changeset
469 to_jid = jid.JID(to_s)
605
c8b129a3c209 core: fixed sendMessage
Goffi <goffi@goffi.org>
parents: 602
diff changeset
470 self.sendMessage(to_jid, msg, subject, mess_type, profile_key=profile_key)
602
6fd1095b2b7b core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 589
diff changeset
471
6fd1095b2b7b core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 589
diff changeset
472 def sendMessage(self, to_jid, msg, subject=None, mess_type='auto', no_trigger = False, profile_key='@NONE@'):
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
473 #FIXME: check validity of recipient
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
474 profile = self.memory.getProfileName(profile_key)
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
475 assert(profile)
489
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
476 client = self.profiles[profile]
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
477 current_jid = client.jid
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
478 mess_data = { # we put data in a dict, so trigger methods can change them
602
6fd1095b2b7b core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 589
diff changeset
479 "to": to_jid,
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
480 "message": msg,
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
481 "subject": subject,
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
482 "type": mess_type
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
483 }
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
484
489
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
485 if mess_data["type"] == "auto":
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
486 # we try to guess the type
489
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
487 if mess_data["subject"]:
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
488 mess_data["type"] = 'normal'
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
489 elif not mess_data["to"].resource: # if to JID has a resource, the type is not 'groupchat'
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
490 # 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
491 try:
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
492 entity_type = self.memory.getEntityData(mess_data["to"], ['type'], profile)["type"]
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
493 #FIXME: should entity_type manage ressources ?
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
494 except (UnknownEntityError, KeyError):
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
495 entity_type = "contact"
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
496
489
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
497 if entity_type == "chatroom":
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
498 mess_data["type"] = 'groupchat'
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
499 else:
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
500 mess_data["type"] = 'chat'
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
501 else:
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
502 mess_data["type"] == 'chat'
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
503 mess_data["type"] == "chat" if mess_data["subject"] else "normal"
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
504
602
6fd1095b2b7b core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 589
diff changeset
505 if not no_trigger:
6fd1095b2b7b core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 589
diff changeset
506 if not self.trigger.point("sendMessage", mess_data, profile):
6fd1095b2b7b core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 589
diff changeset
507 return
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
508
602
6fd1095b2b7b core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 589
diff changeset
509 debug(_("Sending jabber message of type [%(type)s] to %(to)s...") % {"type": mess_data["type"], "to": to_jid.full()})
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
510 message = domish.Element((None, 'message'))
489
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
511 message["to"] = mess_data["to"].full()
62
93cb45a7420f SàT multi-profile: connection using profiles
Goffi <goffi@goffi.org>
parents: 60
diff changeset
512 message["from"] = current_jid.full()
489
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
513 message["type"] = mess_data["type"]
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
514 if mess_data["subject"]:
536
a31abb97310d core, plugins: fixed bad namespace in stanza creation
Goffi <goffi@goffi.org>
parents: 513
diff changeset
515 message.addElement("subject", None, subject)
a31abb97310d core, plugins: fixed bad namespace in stanza creation
Goffi <goffi@goffi.org>
parents: 513
diff changeset
516 message.addElement("body", None, mess_data["message"])
489
f36c705a5310 core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 484
diff changeset
517 client.xmlstream.send(message)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
518 if mess_data["type"] != "groupchat":
602
6fd1095b2b7b core: sendMessage refactoring:
Goffi <goffi@goffi.org>
parents: 589
diff changeset
519 self.memory.addToHistory(current_jid, mess_data['to'], unicode(mess_data["message"]), unicode(mess_data["type"]), profile=profile) # we don't add groupchat message to history, as we get them back
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
520 # and they will be added then
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
521 self.bridge.newMessage(message['from'], unicode(mess_data["message"]), mess_type=mess_data["type"], to_jid=message['to'], extra={}, profile=profile) # We send back the message, so all clients are aware of it
16
0a024d5e0cd0 New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents: 15
diff changeset
522
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
523 def setPresence(self, to="", show="", priority=0, statuses={}, profile_key='@DEFAULT@'):
0
goffi@necton2
parents:
diff changeset
524 """Send our presence information"""
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
525 profile = self.memory.getProfileName(profile_key)
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
526 assert(profile)
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
527 to_jid = jid.JID(to) if to else None
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
528 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
529 #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
530 if '' in statuses:
313
cc8ffbfe938c QnD workaround for presence broadcast openfire bug
Goffi <goffi@goffi.org>
parents: 305
diff changeset
531 statuses['default'] = statuses['']
cc8ffbfe938c QnD workaround for presence broadcast openfire bug
Goffi <goffi@goffi.org>
parents: 305
diff changeset
532 del statuses['']
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
533 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
534 int(priority), statuses, profile)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
535
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
536 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
537 """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
538 @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
539 @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
540 @param profile_key: profile"""
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
541 profile = self.memory.getProfileName(profile_key)
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
542 assert(profile)
50
daa1f01a5332 SàT improvement:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
543 to_jid = jid.JID(raw_jid)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
544 debug(_('subsciption request [%(subs_type)s] for %(jid)s') % {'subs_type': subs_type, 'jid': to_jid.full()})
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
545 if subs_type == "subscribe":
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
546 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
547 elif subs_type == "subscribed":
89
23caf1051099 multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents: 79
diff changeset
548 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
549 elif subs_type == "unsubscribe":
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
550 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
551 elif subs_type == "unsubscribed":
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
552 self.profiles[profile].presence.unsubscribed(to_jid)
0
goffi@necton2
parents:
diff changeset
553
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
554 def addContact(self, to, profile_key):
0
goffi@necton2
parents:
diff changeset
555 """Add a contact in roster list"""
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
556 profile = self.memory.getProfileName(profile_key)
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
557 assert(profile)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
558 to_jid = jid.JID(to)
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
559 #self.profiles[profile].roster.addItem(to_jid) #XXX: disabled (cf http://wokkel.ik.nu/ticket/56))
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
560 self.profiles[profile].presence.subscribe(to_jid)
0
goffi@necton2
parents:
diff changeset
561
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
562 def updateContact(self, to, name, groups, profile_key):
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
563 """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
564 profile = self.memory.getProfileName(profile_key)
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
565 assert(profile)
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
566 to_jid = jid.JID(to)
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
567 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
568 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
569 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
570 roster_item.groups = set(groups)
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
571 self.profiles[profile].roster.updateItem(roster_item)
ca3a041fed30 core: fixed several subscription scheme issues + removed most of profile_key default value in core.sat_main and core.xmmp (source of bugs) + contact update
Goffi <goffi@goffi.org>
parents: 341
diff changeset
572
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
573 def delContact(self, to, profile_key):
0
goffi@necton2
parents:
diff changeset
574 """Remove contact from roster list"""
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
575 profile = self.memory.getProfileName(profile_key)
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
576 assert(profile)
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
577 to_jid = jid.JID(to)
63
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
578 self.profiles[profile].roster.removeItem(to_jid)
0db25931b60d SàT: multi-profiles: somes fixes in core
Goffi <goffi@goffi.org>
parents: 62
diff changeset
579 self.profiles[profile].presence.unsubscribe(to_jid)
0
goffi@necton2
parents:
diff changeset
580
goffi@necton2
parents:
diff changeset
581 ## callbacks ##
goffi@necton2
parents:
diff changeset
582
282
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 277
diff changeset
583 def serverDisco(self, disco, profile):
0
goffi@necton2
parents:
diff changeset
584 """xep-0030 Discovery Protocol."""
14
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
585 for feature in disco.features:
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
586 debug(_("Feature found: %s"), feature)
282
6a0c6d8e119d added plugin xep-0115: entity capabilities
Goffi <goffi@goffi.org>
parents: 277
diff changeset
587 self.memory.addServerFeature(feature, profile)
14
a62d7d453f22 wokkel integration, part II
Goffi <goffi@goffi.org>
parents: 13
diff changeset
588 for cat, type in disco.identities:
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
589 debug(_("Identity found: [%(category)s/%(type)s] %(identity)s") % {'category': cat, 'type': type, 'identity': disco.identities[(cat, type)]})
0
goffi@necton2
parents:
diff changeset
590
305
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
591 def serverDiscoItems(self, disco_result, disco_client, profile, initialized):
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
592 """xep-0030 Discovery Protocol.
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
593 @param disco_result: result of the disco item querry
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
594 @param disco_client: SatDiscoProtocol instance
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
595 @param profile: profile of the user
305
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
596 @param initialized: deferred which must be chained when everything is done"""
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
597
305
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
598 def _check_entity_cb(result, entity, profile):
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
599 for category, type in result.identities:
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
600 debug(_('Identity added: (%(category)s,%(type)s) ==> %(entity)s [%(profile)s]') % {
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
601 'category': category, 'type': type, 'entity': entity, 'profile': profile})
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
602 self.memory.addServerIdentity(category, type, entity, profile)
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
603
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
604 def _errback(result, entity, profile):
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
605 warning(_("Can't get information on identity [%(entity)s] for profile [%(profile)s]") % {'entity': entity, 'profile': profile})
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
606
305
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
607 defer_list = []
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
608 for item in disco_result._items:
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
609 if item.entity.full().count('.') == 1: # XXX: workaround for a bug on jabberfr, tmp
460
fb1abc0f8c6a backend: added warning message when jabberfr workaround is used + fixed missing warning method
Goffi <goffi@goffi.org>
parents: 459
diff changeset
610 warning(_('Using jabberfr workaround, be sure your domain has at least two levels (e.g. "example.tld", not "example" alone)'))
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
611 continue
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
612 args = [item.entity, profile]
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
613 defer_list.append(disco_client.requestInfo(item.entity).addCallbacks(_check_entity_cb, _errback, args, None, args))
305
15a12bf2bb62 core: server identities are now save in memory
Goffi <goffi@goffi.org>
parents: 292
diff changeset
614 defer.DeferredList(defer_list).chainDeferred(initialized)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
615 ## Generic HMI ##
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 579
diff changeset
616
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
617 def actionResult(self, action_id, action_type, data, profile):
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
618 """Send the result of an action
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
619 @param action_id: same action_id used with action
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
620 @param action_type: result action_type ("PARAM", "SUCCESS", "ERROR", "XMLUI")
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
621 @param data: dictionary
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
622 """
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
623 self.bridge.actionResult(action_type, action_id, data, profile)
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
624
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
625 def actionResultExt(self, action_id, action_type, data, profile):
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
626 """Send the result of an action, extended version
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
627 @param action_id: same action_id used with action
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
628 @param action_type: result action_type /!\ only "DICT_DICT" for this method
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
629 @param data: dictionary of dictionaries
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
630 """
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
631 if action_type != "DICT_DICT":
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
632 error(_("action_type for actionResultExt must be DICT_DICT, fixing it"))
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
633 action_type = "DICT_DICT"
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
634 self.bridge.actionResultExt(action_type, action_id, data, profile)
25
53e921c8a357 new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents: 23
diff changeset
635
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
636 def askConfirmation(self, conf_id, conf_type, data, cb, profile):
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
637 """Add a confirmation callback
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
638 @param conf_id: conf_id used to get answer
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
639 @param conf_type: confirmation conf_type ("YES/NO", "FILE_TRANSFER")
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
640 @param data: data (depend of confirmation conf_type)
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
641 @param cb: callback called with the answer
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
642 """
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
643 client = self.getClient(profile)
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
644 if not client:
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
645 raise ProfileUnknownError(_("Asking confirmation a non-existant profile"))
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
646 if conf_id in client._waiting_conf:
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
647 error(_("Attempt to register two callbacks for the same confirmation"))
0
goffi@necton2
parents:
diff changeset
648 else:
541
8b116fa42a31 core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents: 538
diff changeset
649 client._waiting_conf[conf_id] = (conf_type, data, cb)
8b116fa42a31 core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents: 538
diff changeset
650 self.bridge.askConfirmation(conf_id, conf_type, data, profile)
0
goffi@necton2
parents:
diff changeset
651
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
652 def confirmationAnswer(self, conf_id, accepted, data, profile):
0
goffi@necton2
parents:
diff changeset
653 """Called by frontends to answer confirmation requests"""
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
654 client = self.getClient(profile)
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
655 if not client:
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
656 raise ProfileUnknownError(_("Confirmation answer from a non-existant profile"))
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
657 debug(_("Received confirmation answer for conf_id [%(conf_id)s]: %(success)s") % {'conf_id': conf_id, 'success': _("accepted") if accepted else _("refused")})
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
658 if conf_id not in client._waiting_conf:
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
659 error(_("Received an unknown confirmation (%(id)s for %(profile)s)") % {'id': conf_id, 'profile': profile})
0
goffi@necton2
parents:
diff changeset
660 else:
541
8b116fa42a31 core, bridge: waiting confirmation management (new getWaitingConf method)
Goffi <goffi@goffi.org>
parents: 538
diff changeset
661 cb = client._waiting_conf[conf_id][-1]
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
662 del client._waiting_conf[conf_id]
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
663 cb(conf_id, accepted, data, profile)
0
goffi@necton2
parents:
diff changeset
664
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
665 def registerProgressCB(self, progress_id, CB, profile):
0
goffi@necton2
parents:
diff changeset
666 """Register a callback called when progress is requested for id"""
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
667 client = self.getClient(profile)
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
668 if not client:
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
669 raise ProfileUnknownError
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
670 client._progress_cb_map[progress_id] = CB
0
goffi@necton2
parents:
diff changeset
671
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
672 def removeProgressCB(self, progress_id, profile):
0
goffi@necton2
parents:
diff changeset
673 """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
674 client = self.getClient(profile)
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
675 if not client:
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
676 raise ProfileUnknownError
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
677 if progress_id not in client._progress_cb_map:
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
678 error(_("Trying to remove an unknow progress callback"))
0
goffi@necton2
parents:
diff changeset
679 else:
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
680 del client._progress_cb_map[progress_id]
0
goffi@necton2
parents:
diff changeset
681
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
682 def getProgress(self, progress_id, profile):
0
goffi@necton2
parents:
diff changeset
683 """Return a dict with progress information
goffi@necton2
parents:
diff changeset
684 data['position'] : current possition
goffi@necton2
parents:
diff changeset
685 data['size'] : end_position
goffi@necton2
parents:
diff changeset
686 """
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
687 client = self.getClient(profile)
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
688 if not profile:
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
689 raise ProfileNotInCacheError
0
goffi@necton2
parents:
diff changeset
690 data = {}
goffi@necton2
parents:
diff changeset
691 try:
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
692 client._progress_cb_map[progress_id](progress_id, data, profile)
0
goffi@necton2
parents:
diff changeset
693 except KeyError:
goffi@necton2
parents:
diff changeset
694 pass
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 536
diff changeset
695 #debug("Requested progress for unknown progress_id")
0
goffi@necton2
parents:
diff changeset
696 return data
goffi@necton2
parents:
diff changeset
697
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
698 def registerGeneralCB(self, name, CB):
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
699 """Register a callback called for general reason"""
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
700 self.__general_cb_map[name] = CB
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
701
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
702 def removeGeneralCB(self, name):
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
703 """Remove a general callback"""
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
704 if name not in self.__general_cb_map:
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
705 error(_("Trying to remove an unknow general callback"))
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
706 else:
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
707 del self.__general_cb_map[name]
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
708
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
709 def callGeneralCB(self, name, *args, **kwargs):
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
710 """Call general function back"""
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
711 try:
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
712 return self.__general_cb_map[name](*args, **kwargs)
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
713 except KeyError:
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
714 error(_("Trying to call unknown function (%s)") % name)
22
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
715 return None
0
goffi@necton2
parents:
diff changeset
716
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
717 #Menus management
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
718
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
719 def importMenu(self, category, name, callback, help_string="", type="NORMAL"):
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
720 """register a new menu for frontends
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
721 @param category: category of the menu
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
722 @param name: menu item entry
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
723 @param callback: method to be called when menuitem is selected"""
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
724 if (category, name) in self.menus:
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
725 error("Want to register a menu which already existe")
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
726 return
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
727 self.menus[(category, name, type)] = {'callback': callback, 'help_string': help_string, 'type': type}
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
728
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
729 def getMenus(self):
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
730 """Return all menus registered"""
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
731 return self.menus.keys()
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
732
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
733 def getMenuHelp(self, category, name, type="NORMAL"):
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
734 """return the help string of the menu"""
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
735 try:
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
736 return self.menus[(category, name, type)]['help_string']
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
737 except KeyError:
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
738 error(_("Trying to access an unknown menu"))
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
739 return ""
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
740
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
741 def callMenu(self, category, name, type="NORMAL", profile_key='@DEFAULT@'):
266
c4b84a2d2ad1 bridge: constructor and template improved, documentation added
Goffi <goffi@goffi.org>
parents: 264
diff changeset
742 """return the id of the action"""
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
743 profile = self.memory.getProfileName(profile_key)
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
744 if not profile_key:
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
745 error(_('Non-exsitant profile'))
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
746 return ""
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
747 if (category, name, type) in self.menus:
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
748 id = self.get_next_id()
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
749 self.menus[(category, name, type)]['callback'](id, profile)
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
750 return id
102
94011f553cd0 misc bugfixes
Goffi <goffi@goffi.org>
parents: 101
diff changeset
751 else:
589
d1b4805124a1 Fix pep8 support in src/core.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
752 error(_("Trying to access an unknown menu (%(category)s/%(name)s/%(type)s)") % {'category': category, 'name': name, 'type': type})
101
783e9d6980ec Couchsurfing plugin: first draft
Goffi <goffi@goffi.org>
parents: 90
diff changeset
753 return ""