annotate src/workstatuswidget.cpp @ 465:b57d50114d8d

Look up diff/merge paths again if current settings are found not to exist (fixes #111)
author Chris Cannam
date Mon, 04 Jul 2011 14:03:31 +0100
parents a206deb6c1aa
children 43ddfa5e9fd0
rev   line source
Chris@283 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@283 2
Chris@283 3 /*
Chris@283 4 EasyMercurial
Chris@283 5
Chris@283 6 Based on HgExplorer by Jari Korhonen
Chris@283 7 Copyright (c) 2010 Jari Korhonen
Chris@283 8 Copyright (c) 2011 Chris Cannam
Chris@283 9 Copyright (c) 2011 Queen Mary, University of London
Chris@283 10
Chris@283 11 This program is free software; you can redistribute it and/or
Chris@283 12 modify it under the terms of the GNU General Public License as
Chris@283 13 published by the Free Software Foundation; either version 2 of the
Chris@283 14 License, or (at your option) any later version. See the file
Chris@283 15 COPYING included with this distribution for more information.
Chris@283 16 */
Chris@283 17
Chris@283 18 #include "workstatuswidget.h"
Chris@283 19 #include "debug.h"
Chris@283 20 #include "clickablelabel.h"
Chris@283 21
Chris@283 22 #include <QGridLayout>
Chris@283 23 #include <QSpacerItem>
Chris@283 24 #include <QLabel>
Chris@283 25 #include <QProcess>
Chris@283 26 #include <QDir>
Chris@283 27
Chris@283 28 WorkStatusWidget::WorkStatusWidget(QWidget *parent) :
Chris@283 29 QWidget(parent)
Chris@283 30 {
Chris@283 31 QGridLayout *layout = new QGridLayout;
Chris@297 32 layout->setMargin(6);
Chris@297 33 layout->setSpacing(6);
Chris@283 34 setLayout(layout);
Chris@283 35
Chris@283 36 int row = 0;
Chris@283 37
Chris@283 38 #ifndef Q_OS_MAC
Chris@283 39 layout->addItem(new QSpacerItem(1, 1), row, 0);
Chris@283 40 ++row;
Chris@283 41 #endif
Chris@283 42
Chris@297 43 layout->addWidget(new QLabel(tr("Local:")), row, 1);
Chris@283 44
Chris@283 45 m_openButton = new ClickableLabel;
Chris@283 46 QFont f(m_openButton->font());
Chris@283 47 f.setBold(true);
Chris@283 48 m_openButton->setFont(f);
Chris@283 49 m_openButton->setMouseUnderline(true);
Chris@283 50 connect(m_openButton, SIGNAL(clicked()), this, SLOT(openButtonClicked()));
Chris@297 51 layout->addWidget(m_openButton, row, 2, 1, 2, Qt::AlignLeft);
Chris@283 52
Chris@283 53 ++row;
Chris@297 54 layout->addWidget(new QLabel(tr("Remote:")), row, 1);
Chris@283 55 m_remoteURLLabel = new QLabel;
Chris@375 56 m_remoteURLLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
Chris@297 57 layout->addWidget(m_remoteURLLabel, row, 2, 1, 2);
Chris@283 58
Chris@283 59 ++row;
Chris@297 60 layout->addWidget(new QLabel(tr("State:")), row, 1);
Chris@283 61 m_stateLabel = new QLabel;
Chris@297 62 layout->addWidget(m_stateLabel, row, 2, 1, 2);
Chris@283 63
Chris@297 64 layout->setColumnStretch(2, 20);
Chris@283 65
Chris@283 66
Chris@283 67 }
Chris@283 68
Chris@283 69 WorkStatusWidget::~WorkStatusWidget()
Chris@283 70 {
Chris@283 71 }
Chris@283 72
Chris@283 73 void
Chris@283 74 WorkStatusWidget::setLocalPath(QString p)
Chris@283 75 {
Chris@283 76 m_localPath = p;
Chris@283 77 m_openButton->setText(p);
Chris@283 78 m_openButton->setEnabled(QDir(m_localPath).exists());
Chris@283 79 }
Chris@283 80
Chris@283 81 void
Chris@283 82 WorkStatusWidget::setRemoteURL(QString r)
Chris@283 83 {
Chris@283 84 m_remoteURL = r;
Chris@283 85 m_remoteURLLabel->setText(r);
Chris@283 86 }
Chris@283 87
Chris@283 88 void
Chris@283 89 WorkStatusWidget::setState(QString b)
Chris@283 90 {
Chris@283 91 m_state = b;
Chris@283 92 updateStateLabel();
Chris@283 93 }
Chris@283 94
Chris@283 95 void
Chris@283 96 WorkStatusWidget::updateStateLabel()
Chris@283 97 {
Chris@283 98 m_stateLabel->setText(m_state);
Chris@283 99 }
Chris@283 100
Chris@283 101 void
Chris@283 102 WorkStatusWidget::openButtonClicked()
Chris@283 103 {
Chris@283 104 QDir d(m_localPath);
Chris@283 105 if (d.exists()) {
Chris@283 106 QStringList args;
Chris@283 107 QString path = d.canonicalPath();
Chris@283 108 #if defined Q_OS_WIN32
Chris@283 109 // Although the Win32 API is quite happy to have
Chris@283 110 // forward slashes as directory separators, Windows
Chris@283 111 // Explorer is not
Chris@283 112 path = path.replace('/', '\\');
Chris@283 113 args << path;
Chris@283 114 QProcess::execute("c:/windows/explorer.exe", args);
Chris@283 115 #else
Chris@283 116 args << path;
Chris@283 117 QProcess::execute(
Chris@283 118 #if defined Q_OS_MAC
Chris@283 119 "/usr/bin/open",
Chris@283 120 #else
Chris@283 121 "/usr/bin/xdg-open",
Chris@283 122 #endif
Chris@283 123 args);
Chris@283 124 #endif
Chris@283 125 }
Chris@283 126 }