Mercurial > libervia-backend
annotate frontends/src/wix/profile_manager.py @ 555:1d58758689e9
primitivus, wix: fixed bad defaults values for XMLUI class
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 09 Dec 2012 23:25:51 +0100 |
parents | 6970ab58b020 |
children | ca13633d3b6b |
rev | line source |
---|---|
68 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 wix: a SAT frontend | |
459 | 6 Copyright (C) 2009, 2010, 2011, 2012 Jérôme Poisson (goffi@goffi.org) |
68 | 7 |
8 This program is free software: you can redistribute it and/or modify | |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
9 it under the terms of the GNU Affero General Public License as published by |
68 | 10 the Free Software Foundation, either version 3 of the License, or |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
16 GNU Affero General Public License for more details. |
68 | 17 |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
18 You should have received a copy of the GNU Affero General Public License |
68 | 19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 """ | |
21 | |
22 | |
23 | |
24 import wx | |
25 import pdb | |
26 from logging import debug, info, error | |
225
fd9b7834d98a
distutils installation script, draft
Goffi <goffi@goffi.org>
parents:
223
diff
changeset
|
27 from sat.tools.jid import JID |
68 | 28 import pdb |
29 | |
30 | |
31 class ProfileManager(wx.Panel): | |
32 def __init__(self, host): | |
33 super(ProfileManager, self).__init__(host) | |
34 self.host = host | |
35 | |
36 #self.sizer = wx.FlexGridSizer(cols=2) | |
37 self.sizer = wx.BoxSizer(wx.VERTICAL) | |
38 self.SetSizer(self.sizer) | |
39 | |
40 profiles = self.host.bridge.getProfilesList() | |
41 self.profile_name = wx.ComboBox(self, -1, style=wx.CB_READONLY|wx.CB_SORT) | |
42 self.__refillProfiles() | |
43 self.Bind(wx.EVT_COMBOBOX, self.onProfileChange) | |
44 self.panel_id = wx | |
45 | |
46 self.sizer.Add(wx.Window(self, -1), 1) | |
70 | 47 self.sizer.Add(wx.StaticText(self, -1, _("Profile:")), 0, flag=wx.ALIGN_CENTER) |
68 | 48 self.sizer.Add(self.profile_name, 0, flag=wx.ALIGN_CENTER) |
49 button_panel = wx.Panel(self) | |
50 button_panel.sizer = wx.BoxSizer(wx.HORIZONTAL) | |
51 button_panel.SetSizer(button_panel.sizer) | |
70 | 52 button_new = wx.Button(button_panel, -1, _("New")) |
53 button_del = wx.Button(button_panel, -1, _("Delete")) | |
68 | 54 button_panel.sizer.Add(button_new) |
55 button_panel.sizer.Add(button_del) | |
56 self.sizer.Add(button_panel, flag=wx.CENTER) | |
57 self.Bind(wx.EVT_BUTTON, self.onNewProfile, button_new) | |
58 self.Bind(wx.EVT_BUTTON, self.onDeleteProfile, button_del) | |
59 | |
70 | 60 login_box = wx.StaticBox(self, -1, _("Login")) |
68 | 61 self.login_sizer = wx.StaticBoxSizer(login_box, wx.VERTICAL) |
62 self.sizer.Add(self.login_sizer, 1, wx.EXPAND | wx.ALL) | |
63 self.login_jid = wx.TextCtrl(self, -1) | |
64 self.login_sizer.Add(wx.StaticText(self, -1, "JID:"), 0, flag=wx.ALIGN_CENTER) | |
65 self.login_sizer.Add(self.login_jid, flag=wx.EXPAND) | |
66 self.login_pass = wx.TextCtrl(self, -1, style = wx.TE_PASSWORD) | |
70 | 67 self.login_sizer.Add(wx.StaticText(self, -1, _("Password:")), 0, flag=wx.ALIGN_CENTER) |
68 | 68 self.login_sizer.Add(self.login_pass, flag=wx.EXPAND) |
69 | |
70 | 70 loggin_button = wx.Button(self, -1, _("Connect")) |
68 | 71 self.Bind(wx.EVT_BUTTON, self.onConnectButton, loggin_button) |
72 self.login_sizer.Add(loggin_button, flag=wx.ALIGN_CENTER) | |
73 | |
74 self.sizer.Add(wx.Window(self, -1), 1) | |
75 | |
76 #Now we can set the default value | |
77 self.__setDefault() | |
78 | |
79 | |
80 def __setDefault(self): | |
81 profile_default = self.host.bridge.getProfileName("@DEFAULT@") | |
82 if profile_default: | |
83 self.profile_name.SetValue(profile_default) | |
84 self.onProfileChange(None) | |
85 | |
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() | |
91 for profile in profiles: | |
92 self.profile_name.Append(profile) | |
93 | |
94 | |
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: |
103 profile = self.host.bridge.createProfile(name) | |
104 self.__refillProfiles() | |
105 self.profile_name.SetValue(name) | |
106 dlg.Destroy() | |
107 | |
108 def onDeleteProfile(self, event): | |
109 name = self.profile_name.GetValue() | |
110 if not name: | |
111 return | |
70 | 112 dlg = wx.MessageDialog(self, _("Are you sure to delete the profile [%s]") % name, _("Confirmation"), wx.ICON_QUESTION | wx.YES_NO) |
68 | 113 if dlg.ShowModal() == wx.ID_YES: |
114 self.host.bridge.deleteProfile(name) | |
115 self.__refillProfiles() | |
116 self.__setDefault() | |
117 dlg.Destroy() | |
118 | |
119 def onProfileChange(self, event): | |
120 """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
|
121 def setJID(jabberID): |
485a6d125498
Wix: fixed asynchronous call to get profile's data in profile manager
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
122 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
|
123 def setPassword(password): |
485a6d125498
Wix: fixed asynchronous call to get profile's data in profile manager
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
124 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
|
125 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
|
126 self.host.bridge.asyncGetParamA("Password", "Connection", profile_key=self.profile_name.GetValue(), callback=setPassword, errback=self.getParamError) |
68 | 127 |
128 def onConnectButton(self, event): | |
129 """Called when the Connect button is pressed""" | |
130 name = self.profile_name.GetValue() | |
131 if not name: | |
70 | 132 wx.MessageDialog(self, _("You must select a profile or create a new one before connecting"), _("No profile selected"), wx.ICON_ERROR).ShowModal() |
68 | 133 return |
134 if name[0]=='@': | |
70 | 135 wx.MessageDialog(self, _("A profile name can't start with a @"), _("Bad profile name"), wx.ICON_ERROR).ShowModal() |
68 | 136 return |
137 profile = self.host.bridge.getProfileName(name) | |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
72
diff
changeset
|
138 assert(profile) |
552 | 139 |
140 self.host.bridge.asyncGetParamA("JabberID", "Connection", profile_key=profile, callback=lambda old_jid: self.__old_jidReceived(old_jid, profile), errback=self.getParamError) | |
141 | |
142 def __old_jidReceived(self, old_jid, profile): | |
143 self.host.bridge.asyncGetParamA("Password", "Connection", profile_key=profile, callback=lambda old_pass: self.__old_passReceived(old_jid, old_pass, profile), errback=self.getParamError) | |
144 | |
145 def __old_passReceived(self, old_jid, old_pass, profile): | |
68 | 146 new_jid = self.login_jid.GetValue() |
147 new_pass = self.login_pass.GetValue() | |
148 if old_jid != new_jid: | |
72 | 149 debug(_('Saving new JID and server')) |
68 | 150 self.host.bridge.setParam("JabberID", new_jid, "Connection", profile) |
72 | 151 self.host.bridge.setParam("Server", JID(new_jid).domain, "Connection", profile) |
68 | 152 if old_pass != new_pass: |
70 | 153 debug(_('Saving new password')) |
72 | 154 self.host.bridge.setParam("Password", new_pass, "Connection", profile) |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
72
diff
changeset
|
155 self.host.plug_profile(profile) |
68 | 156 |
552 | 157 |
447
485a6d125498
Wix: fixed asynchronous call to get profile's data in profile manager
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
158 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
|
159 wx.MessageDialog(self, _("Can't get profile parameter"), _("Profile error"), wx.ICON_ERROR).ShowModal() |