diff options
author | Luboš Doležel <lubos@dolezel.info> | 2020-04-01 08:28:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-01 08:28:09 +0200 |
commit | f5e4266b3f199e68976a68f96a9d7ae44c589429 (patch) | |
tree | 01e136f5030a98e13c9e3f5148b99c381ac89620 /src/gui | |
parent | 18add724c18235e51ef86364c9c65bbcfe16c173 (diff) | |
parent | 1eb2b7e2c7659e46d4c6dd3786d457c14c5e7ddd (diff) | |
download | twinkle-f5e4266b3f199e68976a68f96a9d7ae44c589429.tar twinkle-f5e4266b3f199e68976a68f96a9d7ae44c589429.tar.gz twinkle-f5e4266b3f199e68976a68f96a9d7ae44c589429.tar.lz twinkle-f5e4266b3f199e68976a68f96a9d7ae44c589429.tar.xz twinkle-f5e4266b3f199e68976a68f96a9d7ae44c589429.zip |
Merge pull request #203 from fbriere/issue/189-profile-name-dialog
Various fixes for the GetProfileNameForm dialog
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/getprofilenameform.cpp | 30 | ||||
-rw-r--r-- | src/gui/getprofilenameform.ui | 24 |
2 files changed, 50 insertions, 4 deletions
diff --git a/src/gui/getprofilenameform.cpp b/src/gui/getprofilenameform.cpp index 89c715e..854b9c2 100644 --- a/src/gui/getprofilenameform.cpp +++ b/src/gui/getprofilenameform.cpp @@ -16,6 +16,7 @@ GetProfileNameForm::GetProfileNameForm(QWidget* parent) : QDialog(parent) { setupUi(this); + init(); } /* @@ -28,17 +29,38 @@ 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 profileLineEdit->setValidator(new QRegExpValidator(rxFilenameChars, this)); + + // Focus seems to default to OK button, despite tab order + profileLineEdit->setFocus(); } 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(); @@ -48,7 +70,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)) { 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 </property> </widget> </item> + <item> + <widget class="QLabel" name="profileNoteLabel"> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>(Allowed characters: letters, digits, '-', '_', '.', '@')</string> + </property> + <property name="scaledContents"> + <bool>false</bool> + </property> + <property name="alignment"> + <set>Qt::AlignVCenter</set> + </property> + <property name="wordWrap"> + <bool>false</bool> + </property> + </widget> + </item> </layout> </item> </layout> |