Chris@88: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@88: Chris@88: /* Chris@88: EasyMercurial Chris@88: Chris@88: Based on HgExplorer by Jari Korhonen Chris@88: Copyright (c) 2010 Jari Korhonen Chris@88: Copyright (c) 2010 Chris Cannam Chris@88: Copyright (c) 2010 Queen Mary, University of London Chris@88: Chris@88: This program is free software; you can redistribute it and/or Chris@88: modify it under the terms of the GNU General Public License as Chris@88: published by the Free Software Foundation; either version 2 of the Chris@88: License, or (at your option) any later version. See the file Chris@88: COPYING included with this distribution for more information. Chris@88: */ Chris@88: Chris@88: #include "filestatuswidget.h" Chris@88: Chris@88: #include Chris@88: #include Chris@88: #include Chris@93: #include Chris@93: #include Chris@93: #include Chris@93: Chris@93: #include "debug.h" Chris@88: Chris@88: FileStatusWidget::FileStatusWidget(QWidget *parent) : Chris@93: QWidget(parent), Chris@93: m_dateReference(0) Chris@88: { Chris@88: QGridLayout *layout = new QGridLayout; Chris@88: setLayout(layout); Chris@88: Chris@88: int row = 0; Chris@88: Chris@88: layout->addWidget(new QLabel(tr("Local:")), row, 0); Chris@88: m_localPathLabel = new QLabel; Chris@89: QFont f(m_localPathLabel->font()); Chris@89: f.setBold(true); Chris@89: m_localPathLabel->setFont(f); Chris@88: layout->addWidget(m_localPathLabel, row, 1); Chris@88: Chris@88: ++row; Chris@88: layout->addWidget(new QLabel(tr("Remote:")), row, 0); Chris@88: m_remoteURLLabel = new QLabel; Chris@88: layout->addWidget(m_remoteURLLabel, row, 1); Chris@88: Chris@89: layout->setColumnStretch(1, 20); Chris@88: Chris@89: QStringList labels; Chris@89: labels << tr("Modified files:") Chris@89: << tr("Added files:") Chris@89: << tr("Removed files:") Chris@89: << tr("New untracked files:") Chris@89: << tr("Missing files:"); Chris@89: Chris@89: QList lists; Chris@89: lists << &m_modifiedList Chris@89: << &m_addedList Chris@89: << &m_removedList Chris@89: << &m_unknownList Chris@89: << &m_missingList; Chris@89: Chris@89: for (int i = 0; i < labels.size(); ++i) { Chris@89: Chris@89: QWidget *box = new QWidget; Chris@89: QGridLayout *boxlayout = new QGridLayout; Chris@89: box->setLayout(boxlayout); Chris@89: Chris@89: boxlayout->addWidget(new QLabel(labels[i]), 0, 0); Chris@89: Chris@89: *lists[i] = new QListWidget; Chris@89: (*lists[i])->setSelectionMode(QListWidget::ExtendedSelection); Chris@89: boxlayout->addWidget(*lists[i], 1, 0); Chris@89: Chris@89: layout->addWidget(box, ++row, 0, 1, 2); Chris@89: box->hide(); Chris@89: } Chris@89: Chris@89: layout->setRowStretch(++row, 20); Chris@88: } Chris@88: Chris@93: FileStatusWidget::~FileStatusWidget() Chris@93: { Chris@93: delete m_dateReference; Chris@93: } Chris@93: Chris@88: void Chris@88: FileStatusWidget::setLocalPath(QString p) Chris@88: { Chris@88: m_localPath = p; Chris@88: m_localPathLabel->setText(p); Chris@93: delete m_dateReference; Chris@93: m_dateReference = new QFileInfo(p + "/.hg/dirstate"); Chris@93: if (!m_dateReference->exists() || Chris@93: !m_dateReference->isFile() || Chris@93: !m_dateReference->isReadable()) { Chris@93: DEBUG << "FileStatusWidget::setLocalPath: date reference file " Chris@93: << m_dateReference->absoluteFilePath() Chris@93: << " does not exist, is not a file, or cannot be read" Chris@93: << endl; Chris@93: delete m_dateReference; Chris@93: m_dateReference = 0; Chris@93: } Chris@88: } Chris@88: Chris@88: void Chris@88: FileStatusWidget::setRemoteURL(QString r) Chris@88: { Chris@88: m_remoteURL = r; Chris@88: m_remoteURLLabel->setText(r); Chris@88: } Chris@88: Chris@88: void Chris@92: FileStatusWidget::setFileStates(FileStates p) Chris@88: { Chris@92: m_fileStates = p; Chris@88: updateWidgets(); Chris@88: } Chris@88: Chris@88: void Chris@93: FileStatusWidget::highlightFile(QListWidget *w, int i) Chris@93: { Chris@93: DEBUG << "FileStatusWidget: highlighting file at " << i << endl; Chris@93: QListWidgetItem *item = w->item(i); Chris@93: item->setForeground(Qt::red); Chris@93: //!!! and a nice gold star Chris@93: } Chris@93: Chris@93: void Chris@88: FileStatusWidget::updateWidgets() Chris@88: { Chris@92: FileStates &sp = m_fileStates; Chris@89: QMap listmap; Chris@89: listmap[&sp.modified] = m_modifiedList; Chris@89: listmap[&sp.added] = m_addedList; Chris@89: listmap[&sp.removed] = m_removedList; Chris@89: listmap[&sp.missing] = m_missingList; Chris@89: listmap[&sp.unknown] = m_unknownList; Chris@88: Chris@89: foreach (QStringList *sl, listmap.keys()) { Chris@89: listmap[sl]->clear(); Chris@89: listmap[sl]->addItems(*sl); Chris@89: listmap[sl]->parentWidget()->setVisible(!sl->empty()); Chris@89: } Chris@93: Chris@93: if (m_dateReference) { Chris@93: // Highlight untracked files that have appeared since the Chris@93: // last interaction with the repo Chris@93: QDateTime refTime = m_dateReference->lastModified(); Chris@93: DEBUG << "reference time: " << refTime << endl; Chris@93: for (int i = 0; i < m_unknownList->count(); ++i) { Chris@93: QString fn(m_localPath + "/" + m_unknownList->item(i)->text()); Chris@93: DEBUG << "comparing with " << fn << endl; Chris@93: QFileInfo fi(fn); Chris@93: if (fi.exists() && fi.lastModified() > refTime) { Chris@93: DEBUG << "file " << fn << " is newer (" << fi.lastModified() Chris@93: << ") than reference" << endl; Chris@93: highlightFile(m_unknownList, i); Chris@93: } Chris@93: } Chris@93: } Chris@88: } Chris@88: