Vidalia 0.2.10

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.vidalia-project.net/. No part of Vidalia, including this file,
00007 **  may be copied, modified, propagated, or distributed except according to the
00008 **  terms described in the LICENSE file.
00009 */
00010 
00011 /*
00012 ** \file vsettings.h
00013 ** \version $Id: VSettings.h 3735 2009-04-28 20:28:01Z edmanm $
00014 ** \brief Stores and retrieves settings from Vidalia's configuration file.
00015 */
00016 
00017 #ifndef _VSETTINGS_H
00018 #define _VSETTINGS_H
00019 
00020 #include <QHash>
00021 #include <QSettings>
00022 
00023 
00024 class VSettings : public QSettings
00025 {
00026   Q_OBJECT
00027 
00028 public:
00029   /** Default constructor. The optional parameter <b>group</b> can be used to
00030    * set a prefix that will be prepended to keys specified to VSettings in
00031    * value() and setValue(). */
00032   VSettings(const QString group = QString());
00033 
00034   /** Returns the location of Vidalia's configuration settings file. */
00035   static QString settingsFile();
00036   /** Returns true if Vidalia's configuration settings file already exists. */
00037   static bool settingsFileExists();
00038 
00039   /** Resets all of Vidalia's settings. */
00040   static void reset();
00041 
00042   /** Returns the saved value associated with <b>key</b>. If no value has been
00043    * set, the default value is returned.
00044    * \sa setDefault
00045    */
00046   virtual QVariant value(const QString &key,
00047                          const QVariant &defaultVal = QVariant()) const;
00048   /** Sets the value associated with <b>key</b> to <b>val</b>. */
00049   virtual void setValue(const QString &key, const QVariant &val);
00050 
00051 protected:
00052   /** Sets the default setting for <b>key</b> to <b>val</b>. */
00053   void setDefault(const QString &key, const QVariant &val);
00054   /** Returns the default setting value associated with <b>key</b>. If
00055    * <b>key</b> has no default value, then an empty QVariant is returned. */
00056   QVariant defaultValue(const QString &key) const;
00057   /** Returns a map of all currently saved settings at the last apply()
00058    * point. */
00059   QMap<QString, QVariant> allSettings() const;
00060 
00061 private:
00062   /** Association of setting key names to default setting values. */
00063   QHash<QString, QVariant> _defaults; 
00064 };
00065 
00066 #endif
00067