/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: Jelmer Vernooij
  • Date: 2012-03-29 13:15:14 UTC
  • mfrom: (786.1.1 register-lazy)
  • Revision ID: jelmer@samba.org-20120329131514-knrl1w2wzntx89rv
Use lazy registration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 Dan Loda <danloda@gmail.com>
 
2
# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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
 
17
 
 
18
from gi.repository import Gtk
 
19
from gi.repository import Pango
 
20
from gi.repository import GObject
 
21
import webbrowser
 
22
 
 
23
from bzrlib import trace
 
24
from bzrlib.osutils import format_date
 
25
from bzrlib.bencode import bdecode
 
26
from bzrlib.testament import Testament
 
27
 
 
28
from bzrlib.plugins.gtk import icon_path
 
29
 
 
30
from bzrlib.plugins.gtk.avatarsbox import AvatarsBox
 
31
 
 
32
try:
 
33
    from bzrlib.plugins.gtk import seahorse
 
34
except ImportError:
 
35
    has_seahorse = False
 
36
else:
 
37
    has_seahorse = True
 
38
 
 
39
PAGE_GENERAL = 0
 
40
PAGE_RELATIONS = 1
 
41
PAGE_SIGNATURE = 2
 
42
PAGE_BUGS = 3
 
43
 
 
44
 
 
45
def _open_link(widget, uri):
 
46
    for cmd in ['sensible-browser', 'xdg-open']:
 
47
        if webbrowser._iscommand(cmd):
 
48
            webbrowser._tryorder.insert(0, '%s "%%s"' % cmd)
 
49
    webbrowser.open(uri)
 
50
 
 
51
 
 
52
class BugsTab(Gtk.VBox):
 
53
 
 
54
    def __init__(self):
 
55
        super(BugsTab, self).__init__(homogeneous=False, spacing=6)
 
56
 
 
57
        table = Gtk.Table(rows=2, columns=2)
 
58
 
 
59
        table.set_row_spacings(6)
 
60
        table.set_col_spacing(0, 16)
 
61
 
 
62
        image = Gtk.Image()
 
63
        image.set_from_file(icon_path("bug.png"))
 
64
        table.attach(image, 0, 1, 0, 1, Gtk.AttachOptions.FILL)
 
65
 
 
66
        align = Gtk.Alignment.new(0.0, 0.1, 0, 0)
 
67
        self.label = Gtk.Label()
 
68
        align.add(self.label)
 
69
        table.attach(align, 1, 2, 0, 1, Gtk.AttachOptions.FILL)
 
70
 
 
71
        treeview = self.construct_treeview()
 
72
        table.attach(treeview, 1, 2, 1, 2, Gtk.AttachOptions.FILL | Gtk.AttachOptions.EXPAND)
 
73
 
 
74
        self.set_border_width(6)
 
75
        self.pack_start(table, False, True, 0)
 
76
 
 
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))
 
101
 
 
102
    def construct_treeview(self):
 
103
        self.bugs = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING)
 
104
        self.treeview = Gtk.TreeView(model=self.bugs)
 
105
        self.treeview.set_headers_visible(False)
 
106
 
 
107
        uri_column = Gtk.TreeViewColumn('Bug URI', Gtk.CellRendererText(), text=0)
 
108
        self.treeview.append_column(uri_column)
 
109
 
 
110
        self.treeview.connect('row-activated', self.on_row_activated)
 
111
 
 
112
        win = Gtk.ScrolledWindow()
 
113
        win.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
 
114
        win.set_shadow_type(Gtk.ShadowType.IN)
 
115
        win.add(self.treeview)
 
116
 
 
117
        return win
 
118
 
 
119
    def clear(self):
 
120
        self.num_bugs = 0
 
121
        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.")
 
125
 
 
126
    def add_bug(self, url, status):
 
127
        self.num_bugs += 1
 
128
        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)
 
137
 
 
138
 
 
139
class SignatureTab(Gtk.VBox):
 
140
 
 
141
    def __init__(self, repository):
 
142
        self.key = None
 
143
        self.revision = None
 
144
        self.repository = repository
 
