Mercurial > libervia-backend
comparison frontends/src/primitivus/profile_manager.py @ 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 | 6a16ec17a458 |
children | 6ec513ad92c2 |
comparison
equal
deleted
inserted
replaced
1033:d87aa6bdb0b4 | 1034:5197600a1e13 |
---|---|
16 | 16 |
17 # You should have received a copy of the GNU Affero General Public License | 17 # You should have received a copy of the GNU Affero General Public License |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 from sat.core.i18n import _ | 20 from sat.core.i18n import _ |
21 from sat_frontends.primitivus.constants import Const as C | |
21 import urwid | 22 import urwid |
22 from urwid_satext.sat_widgets import AdvancedEdit, Password, List, InputDialog, ConfirmDialog, Alert | 23 from urwid_satext.sat_widgets import AdvancedEdit, Password, List, InputDialog, ConfirmDialog, Alert |
23 from sat.tools.jid import JID | 24 from sat.tools.jid import JID |
24 | 25 |
25 | 26 |
33 | 34 |
34 #login & password box must be created before list because of onProfileChange | 35 #login & password box must be created before list because of onProfileChange |
35 self.login_wid = AdvancedEdit(_('Login:'), align='center') | 36 self.login_wid = AdvancedEdit(_('Login:'), align='center') |
36 self.pass_wid = Password(_('Password:'), align='center') | 37 self.pass_wid = Password(_('Password:'), align='center') |
37 | 38 |
38 self.list_profile = List(profiles, style=['single'], align='center', on_change=self.onProfileChange) | 39 self.selected_profile = None # allow to reselect the previous selection until the profile is authenticated |
40 style = ['single'] | |
41 if self.host.options.profile: | |
42 style.append('no_first_select') | |
43 self.list_profile = List(profiles, style=style, align='center', on_change=self.onProfileChange) | |
39 | 44 |
40 #new & delete buttons | 45 #new & delete buttons |
41 buttons = [urwid.Button(_("New"), self.onNewProfile), | 46 buttons = [urwid.Button(_("New"), self.onNewProfile), |
42 urwid.Button(_("Delete"), self.onDeleteProfile)] | 47 urwid.Button(_("Delete"), self.onDeleteProfile)] |
43 buttons_flow = urwid.GridFlow(buttons, max([len(button.get_label()) for button in buttons])+4, 1, 1, 'center') | 48 buttons_flow = urwid.GridFlow(buttons, max([len(button.get_label()) for button in buttons])+4, 1, 1, 'center') |
101 | 106 |
102 def onDeleteProfile(self, e): | 107 def onDeleteProfile(self, e): |
103 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) | 108 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) |
104 self.host.showPopUp(pop_up_widget) | 109 self.host.showPopUp(pop_up_widget) |
105 | 110 |
106 def onProfileChange(self, list_wid): | 111 def getXMPPParams(self, profile): |
112 """This is called from PrimitivusApp.launchAction when the profile has been authenticated. | |
113 | |
114 @param profile: %(doc_profile)s | |
115 """ | |
107 def setJID(jabberID): | 116 def setJID(jabberID): |
108 self.login_wid.set_edit_text(jabberID) | 117 self.login_wid.set_edit_text(jabberID) |
109 self.host.redraw() | 118 self.host.redraw() |
110 | 119 |
111 def setPassword(password): | 120 def setPassword(password): |
112 self.pass_wid.set_edit_text(password) | 121 self.pass_wid.set_edit_text(password) |
113 self.host.redraw() | 122 self.host.redraw() |
114 | 123 |
124 self.list_profile.selectValue(profile, move_focus=False) | |
125 self.selected_profile = profile | |
126 self.host.bridge.asyncGetParamA("JabberID", "Connection", profile_key=profile, callback=setJID, errback=self.getParamError) | |
127 self.host.bridge.asyncGetParamA("Password", "Connection", profile_key=profile, callback=setPassword, errback=self.getParamError) | |
128 | |
129 def onProfileChange(self, list_wid): | |
130 """This is called when a profile is selected in the profile list. | |
131 | |
132 @param list_wid: the List widget who sent the event | |
133 """ | |
115 profile_name = list_wid.getSelectedValue() | 134 profile_name = list_wid.getSelectedValue() |
116 if profile_name: | 135 if not profile_name or profile_name == self.selected_profile: |
117 self.host.bridge.asyncGetParamA("JabberID", "Connection", profile_key=profile_name, callback=setJID, errback=self.getParamError) | 136 return # avoid infinite loop |
118 self.host.bridge.asyncGetParamA("Password", "Connection", profile_key=profile_name, callback=setPassword, errback=self.getParamError) | 137 if self.selected_profile: |
138 list_wid.selectValue(self.selected_profile, move_focus=False) | |
139 else: | |
140 list_wid.unselectAll(invisible=True) | |
141 self.host.redraw() | |
142 self.host.profile = profile_name # FIXME: EXTREMELY DIRTY, needed for sat_frontends.tools.xmlui.XMLUI._xmluiLaunchAction | |
143 self.host.launchAction(C.AUTHENTICATE_PROFILE_ID, {'caller': 'profile_manager'}, profile_key=profile_name) | |
119 | 144 |
120 def onConnectProfile(self, button): | 145 def onConnectProfile(self, button): |
121 profile_name = self.list_profile.getSelectedValue() | 146 profile_name = self.list_profile.getSelectedValue() |
147 assert(profile_name == self.selected_profile) # if not, there's a bug somewhere... | |
122 if not profile_name: | 148 if not profile_name: |
123 pop_up_widget = Alert(_('No profile selected'), _('You need to create and select a profile before connecting'), ok_cb=self.cancelDialog) | 149 pop_up_widget = Alert(_('No profile selected'), _('You need to create and select a profile before connecting'), ok_cb=self.cancelDialog) |
124 self.host.showPopUp(pop_up_widget) | 150 self.host.showPopUp(pop_up_widget) |
125 elif profile_name[0] == '@': | 151 elif profile_name[0] == '@': |
126 pop_up_widget = Alert(_('Bad profile name'), _("A profile name can't start with a @"), ok_cb=self.cancelDialog) | 152 pop_up_widget = Alert(_('Bad profile name'), _("A profile name can't start with a @"), ok_cb=self.cancelDialog) |