Mercurial > libervia-backend
annotate frontends/src/wix/profile_manager.py @ 772:dd07fc737d6c
i18n: merged sat_frontends and sat translations in core's i18n
Translations still need to be updated
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 29 Dec 2013 17:10:10 +0100 |
parents | bfabeedbf32e |
children | 1fe00f0c9a91 |
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 |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013 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 _ |
68 | 23 import wx |
24 import pdb | |
25 from logging import debug, info, error | |
225
fd9b7834d98a
distutils installation script, draft
Goffi <goffi@goffi.org>
parents:
223
diff
changeset
|
26 from sat.tools.jid import JID |
68 | 27 import pdb |
28 | |
29 | |
30 class ProfileManager(wx.Panel): | |
31 def __init__(self, host): | |
32 super(ProfileManager, self).__init__(host) | |
33 self.host = host | |
34 | |
35 #self.sizer = wx.FlexGridSizer(cols=2) | |
36 self.sizer = wx.BoxSizer(wx.VERTICAL) | |
37 self.SetSizer(self.sizer) | |
38 | |
39 profiles = self.host.bridge.getProfilesList() | |
40 self.profile_name = wx.ComboBox(self, -1, style=wx.CB_READONLY|wx.CB_SORT) | |
41 self.__refillProfiles() | |
42 self.Bind(wx.EVT_COMBOBOX, self.onProfileChange) | |
43 self.panel_id = wx | |
44 | |
45 self.sizer.Add(wx.Window(self, -1), 1) | |
70 | 46 self.sizer.Add(wx.StaticText(self, -1, _("Profile:")), 0, flag=wx.ALIGN_CENTER) |
68 | 47 self.sizer.Add(self.profile_name, 0, flag=wx.ALIGN_CENTER) |
48 button_panel = wx.Panel(self) | |
49 button_panel.sizer = wx.BoxSizer(wx.HORIZONTAL) | |
50 button_panel.SetSizer(button_panel.sizer) | |
70 | 51 button_new = wx.Button(button_panel, -1, _("New")) |
52 button_del = wx.Button(button_panel, -1, _("Delete")) | |
68 | 53 button_panel.sizer.Add(button_new) |
54 button_panel.sizer.Add(button_del) | |
55 self.sizer.Add(button_panel, flag=wx.CENTER) | |
56 self.Bind(wx.EVT_BUTTON, self.onNewProfile, button_new) | |
57 self.Bind(wx.EVT_BUTTON, self.onDeleteProfile, button_del) | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
58 |
70 | 59 login_box = wx.StaticBox(self, -1, _("Login")) |
68 | 60 self.login_sizer = wx.StaticBoxSizer(login_box, wx.VERTICAL) |
61 self.sizer.Add(self.login_sizer, 1, wx.EXPAND | wx.ALL) | |
62 self.login_jid = wx.TextCtrl(self, -1) | |
63 self.login_sizer.Add(wx.StaticText(self, -1, "JID:"), 0, flag=wx.ALIGN_CENTER) | |
64 self.login_sizer.Add(self.login_jid, flag=wx.EXPAND) | |
65 self.login_pass = wx.TextCtrl(self, -1, style = wx.TE_PASSWORD) | |
70 | 66 self.login_sizer.Add(wx.StaticText(self, -1, _("Password:")), 0, flag=wx.ALIGN_CENTER) |
68 | 67 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
|
68 |
70 | 69 loggin_button = wx.Button(self, -1, _("Connect")) |
68 | 70 self.Bind(wx.EVT_BUTTON, self.onConnectButton, loggin_button) |
71 self.login_sizer.Add(loggin_button, flag=wx.ALIGN_CENTER) | |
72 | |
73 self.sizer.Add(wx.Window(self, -1), 1) | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
74 |
68 | 75 #Now we can set the default value |
76 self.__setDefault() | |
77 | |
78 | |
79 def __setDefault(self): | |
80 profile_default = self.host.bridge.getProfileName("@DEFAULT@") | |
81 if profile_default: | |
82 self.profile_name.SetValue(profile_default) | |
83 self.onProfileChange(None) | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
84 |
68 | 85 def __refillProfiles(self): |
86 """Update profiles with current names. Must be called after a profile change""" | |
87 self.profile_name.Clear() | |
88 profiles = self.host.bridge.getProfilesList() | |
89 profiles.sort() | |
90 for profile in profiles: | |
91 self.profile_name.Append(profile) | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
92 |
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
93 |
68 | 94 def onNewProfile(self, event): |
70 | 95 dlg = wx.TextEntryDialog(self, _("Please enter the new profile name"), _("New profile"), style = wx.OK | wx.CANCEL) |
68 | 96 if dlg.ShowModal() == wx.ID_OK: |
97 name = dlg.GetValue() | |
98 if name: | |
99 if name[0]=='@': | |
70 | 100 wx.MessageDialog(self, _("A profile name can't start with a @"), _("Bad profile name"), wx.ICON_ERROR).ShowModal() |
68 | 101 else: |
102 profile = self.host.bridge.createProfile(name) | |
103 self.__refillProfiles() | |
104 self.profile_name.SetValue(name) | |
105 dlg.Destroy() | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
106 |
68 | 107 def onDeleteProfile(self, event): |
108 name = self.profile_name.GetValue() | |
109 if not name: | |
110 return | |
70 | 111 dlg = wx.MessageDialog(self, _("Are you sure to delete the profile [%s]") % name, _("Confirmation"), wx.ICON_QUESTION | wx.YES_NO) |
68 | 112 if dlg.ShowModal() == wx.ID_YES: |
113 self.host.bridge.deleteProfile(name) | |
114 self.__refillProfiles() | |
115 self.__setDefault() | |
116 dlg.Destroy() | |
117 | |
118 def onProfileChange(self, event): | |
119 """Called when a profile is choosen in the combo box""" | |
447
485a6d125498
Wix: fixed asynchronous call to get profile's data in profile manager
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
120 def setJID(jabberID): |
485a6d125498
Wix: fixed asynchronous call to get profile's data in profile manager
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
121 self.login_jid.SetValue(jabberID) |
485a6d125498
Wix: fixed asynchronous call to get profile's data in profile manager
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
122 def setPassword(password): |
485a6d125498
Wix: fixed asynchronous call to get profile's data in profile manager
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
123 self.login_pass.SetValue(password) |
485a6d125498
Wix: fixed asynchronous call to get profile's data in profile manager
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
124 self.host.bridge.asyncGetParamA("JabberID", "Connection", profile_key=self.profile_name.GetValue(), callback=setJID, errback=self.getParamError) |
485a6d125498
Wix: fixed asynchronous call to get profile's data in profile manager
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
125 self.host.bridge.asyncGetParamA("Password", "Connection", profile_key=self.profile_name.GetValue(), callback=setPassword, errback=self.getParamError) |
68 | 126 |
127 def onConnectButton(self, event): | |
128 """Called when the Connect button is pressed""" | |
129 name = self.profile_name.GetValue() | |
130 if not name: | |
70 | 131 wx.MessageDialog(self, _("You must select a profile or create a new one before connecting"), _("No profile selected"), wx.ICON_ERROR).ShowModal() |
68 | 132 return |
133 if name[0]=='@': | |
70 | 134 wx.MessageDialog(self, _("A profile name can't start with a @"), _("Bad profile name"), wx.ICON_ERROR).ShowModal() |
68 | 135 return |
136 profile = self.host.bridge.getProfileName(name) | |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
72
diff
changeset
|
137 assert(profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
138 |
552 | 139 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
|
140 |
552 | 141 def __old_jidReceived(self, old_jid, profile): |
142 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
|
143 |
552 | 144 def __old_passReceived(self, old_jid, old_pass, profile): |
68 | 145 new_jid = self.login_jid.GetValue() |
146 new_pass = self.login_pass.GetValue() | |
147 if old_jid != new_jid: | |
72 | 148 debug(_('Saving new JID and server')) |
641
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
149 self.host.bridge.setParam("JabberID", new_jid, "Connection", profile_key=profile) |
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
150 self.host.bridge.setParam("Server", JID(new_jid).domain, "Connection", profile_key=profile) |
68 | 151 if old_pass != new_pass: |
70 | 152 debug(_('Saving new password')) |
641
49587e170f53
core: added the security_limit to setParam
souliane <souliane@mailoo.org>
parents:
609
diff
changeset
|
153 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
|
154 self.host.plug_profile(profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
155 |
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
156 |
447
485a6d125498
Wix: fixed asynchronous call to get profile's data in profile manager
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
157 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
|
158 wx.MessageDialog(self, _("Can't get profile parameter"), _("Profile error"), wx.ICON_ERROR).ShowModal() |