home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / softwareproperties / gtk / SoftwarePropertiesGtk.pyc (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  28.6 KB  |  748 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import apt
  5. import apt_pkg
  6. import tempfile
  7. from gettext import gettext as _
  8. import os
  9. import re
  10. from xml.sax.saxutils import escape
  11. import gtk
  12. import gtk.glade as gtk
  13. import gobject
  14. from SimpleGladeApp import SimpleGladeApp
  15. from aptsources.sourceslist import SourceEntry
  16. from DialogAdd import DialogAdd
  17. from DialogMirror import DialogMirror
  18. from DialogEdit import DialogEdit
  19. from DialogCacheOutdated import DialogCacheOutdated
  20. from DialogAddSourcesList import DialogAddSourcesList
  21. from CdromProgress import CdromProgress
  22. import softwareproperties
  23. import softwareproperties.distro as softwareproperties
  24. from softwareproperties.SoftwareProperties import SoftwareProperties
  25. import softwareproperties.SoftwareProperties as softwareproperties
  26. (LIST_MARKUP, LIST_ENABLED, LIST_ENTRY_OBJ) = range(3)
  27. (COLUMN_ACTIVE, COLUMN_DESC) = range(2)
  28. RESPONSE_REPLACE = 1
  29. RESPONSE_ADD = 2
  30. (STORE_ACTIVE, STORE_DESCRIPTION, STORE_SOURCE, STORE_SEPARATOR, STORE_VISIBLE) = range(5)
  31.  
  32. class SoftwarePropertiesGtk(SoftwareProperties, SimpleGladeApp):
  33.     
  34.     def __init__(self, datadir = None, options = None, file = None, parent = None):
  35.         ''' Provide a GTK based graphical user interface to configure
  36.         the used software repositories, corresponding authentication keys
  37.         and update automation '''
  38.         SoftwareProperties.__init__(self, options = options, datadir = datadir)
  39.         gtk.window_set_default_icon_name('software-properties')
  40.         SimpleGladeApp.__init__(self, datadir + 'glade/main.glade', None, domain = 'software-properties')
  41.         if parent:
  42.             self.window_main.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
  43.             self.window_main.show()
  44.             self.window_main.set_transient_for(parent)
  45.         
  46.         self.options = options
  47.         if options and options.toplevel != None:
  48.             self.window_main.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
  49.             self.window_main.show()
  50.             toplevel = gtk.gdk.window_foreign_new(int(options.toplevel))
  51.             if toplevel:
  52.                 self.window_main.window.set_transient_for(toplevel)
  53.             
  54.         
  55.         if options and options.open_tab:
  56.             self.notebook_main.set_current_page(int(options.open_tab))
  57.         
  58.         self.window_main.show()
  59.         self.handlers = []
  60.         self.init_popcon()
  61.         self.init_auto_update()
  62.         self.init_release_upgrades()
  63.         self.show_auto_update_level()
  64.         self.init_keys()
  65.         self.show_keys()
  66.         self.init_isv_sources()
  67.         self.show_isv_sources()
  68.         self.show_cdrom_sources()
  69.         self.init_distro()
  70.         self.show_distro()
  71.         if file != None and os.path.abspath(file) != '%s%s' % (apt_pkg.Config.FindDir('Dir::Etc'), apt_pkg.Config.Find('Dir::Etc::sourcelist')):
  72.             self.open_file(file)
  73.         
  74.  
  75.     
  76.     def init_popcon(self):
  77.         ''' If popcon is enabled show the statistics tab and an explanation
  78.         corresponding to the used distro '''
  79.         is_helpful = self.get_popcon_participation()
  80.         if is_helpful != None:
  81.             self.label_popcon_desc.set_label(softwareproperties.distro.get_popcon_description(self.distro))
  82.             self.vbox_popcon.show()
  83.             self.checkbutton_popcon.set_active(is_helpful)
  84.         
  85.  
  86.     
  87.     def init_release_upgrades(self):
  88.         ''' setup the widgets that allow configuring the release upgrades '''
  89.         i = self.get_release_upgrades_policy()
  90.         self.combobox_release_upgrades.set_active(i)
  91.         self.combobox_release_upgrades.connect('changed', self.on_combobox_release_upgrades_changed)
  92.  
  93.     
  94.     def init_auto_update(self):
  95.         ''' Set up the widgets that allow to configure the update automation '''
  96.         self.combobox_interval_mapping = {
  97.             0: 1,
  98.             1: 2,
  99.             2: 7,
  100.             3: 14 }
  101.         self.combobox_update_interval.set_active(0)
  102.         self.combobox_update_interval.append_text(_('Daily'))
  103.         self.combobox_update_interval.append_text(_('Every two days'))
  104.         self.combobox_update_interval.append_text(_('Weekly'))
  105.         self.combobox_update_interval.append_text(_('Every two weeks'))
  106.         model_check_interval = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_INT)
  107.         update_days = self.get_update_interval()
  108.         if update_days not in self.combobox_interval_mapping.values():
  109.             if update_days > 0:
  110.                 self.combobox_update_interval.append_text(_('Every %s days') % update_days)
  111.                 self.combobox_interval_mapping[4] = update_days
  112.             
  113.         
  114.         for key in self.combobox_interval_mapping:
  115.             if self.combobox_interval_mapping[key] == update_days:
  116.                 self.combobox_update_interval.set_active(key)
  117.                 break
  118.                 continue
  119.         
  120.         if update_days >= 1:
  121.             self.checkbutton_auto_update.set_active(True)
  122.             self.combobox_update_interval.set_sensitive(True)
  123.             self.vbox_auto_updates.set_sensitive(True)
  124.         else:
  125.             self.checkbutton_auto_update.set_active(False)
  126.             self.combobox_update_interval.set_sensitive(False)
  127.             self.vbox_auto_updates.set_sensitive(False)
  128.         self.handlers.append((self.checkbutton_auto_update, self.checkbutton_auto_update.connect('toggled', self.on_auto_update_toggled)))
  129.         self.handlers.append((self.combobox_update_interval, self.combobox_update_interval.connect('changed', self.on_combobox_update_interval_changed)))
  130.         self.handlers.append((self.radiobutton_updates_download, self.radiobutton_updates_download.connect('toggled', self.set_update_automation_level, softwareproperties.UPDATE_DOWNLOAD)))
  131.         self.handlers.append((self.radiobutton_updates_inst_sec, self.radiobutton_updates_inst_sec.connect('toggled', self.set_update_automation_level, softwareproperties.UPDATE_INST_SEC)))
  132.         self.handlers.append((self.radiobutton_updates_notify, self.radiobutton_updates_notify.connect('toggled', self.set_update_automation_level, softwareproperties.UPDATE_NOTIFY)))
  133.  
  134.     
  135.     def show_auto_update_level(self):
  136.         '''Represent the level of update automation in the user interface'''
  137.         level = self.get_update_automation_level()
  138.         self.block_handlers()
  139.         if level == None:
  140.             self.radiobutton_updates_inst_sec.set_inconsistent(True)
  141.             self.radiobutton_updates_download.set_inconsistent(True)
  142.             self.radiobutton_updates_notify.set_inconsistent(True)
  143.         else:
  144.             self.radiobutton_updates_inst_sec.set_inconsistent(False)
  145.             self.radiobutton_updates_download.set_inconsistent(False)
  146.             self.radiobutton_updates_notify.set_inconsistent(False)
  147.         if level == softwareproperties.UPDATE_MANUAL or level == softwareproperties.UPDATE_NOTIFY:
  148.             self.radiobutton_updates_notify.set_active(True)
  149.         elif level == softwareproperties.UPDATE_DOWNLOAD:
  150.             self.radiobutton_updates_download.set_active(True)
  151.         elif level == softwareproperties.UPDATE_INST_SEC:
  152.             self.radiobutton_updates_inst_sec.set_active(True)
  153.         
  154.         self.unblock_handlers()
  155.  
  156.     
  157.     def init_distro(self):
  158.         '''Setup the user interface elements to represent the distro'''
  159.         self.label_updates.set_label('<b>%s</b>' % _('%s updates') % self.distro.id)
  160.         self.label_dist_name.set_label(_('%s Software') % self.distro.id)
  161.         self.handlers.append((self.checkbutton_source_code, self.checkbutton_source_code.connect('toggled', self.on_checkbutton_source_code_toggled)))
  162.         for checkbutton in self.vbox_dist_comps.get_children():
  163.             self.vbox_dist_comps.remove(checkbutton)
  164.         
  165.         for comp in self.distro.source_template.components:
  166.             label = _('%s (%s)') % (comp.get_description(), comp.name)
  167.             checkbox = gtk.CheckButton(label)
  168.             checkbox.comp = comp
  169.             self.handlers.append((checkbox, checkbox.connect('toggled', self.on_component_toggled, comp.name)))
  170.             self.vbox_dist_comps.add(checkbox)
  171.             checkbox.show()
  172.         
  173.         for checkbutton in self.vbox_updates.get_children():
  174.             self.vbox_updates.remove(checkbutton)
  175.         
  176.         if len(self.distro.source_template.children) < 1:
  177.             self.frame_children.hide()
  178.         
  179.         for template in self.distro.source_template.children:
  180.             checkbox = gtk.CheckButton(label = '%s (%s)' % (template.description, template.name))
  181.             checkbox.template = template
  182.             self.handlers.append((checkbox, checkbox.connect('toggled', self.on_checkbutton_child_toggled, template)))
  183.             self.vbox_updates.add(checkbox)
  184.             checkbox.show()
  185.         
  186.         cell = gtk.CellRendererText()
  187.         self.combobox_server.pack_start(cell, True)
  188.         self.combobox_server.add_attribute(cell, 'text', 0)
  189.         self.handlers.append((self.combobox_server, self.combobox_server.connect('changed', self.on_combobox_server_changed)))
  190.         server_store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_BOOLEAN)
  191.         self.combobox_server.set_model(server_store)
  192.         self.combobox_server.set_row_separator_func(self.is_row_separator, 2)
  193.  
  194.     
  195.     def block_handlers(self):
  196.         for widget, handler in self.handlers:
  197.             widget.handler_block(handler)
  198.         
  199.  
  200.     
  201.     def unblock_handlers(self):
  202.         for widget, handler in self.handlers:
  203.             widget.handler_unblock(handler)
  204.         
  205.  
  206.     
  207.     def show_distro(self):
  208.         '''Fill the distro user interface with life'''
  209.         self.block_handlers()
  210.         for checkbox in self.vbox_updates.get_children():
  211.             (active, inconsistent) = self.get_comp_child_state(checkbox.template)
  212.             checkbox.set_active(active)
  213.             checkbox.set_inconsistent(inconsistent)
  214.         
  215.         for checkbox in self.vbox_dist_comps.get_children():
  216.             (active, inconsistent) = self.get_comp_download_state(checkbox.comp)
  217.             checkbox.set_inconsistent(inconsistent)
  218.             checkbox.set_active(active)
  219.         
  220.         if len(self.distro.enabled_comps) < 1:
  221.             self.vbox_updates.set_sensitive(False)
  222.             self.checkbutton_source_code.set_sensitive(False)
  223.         else:
  224.             self.vbox_updates.set_sensitive(True)
  225.             self.checkbutton_source_code.set_sensitive(True)
  226.         source_code_state = self.get_source_code_state()
  227.         if source_code_state == None:
  228.             self.checkbutton_source_code.set_inconsistent(True)
  229.         elif source_code_state == True:
  230.             self.checkbutton_source_code.set_active(True)
  231.             self.checkbutton_source_code.set_inconsistent(False)
  232.         else:
  233.             self.checkbutton_source_code.set_active(False)
  234.             self.checkbutton_source_code.set_inconsistent(False)
  235.         if len(self.get_cdrom_sources()) == 0:
  236.             self.scrolledwindow_cd.hide()
  237.             self.scrolledwindow_no_cd.show()
  238.         else:
  239.             self.scrolledwindow_cd.show()
  240.             self.scrolledwindow_no_cd.hide()
  241.         server_store = self.combobox_server.get_model()
  242.         server_store.clear()
  243.         seen_server_new = []
  244.         for name, uri, active in self.distro.get_server_list():
  245.             server_store.append([
  246.                 name,
  247.                 uri,
  248.                 False])
  249.             if [
  250.                 name,
  251.                 uri] in self.seen_server:
  252.                 self.seen_server.remove([
  253.                     name,
  254.                     uri])
  255.             elif uri != None:
  256.                 seen_server_new.append([
  257.                     name,
  258.                     uri])
  259.             
  260.             if active == True:
  261.                 self.active_server = len(server_store) - 1
  262.                 self.combobox_server.set_active(self.active_server)
  263.                 continue
  264.         
  265.         for name, uri in self.seen_server:
  266.             server_store.append([
  267.                 name,
  268.                 uri,
  269.                 False])
  270.         
  271.         self.seen_server = seen_server_new
  272.         server_store.append([
  273.             'sep',
  274.             None,
  275.             True])
  276.         server_store.append([
  277.             _('Other...'),
  278.             None,
  279.             False])
  280.         self.unblock_handlers()
  281.         if self.options.debug == True or self.options.massive_debug == True:
  282.             print 'ENABLED COMPS: %s' % self.distro.enabled_comps
  283.             print 'INTERNET COMPS: %s' % self.distro.download_comps
  284.             print 'MAIN SOURCES'
  285.             for source in self.distro.main_sources:
  286.                 self.print_source_entry(source)
  287.             
  288.             print 'CHILD SOURCES'
  289.             for source in self.distro.child_sources:
  290.                 self.print_source_entry(source)
  291.             
  292.             print 'CDROM SOURCES'
  293.             for source in self.distro.cdrom_sources:
  294.                 self.print_source_entry(source)
  295.             
  296.             print 'SOURCE CODE SOURCES'
  297.             for source in self.distro.source_code_sources:
  298.                 self.print_source_entry(source)
  299.             
  300.             print 'DISABLED SOURCES'
  301.             for source in self.distro.disabled_sources:
  302.                 self.print_source_entry(source)
  303.             
  304.             print 'ISV'
  305.             for source in self.sourceslist_visible:
  306.                 self.print_source_entry(source)
  307.             
  308.         
  309.  
  310.     
  311.     def set_update_automation_level(self, widget, state):
  312.         '''Call the backend to set the update automation level to the given 
  313.        value'''
  314.         if widget.get_active() == True:
  315.             self.vbox_auto_updates.foreach((lambda b: b.set_inconsistent(False)))
  316.             SoftwareProperties.set_update_automation_level(self, state)
  317.         
  318.         self.set_modified_config()
  319.  
  320.     
  321.     def is_row_separator(self, model, iter, column = 0):
  322.         ''' Check if a given row is a separator '''
  323.         return model.get_value(iter, column)
  324.  
  325.     
  326.     def on_combobox_release_upgrades_changed(self, combobox):
  327.         ''' set the release upgrades policy '''
  328.         i = combobox.get_active()
  329.         self.set_release_upgrades_policy(i)
  330.  
  331.     
  332.     def on_combobox_server_changed(self, combobox):
  333.         '''
  334.     Replace the servers used by the main and update sources with
  335.     the selected one
  336.     '''
  337.         if combobox.get_active() == self.active_server:
  338.             return None
  339.         server_store = combobox.get_model()
  340.         iter = combobox.get_active_iter()
  341.         uri = server_store.get_value(iter, 1)
  342.         name = server_store.get_value(iter, 0)
  343.         if name == _('Other...'):
  344.             dialog = DialogMirror(self.window_main, self.datadir, self.distro, self.custom_mirrors)
  345.             res = dialog.run()
  346.             if res != None:
  347.                 self.distro.change_server(res)
  348.                 self.set_modified_sourceslist()
  349.             else:
  350.                 combobox.set_active(self.active_server)
  351.         elif uri != None and len(self.distro.used_servers) > 0:
  352.             self.active_server = combobox.get_active()
  353.             self.distro.change_server(uri)
  354.             self.distro.default_server = uri
  355.             self.set_modified_sourceslist()
  356.         else:
  357.             self.distro.default_server = uri
  358.  
  359.     
  360.     def on_component_toggled(self, checkbutton, comp):
  361.         '''
  362.     Sync the components of all main sources (excluding cdroms),
  363.     child sources and source code sources
  364.     '''
  365.         if checkbutton.get_active() == True:
  366.             self.enable_component(comp)
  367.         else:
  368.             self.disable_component(comp)
  369.         self.set_modified_sourceslist()
  370.  
  371.     
  372.     def on_checkbutton_child_toggled(self, checkbutton, template):
  373.         '''
  374.     Enable or disable a child repo of the distribution main repository
  375.     '''
  376.         if checkbutton.get_active() == False:
  377.             self.disable_child_source(template)
  378.         else:
  379.             self.enable_child_source(template)
  380.  
  381.     
  382.     def on_checkbutton_source_code_toggled(self, checkbutton):
  383.         ''' Disable or enable the source code for all sources '''
  384.         if checkbutton.get_active() == True:
  385.             self.enable_source_code_sources()
  386.         else:
  387.             self.disable_source_code_sources()
  388.  
  389.     
  390.     def on_checkbutton_popcon_toggled(self, widget):
  391.         ''' The user clicked on the popcon paritipcation button '''
  392.         self.set_popcon_pariticipation(widget.get_active())
  393.  
  394.     
  395.     def open_file(self, file):
  396.         '''Show a confirmation for adding the channels of the specified file'''
  397.         dialog = DialogAddSourcesList(self.window_main, self.sourceslist, self.render_source, self.get_comparable, self.datadir, file)
  398.         (res, new_sources) = dialog.run()
  399.         if res == RESPONSE_REPLACE:
  400.             self.sourceslist.list = []
  401.         
  402.         if res in (RESPONSE_ADD, RESPONSE_REPLACE):
  403.             for source in new_sources:
  404.                 self.sourceslist.add(source.type, source.uri, source.dist, source.comps, source.comment)
  405.             
  406.             self.set_modified_sourceslist()
  407.         
  408.  
  409.     
  410.     def on_sources_drag_data_received(self, widget, context, x, y, selection, target_type, timestamp):
  411.         '''Extract the dropped file pathes and open the first file, only'''
  412.         uri = selection.data.strip()
  413.         uri_splitted = uri.split()
  414.         if len(uri_splitted) > 0:
  415.             self.open_file(uri_splitted[0])
  416.         
  417.  
  418.     
  419.     def hide(self):
  420.         self.window_main.hide()
  421.  
  422.     
  423.     def init_isv_sources(self):
  424.         '''
  425.     Read all valid sources into our ListStore
  426.     '''
  427.         self.cdrom_store = gtk.ListStore(gobject.TYPE_BOOLEAN, gobject.TYPE_STRING, gobject.TYPE_PYOBJECT, gobject.TYPE_BOOLEAN, gobject.TYPE_BOOLEAN)
  428.         self.treeview_cdroms.set_model(self.cdrom_store)
  429.         self.source_store = gtk.ListStore(gobject.TYPE_BOOLEAN, gobject.TYPE_STRING, gobject.TYPE_PYOBJECT, gobject.TYPE_BOOLEAN, gobject.TYPE_BOOLEAN)
  430.         self.treeview_sources.set_model(self.source_store)
  431.         self.treeview_sources.set_row_separator_func(self.is_separator, STORE_SEPARATOR)
  432.         cell_desc = gtk.CellRendererText()
  433.         cell_desc.set_property('xpad', 2)
  434.         cell_desc.set_property('ypad', 2)
  435.         col_desc = gtk.TreeViewColumn(_('Software Sources'), cell_desc, markup = COLUMN_DESC)
  436.         col_desc.set_max_width(1000)
  437.         cell_toggle = gtk.CellRendererToggle()
  438.         cell_toggle.set_property('xpad', 2)
  439.         cell_toggle.set_property('ypad', 2)
  440.         self.handlers.append([
  441.             cell_toggle,
  442.             cell_toggle.connect('toggled', self.on_isv_source_toggled, self.cdrom_store)])
  443.         col_active = gtk.TreeViewColumn(_('Active'), cell_toggle, active = COLUMN_ACTIVE)
  444.         self.treeview_cdroms.append_column(col_active)
  445.         self.treeview_cdroms.append_column(col_desc)
  446.         cell_desc = gtk.CellRendererText()
  447.         cell_desc.set_property('xpad', 2)
  448.         cell_desc.set_property('ypad', 2)
  449.         col_desc = gtk.TreeViewColumn(_('Software Sources'), cell_desc, markup = COLUMN_DESC)
  450.         col_desc.set_max_width(1000)
  451.         cell_toggle = gtk.CellRendererToggle()
  452.         cell_toggle.set_property('xpad', 2)
  453.         cell_toggle.set_property('ypad', 2)
  454.         self.handlers.append([
  455.             cell_toggle,
  456.             cell_toggle.connect('toggled', self.on_isv_source_toggled, self.source_store)])
  457.         col_active = gtk.TreeViewColumn(_('Active'), cell_toggle, active = COLUMN_ACTIVE)
  458.         self.treeview_sources.append_column(col_active)
  459.         self.treeview_sources.append_column(col_desc)
  460.         self.treeview_sources.drag_dest_set(gtk.DEST_DEFAULT_ALL, [
  461.             ('text/uri-list', 0, 0)], gtk.gdk.ACTION_COPY)
  462.         self.treeview_sources.connect('drag_data_received', self.on_sources_drag_data_received)
  463.  
  464.     
  465.     def on_isv_source_activate(self, treeview, path, column):
  466.         '''Open the edit dialog if a channel was double clicked'''
  467.         self.on_edit_clicked(treeview)
  468.  
  469.     
  470.     def on_treeview_sources_cursor_changed(self, treeview):
  471.         '''Enable the buttons remove and edit if a channel is selected'''
  472.         sel = self.treeview_sources.get_selection()
  473.         (model, iter) = sel.get_selected()
  474.         if iter:
  475.             self.button_edit.set_sensitive(True)
  476.             self.button_remove.set_sensitive(True)
  477.         else:
  478.             self.button_edit.set_sensitive(False)
  479.             self.button_remove.set_sensitive(False)
  480.  
  481.     
  482.     def on_isv_source_toggled(self, cell_toggle, path, store):
  483.         '''Enable or disable the selected channel'''
  484.         iter = store.get_iter((int(path),))
  485.         source_entry = store.get_value(iter, STORE_SOURCE)
  486.         self.toggle_source_use(source_entry)
  487.  
  488.     
  489.     def init_keys(self):
  490.         '''Setup the user interface parts needed for the key handling'''
  491.         self.keys_store = gtk.ListStore(str)
  492.         self.treeview2.set_model(self.keys_store)
  493.         tr = gtk.CellRendererText()
  494.         keys_col = gtk.TreeViewColumn('Key', tr, text = 0)
  495.         self.treeview2.append_column(keys_col)
  496.  
  497.     
  498.     def on_button_revert_clicked(self, button):
  499.         '''Restore the source list from the startup of the dialog'''
  500.         SoftwareProperties.revert(self)
  501.         self.set_modified_sourceslist()
  502.         self.show_auto_update_level()
  503.         self.button_revert.set_sensitive(False)
  504.         self.modified_sourceslist = False
  505.  
  506.     
  507.     def set_modified_config(self):
  508.         '''The config was changed and now needs to be saved and reloaded'''
  509.         SoftwareProperties.set_modified_config(self)
  510.         self.button_revert.set_sensitive(True)
  511.  
  512.     
  513.     def set_modified_sourceslist(self):
  514.         '''The sources list was changed and now needs to be saved and reloaded'''
  515.         SoftwareProperties.set_modified_sourceslist(self)
  516.         self.show_distro()
  517.         self.show_isv_sources()
  518.         self.show_cdrom_sources()
  519.         self.button_revert.set_sensitive(True)
  520.  
  521.     
  522.     def show_isv_sources(self):
  523.         ''' Show the repositories of independent software vendors in the
  524.         third-party software tree view '''
  525.         self.source_store.clear()
  526.         for source in self.get_isv_sources():
  527.             contents = self.render_source(source)
  528.             self.source_store.append([
  529.                 not (source.disabled),
  530.                 contents,
  531.                 source,
  532.                 False,
  533.                 True])
  534.         
  535.         (path_x, path_y) = self.treeview_sources.get_cursor()
  536.         if len(self.source_store) < 1 or path_x < 0:
  537.             self.button_remove.set_sensitive(False)
  538.             self.button_edit.set_sensitive(False)
  539.         
  540.  
  541.     
  542.     def show_cdrom_sources(self):
  543.         ''' Show CD-ROM/DVD based repositories of the currently used distro in
  544.         the CDROM based sources list '''
  545.         self.cdrom_store.clear()
  546.         for source in self.get_cdrom_sources():
  547.             contents = self.render_source(source)
  548.             self.cdrom_store.append([
  549.                 not (source.disabled),
  550.                 contents,
  551.                 source,
  552.                 False,
  553.                 True])
  554.         
  555.  
  556.     
  557.     def is_separator(self, model, iter, column):
  558.         ''' Return true if the selected row is a separator '''
  559.         
  560.         try:
  561.             return model.get_value(iter, column)
  562.         except Exception:
  563.             e = None
  564.             print "is_seperator returned '%s' " % e
  565.             return False
  566.  
  567.  
  568.     
  569.     def show_keys(self):
  570.         self.keys_store.clear()
  571.         for key in self.apt_key.list():
  572.             self.keys_store.append([
  573.                 key])
  574.         
  575.  
  576.     
  577.     def on_combobox_update_interval_changed(self, widget):
  578.         '''Set the update automation interval to the chosen one'''
  579.         i = self.combobox_update_interval.get_active()
  580.         if i != -1:
  581.             value = self.combobox_interval_mapping[i]
  582.             self.set_update_interval(value)
  583.         
  584.  
  585.     
  586.     def on_auto_update_toggled(self, widget):
  587.         '''Enable or disable automatic updates and modify the user interface
  588.        accordingly'''
  589.         if self.checkbutton_auto_update.get_active():
  590.             self.combobox_update_interval.set_sensitive(True)
  591.             self.vbox_auto_updates.set_sensitive(True)
  592.             i = self.combobox_update_interval.get_active()
  593.             if i == -1:
  594.                 i = 0
  595.                 self.combobox_update_interval.set_active(i)
  596.             
  597.             value = self.combobox_interval_mapping[i]
  598.             self.vbox_auto_updates.foreach((lambda b: b.toggled()))
  599.         else:
  600.             self.combobox_update_interval.set_sensitive(False)
  601.             self.vbox_auto_updates.set_sensitive(False)
  602.             SoftwareProperties.set_update_automation_level(self, None)
  603.             value = 0
  604.         self.set_update_interval(str(value))
  605.  
  606.     
  607.     def on_add_clicked(self, widget):
  608.         '''Show a dialog that allows to enter the apt line of a to be used repo'''
  609.         dialog = DialogAdd(self.window_main, self.sourceslist, self.datadir, self.distro)
  610.         line = dialog.run()
  611.         if line != None:
  612.             self.add_source_from_line(line)
  613.             self.set_modified_sourceslist()
  614.         
  615.  
  616.     
  617.     def on_edit_clicked(self, widget):
  618.         '''Show a dialog to edit an ISV source'''
  619.         sel = self.treeview_sources.get_selection()
  620.         (model, iter) = sel.get_selected()
  621.         if not iter:
  622.             return None
  623.         source_entry = model.get_value(iter, LIST_ENTRY_OBJ)
  624.         dialog = DialogEdit(self.window_main, self.sourceslist, source_entry, self.datadir)
  625.         if dialog.run() == gtk.RESPONSE_OK:
  626.             self.set_modified_sourceslist()
  627.         
  628.  
  629.     
  630.     def on_isv_source_activated(self, treeview, path, column):
  631.         '''Open the edit dialog if a channel was double clicked'''
  632.         if self.button_edit.get_property('sensitive') == True:
  633.             self.on_edit_clicked(treeview)
  634.         
  635.  
  636.     
  637.     def on_treeview_sources_cursor_changed(self, treeview):
  638.         '''set the sensitiveness of the edit and remove button
  639.        corresponding to the selected channel'''
  640.         sel = self.treeview_sources.get_selection()
  641.         (model, iter) = sel.get_selected()
  642.         if not iter:
  643.             self.button_edit.set_sensitive(False)
  644.             self.button_remove.set_sensitive(False)
  645.             return None
  646.         self.button_remove.set_sensitive(True)
  647.         source_entry = model.get_value(iter, LIST_ENTRY_OBJ)
  648.         if source_entry.uri.startswith('cdrom:'):
  649.             self.button_edit.set_sensitive(False)
  650.         else:
  651.             self.button_edit.set_sensitive(True)
  652.  
  653.     
  654.     def on_remove_clicked(self, widget):
  655.         '''Remove the selected source'''
  656.         model = self.treeview_sources.get_model()
  657.         (path, column) = self.treeview_sources.get_cursor()
  658.         iter = model.get_iter(path)
  659.         if iter:
  660.             self.remove_source(model.get_value(iter, LIST_ENTRY_OBJ))
  661.             self.set_modified_sourceslist()
  662.         
  663.  
  664.     
  665.     def add_key_clicked(self, widget):
  666.         '''Provide a file chooser that allows to add the gnupg of a trusted
  667.        software vendor'''
  668.         chooser = gtk.FileChooserDialog(title = _('Import key'), parent = self.window_main, buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
  669.         res = chooser.run()
  670.         chooser.hide()
  671.         if res == gtk.RESPONSE_ACCEPT:
  672.             if not self.add_key(chooser.get_filename()):
  673.                 error(self.window_main, _('Error importing selected file'), _('The selected file may not be a GPG key file or it might be corrupt.'))
  674.             
  675.             self.show_keys()
  676.         
  677.  
  678.     
  679.     def remove_key_clicked(self, widget):
  680.         '''Remove a trusted software vendor key'''
  681.         selection = self.treeview2.get_selection()
  682.         (model, a_iter) = selection.get_selected()
  683.         if a_iter == None:
  684.             return None
  685.         key = model.get_value(a_iter, 0)
  686.         if not self.remove_key(key[:8]):
  687.             error(self.main, _('Error removing the key'), _('The key you selected could not be removed. Please report this as a bug.'))
  688.         
  689.         self.show_keys()
  690.  
  691.     
  692.     def on_restore_clicked(self, widget):
  693.         '''Restore the original keys'''
  694.         self.apt_key.update()
  695.         self.show_keys()
  696.  
  697.     
  698.     def on_delete_event(self, widget, args):
  699.         '''Close the window if requested'''
  700.         self.on_close_button(widget)
  701.  
  702.     
  703.     def on_close_button(self, widget):
  704.         '''Show a dialog that a reload of the channel information is required
  705.        only if there is no parent defined'''
  706.         if self.modified_sourceslist == True and self.options.no_update == False:
  707.             d = DialogCacheOutdated(self.window_main, self.datadir)
  708.             res = d.run()
  709.         
  710.         self.quit()
  711.  
  712.     
  713.     def on_button_add_cdrom_clicked(self, widget):
  714.         '''Show a dialog that allows to add a repository located on a CDROM
  715.        or DVD'''
  716.         saved_entry = apt_pkg.Config.Find('Dir::Etc::sourcelist')
  717.         tmp = tempfile.NamedTemporaryFile()
  718.         apt_pkg.Config.Set('Dir::Etc::sourcelist', tmp.name)
  719.         progress = CdromProgress(self.datadir, self.window_main)
  720.         cdrom = apt_pkg.GetCdrom()
  721.         
  722.         try:
  723.             res = cdrom.Add(progress)
  724.         except SystemError:
  725.             msg = None
  726.             progress.close()
  727.             dialog = gtk.MessageDialog(parent = self.window_main, flags = gtk.DIALOG_MODAL, type = gtk.MESSAGE_ERROR, buttons = gtk.BUTTONS_OK, message_format = None)
  728.             dialog.set_markup(_('<big><b>Error scanning the CD</b></big>\n\n%s') % msg)
  729.             res = dialog.run()
  730.             dialog.destroy()
  731.             return None
  732.  
  733.         apt_pkg.Config.Set('Dir::Etc::sourcelist', saved_entry)
  734.         if res == False:
  735.             progress.close()
  736.             return None
  737.         line = ''
  738.         for x in open(tmp.name):
  739.             line = x
  740.         
  741.         if line != '':
  742.             full_path = '%s%s' % (apt_pkg.Config.FindDir('Dir::Etc'), saved_entry)
  743.             self.sourceslist.list.append(SourceEntry(line, full_path))
  744.             self.set_modified_sourceslist()
  745.         
  746.  
  747.  
  748.