1
# dialog_add.py.in - dialog to add a new repository
3
# Copyright (c) 2004 Canonical
7
# Michael Vogt <mvo@debian.org>
8
# Michiel Sikkes <michiels@gnome.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
def __init__(self, parent, sourceslist, datadir):
35
self.sourceslist = sourceslist
38
self.templatelist = aptsources.SourceEntryTemplates()
41
if os.path.exists("../data/SoftwarePropertiesDialogs.glade"):
42
self.gladexml = gtk.glade.XML("../data/SoftwarePropertiesDialogs.glade")
44
self.gladexml = gtk.glade.XML("%s/SoftwarePropertiesDialogs.glade" % datadir)
46
self.main = widget = self.gladexml.get_widget("dialog_add")
47
self.main.set_transient_for(parent)
49
combo = self.gladexml.get_widget("combobox_what")
50
self.gladexml.signal_connect("on_combobox_what_changed", self.on_combobox_what_changed, None)
52
cell = gtk.CellRendererText()
53
combo.pack_start(cell, True)
54
combo.add_attribute(cell, 'text', 0)
55
self.fill_combo(combo)
56
self.gladexml.signal_connect("on_button_custom_clicked",
57
self.on_button_custom_clicked, None)
60
def fill_combo(self,combo):
61
liststore = gtk.ListStore(gobject.TYPE_STRING,gobject.TYPE_PYOBJECT)
62
for item in self.templatelist.templates:
63
liststore.append((item.description, item))
64
combo.set_model(liststore)
67
def on_combobox_what_changed(self, combobox, user):
68
#print "on_combobox_what_changed"
69
vbox = self.gladexml.get_widget("vbox_comps")
70
vbox.foreach(lambda widget,vbox: vbox.remove(widget), vbox)
71
liststore = combobox.get_model()
72
a_iter = liststore.iter_nth_child(None, combobox.get_active())
73
(name, template) = liststore.get(a_iter, 0,1)
74
self.selected = template
75
comps = template.comps
77
checkbox = gtk.CheckButton(c.description)
78
checkbox.set_active(c.on_by_default)
79
checkbox.set_data("name",c.name)
80
vbox.pack_start(checkbox)
83
def on_button_custom_clicked(self, widget, data):
84
#print "on_button_custom_clicked()"
85
# this hide here is ugly :/
87
dialog = self.gladexml.get_widget("dialog_add_custom")
90
entry = self.gladexml.get_widget("entry_source_line")
91
line = entry.get_text() + "\n"
92
self.sourceslist.list.append(aptsources.SourceEntry(line))
93
self.main.response(res)
95
def get_enabled_comps(self, checkbutton):
96
if checkbutton.get_active():
97
self.selected_comps.append(checkbutton.get_data("name"))
100
res = self.main.run()
101
if res == gtk.RESPONSE_OK:
103
self.selected_comps = []
104
vbox = self.gladexml.get_widget("vbox_comps")
105
vbox.foreach(self.get_enabled_comps)
106
self.sourceslist.add(self.selected.type,