Mercurial > hg > sonic-visualiser
diff main/MainWindow.cpp @ 431:ee927c1b7941 templating
Sanitise template file name; ask for confirmation when overwriting
author | Chris Cannam |
---|---|
date | Wed, 11 May 2011 14:41:27 +0100 |
parents | 45bfc5962c33 |
children | db0c86c4e5e9 |
line wrap: on
line diff
--- a/main/MainWindow.cpp Wed May 11 13:52:00 2011 +0100 +++ b/main/MainWindow.cpp Wed May 11 14:41:27 2011 +0100 @@ -2891,13 +2891,22 @@ tr("Please enter a name for the saved template:")); if (name == "") return; - //!!! sanitise name! - - //!!! check/confirm if target exists! + name.replace(QRegExp("[^\\w\\s\\.\"'-]"), "_"); ResourceFinder rf; QString dir = rf.getResourceSaveDir("templates"); - saveSessionTemplate(QString("%1/%2.svt").arg(dir).arg(name)); + QString filename = QString("%1/%2.svt").arg(dir).arg(name); + if (QFile(filename).exists()) { + if (QMessageBox::warning(this, + tr("Template file exists"), + tr("<b>Template file exists</b><p>The template \"%1\" already exists.<br>Overwrite it?").arg(name), + QMessageBox::Ok | QMessageBox::Cancel, + QMessageBox::Cancel) != QMessageBox::Ok) { + return; + } + } + + saveSessionTemplate(filename); } void