OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / vcsbase / checkoutprogresswizardpage.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #include "checkoutprogresswizardpage.h"
34 #include "checkoutjobs.h"
35 #include "ui_checkoutprogresswizardpage.h"
36
37 #include <utils/qtcassert.h>
38
39 #include <QtGui/QApplication>
40 #include <QtGui/QCursor>
41
42 namespace VCSBase {
43 namespace Internal {
44
45 CheckoutProgressWizardPage::CheckoutProgressWizardPage(QWidget *parent) :
46     QWizardPage(parent),
47     ui(new Ui::CheckoutProgressWizardPage),
48     m_state(Idle)
49 {
50     ui->setupUi(this);
51     setTitle(tr("Checkout"));
52 }
53
54 CheckoutProgressWizardPage::~CheckoutProgressWizardPage()
55 {
56     if (m_state == Running) // Paranoia!
57         QApplication::restoreOverrideCursor();
58     delete ui;
59 }
60
61 void CheckoutProgressWizardPage::start(const QSharedPointer<AbstractCheckoutJob> &job)
62 {
63     QTC_ASSERT(m_state != Running, return)
64     m_job = job;
65     connect(job.data(), SIGNAL(output(QString)), ui->logPlainTextEdit, SLOT(appendPlainText(QString)));
66     connect(job.data(), SIGNAL(failed(QString)), this, SLOT(slotFailed(QString)));
67     connect(job.data(), SIGNAL(succeeded()), this, SLOT(slotSucceeded()));
68     QApplication::setOverrideCursor(Qt::WaitCursor);
69     ui->logPlainTextEdit->clear();
70     ui->statusLabel->setText(tr("Checkout started..."));
71     ui->statusLabel->setPalette(QPalette());
72     m_state = Running;
73     // Note: Process jobs can emit failed() right from
74     // the start() method on Windows.
75     job->start();
76 }
77
78 void CheckoutProgressWizardPage::slotFailed(const QString &why)
79 {
80     ui->logPlainTextEdit->appendPlainText(why);
81     if (m_state == Running) {
82         m_state = Failed;
83         QApplication::restoreOverrideCursor();
84         ui->statusLabel->setText(tr("Failed."));
85         QPalette palette = ui->statusLabel->palette();
86         palette.setColor(QPalette::Active, QPalette::Text, Qt::red);
87         ui->statusLabel->setPalette(palette);
88         emit terminated(false);
89     }
90 }
91
92 void CheckoutProgressWizardPage::slotSucceeded()
93 {
94     if (m_state == Running) {
95         m_state = Succeeded;
96         QApplication::restoreOverrideCursor();
97         ui->statusLabel->setText(tr("Succeeded."));
98         QPalette palette = ui->statusLabel->palette();
99         palette.setColor(QPalette::Active, QPalette::Text, Qt::green);
100         ui->statusLabel->setPalette(palette);
101         emit completeChanged();
102         emit terminated(true);
103     }
104 }
105
106 void CheckoutProgressWizardPage::terminate()
107 {
108     if (!m_job.isNull())
109         m_job->cancel();
110 }
111
112 bool CheckoutProgressWizardPage::isComplete() const
113 {
114     return m_state == Succeeded;
115 }
116
117 void CheckoutProgressWizardPage::changeEvent(QEvent *e)
118 {
119     QWizardPage::changeEvent(e);
120     switch (e->type()) {
121     case QEvent::LanguageChange:
122         ui->retranslateUi(this);
123         break;
124     default:
125         break;
126     }
127 }
128
129 } // namespace Internal
130 } // namespace VCSBase