Mercurial > hg > sonic-visualiser
comparison main/MainWindow.cpp @ 483:a6cbec451508
Add option to make the newly saved template the default
author | Chris Cannam |
---|---|
date | Mon, 17 Oct 2011 14:35:24 +0100 |
parents | 4bccf2014f80 |
children | 1f3afbce6c2f c11a29843fe1 bc04d651f8a4 |
comparison
equal
deleted
inserted
replaced
476:9d057ed676b6 | 483:a6cbec451508 |
---|---|
112 #include <QProcess> | 112 #include <QProcess> |
113 #include <QCheckBox> | 113 #include <QCheckBox> |
114 #include <QRegExp> | 114 #include <QRegExp> |
115 #include <QScrollArea> | 115 #include <QScrollArea> |
116 #include <QDesktopServices> | 116 #include <QDesktopServices> |
117 #include <QDialogButtonBox> | |
117 #include <QFileSystemWatcher> | 118 #include <QFileSystemWatcher> |
118 | 119 |
119 #include <iostream> | 120 #include <iostream> |
120 #include <cstdio> | 121 #include <cstdio> |
121 #include <errno.h> | 122 #include <errno.h> |
2862 } | 2863 } |
2863 | 2864 |
2864 void | 2865 void |
2865 MainWindow::saveSessionAsTemplate() | 2866 MainWindow::saveSessionAsTemplate() |
2866 { | 2867 { |
2867 QString name = QInputDialog::getText | 2868 QDialog *d = new QDialog; |
2868 (this, tr("Enter template name"), | 2869 d->setWindowTitle(tr("Enter template name")); |
2869 tr("Please enter a name for the saved template:")); | 2870 |
2870 if (name == "") return; | 2871 QGridLayout *layout = new QGridLayout; |
2872 d->setLayout(layout); | |
2873 | |
2874 layout->addWidget(new QLabel(tr("Please enter a name for the saved template:")), | |
2875 0, 0); | |
2876 QLineEdit *lineEdit = new QLineEdit; | |
2877 layout->addWidget(lineEdit, 1, 0); | |
2878 QCheckBox *makeDefault = new QCheckBox(tr("Set as default template for future audio files")); | |
2879 layout->addWidget(makeDefault, 2, 0); | |
2871 | 2880 |
2872 name.replace(QRegExp("[^\\w\\s\\.\"'-]"), "_"); | 2881 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok | |
2873 | 2882 QDialogButtonBox::Cancel); |
2874 ResourceFinder rf; | 2883 layout->addWidget(bb, 3, 0); |
2875 QString dir = rf.getResourceSaveDir("templates"); | 2884 connect(bb, SIGNAL(accepted()), d, SLOT(accept())); |
2876 QString filename = QString("%1/%2.svt").arg(dir).arg(name); | 2885 connect(bb, SIGNAL(accepted()), d, SLOT(accept())); |
2877 if (QFile(filename).exists()) { | 2886 connect(bb, SIGNAL(rejected()), d, SLOT(reject())); |
2878 if (QMessageBox::warning(this, | 2887 |
2879 tr("Template file exists"), | 2888 if (d->exec() == QDialog::Accepted) { |
2880 tr("<b>Template file exists</b><p>The template \"%1\" already exists.<br>Overwrite it?").arg(name), | 2889 |
2881 QMessageBox::Ok | QMessageBox::Cancel, | 2890 QString name = lineEdit->text(); |
2882 QMessageBox::Cancel) != QMessageBox::Ok) { | 2891 name.replace(QRegExp("[^\\w\\s\\.\"'-]"), "_"); |
2883 return; | 2892 |
2884 } | 2893 ResourceFinder rf; |
2885 } | 2894 QString dir = rf.getResourceSaveDir("templates"); |
2886 | 2895 QString filename = QString("%1/%2.svt").arg(dir).arg(name); |
2887 saveSessionTemplate(filename); | 2896 if (QFile(filename).exists()) { |
2897 if (QMessageBox::warning(this, | |
2898 tr("Template file exists"), | |
2899 tr("<b>Template file exists</b><p>The template \"%1\" already exists.<br>Overwrite it?").arg(name), | |
2900 QMessageBox::Ok | QMessageBox::Cancel, | |
2901 QMessageBox::Cancel) != QMessageBox::Ok) { | |
2902 return; | |
2903 } | |
2904 } | |
2905 | |
2906 if (saveSessionTemplate(filename)) { | |
2907 if (makeDefault->isChecked()) { | |
2908 setDefaultSessionTemplate(name); | |
2909 } | |
2910 } | |
2911 } | |
2888 } | 2912 } |
2889 | 2913 |
2890 void | 2914 void |
2891 MainWindow::manageSavedTemplates() | 2915 MainWindow::manageSavedTemplates() |
2892 { | 2916 { |