Mercurial > libervia-backend
annotate frontends/primitivus/profile_manager.py @ 127:55d3ef84f01f
Primitivus: mouse wheel changed to 'up' and 'down' key press
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 12 Jul 2010 18:55:27 +0800 |
parents | ded2431cea5a |
children | 2240f34f6452 |
rev | line source |
---|---|
112 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 Primitivus: a SAT frontend | |
6 Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org) | |
7 | |
8 This program is free software: you can redistribute it and/or modify | |
9 it under the terms of the GNU General Public License as published by | |
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 | |
16 GNU General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 """ | |
21 | |
22 import urwid | |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
117
diff
changeset
|
23 from custom_widgets import Password,List,InputDialog,ConfirmDialog,Alert,FocusFrame |
112 | 24 |
25 | |
26 class ProfileManager(urwid.WidgetWrap): | |
27 | |
28 def __init__(self, host): | |
29 self.host = host | |
113 | 30 #profiles list |
112 | 31 profiles = self.host.bridge.getProfilesList() |
113 | 32 profiles.sort() |
33 | |
34 #login & password box must be created before list because of onProfileChange | |
35 self.login_wid = urwid.Edit(_('Login:'),align='center') | |
36 self.pass_wid = Password(_('Password:'),align='center') | |
37 | |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
117
diff
changeset
|
38 self.list_profile = List(profiles, style=['single'], align='center', on_click=self.onProfileChange) |
113 | 39 |
40 #toto = urwid.Padding(urwid.Text('toto'), align='center') | |
41 | |
42 #new & delete buttons | |
43 buttons = [urwid.Button(_("New"), self.onNewProfile), | |
44 urwid.Button(_("Delete"), self.onDeleteProfile)] | |
45 buttons_flow = urwid.GridFlow(buttons, max([len(button.get_label()) for button in buttons])+4, 1, 1, 'center') | |
46 | |
47 #second part: login information: | |
48 divider = urwid.Divider('-') | |
49 | |
50 #connect button | |
51 connect_button = urwid.Button(_("Connect"), self.onConnectProfile) | |
52 | |
53 #we now build the widget | |
54 body_content = urwid.SimpleListWalker([buttons_flow,self.list_profile,divider,self.login_wid, self.pass_wid, connect_button]) | |
55 frame_body = urwid.ListBox(body_content) | |
115
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
56 frame = urwid.Frame(frame_body,urwid.AttrMap(urwid.Text(_("Profile Manager"),align='center'),'title')) |
113 | 57 self.main_widget = urwid.LineBox(frame) |
58 urwid.WidgetWrap.__init__(self, self.main_widget) | |
59 | |
60 def __refillProfiles(self): | |
61 """Update the list of profiles""" | |
62 profiles = self.host.bridge.getProfilesList() | |
63 profiles.sort() | |
64 self.list_profile.changeValues(profiles) | |
112 | 65 |
113 | 66 def cancelDialog(self, button): |
117 | 67 self.host.removePopUp() |
113 | 68 |
69 def newProfile(self, button, edit): | |
70 name = edit.get_edit_text() | |
71 self.host.bridge.createProfile(name) | |
72 self.__refillProfiles() | |
73 self.list_profile.selectValue(name) | |
117 | 74 self.host.removePopUp() |
113 | 75 |
76 def deleteProfile(self, button): | |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
117
diff
changeset
|
77 profile_name = self.list_profile.getSelectedValue() |
115
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
78 if profile_name: |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
79 self.host.bridge.deleteProfile(profile_name) |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
80 self.__refillProfiles() |
117 | 81 self.host.removePopUp() |
113 | 82 |
83 | |
84 def onNewProfile(self, e): | |
85 pop_up_widget = InputDialog(_("New profile"), _("Please enter a new profile name"), cancel_cb=self.cancelDialog, ok_cb=self.newProfile) | |
117 | 86 self.host.showPopUp(pop_up_widget) |
113 | 87 |
88 def onDeleteProfile(self, e): | |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
117
diff
changeset
|
89 pop_up_widget = ConfirmDialog(_("Are you sure you want to delete the profile %s ?") % self.list_profile.getSelectedValue(), no_cb=self.cancelDialog, yes_cb=self.deleteProfile) |
117 | 90 self.host.showPopUp(pop_up_widget) |
113 | 91 |
92 def onProfileChange(self, list_wid): | |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
117
diff
changeset
|
93 profile_name = list_wid.getSelectedValue() |
115
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
94 if profile_name: |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
95 jabberID = self.host.bridge.getParamA("JabberID", "Connection", profile_key=profile_name) |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
96 password = self.host.bridge.getParamA("Password", "Connection", profile_key=profile_name) |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
97 self.login_wid.set_edit_text(jabberID) |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
98 self.pass_wid.set_edit_text(password) |
113 | 99 |
100 def onConnectProfile(self, button): | |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
117
diff
changeset
|
101 profile_name = self.list_profile.getSelectedValue() |
115
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
102 if not profile_name: |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
103 pop_up_widget = Alert(_('No profile selected'), _('You need to create and select a profile before connecting'), ok_cb=self.cancelDialog) |
117 | 104 self.host.showPopUp(pop_up_widget) |
115
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
105 elif profile_name[0] == '@': |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
106 pop_up_widget = Alert(_('Bad profile name'), _("A profile name can't start with a @"), ok_cb=self.cancelDialog) |
117 | 107 self.host.showPopUp(pop_up_widget) |
115
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
108 else: |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
109 profile = self.host.bridge.getProfileName(profile_name) |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
110 assert(profile) |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
111 #TODO: move this to quick_app |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
112 old_jid = self.host.bridge.getParamA("JabberID", "Connection", profile_key=profile) |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
113 old_pass = self.host.bridge.getParamA("Password", "Connection", profile_key=profile) |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
114 new_jid = self.login_wid.get_edit_text() |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
115 new_pass = self.pass_wid.get_edit_text() |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
116 |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
117 if old_jid != new_jid: |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
118 self.host.bridge.setParam("JabberID", new_jid, "Connection", profile) |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
119 self.host.bridge.setParam("Server", JID(new_jid).domain, "Connection", profile) |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
120 if old_pass != new_pass: |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
121 self.host.bridge.setParam("Password", new_pass, "Connection", profile) |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
122 self.host.plug_profile(profile) |
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
123 |