Mercurial > libervia-backend
annotate frontends/quick_frontend/quick_app.py @ 86:4b5f2d55b6ac
wix: Tarot panel now appear on top of groupchat window when a Tarot game is started
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 11 May 2010 13:06:05 +0930 |
parents | fc7583282d40 |
children | 66d784082930 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 helper class for making a SAT frontend | |
57 | 6 Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org) |
0 | 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 |
70 | 27 import gettext |
28 gettext.install('sat_frontend', "../i18n", unicode=True) | |
29 | |
0 | 30 class QuickApp(): |
31 """This class contain the main methods needed for the frontend""" | |
32 | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
33 def __init__(self, single_profile=True): |
0 | 34 self.rosterList = {} |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
35 self.profiles = {} |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
36 self.single_profile = single_profile |
0 | 37 |
38 ## bridge ## | |
39 self.bridge=DBusBridgeFrontend() | |
52 | 40 self.bridge.register("connected", self.connected) |
41 self.bridge.register("disconnected", self.disconnected) | |
0 | 42 self.bridge.register("newContact", self.newContact) |
43 self.bridge.register("newMessage", self.newMessage) | |
44 self.bridge.register("presenceUpdate", self.presenceUpdate) | |
72 | 45 self.bridge.register("roomJoined", self.roomJoined) |
75 | 46 self.bridge.register("roomUserJoined", self.roomUserJoined) |
47 self.bridge.register("roomUserLeft", self.roomUserLeft) | |
76 | 48 self.bridge.register("roomNewSubject", self.roomNewSubject) |
85 | 49 self.bridge.register("tarotGameStarted", self.tarotGameStarted) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
50 self.bridge.register("subscribe", self.subscribe) |
0 | 51 self.bridge.register("paramUpdate", self.paramUpdate) |
52 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
|
53 self.bridge.register("updatedValue", self.updatedValue, "request") |
0 | 54 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
|
55 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
|
56 self.bridge.register("actionResultExt", self.actionResult, "request") |
0 | 57 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
58 self.current_action_ids = set() |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
59 self.current_action_ids_cb = {} |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
60 |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
61 def __check_profile(self, profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
62 """Tell if the profile is currently followed by the application""" |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
63 return profile in self.profiles.keys() |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
64 |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
65 def plug_profile(self, profile_key='@DEFAULT@'): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
66 """Tell application which profile must be used""" |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
67 if self.single_profile and self.profiles: |
70 | 68 error(_('There is already one profile plugged (we are in single profile mode) !')) |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
69 return |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
70 profile = self.bridge.getProfileName(profile_key) |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
71 if not profile: |
70 | 72 error(_("The profile asked doesn't exist")) |
68 | 73 return |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
74 if self.profiles.has_key(profile): |
70 | 75 warning(_("The profile is already plugged")) |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
76 return |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
77 self.profiles[profile]={} |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
78 if self.single_profile: |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
79 self.profile = profile |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
80 |
0 | 81 ###now we get the essential params### |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
82 self.profiles[profile]['whoami']=JID(self.bridge.getParamA("JabberID","Connection", profile)) |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
83 self.profiles[profile]['watched']=self.bridge.getParamA("Watched", "Misc", profile).split() #TODO: put this in a plugin |
0 | 84 |
85 ## misc ## | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
86 self.profiles[profile]['onlineContact'] = set() #FIXME: temporary |
0 | 87 |
72 | 88 #TODO: gof: managed multi-profiles here |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
89 if self.bridge.isConnected(profile): |
0 | 90 self.setStatusOnline(True) |
52 | 91 else: |
92 self.setStatusOnline(False) | |
93 return | |
0 | 94 |
95 ### now we fill the contact list ### | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
96 for contact in self.bridge.getContacts(profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
97 self.newContact(contact[0], contact[1], contact[2], profile) |
0 | 98 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
99 presences = self.bridge.getPresenceStatus(profile) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
100 for contact in presences: |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
101 for res in presences[contact]: |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
102 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
|
103 show = presences[contact][res][0] |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
104 priority = presences[contact][res][1] |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
105 statuses = presences[contact][res][2] |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
106 self.presenceUpdate(jabber_id, show, priority, statuses, profile) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
107 |
78
ace2af8abc5a
Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents:
76
diff
changeset
|
108 #The waiting subscription requests |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
109 waitingSub = self.bridge.getWaitingSub(profile) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
110 for sub in waitingSub: |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
111 self.subscribe(waitingSub[sub], sub, profile) |
0 | 112 |
78
ace2af8abc5a
Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents:
76
diff
changeset
|
113 #Now we open the MUC window when we already are: |
ace2af8abc5a
Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents:
76
diff
changeset
|
114 for room_args in self.bridge.getRoomJoined(profile): |
ace2af8abc5a
Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents:
76
diff
changeset
|
115 self.roomJoined(*room_args, profile=profile) |
ace2af8abc5a
Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents:
76
diff
changeset
|
116 |
ace2af8abc5a
Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents:
76
diff
changeset
|
117 for subject_args in self.bridge.getRoomSubjects(profile): |
ace2af8abc5a
Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents:
76
diff
changeset
|
118 self.roomNewSubject(*subject_args, profile=profile) |
ace2af8abc5a
Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents:
76
diff
changeset
|
119 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
120 def unplug_profile(self, profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
121 """Tell the application to not follow anymore the profile""" |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
122 if not profile in self.profiles: |
70 | 123 warning (_("This profile is not plugged")) |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
124 return |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
125 self.profiles.remove(profile) |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
126 |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
127 def clear_profile(self): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
128 self.profiles.clear() |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
129 |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
130 def connected(self, profile): |
52 | 131 """called when the connection is made""" |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
132 if not self.__check_profile(profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
133 return |
70 | 134 debug(_("Connected")) |
52 | 135 self.setStatusOnline(True) |
136 | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
137 def disconnected(self, profile): |
52 | 138 """called when the connection is closed""" |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
139 if not self.__check_profile(profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
140 return |
70 | 141 debug(_("Disconnected")) |
52 | 142 self.CM.clear() |
143 self.contactList.clear_contacts() | |
144 self.setStatusOnline(False) | |
145 | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
146 def newContact(self, JabberId, attributes, groups, profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
147 if not self.__check_profile(profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
148 return |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
149 entity=JID(JabberId) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
150 self.rosterList[entity.short]=(dict(attributes), list(groups)) |
0 | 151 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
152 def newMessage(self, from_jid, msg, type, to_jid, profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
153 if not self.__check_profile(profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
154 return |
0 | 155 sender=JID(from_jid) |
156 addr=JID(to_jid) | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
157 win = addr if sender.short == self.profiles[profile]['whoami'].short else sender |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
158 self.current_action_ids = set() |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
159 self.current_action_ids_cb = {} |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
160 self.chat_wins[win.short].printMessage(sender, msg, profile) |
0 | 161 |
162 def setStatusOnline(self, online=True): | |
163 pass | |
164 | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
165 def presenceUpdate(self, jabber_id, show, priority, statuses, profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
166 if not self.__check_profile(profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
167 return |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
168 print "check ok" |
72 | 169 debug (_("presence update for %(jid)s (show=%(show)s, priority=%(priority)s, statuses=%(statuses)s) [profile:%(profile)s]") % {'jid':jabber_id, 'show':show, 'priority':priority, 'statuses':statuses, 'profile':profile}); |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
170 from_jid=JID(jabber_id) |
70 | 171 debug ("from_jid.short=%(from_jid)s whoami.short=%(whoami)s" % {'from_jid':from_jid.short, 'whoami':self.profiles[profile]['whoami'].short}) |
0 | 172 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
173 if from_jid.short==self.profiles[profile]['whoami'].short: |
0 | 174 if not type: |
175 self.setStatusOnline(True) | |
176 elif type=="unavailable": | |
177 self.setStatusOnline(False) | |
178 return | |
179 | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
180 if show != 'unavailable': |
0 | 181 name="" |
53
6dfe5bb10008
Wix: groups in contact list, first draft
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
182 groups = [] |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
183 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
|
184 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
|
185 name=self.rosterList[from_jid.short][0]["name"] |
53
6dfe5bb10008
Wix: groups in contact list, first draft
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
186 groups=self.rosterList[from_jid.short][1] |
0 | 187 |
188 #FIXME: must be moved in a plugin | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
189 if from_jid.short in self.profiles[profile]['watched'] and not from_jid.short in self.profiles[profile]['onlineContact']: |
70 | 190 self.showAlert(_("Watched jid [%s] is connected !") % from_jid.short) |
0 | 191 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
192 self.profiles[profile]['onlineContact'].add(from_jid) #FIXME onlineContact is useless with CM, must be removed |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
193 self.CM.add(from_jid) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
194 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
|
195 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
|
196 self.CM.update(from_jid, 'statuses', statuses) |
53
6dfe5bb10008
Wix: groups in contact list, first draft
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
197 self.CM.update(from_jid, 'groups', groups) |
64 | 198 cache = self.bridge.getCardCache(from_jid) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
199 if cache.has_key('nick'): |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
200 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
|
201 if cache.has_key('avatar'): |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
202 self.CM.update(from_jid, 'avatar', self.bridge.getAvatarFile(cache['avatar'])) |
72 | 203 self.contactList.replace(from_jid, self.CM.getAttr(from_jid, 'groups')) |
0 | 204 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
205 if show=="unavailable" and from_jid in self.profiles[profile]['onlineContact']: |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
206 self.profiles[profile]['onlineContact'].remove(from_jid) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
207 self.CM.remove(from_jid) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
208 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
|
209 self.contactList.disconnect(from_jid) |
72 | 210 |
211 def roomJoined(self, room_id, room_service, room_nicks, user_nick, profile): | |
212 """Called when a MUC room is joined""" | |
75 | 213 if not self.__check_profile(profile): |
214 return | |
215 debug (_("Room [%(room_name)s] joined by %(profile)s, users presents:%(users)s") % {'room_name':room_id+'@'+room_service, 'profile': profile, 'users':room_nicks}) | |
216 room_jid=room_id+'@'+room_service | |
79 | 217 self.chat_wins[room_jid].setUserNick(user_nick) |
75 | 218 self.chat_wins[room_jid].setType("group") |
85 | 219 self.chat_wins[room_jid].id = room_jid |
75 | 220 self.chat_wins[room_jid].setPresents([user_nick]+room_nicks) |
72 | 221 |
222 | |
75 | 223 def roomUserJoined(self, room_id, room_service, user_nick, user_data, profile): |
224 """Called when an user joined a MUC room""" | |
225 if not self.__check_profile(profile): | |
226 return | |
227 room_jid=room_id+'@'+room_service | |
228 if self.chat_wins.has_key(room_jid): | |
229 self.chat_wins[room_jid].replaceUser(user_nick) | |
76 | 230 debug (_("user [%(user_nick)s] joined room [%(room_jid)s]") % {'user_nick':user_nick, 'room_jid':room_jid}) |
75 | 231 |
232 def roomUserLeft(self, room_id, room_service, user_nick, user_data, profile): | |
233 """Called when an user joined a MUC room""" | |
234 if not self.__check_profile(profile): | |
235 return | |
236 room_jid=room_id+'@'+room_service | |
237 if self.chat_wins.has_key(room_jid): | |
238 self.chat_wins[room_jid].removeUser(user_nick) | |
76 | 239 debug (_("user [%(user_nick)s] left room [%(room_jid)s]") % {'user_nick':user_nick, 'room_jid':room_jid}) |
240 | |
241 def roomNewSubject(self, room_id, room_service, subject, profile): | |
242 """Called when subject of MUC room change""" | |
243 if not self.__check_profile(profile): | |
244 return | |
245 room_jid=room_id+'@'+room_service | |
246 if self.chat_wins.has_key(room_jid): | |
247 self.chat_wins[room_jid].setSubject(subject) | |
248 debug (_("new subject for room [%(room_jid)s]: %(subject)s") % {'room_jid':room_jid, "subject":subject}) | |
85 | 249 |
250 def tarotGameStarted(self, room_jid, players, profile): | |
251 if not self.__check_profile(profile): | |
252 return | |
253 print "Tarot Game Started \o/" | |
86
4b5f2d55b6ac
wix: Tarot panel now appear on top of groupchat window when a Tarot game is started
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
254 if self.chat_wins.has_key(room_jid): |
4b5f2d55b6ac
wix: Tarot panel now appear on top of groupchat window when a Tarot game is started
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
255 self.chat_wins[room_jid].startGame("Tarot") |
4b5f2d55b6ac
wix: Tarot panel now appear on top of groupchat window when a Tarot game is started
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
256 debug (_("new Tarot game started in room [%(room_jid)s]") % {'room_jid':room_jid}) |
4b5f2d55b6ac
wix: Tarot panel now appear on top of groupchat window when a Tarot game is started
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
257 |
76 | 258 |
0 | 259 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
260 def subscribe(self, type, raw_jid, profile): |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
261 """Called when a subsciption maangement signal is received""" |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
262 if not self.__check_profile(profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
263 return |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
264 entity = JID(raw_jid) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
265 if type=="subscribed": |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
266 # this is a subscription confirmation, we just have to inform user |
70 | 267 self.showDialog(_("The contact %s has accepted your subscription") % entity.short, _('Subscription confirmation')) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
268 elif type=="unsubscribed": |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
269 # this is a subscription refusal, we just have to inform user |
70 | 270 self.showDialog(_("The contact %s has refused your subscription") % entity.short, _('Subscription refusal'), 'error') |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
271 elif type=="subscribe": |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
272 # this is a subscriptionn request, we have to ask for user confirmation |
70 | 273 answer = self.showDialog(_("The contact %s wants to subscribe to your presence.\nDo you accept ?") % entity.short, _('Subscription confirmation'), 'yes/no') |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
274 if answer: |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
275 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
|
276 else: |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
277 self.bridge.subscribed("unsubscribed", entity.short) |
0 | 278 |
279 def showDialog(self, message, title, type="info"): | |
280 raise NotImplementedError | |
281 | |
282 def showAlert(self, message): | |
283 pass #FIXME | |
284 | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
285 def paramUpdate(self, name, value, namespace, profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
286 if not self.__check_profile(profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
287 return |
70 | 288 debug(_("param update: [%(namespace)s] %(name)s = %(value)s") % {'namespace':namespace, 'name':name, 'value':value}) |
0 | 289 if (namespace,name) == ("Connection", "JabberID"): |
70 | 290 debug (_("Changing JID to %s"), value) |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
291 self.profiles[profile]['whoami']=JID(value) |
0 | 292 elif (namespace,name) == ("Misc", "Watched"): |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
293 self.profiles[profile]['watched']=value.split() |
0 | 294 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
295 def contactDeleted(self, jid, profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
296 if not self.__check_profile(profile): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
297 return |
0 | 298 target = JID(jid) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
299 self.CM.remove(target) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
300 self.contactList.remove(self.CM.get_full(target)) |
0 | 301 try: |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
302 self.profiles[profile]['onlineContact'].remove(target.short) |
0 | 303 except KeyError: |
304 pass | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
305 |
71
efe81b61673c
quick app: updatedValue wrong parameter fix
Goffi <goffi@goffi.org>
parents:
70
diff
changeset
|
306 def updatedValue(self, name, data): |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
307 if name == "card_nick": |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
308 target = JID(data['jid']) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
309 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
|
310 self.contactList.replace(target) |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
311 elif name == "card_avatar": |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
312 target = JID(data['jid']) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
313 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
|
314 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
|
315 self.contactList.replace(target) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
316 |
0 | 317 def askConfirmation(self, type, id, data): |
318 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
|
319 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
320 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
|
321 raise NotImplementedError |