annotate workstatuswidget.cpp @ 361:4cd753e083cc feature_91b

Add Rename and Copy to right-button menu on file status widget. (This is the real feature 91 -- I bungled the feature number with the earlier feature_91 branch, which actually addressed feature 106.)
author Chris Cannam
date Thu, 17 Mar 2011 17:34:23 +0000
parents e4284fab6962
children
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@297 56 layout->addWidget(m_remoteURLLabel, row, 2, 1, 2);
Chris@283 57
Chris@283 58 ++row;
Chris@297 59 layout->addWidget(new QLabel(tr("State:")), row, 1);
Chris@283 60 m_stateLabel = new QLabel;
Chris@297 61 layout->addWidget(m_stateLabel, row, 2, 1, 2);
Chris@283 62
Chris@297 63 layout->setColumnStretch(2, 20);
Chris@283 64
Chris@283 65
Chris@283 66 }
Chris@283 67
Chris@283 68 WorkStatusWidget::~WorkStatusWidget()
Chris@283 69 {
Chris@283 70 }
Chris@283 71
Chris@283 72 void
Chris@283 73 WorkStatusWidget::setLocalPath(QString p)
Chris@283 74 {
Chris@283 75 m_localPath = p;
Chris@283 76 m_openButton->setText(p);
Chris@283 77 m_openButton->setEnabled(QDir(m_localPath).exists());
Chris@283 78 }
Chris@283 79
Chris@283 80 void
Chris@283 81 WorkStatusWidget::setRemoteURL(QString r)
Chris@283 82 {
Chris@283 83 m_remoteURL = r;
Chris@283 84 m_remoteURLLabel->setText(r);
Chris@283 85 }
Chris@283 86
Chris@283 87 void
Chris@283 88 WorkStatusWidget::setState(QString b)
Chris@283 89 {
Chris@283 90 m_state = b;
Chris@283 91 updateStateLabel();
Chris@283 92 }
Chris@283 93
Chris@283 94 void
Chris@283 95 WorkStatusWidget::updateStateLabel()
Chris@283 96 {
Chris@283 97 m_stateLabel->setText(m_state);
Chris@283 98 }
Chris@283 99
Chris@283 100 void
Chris@283 101 WorkStatusWidget::openButtonClicked()
Chris@283 102 {
Chris@283 103 QDir d(m_localPath);
Chris@283 104 if (d.exists()) {
Chris@283 105 QStringList args;
Chris@283 106 QString path = d.canonicalPath();
Chris@283 107 #if defined Q_OS_WIN32
Chris@283 108 // Although the Win32 API is quite happy to have
Chris@283 109 // forward slashes as directory separators, Windows
Chris@283 110 // Explorer is not
Chris@283 111 path = path.replace('/', '\\');
Chris@283 112 args << path;
Chris@283 113 QProcess::execute("c:/windows/explorer.exe", args);
Chris@283 114 #else
Chris@283 115 args << path;
Chris@283 116 QProcess::execute(
Chris@283 117 #if defined Q_OS_MAC
Chris@283 118 "/usr/bin/open",
Chris@283 119 #else
Chris@283 120 "/usr/bin/xdg-open",
Chris@283 121 #endif
Chris@283 122 args);
Chris@283 123 #endif
Chris@283 124 }
Chris@283 125 }