Skip to content

Commit

Permalink
dbhub: Better validation in push dialog
Browse files Browse the repository at this point in the history
This makes it more obvious to the user where the error in the input is
by just now allowing invalid characters.

It also prevents an annoying error message from popping up when entering
invalid database names and changing focus to another field afterwards.

See issue #1136.
  • Loading branch information
MKleusberg committed Oct 6, 2017
1 parent 8a7b662 commit eff92c2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/RemotePushDialog.cpp
@@ -1,5 +1,6 @@
#include <QPushButton>
#include <QUrlQuery>
#include <QRegExpValidator>

#include "RemotePushDialog.h"
#include "ui_RemotePushDialog.h"
Expand All @@ -10,10 +11,14 @@ RemotePushDialog::RemotePushDialog(QWidget* parent, RemoteDatabase& remote, cons
ui(new Ui::RemotePushDialog),
m_host(host),
m_clientCert(clientCert),
remoteDatabase(remote)
remoteDatabase(remote),
m_nameValidator(new QRegExpValidator(QRegExp("^[a-z,A-Z,0-9,\\.,\\-,\\_,\\(,\\),\\+,\\ ]+$"), this)),
m_branchValidator(new QRegExpValidator(QRegExp("^[a-z,A-Z,0-9,\\^,\\.,\\-,\\_,\\/,\\(,\\),\\:,\\&,\\ )]+$"), this))
{
// Create UI
ui->setupUi(this);
ui->editName->setValidator(m_nameValidator);
ui->comboBranch->setValidator(m_branchValidator);

// Set start values
ui->editName->setText(name);
Expand Down Expand Up @@ -54,16 +59,12 @@ void RemotePushDialog::checkInput()

if(ui->editName->text().trimmed().isEmpty())
valid = false;
if(!QRegExp("^[a-z,A-Z,0-9,\\.,\\-,\\_,\\(,\\),\\+,\\ ]+$").exactMatch(ui->editName->text()))
valid = false;

if(ui->editCommitMessage->toPlainText().size() > 1024)
valid = false;

if(ui->comboBranch->currentText().size() < 1 || ui->comboBranch->currentText().size() > 32)
valid = false;
if(!QRegExp("^[a-z,A-Z,0-9,\\^,\\.,\\-,\\_,\\/,\\(,\\),\\:,\\&,\\ )]+$").exactMatch(ui->comboBranch->currentText()))
valid = false;

ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(valid);
}
Expand Down
5 changes: 5 additions & 0 deletions src/RemotePushDialog.h
Expand Up @@ -4,6 +4,7 @@
#include <QDialog>

class RemoteDatabase;
class QRegExpValidator;

namespace Ui {
class RemotePushDialog;
Expand Down Expand Up @@ -34,6 +35,10 @@ class RemotePushDialog : public QDialog
// Reference to the remote database object which is stored somewhere in the main window
RemoteDatabase& remoteDatabase;

// Validators
QRegExpValidator* m_nameValidator;
QRegExpValidator* m_branchValidator;

protected slots:
void checkInput();
virtual void accept();
Expand Down

0 comments on commit eff92c2

Please sign in to comment.