/b-gtk/fix-viz

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

« back to all changes in this revision

Viewing changes to revisionview.py

  • Committer: Daniel Schierbeck
  • Date: 2008-04-01 22:05:41 UTC
  • mto: (461.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 462.
  • Revision ID: daniel.schierbeck@gmail.com-20080401220541-kyqyda8yhp8skurp
Made bug tab prettier.

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
import gobject
 
23
import subprocess
22
24
 
23
 
from bzrlib import trace
 
25
from bzrlib.plugins.gtk import icon_path
24
26
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
 
 
 
27
from bzrlib.util.bencode import bdecode
44
28
 
45
29
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
 
 
 
30
    subprocess.Popen(['sensible-browser', uri], close_fds=True)
 
31
 
 
32
gtk.link_button_set_uri_hook(_open_link)
 
33
 
 
34
class BugsTab(gtk.VBox):
54
35
    def __init__(self):
55
 
        super(BugsTab, self).__init__(homogeneous=False, spacing=6)
 
36
        super(BugsTab, self).__init__(False, 6)
56
37
 
57
 
        table = Gtk.Table(rows=2, columns=2)
 
38
        table = gtk.Table(rows=2, columns=2)
58
39
 
59
40
        table.set_row_spacings(6)
60
 
        table.set_col_spacing(0, 16)
61
41
 
62
 
        image = Gtk.Image()
 
42
        image = gtk.Image()
63
43
        image.set_from_file(icon_path("bug.png"))
64
 
        table.attach(image, 0, 1, 0, 1, Gtk.AttachOptions.FILL)
 
44
        table.attach(image, 0, 1, 0, 1, gtk.FILL)
65
45
 
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)
 
46
        align = gtk.Alignment(0.0, 0.5)
 
47
        label = gtk.Label()
 
48
        label.set_markup("<b>Bugs</b>\nThis revision has one or more bug associations.")
 
49
        align.add(label)
 
50
        table.attach(align, 1, 2, 0, 1, gtk.FILL)
70
51
 
71
52
        treeview = self.construct_treeview()
72
 
        table.attach(treeview, 1, 2, 1, 2, Gtk.AttachOptions.FILL | Gtk.AttachOptions.EXPAND)
 
53
        table.attach(treeview, 1, 2, 1, 2, gtk.FILL | gtk.EXPAND)
73
54
 
74
55
        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))
 
56
        self.pack_start(table, expand=False)
 
57
 
 
58
        self.hide_all()
101
59
 
102
60
    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)
 
61
        self.bugs = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
 
62
        self.treeview = gtk.TreeView(self.bugs)
 
63
 
 
64
        uri_column = gtk.TreeViewColumn('Bug URI', gtk.CellRendererText(), text=0)
 
65
        status_column = gtk.TreeViewColumn('Status', gtk.CellRendererText(), text=1)
 
66
 
108
67
        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)
 
68
        self.treeview.append_column(status_column)
 
69
 
 
70
        win = gtk.ScrolledWindow()
 
71
        win.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
 
72
        win.set_shadow_type(gtk.SHADOW_IN)
115
73
        win.add(self.treeview)
116
74
 
117
75
        return win
118
76
 
119
77
    def clear(self):
120
 
        self.num_bugs = 0
121
78
        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.")
 
79
        self.hide_all() # Only shown when there are bugs
125
80
 
126
81
    def add_bug(self, url, status):
127
 
        self.num_bugs += 1
128
82
        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()
 
83
        self.show_all()
 
84
 
 
85
 
 
86
class SignatureTab(gtk.VBox):
 
87
    def __init__(self):
 
88
        from gpg import GPGSubprocess
 
89
        self.gpg = GPGSubprocess()
 
90
        super(SignatureTab, self).__init__(False, 6)
 
91
        signature_box = gtk.Table(rows=1, columns=2)
 
92
        signature_box.set_col_spacing(0, 12)
 
93
 
 
94
        self.signature_image = gtk.Image()
 
95
        signature_box.attach(self.signature_image, 0, 1, 0, 1, gtk.FILL)
 
96
 
 
97
        self.signature_label = gtk.Label()
 
98
        signature_box.attach(self.signature_label, 1, 2, 0, 1, gtk.FILL)
 
