/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 branchview/treemodel.py

  • Committer: Jelmer Vernooij
  • Date: 2011-04-10 18:44:39 UTC
  • mto: This revision was merged to the branch mainline in revision 730.
  • Revision ID: jelmer@samba.org-20110410184439-g7hqaacexqtviq13
Move i18n support to a separate file, so gettext files aren't loaded unless bzr-gtk is used.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: UTF-8 -*-
 
2
"""Tree model.
 
3
 
 
4
"""
 
5
 
 
6
__copyright__ = "Copyright � 2005 Canonical Ltd."
 
7
__author__    = "Gary van der Merwe <garyvdm@gmail.com>"
 
8
 
 
9
 
 
10
import gtk
 
11
import gobject
 
12
from xml.sax.saxutils import escape
 
13
 
 
14
from bzrlib.config import parse_username
 
15
from bzrlib.revision import NULL_REVISION
 
16
 
 
17
from time import (
 
18
    strftime,
 
19
    localtime,
 
20
    )
 
21
 
 
22
REVID = 0
 
23
NODE = 1
 
24
LINES = 2
 
25
LAST_LINES = 3
 
26
REVNO = 4
 
27
SUMMARY = 5
 
28
MESSAGE = 6
 
29
COMMITTER = 7
 
30
TIMESTAMP = 8
 
31
REVISION = 9
 
32
PARENTS = 10
 
33
CHILDREN = 11
 
34
TAGS = 12
 
35
AUTHORS = 13
 
36
 
 
37
class TreeModel(gtk.GenericTreeModel):
 
38
 
 
39
    def __init__ (self, branch, line_graph_data):
 
40
        gtk.GenericTreeModel.__init__(self)
 
41
        self.revisions = {}
 
42
        self.branch = branch
 
43
        self.repository = branch.repository
 
44
        self.line_graph_data = line_graph_data
 
45
 
 
46
        if self.branch.supports_tags():
 
47
            self.tags = self.branch.tags.get_reverse_tag_dict()
 
48
        else:
 
49
            self.tags = {}
 
50
 
 
51
    def add_tag(self, tag, revid):
 
52
        self.branch.tags.set_tag(tag, revid)
 
53
        try:
 
54
            self.tags[revid].append(tag)
 
55
        except KeyError:
 
56
            self.tags[revid] = [tag]
 
57
 
 
58
    def on_get_flags(self):
 
59
        return gtk.TREE_MODEL_LIST_ONLY
 
60
 
 
61
    def on_get_n_columns(self):
 
62
        return 14
 
63
 
 
64
    def on_get_column_type(self, index):
 
65
        if index == REVID: return gobject.TYPE_STRING
 
66
        if index == NODE: return gobject.TYPE_PYOBJECT
 
67
        if index == LINES: return gobject.TYPE_PYOBJECT
 
68
        if index == LAST_LINES: return gobject.TYPE_PYOBJECT
 
69
        if index == REVNO: return gobject.TYPE_STRING
 
70
        if index == SUMMARY: return gobject.TYPE_STRING
 
71
        if index == MESSAGE: return gobject.TYPE_STRING
 
72
        if index == COMMITTER: return gobject.TYPE_STRING
 
73
        if index == TIMESTAMP: return gobject.TYPE_STRING
 
74
        if index == REVISION: return gobject.TYPE_PYOBJECT
 
75
        if index == PARENTS: return gobject.TYPE_PYOBJECT
 
76
        if index == CHILDREN: return gobject.TYPE_PYOBJECT
 
77
        if index == TAGS: return gobject.TYPE_PYOBJECT
 
78
        if index == AUTHORS: return gobject.TYPE_STRING
 
79
 
 
80
    def on_get_iter(self, path):
 
81
        return path[0]
 
82
 
 
83
    def on_get_path(self, rowref):
 
84
        return rowref
 
85
 
 
86
    def on_get_value(self, rowref, column):
 
87
        if len(self.line_graph_data) > 0:
 
88
            (revid, node, lines, parents,
 
89
             children, revno_sequence) = self.line_graph_data[rowref]
 
90
        else:
 
91
            (revid, node, lines, parents,
 
92
             children, revno_sequence) = (None, (0, 0), (), (),
 
93
                                          (), ())
 
94
        if column == REVID: return revid
 
95
        if column == NODE: return node
 
96
        if column == LINES: return lines
 
97
        if column == PARENTS: return parents
 
98
        if column == CHILDREN: return children
 
99
        if column == LAST_LINES:
 
100
            if rowref>0:
 
101
                return self.line_graph_data[rowref-1][2]
 
102
            return []
 
103
        if column == REVNO: return ".".join(["%d" % (revno)
 
104
                                      for revno in revno_sequence])
 
105
 
 
106
        if column == TAGS: return self.tags.get(revid, [])
 
107
 
 
108
        if not revid or revid == NULL_REVISION:
 
109
            return None
 
110
        if revid not in self.revisions:
 
111
            revision = self.repository.get_revisions([revid])[0]
 
112
            self.revisions[revid] = revision
 
113
        else:
 
114
            revision = self.revisions[revid]
 
115
 
 
116
        if column == REVISION: return revision
 
117
        if column == SUMMARY: return escape(revision.get_summary())
 
118
        if column == MESSAGE: return escape(revision.message)
 
119
        if column == COMMITTER: return parse_username(revision.committer)[0]
 
120
        if column == TIMESTAMP:
 
121
            return strftime("%Y-%m-%d %H:%M", localtime(revision.timestamp))
 
122
        if column == AUTHORS:
 
123
            return ", ".join([
 
124
                parse_username(author)[0] for author in revision.get_apparent_authors()])
 
125
 
 
126
    def on_iter_next(self, rowref):
 
127
        if rowref < len(self.line_graph_data) - 1:
 
128
            return rowref+1
 
129
        return None
 
130
 
 
131
    def on_iter_children(self, parent):
 
132
        if parent is None: return 0
 
133
        return None
 
134
 
 
135
    def on_iter_has_child(self, rowref):
 
136
        return False
 
137
 
 
138
    def on_iter_n_children(self, rowref):
 
139
        if rowref is None: return len(self.line_graph_data)
 
140
        return 0
 
141
 
 
142
    def on_iter_nth_child(self, parent, n):
 
143
        if parent is None: return n
 
144
        return None
 
145
 
 
146
    def on_iter_parent(self, child):
 
147
        return None