From e8c2443bbd54d47cb2d3868d454ea48428b34bf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Bri=C3=A8re?= Date: Tue, 31 Mar 2020 14:24:28 -0400 Subject: Call GetProfileNameForm::init() in the constructor init() is responsible for setting a validator for profileLineEdit; its invocation was probably lost in the Qt4/5 transition. Closes #189 --- src/gui/getprofilenameform.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/gui/getprofilenameform.cpp b/src/gui/getprofilenameform.cpp index 89c715e..19e3a62 100644 --- a/src/gui/getprofilenameform.cpp +++ b/src/gui/getprofilenameform.cpp @@ -16,6 +16,7 @@ GetProfileNameForm::GetProfileNameForm(QWidget* parent) : QDialog(parent) { setupUi(this); + init(); } /* -- cgit v1.2.3 From ea00ce2f9d24ade8bcf8736a31516b41511e6233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Bri=C3=A8re?= Date: Tue, 31 Mar 2020 14:45:02 -0400 Subject: Add a note in getprofilenameform.ui listing which characters are allowed --- src/gui/getprofilenameform.ui | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src') diff --git a/src/gui/getprofilenameform.ui b/src/gui/getprofilenameform.ui index 9e1ba47..417e952 100644 --- a/src/gui/getprofilenameform.ui +++ b/src/gui/getprofilenameform.ui @@ -109,6 +109,30 @@ To remember your profiles easily you could use your SIP user name as a profile n + + + + + 5 + 0 + 0 + 0 + + + + (Allowed characters: letters, digits, '-', '_', '.', '@') + + + false + + + Qt::AlignVCenter + + + false + + + -- cgit v1.2.3 From ba8292d0fb08d39b0d8b9913889ffd589821b070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Bri=C3=A8re?= Date: Tue, 31 Mar 2020 17:24:27 -0400 Subject: Relax GetProfileNameForm validator to only check individual characters QRegExpValidator can be somewhat user-unfriendly, as it will prevent characters from being input, or even deleted, while leaving the user in the dark as to what is going on. Retricting the set of characters allowed shouldn't pose a problem if we make a mention of this on the form. Checking for a leading "." or "@", however, is better left at submission time, with an explicit error message in that case. --- src/gui/getprofilenameform.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/gui/getprofilenameform.cpp b/src/gui/getprofilenameform.cpp index 19e3a62..f2042c5 100644 --- a/src/gui/getprofilenameform.cpp +++ b/src/gui/getprofilenameform.cpp @@ -29,8 +29,8 @@ GetProfileNameForm::~GetProfileNameForm() void GetProfileNameForm::init() { - // Letters, digits, underscore, minus - QRegExp rxFilenameChars("[\\w\\-][\\w\\-@\\.]*"); + // Letters, digits, underscore, minus, "@" and period + QRegExp rxFilenameChars("[\\w\\-@\\.]*"); // Set validators // USER @@ -39,7 +39,25 @@ void GetProfileNameForm::init() void GetProfileNameForm::validate() { - if (profileLineEdit->text().isEmpty()) return; + QString profileName = profileLineEdit->text(); + + if (profileName.isEmpty()) return; + + // Check for anything that was let through by the validator + QRegExp rxFilename("^[\\w\\-][\\w\\-@\\.]*$"); + if (!rxFilename.exactMatch(profileName)) { + QMessageBox::critical(this, PRODUCT_NAME, + tr("Invalid profile name: %1").arg(profileName) + // While this would be better suited as informativeText, + // Qt wouldn't take it into account when sizing the box + // (see http://apocalyptech.com/linux/qt/qmessagebox/) + + QString("\n\n") + tr( + "Allowed characters are: letters, digits, '-', '_', '.' and '@'.\n" + "Furthermore, the initial character cannot be '.' or '@'." + )); + + return; + } // Find the .twinkle directory in HOME QDir d = QDir::home(); @@ -49,7 +67,7 @@ void GetProfileNameForm::validate() reject(); } - QString filename = profileLineEdit->text(); + QString filename = profileName; filename.append(USER_FILE_EXT); QString fullname = d.filePath(filename); if (QFile::exists(fullname)) { -- cgit v1.2.3 From 1eb2b7e2c7659e46d4c6dd3786d457c14c5e7ddd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Bri=C3=A8re?= Date: Tue, 31 Mar 2020 17:51:15 -0400 Subject: Give focus to profileLineEdit in GetProfileNameForm constructor Even though focus is supposed to initially go to profileLineEdit (due to its first position in the tabstops list), this doesn't seem to be the case in reality (at least for me). --- src/gui/getprofilenameform.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/gui/getprofilenameform.cpp b/src/gui/getprofilenameform.cpp index f2042c5..854b9c2 100644 --- a/src/gui/getprofilenameform.cpp +++ b/src/gui/getprofilenameform.cpp @@ -35,6 +35,9 @@ void GetProfileNameForm::init() // Set validators // USER profileLineEdit->setValidator(new QRegExpValidator(rxFilenameChars, this)); + + // Focus seems to default to OK button, despite tab order + profileLineEdit->setFocus(); } void GetProfileNameForm::validate() -- cgit v1.2.3