/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: Martin Albisetti
  • Date: 2008-04-04 01:46:01 UTC
  • Revision ID: argentina@gmail.com-20080404014601-hutl46uqxx7psg2o
Removed duplicate code

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import gtk
21
21
import pango
22
22
import gobject
23
 
import webbrowser
 
23
import subprocess
24
24
 
 
25
from bzrlib.plugins.gtk import icon_path
25
26
from bzrlib.osutils import format_date
26
27
from bzrlib.util.bencode import bdecode
27
 
from bzrlib.testament import Testament
28
 
 
29
 
from bzrlib.plugins.gtk import icon_path
30
28
 
31
29
try:
32
30
    from bzrlib.plugins.gtk import seahorse
35
33
else:
36
34
    has_seahorse = True
37
35
 
38
 
PAGE_GENERAL = 0
39
 
PAGE_RELATIONS = 1
40
 
PAGE_SIGNATURE = 2
41
 
PAGE_BUGS = 3
42
 
 
43
 
 
44
36
def _open_link(widget, uri):
45
 
    for cmd in ['sensible-browser', 'xdg-open']:
46
 
        if webbrowser._iscommand(cmd):
47
 
            webbrowser._tryorder.insert(0, '%s "%%s"' % cmd)
48
 
    webbrowser.open(uri)
 
37
    subprocess.Popen(['sensible-browser', uri], close_fds=True)
49
38
 
50
39
gtk.link_button_set_uri_hook(_open_link)
51
40
 
52
 
class BugsTab(gtk.VBox):
 
41
class BugsTab(gtk.Table):
53
42
 
54
43
    def __init__(self):
55
 
        super(BugsTab, self).__init__(False, 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.FILL)
65
 
 
66
 
        align = gtk.Alignment(0.0, 0.1)
67
 
        self.label = gtk.Label()
68
 
        align.add(self.label)
69
 
        table.attach(align, 1, 2, 0, 1, gtk.FILL)
70
 
 
71
 
        treeview = self.construct_treeview()
72
 
        table.attach(treeview, 1, 2, 1, 2, gtk.FILL | gtk.EXPAND)
73
 
 
74
 
        self.set_border_width(6)
75
 
        self.pack_start(table, expand=False)
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(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.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
114
 
        win.set_shadow_type(gtk.SHADOW_IN)
115
 
        win.add(self.treeview)
116
 
 
117
 
        return win
 
44
        super(BugsTab, self).__init__(rows=5, columns=2)
 
45
        self.set_row_spacings(6)
 
46
        self.set_col_spacings(6)
 
47
        self.clear()
118
48
 
119
49
    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.")
 
50
        for c in self.get_children():
 
51
            self.remove(c)
 
52
        self.count = 0
 
53
        self.hide_all() # Only shown when there are bugs
125
54
 
126
55
    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)
 
56
        button = gtk.LinkButton(url, url)
 
57
        self.attach(button, 0, 1, self.count, self.count + 1,
 
58
                              gtk.EXPAND | gtk.FILL, gtk.FILL)
 
59
        status_label = gtk.Label(status)
 
60
        self.attach(status_label, 1, 2, self.count, self.count + 1,
 
61
                              gtk.EXPAND | gtk.FILL, gtk.FILL)
 
62
        self.count += 1
 
63
        self.show_all()
137
64
 
138
65
 
139
66
class SignatureTab(gtk.VBox):
222
149
                                        "This revision has not been signed.")
223
150
 
224
151
    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
 
152
        key = seahorse.verify(crypttext)
236
153
 
237
154
        if key and key.is_available():
238
155
            if key.is_trusted():
321
238
        )
322
239
    }
323
240
 
324
 
    def __init__(self, branch=None, repository=None):
 
241
 
 
242
    def __init__(self, branch=None):
325
243
        gtk.Notebook.__init__(self)
326
244
 
327
245
        self._revision = None
