summaryrefslogtreecommitdiff
path: root/src/plugins/git/remotedialog.cpp
diff options
context:
space:
mode:
authorAndre Hartmann <aha_1980@gmx.de>2017-03-04 17:38:12 +0100
committerAndré Hartmann <aha_1980@gmx.de>2017-03-09 22:03:05 +0000
commit209cc214341226cb5c04283b7c3c8b1221bf3b5b (patch)
tree35d61c28721fb8cadec0235cb60b451e44dddf8e /src/plugins/git/remotedialog.cpp
parentb0ac6435b3786854e7a8d10cf4d8df49ca74618a (diff)
downloadqt-creator-209cc214341226cb5c04283b7c3c8b1221bf3b5b.tar.gz
Git: Add input validation to RemoteAdditionDialog
Use FancyLineEdits to indicate invalid inputs for remote names and URLs. For remote names: * Check for duplicate remote names and indicate these * Remove invalid chars during input For remote URLs: * Check if the input matches a valid URL or existing local directory Task-number: QTCREATORBUG-15998 Change-Id: I224e669f16e34e2cd3d075c602b431ce5bbdd391 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Diffstat (limited to 'src/plugins/git/remotedialog.cpp')
-rw-r--r--src/plugins/git/remotedialog.cpp53
1 files changed, 51 insertions, 2 deletions
diff --git a/src/plugins/git/remotedialog.cpp b/src/plugins/git/remotedialog.cpp
index 7fc352e179..6ab4d0449f 100644
--- a/src/plugins/git/remotedialog.cpp
+++ b/src/plugins/git/remotedialog.cpp
@@ -31,10 +31,12 @@
#include "ui_remotedialog.h"
#include "ui_remoteadditiondialog.h"
+#include <utils/fancylineedit.h>
#include <utils/headerviewstretcher.h>
#include <vcsbase/vcsoutputwindow.h>
#include <QMessageBox>
+#include <QRegularExpression>
namespace Git {
namespace Internal {
@@ -46,10 +48,55 @@ namespace Internal {
class RemoteAdditionDialog : public QDialog
{
public:
- RemoteAdditionDialog()
+ RemoteAdditionDialog(const QStringList &remoteNames) :
+ m_invalidRemoteNameChars(GitPlugin::invalidBranchAndRemoteNamePattern()),
+ m_remoteNames(remoteNames)
{
m_ui.setupUi(this);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
+ m_ui.nameEdit->setValidationFunction([this](Utils::FancyLineEdit *edit, QString *errorMessage) {
+ if (!edit)
+ return false;
+
+ QString input = edit->text();
+ edit->setText(input.replace(m_invalidRemoteNameChars, "_"));
+
+ // "Intermediate" patterns, may change to Acceptable when user edits further:
+
+ if (input.endsWith(".lock")) //..may not end with ".lock"
+ return false;
+
+ if (input.endsWith('.')) // no dot at the end (but allowed in the middle)
+ return false;
+
+ if (input.endsWith('/')) // no slash at the end (but allowed in the middle)
+ return false;
+
+ if (m_remoteNames.contains(input)) {
+ if (errorMessage)
+ *errorMessage = tr("A remote with the name \"%1\" already exists.").arg(input);
+ return false;
+ }
+
+ // is a valid remote name
+ return !input.isEmpty();
+ });
+ connect(m_ui.nameEdit, &QLineEdit::textChanged, [this]() {
+ m_ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(m_ui.nameEdit->isValid());
+ });
+
+ m_ui.urlEdit->setValidationFunction([](Utils::FancyLineEdit *edit, QString *errorMessage) {
+ if (!edit || edit->text().isEmpty())
+ return false;
+
+ const GitRemote r(edit->text());
+ if (!r.isValid && errorMessage)
+ *errorMessage = tr("The URL may not be valid.");
+
+ return r.isValid;
+ });
+
+ m_ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
}
QString remoteName() const
@@ -64,6 +111,8 @@ public:
private:
Ui::RemoteAdditionDialog m_ui;
+ const QRegularExpression m_invalidRemoteNameChars;
+ QStringList m_remoteNames;
};
@@ -125,7 +174,7 @@ void RemoteDialog::refreshRemotes()
void RemoteDialog::addRemote()
{
- RemoteAdditionDialog addDialog;
+ RemoteAdditionDialog addDialog(m_remoteModel->allRemoteNames());
if (addDialog.exec() != QDialog::Accepted)
return;