1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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
16 ** GNU Lesser General Public License Usage
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.
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.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "basecheckoutwizardpage.h"
35 #include "ui_basecheckoutwizardpage.h"
37 #include <QtGui/QIcon>
41 struct BaseCheckoutWizardPagePrivate {
42 BaseCheckoutWizardPagePrivate() : m_valid(false), m_directoryEdited(false) {}
44 Ui::BaseCheckoutWizardPage ui;
46 bool m_directoryEdited;
49 BaseCheckoutWizardPage::BaseCheckoutWizardPage(QWidget *parent) :
51 d(new BaseCheckoutWizardPagePrivate)
55 connect(d->ui.repositoryLineEdit, SIGNAL(textChanged(QString)), this, SLOT(slotRepositoryChanged(QString)));
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()));
63 d->ui.pathChooser->setExpectedKind(Utils::PathChooser::Directory);
64 connect(d->ui.pathChooser, SIGNAL(validChanged()), this, SLOT(slotChanged()));
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()));
71 BaseCheckoutWizardPage::~BaseCheckoutWizardPage()
76 void BaseCheckoutWizardPage::addLocalControl(QWidget *w)
78 d->ui.localLayout->addRow(w);
81 void BaseCheckoutWizardPage::addLocalControl(QString &description, QWidget *w)
83 d->ui.localLayout->addRow(description, w);
86 void BaseCheckoutWizardPage::addRepositoryControl(QWidget *w)
88 d->ui.repositoryLayout->addRow(w);
91 bool BaseCheckoutWizardPage::checkIsValid() const
93 return d->ui.pathChooser->isValid()
94 && !d->ui.checkoutDirectoryLineEdit->text().isEmpty()
95 && !d->ui.repositoryLineEdit->text().isEmpty();
98 void BaseCheckoutWizardPage::addRepositoryControl(QString &description, QWidget *w)
100 d->ui.repositoryLayout->addRow(description, w);
103 bool BaseCheckoutWizardPage::isBranchSelectorVisible() const
105 return d->ui.branchComboBox->isVisible();
108 void BaseCheckoutWizardPage::setBranchSelectorVisible(bool v)
110 d->ui.branchComboBox->setVisible(v);
111 d->ui.branchRefreshToolButton->setVisible(v);
112 d->ui.branchLabel->setVisible(v);
115 void BaseCheckoutWizardPage::setRepositoryLabel(const QString &l)
117 d->ui.repositoryLabel->setText(l);
120 bool BaseCheckoutWizardPage::isRepositoryReadOnly() const
122 return d->ui.repositoryLineEdit->isReadOnly();
125 void BaseCheckoutWizardPage::setRepositoryReadOnly(bool v)
127 d->ui.repositoryLineEdit->setReadOnly(v);
130 QString BaseCheckoutWizardPage::path() const
132 return d->ui.pathChooser->path();
135 void BaseCheckoutWizardPage::setPath(const QString &p)
137 d->ui.pathChooser->setPath(p);
140 QString BaseCheckoutWizardPage::directory() const
142 return d->ui.checkoutDirectoryLineEdit->text();
145 void BaseCheckoutWizardPage::setDirectory(const QString &dir)
147 d->ui.checkoutDirectoryLineEdit->setText(dir);
150 void BaseCheckoutWizardPage::setDirectoryVisible(bool v)
152 d->ui.checkoutDirectoryLabel->setVisible(v);
153 d->ui.checkoutDirectoryLineEdit->setVisible(v);
156 QString BaseCheckoutWizardPage::repository() const
158 return d->ui.repositoryLineEdit->text().trimmed();
161 void BaseCheckoutWizardPage::setRepository(const QString &r)
163 d->ui.repositoryLineEdit->setText(r);
166 QString BaseCheckoutWizardPage::branch() const
168 return d->ui.branchComboBox->currentText();
171 void BaseCheckoutWizardPage::setBranch(const QString &b)
173 const int index = d->ui.branchComboBox->findText(b);
175 d->ui.branchComboBox->setCurrentIndex(index);
178 void BaseCheckoutWizardPage::slotRefreshBranches()
180 if (!isBranchSelectorVisible())
182 // Refresh branch list on demand. This is hard to make
183 // automagically since there can be network slowness/timeouts, etc.
185 const QStringList branchList = branches(repository(), ¤t);
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);
196 void BaseCheckoutWizardPage::slotRepositoryChanged(const QString &repo)
198 // Derive directory name from repository unless user manually edited it.
199 if (!d->m_directoryEdited)
200 d->ui.checkoutDirectoryLineEdit->setText(directoryFromRepository(repo));
204 QString BaseCheckoutWizardPage::directoryFromRepository(const QString &r) const
209 QStringList BaseCheckoutWizardPage::branches(const QString &, int *)
211 return QStringList();
214 void BaseCheckoutWizardPage::slotDirectoryEdited()
216 d->m_directoryEdited = true;
220 void BaseCheckoutWizardPage::changeEvent(QEvent *e)
222 QWizardPage::changeEvent(e);
224 case QEvent::LanguageChange:
225 d->ui.retranslateUi(this);
232 bool BaseCheckoutWizardPage::isComplete() const
237 void BaseCheckoutWizardPage::slotChanged()
239 const bool valid = checkIsValid();
241 if (valid != d->m_valid) {
243 emit completeChanged();
247 } // namespace VCSBase