328
246
        self._branch = branch
329
 
        if branch is not None:
330
 
            self._repository = branch.repository
331
 
        else:
332
 
            self._repository = repository
333
247
 
334
248
        self._create_general()
335
249
        self._create_relations()
336
 
        # Disabled because testaments aren't verified yet:
337
250
        if has_seahorse:
338
251
            self._create_signature()
339
252
        self._create_file_info_view()
340
253
        self._create_bugs()
341
254
 
342
 
        self.set_current_page(PAGE_GENERAL)
343
 
        self.connect_after('switch-page', self._switch_page_cb)
 
255
        self.set_current_page(0)
344
256
        
345
257
        self._show_callback = None
346
258
        self._clicked_callback = None
447
359
        else:
448
360
            self.file_info_box.hide()
449
361
 
 
362
        self.bugs_table.clear()
 
363
        bugs_text = revision.properties.get('bugs', None)
 
364
        if bugs_text:
 
365
            for bugline in bugs_text.splitlines():
 
366
                (url, status) = bugline.split(" ")
 
367
                self.bugs_table.add_bug(url, status)
 
368
 
450
369
    def update_tags(self):
451
370
        if self._branch is not None and self._branch.supports_tags():
452
371
            self._tagdict = self._branch.tags.get_reverse_tag_dict()
456
375
        self._add_tags()
457
376
 
458
377
    def _update_signature(self, widget, param):
459
 
        if self.get_current_page() == PAGE_SIGNATURE:
460
 
            self.signature_table.set_revision(self._revision)
461
 
 
462
 
    def _update_bugs(self, widget, param):
463
 
        self.bugs_page.set_revision(self._revision)
464
 
        label = self.get_tab_label(self.bugs_page)
465
 
        label.set_sensitive(self.bugs_page.get_num_bugs() != 0)
 
378
        self.signature_table.set_revision(self._revision)
466
379
 
467
380
    def set_children(self, children):
468
381
        self._add_parents_or_children(children,
469
382
                                      self.children_widgets,
470
383
                                      self.children_table)
471
384
 
472
 
    def _switch_page_cb(self, notebook, page, page_num):
473
 
        if page_num == PAGE_SIGNATURE:
474
 
            self.signature_table.set_revision(self._revision)
475
 
 
476
 
 
477
 
 
478
385
    def _show_clicked_cb(self, widget, revid, parentid):
479
386
        """Callback for when the show button for a parent is clicked."""
480
387
        self._show_callback(revid, parentid)
509
416
        table.resize(max(len(revids), 1), 2)
510
417
 
511
418
        for idx, revid in enumerate(revids):
512
 
            align = gtk.Alignment(0.0, 0.0, 1, 1)
 
419
            align = gtk.Alignment(0.0, 0.0)
513
420
            widgets.append(align)
514
421
            table.attach(align, 1, 2, idx, idx + 1,
515
422
                                      gtk.EXPAND | gtk.FILL, gtk.FILL)
532
439
                hbox.pack_start(button, expand=False, fill=True)
533
440
                button.show()
534
441
 
535
 
            button = gtk.Button()
536
 
            revid_label = gtk.Label(str(revid))
537
 
            revid_label.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
538
 
            revid_label.set_alignment(0.0, 0.5)
539
 
            button.add(revid_label)
 
442
            button = gtk.Button(revid)
540
443
            button.connect("clicked",
541
 
                    lambda w, r: self.set_revision(self._repository.get_revision(r)), revid)
 
444
                    lambda w, r: self.set_revision(self._branch.repository.get_revision(r)), revid)
542
445
            button.set_use_underline(False)
543
 
            hbox.pack_start(button, expand=True, fill=True)
544
 
            button.show_all()
 
446
            hbox.pack_start(button, expand=False, fill=True)
 
447
            button.show()
545
448
 
546
449
    def _create_general(self):
547
450
        vbox = gtk.VBox(False, 6)
