annotate frontends/src/wix/profile_manager.py @ 495:a726b234d3bf

primitivus: moved constants in a separate file
author Goffi <goffi@goffi.org>
date Mon, 03 Sep 2012 23:43:15 +0200
parents 2a072735e459
children 6970ab58b020
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
3
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
5 wix: a SAT frontend
459
cf005701624b copyleft date update
Goffi <goffi@goffi.org>
parents: 447
diff changeset
6 Copyright (C) 2009, 2010, 2011, 2012 Jérôme Poisson (goffi@goffi.org)
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
7
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
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
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
12
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
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
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
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
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
21
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
22
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
23
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
24 import wx
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
25 import pdb
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
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
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
28 import pdb
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
29
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
30
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
31 class ProfileManager(wx.Panel):
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
32 def __init__(self, host):
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
33 super(ProfileManager, self).__init__(host)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
34 self.host = host
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
35
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
36 #self.sizer = wx.FlexGridSizer(cols=2)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
37 self.sizer = wx.BoxSizer(wx.VERTICAL)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
38 self.SetSizer(self.sizer)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
39
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
40 profiles = self.host.bridge.getProfilesList()
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
41 self.profile_name = wx.ComboBox(self, -1, style=wx.CB_READONLY|wx.CB_SORT)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
42 self.__refillProfiles()
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
43 self.Bind(wx.EVT_COMBOBOX, self.onProfileChange)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
44 self.panel_id = wx
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
45
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
46 self.sizer.Add(wx.Window(self, -1), 1)
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
47 self.sizer.Add(wx.StaticText(self, -1, _("Profile:")), 0, flag=wx.ALIGN_CENTER)
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
48 self.sizer.Add(self.profile_name, 0, flag=wx.ALIGN_CENTER)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
49 button_panel = wx.Panel(self)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
50 button_panel.sizer = wx.BoxSizer(wx.HORIZONTAL)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
51 button_panel.SetSizer(button_panel.sizer)
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
52 button_new = wx.Button(button_panel, -1, _("New"))
Goffi <goffi@goffi.org>
parents: 68
diff changeset
53 button_del = wx.Button(button_panel, -1, _("Delete"))
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
54 button_panel.sizer.Add(button_new)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
55 button_panel.sizer.Add(button_del)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
56 self.sizer.Add(button_panel, flag=wx.CENTER)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
57 self.Bind(wx.EVT_BUTTON, self.onNewProfile, button_new)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
58 self.Bind(wx.EVT_BUTTON, self.onDeleteProfile, button_del)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
59
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
60 login_box = wx.StaticBox(self, -1, _("Login"))
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
61 self.login_sizer = wx.StaticBoxSizer(login_box, wx.VERTICAL)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
62 self.sizer.Add(self.login_sizer, 1, wx.EXPAND | wx.ALL)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
63 self.login_jid = wx.TextCtrl(self, -1)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
64 self.login_sizer.Add(wx.StaticText(self, -1, "JID:"), 0, flag=wx.ALIGN_CENTER)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
65 self.login_sizer.Add(self.login_jid, flag=wx.EXPAND)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
66 self.login_pass = wx.TextCtrl(self, -1, style = wx.TE_PASSWORD)
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
67 self.login_sizer.Add(wx.StaticText(self, -1, _("Password:")), 0, flag=wx.ALIGN_CENTER)
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
68 self.login_sizer.Add(self.login_pass, flag=wx.EXPAND)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
69
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
70 loggin_button = wx.Button(self, -1, _("Connect"))
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
71 self.Bind(wx.EVT_BUTTON, self.onConnectButton, loggin_button)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
72 self.login_sizer.Add(loggin_button, flag=wx.ALIGN_CENTER)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
73
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
74 self.sizer.Add(wx.Window(self, -1), 1)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
75
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
76 #Now we can set the default value
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
77 self.__setDefault()
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
78
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
79
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
80 def __setDefault(self):
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
81 profile_default = self.host.bridge.getProfileName("@DEFAULT@")
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
82 if profile_default:
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
83 self.profile_name.SetValue(profile_default)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
84 self.onProfileChange(None)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
85
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
86 def __refillProfiles(self):
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
87 """Update profiles with current names. Must be called after a profile change"""
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
88 self.profile_name.Clear()
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
89 profiles = self.host.bridge.getProfilesList()
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
90 profiles.sort()
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
91 for profile in profiles:
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
92 self.profile_name.Append(profile)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
93
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
94
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
95 def onNewProfile(self, event):
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
96 dlg = wx.TextEntryDialog(self, _("Please enter the new profile name"), _("New profile"), style = wx.OK | wx.CANCEL)
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
97 if dlg.ShowModal() == wx.ID_OK:
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
98 name = dlg.GetValue()
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
99 if name:
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
100 if name[0]=='@':
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
101 wx.MessageDialog(self, _("A profile name can't start with a @"), _("Bad profile name"), wx.ICON_ERROR).ShowModal()
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
102 else:
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
103 profile = self.host.bridge.createProfile(name)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
104 self.__refillProfiles()
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
105 self.profile_name.SetValue(name)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
106 dlg.Destroy()
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
107
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
108 def onDeleteProfile(self, event):
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
109 name = self.profile_name.GetValue()
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
110 if not name:
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
111 return
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
112 dlg = wx.MessageDialog(self, _("Are you sure to delete the profile [%s]") % name, _("Confirmation"), wx.ICON_QUESTION | wx.YES_NO)
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
113 if dlg.ShowModal() == wx.ID_YES:
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
114 self.host.bridge.deleteProfile(name)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
115 self.__refillProfiles()
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
116 self.__setDefault()
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
117 dlg.Destroy()
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
118
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
119 def onProfileChange(self, event):
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
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
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
127
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
128 def onConnectButton(self, event):
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
129 """Called when the Connect button is pressed"""
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
130 name = self.profile_name.GetValue()
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
131 if not name:
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
132 wx.MessageDialog(self, _("You must select a profile or create a new one before connecting"), _("No profile selected"), wx.ICON_ERROR).ShowModal()
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
133 return
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
134 if name[0]=='@':
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
135 wx.MessageDialog(self, _("A profile name can't start with a @"), _("Bad profile name"), wx.ICON_ERROR).ShowModal()
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
136 return
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
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)
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
139 old_jid = self.host.bridge.getParamA("JabberID", "Connection", profile_key=profile)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
140 old_pass = self.host.bridge.getParamA("Password", "Connection", profile_key=profile)
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
141 new_jid = self.login_jid.GetValue()
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
142 new_pass = self.login_pass.GetValue()
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
143 if old_jid != new_jid:
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
144 debug(_('Saving new JID and server'))
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
145 self.host.bridge.setParam("JabberID", new_jid, "Connection", profile)
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
146 self.host.bridge.setParam("Server", JID(new_jid).domain, "Connection", profile)
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
147 if old_pass != new_pass:
70
Goffi <goffi@goffi.org>
parents: 68
diff changeset
148 debug(_('Saving new password'))
72
f271fff3a713 MUC implementation: first draft
Goffi <goffi@goffi.org>
parents: 70
diff changeset
149 self.host.bridge.setParam("Password", new_pass, "Connection", profile)
89
23caf1051099 multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents: 72
diff changeset
150 self.host.plug_profile(profile)
68
9b842086d915 multiple profiles update
Goffi <goffi@goffi.org>
parents:
diff changeset
151
447
485a6d125498 Wix: fixed asynchronous call to get profile's data in profile manager
Goffi <goffi@goffi.org>
parents: 228
diff changeset
152 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
153 wx.MessageDialog(self, _("Can't get profile parameter"), _("Profile error"), wx.ICON_ERROR).ShowModal()