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