comparison 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
comparison
equal deleted inserted replaced
430:45bfc5962c33 431:ee927c1b7941
2889 QString name = QInputDialog::getText 2889 QString name = QInputDialog::getText
2890 (this, tr("Enter template name"), 2890 (this, tr("Enter template name"),
2891 tr("Please enter a name for the saved template:")); 2891 tr("Please enter a name for the saved template:"));
2892 if (name == "") return; 2892 if (name == "") return;
2893 2893
2894 //!!! sanitise name! 2894 name.replace(QRegExp("[^\\w\\s\\.\"'-]"), "_");
2895
2896 //!!! check/confirm if target exists!
2897 2895
2898 ResourceFinder rf; 2896 ResourceFinder rf;
2899 QString dir = rf.getResourceSaveDir("templates"); 2897 QString dir = rf.getResourceSaveDir("templates");
2900 saveSessionTemplate(QString("%1/%2.svt").arg(dir).arg(name)); 2898 QString filename = QString("%1/%2.svt").arg(dir).arg(name);
2899 if (QFile(filename).exists()) {
2900 if (QMessageBox::warning(this,
2901 tr("Template file exists"),
2902 tr("<b>Template file exists</b><p>The template \"%1\" already exists.<br>Overwrite it?").arg(name),
2903 QMessageBox::Ok | QMessageBox::Cancel,
2904 QMessageBox::Cancel) != QMessageBox::Ok) {
2905 return;
2906 }
2907 }
2908
2909 saveSessionTemplate(filename);
2901 } 2910 }
2902 2911
2903 void 2912 void
2904 MainWindow::manageSavedTemplates() 2913 MainWindow::manageSavedTemplates()
2905 { 2914 {