示例#1
0
    def __init__(self, datadir=None, options=None, parent=None, file=None):
        gtk.window_set_default_icon_name("software-properties")
        self.popconfile = "/etc/popularity-contest.conf"

        # FIXME: some saner way is needed here
        if datadir == None:
            datadir = "/usr/share/update-manager/"
        self.datadir = datadir
        SimpleGladeApp.__init__(self,
                                datadir + "glade/SoftwareProperties.glade",
                                None,
                                domain="update-manager")
        self.modified = False

        self.file = file

        self.distro = aptsources.Distribution()
        cell = gtk.CellRendererText()
        self.combobox_server.pack_start(cell, True)
        self.combobox_server.add_attribute(cell, 'text', 0)

        # set up the handler id for the callbacks
        self.handler_server_changed = self.combobox_server.connect(
            "changed", self.on_combobox_server_changed)
        self.handler_source_code_changed = self.checkbutton_source_code.connect(
            "toggled", self.on_checkbutton_source_code_toggled)

        if parent:
            self.window_main.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
            self.window_main.show()
            self.window_main.set_transient_for(parent)

        # If externally called, reparent to external application.
        self.options = options
        if options and options.toplevel != None:
            self.window_main.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
            self.window_main.show()
            toplevel = gtk.gdk.window_foreign_new(int(options.toplevel))
            self.window_main.window.set_transient_for(toplevel)

        self.init_sourceslist()
        self.reload_sourceslist()
        self.backup_sourceslist()

        self.window_main.show()

        # this maps the key (combo-box-index) to the auto-update-interval value
        # where (-1) means, no key
        self.combobox_interval_mapping = {0: 1, 1: 2, 2: 7, 3: 14}
        self.combobox_update_interval.set_active(0)

        update_days = apt_pkg.Config.FindI(CONF_MAP["autoupdate"])

        self.combobox_update_interval.append_text(_("Daily"))
        self.combobox_update_interval.append_text(_("Every two days"))
        self.combobox_update_interval.append_text(_("Weekly"))
        self.combobox_update_interval.append_text(_("Every two weeks"))

        # If a custom period is defined add an corresponding entry
        if not update_days in self.combobox_interval_mapping.values():
            if update_days > 0:
                self.combobox_update_interval.append_text(
                    _("Every %s days") % update_days)
                self.combobox_interval_mapping[4] = update_days

        for key in self.combobox_interval_mapping:
            if self.combobox_interval_mapping[key] == update_days:
                self.combobox_update_interval.set_active(key)
                break

        if update_days >= 1:
            self.checkbutton_auto_update.set_active(True)
            self.combobox_update_interval.set_sensitive(True)
        else:
            self.checkbutton_auto_update.set_active(False)
            self.combobox_update_interval.set_sensitive(False)

        # Automatic removal of cached packages by age
        self.combobox_delete_interval_mapping = {0: 7, 1: 14, 2: 30}

        delete_days = apt_pkg.Config.FindI(CONF_MAP["max_age"])

        self.combobox_delete_interval.append_text(_("After one week"))
        self.combobox_delete_interval.append_text(_("After two weeks"))
        self.combobox_delete_interval.append_text(_("After one month"))

        # If a custom period is defined add an corresponding entry
        if not delete_days in self.combobox_delete_interval_mapping.values():
            if delete_days > 0 and CONF_MAP["autoclean"] != 0:
                self.combobox_delete_interval.append_text(
                    _("After %s days") % delete_days)
                self.combobox_delete_interval_mapping[3] = delete_days

        for key in self.combobox_delete_interval_mapping:
            if self.combobox_delete_interval_mapping[key] == delete_days:
                self.combobox_delete_interval.set_active(key)
                break

        if delete_days >= 1 and apt_pkg.Config.FindI(
                CONF_MAP["autoclean"]) != 0:
            self.checkbutton_auto_delete.set_active(True)
            self.combobox_delete_interval.set_sensitive(True)
        else:
            self.checkbutton_auto_delete.set_active(False)
            self.combobox_delete_interval.set_sensitive(False)

        # Autodownload
        if apt_pkg.Config.FindI(CONF_MAP["autodownload"]) == 1:
            self.checkbutton_auto_download.set_active(True)
        else:
            self.checkbutton_auto_download.set_active(False)

        # Unattended updates
        if os.path.exists("/usr/bin/unattended-upgrade"):
            # FIXME: we should always show the option. if unattended-upgrades is
            # not installed a dialog should popup and allow the user to install
            # unattended-upgrade
            #self.checkbutton_unattended.set_sensitive(True)
            self.checkbutton_unattended.show()
        else:
            #self.checkbutton_unattended.set_sensitive(False)
            self.checkbutton_unattended.hide()
        if apt_pkg.Config.FindI(CONF_MAP["unattended"]) == 1:
            self.checkbutton_unattended.set_active(True)
        else:
            self.checkbutton_unattended.set_active(False)

        self.help_viewer = HelpViewer("update-manager#setting-preferences")
        if self.help_viewer.check() == False:
            self.button_help.set_sensitive(False)

        # apt-key stuff
        self.apt_key = apt_key()
        self.init_keyslist()
        self.reload_keyslist()

        # drag and drop support for sources.list
        self.treeview_sources.drag_dest_set(gtk.DEST_DEFAULT_ALL, \
                                            [('text/uri-list',0, 0)], \
                                            gtk.gdk.ACTION_COPY)
        self.treeview_sources.connect("drag_data_received",\
                                      self.on_sources_drag_data_received)

        # popcon
        if os.path.exists(self.popconfile):
            # read it
            lines = open(self.popconfile).read().split("\n")
            active = False
            for line in lines:
                try:
                    (key, value) = line.split("=")
                    if key == "PARTICIPATE":
                        if value.strip('"').lower() == "yes":
                            active = True
                except ValueError:
                    continue
            self.checkbutton_popcon.set_active(active)

        # call the add sources.list dialog if we got a file from the cli
        if self.file != None:
            self.open_file(file)