Mercurial > libervia-backend
annotate frontends/src/quick_frontend/quick_app.py @ 361:141eeb7cd9e6
Quizz game: first draft
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 12 Jun 2011 16:28:33 +0200 |
parents | ea3e1b82dd79 |
children | 208107419b17 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 helper class for making a SAT frontend | |
228 | 6 Copyright (C) 2009, 2010, 2011 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 | |
225
fd9b7834d98a
distutils installation script, draft
Goffi <goffi@goffi.org>
parents:
223
diff
changeset
|
23 from sat.tools.jid import JID |
fd9b7834d98a
distutils installation script, draft
Goffi <goffi@goffi.org>
parents:
223
diff
changeset
|
24 from sat_frontends.bridge.DBus import DBusBridgeFrontend,BridgeExceptionNoService |
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 ## | |
165
8a2053de6f8c
Frontends: management of unlaunched SàT Backend (information message and exit)
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
41 try: |
8a2053de6f8c
Frontends: management of unlaunched SàT Backend (information message and exit)
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
42 self.bridge=DBusBridgeFrontend() |
8a2053de6f8c
Frontends: management of unlaunched SàT Backend (information message and exit)
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
43 except BridgeExceptionNoService: |
8a2053de6f8c
Frontends: management of unlaunched SàT Backend (information message and exit)
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
44 print(_(u"Can't connect to SàT backend, are you sure it's launched ?")) |
8a2053de6f8c
Frontends: management of unlaunched SàT Backend (information message and exit)
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
45 import sys |
8a2053de6f8c
Frontends: management of unlaunched SàT Backend (information message and exit)
Goffi <goffi@goffi.org>
parents:
159
diff
changeset
|
46 sys.exit(1) |
52 | 47 self.bridge.register("connected", self.connected) |
48 self.bridge.register("disconnected", self.disconnected) | |
274
c1ad04586edf
Bridge: rename connection_error to connectionError for function name consistency
Goffi <goffi@goffi.org>
parents:
272
diff
changeset
|
49 self.bridge.register("connectionError", self.connectionError) |
0 | 50 self.bridge.register("newContact", self.newContact) |
51 self.bridge.register("newMessage", self.newMessage) | |
182
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
52 self.bridge.register("newAlert", self.newAlert) |
0 | 53 self.bridge.register("presenceUpdate", self.presenceUpdate) |
72 | 54 self.bridge.register("roomJoined", self.roomJoined) |
75 | 55 self.bridge.register("roomUserJoined", self.roomUserJoined) |
56 self.bridge.register("roomUserLeft", self.roomUserLeft) | |
76 | 57 self.bridge.register("roomNewSubject", self.roomNewSubject) |
85 | 58 self.bridge.register("tarotGameStarted", self.tarotGameStarted) |
87 | 59 self.bridge.register("tarotGameNew", self.tarotGameNew) |
92 | 60 self.bridge.register("tarotGameChooseContrat", self.tarotChooseContrat) |
61 self.bridge.register("tarotGameShowCards", self.tarotShowCards) | |
62 self.bridge.register("tarotGameYourTurn", self.tarotMyTurn) | |
95 | 63 self.bridge.register("tarotGameScore", self.tarotScore) |
93 | 64 self.bridge.register("tarotGameCardsPlayed", self.tarotCardsPlayed) |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
65 self.bridge.register("tarotGameInvalidCards", self.tarotInvalidCards) |
361 | 66 self.bridge.register("quizGameStarted", self.quizGameStarted) |
67 self.bridge.register("quizGameNew", self.quizGameNew) | |
68 self.bridge.register("quizGameQuestion", self.quizGameQuestion) | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
69 self.bridge.register("subscribe", self.subscribe) |
0 | 70 self.bridge.register("paramUpdate", self.paramUpdate) |
71 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
|
72 self.bridge.register("updatedValue", self.updatedValue, "request") |
0 | 73 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
|
74 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
|
75 self.bridge.register("actionResultExt", self.actionResult, "request") |
0 | 76 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
77 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
|
78 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
|
79 |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
80 def check_profile(self, profile): |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
81 """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
|
82 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
|
83 |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
117
diff
changeset
|
84 def postInit(self): |
159
2fa58703f1b7
Primitivus: notification bar, first draft
Goffi <goffi@goffi.org>
parents:
150
diff
changeset
|
85 """Must be called after initialization is done, do all automatic task (auto plug profile)""" |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
117
diff
changeset
|
86 if self.options.profile: |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
117
diff
changeset
|
87 if not self.bridge.getProfileName(self.options.profile): |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
117
diff
changeset
|
88 error(_("Trying to plug an unknown profile (%s)" % self.options.profile)) |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
117
diff
changeset
|
89 else: |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
117
diff
changeset
|
90 self.plug_profile(self.options.profile) |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
117
diff
changeset
|
91 |
91 | 92 def check_options(self): |
93 """Check command line options""" | |
94 usage=_(""" | |
95 %prog [options] | |
96 | |
97 %prog --help for options list | |
98 """) | |
99 parser = OptionParser(usage=usage) | |
100 | |
101 parser.add_option("-p", "--profile", help=_("Select the profile to use")) | |
102 | |
103 (self.options, args) = parser.parse_args() | |
132
a86607e5cf38
quick_app: self.occupants for group chat are now managed by quick_chat. self.options.profile now support unicode
Goffi <goffi@goffi.org>
parents:
125
diff
changeset
|
104 if self.options.profile: |
a86607e5cf38
quick_app: self.occupants for group chat are now managed by quick_chat. self.options.profile now support unicode
Goffi <goffi@goffi.org>
parents:
125
diff
changeset
|
105 self.options.profile = self.options.profile.decode('utf-8') |
91 | 106 return args |
107 | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
108 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
|
109 """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
|
110 if self.single_profile and self.profiles: |
70 | 111 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
|
112 return |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
113 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
|
114 if not profile: |
70 | 115 error(_("The profile asked doesn't exist")) |
68 | 116 return |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
117 if self.profiles.has_key(profile): |
70 | 118 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
|
119 return |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
120 self.profiles[profile]={} |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
121 if self.single_profile: |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
122 self.profile = profile |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
123 |
0 | 124 ###now we get the essential params### |
272
1d2e0dfe7114
bridge: core & frontend sides of bridge are now generated
Goffi <goffi@goffi.org>
parents:
266
diff
changeset
|
125 self.profiles[profile]['whoami']=JID(self.bridge.getParamA("JabberID","Connection", profile_key=profile)) |
1d2e0dfe7114
bridge: core & frontend sides of bridge are now generated
Goffi <goffi@goffi.org>
parents:
266
diff
changeset
|
126 autoconnect = self.bridge.getParamA("autoconnect","Connection", profile_key=profile) == "true" |
1d2e0dfe7114
bridge: core & frontend sides of bridge are now generated
Goffi <goffi@goffi.org>
parents:
266
diff
changeset
|
127 self.profiles[profile]['watched']=self.bridge.getParamA("Watched", "Misc", profile_key=profile).split() #TODO: put this in a plugin |
0 | 128 |
129 ## misc ## | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
130 self.profiles[profile]['onlineContact'] = set() #FIXME: temporary |
0 | 131 |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
132 #TODO: gof: manage multi-profiles here |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
133 if not self.bridge.isConnected(profile): |
52 | 134 self.setStatusOnline(False) |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
135 else: |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
136 self.setStatusOnline(True) |
0 | 137 |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
138 ### now we fill the contact list ### |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
139 for contact in self.bridge.getContacts(profile): |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
140 self.newContact(contact[0], contact[1], contact[2], profile) |
0 | 141 |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
142 presences = self.bridge.getPresenceStatus(profile) |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
143 for contact in presences: |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
144 for res in presences[contact]: |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
145 jabber_id = contact+('/'+res if res else '') |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
146 show = presences[contact][res][0] |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
147 priority = presences[contact][res][1] |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
148 statuses = presences[contact][res][2] |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
149 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
|
150 |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
151 #The waiting subscription requests |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
152 waitingSub = self.bridge.getWaitingSub(profile) |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
153 for sub in waitingSub: |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
154 self.subscribe(waitingSub[sub], sub, profile) |
0 | 155 |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
156 #Now we open the MUC window where we already are: |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
157 for room_args in self.bridge.getRoomJoined(profile): |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
158 self.roomJoined(*room_args, profile=profile) |
78
ace2af8abc5a
Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents:
76
diff
changeset
|
159 |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
160 for subject_args in self.bridge.getRoomSubjects(profile): |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
161 self.roomNewSubject(*subject_args, profile=profile) |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
162 |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
163 if autoconnect and not self.bridge.isConnected(profile_key): |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
164 #Does the user want autoconnection ? |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
165 self.bridge.connect(profile_key) |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
166 |
78
ace2af8abc5a
Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents:
76
diff
changeset
|
167 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
168 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
|
169 """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
|
170 if not profile in self.profiles: |
70 | 171 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
|
172 return |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
173 self.profiles.remove(profile) |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
174 |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
175 def clear_profile(self): |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
176 self.profiles.clear() |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
177 |
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
178 def connected(self, profile): |
52 | 179 """called when the connection is made""" |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
180 if not self.check_profile(profile): |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
181 return |
70 | 182 debug(_("Connected")) |
52 | 183 self.setStatusOnline(True) |
184 | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
185 def disconnected(self, profile): |
52 | 186 """called when the connection is closed""" |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
187 if not self.check_profile(profile): |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
188 return |
70 | 189 debug(_("Disconnected")) |
52 | 190 self.CM.clear() |
191 self.contactList.clear_contacts() | |
192 self.setStatusOnline(False) | |
193 | |
274
c1ad04586edf
Bridge: rename connection_error to connectionError for function name consistency
Goffi <goffi@goffi.org>
parents:
272
diff
changeset
|
194 def connectionError(self, error_type, profile): |
262
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
195 """called when something goest wrong with the connection""" |
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
196 if not self.check_profile(profile): |
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
197 return |
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
198 debug(_("Connection Error")) |
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
199 self.disconnected(profile) |
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
200 if error_type == "AUTH_ERROR": |
263
bfd01aed0a3a
added "please" in password error message
Goffi <goffi@goffi.org>
parents:
262
diff
changeset
|
201 self.showDialog(_("Can't connect to account, please check your password"), _("Connection error"), "error") |
262
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
202 else: |
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
203 error(_('FIXME: error_type %s not implemented') % error_type) |
af3d4f11fe43
Added management of connection error
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
204 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
205 def newContact(self, JabberId, attributes, groups, profile): |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
206 if not self.check_profile(profile): |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
207 return |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
208 entity=JID(JabberId) |
347
ea3e1b82dd79
core: contact deletion from roster if we have no subscription to it (behaviour may change in futur)
Goffi <goffi@goffi.org>
parents:
344
diff
changeset
|
209 _groups = list(groups) |
ea3e1b82dd79
core: contact deletion from roster if we have no subscription to it (behaviour may change in futur)
Goffi <goffi@goffi.org>
parents:
344
diff
changeset
|
210 self.rosterList[entity.short]=(dict(attributes), _groups) |
ea3e1b82dd79
core: contact deletion from roster if we have no subscription to it (behaviour may change in futur)
Goffi <goffi@goffi.org>
parents:
344
diff
changeset
|
211 if entity in self.CM: |
ea3e1b82dd79
core: contact deletion from roster if we have no subscription to it (behaviour may change in futur)
Goffi <goffi@goffi.org>
parents:
344
diff
changeset
|
212 self.CM.update(entity, 'groups', _groups) |
ea3e1b82dd79
core: contact deletion from roster if we have no subscription to it (behaviour may change in futur)
Goffi <goffi@goffi.org>
parents:
344
diff
changeset
|
213 self.contactList.replace(entity, self.CM.getAttr(entity, 'groups')) |
0 | 214 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
215 def newMessage(self, from_jid, msg, type, to_jid, profile): |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
216 if not self.check_profile(profile): |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
217 return |
0 | 218 sender=JID(from_jid) |
219 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
|
220 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
|
221 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
|
222 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
|
223 self.chat_wins[win.short].printMessage(sender, msg, profile) |
0 | 224 |
221
96186f36d8cb
bridge: fixed newAlert parameters order
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
225 def newAlert(self, msg, title, alert_type, profile): |
182
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
226 if not self.check_profile(profile): |
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
227 return |
221
96186f36d8cb
bridge: fixed newAlert parameters order
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
228 assert alert_type in ['INFO','ERROR'] |
96186f36d8cb
bridge: fixed newAlert parameters order
Goffi <goffi@goffi.org>
parents:
200
diff
changeset
|
229 self.showDialog(unicode(msg),unicode(title),alert_type.lower()) |
182
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
230 |
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
231 |
0 | 232 def setStatusOnline(self, online=True): |
233 pass | |
234 | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
235 def presenceUpdate(self, jabber_id, show, priority, statuses, profile): |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
236 if not self.check_profile(profile): |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
237 return |
72 | 238 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
|
239 from_jid=JID(jabber_id) |
70 | 240 debug ("from_jid.short=%(from_jid)s whoami.short=%(whoami)s" % {'from_jid':from_jid.short, 'whoami':self.profiles[profile]['whoami'].short}) |
0 | 241 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
242 if from_jid.short==self.profiles[profile]['whoami'].short: |
0 | 243 if not type: |
244 self.setStatusOnline(True) | |
245 elif type=="unavailable": | |
246 self.setStatusOnline(False) | |
247 return | |
248 | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
249 if show != 'unavailable': |
0 | 250 name="" |
53
6dfe5bb10008
Wix: groups in contact list, first draft
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
251 groups = [] |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
252 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
|
253 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
|
254 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
|
255 groups=self.rosterList[from_jid.short][1] |
0 | 256 |
257 #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
|
258 if from_jid.short in self.profiles[profile]['watched'] and not from_jid.short in self.profiles[profile]['onlineContact']: |
70 | 259 self.showAlert(_("Watched jid [%s] is connected !") % from_jid.short) |
0 | 260 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
261 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
|
262 self.CM.add(from_jid) |
244
3bc4457687a2
quick_frontend: fixed bad string type with DBus by converting them to unicode
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
263 self.CM.update(from_jid, 'name', unicode(name)) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
264 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
|
265 self.CM.update(from_jid, 'statuses', statuses) |
53
6dfe5bb10008
Wix: groups in contact list, first draft
Goffi <goffi@goffi.org>
parents:
52
diff
changeset
|
266 self.CM.update(from_jid, 'groups', groups) |
64 | 267 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
|
268 if cache.has_key('nick'): |
244
3bc4457687a2
quick_frontend: fixed bad string type with DBus by converting them to unicode
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
269 self.CM.update(from_jid, 'nick', unicode(cache['nick'])) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
270 if cache.has_key('avatar'): |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
271 self.CM.update(from_jid, 'avatar', self.bridge.getAvatarFile(cache['avatar'])) |
72 | 272 self.contactList.replace(from_jid, self.CM.getAttr(from_jid, 'groups')) |
0 | 273 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
274 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
|
275 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
|
276 self.CM.remove(from_jid) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
277 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
|
278 self.contactList.disconnect(from_jid) |
72 | 279 |
280 def roomJoined(self, room_id, room_service, room_nicks, user_nick, profile): | |
281 """Called when a MUC room is joined""" | |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
282 if not self.check_profile(profile): |
75 | 283 return |
284 debug (_("Room [%(room_name)s] joined by %(profile)s, users presents:%(users)s") % {'room_name':room_id+'@'+room_service, 'profile': profile, 'users':room_nicks}) | |
285 room_jid=room_id+'@'+room_service | |
79 | 286 self.chat_wins[room_jid].setUserNick(user_nick) |
75 | 287 self.chat_wins[room_jid].setType("group") |
85 | 288 self.chat_wins[room_jid].id = room_jid |
124 | 289 self.chat_wins[room_jid].setPresents(list(set([user_nick]+room_nicks))) |
72 | 290 |
291 | |
75 | 292 def roomUserJoined(self, room_id, room_service, user_nick, user_data, profile): |
293 """Called when an user joined a MUC room""" | |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
294 if not self.check_profile(profile): |
75 | 295 return |
296 room_jid=room_id+'@'+room_service | |
297 if self.chat_wins.has_key(room_jid): | |
298 self.chat_wins[room_jid].replaceUser(user_nick) | |
76 | 299 debug (_("user [%(user_nick)s] joined room [%(room_jid)s]") % {'user_nick':user_nick, 'room_jid':room_jid}) |
75 | 300 |
301 def roomUserLeft(self, room_id, room_service, user_nick, user_data, profile): | |
302 """Called when an user joined a MUC room""" | |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
303 if not self.check_profile(profile): |
75 | 304 return |
305 room_jid=room_id+'@'+room_service | |
306 if self.chat_wins.has_key(room_jid): | |
307 self.chat_wins[room_jid].removeUser(user_nick) | |
76 | 308 debug (_("user [%(user_nick)s] left room [%(room_jid)s]") % {'user_nick':user_nick, 'room_jid':room_jid}) |
309 | |
310 def roomNewSubject(self, room_id, room_service, subject, profile): | |
311 """Called when subject of MUC room change""" | |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
312 if not self.check_profile(profile): |
76 | 313 return |
314 room_jid=room_id+'@'+room_service | |
315 if self.chat_wins.has_key(room_jid): | |
316 self.chat_wins[room_jid].setSubject(subject) | |
317 debug (_("new subject for room [%(room_jid)s]: %(subject)s") % {'room_jid':room_jid, "subject":subject}) | |
85 | 318 |
90 | 319 def tarotGameStarted(self, room_jid, referee, players, profile): |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
320 if not self.check_profile(profile): |
85 | 321 return |
87 | 322 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
|
323 if self.chat_wins.has_key(room_jid): |
90 | 324 self.chat_wins[room_jid].startGame("Tarot", referee, players) |
325 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 | 326 |
327 def tarotGameNew(self, room_jid, hand, profile): | |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
328 if not self.check_profile(profile): |
87 | 329 return |
330 debug (_("New Tarot Game")) | |
331 if self.chat_wins.has_key(room_jid): | |
332 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
|
333 |
91 | 334 def tarotChooseContrat(self, room_jid, xml_data, profile): |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
132
diff
changeset
|
335 """Called when the player has to select his contrat""" |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
336 if not self.check_profile(profile): |
91 | 337 return |
338 debug (_("Tarot: need to select a contrat")) | |
339 if self.chat_wins.has_key(room_jid): | |
340 self.chat_wins[room_jid].getGame("Tarot").chooseContrat(xml_data) | |
341 | |
92 | 342 def tarotShowCards(self, room_jid, game_stage, cards, data, profile): |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
343 if not self.check_profile(profile): |
92 | 344 return |
345 debug (_("Show cards")) | |
346 if self.chat_wins.has_key(room_jid): | |
347 self.chat_wins[room_jid].getGame("Tarot").showCards(game_stage, cards, data) | |
87 | 348 |
92 | 349 def tarotMyTurn(self, room_jid, profile): |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
350 if not self.check_profile(profile): |
92 | 351 return |
352 debug (_("My turn to play")) | |
353 if self.chat_wins.has_key(room_jid): | |
150 | 354 self.chat_wins[room_jid].getGame("Tarot").myTurn() |
93 | 355 |
95 | 356 def tarotScore(self, room_jid, xml_data, winners, loosers, profile): |
357 """Called when the game is finished and the score are updated""" | |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
358 if not self.check_profile(profile): |
95 | 359 return |
360 debug (_("Tarot: score received")) | |
361 if self.chat_wins.has_key(room_jid): | |
362 self.chat_wins[room_jid].getGame("Tarot").showScores(xml_data, winners, loosers) | |
363 | |
93 | 364 def tarotCardsPlayed(self, room_jid, player, cards, profile): |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
365 if not self.check_profile(profile): |
93 | 366 return |
367 debug (_("Card(s) played (%(player)s): %(cards)s") % {"player":player, "cards":cards}) | |
368 if self.chat_wins.has_key(room_jid): | |
369 self.chat_wins[room_jid].getGame("Tarot").cardsPlayed(player, cards) | |
370 | |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
371 def tarotInvalidCards(self, room_jid, phase, played_cards, invalid_cards, profile): |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
372 if not self.check_profile(profile): |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
373 return |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
374 debug (_("Cards played are not valid: %s") % invalid_cards) |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
375 if self.chat_wins.has_key(room_jid): |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
95
diff
changeset
|
376 self.chat_wins[room_jid].getGame("Tarot").invalidCards(phase, played_cards, invalid_cards) |
182
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
377 |
361 | 378 def quizGameStarted(self, room_jid, referee, players, profile): |
379 if not self.check_profile(profile): | |
380 print "gof: NOT CHECK PROFILE", profile | |
381 return | |
382 debug (_("Quiz Game Started \o/")) | |
383 if self.chat_wins.has_key(room_jid): | |
384 self.chat_wins[room_jid].startGame("Quiz", referee, players) | |
385 debug (_("new Quiz 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]}) | |
386 | |
387 def quizGameNew(self, room_jid, data, profile): | |
388 if not self.check_profile(profile): | |
389 return | |
390 debug (_("New Quiz Game")) | |
391 if self.chat_wins.has_key(room_jid): | |
392 self.chat_wins[room_jid].getGame("Quiz").quizGameNew(data) | |
393 | |
394 def quizGameQuestion(self, room_jid, question_id, question, timer, profile): | |
395 """Called when a new question is asked""" | |
396 if not self.check_profile(profile): | |
397 return | |
398 debug (_(u"Quiz: new question: %s") % question) | |
399 if self.chat_wins.has_key(room_jid): | |
400 self.chat_wins[room_jid].getGame("Quiz").quizGameQuestion(question_id, question, timer) | |
401 | |
182
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
402 def _subscribe_cb(self, answer, data): |
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
403 entity, profile = data |
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
404 if answer: |
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
405 self.bridge.subscription("subscribed", entity.short, profile_key = profile) |
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
406 else: |
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
407 self.bridge.subscription("unsubscribed", entity.short, profile_key = profile) |
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
408 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
409 def subscribe(self, type, raw_jid, profile): |
87 | 410 """Called when a subsciption management signal is received""" |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
411 if not self.check_profile(profile): |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
412 return |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
413 entity = JID(raw_jid) |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
414 if type=="subscribed": |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
415 # this is a subscription confirmation, we just have to inform user |
70 | 416 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
|
417 elif type=="unsubscribed": |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
418 # this is a subscription refusal, we just have to inform user |
70 | 419 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
|
420 elif type=="subscribe": |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
421 # this is a subscriptionn request, we have to ask for user confirmation |
182
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
422 answer = self.showDialog(_("The contact %s wants to subscribe to your presence.\nDo you accept ?") % entity.short, _('Subscription confirmation'), 'yes/no', answer_cb = self._subscribe_cb, answer_data=(entity, profile)) |
0 | 423 |
182
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
165
diff
changeset
|
424 def showDialog(self, message, title, type="info", answer_cb = None): |
0 | 425 raise NotImplementedError |
426 | |
427 def showAlert(self, message): | |
428 pass #FIXME | |
429 | |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
430 def paramUpdate(self, name, value, namespace, profile): |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
431 if not self.check_profile(profile): |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
432 return |
70 | 433 debug(_("param update: [%(namespace)s] %(name)s = %(value)s") % {'namespace':namespace, 'name':name, 'value':value}) |
0 | 434 if (namespace,name) == ("Connection", "JabberID"): |
70 | 435 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
|
436 self.profiles[profile]['whoami']=JID(value) |
0 | 437 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
|
438 self.profiles[profile]['watched']=value.split() |
0 | 439 |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
440 def contactDeleted(self, jid, profile): |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
441 if not self.check_profile(profile): |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
442 return |
0 | 443 target = JID(jid) |
344
f19771d2e63b
quickapp: fixed contact removing bug
Goffi <goffi@goffi.org>
parents:
274
diff
changeset
|
444 self.contactList.remove(self.CM.get_full(target)) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
445 self.CM.remove(target) |
0 | 446 try: |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
447 self.profiles[profile]['onlineContact'].remove(target.short) |
0 | 448 except KeyError: |
449 pass | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
450 |
71
efe81b61673c
quick app: updatedValue wrong parameter fix
Goffi <goffi@goffi.org>
parents:
70
diff
changeset
|
451 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
|
452 if name == "card_nick": |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
453 target = JID(data['jid']) |
124 | 454 if target in self.contactList: |
244
3bc4457687a2
quick_frontend: fixed bad string type with DBus by converting them to unicode
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
455 self.CM.update(target, 'nick', unicode(data['nick'])) |
124 | 456 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
|
457 elif name == "card_avatar": |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
458 target = JID(data['jid']) |
124 | 459 if target in self.contactList: |
460 filename = self.bridge.getAvatarFile(data['avatar']) | |
461 self.CM.update(target, 'avatar', filename) | |
462 self.contactList.replace(target) | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
463 |
0 | 464 def askConfirmation(self, type, id, data): |
465 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
|
466 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
467 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
|
468 raise NotImplementedError |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
469 |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
470 def onExit(self): |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
471 """Must be called when the frontend is terminating""" |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
472 #TODO: mange multi-profile here |
200
7baee9bb37af
quick_frontend: fixed disconnect, and removed autojoin of muc room put for dev
Goffi <goffi@goffi.org>
parents:
183
diff
changeset
|
473 try: |
272
1d2e0dfe7114
bridge: core & frontend sides of bridge are now generated
Goffi <goffi@goffi.org>
parents:
266
diff
changeset
|
474 autodisconnect = self.bridge.getParamA("autodisconnect","Connection", profile_key=self.profile) == "true" |
200
7baee9bb37af
quick_frontend: fixed disconnect, and removed autojoin of muc room put for dev
Goffi <goffi@goffi.org>
parents:
183
diff
changeset
|
475 if autodisconnect and self.bridge.isConnected(self.profile): |
7baee9bb37af
quick_frontend: fixed disconnect, and removed autojoin of muc room put for dev
Goffi <goffi@goffi.org>
parents:
183
diff
changeset
|
476 #Does the user want autodisconnection ? |
7baee9bb37af
quick_frontend: fixed disconnect, and removed autojoin of muc room put for dev
Goffi <goffi@goffi.org>
parents:
183
diff
changeset
|
477 self.bridge.disconnect(self.profile) |
7baee9bb37af
quick_frontend: fixed disconnect, and removed autojoin of muc room put for dev
Goffi <goffi@goffi.org>
parents:
183
diff
changeset
|
478 except: |
7baee9bb37af
quick_frontend: fixed disconnect, and removed autojoin of muc room put for dev
Goffi <goffi@goffi.org>
parents:
183
diff
changeset
|
479 pass |