OSDN Git Service

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