Chris@57: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@57: Chris@57: /* Chris@57: EasyMercurial Chris@57: Chris@57: Based on HgExplorer by Jari Korhonen Chris@57: Copyright (c) 2010 Jari Korhonen Chris@644: Copyright (c) 2013 Chris Cannam Chris@644: Copyright (c) 2013 Queen Mary, University of London Chris@57: Chris@57: This program is free software; you can redistribute it and/or Chris@57: modify it under the terms of the GNU General Public License as Chris@57: published by the Free Software Foundation; either version 2 of the Chris@57: License, or (at your option) any later version. See the file Chris@57: COPYING included with this distribution for more information. Chris@57: */ Chris@57: Chris@43: #include "changeset.h" Chris@125: #include "common.h" Chris@419: #include "debug.h" Chris@106: Chris@106: #include Chris@106: Chris@510: Changeset::Changeset(const LogEntry &e) : Chris@510: m_closed(false) Chris@106: { Chris@106: foreach (QString key, e.keys()) { Chris@106: if (key == "parents") { Chris@106: QStringList parents = e.value(key).split Chris@106: (" ", QString::SkipEmptyParts); Chris@106: setParents(parents); Chris@128: } else if (key == "tag") { Chris@128: QStringList tags = e.value(key).split Chris@128: (" ", QString::SkipEmptyParts); Chris@128: setTags(tags); Chris@520: } else if (key == "bookmarks") { Chris@520: QStringList bmarks = e.value(key).split Chris@520: (" ", QString::SkipEmptyParts); Chris@520: setBookmarks(bmarks); Chris@106: } else if (key == "timestamp") { Chris@106: setTimestamp(e.value(key).split(" ")[0].toULongLong()); Chris@108: } else if (key == "changeset") { Chris@108: setId(e.value(key)); Chris@106: } else { Chris@106: setProperty(key.toLocal8Bit().data(), e.value(key)); Chris@106: } Chris@106: } Chris@106: } Chris@106: Chris@125: QString Changeset::getLogTemplate() Chris@125: { Chris@520: return "id: {rev}:{node|short}\\nauthor: {author}\\nbranch: {branches}\\ntag: {tags}\\nbookmarks: {bookmarks}\\ndatetime: {date|isodate}\\ntimestamp: {date|hgdate}\\nage: {date|age}\\nparents: {parents}\\ncomment: {desc|json}\\n\\n"; Chris@125: } Chris@125: Chris@125: QString Changeset::formatHtml() Chris@125: { Chris@125: QString description; Chris@153: QString rowTemplate = "%1 %2"; Chris@125: Chris@125: description = ""; Chris@125: Chris@419: // DEBUG << "comment is " << comment() << endl; Chris@419: Chris@125: QString c = comment().trimmed(); Chris@125: c = c.replace(QRegExp("^\""), ""); Chris@125: c = c.replace(QRegExp("\"$"), ""); Chris@125: c = c.replace("\\\"", "\""); Chris@125: c = xmlEncode(c); Chris@125: c = c.replace("\\n", "
"); Chris@125: Chris@125: QStringList propNames, propTexts; Chris@125: Chris@125: propNames << "id" Chris@128: << "author" Chris@125: << "datetime" Chris@125: << "branch" Chris@128: << "tags" Chris@520: << "bookmarks" Chris@125: << "comment"; Chris@125: Chris@165: propTexts << QObject::tr("Identifier:") Chris@165: << QObject::tr("Author:") Chris@165: << QObject::tr("Date:") Chris@165: << QObject::tr("Branch:") Chris@521: << QObject::tr("Tags:") Chris@521: << QObject::tr("Bookmarks:") Chris@165: << QObject::tr("Comment:"); Chris@125: Chris@125: for (int i = 0; i < propNames.size(); ++i) { Chris@125: QString prop = propNames[i]; Chris@125: QString value; Chris@165: if (prop == "id") { Chris@165: value = hashOf(id()); Chris@165: } else if (prop == "comment") { Chris@128: value = c; Chris@128: } else if (prop == "tags") { Chris@128: value = tags().join(" "); Chris@520: } else if (prop == "bookmarks") { Chris@520: value = bookmarks().join(" "); Chris@128: } else { Chris@125: value = xmlEncode(property(prop.toLocal8Bit().data()).toString()); Chris@125: } Chris@125: if (value != "") { Chris@125: description += rowTemplate Chris@125: .arg(xmlEncode(propTexts[i])) Chris@125: .arg(value); Chris@125: } Chris@125: } Chris@125: Chris@125: description += "
"; Chris@125: Chris@125: return description; Chris@125: }