Chris@283: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@283: Chris@283: /* Chris@283: EasyMercurial Chris@283: Chris@283: Based on HgExplorer by Jari Korhonen Chris@283: Copyright (c) 2010 Jari Korhonen Chris@283: Copyright (c) 2011 Chris Cannam Chris@283: Copyright (c) 2011 Queen Mary, University of London Chris@283: Chris@283: This program is free software; you can redistribute it and/or Chris@283: modify it under the terms of the GNU General Public License as Chris@283: published by the Free Software Foundation; either version 2 of the Chris@283: License, or (at your option) any later version. See the file Chris@283: COPYING included with this distribution for more information. Chris@283: */ Chris@283: Chris@283: #include "workstatuswidget.h" Chris@283: #include "debug.h" Chris@283: #include "clickablelabel.h" Chris@283: Chris@283: #include Chris@283: #include Chris@283: #include Chris@283: #include Chris@283: #include Chris@283: Chris@283: WorkStatusWidget::WorkStatusWidget(QWidget *parent) : Chris@283: QWidget(parent) Chris@283: { Chris@283: QGridLayout *layout = new QGridLayout; Chris@297: layout->setMargin(6); Chris@297: layout->setSpacing(6); Chris@283: setLayout(layout); Chris@283: Chris@283: int row = 0; Chris@283: Chris@283: #ifndef Q_OS_MAC Chris@283: layout->addItem(new QSpacerItem(1, 1), row, 0); Chris@283: ++row; Chris@283: #endif Chris@283: Chris@297: layout->addWidget(new QLabel(tr("Local:")), row, 1); Chris@283: Chris@283: m_openButton = new ClickableLabel; Chris@283: QFont f(m_openButton->font()); Chris@283: f.setBold(true); Chris@283: m_openButton->setFont(f); Chris@283: m_openButton->setMouseUnderline(true); Chris@283: connect(m_openButton, SIGNAL(clicked()), this, SLOT(openButtonClicked())); Chris@297: layout->addWidget(m_openButton, row, 2, 1, 2, Qt::AlignLeft); Chris@283: Chris@283: ++row; Chris@297: layout->addWidget(new QLabel(tr("Remote:")), row, 1); Chris@283: m_remoteURLLabel = new QLabel; Chris@297: layout->addWidget(m_remoteURLLabel, row, 2, 1, 2); Chris@283: Chris@283: ++row; Chris@297: layout->addWidget(new QLabel(tr("State:")), row, 1); Chris@283: m_stateLabel = new QLabel; Chris@297: layout->addWidget(m_stateLabel, row, 2, 1, 2); Chris@283: Chris@297: layout->setColumnStretch(2, 20); Chris@283: Chris@283: Chris@283: } Chris@283: Chris@283: WorkStatusWidget::~WorkStatusWidget() Chris@283: { Chris@283: } Chris@283: Chris@283: void Chris@283: WorkStatusWidget::setLocalPath(QString p) Chris@283: { Chris@283: m_localPath = p; Chris@283: m_openButton->setText(p); Chris@283: m_openButton->setEnabled(QDir(m_localPath).exists()); Chris@283: } Chris@283: Chris@283: void Chris@283: WorkStatusWidget::setRemoteURL(QString r) Chris@283: { Chris@283: m_remoteURL = r; Chris@283: m_remoteURLLabel->setText(r); Chris@283: } Chris@283: Chris@283: void Chris@283: WorkStatusWidget::setState(QString b) Chris@283: { Chris@283: m_state = b; Chris@283: updateStateLabel(); Chris@283: } Chris@283: Chris@283: void Chris@283: WorkStatusWidget::updateStateLabel() Chris@283: { Chris@283: m_stateLabel->setText(m_state); Chris@283: } Chris@283: Chris@283: void Chris@283: WorkStatusWidget::openButtonClicked() Chris@283: { Chris@283: QDir d(m_localPath); Chris@283: if (d.exists()) { Chris@283: QStringList args; Chris@283: QString path = d.canonicalPath(); Chris@283: #if defined Q_OS_WIN32 Chris@283: // Although the Win32 API is quite happy to have Chris@283: // forward slashes as directory separators, Windows Chris@283: // Explorer is not Chris@283: path = path.replace('/', '\\'); Chris@283: args << path; Chris@283: QProcess::execute("c:/windows/explorer.exe", args); Chris@283: #else Chris@283: args << path; Chris@283: QProcess::execute( Chris@283: #if defined Q_OS_MAC Chris@283: "/usr/bin/open", Chris@283: #else Chris@283: "/usr/bin/xdg-open", Chris@283: #endif Chris@283: args); Chris@283: #endif Chris@283: } Chris@283: }