annotate frontends/quick_frontend/quick_app.py @ 42:874de3020e1c

Initial VCard (XEP-0054) support + misc fixes - new xep-0054 plugin, avatar are cached, new getProfile bridge method - gateways plugin (XEP-0100): new __private__ key in resulting data, used to keep target jid
author Goffi <goffi@goffi.org>
date Mon, 21 Dec 2009 13:22:11 +1100
parents c2b131e4e262
children 8c67ea98ab91
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
goffi@necton2
parents:
diff changeset
1 #!/usr/bin/python
goffi@necton2
parents:
diff changeset
2 # -*- coding: utf-8 -*-
goffi@necton2
parents:
diff changeset
3
goffi@necton2
parents:
diff changeset
4 """
goffi@necton2
parents:
diff changeset
5 helper class for making a SAT frontend
goffi@necton2
parents:
diff changeset
6 Copyright (C) 2009 Jérôme Poisson (goffi@goffi.org)
goffi@necton2
parents:
diff changeset
7
goffi@necton2
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
goffi@necton2
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
goffi@necton2
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
goffi@necton2
parents:
diff changeset
11 (at your option) any later version.
goffi@necton2
parents:
diff changeset
12
goffi@necton2
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
goffi@necton2
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
goffi@necton2
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
goffi@necton2
parents:
diff changeset
16 GNU General Public License for more details.
goffi@necton2
parents:
diff changeset
17
goffi@necton2
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
goffi@necton2
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
goffi@necton2
parents:
diff changeset
20 """
goffi@necton2
parents:
diff changeset
21
goffi@necton2
parents:
diff changeset
22 from logging import debug, info, error
goffi@necton2
parents:
diff changeset
23 from tools.jid import JID
goffi@necton2
parents:
diff changeset
24 from sat_bridge_frontend.DBus import DBusBridgeFrontend
goffi@necton2
parents:
diff changeset
25 from quick_frontend.quick_contact_management import QuickContactManagement
goffi@necton2
parents:
diff changeset
26
goffi@necton2
parents:
diff changeset
27
goffi@necton2
parents:
diff changeset
28 class QuickApp():
goffi@necton2
parents:
diff changeset
29 """This class contain the main methods needed for the frontend"""
goffi@necton2
parents:
diff changeset
30
goffi@necton2
parents:
diff changeset
31 def __init__(self):
goffi@necton2
parents:
diff changeset
32 self.rosterList = {}
goffi@necton2
parents:
diff changeset
33 self.CM = QuickContactManagement() #a short name if more handy
goffi@necton2
parents:
diff changeset
34
goffi@necton2
parents:
diff changeset
35 ## bridge ##
goffi@necton2
parents:
diff changeset
36 self.bridge=DBusBridgeFrontend()
goffi@necton2
parents:
diff changeset
37 self.bridge.register("newContact", self.newContact)
goffi@necton2
parents:
diff changeset
38 self.bridge.register("newMessage", self.newMessage)
goffi@necton2
parents:
diff changeset
39 self.bridge.register("presenceUpdate", self.presenceUpdate)
goffi@necton2
parents:
diff changeset
40 self.bridge.register("paramUpdate", self.paramUpdate)
goffi@necton2
parents:
diff changeset
41 self.bridge.register("contactDeleted", self.contactDeleted)
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
45
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
49
goffi@necton2
parents:
diff changeset
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
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents: 25
diff changeset
52 self.current_action_ids_cb = {}
0
goffi@necton2
parents:
diff changeset
53 self.onlineContact = set() #FIXME: temporary
goffi@necton2
parents:
diff changeset
54
goffi@necton2
parents:
diff changeset
55 if self.bridge.isConnected():
goffi@necton2
parents:
diff changeset
56 self.setStatusOnline(True)
goffi@necton2
parents:
diff changeset
57
goffi@necton2
parents:
diff changeset
58 ### now we fill the contact list ###
goffi@necton2
parents:
diff changeset
59 for contact in self.bridge.getContacts():
goffi@necton2
parents:
diff changeset
60 self.newContact(contact[0], contact[1], contact[2])
goffi@necton2
parents:
diff changeset
61
goffi@necton2
parents:
diff changeset
62 for status in self.bridge.getPresenceStatus():
goffi@necton2
parents:
diff changeset
63 self.presenceUpdate(status[0], status[1], status[2], status[3], status[4])
goffi@necton2
parents:
diff changeset
64
goffi@necton2
parents:
diff changeset
65
goffi@necton2
parents:
diff changeset
66 def newContact(self, JabberId, attributes, groups):
goffi@necton2
parents:
diff changeset
67 jid=JID(JabberId)
goffi@necton2
parents:
diff changeset
68 self.rosterList[jid.short]=(dict(attributes), list(groups))
goffi@necton2
parents:
diff changeset
69
goffi@necton2
parents:
diff changeset
70 def newMessage(self, from_jid, msg, type, to_jid):
goffi@necton2
parents:
diff changeset
71 sender=JID(from_jid)
goffi@necton2
parents:
diff changeset
72 addr=JID(to_jid)
goffi@necton2
parents:
diff changeset
73 win = addr if sender.short == self.whoami.short else sender
goffi@necton2
parents:
diff changeset
74 self.chat_wins[win.short].printMessage(sender, msg)
goffi@necton2
parents:
diff changeset
75
goffi@necton2
parents:
diff changeset
76 def setStatusOnline(self, online=True):
goffi@necton2
parents:
diff changeset
77 pass
goffi@necton2
parents:
diff changeset
78
goffi@necton2
parents:
diff changeset
79 def presenceUpdate(self, jabber_id, type, show, status, priority):
goffi@necton2
parents:
diff changeset
80 debug ("presence update for %s (type=%s, show=%s, status=%s)", jabber_id, type, show, status);
goffi@necton2
parents:
diff changeset
81 jid=JID(jabber_id)
goffi@necton2
parents:
diff changeset
82 debug ("jid.short=%s whoami.short=%s", jid.short, self.whoami.short)
goffi@necton2
parents:
diff changeset
83
goffi@necton2
parents:
diff changeset
84 ### subscription management ###
goffi@necton2
parents:
diff changeset
85 if type=="subscribed":
goffi@necton2
parents:
diff changeset
86 # this is a subscription confirmation, we just have to inform user
goffi@necton2
parents:
diff changeset
87 self.showDialog("The contact %s has accepted your subscription" % jid.short, 'Subscription confirmation')
goffi@necton2
parents:
diff changeset
88 return
goffi@necton2
parents:
diff changeset
89 elif type=="unsubscribed":
goffi@necton2
parents:
diff changeset
90 # this is a subscription refusal, we just have to inform user
goffi@necton2
parents:
diff changeset
91 self.showDialog("The contact %s has refused your subscription" % jid.short, 'Subscription refusal', 'error')
goffi@necton2
parents:
diff changeset
92 return
goffi@necton2
parents:
diff changeset
93 elif type=="subscribe":
goffi@necton2
parents:
diff changeset
94 # this is a subscrition request, we have to ask for user confirmation
goffi@necton2
parents:
diff changeset
95 answer = self.showDialog("The contact %s wants to subscribe to your presence.\nDo you accept ?" % jid.short, 'Subscription confirmation', 'question')
goffi@necton2
parents:
diff changeset
96 if answer:
goffi@necton2
parents:
diff changeset
97 self.bridge.setPresence(type="subscribed", to=jid.short)
goffi@necton2
parents:
diff changeset
98 else:
goffi@necton2
parents:
diff changeset
99 self.bridge.setPresence(type="unsubscribed", to=jid.short)
goffi@necton2
parents:
diff changeset
100 return
goffi@necton2
parents:
diff changeset
101 ### subscription management end ###
goffi@necton2
parents:
diff changeset
102
goffi@necton2
parents:
diff changeset
103 if jid.short==self.whoami.short:
goffi@necton2
parents:
diff changeset
104 if not type:
goffi@necton2
parents:
diff changeset
105 self.setStatusOnline(True)
goffi@necton2
parents:
diff changeset
106 elif type=="unavailable":
goffi@necton2
parents:
diff changeset
107 self.setStatusOnline(False)
goffi@necton2
parents:
diff changeset
108 return
goffi@necton2
parents:
diff changeset
109
goffi@necton2
parents:
diff changeset
110 if not type:
goffi@necton2
parents:
diff changeset
111 name=""
goffi@necton2
parents:
diff changeset
112 group=""
goffi@necton2
parents:
diff changeset
113 if self.rosterList.has_key(jid.short):
goffi@necton2
parents:
diff changeset
114 if self.rosterList[jid.short][0].has_key("name"):
goffi@necton2
parents:
diff changeset
115 name=self.rosterList[jid.short][0]["name"]
goffi@necton2
parents:
diff changeset
116 if self.rosterList[jid.short][0].has_key("show"):
goffi@necton2
parents:
diff changeset
117 name=self.rosterList[jid.short][0]["show"]
goffi@necton2
parents:
diff changeset
118 if self.rosterList[jid.short][0].has_key("status"):
goffi@necton2
parents:
diff changeset
119 name=self.rosterList[jid.short][0]["status"]
goffi@necton2
parents:
diff changeset
120 if len(self.rosterList[jid.short][1]):
goffi@necton2
parents:
diff changeset
121 group=self.rosterList[jid.short][1][0]
goffi@necton2
parents:
diff changeset
122
goffi@necton2
parents:
diff changeset
123 #FIXME: must be moved in a plugin
goffi@necton2
parents:
diff changeset
124 if jid.short in self.watched and not jid.short in self.onlineContact:
goffi@necton2
parents:
diff changeset
125 self.showAlert("Watched jid [%s] is connected !" % jid.short)
goffi@necton2
parents:
diff changeset
126
goffi@necton2
parents:
diff changeset
127 self.onlineContact.add(jid) #FIXME onlineContact is useless with CM, must be removed
goffi@necton2
parents:
diff changeset
128 self.CM.add(jid)
goffi@necton2
parents:
diff changeset
129 self.contactList.replace(jid, show=show, status=status, name=name, group=group)
goffi@necton2
parents:
diff changeset
130
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
134 self.CM.remove(jid)
goffi@necton2
parents:
diff changeset
135 self.contactList.remove(jid)
goffi@necton2
parents:
diff changeset
136
goffi@necton2
parents:
diff changeset
137
goffi@necton2
parents:
diff changeset
138 def showDialog(self, message, title, type="info"):
goffi@necton2
parents:
diff changeset
139 raise NotImplementedError
goffi@necton2
parents:
diff changeset
140
goffi@necton2
parents:
diff changeset
141 def showAlert(self, message):
goffi@necton2
parents:
diff changeset
142 pass #FIXME
goffi@necton2
parents:
diff changeset
143
goffi@necton2
parents:
diff changeset
144 def paramUpdate(self, name, value, namespace):
goffi@necton2
parents:
diff changeset
145 debug("param update: [%s] %s = %s", namespace, name, value)
goffi@necton2
parents:
diff changeset
146 if (namespace,name) == ("Connection", "JabberID"):
goffi@necton2
parents:
diff changeset
147 debug ("Changing ID to %s", value)
goffi@necton2
parents:
diff changeset
148 self.whoami=JID(value)
goffi@necton2
parents:
diff changeset
149 elif (namespace,name) == ("Misc", "Watched"):
goffi@necton2
parents:
diff changeset
150 self.watched=value.split()
goffi@necton2
parents:
diff changeset
151
goffi@necton2
parents:
diff changeset
152 def contactDeleted(self, jid):
goffi@necton2
parents:
diff changeset
153 target = JID(jid)
goffi@necton2
parents:
diff changeset
154 try:
goffi@necton2
parents:
diff changeset
155 self.onlineContact.remove(target.short)
goffi@necton2
parents:
diff changeset
156 except KeyError:
goffi@necton2
parents:
diff changeset
157 pass
goffi@necton2
parents:
diff changeset
158 self.contactList.remove(self.CM.get_full(jid))
goffi@necton2
parents:
diff changeset
159 self.CM.remove(target)
goffi@necton2
parents:
diff changeset
160
goffi@necton2
parents:
diff changeset
161 def askConfirmation(self, type, id, data):
goffi@necton2
parents:
diff changeset
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