145
 
 
146
        super(SignatureTab, self).__init__(homogeneous=False, spacing=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)
 
151
 
 
152
        self.signature_image = Gtk.Image()
 
153
        signature_box.attach(self.signature_image, 0, 1, 0, 1, Gtk.AttachOptions.FILL)
 
154
 
 
155
        align = Gtk.Alignment.new(0.0, 0.1, 0.0, 0.0)
 
156
        self.signature_label = Gtk.Label()
 
157
        align.add(self.signature_label)
 
158
        signature_box.attach(align, 1, 3, 0, 1, Gtk.AttachOptions.FILL)
 
159
 
 
160
        align = Gtk.Alignment.new(0.0, 0.5, 0.0, 0.0)
 
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.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
165
 
 
166
        align = Gtk.Alignment.new(0.0, 0.5, 0.0, 0.0)
 
167
        self.signature_key_id = Gtk.Label()
 
168
        self.signature_key_id.set_selectable(True)
 
169
        align.add(self.signature_key_id)
 
170
        signature_box.attach(align, 2, 3, 1, 2, Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
171
 
 
172
        align = Gtk.Alignment.new(0.0, 0.5, 0.0, 0.0)
 
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.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
177
 
 
178
        align = Gtk.Alignment.new(0.0, 0.5, 0.0, 0.0)
 
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.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
183
 
 
184
        align = Gtk.Alignment.new(0.0, 0.5, 0.0, 0.0)
 
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.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
189
 
 
190
        align = Gtk.Alignment.new(0.0, 0.5, 0.0, 0.0)
 
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.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
195
 
 
196
        self.set_border_width(6)
 
197
        self.pack_start(signature_box, False, True, 0)
 
198
        self.show_all()
 
199
 
 
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
    def show_no_signature(self):
 
211
        self.signature_key_id_label.hide()
 
212
        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
        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.")
 
253
        else:
 
254
            self.show_no_signature()
 
255
            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)
 
285
 
 
286
 
 
287
class RevisionView(Gtk.Notebook):
 
288
    """ Custom widget for commit log details.
 
289
 
 
290
    A variety of bzr tools may need to implement such a thing. This is a
 
291
    start.
 
292
    """
 
293
 
 
294
    __gproperties__ = {
 
295
        'branch': (
 
296
            GObject.TYPE_PYOBJECT,
 
297
            'Branch',
 
298
            'The branch holding the revision being displayed',
 
299
            GObject.PARAM_CONSTRUCT_ONLY | GObject.PARAM_WRITABLE
 
300
        ),
 
301
 
 
302
        'revision': (
 
303
            GObject.TYPE_PYOBJECT,
 
304
            'Revision',
 
305
            'The revision being displayed',
 
306
            GObject.PARAM_READWRITE
 
307
        ),
 
308
 
 
309
        'children': (
 
310
            GObject.TYPE_PYOBJECT,
 
311
            'Children',
 
312
            'Child revisions',
 
313
            GObject.PARAM_READWRITE
 
314
        ),
 
315
 
 
316
        'file-id': (
 
317
            GObject.TYPE_PYOBJECT,
 
318
            'File Id',
 
319
            'The file id',
 
320
            GObject.PARAM_READWRITE
 
321
        )
 
322
    }
 
323
 
 
324
    def __init__(self, branch=None, repository=None):
 
325
        super(RevisionView, self).__init__()
 
326
 
 
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
        self.signature_table = None
 
334
 
 
335
        self._create_general()
 
336
        self._create_relations()
 
337
        # Disabled because testaments aren't verified yet:
 
338
        if has_seahorse:
 
339
            self._create_signature()
 
340
        self._create_file_info_view()
 
341
        self._create_bugs()
 
342
 
 
343
        self.set_current_page(PAGE_GENERAL)
 
344
        self.connect_after('switch-page', self._switch_page_cb)
 
345
        
 
346
        self._show_callback = None
 
347
        self._clicked_callback = None
 
348
 
 
349
        self._revision = None
 
350
        self._branch = branch
 
351
 
 
352
        self.update_tags()
 
353
 
 
354
        self.set_file_id(None)
 
