From d5fac19b9e26c5863f54ba587e5d103641d74851 Mon Sep 17 00:00:00 2001 From: Goffi Date: Tue, 16 Oct 2012 01:22:40 +0200 Subject: [PATCH] Primitivus: present contacts in groups chat can now be clicked - updated GenericList/List signals to manage change/click fix in urwid-satext - a click on a nick in a group chat create a private conversation with her, and select this conversation /!\ history in backend doesn't manage correctly yet the private conversations /!\ --- frontends/src/primitivus/chat.py | 18 ++++++++++++++++-- frontends/src/primitivus/contact_list.py | 10 +++++++--- frontends/src/primitivus/profile_manager.py | 2 +- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/frontends/src/primitivus/chat.py b/frontends/src/primitivus/chat.py index beaa472b..df393745 100644 --- a/frontends/src/primitivus/chat.py +++ b/frontends/src/primitivus/chat.py @@ -24,7 +24,7 @@ from urwid_satext import sat_widgets from urwid_satext.files_management import FileDialog from sat_frontends.quick_frontend.quick_chat import QuickChat from sat_frontends.primitivus.card_game import CardGame -from sat_frontends.quick_frontend.quick_utils import unescapePrivate +from sat_frontends.quick_frontend.quick_utils import escapePrivate, unescapePrivate import time from sat.tools.jid import JID @@ -155,9 +155,23 @@ class Chat(urwid.WidgetWrap, QuickChat): main_widget = self.pile self._w = main_widget + def _presentClicked(self, list_wid, clicked_wid): + assert(self.type == 'group') + nick = clicked_wid.getValue() + if nick == self.getUserNick(): + #We ignore click on our own nick + return + #we have a click on a nick, we add the private conversation to the contact_list + full_jid = JID("%s/%s" % (self.target.short, nick)) + new_jid = escapePrivate(full_jid) + if new_jid not in self.host.contact_list: + self.host.contact_list.add(new_jid) + + #now we select the new window + self.host.contact_list.setFocus(full_jid, True) def __buildPresentList(self): - self.present_wid = sat_widgets.GenericList([],option_type = sat_widgets.ClickableText) + self.present_wid = sat_widgets.GenericList([],option_type = sat_widgets.ClickableText, on_click=self._presentClicked) return self.present_wid def __appendPresentPanel(self): diff --git a/frontends/src/primitivus/contact_list.py b/frontends/src/primitivus/contact_list.py index 71b6eb97..c2010774 100644 --- a/frontends/src/primitivus/contact_list.py +++ b/frontends/src/primitivus/contact_list.py @@ -73,13 +73,17 @@ class ContactList(urwid.WidgetWrap, QuickContactList): return True return False - def setFocus(self, name): - """give focus to the first group or contact with the given name""" + def setFocus(self, name, select=False): + """give focus to the first group or contact wich contain the given name + @param name: name to check + @param select: if True, the contact/group is also clicked""" idx = 0 for widget in self.frame.body.body: try: - if widget.getValue() == name: + if name in widget.getValue(): self.frame.body.set_focus(idx) + if select: + self.__contactClicked(widget, True) return except AttributeError: pass diff --git a/frontends/src/primitivus/profile_manager.py b/frontends/src/primitivus/profile_manager.py index 413bf34a..250ccc7e 100644 --- a/frontends/src/primitivus/profile_manager.py +++ b/frontends/src/primitivus/profile_manager.py @@ -36,7 +36,7 @@ class ProfileManager(urwid.WidgetWrap): self.login_wid = AdvancedEdit(_('Login:'),align='center') self.pass_wid = Password(_('Password:'),align='center') - self.list_profile = List(profiles, style=['single'], align='center', on_click=self.onProfileChange) + self.list_profile = List(profiles, style=['single'], align='center', on_change=self.onProfileChange) #new & delete buttons buttons = [urwid.Button(_("New"), self.onNewProfile),