OSDN Git Service

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