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@57: Copyright (c) 2010 Chris Cannam Chris@57: Copyright (c) 2010 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: */ jtkorhonen@0: jtkorhonen@0: #include "hgexpwidget.h" jtkorhonen@0: #include "common.h" Chris@43: #include "logparser.h" Chris@43: #include "changeset.h" Chris@43: #include "changesetitem.h" Chris@44: #include "grapher.h" cannam@45: #include "panner.h" cannam@45: #include "panned.h" Chris@88: #include "filestatuswidget.h" Chris@44: Chris@50: #include Chris@50: #include Chris@50: #include Chris@50: Chris@44: #include jtkorhonen@0: Chris@88: HgExpWidget::HgExpWidget(QWidget *parent, QString remoteRepo, Chris@88: QString workFolderPath, Chris@88: unsigned char viewFileTypesBits) : Chris@88: QTabWidget(parent) jtkorhonen@0: { Chris@91: // Work page Chris@88: fileStatusWidget = new FileStatusWidget; Chris@89: fileStatusWidget->setLocalPath(workFolderPath); Chris@89: fileStatusWidget->setRemoteURL(remoteRepo); Chris@89: addTab(fileStatusWidget, tr("My work")); Chris@88: Chris@43: // History graph page cannam@45: historyGraphPageWidget = new QWidget; cannam@45: Panned *panned = new Panned; cannam@45: Panner *panner = new Panner; cannam@45: historyGraphWidget = panned; cannam@45: historyGraphPanner = panner; cannam@45: QGridLayout *layout = new QGridLayout; cannam@45: layout->addWidget(historyGraphWidget, 0, 0); cannam@45: layout->addWidget(historyGraphPanner, 0, 1); cannam@45: panner->setMaximumWidth(80); cannam@45: panner->connectToPanned(panned); cannam@45: historyGraphPageWidget->setLayout(layout); Chris@58: addTab(historyGraphPageWidget, tr("History")); jtkorhonen@32: } jtkorhonen@32: Chris@90: bool HgExpWidget::canCommit() const Chris@90: { Chris@90: return fileStatusWidget->haveChangesToCommit(); Chris@90: } jtkorhonen@0: jtkorhonen@0: void HgExpWidget::updateWorkFolderFileList(QString fileList) jtkorhonen@0: { Chris@86: statParser = StatParser(fileList); Chris@89: fileStatusWidget->setStatParser(statParser); jtkorhonen@0: } jtkorhonen@0: jtkorhonen@0: void HgExpWidget::updateLocalRepoHgLogList(QString hgLogList) jtkorhonen@0: { Chris@43: //!!! cannam@45: Panned *panned = static_cast(historyGraphWidget); cannam@45: Panner *panner = static_cast(historyGraphPanner); Chris@43: QGraphicsScene *scene = new QGraphicsScene(); Chris@43: Changesets csets = parseChangeSets(hgLogList); Chris@44: if (csets.empty()) return; Chris@53: Grapher g(scene); Chris@44: try { Chris@53: g.layout(csets); Chris@44: } catch (std::string s) { Chris@44: std::cerr << "Internal error: Layout failed: " << s << std::endl; Chris@44: } Chris@87: QGraphicsScene *oldScene = panned->scene(); cannam@45: panned->setScene(scene); cannam@45: panner->setScene(scene); Chris@87: if (oldScene) delete oldScene; Chris@53: ChangesetItem *tipItem = g.getItemFor(csets[0]); Chris@53: if (tipItem) tipItem->ensureVisible(); jtkorhonen@0: } jtkorhonen@0: Chris@43: Changesets HgExpWidget::parseChangeSets(QString changeSetsStr) Chris@43: { Chris@43: Changesets csets; Chris@43: LogList log = LogParser(changeSetsStr).parse(); Chris@43: foreach (LogEntry e, log) { Chris@43: Changeset *cs = new Changeset(); Chris@43: foreach (QString key, e.keys()) { Chris@44: if (key == "parents") { Chris@44: QStringList parents = e.value(key).split Chris@44: (" ", QString::SkipEmptyParts); Chris@44: cs->setParents(parents); Chris@52: } else if (key == "timestamp") { Chris@52: cs->setTimestamp(e.value(key).split(" ")[0].toULongLong()); Chris@44: } else { Chris@44: cs->setProperty(key.toLocal8Bit().data(), e.value(key)); Chris@44: } Chris@43: } Chris@43: csets.push_back(cs); Chris@43: } Chris@44: for (int i = 0; i+1 < csets.size(); ++i) { Chris@44: Changeset *cs = csets[i]; Chris@44: if (cs->parents().empty()) { Chris@44: QStringList list; Chris@44: list.push_back(csets[i+1]->id()); Chris@44: cs->setParents(list); Chris@44: } Chris@44: } Chris@43: return csets; jtkorhonen@0: } jtkorhonen@0: jtkorhonen@0: void HgExpWidget::setWorkFolderAndRepoNames(QString workFolderPath, QString remoteRepoPath) jtkorhonen@0: { Chris@89: fileStatusWidget->setLocalPath(workFolderPath); Chris@89: fileStatusWidget->setRemoteURL(remoteRepoPath); jtkorhonen@0: }