checkoutprogresswizardpage.cpp 4.93 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8 9 10 11 12
** 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
** a written agreement between you and Digia.  For licensing terms and
Eike Ziller's avatar
Eike Ziller committed
13 14
** conditions see http://www.qt.io/licensing.  For further information
** use the contact form at http://www.qt.io/contact-us.
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18 19 20 21 22 23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
hjk's avatar
hjk committed
24 25 26
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
27 28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
29
****************************************************************************/
30 31

#include "checkoutprogresswizardpage.h"
hjk's avatar
hjk committed
32
#include "vcscommand.h"
33
#include "vcsbaseplugin.h"
34

35
#include <utils/outputformatter.h>
36 37
#include <utils/qtcassert.h>

38
#include <QApplication>
39 40 41
#include <QLabel>
#include <QPlainTextEdit>
#include <QVBoxLayout>
42

43
/*!
44
    \class VcsBase::Internal::CheckoutProgressWizardPage
45

46 47 48 49
    \brief The CheckoutProgressWizardPage implements a page showing the
    progress of an initial project checkout.

    Turns complete when the job succeeds.
50

hjk's avatar
hjk committed
51
    \sa VcsBase::BaseCheckoutWizard
52 53
*/

hjk's avatar
hjk committed
54
namespace VcsBase {
55 56 57 58
namespace Internal {

CheckoutProgressWizardPage::CheckoutProgressWizardPage(QWidget *parent) :
    QWizardPage(parent),
59
    m_startedStatus(tr("Checkout started...")),
60
    m_overwriteOutput(false),
61 62
    m_state(Idle)
{
63 64 65
    resize(264, 200);
    QVBoxLayout *verticalLayout = new QVBoxLayout(this);
    m_logPlainTextEdit = new QPlainTextEdit;
66
    m_formatter = new Utils::OutputFormatter;
67
    m_logPlainTextEdit->setReadOnly(true);
68
    m_formatter->setPlainTextEdit(m_logPlainTextEdit);
69 70 71 72 73

    verticalLayout->addWidget(m_logPlainTextEdit);

    m_statusLabel = new QLabel;
    verticalLayout->addWidget(m_statusLabel);
74
    setTitle(tr("Checkout"));
75 76 77 78
}

CheckoutProgressWizardPage::~CheckoutProgressWizardPage()
{
79
    QTC_ASSERT(m_state != Running, QApplication::restoreOverrideCursor());
80
    delete m_formatter;
81 82
}

83 84 85 86 87
void CheckoutProgressWizardPage::setStartedStatus(const QString &startedStatus)
{
    m_startedStatus = startedStatus;
}

hjk's avatar
hjk committed
88
void CheckoutProgressWizardPage::start(VcsCommand *command)
89
{
90
    if (!command) {
91
        m_logPlainTextEdit->setPlainText(tr("No job running, please abort."));
92 93 94
        return;
    }

95
    QTC_ASSERT(m_state != Running, return);
96 97
    m_command = command;
    command->setProgressiveOutput(true);
98 99 100
    connect(command, &VcsCommand::output, this, &CheckoutProgressWizardPage::reportStdOut);
    connect(command, &VcsCommand::errorText, this, &CheckoutProgressWizardPage::reportStdErr);
    connect(command, &VcsCommand::finished, this, &CheckoutProgressWizardPage::slotFinished);
101
    QApplication::setOverrideCursor(Qt::WaitCursor);
102
    m_logPlainTextEdit->clear();
103
    m_overwriteOutput = false;
104 105
    m_statusLabel->setText(m_startedStatus);
    m_statusLabel->setPalette(QPalette());
106
    m_state = Running;
107
    command->execute();
108 109
}

110
void CheckoutProgressWizardPage::slotFinished(bool ok, int exitCode, const QVariant &)
111
{
112 113 114 115 116 117 118 119 120 121
    QTC_ASSERT(m_state == Running, return);

    const bool success = (ok && exitCode == 0);
    QString message;
    QPalette palette;

    if (success) {
        m_state = Succeeded;
        message = tr("Succeeded.");
        palette.setColor(QPalette::Active, QPalette::Text, Qt::green);
122
    } else {
123 124 125
        m_state = Failed;
        message = tr("Failed.");
        palette.setColor(QPalette::Active, QPalette::Text, Qt::red);
126
    }
127 128 129 130 131 132 133 134 135

    m_statusLabel->setText(message);
    m_statusLabel->setPalette(palette);

    QApplication::restoreOverrideCursor();

    if (success)
        emit completeChanged();
    emit terminated(success);
136 137
}

138
void CheckoutProgressWizardPage::reportStdOut(const QString &text)
139
{
140
    m_formatter->appendMessage(text, Utils::StdOutFormat);
141 142
}

143
void CheckoutProgressWizardPage::reportStdErr(const QString &text)
144
{
145
    m_formatter->appendMessage(text, Utils::StdErrFormat);
146 147 148 149
}

void CheckoutProgressWizardPage::terminate()
{
150
    if (m_command)
Orgad Shaneh's avatar
Orgad Shaneh committed
151
        m_command->cancel();
152 153 154 155 156 157 158 159
}

bool CheckoutProgressWizardPage::isComplete() const
{
    return m_state == Succeeded;
}

} // namespace Internal
hjk's avatar
hjk committed
160
} // namespace VcsBase