/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 logview.py

  • Committer: Jelmer Vernooij
  • Date: 2007-04-03 17:16:07 UTC
  • mfrom: (187 trunk)
  • mto: This revision was merged to the branch mainline in revision 188.
  • Revision ID: jelmer@samba.org-20070403171607-0zaskazouokrm4cq
Tags: bzr-gtk-0.15.2
PrepareĀ forĀ 0.15.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
 
from gi.repository import Gtk
19
 
from gi.repository import Pango
20
 
from gi.repository import GObject
21
 
import webbrowser
 
18
import pygtk
 
19
pygtk.require("2.0")
 
20
import gtk
 
21
import pango
22
22
 
23
 
from bzrlib import trace
24
23
from bzrlib.osutils import format_date
25
 
try:
26
 
    from bzrlib.bencode import bdecode
27
 
except ImportError:
28
 
    from bzrlib.util.bencode import bdecode
29
 
from bzrlib.testament import Testament
30
 
 
31
 
from bzrlib.plugins.gtk import icon_path
32
 
 
33
 
from bzrlib.plugins.gtk.avatarsbox import AvatarsBox
34
 
 
35
 
try:
36
 
    from bzrlib.plugins.gtk import seahorse
37
 
except ImportError:
38
 
    has_seahorse = False
39
 
else:
40
 
    has_seahorse = True
41
 
 
42
 
PAGE_GENERAL = 0
43
 
PAGE_RELATIONS = 1
44
 
PAGE_SIGNATURE = 2
45
 
PAGE_BUGS = 3
46
 
 
47
 
 
48
 
def _open_link(widget, uri):
49
 
    for cmd in ['sensible-browser', 'xdg-open']:
50
 
        if webbrowser._iscommand(cmd):
51
 
            webbrowser._tryorder.insert(0, '%s "%%s"' % cmd)
52
 
    webbrowser.open(uri)
53
 
 
54
 
if getattr(gtk, 'link_button_set_uri_hook', None) is not None:
55
 
    Gtk.link_button_set_uri_hook(_open_link)
56
 
 
57
 
class BugsTab(Gtk.VBox):
58
 
 
59
 
    def __init__(self):
60
 
        super(BugsTab, self).__init__(False, 6)
61
 
 
62
 
        table = Gtk.Table(rows=2, columns=2)
63
 
 
64
 
        table.set_row_spacings(6)
65
 
        table.set_col_spacing(0, 16)
66
 
 
67
 
        image = Gtk.Image()
68
 
        image.set_from_file(icon_path("bug.png"))
69
 
        table.attach(image, 0, 1, 0, 1, Gtk.AttachOptions.FILL)
70
 
 
71
 
        align = Gtk.Alignment.new(0.0, 0.1)
72
 
        self.label = Gtk.Label()
73
 
        align.add(self.label)
74
 
        table.attach(align, 1, 2, 0, 1, Gtk.AttachOptions.FILL)
75
 
 
76
 
        treeview = self.construct_treeview()
77
 
        table.attach(treeview, 1, 2, 1, 2, Gtk.AttachOptions.FILL | Gtk.AttachOptions.EXPAND)
78
 
 
79
 
        self.set_border_width(6)
80
 
        self.pack_start(table, False, True, 0)
81
 
 
82
 
        self.clear()
83
 
        self.show_all()
84
 
 
85
 
    def set_revision(self, revision):
86
 
        if revision is None:
87
 
            return
88
 
 
89
 
        self.clear()
90
 
        bugs_text = revision.properties.get('bugs', '')
91
 
        for bugline in bugs_text.splitlines():
92
 
                (url, status) = bugline.split(" ")
93
 
                if status == "fixed":
94
 
                    self.add_bug(url, status)
95
 
 
96
 
        if self.num_bugs == 0:
97
 
            return
98
 
        elif self.num_bugs == 1:
99
 
            label = "bug"
100
 
        else:
101
 
            label = "bugs"
102
 
 
103
 
        self.label.set_markup("<b>Bugs fixed</b>\n" +
104
 
                              "This revision claims to fix " +
105
 
                              "%d %s." % (self.num_bugs, label))
106
 
 
107
 
    def construct_treeview(self):
108
 
        self.bugs = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING)
109
 
        self.treeview = Gtk.TreeView(self.bugs)
110
 
        self.treeview.set_headers_visible(False)
111
 
 
112
 
        uri_column = Gtk.TreeViewColumn('Bug URI', Gtk.CellRendererText(), text=0)
113
 
        self.treeview.append_column(uri_column)
114
 
 
115
 
        self.treeview.connect('row-activated', self.on_row_activated)
116
 
 
117
 
        win = Gtk.ScrolledWindow()
118
 
        win.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
119
 
        win.set_shadow_type(Gtk.ShadowType.IN)
120
 
        win.add(self.treeview)
121
 
 
122
 
        return win
