Vidalia
0.2.17
|
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 AbstractTorSettings.h 00013 ** \brief Manages settings that need to be SETCONF'ed to Tor 00014 */ 00015 00016 #ifndef _ABSTRACTTORSETTINGS_H 00017 #define _ABSTRACTTORSETTINGS_H 00018 00019 #include "VSettings.h" 00020 #include "TorControl.h" 00021 00022 class AbstractTorSettings : public VSettings 00023 { 00024 Q_OBJECT 00025 00026 public: 00027 /** Constructor. All settings will be under the heading <b>group</b> and 00028 * <b>torControl</b> will be used to <i>getconf</i> values from Tor. */ 00029 AbstractTorSettings(const QString &group, TorControl *torControl = 0); 00030 00031 /** Sets a value indicating that the server settings have changed since 00032 * apply() was last called. */ 00033 void setChanged(bool changed); 00034 /** Returns true if any settings have changed since the last time apply() 00035 * was called. */ 00036 virtual bool changedSinceLastApply() const; 00037 /** Reverts all settings to their values at the last time apply() was 00038 * called. */ 00039 virtual void revert(); 00040 /** Subclasses must implement this to <i>setconf</i> values to apply them 00041 * to a running Tor instance. */ 00042 virtual bool apply(QString *errmsg) = 0; 00043 00044 protected: 00045 /** If Vidalia is connected to Tor, this returns the value associated with 00046 * <b>key</b> by calling torValue(). Otherwise, this calls localValue() 00047 * to get the locally saved value associated with <b>key</b>. */ 00048 virtual QVariant value(const QString &key) const; 00049 /** Returns the value associated with <b>key</b> saved in the local 00050 * configuration file. */ 00051 virtual QVariant localValue(const QString &key) const; 00052 /** Returns the value associated with <b>key</b> by querying TOr via 00053 * <i>getconf key</i>. */ 00054 virtual QVariant torValue(const QString &key) const; 00055 /** Saves the value <b>val</b> for the setting <b>key</b> to the local 00056 * settings file. */ 00057 virtual void setValue(const QString &key, const QVariant &value); 00058 00059 /** Returns true if the given QVariant contains an empty value, depending on 00060 * the data type. For example, 0 is considered an empty integer and "" is 00061 * an empty string. */ 00062 bool isEmptyValue(const QVariant &value) const; 00063 00064 protected: 00065 /** Returns the TorControl object used for reading settings from or writing 00066 * settings to Tor, if one was specified. Returns 0 if no TorControl object 00067 * was given. */ 00068 TorControl* torControl() const { return _torControl; }; 00069 00070 private: 00071 /** TorControl object used for reading settings from or applying settings to 00072 * Tor. */ 00073 TorControl* _torControl; 00074 /** Collection of settings values at the last time apply() was called. */ 00075 QMap<QString, QVariant> _backupSettings; 00076 }; 00077 00078 #endif 00079