2
# gnome-software-properties.in - edit /etc/apt/sources.list
4
# Copyright (c) 2004 Canonical
5
# 2004-2005 Michiel Sikkes
7
# Author: Michiel Sikkes <michiel@eyesopened.nl>
8
# Michael Vogt <mvo@debian.org>
10
# This program is free software; you can redistribute it and/or
11
# modify it under the terms of the GNU General Public License as
12
# published by the Free Software Foundation; either version 2 of the
13
# License, or (at your option) any later version.
15
# This program is distributed in the hope that it will be useful,
16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
# GNU General Public License for more details.
20
# You should have received a copy of the GNU General Public License
21
# along with this program; if not, write to the Free Software
22
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
33
sys.path.append("@prefix/share/update-manager/python")
35
from SimpleGladeApp import *
39
from dialog_apt_key import apt_key
42
(LIST_MARKUP, LIST_ENABLED, LIST_ENTRY_OBJ) = range(3)
45
"autoupdate" : "APT::Periodic::Update-Package-Lists",
46
"autodownload" : "APT::Periodic::Download-Upgradeable-Packages",
47
"autoclean" : "APT::Periodic::AutocleanInterval",
48
"max_size" : "APT::Archives::MaxSize",
49
"max_age" : "APT::Archives::MaxAge"
52
DATADIR = "@prefix@/share/update-manager"
55
class SoftwareProperties(SimpleGladeApp):
57
def __init__(self, gladefile, root, domain, options):
58
SimpleGladeApp.__init__(self, gladefile, None, domain)
65
self.gnome_program = gnome.init("Software Properties", "0.41")
66
self.gconfclient = gconf.client_get_default()
68
# Get some configuration options
69
self.show_disabled = self.gconfclient.get_bool("/apps/gnome-software-" \
70
"properties/show_disabled")
72
self.window_main.hide()
74
# If externally called, reparent to external application.
75
if (options.socket != None):
76
plug = gtk.Plug(long(options.socket))
77
self.vbox1.reparent(plug)
80
self.window_main.show()
82
self.init_sourceslist()
83
self.reload_sourceslist()
85
update_days = apt_pkg.Config.FindI(CONF_MAP["autoupdate"])
87
self.spinbutton_update_interval.set_value(update_days)
90
self.checkbutton_auto_update.set_active(True)
92
self.checkbutton_auto_update.set_active(False)
94
self.apt_key = apt_key()
97
self.reload_keyslist()
99
def init_sourceslist(self):
100
self.source_store = gtk.ListStore(str, bool, gobject.TYPE_PYOBJECT)
101
self.treeview1.set_model(self.source_store)
103
tr = gtk.CellRendererText()
105
source_col = gtk.TreeViewColumn("Description", tr, markup=LIST_MARKUP)
106
source_col.set_max_width(500)
107
self.treeview1.append_column(source_col)
109
self.sourceslist = aptsources.SourcesList()
110
self.matcher = aptsources.SourceEntryMatcher()
112
def init_keyslist(self):
113
self.keys_store = gtk.ListStore(str)
114
self.treeview2.set_model(self.keys_store)
116
tr = gtk.CellRendererText()
118
keys_col = gtk.TreeViewColumn("Key", tr, text=0)
119
self.treeview2.append_column(keys_col)
121
def reload_sourceslist(self):
122
self.source_store.clear()
123
for source in self.sourceslist.list:
124
if source.invalid or source.disabled:
126
(a_type, dists, comps) = self.matcher.match(source)
129
if source.comment != "":
130
contents += "<i>%s</i>\n\n" % (source.comment)
131
contents += "%s <small>(%s)</small>" % (dists, a_type)
133
self.source_store.append([contents, not source.disabled, source])
135
def reload_keyslist(self):
136
self.keys_store.clear()
137
for key in self.apt_key.list():
138
self.keys_store.append([key])
140
def opt_autoupdate_toggled(self, widget):
141
if self.checkbutton_auto_update.get_active():
142
if self.spinbutton_update_interval.get_value() == 0:
143
self.spinbutton_update_interval.set_value(1)
146
value = str(self.spinbutton_update_interval.get_value())
150
apt_pkg.Config.Set(CONF_MAP["autoupdate"], str(value))
152
# FIXME: Write config options, apt_pkg should be able to do this.
155
def write_config(self):
156
periodic = "/etc/apt/apt.conf.d/10periodic"
160
if os.path.isfile(periodic):
161
content = open(periodic, "r").readlines()
163
cnf = apt_pkg.Config.SubTree("APT::Periodic")
165
f = open(periodic, "w+")
168
for key in cnf.List():
169
if line.find("APT::Periodic::%s" % (key)) >= 0:
176
f.write("APT::Periodic::%s \"%s\";\n" % (i, cnf.FindI(i)))
179
def save_sourceslist(self):
180
location = "/etc/apt/sources.list"
181
shutil.copy(location, location + ".save")
182
self.sourceslist.save(location)
184
def on_add_clicked(self, widget):
185
dialog = dialog_add.dialog_add(self.window_main, self.sourceslist, DATADIR)
186
if dialog.run() == gtk.RESPONSE_OK:
187
self.reload_sourceslist()
191
def on_edit_clicked(self, widget):
192
sel = self.treeview1.get_selection()
193
(model, iter) = sel.get_selected()
194
source_entry = model.get_value(iter, LIST_ENTRY_OBJ)
196
dialog = dialog_edit.dialog_edit(self.window_main, self.sourceslist,
197
source_entry, DATADIR)
199
if dialog.run() == gtk.RESPONSE_OK:
200
self.reload_sourceslist()
204
def on_remove_clicked(self, widget):
205
sel = self.treeview1.get_selection()
206
(model, iter) = sel.get_selected()
209
source = model.get_value(iter, LIST_ENTRY_OBJ)
210
self.sourceslist.remove(source)
211
self.reload_sourceslist()
215
def add_key_clicked(self, widget):
217
chooser = gtk.FileChooserDialog(title=_("Choose a key-file"),
218
parent=self.window_main,
219
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_REJECT,
220
gtk.STOCK_OK,gtk.RESPONSE_ACCEPT))
223
if res == gtk.RESPONSE_ACCEPT:
224
if not self.apt_key.add(chooser.get_filename()):
225
error(self.window_main,
226
_("Error importing selected file"),
227
_("The selected file may not be a GPG key file " \
228
"or it might be corrupt."))
229
self.reload_keyslist()
231
def remove_key_clicked(self, widget):
232
selection = self.treeview2.get_selection()
233
(model,a_iter) = selection.get_selected()
236
key = model.get_value(a_iter,0)
237
if not self.apt_key.rm(key[:8]):
239
_("Error removing the key"),
240
_("The key you selected could not be removed. "
241
"Please report this as a bug."))
242
self.reload_keyslist()
244
def on_restore_clicked(self, widget):
245
self.apt_key.update()
246
self.reload_keyslist()
248
def on_delete_event(self, widget, args):
249
self.save_sourceslist()
252
def on_close_button(self, widget):
253
self.save_sourceslist()
256
def on_help_button(self, widget):
257
gnome.help_display_desktop(self.gnome_program,
258
"update-manager", "update-manager",
259
"setting-preferences")