~ubuntu-core-dev/update-manager/main

1 by Michael Vogt
* initial revision (after accidently killing it)
1
# dialog_edit.py.in - edit a existing 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_edit:
33
  def __init__(self, parent, sourceslist, source_entry, datadir):
34
    self.sourceslist = sourceslist
35
    self.source_entry = source_entry
36
37
    # gtk stuff
38
    if os.path.exists("../data/SoftwarePropertiesDialogs.glade"):
39
      self.gladexml = gtk.glade.XML("../data/SoftwarePropertiesDialogs.glade")
40
    else:
41
      self.gladexml = gtk.glade.XML("%s/SoftwarePropertiesDialogs.glade" % datadir)
42
    self.main = self.gladexml.get_widget("dialog_edit")
43
    self.main.set_transient_for(parent)
44
    
45
    # type
46
    combo_type = self.gladexml.get_widget("combobox_type")
47
    if source_entry.type == "deb":
48
      combo_type.set_active(0)
49
    elif source_entry.type == "deb-src":
50
      combo_type.set_active(1)
51
    else:
52
      print "Error, unknown source type: '%s'" % source_enrty.type
53
54
    # uri
55
    entry = self.gladexml.get_widget("entry_uri")
56
    entry.set_text(source_entry.uri)
57
58
    entry = self.gladexml.get_widget("entry_dist")
59
    entry.set_text(source_entry.dist)
60
61
    entry = self.gladexml.get_widget("entry_comps")
62
    comps = ""
63
    for c in source_entry.comps:
64
      if len(comps) > 0:
65
        comps = comps + " " + c
66
      else:
67
        comps = c
68
    entry.set_text(comps)
69
70
    entry = self.gladexml.get_widget("entry_comment")
71
    entry.set_text(source_entry.comment)
72
73
  def run(self):
74
      res = self.main.run()
75
      if res == gtk.RESPONSE_OK:
76
        # get values
77
        combo_type = self.gladexml.get_widget("combobox_type")
78
        if combo_type.get_active() == 0:
79
          line = "deb"
80
        else:
81
          line = "deb-src"
82
        entry = self.gladexml.get_widget("entry_uri")
83
        line = line + " " + entry.get_text()
84
85
        entry = self.gladexml.get_widget("entry_dist")
86
        line = line + " " + entry.get_text()
87
88
        entry = self.gladexml.get_widget("entry_comps")
89
        line = line + " " + entry.get_text()
90
91
        entry = self.gladexml.get_widget("entry_comment")
92
        if entry.get_text() != "":
93
          line = line + " #" + entry.get_text() + "\n"
94
        else:
95
          line = line + "\n"
96
97
        # change repository
98
        index = self.sourceslist.list.index(self.source_entry)
99
        file = self.sourceslist.list[index].file
100
        self.sourceslist.list[index] = aptsources.SourceEntry(line,file)
101
        #self.sourceslist.add(self.selected.type,
102
        #                     self.selected.uri,
103
        #                     self.selected.dist,
104
        #                     self.selected_comps)
105
      self.main.hide()
106
      return res