99
 
 
100
        signature_info = gtk.Table(rows=1, columns=2)
 
101
        signature_info.set_row_spacings(6)
 
102
        signature_info.set_col_spacings(6)
 
103
 
 
104
        align = gtk.Alignment(1.0, 0.5)
 
105
        label = gtk.Label()
 
106
        label.set_markup("<b>Key Id:</b>")
 
107
        align.add(label)
 
108
        signature_info.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
 
109
 
 
110
        align = gtk.Alignment(0.0, 0.5)
 
111
        self.signature_key_id = gtk.Label()
168
112
        self.signature_key_id.set_selectable(True)
169
113
        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)
 
114
        signature_info.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
195
115
 
196
116
        self.set_border_width(6)
197
 
        self.pack_start(signature_box, False, True, 0)
 
117
        self.pack_start(signature_box, expand=False)
 
118
        self.pack_start(signature_info, expand=False)
198
119
        self.show_all()
199
120
 
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
121
    def show_no_signature(self):
211
 
        self.signature_key_id_label.hide()
212
122
        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
123
        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.")
 
124
        self.signature_label.set_text("This revision has not been signed.")
 
125
 
 
126
    def show_signature(self, text):
 
127
        signature = self.gpg.verify(text)
 
128
 
 
129
        if signature.key_id is not None:
 
130
            self.signature_key_id.set_text(signature.key_id)
 
131
 
 
132
        if signature.is_valid():
 
133
            self.signature_image.set_from_file(icon_path("sign-ok.png"))
 
134
            self.signature_label.set_text("This revision has been signed.")
253
135
        else:
254
 
            self.show_no_signature()
255
136
            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):
 
137
            self.signature_label.set_text("This revision has been signed, " + 
 
138
                    "but the authenticity of the signature cannot be verified.")
 
