From fa430d5105bd7f12bd876741e00a2864dd0ebf3a Mon Sep 17 00:00:00 2001 From: souliane Date: Wed, 7 May 2014 16:11:32 +0200 Subject: [PATCH] quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords --- frontends/src/primitivus/primitivus | 13 ++++++-- frontends/src/primitivus/profile_manager.py | 36 ++++++++++++++++++--- frontends/src/quick_frontend/quick_app.py | 5 ++- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/frontends/src/primitivus/primitivus b/frontends/src/primitivus/primitivus index d48a1274..b47e13e9 100755 --- a/frontends/src/primitivus/primitivus +++ b/frontends/src/primitivus/primitivus @@ -318,10 +318,10 @@ class PrimitivusApp(QuickApp, InputHistory): self.main_widget = sat_widgets.FocusFrame(self.center_part, header=self.menu_roller, footer=self.editBar, focus_part='footer') return self.main_widget - def plug_profile(self, profile_key='@DEFAULT@'): + def plug_profile_1(self, profile_key='@DEFAULT@'): self.loop.widget = self._buildMainWidget() self.redraw() - QuickApp.plug_profile(self, profile_key) + QuickApp.plug_profile_1(self, profile_key) def removePopUp(self, widget=None): "Remove current pop-up, and if there is other in queue, show it" @@ -455,6 +455,15 @@ class PrimitivusApp(QuickApp, InputHistory): elif "xmlui" in data: ui = XMLUI(self, xml_data=data['xmlui']) ui.show() + elif "authenticated_profile" in data: + assert("caller" in data) + if data["caller"] == "profile_manager": + assert(isinstance(self.main_widget, ProfileManager)) + self.main_widget.getXMPPParams(data['authenticated_profile']) + elif data["caller"] == "plug_profile": + self.plug_profile_1(data['authenticated_profile']) + else: + raise NotImplementedError else: self.showPopUp(sat_widgets.Alert(_("Error"), _(u"Unmanaged action result"), ok_cb=self.removePopUp)) diff --git a/frontends/src/primitivus/profile_manager.py b/frontends/src/primitivus/profile_manager.py index caea6458..419e0552 100644 --- a/frontends/src/primitivus/profile_manager.py +++ b/frontends/src/primitivus/profile_manager.py @@ -18,6 +18,7 @@ # along with this program. If not, see . from sat.core.i18n import _ +from sat_frontends.primitivus.constants import Const as C import urwid from urwid_satext.sat_widgets import AdvancedEdit, Password, List, InputDialog, ConfirmDialog, Alert from sat.tools.jid import JID @@ -35,7 +36,11 @@ 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_change=self.onProfileChange) + self.selected_profile = None # allow to reselect the previous selection until the profile is authenticated + style = ['single'] + if self.host.options.profile: + style.append('no_first_select') + self.list_profile = List(profiles, style=style, align='center', on_change=self.onProfileChange) #new & delete buttons buttons = [urwid.Button(_("New"), self.onNewProfile), @@ -103,7 +108,11 @@ class ProfileManager(urwid.WidgetWrap): pop_up_widget = ConfirmDialog(_("Are you sure you want to delete the profile %s ?") % self.list_profile.getSelectedValue(), no_cb=self.cancelDialog, yes_cb=self.deleteProfile) self.host.showPopUp(pop_up_widget) - def onProfileChange(self, list_wid): + def getXMPPParams(self, profile): + """This is called from PrimitivusApp.launchAction when the profile has been authenticated. + + @param profile: %(doc_profile)s + """ def setJID(jabberID): self.login_wid.set_edit_text(jabberID) self.host.redraw() @@ -112,13 +121,30 @@ class ProfileManager(urwid.WidgetWrap): self.pass_wid.set_edit_text(password) self.host.redraw() + self.list_profile.selectValue(profile, move_focus=False) + self.selected_profile = profile + self.host.bridge.asyncGetParamA("JabberID", "Connection", profile_key=profile, callback=setJID, errback=self.getParamError) + self.host.bridge.asyncGetParamA("Password", "Connection", profile_key=profile, callback=setPassword, errback=self.getParamError) + + def onProfileChange(self, list_wid): + """This is called when a profile is selected in the profile list. + + @param list_wid: the List widget who sent the event + """ profile_name = list_wid.getSelectedValue() - if profile_name: - self.host.bridge.asyncGetParamA("JabberID", "Connection", profile_key=profile_name, callback=setJID, errback=self.getParamError) - self.host.bridge.asyncGetParamA("Password", "Connection", profile_key=profile_name, callback=setPassword, errback=self.getParamError) + if not profile_name or profile_name == self.selected_profile: + return # avoid infinite loop + if self.selected_profile: + list_wid.selectValue(self.selected_profile, move_focus=False) + else: + list_wid.unselectAll(invisible=True) + self.host.redraw() + self.host.profile = profile_name # FIXME: EXTREMELY DIRTY, needed for sat_frontends.tools.xmlui.XMLUI._xmluiLaunchAction + self.host.launchAction(C.AUTHENTICATE_PROFILE_ID, {'caller': 'profile_manager'}, profile_key=profile_name) def onConnectProfile(self, button): profile_name = self.list_profile.getSelectedValue() + assert(profile_name == self.selected_profile) # if not, there's a bug somewhere... if not profile_name: pop_up_widget = Alert(_('No profile selected'), _('You need to create and select a profile before connecting'), ok_cb=self.cancelDialog) self.host.showPopUp(pop_up_widget) diff --git a/frontends/src/quick_frontend/quick_app.py b/frontends/src/quick_frontend/quick_app.py index a25a1781..dd7bbf59 100644 --- a/frontends/src/quick_frontend/quick_app.py +++ b/frontends/src/quick_frontend/quick_app.py @@ -136,6 +136,9 @@ class QuickApp(object): if self.single_profile: self.profile = profile + self.launchAction(C.AUTHENTICATE_PROFILE_ID, {'caller': 'plug_profile'}, profile_key=profile) + + def plug_profile_1(self, profile): ###now we get the essential params### self.bridge.asyncGetParamA("JabberID", "Connection", profile_key=profile, callback=lambda _jid: self.plug_profile_2(_jid, profile), errback=self._getParamError) @@ -152,7 +155,7 @@ class QuickApp(object): def plug_profile_4(self, watched, autoconnect, profile): if autoconnect and not self.bridge.isConnected(profile): #Does the user want autoconnection ? - self.bridge.asyncConnect(profile, callback=lambda: self.plug_profile_5(watched, autoconnect, profile), errback=lambda ignore: log.error(_('Error during autoconnection'))) + self.bridge.asyncConnect(profile, callback=lambda dummy: self.plug_profile_5(watched, autoconnect, profile), errback=lambda ignore: log.error(_('Error during autoconnection'))) else: self.plug_profile_5(watched, autoconnect, profile)