355
 
 
356
    def do_get_property(self, property):
 
357
        if property.name == 'branch':
 
358
            return self._branch
 
359
        elif property.name == 'revision':
 
360
            return self._revision
 
361
        elif property.name == 'children':
 
362
            return self._children
 
363
        elif property.name == 'file-id':
 
364
            return self._file_id
 
365
        else:
 
366
            raise AttributeError, 'unknown property %s' % property.name
 
367
 
 
368
    def do_set_property(self, property, value):
 
369
        if property.name == 'branch':
 
370
            self._branch = value
 
371
        elif property.name == 'revision':
 
372
            self._set_revision(value)
 
373
        elif property.name == 'children':
 
374
            self.set_children(value)
 
375
        elif property.name == 'file-id':
 
376
            self._file_id = value
 
377
        else:
 
378
            raise AttributeError, 'unknown property %s' % property.name
 
379
 
 
380
    def set_show_callback(self, callback):
 
381
        self._show_callback = callback
 
382
 
 
383
    def set_file_id(self, file_id):
 
384
        """Set a specific file id that we want to track.
 
385
 
 
386
        This just effects the display of a per-file commit message.
 
387
        If it is set to None, then all commit messages will be shown.
 
388
        """
 
389
        self.set_property('file-id', file_id)
 
390
 
 
391
    def set_revision(self, revision):
 
392
        if revision != self._revision:
 
393
            self.set_property('revision', revision)
 
394
 
 
395
    def get_revision(self):
 
396
        return self.get_property('revision')
 
397
 
 
398
    def _set_revision(self, revision):
 
399
        if revision is None: return
 
400
        
 
401
        self.avatarsbox.reset()
 
402
        
 
403
        self._revision = revision
 
404
        if revision.committer is not None:
 
405
            self.committer.set_text(revision.committer)
 
406
            self.avatarsbox.add(revision.committer, "committer")
 
407
        else:
 
408
            self.committer.set_text("")
 
409
            self.avatarsbox.hide()
 
410
        author = revision.properties.get('author', '')
 
411
        self.avatarsbox.merge(revision.get_apparent_authors(), "author")
 
412
        if author != '':
 
413
            self.author.set_text(author)
 
414
            self.author.show()
 
415
            self.author_label.show()
 
416
        else:
 
417
            self.author.hide()
 
418
            self.author_label.hide()
 
419
 
 
420
        if revision.timestamp is not None:
 
421
            self.timestamp.set_text(format_date(revision.timestamp,
 
422
                                                revision.timezone))
 
423
        try:
 
424
            self.branchnick.show()
 
425
            self.branchnick_label.show()
 
426
            self.branchnick.set_text(revision.properties['branch-nick'])
 
427
        except KeyError:
 
428
            self.branchnick.hide()
 
429
            self.branchnick_label.hide()
 
430
 
 
431
        self._add_parents_or_children(revision.parent_ids,
 
432
                                      self.parents_widgets,
 
433
                                      self.parents_table)
 
434
 
 
435
        file_info = revision.properties.get('file-info', None)
 
436
        if file_info is not None:
 
437
            try:
 
438
                file_info = bdecode(file_info.encode('UTF-8'))
 
439
            except ValueError:
 
440
                trace.note('Invalid per-file info for revision:%s, value: %r',
 
441
                           revision.revision_id, file_info)
 
442
                file_info = None
 
443
 
 
444
        if file_info:
 
445
            if self._file_id is None:
 
446
                text = []
 
447
                for fi in file_info:
 
448
                    text.append('%(path)s\n%(message)s' % fi)
 
449
                self.file_info_buffer.set_text('\n'.join(text))
 
450
                self.file_info_box.show()
 
451
            else:
 
452
                text = []
 
453
                for fi in file_info:
 
454
                    if fi['file_id'] == self._file_id:
 
455
                        text.append(fi['message'])
 
456
                if text:
 
457
                    self.file_info_buffer.set_text('\n'.join(text))
 
458
                    self.file_info_box.show()
 
459
                else:
 
460
                    self.file_info_box.hide()
 
461
        else:
 
