quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords

This commit is contained in:
souliane 2014-05-07 16:11:32 +02:00
commit fa430d5105
3 changed files with 46 additions and 8 deletions

View file

@ -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') self.main_widget = sat_widgets.FocusFrame(self.center_part, header=self.menu_roller, footer=self.editBar, focus_part='footer')
return self.main_widget 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.loop.widget = self._buildMainWidget()
self.redraw() self.redraw()
QuickApp.plug_profile(self, profile_key) QuickApp.plug_profile_1(self, profile_key)
def removePopUp(self, widget=None): def removePopUp(self, widget=None):
"Remove current pop-up, and if there is other in queue, show it" "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: elif "xmlui" in data:
ui = XMLUI(self, xml_data=data['xmlui']) ui = XMLUI(self, xml_data=data['xmlui'])
ui.show() 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: else:
self.showPopUp(sat_widgets.Alert(_("Error"), _(u"Unmanaged action result"), ok_cb=self.removePopUp)) self.showPopUp(sat_widgets.Alert(_("Error"), _(u"Unmanaged action result"), ok_cb=self.removePopUp))

View file

@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _ from sat.core.i18n import _
from sat_frontends.primitivus.constants import Const as C
import urwid import urwid
from urwid_satext.sat_widgets import AdvancedEdit, Password, List, InputDialog, ConfirmDialog, Alert from urwid_satext.sat_widgets import AdvancedEdit, Password, List, InputDialog, ConfirmDialog, Alert
from sat.tools.jid import JID from sat.tools.jid import JID
@ -35,7 +36,11 @@ class ProfileManager(urwid.WidgetWrap):
self.login_wid = AdvancedEdit(_('Login:'), align='center') self.login_wid = AdvancedEdit(_('Login:'), align='center')
self.pass_wid = Password(_('Password:'), 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 #new & delete buttons
buttons = [urwid.Button(_("New"), self.onNewProfile), 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) 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) 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): def setJID(jabberID):
self.login_wid.set_edit_text(jabberID) self.login_wid.set_edit_text(jabberID)
self.host.redraw() self.host.redraw()
@ -112,13 +121,30 @@ class ProfileManager(urwid.WidgetWrap):
self.pass_wid.set_edit_text(password) self.pass_wid.set_edit_text(password)
self.host.redraw() 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() profile_name = list_wid.getSelectedValue()
if profile_name: if not profile_name or profile_name == self.selected_profile:
self.host.bridge.asyncGetParamA("JabberID", "Connection", profile_key=profile_name, callback=setJID, errback=self.getParamError) return # avoid infinite loop
self.host.bridge.asyncGetParamA("Password", "Connection", profile_key=profile_name, callback=setPassword, errback=self.getParamError) 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): def onConnectProfile(self, button):
profile_name = self.list_profile.getSelectedValue() profile_name = self.list_profile.getSelectedValue()
assert(profile_name == self.selected_profile) # if not, there's a bug somewhere...
if not profile_name: 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) 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) self.host.showPopUp(pop_up_widget)

View file

@ -136,6 +136,9 @@ class QuickApp(object):
if self.single_profile: if self.single_profile:
self.profile = 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### ###now we get the essential params###
self.bridge.asyncGetParamA("JabberID", "Connection", profile_key=profile, self.bridge.asyncGetParamA("JabberID", "Connection", profile_key=profile,
callback=lambda _jid: self.plug_profile_2(_jid, profile), errback=self._getParamError) 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): def plug_profile_4(self, watched, autoconnect, profile):
if autoconnect and not self.bridge.isConnected(profile): if autoconnect and not self.bridge.isConnected(profile):
#Does the user want autoconnection ? #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: else:
self.plug_profile_5(watched, autoconnect, profile) self.plug_profile_5(watched, autoconnect, profile)