Mercurial > libervia-backend
annotate frontends/quick_frontend/quick_app.py @ 24:61124cb82fb7
Updated README and licenses (for images), added installation instructions.
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 01 Dec 2009 07:55:46 +0100 |
parents | bb72c29f3432 |
children | 53e921c8a357 |
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") | |
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") |
0 | 44 |
45 ###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
|
46 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
|
47 self.watched=self.bridge.getParamA("Watched", "Misc").split() #TODO: put this in a plugin |
0 | 48 |
49 ## 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
|
50 self.current_action_ids = set() |
0 | 51 self.onlineContact = set() #FIXME: temporary |
52 | |
53 if self.bridge.isConnected(): | |
54 self.setStatusOnline(True) | |
55 | |
56 ### now we fill the contact list ### | |
57 for contact in self.bridge.getContacts(): | |
58 self.newContact(contact[0], contact[1], contact[2]) | |
59 | |
60 for status in self.bridge.getPresenceStatus(): | |
61 self.presenceUpdate(status[0], status[1], status[2], status[3], status[4]) | |
62 | |
63 | |
64 def newContact(self, JabberId, attributes, groups): | |
65 jid=JID(JabberId) | |
66 self.rosterList[jid.short]=(dict(attributes), list(groups)) | |
67 | |
68 def newMessage(self, from_jid, msg, type, to_jid): | |
69 sender=JID(from_jid) | |
70 addr=JID(to_jid) | |
71 win = addr if sender.short == self.whoami.short else sender | |
72 self.chat_wins[win.short].printMessage(sender, msg) | |
73 | |
74 def setStatusOnline(self, online=True): | |
75 pass | |
76 | |
77 def presenceUpdate(self, jabber_id, type, show, status, priority): | |
78 debug ("presence update for %s (type=%s, show=%s, status=%s)", jabber_id, type, show, status); | |
79 jid=JID(jabber_id) | |
80 debug ("jid.short=%s whoami.short=%s", jid.short, self.whoami.short) | |
81 | |
82 ### subscription management ### | |
83 if type=="subscribed": | |
84 # this is a subscription confirmation, we just have to inform user | |
85 self.showDialog("The contact %s has accepted your subscription" % jid.short, 'Subscription confirmation') | |
86 return | |
87 elif type=="unsubscribed": | |
88 # this is a subscription refusal, we just have to inform user | |
89 self.showDialog("The contact %s has refused your subscription" % jid.short, 'Subscription refusal', 'error') | |
90 return | |
91 elif type=="subscribe": | |
92 # this is a subscrition request, we have to ask for user confirmation | |
93 answer = self.showDialog("The contact %s wants to subscribe to your presence.\nDo you accept ?" % jid.short, 'Subscription confirmation', 'question') | |
94 if answer: | |
95 self.bridge.setPresence(type="subscribed", to=jid.short) | |
96 else: | |
97 self.bridge.setPresence(type="unsubscribed", to=jid.short) | |
98 return | |
99 ### subscription management end ### | |
100 | |
101 if jid.short==self.whoami.short: | |
102 if not type: | |
103 self.setStatusOnline(True) | |
104 elif type=="unavailable": | |
105 self.setStatusOnline(False) | |
106 return | |
107 | |
108 if not type: | |
109 name="" | |
110 group="" | |
111 if self.rosterList.has_key(jid.short): | |
112 if self.rosterList[jid.short][0].has_key("name"): | |
113 name=self.rosterList[jid.short][0]["name"] | |
114 if self.rosterList[jid.short][0].has_key("show"): | |
115 name=self.rosterList[jid.short][0]["show"] | |
116 if self.rosterList[jid.short][0].has_key("status"): | |
117 name=self.rosterList[jid.short][0]["status"] | |
118 if len(self.rosterList[jid.short][1]): | |
119 group=self.rosterList[jid.short][1][0] | |
120 | |
121 #FIXME: must be moved in a plugin | |
122 if jid.short in self.watched and not jid.short in self.onlineContact: | |
123 self.showAlert("Watched jid [%s] is connected !" % jid.short) | |
124 | |
125 self.onlineContact.add(jid) #FIXME onlineContact is useless with CM, must be removed | |
126 self.CM.add(jid) | |
127 self.contactList.replace(jid, show=show, status=status, name=name, group=group) | |
128 | |
129 | |
13
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
130 if type=="unavailable" and jid in self.onlineContact: |
bd9e9997d540
wokkel integration (not finished yet)
Goffi <goffi@goffi.org>
parents:
0
diff
changeset
|
131 self.onlineContact.remove(jid) |
0 | 132 self.CM.remove(jid) |
133 self.contactList.remove(jid) | |
134 | |
135 | |
136 def showDialog(self, message, title, type="info"): | |
137 raise NotImplementedError | |
138 | |
139 def showAlert(self, message): | |
140 pass #FIXME | |
141 | |
142 def paramUpdate(self, name, value, namespace): | |
143 debug("param update: [%s] %s = %s", namespace, name, value) | |
144 if (namespace,name) == ("Connection", "JabberID"): | |
145 debug ("Changing ID to %s", value) | |
146 self.whoami=JID(value) | |
147 elif (namespace,name) == ("Misc", "Watched"): | |
148 self.watched=value.split() | |
149 | |
150 def contactDeleted(self, jid): | |
151 target = JID(jid) | |
152 try: | |
153 self.onlineContact.remove(target.short) | |
154 except KeyError: | |
155 pass | |
156 self.contactList.remove(self.CM.get_full(jid)) | |
157 self.CM.remove(target) | |
158 | |
159 def askConfirmation(self, type, id, data): | |
160 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
|
161 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
162 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
|
163 raise NotImplementedError |