comparison filestatuswidget.cpp @ 283:bc39f2e28da8 status_outside_tabs

Separate out work-status code from the file status widget
author Chris Cannam
date Mon, 21 Feb 2011 08:48:31 +0000
parents 8fd71f570884
children 3fbafca196e4
comparison
equal deleted inserted replaced
282:1ec306df738e 283:bc39f2e28da8
16 */ 16 */
17 17
18 #include "filestatuswidget.h" 18 #include "filestatuswidget.h"
19 #include "debug.h" 19 #include "debug.h"
20 #include "multichoicedialog.h" 20 #include "multichoicedialog.h"
21 #include "clickablelabel.h" 21 #include "workstatuswidget.h"
22 22
23 #include <QLabel> 23 #include <QLabel>
24 #include <QListWidget> 24 #include <QListWidget>
25 #include <QGridLayout> 25 #include <QGridLayout>
26 #include <QFileInfo> 26 #include <QFileInfo>
41 layout->setMargin(10); 41 layout->setMargin(10);
42 setLayout(layout); 42 setLayout(layout);
43 43
44 int row = 0; 44 int row = 0;
45 45
46 #ifndef Q_OS_MAC 46 m_workStatus = new WorkStatusWidget(this);
47 layout->addItem(new QSpacerItem(1, 1), row, 0); 47 layout->addWidget(m_workStatus, row, 0, 1, 3);
48 ++row;
49 #endif
50
51 layout->addWidget(new QLabel(tr("Local:")), row, 0);
52
53 m_openButton = new ClickableLabel;
54 QFont f(m_openButton->font());
55 f.setBold(true);
56 m_openButton->setFont(f);
57 m_openButton->setMouseUnderline(true);
58 connect(m_openButton, SIGNAL(clicked()), this, SLOT(openButtonClicked()));
59 layout->addWidget(m_openButton, row, 1, 1, 2, Qt::AlignLeft);
60
61 ++row;
62 layout->addWidget(new QLabel(tr("Remote:")), row, 0);
63 m_remoteURLLabel = new QLabel;
64 layout->addWidget(m_remoteURLLabel, row, 1, 1, 2);
65
66 ++row;
67 layout->addWidget(new QLabel(tr("State:")), row, 0);
68 m_stateLabel = new QLabel;
69 layout->addWidget(m_stateLabel, row, 1, 1, 2);
70
71 layout->setColumnStretch(1, 20);
72
73 layout->addWidget(new QLabel("<qt><hr></qt>"), ++row, 0, 1, 3);
74
75 ++row; 48 ++row;
76 49
77 m_noModificationsLabel = new QLabel; 50 m_noModificationsLabel = new QLabel;
78 setNoModificationsLabelText(); 51 setNoModificationsLabelText();
79 layout->addWidget(m_noModificationsLabel, row, 1, 1, 2); 52 layout->addWidget(m_noModificationsLabel, row, 1, 1, 2);
158 } 131 }
159 132
160 FileStatusWidget::~FileStatusWidget() 133 FileStatusWidget::~FileStatusWidget()
161 { 134 {
162 delete m_dateReference; 135 delete m_dateReference;
163 }
164
165 void FileStatusWidget::openButtonClicked()
166 {
167 QDir d(m_localPath);
168 if (d.exists()) {
169 QStringList args;
170 QString path = d.canonicalPath();
171 #if defined Q_OS_WIN32
172 // Although the Win32 API is quite happy to have
173 // forward slashes as directory separators, Windows
174 // Explorer is not
175 path = path.replace('/', '\\');
176 args << path;
177 QProcess::execute("c:/windows/explorer.exe", args);
178 #else
179 args << path;
180 QProcess::execute(
181 #if defined Q_OS_MAC
182 "/usr/bin/open",
183 #else
184 "/usr/bin/xdg-open",
185 #endif
186 args);
187 #endif
188 }
189 } 136 }
190 137
191 QString FileStatusWidget::labelFor(FileStates::State s, bool addHighlightExplanation) 138 QString FileStatusWidget::labelFor(FileStates::State s, bool addHighlightExplanation)
192 { 139 {
193 QSettings settings; 140 QSettings settings;
410 files << m_fileStates.getFilesInState(FileStates::Missing); 357 files << m_fileStates.getFilesInState(FileStates::Missing);
411 files << m_fileStates.getFilesInState(FileStates::InConflict); 358 files << m_fileStates.getFilesInState(FileStates::InConflict);
412 return files; 359 return files;
413 } 360 }
414 361
362 QString
363 FileStatusWidget::localPath() const
364 {
365 return m_workStatus->localPath();
366 }
367
415 void 368 void
416 FileStatusWidget::setLocalPath(QString p) 369 FileStatusWidget::setLocalPath(QString p)
417 { 370 {
418 m_localPath = p; 371 m_workStatus->setLocalPath(p);
419 m_openButton->setText(p);
420 delete m_dateReference; 372 delete m_dateReference;
421 m_dateReference = new QFileInfo(p + "/.hg/dirstate"); 373 m_dateReference = new QFileInfo(p + "/.hg/dirstate");
422 if (!m_dateReference->exists() || 374 if (!m_dateReference->exists() ||
423 !m_dateReference->isFile() || 375 !m_dateReference->isFile() ||
424 !m_dateReference->isReadable()) { 376 !m_dateReference->isReadable()) {
427 << " does not exist, is not a file, or cannot be read" 379 << " does not exist, is not a file, or cannot be read"
428 << endl; 380 << endl;
429 delete m_dateReference; 381 delete m_dateReference;
430 m_dateReference = 0; 382 m_dateReference = 0;
431 } 383 }
432 m_openButton->setEnabled(QDir(m_localPath).exists()); 384 }
385
386 QString
387 FileStatusWidget::remoteURL() const
388 {
389 return m_workStatus->remoteURL();
433 } 390 }
434 391
435 void 392 void
436 FileStatusWidget::setRemoteURL(QString r) 393 FileStatusWidget::setRemoteURL(QString r)
437 { 394 {
438 m_remoteURL = r; 395 m_workStatus->setRemoteURL(r);
439 m_remoteURLLabel->setText(r); 396 }
397
398 QString
399 FileStatusWidget::state() const
400 {
401 return m_workStatus->state();
402 }
403
404 void
405 FileStatusWidget::setState(QString b)
406 {
407 m_workStatus->setState(b);
440 } 408 }
441 409
442 void 410 void
443 FileStatusWidget::setFileStates(FileStates p) 411 FileStatusWidget::setFileStates(FileStates p)
444 { 412 {
445 m_fileStates = p; 413 m_fileStates = p;
446 updateWidgets(); 414 updateWidgets();
447 }
448
449 void
450 FileStatusWidget::setState(QString b)
451 {
452 m_state = b;
453 updateStateLabel();
454 } 415 }
455 416
456 void 417 void
457 FileStatusWidget::updateWidgets() 418 FileStatusWidget::updateWidgets()
458 { 419 {
480 bool highlighted = false; 441 bool highlighted = false;
481 442
482 if (s == FileStates::Unknown) { 443 if (s == FileStates::Unknown) {
483 // We want to highlight untracked files that have appeared 444 // We want to highlight untracked files that have appeared
484 // since the last interaction with the repo 445 // since the last interaction with the repo
485 QString fn(m_localPath + "/" + file); 446 QString fn(m_workStatus->localPath() + "/" + file);
486 DEBUG << "comparing with " << fn << endl; 447 DEBUG << "comparing with " << fn << endl;
487 QFileInfo fi(fn); 448 QFileInfo fi(fn);
488 if (fi.exists() && fi.created() > lastInteractionTime) { 449 if (fi.exists() && fi.created() > lastInteractionTime) {
489 DEBUG << "file " << fn << " is newer (" << fi.lastModified() 450 DEBUG << "file " << fn << " is newer (" << fi.lastModified()
490 << ") than reference" << endl; 451 << ") than reference" << endl;
528 layoutBoxesGridly(visibleCount); 489 layoutBoxesGridly(visibleCount);
529 } else { 490 } else {
530 layoutBoxesLinearly(); 491 layoutBoxesLinearly();
531 } 492 }
532 493
533 updateStateLabel();
534 setNoModificationsLabelText(); 494 setNoModificationsLabelText();
535 } 495 }
536 496
537 void FileStatusWidget::layoutBoxesGridly(int visibleCount) 497 void FileStatusWidget::layoutBoxesGridly(int visibleCount)
538 { 498 {
592 QWidget *p = w->parentWidget(); 552 QWidget *p = w->parentWidget();
593 QList<QLabel *> ql = p->findChildren<QLabel *>(); 553 QList<QLabel *> ql = p->findChildren<QLabel *>();
594 if (!ql.empty()) ql[0]->setText(text); 554 if (!ql.empty()) ql[0]->setText(text);
595 } 555 }
596 556
597 void FileStatusWidget::updateStateLabel()
598 {
599 m_stateLabel->setText(m_state);
600 }