139
 
 
140
 
 
141
class RevisionView(gtk.Notebook):
288
142
    """ Custom widget for commit log details.
289
143
 
290
144
    A variety of bzr tools may need to implement such a thing. This is a
293
147
 
294
148
    __gproperties__ = {
295
149
        'branch': (
296
 
            GObject.TYPE_PYOBJECT,
 
150
            gobject.TYPE_PYOBJECT,
297
151
            'Branch',
298
152
            'The branch holding the revision being displayed',
299
 
            GObject.PARAM_CONSTRUCT_ONLY | GObject.PARAM_WRITABLE
 
153
            gobject.PARAM_CONSTRUCT_ONLY | gobject.PARAM_WRITABLE
300
154
        ),
301
155
 
302
156
        'revision': (
303
 
            GObject.TYPE_PYOBJECT,
 
157
            gobject.TYPE_PYOBJECT,
304
158
            'Revision',
305
159
            'The revision being displayed',
306
 
            GObject.PARAM_READWRITE
 
160
            gobject.PARAM_READWRITE
307
161
        ),
308
162
 
309
163
        'children': (
310
 
            GObject.TYPE_PYOBJECT,
 
164
            gobject.TYPE_PYOBJECT,
311
165
            'Children',
312
166
            'Child revisions',
313
 
            GObject.PARAM_READWRITE
 
167
            gobject.PARAM_READWRITE
314
168
        ),
315
169
 
316
170
        'file-id': (
317
 
            GObject.TYPE_PYOBJECT,
 
171
            gobject.TYPE_PYOBJECT,
318
172
            'File Id',
319
173
            'The file id',
320
 
            GObject.PARAM_READWRITE
 
174
            gobject.PARAM_READWRITE
321
175
        )
322
176
    }
323
177
 
324
 
    def __init__(self, branch=None, repository=None):
325
 
        super(RevisionView, self).__init__()
326
178
 
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
 
179
    def __init__(self, branch=None):
 
180
        gtk.Notebook.__init__(self)
334
181
 
335
182
        self._create_general()
336
183
        self._create_relations()
337
 
        # Disabled because testaments aren't verified yet:
338
 
        if has_seahorse:
339
 
            self._create_signature()
 
184
        self._create_signature()
340
185
        self._create_file_info_view()
341
186
        self._create_bugs()
342
187
 
343
 
        self.set_current_page(PAGE_GENERAL)
344
 
        self.connect_after('switch-page', self._switch_page_cb)
 
188
        self.set_current_page(0)
345
189
        
346
190
        self._show_callback = None
347
191
        self._clicked_callback = None
397
241
 
398
242
    def _set_revision(self, revision):
399
243
        if revision is None: return
400
 
        
401
 
        self.avatarsbox.reset()
402
 
        
 
244
 
403
245
        self._revision = revision
404
246
        if revision.committer is not None:
405
247
            self.committer.set_text(revision.committer)
406
 
            self.avatarsbox.add(revision.committer, "committer")
407
248
        else:
408
249
            self.committer.set_text("")
409
 
            self.avatarsbox.hide()
410
250
        author = revision.properties.get('author', '')
411
 
        self.avatarsbox.merge(revision.get_apparent_authors(), "author")
412
251
        if author != '':
413
252
            self.author.set_text(author)
414
253
            self.author.show()
421
260
            self.timestamp.set_text(format_date(revision.timestamp,
422
261
                                                revision.timezone))
423
262
        try:
424
 
            self.branchnick.show()
425
 
            self.branchnick_label.show()
426
 
            self.branchnick.set_text(revision.properties['branch-nick'])
 
263
            self.branchnick_label.set_text(revision.properties['branch-nick'])
427
264
        except KeyError:
428
 
            self.branchnick.hide()
429
 
            self.branchnick_label.hide()
 
265
            self.branchnick_label.set_text("")
430
266
 
431
267
        self._add_parents_or_children(revision.parent_ids,
432
268
                                      self.parents_widgets,
433
269
                                      self.parents_table)
434
 
 
 
270
        
435
271
        file_info = revision.properties.get('file-info', None)
436
272
        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
 
273
            file_info = bdecode(file_info.encode('UTF-8'))
443
274
 
444
275
        if file_info:
445
276
            if self._file_id is None:
461
292
        else:
462
293
            self.file_info_box.hide()
463
294
 
 
295
        self.bugs_table.clear()
 
296
        bugs_text = revision.properties.get('bugs', None)
 
297
        if bugs_text:
 
298
            for bugline in bugs_text.splitlines():
 
299
                (url, status) = bugline.split(" ")
 
300
                self.bugs_table.add_bug(url, status)
 
301
 
464
302
    def update_tags(self):
465
303
        if self._branch is not None and self._branch.supports_tags():
466
304
            self._tagdict = self._branch.tags.get_reverse_tag_dict()
470
308
        self._add_tags()
471
309
 
472
310
    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)
 
311
        revid = self._revision.revision_id
477
312
 
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)
 
313
        if self._branch.repository.has_signature_for_revision_id(revid):
 
314
            signature_text = self._branch.repository.get_signature_text(revid)
 
315
            self.signature_table.show_signature(signature_text)
 
316
        else:
 
317
            self.signature_table.show_no_signature()
482
318
 
483
319
    def set_children(self, children):
484
320
        self._add_parents_or_children(children,
485
321
                                      self.children_widgets,
486
322
                                      self.children_table)
487
323
 
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
324
    def _show_clicked_cb(self, widget, revid, parentid):
497
325
        """Callback for when the show button for a parent is clicked."""
498
326
        self._show_callback(revid, parentid)
527
355
        table.resize(max(len(revids), 1), 2)
528
356
 
529
357
        for idx, revid in enumerate(revids):
530
 
            align = Gtk.Alignment.new(0.0, 0.0, 1, 1)
 
358
            align = gtk.Alignment(0.0, 0.0)
531
359
            widgets.append(align)
532
360
            table.attach(align, 1, 2, idx, idx + 1,
533
 
                                      Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
361
                                      gtk.EXPAND | gtk.FILL, gtk.FILL)
534
362
            align.show()
535
363
 
536
 
            hbox = Gtk.HBox(homogeneous=False, spacing=6)
 
364
            hbox = gtk.HBox(False, spacing=6)
537
365
            align.add(hbox)
538
366
            hbox.show()
539
367
 
540
 
            image = Gtk.Image()
 
368
            image = gtk.Image()
541
369
            image.set_from_stock(
542
 
                Gtk.STOCK_FIND, Gtk.IconSize.SMALL_TOOLBAR)
 
370
                gtk.STOCK_FIND, gtk.ICON_SIZE_SMALL_TOOLBAR)
543
371
            image.show()
544
372
 
545
373
            if self._show_callback is not None:
546
 
                button = Gtk.Button()
 
374
                button = gtk.Button()
547
375
                button.add(image)
548
376
                button.connect("clicked", self._show_clicked_cb,
549
377
                               self._revision.revision_id, revid)
550
 
                hbox.pack_start(button, False, True, 0)
 
378
                hbox.pack_start(button, expand=False, fill=True)
551
379
                button.show()
552
380
 
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)
 
381
            button = gtk.Button(revid)
558
382
            button.connect("clicked",
559
 
                    lambda w, r: self.set_revision(
560
 
                        self._repository.get_revision(r)), revid)
 
383
                    lambda w, r: self.set_revision(self._branch.repository.get_revision(r)), revid)
561
384
            button.set_use_underline(False)
562
 
            hbox.pack_start(button, True, True, 0)
563
 
            button.show_all()
 
385
            hbox.pack_start(button, expand=False, fill=True)
 
386
            button.show()
564
387
 
565
388
    def _create_general(self):
566
 
        vbox = Gtk.VBox(homogeneous=False, spacing=6)
 
389
        vbox = gtk.VBox(False, 6)
567
390
        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"))
 
391
        vbox.pack_start(self._create_headers(), expand=False, fill=True)
 
392
        vbox.pack_start(self._create_message_view())
 
393
        self.append_page(vbox, tab_label=gtk.Label("General"))
571
394
        vbox.show()
572
395
 
573
396
    def _create_relations(self):
574
 
        vbox = Gtk.VBox(homogeneous=False, spacing=6)
 
397
        vbox = gtk.VBox(False, 6)
575
398
        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"))
 
399
        vbox.pack_start(self._create_parents(), expand=False, fill=True)
 
400
        vbox.pack_start(self._create_children(), expand=False, fill=True)
 
401
        self.append_page(vbox, tab_label=gtk.Label("Relations"))
579
402
        vbox.show()
580
403
 
581
404
    def _create_signature(self):
582
 
        self.signature_table = SignatureTab(self._repository)
583
 
        self.append_page(
584
 
            self.signature_table, Gtk.Label(label='Signature'))
 
405
        try:
 
406
            self.signature_table = SignatureTab()
 
407
        except ValueError: # No GPG found
 
408
            self.signature_table = None
 
409
            return
 
410
        self.append_page(self.signature_table, tab_label=gtk.Label('Signature'))
585
411
        self.connect_after('notify::revision', self._update_signature)
586
412
 
587
413
    def _create_headers(self):
588
 
        self.avatarsbox = AvatarsBox()
589
 
        
590
 
        self.table = Gtk.Table(rows=5, columns=2)
 
414
        self.table = gtk.Table(rows=5, columns=2)
591
415
        self.table.set_row_spacings(6)
592
416
        self.table.set_col_spacings(6)
593
417
        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)
 
418
 
 
419
        align = gtk.Alignment(1.0, 0.5)
 
420
        label = gtk.Label()
602
421
        label.set_markup("<b>Revision Id:</b>")
603
 
        self.table.attach(label, 0, 1, row, row+1, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
422
        align.add(label)
 
423
        self.table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
 
424
        align.show()
604
425
        label.show()
605
426
 
606
 
        revision_id = Gtk.Label()
607
 
        revision_id.set_ellipsize(Pango.EllipsizeMode.MIDDLE)
608
 
        revision_id.set_alignment(0.0, 0.5)
 
427
        align = gtk.Alignment(0.0, 0.5)
 
428
        revision_id = gtk.Label()
609
429
        revision_id.set_selectable(True)
610
430
        self.connect('notify::revision', 
611
431
                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)
 
432
        align.add(revision_id)
 
433
        self.table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
434
        align.show()
613
435
        revision_id.show()
614
436
 
615
 
        row += 1
616
 
        self.author_label = Gtk.Label()
617
 
        self.author_label.set_alignment(1.0, 0.5)
 
437
        align = gtk.Alignment(1.0, 0.5)
 
438
        self.author_label = gtk.Label()
618
439
        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)
 
440
        align.add(self.author_label)
 
441
        self.table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL)
 
442
        align.show()
620
443
        self.author_label.show()
621
444
 
622
 
        self.author = Gtk.Label()
623
 
        self.author.set_ellipsize(Pango.EllipsizeMode.END)
624
 
        self.author.set_alignment(0.0, 0.5)
 
445
        align = gtk.Alignment(0.0, 0.5)
 
446
        self.author = gtk.Label()
625
447
        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)
 
448
        align.add(self.author)
 
449
        self.table.attach(align, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
450
        align.show()
627
451
        self.author.show()
628
452
        self.author.hide()
629
453
 
630
 
        row += 1
631
 
        label = Gtk.Label()
632
 
        label.set_alignment(1.0, 0.5)
 
454
        align = gtk.Alignment(1.0, 0.5)
 
455
        label = gtk.Label()
633
456
        label.set_markup("<b>Committer:</b>")
634
 
        self.table.attach(label, 0, 1, row, row+1, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
457
        align.add(label)
 
458
        self.table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
 
459
        align.show()
635
460
        label.show()
636
461
 
637
 
        self.committer = Gtk.Label()
638
 
        self.committer.set_ellipsize(Pango.EllipsizeMode.END)
639
 
        self.committer.set_alignment(0.0, 0.5)
 
462
        align = gtk.Alignment(0.0, 0.5)
 
463
        self.committer = gtk.Label()
640
464
        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)
 
465
        align.add(self.committer)
 
466
        self.table.attach(align, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
467
        align.show()
642
468
        self.committer.show()
643
469
 
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)
 
470
        align = gtk.Alignment(0.0, 0.5)
 
471
        label = gtk.Label()
 
472
        label.set_markup("<b>Branch nick:</b>")
 
473
        align.add(label)
 
474
        self.table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL)
 
475
        label.show()
 
476
        align.show()
 
477
 
 
478
        align = gtk.Alignment(0.0, 0.5)
 
479
        self.branchnick_label = gtk.Label()
 
480
        self.branchnick_label.set_selectable(True)
 
481
        align.add(self.branchnick_label)
 
482
        self.table.attach(align, 1, 2, 3, 4, gtk.EXPAND | gtk.FILL, gtk.FILL)
649
483
        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)
 
484
        align.show()
 
485
 
 
486
        align = gtk.Alignment(1.0, 0.5)
 
487
        label = gtk.Label()
661
488
        label.set_markup("<b>Timestamp:</b>")
662
 
        self.table.attach(label, 0, 1, row, row+1, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
489
        align.add(label)
 
490
        self.table.attach(align, 0, 1, 4, 5, gtk.FILL, gtk.FILL)
 
491
        align.show()
663
492
        label.show()
664
493
 
665
 
        self.timestamp = Gtk.Label()
666
 
        self.timestamp.set_ellipsize(Pango.EllipsizeMode.END)
667
 
        self.timestamp.set_alignment(0.0, 0.5)
 
494
        align = gtk.Alignment(0.0, 0.5)
 
495
        self.timestamp = gtk.Label()
668
496
        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)
 
497
        align.add(self.timestamp)
 
498
        self.table.attach(align, 1, 2, 4, 5, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
499
        align.show()
670
500
        self.timestamp.show()
671
501
 
672
 
        row += 1
673
 
        self.tags_label = Gtk.Label()
674
 
        self.tags_label.set_alignment(1.0, 0.5)
 
502
        align = gtk.Alignment(1.0, 0.5)
 
503
        self.tags_label = gtk.Label()
675
504
        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)
 
505
        align.add(self.tags_label)
 
506
        align.show()
 
507
        self.table.attach(align, 0, 1, 5, 6, gtk.FILL, gtk.FILL)
677
508
        self.tags_label.show()
678
509
 
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)
 
510
        align = gtk.Alignment(0.0, 0.5)
 
511
        self.tags_list = gtk.Label()
 
512
        align.add(self.tags_list)
 
513
        self.table.attach(align, 1, 2, 5, 6, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
514
        align.show()
683
515
        self.tags_list.show()
684
516
 
685
517
        self.connect('notify::revision', self._add_tags)
686
518
 
687
 
        return self.avatarsbox
 
519
        return self.table
688
520
    
689
521
    def _create_parents(self):
690
 
        hbox = Gtk.HBox(homogeneous=True, spacing=3)
 
522
        hbox = gtk.HBox(True, 3)
691
523
        
692
524
        self.parents_table = self._create_parents_or_children_table(
693
525
            "<b>Parents:</b>")
694
526
        self.parents_widgets = []
695
 
        hbox.pack_start(self.parents_table, True, True, 0)
 
527
        hbox.pack_start(self.parents_table)
696
528
 
697
529
        hbox.show()
698
530
        return hbox
699
531
 
700
532
    def _create_children(self):
701
 
        hbox = Gtk.HBox(homogeneous=True, spacing=3)
 
533
        hbox = gtk.HBox(True, 3)
702
534
        self.children_table = self._create_parents_or_children_table(
703
535
            "<b>Children:</b>")
704
536
        self.children_widgets = []
705
 
        hbox.pack_start(self.children_table, True, True, 0)
 
537
        hbox.pack_start(self.children_table)
706
538
        hbox.show()
707
539
        return hbox
708
540
        
709
541
    def _create_parents_or_children_table(self, text):
710
 
        table = Gtk.Table(rows=1, columns=2)
 
542
        table = gtk.Table(rows=1, columns=2)
711
543
        table.set_row_spacings(3)
712
544
        table.set_col_spacings(6)
713
545
        table.show()
714
546
 
715
 
        label = Gtk.Label()
 
547
        label = gtk.Label()
716
548
        label.set_markup(text)
717
 
        align = Gtk.Alignment.new(0.0, 0.5, 0, 0)
 
549
        align = gtk.Alignment(0.0, 0.5)
718
550
        align.add(label)
719
 
        table.attach(align, 0, 1, 0, 1, Gtk.AttachOptions.FILL, Gtk.AttachOptions.FILL)
 
551
        table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
720
552
        label.show()
721
553
        align.show()
722
554
 
723
555
        return table
724
556
 
725
557
    def _create_message_view(self):
726
 
        msg_buffer = Gtk.TextBuffer()
 
558
        msg_buffer = gtk.TextBuffer()
727
559
        self.connect('notify::revision',
728
560
                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)
 
561
        window = gtk.ScrolledWindow()
 
562
        window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
 
563
        window.set_shadow_type(gtk.SHADOW_IN)
 
564
        tv = gtk.TextView(msg_buffer)
733
565
        tv.set_editable(False)
734
 
        tv.set_wrap_mode(Gtk.WrapMode.WORD)
 
566
        tv.set_wrap_mode(gtk.WRAP_WORD)
735
567
 
736
 
        tv.modify_font(Pango.FontDescription("Monospace"))
 
568
        tv.modify_font(pango.FontDescription("Monospace"))
737
569
        tv.show()
738
570
        window.add(tv)
739
571
        window.show()
740
572
        return window
741
573
 
742
574
    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'))
 
575
        self.bugs_table = BugsTab()
 
576
        self.append_page(self.bugs_table, tab_label=gtk.Label('Bugs'))
746
577
 
747
578
    def _create_file_info_view(self):
748
 
        self.file_info_box = Gtk.VBox(homogeneous=False, spacing=6)
 
579
        self.file_info_box = gtk.VBox(False, 6)
749
580
        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)
 
581
        self.file_info_buffer = gtk.TextBuffer()
 
582
        window = gtk.ScrolledWindow()
 
583
        window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
 
584
        window.set_shadow_type(gtk.SHADOW_IN)
 
585
        tv = gtk.TextView(self.file_info_buffer)
755
586
        tv.set_editable(False)
756
 
        tv.set_wrap_mode(Gtk.WrapMode.WORD)
757
 
        tv.modify_font(Pango.FontDescription("Monospace"))
 
587
        tv.set_wrap_mode(gtk.WRAP_WORD)
 
588
        tv.modify_font(pango.FontDescription("Monospace"))
758
589
        tv.show()
759
590
        window.add(tv)
760
591
        window.show()
761
 
        self.file_info_box.pack_start(window, True, True, 0)
 
592
        self.file_info_box.pack_start(window)
762
593
        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'))
 
594
        self.append_page(self.file_info_box, tab_label=gtk.Label('Per-file'))
764
595