462
            self.file_info_box.hide()
 
463
 
 
464
    def update_tags(self):
 
465
        if self._branch is not None and self._branch.supports_tags():
 
466
            self._tagdict = self._branch.tags.get_reverse_tag_dict()
 
467
        else:
 
468
            self._tagdict = {}
 
469
 
 
470
        self._add_tags()
 
471
 
 
472
    def _update_signature(self, widget, param):
 
473
        if not has_seahorse:
 
474
            return
 
475
        if self.get_current_page() == PAGE_SIGNATURE:
 
476
            self.signature_table.set_revision(self._revision)
 
477
 
 
478
    def _update_bugs(self, widget, param):
 
479
        self.bugs_page.set_revision(self._revision)
 
480
        label = self.get_tab_label(self.bugs_page)
 
481
        label.set_sensitive(self.bugs_page.get_num_bugs() != 0)
 
482
 
 
483
    def set_children(self, children):
 
484
        self._add_parents_or_children(children,
 
485
                                      self.children_widgets,
 
486
                                      self.children_table)
 
487
 
 
488
    def _switch_page_cb(self, notebook, page, page_num):
 
489
        if not has_seahorse:
 
490
            return
 
491
        if page_num == PAGE_SIGNATURE:
 
492
            self.signature_table.set_revision(self._revision)
 
493
 
 
494
 
 
495
 
 
496
    def _show_clicked_cb(self, widget, revid, parentid):
 
497
        """Callback for when the show button for a parent is clicked."""
 
498
        self._show_callback(revid, parentid)
 
499
 
 
500
    def _go_clicked_cb(self, widget, revid):
 
