From 9fbd630070fda42945f4f5362a00188249f6ecc8 Mon Sep 17 00:00:00 2001 From: Sean Robinson Date: Sun, 6 Apr 2014 11:27:46 -0700 Subject: [PATCH] Simplify handling a user request to delete a profile Now that profiles are not stored in the GUI, it's just a matter of checking various UI elements before sending a delete message. Signed-off-by: Sean Robinson --- wifiradar/gui/g2/__init__.py | 62 +++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/wifiradar/gui/g2/__init__.py b/wifiradar/gui/g2/__init__.py index 5abd4b7..76de894 100644 --- a/wifiradar/gui/g2/__init__.py +++ b/wifiradar/gui/g2/__init__.py @@ -185,7 +185,7 @@ class RadarWindow: self.edit_button.set_sensitive(False) # Add Delete button self.delete_button = gtk.Button("_Delete") - self.delete_button.connect('clicked', self.delete_profile_with_check, None) + self.delete_button.connect('clicked', self.request_profile_delete) self.delete_button.show() self.delete_button.set_sensitive(False) # Add Connect button @@ -517,41 +517,39 @@ class RadarWindow: self.msg_pipe.send(Message('PROFILE-EDITED', (edited_profile, profile))) - def delete_profile(self, apname): - """ Delete the profile associated with :data:`apname` (i.e. make - the profile unknown). - """ - self.msg_pipe.send(Message('PROFILE-REMOVE', apname)) - - def delete_profile_with_check(self, widget=None, data=None): + def request_profile_delete(self, widget=None, data=None): """ Respond to a request to delete an AP profile (i.e. make the - profile unknown) Check with the user first. :data:`widget` - is the widget sending the signal and :data:`data` is a list of - arbitrary arguments, both are ignored. + profile unknown). Trying to delete an AP which is not configured + is a NOOP. Check with the user before deleting the profile. + :data:`widget` is the widget sending the signal and :data:`data` + is a list of arbitrary arguments, both are ignored. """ store, selected_iter = self.plist.get_selection().get_selected() - if selected_iter is None: - return + if selected_iter is not None: + if store.get_value(selected_iter, 3): + # The selected AP is configured (a.k.a. 'known'). + essid = self.pstore.get_value(selected_iter, 0) + bssid = self.pstore.get_value(selected_iter, 1) + if bssid == ' Multiple APs': + # AP list says this is a roaming profile + bssid = '' + profile_name = essid + else: + profile_name = '{} ({})'.format(essid, bssid) - essid = self.pstore.get_value(selected_iter, 0) - bssid = self.pstore.get_value(selected_iter, 1) - if bssid == ' Multiple APs': - apname = make_section_name(essid, '') - else: - apname = make_section_name(essid, bssid) - profile = self.config.get_profile(apname) - if profile['roaming']: - dlg = gtk.MessageDialog(self.window, gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, "Are you sure you want to delete the %s profile?" % (essid, )) - else: - dlg = gtk.MessageDialog(self.window, gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, "Are you sure you want to delete the %s (%s) profile?" % (essid, bssid)) - known = store.get_value(selected_iter, 3) - if not known: return - res = dlg.run() - dlg.destroy() - del dlg - if res == gtk.RESPONSE_NO: - return - self.delete_profile(apname) + dialog = gtk.MessageDialog(self.window, + gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_MODAL, + gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, + 'Are you sure you want to delete the ' + + '{} profile?'.format(profile_name)) + + result = dialog.run() + dialog.destroy() + del dialog + + if result == gtk.RESPONSE_YES: + apname = make_section_name(essid, bssid) + self.msg_pipe.send(Message('PROFILE-REMOVE', apname)) def connect_profile(self, widget, profile, data=None): """ Respond to a request to connect to an AP. -- 2.11.4.GIT