Chris@57
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@57
|
2
|
Chris@57
|
3 /*
|
Chris@57
|
4 EasyMercurial
|
Chris@57
|
5
|
Chris@57
|
6 Based on HgExplorer by Jari Korhonen
|
Chris@57
|
7 Copyright (c) 2010 Jari Korhonen
|
Chris@57
|
8 Copyright (c) 2010 Chris Cannam
|
Chris@57
|
9 Copyright (c) 2010 Queen Mary, University of London
|
Chris@57
|
10
|
Chris@57
|
11 This program is free software; you can redistribute it and/or
|
Chris@57
|
12 modify it under the terms of the GNU General Public License as
|
Chris@57
|
13 published by the Free Software Foundation; either version 2 of the
|
Chris@57
|
14 License, or (at your option) any later version. See the file
|
Chris@57
|
15 COPYING included with this distribution for more information.
|
Chris@57
|
16 */
|
Chris@57
|
17
|
Chris@43
|
18 #include "changeset.h"
|
Chris@125
|
19 #include "common.h"
|
Chris@106
|
20
|
Chris@106
|
21 #include <QVariant>
|
Chris@106
|
22
|
Chris@106
|
23 Changeset::Changeset(const LogEntry &e)
|
Chris@106
|
24 {
|
Chris@106
|
25 foreach (QString key, e.keys()) {
|
Chris@106
|
26 if (key == "parents") {
|
Chris@106
|
27 QStringList parents = e.value(key).split
|
Chris@106
|
28 (" ", QString::SkipEmptyParts);
|
Chris@106
|
29 setParents(parents);
|
Chris@128
|
30 } else if (key == "tag") {
|
Chris@128
|
31 QStringList tags = e.value(key).split
|
Chris@128
|
32 (" ", QString::SkipEmptyParts);
|
Chris@128
|
33 setTags(tags);
|
Chris@106
|
34 } else if (key == "timestamp") {
|
Chris@106
|
35 setTimestamp(e.value(key).split(" ")[0].toULongLong());
|
Chris@108
|
36 } else if (key == "changeset") {
|
Chris@108
|
37 setId(e.value(key));
|
Chris@106
|
38 } else {
|
Chris@106
|
39 setProperty(key.toLocal8Bit().data(), e.value(key));
|
Chris@106
|
40 }
|
Chris@106
|
41 }
|
Chris@106
|
42 }
|
Chris@106
|
43
|
Chris@125
|
44 QString Changeset::getLogTemplate()
|
Chris@125
|
45 {
|
Chris@128
|
46 return "id: {rev}:{node|short}\\nauthor: {author}\\nbranch: {branches}\\ntag: {tags}\\ndatetime: {date|isodate}\\ntimestamp: {date|hgdate}\\nage: {date|age}\\nparents: {parents}\\ncomment: {desc|json}\\n\\n";
|
Chris@125
|
47 }
|
Chris@125
|
48
|
Chris@125
|
49 QString Changeset::formatHtml()
|
Chris@125
|
50 {
|
Chris@125
|
51 QString description;
|
Chris@125
|
52 QString rowTemplate = "<tr><td><b>%1</b></td><td>%2</td></tr>";
|
Chris@125
|
53
|
Chris@125
|
54 description = "<qt><table border=0>";
|
Chris@125
|
55
|
Chris@125
|
56 QString c = comment().trimmed();
|
Chris@125
|
57 c = c.replace(QRegExp("^\""), "");
|
Chris@125
|
58 c = c.replace(QRegExp("\"$"), "");
|
Chris@125
|
59 c = c.replace("\\\"", "\"");
|
Chris@125
|
60 c = xmlEncode(c);
|
Chris@125
|
61 c = c.replace("\\n", "<br>");
|
Chris@125
|
62
|
Chris@125
|
63 QStringList propNames, propTexts;
|
Chris@125
|
64
|
Chris@125
|
65 propNames << "id"
|
Chris@128
|
66 << "author"
|
Chris@125
|
67 << "datetime"
|
Chris@125
|
68 << "branch"
|
Chris@128
|
69 << "tags"
|
Chris@125
|
70 << "comment";
|
Chris@125
|
71
|
Chris@125
|
72 propTexts << QObject::tr("Identifier")
|
Chris@125
|
73 << QObject::tr("Author")
|
Chris@125
|
74 << QObject::tr("Date")
|
Chris@125
|
75 << QObject::tr("Branch")
|
Chris@125
|
76 << QObject::tr("Tag")
|
Chris@125
|
77 << QObject::tr("Comment");
|
Chris@125
|
78
|
Chris@125
|
79 for (int i = 0; i < propNames.size(); ++i) {
|
Chris@125
|
80 QString prop = propNames[i];
|
Chris@125
|
81 QString value;
|
Chris@128
|
82 if (prop == "comment") {
|
Chris@128
|
83 value = c;
|
Chris@128
|
84 } else if (prop == "tags") {
|
Chris@128
|
85 value = tags().join(" ");
|
Chris@128
|
86 } else {
|
Chris@125
|
87 value = xmlEncode(property(prop.toLocal8Bit().data()).toString());
|
Chris@125
|
88 }
|
Chris@125
|
89 if (value != "") {
|
Chris@125
|
90 description += rowTemplate
|
Chris@125
|
91 .arg(xmlEncode(propTexts[i]))
|
Chris@125
|
92 .arg(value);
|
Chris@125
|
93 }
|
Chris@125
|
94 }
|
Chris@125
|
95
|
Chris@125
|
96 description += "</table></qt>";
|
Chris@125
|
97
|
Chris@125
|
98 return description;
|
Chris@125
|
99 }
|