~ilidrissi.amine/software-properties/updates-redesign

« back to all changes in this revision

Viewing changes to softwareproperties/gtk/DialogAptKey.py

  • Committer: Mohamed Amine IL Idrissi
  • Date: 2010-10-02 14:27:09 UTC
  • mfrom: (606.1.29 main)
  • Revision ID: ilidrissiamine@gmail.com-20101002142709-nu4jxh0hoda4tspc
merge with trunk and fix the kde frontend.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# dialog_apt_key.py.in - edit the apt keys
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
 
import subprocess
27
 
import gettext
28
 
from utils import *
29
 
from subprocess import PIPE
30
 
 
31
 
# gettext convenient
32
 
_ = gettext.gettext
33
 
def dummy(e): return e
34
 
N_ = dummy
35
 
 
36
 
# some known keys
37
 
N_("Ubuntu Archive Automatic Signing Key <ftpmaster@ubuntu.com>")
38
 
N_("Ubuntu CD Image Automatic Signing Key <cdimage@ubuntu.com>")
39
 
 
40
 
class DialogAddKey:
41
 
  """This class is currently not used anymore"""
42
 
  def __init__(self, parent, datadir):
43
 
    # gtk stuff
44
 
    if os.path.exists("../data/dialogs.glade"):
45
 
      self.gladexml = gtk.glade.XML("../data/dialogs.glade")
46
 
    else:
47
 
      self.gladexml = gtk.glade.XML("%s/dialogs.glade", datadir)
48
 
    self.main = self.gladexml.get_widget("dialog_apt_key")
49
 
    self.main.set_transient_for(parent)
50
 
 
51
 
    self.gladexml.signal_connect("on_button_key_add_clicked",
52
 
                                 self.on_button_key_add_clicked)
53
 
    self.gladexml.signal_connect("on_button_key_remove_clicked",
54
 
                                 self.on_button_key_remove_clicked)
55
 
    self.gladexml.signal_connect("on_button_apt_key_update_clicked",
56
 
                                 self.on_button_apt_key_update_clicked)
57
 
 
58
 
    # create apt-key object (abstraction for the apt-key command)
59
 
    self.apt_key = apt_key()
60
 
    
61
 
    # get some widgets
62
 
    self.treeview_apt_key = self.gladexml.get_widget("treeview_apt_key")
63
 
    self.liststore_apt_key = gtk.ListStore(str)
64
 
    self.treeview_apt_key.set_model(self.liststore_apt_key)
65
 
    # Create columns and append them.
66
 
    tr = gtk.CellRendererText()
67
 
    tr.set_property("xpad", 10)
68
 
    tr.set_property("ypad", 10)
69
 
    c0 = gtk.TreeViewColumn("Key", tr, text=0)
70
 
    self.treeview_apt_key.append_column(c0)
71
 
    self.update_key_list()
72
 
 
73
 
  def on_button_apt_key_update_clicked(self, widget):
74
 
      self.apt_key.update()
75
 
      self.update_key_list()
76
 
 
77
 
  def on_button_key_add_clicked(self, widget):
78
 
      chooser = gtk.FileChooserDialog(title=_("Choose a key-file"),
79
 
                                      parent=self.main,
80
 
                                      buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_REJECT,
81
 
                                               gtk.STOCK_OK,gtk.RESPONSE_ACCEPT))
82
 
      res = chooser.run()
83
 
      chooser.hide()
84
 
      if res == gtk.RESPONSE_ACCEPT:
85
 
          #print chooser.get_filename()
86
 
          if not self.apt_key.add(chooser.get_filename()):
87
 
              dialog_error(self.main,
88
 
                    _("Error importing selected file"),
89
 
                    _("The selected file may not be a GPG key file "
90
 
                      "or it might be corrupt."))
91
 
          self.update_key_list()
92
 
          
93
 
  def on_button_key_remove_clicked(self, widget):
94
 
      selection = self.treeview_apt_key.get_selection()
95
 
      (model,a_iter) = selection.get_selected()
96
 
      if a_iter == None:
97
 
          return
98
 
      key = model.get_value(a_iter,0)
99
 
      if not self.apt_key.rm(key[:8]):
100
 
          error(self.main,
101
 
                _("Error removing the key"),
102
 
                _("The key you selected could not be removed. "
103
 
                  "Please report this as a bug."))
104
 
      self.update_key_list()
105
 
 
106
 
  def update_key_list(self):
107
 
      self.liststore_apt_key.clear()
108
 
      for key in self.apt_key.list():
109
 
          self.liststore_apt_key.append([key])
110
 
 
111
 
  def run(self):
112
 
      res = self.main.run()
113
 
      self.main.hide()
114
 
 
115
 
 
116
 
if __name__ == "__main__":
117
 
    ui = dialog_apt_key(None)
118
 
    ui.run()
119