comparison filestatuswidget.cpp @ 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
comparison
equal deleted inserted replaced
92:06f4fffd5287 93:dfb7a274b90f
18 #include "filestatuswidget.h" 18 #include "filestatuswidget.h"
19 19
20 #include <QLabel> 20 #include <QLabel>
21 #include <QListWidget> 21 #include <QListWidget>
22 #include <QGridLayout> 22 #include <QGridLayout>
23 #include <QFileInfo>
24 #include <QApplication>
25 #include <QDateTime>
26
27 #include "debug.h"
23 28
24 FileStatusWidget::FileStatusWidget(QWidget *parent) : 29 FileStatusWidget::FileStatusWidget(QWidget *parent) :
25 QWidget(parent) 30 QWidget(parent),
31 m_dateReference(0)
26 { 32 {
27 QGridLayout *layout = new QGridLayout; 33 QGridLayout *layout = new QGridLayout;
28 setLayout(layout); 34 setLayout(layout);
29 35
30 int row = 0; 36 int row = 0;
74 } 80 }
75 81
76 layout->setRowStretch(++row, 20); 82 layout->setRowStretch(++row, 20);
77 } 83 }
78 84
85 FileStatusWidget::~FileStatusWidget()
86 {
87 delete m_dateReference;
88 }
89
79 void 90 void
80 FileStatusWidget::setLocalPath(QString p) 91 FileStatusWidget::setLocalPath(QString p)
81 { 92 {
82 m_localPath = p; 93 m_localPath = p;
83 m_localPathLabel->setText(p); 94 m_localPathLabel->setText(p);
95 delete m_dateReference;
96 m_dateReference = new QFileInfo(p + "/.hg/dirstate");
97 if (!m_dateReference->exists() ||
98 !m_dateReference->isFile() ||
99 !m_dateReference->isReadable()) {
100 DEBUG << "FileStatusWidget::setLocalPath: date reference file "
101 << m_dateReference->absoluteFilePath()
102 << " does not exist, is not a file, or cannot be read"
103 << endl;
104 delete m_dateReference;
105 m_dateReference = 0;
106 }
84 } 107 }
85 108
86 void 109 void
87 FileStatusWidget::setRemoteURL(QString r) 110 FileStatusWidget::setRemoteURL(QString r)
88 { 111 {
93 void 116 void
94 FileStatusWidget::setFileStates(FileStates p) 117 FileStatusWidget::setFileStates(FileStates p)
95 { 118 {
96 m_fileStates = p; 119 m_fileStates = p;
97 updateWidgets(); 120 updateWidgets();
121 }
122
123 void
124 FileStatusWidget::highlightFile(QListWidget *w, int i)
125 {
126 DEBUG << "FileStatusWidget: highlighting file at " << i << endl;
127 QListWidgetItem *item = w->item(i);
128 item->setForeground(Qt::red);
129 //!!! and a nice gold star
98 } 130 }
99 131
100 void 132 void
101 FileStatusWidget::updateWidgets() 133 FileStatusWidget::updateWidgets()
102 { 134 {
111 foreach (QStringList *sl, listmap.keys()) { 143 foreach (QStringList *sl, listmap.keys()) {
112 listmap[sl]->clear(); 144 listmap[sl]->clear();
113 listmap[sl]->addItems(*sl); 145 listmap[sl]->addItems(*sl);
114 listmap[sl]->parentWidget()->setVisible(!sl->empty()); 146 listmap[sl]->parentWidget()->setVisible(!sl->empty());
115 } 147 }
148
149 if (m_dateReference) {
150 // Highlight untracked files that have appeared since the
151 // last interaction with the repo
152 QDateTime refTime = m_dateReference->lastModified();
153 DEBUG << "reference time: " << refTime << endl;
154 for (int i = 0; i < m_unknownList->count(); ++i) {
155 QString fn(m_localPath + "/" + m_unknownList->item(i)->text());
156 DEBUG << "comparing with " << fn << endl;
157 QFileInfo fi(fn);
158 if (fi.exists() && fi.lastModified() > refTime) {
159 DEBUG << "file " << fn << " is newer (" << fi.lastModified()
160 << ") than reference" << endl;
161 highlightFile(m_unknownList, i);
162 }
163 }
164 }
116 } 165 }
117 166