diff options
| author | Sebastian Heinlein <sebastian.heinlein@web.de> | 2006-02-23 15:14:57 +0100 |
|---|---|---|
| committer | Sebastian Heinlein <sebastian.heinlein@web.de> | 2006-02-23 15:14:57 +0100 |
| commit | fcea944da8f0ce5e178f79ec670658e279c07467 (patch) | |
| tree | 9ca0f1d441238fc8ea5faf4e1fb957f4ac63d3d4 /SoftwareProperties | |
| parent | 28d131b543b638589c243abb6b1c247c8c653321 (diff) | |
| download | python-apt-fcea944da8f0ce5e178f79ec670658e279c07467.tar.gz | |
* Use a smaller border in the add cdrom dialog
* add sources list was missing
Diffstat (limited to 'SoftwareProperties')
| -rw-r--r-- | SoftwareProperties/dialog_sources_list.py | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/SoftwareProperties/dialog_sources_list.py b/SoftwareProperties/dialog_sources_list.py new file mode 100644 index 00000000..9159d01f --- /dev/null +++ b/SoftwareProperties/dialog_sources_list.py @@ -0,0 +1,122 @@ +#!/usr/bin/env python +import pygtk +import gtk +import gtk.glade +import gobject +import os +from optparse import OptionParser +from aptsources import SourcesList, SourceEntryMatcher +from gettext import gettext as _ +import gettext +import urllib + +class AddSourcesList: + def __init__(self, parent, sourceslist, datadir, file): + print file + self.parent = parent + self.sources_old = sourceslist + self.file = self.format_uri(file) + self.glade = gtk.glade.XML(os.path.join(datadir, + "glade/SoftwarePropertiesDialogs.glade")) + self.glade.signal_autoconnect(self) + self.dialog = self.glade.get_widget("dialog_sources_list") + self.label = self.glade.get_widget("label_sources") + self.button_add = self.glade.get_widget("button_add") + self.button_cancel = self.glade.get_widget("button_cancel") + self.treeview = self.glade.get_widget("treeview_sources") + self.button_close = self.glade.get_widget("button_close") + self.scrolled = self.glade.get_widget("scrolled_window") + self.image = self.glade.get_widget("image_sources_list") + + self.dialog.realize() + if self.parent != None: + self.dialog.set_transient_for(parent) + else: + self.dialog.set_title(_("Add Software Channels")) + self.dialog.window.set_functions(gtk.gdk.FUNC_MOVE) + + # Setup the treeview + self.store = gtk.ListStore(gobject.TYPE_STRING) + self.treeview.set_model(self.store) + cell = gtk.CellRendererText() + column = gtk.TreeViewColumn("Software Channel", cell, markup=0) + column.set_max_width(500) + self.treeview.append_column(column) + + # Parse the source.list file + try: + self.sources = SingleSourcesList(self.file) + except: + self.error() + return + self.matcher = SourceEntryMatcher() + + # show the found channels or an error message + if len(self.sources.list) > 0: + self.button_close.hide() + found = False + for source in self.sources.list: + if source.invalid or source.disabled: + continue + found = True + (a_type, dist, comps) = self.matcher.match(source) + + line = "<b>%s</b> (%s)%s" %\ + (dist, a_type, comps) + self.store.append([line]) + if found == False: + self.error() + return + + header = gettext.ngettext("Add the following software channel?", + "Add the following software channels?", + len(self.sources.list)) + body = _("You can install software from a channel. Use "\ + "trusted channels, only.") + self.label.set_markup("<big><b>%s</b></big>\n\n%s" % (header, body)) + self.button_add.set_use_underline(True) + self.button_add.set_label(gettext.ngettext("_Add Channel", + "_Add Channels", + len(self.sources.list))) + else: + self.error() + return + + def error(self): + self.button_add.hide() + self.button_cancel.hide() + self.scrolled.hide() + self.button_close.show() + self.image.set_from_stock(gtk.STOCK_DIALOG_ERROR, gtk.ICON_SIZE_DIALOG) + header = _("Could not add any software channels") + body = _("The file '%s' does not contain any valid " + "software channels." % self.file) + self.label.set_markup("<big><b>%s</b></big>\n\n%s" % (header, body)) + + def run(self): + res = self.dialog.run() + if res == gtk.RESPONSE_OK: + for source in self.sources: + self.sources_old.add(source.type, + source.uri, + source.dist, + source.comps, + source.comment) + self.dialog.destroy() + return res + + def format_uri(self, uri): + path = urllib.url2pathname(uri) # escape special chars + path = path.strip('\r\n\x00') # remove \r\n and NULL + if path.startswith('file:\\\\\\'): # windows + path = path[8:] # 8 is len('file:///') + elif path.startswith('file://'): #nautilus, rox + path = path[7:] # 7 is len('file://') + elif path.startswith('file:'): # xffm + path = path[5:] # 5 is len('file:') + return path + +class SingleSourcesList(SourcesList): + def __init__(self, file): + self.list = [] + self.load(file) |
