diff options
author | Tobias Hunger <tobias.hunger@nokia.com> | 2010-10-04 15:37:15 +0200 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@nokia.com> | 2010-10-04 15:49:22 +0200 |
commit | c7142affef4b4ea78306254b62da13d66f9be0af (patch) | |
tree | 9e01360bc8a052f8bb1d07c40d17ebf3f8c51a57 /src/plugins/git/gitsubmiteditorwidget.cpp | |
parent | 685ae6bc55f8a0b5fb94c059daa1f414aa57e6eb (diff) | |
download | qt-creator-c7142affef4b4ea78306254b62da13d66f9be0af.tar.gz |
Git: Only allow commit if author information is valid
Check author information to be valid before enableing
the commit button.
Task-number: QTCREATORBUG-2410
Diffstat (limited to 'src/plugins/git/gitsubmiteditorwidget.cpp')
-rw-r--r-- | src/plugins/git/gitsubmiteditorwidget.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/plugins/git/gitsubmiteditorwidget.cpp b/src/plugins/git/gitsubmiteditorwidget.cpp index 1a02f4a8a1..5014a8b20f 100644 --- a/src/plugins/git/gitsubmiteditorwidget.cpp +++ b/src/plugins/git/gitsubmiteditorwidget.cpp @@ -34,10 +34,13 @@ #include <texteditor/fontsettings.h> #include <texteditor/texteditorconstants.h> +#include <QtGui/QLineEdit> +#include <QtGui/QRegExpValidator> #include <QtGui/QSyntaxHighlighter> #include <QtGui/QTextEdit> #include <QtCore/QDebug> +#include <QtCore/QDir> #include <QtCore/QRegExp> namespace Git { @@ -116,11 +119,19 @@ GitSubmitEditorWidget::GitSubmitEditorWidget(QWidget *parent) : m_gitSubmitPanelUi.setupUi(m_gitSubmitPanel); insertTopWidget(m_gitSubmitPanel); new GitSubmitHighlighter(descriptionEdit()); + + m_emailValidator = new QRegExpValidator(QRegExp(QLatin1String("[^@ ]+@[^@ ]+\\.[a-zA-Z]+")), this); + + m_gitSubmitPanelUi.emailLineEdit->setValidator(m_emailValidator); + connect(m_gitSubmitPanelUi.authorLineEdit, SIGNAL(textChanged(QString)), + this, SLOT(authorInformationChanged())); + connect(m_gitSubmitPanelUi.emailLineEdit, SIGNAL(textChanged(QString)), + this, SLOT(authorInformationChanged())); } void GitSubmitEditorWidget::setPanelInfo(const GitSubmitEditorPanelInfo &info) { - m_gitSubmitPanelUi.repositoryLabel->setText(info.repository); + m_gitSubmitPanelUi.repositoryLabel->setText(QDir::toNativeSeparators(info.repository)); m_gitSubmitPanelUi.branchLabel->setText(info.branch); } @@ -136,6 +147,32 @@ void GitSubmitEditorWidget::setPanelData(const GitSubmitEditorPanelData &data) { m_gitSubmitPanelUi.authorLineEdit->setText(data.author); m_gitSubmitPanelUi.emailLineEdit->setText(data.email); + authorInformationChanged(); +} + +bool GitSubmitEditorWidget::canSubmit() const +{ + if (m_gitSubmitPanelUi.authorLineEdit->text().isEmpty() + || !emailIsValid()) + return false; + return SubmitEditorWidget::canSubmit(); +} + +void GitSubmitEditorWidget::authorInformationChanged() +{ + m_gitSubmitPanelUi.invalidAuthorLabel-> + setVisible(m_gitSubmitPanelUi.authorLineEdit->text().isEmpty()); + m_gitSubmitPanelUi.invalidEmailLabel-> + setVisible(!emailIsValid()); + + updateSubmitAction(); +} + +bool GitSubmitEditorWidget::emailIsValid() const +{ + int pos = m_gitSubmitPanelUi.emailLineEdit->cursorPosition(); + return m_emailValidator->validate(m_gitSubmitPanelUi.emailLineEdit->text(), pos) + == QValidator::Acceptable; } } // namespace Internal |