501
        """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 = []
 
511
            
 
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)
 
534
            align.show()
 
535
 
 
536
            hbox = Gtk.HBox(homogeneous=False, spacing=6)
 
537
            align.add(hbox)
 
538
            hbox.show()
 
539
 
 
540
            image = Gtk.Image()
 
541
            image.set_from_stock(
 
542
                Gtk.STOCK_FIND, Gtk.IconSize.SMALL_TOOLBAR)
 
543
            image.show()
 
544
 
 
545
            if self._show_callback is not None:
 
546
                button = Gtk.Button()
 
547
                button.add(image)
 
548
                button.connect("clicked", self._show_clicked_cb,
 
549
                               self._revision.revision_id, revid)
 
550
                hbox.pack_start(button, False, True, 0)
 
551
                button.show()
 
552
 
 
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(
 
560
                        self._repository.get_revision(r)), revid)
 
561
            button.set_use_underline(False)
 
562
            hbox.pack_start(button, True, True, 0)
 
563
            button.show_all()
 
564
 
 
565
    def _create_general(self):
 
566
        vbox = Gtk.VBox(homogeneous=False, spacing=6)
 
567
        vbox.set_border_width(6)
 
568
        vbox.pack_start(self._create_headers(), False, True, 0)
 
569
        vbox.pack_start(self._create_message_view(), True, True, 0)
 
570
        self.append_page(vbox, Gtk.Label(label="General"))
 
571
        vbox.show()
 
572
 
 
573
    def _create_relations(self):
 
574
        vbox = Gtk.VBox(homogeneous=False, spacing=6)
 
575
        vbox.set_border_width(6)
 
576
        vbox.pack_start(self._create_parents(), False, True, 0)
 
577
        vbox.pack_start(self._create_children(), False, True, 0)
 
578
        self.append_page(vbox, Gtk.Label(label="Relations"))
 
579
        vbox.show()
 
580
 
 
581
    def _create_signature(self):
 
582
        self.signature_table = SignatureTab(self._repository)
 
583
        self.append_page(
 
584
            self.signature_table, Gtk.Label(label='Signature'))
 
585
        self.connect_after('notify::revision', self._update_signature)
 
586
 
 
587
    def _create_headers(self):
 
588
        self.avatarsbox = AvatarsBox()
 
589
        
 
590
        self.table = Gtk.Table(rows=5, columns=2)
 
591
        self.table.set_row_spacings(6)
 
592
        self.table.set_col_spacings(6)
 
593
        self.table.show()
 
594
        
 
595
        self.avatarsbox.pack_start(self.table, True, True, 0)
 
596
        self.avatarsbox.show()
 
597
 
 
598
        row = 0
 
599
 
 
600
        label = Gtk.Label()
 
601
        label.set_alignment(1.0, 0.5)
 
602
        label.set_markup("<b>Revision Id:</b>")
 
603
        self.table.attach(label, 0, 1, row, row+1, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
604
        label.show()
 
605
 
 
606
        revision_id = Gtk.Label()
 
607
        revision_id.set_ellipsize(Pango.EllipsizeMode.MIDDLE)
 
608
        revision_id.set_alignment(0.0, 0.5)
 
609
        revision_id.set_selectable(True)
 
610
        self.connect('notify::revision', 
 
611
                lambda w, p: revision_id.set_text(self._revision.revision_id))
 
612
        self.table.attach(revision_id, 1, 2, row, row+1, Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
613
        revision_id.show()
 
614
 
 
615
        row += 1
 
616
        self.author_label = Gtk.Label()
 
617
        self.author_label.set_alignment(1.0, 0.5)
 
618
        self.author_label.set_markup("<b>Author:</b>")
 
619
        self.table.attach(self.author_label, 0, 1, row, row+1, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
620
        self.author_label.show()
 
621
 
 
622
        self.author = Gtk.Label()
 
623
        self.author.set_ellipsize(Pango.EllipsizeMode.END)
 
624
        self.author.set_alignment(0.0, 0.5)
 
625
        self.author.set_selectable(True)
 
626
        self.table.attach(self.author, 1, 2, row, row+1, Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
627
        self.author.show()
 
628
        self.author.hide()
 
629
 
 
630
        row += 1
 
631
        label = Gtk.Label()
 
632
        label.set_alignment(1.0, 0.5)
 
633
        label.set_markup("<b>Committer:</b>")
 
634
        self.table.attach(label, 0, 1, row, row+1, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
635
        label.show()
 
636
 
 
637
        self.committer = Gtk.Label()
 
638
        self.committer.set_ellipsize(Pango.EllipsizeMode.END)
 
639
        self.committer.set_alignment(0.0, 0.5)
 
640
        self.committer.set_selectable(True)
 
641
        self.table.attach(self.committer, 1, 2, row, row+1, Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
642
        self.committer.show()
 
643
 
 
644
        row += 1
 
645
        self.branchnick_label = Gtk.Label()
 
646
        self.branchnick_label.set_alignment(1.0, 0.5)
 
647
        self.branchnick_label.set_markup("<b>Branch nick:</b>")
 
648
        self.table.attach(self.branchnick_label, 0, 1, row, row+1, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
649
        self.branchnick_label.show()
 
650
 
 
651
        self.branchnick = Gtk.Label()
 
652
        self.branchnick.set_ellipsize(Pango.EllipsizeMode.MIDDLE)
 
653
        self.branchnick.set_alignment(0.0, 0.5)
 
654
        self.branchnick.set_selectable(True)
 
655
        self.table.attach(self.branchnick, 1, 2, row, row+1, Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
656
        self.branchnick.show()
 
657
 
 
658
        row += 1
 
659
        label = Gtk.Label()
 
660
        label.set_alignment(1.0, 0.5)
 
661
        label.set_markup("<b>Timestamp:</b>")
 
662
        self.table.attach(label, 0, 1, row, row+1, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
663
        label.show()
 
664
 
 
665
        self.timestamp = Gtk.Label()
 
666
        self.timestamp.set_ellipsize(Pango.EllipsizeMode.END)
 
667
        self.timestamp.set_alignment(0.0, 0.5)
 
668
        self.timestamp.set_selectable(True)
 
669
        self.table.attach(self.timestamp, 1, 2, row, row+1, Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
670
        self.timestamp.show()
 
671
 
 
672
        row += 1
 
673
        self.tags_label = Gtk.Label()
 
674
        self.tags_label.set_alignment(1.0, 0.5)
 
675
        self.tags_label.set_markup("<b>Tags:</b>")
 
676
        self.table.attach(self.tags_label, 0, 1, row, row+1, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
677
        self.tags_label.show()
 
678
 
 
679
        self.tags_list = Gtk.Label()
 
680
        self.tags_list.set_ellipsize(Pango.EllipsizeMode.MIDDLE)
 
681
        self.tags_list.set_alignment(0.0, 0.5)
 
682
        self.table.attach(self.tags_list, 1, 2, row, row+1, Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
683
        self.tags_list.show()
 
684
 
 
685
        self.connect('notify::revision', self._add_tags)
 
686
 
 
687
        return self.avatarsbox
 
688
    
 
689
    def _create_parents(self):
 
690
        hbox = Gtk.HBox(homogeneous=True, spacing=3)
 
691
        
 
692
        self.parents_table = self._create_parents_or_children_table(
 
693
            "<b>Parents:</b>")
 
694
        self.parents_widgets = []
 
695
        hbox.pack_start(self.parents_table, True, True, 0)
 
696
 
 
697
        hbox.show()
 
698
        return hbox
 
699
 
 
700
    def _create_children(self):
 
701
        hbox = Gtk.HBox(homogeneous=True, spacing=3)
 
702
        self.children_table = self._create_parents_or_children_table(
 
703
            "<b>Children:</b>")
 
704
        self.children_widgets = []
 
705
        hbox.pack_start(self.children_table, True, True, 0)
 
706
        hbox.show()
 
707
        return hbox
 
708
        
 
709
    def _create_parents_or_children_table(self, text):
 
710
        table = Gtk.Table(rows=1, columns=2)
 
711
        table.set_row_spacings(3)
 
712
        table.set_col_spacings(6)
 
713
        table.show()
 
714
 
 
715
        label = Gtk.Label()
 
716
        label.set_markup(text)
 
717
        align = Gtk.Alignment.new(0.0, 0.5, 0, 0)
 
718
        align.add(label)
 
719
        table.attach(align, 0, 1, 0, 1, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
720
        label.show()
 
721
        align.show()
 
722
 
 
723
        return table
 
724
 
 
725
    def _create_message_view(self):
 
726
        msg_buffer = Gtk.TextBuffer()
 
727
        self.connect('notify::revision',
 
728
                lambda w, p: msg_buffer.set_text(self._revision.message))
 
729
        window = Gtk.ScrolledWindow()
 
730
        window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
 
731
        window.set_shadow_type(Gtk.ShadowType.IN)
 
732
        tv = Gtk.TextView(buffer=msg_buffer)
 
733
        tv.set_editable(False)
 
734
        tv.set_wrap_mode(Gtk.WrapMode.WORD)
 
735
 
 
736
        tv.modify_font(Pango.FontDescription("Monospace"))
 
737
        tv.show()
 
738
        window.add(tv)
 
739
        window.show()
 
740
        return window
 
741
 
 
742
    def _create_bugs(self):
 
743
        self.bugs_page = BugsTab()
 
744
        self.connect_after('notify::revision', self._update_bugs) 
 
745
        self.append_page(self.bugs_page, Gtk.Label(label='Bugs'))
 
746
 
 
747
    def _create_file_info_view(self):
 
748
        self.file_info_box = Gtk.VBox(homogeneous=False, spacing=6)
 
749
        self.file_info_box.set_border_width(6)
 
750
        self.file_info_buffer = Gtk.TextBuffer()
 
751
        window = Gtk.ScrolledWindow()
 
752
        window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
 
753
        window.set_shadow_type(Gtk.ShadowType.IN)
 
754
        tv = Gtk.TextView(buffer=self.file_info_buffer)
 
755
        tv.set_editable(False)
 
756
        tv.set_wrap_mode(Gtk.WrapMode.WORD)
 
757
        tv.modify_font(Pango.FontDescription("Monospace"))
 
758
        tv.show()
 
759
        window.add(tv)
 
760
        window.show()
 
761
        self.file_info_box.pack_start(window, True, True, 0)
 
762
        self.file_info_box.hide() # Only shown when there are per-file messages
 
763
        self.append_page(self.file_info_box, Gtk.Label(label='Per-file'))
 
764