comparison main/MainWindow.cpp @ 484:1f3afbce6c2f integration_library

Merge from the default branch
author mathieub <mathieu.barthet@eecs.qmul.ac.uk>
date Mon, 17 Oct 2011 15:24:22 +0100
parents e5c6aed2bf6b a6cbec451508
children b6c00a0a618e
comparison
equal deleted inserted replaced
482:e5c6aed2bf6b 484:1f3afbce6c2f
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>
2911 } 2912 }
2912 2913
2913 void 2914 void
2914 MainWindow::saveSessionAsTemplate() 2915 MainWindow::saveSessionAsTemplate()
2915 { 2916 {
2916 QString name = QInputDialog::getText 2917 QDialog *d = new QDialog;
2917 (this, tr("Enter template name"), 2918 d->setWindowTitle(tr("Enter template name"));
2918 tr("Please enter a name for the saved template:")); 2919
2919 if (name == "") return; 2920 QGridLayout *layout = new QGridLayout;
2921 d->setLayout(layout);
2922
2923 layout->addWidget(new QLabel(tr("Please enter a name for the saved template:")),
2924 0, 0);
2925 QLineEdit *lineEdit = new QLineEdit;
2926 layout->addWidget(lineEdit, 1, 0);
2927 QCheckBox *makeDefault = new QCheckBox(tr("Set as default template for future audio files"));
2928 layout->addWidget(makeDefault, 2, 0);
2920 2929
2921 name.replace(QRegExp("[^\\w\\s\\.\"'-]"), "_"); 2930 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok |
2922 2931 QDialogButtonBox::Cancel);
2923 ResourceFinder rf; 2932 layout->addWidget(bb, 3, 0);
2924 QString dir = rf.getResourceSaveDir("templates"); 2933 connect(bb, SIGNAL(accepted()), d, SLOT(accept()));
2925 QString filename = QString("%1/%2.svt").arg(dir).arg(name); 2934 connect(bb, SIGNAL(accepted()), d, SLOT(accept()));
2926 if (QFile(filename).exists()) { 2935 connect(bb, SIGNAL(rejected()), d, SLOT(reject()));
2927 if (QMessageBox::warning(this, 2936
2928 tr("Template file exists"), 2937 if (d->exec() == QDialog::Accepted) {
2929 tr("<b>Template file exists</b><p>The template \"%1\" already exists.<br>Overwrite it?").arg(name), 2938
2930 QMessageBox::Ok | QMessageBox::Cancel, 2939 QString name = lineEdit->text();
2931 QMessageBox::Cancel) != QMessageBox::Ok) { 2940 name.replace(QRegExp("[^\\w\\s\\.\"'-]"), "_");
2932 return; 2941
2933 } 2942 ResourceFinder rf;
2934 } 2943 QString dir = rf.getResourceSaveDir("templates");
2935 2944 QString filename = QString("%1/%2.svt").arg(dir).arg(name);
2936 saveSessionTemplate(filename); 2945 if (QFile(filename).exists()) {
2946 if (QMessageBox::warning(this,
2947 tr("Template file exists"),
2948 tr("<b>Template file exists</b><p>The template \"%1\" already exists.<br>Overwrite it?").arg(name),
2949 QMessageBox::Ok | QMessageBox::Cancel,
2950 QMessageBox::Cancel) != QMessageBox::Ok) {
2951 return;
2952 }
2953 }
2954
2955 if (saveSessionTemplate(filename)) {
2956 if (makeDefault->isChecked()) {
2957 setDefaultSessionTemplate(name);
2958 }
2959 }
2960 }
2937 } 2961 }
2938 2962
2939 void 2963 void
2940 MainWindow::manageSavedTemplates() 2964 MainWindow::manageSavedTemplates()
2941 { 2965 {