home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / python2.4 / site-packages / SoftwareProperties / dialog_edit.py < prev    next >
Encoding:
Python Source  |  2006-08-24  |  4.6 KB  |  140 lines

  1. # dialog_edit.py.in - edit a existing repository
  2. #  
  3. #  Copyright (c) 2004-2005 Canonical
  4. #                2005 Michiel Sikkes
  5. #  
  6. #  Authors: 
  7. #       Michael Vogt <mvo@debian.org>
  8. #       Michiel Sikkes <michiels@gnome.org>
  9. #  This program is free software; you can redistribute it and/or 
  10. #  modify it under the terms of the GNU General Public License as 
  11. #  published by the Free Software Foundation; either version 2 of the
  12. #  License, or (at your option) any later version.
  13. #  This program is distributed in the hope that it will be useful,
  14. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. #  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
  20. #  USA
  21.  
  22. import os
  23. import gobject
  24. import gtk
  25. import gtk.glade
  26.  
  27. import UpdateManager.Common.aptsources as aptsources
  28.  
  29. class dialog_edit:
  30.   def __init__(self, parent, sourceslist, source_entry, datadir):
  31.     self.sourceslist = sourceslist
  32.     self.source_entry = source_entry
  33.  
  34.     # gtk stuff
  35.     if os.path.exists("../data/SoftwarePropertiesDialogs.glade"):
  36.       self.gladexml = gtk.glade.XML("../data/SoftwarePropertiesDialogs.glade")
  37.     else:
  38.       self.gladexml = gtk.glade.XML("%s/glade/SoftwarePropertiesDialogs.glade" % datadir)
  39.     self.main = self.gladexml.get_widget("dialog_edit")
  40.     self.main.set_transient_for(parent)
  41.     self.button_edit_ok = self.gladexml.get_widget("button_edit_ok")
  42.     
  43.     # type
  44.     combo_type = self.gladexml.get_widget("combobox_type")
  45.     if source_entry.type == "deb":
  46.       combo_type.set_active(0)
  47.     elif source_entry.type == "deb-src":
  48.       combo_type.set_active(1)
  49.     else:
  50.       print "Error, unknown source type: '%s'" % source_enrty.type
  51.  
  52.     # uri
  53.     entry = self.gladexml.get_widget("entry_uri")
  54.     entry.set_text(source_entry.uri)
  55.  
  56.     entry = self.gladexml.get_widget("entry_dist")
  57.     entry.set_text(source_entry.dist)
  58.  
  59.     entry = self.gladexml.get_widget("entry_comps")
  60.     comps = ""
  61.     for c in source_entry.comps:
  62.       if len(comps) > 0:
  63.         comps = comps + " " + c
  64.       else:
  65.         comps = c
  66.     entry.set_text(comps)
  67.  
  68.     entry = self.gladexml.get_widget("entry_comment")
  69.     entry.set_text(source_entry.comment)
  70.  
  71.     # finally set the signal so that the check function is not tiggered 
  72.     # during initialisation
  73.     self.gladexml.signal_connect("on_entry_source_line_changed",
  74.                                  self.check_line)
  75.  
  76.   def check_line(self, *args):
  77.     """Check for a valid apt line and set the sensitiveness of the
  78.        button 'add' accordingly"""
  79.     line = self.get_line()
  80.     if line == False:
  81.       self.button_edit_ok.set_sensitive(False)
  82.       return
  83.     source_entry = aptsources.SourceEntry(line)
  84.     if (source_entry.invalid == True or source_entry.disabled == True):
  85.       self.button_edit_ok.set_sensitive(False)
  86.     else:
  87.       self.button_edit_ok.set_sensitive(True)
  88.  
  89.   def get_line(self):
  90.     """Collect all values from the entries and create an apt line"""
  91.     combo_type = self.gladexml.get_widget("combobox_type")
  92.     if combo_type.get_active() == 0:
  93.       line = "deb"
  94.     else:
  95.       line = "deb-src"
  96.  
  97.     entry = self.gladexml.get_widget("entry_uri")
  98.     text = entry.get_text()
  99.     if len(text) < 1 or text.find(" ") != -1 or text.find("#") != -1:
  100.       return False  
  101.     line = line + " " + entry.get_text()
  102.  
  103.     entry = self.gladexml.get_widget("entry_dist")
  104.     text = entry.get_text()
  105.     if len(text) < 1 or text.find(" ") != -1 or text.find("#") != -1:
  106.       return False    
  107.     line = line + " " + entry.get_text()
  108.  
  109.     entry = self.gladexml.get_widget("entry_comps")
  110.     text = entry.get_text()
  111.     if len(text) < 1 or text.find("#") != -1:
  112.       return False    
  113.     line = line + " " + entry.get_text()
  114.  
  115.     entry = self.gladexml.get_widget("entry_comment")
  116.     if entry.get_text() != "":
  117.       line = line + " #" + entry.get_text() + "\n"
  118.     else:
  119.       line = line + "\n"
  120.     return line
  121.           
  122.   def run(self):
  123.       res = self.main.run()
  124.       if res == gtk.RESPONSE_OK:
  125.         line = self.get_line()
  126.  
  127.         # change repository
  128.         index = self.sourceslist.list.index(self.source_entry)
  129.         file = self.sourceslist.list[index].file
  130.         self.sourceslist.list[index] = aptsources.SourceEntry(line,file)
  131.         #self.sourceslist.add(self.selected.type,
  132.         #                     self.selected.uri,
  133.         #                     self.selected.dist,
  134.         #                     self.selected_comps)
  135.       self.main.hide()
  136.       return res
  137.