1
# dialog_add.py.in - dialog to add a new repository
3
# Copyright (c) 2004 Canonical
5
# Author: Michael Vogt <mvo@debian.org>
7
# This program is free software; you can redistribute it and/or
8
# modify it under the terms of the GNU General Public License as
9
# published by the Free Software Foundation; either version 2 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
30
def __init__(self,parent,sourceslist):
31
self.sourceslist = sourceslist
34
self.templatelist = aptsources.SourceEntryTemplates()
37
if os.path.exists("../data/gnome-software-properties.glade"):
38
self.gladexml = gtk.glade.XML("../data/gnome-software-properties.glade")
40
self.gladexml = gtk.glade.XML("@prefix@/share/update-manager/gnome-software-properties.glade")
42
self.main = widget = self.gladexml.get_widget("dialog_add")
43
self.main.set_transient_for(parent)
45
combo = self.gladexml.get_widget("combobox_what")
46
self.gladexml.signal_connect("on_combobox_what_changed", self.on_combobox_what_changed, None)
48
cell = gtk.CellRendererText()
49
combo.pack_start(cell, True)
50
combo.add_attribute(cell, 'text', 0)
51
self.fill_combo(combo)
52
self.gladexml.signal_connect("on_button_custom_clicked",
53
self.on_button_custom_clicked, None)
56
def fill_combo(self,combo):
57
liststore = gtk.ListStore(gobject.TYPE_STRING,gobject.TYPE_PYOBJECT)
58
for item in self.templatelist.templates:
59
liststore.append((item.description, item))
60
combo.set_model(liststore)
63
def on_combobox_what_changed(self, combobox, user):
64
#print "on_combobox_what_changed"
65
vbox = self.gladexml.get_widget("vbox_comps")
66
vbox.foreach(lambda widget,vbox: vbox.remove(widget), vbox)
67
liststore = combobox.get_model()
68
a_iter = liststore.iter_nth_child(None, combobox.get_active())
69
(name, template) = liststore.get(a_iter, 0,1)
70
self.selected = template
71
comps = template.comps
73
checkbox = gtk.CheckButton(c.description)
74
checkbox.set_active(c.on_by_default)
75
checkbox.set_data("name",c.name)
76
vbox.pack_start(checkbox)
79
def on_button_custom_clicked(self, widget, data):
80
#print "on_button_custom_clicked()"
81
# this hide here is ugly :/
83
dialog = self.gladexml.get_widget("dialog_add_custom")
86
entry = self.gladexml.get_widget("entry_source_line")
87
line = entry.get_text() + "\n"
88
self.sourceslist.list.append(aptsources.SourceEntry(line))
89
self.main.response(res)
91
def get_enabled_comps(self, checkbutton):
92
if checkbutton.get_active():
93
self.selected_comps.append(checkbutton.get_data("name"))
97
if res == gtk.RESPONSE_OK:
99
self.selected_comps = []
100
vbox = self.gladexml.get_widget("vbox_comps")
101
vbox.foreach(self.get_enabled_comps)
102
self.sourceslist.add(self.selected.type,