Vidalia  0.3.1
AbstractTorSettings.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 AbstractTorSettings.h
13 ** \brief Manages settings that need to be SETCONF'ed to Tor
14 */
15 
16 #ifndef _ABSTRACTTORSETTINGS_H
17 #define _ABSTRACTTORSETTINGS_H
18 
19 #include "VSettings.h"
20 #include "TorControl.h"
21 
23 {
24  Q_OBJECT
25 
26 public:
27  /** Constructor. All settings will be under the heading <b>group</b> and
28  * <b>torControl</b> will be used to <i>getconf</i> values from Tor. */
29  AbstractTorSettings(const QString &group, TorControl *torControl = 0);
30 
31  /** Sets a value indicating that the server settings have changed since
32  * apply() was last called. */
33  void setChanged(bool changed);
34  /** Returns true if any settings have changed since the last time apply()
35  * was called. */
36  virtual bool changedSinceLastApply() const;
37  /** Reverts all settings to their values at the last time apply() was
38  * called. */
39  virtual void revert();
40  /** Subclasses must implement this to <i>setconf</i> values to apply them
41  * to a running Tor instance. */
42  virtual bool apply(QString *errmsg) = 0;
43 
44 protected:
45  /** If Vidalia is connected to Tor, this returns the value associated with
46  * <b>key</b> by calling torValue(). Otherwise, this calls localValue()
47  * to get the locally saved value associated with <b>key</b>. */
48  virtual QVariant value(const QString &key) const;
49  /** Returns the value associated with <b>key</b> saved in the local
50  * configuration file. */
51  virtual QVariant localValue(const QString &key) const;
52  /** Returns the value associated with <b>key</b> by querying TOr via
53  * <i>getconf key</i>. */
54  virtual QVariant torValue(const QString &key) const;
55  /** Saves the value <b>val</b> for the setting <b>key</b> to the local
56  * settings file. */
57  virtual void setValue(const QString &key, const QVariant &value);
58 
59  /** Returns true if the given QVariant contains an empty value, depending on
60  * the data type. For example, 0 is considered an empty integer and "" is
61  * an empty string. */
62  bool isEmptyValue(const QVariant &value) const;
63 
64 protected:
65  /** Returns the TorControl object used for reading settings from or writing
66  * settings to Tor, if one was specified. Returns 0 if no TorControl object
67  * was given. */
68  TorControl* torControl() const { return _torControl; };
69 
70 private:
71  /** TorControl object used for reading settings from or applying settings to
72  * Tor. */
74  /** Collection of settings values at the last time apply() was called. */
75  QMap<QString, QVariant> _backupSettings;
76 };
77 
78 #endif
79 
stop errmsg QVariant
QMap< QString, QVariant > _backupSettings
virtual void setValue(const QString &key, const QVariant &value)
virtual QVariant torValue(const QString &key) const
virtual QVariant localValue(const QString &key) const
void setChanged(bool changed)
virtual bool changedSinceLastApply() const
TorControl * torControl() const
AbstractTorSettings(const QString &group, TorControl *torControl=0)
virtual QVariant value(const QString &key) const
virtual bool apply(QString *errmsg)=0
bool isEmptyValue(const QVariant &value) const