Chris@149: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@149: Chris@149: /* Chris@149: Sonic Visualiser Chris@149: An audio file viewer and annotation editor. Chris@149: Centre for Digital Music, Queen Mary, University of London. Chris@149: This file copyright 2006 Chris Cannam. Chris@149: Chris@149: This program is free software; you can redistribute it and/or Chris@149: modify it under the terms of the GNU General Public License as Chris@149: published by the Free Software Foundation; either version 2 of the Chris@149: License, or (at your option) any later version. See the file Chris@149: COPYING included with this distribution for more information. Chris@149: */ Chris@149: Chris@149: #ifndef _CONFIG_FILE_H_ Chris@149: #define _CONFIG_FILE_H_ Chris@149: Chris@149: #include Chris@149: #include Chris@149: Chris@149: #include Chris@149: Chris@149: class ConfigFile Chris@149: { Chris@149: public: Chris@149: ConfigFile(QString filename); Chris@149: virtual ~ConfigFile(); Chris@149: Chris@149: /** Chris@149: * Get a value, with a default if it hasn't been set. Chris@149: */ Chris@149: QString get(QString key, QString deft = ""); Chris@149: Chris@149: bool getBool(QString key, bool deft); Chris@149: Chris@149: int getInt(QString key, int deft); Chris@149: Chris@149: float getFloat(QString key, float deft); Chris@149: Chris@149: QStringList getStringList(QString key); Chris@149: Chris@149: /** Chris@149: * Set a value. Values must not contain carriage return or other Chris@149: * non-printable characters. Keys must contain [a-zA-Z0-9_-] only. Chris@149: */ Chris@149: void set(QString key, QString value); Chris@149: Chris@149: void set(QString key, bool value); Chris@149: Chris@149: void set(QString key, int value); Chris@149: Chris@149: void set(QString key, float value); Chris@149: Chris@149: void set(QString key, const QStringList &values); // must not contain '|' Chris@149: Chris@149: /** Chris@149: * Write the data to file. May throw FileOperationFailed. Chris@149: * Chris@149: * This is called automatically on destruction if any data has Chris@149: * changed since it was last called. At that time, any exception Chris@149: * will be ignored. If you want to ensure that exceptions are Chris@149: * handled, call it yourself before destruction. Chris@149: */ Chris@149: void commit(); Chris@149: Chris@149: /** Chris@149: * Return to the stored values. You can also call this before Chris@149: * destruction if you want to ensure that any values modified so Chris@149: * far are not written out to file on destruction. Chris@149: */ Chris@149: void reset(); Chris@149: Chris@149: protected: Chris@149: bool load(); Chris@149: Chris@149: QString m_filename; Chris@149: Chris@149: typedef std::map DataMap; Chris@149: DataMap m_data; Chris@149: Chris@149: bool m_loaded; Chris@149: bool m_modified; Chris@149: Chris@149: QMutex m_mutex; Chris@149: }; Chris@149: Chris@149: #endif Chris@149: