# HG changeset patch # User Goffi # Date 1277979560 -28800 # Node ID eed4f77c942e677219e5f85ede80283e511007aa # Parent 77f48939ad6e83d064c0a05247798fa3922c8e47 primitivus: Profile Manager should now be fully fonctionnal diff -r 77f48939ad6e -r eed4f77c942e frontends/primitivus/profile_manager.py --- a/frontends/primitivus/profile_manager.py Thu Jul 01 18:18:34 2010 +0800 +++ b/frontends/primitivus/profile_manager.py Thu Jul 01 18:19:20 2010 +0800 @@ -20,7 +20,7 @@ """ import urwid -from custom_widgets import Password,List,InputDialog,ConfirmDialog +from custom_widgets import Password,List,InputDialog,ConfirmDialog,Alert class ProfileManager(urwid.WidgetWrap): @@ -53,7 +53,7 @@ #we now build the widget body_content = urwid.SimpleListWalker([buttons_flow,self.list_profile,divider,self.login_wid, self.pass_wid, connect_button]) frame_body = urwid.ListBox(body_content) - frame = urwid.Frame(frame_body,urwid.AttrMap(urwid.Text("Profile Manager",align='center'),'title')) + frame = urwid.Frame(frame_body,urwid.AttrMap(urwid.Text(_("Profile Manager"),align='center'),'title')) self.main_widget = urwid.LineBox(frame) urwid.WidgetWrap.__init__(self, self.main_widget) @@ -63,6 +63,10 @@ profiles.sort() self.list_profile.changeValues(profiles) + def __showPopUp(self, pop_up_widget): + display_widget = urwid.Overlay(pop_up_widget, self.main_widget, 'center', ('relative', 40), 'middle', ('relative', 40)) + self._set_w(display_widget) + def cancelDialog(self, button): self._set_w(self.main_widget) @@ -75,26 +79,49 @@ def deleteProfile(self, button): self._set_w(self.main_widget) - self.host.bridge.deleteProfile(self.list_profile.getValues()[0]) - self.__refillProfiles() + profile_name = self.list_profile.getValue() + if profile_name: + self.host.bridge.deleteProfile(profile_name) + self.__refillProfiles() def onNewProfile(self, e): pop_up_widget = InputDialog(_("New profile"), _("Please enter a new profile name"), cancel_cb=self.cancelDialog, ok_cb=self.newProfile) - display_widget = urwid.Overlay(pop_up_widget, self.main_widget, 'center', ('relative', 40), 'middle', ('relative', 40)) - self._set_w(display_widget) + self.__showPopUp(pop_up_widget) def onDeleteProfile(self, e): - 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) - display_widget = urwid.Overlay(pop_up_widget, self.main_widget, 'center', ('relative', 40), 'middle', ('relative', 40)) - self._set_w(display_widget) + 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) + self.__showPopUp(pop_up_widget) def onProfileChange(self, list_wid): - profile_name = list_wid.getValues()[0] - jabberID = self.host.bridge.getParamA("JabberID", "Connection", profile_key=profile_name) - password = self.host.bridge.getParamA("Password", "Connection", profile_key=profile_name) - self.login_wid.set_edit_text(jabberID) - self.pass_wid.set_edit_text(password) + profile_name = list_wid.getValue() + if profile_name: + jabberID = self.host.bridge.getParamA("JabberID", "Connection", profile_key=profile_name) + password = self.host.bridge.getParamA("Password", "Connection", profile_key=profile_name) + self.login_wid.set_edit_text(jabberID) + self.pass_wid.set_edit_text(password) def onConnectProfile(self, button): - pass + profile_name = self.list_profile.getValue() + if not profile_name: + pop_up_widget = Alert(_('No profile selected'), _('You need to create and select a profile before connecting'), ok_cb=self.cancelDialog) + self.__showPopUp(pop_up_widget) + elif profile_name[0] == '@': + pop_up_widget = Alert(_('Bad profile name'), _("A profile name can't start with a @"), ok_cb=self.cancelDialog) + self.__showPopUp(pop_up_widget) + else: + profile = self.host.bridge.getProfileName(profile_name) + assert(profile) + #TODO: move this to quick_app + old_jid = self.host.bridge.getParamA("JabberID", "Connection", profile_key=profile) + old_pass = self.host.bridge.getParamA("Password", "Connection", profile_key=profile) + new_jid = self.login_wid.get_edit_text() + new_pass = self.pass_wid.get_edit_text() + + if old_jid != new_jid: + self.host.bridge.setParam("JabberID", new_jid, "Connection", profile) + self.host.bridge.setParam("Server", JID(new_jid).domain, "Connection", profile) + if old_pass != new_pass: + self.host.bridge.setParam("Password", new_pass, "Connection", profile) + self.host.plug_profile(profile) +