Vidalia  0.3.1
VSettings.h
Go to the documentation of this file.
1 /*
2 ** This file is part of Vidalia, and is subject to the license terms in the
3 ** LICENSE file, found in the top level directory of this distribution. If you
4 ** did not receive the LICENSE file with this file, you may obtain it from the
5 ** Vidalia source package distributed by the Vidalia Project at
6 ** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7 ** including this file, may be copied, modified, propagated, or distributed
8 ** except according to the terms described in the LICENSE file.
9 */
10 
11 /*
12 ** \file vsettings.h
13 ** \brief Stores and retrieves settings from Vidalia's configuration file.
14 */
15 
16 #ifndef _VSETTINGS_H
17 #define _VSETTINGS_H
18 
19 #include <QHash>
20 #include <QSettings>
21 
22 
23 class VSettings : public QSettings
24 {
25  Q_OBJECT
26 
27 public:
28  /** Default constructor. The optional parameter <b>group</b> can be used to
29  * set a prefix that will be prepended to keys specified to VSettings in
30  * value() and setValue(). */
31  VSettings(const QString group = QString());
32 
33  /** Returns the location of Vidalia's configuration settings file. */
34  static QString settingsFile();
35  /** Returns true if Vidalia's configuration settings file already exists. */
36  static bool settingsFileExists();
37 
38  /** Resets all of Vidalia's settings. */
39  static void reset();
40 
41  /** Returns the saved value associated with <b>key</b>. If no value has been
42  * set, the default value is returned.
43  * \sa setDefault
44  */
45  virtual QVariant value(const QString &key,
46  const QVariant &defaultVal = QVariant()) const;
47  /** Sets the value associated with <b>key</b> to <b>val</b>. */
48  virtual void setValue(const QString &key, const QVariant &val);
49 
50 protected:
51  /** Sets the default setting for <b>key</b> to <b>val</b>. */
52  void setDefault(const QString &key, const QVariant &val);
53  /** Returns the default setting value associated with <b>key</b>. If
54  * <b>key</b> has no default value, then an empty QVariant is returned. */
55  QVariant defaultValue(const QString &key) const;
56  /** Returns a map of all currently saved settings at the last apply()
57  * point. */
58  QMap<QString, QVariant> allSettings() const;
59 
60 private:
61  /** Association of setting key names to default setting values. */
62  QHash<QString, QVariant> _defaults;
63 };
64 
65 #endif
66