comparison filestatuswidget.cpp @ 186:6c15700f4103

* Open local folder in Finder/Explorer/whatever when its path is clicked on
author Chris Cannam
date Mon, 20 Dec 2010 14:37:35 +0000
parents 5c262ac73948
children 869825bc8bc4
comparison
equal deleted inserted replaced
185:ec2baee80833 186:6c15700f4103
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 22
22 #include <QLabel> 23 #include <QLabel>
23 #include <QListWidget> 24 #include <QListWidget>
24 #include <QGridLayout> 25 #include <QGridLayout>
25 #include <QFileInfo> 26 #include <QFileInfo>
26 #include <QApplication> 27 #include <QApplication>
27 #include <QDateTime> 28 #include <QDateTime>
28 #include <QPushButton> 29 #include <QPushButton>
30 #include <QToolButton>
31 #include <QDir>
32 #include <QProcess>
29 33
30 FileStatusWidget::FileStatusWidget(QWidget *parent) : 34 FileStatusWidget::FileStatusWidget(QWidget *parent) :
31 QWidget(parent), 35 QWidget(parent),
32 m_dateReference(0) 36 m_dateReference(0)
33 { 37 {
38 42
39 layout->addItem(new QSpacerItem(1, 1), row, 0); 43 layout->addItem(new QSpacerItem(1, 1), row, 0);
40 44
41 ++row; 45 ++row;
42 layout->addWidget(new QLabel(tr("Local:")), row, 0); 46 layout->addWidget(new QLabel(tr("Local:")), row, 0);
43 m_localPathLabel = new QLabel; 47
44 QFont f(m_localPathLabel->font()); 48 m_openButton = new ClickableLabel;
49 QFont f(m_openButton->font());
45 f.setBold(true); 50 f.setBold(true);
46 m_localPathLabel->setFont(f); 51 m_openButton->setFont(f);
47 layout->addWidget(m_localPathLabel, row, 1); 52 m_openButton->setMouseUnderline(true);
53 connect(m_openButton, SIGNAL(clicked()), this, SLOT(openButtonClicked()));
54 layout->addWidget(m_openButton, row, 1, 1, 2);
48 55
49 ++row; 56 ++row;
50 layout->addWidget(new QLabel(tr("Remote:")), row, 0); 57 layout->addWidget(new QLabel(tr("Remote:")), row, 0);
51 m_remoteURLLabel = new QLabel; 58 m_remoteURLLabel = new QLabel;
52 layout->addWidget(m_remoteURLLabel, row, 1); 59 layout->addWidget(m_remoteURLLabel, row, 1, 1, 2);
53 60
54 ++row; 61 ++row;
55 layout->addWidget(new QLabel(tr("State:")), row, 0); 62 layout->addWidget(new QLabel(tr("State:")), row, 0);
56 m_stateLabel = new QLabel; 63 m_stateLabel = new QLabel;
57 layout->addWidget(m_stateLabel, row, 1, 1, 2); 64 layout->addWidget(m_stateLabel, row, 1, 1, 2);
81 m_descriptions[FileStates::Missing] = tr("These files are recorded in the version control, but absent from your working folder.<br>" 88 m_descriptions[FileStates::Missing] = tr("These files are recorded in the version control, but absent from your working folder.<br>"
82 "If you intended to delete them, select them and use Remove to tell the version control system about it.<br>" 89 "If you intended to delete them, select them and use Remove to tell the version control system about it.<br>"
83 "If you deleted them by accident, select them and use Revert to restore their previous contents."); 90 "If you deleted them by accident, select them and use Revert to restore their previous contents.");
84 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."); 91 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.");
85 m_descriptions[FileStates::Unknown] = tr("These files are in your working folder but are not under version control.<br>" 92 m_descriptions[FileStates::Unknown] = tr("These files are in your working folder but are not under version control.<br>"
86 "Select a file and use Add to place it under version control or Ignore to remove it from this list."); 93 // "Select a file and use Add to place it under version control or Ignore to remove it from this list.");
94 "Select a file and use Add to place it under version control.");
87 95
88 m_highlightExplanation = tr("Files highlighted <font color=#d40000>in red</font> " 96 m_highlightExplanation = tr("Files highlighted <font color=#d40000>in red</font> "
89 "have appeared since your most recent commit or update."); 97 "have appeared since your most recent commit or update.");
90 98
91 for (int i = int(FileStates::FirstState); 99 for (int i = int(FileStates::FirstState);
113 layout->addWidget(box, ++row, 0, 1, 3); 121 layout->addWidget(box, ++row, 0, 1, 3);
114 box->hide(); 122 box->hide();
115 } 123 }
116 124
117 layout->setRowStretch(++row, 20); 125 layout->setRowStretch(++row, 20);
126
118 } 127 }
119 128
120 FileStatusWidget::~FileStatusWidget() 129 FileStatusWidget::~FileStatusWidget()
121 { 130 {
122 delete m_dateReference; 131 delete m_dateReference;
132 }
133
134 void FileStatusWidget::openButtonClicked()
135 {
136 QDir d(m_localPath);
137 if (d.exists()) {
138 QStringList args;
139 args << d.canonicalPath();
140 QProcess::execute(
141 #if defined Q_OS_WIN32
142 "c:/windows/explorer.exe",
143 #elif defined Q_OS_MAC
144 "/usr/bin/open",
145 #else
146 "/usr/bin/xdg-open",
147 #endif
148 args);
149 }
123 } 150 }
124 151
125 QString FileStatusWidget::labelFor(FileStates::State s, bool addHighlightExplanation) 152 QString FileStatusWidget::labelFor(FileStates::State s, bool addHighlightExplanation)
126 { 153 {
127 if (addHighlightExplanation) { 154 if (addHighlightExplanation) {
319 346
320 void 347 void
321 FileStatusWidget::setLocalPath(QString p) 348 FileStatusWidget::setLocalPath(QString p)
322 { 349 {
323 m_localPath = p; 350 m_localPath = p;
324 m_localPathLabel->setText(p); 351 m_openButton->setText(p);
325 delete m_dateReference; 352 delete m_dateReference;
326 m_dateReference = new QFileInfo(p + "/.hg/dirstate"); 353 m_dateReference = new QFileInfo(p + "/.hg/dirstate");
327 if (!m_dateReference->exists() || 354 if (!m_dateReference->exists() ||
328 !m_dateReference->isFile() || 355 !m_dateReference->isFile() ||
329 !m_dateReference->isReadable()) { 356 !m_dateReference->isReadable()) {
332 << " does not exist, is not a file, or cannot be read" 359 << " does not exist, is not a file, or cannot be read"
333 << endl; 360 << endl;
334 delete m_dateReference; 361 delete m_dateReference;
335 m_dateReference = 0; 362 m_dateReference = 0;
336 } 363 }
364 m_openButton->setEnabled(QDir(m_localPath).exists());
337 } 365 }
338 366
339 void 367 void
340 FileStatusWidget::setRemoteURL(QString r) 368 FileStatusWidget::setRemoteURL(QString r)
341 { 369 {