diff options
Diffstat (limited to 'SoftwareProperties/dialog_add.py')
| -rw-r--r-- | SoftwareProperties/dialog_add.py | 91 |
1 files changed, 78 insertions, 13 deletions
diff --git a/SoftwareProperties/dialog_add.py b/SoftwareProperties/dialog_add.py index 9b384623..4ee17a87 100644 --- a/SoftwareProperties/dialog_add.py +++ b/SoftwareProperties/dialog_add.py @@ -26,13 +26,19 @@ import os import gobject import gtk import gtk.glade +from gettext import gettext as _ import aptsources +import dialog_edit class dialog_add: - def __init__(self, parent, sourceslist, datadir): + def __init__(self, parent, sourceslist, datadir, source_entry = None): self.sourceslist = sourceslist self.parent = parent + self.datadir = datadir + self.custom = False + # we have a source_entry that we want to modify + self.source_entry = source_entry # templates self.templatelist = aptsources.SourceEntryTemplates(datadir) @@ -52,16 +58,31 @@ class dialog_add: combo.pack_start(cell, True) combo.add_attribute(cell, 'text', 0) self.fill_combo(combo) + if source_entry: + self.main.set_title(_("Edit Channel")) + self.gladexml.get_widget("button_add").set_label("gtk-ok") self.gladexml.signal_connect("on_button_custom_clicked", self.on_button_custom_clicked, None) def fill_combo(self,combo): liststore = gtk.ListStore(gobject.TYPE_STRING,gobject.TYPE_PYOBJECT) + matched_template = None for item in self.templatelist.templates: liststore.append((item.description, item)) + if self.source_entry and item.matches(self.source_entry): + matched_template = item combo.set_model(liststore) - combo.set_active(0) + if matched_template: + try: + combo.set_active(self.templatelist.templates.index(matched_template)) + vbox = self.gladexml.get_widget("vbox_comps") + for c in vbox.get_children(): + c.set_active(c.get_data("name") in self.source_entry.comps) + except ValueError: + pass + else: + combo.set_active(0) def on_combobox_what_changed(self, combobox, user): #print "on_combobox_what_changed" @@ -83,19 +104,55 @@ class dialog_add: #print "on_button_custom_clicked()" # this hide here is ugly :/ self.main.hide() - dialog = self.gladexml.get_widget("dialog_add_custom") - dialog.set_transient_for(self.parent) - res = dialog.run() - dialog.hide() - entry = self.gladexml.get_widget("entry_source_line") - line = entry.get_text() + "\n" - self.sourceslist.list.append(aptsources.SourceEntry(line)) + # check if we are in add or edit-matched mode + if self.source_entry: + # we are in "edit" mode + # get the SourceEntry as it is now (with local changes) + # and display the "old" edit dialog + self.selected_comps = [] + vbox = self.gladexml.get_widget("vbox_comps") + vbox.foreach(self.get_enabled_comps) + source_entry = self._make_source_entry() + # since we're passing the SourceEntry as it is now, + # this SourceEntry needs to be in the sourceslist, + # so temporarily swap the original for the current + source_entry_index = self.sourcelist.list.index(source_entry) + self.sourceslist.list[source_entry_index] = source_entry + dialog = dialog_edit.dialog_edit(self.parent, self.sourceslist, + source_entry, self.datadir) + res = dialog.run() + if res == gtk.RESPONSE_CANCEL: + # restore original SourceEntry + self.sourceslist.list[source_entry_index] = self.source_entry + elif res == gtk.RESPONSE_OK: + # the sourceslist is allready updated, but we'll overwrite it + # in self.run if we're not carefull + self.custom = True + else: + # we are in "add" mode + dialog = self.gladexml.get_widget("dialog_add_custom") + dialog.set_transient_for(self.parent) + res = dialog.run() + dialog.hide() + entry = self.gladexml.get_widget("entry_source_line") + line = entry.get_text() + "\n" + self.sourceslist.list.append(aptsources.SourceEntry(line)) self.main.response(res) def get_enabled_comps(self, checkbutton): if checkbutton.get_active(): self.selected_comps.append(checkbutton.get_data("name")) + def _make_source_entry(self): + " helper for the 'edit' mode " + line = "%s %s %s" % (self.selected.type, self.source_entry.uri, self.selected.dist) + if len(self.selected_comps) > 0: + line += " " + " ".join(self.selected_comps) + if self.selected.matches(self.source_entry) and self.source_entry.comment != "": + line += " #"+self.source_entry.comment + line += "\n" + return aptsources.SourceEntry(line,self.source_entry.file) + def run(self): res = self.main.run() if res == gtk.RESPONSE_OK: @@ -103,9 +160,17 @@ class dialog_add: self.selected_comps = [] vbox = self.gladexml.get_widget("vbox_comps") vbox.foreach(self.get_enabled_comps) - self.sourceslist.add(self.selected.type, - self.selected.uri, - self.selected.dist, - self.selected_comps) + # check if we are in 'add' or 'edit' mode + if self.source_entry: + # 'edit' - ode + if not self.custom: + source_entry_index = self.sourcelist.list.index(source_entry) + self.sourceslist.list[source_entry_index] = self._make_source_entry() + else: + # 'add' mode + self.sourceslist.add(self.selected.type, + self.selected.uri, + self.selected.dist, + self.selected_comps) self.main.hide() return res |
