changeset 93:dfb7a274b90f

* Highlight untracked files that are newer than last repo interaction
author Chris Cannam
date Wed, 24 Nov 2010 13:50:33 +0000
parents 06f4fffd5287
children 44ed7766d55a
files filestatuswidget.cpp filestatuswidget.h hgrunner.cpp
diffstat 3 files changed, 56 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/filestatuswidget.cpp	Wed Nov 24 13:23:30 2010 +0000
+++ b/filestatuswidget.cpp	Wed Nov 24 13:50:33 2010 +0000
@@ -20,9 +20,15 @@
 #include <QLabel>
 #include <QListWidget>
 #include <QGridLayout>
+#include <QFileInfo>
+#include <QApplication>
+#include <QDateTime>
+
+#include "debug.h"
 
 FileStatusWidget::FileStatusWidget(QWidget *parent) :
-    QWidget(parent)
+    QWidget(parent),
+    m_dateReference(0)
 {
     QGridLayout *layout = new QGridLayout;
     setLayout(layout);
@@ -76,11 +82,28 @@
     layout->setRowStretch(++row, 20);
 }
 
+FileStatusWidget::~FileStatusWidget()
+{
+    delete m_dateReference;
+}
+
 void
 FileStatusWidget::setLocalPath(QString p)
 {
     m_localPath = p;
     m_localPathLabel->setText(p);
+    delete m_dateReference;
+    m_dateReference = new QFileInfo(p + "/.hg/dirstate");
+    if (!m_dateReference->exists() ||
+        !m_dateReference->isFile() ||
+        !m_dateReference->isReadable()) {
+        DEBUG << "FileStatusWidget::setLocalPath: date reference file "
+                << m_dateReference->absoluteFilePath()
+                << " does not exist, is not a file, or cannot be read"
+                << endl;
+        delete m_dateReference;
+        m_dateReference = 0;
+    }
 }
 
 void
@@ -98,6 +121,15 @@
 }
 
 void
+FileStatusWidget::highlightFile(QListWidget *w, int i)
+{
+    DEBUG << "FileStatusWidget: highlighting file at " << i << endl;
+    QListWidgetItem *item = w->item(i);
+    item->setForeground(Qt::red);
+    //!!! and a nice gold star
+}
+
+void
 FileStatusWidget::updateWidgets()
 {
     FileStates &sp = m_fileStates;
@@ -113,5 +145,22 @@
         listmap[sl]->addItems(*sl);
         listmap[sl]->parentWidget()->setVisible(!sl->empty());
     }
+
+    if (m_dateReference) {
+        // Highlight untracked files that have appeared since the
+        // last interaction with the repo
+        QDateTime refTime = m_dateReference->lastModified();
+        DEBUG << "reference time: " << refTime << endl;
+        for (int i = 0; i < m_unknownList->count(); ++i) {
+            QString fn(m_localPath + "/" + m_unknownList->item(i)->text());
+            DEBUG << "comparing with " << fn << endl;
+            QFileInfo fi(fn);
+            if (fi.exists() && fi.lastModified() > refTime) {
+                DEBUG << "file " << fn << " is newer (" << fi.lastModified()
+                        << ") than reference" << endl;
+                highlightFile(m_unknownList, i);
+            }
+        }
+    }
 }
 
--- a/filestatuswidget.h	Wed Nov 24 13:23:30 2010 +0000
+++ b/filestatuswidget.h	Wed Nov 24 13:50:33 2010 +0000
@@ -24,6 +24,7 @@
 
 class QLabel;
 class QListWidget;
+class QFileInfo;
 
 class FileStatusWidget : public QWidget
 {
@@ -31,6 +32,7 @@
 
 public:
     FileStatusWidget(QWidget *parent = 0);
+    ~FileStatusWidget();
 
     QString localPath() const { return m_localPath; }
     void setLocalPath(QString p);
@@ -62,7 +64,10 @@
     QListWidget *m_removedList;
     QListWidget *m_missingList;
 
+    QFileInfo *m_dateReference;
+
     void updateWidgets();
+    void highlightFile(QListWidget *, int);
 };
 
 #endif
--- a/hgrunner.cpp	Wed Nov 24 13:23:30 2010 +0000
+++ b/hgrunner.cpp	Wed Nov 24 13:50:33 2010 +0000
@@ -170,7 +170,7 @@
 
 void HgRunner::checkPrompts(QString chunk)
 {
-    DEBUG << "checkPrompts: " << chunk << endl;
+    //DEBUG << "checkPrompts: " << chunk << endl;
 
     QString text = chunk.trimmed();
     QString lower = text.toLower();