1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
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.
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "basecheckoutwizardpage.h"
34 #include "ui_basecheckoutwizardpage.h"
36 #include <QtGui/QIcon>
40 struct BaseCheckoutWizardPagePrivate {
41 BaseCheckoutWizardPagePrivate() : m_valid(false), m_directoryEdited(false) {}
43 Ui::BaseCheckoutWizardPage ui;
45 bool m_directoryEdited;
48 BaseCheckoutWizardPage::BaseCheckoutWizardPage(QWidget *parent) :
50 d(new BaseCheckoutWizardPagePrivate)
54 connect(d->ui.repositoryLineEdit, SIGNAL(textChanged(QString)), this, SLOT(slotRepositoryChanged(QString)));
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()));
62 d->ui.pathChooser->setExpectedKind(Utils::PathChooser::ExistingDirectory);
63 connect(d->ui.pathChooser, SIGNAL(validChanged()), this, SLOT(slotChanged()));
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()));
70 BaseCheckoutWizardPage::~BaseCheckoutWizardPage()
75 void BaseCheckoutWizardPage::addLocalControl(QWidget *w)
77 d->ui.localLayout->addRow(w);
80 void BaseCheckoutWizardPage::addLocalControl(QString &description, QWidget *w)
82 d->ui.localLayout->addRow(description, w);
85 void BaseCheckoutWizardPage::addRepositoryControl(QWidget *w)
87 d->ui.repositoryLayout->addRow(w);
90 bool BaseCheckoutWizardPage::checkIsValid() const
92 return d->ui.pathChooser->isValid()
93 && !d->ui.checkoutDirectoryLineEdit->text().isEmpty()
94 && !d->ui.repositoryLineEdit->text().isEmpty();
97 void BaseCheckoutWizardPage::addRepositoryControl(QString &description, QWidget *w)
99 d->ui.repositoryLayout->addRow(description, w);
102 bool BaseCheckoutWizardPage::isBranchSelectorVisible() const
104 return d->ui.branchComboBox->isVisible();
107 void BaseCheckoutWizardPage::setBranchSelectorVisible(bool v)
109 d->ui.branchComboBox->setVisible(v);
110 d->ui.branchRefreshToolButton->setVisible(v);
111 d->ui.branchLabel->setVisible(v);
114 void BaseCheckoutWizardPage::setRepositoryLabel(const QString &l)
116 d->ui.repositoryLabel->setText(l);
119 bool BaseCheckoutWizardPage::isRepositoryReadOnly() const
121 return d->ui.repositoryLineEdit->isReadOnly();
124 void BaseCheckoutWizardPage::setRepositoryReadOnly(bool v)
126 d->ui.repositoryLineEdit->setReadOnly(v);
129 QString BaseCheckoutWizardPage::path() const
131 return d->ui.pathChooser->path();
134 void BaseCheckoutWizardPage::setPath(const QString &p)
136 d->ui.pathChooser->setPath(p);
139 QString BaseCheckoutWizardPage::directory() const
141 return d->ui.checkoutDirectoryLineEdit->text();
144 void BaseCheckoutWizardPage::setDirectory(const QString &dir)
146 d->ui.checkoutDirectoryLineEdit->setText(dir);
149 void BaseCheckoutWizardPage::setDirectoryVisible(bool v)
151 d->ui.checkoutDirectoryLabel->setVisible(v);
152 d->ui.checkoutDirectoryLineEdit->setVisible(v);
155 QString BaseCheckoutWizardPage::repository() const
157 return d->ui.repositoryLineEdit->text().trimmed();
160 void BaseCheckoutWizardPage::setRepository(const QString &r)
162 d->ui.repositoryLineEdit->setText(r);
165 QString BaseCheckoutWizardPage::branch() const
167 return d->ui.branchComboBox->currentText();
170 void BaseCheckoutWizardPage::setBranch(const QString &b)
172 const int index = d->ui.branchComboBox->findText(b);
174 d->ui.branchComboBox->setCurrentIndex(index);
177 void BaseCheckoutWizardPage::slotRefreshBranches()
179 if (!isBranchSelectorVisible())
181 // Refresh branch list on demand. This is hard to make
182 // automagically since there can be network slowness/timeouts, etc.
184 const QStringList branchList = branches(repository(), ¤t);
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);
195 void BaseCheckoutWizardPage::slotRepositoryChanged(const QString &repo)
197 // Derive directory name from repository unless user manually edited it.
198 if (!d->m_directoryEdited)
199 d->ui.checkoutDirectoryLineEdit->setText(directoryFromRepository(repo));
203 QString BaseCheckoutWizardPage::directoryFromRepository(const QString &r) const
208 QStringList BaseCheckoutWizardPage::branches(const QString &, int *)
210 return QStringList();
213 void BaseCheckoutWizardPage::slotDirectoryEdited()
215 d->m_directoryEdited = true;
219 void BaseCheckoutWizardPage::changeEvent(QEvent *e)
221 QWizardPage::changeEvent(e);
223 case QEvent::LanguageChange:
224 d->ui.retranslateUi(this);
231 bool BaseCheckoutWizardPage::isComplete() const
236 void BaseCheckoutWizardPage::slotChanged()
238 const bool valid = checkIsValid();
240 if (valid != d->m_valid) {
242 emit completeChanged();
246 } // namespace VCSBase