/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to revisionview.py

  • Committer: Daniel Schierbeck
  • Date: 2008-04-01 22:27:50 UTC
  • mto: (461.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 462.
  • Revision ID: daniel.schierbeck@gmail.com-20080401222750-a9ta5rbydf7fy8ew
Made the bug icon be installed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import gtk
21
21
import pango
22
22
import gobject
23
 
import webbrowser
 
23
import subprocess
24
24
 
 
25
from bzrlib.plugins.gtk import icon_path
25
26
from bzrlib.osutils import format_date
26
27
from bzrlib.util.bencode import bdecode
27
 
from bzrlib.testament import Testament
28
 
 
29
 
from bzrlib.plugins.gtk import icon_path
30
 
 
31
 
try:
32
 
    from bzrlib.plugins.gtk import seahorse
33
 
except ImportError:
34
 
    has_seahorse = False
35
 
else:
36
 
    has_seahorse = True
37
 
 
38
 
PAGE_GENERAL = 0
39
 
PAGE_RELATIONS = 1
40
 
PAGE_SIGNATURE = 2
41
 
PAGE_BUGS = 3
42
 
 
43
28
 
44
29
def _open_link(widget, uri):
45
 
    for cmd in ['sensible-browser', 'xdg-open']:
46
 
        if webbrowser._iscommand(cmd):
47
 
            webbrowser._tryorder.insert(0, '%s "%%s"' % cmd)
48
 
    webbrowser.open(uri)
 
30
    subprocess.Popen(['sensible-browser', uri], close_fds=True)
49
31
 
50
32
gtk.link_button_set_uri_hook(_open_link)
51
33
 
52
34
class BugsTab(gtk.VBox):
53
 
 
54
35
    def __init__(self):
55
36
        super(BugsTab, self).__init__(False, 6)
56
 
    
 
37
 
57
38
        table = gtk.Table(rows=2, columns=2)
58
39
 
59
40
        table.set_row_spacings(6)
60
 
        table.set_col_spacing(0, 16)
 
41
        table.set_col_spacings(12)
61
42
 
62
43
        image = gtk.Image()
63
44
        image.set_from_file(icon_path("bug.png"))
64
45
        table.attach(image, 0, 1, 0, 1, gtk.FILL)
65
46
 
66
47
        align = gtk.Alignment(0.0, 0.1)
67
 
        self.label = gtk.Label()
68
 
        align.add(self.label)
 
48
        label = gtk.Label()
 
49
        label.set_markup("<b>Bugs</b>\nThis revision has one or more bug associations.")
 
50
        align.add(label)
69
51
        table.attach(align, 1, 2, 0, 1, gtk.FILL)
70
52
 
71
53
        treeview = self.construct_treeview()
74
56
        self.set_border_width(6)
75
57
        self.pack_start(table, expand=False)
76
58
 
77
 
        self.clear()
78
 
        self.show_all()
79
 
 
80
 
    def set_revision(self, revision):
81
 
        if revision is None:
82
 
            return
83
 
 
84
 
        self.clear()
85
 
        bugs_text = revision.properties.get('bugs', '')
86
 
        for bugline in bugs_text.splitlines():
87
 
                (url, status) = bugline.split(" ")
88
 
                if status == "fixed":
89
 
                    self.add_bug(url, status)
90
 
        
91
 
        if self.num_bugs == 0:
92
 
            return
93
 
        elif self.num_bugs == 1:
94
 
            label = "bug"
95
 
        else:
96
 
            label = "bugs"
97
 
 
98
 
        self.label.set_markup("<b>Bugs fixed</b>\n" +
99
 
                              "This revision claims to fix " +
100
 
                              "%d %s." % (self.num_bugs, label))
 
59
        self.hide_all()
101
60
 
102
61
    def construct_treeview(self):
103
62
        self.bugs = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
104
63
        self.treeview = gtk.TreeView(self.bugs)
105
 
        self.treeview.set_headers_visible(False)
106
64
 
107
65
        uri_column = gtk.TreeViewColumn('Bug URI', gtk.CellRendererText(), text=0)
 
66
        status_column = gtk.TreeViewColumn('Status', gtk.CellRendererText(), text=1)
 
67
 
108
68
        self.treeview.append_column(uri_column)
109
 
 
110
 
        self.treeview.connect('row-activated', self.on_row_activated)
 
69
        self.treeview.append_column(status_column)
111
70
 
112
71
        win = gtk.ScrolledWindow()
113
72
        win.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
117
76
        return win
118
77
 
119
78
    def clear(self):
120
 
        self.num_bugs = 0
121
79
        self.bugs.clear()
122
 
        self.set_sensitive(False)
123
 
        self.label.set_markup("<b>No bugs fixed</b>\n" +
124
 
                              "This revision does not claim to fix any bugs.")
 
80
        self.hide_all() # Only shown when there are bugs
125
81
 
126
82
    def add_bug(self, url, status):
127
 
        self.num_bugs += 1
128
83
        self.bugs.append([url, status])
129
 
        self.set_sensitive(True)
130
 
 
131
 
    def get_num_bugs(self):
132
 
        return self.num_bugs
133
 
 
134
 
    def on_row_activated(self, treeview, path, column):
135
 
        uri = self.bugs.get_value(self.bugs.get_iter(path), 0)
136
 
        _open_link(self, uri)
 
84
        self.show_all()
137
85
 
138
86
 
139
87
class SignatureTab(gtk.VBox):
140
 
 
141
 
    def __init__(self, repository):
142
 
        self.key = None
143
 
        self.revision = None
144
 
        self.repository = repository
145
 
 
 
88
    def __init__(self):
 
89
        from gpg import GPGSubprocess
 
90
        self.gpg = GPGSubprocess()
146
91
        super(SignatureTab, self).__init__(False, 6)
147
 
        signature_box = gtk.Table(rows=3, columns=3)
148
 
        signature_box.set_col_spacing(0, 16)
149
 
        signature_box.set_col_spacing(1, 12)
150
 
        signature_box.set_row_spacings(6)
 
92
        signature_box = gtk.Table(rows=1, columns=2)
 
93
        signature_box.set_col_spacing(0, 12)
151
94
 
152
95
        self.signature_image = gtk.Image()
153
96
        signature_box.attach(self.signature_image, 0, 1, 0, 1, gtk.FILL)
154
97
 
155
 
        align = gtk.Alignment(0.0, 0.1)
156
98
        self.signature_label = gtk.Label()
157
 
        align.add(self.signature_label)
158
 
        signature_box.attach(align, 1, 3, 0, 1, gtk.FILL)
159
 
 
160
 
        align = gtk.Alignment(0.0, 0.5)
161
 
        self.signature_key_id_label = gtk.Label()
162
 
        self.signature_key_id_label.set_markup("<b>Key Id:</b>")
163
 
        align.add(self.signature_key_id_label)
164
 
        signature_box.attach(align, 1, 2, 1, 2, gtk.FILL, gtk.FILL)
 
99
        signature_box.attach(self.signature_label, 1, 2, 0, 1, gtk.FILL)
 
100
 
 
101
        signature_info = gtk.Table(rows=1, columns=2)
 
102
        signature_info.set_row_spacings(6)
 
103
        signature_info.set_col_spacings(6)
 
104
 
 
105
        align = gtk.Alignment(1.0, 0.5)
 
106
        label = gtk.Label()
 
107
        label.set_markup("<b>Key Id:</b>")
 
108
        align.add(label)
 
109
        signature_info.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
165
110
 
166
111
        align = gtk.Alignment(0.0, 0.5)
167
112
        self.signature_key_id = gtk.Label()
168
113
        self.signature_key_id.set_selectable(True)
169
114
        align.add(self.signature_key_id)
170
 
        signature_box.attach(align, 2, 3, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
171
 
 
172
 
        align = gtk.Alignment(0.0, 0.5)
173
 
        self.signature_fingerprint_label = gtk.Label()
174
 
        self.signature_fingerprint_label.set_markup("<b>Fingerprint:</b>")
175
 
        align.add(self.signature_fingerprint_label)
176
 
        signature_box.attach(align, 1, 2, 2, 3, gtk.FILL, gtk.FILL)
177
 
 
178
 
        align = gtk.Alignment(0.0, 0.5)
179
 
        self.signature_fingerprint = gtk.Label()
180
 
        self.signature_fingerprint.set_selectable(True)
181
 
        align.add(self.signature_fingerprint)
182
 
        signature_box.attach(align, 2, 3, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL)
183
 
 
184
 
        align = gtk.Alignment(0.0, 0.5)
185
 
        self.signature_trust_label = gtk.Label()
186
 
        self.signature_trust_label.set_markup("<b>Trust:</b>")
187
 
        align.add(self.signature_trust_label)
188
 
        signature_box.attach(align, 1, 2, 3, 4, gtk.FILL, gtk.FILL)
189
 
 
190
 
        align = gtk.Alignment(0.0, 0.5)
191
 
        self.signature_trust = gtk.Label()
192
 
        self.signature_trust.set_selectable(True)
193
 
        align.add(self.signature_trust)
194
 
        signature_box.attach(align, 2, 3, 3, 4, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
115
        signature_info.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
195
116
 
196
117
        self.set_border_width(6)
197
118
        self.pack_start(signature_box, expand=False)
 
119
        self.pack_start(signature_info, expand=False)
198
120
        self.show_all()
199
121
 
200
 
    def set_revision(self, revision):
201
 
        self.revision = revision
202
 
        revid = revision.revision_id
203
 
 
204
 
        if self.repository.has_signature_for_revision_id(revid):
205
 
            crypttext = self.repository.get_signature_text(revid)
206
 
            self.show_signature(crypttext)
207
 
        else:
208
 
            self.show_no_signature()
209
 
 
210
122
    def show_no_signature(self):
211
 
        self.signature_key_id_label.hide()
212
123
        self.signature_key_id.set_text("")
213
 
 
214
 
        self.signature_fingerprint_label.hide()
215
 
        self.signature_fingerprint.set_text("")
216
 
 
217
 
        self.signature_trust_label.hide()
218
 
        self.signature_trust.set_text("")
219
 
 
220
124
        self.signature_image.set_from_file(icon_path("sign-unknown.png"))
221
 
        self.signature_label.set_markup("<b>Authenticity unknown</b>\n" +
222
 
                                        "This revision has not been signed.")
223
 
 
224
 
    def show_signature(self, crypttext):
225
 
        (cleartext, key) = seahorse.verify(crypttext)
226
 
 
227
 
        assert cleartext is not None
228
 
 
229
 
        inv = self.repository.get_inventory(self.revision.revision_id)
230
 
        expected_testament = Testament(self.revision, inv).as_short_text()
231
 
        if expected_testament != cleartext:
232
 
            self.signature_image.set_from_file(icon_path("sign-bad.png"))
233
 
            self.signature_label.set_markup("<b>Signature does not match repository data</b>\n" +
234
 
                        "The signature plaintext is different from the expected testament plaintext.")
235
 
            return
236
 
 
237
 
        if key and key.is_available():
238
 
            if key.is_trusted():
239
 
                if key.get_display_name() == self.revision.committer:
240
 
                    self.signature_image.set_from_file(icon_path("sign-ok.png"))
241
 
                    self.signature_label.set_markup("<b>Authenticity confirmed</b>\n" +
242
 
                                                    "This revision has been signed with " +
243
 
                                                    "a trusted key.")
244
 
                else:
245
 
                    self.signature_image.set_from_file(icon_path("sign-bad.png"))
246
 
                    self.signature_label.set_markup("<b>Authenticity cannot be confirmed</b>\n" +
247
 
                                                    "Revision committer is not the same as signer.")
248
 
            else:
249
 
                self.signature_image.set_from_file(icon_path("sign-bad.png"))
250
 
                self.signature_label.set_markup("<b>Authenticity cannot be confirmed</b>\n" +
251
 
                                                "This revision has been signed, but the " +
252
 
                                                "key is not trusted.")
 
125
        self.signature_label.set_text("This revision has not been signed.")
 
126
 
 
127
    def show_signature(self, text):
 
128
        signature = self.gpg.verify(text)
 
129
 
 
130
        if signature.key_id is not None:
 
131
            self.signature_key_id.set_text(signature.key_id)
 
132
 
 
133
        if signature.is_valid():
 
134
            self.signature_image.set_from_file(icon_path("sign-ok.png"))
 
135
            self.signature_label.set_text("This revision has been signed.")
253
136
        else:
254
 
            self.show_no_signature()
255
137
            self.signature_image.set_from_file(icon_path("sign-bad.png"))
256
 
            self.signature_label.set_markup("<b>Authenticity cannot be confirmed</b>\n" +
257
 
                                            "Signature key not available.")
258
 
            return
259
 
 
260
 
        trust = key.get_trust()
261
 
 
262
 
        if trust <= seahorse.TRUST_NEVER:
263
 
            trust_text = 'never trusted'
264
 
        elif trust == seahorse.TRUST_UNKNOWN:
265
 
            trust_text = 'not trusted'
266
 
        elif trust == seahorse.TRUST_MARGINAL:
267
 
            trust_text = 'marginally trusted'
268
 
        elif trust == seahorse.TRUST_FULL:
269
 
            trust_text = 'fully trusted'
270
 
        elif trust == seahorse.TRUST_ULTIMATE:
271
 
            trust_text = 'ultimately trusted'
272
 
 
273
 
        self.signature_key_id_label.show()
274
 
        self.signature_key_id.set_text(key.get_id())
275
 
 
276
 
        fingerprint = key.get_fingerprint()
277
 
        if fingerprint == "":
278
 
            fingerprint = '<span foreground="dim grey">N/A</span>'
279
 
 
280
 
        self.signature_fingerprint_label.show()
281
 
        self.signature_fingerprint.set_markup(fingerprint)
282
 
 
283
 
        self.signature_trust_label.show()
284
 
        self.signature_trust.set_text('This key is ' + trust_text)
 
138
            self.signature_label.set_text("This revision has been signed, " + 
 
139
                    "but the authenticity of the signature cannot be verified.")
285
140
 
286
141
 
287
142
class RevisionView(gtk.Notebook):
321
176
        )
322
177
    }
323
178
 
324
 
    def __init__(self, branch=None, repository=None):
 
179
 
 
180
    def __init__(self, branch=None):
325
181
        gtk.Notebook.__init__(self)
326
182
 
327
 
        self._revision = None
328
 
        self._branch = branch
329
 
        if branch is not None:
330
 
            self._repository = branch.repository
331
 
        else:
332
 
            self._repository = repository
333
 
 
334
183
        self._create_general()
335
184
        self._create_relations()
336
 
        # Disabled because testaments aren't verified yet:
337
 
        if has_seahorse:
338
 
            self._create_signature()
 
185
        self._create_signature()
339
186
        self._create_file_info_view()
340
187
        self._create_bugs()
341
188
 
342
 
        self.set_current_page(PAGE_GENERAL)
343
 
        self.connect_after('switch-page', self._switch_page_cb)
 
189
        self.set_current_page(0)
344
190
        
345
191
        self._show_callback = None
346
192
        self._clicked_callback = None
447
293
        else:
448
294
            self.file_info_box.hide()
449
295
 
 
296
        self.bugs_table.clear()
 
297
        bugs_text = revision.properties.get('bugs', None)
 
298
        if bugs_text:
 
299
            for bugline in bugs_text.splitlines():
 
300
                (url, status) = bugline.split(" ")
 
301
                self.bugs_table.add_bug(url, status)
 
302
 
450
303
    def update_tags(self):
451
304
        if self._branch is not None and self._branch.supports_tags():
452
305
            self._tagdict = self._branch.tags.get_reverse_tag_dict()
456
309
        self._add_tags()
457
310
 
458
311
    def _update_signature(self, widget, param):
459
 
        if self.get_current_page() == PAGE_SIGNATURE:
460
 
            self.signature_table.set_revision(self._revision)
 
312
        revid = self._revision.revision_id
461
313
 
462
 
    def _update_bugs(self, widget, param):
463
 
        self.bugs_page.set_revision(self._revision)
464
 
        label = self.get_tab_label(self.bugs_page)
465
 
        label.set_sensitive(self.bugs_page.get_num_bugs() != 0)
 
314
        if self._branch.repository.has_signature_for_revision_id(revid):
 
315
            signature_text = self._branch.repository.get_signature_text(revid)
 
316
            self.signature_table.show_signature(signature_text)
 
317
        else:
 
318
            self.signature_table.show_no_signature()
466
319
 
467
320
    def set_children(self, children):
468
321
        self._add_parents_or_children(children,
469
322
                                      self.children_widgets,
470
323
                                      self.children_table)
471
324
 
472
 
    def _switch_page_cb(self, notebook, page, page_num):
473
 
        if page_num == PAGE_SIGNATURE:
474
 
            self.signature_table.set_revision(self._revision)
475
 
 
476
 
 
477
 
 
478
325
    def _show_clicked_cb(self, widget, revid, parentid):
479
326
        """Callback for when the show button for a parent is clicked."""
480
327
        self._show_callback(revid, parentid)
534
381
 
535
382
            button = gtk.Button(revid)
536
383
            button.connect("clicked",
537
 
                    lambda w, r: self.set_revision(self._repository.get_revision(r)), revid)
 
384
                    lambda w, r: self.set_revision(self._branch.repository.get_revision(r)), revid)
538
385
            button.set_use_underline(False)
539
386
            hbox.pack_start(button, expand=False, fill=True)
540
387
            button.show()
556
403
        vbox.show()
557
404
 
558
405
    def _create_signature(self):
559
 
        self.signature_table = SignatureTab(self._repository)
 
406
        try:
 
407
            self.signature_table = SignatureTab()
 
408
        except ValueError: # No GPG found
 
409
            self.signature_table = None
 
410
            return
560
411
        self.append_page(self.signature_table, tab_label=gtk.Label('Signature'))
561
412
        self.connect_after('notify::revision', self._update_signature)
562
413
 
722
573
        return window
723
574
 
724
575
    def _create_bugs(self):
725
 
        self.bugs_page = BugsTab()
726
 
        self.connect_after('notify::revision', self._update_bugs) 
727
 
        self.append_page(self.bugs_page, tab_label=gtk.Label('Bugs'))
 
576
        self.bugs_table = BugsTab()
 
577
        self.append_page(self.bugs_table, tab_label=gtk.Label('Bugs'))
728
578
 
729
579
    def _create_file_info_view(self):
730
580
        self.file_info_box = gtk.VBox(False, 6)