mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-26 16:56:19 +00:00
Fixed: Check if profiles are correct before using them
This commit is contained in:
parent
89850bc52d
commit
d08ff5970f
3 changed files with 41 additions and 1 deletions
|
@ -49,6 +49,29 @@ void CProfile::saveToSettings(QSettings &settings) const
|
|||
settings.setValue("menu_shortcut", menuShortcut);
|
||||
}
|
||||
|
||||
bool CProfile::isValid(QString &error) const
|
||||
{
|
||||
QRegExp idReg("^[0-9a-z_]+$");
|
||||
|
||||
if (!idReg.exactMatch(id))
|
||||
{
|
||||
error = QApplication::tr("Profile ID %1 is using invalid characters (only lowercase letters, numbers and underscore are allowed)").arg(id);
|
||||
return false;
|
||||
}
|
||||
|
||||
QRegExp nameReg("[/\\\\<>?*:.%|\"]");
|
||||
|
||||
int pos = nameReg.indexIn(name);
|
||||
|
||||
if (pos > -1)
|
||||
{
|
||||
error = QApplication::tr("Profile name %1 is using invalid character %2 at position %3").arg(name).arg(name[pos]).arg(pos);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QString CProfile::getDirectory() const
|
||||
{
|
||||
return CConfigFile::getInstance()->getProfileDirectory() + "/" + id;
|
||||
|
@ -105,7 +128,7 @@ void CProfile::createShortcuts() const
|
|||
// create desktop shortcut
|
||||
if (!createShortcut(shortcut, name, exe, profileArguments, icon, workingDir))
|
||||
{
|
||||
qDebug() << "Unable to create desktop directory";
|
||||
qDebug() << "Unable to create desktop shortcut";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,8 @@ public:
|
|||
void loadFromSettings(const QSettings &settings);
|
||||
void saveToSettings(QSettings &settings) const;
|
||||
|
||||
bool isValid(QString &error) const;
|
||||
|
||||
// helpers
|
||||
QString getDirectory() const;
|
||||
QString getClientFullPath() const;
|
||||
|
|
|
@ -56,6 +56,21 @@ void CProfilesDialog::accept()
|
|||
{
|
||||
saveProfile(m_currentProfileIndex);
|
||||
|
||||
const CProfiles &profiles = m_model->getProfiles();
|
||||
|
||||
// check if profiles are valid
|
||||
foreach(const CProfile &profile, profiles)
|
||||
{
|
||||
QString error;
|
||||
|
||||
if (!profile.isValid(error))
|
||||
{
|
||||
// display an error message
|
||||
QMessageBox::critical(this, tr("Error"), error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
m_model->save();
|
||||
|
||||
QDialog::accept();
|
||||
|
|
Loading…
Reference in a new issue