annotate src/changeset.cpp @ 438:a5696a1f2dc5

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