7
7
__author__ = "Gary van der Merwe <garyvdm@gmail.com>"
10
from gi.repository import Gtk
11
from gi.repository import GObject
14
12
from xml.sax.saxutils import escape
14
from bzrlib.config import parse_username
15
15
from bzrlib.revision import NULL_REVISION
17
from time import (strftime, localtime)
33
class TreeModel(gtk.GenericTreeModel):
37
class TreeModel(Gtk.TreeStore):
36
39
def __init__ (self, branch, line_graph_data):
37
gtk.GenericTreeModel.__init__(self)
40
Gtk.TreeStore.__init__(self)
38
41
self.revisions = {}
40
43
self.repository = branch.repository
41
44
self.line_graph_data = line_graph_data
43
if self.branch.supports_tags():
46
if self.branch.supports_tags():
44
47
self.tags = self.branch.tags.get_reverse_tag_dict()
53
56
self.tags[revid] = [tag]
55
58
def on_get_flags(self):
56
return gtk.TREE_MODEL_LIST_ONLY
59
return Gtk.TREE_MODEL_LIST_ONLY
58
61
def on_get_n_columns(self):
61
64
def on_get_column_type(self, index):
62
if index == REVID: return gobject.TYPE_STRING
63
if index == NODE: return gobject.TYPE_PYOBJECT
64
if index == LINES: return gobject.TYPE_PYOBJECT
65
if index == LAST_LINES: return gobject.TYPE_PYOBJECT
66
if index == REVNO: return gobject.TYPE_STRING
67
if index == SUMMARY: return gobject.TYPE_STRING
68
if index == MESSAGE: return gobject.TYPE_STRING
69
if index == COMMITTER: return gobject.TYPE_STRING
70
if index == TIMESTAMP: return gobject.TYPE_STRING
71
if index == REVISION: return gobject.TYPE_PYOBJECT
72
if index == PARENTS: return gobject.TYPE_PYOBJECT
73
if index == CHILDREN: return gobject.TYPE_PYOBJECT
74
if index == TAGS: return gobject.TYPE_PYOBJECT
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
76
80
def on_get_iter(self, path):
81
# XXX sinzui 2011-08-12: maybe path.get_indices()[0]?
79
84
def on_get_path(self, rowref):
82
87
def on_get_value(self, rowref, column):
83
88
if len(self.line_graph_data) > 0:
84
89
(revid, node, lines, parents,
108
113
self.revisions[revid] = revision
110
115
revision = self.revisions[revid]
112
117
if column == REVISION: return revision
113
118
if column == SUMMARY: return escape(revision.get_summary())
114
119
if column == MESSAGE: return escape(revision.message)
115
if column == COMMITTER: return re.sub('<.*@.*>', '',
116
revision.committer).strip(' ')
117
if column == TIMESTAMP:
120
if column == COMMITTER: return parse_username(revision.committer)[0]
121
if column == TIMESTAMP:
118
122
return strftime("%Y-%m-%d %H:%M", localtime(revision.timestamp))
123
if column == AUTHORS:
125
parse_username(author)[0] for author in revision.get_apparent_authors()])
120
127
def on_iter_next(self, rowref):
121
128
if rowref < len(self.line_graph_data) - 1:
125
132
def on_iter_children(self, parent):
126
133
if parent is None: return 0
129
136
def on_iter_has_child(self, rowref):
132
139
def on_iter_n_children(self, rowref):
133
140
if rowref is None: return len(self.line_graph_data)
136
143
def on_iter_nth_child(self, parent, n):
137
144
if parent is None: return n
140
147
def on_iter_parent(self, child):