OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / vcsbase / basecheckoutwizardpage.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 "basecheckoutwizardpage.h"
34 #include "ui_basecheckoutwizardpage.h"
35
36 #include <QtGui/QIcon>
37
38 namespace VCSBase {
39
40 struct BaseCheckoutWizardPagePrivate {
41     BaseCheckoutWizardPagePrivate() : m_valid(false), m_directoryEdited(false) {}
42
43     Ui::BaseCheckoutWizardPage ui;
44     bool m_valid;
45     bool m_directoryEdited;
46 };
47
48 BaseCheckoutWizardPage::BaseCheckoutWizardPage(QWidget *parent) :
49     QWizardPage(parent),
50     d(new BaseCheckoutWizardPagePrivate)
51 {
52     d->ui.setupUi(this);
53
54     connect(d->ui.repositoryLineEdit, SIGNAL(textChanged(QString)), this, SLOT(slotRepositoryChanged(QString)));
55
56     connect(d->ui.checkoutDirectoryLineEdit, SIGNAL(textChanged(QString)),
57             this, SLOT(slotChanged()));
58     connect(d->ui.checkoutDirectoryLineEdit, SIGNAL(textEdited(QString)), this, SLOT(slotDirectoryEdited()));
59     connect(d->ui.branchComboBox, SIGNAL(currentIndexChanged(int)),
60             this, SLOT(slotChanged()));
61
62     d->ui.pathChooser->setExpectedKind(Utils::PathChooser::ExistingDirectory);
63     connect(d->ui.pathChooser, SIGNAL(validChanged()), this, SLOT(slotChanged()));
64
65     d->ui.branchComboBox->setEnabled(false);
66     d->ui.branchRefreshToolButton->setIcon(QIcon(QLatin1String(":/locator/images/reload.png")));
67     connect(d->ui.branchRefreshToolButton, SIGNAL(clicked()), this, SLOT(slotRefreshBranches()));
68 }
69
70 BaseCheckoutWizardPage::~BaseCheckoutWizardPage()
71 {
72     delete d;
73 }
74
75 void BaseCheckoutWizardPage::addLocalControl(QWidget *w)
76 {
77     d->ui.localLayout->addRow(w);
78 }
79
80 void BaseCheckoutWizardPage::addLocalControl(QString &description, QWidget *w)
81 {
82     d->ui.localLayout->addRow(description, w);
83 }
84
85 void BaseCheckoutWizardPage::addRepositoryControl(QWidget *w)
86 {
87     d->ui.repositoryLayout->addRow(w);
88 }
89
90 bool BaseCheckoutWizardPage::checkIsValid() const
91 {
92     return d->ui.pathChooser->isValid()
93             && !d->ui.checkoutDirectoryLineEdit->text().isEmpty()
94             && !d->ui.repositoryLineEdit->text().isEmpty();
95 }
96
97 void BaseCheckoutWizardPage::addRepositoryControl(QString &description, QWidget *w)
98 {
99     d->ui.repositoryLayout->addRow(description, w);
100 }
101
102 bool BaseCheckoutWizardPage::isBranchSelectorVisible() const
103 {
104     return d->ui.branchComboBox->isVisible();
105 }
106
107 void BaseCheckoutWizardPage::setBranchSelectorVisible(bool v)
108 {
109     d->ui.branchComboBox->setVisible(v);
110     d->ui.branchRefreshToolButton->setVisible(v);
111     d->ui.branchLabel->setVisible(v);
112 }
113
114 void BaseCheckoutWizardPage::setRepositoryLabel(const QString &l)
115 {
116     d->ui.repositoryLabel->setText(l);
117 }
118
119 bool BaseCheckoutWizardPage::isRepositoryReadOnly() const
120 {
121     return d->ui.repositoryLineEdit->isReadOnly();
122 }
123
124 void BaseCheckoutWizardPage::setRepositoryReadOnly(bool v)
125 {
126     d->ui.repositoryLineEdit->setReadOnly(v);
127 }
128
129 QString BaseCheckoutWizardPage::path() const
130 {
131     return d->ui.pathChooser->path();
132 }
133
134 void BaseCheckoutWizardPage::setPath(const QString &p)
135 {
136     d->ui.pathChooser->setPath(p);
137 }
138
139 QString BaseCheckoutWizardPage::directory() const
140 {
141     return d->ui.checkoutDirectoryLineEdit->text();
142 }
143
144 void BaseCheckoutWizardPage::setDirectory(const QString &dir)
145 {
146     d->ui.checkoutDirectoryLineEdit->setText(dir);
147 }
148
149 void BaseCheckoutWizardPage::setDirectoryVisible(bool v)
150 {
151     d->ui.checkoutDirectoryLabel->setVisible(v);
152     d->ui.checkoutDirectoryLineEdit->setVisible(v);
153 }
154
155 QString BaseCheckoutWizardPage::repository() const
156 {
157     return d->ui.repositoryLineEdit->text().trimmed();
158 }
159
160 void BaseCheckoutWizardPage::setRepository(const QString &r)
161 {
162     d->ui.repositoryLineEdit->setText(r);
163 }
164
165 QString BaseCheckoutWizardPage::branch() const
166 {
167     return d->ui.branchComboBox->currentText();
168 }
169
170 void BaseCheckoutWizardPage::setBranch(const QString &b)
171 {
172     const int index = d->ui.branchComboBox->findText(b);
173     if (index != -1)
174         d->ui.branchComboBox->setCurrentIndex(index);
175 }
176
177 void BaseCheckoutWizardPage::slotRefreshBranches()
178 {
179     if (!isBranchSelectorVisible())
180         return;
181     // Refresh branch list on demand. This is hard to make
182     // automagically since there can be network slowness/timeouts, etc.
183     int current;
184     const QStringList branchList = branches(repository(), &current);
185     d->ui.branchComboBox->clear();
186     d->ui.branchComboBox->setEnabled(branchList.size() > 1);
187     if (!branchList.isEmpty()) {
188         d->ui.branchComboBox->addItems(branchList);
189         if (current >= 0 && current < branchList.size())
190             d->ui.branchComboBox->setCurrentIndex(current);
191     }
192     slotChanged();
193 }
194
195 void BaseCheckoutWizardPage::slotRepositoryChanged(const QString &repo)
196 {
197     // Derive directory name from repository unless user manually edited it.
198     if (!d->m_directoryEdited)
199         d->ui.checkoutDirectoryLineEdit->setText(directoryFromRepository(repo));
200     slotChanged();
201 }
202
203 QString BaseCheckoutWizardPage::directoryFromRepository(const QString &r) const
204 {
205     return r;
206 }
207
208 QStringList BaseCheckoutWizardPage::branches(const QString &, int *)
209 {
210     return QStringList();
211 }
212
213 void BaseCheckoutWizardPage::slotDirectoryEdited()
214 {
215     d->m_directoryEdited = true;
216     slotChanged();
217 }
218
219 void BaseCheckoutWizardPage::changeEvent(QEvent *e)
220 {
221     QWizardPage::changeEvent(e);
222     switch (e->type()) {
223     case QEvent::LanguageChange:
224         d->ui.retranslateUi(this);
225         break;
226     default:
227         break;
228     }
229 }
230
231 bool BaseCheckoutWizardPage::isComplete() const
232 {
233     return d->m_valid;
234 }
235
236 void BaseCheckoutWizardPage::slotChanged()
237 {
238     const bool valid = checkIsValid();
239
240     if (valid != d->m_valid) {
241         d->m_valid = valid;
242         emit completeChanged();
243     }
244 }
245
246 } // namespace VCSBase