Mercurial > libervia-backend
annotate frontends/src/wix/profile_manager.py @ 1111:9344e4542f26
core (constants): removed pyjamas workaround
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 20 Aug 2014 22:59:33 +0200 |
parents | e2e1e27a3680 |
children |
rev | line source |
---|---|
68 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
4 # wix: a SAT frontend |
811 | 5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org) |
68 | 6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
10 # (at your option) any later version. |
68 | 11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
15 # GNU Affero General Public License for more details. |
68 | 16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
68 | 19 |
20 | |
21 | |
771 | 22 from sat.core.i18n import _ |
1035
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
23 from sat_frontends.primitivus.constants import Const as C |
68 | 24 import wx |
1011 | 25 from sat.core.log import getLogger |
26 log = getLogger(__name__) | |
68 | 27 |
28 | |
1035
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
29 NO_SELECTION_ENTRY = ' ' |
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
30 |
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
31 |
68 | 32 class ProfileManager(wx.Panel): |
33 def __init__(self, host): | |
34 super(ProfileManager, self).__init__(host) | |
35 self.host = host | |
36 | |
37 #self.sizer = wx.FlexGridSizer(cols=2) | |
38 self.sizer = wx.BoxSizer(wx.VERTICAL) | |
39 self.SetSizer(self.sizer) | |
40 | |
1035
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
41 self.selected_profile = NO_SELECTION_ENTRY # allow to reselect the previous selection until the profile is authenticated |
68 | 42 self.profile_name = wx.ComboBox(self, -1, style=wx.CB_READONLY|wx.CB_SORT) |
43 self.__refillProfiles() | |
44 self.Bind(wx.EVT_COMBOBOX, self.onProfileChange) | |
45 self.panel_id = wx | |
46 | |
47 self.sizer.Add(wx.Window(self, -1), 1) | |
70 | 48 self.sizer.Add(wx.StaticText(self, -1, _("Profile:")), 0, flag=wx.ALIGN_CENTER) |
68 | 49 self.sizer.Add(self.profile_name, 0, flag=wx.ALIGN_CENTER) |
50 button_panel = wx.Panel(self) | |
51 button_panel.sizer = wx.BoxSizer(wx.HORIZONTAL) | |
52 button_panel.SetSizer(button_panel.sizer) | |
70 | 53 button_new = wx.Button(button_panel, -1, _("New")) |
54 button_del = wx.Button(button_panel, -1, _("Delete")) | |
68 | 55 button_panel.sizer.Add(button_new) |
56 button_panel.sizer.Add(button_del) | |
57 self.sizer.Add(button_panel, flag=wx.CENTER) | |
58 self.Bind(wx.EVT_BUTTON, self.onNewProfile, button_new) | |
59 self.Bind(wx.EVT_BUTTON, self.onDeleteProfile, button_del) | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
60 |
70 | 61 login_box = wx.StaticBox(self, -1, _("Login")) |
68 | 62 self.login_sizer = wx.StaticBoxSizer(login_box, wx.VERTICAL) |
63 self.sizer.Add(self.login_sizer, 1, wx.EXPAND | wx.ALL) | |
64 self.login_jid = wx.TextCtrl(self, -1) | |
65 self.login_sizer.Add(wx.StaticText(self, -1, "JID:"), 0, flag=wx.ALIGN_CENTER) | |
66 self.login_sizer.Add(self.login_jid, flag=wx.EXPAND) | |
67 self.login_pass = wx.TextCtrl(self, -1, style = wx.TE_PASSWORD) | |
70 | 68 self.login_sizer.Add(wx.StaticText(self, -1, _("Password:")), 0, flag=wx.ALIGN_CENTER) |
68 | 69 self.login_sizer.Add(self.login_pass, flag=wx.EXPAND) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
70 |
70 | 71 loggin_button = wx.Button(self, -1, _("Connect")) |
68 | 72 self.Bind(wx.EVT_BUTTON, self.onConnectButton, loggin_button) |
73 self.login_sizer.Add(loggin_button, flag=wx.ALIGN_CENTER) | |
74 | |
75 self.sizer.Add(wx.Window(self, -1), 1) | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
76 |
68 | 77 #Now we can set the default value |
78 self.__setDefault() | |
79 | |
80 def __setDefault(self): | |
1035
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
81 profile_default = NO_SELECTION_ENTRY if self.host.options.profile else self.host.bridge.getProfileName("@DEFAULT@") |
68 | 82 if profile_default: |
83 self.profile_name.SetValue(profile_default) | |
84 self.onProfileChange(None) | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
85 |
68 | 86 def __refillProfiles(self): |
87 """Update profiles with current names. Must be called after a profile change""" | |
88 self.profile_name.Clear() | |
89 profiles = self.host.bridge.getProfilesList() | |
90 profiles.sort() | |
1035
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
91 self.profile_name.Append(NO_SELECTION_ENTRY) |
68 | 92 for profile in profiles: |
93 self.profile_name.Append(profile) | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
94 |
68 | 95 def onNewProfile(self, event): |
70 | 96 dlg = wx.TextEntryDialog(self, _("Please enter the new profile name"), _("New profile"), style = wx.OK | wx.CANCEL) |
68 | 97 if dlg.ShowModal() == wx.ID_OK: |
98 name = dlg.GetValue() | |
99 if name: | |
100 if name[0]=='@': | |
70 | 101 wx.MessageDialog(self, _("A profile name can't start with a @"), _("Bad profile name"), wx.ICON_ERROR).ShowModal() |
68 | 102 else: |
893
308a96bc7c1b
core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
103 def cb(): |
308a96bc7c1b
core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
104 self.__refillProfiles() |
308a96bc7c1b
core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
105 self.profile_name.SetValue(name) |
1035
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
106 self.selected_profile = name |
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
107 self.getXMPPParams(name) |
893
308a96bc7c1b
core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
108 self.host.bridge.asyncCreateProfile(name, callback=cb) |
68 | 109 dlg.Destroy() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
110 |
68 | 111 def onDeleteProfile(self, event): |
112 name = self.profile_name.GetValue() | |
113 if not name: | |
114 return | |
70 | 115 dlg = wx.MessageDialog(self, _("Are you sure to delete the profile [%s]") % name, _("Confirmation"), wx.ICON_QUESTION | wx.YES_NO) |
68 | 116 if dlg.ShowModal() == wx.ID_YES: |
893
308a96bc7c1b
core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
117 def cb(): |
308a96bc7c1b
core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
118 self.__refillProfiles() |
308a96bc7c1b
core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
119 self.__setDefault() |
308a96bc7c1b
core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
120 self.host.bridge.asyncDeleteProfile(name, callback=cb) |
68 | 121 dlg.Destroy() |
122 | |
1035
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
123 def getXMPPParams(self, profile): |
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
124 """This is called from MainWindow.launchAction when the profile has been authenticated. |
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
125 |
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
126 @param profile: %(doc_profile)s |
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
127 """ |
447
485a6d125498
Wix: fixed asynchronous call to get profile's data in profile manager
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
128 def setJID(jabberID): |
485a6d125498
Wix: fixed asynchronous call to get profile's data in profile manager
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
129 self.login_jid.SetValue(jabberID) |
1035
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
130 |
447
485a6d125498
Wix: fixed asynchronous call to get profile's data in profile manager
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
131 def setPassword(password): |
485a6d125498
Wix: fixed asynchronous call to get profile's data in profile manager
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
132 self.login_pass.SetValue(password) |
1035
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
133 |
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
134 self.profile_name.SetValue(profile) |
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
135 self.selected_profile = profile |
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
136 self.host.bridge.asyncGetParamA("JabberID", "Connection", profile_key=profile, callback=setJID, errback=self.getParamError) |
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
137 self.host.bridge.asyncGetParamA("Password", "Connection", profile_key=profile, callback=setPassword, errback=self.getParamError) |
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
138 |
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
139 def onProfileChange(self, event): |
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
140 """Called when a profile is choosen in the combo box""" |
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
141 profile_name = self.profile_name.GetValue() |
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
142 if not profile_name or profile_name == self.selected_profile: |
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
143 return # avoid infinite loop |
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
144 if profile_name == NO_SELECTION_ENTRY: |
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
145 self.selected_profile = NO_SELECTION_ENTRY |
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
146 return |
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
147 if self.selected_profile: |
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
148 self.profile_name.SetValue(self.selected_profile) |
1106
e2e1e27a3680
frontends: XMLUI refactoring + dialogs:
Goffi <goffi@goffi.org>
parents:
1089
diff
changeset
|
149 self.host.profile = profile_name # FIXME: EXTREMELY DIRTY, needed for sat_frontends.tools.xmlui.XMLUI.submit |
1035
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
150 self.host.launchAction(C.AUTHENTICATE_PROFILE_ID, {'caller': 'profile_manager'}, profile_key=profile_name) |
68 | 151 |
152 def onConnectButton(self, event): | |
153 """Called when the Connect button is pressed""" | |
154 name = self.profile_name.GetValue() | |
1035
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
155 assert(name == self.selected_profile) # if not, there's a bug somewhere... |
c4c14480715a
wix: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1011
diff
changeset
|
156 if not name or name == NO_SELECTION_ENTRY: |
70 | 157 wx.MessageDialog(self, _("You must select a profile or create a new one before connecting"), _("No profile selected"), wx.ICON_ERROR).ShowModal() |
68 | 158 return |
159 if name[0]=='@': | |
70 | 160 wx.MessageDialog(self, _("A profile name can't start with a @"), _("Bad profile name"), wx.ICON_ERROR).ShowModal() |
68 | 161 return |
162 profile = self.host.bridge.getProfileName(name) | |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
72
diff
changeset
|
163 assert(profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
164 |
552 | 165 self.host.bridge.asyncGetParamA("JabberID", "Connection", profile_key=profile, callback=lambda old_jid: self.__old_jidReceived(old_jid, profile), errback=self.getParamError) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
166 |
552 | 167 def __old_jidReceived(self, old_jid, profile): |
168 self.host.bridge.asyncGetParamA("Password", "Connection", profile_key=profile, callback=lambda old_pass: self.__old_passReceived(old_jid, old_pass, profile), errback=self.getParamError) | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
169 |
552 | 170 def __old_passReceived(self, old_jid, old_pass, profile): |
68 | 171 new_jid = self.login_jid.GetValue() |
172 new_pass = self.login_pass.GetValue() | |
173 if old_jid != new_jid: | |
1011 | 174 log.debug(_('Saving new JID and server')) |
641
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
175 self.host.bridge.setParam("JabberID", new_jid, "Connection", profile_key=profile) |
68 | 176 if old_pass != new_pass: |
1011 | 177 log.debug(_('Saving new password')) |
641
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
178 self.host.bridge.setParam("Password", new_pass, "Connection", profile_key=profile) |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
72
diff
changeset
|
179 self.host.plug_profile(profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
180 |
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
181 |
447
485a6d125498
Wix: fixed asynchronous call to get profile's data in profile manager
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
182 def getParamError(self, ignore): |
485a6d125498
Wix: fixed asynchronous call to get profile's data in profile manager
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
183 wx.MessageDialog(self, _("Can't get profile parameter"), _("Profile error"), wx.ICON_ERROR).ShowModal() |