Mercurial > libervia-backend
annotate frontends/quick_frontend/quick_app.py @ 51:8c67ea98ab91
frontend improved to take into account new SàT features
- quick_frontend: better use of contact management, it now manages nicks, avatars, and connected status
- quick_frontend: disconnect and remove are now 2 separate methods for contact list
- wix: new contact list using HTML items, and showing avatars. Groups are not showed for now
- wix: contact status now use tuples, to keep order, human readable status and color of contact
- wix: contact list is updated when avatar or nick is found
- wix: fixed 'question' dialog, which is renamed in 'yes/no'
- wix: action result are now ignored for unkwnown id
- sortilege refactored to work again
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 07 Jan 2010 00:17:27 +1100 |
parents | c2b131e4e262 |
children | 6455fb62ff83 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 helper class for making a SAT frontend | |
6 Copyright (C) 2009 Jérôme Poisson (goffi@goffi.org) | |
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 from logging import debug, info, error | |
23 from tools.jid import JID | |
24 from sat_bridge_frontend.DBus import DBusBridgeFrontend | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
25 import pdb |
0 | 26 |
27 class QuickApp(): | |
28 """This class contain the main methods needed for the frontend""" | |
29 | |
30 def __init__(self): | |
31 self.rosterList = {} | |
32 | |
33 ## bridge ## | |
34 self.bridge=DBusBridgeFrontend() | |
35 self.bridge.register("newContact", self.newContact) | |
36 self.bridge.register("newMessage", self.newMessage) | |
37 self.bridge.register("presenceUpdate", self.presenceUpdate) | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
38 self.bridge.register("subscribe", self.subscribe) |
0 | 39 self.bridge.register("paramUpdate", self.paramUpdate) |
40 self.bridge.register("contactDeleted", self.contactDeleted) | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
41 self.bridge.register("updatedValue", self.updatedValue, "request") |
0 | 42 self.bridge.register("askConfirmation", self.askConfirmation, "request") |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
43 self.bridge.register("actionResult", self.actionResult, "request") |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
44 self.bridge.register("actionResultExt", self.actionResult, "request") |
0 | 45 |
46 ###now we get the essential params### | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
47 self.whoami=JID(self.bridge.getParamA("JabberID","Connection")) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
48 self.watched=self.bridge.getParamA("Watched", "Misc").split() #TODO: put this in a plugin |
0 | 49 |
50 ## misc ## | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
51 self.current_action_ids = set() |
28 | 52 self.current_action_ids_cb = {} |
0 | 53 self.onlineContact = set() #FIXME: temporary |
54 | |
55 if self.bridge.isConnected(): | |
56 self.setStatusOnline(True) | |
57 | |
58 ### now we fill the contact list ### | |
59 for contact in self.bridge.getContacts(): | |
60 self.newContact(contact[0], contact[1], contact[2]) | |
61 | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
62 presences = self.bridge.getPresenceStatus() |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
63 for contact in presences: |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
64 for res in presences[contact]: |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
65 jabber_id = contact+('/'+res if res else '') |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
66 show = presences[contact][res][0] |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
67 priority = presences[contact][res][1] |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
68 statuses = presences[contact][res][2] |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
69 self.presenceUpdate(jabber_id, show, priority, statuses) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
70 |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
71 waitingSub = self.bridge.getWaitingSub() |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
72 for sub in waitingSub: |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
73 self.subscribe(waitingSub[sub], sub) |
0 | 74 |
75 | |
76 def newContact(self, JabberId, attributes, groups): | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
77 entity=JID(JabberId) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
78 self.rosterList[entity.short]=(dict(attributes), list(groups)) |
0 | 79 |
80 def newMessage(self, from_jid, msg, type, to_jid): | |
81 sender=JID(from_jid) | |
82 addr=JID(to_jid) | |
83 win = addr if sender.short == self.whoami.short else sender | |
84 self.chat_wins[win.short].printMessage(sender, msg) | |
85 | |
86 def setStatusOnline(self, online=True): | |
87 pass | |
88 | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
89 def presenceUpdate(self, jabber_id, show, priority, statuses): |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
90 debug ("presence update for %s (show=%s, statuses=%s)", jabber_id, show, statuses); |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
91 from_jid=JID(jabber_id) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
92 debug ("from_jid.short=%s whoami.short=%s", from_jid.short, self.whoami.short) |
0 | 93 |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
94 if from_jid.short==self.whoami.short: |
0 | 95 if not type: |
96 self.setStatusOnline(True) | |
97 elif type=="unavailable": | |
98 self.setStatusOnline(False) | |
99 return | |
100 | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
101 if show != 'unavailable': |
0 | 102 name="" |
103 group="" | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
104 if self.rosterList.has_key(from_jid.short): |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
105 if self.rosterList[from_jid.short][0].has_key("name"): |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
106 name=self.rosterList[from_jid.short][0]["name"] |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
107 if len(self.rosterList[from_jid.short][1]): |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
108 group=self.rosterList[from_jid.short][1][0] |
0 | 109 |
110 #FIXME: must be moved in a plugin | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
111 if from_jid.short in self.watched and not from_jid.short in self.onlineContact: |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
112 self.showAlert("Watched jid [%s] is connected !" % from_jid.short) |
0 | 113 |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
114 self.onlineContact.add(from_jid) #FIXME onlineContact is useless with CM, must be removed |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
115 self.CM.add(from_jid) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
116 self.CM.update(from_jid, 'name', name) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
117 self.CM.update(from_jid, 'show', show) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
118 self.CM.update(from_jid, 'statuses', statuses) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
119 self.CM.update(from_jid, 'group', group) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
120 cache = self.bridge.getProfileCache(from_jid) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
121 if cache.has_key('nick'): |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
122 self.CM.update(from_jid, 'nick', cache['nick']) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
123 if cache.has_key('avatar'): |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
124 self.CM.update(from_jid, 'avatar', self.bridge.getAvatarFile(cache['avatar'])) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
125 self.contactList.replace(from_jid) |
0 | 126 |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
127 if show=="unavailable" and from_jid in self.onlineContact: |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
128 self.onlineContact.remove(from_jid) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
129 self.CM.remove(from_jid) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
130 if not self.CM.isConnected(from_jid): |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
131 self.contactList.disconnect(from_jid) |
0 | 132 |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
133 def subscribe(self, type, raw_jid): |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
134 """Called when a subsciption maangement signal is received""" |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
135 entity = JID(raw_jid) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
136 if type=="subscribed": |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
137 # this is a subscription confirmation, we just have to inform user |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
138 self.showDialog("The contact %s has accepted your subscription" % entity.short, 'Subscription confirmation') |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
139 elif type=="unsubscribed": |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
140 # this is a subscription refusal, we just have to inform user |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
141 self.showDialog("The contact %s has refused your subscription" % entity.short, 'Subscription refusal', 'error') |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
142 elif type=="subscribe": |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
143 # this is a subscriptionn request, we have to ask for user confirmation |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
144 answer = self.showDialog("The contact %s wants to subscribe to your presence.\nDo you accept ?" % entity.short, 'Subscription confirmation', 'yes/no') |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
145 if answer: |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
146 self.bridge.subscription("subscribed", entity.short) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
147 else: |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
148 self.bridge.subscribed("unsubscribed", entity.short) |
0 | 149 |
150 def showDialog(self, message, title, type="info"): | |
151 raise NotImplementedError | |
152 | |
153 def showAlert(self, message): | |
154 pass #FIXME | |
155 | |
156 def paramUpdate(self, name, value, namespace): | |
157 debug("param update: [%s] %s = %s", namespace, name, value) | |
158 if (namespace,name) == ("Connection", "JabberID"): | |
159 debug ("Changing ID to %s", value) | |
160 self.whoami=JID(value) | |
161 elif (namespace,name) == ("Misc", "Watched"): | |
162 self.watched=value.split() | |
163 | |
164 def contactDeleted(self, jid): | |
165 target = JID(jid) | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
166 self.CM.remove(target) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
167 self.contactList.remove(self.CM.get_full(target)) |
0 | 168 try: |
169 self.onlineContact.remove(target.short) | |
170 except KeyError: | |
171 pass | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
172 |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
173 def updatedValue(self, name, data): |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
174 print "toto" |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
175 print "updatedValue", name, data |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
176 if name == "profile_nick": |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
177 target = JID(data['jid']) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
178 self.CM.update(target, 'nick', data['nick']) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
179 self.contactList.replace(target) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
180 elif name == "profile_avatar": |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
181 target = JID(data['jid']) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
182 filename = self.bridge.getAvatarFile(data['avatar']) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
183 self.CM.update(target, 'avatar', filename) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
184 self.contactList.replace(target) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
185 |
0 | 186 def askConfirmation(self, type, id, data): |
187 raise NotImplementedError | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
188 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
189 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
|
190 raise NotImplementedError |