Commit 45b4ff4e authored by Friedemann Kleint's avatar Friedemann Kleint Committed by Tobias Hunger
Browse files

Gerrit: Disable buttons while fetch operation is in progress.



Gerrit operations should not be started in parallel since
they use FETCH_HEAD, which can cause mix-ups.

Change-Id: Icb421c8065f680a4bb93acd63e1ffe6309ce774a
Reviewed-by: default avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent ef65ce48
......@@ -104,6 +104,7 @@ GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &p,
, m_queryLineEdit(new QueryValidatingLineEdit)
, m_filterLineEdit(new Utils::FilterLineEdit)
, m_buttonBox(new QDialogButtonBox(QDialogButtonBox::Close))
, m_fetchRunning(false)
{
setWindowTitle(tr("Gerrit %1@%2").arg(p->user, p->host));
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
......@@ -266,6 +267,14 @@ const QStandardItem *GerritDialog::currentItem(int column) const
return 0;
}
void GerritDialog::updateButtons()
{
const bool enabled = !m_fetchRunning && m_treeView->selectionModel()->currentIndex().isValid();
m_displayButton->setEnabled(enabled);
m_applyButton->setEnabled(enabled);
m_checkoutButton->setEnabled(enabled);
}
void GerritDialog::slotCurrentChanged()
{
const QModelIndex current = m_treeView->selectionModel()->currentIndex();
......@@ -276,9 +285,27 @@ void GerritDialog::slotCurrentChanged()
} else {
m_detailsBrowser->setText(QString());
}
m_displayButton->setEnabled(valid);
m_applyButton->setEnabled(valid);
m_checkoutButton->setEnabled(valid);
updateButtons();
}
void GerritDialog::fetchStarted(const QSharedPointer<Gerrit::Internal::GerritChange> &change)
{
// Disable buttons to prevent parallel gerrit operations which can cause mix-ups.
m_fetchRunning = true;
updateButtons();
const QString toolTip = tr("Fetching \"%1\"...").arg(change->title);
m_displayButton->setToolTip(toolTip);
m_applyButton->setToolTip(toolTip);
m_checkoutButton->setToolTip(toolTip);
}
void GerritDialog::fetchFinished()
{
m_fetchRunning = false;
updateButtons();
m_displayButton->setToolTip(QString());
m_applyButton->setToolTip(QString());
m_checkoutButton->setToolTip(QString());
}
} // namespace Internal
......
......@@ -84,6 +84,10 @@ signals:
void fetchApply(const QSharedPointer<Gerrit::Internal::GerritChange> &);
void fetchCheckout(const QSharedPointer<Gerrit::Internal::GerritChange> &);
public slots:
void fetchStarted(const QSharedPointer<Gerrit::Internal::GerritChange> &change);
void fetchFinished();
private slots:
void slotCurrentChanged();
void slotDoubleClicked(const QModelIndex &);
......@@ -98,6 +102,7 @@ private:
const QStandardItem *currentItem(int column = 0) const;
QPushButton *addActionButton(const QString &text, const char *buttonSlot);
void updateCompletions(const QString &query);
void updateButtons();
const QSharedPointer<GerritParameters> m_parameters;
QSortFilterProxyModel *m_filterModel;
......@@ -112,6 +117,7 @@ private:
QPushButton *m_applyButton;
QPushButton *m_checkoutButton;
QPushButton *m_refreshButton;
bool m_fetchRunning;
};
} // namespace Internal
......
......@@ -372,6 +372,9 @@ void GerritPlugin::openView()
this, SLOT(fetchApply(QSharedPointer<Gerrit::Internal::GerritChange>)));
connect(gd, SIGNAL(fetchCheckout(QSharedPointer<Gerrit::Internal::GerritChange>)),
this, SLOT(fetchCheckout(QSharedPointer<Gerrit::Internal::GerritChange>)));
connect(this, SIGNAL(fetchStarted(QSharedPointer<Gerrit::Internal::GerritChange>)),
gd, SLOT(fetchStarted(QSharedPointer<Gerrit::Internal::GerritChange>)));
connect(this, SIGNAL(fetchFinished()), gd, SLOT(fetchFinished()));
m_dialog = gd;
}
const Qt::WindowStates state = m_dialog.data()->windowState();
......@@ -442,6 +445,8 @@ void GerritPlugin::fetch(const QSharedPointer<Gerrit::Internal::GerritChange> &c
FetchContext *fc = new FetchContext(change, repository, git,
m_parameters, FetchMode(mode), this);
connect(fc, SIGNAL(destroyed(QObject*)), this, SIGNAL(fetchFinished()));
emit fetchStarted(change);
fc->start();
}
......
......@@ -62,6 +62,10 @@ public slots:
void fetchApply(const QSharedPointer<Gerrit::Internal::GerritChange> &change);
void fetchCheckout(const QSharedPointer<Gerrit::Internal::GerritChange> &change);
signals:
void fetchStarted(const QSharedPointer<Gerrit::Internal::GerritChange> &change);
void fetchFinished();
private slots:
void openView();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment