2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-07-17 17:19:23 +02:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2009-07-17 17:19:23 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-07-17 17:19:23 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:58:39 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2009-07-17 17:19:23 +02:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-07-17 17:19:23 +02:00
|
|
|
|
2015-01-23 10:00:45 +01:00
|
|
|
#include "shellcommandpage.h"
|
|
|
|
|
#include "shellcommand.h"
|
|
|
|
|
#include "outputformatter.h"
|
|
|
|
|
#include "qtcassert.h"
|
|
|
|
|
#include "theme/theme.h"
|
2009-07-17 17:19:23 +02:00
|
|
|
|
2015-05-05 16:26:26 +02:00
|
|
|
#include <QAbstractButton>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QApplication>
|
2014-03-18 18:22:10 +02:00
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QPlainTextEdit>
|
|
|
|
|
#include <QVBoxLayout>
|
2009-07-17 17:19:23 +02:00
|
|
|
|
2011-03-28 14:19:17 +02:00
|
|
|
/*!
|
2015-01-23 10:00:45 +01:00
|
|
|
\class Utils::ShellCommandPage
|
2013-06-05 14:29:24 +02:00
|
|
|
|
2015-01-23 10:00:45 +01:00
|
|
|
\brief The ShellCommandPage implements a page showing the
|
|
|
|
|
progress of a \c ShellCommand.
|
2011-03-28 14:19:17 +02:00
|
|
|
|
2015-01-23 10:00:45 +01:00
|
|
|
Turns complete when the command succeeds.
|
2011-03-28 14:19:17 +02:00
|
|
|
*/
|
|
|
|
|
|
2015-01-23 10:00:45 +01:00
|
|
|
namespace Utils {
|
2009-07-17 17:19:23 +02:00
|
|
|
|
2015-01-23 10:00:45 +01:00
|
|
|
ShellCommandPage::ShellCommandPage(QWidget *parent) :
|
|
|
|
|
WizardPage(parent),
|
2016-12-05 20:01:41 +01:00
|
|
|
m_startedStatus(tr("Command started..."))
|
2009-07-17 17:19:23 +02:00
|
|
|
{
|
2014-03-18 18:22:10 +02:00
|
|
|
resize(264, 200);
|
2015-01-22 13:54:05 +01:00
|
|
|
auto verticalLayout = new QVBoxLayout(this);
|
2014-03-18 18:22:10 +02:00
|
|
|
m_logPlainTextEdit = new QPlainTextEdit;
|
2014-03-18 20:23:08 +02:00
|
|
|
m_formatter = new Utils::OutputFormatter;
|
2014-03-18 18:22:10 +02:00
|
|
|
m_logPlainTextEdit->setReadOnly(true);
|
2014-03-18 20:23:08 +02:00
|
|
|
m_formatter->setPlainTextEdit(m_logPlainTextEdit);
|
2014-03-18 18:22:10 +02:00
|
|
|
|
|
|
|
|
verticalLayout->addWidget(m_logPlainTextEdit);
|
|
|
|
|
|
|
|
|
|
m_statusLabel = new QLabel;
|
|
|
|
|
verticalLayout->addWidget(m_statusLabel);
|
2015-01-23 10:00:45 +01:00
|
|
|
setTitle(tr("Run Command"));
|
2009-07-17 17:19:23 +02:00
|
|
|
}
|
|
|
|
|
|
2015-01-23 10:00:45 +01:00
|
|
|
ShellCommandPage::~ShellCommandPage()
|
2009-07-17 17:19:23 +02:00
|
|
|
{
|
2014-11-06 12:30:39 +01:00
|
|
|
QTC_ASSERT(m_state != Running, QApplication::restoreOverrideCursor());
|
2014-03-18 20:23:08 +02:00
|
|
|
delete m_formatter;
|
2009-07-17 17:19:23 +02:00
|
|
|
}
|
|
|
|
|
|
2015-01-23 10:00:45 +01:00
|
|
|
void ShellCommandPage::setStartedStatus(const QString &startedStatus)
|
2013-08-29 13:37:45 +03:00
|
|
|
{
|
|
|
|
|
m_startedStatus = startedStatus;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-23 10:00:45 +01:00
|
|
|
void ShellCommandPage::start(ShellCommand *command)
|
2009-07-17 17:19:23 +02:00
|
|
|
{
|
2013-08-28 21:27:47 +03:00
|
|
|
if (!command) {
|
2014-03-18 18:22:10 +02:00
|
|
|
m_logPlainTextEdit->setPlainText(tr("No job running, please abort."));
|
2012-03-13 11:26:36 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(m_state != Running, return);
|
2013-08-28 21:27:47 +03:00
|
|
|
m_command = command;
|
|
|
|
|
command->setProgressiveOutput(true);
|
2016-01-26 22:57:51 +02:00
|
|
|
connect(command, &ShellCommand::stdOutText, this, [this](const QString &text) {
|
|
|
|
|
m_formatter->appendMessage(text, Utils::StdOutFormat);
|
|
|
|
|
});
|
|
|
|
|
connect(command, &ShellCommand::stdErrText, this, [this](const QString &text) {
|
|
|
|
|
m_formatter->appendMessage(text, Utils::StdErrFormat);
|
|
|
|
|
});
|
2015-01-23 10:00:45 +01:00
|
|
|
connect(command, &ShellCommand::finished, this, &ShellCommandPage::slotFinished);
|
2009-07-17 17:19:23 +02:00
|
|
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
2014-03-18 18:22:10 +02:00
|
|
|
m_logPlainTextEdit->clear();
|
2014-03-07 14:23:54 +01:00
|
|
|
m_overwriteOutput = false;
|
2014-03-18 18:22:10 +02:00
|
|
|
m_statusLabel->setText(m_startedStatus);
|
|
|
|
|
m_statusLabel->setPalette(QPalette());
|
2009-07-17 17:19:23 +02:00
|
|
|
m_state = Running;
|
2013-08-28 21:27:47 +03:00
|
|
|
command->execute();
|
2015-05-05 16:26:26 +02:00
|
|
|
|
|
|
|
|
wizard()->button(QWizard::BackButton)->setEnabled(false);
|
2009-07-17 17:19:23 +02:00
|
|
|
}
|
|
|
|
|
|
2015-01-23 10:00:45 +01:00
|
|
|
void ShellCommandPage::slotFinished(bool ok, int exitCode, const QVariant &)
|
2009-07-17 17:19:23 +02:00
|
|
|
{
|
2014-11-06 12:30:39 +01:00
|
|
|
QTC_ASSERT(m_state == Running, return);
|
|
|
|
|
|
|
|
|
|
const bool success = (ok && exitCode == 0);
|
|
|
|
|
QString message;
|
|
|
|
|
QPalette palette;
|
|
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
|
m_state = Succeeded;
|
|
|
|
|
message = tr("Succeeded.");
|
2015-01-23 10:00:45 +01:00
|
|
|
palette.setColor(QPalette::WindowText, creatorTheme()->color(Theme::TextColorNormal).name());
|
2013-08-28 21:27:47 +03:00
|
|
|
} else {
|
2014-11-06 12:30:39 +01:00
|
|
|
m_state = Failed;
|
|
|
|
|
message = tr("Failed.");
|
2015-01-23 10:00:45 +01:00
|
|
|
palette.setColor(QPalette::WindowText, creatorTheme()->color(Theme::TextColorError).name());
|
2009-07-17 17:19:23 +02:00
|
|
|
}
|
2014-11-06 12:30:39 +01:00
|
|
|
|
|
|
|
|
m_statusLabel->setText(message);
|
|
|
|
|
m_statusLabel->setPalette(palette);
|
|
|
|
|
|
|
|
|
|
QApplication::restoreOverrideCursor();
|
2015-05-05 16:26:26 +02:00
|
|
|
wizard()->button(QWizard::BackButton)->setEnabled(true);
|
2014-11-06 12:30:39 +01:00
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
emit completeChanged();
|
2015-01-23 10:00:45 +01:00
|
|
|
emit finished(success);
|
2009-07-17 17:19:23 +02:00
|
|
|
}
|
|
|
|
|
|
2015-01-23 10:00:45 +01:00
|
|
|
void ShellCommandPage::terminate()
|
2009-07-17 17:19:23 +02:00
|
|
|
{
|
2013-08-28 21:27:47 +03:00
|
|
|
if (m_command)
|
2013-09-22 13:13:38 +03:00
|
|
|
m_command->cancel();
|
2009-07-17 17:19:23 +02:00
|
|
|
}
|
|
|
|
|
|
2015-05-05 16:39:28 +02:00
|
|
|
bool ShellCommandPage::handleReject()
|
|
|
|
|
{
|
|
|
|
|
if (!isRunning())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
terminate();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-23 10:00:45 +01:00
|
|
|
bool ShellCommandPage::isComplete() const
|
2009-07-17 17:19:23 +02:00
|
|
|
{
|
|
|
|
|
return m_state == Succeeded;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-23 10:00:45 +01:00
|
|
|
} // namespace Utils
|