Commit f21d2023 authored by Tobias Hunger's avatar Tobias Hunger

Utils: Add a WizardPage to show progress of a ShellCommand

Use the new page in favor of the CheckoutProgressWizardPage.

Change-Id: I7801c146fa67d6fcf550616f3798a7a919aafb96
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
parent caca9dfa
......@@ -28,12 +28,11 @@
**
****************************************************************************/
#include "checkoutprogresswizardpage.h"
#include "vcscommand.h"
#include "vcsbaseplugin.h"
#include <utils/outputformatter.h>
#include <utils/qtcassert.h>
#include "shellcommandpage.h"
#include "shellcommand.h"
#include "outputformatter.h"
#include "qtcassert.h"
#include "theme/theme.h"
#include <QApplication>
#include <QLabel>
......@@ -41,22 +40,19 @@
#include <QVBoxLayout>
/*!
\class VcsBase::Internal::CheckoutProgressWizardPage
\brief The CheckoutProgressWizardPage implements a page showing the
progress of an initial project checkout.
\class Utils::ShellCommandPage
Turns complete when the job succeeds.
\brief The ShellCommandPage implements a page showing the
progress of a \c ShellCommand.
\sa VcsBase::BaseCheckoutWizard
Turns complete when the command succeeds.
*/
namespace VcsBase {
namespace Internal {
namespace Utils {
CheckoutProgressWizardPage::CheckoutProgressWizardPage(QWidget *parent) :
QWizardPage(parent),
m_startedStatus(tr("Checkout started...")),
ShellCommandPage::ShellCommandPage(QWidget *parent) :
WizardPage(parent),
m_startedStatus(tr("Command started...")),
m_overwriteOutput(false),
m_state(Idle)
{
......@@ -71,21 +67,21 @@ CheckoutProgressWizardPage::CheckoutProgressWizardPage(QWidget *parent) :
m_statusLabel = new QLabel;
verticalLayout->addWidget(m_statusLabel);
setTitle(tr("Checkout"));
setTitle(tr("Run Command"));
}
CheckoutProgressWizardPage::~CheckoutProgressWizardPage()
ShellCommandPage::~ShellCommandPage()
{
QTC_ASSERT(m_state != Running, QApplication::restoreOverrideCursor());
delete m_formatter;
}
void CheckoutProgressWizardPage::setStartedStatus(const QString &startedStatus)
void ShellCommandPage::setStartedStatus(const QString &startedStatus)
{
m_startedStatus = startedStatus;
}
void CheckoutProgressWizardPage::start(VcsCommand *command)
void ShellCommandPage::start(ShellCommand *command)
{
if (!command) {
m_logPlainTextEdit->setPlainText(tr("No job running, please abort."));
......@@ -95,9 +91,9 @@ void CheckoutProgressWizardPage::start(VcsCommand *command)
QTC_ASSERT(m_state != Running, return);
m_command = command;
command->setProgressiveOutput(true);
connect(command, &VcsCommand::stdOutText, this, &CheckoutProgressWizardPage::reportStdOut);
connect(command, &VcsCommand::stdErrText, this, &CheckoutProgressWizardPage::reportStdErr);
connect(command, &VcsCommand::finished, this, &CheckoutProgressWizardPage::slotFinished);
connect(command, &ShellCommand::stdOutText, this, &ShellCommandPage::reportStdOut);
connect(command, &ShellCommand::stdErrText, this, &ShellCommandPage::reportStdErr);
connect(command, &ShellCommand::finished, this, &ShellCommandPage::slotFinished);
QApplication::setOverrideCursor(Qt::WaitCursor);
m_logPlainTextEdit->clear();
m_overwriteOutput = false;
......@@ -107,7 +103,7 @@ void CheckoutProgressWizardPage::start(VcsCommand *command)
command->execute();
}
void CheckoutProgressWizardPage::slotFinished(bool ok, int exitCode, const QVariant &)
void ShellCommandPage::slotFinished(bool ok, int exitCode, const QVariant &)
{
QTC_ASSERT(m_state == Running, return);
......@@ -118,11 +114,11 @@ void CheckoutProgressWizardPage::slotFinished(bool ok, int exitCode, const QVari
if (success) {
m_state = Succeeded;
message = tr("Succeeded.");
palette.setColor(QPalette::Active, QPalette::Text, Qt::green);
palette.setColor(QPalette::WindowText, creatorTheme()->color(Theme::TextColorNormal).name());
} else {
m_state = Failed;
message = tr("Failed.");
palette.setColor(QPalette::Active, QPalette::Text, Qt::red);
palette.setColor(QPalette::WindowText, creatorTheme()->color(Theme::TextColorError).name());
}
m_statusLabel->setText(message);
......@@ -132,29 +128,28 @@ void CheckoutProgressWizardPage::slotFinished(bool ok, int exitCode, const QVari
if (success)
emit completeChanged();
emit terminated(success);
emit finished(success);
}
void CheckoutProgressWizardPage::reportStdOut(const QString &text)
void ShellCommandPage::reportStdOut(const QString &text)
{
m_formatter->appendMessage(text, Utils::StdOutFormat);
}
void CheckoutProgressWizardPage::reportStdErr(const QString &text)
void ShellCommandPage::reportStdErr(const QString &text)
{
m_formatter->appendMessage(text, Utils::StdErrFormat);
}
void CheckoutProgressWizardPage::terminate()
void ShellCommandPage::terminate()
{
if (m_command)
m_command->cancel();
}
bool CheckoutProgressWizardPage::isComplete() const
bool ShellCommandPage::isComplete() const
{
return m_state == Succeeded;
}
} // namespace Internal
} // namespace VcsBase
} // namespace Utils
......@@ -28,36 +28,34 @@
**
****************************************************************************/
#ifndef CHECKOUTPROGRESSWIZARDPAGE_H
#define CHECKOUTPROGRESSWIZARDPAGE_H
#ifndef SHELLCOMMANDPAGE_H
#define SHELLCOMMANDPAGE_H
#include <QSharedPointer>
#include <QWizardPage>
#include "utils_global.h"
#include "wizardpage.h"
QT_BEGIN_NAMESPACE
class QPlainTextEdit;
class QLabel;
QT_END_NAMESPACE
namespace Utils { class OutputFormatter; }
namespace VcsBase {
class VcsCommand;
namespace Internal {
namespace Utils {
class OutputFormatter;
class ShellCommand;
class CheckoutProgressWizardPage : public QWizardPage
class QTCREATOR_UTILS_EXPORT ShellCommandPage : public WizardPage
{
Q_OBJECT
public:
enum State { Idle, Running, Failed, Succeeded };
explicit CheckoutProgressWizardPage(QWidget *parent = 0);
~CheckoutProgressWizardPage();
explicit ShellCommandPage(QWidget *parent = 0);
~ShellCommandPage();
void setStartedStatus(const QString &startedStatus);
void start(VcsCommand *command);
void start(ShellCommand *command);
virtual bool isComplete() const;
bool isRunning() const{ return m_state == Running; }
......@@ -65,26 +63,24 @@ public:
void terminate();
signals:
void terminated(bool success);
void finished(bool success);
private slots:
private:
void slotFinished(bool ok, int exitCode, const QVariant &cookie);
void reportStdOut(const QString &text);
void reportStdErr(const QString &text);
private:
QPlainTextEdit *m_logPlainTextEdit;
Utils::OutputFormatter *m_formatter;
OutputFormatter *m_formatter;
QLabel *m_statusLabel;
VcsCommand *m_command;
ShellCommand *m_command;
QString m_startedStatus;
bool m_overwriteOutput;
State m_state;
};
} // namespace Internal
} // namespace VcsBase
} // namespace Utils
#endif // CHECKOUTPROGRESSWIZARDPAGE_H
#endif // SHELLCOMMANDPAGE_H
......@@ -13,6 +13,7 @@ SOURCES += $$PWD/environment.cpp \
$$PWD/qtcprocess.cpp \
$$PWD/reloadpromptutils.cpp \
$$PWD/shellcommand.cpp \
$$PWD/shellcommandpage.cpp \
$$PWD/settingsselector.cpp \
$$PWD/stringutils.cpp \
$$PWD/textfieldcheckbox.cpp \
......@@ -101,6 +102,7 @@ HEADERS += \
$$PWD/reloadpromptutils.h \
$$PWD/settingsselector.h \
$$PWD/shellcommand.h \
$$PWD/shellcommandpage.h \
$$PWD/stringutils.h \
$$PWD/textfieldcheckbox.h \
$$PWD/textfieldcombobox.h \
......
......@@ -162,6 +162,8 @@ QtcLibrary {
"settingsutils.h",
"shellcommand.cpp",
"shellcommand.h",
"shellcommandpage.cpp",
"shellcommandpage.h",
"sleep.cpp",
"sleep.h",
"statuslabel.cpp",
......
......@@ -73,6 +73,10 @@ VcsCommand *CheckoutWizard::createCommand(Utils::FileName *checkoutDir)
const Utils::FileName binary = settings.binaryPath();
QStringList args;
// cwp->repository() contains the CVS module to check out only.
// The CVSROOT (== actual repository) for that module is part of the CVS settings.
// The checkout will always go into a new subfolder named after the CVS module.
const QString repository = cwp->repository();
args << QLatin1String("checkout") << repository;
const QString workingDirectory = cwp->path();
......
......@@ -30,9 +30,10 @@
#include "basecheckoutwizard.h"
#include "basecheckoutwizardfactory.h"
#include "checkoutprogresswizardpage.h"
#include "vcscommand.h"
#include <utils/qtcassert.h>
#include <utils/shellcommandpage.h>
#include <QPushButton>
......@@ -47,12 +48,12 @@ namespace VcsBase {
BaseCheckoutWizard::BaseCheckoutWizard(const Utils::FileName &path, QWidget *parent) :
Utils::Wizard(parent),
m_progressPage(new Internal::CheckoutProgressWizardPage),
m_progressPage(new Utils::ShellCommandPage),
m_progressPageId(-1)
{
Q_UNUSED(path);
connect(this, &QWizard::currentIdChanged, this, &BaseCheckoutWizard::slotPageChanged);
connect(m_progressPage, &Internal::CheckoutProgressWizardPage::terminated,
connect(m_progressPage, &Utils::ShellCommandPage::finished,
this, &BaseCheckoutWizard::slotTerminated);
setOption(QWizard::NoBackButtonOnLastPage);
}
......
......@@ -36,11 +36,11 @@
#include <utils/fileutils.h>
#include <utils/wizard.h>
namespace Utils { class ShellCommandPage; }
namespace VcsBase {
class VcsCommand;
namespace Internal { class CheckoutProgressWizardPage; }
class VCSBASE_EXPORT BaseCheckoutWizard : public Utils::Wizard
{
Q_OBJECT
......@@ -62,7 +62,7 @@ private slots:
virtual void reject();
private:
Internal::CheckoutProgressWizardPage *m_progressPage;
Utils::ShellCommandPage *m_progressPage;
int m_progressPageId;
Utils::FileName m_checkoutDir;
};
......
......@@ -21,7 +21,6 @@ HEADERS += vcsbase_global.h \
nicknamedialog.h \
basecheckoutwizardfactory.h \
basecheckoutwizard.h \
checkoutprogresswizardpage.h \
basecheckoutwizardpage.h \
vcsoutputwindow.h \
cleandialog.h \
......@@ -52,7 +51,6 @@ SOURCES += vcsplugin.cpp \
nicknamedialog.cpp \
basecheckoutwizardfactory.cpp \
basecheckoutwizard.cpp \
checkoutprogresswizardpage.cpp \
basecheckoutwizardpage.cpp \
vcsoutputwindow.cpp \
cleandialog.cpp \
......
......@@ -27,8 +27,6 @@ QtcPlugin {
"basevcseditorfactory.h",
"basevcssubmiteditorfactory.cpp",
"basevcssubmiteditorfactory.h",
"checkoutprogresswizardpage.cpp",
"checkoutprogresswizardpage.h",
"cleandialog.cpp",
"cleandialog.h",
"cleandialog.ui",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment