~ubuntu-core-dev/ubuntu-release-upgrader/trunk

« back to all changes in this revision

Viewing changes to SoftwareProperties/dialog_add.py

  • Committer: Michael Vogt
  • Date: 2005-11-15 13:18:07 UTC
  • Revision ID: egon@top-20051115131807-12fada324eb74180
* initial revision (after accidently killing it)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# dialog_add.py.in - dialog to add a new repository
 
2
#  
 
3
#  Copyright (c) 2004 Canonical
 
4
#                2005 Michiel Sikkes
 
5
#              
 
6
#  Authors: 
 
7
#       Michael Vogt <mvo@debian.org>
 
8
#       Michiel Sikkes <michiels@gnome.org>
 
9
 
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.
 
14
 
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.
 
19
 
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
 
23
#  USA
 
24
 
 
25
import os
 
26
import gobject
 
27
import gtk
 
28
import gtk.glade
 
29
 
 
30
import aptsources
 
31
 
 
32
class dialog_add:
 
33
  def __init__(self, parent, sourceslist, datadir):
 
34
    print datadir
 
35
    self.sourceslist = sourceslist
 
36
 
 
37
    # templates
 
38
    self.templatelist = aptsources.SourceEntryTemplates()
 
39
 
 
40
    # gtk stuff
 
41
    if os.path.exists("../data/SoftwarePropertiesDialogs.glade"):
 
42
      self.gladexml = gtk.glade.XML("../data/SoftwarePropertiesDialogs.glade")
 
43
    else:
 
44
      self.gladexml = gtk.glade.XML("%s/SoftwarePropertiesDialogs.glade" % datadir)
 
45
    
 
46
    self.main = widget = self.gladexml.get_widget("dialog_add")
 
47
    self.main.set_transient_for(parent)
 
48
    
 
49
    combo = self.gladexml.get_widget("combobox_what")
 
50
    self.gladexml.signal_connect("on_combobox_what_changed", self.on_combobox_what_changed, None)
 
51
    # combox box needs 
 
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)
 
58
 
 
59
 
 
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)
 
65
    combo.set_active(0)
 
66
 
 
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
 
76
    for c in 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)
 
81
      checkbox.show()
 
82
 
 
83
  def on_button_custom_clicked(self, widget, data):
 
84
    #print "on_button_custom_clicked()"
 
85
    # this hide here is ugly :/
 
86
    self.main.hide()
 
87
    dialog = self.gladexml.get_widget("dialog_add_custom")
 
88
    res = dialog.run()
 
89
    dialog.hide()
 
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)
 
94
 
 
95
  def get_enabled_comps(self, checkbutton):
 
96
    if checkbutton.get_active():
 
97
      self.selected_comps.append(checkbutton.get_data("name"))
 
98
  
 
99
  def run(self):
 
100
      res = self.main.run()
 
101
      if res == gtk.RESPONSE_OK:
 
102
          # add repository
 
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,
 
107
                               self.selected.uri,
 
108
                               self.selected.dist,
 
109
                               self.selected_comps)
 
110
      self.main.hide()
 
111
      return res