Mercurial > hg > sonic-visualiser
comparison 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 |
comparison
equal
deleted
inserted
replaced
10:582f4d6e82c7 | 11:0dbd08e365ce |
---|---|
74 #include <QFile> | 74 #include <QFile> |
75 #include <QTextStream> | 75 #include <QTextStream> |
76 #include <QProcess> | 76 #include <QProcess> |
77 #include <QShortcut> | 77 #include <QShortcut> |
78 #include <QSettings> | 78 #include <QSettings> |
79 #include <QDateTime> | |
80 #include <QProcess> | |
79 | 81 |
80 #include <iostream> | 82 #include <iostream> |
81 #include <cstdio> | 83 #include <cstdio> |
82 #include <errno.h> | 84 #include <errno.h> |
83 | 85 |
2149 e->accept(); | 2151 e->accept(); |
2150 return; | 2152 return; |
2151 } | 2153 } |
2152 | 2154 |
2153 bool | 2155 bool |
2156 MainWindow::commitData(bool mayAskUser) | |
2157 { | |
2158 if (mayAskUser) { | |
2159 return checkSaveModified(); | |
2160 } else { | |
2161 if (!m_documentModified) return true; | |
2162 | |
2163 // If we can't check with the user first, then we can't save | |
2164 // to the original session file (even if we have it) -- have | |
2165 // to use a temporary file | |
2166 | |
2167 QString svDirBase = ".sv1"; | |
2168 QString svDir = QDir::home().filePath(svDirBase); | |
2169 | |
2170 if (!QFileInfo(svDir).exists()) { | |
2171 if (!QDir::home().mkdir(svDirBase)) return false; | |
2172 } else { | |
2173 if (!QFileInfo(svDir).isDir()) return false; | |
2174 } | |
2175 | |
2176 // This name doesn't have to be unguessable | |
2177 | |
2178 QString fname = QString("tmp-%1-%2.sv") | |
2179 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz")) | |
2180 .arg(QProcess().pid()); | |
2181 QString fpath = QDir(svDir).filePath(fname); | |
2182 if (saveSessionFile(fpath)) { | |
2183 RecentFiles::getInstance()->addFile(fpath); | |
2184 return true; | |
2185 } else { | |
2186 return false; | |
2187 } | |
2188 } | |
2189 } | |
2190 | |
2191 bool | |
2154 MainWindow::checkSaveModified() | 2192 MainWindow::checkSaveModified() |
2155 { | 2193 { |
2156 // Called before some destructive operation (e.g. new session, | 2194 // Called before some destructive operation (e.g. new session, |
2157 // exit program). Return true if we can safely proceed, false to | 2195 // exit program). Return true if we can safely proceed, false to |
2158 // cancel. | 2196 // cancel. |