Mercurial > libervia-backend
annotate frontends/quick_frontend/quick_app.py @ 13:bd9e9997d540
wokkel integration (not finished yet)
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 30 Oct 2009 17:38:27 +0100 |
parents | c4bc297b82f0 |
children | 6928e3cb73a8 |
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 | |
25 from quick_frontend.quick_contact_management import QuickContactManagement | |
26 | |
27 | |
28 class QuickApp(): | |
29 """This class contain the main methods needed for the frontend""" | |
30 | |
31 def __init__(self): | |
32 self.rosterList = {} | |
33 self.CM = QuickContactManagement() #a short name if more handy | |
34 | |
35 ## bridge ## | |
36 self.bridge=DBusBridgeFrontend() | |
37 self.bridge.register("newContact", self.newContact) | |
38 self.bridge.register("newMessage", self.newMessage) | |
39 self.bridge.register("presenceUpdate", self.presenceUpdate) | |
40 self.bridge.register("paramUpdate", self.paramUpdate) | |
41 self.bridge.register("contactDeleted", self.contactDeleted) | |
42 self.bridge.register("askConfirmation", self.askConfirmation, "request") | |
43 | |
44 ###now we get the essential params### | |
45 self.whoami=JID(self.bridge.getParam("JabberID","Connection")[0]) | |
46 self.watched=self.bridge.getParam("Watched", "Misc")[0].split() #TODO: put this in a plugin | |
47 | |
48 ## misc ## | |
49 self.onlineContact = set() #FIXME: temporary | |
50 | |
51 if self.bridge.isConnected(): | |
52 self.setStatusOnline(True) | |
53 | |
54 ### now we fill the contact list ### | |
55 for contact in self.bridge.getContacts(): | |
56 self.newContact(contact[0], contact[1], contact[2]) | |
57 | |
58 for status in self.bridge.getPresenceStatus(): | |
59 self.presenceUpdate(status[0], status[1], status[2], status[3], status[4]) | |
60 | |
61 | |
62 def newContact(self, JabberId, attributes, groups): | |
63 jid=JID(JabberId) | |
64 self.rosterList[jid.short]=(dict(attributes), list(groups)) | |
65 | |
66 def newMessage(self, from_jid, msg, type, to_jid): | |
67 sender=JID(from_jid) | |
68 addr=JID(to_jid) | |
69 win = addr if sender.short == self.whoami.short else sender | |
70 self.chat_wins[win.short].printMessage(sender, msg) | |
71 | |
72 def setStatusOnline(self, online=True): | |
73 pass | |
74 | |
75 def presenceUpdate(self, jabber_id, type, show, status, priority): | |
76 debug ("presence update for %s (type=%s, show=%s, status=%s)", jabber_id, type, show, status); | |
77 jid=JID(jabber_id) | |
78 debug ("jid.short=%s whoami.short=%s", jid.short, self.whoami.short) | |
79 | |
80 ### subscription management ### | |
81 if type=="subscribed": | |
82 # this is a subscription confirmation, we just have to inform user | |
83 self.showDialog("The contact %s has accepted your subscription" % jid.short, 'Subscription confirmation') | |
84 return | |
85 elif type=="unsubscribed": | |
86 # this is a subscription refusal, we just have to inform user | |
87 self.showDialog("The contact %s has refused your subscription" % jid.short, 'Subscription refusal', 'error') | |
88 return | |
89 elif type=="subscribe": | |
90 # this is a subscrition request, we have to ask for user confirmation | |
91 answer = self.showDialog("The contact %s wants to subscribe to your presence.\nDo you accept ?" % jid.short, 'Subscription confirmation', 'question') | |
92 if answer: | |
93 self.bridge.setPresence(type="subscribed", to=jid.short) | |
94 else: | |
95 self.bridge.setPresence(type="unsubscribed", to=jid.short) | |
96 return | |
97 ### subscription management end ### | |
98 | |
99 if jid.short==self.whoami.short: | |
100 if not type: | |
101 self.setStatusOnline(True) | |
102 elif type=="unavailable": | |
103 self.setStatusOnline(False) | |
104 return | |
105 | |
106 if not type: | |
107 name="" | |
108 group="" | |
109 if self.rosterList.has_key(jid.short): | |
110 if self.rosterList[jid.short][0].has_key("name"): | |
111 name=self.rosterList[jid.short][0]["name"] | |
112 if self.rosterList[jid.short][0].has_key("show"): | |
113 name=self.rosterList[jid.short][0]["show"] | |
114 if self.rosterList[jid.short][0].has_key("status"): | |
115 name=self.rosterList[jid.short][0]["status"] | |
116 if len(self.rosterList[jid.short][1]): | |
117 group=self.rosterList[jid.short][1][0] | |
118 | |
119 #FIXME: must be moved in a plugin | |
120 if jid.short in self.watched and not jid.short in self.onlineContact: | |
121 self.showAlert("Watched jid [%s] is connected !" % jid.short) | |
122 | |
123 self.onlineContact.add(jid) #FIXME onlineContact is useless with CM, must be removed | |
124 self.CM.add(jid) | |
125 self.contactList.replace(jid, show=show, status=status, name=name, group=group) | |
126 | |
127 | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
128 if type=="unavailable" and jid in self.onlineContact: |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
129 self.onlineContact.remove(jid) |
0 | 130 self.CM.remove(jid) |
131 self.contactList.remove(jid) | |
132 | |
133 | |
134 def showDialog(self, message, title, type="info"): | |
135 raise NotImplementedError | |
136 | |
137 def showAlert(self, message): | |
138 pass #FIXME | |
139 | |
140 def paramUpdate(self, name, value, namespace): | |
141 debug("param update: [%s] %s = %s", namespace, name, value) | |
142 if (namespace,name) == ("Connection", "JabberID"): | |
143 debug ("Changing ID to %s", value) | |
144 self.whoami=JID(value) | |
145 elif (namespace,name) == ("Misc", "Watched"): | |
146 self.watched=value.split() | |
147 | |
148 def contactDeleted(self, jid): | |
149 target = JID(jid) | |
150 try: | |
151 self.onlineContact.remove(target.short) | |
152 except KeyError: | |
153 pass | |
154 self.contactList.remove(self.CM.get_full(jid)) | |
155 self.CM.remove(target) | |
156 | |
157 def askConfirmation(self, type, id, data): | |
158 raise NotImplementedError |