Mercurial > libervia-backend
changeset 1034:5197600a1e13
quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
author | souliane <souliane@mailoo.org> |
---|---|
date | Wed, 07 May 2014 16:11:32 +0200 |
parents | d87aa6bdb0b4 |
children | c4c14480715a |
files | frontends/src/primitivus/primitivus frontends/src/primitivus/profile_manager.py frontends/src/quick_frontend/quick_app.py |
diffstat | 3 files changed, 46 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/src/primitivus/primitivus Wed May 07 16:10:20 2014 +0200 +++ b/frontends/src/primitivus/primitivus Wed May 07 16:11:32 2014 +0200 @@ -318,10 +318,10 @@ 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 @@ 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))
--- a/frontends/src/primitivus/profile_manager.py Wed May 07 16:10:20 2014 +0200 +++ b/frontends/src/primitivus/profile_manager.py Wed May 07 16:11:32 2014 +0200 @@ -18,6 +18,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. 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 @@ 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 @@ 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 @@ 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)
--- a/frontends/src/quick_frontend/quick_app.py Wed May 07 16:10:20 2014 +0200 +++ b/frontends/src/quick_frontend/quick_app.py Wed May 07 16:11:32 2014 +0200 @@ -136,6 +136,9 @@ 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 @@ 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)