diff framework/MainWindowBase.cpp @ 224:46213a34900f templating

Add saveSessionTemplate method
author Chris Cannam
date Tue, 10 May 2011 13:58:08 +0100
parents e8ae978e1a3d
children 9d50c42d7ca0
line wrap: on
line diff
--- a/framework/MainWindowBase.cpp	Mon May 09 16:55:47 2011 +0100
+++ b/framework/MainWindowBase.cpp	Tue May 10 13:58:08 2011 +0100
@@ -1981,6 +1981,43 @@
     }
 }
 
+bool
+MainWindowBase::saveSessionTemplate(QString path)
+{
+    try {
+
+        TempWriteFile temp(path);
+
+        QFile file(temp.getTemporaryFilename());
+        if (!file.open(QIODevice::WriteOnly)) {
+            std::cerr << "Failed to open session template file \""
+                      << temp.getTemporaryFilename().toStdString()
+                      << "\" for writing: "
+                      << file.errorString().toStdString() << std::endl;
+            return false;
+        }
+        
+        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+
+        QTextStream out(&file);
+        toXml(out);
+        out.flush();
+
+        QApplication::restoreOverrideCursor();
+
+        file.close();
+        temp.moveToTarget();
+        return true;
+
+    } catch (FileOperationFailed &f) {
+        
+        QMessageBox::critical(this, tr("Failed to write file"),
+                              tr("<b>Save failed</b><p>Failed to write to file \"%1\": %2")
+                              .arg(path).arg(f.what()));
+        return false;
+    }
+}
+
 void
 MainWindowBase::toXml(QTextStream &out)
 {