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@244
|
8 Copyright (c) 2011 Chris Cannam
|
Chris@244
|
9 Copyright (c) 2011 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@419
|
20 #include "debug.h"
|
Chris@106
|
21
|
Chris@106
|
22 #include <QVariant>
|
Chris@106
|
23
|
Chris@510
|
24 Changeset::Changeset(const LogEntry &e) :
|
Chris@510
|
25 m_closed(false)
|
Chris@106
|
26 {
|
Chris@106
|
27 foreach (QString key, e.keys()) {
|
Chris@106
|
28 if (key == "parents") {
|
Chris@106
|
29 QStringList parents = e.value(key).split
|
Chris@106
|
30 (" ", QString::SkipEmptyParts);
|
Chris@106
|
31 setParents(parents);
|
Chris@128
|
32 } else if (key == "tag") {
|
Chris@128
|
33 QStringList tags = e.value(key).split
|
Chris@128
|
34 (" ", QString::SkipEmptyParts);
|
Chris@128
|
35 setTags(tags);
|
Chris@106
|
36 } else if (key == "timestamp") {
|
Chris@106
|
37 setTimestamp(e.value(key).split(" ")[0].toULongLong());
|
Chris@108
|
38 } else if (key == "changeset") {
|
Chris@108
|
39 setId(e.value(key));
|
Chris@106
|
40 } else {
|
Chris@106
|
41 setProperty(key.toLocal8Bit().data(), e.value(key));
|
Chris@106
|
42 }
|
Chris@106
|
43 }
|
Chris@106
|
44 }
|
Chris@106
|
45
|
Chris@125
|
46 QString Changeset::getLogTemplate()
|
Chris@125
|
47 {
|
Chris@128
|
48 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
|
49 }
|
Chris@125
|
50
|
Chris@125
|
51 QString Changeset::formatHtml()
|
Chris@125
|
52 {
|
Chris@125
|
53 QString description;
|
Chris@153
|
54 QString rowTemplate = "<tr><td><b>%1</b> </td><td>%2</td></tr>";
|
Chris@125
|
55
|
Chris@125
|
56 description = "<qt><table border=0>";
|
Chris@125
|
57
|
Chris@419
|
58 // DEBUG << "comment is " << comment() << endl;
|
Chris@419
|
59
|
Chris@125
|
60 QString c = comment().trimmed();
|
Chris@125
|
61 c = c.replace(QRegExp("^\""), "");
|
Chris@125
|
62 c = c.replace(QRegExp("\"$"), "");
|
Chris@125
|
63 c = c.replace("\\\"", "\"");
|
Chris@125
|
64 c = xmlEncode(c);
|
Chris@125
|
65 c = c.replace("\\n", "<br>");
|
Chris@125
|
66
|
Chris@125
|
67 QStringList propNames, propTexts;
|
Chris@125
|
68
|
Chris@125
|
69 propNames << "id"
|
Chris@128
|
70 << "author"
|
Chris@125
|
71 << "datetime"
|
Chris@125
|
72 << "branch"
|
Chris@128
|
73 << "tags"
|
Chris@125
|
74 << "comment";
|
Chris@125
|
75
|
Chris@165
|
76 propTexts << QObject::tr("Identifier:")
|
Chris@165
|
77 << QObject::tr("Author:")
|
Chris@165
|
78 << QObject::tr("Date:")
|
Chris@165
|
79 << QObject::tr("Branch:")
|
Chris@165
|
80 << QObject::tr("Tag:")
|
Chris@165
|
81 << QObject::tr("Comment:");
|
Chris@125
|
82
|
Chris@125
|
83 for (int i = 0; i < propNames.size(); ++i) {
|
Chris@125
|
84 QString prop = propNames[i];
|
Chris@125
|
85 QString value;
|
Chris@165
|
86 if (prop == "id") {
|
Chris@165
|
87 value = hashOf(id());
|
Chris@165
|
88 } else if (prop == "comment") {
|
Chris@128
|
89 value = c;
|
Chris@128
|
90 } else if (prop == "tags") {
|
Chris@128
|
91 value = tags().join(" ");
|
Chris@128
|
92 } else {
|
Chris@125
|
93 value = xmlEncode(property(prop.toLocal8Bit().data()).toString());
|
Chris@125
|
94 }
|
Chris@125
|
95 if (value != "") {
|
Chris@125
|
96 description += rowTemplate
|
Chris@125
|
97 .arg(xmlEncode(propTexts[i]))
|
Chris@125
|
98 .arg(value);
|
Chris@125
|
99 }
|
Chris@125
|
100 }
|
Chris@125
|
101
|
Chris@125
|
102 description += "</table></qt>";
|
Chris@125
|
103
|
Chris@125
|
104 return description;
|
Chris@125
|
105 }
|