560
463
        vbox.show()
561
464
 
562
465
    def _create_signature(self):
563
 
        self.signature_table = SignatureTab(self._repository)
 
466
        self.signature_table = SignatureTab(self._branch.repository)
564
467
        self.append_page(self.signature_table, tab_label=gtk.Label('Signature'))
565
468
        self.connect_after('notify::revision', self._update_signature)
566
469
 
570
473
        self.table.set_col_spacings(6)
571
474
        self.table.show()
572
475
 
573
 
        row = 0
574
 
 
 
476
        align = gtk.Alignment(1.0, 0.5)
575
477
        label = gtk.Label()
576
 
        label.set_alignment(1.0, 0.5)
577
478
        label.set_markup("<b>Revision Id:</b>")
578
 
        self.table.attach(label, 0, 1, row, row+1, gtk.FILL, gtk.FILL)
 
479
        align.add(label)
 
480
        self.table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
 
481
        align.show()
579
482
        label.show()
580
483
 
 
484
        align = gtk.Alignment(0.0, 0.5)
581
485
        revision_id = gtk.Label()
582
 
        revision_id.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
583
 
        revision_id.set_alignment(0.0, 0.5)
584
486
        revision_id.set_selectable(True)
585
487
        self.connect('notify::revision', 
586
488
                lambda w, p: revision_id.set_text(self._revision.revision_id))
587
 
        self.table.attach(revision_id, 1, 2, row, row+1, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
489
        align.add(revision_id)
 
490
        self.table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
491
        align.show()
588
492
        revision_id.show()
589
493
 
590
 
        row += 1
 
494
        align = gtk.Alignment(1.0, 0.5)
591
495
        self.author_label = gtk.Label()
592
 
        self.author_label.set_alignment(1.0, 0.5)
593
496
        self.author_label.set_markup("<b>Author:</b>")
594
 
        self.table.attach(self.author_label, 0, 1, row, row+1, gtk.FILL, gtk.FILL)
 
497
        align.add(self.author_label)
 
498
        self.table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL)
 
499
        align.show()
595
500
        self.author_label.show()
596
501
 
 
502
        align = gtk.Alignment(0.0, 0.5)
597
503
        self.author = gtk.Label()
598
 
        self.author.set_ellipsize(pango.ELLIPSIZE_END)
599
 
        self.author.set_alignment(0.0, 0.5)
600
504
        self.author.set_selectable(True)
