Mercurial > libervia-backend
annotate frontends/quick_frontend/quick_app.py @ 92:2503de7fb4c7
Tarot game: chien/écart stage
- tarot plugin: new methods/signals tarotGamePlayCards, tarotGameShowCards, tarotGameYourTurn
- tarot plugin: protocole update
- tarot plugin: family renamed in suit
- wix: card_game: card can be selected for écart, card move when mouse is over only if it's our turn
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 29 May 2010 20:53:03 +0930 |
parents | 39c672544593 |
children | 2f87651a5ad8 |
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 | |
91 | 25 from optparse import OptionParser |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
26 import pdb |
0 | 27 |
70 | 28 import gettext |
29 gettext.install('sat_frontend', "../i18n", unicode=True) | |
30 | |
0 | 31 class QuickApp(): |
32 """This class contain the main methods needed for the frontend""" | |
33 | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
34 def __init__(self, single_profile=True): |
0 | 35 self.rosterList = {} |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
36 self.profiles = {} |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
37 self.single_profile = single_profile |
91 | 38 self.check_options() |
0 | 39 |
40 ## bridge ## | |
41 self.bridge=DBusBridgeFrontend() | |
52 | 42 self.bridge.register("connected", self.connected) |
43 self.bridge.register("disconnected", self.disconnected) | |
0 | 44 self.bridge.register("newContact", self.newContact) |
45 self.bridge.register("newMessage", self.newMessage) | |
46 self.bridge.register("presenceUpdate", self.presenceUpdate) | |
72 | 47 self.bridge.register("roomJoined", self.roomJoined) |
75 | 48 self.bridge.register("roomUserJoined", self.roomUserJoined) |
49 self.bridge.register("roomUserLeft", self.roomUserLeft) | |
76 | 50 self.bridge.register("roomNewSubject", self.roomNewSubject) |
85 | 51 self.bridge.register("tarotGameStarted", self.tarotGameStarted) |
87 | 52 self.bridge.register("tarotGameNew", self.tarotGameNew) |
92 | 53 self.bridge.register("tarotGameChooseContrat", self.tarotChooseContrat) |
54 self.bridge.register("tarotGameShowCards", self.tarotShowCards) | |
55 self.bridge.register("tarotGameYourTurn", self.tarotMyTurn) | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
56 self.bridge.register("subscribe", self.subscribe) |
0 | 57 self.bridge.register("paramUpdate", self.paramUpdate) |
58 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
|
59 self.bridge.register("updatedValue", self.updatedValue, "request") |
0 | 60 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
|
61 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
|
62 self.bridge.register("actionResultExt", self.actionResult, "request") |
0 | 63 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
64 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
|
65 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
|
66 |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
67 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
|
68 """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
|
69 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
|
70 |
91 | 71 def check_options(self): |
72 """Check command line options""" | |
73 usage=_(""" | |
74 %prog [options] | |
75 | |
76 %prog --help for options list | |
77 """) | |
78 parser = OptionParser(usage=usage) | |
79 | |
80 parser.add_option("-p", "--profile", help=_("Select the profile to use")) | |
81 | |
82 (self.options, args) = parser.parse_args() | |
83 return args | |
84 | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
85 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
|
86 """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
|
87 if self.single_profile and self.profiles: |
70 | 88 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
|
89 return |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
90 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
|
91 if not profile: |
70 | 92 error(_("The profile asked doesn't exist")) |
68 | 93 return |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
94 if self.profiles.has_key(profile): |
70 | 95 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
|
96 return |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
97 self.profiles[profile]={} |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
98 if self.single_profile: |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
99 self.profile = profile |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
100 |
0 | 101 ###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
|
102 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
|
103 self.profiles[profile]['watched']=self.bridge.getParamA("Watched", "Misc", profile).split() #TODO: put this in a plugin |
0 | 104 |
105 ## misc ## | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
106 self.profiles[profile]['onlineContact'] = set() #FIXME: temporary |
0 | 107 |
72 | 108 #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
|
109 if self.bridge.isConnected(profile): |
0 | 110 self.setStatusOnline(True) |
52 | 111 else: |
112 self.setStatusOnline(False) | |
113 return | |
0 | 114 |
115 ### 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
|
116 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
|
117 self.newContact(contact[0], contact[1], contact[2], profile) |
0 | 118 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
119 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
|
120 for contact in presences: |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
121 for res in presences[contact]: |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
122 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
|
123 show = presences[contact][res][0] |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
124 priority = presences[contact][res][1] |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
125 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
|
126 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
|
127 |
78
ace2af8abc5a
Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents:
76
diff
changeset
|
128 #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
|
129 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
|
130 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
|
131 self.subscribe(waitingSub[sub], sub, profile) |
0 | 132 |
78
ace2af8abc5a
Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents:
76
diff
changeset
|
133 #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
|
134 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
|
135 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
|
136 |
ace2af8abc5a
Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents:
76
diff
changeset
|
137 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
|
138 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
|
139 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
140 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
|
141 """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
|
142 if not profile in self.profiles: |
70 | 143 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
|
144 return |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
145 self.profiles.remove(profile) |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
146 |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
147 def clear_profile(self): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
148 self.profiles.clear() |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
149 |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
150 def connected(self, profile): |
52 | 151 """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
|
152 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
|
153 return |
70 | 154 debug(_("Connected")) |
52 | 155 self.setStatusOnline(True) |
91 | 156 self.bridge.joinMUC('conference.necton2.int', 'test', self.profiles[self.profile]['whoami'].node, self.profile) #gof: |
157 | |
52 | 158 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
159 def disconnected(self, profile): |
52 | 160 """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
|
161 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
|
162 return |
70 | 163 debug(_("Disconnected")) |
52 | 164 self.CM.clear() |
165 self.contactList.clear_contacts() | |
166 self.setStatusOnline(False) | |
167 | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
168 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
|
169 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
|
170 return |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
171 entity=JID(JabberId) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
172 self.rosterList[entity.short]=(dict(attributes), list(groups)) |
0 | 173 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
174 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
|
175 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
|
176 return |
0 | 177 sender=JID(from_jid) |
178 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
|
179 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
|
180 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
|
181 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
|
182 self.chat_wins[win.short].printMessage(sender, msg, profile) |
0 | 183 |
184 def setStatusOnline(self, online=True): | |
185 pass | |
186 | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
187 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
|
188 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
|
189 return |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
190 print "check ok" |
72 | 191 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
|
192 from_jid=JID(jabber_id) |
70 | 193 debug ("from_jid.short=%(from_jid)s whoami.short=%(whoami)s" % {'from_jid':from_jid.short, 'whoami':self.profiles[profile]['whoami'].short}) |
0 | 194 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
195 if from_jid.short==self.profiles[profile]['whoami'].short: |
0 | 196 if not type: |
197 self.setStatusOnline(True) | |
198 elif type=="unavailable": | |
199 self.setStatusOnline(False) | |
200 return | |
201 | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
202 if show != 'unavailable': |
0 | 203 name="" |
53
6dfe5bb10008
Wix: groups in contact list, first draft
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
204 groups = [] |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
205 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
|
206 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
|
207 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
|
208 groups=self.rosterList[from_jid.short][1] |
0 | 209 |
210 #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
|
211 if from_jid.short in self.profiles[profile]['watched'] and not from_jid.short in self.profiles[profile]['onlineContact']: |
70 | 212 self.showAlert(_("Watched jid [%s] is connected !") % from_jid.short) |
0 | 213 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
214 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
|
215 self.CM.add(from_jid) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
216 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
|
217 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
|
218 self.CM.update(from_jid, 'statuses', statuses) |
53
6dfe5bb10008
Wix: groups in contact list, first draft
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
219 self.CM.update(from_jid, 'groups', groups) |
64 | 220 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
|
221 if cache.has_key('nick'): |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
222 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
|
223 if cache.has_key('avatar'): |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
224 self.CM.update(from_jid, 'avatar', self.bridge.getAvatarFile(cache['avatar'])) |
72 | 225 self.contactList.replace(from_jid, self.CM.getAttr(from_jid, 'groups')) |
0 | 226 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
227 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
|
228 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
|
229 self.CM.remove(from_jid) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
230 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
|
231 self.contactList.disconnect(from_jid) |
72 | 232 |
233 def roomJoined(self, room_id, room_service, room_nicks, user_nick, profile): | |
234 """Called when a MUC room is joined""" | |
75 | 235 if not self.__check_profile(profile): |
236 return | |
237 debug (_("Room [%(room_name)s] joined by %(profile)s, users presents:%(users)s") % {'room_name':room_id+'@'+room_service, 'profile': profile, 'users':room_nicks}) | |
238 room_jid=room_id+'@'+room_service | |
79 | 239 self.chat_wins[room_jid].setUserNick(user_nick) |
75 | 240 self.chat_wins[room_jid].setType("group") |
85 | 241 self.chat_wins[room_jid].id = room_jid |
75 | 242 self.chat_wins[room_jid].setPresents([user_nick]+room_nicks) |
72 | 243 |
244 | |
75 | 245 def roomUserJoined(self, room_id, room_service, user_nick, user_data, profile): |
246 """Called when an user joined a MUC room""" | |
247 if not self.__check_profile(profile): | |
248 return | |
249 room_jid=room_id+'@'+room_service | |
250 if self.chat_wins.has_key(room_jid): | |
251 self.chat_wins[room_jid].replaceUser(user_nick) | |
76 | 252 debug (_("user [%(user_nick)s] joined room [%(room_jid)s]") % {'user_nick':user_nick, 'room_jid':room_jid}) |
75 | 253 |
254 def roomUserLeft(self, room_id, room_service, user_nick, user_data, profile): | |
255 """Called when an user joined a MUC room""" | |
256 if not self.__check_profile(profile): | |
257 return | |
258 room_jid=room_id+'@'+room_service | |
259 if self.chat_wins.has_key(room_jid): | |
260 self.chat_wins[room_jid].removeUser(user_nick) | |
76 | 261 debug (_("user [%(user_nick)s] left room [%(room_jid)s]") % {'user_nick':user_nick, 'room_jid':room_jid}) |
262 | |
263 def roomNewSubject(self, room_id, room_service, subject, profile): | |
264 """Called when subject of MUC room change""" | |
265 if not self.__check_profile(profile): | |
266 return | |
267 room_jid=room_id+'@'+room_service | |
268 if self.chat_wins.has_key(room_jid): | |
269 self.chat_wins[room_jid].setSubject(subject) | |
270 debug (_("new subject for room [%(room_jid)s]: %(subject)s") % {'room_jid':room_jid, "subject":subject}) | |
85 | 271 |
90 | 272 def tarotGameStarted(self, room_jid, referee, players, profile): |
85 | 273 if not self.__check_profile(profile): |
274 return | |
87 | 275 debug (_("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
|
276 if self.chat_wins.has_key(room_jid): |
90 | 277 self.chat_wins[room_jid].startGame("Tarot", referee, players) |
278 debug (_("new Tarot game started by [%(referee)s] in room [%(room_jid)s] with %(players)s") % {'referee':referee, 'room_jid':room_jid, 'players':[str(player) for player in players]}) | |
87 | 279 |
280 def tarotGameNew(self, room_jid, hand, profile): | |
281 if not self.__check_profile(profile): | |
282 return | |
283 debug (_("New Tarot Game")) | |
90 | 284 print "room: %s, hand: %s" % (room_jid,hand) |
87 | 285 if self.chat_wins.has_key(room_jid): |
286 self.chat_wins[room_jid].getGame("Tarot").newGame(hand) | |
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
|
287 |
91 | 288 def tarotChooseContrat(self, room_jid, xml_data, profile): |
289 """Called when the player has too select his contrat""" | |
290 if not self.__check_profile(profile): | |
291 return | |
292 debug (_("Tarot: need to select a contrat")) | |
293 if self.chat_wins.has_key(room_jid): | |
294 self.chat_wins[room_jid].getGame("Tarot").chooseContrat(xml_data) | |
295 | |
92 | 296 def tarotShowCards(self, room_jid, game_stage, cards, data, profile): |
297 if not self.__check_profile(profile): | |
298 return | |
299 debug (_("Show cards")) | |
300 if self.chat_wins.has_key(room_jid): | |
301 self.chat_wins[room_jid].getGame("Tarot").showCards(game_stage, cards, data) | |
87 | 302 |
92 | 303 def tarotMyTurn(self, room_jid, profile): |
304 if not self.__check_profile(profile): | |
305 return | |
306 debug (_("My turn to play")) | |
307 if self.chat_wins.has_key(room_jid): | |
308 self.chat_wins[room_jid].getGame("Tarot").MyTurn() | |
0 | 309 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
310 def subscribe(self, type, raw_jid, profile): |
87 | 311 """Called when a subsciption management signal is received""" |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
312 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
|
313 return |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
314 entity = JID(raw_jid) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
315 if type=="subscribed": |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
316 # this is a subscription confirmation, we just have to inform user |
70 | 317 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
|
318 elif type=="unsubscribed": |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
319 # this is a subscription refusal, we just have to inform user |
70 | 320 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
|
321 elif type=="subscribe": |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
322 # this is a subscriptionn request, we have to ask for user confirmation |
70 | 323 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
|
324 if answer: |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
87
diff
changeset
|
325 self.bridge.subscription("subscribed", entity.short, profile_key = profile) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
326 else: |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
87
diff
changeset
|
327 self.bridge.subscription("unsubscribed", entity.short, profile_key = profile) |
0 | 328 |
329 def showDialog(self, message, title, type="info"): | |
330 raise NotImplementedError | |
331 | |
332 def showAlert(self, message): | |
333 pass #FIXME | |
334 | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
335 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
|
336 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
|
337 return |
70 | 338 debug(_("param update: [%(namespace)s] %(name)s = %(value)s") % {'namespace':namespace, 'name':name, 'value':value}) |
0 | 339 if (namespace,name) == ("Connection", "JabberID"): |
70 | 340 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
|
341 self.profiles[profile]['whoami']=JID(value) |
0 | 342 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
|
343 self.profiles[profile]['watched']=value.split() |
0 | 344 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
345 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
|
346 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
|
347 return |
0 | 348 target = JID(jid) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
349 self.CM.remove(target) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
350 self.contactList.remove(self.CM.get_full(target)) |
0 | 351 try: |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
352 self.profiles[profile]['onlineContact'].remove(target.short) |
0 | 353 except KeyError: |
354 pass | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
355 |
71
efe81b61673c
quick app: updatedValue wrong parameter fix
Goffi <goffi@goffi.org>
parents:
70
diff
changeset
|
356 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
|
357 if name == "card_nick": |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
358 target = JID(data['jid']) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
359 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
|
360 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
|
361 elif name == "card_avatar": |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
362 target = JID(data['jid']) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
363 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
|
364 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
|
365 self.contactList.replace(target) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
366 |
0 | 367 def askConfirmation(self, type, id, data): |
368 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
|
369 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
370 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
|
371 raise NotImplementedError |