From c0e4960c559f4c09a72bafad4ecc149e60aa9038 Mon Sep 17 00:00:00 2001 From: Goffi Date: Sun, 24 Jul 2016 19:00:50 +0200 Subject: [PATCH] =?UTF-8?q?primitivus=20(chat):=20added=20:topic=20(and=20?= =?UTF-8?q?:subject=20and=20:title=20aliases)=20to=20change=20subject=20wi?= =?UTF-8?q?th=20a=20dialog=20(/!\=20urwid=20S=C3=A0Text=20need=20to=20be?= =?UTF-8?q?=20updated)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontends/src/primitivus/chat.py | 13 +++++++++++++ frontends/src/primitivus/primitivus | 8 ++++++++ frontends/src/quick_frontend/quick_chat.py | 10 +++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/frontends/src/primitivus/chat.py b/frontends/src/primitivus/chat.py index f0348a37..e46afb69 100644 --- a/frontends/src/primitivus/chat.py +++ b/frontends/src/primitivus/chat.py @@ -603,5 +603,18 @@ class Chat(PrimitivusWidget, quick_chat.QuickChat): self.title_dynamic = C.CHAT_STATE_ICON[state] self.host.redraw() # FIXME: should not be necessary + def _onSubjectDialogCb(self, button, dialog): + self.changeSubject(dialog.text) + self.host.removePopUp(dialog) + + def onSubjectDialog(self, new_subject=None): + dialog = sat_widgets.InputDialog( + _(u'Change title'), + _(u'Enter the new title'), + default_txt=new_subject if new_subject is not None else self.subject) + dialog.setCallback('ok', self._onSubjectDialogCb, dialog) + dialog.setCallback('cancel', lambda dummy: self.host.removePopUp(dialog)) + self.host.showPopUp(dialog) + quick_widgets.register(quick_chat.QuickChat, Chat) quick_widgets.register(quick_games.Tarot, game_tarot.TarotGame) diff --git a/frontends/src/primitivus/primitivus b/frontends/src/primitivus/primitivus index 6a1d62a5..75e138fd 100755 --- a/frontends/src/primitivus/primitivus +++ b/frontends/src/primitivus/primitivus @@ -138,6 +138,14 @@ class EditBar(sat_widgets.ModalEdit): # FIXME: Q&D way, need to be more generic if isinstance(widget, quick_chat.QuickChat): widget.setFilter(args) + elif command in ('topic', 'suject', 'title'): + try: + new_title = args[0].strip() + except IndexError: + new_title = None + widget = self.host.selected_widget + if isinstance(widget, quick_chat.QuickChat) and widget.type == C.CHAT_GROUP: + widget.onSubjectDialog(new_title) else: return self.set_edit_text('') diff --git a/frontends/src/quick_frontend/quick_chat.py b/frontends/src/quick_frontend/quick_chat.py index 847cf678..e86234f9 100644 --- a/frontends/src/quick_frontend/quick_chat.py +++ b/frontends/src/quick_frontend/quick_chat.py @@ -423,9 +423,17 @@ class QuickChat(quick_widgets.QuickWidget): def setSubject(self, subject): """Set title for a group chat""" - self.subject = subject if self.type != C.CHAT_GROUP: raise exceptions.InternalError("trying to set subject for a non group chat window") + self.subject = subject + + def changeSubject(self, new_subject): + """Change the subject of the room + + This change the subject on the room itself (i.e. via XMPP), + while setSubject change the subject of this widget + """ + self.host.bridge.mucSubject(unicode(self.target), new_subject, self.profile) def addGamePanel(self, widget): """Insert a game panel to this Chat dialog.