annotate frontends/quick_frontend/quick_app.py @ 124:961e0898271f

primitivus chat window - management of one 2 one / group chat - timestamp displayed - added shortcuts for showing/hiding panels - color used - fixed vcard bug (contact displayed even if not from current profile if vcard changed/not in cache) - added VerticalSeparator widget - *List widgets can now use an other widget than SelectableText - new UnselectableText widget
author Goffi <goffi@goffi.org>
date Thu, 08 Jul 2010 19:47:54 +0800
parents ded2431cea5a
children 8d611eb9ae48
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
goffi@necton2
parents:
diff changeset
1 #!/usr/bin/python
goffi@necton2
parents:
diff changeset
2 # -*- coding: utf-8 -*-
goffi@necton2
parents:
diff changeset
3
goffi@necton2
parents:
diff changeset
4 """
goffi@necton2
parents:
diff changeset
5 helper class for making a SAT frontend
57
a5b5fb5fc9fd updated README and copyright note
Goffi <goffi@goffi.org>
parents: 53
diff changeset
6 Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org)
0
goffi@necton2
parents:
diff changeset
7
goffi@necton2
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
goffi@necton2
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
goffi@necton2
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
goffi@necton2
parents:
diff changeset
11 (at your option) any later version.
goffi@necton2
parents:
diff changeset
12
goffi@necton2
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
goffi@necton2
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
goffi@necton2
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
goffi@necton2
parents:
diff changeset
16 GNU General Public License for more details.
goffi@necton2
parents:
diff changeset
17
goffi@necton2
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
goffi@necton2
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
goffi@necton2
parents:
diff changeset
20 """
goffi@necton2
parents:
diff changeset
21
goffi@necton2
parents:
diff changeset
22 from logging import debug, info, error
goffi@necton2
parents:
diff changeset
23 from tools.jid import JID
goffi@necton2
parents:
diff changeset
24 from sat_bridge_frontend.DBus import DBusBridgeFrontend
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
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
goffi@necton2
parents:
diff changeset
27
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
28 import gettext
Goffi <goffi@goffi.org>
parents: 68
diff changeset
29 gettext.install('sat_frontend', "../i18n", unicode=True)
Goffi <goffi@goffi.org>
parents: 68
diff changeset
30
0
goffi@necton2
parents:
diff changeset
31 class QuickApp():
goffi@necton2
parents:
diff changeset
32 """This class contain the main methods needed for the frontend"""
goffi@necton2
parents:
diff changeset
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
goffi@necton2
parents:
diff changeset
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
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
38 self.check_options()
0
goffi@necton2
parents:
diff changeset
39
goffi@necton2
parents:
diff changeset
40 ## bridge ##
goffi@necton2
parents:
diff changeset
41 self.bridge=DBusBridgeFrontend()
52
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
42 self.bridge.register("connected", self.connected)
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
43 self.bridge.register("disconnected", self.disconnected)
0
goffi@necton2
parents:
diff changeset
44 self.bridge.register("newContact", self.newContact)
goffi@necton2
parents:
diff changeset
45 self.bridge.register("newMessage", self.newMessage)
goffi@necton2
parents:
diff changeset
46 self.bridge.register("presenceUpdate", self.presenceUpdate)
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 71
diff changeset
47 self.bridge.register("roomJoined", self.roomJoined)
75
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
48 self.bridge.register("roomUserJoined", self.roomUserJoined)
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
49 self.bridge.register("roomUserLeft", self.roomUserLeft)
76
8becde8a967c MUC: added subject management
Goffi <goffi@goffi.org>
parents: 75
diff changeset
50 self.bridge.register("roomNewSubject", self.roomNewSubject)
85
fc7583282d40 Tarot Game plugin: first draft
Goffi <goffi@goffi.org>
parents: 79
diff changeset
51 self.bridge.register("tarotGameStarted", self.tarotGameStarted)
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
52 self.bridge.register("tarotGameNew", self.tarotGameNew)
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
53 self.bridge.register("tarotGameChooseContrat", self.tarotChooseContrat)
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
54 self.bridge.register("tarotGameShowCards", self.tarotShowCards)
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
55 self.bridge.register("tarotGameYourTurn", self.tarotMyTurn)
95
be206a3d1a9b Tarot game: score calculation
Goffi <goffi@goffi.org>
parents: 93
diff changeset
56 self.bridge.register("tarotGameScore", self.tarotScore)
93
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
57 self.bridge.register("tarotGameCardsPlayed", self.tarotCardsPlayed)
99
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 95
diff changeset
58 self.bridge.register("tarotGameInvalidCards", self.tarotInvalidCards)
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
59 self.bridge.register("subscribe", self.subscribe)
0
goffi@necton2
parents:
diff changeset
60 self.bridge.register("paramUpdate", self.paramUpdate)
goffi@necton2
parents:
diff changeset
61 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
62 self.bridge.register("updatedValue", self.updatedValue, "request")
0
goffi@necton2
parents:
diff changeset
63 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
64 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
65 self.bridge.register("actionResultExt", self.actionResult, "request")
0
goffi@necton2
parents:
diff changeset
66
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
67 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
68 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
69
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
70 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
71 """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
72 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
73
119
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 117
diff changeset
74 def postInit(self):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 117
diff changeset
75 """Must be called after __init__, do all automatic task (auto plug profile)"""
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 117
diff changeset
76 if self.options.profile:
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 117
diff changeset
77 if not self.bridge.getProfileName(self.options.profile):
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 117
diff changeset
78 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
79 else:
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 117
diff changeset
80 self.plug_profile(self.options.profile)
ded2431cea5a Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents: 117
diff changeset
81
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
82 def check_options(self):
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
83 """Check command line options"""
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
84 usage=_("""
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
85 %prog [options]
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
86
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
87 %prog --help for options list
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
88 """)
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
89 parser = OptionParser(usage=usage)
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
90
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
91 parser.add_option("-p", "--profile", help=_("Select the profile to use"))
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
92
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
93 (self.options, args) = parser.parse_args()
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
94 return args
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
95
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
96 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
97 """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
98 if self.single_profile and self.profiles:
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
99 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
100 return
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
101 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
102 if not profile:
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
103 error(_("The profile asked doesn't exist"))
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents: 66
diff changeset
104 return
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
105 if self.profiles.has_key(profile):
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
106 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
107 return
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
108 self.profiles[profile]={}
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
109 if self.single_profile:
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
110 self.profile = profile
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
111
0
goffi@necton2
parents:
diff changeset
112 ###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
113 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
114 self.profiles[profile]['watched']=self.bridge.getParamA("Watched", "Misc", profile).split() #TODO: put this in a plugin
0
goffi@necton2
parents:
diff changeset
115
goffi@necton2
parents:
diff changeset
116 ## misc ##
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
117 self.profiles[profile]['onlineContact'] = set() #FIXME: temporary
0
goffi@necton2
parents:
diff changeset
118
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 71
diff changeset
119 #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
120 if self.bridge.isConnected(profile):
0
goffi@necton2
parents:
diff changeset
121 self.setStatusOnline(True)
52
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
122 else:
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
123 self.setStatusOnline(False)
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
124 return
0
goffi@necton2
parents:
diff changeset
125
goffi@necton2
parents:
diff changeset
126 ### 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
127 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
128 self.newContact(contact[0], contact[1], contact[2], profile)
0
goffi@necton2
parents:
diff changeset
129
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
130 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
131 for contact in presences:
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
132 for res in presences[contact]:
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
133 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
134 show = presences[contact][res][0]
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
135 priority = presences[contact][res][1]
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
136 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
137 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
138
78
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 76
diff changeset
139 #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
140 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
141 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
142 self.subscribe(waitingSub[sub], sub, profile)
0
goffi@necton2
parents:
diff changeset
143
78
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 76
diff changeset
144 #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
145 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
146 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
147
ace2af8abc5a Added method to know which MUC are joined, and which subjects were received.
Goffi <goffi@goffi.org>
parents: 76
diff changeset
148 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
149 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
150
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
151 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
152 """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
153 if not profile in self.profiles:
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
154 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
155 return
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
156 self.profiles.remove(profile)
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
157
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
158 def clear_profile(self):
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
159 self.profiles.clear()
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
160
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
161 def connected(self, profile):
52
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
162 """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
163 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
164 return
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
165 debug(_("Connected"))
52
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
166 self.setStatusOnline(True)
102
94011f553cd0 misc bugfixes
Goffi <goffi@goffi.org>
parents: 99
diff changeset
167 #self.bridge.joinMUC('conference.necton2.int', 'test', self.profiles[self.profile]['whoami'].node, self.profile) #gof:
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
168
52
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
169
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
170 def disconnected(self, profile):
52
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
171 """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
172 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
173 return
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
174 debug(_("Disconnected"))
52
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
175 self.CM.clear()
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
176 self.contactList.clear_contacts()
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
177 self.setStatusOnline(False)
6455fb62ff83 Connection/disconnection signals
Goffi <goffi@goffi.org>
parents: 51
diff changeset
178
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
179 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
180 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
181 return
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
182 entity=JID(JabberId)
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
183 self.rosterList[entity.short]=(dict(attributes), list(groups))
0
goffi@necton2
parents:
diff changeset
184
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
185 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
186 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
187 return
0
goffi@necton2
parents:
diff changeset
188 sender=JID(from_jid)
goffi@necton2
parents:
diff changeset
189 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
190 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
191 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
192 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
193 self.chat_wins[win.short].printMessage(sender, msg, profile)
0
goffi@necton2
parents:
diff changeset
194
goffi@necton2
parents:
diff changeset
195 def setStatusOnline(self, online=True):
goffi@necton2
parents:
diff changeset
196 pass
goffi@necton2
parents:
diff changeset
197
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
198 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
199 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
200 return
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 71
diff changeset
201 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
202 from_jid=JID(jabber_id)
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
203 debug ("from_jid.short=%(from_jid)s whoami.short=%(whoami)s" % {'from_jid':from_jid.short, 'whoami':self.profiles[profile]['whoami'].short})
0
goffi@necton2
parents:
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 if from_jid.short==self.profiles[profile]['whoami'].short:
0
goffi@necton2
parents:
diff changeset
206 if not type:
goffi@necton2
parents:
diff changeset
207 self.setStatusOnline(True)
goffi@necton2
parents:
diff changeset
208 elif type=="unavailable":
goffi@necton2
parents:
diff changeset
209 self.setStatusOnline(False)
goffi@necton2
parents:
diff changeset
210 return
goffi@necton2
parents:
diff changeset
211
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
212 if show != 'unavailable':
0
goffi@necton2
parents:
diff changeset
213 name=""
53
6dfe5bb10008 Wix: groups in contact list, first draft
Goffi <goffi@goffi.org>
parents: 52
diff changeset
214 groups = []
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
215 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
216 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
217 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
218 groups=self.rosterList[from_jid.short][1]
0
goffi@necton2
parents:
diff changeset
219
goffi@necton2
parents:
diff changeset
220 #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
221 if from_jid.short in self.profiles[profile]['watched'] and not from_jid.short in self.profiles[profile]['onlineContact']:
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
222 self.showAlert(_("Watched jid [%s] is connected !") % from_jid.short)
0
goffi@necton2
parents:
diff changeset
223
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
224 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
225 self.CM.add(from_jid)
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
226 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
227 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
228 self.CM.update(from_jid, 'statuses', statuses)
53
6dfe5bb10008 Wix: groups in contact list, first draft
Goffi <goffi@goffi.org>
parents: 52
diff changeset
229 self.CM.update(from_jid, 'groups', groups)
64
d46f849664aa SàT: multi-profile, plugins updated
Goffi <goffi@goffi.org>
parents: 57
diff changeset
230 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
231 if cache.has_key('nick'):
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
232 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
233 if cache.has_key('avatar'):
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
234 self.CM.update(from_jid, 'avatar', self.bridge.getAvatarFile(cache['avatar']))
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 71
diff changeset
235 self.contactList.replace(from_jid, self.CM.getAttr(from_jid, 'groups'))
0
goffi@necton2
parents:
diff changeset
236
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
237 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
238 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
239 self.CM.remove(from_jid)
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
240 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
241 self.contactList.disconnect(from_jid)
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 71
diff changeset
242
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 71
diff changeset
243 def roomJoined(self, room_id, room_service, room_nicks, user_nick, profile):
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 71
diff changeset
244 """Called when a MUC room is joined"""
75
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
245 if not self.__check_profile(profile):
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
246 return
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
247 debug (_("Room [%(room_name)s] joined by %(profile)s, users presents:%(users)s") % {'room_name':room_id+'@'+room_service, 'profile': profile, 'users':room_nicks})
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
248 room_jid=room_id+'@'+room_service
79
db0a0f000e37 Chat presentation enhancement
Goffi <goffi@goffi.org>
parents: 78
diff changeset
249 self.chat_wins[room_jid].setUserNick(user_nick)
75
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
250 self.chat_wins[room_jid].setType("group")
85
fc7583282d40 Tarot Game plugin: first draft
Goffi <goffi@goffi.org>
parents: 79
diff changeset
251 self.chat_wins[room_jid].id = room_jid
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 119
diff changeset
252 self.chat_wins[room_jid].setPresents(list(set([user_nick]+room_nicks)))
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 71
diff changeset
253
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 71
diff changeset
254
75
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
255 def roomUserJoined(self, room_id, room_service, user_nick, user_data, profile):
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
256 """Called when an user joined a MUC room"""
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
257 if not self.__check_profile(profile):
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
258 return
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
259 room_jid=room_id+'@'+room_service
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
260 if self.chat_wins.has_key(room_jid):
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
261 self.chat_wins[room_jid].replaceUser(user_nick)
76
8becde8a967c MUC: added subject management
Goffi <goffi@goffi.org>
parents: 75
diff changeset
262 debug (_("user [%(user_nick)s] joined room [%(room_jid)s]") % {'user_nick':user_nick, 'room_jid':room_jid})
75
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
263
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
264 def roomUserLeft(self, room_id, room_service, user_nick, user_data, profile):
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
265 """Called when an user joined a MUC room"""
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
266 if not self.__check_profile(profile):
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
267 return
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
268 room_jid=room_id+'@'+room_service
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
269 if self.chat_wins.has_key(room_jid):
7322a41f8a8e Basic user joined/left management
Goffi <goffi@goffi.org>
parents: 72
diff changeset
270 self.chat_wins[room_jid].removeUser(user_nick)
76
8becde8a967c MUC: added subject management
Goffi <goffi@goffi.org>
parents: 75
diff changeset
271 debug (_("user [%(user_nick)s] left room [%(room_jid)s]") % {'user_nick':user_nick, 'room_jid':room_jid})
8becde8a967c MUC: added subject management
Goffi <goffi@goffi.org>
parents: 75
diff changeset
272
8becde8a967c MUC: added subject management
Goffi <goffi@goffi.org>
parents: 75
diff changeset
273 def roomNewSubject(self, room_id, room_service, subject, profile):
8becde8a967c MUC: added subject management
Goffi <goffi@goffi.org>
parents: 75
diff changeset
274 """Called when subject of MUC room change"""
8becde8a967c MUC: added subject management
Goffi <goffi@goffi.org>
parents: 75
diff changeset
275 if not self.__check_profile(profile):
8becde8a967c MUC: added subject management
Goffi <goffi@goffi.org>
parents: 75
diff changeset
276 return
8becde8a967c MUC: added subject management
Goffi <goffi@goffi.org>
parents: 75
diff changeset
277 room_jid=room_id+'@'+room_service
8becde8a967c MUC: added subject management
Goffi <goffi@goffi.org>
parents: 75
diff changeset
278 if self.chat_wins.has_key(room_jid):
8becde8a967c MUC: added subject management
Goffi <goffi@goffi.org>
parents: 75
diff changeset
279 self.chat_wins[room_jid].setSubject(subject)
8becde8a967c MUC: added subject management
Goffi <goffi@goffi.org>
parents: 75
diff changeset
280 debug (_("new subject for room [%(room_jid)s]: %(subject)s") % {'room_jid':room_jid, "subject":subject})
85
fc7583282d40 Tarot Game plugin: first draft
Goffi <goffi@goffi.org>
parents: 79
diff changeset
281
90
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
282 def tarotGameStarted(self, room_jid, referee, players, profile):
85
fc7583282d40 Tarot Game plugin: first draft
Goffi <goffi@goffi.org>
parents: 79
diff changeset
283 if not self.__check_profile(profile):
fc7583282d40 Tarot Game plugin: first draft
Goffi <goffi@goffi.org>
parents: 79
diff changeset
284 return
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
285 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
286 if self.chat_wins.has_key(room_jid):
90
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
287 self.chat_wins[room_jid].startGame("Tarot", referee, players)
4020931569b8 Tarot Game: session initialization
Goffi <goffi@goffi.org>
parents: 89
diff changeset
288 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
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
289
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
290 def tarotGameNew(self, room_jid, hand, profile):
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
291 if not self.__check_profile(profile):
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
292 return
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
293 debug (_("New Tarot Game"))
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
294 if self.chat_wins.has_key(room_jid):
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
295 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
296
91
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
297 def tarotChooseContrat(self, room_jid, xml_data, profile):
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
298 """Called when the player has too select his contrat"""
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
299 if not self.__check_profile(profile):
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
300 return
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
301 debug (_("Tarot: need to select a contrat"))
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
302 if self.chat_wins.has_key(room_jid):
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
303 self.chat_wins[room_jid].getGame("Tarot").chooseContrat(xml_data)
39c672544593 Tarot: bidding phase
Goffi <goffi@goffi.org>
parents: 90
diff changeset
304
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
305 def tarotShowCards(self, room_jid, game_stage, cards, data, profile):
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
306 if not self.__check_profile(profile):
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
307 return
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
308 debug (_("Show cards"))
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
309 if self.chat_wins.has_key(room_jid):
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
310 self.chat_wins[room_jid].getGame("Tarot").showCards(game_stage, cards, data)
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
311
92
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
312 def tarotMyTurn(self, room_jid, profile):
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
313 if not self.__check_profile(profile):
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
314 return
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
315 debug (_("My turn to play"))
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
316 if self.chat_wins.has_key(room_jid):
2503de7fb4c7 Tarot game: chien/écart stage
Goffi <goffi@goffi.org>
parents: 91
diff changeset
317 self.chat_wins[room_jid].getGame("Tarot").MyTurn()
93
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
318
95
be206a3d1a9b Tarot game: score calculation
Goffi <goffi@goffi.org>
parents: 93
diff changeset
319 def tarotScore(self, room_jid, xml_data, winners, loosers, profile):
be206a3d1a9b Tarot game: score calculation
Goffi <goffi@goffi.org>
parents: 93
diff changeset
320 """Called when the game is finished and the score are updated"""
be206a3d1a9b Tarot game: score calculation
Goffi <goffi@goffi.org>
parents: 93
diff changeset
321 if not self.__check_profile(profile):
be206a3d1a9b Tarot game: score calculation
Goffi <goffi@goffi.org>
parents: 93
diff changeset
322 return
be206a3d1a9b Tarot game: score calculation
Goffi <goffi@goffi.org>
parents: 93
diff changeset
323 debug (_("Tarot: score received"))
be206a3d1a9b Tarot game: score calculation
Goffi <goffi@goffi.org>
parents: 93
diff changeset
324 if self.chat_wins.has_key(room_jid):
be206a3d1a9b Tarot game: score calculation
Goffi <goffi@goffi.org>
parents: 93
diff changeset
325 self.chat_wins[room_jid].getGame("Tarot").showScores(xml_data, winners, loosers)
be206a3d1a9b Tarot game: score calculation
Goffi <goffi@goffi.org>
parents: 93
diff changeset
326
93
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
327 def tarotCardsPlayed(self, room_jid, player, cards, profile):
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
328 if not self.__check_profile(profile):
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
329 return
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
330 debug (_("Card(s) played (%(player)s): %(cards)s") % {"player":player, "cards":cards})
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
331 if self.chat_wins.has_key(room_jid):
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
332 self.chat_wins[room_jid].getGame("Tarot").cardsPlayed(player, cards)
2f87651a5ad8 Tarot game: basic trick
Goffi <goffi@goffi.org>
parents: 92
diff changeset
333
99
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 95
diff changeset
334 def tarotInvalidCards(self, room_jid, phase, played_cards, invalid_cards, profile):
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 95
diff changeset
335 if not self.__check_profile(profile):
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 95
diff changeset
336 return
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 95
diff changeset
337 debug (_("Cards played are not valid: %s") % invalid_cards)
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 95
diff changeset
338 if self.chat_wins.has_key(room_jid):
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 95
diff changeset
339 self.chat_wins[room_jid].getGame("Tarot").invalidCards(phase, played_cards, invalid_cards)
63c9067a1499 Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents: 95
diff changeset
340
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
341 def subscribe(self, type, raw_jid, profile):
87
66d784082930 Tarot game
Goffi <goffi@goffi.org>
parents: 86
diff changeset
342 """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
343 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
344 return
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
345 entity = JID(raw_jid)
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
346 if type=="subscribed":
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
347 # this is a subscription confirmation, we just have to inform user
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
348 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
349 elif type=="unsubscribed":
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
350 # this is a subscription refusal, we just have to inform user
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
351 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
352 elif type=="subscribe":
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
353 # this is a subscriptionn request, we have to ask for user confirmation
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
354 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
355 if answer:
89
23caf1051099 multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents: 87
diff changeset
356 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
357 else:
89
23caf1051099 multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents: 87
diff changeset
358 self.bridge.subscription("unsubscribed", entity.short, profile_key = profile)
0
goffi@necton2
parents:
diff changeset
359
goffi@necton2
parents:
diff changeset
360 def showDialog(self, message, title, type="info"):
goffi@necton2
parents:
diff changeset
361 raise NotImplementedError
goffi@necton2
parents:
diff changeset
362
goffi@necton2
parents:
diff changeset
363 def showAlert(self, message):
goffi@necton2
parents:
diff changeset
364 pass #FIXME
goffi@necton2
parents:
diff changeset
365
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
366 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
367 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
368 return
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
369 debug(_("param update: [%(namespace)s] %(name)s = %(value)s") % {'namespace':namespace, 'name':name, 'value':value})
0
goffi@necton2
parents:
diff changeset
370 if (namespace,name) == ("Connection", "JabberID"):
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
371 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
372 self.profiles[profile]['whoami']=JID(value)
0
goffi@necton2
parents:
diff changeset
373 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
374 self.profiles[profile]['watched']=value.split()
0
goffi@necton2
parents:
diff changeset
375
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
376 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
377 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
378 return
0
goffi@necton2
parents:
diff changeset
379 target = JID(jid)
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
380 self.CM.remove(target)
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
381 self.contactList.remove(self.CM.get_full(target))
0
goffi@necton2
parents:
diff changeset
382 try:
66
8147b4f40809 SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
383 self.profiles[profile]['onlineContact'].remove(target.short)
0
goffi@necton2
parents:
diff changeset
384 except KeyError:
goffi@necton2
parents:
diff changeset
385 pass
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
386
71
efe81b61673c quick app: updatedValue wrong parameter fix
Goffi <goffi@goffi.org>
parents: 70
diff changeset
387 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
388 if name == "card_nick":
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
389 target = JID(data['jid'])
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 119
diff changeset
390 if target in self.contactList:
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 119
diff changeset
391 self.CM.update(target, 'nick', data['nick'])
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 119
diff changeset
392 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
393 elif name == "card_avatar":
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
394 target = JID(data['jid'])
124
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 119
diff changeset
395 if target in self.contactList:
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 119
diff changeset
396 filename = self.bridge.getAvatarFile(data['avatar'])
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 119
diff changeset
397 self.CM.update(target, 'avatar', filename)
961e0898271f primitivus chat window
Goffi <goffi@goffi.org>
parents: 119
diff changeset
398 self.contactList.replace(target)
51
8c67ea98ab91 frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents: 28
diff changeset
399
0
goffi@necton2
parents:
diff changeset
400 def askConfirmation(self, type, id, data):
goffi@necton2
parents:
diff changeset
401 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
402
bb72c29f3432 added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents: 18
diff changeset
403 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
404 raise NotImplementedError