123
 
 
124
 
    def clear(self):
125
 
        self.num_bugs = 0
126
 
        self.bugs.clear()
127
 
        self.set_sensitive(False)
128
 
        self.label.set_markup("<b>No bugs fixed</b>\n" +
129
 
                              "This revision does not claim to fix any bugs.")
130
 
 
131
 
    def add_bug(self, url, status):
132
 
        self.num_bugs += 1
133
 
        self.bugs.append([url, status])
134
 
        self.set_sensitive(True)
135
 
 
136
 
    def get_num_bugs(self):
137
 
        return self.num_bugs
138
 
 
139
 
    def on_row_activated(self, treeview, path, column):
140
 
        uri = self.bugs.get_value(self.bugs.get_iter(path), 0)
141
 
        _open_link(self, uri)
142
 
 
143
 
 
144
 
class SignatureTab(Gtk.VBox):
145
 
 
146
 
    def __init__(self, repository):
147
 
        self.key = None
148
 
        self.revision = None
149
 
        self.repository = repository
150
 
 
151
 
        super(SignatureTab, self).__init__(False, 6)
152
 
        signature_box = Gtk.Table(rows=3, columns=3)
153
 
        signature_box.set_col_spacing(0, 16)
154
 
        signature_box.set_col_spacing(1, 12)
155
 
        signature_box.set_row_spacings(6)
156
 
 
157
 
        self.signature_image = Gtk.Image()
158
 
        signature_box.attach(self.signature_image, 0, 1, 0, 1, Gtk.AttachOptions.FILL)
159
 
 
160
 
        align = Gtk.Alignment.new(0.0, 0.1)
161
 
        self.signature_label = Gtk.Label()
162
 
        align.add(self.signature_label)
163
 
        signature_box.attach(align, 1, 3, 0, 1, Gtk.AttachOptions.FILL)
164
 
 
165
 
        align = Gtk.Alignment.new(0.0, 0.5)
166
 
        self.signature_key_id_label = Gtk.Label()
167
 
        self.signature_key_id_label.set_markup("<b>Key Id:</b>")
168
 
        align.add(self.signature_key_id_label)
