Mercurial > libervia-backend
comparison frontends/src/wix/profile_manager.py @ 1035:c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
author | souliane <souliane@mailoo.org> |
---|---|
date | Wed, 07 May 2014 18:16:15 +0200 |
parents | 5a6354ff468c |
children | b29452cab50b |
comparison
equal
deleted
inserted
replaced
1034:5197600a1e13 | 1035:c4c14480715a |
---|---|
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 | 20 |
21 | 21 |
22 from sat.core.i18n import _ | 22 from sat.core.i18n import _ |
23 from sat_frontends.primitivus.constants import Const as C | |
23 import wx | 24 import wx |
24 from sat.core.log import getLogger | 25 from sat.core.log import getLogger |
25 log = getLogger(__name__) | 26 log = getLogger(__name__) |
26 from sat.tools.jid import JID | 27 from sat.tools.jid import JID |
28 | |
29 | |
30 NO_SELECTION_ENTRY = ' ' | |
27 | 31 |
28 | 32 |
29 class ProfileManager(wx.Panel): | 33 class ProfileManager(wx.Panel): |
30 def __init__(self, host): | 34 def __init__(self, host): |
31 super(ProfileManager, self).__init__(host) | 35 super(ProfileManager, self).__init__(host) |
33 | 37 |
34 #self.sizer = wx.FlexGridSizer(cols=2) | 38 #self.sizer = wx.FlexGridSizer(cols=2) |
35 self.sizer = wx.BoxSizer(wx.VERTICAL) | 39 self.sizer = wx.BoxSizer(wx.VERTICAL) |
36 self.SetSizer(self.sizer) | 40 self.SetSizer(self.sizer) |
37 | 41 |
38 profiles = self.host.bridge.getProfilesList() | 42 self.selected_profile = NO_SELECTION_ENTRY # allow to reselect the previous selection until the profile is authenticated |
39 self.profile_name = wx.ComboBox(self, -1, style=wx.CB_READONLY|wx.CB_SORT) | 43 self.profile_name = wx.ComboBox(self, -1, style=wx.CB_READONLY|wx.CB_SORT) |
40 self.__refillProfiles() | 44 self.__refillProfiles() |
41 self.Bind(wx.EVT_COMBOBOX, self.onProfileChange) | 45 self.Bind(wx.EVT_COMBOBOX, self.onProfileChange) |
42 self.panel_id = wx | 46 self.panel_id = wx |
43 | 47 |
72 self.sizer.Add(wx.Window(self, -1), 1) | 76 self.sizer.Add(wx.Window(self, -1), 1) |
73 | 77 |
74 #Now we can set the default value | 78 #Now we can set the default value |
75 self.__setDefault() | 79 self.__setDefault() |
76 | 80 |
77 | |
78 def __setDefault(self): | 81 def __setDefault(self): |
79 profile_default = self.host.bridge.getProfileName("@DEFAULT@") | 82 profile_default = NO_SELECTION_ENTRY if self.host.options.profile else self.host.bridge.getProfileName("@DEFAULT@") |
80 if profile_default: | 83 if profile_default: |
81 self.profile_name.SetValue(profile_default) | 84 self.profile_name.SetValue(profile_default) |
82 self.onProfileChange(None) | 85 self.onProfileChange(None) |
83 | 86 |
84 def __refillProfiles(self): | 87 def __refillProfiles(self): |
85 """Update profiles with current names. Must be called after a profile change""" | 88 """Update profiles with current names. Must be called after a profile change""" |
86 self.profile_name.Clear() | 89 self.profile_name.Clear() |
87 profiles = self.host.bridge.getProfilesList() | 90 profiles = self.host.bridge.getProfilesList() |
88 profiles.sort() | 91 profiles.sort() |
92 self.profile_name.Append(NO_SELECTION_ENTRY) | |
89 for profile in profiles: | 93 for profile in profiles: |
90 self.profile_name.Append(profile) | 94 self.profile_name.Append(profile) |
91 | |
92 | 95 |
93 def onNewProfile(self, event): | 96 def onNewProfile(self, event): |
94 dlg = wx.TextEntryDialog(self, _("Please enter the new profile name"), _("New profile"), style = wx.OK | wx.CANCEL) | 97 dlg = wx.TextEntryDialog(self, _("Please enter the new profile name"), _("New profile"), style = wx.OK | wx.CANCEL) |
95 if dlg.ShowModal() == wx.ID_OK: | 98 if dlg.ShowModal() == wx.ID_OK: |
96 name = dlg.GetValue() | 99 name = dlg.GetValue() |
99 wx.MessageDialog(self, _("A profile name can't start with a @"), _("Bad profile name"), wx.ICON_ERROR).ShowModal() | 102 wx.MessageDialog(self, _("A profile name can't start with a @"), _("Bad profile name"), wx.ICON_ERROR).ShowModal() |
100 else: | 103 else: |
101 def cb(): | 104 def cb(): |
102 self.__refillProfiles() | 105 self.__refillProfiles() |
103 self.profile_name.SetValue(name) | 106 self.profile_name.SetValue(name) |
107 self.selected_profile = name | |
108 self.getXMPPParams(name) | |
104 self.host.bridge.asyncCreateProfile(name, callback=cb) | 109 self.host.bridge.asyncCreateProfile(name, callback=cb) |
105 dlg.Destroy() | 110 dlg.Destroy() |
106 | 111 |
107 def onDeleteProfile(self, event): | 112 def onDeleteProfile(self, event): |
108 name = self.profile_name.GetValue() | 113 name = self.profile_name.GetValue() |
114 self.__refillProfiles() | 119 self.__refillProfiles() |
115 self.__setDefault() | 120 self.__setDefault() |
116 self.host.bridge.asyncDeleteProfile(name, callback=cb) | 121 self.host.bridge.asyncDeleteProfile(name, callback=cb) |
117 dlg.Destroy() | 122 dlg.Destroy() |
118 | 123 |
124 def getXMPPParams(self, profile): | |
125 """This is called from MainWindow.launchAction when the profile has been authenticated. | |
126 | |
127 @param profile: %(doc_profile)s | |
128 """ | |
129 def setJID(jabberID): | |
130 self.login_jid.SetValue(jabberID) | |
131 | |
132 def setPassword(password): | |
133 self.login_pass.SetValue(password) | |
134 | |
135 self.profile_name.SetValue(profile) | |
136 self.selected_profile = profile | |
137 self.host.bridge.asyncGetParamA("JabberID", "Connection", profile_key=profile, callback=setJID, errback=self.getParamError) | |
138 self.host.bridge.asyncGetParamA("Password", "Connection", profile_key=profile, callback=setPassword, errback=self.getParamError) | |
139 | |
119 def onProfileChange(self, event): | 140 def onProfileChange(self, event): |
120 """Called when a profile is choosen in the combo box""" | 141 """Called when a profile is choosen in the combo box""" |
121 def setJID(jabberID): | 142 profile_name = self.profile_name.GetValue() |
122 self.login_jid.SetValue(jabberID) | 143 if not profile_name or profile_name == self.selected_profile: |
123 def setPassword(password): | 144 return # avoid infinite loop |
124 self.login_pass.SetValue(password) | 145 if profile_name == NO_SELECTION_ENTRY: |
125 self.host.bridge.asyncGetParamA("JabberID", "Connection", profile_key=self.profile_name.GetValue(), callback=setJID, errback=self.getParamError) | 146 self.selected_profile = NO_SELECTION_ENTRY |
126 self.host.bridge.asyncGetParamA("Password", "Connection", profile_key=self.profile_name.GetValue(), callback=setPassword, errback=self.getParamError) | 147 return |
148 if self.selected_profile: | |
149 self.profile_name.SetValue(self.selected_profile) | |
150 self.host.profile = profile_name # FIXME: EXTREMELY DIRTY, needed for sat_frontends.tools.xmlui.XMLUI._xmluiLaunchAction | |
151 self.host.launchAction(C.AUTHENTICATE_PROFILE_ID, {'caller': 'profile_manager'}, profile_key=profile_name) | |
127 | 152 |
128 def onConnectButton(self, event): | 153 def onConnectButton(self, event): |
129 """Called when the Connect button is pressed""" | 154 """Called when the Connect button is pressed""" |
130 name = self.profile_name.GetValue() | 155 name = self.profile_name.GetValue() |
131 if not name: | 156 assert(name == self.selected_profile) # if not, there's a bug somewhere... |
157 if not name or name == NO_SELECTION_ENTRY: | |
132 wx.MessageDialog(self, _("You must select a profile or create a new one before connecting"), _("No profile selected"), wx.ICON_ERROR).ShowModal() | 158 wx.MessageDialog(self, _("You must select a profile or create a new one before connecting"), _("No profile selected"), wx.ICON_ERROR).ShowModal() |
133 return | 159 return |
134 if name[0]=='@': | 160 if name[0]=='@': |
135 wx.MessageDialog(self, _("A profile name can't start with a @"), _("Bad profile name"), wx.ICON_ERROR).ShowModal() | 161 wx.MessageDialog(self, _("A profile name can't start with a @"), _("Bad profile name"), wx.ICON_ERROR).ShowModal() |
136 return | 162 return |