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
29
def _open_link(widget, uri):
30
subprocess.Popen(['sensible-browser', uri], close_fds=True)
32
gtk.link_button_set_uri_hook(_open_link)
34
class BugsTab(gtk.Table):
36
super(BugsTab, self).__init__(rows=5, columns=2)
37
self.set_row_spacings(6)
38
self.set_col_spacings(6)
42
for c in self.get_children():
45
self.hide_all() # Only shown when there are bugs
47
def add_bug(self, url, status):
48
button = gtk.LinkButton(url, url)
49
self.attach(button, 0, 1, self.count, self.count + 1,
50
gtk.EXPAND | gtk.FILL, gtk.FILL)
51
status_label = gtk.Label(status)
52
self.attach(status_label, 1, 2, self.count, self.count + 1,
53
gtk.EXPAND | gtk.FILL, gtk.FILL)
58
class SignatureTab(gtk.VBox):
60
from gpg import GPGSubprocess
61
self.gpg = GPGSubprocess()
62
super(SignatureTab, self).__init__(False, 6)
63
signature_box = gtk.Table(rows=1, columns=2)
64
signature_box.set_col_spacing(0, 12)
66
self.signature_image = gtk.Image()
67
signature_box.attach(self.signature_image, 0, 1, 0, 1, gtk.FILL)
69
self.signature_label = gtk.Label()
70
signature_box.attach(self.signature_label, 1, 2, 0, 1, gtk.FILL)
72
signature_info = gtk.Table(rows=1, columns=2)
73
signature_info.set_row_spacings(6)
74
signature_info.set_col_spacings(6)
76
align = gtk.Alignment(1.0, 0.5)
78
label.set_markup("<b>Key Id:</b>")
80
signature_info.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
82
align = gtk.Alignment(0.0, 0.5)
83
self.signature_key_id = gtk.Label()
84
self.signature_key_id.set_selectable(True)
85
align.add(self.signature_key_id)
86
signature_info.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
88
self.set_border_width(6)
89
self.pack_start(signature_box, expand=False)
90
self.pack_start(signature_info, expand=False)
93
def show_no_signature(self):
94
self.signature_key_id.set_text("")
95
self.signature_image.set_from_file(icon_path("sign-unknown.png"))
96
self.signature_label.set_text("This revision has not been signed.")
98
def show_signature(self, text):
99
signature = self.gpg.verify(text)
101
if signature.key_id is not None:
102
self.signature_key_id.set_text(signature.key_id)
104
if signature.is_valid():
105
self.signature_image.set_from_file(icon_path("sign-ok.png"))
106
self.signature_label.set_text("This revision has been signed.")
108
self.signature_image.set_from_file(icon_path("sign-bad.png"))
109
self.signature_label.set_text("This revision has been signed, " +
110
"but the authenticity of the signature cannot be verified.")
113
class RevisionView(gtk.Notebook):
114
""" Custom widget for commit log details.
116
A variety of bzr tools may need to implement such a thing. This is a
122
gobject.TYPE_PYOBJECT,
124
'The branch holding the revision being displayed',
125
gobject.PARAM_CONSTRUCT_ONLY | gobject.PARAM_WRITABLE
129
gobject.TYPE_PYOBJECT,
131
'The revision being displayed',
132
gobject.PARAM_READWRITE
136
gobject.TYPE_PYOBJECT,
139
gobject.PARAM_READWRITE
143
gobject.TYPE_PYOBJECT,
146
gobject.PARAM_READWRITE
151
def __init__(self, branch=None):
152
gtk.Notebook.__init__(self)
154
self._create_general()
155
self._create_relations()
156
self._create_signature()
157
self._create_file_info_view()
160
self.set_current_page(0)
162
self._show_callback = None
163
self._clicked_callback = None
165
self._revision = None
166
self._branch = branch
170
self.set_file_id(None)
172
def do_get_property(self, property):
173
if property.name == 'branch':
175
elif property.name == 'revision':
176
return self._revision
177
elif property.name == 'children':
178
return self._children
179
elif property.name == 'file-id':
182
raise AttributeError, 'unknown property %s' % property.name
184
def do_set_property(self, property, value):
185
if property.name == 'branch':
187
elif property.name == 'revision':
188
self._set_revision(value)
189
elif property.name == 'children':
190
self.set_children(value)
191
elif property.name == 'file-id':
192
self._file_id = value
194
raise AttributeError, 'unknown property %s' % property.name
196
def set_show_callback(self, callback):
197
self._show_callback = callback
199
def set_file_id(self, file_id):
200
"""Set a specific file id that we want to track.
202
This just effects the display of a per-file commit message.
203
If it is set to None, then all commit messages will be shown.
205
self.set_property('file-id', file_id)
207
def set_revision(self, revision):
208
if revision != self._revision:
209
self.set_property('revision', revision)
211
def get_revision(self):
212
return self.get_property('revision')
214
def _set_revision(self, revision):
215
if revision is None: return
217
self._revision = revision
218
if revision.committer is not None:
219
self.committer.set_text(revision.committer)
221
self.committer.set_text("")
222
author = revision.properties.get('author', '')
224
self.author.set_text(author)
226
self.author_label.show()
229
self.author_label.hide()
231
if revision.timestamp is not None:
232
self.timestamp.set_text(format_date(revision.timestamp,
235
self.branchnick_label.set_text(revision.properties['branch-nick'])
237
self.branchnick_label.set_text("")
239
self._add_parents_or_children(revision.parent_ids,
240
self.parents_widgets,
243
file_info = revision.properties.get('file-info', None)
244
if file_info is not None:
245
file_info = bdecode(file_info.encode('UTF-8'))
248
if self._file_id is None:
251
text.append('%(path)s\n%(message)s' % fi)
252
self.file_info_buffer.set_text('\n'.join(text))
253
self.file_info_box.show()
257
if fi['file_id'] == self._file_id:
258
text.append(fi['message'])
260
self.file_info_buffer.set_text('\n'.join(text))
261
self.file_info_box.show()
263
self.file_info_box.hide()
265
self.file_info_box.hide()
267
self.bugs_table.clear()
268
bugs_text = revision.properties.get('bugs', None)
270
for bugline in bugs_text.splitlines():
271
(url, status) = bugline.split(" ")
272
self.bugs_table.add_bug(url, status)
274
def update_tags(self):
275
if self._branch is not None and self._branch.supports_tags():
276
self._tagdict = self._branch.tags.get_reverse_tag_dict()
282
def _update_signature(self, widget, param):
283
revid = self._revision.revision_id
285
if self._branch.repository.has_signature_for_revision_id(revid):
286
signature_text = self._branch.repository.get_signature_text(revid)
287
self.signature_table.show_signature(signature_text)
289
self.signature_table.show_no_signature()
291
def set_children(self, children):
292
self._add_parents_or_children(children,
293
self.children_widgets,
296
def _show_clicked_cb(self, widget, revid, parentid):
297
"""Callback for when the show button for a parent is clicked."""
298
self._show_callback(revid, parentid)
300
def _go_clicked_cb(self, widget, revid):
301
"""Callback for when the go button for a parent is clicked."""
303
def _add_tags(self, *args):
304
if self._revision is None:
307
if self._tagdict.has_key(self._revision.revision_id):
308
tags = self._tagdict[self._revision.revision_id]
313
self.tags_list.hide()
314
self.tags_label.hide()
317
self.tags_list.set_text(", ".join(tags))
319
self.tags_list.show_all()
320
self.tags_label.show_all()
322
def _add_parents_or_children(self, revids, widgets, table):
323
while len(widgets) > 0:
324
widget = widgets.pop()
327
table.resize(max(len(revids), 1), 2)
329
for idx, revid in enumerate(revids):
330
align = gtk.Alignment(0.0, 0.0)
331
widgets.append(align)
332
table.attach(align, 1, 2, idx, idx + 1,
333
gtk.EXPAND | gtk.FILL, gtk.FILL)
336
hbox = gtk.HBox(False, spacing=6)
341
image.set_from_stock(
342
gtk.STOCK_FIND, gtk.ICON_SIZE_SMALL_TOOLBAR)
345
if self._show_callback is not None:
346
button = gtk.Button()
348
button.connect("clicked", self._show_clicked_cb,
349
self._revision.revision_id, revid)
350
hbox.pack_start(button, expand=False, fill=True)
353
button = gtk.Button(revid)
354
button.connect("clicked",
355
lambda w, r: self.set_revision(self._branch.repository.get_revision(r)), revid)
356
button.set_use_underline(False)
357
hbox.pack_start(button, expand=False, fill=True)
360
def _create_general(self):
361
vbox = gtk.VBox(False, 6)
362
vbox.set_border_width(6)
363
vbox.pack_start(self._create_headers(), expand=False, fill=True)
364
vbox.pack_start(self._create_message_view())
365
self.append_page(vbox, tab_label=gtk.Label("General"))
368
def _create_relations(self):
369
vbox = gtk.VBox(False, 6)
370
vbox.set_border_width(6)
371
vbox.pack_start(self._create_parents(), expand=False, fill=True)
372
vbox.pack_start(self._create_children(), expand=False, fill=True)
373
self.append_page(vbox, tab_label=gtk.Label("Relations"))
376
def _create_signature(self):
378
self.signature_table = SignatureTab()
379
except ValueError: # No GPG found
380
self.signature_table = None
382
self.append_page(self.signature_table, tab_label=gtk.Label('Signature'))
383
self.connect_after('notify::revision', self._update_signature)
385
def _create_headers(self):
386
self.table = gtk.Table(rows=5, columns=2)
387
self.table.set_row_spacings(6)
388
self.table.set_col_spacings(6)
391
align = gtk.Alignment(1.0, 0.5)
393
label.set_markup("<b>Revision Id:</b>")
395
self.table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
399
align = gtk.Alignment(0.0, 0.5)
400
revision_id = gtk.Label()
401
revision_id.set_selectable(True)
402
self.connect('notify::revision',
403
lambda w, p: revision_id.set_text(self._revision.revision_id))
404
align.add(revision_id)
405
self.table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
409
align = gtk.Alignment(1.0, 0.5)
410
self.author_label = gtk.Label()
411
self.author_label.set_markup("<b>Author:</b>")
412
align.add(self.author_label)
413
self.table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL)
415
self.author_label.show()
417
align = gtk.Alignment(0.0, 0.5)
418
self.author = gtk.Label()
419
self.author.set_selectable(True)
420
align.add(self.author)
421
self.table.attach(align, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
426
align = gtk.Alignment(1.0, 0.5)
428
label.set_markup("<b>Committer:</b>")
430
self.table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
434
align = gtk.Alignment(0.0, 0.5)
435
self.committer = gtk.Label()
436
self.committer.set_selectable(True)
437
align.add(self.committer)
438
self.table.attach(align, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL)
440
self.committer.show()
442
align = gtk.Alignment(0.0, 0.5)
444
label.set_markup("<b>Branch nick:</b>")
446
self.table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL)
450
align = gtk.Alignment(0.0, 0.5)
451
self.branchnick_label = gtk.Label()
452
self.branchnick_label.set_selectable(True)
453
align.add(self.branchnick_label)
454
self.table.attach(align, 1, 2, 3, 4, gtk.EXPAND | gtk.FILL, gtk.FILL)
455
self.branchnick_label.show()
458
align = gtk.Alignment(1.0, 0.5)
460
label.set_markup("<b>Timestamp:</b>")
462
self.table.attach(align, 0, 1, 4, 5, gtk.FILL, gtk.FILL)
466
align = gtk.Alignment(0.0, 0.5)
467
self.timestamp = gtk.Label()
468
self.timestamp.set_selectable(True)
469
align.add(self.timestamp)
470
self.table.attach(align, 1, 2, 4, 5, gtk.EXPAND | gtk.FILL, gtk.FILL)
472
self.timestamp.show()
474
align = gtk.Alignment(1.0, 0.5)
475
self.tags_label = gtk.Label()
476
self.tags_label.set_markup("<b>Tags:</b>")
477
align.add(self.tags_label)
479
self.table.attach(align, 0, 1, 5, 6, gtk.FILL, gtk.FILL)
480
self.tags_label.show()
482
align = gtk.Alignment(0.0, 0.5)
483
self.tags_list = gtk.Label()
484
align.add(self.tags_list)
485
self.table.attach(align, 1, 2, 5, 6, gtk.EXPAND | gtk.FILL, gtk.FILL)
487
self.tags_list.show()
489
self.connect('notify::revision', self._add_tags)
493
def _create_parents(self):
494
hbox = gtk.HBox(True, 3)
496
self.parents_table = self._create_parents_or_children_table(
498
self.parents_widgets = []
499
hbox.pack_start(self.parents_table)
504
def _create_children(self):
505
hbox = gtk.HBox(True, 3)
506
self.children_table = self._create_parents_or_children_table(
508
self.children_widgets = []
509
hbox.pack_start(self.children_table)
513
def _create_parents_or_children_table(self, text):
514
table = gtk.Table(rows=1, columns=2)
515
table.set_row_spacings(3)
516
table.set_col_spacings(6)
520
label.set_markup(text)
521
align = gtk.Alignment(0.0, 0.5)
523
table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
529
def _create_message_view(self):
530
msg_buffer = gtk.TextBuffer()
531
self.connect('notify::revision',
532
lambda w, p: msg_buffer.set_text(self._revision.message))
533
window = gtk.ScrolledWindow()
534
window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
535
window.set_shadow_type(gtk.SHADOW_IN)
536
tv = gtk.TextView(msg_buffer)
537
tv.set_editable(False)
538
tv.set_wrap_mode(gtk.WRAP_WORD)
540
tv.modify_font(pango.FontDescription("Monospace"))
546
def _create_bugs(self):
547
self.bugs_table = BugsTab()
548
self.append_page(self.bugs_table, tab_label=gtk.Label('Bugs'))
550
def _create_file_info_view(self):
551
self.file_info_box = gtk.VBox(False, 6)
552
self.file_info_box.set_border_width(6)
553
self.file_info_buffer = gtk.TextBuffer()
554
window = gtk.ScrolledWindow()
555
window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
556
window.set_shadow_type(gtk.SHADOW_IN)
557
tv = gtk.TextView(self.file_info_buffer)
558
tv.set_editable(False)
559
tv.set_wrap_mode(gtk.WRAP_WORD)
560
tv.modify_font(pango.FontDescription("Monospace"))
564
self.file_info_box.pack_start(window)
565
self.file_info_box.hide() # Only shown when there are per-file messages
566
self.append_page(self.file_info_box, tab_label=gtk.Label('Per-file'))