601
 
        self.table.attach(self.author, 1, 2, row, row+1, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
505
        align.add(self.author)
 
506
        self.table.attach(align, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
507
        align.show()
602
508
        self.author.show()
603
509
        self.author.hide()
604
510
 
605
 
        row += 1
 
511
        align = gtk.Alignment(1.0, 0.5)
606
512
        label = gtk.Label()
607
 
        label.set_alignment(1.0, 0.5)
608
513
        label.set_markup("<b>Committer:</b>")
609
 
        self.table.attach(label, 0, 1, row, row+1, gtk.FILL, gtk.FILL)
 
514
        align.add(label)
 
515
        self.table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
 
516
        align.show()
610
517
        label.show()
611
518
 
 
519
        align = gtk.Alignment(0.0, 0.5)
612
520
        self.committer = gtk.Label()
613
 
        self.committer.set_ellipsize(pango.ELLIPSIZE_END)
614
 
        self.committer.set_alignment(0.0, 0.5)
615
521
        self.committer.set_selectable(True)
616
 
        self.table.attach(self.committer, 1, 2, row, row+1, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
522
        align.add(self.committer)
 
523
        self.table.attach(align, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
524
        align.show()
617
525
        self.committer.show()
618
526
 
619
 
        row += 1
 
527
        align = gtk.Alignment(0.0, 0.5)
620
528
        label = gtk.Label()
621
 
        label.set_alignment(1.0, 0.5)
622
529
        label.set_markup("<b>Branch nick:</b>")
623
 
        self.table.attach(label, 0, 1, row, row+1, gtk.FILL, gtk.FILL)
 
530
        align.add(label)
 
531
        self.table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL)
624
532
        label.show()
 
533
        align.show()
625
534
 
 
535
        align = gtk.Alignment(0.0, 0.5)
626
536
        self.branchnick_label = gtk.Label()
627
 
        self.branchnick_label.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
628
 
        self.branchnick_label.set_alignment(0.0, 0.5)
629
537
        self.branchnick_label.set_selectable(True)
630
 
        self.table.attach(self.branchnick_label, 1, 2, row, row+1, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
538
        align.add(self.branchnick_label)
 
539
        self.table.attach(align, 1, 2, 3, 4, gtk.EXPAND | gtk.FILL, gtk.FILL)
631
540
        self.branchnick_label.show()
 
541
        align.show()
632
542
 
633
 
        row += 1
 
543
        align = gtk.Alignment(1.0, 0.5)
634
544
        label = gtk.Label()
635
 
        label.set_alignment(1.0, 0.5)
636
545
        label.set_markup("<b>Timestamp:</b>")
637
 
        self.table.attach(label, 0, 1, row, row+1, gtk.FILL, gtk.FILL)
 
546
        align.add(label)
 
547
        self.table.attach(align, 0, 1, 4, 5, gtk.FILL, gtk.FILL)
 
548
        align.show()
638
549
        label.show()
639
550
 
 
551
        align = gtk.Alignment(0.0, 0.5)
640
552
        self.timestamp = gtk.Label()
641
 
        self.timestamp.set_ellipsize(pango.ELLIPSIZE_END)
642
 
        self.timestamp.set_alignment(0.0, 0.5)
643
553
        self.timestamp.set_selectable(True)
644
 
        self.table.attach(self.timestamp, 1, 2, row, row+1, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
554
        align.add(self.timestamp)
 
555
        self.table.attach(align, 1, 2, 4, 5, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
556
        align.show()
645
557
        self.timestamp.show()
646
558
 
647
 
        row += 1
 
559
        align = gtk.Alignment(1.0, 0.5)
648
560
        self.tags_label = gtk.Label()
649
 
        self.tags_label.set_alignment(1.0, 0.5)
650
561
        self.tags_label.set_markup("<b>Tags:</b>")
651
 
        self.table.attach(self.tags_label, 0, 1, row, row+1, gtk.FILL, gtk.FILL)
 
562
        align.add(self.tags_label)
 
563
        align.show()
 
564
        self.table.attach(align, 0, 1, 5, 6, gtk.FILL, gtk.FILL)
652
565
        self.tags_label.show()
653
566
 
 
567
        align = gtk.Alignment(0.0, 0.5)
654
568
        self.tags_list = gtk.Label()
655
 
        self.tags_list.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
656
 
        self.tags_list.set_alignment(0.0, 0.5)
657
 
        self.table.attach(self.tags_list, 1, 2, row, row+1, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
569
        align.add(self.tags_list)
 
570
        self.table.attach(align, 1, 2, 5, 6, gtk.EXPAND | gtk.FILL, gtk.FILL)
 
571
        align.show()
658
572
        self.tags_list.show()
659
573
 
660
574
        self.connect('notify::revision', self._add_tags)
715
629
        return window
716
630
 
717
631
    def _create_bugs(self):
718
 
        self.bugs_page = BugsTab()
719
 
        self.connect_after('notify::revision', self._update_bugs) 
720
 
        self.append_page(self.bugs_page, tab_label=gtk.Label('Bugs'))
 
632
        self.bugs_table = BugsTab()
 
633
        self.append_page(self.bugs_table, tab_label=gtk.Label('Bugs'))
721
634
 
722
635
    def _create_file_info_view(self):
723
636
        self.file_info_box = gtk.VBox(False, 6)