Mercurial > libervia-backend
annotate sat_bridge/DBus.py @ 68:9b842086d915
multiple profiles update
- Wix: new profile managed, it appear at launch in place of the contact list, and disappear once the profile is choosen
- SàT: default profile is now saved, first one is choosed is no default profile
- Bridge: new delete profile method
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 25 Feb 2010 17:09:18 +1100 |
parents | 0e50dd3a234a |
children | f271fff3a713 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 #-*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 SAT: a jabber client | |
57 | 6 Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org) |
0 | 7 |
8 This program is free software: you can redistribute it and/or modify | |
9 it under the terms of the GNU General Public License as published by | |
10 the Free Software Foundation, either version 3 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 """ | |
21 | |
22 | |
23 from bridge import Bridge | |
24 import dbus | |
25 import dbus.service | |
26 import dbus.mainloop.glib | |
27 import pdb | |
28 from logging import debug, info, error | |
29 | |
10 | 30 const_INT_PREFIX = "org.goffi.SAT" #Interface prefix |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
31 const_COMM_SUFFIX = ".communication" |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
32 const_REQ_SUFFIX = ".request" |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
33 |
0 | 34 class DbusObject(dbus.service.Object): |
35 | |
36 def __init__(self, bus, path): | |
37 dbus.service.Object.__init__(self, bus, path) | |
38 debug("Init DbusObject...") | |
39 self.cb={} | |
40 | |
41 def register(self, name, cb): | |
42 self.cb[name]=cb | |
43 | |
44 ### signals ### | |
45 | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
46 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
47 signature='s') |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
48 def connected(self, profile): |
52 | 49 debug("Connected signal") |
50 | |
51 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
52 signature='s') |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
53 def disconnected(self, profile): |
52 | 54 debug("Disconnected signal") |
55 | |
56 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
57 signature='sa{ss}ass') |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
58 def newContact(self, contact, attributes, groups, profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
59 debug("new contact signal (%s) sended (profile: %s)", contact, profile) |
0 | 60 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
61 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
62 signature='sssss') |
67
0e50dd3a234a
message sending bug fixes + sortilege update
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
63 def newMessage(self, from_jid, msg, type, to, profile): |
0 | 64 debug("new message signal (from:%s msg:%s type:%s to:%s) sended", from_jid, msg, type, to) |
65 | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
66 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
67 signature='ssia{ss}s') |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
68 def presenceUpdate(self, entity, show, priority, statuses, profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
69 debug("presence update signal (from:%s show:%s priority:%d statuses:%s profile:%s) sended" , entity, show, priority, statuses, profile) |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
70 |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
71 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
72 signature='sss') |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
73 def subscribe(self, type, entity, profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
74 debug("subscribe (type: [%s] from:[%s] profile:[%s])" , type, entity, profile) |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
75 |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
76 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
77 signature='ssss') |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
78 def paramUpdate(self, name, value, category, profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
79 debug("param update signal: %s=%s in category %s (profile: %s)", name, value, category, profile) |
0 | 80 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
81 @dbus.service.signal(const_INT_PREFIX+const_COMM_SUFFIX, |
49 | 82 signature='ss') |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
83 def contactDeleted(self, entity, profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
84 debug("contact deleted signal: %s (profile: %s)", entity, profile) |
0 | 85 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
86 @dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX, |
0 | 87 signature='ssa{ss}') |
88 def askConfirmation(self, type, id, data): | |
89 debug("asking for confirmation: id = [%s] type = %s data = %s", id, type, data) | |
90 | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
91 @dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX, |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
92 signature='ssa{ss}') |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
93 def actionResult(self, type, id, data): |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
94 debug("result of action: id = [%s] type = %s data = %s", id, type, data) |
0 | 95 |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
96 @dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX, |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
97 signature='ssa{sa{ss}}') |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
98 def actionResultExt(self, type, id, data): |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
99 debug("extended result of action: id = [%s] type = %s data = %s", id, type, data) |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
100 |
49 | 101 @dbus.service.signal(const_INT_PREFIX+const_REQ_SUFFIX, |
102 signature='sa{ss}') | |
103 def updatedValue(self, name, value): | |
104 debug("updated value: %s = %s", name, value) | |
105 | |
0 | 106 ### methods ### |
107 | |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
108 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
109 in_signature='s', out_signature='s') |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
110 def getProfileName(self, profile_key): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
111 return self.cb["getProfileName"](profile_key) |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
112 |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
113 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
114 in_signature='', out_signature='as') |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
115 def getProfilesList(self): |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
116 info ('Profile list asked') |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
117 return self.cb["getProfilesList"]() |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
118 |
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
119 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, |
68 | 120 in_signature='s', out_signature='i') |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
121 def createProfile(self, name): |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
122 info ('Profile creation asked') |
68 | 123 return self.cb["createProfile"](str(name)) |
124 | |
125 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, | |
126 in_signature='s', out_signature='i') | |
127 def deleteProfile(self, name): | |
128 info ('Profile deletion asked') | |
129 return self.cb["deleteProfile"](str(name)) | |
60
9764e027ecc0
SàT: multi-profile parameters, first draft
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
130 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
131 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
132 in_signature='sssi', out_signature='s') |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
133 def registerNewAccount(self, login, password, host, port=5222): |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
134 info ("New account registration asked") |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
135 return self.cb["registerNewAccount"](login, password, host, port) |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
136 |
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
137 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
138 in_signature='s', out_signature='') |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
139 def connect(self, profile_key='@DEFAULT@'): |
0 | 140 info ("Connection asked") |
141 return self.cb["connect"]() | |
142 | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
143 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
144 in_signature='s', out_signature='') |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
145 def disconnect(self, profile_key='@DEFAULT@'): |
1 | 146 info ("Disconnection asked") |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
147 return self.cb["disconnect"](profile_key) |
1 | 148 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
149 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
52 | 150 in_signature='', out_signature='b') |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
151 def isConnected(self, profile_key='@DEFAULT@'): |
52 | 152 info ("Connection status asked") |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
153 return self.cb["isConnected"](profile_key) |
52 | 154 |
155 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
156 in_signature='s', out_signature='a(sa{ss}as)') |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
157 def getContacts(self, profile_key='@DEFAULT@'): |
0 | 158 debug("getContacts...") |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
159 return self.cb["getContacts"](profile_key) |
0 | 160 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
161 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
162 in_signature='s', out_signature='a{sa{s(sia{ss})}}') |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
163 def getPresenceStatus(self, profile_key='@DEFAULT@'): |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
164 debug("getPresenceStatus...") |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
165 return self.cb["getPresenceStatus"](profile_key) |
49 | 166 |
167 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, | |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
168 in_signature='s', out_signature='a{ss}') |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
169 def getWaitingSub(self, profile_key='@DEFAULT@'): |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
170 debug("getWaitingSub...") |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
171 return self.cb["getWaitingSub"](profile_key) |
0 | 172 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
173 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
67
0e50dd3a234a
message sending bug fixes + sortilege update
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
174 in_signature='ssss', out_signature='') |
0e50dd3a234a
message sending bug fixes + sortilege update
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
175 def sendMessage(self, to, message, type='chat', profile_key='@DEFAULT@'): |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
176 debug("sendMessage...") |
67
0e50dd3a234a
message sending bug fixes + sortilege update
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
177 print "sendtype=", type #gof |
0e50dd3a234a
message sending bug fixes + sortilege update
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
178 self.cb["sendMessage"](to, message, type, profile_key) |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
179 |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
180 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
181 in_signature='ssia{ss}s', out_signature='') |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
182 def setPresence(self, to="", show="", priority=0, statuses={}, profile_key='@DEFAULT@'): |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
183 self.cb["setPresence"](to, show, priority, statuses, profile_key) |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
184 |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
185 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
186 in_signature='sss', out_signature='') |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
187 def subscription(self, type, entity, profile_key='@DEFAULT@'): |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
188 self.cb["subscription"](type, entity, profile_key) |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
189 |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
190 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
191 in_signature='ssss', out_signature='') |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
192 def setParam(self, name, value, category, profile_key='@DEFAULT@'): |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
193 self.cb["setParam"](str(name), str(value), str(category), profile_key) |
0 | 194 |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
195 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
196 in_signature='sss', out_signature='s') |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
197 def getParamA(self, name, category="default", profile_key='@DEFAULT@'): |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
198 return self.cb["getParamA"](name, category, profile_key = profile_key) |
0 | 199 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
200 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
201 in_signature='s', out_signature='s') |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
202 def getParams(self, profile_key='@DEFAULT@'): |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
203 return self.cb["getParams"](profile_key) |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
204 |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
205 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
206 in_signature='ss', out_signature='s') |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
207 def getParamsForCategory(self, category, profile_key='@DEFAULT@'): |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
208 return self.cb["getParamsForCategory"](category, profile_key) |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
209 |
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
210 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
0 | 211 in_signature='', out_signature='as') |
212 def getParamsCategories(self): | |
213 return self.cb["getParamsCategories"]() | |
214 | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
215 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
0 | 216 in_signature='ssi', out_signature='a{i(ss)}') |
217 def getHistory(self, from_jid, to_jid, size): | |
218 debug("History asked for %s", to_jid) | |
219 return self.cb["getHistory"](from_jid, to_jid, size) | |
220 | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
221 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
222 in_signature='ss', out_signature='') |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
223 def addContact(self, entity, profile_key='@DEFAULT@'): |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
224 debug("Subscription asked for %s (profile %s)", entity, profile_key) |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
225 return self.cb["addContact"](entity, profile_key) |
0 | 226 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
227 @dbus.service.method(const_INT_PREFIX+const_COMM_SUFFIX, |
65
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
228 in_signature='ss', out_signature='') |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
229 def delContact(self, entity, profile_key='@DEFAULT@'): |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
230 debug("Unsubscription asked for %s (profile %s)", entity, profile_key) |
d35c5edab53f
SàT: multi-profile: memory & dbus bridge's methods profile management
Goffi <goffi@goffi.org>
parents:
61
diff
changeset
|
231 return self.cb["delContact"](entity, profile_key) |
0 | 232 |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
233 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
234 in_signature='sa{ss}', out_signature='s') |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
235 def launchAction(self, type, data): |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
236 return self.cb["launchAction"](type, data) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
237 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
238 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, |
0 | 239 in_signature='sba{ss}', out_signature='') |
240 def confirmationAnswer(self, id, accepted, data): | |
241 debug("Answer for confirmation [%s]: %s", id, "Accepted" if accepted else "Refused") | |
242 return self.cb["confirmationAnswer"](id, accepted, data) | |
243 | |
36 | 244 |
245 @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX, | |
0 | 246 in_signature='s', out_signature='a{ss}') |
247 def getProgress(self, id): | |
248 #debug("Progress asked for %s", id) | |
249 return self.cb["getProgress"](id) | |
250 | |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
251 def __attribute_string(self, in_sign): |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
252 i=0 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
253 idx=0 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
254 attr_string="" |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
255 while i<len(in_sign): |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
256 if in_sign[i] not in ['b','y','n','i','x','q','u','t','d','s','a']: |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
257 raise Exception #FIXME: create an exception here (unmanaged attribute type) |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
258 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
259 attr_string += ("" if idx==0 else ",") + ("arg_%i" % idx) |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
260 idx+=1 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
261 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
262 if in_sign[i] == 'a': |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
263 while (True): |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
264 i+=1 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
265 if i>=len(in_sign): |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
266 raise Exception #FIXME: create an exception here (the '}' is not presend) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
267 if in_sign[i] == '}' or in_sign[i] == ')': |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
268 break |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
269 i+=1 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
270 return attr_string |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
271 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
272 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
273 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
274 def addMethod(self, name, int_suffix, in_sign, out_sign): |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
275 """Dynamically add a method to Dbus Bridge""" |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
276 #FIXME: Better way ??? |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
277 attributes = self.__attribute_string(in_sign) |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
278 |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
279 code = compile ('def '+name+' (self,'+attributes+'): return self.cb["'+name+'"]('+attributes+')', '<DBus bridge>','exec') |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
280 exec (code) |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
281 method = locals()[name] |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
282 setattr(DbusObject, name, dbus.service.method( |
10 | 283 const_INT_PREFIX+int_suffix, in_signature=in_sign, out_signature=out_sign)(method)) |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
284 |
0 | 285 class DBusBridge(Bridge): |
286 def __init__(self): | |
287 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) | |
288 Bridge.__init__(self) | |
289 info ("Init DBus...") | |
290 self.session_bus = dbus.SessionBus() | |
10 | 291 self.dbus_name = dbus.service.BusName(const_INT_PREFIX, self.session_bus) |
0 | 292 self.dbus_bridge = DbusObject(self.session_bus, '/org/goffi/SAT/bridge') |
293 | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
294 def connected(self, profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
295 self.dbus_bridge.connected(profile) |
52 | 296 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
297 def disconnected(self, profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
298 self.dbus_bridge.disconnected(profile) |
52 | 299 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
300 def newContact(self, contact, attributes, groups, profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
301 self.dbus_bridge.newContact(contact, attributes, groups, profile) |
0 | 302 |
67
0e50dd3a234a
message sending bug fixes + sortilege update
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
303 def newMessage(self, from_jid, msg, type='chat', to='', profile='@NONE@'): |
0 | 304 debug("sending message...") |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
305 self.dbus_bridge.newMessage(from_jid, msg, type, to, profile) |
0 | 306 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
307 def presenceUpdate(self, entity, show, priority, statuses, profile): |
49 | 308 debug("updating presence for %s",entity) |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
309 self.dbus_bridge.presenceUpdate(entity, show, priority, statuses, profile) |
49 | 310 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
311 def subscribe(self, type, entity, profile): |
49 | 312 debug("subscribe request for %s",entity) |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
313 self.dbus_bridge.subscribe(type, entity, profile) |
0 | 314 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
315 def paramUpdate(self, name, value, category, profile): |
18
6928e3cb73a8
refactoring: using xml params part II
Goffi <goffi@goffi.org>
parents:
17
diff
changeset
|
316 debug("updating param [%s] %s ", category, name) |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
317 self.dbus_bridge.paramUpdate(name, value, category, profile) |
0 | 318 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
319 def contactDeleted(self, entity, profile): |
49 | 320 debug("sending contact deleted signal %s ", entity) |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
321 self.dbus_bridge.contactDeleted(entity, profile) |
0 | 322 |
323 def askConfirmation(self, type, id, data): | |
324 self.dbus_bridge.askConfirmation(type, id, data) | |
325 | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
326 def actionResult(self, type, id, data): |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
327 self.dbus_bridge.actionResult(type, id, data) |
16
0a024d5e0cd0
New account creation (in-band registration)
Goffi <goffi@goffi.org>
parents:
10
diff
changeset
|
328 |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
329 def actionResultExt(self, type, id, data): |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
330 self.dbus_bridge.actionResultExt(type, id, data) |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
331 |
49 | 332 def updatedValue(self, name, value): |
333 self.dbus_bridge.updatedValue(name, value) | |
334 | |
0 | 335 def register(self, name, callback): |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
65
diff
changeset
|
336 debug("registering DBus bridge method [%s]", name) |
0 | 337 self.dbus_bridge.register(name, callback) |
338 | |
7
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
339 def addMethod(self, name, int_suffix, in_sign, out_sign, method): |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
340 """Dynamically add a method to Dbus Bridge""" |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
341 print ("Adding method [%s] to DBus bridge" % name) |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
342 self.dbus_bridge.addMethod(name, int_suffix, in_sign, out_sign) |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
343 self.register(name, method) |
c14a3a7018a5
added dynamic exportation of Dbus bridge method (usefull for plugins)
Goffi <goffi@goffi.org>
parents:
1
diff
changeset
|
344 |