Chris@88
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@88
|
2
|
Chris@88
|
3 /*
|
Chris@88
|
4 EasyMercurial
|
Chris@88
|
5
|
Chris@88
|
6 Based on HgExplorer by Jari Korhonen
|
Chris@88
|
7 Copyright (c) 2010 Jari Korhonen
|
Chris@244
|
8 Copyright (c) 2011 Chris Cannam
|
Chris@244
|
9 Copyright (c) 2011 Queen Mary, University of London
|
Chris@88
|
10
|
Chris@88
|
11 This program is free software; you can redistribute it and/or
|
Chris@88
|
12 modify it under the terms of the GNU General Public License as
|
Chris@88
|
13 published by the Free Software Foundation; either version 2 of the
|
Chris@88
|
14 License, or (at your option) any later version. See the file
|
Chris@88
|
15 COPYING included with this distribution for more information.
|
Chris@88
|
16 */
|
Chris@88
|
17
|
Chris@88
|
18 #include "filestatuswidget.h"
|
Chris@115
|
19 #include "debug.h"
|
Chris@115
|
20 #include "multichoicedialog.h"
|
Chris@88
|
21
|
Chris@88
|
22 #include <QLabel>
|
Chris@88
|
23 #include <QListWidget>
|
Chris@88
|
24 #include <QGridLayout>
|
Chris@93
|
25 #include <QFileInfo>
|
Chris@93
|
26 #include <QApplication>
|
Chris@93
|
27 #include <QDateTime>
|
Chris@115
|
28 #include <QPushButton>
|
Chris@186
|
29 #include <QToolButton>
|
Chris@186
|
30 #include <QDir>
|
Chris@186
|
31 #include <QProcess>
|
Chris@199
|
32 #include <QCheckBox>
|
Chris@230
|
33 #include <QSettings>
|
Chris@88
|
34
|
Chris@88
|
35 FileStatusWidget::FileStatusWidget(QWidget *parent) :
|
Chris@93
|
36 QWidget(parent),
|
Chris@93
|
37 m_dateReference(0)
|
Chris@88
|
38 {
|
Chris@88
|
39 QGridLayout *layout = new QGridLayout;
|
Chris@215
|
40 layout->setMargin(10);
|
Chris@88
|
41 setLayout(layout);
|
Chris@88
|
42
|
Chris@88
|
43 int row = 0;
|
Chris@211
|
44
|
Chris@230
|
45 m_noModificationsLabel = new QLabel;
|
Chris@230
|
46 setNoModificationsLabelText();
|
Chris@297
|
47 layout->addWidget(m_noModificationsLabel, row, 0);
|
Chris@202
|
48 m_noModificationsLabel->hide();
|
Chris@106
|
49
|
Chris@100
|
50 m_simpleLabels[FileStates::Clean] = tr("Unmodified:");
|
Chris@100
|
51 m_simpleLabels[FileStates::Modified] = tr("Modified:");
|
Chris@100
|
52 m_simpleLabels[FileStates::Added] = tr("Added:");
|
Chris@100
|
53 m_simpleLabels[FileStates::Removed] = tr("Removed:");
|
Chris@100
|
54 m_simpleLabels[FileStates::Missing] = tr("Missing:");
|
Chris@163
|
55 m_simpleLabels[FileStates::InConflict] = tr("In Conflict:");
|
Chris@100
|
56 m_simpleLabels[FileStates::Unknown] = tr("Untracked:");
|
Chris@199
|
57 m_simpleLabels[FileStates::Ignored] = tr("Ignored:");
|
Chris@99
|
58
|
Chris@100
|
59 m_descriptions[FileStates::Clean] = tr("You have not changed these files.");
|
Chris@100
|
60 m_descriptions[FileStates::Modified] = tr("You have changed these files since you last committed them.");
|
Chris@225
|
61 m_descriptions[FileStates::Added] = tr("These files will be added to version control next time you commit them.");
|
Chris@225
|
62 m_descriptions[FileStates::Removed] = tr("These files will be removed from version control next time you commit them.<br>"
|
Chris@100
|
63 "They will not be deleted from the local folder.");
|
Chris@109
|
64 m_descriptions[FileStates::Missing] = tr("These files are recorded in the version control, but absent from your working folder.<br>"
|
Chris@153
|
65 "If you intended to delete them, select them and use Remove to tell the version control system about it.<br>"
|
Chris@153
|
66 "If you deleted them by accident, select them and use Revert to restore their previous contents.");
|
Chris@163
|
67 m_descriptions[FileStates::InConflict] = tr("These files are unresolved following an incomplete merge.<br>Select a file and use Merge to try to resolve the merge again.");
|
Chris@100
|
68 m_descriptions[FileStates::Unknown] = tr("These files are in your working folder but are not under version control.<br>"
|
Chris@186
|
69 // "Select a file and use Add to place it under version control or Ignore to remove it from this list.");
|
Chris@186
|
70 "Select a file and use Add to place it under version control.");
|
Chris@199
|
71 m_descriptions[FileStates::Ignored] = tr("These files have names that match entries in the working folder's .hgignore file,<br>"
|
Chris@199
|
72 "and so will be ignored by the version control system.");
|
Chris@100
|
73
|
Chris@118
|
74 m_highlightExplanation = tr("Files highlighted <font color=#d40000>in red</font> "
|
Chris@100
|
75 "have appeared since your most recent commit or update.");
|
Chris@89
|
76
|
Chris@230
|
77 m_boxesParent = new QWidget(this);
|
Chris@297
|
78 layout->addWidget(m_boxesParent, ++row, 0);
|
Chris@230
|
79
|
Chris@230
|
80 QGridLayout *boxesLayout = new QGridLayout;
|
Chris@230
|
81 boxesLayout->setMargin(0);
|
Chris@230
|
82 m_boxesParent->setLayout(boxesLayout);
|
Chris@230
|
83 int boxRow = 0;
|
Chris@230
|
84
|
Chris@94
|
85 for (int i = int(FileStates::FirstState);
|
Chris@163
|
86 i <= int(FileStates::LastState); ++i) {
|
Chris@89
|
87
|
Chris@94
|
88 FileStates::State s = FileStates::State(i);
|
Chris@89
|
89
|
Chris@230
|
90 QWidget *box = new QWidget(m_boxesParent);
|
Chris@89
|
91 QGridLayout *boxlayout = new QGridLayout;
|
Chris@99
|
92 boxlayout->setMargin(0);
|
Chris@89
|
93 box->setLayout(boxlayout);
|
Chris@89
|
94
|
Chris@211
|
95 boxlayout->addItem(new QSpacerItem(3, 3), 0, 0);
|
Chris@101
|
96
|
Chris@230
|
97 QLabel *label = new QLabel(labelFor(s));
|
Chris@230
|
98 label->setWordWrap(true);
|
Chris@230
|
99 boxlayout->addWidget(label, 1, 0);
|
Chris@89
|
100
|
Chris@94
|
101 QListWidget *w = new QListWidget;
|
Chris@94
|
102 m_stateListMap[s] = w;
|
Chris@94
|
103 w->setSelectionMode(QListWidget::ExtendedSelection);
|
Chris@101
|
104 boxlayout->addWidget(w, 2, 0);
|
Chris@89
|
105
|
Chris@95
|
106 connect(w, SIGNAL(itemSelectionChanged()),
|
Chris@95
|
107 this, SLOT(itemSelectionChanged()));
|
Chris@95
|
108
|
Chris@211
|
109 boxlayout->addItem(new QSpacerItem(2, 2), 3, 0);
|
Chris@211
|
110
|
Chris@230
|
111 boxesLayout->addWidget(box, ++boxRow, 0);
|
Chris@230
|
112 m_boxes.push_back(box);
|
Chris@89
|
113 box->hide();
|
Chris@89
|
114 }
|
Chris@89
|
115
|
Chris@230
|
116 m_gridlyLayout = false;
|
Chris@230
|
117
|
Chris@89
|
118 layout->setRowStretch(++row, 20);
|
Chris@186
|
119
|
Chris@211
|
120 layout->addItem(new QSpacerItem(8, 8), ++row, 0);
|
Chris@199
|
121
|
Chris@199
|
122 m_showAllFiles = new QCheckBox(tr("Show all files"), this);
|
Chris@297
|
123 layout->addWidget(m_showAllFiles, ++row, 0, Qt::AlignLeft);
|
Chris@199
|
124 connect(m_showAllFiles, SIGNAL(toggled(bool)),
|
Chris@199
|
125 this, SIGNAL(showAllChanged(bool)));
|
Chris@88
|
126 }
|
Chris@88
|
127
|
Chris@93
|
128 FileStatusWidget::~FileStatusWidget()
|
Chris@93
|
129 {
|
Chris@93
|
130 delete m_dateReference;
|
Chris@93
|
131 }
|
Chris@93
|
132
|
Chris@100
|
133 QString FileStatusWidget::labelFor(FileStates::State s, bool addHighlightExplanation)
|
Chris@100
|
134 {
|
Chris@230
|
135 QSettings settings;
|
Chris@230
|
136 settings.beginGroup("Presentation");
|
Chris@230
|
137 if (settings.value("showhelpfultext", true).toBool()) {
|
Chris@230
|
138 if (addHighlightExplanation) {
|
Chris@230
|
139 return QString("<qt><b>%1</b><br>%2<br>%3</qt>")
|
Chris@230
|
140 .arg(m_simpleLabels[s])
|
Chris@230
|
141 .arg(m_descriptions[s])
|
Chris@230
|
142 .arg(m_highlightExplanation);
|
Chris@230
|
143 } else {
|
Chris@230
|
144 return QString("<qt><b>%1</b><br>%2</qt>")
|
Chris@230
|
145 .arg(m_simpleLabels[s])
|
Chris@230
|
146 .arg(m_descriptions[s]);
|
Chris@230
|
147 }
|
Chris@100
|
148 } else {
|
Chris@230
|
149 return QString("<qt><b>%1</b></qt>")
|
Chris@230
|
150 .arg(m_simpleLabels[s]);
|
Chris@230
|
151 }
|
Chris@230
|
152 settings.endGroup();
|
Chris@230
|
153 }
|
Chris@230
|
154
|
Chris@230
|
155 void FileStatusWidget::setNoModificationsLabelText()
|
Chris@230
|
156 {
|
Chris@230
|
157 QSettings settings;
|
Chris@230
|
158 settings.beginGroup("Presentation");
|
Chris@230
|
159 if (settings.value("showhelpfultext", true).toBool()) {
|
Chris@230
|
160 m_noModificationsLabel->setText
|
Chris@230
|
161 (tr("<qt>This area will list files in your working folder that you have changed.<br><br>At the moment you have no uncommitted changes.<br><br>To see changes previously made to the repository,<br>switch to the History tab.<br><br>%1</qt>")
|
Chris@230
|
162 #if defined Q_OS_MAC
|
Chris@230
|
163 .arg(tr("To open the working folder in Finder,<br>click on the “Local” folder path shown above."))
|
Chris@230
|
164 #elif defined Q_OS_WIN32
|
Chris@230
|
165 .arg(tr("To open the working folder in Windows Explorer,<br>click on the “Local” folder path shown above."))
|
Chris@230
|
166 #else
|
Chris@230
|
167 .arg(tr("To open the working folder in your system file manager,<br>click the “Local” folder path shown above."))
|
Chris@230
|
168 #endif
|
Chris@230
|
169 );
|
Chris@230
|
170 } else {
|
Chris@230
|
171 m_noModificationsLabel->setText
|
Chris@230
|
172 (tr("<qt>You have no uncommitted changes.</qt>"));
|
Chris@100
|
173 }
|
Chris@100
|
174 }
|
Chris@100
|
175
|
Chris@95
|
176 void FileStatusWidget::itemSelectionChanged()
|
Chris@95
|
177 {
|
Chris@135
|
178 DEBUG << "FileStatusWidget::itemSelectionChanged" << endl;
|
Chris@135
|
179
|
Chris@135
|
180 QListWidget *list = qobject_cast<QListWidget *>(sender());
|
Chris@135
|
181
|
Chris@135
|
182 if (list) {
|
Chris@135
|
183 foreach (QListWidget *w, m_stateListMap) {
|
Chris@135
|
184 if (w != list) {
|
Chris@135
|
185 w->blockSignals(true);
|
Chris@135
|
186 w->clearSelection();
|
Chris@135
|
187 w->blockSignals(false);
|
Chris@135
|
188 }
|
Chris@135
|
189 }
|
Chris@135
|
190 }
|
Chris@135
|
191
|
Chris@95
|
192 m_selectedFiles.clear();
|
Chris@95
|
193
|
Chris@95
|
194 foreach (QListWidget *w, m_stateListMap) {
|
Chris@95
|
195 QList<QListWidgetItem *> sel = w->selectedItems();
|
Chris@95
|
196 foreach (QListWidgetItem *i, sel) {
|
Chris@95
|
197 m_selectedFiles.push_back(i->text());
|
Chris@95
|
198 DEBUG << "file " << i->text() << " is selected" << endl;
|
Chris@95
|
199 }
|
Chris@95
|
200 }
|
Chris@95
|
201
|
Chris@95
|
202 emit selectionChanged();
|
Chris@95
|
203 }
|
Chris@95
|
204
|
Chris@94
|
205 void FileStatusWidget::clearSelections()
|
Chris@94
|
206 {
|
Chris@95
|
207 m_selectedFiles.clear();
|
Chris@94
|
208 foreach (QListWidget *w, m_stateListMap) {
|
Chris@94
|
209 w->clearSelection();
|
Chris@94
|
210 }
|
Chris@94
|
211 }
|
Chris@94
|
212
|
Chris@95
|
213 bool FileStatusWidget::haveChangesToCommit() const
|
Chris@95
|
214 {
|
Chris@95
|
215 return !m_fileStates.added().empty() ||
|
Chris@95
|
216 !m_fileStates.removed().empty() ||
|
Chris@95
|
217 !m_fileStates.modified().empty();
|
Chris@95
|
218 }
|
Chris@95
|
219
|
Chris@95
|
220 bool FileStatusWidget::haveSelection() const
|
Chris@95
|
221 {
|
Chris@95
|
222 return !m_selectedFiles.empty();
|
Chris@95
|
223 }
|
Chris@95
|
224
|
Chris@95
|
225 QStringList FileStatusWidget::getAllSelectedFiles() const
|
Chris@95
|
226 {
|
Chris@95
|
227 return m_selectedFiles;
|
Chris@95
|
228 }
|
Chris@95
|
229
|
Chris@95
|
230 QStringList FileStatusWidget::getSelectedCommittableFiles() const
|
Chris@95
|
231 {
|
Chris@95
|
232 QStringList files;
|
Chris@95
|
233 foreach (QString f, m_selectedFiles) {
|
Chris@95
|
234 switch (m_fileStates.getStateOfFile(f)) {
|
Chris@95
|
235 case FileStates::Added:
|
Chris@95
|
236 case FileStates::Modified:
|
Chris@95
|
237 case FileStates::Removed:
|
Chris@95
|
238 files.push_back(f);
|
Chris@95
|
239 break;
|
Chris@95
|
240 default: break;
|
Chris@95
|
241 }
|
Chris@95
|
242 }
|
Chris@95
|
243 return files;
|
Chris@95
|
244 }
|
Chris@95
|
245
|
Chris@103
|
246 QStringList FileStatusWidget::getAllCommittableFiles() const
|
Chris@103
|
247 {
|
Chris@103
|
248 QStringList files;
|
Chris@103
|
249 files << m_fileStates.getFilesInState(FileStates::Modified);
|
Chris@103
|
250 files << m_fileStates.getFilesInState(FileStates::Added);
|
Chris@103
|
251 files << m_fileStates.getFilesInState(FileStates::Removed);
|
Chris@103
|
252 return files;
|
Chris@103
|
253 }
|
Chris@103
|
254
|
Chris@109
|
255 QStringList FileStatusWidget::getSelectedRevertableFiles() const
|
Chris@109
|
256 {
|
Chris@109
|
257 QStringList files;
|
Chris@109
|
258 foreach (QString f, m_selectedFiles) {
|
Chris@109
|
259 switch (m_fileStates.getStateOfFile(f)) {
|
Chris@109
|
260 case FileStates::Added:
|
Chris@109
|
261 case FileStates::Modified:
|
Chris@109
|
262 case FileStates::Removed:
|
Chris@109
|
263 case FileStates::Missing:
|
Chris@163
|
264 case FileStates::InConflict:
|
Chris@109
|
265 files.push_back(f);
|
Chris@109
|
266 break;
|
Chris@109
|
267 default: break;
|
Chris@109
|
268 }
|
Chris@109
|
269 }
|
Chris@109
|
270 return files;
|
Chris@109
|
271 }
|
Chris@109
|
272
|
Chris@109
|
273 QStringList FileStatusWidget::getAllRevertableFiles() const
|
Chris@109
|
274 {
|
Chris@109
|
275 QStringList files;
|
Chris@109
|
276 files << m_fileStates.getFilesInState(FileStates::Modified);
|
Chris@109
|
277 files << m_fileStates.getFilesInState(FileStates::Added);
|
Chris@109
|
278 files << m_fileStates.getFilesInState(FileStates::Removed);
|
Chris@109
|
279 files << m_fileStates.getFilesInState(FileStates::Missing);
|
Chris@163
|
280 files << m_fileStates.getFilesInState(FileStates::InConflict);
|
Chris@163
|
281 return files;
|
Chris@163
|
282 }
|
Chris@163
|
283
|
Chris@163
|
284 QStringList FileStatusWidget::getSelectedUnresolvedFiles() const
|
Chris@163
|
285 {
|
Chris@163
|
286 QStringList files;
|
Chris@163
|
287 foreach (QString f, m_selectedFiles) {
|
Chris@163
|
288 switch (m_fileStates.getStateOfFile(f)) {
|
Chris@163
|
289 case FileStates::InConflict:
|
Chris@163
|
290 files.push_back(f);
|
Chris@163
|
291 break;
|
Chris@163
|
292 default: break;
|
Chris@163
|
293 }
|
Chris@163
|
294 }
|
Chris@163
|
295 return files;
|
Chris@163
|
296 }
|
Chris@163
|
297
|
Chris@163
|
298 QStringList FileStatusWidget::getAllUnresolvedFiles() const
|
Chris@163
|
299 {
|
Chris@163
|
300 QStringList files;
|
Chris@163
|
301 files << m_fileStates.getFilesInState(FileStates::InConflict);
|
Chris@109
|
302 return files;
|
Chris@109
|
303 }
|
Chris@109
|
304
|
Chris@95
|
305 QStringList FileStatusWidget::getSelectedAddableFiles() const
|
Chris@95
|
306 {
|
Chris@95
|
307 QStringList files;
|
Chris@95
|
308 foreach (QString f, m_selectedFiles) {
|
Chris@95
|
309 switch (m_fileStates.getStateOfFile(f)) {
|
Chris@95
|
310 case FileStates::Unknown:
|
Chris@95
|
311 case FileStates::Removed:
|
Chris@95
|
312 files.push_back(f);
|
Chris@95
|
313 break;
|
Chris@95
|
314 default: break;
|
Chris@95
|
315 }
|
Chris@95
|
316 }
|
Chris@95
|
317 return files;
|
Chris@95
|
318 }
|
Chris@95
|
319
|
Chris@103
|
320 QStringList FileStatusWidget::getAllAddableFiles() const
|
Chris@103
|
321 {
|
Chris@103
|
322 QStringList files;
|
Chris@103
|
323 files << m_fileStates.getFilesInState(FileStates::Removed);
|
Chris@103
|
324 files << m_fileStates.getFilesInState(FileStates::Unknown);
|
Chris@103
|
325 return files;
|
Chris@103
|
326 }
|
Chris@103
|
327
|
Chris@95
|
328 QStringList FileStatusWidget::getSelectedRemovableFiles() const
|
Chris@95
|
329 {
|
Chris@95
|
330 QStringList files;
|
Chris@95
|
331 foreach (QString f, m_selectedFiles) {
|
Chris@95
|
332 switch (m_fileStates.getStateOfFile(f)) {
|
Chris@95
|
333 case FileStates::Clean:
|
Chris@95
|
334 case FileStates::Added:
|
Chris@95
|
335 case FileStates::Modified:
|
Chris@95
|
336 case FileStates::Missing:
|
Chris@163
|
337 case FileStates::InConflict:
|
Chris@95
|
338 files.push_back(f);
|
Chris@95
|
339 break;
|
Chris@95
|
340 default: break;
|
Chris@95
|
341 }
|
Chris@95
|
342 }
|
Chris@95
|
343 return files;
|
Chris@95
|
344 }
|
Chris@95
|
345
|
Chris@103
|
346 QStringList FileStatusWidget::getAllRemovableFiles() const
|
Chris@103
|
347 {
|
Chris@103
|
348 QStringList files;
|
Chris@103
|
349 files << m_fileStates.getFilesInState(FileStates::Clean);
|
Chris@103
|
350 files << m_fileStates.getFilesInState(FileStates::Added);
|
Chris@103
|
351 files << m_fileStates.getFilesInState(FileStates::Modified);
|
Chris@103
|
352 files << m_fileStates.getFilesInState(FileStates::Missing);
|
Chris@163
|
353 files << m_fileStates.getFilesInState(FileStates::InConflict);
|
Chris@103
|
354 return files;
|
Chris@103
|
355 }
|
Chris@103
|
356
|
Chris@283
|
357 QString
|
Chris@283
|
358 FileStatusWidget::localPath() const
|
Chris@283
|
359 {
|
Chris@287
|
360 return m_localPath;
|
Chris@283
|
361 }
|
Chris@283
|
362
|
Chris@88
|
363 void
|
Chris@88
|
364 FileStatusWidget::setLocalPath(QString p)
|
Chris@88
|
365 {
|
Chris@287
|
366 m_localPath = p;
|
Chris@93
|
367 delete m_dateReference;
|
Chris@93
|
368 m_dateReference = new QFileInfo(p + "/.hg/dirstate");
|
Chris@93
|
369 if (!m_dateReference->exists() ||
|
Chris@93
|
370 !m_dateReference->isFile() ||
|
Chris@93
|
371 !m_dateReference->isReadable()) {
|
Chris@93
|
372 DEBUG << "FileStatusWidget::setLocalPath: date reference file "
|
Chris@93
|
373 << m_dateReference->absoluteFilePath()
|
Chris@93
|
374 << " does not exist, is not a file, or cannot be read"
|
Chris@93
|
375 << endl;
|
Chris@93
|
376 delete m_dateReference;
|
Chris@93
|
377 m_dateReference = 0;
|
Chris@93
|
378 }
|
Chris@283
|
379 }
|
Chris@283
|
380
|
Chris@88
|
381 void
|
Chris@92
|
382 FileStatusWidget::setFileStates(FileStates p)
|
Chris@88
|
383 {
|
Chris@92
|
384 m_fileStates = p;
|
Chris@88
|
385 updateWidgets();
|
Chris@88
|
386 }
|
Chris@88
|
387
|
Chris@88
|
388 void
|
Chris@88
|
389 FileStatusWidget::updateWidgets()
|
Chris@88
|
390 {
|
Chris@95
|
391 QDateTime lastInteractionTime;
|
Chris@95
|
392 if (m_dateReference) {
|
Chris@95
|
393 lastInteractionTime = m_dateReference->lastModified();
|
Chris@95
|
394 DEBUG << "reference time: " << lastInteractionTime << endl;
|
Chris@95
|
395 }
|
Chris@95
|
396
|
Chris@95
|
397 QSet<QString> selectedFiles;
|
Chris@95
|
398 foreach (QString f, m_selectedFiles) selectedFiles.insert(f);
|
Chris@95
|
399
|
Chris@230
|
400 int visibleCount = 0;
|
Chris@115
|
401
|
Chris@94
|
402 foreach (FileStates::State s, m_stateListMap.keys()) {
|
Chris@95
|
403
|
Chris@94
|
404 QListWidget *w = m_stateListMap[s];
|
Chris@94
|
405 w->clear();
|
Chris@95
|
406 QStringList files = m_fileStates.getFilesInState(s);
|
Chris@93
|
407
|
Chris@95
|
408 QStringList highPriority, lowPriority;
|
Chris@95
|
409
|
Chris@95
|
410 foreach (QString file, files) {
|
Chris@95
|
411
|
Chris@95
|
412 bool highlighted = false;
|
Chris@95
|
413
|
Chris@95
|
414 if (s == FileStates::Unknown) {
|
Chris@95
|
415 // We want to highlight untracked files that have appeared
|
Chris@95
|
416 // since the last interaction with the repo
|
Chris@287
|
417 QString fn(m_localPath + "/" + file);
|
Chris@95
|
418 DEBUG << "comparing with " << fn << endl;
|
Chris@95
|
419 QFileInfo fi(fn);
|
Chris@100
|
420 if (fi.exists() && fi.created() > lastInteractionTime) {
|
Chris@95
|
421 DEBUG << "file " << fn << " is newer (" << fi.lastModified()
|
Chris@95
|
422 << ") than reference" << endl;
|
Chris@95
|
423 highlighted = true;
|
Chris@95
|
424 }
|
Chris@95
|
425 }
|
Chris@95
|
426
|
Chris@95
|
427 if (highlighted) {
|
Chris@95
|
428 highPriority.push_back(file);
|
Chris@95
|
429 } else {
|
Chris@95
|
430 lowPriority.push_back(file);
|
Chris@93
|
431 }
|
Chris@93
|
432 }
|
Chris@95
|
433
|
Chris@95
|
434 foreach (QString file, highPriority) {
|
Chris@95
|
435 QListWidgetItem *item = new QListWidgetItem(file);
|
Chris@95
|
436 w->addItem(item);
|
Chris@118
|
437 item->setForeground(QColor("#d40000")); //!!! and a nice gold star
|
Chris@95
|
438 item->setSelected(selectedFiles.contains(file));
|
Chris@95
|
439 }
|
Chris@95
|
440
|
Chris@95
|
441 foreach (QString file, lowPriority) {
|
Chris@95
|
442 QListWidgetItem *item = new QListWidgetItem(file);
|
Chris@95
|
443 w->addItem(item);
|
Chris@95
|
444 item->setSelected(selectedFiles.contains(file));
|
Chris@95
|
445 }
|
Chris@95
|
446
|
Chris@100
|
447 setLabelFor(w, s, !highPriority.empty());
|
Chris@100
|
448
|
Chris@115
|
449 if (files.empty()) {
|
Chris@115
|
450 w->parentWidget()->hide();
|
Chris@115
|
451 } else {
|
Chris@115
|
452 w->parentWidget()->show();
|
Chris@230
|
453 ++visibleCount;
|
Chris@115
|
454 }
|
Chris@93
|
455 }
|
Chris@115
|
456
|
Chris@230
|
457 m_noModificationsLabel->setVisible(visibleCount == 0);
|
Chris@230
|
458
|
Chris@230
|
459 if (visibleCount > 3) {
|
Chris@230
|
460 layoutBoxesGridly(visibleCount);
|
Chris@230
|
461 } else {
|
Chris@230
|
462 layoutBoxesLinearly();
|
Chris@230
|
463 }
|
Chris@115
|
464
|
Chris@230
|
465 setNoModificationsLabelText();
|
Chris@230
|
466 }
|
Chris@230
|
467
|
Chris@230
|
468 void FileStatusWidget::layoutBoxesGridly(int visibleCount)
|
Chris@230
|
469 {
|
Chris@230
|
470 if (m_gridlyLayout && m_lastGridlyCount == visibleCount) return;
|
Chris@230
|
471
|
Chris@230
|
472 delete m_boxesParent->layout();
|
Chris@230
|
473
|
Chris@230
|
474 QGridLayout *layout = new QGridLayout;
|
Chris@230
|
475 layout->setMargin(0);
|
Chris@230
|
476 m_boxesParent->setLayout(layout);
|
Chris@230
|
477
|
Chris@230
|
478 int row = 0;
|
Chris@230
|
479 int col = 0;
|
Chris@230
|
480
|
Chris@230
|
481 DEBUG << "FileStatusWidget::layoutBoxesGridly: visibleCount = "
|
Chris@230
|
482 << visibleCount << endl;
|
Chris@230
|
483
|
Chris@230
|
484 for (int i = 0; i < m_boxes.size(); ++i) {
|
Chris@230
|
485
|
Chris@230
|
486 if (!m_boxes[i]->isVisible()) continue;
|
Chris@230
|
487
|
Chris@230
|
488 if (col == 0 && row >= (visibleCount+1)/2) {
|
Chris@230
|
489 layout->addItem(new QSpacerItem(10, 5), 0, 1);
|
Chris@230
|
490 col = 2;
|
Chris@230
|
491 row = 0;
|
Chris@230
|
492 }
|
Chris@230
|
493
|
Chris@230
|
494 layout->addWidget(m_boxes[i], row, col);
|
Chris@230
|
495
|
Chris@230
|
496 ++row;
|
Chris@230
|
497 }
|
Chris@230
|
498
|
Chris@230
|
499 m_gridlyLayout = true;
|
Chris@230
|
500 m_lastGridlyCount = visibleCount;
|
Chris@230
|
501 }
|
Chris@230
|
502
|
Chris@230
|
503 void FileStatusWidget::layoutBoxesLinearly()
|
Chris@230
|
504 {
|
Chris@230
|
505 if (!m_gridlyLayout) return;
|
Chris@230
|
506
|
Chris@230
|
507 delete m_boxesParent->layout();
|
Chris@230
|
508
|
Chris@230
|
509 QGridLayout *layout = new QGridLayout;
|
Chris@230
|
510 layout->setMargin(0);
|
Chris@230
|
511 m_boxesParent->setLayout(layout);
|
Chris@230
|
512
|
Chris@230
|
513 for (int i = 0; i < m_boxes.size(); ++i) {
|
Chris@230
|
514 layout->addWidget(m_boxes[i], i, 0);
|
Chris@230
|
515 }
|
Chris@230
|
516
|
Chris@230
|
517 m_gridlyLayout = false;
|
Chris@88
|
518 }
|
Chris@88
|
519
|
Chris@100
|
520 void FileStatusWidget::setLabelFor(QWidget *w, FileStates::State s, bool addHighlight)
|
Chris@100
|
521 {
|
Chris@100
|
522 QString text = labelFor(s, addHighlight);
|
Chris@100
|
523 QWidget *p = w->parentWidget();
|
Chris@100
|
524 QList<QLabel *> ql = p->findChildren<QLabel *>();
|
Chris@100
|
525 if (!ql.empty()) ql[0]->setText(text);
|
Chris@100
|
526 }
|
Chris@115
|
527
|