Mercurial > libervia-backend
diff frontends/src/quick_frontend/quick_app.py @ 1351:ec43552f5f8b frontends_multi_profiles
quick_frontend: replace last occurences of QuickApp.chat_wins with QuickApp.widgets
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 05 Mar 2015 13:48:49 +0100 |
parents | a39d2db03c80 |
children | 56c14cb29e0f |
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_app.py Wed Mar 04 14:04:03 2015 +0100 +++ b/frontends/src/quick_frontend/quick_app.py Thu Mar 05 13:48:49 2015 +0100 @@ -532,7 +532,7 @@ """Called when a MUC room is joined""" log.debug("Room [%(room_jid)s] joined by %(profile)s, users presents:%(users)s" % {'room_jid': room_jid_s, 'profile': profile, 'users': room_nicks}) room_jid = jid.JID(room_jid_s) - chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_='group', profile=profile) + chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, profile=profile) chat_widget.setUserNick(user_nick) chat_widget.id = room_jid # FIXME: to be removed chat_widget.setPresents(list(set([user_nick] + room_nicks))) @@ -541,122 +541,140 @@ def roomLeftHandler(self, room_jid_s, profile): """Called when a MUC room is left""" log.debug("Room [%(room_jid)s] left by %(profile)s" % {'room_jid': room_jid_s, 'profile': profile}) - del self.chat_wins[room_jid_s] - self.contact_lists[profile].remove(jid.JID(room_jid_s)) + room_jid = jid.JID(room_jid_s) + chat_widget = self.widgets.getWidget(quick_chat.QuickChat, room_jid, profile) + if chat_widget: + self.widgets.deleteWidget(chat_widget) + self.contact_lists[profile].remove(room_jid) def roomUserJoinedHandler(self, room_jid_s, user_nick, user_data, profile): """Called when an user joined a MUC room""" room_jid = jid.JID(room_jid_s) - chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_='group', profile=profile) + chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, profile=profile) chat_widget.replaceUser(user_nick) log.debug("user [%(user_nick)s] joined room [%(room_jid)s]" % {'user_nick': user_nick, 'room_jid': room_jid}) def roomUserLeftHandler(self, room_jid_s, user_nick, user_data, profile): """Called when an user joined a MUC room""" room_jid = jid.JID(room_jid_s) - chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_='group', profile=profile) + chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, profile=profile) chat_widget.removeUser(user_nick) log.debug("user [%(user_nick)s] left room [%(room_jid)s]" % {'user_nick': user_nick, 'room_jid': room_jid}) def roomUserChangedNickHandler(self, room_jid_s, old_nick, new_nick, profile): """Called when an user joined a MUC room""" room_jid = jid.JID(room_jid_s) - chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_='group', profile=profile) + chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, profile=profile) chat_widget.changeUserNick(old_nick, new_nick) log.debug("user [%(old_nick)s] is now known as [%(new_nick)s] in room [%(room_jid)s]" % {'old_nick': old_nick, 'new_nick': new_nick, 'room_jid': room_jid}) def roomNewSubjectHandler(self, room_jid_s, subject, profile): """Called when subject of MUC room change""" room_jid = jid.JID(room_jid_s) - chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_='group', profile=profile) + chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, profile=profile) chat_widget.setSubject(subject) log.debug("new subject for room [%(room_jid)s]: %(subject)s" % {'room_jid': room_jid, "subject": subject}) def tarotGameStartedHandler(self, room_jid_s, referee, players, profile): log.debug(_("Tarot Game Started \o/")) room_jid = jid.JID(room_jid_s) - chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_='group', profile=profile) + chat_widget = self.widgets.getOrCreateWidget(quick_chat.QuickChat, room_jid, type_=C.CHAT_GROUP, profile=profile) chat_widget.startGame("Tarot", referee, players) log.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]}) - def tarotGameNewHandler(self, room_jid, hand, profile): + def tarotGameNewHandler(self, room_jid_s, hand, profile): log.debug(_("New Tarot Game")) - if room_jid in self.chat_wins: - self.chat_wins[room_jid].getGame("Tarot").newGame(hand) + chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) + if chat_widget: + chat_widget.getGame("Tarot").newGame(hand) - def tarotGameChooseContratHandler(self, room_jid, xml_data, profile): + def tarotGameChooseContratHandler(self, room_jid_s, xml_data, profile): """Called when the player has to select his contrat""" log.debug(_("Tarot: need to select a contrat")) - if room_jid in self.chat_wins: - self.chat_wins[room_jid].getGame("Tarot").chooseContrat(xml_data) + chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) + if chat_widget: + chat_widget.getGame("Tarot").chooseContrat(xml_data) - def tarotGameShowCardsHandler(self, room_jid, game_stage, cards, data, profile): + def tarotGameShowCardsHandler(self, room_jid_s, game_stage, cards, data, profile): log.debug(_("Show cards")) - if room_jid in self.chat_wins: - self.chat_wins[room_jid].getGame("Tarot").showCards(game_stage, cards, data) + chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) + if chat_widget: + chat_widget.getGame("Tarot").showCards(game_stage, cards, data) - def tarotGameYourTurnHandler(self, room_jid, profile): + def tarotGameYourTurnHandler(self, room_jid_s, profile): log.debug(_("My turn to play")) - if room_jid in self.chat_wins: - self.chat_wins[room_jid].getGame("Tarot").myTurn() + chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) + if chat_widget: + chat_widget.getGame("Tarot").myTurn() - def tarotGameScoreHandler(self, room_jid, xml_data, winners, loosers, profile): + def tarotGameScoreHandler(self, room_jid_s, xml_data, winners, loosers, profile): """Called when the game is finished and the score are updated""" log.debug(_("Tarot: score received")) - if room_jid in self.chat_wins: - self.chat_wins[room_jid].getGame("Tarot").showScores(xml_data, winners, loosers) + chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) + if chat_widget: + chat_widget.getGame("Tarot").showScores(xml_data, winners, loosers) - def tarotGameCardsPlayedHandler(self, room_jid, player, cards, profile): + def tarotGameCardsPlayedHandler(self, room_jid_s, player, cards, profile): log.debug(_("Card(s) played (%(player)s): %(cards)s") % {"player": player, "cards": cards}) - if room_jid in self.chat_wins: - self.chat_wins[room_jid].getGame("Tarot").cardsPlayed(player, cards) - - def tarotGameInvalidCardsHandler(self, room_jid, phase, played_cards, invalid_cards, profile): - log.debug(_("Cards played are not valid: %s") % invalid_cards) - if room_jid in self.chat_wins: - self.chat_wins[room_jid].getGame("Tarot").invalidCards(phase, played_cards, invalid_cards) + chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) + if chat_widget: + chat_widget.getGame("Tarot").cardsPlayed(player, cards) - def quizGameStartedHandler(self, room_jid, referee, players, profile): - log.debug(_("Quiz Game Started \o/")) - if room_jid in self.chat_wins: - self.chat_wins[room_jid].startGame("Quiz", referee, players) - log.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]}) + def tarotGameInvalidCardsHandler(self, room_jid_s, phase, played_cards, invalid_cards, profile): + log.debug(_("Cards played are not valid: %s") % invalid_cards) + chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) + if chat_widget: + chat_widget.getGame("Tarot").invalidCards(phase, played_cards, invalid_cards) - def quizGameNewHandler(self, room_jid, data, profile): + def quizGameStartedHandler(self, room_jid_s, referee, players, profile): + log.debug(_("Quiz Game Started \o/")) + chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) + if chat_widget: + chat_widget.startGame("Quiz", referee, players) + log.debug(_("new Quiz game started by [%(referee)s] in room [%(room_jid)s] with %(players)s") % {'referee': referee, 'room_jid': room_jid_s, 'players': [str(player) for player in players]}) + + def quizGameNewHandler(self, room_jid_s, data, profile): log.debug(_("New Quiz Game")) - if room_jid in self.chat_wins: - self.chat_wins[room_jid].getGame("Quiz").quizGameNewHandler(data) + chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) + if chat_widget: + chat_widget.getGame("Quiz").quizGameNewHandler(data) - def quizGameQuestionHandler(self, room_jid, question_id, question, timer, profile): + def quizGameQuestionHandler(self, room_jid_s, question_id, question, timer, profile): """Called when a new question is asked""" log.debug(_(u"Quiz: new question: %s") % question) - if room_jid in self.chat_wins: - self.chat_wins[room_jid].getGame("Quiz").quizGameQuestionHandler(question_id, question, timer) + chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) + if chat_widget: + chat_widget.getGame("Quiz").quizGameQuestionHandler(question_id, question, timer) - def quizGamePlayerBuzzedHandler(self, room_jid, player, pause, profile): + def quizGamePlayerBuzzedHandler(self, room_jid_s, player, pause, profile): """Called when a player pushed the buzzer""" - if room_jid in self.chat_wins: - self.chat_wins[room_jid].getGame("Quiz").quizGamePlayerBuzzedHandler(player, pause) + chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) + if chat_widget: + chat_widget.getGame("Quiz").quizGamePlayerBuzzedHandler(player, pause) - def quizGamePlayerSaysHandler(self, room_jid, player, text, delay, profile): + def quizGamePlayerSaysHandler(self, room_jid_s, player, text, delay, profile): """Called when a player say something""" - if room_jid in self.chat_wins: - self.chat_wins[room_jid].getGame("Quiz").quizGamePlayerSaysHandler(player, text, delay) + chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) + if chat_widget: + chat_widget.getGame("Quiz").quizGamePlayerSaysHandler(player, text, delay) - def quizGameAnswerResultHandler(self, room_jid, player, good_answer, score, profile): + def quizGameAnswerResultHandler(self, room_jid_s, player, good_answer, score, profile): """Called when a player say something""" - if room_jid in self.chat_wins: - self.chat_wins[room_jid].getGame("Quiz").quizGameAnswerResultHandler(player, good_answer, score) + chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) + if chat_widget: + chat_widget.getGame("Quiz").quizGameAnswerResultHandler(player, good_answer, score) - def quizGameTimerExpiredHandler(self, room_jid, profile): + def quizGameTimerExpiredHandler(self, room_jid_s, profile): """Called when nobody answered the question in time""" - if room_jid in self.chat_wins: - self.chat_wins[room_jid].getGame("Quiz").quizGameTimerExpiredHandler() + chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) + if chat_widget: + chat_widget.getGame("Quiz").quizGameTimerExpiredHandler() - def quizGameTimerRestartedHandler(self, room_jid, time_left, profile): + def quizGameTimerRestartedHandler(self, room_jid_s, time_left, profile): """Called when the question is not answered, and we still have time""" - if room_jid in self.chat_wins: - self.chat_wins[room_jid].getGame("Quiz").quizGameTimerRestartedHandler(time_left) + chat_widget = self.widgets.getWidget(quick_chat.QuickChat, jid.JID(room_jid_s), profile) + if chat_widget: + chat_widget.getGame("Quiz").quizGameTimerRestartedHandler(time_left) def chatStateReceivedHandler(self, from_jid_s, state, profile): """Called when a new chat state is received.