diff main/MainWindow.cpp @ 11:0dbd08e365ce

* Add session management support (commitData)
author Chris Cannam
date Tue, 12 Sep 2006 12:15:44 +0000
parents 92cb01225e7a
children ee967635c728
line wrap: on
line diff
--- a/main/MainWindow.cpp	Mon Sep 11 16:40:18 2006 +0000
+++ b/main/MainWindow.cpp	Tue Sep 12 12:15:44 2006 +0000
@@ -76,6 +76,8 @@
 #include <QProcess>
 #include <QShortcut>
 #include <QSettings>
+#include <QDateTime>
+#include <QProcess>
 
 #include <iostream>
 #include <cstdio>
@@ -2151,6 +2153,42 @@
 }
 
 bool
+MainWindow::commitData(bool mayAskUser)
+{
+    if (mayAskUser) {
+        return checkSaveModified();
+    } else {
+        if (!m_documentModified) return true;
+
+        // If we can't check with the user first, then we can't save
+        // to the original session file (even if we have it) -- have
+        // to use a temporary file
+
+        QString svDirBase = ".sv1";
+        QString svDir = QDir::home().filePath(svDirBase);
+
+        if (!QFileInfo(svDir).exists()) {
+            if (!QDir::home().mkdir(svDirBase)) return false;
+        } else {
+            if (!QFileInfo(svDir).isDir()) return false;
+        }
+        
+        // This name doesn't have to be unguessable
+
+        QString fname = QString("tmp-%1-%2.sv")
+            .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"))
+            .arg(QProcess().pid());
+        QString fpath = QDir(svDir).filePath(fname);
+        if (saveSessionFile(fpath)) {
+            RecentFiles::getInstance()->addFile(fpath);
+            return true;
+        } else {
+            return false;
+        }
+    }
+}
+
+bool
 MainWindow::checkSaveModified()
 {
     // Called before some destructive operation (e.g. new session,