Chris@81: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@81: Chris@81: /* Chris@81: Sonic Visualiser Chris@81: An audio file viewer and annotation editor. Chris@81: Centre for Digital Music, Queen Mary, University of London. Chris@81: This file copyright 2006 Chris Cannam. Chris@81: Chris@81: This program is free software; you can redistribute it and/or Chris@81: modify it under the terms of the GNU General Public License as Chris@81: published by the Free Software Foundation; either version 2 of the Chris@81: License, or (at your option) any later version. See the file Chris@81: COPYING included with this distribution for more information. Chris@81: */ Chris@81: Chris@81: #ifndef _TEMP_DIRECTORY_H_ Chris@81: #define _TEMP_DIRECTORY_H_ Chris@81: Chris@81: #include Chris@81: #include Chris@81: Chris@81: #include Chris@81: Chris@81: /** Chris@81: * A class that manages the creation and removal of a temporary Chris@81: * directory tree to store data during the program run. There is one Chris@81: * root temporary directory for the program, created on demand and Chris@81: * deleted when the program exits. Chris@81: * Chris@81: * This class is thread safe. Chris@81: */ Chris@81: Chris@81: class TempDirectory Chris@81: { Chris@81: public: Chris@81: static TempDirectory *instance(); Chris@81: Chris@81: virtual ~TempDirectory(); Chris@81: Chris@81: class DirectoryCreationFailed : virtual public std::exception Chris@81: { Chris@81: public: Chris@81: DirectoryCreationFailed(QString directory) throw(); Chris@81: virtual DirectoryCreationFailed::~DirectoryCreationFailed() throw() { } Chris@81: virtual const char *what() const throw(); Chris@81: Chris@81: protected: Chris@81: QString m_directory; Chris@81: }; Chris@81: Chris@81: /** Chris@81: * Create the root temporary directory if necessary, and return Chris@81: * its path. Throw DirectoryCreationFailed if the directory Chris@81: * cannot be created. Chris@81: */ Chris@81: QString getPath(); Chris@81: Chris@81: /** Chris@81: * Create an immediate subdirectory of the root temporary Chris@81: * directory of the given name, if it doesn't already exist, and Chris@81: * return its path. Throw DirectoryCreationFailed if the Chris@81: * directory cannot be created. Chris@81: */ Chris@81: QString getSubDirectoryPath(QString subdir); Chris@81: Chris@81: /** Chris@81: * Delete the temporary directory (before exiting). Chris@81: */ Chris@81: void cleanup(); Chris@81: Chris@81: protected: Chris@81: TempDirectory(); Chris@81: void cleanupDirectory(QString tmpDir); Chris@81: QString m_tmpdir; Chris@81: QMutex m_mutex; Chris@81: Chris@81: static TempDirectory *m_instance; Chris@81: }; Chris@81: Chris@81: Chris@81: #endif