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

View file

@ -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 @@ 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)