summaryrefslogtreecommitdiffstats
path: root/src/gui/getprofilenameform.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/getprofilenameform.cpp')
-rw-r--r--src/gui/getprofilenameform.cpp30
1 files changed, 26 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)) {