1
# Copyright (C) 2005 Dan Loda <danloda@gmail.com>
2
# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
from bzrlib.plugins.gtk import icon_path
26
from bzrlib.osutils import format_date
27
from bzrlib.util.bencode import bdecode
30
from bzrlib.plugins.gtk import seahorse
36
def _open_link(widget, uri):
37
subprocess.Popen(['sensible-browser', uri], close_fds=True)
39
gtk.link_button_set_uri_hook(_open_link)
41
class BugsTab(gtk.VBox):
44
super(BugsTab, self).__init__(False, 6)
46
table = gtk.Table(rows=2, columns=2)
48
table.set_row_spacings(6)
49
table.set_col_spacing(0, 16)
52
image.set_from_file(icon_path("bug.png"))
53
table.attach(image, 0, 1, 0, 1, gtk.FILL)
55
align = gtk.Alignment(0.0, 0.1)
56
self.label = gtk.Label()
58
table.attach(align, 1, 2, 0, 1, gtk.FILL)
60
treeview = self.construct_treeview()
61
table.attach(treeview, 1, 2, 1, 2, gtk.FILL | gtk.EXPAND)
63
self.set_border_width(6)
64
self.pack_start(table, expand=False)
69
def set_revision(self, revision):
74
bugs_text = revision.properties.get('bugs', '')
75
for bugline in bugs_text.splitlines():
76
(url, status) = bugline.split(" ")
78
self.add_bug(url, status)
80
if self.num_bugs == 0:
82
elif self.num_bugs == 1:
87
self.label.set_markup("<b>Bugs fixed</b>\n" +
88
"This revision claims to fix " +
89
"%d %s." % (self.num_bugs, label))
91
def construct_treeview(self):
92
self.bugs = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
93
self.treeview = gtk.TreeView(self.bugs)
94
self.treeview.set_headers_visible(False)
96
uri_column = gtk.TreeViewColumn('Bug URI', gtk.CellRendererText(), text=0)
97
self.treeview.append_column(uri_column)
99
self.treeview.connect('row-activated', self.on_row_activated)
101
win = gtk.ScrolledWindow()
102
win.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
103
win.set_shadow_type(gtk.SHADOW_IN)
104
win.add(self.treeview)
111
self.set_sensitive(False)
112
self.label.set_markup("<b>No bugs fixed</b>\n" +
113
"This revision does not claim to fix any bugs.")
115
def add_bug(self, url, status):
117
self.bugs.append([url, status])
118
self.set_sensitive(True)
120
def get_num_bugs(self):
123
def on_row_activated(self, treeview, path, column):
124
uri = self.bugs.get_value(self.bugs.get_iter(path), 0)
125
_open_link(self, uri)
128
class SignatureTab(gtk.VBox):
130
def __init__(self, repository):
133
self.repository = repository
135
super(SignatureTab, self).__init__(False, 6)
136
signature_box = gtk.Table(rows=3, columns=3)
137
signature_box.set_col_spacing(0, 16)
138
signature_box.set_col_spacing(1, 12)
139
signature_box.set_row_spacings(6)
141
self.signature_image = gtk.Image()
142
signature_box.attach(self.signature_image, 0, 1, 0, 1, gtk.FILL)
144
align = gtk.Alignment(0.0, 0.1)
145
self.signature_label = gtk.Label()
146
align.add(self.signature_label)
147
signature_box.attach(align, 1, 3, 0, 1, gtk.FILL)
149
align = gtk.Alignment(0.0, 0.5)
150
self.signature_key_id_label = gtk.Label()
151
self.signature_key_id_label.set_markup("<b>Key Id:</b>")
152
align.add(self.signature_key_id_label)
153
signature_box.attach(align, 1, 2, 1, 2, gtk.FILL, gtk.FILL)
155
align = gtk.Alignment(0.0, 0.5)
156
self.signature_key_id = gtk.Label()
157
self.signature_key_id.set_selectable(True)
158
align.add(self.signature_key_id)
159
signature_box.attach(align, 2, 3, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
161
align = gtk.Alignment(0.0, 0.5)
162
self.signature_fingerprint_label = gtk.Label()
163
self.signature_fingerprint_label.set_markup("<b>Fingerprint:</b>")
164
align.add(self.signature_fingerprint_label)
165
signature_box.attach(align, 1, 2, 2, 3, gtk.FILL, gtk.FILL)
167
align = gtk.Alignment(0.0, 0.5)
168
self.signature_fingerprint = gtk.Label()
169
self.signature_fingerprint.set_selectable(True)
170
align.add(self.signature_fingerprint)
171
signature_box.attach(align, 2, 3, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL)
173
align = gtk.Alignment(0.0, 0.5)
174
self.signature_trust_label = gtk.Label()
175
self.signature_trust_label.set_markup("<b>Trust:</b>")
176
align.add(self.signature_trust_label)
177
signature_box.attach(align, 1, 2, 3, 4, gtk.FILL, gtk.FILL)
179
align = gtk.Alignment(0.0, 0.5)
180
self.signature_trust = gtk.Label()
181
self.signature_trust.set_selectable(True)
182
align.add(self.signature_trust)
183
signature_box.attach(align, 2, 3, 3, 4, gtk.EXPAND | gtk.FILL, gtk.FILL)
185
self.set_border_width(6)
186
self.pack_start(signature_box, expand=False)
189
def set_revision(self, revision):
190
self.revision = revision
191
revid = revision.revision_id
193
if self.repository.has_signature_for_revision_id(revid):
194
crypttext = self.repository.get_signature_text(revid)
195
self.show_signature(crypttext)
197
self.show_no_signature()
199
def show_no_signature(self):
200
self.signature_key_id_label.hide()
201
self.signature_key_id.set_text("")
203
self.signature_fingerprint_label.hide()
204
self.signature_fingerprint.set_text("")
206
self.signature_trust_label.hide()
207
self.signature_trust.set_text("")
209
self.signature_image.set_from_file(icon_path("sign-unknown.png"))
210
self.signature_label.set_markup("<b>Authenticity unknown</b>\n" +
211
"This revision has not been signed.")
213
def show_signature(self, crypttext):
214
key = seahorse.verify(crypttext)
216
if key and key.is_available():
218
if key.get_display_name() == self.revision.committer:
219
self.signature_image.set_from_file(icon_path("sign-ok.png"))
220
self.signature_label.set_markup("<b>Authenticity confirmed</b>\n" +
221
"This revision has been signed with " +
224
self.signature_image.set_from_file(icon_path("sign-bad.png"))
225
self.signature_label.set_markup("<b>Authenticity cannot be confirmed</b>\n" +
226
"Revision committer is not the same as signer.")
228
self.signature_image.set_from_file(icon_path("sign-bad.png"))
229
self.signature_label.set_markup("<b>Authenticity cannot be confirmed</b>\n" +
230
"This revision has been signed, but the " +
231
"key is not trusted.")
233
self.show_no_signature()
234
self.signature_image.set_from_file(icon_path("sign-bad.png"))
235
self.signature_label.set_markup("<b>Authenticity cannot be confirmed</b>\n" +
236
"Signature key not available.")
239
trust = key.get_trust()
241
if trust <= seahorse.TRUST_NEVER:
242
trust_text = 'never trusted'
243
elif trust == seahorse.TRUST_UNKNOWN:
244
trust_text = 'not trusted'
245
elif trust == seahorse.TRUST_MARGINAL:
246
trust_text = 'marginally trusted'
247
elif trust == seahorse.TRUST_FULL:
248
trust_text = 'fully trusted'
249
elif trust == seahorse.TRUST_ULTIMATE:
250
trust_text = 'ultimately trusted'
252
self.signature_key_id_label.show()
253
self.signature_key_id.set_text(key.get_id())
255
fingerprint = key.get_fingerprint()
256
if fingerprint == "":
257
fingerprint = '<span foreground="dim grey">N/A</span>'
259
self.signature_fingerprint_label.show()
260
self.signature_fingerprint.set_markup(fingerprint)
262
self.signature_trust_label.show()
263
self.signature_trust.set_text('This key is ' + trust_text)
266
class RevisionView(gtk.Notebook):
267
""" Custom widget for commit log details.
269
A variety of bzr tools may need to implement such a thing. This is a
275
gobject.TYPE_PYOBJECT,
277
'The branch holding the revision being displayed',
278
gobject.PARAM_CONSTRUCT_ONLY | gobject.PARAM_WRITABLE
282
gobject.TYPE_PYOBJECT,
284
'The revision being displayed',
285
gobject.PARAM_READWRITE
289
gobject.TYPE_PYOBJECT,
292
gobject.PARAM_READWRITE
296
gobject.TYPE_PYOBJECT,
299
gobject.PARAM_READWRITE
304
def __init__(self, branch=None):
305
gtk.Notebook.__init__(self)
307
self._revision = None
308
self._branch = branch
310
self._create_general()
311
self._create_relations()
313
self._create_signature()
314
self._create_file_info_view()
317
self.set_current_page(0)
319
self._show_callback = None
320
self._clicked_callback = None
322
self._revision = None
323
self._branch = branch
327
self.set_file_id(None)
329
def do_get_property(self, property):
330
if property.name == 'branch':
332
elif property.name == 'revision':
333
return self._revision
334
elif property.name == 'children':
335
return self._children
336
elif property.name == 'file-id':
339
raise AttributeError, 'unknown property %s' % property.name
341
def do_set_property(self, property, value):
342
if property.name == 'branch':
344
elif property.name == 'revision':
345
self._set_revision(value)
346
elif property.name == 'children':
347
self.set_children(value)
348
elif property.name == 'file-id':
349
self._file_id = value
351
raise AttributeError, 'unknown property %s' % property.name
353
def set_show_callback(self, callback):
354
self._show_callback = callback
356
def set_file_id(self, file_id):
357
"""Set a specific file id that we want to track.
359
This just effects the display of a per-file commit message.
360
If it is set to None, then all commit messages will be shown.
362
self.set_property('file-id', file_id)
364
def set_revision(self, revision):
365
if revision != self._revision:
366
self.set_property('revision', revision)
368
def get_revision(self):
369
return self.get_property('revision')
371
def _set_revision(self, revision):
372
if revision is None: return
374
self._revision = revision
375
if revision.committer is not None:
376
self.committer.set_text(revision.committer)
378
self.committer.set_text("")
379
author = revision.properties.get('author', '')
381
self.author.set_text(author)
383
self.author_label.show()
386
self.author_label.hide()
388
if revision.timestamp is not None:
389
self.timestamp.set_text(format_date(revision.timestamp,
392
self.branchnick_label.set_text(revision.properties['branch-nick'])
394
self.branchnick_label.set_text("")
396
self._add_parents_or_children(revision.parent_ids,
397
self.parents_widgets,
400
file_info = revision.properties.get('file-info', None)
401
if file_info is not None:
402
file_info = bdecode(file_info.encode('UTF-8'))
405
if self._file_id is None:
408
text.append('%(path)s\n%(message)s' % fi)
409
self.file_info_buffer.set_text('\n'.join(text))
410
self.file_info_box.show()
414
if fi['file_id'] == self._file_id:
415
text.append(fi['message'])
417
self.file_info_buffer.set_text('\n'.join(text))
418
self.file_info_box.show()
420
self.file_info_box.hide()
422
self.file_info_box.hide()
424
def update_tags(self):
425
if self._branch is not None and self._branch.supports_tags():
426
self._tagdict = self._branch.tags.get_reverse_tag_dict()
432
def _update_signature(self, widget, param):
433
self.signature_table.set_revision(self._revision)
435
def _update_bugs(self, widget, param):
436
self.bugs_page.set_revision(self._revision)
437
label = self.get_tab_label(self.bugs_page)
438
label.set_sensitive(self.bugs_page.get_num_bugs() != 0)
440
def set_children(self, children):
441
self._add_parents_or_children(children,
442
self.children_widgets,
445
def _show_clicked_cb(self, widget, revid, parentid):
446
"""Callback for when the show button for a parent is clicked."""
447
self._show_callback(revid, parentid)
449
def _go_clicked_cb(self, widget, revid):
450
"""Callback for when the go button for a parent is clicked."""
452
def _add_tags(self, *args):
453
if self._revision is None:
456
if self._tagdict.has_key(self._revision.revision_id):
457
tags = self._tagdict[self._revision.revision_id]
462
self.tags_list.hide()
463
self.tags_label.hide()
466
self.tags_list.set_text(", ".join(tags))
468
self.tags_list.show_all()
469
self.tags_label.show_all()
471
def _add_parents_or_children(self, revids, widgets, table):
472
while len(widgets) > 0:
473
widget = widgets.pop()
476
table.resize(max(len(revids), 1), 2)
478
for idx, revid in enumerate(revids):
479
align = gtk.Alignment(0.0, 0.0)
480
widgets.append(align)
481
table.attach(align, 1, 2, idx, idx + 1,
482
gtk.EXPAND | gtk.FILL, gtk.FILL)
485
hbox = gtk.HBox(False, spacing=6)
490
image.set_from_stock(
491
gtk.STOCK_FIND, gtk.ICON_SIZE_SMALL_TOOLBAR)
494
if self._show_callback is not None:
495
button = gtk.Button()
497
button.connect("clicked", self._show_clicked_cb,
498
self._revision.revision_id, revid)
499
hbox.pack_start(button, expand=False, fill=True)
502
button = gtk.Button(revid)
503
button.connect("clicked",
504
lambda w, r: self.set_revision(self._branch.repository.get_revision(r)), revid)
505
button.set_use_underline(False)
506
hbox.pack_start(button, expand=False, fill=True)
509
def _create_general(self):
510
vbox = gtk.VBox(False, 6)
511
vbox.set_border_width(6)
512
vbox.pack_start(self._create_headers(), expand=False, fill=True)
513
vbox.pack_start(self._create_message_view())
514
self.append_page(vbox, tab_label=gtk.Label("General"))
517
def _create_relations(self):
518
vbox = gtk.VBox(False, 6)
519
vbox.set_border_width(6)
520
vbox.pack_start(self._create_parents(), expand=False, fill=True)
521
vbox.pack_start(self._create_children(), expand=False, fill=True)
522
self.append_page(vbox, tab_label=gtk.Label("Relations"))
525
def _create_signature(self):
526
self.signature_table = SignatureTab(self._branch.repository)
527
self.append_page(self.signature_table, tab_label=gtk.Label('Signature'))
528
self.connect_after('notify::revision', self._update_signature)
530
def _create_headers(self):
531
self.table = gtk.Table(rows=5, columns=2)
532
self.table.set_row_spacings(6)
533
self.table.set_col_spacings(6)
536
align = gtk.Alignment(1.0, 0.5)
538
label.set_markup("<b>Revision Id:</b>")
540
self.table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
544
align = gtk.Alignment(0.0, 0.5)
545
revision_id = gtk.Label()
546
revision_id.set_selectable(True)
547
self.connect('notify::revision',
548
lambda w, p: revision_id.set_text(self._revision.revision_id))
549
align.add(revision_id)
550
self.table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
554
align = gtk.Alignment(1.0, 0.5)
555
self.author_label = gtk.Label()
556
self.author_label.set_markup("<b>Author:</b>")
557
align.add(self.author_label)
558
self.table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL)
560
self.author_label.show()
562
align = gtk.Alignment(0.0, 0.5)
563
self.author = gtk.Label()
564
self.author.set_selectable(True)
565
align.add(self.author)
566
self.table.attach(align, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
571
align = gtk.Alignment(1.0, 0.5)
573
label.set_markup("<b>Committer:</b>")
575
self.table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
579
align = gtk.Alignment(0.0, 0.5)
580
self.committer = gtk.Label()
581
self.committer.set_selectable(True)
582
align.add(self.committer)
583
self.table.attach(align, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL)
585
self.committer.show()
587
align = gtk.Alignment(0.0, 0.5)
589
label.set_markup("<b>Branch nick:</b>")
591
self.table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL)
595
align = gtk.Alignment(0.0, 0.5)
596
self.branchnick_label = gtk.Label()
597
self.branchnick_label.set_selectable(True)
598
align.add(self.branchnick_label)
599
self.table.attach(align, 1, 2, 3, 4, gtk.EXPAND | gtk.FILL, gtk.FILL)
600
self.branchnick_label.show()
603
align = gtk.Alignment(1.0, 0.5)
605
label.set_markup("<b>Timestamp:</b>")
607
self.table.attach(align, 0, 1, 4, 5, gtk.FILL, gtk.FILL)
611
align = gtk.Alignment(0.0, 0.5)
612
self.timestamp = gtk.Label()
613
self.timestamp.set_selectable(True)
614
align.add(self.timestamp)
615
self.table.attach(align, 1, 2, 4, 5, gtk.EXPAND | gtk.FILL, gtk.FILL)
617
self.timestamp.show()
619
align = gtk.Alignment(1.0, 0.5)
620
self.tags_label = gtk.Label()
621
self.tags_label.set_markup("<b>Tags:</b>")
622
align.add(self.tags_label)
624
self.table.attach(align, 0, 1, 5, 6, gtk.FILL, gtk.FILL)
625
self.tags_label.show()
627
align = gtk.Alignment(0.0, 0.5)
628
self.tags_list = gtk.Label()
629
align.add(self.tags_list)
630
self.table.attach(align, 1, 2, 5, 6, gtk.EXPAND | gtk.FILL, gtk.FILL)
632
self.tags_list.show()
634
self.connect('notify::revision', self._add_tags)
638
def _create_parents(self):
639
hbox = gtk.HBox(True, 3)
641
self.parents_table = self._create_parents_or_children_table(
643
self.parents_widgets = []
644
hbox.pack_start(self.parents_table)
649
def _create_children(self):
650
hbox = gtk.HBox(True, 3)
651
self.children_table = self._create_parents_or_children_table(
653
self.children_widgets = []
654
hbox.pack_start(self.children_table)
658
def _create_parents_or_children_table(self, text):
659
table = gtk.Table(rows=1, columns=2)
660
table.set_row_spacings(3)
661
table.set_col_spacings(6)
665
label.set_markup(text)
666
align = gtk.Alignment(0.0, 0.5)
668
table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
674
def _create_message_view(self):
675
msg_buffer = gtk.TextBuffer()
676
self.connect('notify::revision',
677
lambda w, p: msg_buffer.set_text(self._revision.message))
678
window = gtk.ScrolledWindow()
679
window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
680
window.set_shadow_type(gtk.SHADOW_IN)
681
tv = gtk.TextView(msg_buffer)
682
tv.set_editable(False)
683
tv.set_wrap_mode(gtk.WRAP_WORD)
685
tv.modify_font(pango.FontDescription("Monospace"))
691
def _create_bugs(self):
692
self.bugs_page = BugsTab()
693
self.connect_after('notify::revision', self._update_bugs)
694
self.append_page(self.bugs_page, tab_label=gtk.Label('Bugs'))
696
def _create_file_info_view(self):
697
self.file_info_box = gtk.VBox(False, 6)
698
self.file_info_box.set_border_width(6)
699
self.file_info_buffer = gtk.TextBuffer()
700
window = gtk.ScrolledWindow()
701
window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
702
window.set_shadow_type(gtk.SHADOW_IN)
703
tv = gtk.TextView(self.file_info_buffer)
704
tv.set_editable(False)
705
tv.set_wrap_mode(gtk.WRAP_WORD)
706
tv.modify_font(pango.FontDescription("Monospace"))
710
self.file_info_box.pack_start(window)
711
self.file_info_box.hide() # Only shown when there are per-file messages
712
self.append_page(self.file_info_box, tab_label=gtk.Label('Per-file'))