annotate base/ConfigFile.h @ 155:ae9be6b6b522

* Add Thumbwheel widget for all our zooming needs * Use QSettings to save/restore window size and position -- precursor to switching our preferences to QSettings as well -- wish I'd noticed it sooner * Only suspend writes (not reads from the underlying cache objects) from the fft caches when repainting the spectrogram -- performance should now be significantly better
author Chris Cannam
date Thu, 03 Aug 2006 15:40:11 +0000
parents 3e4c384f518e
children
rev   line source
Chris@149 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@149 2
Chris@149 3 /*
Chris@149 4 Sonic Visualiser
Chris@149 5 An audio file viewer and annotation editor.
Chris@149 6 Centre for Digital Music, Queen Mary, University of London.
Chris@149 7 This file copyright 2006 Chris Cannam.
Chris@149 8
Chris@149 9 This program is free software; you can redistribute it and/or
Chris@149 10 modify it under the terms of the GNU General Public License as
Chris@149 11 published by the Free Software Foundation; either version 2 of the
Chris@149 12 License, or (at your option) any later version. See the file
Chris@149 13 COPYING included with this distribution for more information.
Chris@149 14 */
Chris@149 15
Chris@149 16 #ifndef _CONFIG_FILE_H_
Chris@149 17 #define _CONFIG_FILE_H_
Chris@149 18
Chris@149 19 #include <QString>
Chris@149 20 #include <QMutex>
Chris@149 21
Chris@149 22 #include <map>
Chris@149 23
Chris@149 24 class ConfigFile
Chris@149 25 {
Chris@149 26 public:
Chris@149 27 ConfigFile(QString filename);
Chris@149 28 virtual ~ConfigFile();
Chris@149 29
Chris@149 30 /**
Chris@149 31 * Get a value, with a default if it hasn't been set.
Chris@149 32 */
Chris@149 33 QString get(QString key, QString deft = "");
Chris@149 34
Chris@149 35 bool getBool(QString key, bool deft);
Chris@149 36
Chris@149 37 int getInt(QString key, int deft);
Chris@149 38
Chris@149 39 float getFloat(QString key, float deft);
Chris@149 40
Chris@149 41 QStringList getStringList(QString key);
Chris@149 42
Chris@149 43 /**
Chris@149 44 * Set a value. Values must not contain carriage return or other
Chris@149 45 * non-printable characters. Keys must contain [a-zA-Z0-9_-] only.
Chris@149 46 */
Chris@149 47 void set(QString key, QString value);
Chris@149 48
Chris@149 49 void set(QString key, bool value);
Chris@149 50
Chris@149 51 void set(QString key, int value);
Chris@149 52
Chris@149 53 void set(QString key, float value);
Chris@149 54
Chris@149 55 void set(QString key, const QStringList &values); // must not contain '|'
Chris@149 56
Chris@149 57 /**
Chris@149 58 * Write the data to file. May throw FileOperationFailed.
Chris@149 59 *
Chris@149 60 * This is called automatically on destruction if any data has
Chris@149 61 * changed since it was last called. At that time, any exception
Chris@149 62 * will be ignored. If you want to ensure that exceptions are
Chris@149 63 * handled, call it yourself before destruction.
Chris@149 64 */
Chris@149 65 void commit();
Chris@149 66
Chris@149 67 /**
Chris@149 68 * Return to the stored values. You can also call this before
Chris@149 69 * destruction if you want to ensure that any values modified so
Chris@149 70 * far are not written out to file on destruction.
Chris@149 71 */
Chris@149 72 void reset();
Chris@149 73
Chris@149 74 protected:
Chris@149 75 bool load();
Chris@149 76
Chris@149 77 QString m_filename;
Chris@149 78
Chris@149 79 typedef std::map<QString, QString> DataMap;
Chris@149 80 DataMap m_data;
Chris@149 81
Chris@149 82 bool m_loaded;
Chris@149 83 bool m_modified;
Chris@149 84
Chris@149 85 QMutex m_mutex;
Chris@149 86 };
Chris@149 87
Chris@149 88 #endif
Chris@149 89