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