From 4b4323bc297cde4d65280a0844b7977ce52a34b7 Mon Sep 17 00:00:00 2001 From: Sebastian Heinlein Date: Mon, 17 Apr 2006 16:20:07 +0200 Subject: * do not allow to create an invalid channel in the edit dialog --- SoftwareProperties/dialog_edit.py | 57 +++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 20 deletions(-) (limited to 'SoftwareProperties/dialog_edit.py') diff --git a/SoftwareProperties/dialog_edit.py b/SoftwareProperties/dialog_edit.py index 05cbddba..eb2cdc97 100644 --- a/SoftwareProperties/dialog_edit.py +++ b/SoftwareProperties/dialog_edit.py @@ -41,6 +41,9 @@ class dialog_edit: self.gladexml = gtk.glade.XML("%s/glade/SoftwarePropertiesDialogs.glade" % datadir) self.main = self.gladexml.get_widget("dialog_edit") self.main.set_transient_for(parent) + self.button_edit_ok = self.gladexml.get_widget("button_edit_ok") + self.gladexml.signal_connect("on_entry_source_line_changed", + self.check_line) # type combo_type = self.gladexml.get_widget("combobox_type") @@ -70,29 +73,43 @@ class dialog_edit: entry = self.gladexml.get_widget("entry_comment") entry.set_text(source_entry.comment) - def run(self): - res = self.main.run() - if res == gtk.RESPONSE_OK: - # get values - combo_type = self.gladexml.get_widget("combobox_type") - if combo_type.get_active() == 0: - line = "deb" - else: - line = "deb-src" - entry = self.gladexml.get_widget("entry_uri") - line = line + " " + entry.get_text() + def check_line(self, *args): + """Check for a valid apt line and set the sensitiveness of the + button 'add' accordingly""" + line = self.get_line() + source_entry = aptsources.SourceEntry(line) + if source_entry.invalid == True or source_entry.disabled == True: + self.button_edit_ok.set_sensitive(False) + else: + self.button_edit_ok.set_sensitive(True) + + def get_line(self): + """Collect all values from the entries and create an apt line""" + combo_type = self.gladexml.get_widget("combobox_type") + if combo_type.get_active() == 0: + line = "deb" + else: + line = "deb-src" + entry = self.gladexml.get_widget("entry_uri") + line = line + " " + entry.get_text() - entry = self.gladexml.get_widget("entry_dist") - line = line + " " + entry.get_text() + entry = self.gladexml.get_widget("entry_dist") + line = line + " " + entry.get_text() - entry = self.gladexml.get_widget("entry_comps") - line = line + " " + entry.get_text() + entry = self.gladexml.get_widget("entry_comps") + line = line + " " + entry.get_text() - entry = self.gladexml.get_widget("entry_comment") - if entry.get_text() != "": - line = line + " #" + entry.get_text() + "\n" - else: - line = line + "\n" + entry = self.gladexml.get_widget("entry_comment") + if entry.get_text() != "": + line = line + " #" + entry.get_text() + "\n" + else: + line = line + "\n" + return line + + def run(self): + res = self.main.run() + if res == gtk.RESPONSE_OK: + line = self.get_line() # change repository index = self.sourceslist.list.index(self.source_entry) -- cgit v1.2.3 From 09a3302637368aa2dda1ea8cef86dd32d7423c26 Mon Sep 17 00:00:00 2001 From: Sebastian Heinlein Date: Mon, 17 Apr 2006 16:45:16 +0200 Subject: * more sanity checking for apt lines --- SoftwareProperties/aptsources.py | 2 ++ SoftwareProperties/dialog_edit.py | 26 +++++++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) (limited to 'SoftwareProperties/dialog_edit.py') diff --git a/SoftwareProperties/aptsources.py b/SoftwareProperties/aptsources.py index a2d0a67d..247879a3 100644 --- a/SoftwareProperties/aptsources.py +++ b/SoftwareProperties/aptsources.py @@ -155,6 +155,8 @@ class SourceEntry: return # URI self.uri = string.strip(pieces[1]) + if len(self.uri) < 1: + self.invalid = True # distro and components (optional) # Directory or distro self.dist = string.strip(pieces[2]) diff --git a/SoftwareProperties/dialog_edit.py b/SoftwareProperties/dialog_edit.py index eb2cdc97..59788915 100644 --- a/SoftwareProperties/dialog_edit.py +++ b/SoftwareProperties/dialog_edit.py @@ -42,8 +42,6 @@ class dialog_edit: self.main = self.gladexml.get_widget("dialog_edit") self.main.set_transient_for(parent) self.button_edit_ok = self.gladexml.get_widget("button_edit_ok") - self.gladexml.signal_connect("on_entry_source_line_changed", - self.check_line) # type combo_type = self.gladexml.get_widget("combobox_type") @@ -73,12 +71,20 @@ class dialog_edit: entry = self.gladexml.get_widget("entry_comment") entry.set_text(source_entry.comment) + # finally set the signal so that the check function is not tiggered + # during initialisation + self.gladexml.signal_connect("on_entry_source_line_changed", + self.check_line) + def check_line(self, *args): """Check for a valid apt line and set the sensitiveness of the button 'add' accordingly""" line = self.get_line() + if line == False: + self.button_edit_ok.set_sensitive(False) + return source_entry = aptsources.SourceEntry(line) - if source_entry.invalid == True or source_entry.disabled == True: + if (source_entry.invalid == True or source_entry.disabled == True): self.button_edit_ok.set_sensitive(False) else: self.button_edit_ok.set_sensitive(True) @@ -90,13 +96,23 @@ class dialog_edit: line = "deb" else: line = "deb-src" - entry = self.gladexml.get_widget("entry_uri") - line = line + " " + entry.get_text() + + entry = self.gladexml.get_widget("entry_uri") + text = entry.get_text() + if len(text) < 1 or text.find(" ") != -1 or text.find("#") != -1: + return False + line = line + " " + entry.get_text() entry = self.gladexml.get_widget("entry_dist") + text = entry.get_text() + if len(text) < 1 or text.find(" ") != -1 or text.find("#") != -1: + return False line = line + " " + entry.get_text() entry = self.gladexml.get_widget("entry_comps") + text = entry.get_text() + if len(text) < 1 or text.find("#") != -1: + return False line = line + " " + entry.get_text() entry = self.gladexml.get_widget("entry_comment") -- cgit v1.2.3