~ubuntu-core-dev/software-properties/main

« back to all changes in this revision

Viewing changes to src/dialog_add.py.in

  • 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
#              
 
5
#  Author: Michael Vogt <mvo@debian.org>
 
6
 
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.
 
11
 
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.
 
16
 
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
 
20
#  USA
 
21
 
 
22
import os
 
23
import gobject
 
24
import gtk
 
25
import gtk.glade
 
26
 
 
27
import aptsources
 
28
 
 
29
class dialog_add:
 
30
  def __init__(self,parent,sourceslist):
 
31
    self.sourceslist = sourceslist
 
32
 
 
33
    # templates
 
34
    self.templatelist = aptsources.SourceEntryTemplates()
 
35
 
 
36
    # gtk stuff
 
37
    if os.path.exists("../data/gnome-software-properties.glade"):
 
38
      self.gladexml = gtk.glade.XML("../data/gnome-software-properties.glade")
 
39
    else:
 
40
      self.gladexml = gtk.glade.XML("@prefix@/share/update-manager/gnome-software-properties.glade")
 
41
    
 
42
    self.main = widget = self.gladexml.get_widget("dialog_add")
 
43
    self.main.set_transient_for(parent)
 
44
    
 
45
    combo = self.gladexml.get_widget("combobox_what")
 
46
    self.gladexml.signal_connect("on_combobox_what_changed", self.on_combobox_what_changed, None)
 
47
    # combox box needs 
 
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)
 
54
 
 
55
 
 
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)
 
61
    combo.set_active(0)
 
62
 
 
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
 
72
    for c in 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)
 
77
      checkbox.show()
 
78
 
 
79
  def on_button_custom_clicked(self, widget, data):
 
80
    #print "on_button_custom_clicked()"
 
81
    # this hide here is ugly :/
 
82
    self.main.hide()
 
83
    dialog = self.gladexml.get_widget("dialog_add_custom")
 
84
    res = dialog.run()
 
85
    dialog.hide()
 
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)
 
90
 
 
91
  def get_enabled_comps(self, checkbutton):
 
92
    if checkbutton.get_active():
 
93
      self.selected_comps.append(checkbutton.get_data("name"))
 
94
  
 
95
  def run(self):
 
96
      res = self.main.run()
 
97
      if res == gtk.RESPONSE_OK:
 
98
          # add repository
 
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,
 
103
                               self.selected.uri,
 
104
                               self.selected.dist,
 
105
                               self.selected_comps)
 
106
      self.main.hide()
 
107
      return res