comparison frontends/primitivus/profile_manager.py @ 115:eed4f77c942e

primitivus: Profile Manager should now be fully fonctionnal
author Goffi <goffi@goffi.org>
date Thu, 01 Jul 2010 18:19:20 +0800
parents e5ca22113280
children 1f0fd6f03e2b
comparison
equal deleted inserted replaced
114:77f48939ad6e 115:eed4f77c942e
18 You should have received a copy of the GNU General Public License 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/>. 19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """ 20 """
21 21
22 import urwid 22 import urwid
23 from custom_widgets import Password,List,InputDialog,ConfirmDialog 23 from custom_widgets import Password,List,InputDialog,ConfirmDialog,Alert
24 24
25 25
26 class ProfileManager(urwid.WidgetWrap): 26 class ProfileManager(urwid.WidgetWrap):
27 27
28 def __init__(self, host): 28 def __init__(self, host):
51 connect_button = urwid.Button(_("Connect"), self.onConnectProfile) 51 connect_button = urwid.Button(_("Connect"), self.onConnectProfile)
52 52
53 #we now build the widget 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]) 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) 55 frame_body = urwid.ListBox(body_content)
56 frame = urwid.Frame(frame_body,urwid.AttrMap(urwid.Text("Profile Manager",align='center'),'title')) 56 frame = urwid.Frame(frame_body,urwid.AttrMap(urwid.Text(_("Profile Manager"),align='center'),'title'))
57 self.main_widget = urwid.LineBox(frame) 57 self.main_widget = urwid.LineBox(frame)
58 urwid.WidgetWrap.__init__(self, self.main_widget) 58 urwid.WidgetWrap.__init__(self, self.main_widget)
59 59
60 def __refillProfiles(self): 60 def __refillProfiles(self):
61 """Update the list of profiles""" 61 """Update the list of profiles"""
62 profiles = self.host.bridge.getProfilesList() 62 profiles = self.host.bridge.getProfilesList()
63 profiles.sort() 63 profiles.sort()
64 self.list_profile.changeValues(profiles) 64 self.list_profile.changeValues(profiles)
65
66 def __showPopUp(self, pop_up_widget):
67 display_widget = urwid.Overlay(pop_up_widget, self.main_widget, 'center', ('relative', 40), 'middle', ('relative', 40))
68 self._set_w(display_widget)
65 69
66 def cancelDialog(self, button): 70 def cancelDialog(self, button):
67 self._set_w(self.main_widget) 71 self._set_w(self.main_widget)
68 72
69 def newProfile(self, button, edit): 73 def newProfile(self, button, edit):
73 self.__refillProfiles() 77 self.__refillProfiles()
74 self.list_profile.selectValue(name) 78 self.list_profile.selectValue(name)
75 79
76 def deleteProfile(self, button): 80 def deleteProfile(self, button):
77 self._set_w(self.main_widget) 81 self._set_w(self.main_widget)
78 self.host.bridge.deleteProfile(self.list_profile.getValues()[0]) 82 profile_name = self.list_profile.getValue()
79 self.__refillProfiles() 83 if profile_name:
84 self.host.bridge.deleteProfile(profile_name)
85 self.__refillProfiles()
80 86
81 87
82 def onNewProfile(self, e): 88 def onNewProfile(self, e):
83 pop_up_widget = InputDialog(_("New profile"), _("Please enter a new profile name"), cancel_cb=self.cancelDialog, ok_cb=self.newProfile) 89 pop_up_widget = InputDialog(_("New profile"), _("Please enter a new profile name"), cancel_cb=self.cancelDialog, ok_cb=self.newProfile)
84 display_widget = urwid.Overlay(pop_up_widget, self.main_widget, 'center', ('relative', 40), 'middle', ('relative', 40)) 90 self.__showPopUp(pop_up_widget)
85 self._set_w(display_widget)
86 91
87 def onDeleteProfile(self, e): 92 def onDeleteProfile(self, e):
88 pop_up_widget = ConfirmDialog(_("Are you sure you want to delete the profile %s ?") % self.list_profile.getValues()[0], no_cb=self.cancelDialog, yes_cb=self.deleteProfile) 93 pop_up_widget = ConfirmDialog(_("Are you sure you want to delete the profile %s ?") % self.list_profile.getValue(), no_cb=self.cancelDialog, yes_cb=self.deleteProfile)
89 display_widget = urwid.Overlay(pop_up_widget, self.main_widget, 'center', ('relative', 40), 'middle', ('relative', 40)) 94 self.__showPopUp(pop_up_widget)
90 self._set_w(display_widget)
91 95
92 def onProfileChange(self, list_wid): 96 def onProfileChange(self, list_wid):
93 profile_name = list_wid.getValues()[0] 97 profile_name = list_wid.getValue()
94 jabberID = self.host.bridge.getParamA("JabberID", "Connection", profile_key=profile_name) 98 if profile_name:
95 password = self.host.bridge.getParamA("Password", "Connection", profile_key=profile_name) 99 jabberID = self.host.bridge.getParamA("JabberID", "Connection", profile_key=profile_name)
96 self.login_wid.set_edit_text(jabberID) 100 password = self.host.bridge.getParamA("Password", "Connection", profile_key=profile_name)
97 self.pass_wid.set_edit_text(password) 101 self.login_wid.set_edit_text(jabberID)
102 self.pass_wid.set_edit_text(password)
98 103
99 def onConnectProfile(self, button): 104 def onConnectProfile(self, button):
100 pass 105 profile_name = self.list_profile.getValue()
106 if not profile_name:
107 pop_up_widget = Alert(_('No profile selected'), _('You need to create and select a profile before connecting'), ok_cb=self.cancelDialog)
108 self.__showPopUp(pop_up_widget)
109 elif profile_name[0] == '@':
110 pop_up_widget = Alert(_('Bad profile name'), _("A profile name can't start with a @"), ok_cb=self.cancelDialog)
111 self.__showPopUp(pop_up_widget)
112 else:
113 profile = self.host.bridge.getProfileName(profile_name)
114 assert(profile)
115 #TODO: move this to quick_app
116 old_jid = self.host.bridge.getParamA("JabberID", "Connection", profile_key=profile)
117 old_pass = self.host.bridge.getParamA("Password", "Connection", profile_key=profile)
118 new_jid = self.login_wid.get_edit_text()
119 new_pass = self.pass_wid.get_edit_text()
120
121 if old_jid != new_jid:
122 self.host.bridge.setParam("JabberID", new_jid, "Connection", profile)
123 self.host.bridge.setParam("Server", JID(new_jid).domain, "Connection", profile)
124 if old_pass != new_pass:
125 self.host.bridge.setParam("Password", new_pass, "Connection", profile)
126 self.host.plug_profile(profile)
127