169
 
        signature_box.attach(align, 1, 2, 1, 2, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
170
 
 
171
 
        align = Gtk.Alignment.new(0.0, 0.5)
172
 
        self.signature_key_id = Gtk.Label()
173
 
        self.signature_key_id.set_selectable(True)
174
 
        align.add(self.signature_key_id)
175
 
        signature_box.attach(align, 2, 3, 1, 2, Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
176
 
 
177
 
        align = Gtk.Alignment.new(0.0, 0.5)
178
 
        self.signature_fingerprint_label = Gtk.Label()
179
 
        self.signature_fingerprint_label.set_markup("<b>Fingerprint:</b>")
180
 
        align.add(self.signature_fingerprint_label)
181
 
        signature_box.attach(align, 1, 2, 2, 3, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
182
 
 
183
 
        align = Gtk.Alignment.new(0.0, 0.5)
184
 
        self.signature_fingerprint = Gtk.Label()
185
 
        self.signature_fingerprint.set_selectable(True)
186
 
        align.add(self.signature_fingerprint)
187
 
        signature_box.attach(align, 2, 3, 2, 3, Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
188
 
 
189
 
        align = Gtk.Alignment.new(0.0, 0.5)
190
 
        self.signature_trust_label = Gtk.Label()
191
 
        self.signature_trust_label.set_markup("<b>Trust:</b>")
192
 
        align.add(self.signature_trust_label)
193
 
        signature_box.attach(align, 1, 2, 3, 4, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
194
 
 
195
 
        align = Gtk.Alignment.new(0.0, 0.5)
196
 
        self.signature_trust = Gtk.Label()
197
 
        self.signature_trust.set_selectable(True)
198
 
        align.add(self.signature_trust)
199
 
        signature_box.attach(align, 2, 3, 3, 4, Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
200
 
 
201
 
        self.set_border_width(6)
202
 
        self.pack_start(signature_box, False, True, 0)
203
 
        self.show_all()
204
 
 
205
 
    def set_revision(self, revision):
206
 
        self.revision = revision
207
 
        revid = revision.revision_id
208
 
 
209
 
        if self.repository.has_signature_for_revision_id(revid):
210
 
            crypttext = self.repository.get_signature_text(revid)
211
 
            self.show_signature(crypttext)
212
 
        else:
213
 
            self.show_no_signature()
214
 
 
215
 
    def show_no_signature(self):
216
 
        self.signature_key_id_label.hide()
217
 
        self.signature_key_id.set_text("")
218
 
 
219
 
        self.signature_fingerprint_label.hide()
220
 
        self.signature_fingerprint.set_text("")
221
 
 
222
 
        self.signature_trust_label.hide()
223
 
        self.signature_trust.set_text("")
224
 
 
225
 
        self.signature_image.set_from_file(icon_path("sign-unknown.png"))
226
 
        self.signature_label.set_markup("<b>Authenticity unknown</b>\n" +
227
 
                                        "This revision has not been signed.")
228
 
 
229
 
    def show_signature(self, crypttext):
230
 
        (cleartext, key) = seahorse.verify(crypttext)
231
 
 
232
 
        assert cleartext is not None
233
 
 
234
 
        inv = self.repository.get_inventory(self.revision.revision_id)
235
 
        expected_testament = Testament(self.revision, inv).as_short_text()
236
 
        if expected_testament != cleartext:
237
 
            self.signature_image.set_from_file(icon_path("sign-bad.png"))
238
 
            self.signature_label.set_markup("<b>Signature does not match repository data</b>\n" +
239
 
                        "The signature plaintext is different from the expected testament plaintext.")
240
 
            return
241
 
 
242
 
        if key and key.is_available():
243
 
            if key.is_trusted():
244
 
                if key.get_display_name() == self.revision.committer:
245
 
                    self.signature_image.set_from_file(icon_path("sign-ok.png"))
246
 
                    self.signature_label.set_markup("<b>Authenticity confirmed</b>\n" +
247
 
                                                    "This revision has been signed with " +
248
 
                                                    "a trusted key.")
249
 
                else:
250
 
                    self.signature_image.set_from_file(icon_path("sign-bad.png"))
251
 
                    self.signature_label.set_markup("<b>Authenticity cannot be confirmed</b>\n" +
252
 
                                                    "Revision committer is not the same as signer.")
253
 
            else:
254
 
                self.signature_image.set_from_file(icon_path("sign-bad.png"))
255
 
                self.signature_label.set_markup("<b>Authenticity cannot be confirmed</b>\n" +
256
 
                                                "This revision has been signed, but the " +
257
 
                                                "key is not trusted.")
258
 
        else:
259
 
            self.show_no_signature()
260
 
            self.signature_image.set_from_file(icon_path("sign-bad.png"))
261
 
            self.signature_label.set_markup("<b>Authenticity cannot be confirmed</b>\n" +
262
 
                                            "Signature key not available.")
263
 
            return
264
 
 
265
 
        trust = key.get_trust()
266
 
 
267
 
        if trust <= seahorse.TRUST_NEVER:
268
 
            trust_text = 'never trusted'
269
 
        elif trust == seahorse.TRUST_UNKNOWN:
270
 
            trust_text = 'not trusted'
271
 
        elif trust == seahorse.TRUST_MARGINAL:
272
 
            trust_text = 'marginally trusted'
273
 
        elif trust == seahorse.TRUST_FULL:
274
 
            trust_text = 'fully trusted'
275
 
        elif trust == seahorse.TRUST_ULTIMATE:
276
 
            trust_text = 'ultimately trusted'
277
 
 
278
 
        self.signature_key_id_label.show()
279
 
        self.signature_key_id.set_text(key.get_id())
280
 
 
281
 
        fingerprint = key.get_fingerprint()
282
 
        if fingerprint == "":
283
 
            fingerprint = '<span foreground="dim grey">N/A</span>'
284
 
 
285
 
        self.signature_fingerprint_label.show()
286
 
        self.signature_fingerprint.set_markup(fingerprint)
287
 
 
288
 
        self.signature_trust_label.show()
289
 
        self.signature_trust.set_text('This key is ' + trust_text)
290
 
 
291
 
 
292
 
class RevisionView(Gtk.Notebook):
 
24
 
 
25
 
 
26
class LogView(gtk.ScrolledWindow):
293
27
    """ Custom widget for commit log details.
294
28
 
295
29
    A variety of bzr tools may need to implement such a thing. This is a
296
30
    start.
297
31
    """
298
32
 
299
 
    __gproperties__ = {
300
 
        'branch': (
301
 
            GObject.TYPE_PYOBJECT,
302
 
            'Branch',
303
 
            'The branch holding the revision being displayed',
304
 
            GObject.PARAM_CONSTRUCT_ONLY | GObject.PARAM_WRITABLE
305
 
        ),
306
 
 
307
 
        'revision': (
308
 
            GObject.TYPE_PYOBJECT,
309
 
            'Revision',
310
 
            'The revision being displayed',
311
 
            GObject.PARAM_READWRITE
312
 
        ),
313
 
 
314
 
        'children': (
315
 
            GObject.TYPE_PYOBJECT,
316
 
            'Children',
317
 
            'Child revisions',
318
 
            GObject.PARAM_READWRITE
319
 
        ),
320
 
 
321
 
        'file-id': (
322
 
            GObject.TYPE_PYOBJECT,
323
 
            'File Id',
324
 
            'The file id',
325
 
            GObject.PARAM_READWRITE
326
 
        )
327
 
    }
328
 
 
329
 
    def __init__(self, branch=None, repository=None):
330
 
        GObject.GObject.__init__(self)
331
 
 
332
 
        self._revision = None
333
 
        self._branch = branch
334
 
        if branch is not None:
335
 
            self._repository = branch.repository
 
33
    def __init__(self, revision=None, scroll=True):
 
34
        super(LogView, self).__init__()
 
35
        if scroll:
 
36
            self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
336
37
        else:
337
 
            self._repository = repository
338
 
 
339
 
        self._create_general()
340
 
        self._create_relations()
341
 
        # Disabled because testaments aren't verified yet:
342
 
        if has_seahorse:
343
 
            self._create_signature()
344
 
        self._create_file_info_view()
345
 
        self._create_bugs()
346
 
 
347
 
        self.set_current_page(PAGE_GENERAL)
348
 
        self.connect_after('switch-page', self._switch_page_cb)
349
 
        
 
38
            self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER)
 
39
        self.set_shadow_type(gtk.SHADOW_NONE)
 
40
        self._create()
350
41
        self._show_callback = None
 
42
        self._go_callback = None
351
43
        self._clicked_callback = None
352
44
 
353
 
        self._revision = None
354
 
        self._branch = branch
355
 
 
356
 
        self.update_tags()
357
 
 
358
 
        self.set_file_id(None)
359
 
 
360
 
    def do_get_property(self, property):
361
 
        if property.name == 'branch':
362
 
            return self._branch
363
 
        elif property.name == 'revision':
364
 
            return self._revision
365
 
        elif property.name == 'children':
366
 
            return self._children
367
 
        elif property.name == 'file-id':
368
 
            return self._file_id
369
 
        else:
370
 
            raise AttributeError, 'unknown property %s' % property.name
371
 
 
372
 
    def do_set_property(self, property, value):
373
 
        if property.name == 'branch':
374
 
            self._branch = value
375
 
        elif property.name == 'revision':
376
 
            self._set_revision(value)
377
 
        elif property.name == 'children':
378
 
            self.set_children(value)
379
 
        elif property.name == 'file-id':
380
 
            self._file_id = value
381
 
        else:
382
 
            raise AttributeError, 'unknown property %s' % property.name
 
45
        if revision is not None:
 
46
            self.set_revision(revision)
383
47
 
384
48
    def set_show_callback(self, callback):
385
49
        self._show_callback = callback
386
50
 
387
 
    def set_file_id(self, file_id):
388
 
        """Set a specific file id that we want to track.
389
 
 
390
 
        This just effects the display of a per-file commit message.
391
 
        If it is set to None, then all commit messages will be shown.
392
 
        """
393
 
        self.set_property('file-id', file_id)
 
51
    def set_go_callback(self, callback):
 
52
        self._go_callback = callback
394
53
 
395
54
    def set_revision(self, revision):
396
 
        if revision != self._revision:
397
 
            self.set_property('revision', revision)
398
 
 
399
 
    def get_revision(self):
400
 
        return self.get_property('revision')
401
 
 
402
 
    def _set_revision(self, revision):
403
 
        if revision is None: return
404
 
        
405
 
        self.avatarsbox.reset()
406
 
        
407
55
        self._revision = revision
408
 
        if revision.committer is not None:
409
 
            self.committer.set_text(revision.committer)
410
 
            self.avatarsbox.add(revision.committer, "committer")
411
 
        else:
412
 
            self.committer.set_text("")
413
 
            self.avatarsbox.hide()
414
 
        author = revision.properties.get('author', '')
415
 
        self.avatarsbox.merge(revision.get_apparent_authors(), "author")
416
 
        if author != '':
417
 
            self.author.set_text(author)
418
 
            self.author.show()
419
 
            self.author_label.show()
420
 
        else:
421
 
            self.author.hide()
422
 
            self.author_label.hide()
423
 
 
424
 
        if revision.timestamp is not None:
425
 
            self.timestamp.set_text(format_date(revision.timestamp,
426
 
                                                revision.timezone))
 
56
        self.revision_id.set_text(revision.revision_id)
 
57
        self.committer.set_text(revision.committer)
 
58
        self.timestamp.set_text(format_date(revision.timestamp,
 
59
                                            revision.timezone))
 
60
        self.message_buffer.set_text(revision.message)
427
61
        try:
428
 
            self.branchnick.show()
429
 
            self.branchnick_label.show()
430
 
            self.branchnick.set_text(revision.properties['branch-nick'])
 
62
            self.branchnick_label.set_text(revision.properties['branch-nick'])
431
63
        except KeyError:
432
 
            self.branchnick.hide()
433
 
            self.branchnick_label.hide()
434
 
 
435
 
        self._add_parents_or_children(revision.parent_ids,
436
 
                                      self.parents_widgets,
437
 
                                      self.parents_table)
438
 
 
439
 
        file_info = revision.properties.get('file-info', None)
440
 
        if file_info is not None:
441
 
            try:
442
 
                file_info = bdecode(file_info.encode('UTF-8'))
443
 
            except ValueError:
444
 
                trace.note('Invalid per-file info for revision:%s, value: %r',
445
 
                           revision.revision_id, file_info)
446
 
                file_info = None
447
 
 
448
 
        if file_info:
449
 
            if self._file_id is None:
450
 
                text = []
451
 
                for fi in file_info:
452
 
                    text.append('%(path)s\n%(message)s' % fi)
453
 
                self.file_info_buffer.set_text('\n'.join(text))
454
 
                self.file_info_box.show()
455
 
            else:
456
 
                text = []
457
 
                for fi in file_info:
458
 
                    if fi['file_id'] == self._file_id:
459
 
                        text.append(fi['message'])
460
 
                if text:
461
 
                    self.file_info_buffer.set_text('\n'.join(text))
462
 
                    self.file_info_box.show()
463
 
                else:
464
 
                    self.file_info_box.hide()
465
 
        else:
466
 
            self.file_info_box.hide()
467
 
 
468
 
    def update_tags(self):
469
 
        if self._branch is not None and self._branch.supports_tags():
470
 
            self._tagdict = self._branch.tags.get_reverse_tag_dict()
471
 
        else:
472
 
            self._tagdict = {}
473
 
 
474
 
        self._add_tags()
475
 
 
476
 
    def _update_signature(self, widget, param):
477
 
        if self.get_current_page() == PAGE_SIGNATURE:
478
 
            self.signature_table.set_revision(self._revision)
479
 
 
480
 
    def _update_bugs(self, widget, param):
481
 
        self.bugs_page.set_revision(self._revision)
482
 
        label = self.get_tab_label(self.bugs_page)
483
 
        label.set_sensitive(self.bugs_page.get_num_bugs() != 0)
484
 
 
485
 
    def set_children(self, children):
486
 
        self._add_parents_or_children(children,
487
 
                                      self.children_widgets,
488
 
                                      self.children_table)
489
 
 
490
 
    def _switch_page_cb(self, notebook, page, page_num):
491
 
        if page_num == PAGE_SIGNATURE:
492
 
            self.signature_table.set_revision(self._revision)
493
 
 
494
 
 
 
64
            self.branchnick_label.set_text("")
 
65
 
 
66
        self._add_parents(revision.parent_ids)
495
67
 
496
68
    def _show_clicked_cb(self, widget, revid, parentid):
497
69
        """Callback for when the show button for a parent is clicked."""
499
71
 
500
72
    def _go_clicked_cb(self, widget, revid):
501
73
        """Callback for when the go button for a parent is clicked."""
502
 
 
503
 
    def _add_tags(self, *args):
504
 
        if self._revision is None:
505
 
            return
506
 
 
507
 
        if self._tagdict.has_key(self._revision.revision_id):
508
 
            tags = self._tagdict[self._revision.revision_id]
509
 
        else:
510
 
            tags = []
 
74
        self._go_callback(revid)
 
75
 
 
76
    def _add_parents(self, parent_ids):
 
77
        for widget in self.parents_widgets:
 
78
            self.parents_table.remove(widget)
511
79
            
512
 
        if tags == []:
513
 
            self.tags_list.hide()
514
 
            self.tags_label.hide()
515
 
            return
516
 
 
517
 
        self.tags_list.set_text(", ".join(tags))
518
 
 
519
 
        self.tags_list.show_all()
520
 
        self.tags_label.show_all()
521
 
        
522
 
    def _add_parents_or_children(self, revids, widgets, table):
523
 
        while len(widgets) > 0:
524
 
            widget = widgets.pop()
525
 
            table.remove(widget)
526
 
        
527
 
        table.resize(max(len(revids), 1), 2)
528
 
 
529
 
        for idx, revid in enumerate(revids):
530
 
            align = Gtk.Alignment.new(0.0, 0.0, 1, 1)
531
 
            widgets.append(align)
532
 
            table.attach(align, 1, 2, idx, idx + 1,
533
 
                                      Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
80
        self.parents_widgets = []
 
81
        self.parents_table.resize(max(len(parent_ids), 1), 2)
 
82
 
 
83
        for idx, parent_id in enumerate(parent_ids):
 
84
            align = gtk.Alignment(0.0, 0.0)
 
85
            self.parents_widgets.append(align)
 
86
            self.parents_table.attach(align, 1, 2, idx, idx + 1,
 
87
                                      gtk.EXPAND | gtk.FILL, gtk.FILL)
534
88
            align.show()
535
89
 
536
 
            hbox = Gtk.HBox(False, spacing=6)
 
90
            hbox = gtk.HBox(False, spacing=6)
537
91
            align.add(hbox)
538
92
            hbox.show()
539
93
 
540
 
            image = Gtk.Image()
 
94
            image = gtk.Image()
541
95
            image.set_from_stock(
542
 
                Gtk.STOCK_FIND, Gtk.IconSize.SMALL_TOOLBAR)
 
96
                gtk.STOCK_FIND, gtk.ICON_SIZE_SMALL_TOOLBAR)
543
97
            image.show()
544
98
 
545
99
            if self._show_callback is not None:
546
 
                button = Gtk.Button()
 
100
                button = gtk.Button()
547
101
                button.add(image)
548
102
                button.connect("clicked", self._show_clicked_cb,
549
 
                               self._revision.revision_id, revid)
 
103
                               self._revision.revision_id, parent_id)
550
104
                hbox.pack_start(button, expand=False, fill=True)
551
105
                button.show()
552
106
 
553
 
            button = Gtk.Button()
554
 
            revid_label = Gtk.Label(label=str(revid))
555
 
            revid_label.set_ellipsize(Pango.EllipsizeMode.MIDDLE)
556
 
            revid_label.set_alignment(0.0, 0.5)
557
 
            button.add(revid_label)
558
 
            button.connect("clicked",
559
 
                    lambda w, r: self.set_revision(self._repository.get_revision(r)), revid)
 
107
            if self._go_callback is not None:
 
108
                button = gtk.Button(parent_id)
 
109
                button.connect("clicked", self._go_clicked_cb, parent_id)
 
110
            else:
 
111
                button = gtk.Label(parent_id)
560
112
            button.set_use_underline(False)
561
 
            hbox.pack_start(button, expand=True, fill=True)
562
 
            button.show_all()
563
 
 
564
 
    def _create_general(self):
565
 
        vbox = Gtk.VBox(False, 6)
566
 
        vbox.set_border_width(6)
567
 
        vbox.pack_start(self._create_headers(, True, True, 0), expand=False, fill=True)
568
 
        vbox.pack_start(self._create_message_view(, True, True, 0))
569
 
        self.append_page(vbox, tab_label=Gtk.Label(label="General"))
570
 
        vbox.show()
571
 
 
572
 
    def _create_relations(self):
573
 
        vbox = Gtk.VBox(False, 6)
574
 
        vbox.set_border_width(6)
575
 
        vbox.pack_start(self._create_parents(, True, True, 0), expand=False, fill=True)
576
 
        vbox.pack_start(self._create_children(, True, True, 0), expand=False, fill=True)
577
 
        self.append_page(vbox, tab_label=Gtk.Label(label="Relations"))
578
 
        vbox.show()
579
 
 
580
 
    def _create_signature(self):
581
 
        self.signature_table = SignatureTab(self._repository)
582
 
        self.append_page(self.signature_table, tab_label=Gtk.Label(label='Signature'))
583
 
        self.connect_after('notify::revision', self._update_signature)
 
113
            hbox.pack_start(button, expand=False, fill=True)
 
114
            button.show()
 
115
 
 
116
    def _create(self):
 
117
        vbox = gtk.VBox(False, 6)
 
118
        vbox.set_border_width(6)
 
119
        vbox.pack_start(self._create_headers(), expand=False, fill=True)
 
120
        vbox.pack_start(self._create_parents_table(), expand=False, fill=True)
 
121
        vbox.pack_start(self._create_message_view())
 
122
        self.add_with_viewport(vbox)
 
123
        vbox.show()
584
124
 
585
125
    def _create_headers(self):
586
 
        self.avatarsbox = AvatarsBox()
587
 
        
588
 
        self.table = Gtk.Table(rows=5, columns=2)
 
126
        self.table = gtk.Table(rows=4, columns=2)
589
127
        self.table.set_row_spacings(6)
590
128
        self.table.set_col_spacings(6)
591
129
        self.table.show()
592
 
        
593
 
        self.avatarsbox.pack_start(self.table, True, True, 0)
594
 
        self.avatarsbox.show()
595
 
 
596
 
        row = 0
597
 
 
598
 
        label = Gtk.Label()
599
 
        label.set_alignment(1.0, 0.5)
 
130
 
 
131
        align = gtk.Alignment(1.0, 0.5)
 
132
        label = gtk.Label()
600
133
        label.set_markup("<b>Revision Id:</b>")
601
 
        self.table.attach(label, 0, 1, row, row+1, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
134
        align.add(label)
 
135
        self.table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
 
136
        align.show()
602
137
        label.show()
603
138
 
604
 
        revision_id = Gtk.Label()
605
 
        revision_id.set_ellipsize(Pango.EllipsizeMode.MIDDLE)
606
 
        revision_id.set_alignment(0.0, 0.5)
607
 
        revision_id.set_selectable(True)
608
 
        self.connect('notify::revision', 
609
 
                lambda w, p: revision_id.set_text(self._revision.revision_id))
610
 
        self.table.attach(revision_id, 1, 2, row, row+1, Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
611
 
        revision_id.show()
612
 
 
613
 
        row += 1
614
 
        self.author_label = Gtk.Label()
615
 
        self.author_label.set_alignment(1.0, 0.5)
616
 
        self.author_label.set_markup("<b>Author:</b>")
617
 
        self.table.attach(self.author_label, 0, 1, row, row+1, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
618
 
        self.author_label.show()
619
 
 
620
 
        self.author = Gtk.Label()
621
 
        self.author.set_ellipsize(Pango.EllipsizeMode.END)
622
 
        self.author.set_alignment(0.0, 0.5)
623
 
        self.author.set_selectable(True)
624
 
        self.table.attach(self.author, 1, 2, row, row+1, Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
625
 
        self.author.show()
626
 
        self.author.hide()
627
 
 
628
 
        row += 1
629
 
        label = Gtk.Label()
630
 
        label.set_alignment(1.0, 0.5)
 
139
        align = gtk.Alignment(0.0, 0.5)
 
140
        self.revision_id = gtk.Label()
 
141
        self.revision_id.set_selectable(True)
 
142
        align.add(self.revision_id)
 
143
        self.table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
144
        align.show()
 
145
        self.revision_id.show()
 
146
 
 
147
        align = gtk.Alignment(1.0, 0.5)
 
148
        label = gtk.Label()
631
149
        label.set_markup("<b>Committer:</b>")
632
 
        self.table.attach(label, 0, 1, row, row+1, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
150
        align.add(label)
 
151
        self.table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL)
 
152
        align.show()
633
153
        label.show()
634
154
 
635
 
        self.committer = Gtk.Label()
636
 
        self.committer.set_ellipsize(Pango.EllipsizeMode.END)
637
 
        self.committer.set_alignment(0.0, 0.5)
 
155
        align = gtk.Alignment(0.0, 0.5)
 
156
        self.committer = gtk.Label()
638
157
        self.committer.set_selectable(True)
639
 
        self.table.attach(self.committer, 1, 2, row, row+1, Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
158
        align.add(self.committer)
 
159
        self.table.attach(align, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
160
        align.show()
640
161
        self.committer.show()
641
162
 
642
 
        row += 1
643
 
        self.branchnick_label = Gtk.Label()
644
 
        self.branchnick_label.set_alignment(1.0, 0.5)
645
 
        self.branchnick_label.set_markup("<b>Branch nick:</b>")
646
 
        self.table.attach(self.branchnick_label, 0, 1, row, row+1, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
163
        align = gtk.Alignment(0.0, 0.5)
 
164
        label = gtk.Label()
 
165
        label.set_markup("<b>Branch nick:</b>")
 
166
        align.add(label)
 
167
        self.table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
 
168
        label.show()
 
169
        align.show()
 
170
 
 
171
        align = gtk.Alignment(0.0, 0.5)
 
172
        self.branchnick_label = gtk.Label()
 
173
        self.branchnick_label.set_selectable(True)
 
174
        align.add(self.branchnick_label)
 
175
        self.table.attach(align, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL)
647
176
        self.branchnick_label.show()
648
 
 
649
 
        self.branchnick = Gtk.Label()
650
 
        self.branchnick.set_ellipsize(Pango.EllipsizeMode.MIDDLE)
651
 
        self.branchnick.set_alignment(0.0, 0.5)
652
 
        self.branchnick.set_selectable(True)
653
 
        self.table.attach(self.branchnick, 1, 2, row, row+1, Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
654
 
        self.branchnick.show()
655
 
 
656
 
        row += 1
657
 
        label = Gtk.Label()
658
 
        label.set_alignment(1.0, 0.5)
 
177
        align.show()
 
178
 
 
179
        align = gtk.Alignment(1.0, 0.5)
 
180
        label = gtk.Label()
659
181
        label.set_markup("<b>Timestamp:</b>")
660
 
        self.table.attach(label, 0, 1, row, row+1, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
182
        align.add(label)
 
183
        self.table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL)
 
184
        align.show()
661
185
        label.show()
662
186
 
663
 
        self.timestamp = Gtk.Label()
664
 
        self.timestamp.set_ellipsize(Pango.EllipsizeMode.END)
665
 
        self.timestamp.set_alignment(0.0, 0.5)
 
187
        align = gtk.Alignment(0.0, 0.5)
 
188
        self.timestamp = gtk.Label()
666
189
        self.timestamp.set_selectable(True)
667
 
        self.table.attach(self.timestamp, 1, 2, row, row+1, Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
190
        align.add(self.timestamp)
 
191
        self.table.attach(align, 1, 2, 3, 4, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
192
        align.show()
668
193
        self.timestamp.show()
669
194
 
670
 
        row += 1
671
 
        self.tags_label = Gtk.Label()
672
 
        self.tags_label.set_alignment(1.0, 0.5)
673
 
        self.tags_label.set_markup("<b>Tags:</b>")
674
 
        self.table.attach(self.tags_label, 0, 1, row, row+1, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
675
 
        self.tags_label.show()
676
 
 
677
 
        self.tags_list = Gtk.Label()
678
 
        self.tags_list.set_ellipsize(Pango.EllipsizeMode.MIDDLE)
679
 
        self.tags_list.set_alignment(0.0, 0.5)
680
 
        self.table.attach(self.tags_list, 1, 2, row, row+1, Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
681
 
        self.tags_list.show()
682
 
 
683
 
        self.connect('notify::revision', self._add_tags)
684
 
 
685
 
        self.avatarsbox.show()
686
 
        return self.avatarsbox
687
 
    
688
 
    def _create_parents(self):
689
 
        hbox = Gtk.HBox(True, 3)
690
 
        
691
 
        self.parents_table = self._create_parents_or_children_table(
692
 
            "<b>Parents:</b>")
 
195
        return self.table
 
196
 
 
197
    def _create_parents_table(self):
 
198
        self.parents_table = gtk.Table(rows=1, columns=2)
 
199
        self.parents_table.set_row_spacings(3)
 
200
        self.parents_table.set_col_spacings(6)
 
201
        self.parents_table.show()
693
202
        self.parents_widgets = []
694
 
        hbox.pack_start(self.parents_table, True, True, 0)
695
 
 
696
 
        hbox.show()
697
 
        return hbox
698
 
 
699
 
    def _create_children(self):
700
 
        hbox = Gtk.HBox(True, 3)
701
 
        self.children_table = self._create_parents_or_children_table(
702
 
            "<b>Children:</b>")
703
 
        self.children_widgets = []
704
 
        hbox.pack_start(self.children_table, True, True, 0)
705
 
        hbox.show()
706
 
        return hbox
707
 
        
708
 
    def _create_parents_or_children_table(self, text):
709
 
        table = Gtk.Table(rows=1, columns=2)
710
 
        table.set_row_spacings(3)
711
 
        table.set_col_spacings(6)
712
 
        table.show()
713
 
 
714
 
        label = Gtk.Label()
715
 
        label.set_markup(text)
716
 
        align = Gtk.Alignment.new(0.0, 0.5)
 
203
 
 
204
        label = gtk.Label()
 
205
        label.set_markup("<b>Parents:</b>")
 
206
        align = gtk.Alignment(0.0, 0.5)
717
207
        align.add(label)
718
 
        table.attach(align, 0, 1, 0, 1, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
208
        self.parents_table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
719
209
        label.show()
720
210
        align.show()
721
211
 
722
 
        return table
 
212
        return self.parents_table
723
213
 
724
214
    def _create_message_view(self):
725
 
        msg_buffer = Gtk.TextBuffer()
726
 
        self.connect('notify::revision',
727
 
                lambda w, p: msg_buffer.set_text(self._revision.message))
728
 
        window = Gtk.ScrolledWindow()
729
 
        window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
730
 
        window.set_shadow_type(Gtk.ShadowType.IN)
731
 
        tv = Gtk.TextView(msg_buffer)
732
 
        tv.set_editable(False)
733
 
        tv.set_wrap_mode(Gtk.WrapMode.WORD)
734
 
 
735
 
        tv.modify_font(Pango.FontDescription("Monospace"))
736
 
        tv.show()
737
 
        window.add(tv)
738
 
        window.show()
739
 
        return window
740
 
 
741
 
    def _create_bugs(self):
742
 
        self.bugs_page = BugsTab()
743
 
        self.connect_after('notify::revision', self._update_bugs) 
744
 
        self.append_page(self.bugs_page, tab_label=Gtk.Label(label='Bugs'))
745
 
 
746
 
    def _create_file_info_view(self):
747
 
        self.file_info_box = Gtk.VBox(False, 6)
748
 
        self.file_info_box.set_border_width(6)
749
 
        self.file_info_buffer = Gtk.TextBuffer()
750
 
        window = Gtk.ScrolledWindow()
751
 
        window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
752
 
        window.set_shadow_type(Gtk.ShadowType.IN)
753
 
        tv = Gtk.TextView(self.file_info_buffer)
754
 
        tv.set_editable(False)
755
 
        tv.set_wrap_mode(Gtk.WrapMode.WORD)
756
 
        tv.modify_font(Pango.FontDescription("Monospace"))
757
 
        tv.show()
758
 
        window.add(tv)
759
 
        window.show()
760
 
        self.file_info_box.pack_start(window, True, True, 0)
761
 
        self.file_info_box.hide() # Only shown when there are per-file messages
762
 
        self.append_page(self.file_info_box, tab_label=Gtk.Label(label='Per-file'))
 
215
        self.message_buffer = gtk.TextBuffer()
 
216
        tv = gtk.TextView(self.message_buffer)
 
217
        tv.set_editable(False)
 
218
        tv.set_wrap_mode(gtk.WRAP_WORD)
 
219
        tv.modify_font(pango.FontDescription("Monospace"))
 
220
        tv.show()
 
221
        return tv
763
222