changeset 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 5197600a1e13
children 35048cafb18d
files frontends/src/wix/main_window.py frontends/src/wix/profile_manager.py
diffstat 2 files changed, 46 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/wix/main_window.py	Wed May 07 16:11:32 2014 +0200
+++ b/frontends/src/wix/main_window.py	Wed May 07 18:16:15 2014 +0200
@@ -103,7 +103,7 @@
 
         self.Show()
 
-    def plug_profile(self, profile_key='@DEFAULT@'):
+    def plug_profile_1(self, profile_key='@DEFAULT@'):
         """Hide profile panel then plug profile"""
         log.debug (_('plugin profile %s' % profile_key))
         self.profile_pan.Hide()
@@ -111,7 +111,7 @@
         self.sizer.Layout()
         for i in range(self.menuBar.GetMenuCount()):
             self.menuBar.EnableTop(i, True)
-        super(MainWindow, self).plug_profile(profile_key)
+        super(MainWindow, self).plug_profile_1(profile_key)
 
     def createMenus(self):
         log.info(_("Creating menus"))
@@ -239,6 +239,15 @@
             elif "xmlui" in data:
                 log.debug (_("XML user interface received"))
                 XMLUI(self, xml_data = data['xmlui'])
+            elif "authenticated_profile" in data:
+                assert("caller" in data)
+                if data["caller"] == "profile_manager":
+                    assert(self.profile_pan.IsShown())
+                    self.profile_pan.getXMPPParams(data['authenticated_profile'])
+                elif data["caller"] == "plug_profile":
+                    self.plug_profile_1(data['authenticated_profile'])
+                else:
+                    raise NotImplementedError
             else:
                 dlg = wx.MessageDialog(self, _(u"Unmanaged action result"),
                                        _('Error'),
--- a/frontends/src/wix/profile_manager.py	Wed May 07 16:11:32 2014 +0200
+++ b/frontends/src/wix/profile_manager.py	Wed May 07 18:16:15 2014 +0200
@@ -20,12 +20,16 @@
 
 
 from sat.core.i18n import _
+from sat_frontends.primitivus.constants import Const as C
 import wx
 from sat.core.log import getLogger
 log = getLogger(__name__)
 from sat.tools.jid  import JID
 
 
+NO_SELECTION_ENTRY = ' '
+
+
 class ProfileManager(wx.Panel):
     def __init__(self, host):
         super(ProfileManager, self).__init__(host)
@@ -35,7 +39,7 @@
         self.sizer = wx.BoxSizer(wx.VERTICAL)
         self.SetSizer(self.sizer)
 
-        profiles = self.host.bridge.getProfilesList()
+        self.selected_profile = NO_SELECTION_ENTRY  # allow to reselect the previous selection until the profile is authenticated
         self.profile_name = wx.ComboBox(self, -1, style=wx.CB_READONLY|wx.CB_SORT)
         self.__refillProfiles()
         self.Bind(wx.EVT_COMBOBOX, self.onProfileChange)
@@ -74,9 +78,8 @@
         #Now we can set the default value
         self.__setDefault()
 
-
     def __setDefault(self):
-        profile_default = self.host.bridge.getProfileName("@DEFAULT@")
+        profile_default = NO_SELECTION_ENTRY if self.host.options.profile else self.host.bridge.getProfileName("@DEFAULT@")
         if profile_default:
             self.profile_name.SetValue(profile_default)
             self.onProfileChange(None)
@@ -86,10 +89,10 @@
         self.profile_name.Clear()
         profiles = self.host.bridge.getProfilesList()
         profiles.sort()
+        self.profile_name.Append(NO_SELECTION_ENTRY)
         for profile in profiles:
             self.profile_name.Append(profile)
 
-
     def onNewProfile(self, event):
         dlg = wx.TextEntryDialog(self, _("Please enter the new profile name"), _("New profile"), style = wx.OK | wx.CANCEL)
         if dlg.ShowModal() == wx.ID_OK:
@@ -101,6 +104,8 @@
                     def cb():
                         self.__refillProfiles()
                         self.profile_name.SetValue(name)
+                        self.selected_profile = name
+                        self.getXMPPParams(name)
                     self.host.bridge.asyncCreateProfile(name, callback=cb)
         dlg.Destroy()
 
@@ -116,19 +121,40 @@
             self.host.bridge.asyncDeleteProfile(name, callback=cb)
         dlg.Destroy()
 
-    def onProfileChange(self, event):
-        """Called when a profile is choosen in the combo box"""
+    def getXMPPParams(self, profile):
+        """This is called from MainWindow.launchAction when the profile has been authenticated.
+
+        @param profile: %(doc_profile)s
+        """
         def setJID(jabberID):
             self.login_jid.SetValue(jabberID)
+
         def setPassword(password):
             self.login_pass.SetValue(password)
-        self.host.bridge.asyncGetParamA("JabberID", "Connection", profile_key=self.profile_name.GetValue(), callback=setJID, errback=self.getParamError)
-        self.host.bridge.asyncGetParamA("Password", "Connection", profile_key=self.profile_name.GetValue(), callback=setPassword, errback=self.getParamError)
+
+        self.profile_name.SetValue(profile)
+        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, event):
+        """Called when a profile is choosen in the combo box"""
+        profile_name = self.profile_name.GetValue()
+        if not profile_name or profile_name == self.selected_profile:
+            return  # avoid infinite loop
+        if profile_name == NO_SELECTION_ENTRY:
+            self.selected_profile = NO_SELECTION_ENTRY
+            return
+        if self.selected_profile:
+            self.profile_name.SetValue(self.selected_profile)
+        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 onConnectButton(self, event):
         """Called when the Connect button is pressed"""
         name = self.profile_name.GetValue()
-        if not name:
+        assert(name == self.selected_profile)  # if not, there's a bug somewhere...
+        if not name or name == NO_SELECTION_ENTRY:
             wx.MessageDialog(self, _("You must select a profile or create a new one before connecting"), _("No profile selected"), wx.ICON_ERROR).ShowModal()
             return
         if name[0]=='@':