Mercurial > hg > svcore
comparison base/TempWriteFile.h @ 674:920e3880f7b4
* Add TempWriteFile abstraction, use it when exporting audio to avoid clobbering existing file before export is complete
author | Chris Cannam |
---|---|
date | Tue, 29 Mar 2011 17:30:23 +0100 |
parents | |
children | 1c9bbbb6116a |
comparison
equal
deleted
inserted
replaced
673:a1ae2c1f80ab | 674:920e3880f7b4 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 | |
8 This program is free software; you can redistribute it and/or | |
9 modify it under the terms of the GNU General Public License as | |
10 published by the Free Software Foundation; either version 2 of the | |
11 License, or (at your option) any later version. See the file | |
12 COPYING included with this distribution for more information. | |
13 */ | |
14 | |
15 #ifndef _TEMP_WRITE_FILE_H_ | |
16 #define _TEMP_WRITE_FILE_H_ | |
17 | |
18 #include <QTemporaryFile> | |
19 | |
20 /** | |
21 * A class that manages the creation of a temporary file with a given | |
22 * prefix and the renaming of that file to the prefix after use. For | |
23 * use when saving a file over an existing one, to avoid clobbering | |
24 * the original before the save is complete. | |
25 */ | |
26 | |
27 class TempWriteFile | |
28 { | |
29 public: | |
30 TempWriteFile(QString targetFileName); // may throw FileOperationFailed | |
31 | |
32 /** | |
33 * Destroy the temporary file object. If moveToTarget has not | |
34 * been called, the associated temporary file will be deleted | |
35 * without being copied to the target location. | |
36 */ | |
37 ~TempWriteFile(); | |
38 | |
39 /** | |
40 * Return the name of the temporary file. Unless the constructor | |
41 * threw an exception, this file will have been created already | |
42 * (but it will not be open). | |
43 * | |
44 * (If moveToTarget has already been called, return an empty | |
45 * string.) | |
46 */ | |
47 QString getTemporaryFilename(); | |
48 | |
49 /** | |
50 * Rename the temporary file to the target filename. | |
51 */ | |
52 void moveToTarget(); | |
53 | |
54 protected: | |
55 QString m_target; | |
56 QString m_temp; | |
57 }; | |
58 | |
59 | |
60 #endif |