Vidalia  0.2.15
VSettings.h
Go to the documentation of this file.
00001 /*
00002 **  This file is part of Vidalia, and is subject to the license terms in the
00003 **  LICENSE file, found in the top level directory of this distribution. If you
00004 **  did not receive the LICENSE file with this file, you may obtain it from the
00005 **  Vidalia source package distributed by the Vidalia Project at
00006 **  http://www.torproject.org/projects/vidalia.html. No part of Vidalia, 
00007 **  including this file, may be copied, modified, propagated, or distributed 
00008 **  except according to the terms described in the LICENSE file.
00009 */
00010 
00011 /*
00012 ** \file vsettings.h
00013 ** \brief Stores and retrieves settings from Vidalia's configuration file.
00014 */
00015 
00016 #ifndef _VSETTINGS_H
00017 #define _VSETTINGS_H
00018 
00019 #include <QHash>
00020 #include <QSettings>
00021 
00022 
00023 class VSettings : public QSettings
00024 {
00025   Q_OBJECT
00026 
00027 public:
00028   /** Default constructor. The optional parameter <b>group</b> can be used to
00029    * set a prefix that will be prepended to keys specified to VSettings in
00030    * value() and setValue(). */
00031   VSettings(const QString group = QString());
00032 
00033   /** Returns the location of Vidalia's configuration settings file. */
00034   static QString settingsFile();
00035   /** Returns true if Vidalia's configuration settings file already exists. */
00036   static bool settingsFileExists();
00037 
00038   /** Resets all of Vidalia's settings. */
00039   static void reset();
00040 
00041   /** Returns the saved value associated with <b>key</b>. If no value has been
00042    * set, the default value is returned.
00043    * \sa setDefault
00044    */
00045   virtual QVariant value(const QString &key,
00046                          const QVariant &defaultVal = QVariant()) const;
00047   /** Sets the value associated with <b>key</b> to <b>val</b>. */
00048   virtual void setValue(const QString &key, const QVariant &val);
00049 
00050 protected:
00051   /** Sets the default setting for <b>key</b> to <b>val</b>. */
00052   void setDefault(const QString &key, const QVariant &val);
00053   /** Returns the default setting value associated with <b>key</b>. If
00054    * <b>key</b> has no default value, then an empty QVariant is returned. */
00055   QVariant defaultValue(const QString &key) const;
00056   /** Returns a map of all currently saved settings at the last apply()
00057    * point. */
00058   QMap<QString, QVariant> allSettings() const;
00059 
00060 private:
00061   /** Association of setting key names to default setting values. */
00062   QHash<QString, QVariant> _defaults; 
00063 };
00064 
00065 #endif
00066