Vidalia  0.3.1
MainWindow.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 MainWindow.h
13 ** \brief Main window. Creates tray menu and child windows
14 */
15 
16 #ifndef _MAINWINDOW_H
17 #define _MAINWINDOW_H
18 
19 #include "config.h"
20 #include "ui_MainWindow.h"
21 
22 #include "VidaliaWindow.h"
23 #include "StatusTab.h"
24 #include "ConfigDialog.h"
25 #include "MessageLog.h"
26 #include "NetViewer.h"
27 #include "BandwidthGraph.h"
28 #include "HelperProcess.h"
29 #if defined(USE_AUTOUPDATE)
30 #include "UpdateProcess.h"
31 #include "UpdateProgressDialog.h"
32 #endif
33 #if defined(USE_MINIUPNPC)
34 #include "UPNPControl.h"
35 #endif
36 
37 #include "TorControl.h"
38 
39 #include "PluginEngine.h"
40 
41 #include <QMainWindow>
42 #include <QTimer>
43 #include <QSystemTrayIcon>
44 
45 class MainWindow : public VidaliaWindow
46 {
47  Q_OBJECT
48 
49 public:
50  /** Default constructor */
51  MainWindow();
52  /** Destructor. */
53  ~MainWindow();
54 
55 public slots:
56  /** Shows or hides this window. **/
57  virtual void setVisible(bool visible);
58 
59 protected:
60  /** Called when the user changes the UI translation. */
61  virtual void retranslateUi();
62 
63 private slots:
64  /** Respond to a double-click on the tray icon by opening the Control Panel
65  * window. */
66  void trayIconActivated(QSystemTrayIcon::ActivationReason reason);
67  /** Called when the user selects "Start" from the menu. */
68  void start();
69  /** Called when the user changes a setting that needs Tor restarting */
70  void restart();
71  /** Called when the user wants to reload Tor's config */
72  void sighup();
73  /** Called when the Tor process fails to start. */
74  void startFailed(QString errmsg);
75  /** Called when the Tor process has successfully started. */
76  void started();
77  /** Called when the user selects "Stop" form the menu. */
78  bool stop();
79  /** Called when the Tor process has exited, either expectedly or not. */
80  void stopped(int errorCode, QProcess::ExitStatus exitStatus);
81  /** Called when the control socket has connected to Tor. */
82  void connected();
83  /** Called when the control connection fails. */
84  void connectFailed(QString errmsg);
85  /** Called when Vidalia wants to disconnect from a Tor it did not start. */
86  void disconnect();
87  /** Called when the control socket has been disconnected. */
88  void disconnected();
89  /** Called when Vidalia has successfully authenticated to Tor. */
90  void authenticated();
91  /** Called when authenticated() detects that you can do auth with a cookie */
92  bool tryCookie(const ProtocolInfo &pi);
93  /** Called when cookie auth fails or when it's the only method configured */
94  bool tryHashed();
95  /** Called when Vidalia fails to authenticate to Tor. The failure reason is
96  * specified in <b>errmsg</b>. */
97  void authenticationFailed(QString errmsg);
98  /** Re-enables the 'New Identity' button after a delay from the previous time
99  * 'New Identity' was used. */
100  void enableNewIdentity();
101  /** Called when the user selects the "New Identity" action from the menu. */
102  void newIdentity();
103  /** Called when the user exits Vidalia. */
104  void close();
105  /** Called when the application has started and the main event loop is
106  * running. */
107  void running();
108  /** Terminate the Tor process if it is being run under Vidalia, disconnect
109  * all TorControl signals, and exit Vidalia. */
110  void aboutToQuit();
111 
112  /** Called when Tor has successfully established a circuit. */
113  void circuitEstablished();
114  /** Called when Tor thinks the user has tried to connect to a port that
115  * typically is used for unencrypted applications. Warns the user and allows
116  * them to ignore future warnings on <b>port</b>. */
117  void warnDangerousPort(quint16 port, bool rejected);
118  /** Called when Tor's bootstrapping status changes. <b>bse</b> represents
119  * Tor's current estimate of its bootstrapping progress. */
120  void bootstrapStatusChanged(const BootstrapStatus &bs);
121  /** Called when Tor thinks its version is old or unrecommended, and displays
122  * a message notifying the user. */
124  const QString &version,
125  const QStringList &recommended);
126  void handleCloseTab(int index);
127  /** Creates and displays the Configuration dialog with the current page set
128  * to <b>page</b>. */
130  /** Displays the Message Log tab */
131  void showMessageLogTab();
132  /** Displays the General Tor Status tab */
133  void showStatusTab();
134  /** Displays the Bandwidth graph tab */
135  void showBandwidthTab();
136  /** Displays the Network map tab */
137  void showNetViewerTab();
138  /** Creates and displays Vidalia's About dialog. */
139  void showAboutDialog();
140  /** Displays the help browser and displays the most recently viewed help
141  * topic. */
142  void showHelpDialog();
143  /** Called when a child window requests the given help <b>topic</b>. */
144  void showHelpDialog(const QString &topic);
145 
146  /** Displays the debug output dialog for plugins */
147  void showDebugDialog();
148 
149  /** Adds a new tab to the MainWindow */
150  void addTab(VidaliaTab *tab);
151  /** Deletes the tab at index if it exists and it isn't the Status tab */
152  void delTab(int index = -1);
153 
154  /** Attaches a tab to the tabwidget */
155  void attachTab();
156  /** Detaches a tab from the tabwidget */
157  void detachTab();
158 
159  /** Called when trying to close a tab that has been detached */
160  void handleAttachedClose();
161 
162  /** Called when tor detects a problem with the system clock */
163  void clockSkewed(int skew, const QString &source);
164 
165 #if defined(USE_AUTOUPDATE)
166  /** Called when the user clicks the 'Check Now' button in the General
167  * settings page. */
168  void checkForUpdatesWithUi();
169  /** Called when the update interval timer expires, notifying Vidalia that
170  * we should check for updates again. */
171  void checkForUpdates(bool showProgress = false);
172  /** Called when the check for software updates fails. */
173  void checkForUpdatesFailed(const QString &errmsg);
174  /** Called when there is an update available for installation. */
175  void updatesAvailable(UpdateProcess::BundleInfo bi,
176  const PackageList &packageList);
177  /** Stops Tor (if necessary), installs any available for <b>bi</b>, and
178  * restarts Tor (if necessary). */
179  void installUpdates(UpdateProcess::BundleInfo bi);
180  /** Called when all <b>numUpdates</b> software updates have been installed
181  * successfully. */
182  void updatesInstalled(int numUpdates);
183  /** Called when an update fails to install. <b>errmsg</b> contains details
184  * about the failure. */
185  void installUpdatesFailed(const QString &errmsg);
186 #endif
187 
188 
189 #if defined(USE_MINIUPNPC)
190  /** Called when a UPnP error occurs. */
191  void upnpError(UPNPControl::UPNPError error);
192 #endif
193 
194 private:
195  enum TorStatus {
196  Unset, /**< Tor's status has not yet been set. */
197  Stopping, /**< Tor is in the process of shutting down. */
198  Stopped, /**< Tor is not running. */
199  Starting, /**< Tor is in the process of starting. */
200  Started, /**< Tor is currently running. */
201  Authenticating, /**< Vidalia is authenticating to Tor. */
202  Authenticated, /**< Vidalia has authenticated to Tor. */
203  CircuitEstablished /**< Tor has built a circuit. */
204  };
205 
206  void createGUI();
207  void createConnections();
208  /** Create the actions on the tray menu or menubar */
209  void createActions();
210  /** Creates a tray icon with a context menu and adds it to the system
211  * notification area. On Mac, we also set up an application menubar. */
212  void createTrayIcon();
213  /** Create the tray popup menu and it's submenus */
214  QMenu* createTrayMenu();
215  /** Creates a menubar */
216  void createMenuBar();
217  /** Creates a toolbar */
218  void createToolBar();
219  /** Sets the current tray or dock icon image to <b>iconFile</b>. */
220  void setTrayIcon(const QString &iconFile);
221  /** Updates the UI to reflect Tor's current <b>status</b>. Returns the
222  * previously set TorStatus value. */
224  /** Converts a TorStatus enum value to a string for debug logging purposes. */
225  QString toString(TorStatus status);
226  /** Authenticates Vidalia to Tor's control port. */
227  bool authenticate();
228  /** Searches for and attempts to load the control authentication cookie.
229  * This assumes the cookie is named 'control_auth_cookie'. If
230  * <b>cookiePath</b> is empty, this method will search some default locations
231  * depending on the current platform. <b>cookiePath</b> can point to either
232  * a cookie file or a directory containing the cookie file. */
233  QByteArray loadControlCookie(QString cookiePath = QString());
234  /** Checks the status of the current version of Tor to see if it's old,
235  * unrecommended, or obsolete. */
236  void checkTorVersion();
237  /** Alerts the user that their current Tor version is either obsolete or
238  * no longer recommended. If Vidalia was built with auto-update support,
239  * they will be given the option to check for available updates. */
241  /** Sets the visibility of the startup status description and progress bar
242  * to <b>visible</b>. */
243  void setStartupProgressVisible(bool visible);
244  /** Sets the progress bar completion value to <b>progressValue</b> and sets
245  * the status text to <b>description</b>. */
246  void setStartupProgress(int percentComplete, const QString &description);
247 
248  /** The current status of Tor. */
250  /** Used to determine if the Tor process exiting was intentional or not */
252  /** Tracks whether we started a delayed server shutdown. */
254  /** Set to true if Vidalia started its own Tor process. */
256  /** A TorControl object that handles communication with Tor */
258  /** Remembers the control password between when we start Tor with a hash of
259  * the password and when we need to provide the password itself. */
261  /** Set to true if we should use the control password saved in TorSettings
262  * when authenticating to Tor. */
264  /** The Vidalia icon that sits in the tray. */
265  QSystemTrayIcon _trayIcon;
266 
267 #if defined(USE_AUTOUPDATE)
268  /** Timer used to remind us to check for software updates. */
269  QTimer _updateTimer;
270  /** The auto-update process used to check for and download updates. */
271  UpdateProcess _updateProcess;
272  /** Dialog instance that is be used to show the progress of the auto-update
273  * executable. */
274  UpdateProgressDialog _updateProgressDialog;
275  /** Set to true if Vidalia should restart Tor after a software upgrade. */
276  bool _restartTorAfterUpgrade;
277 #endif
278 
279  /** Defines the actions for the tray menu */
285  QAction *_actionStatus;
291  QAction *_actionAbout;
292  QAction *_actionExit;
294 
295  QMenu _reattachMenu; /**< Menu used to handle tab re-attaching */
296  QAction *_dummy; /**< Dummy action to display when there are no more tabs */
297 
298  Ui::MainWindow ui; /**< Qt Designer generated object. */
299 
300  StatusTab _statusTab; /**< Status tab that displays the load progress and a short log */
301  MessageLog *_messageLog; /**< Message log that displays a more detailed log from Tor */
302  NetViewer _netViewer; /**< Network map that draws circuits */
303  BandwidthGraph *_graph; /**< Graph that draws bandwidth usage */
304 
306  QStringList _tabMap; /**< Map to handle opened tabs */
307  QStringList _detachedTabMap; /**< Map to handle detached tabs */
308 
309  bool _startedWithPrevious; /**< True if Vidalia tried to start Tor with the previous ports */
310  QString _previousControlPort; /**< Holds the previous controlport used */
311  QString _previousSocksPort; /**< Holds the previous socksport used */
312 };
313 
314 #endif
315 
StatusTab
Definition: StatusTab.h:22
MainWindow::_controlPassword
QString _controlPassword
Definition: MainWindow.h:260
VidaliaWindow
Definition: VidaliaWindow.h:27
UpdateProcess
Definition: UpdateProcess.h:22
MainWindow::createTrayIcon
void createTrayIcon()
Definition: MainWindow.cpp:295
MainWindow::_tabMap
QStringList _tabMap
Definition: MainWindow.h:306
MainWindow::_graph
BandwidthGraph * _graph
Definition: MainWindow.h:303
UpdateProcess::BundleInfo
BundleInfo
Definition: UpdateProcess.h:27
MainWindow::displayTorVersionWarning
void displayTorVersionWarning()
Definition: MainWindow.cpp:1070
MainWindow::createTrayMenu
QMenu * createTrayMenu()
Definition: MainWindow.cpp:245
MainWindow::showMessageLogTab
void showMessageLogTab()
Definition: MainWindow.cpp:1863
MainWindow::updateTorStatus
TorStatus updateTorStatus(TorStatus status)
Definition: MainWindow.cpp:1473
MainWindow::sighup
void sighup()
Definition: MainWindow.cpp:1602
TorControl
Definition: TorControl.h:49
MainWindow::started
void started()
Definition: MainWindow.cpp:689
MainWindow::Stopped
@ Stopped
Definition: MainWindow.h:198
MainWindow::_actionBandwidthGraph
QAction * _actionBandwidthGraph
Definition: MainWindow.h:288
MainWindow::checkTorVersion
void checkTorVersion()
Definition: MainWindow.cpp:1407
MainWindow::authenticationFailed
void authenticationFailed(QString errmsg)
Definition: MainWindow.cpp:1003
PluginEngine
Definition: PluginEngine.h:35
MainWindow::loadControlCookie
QByteArray loadControlCookie(QString cookiePath=QString())
Definition: MainWindow.cpp:1428
MainWindow::showNetViewerTab
void showNetViewerTab()
Definition: MainWindow.cpp:1901
MainWindow::_reattachMenu
QMenu _reattachMenu
Definition: MainWindow.h:295
BandwidthGraph
Definition: BandwidthGraph.h:31
BootstrapStatus
Definition: BootstrapStatus.h:25
MainWindow::setStartupProgressVisible
void setStartupProgressVisible(bool visible)
Definition: MainWindow.cpp:1619
MainWindow::_detachedTabMap
QStringList _detachedTabMap
Definition: MainWindow.h:307
MainWindow::detachTab
void detachTab()
Definition: MainWindow.cpp:1735
MainWindow::running
void running()
Definition: MainWindow.cpp:489
MainWindow::CircuitEstablished
@ CircuitEstablished
Definition: MainWindow.h:203
MainWindow::_actionNewIdentity
QAction * _actionNewIdentity
Definition: MainWindow.h:284
MainWindow::_startedWithPrevious
bool _startedWithPrevious
Definition: MainWindow.h:309
MainWindow::_isIntentionalExit
bool _isIntentionalExit
Definition: MainWindow.h:251
MainWindow::_delayedShutdownStarted
bool _delayedShutdownStarted
Definition: MainWindow.h:253
ConfigDialog::General
@ General
Definition: ConfigDialog.h:33
MainWindow::_status
TorStatus _status
Definition: MainWindow.h:249
MainWindow::tryCookie
bool tryCookie(const ProtocolInfo &pi)
Definition: MainWindow.cpp:1351
MainWindow::_actionMessageLog
QAction * _actionMessageLog
Definition: MainWindow.h:287
MainWindow::setTrayIcon
void setTrayIcon(const QString &iconFile)
Definition: MainWindow.cpp:1556
BandwidthGraph.h
PackageList
QList< PackageInfo > PackageList
Definition: PackageInfo.h:93
MessageLog.h
MainWindow::Starting
@ Starting
Definition: MainWindow.h:199
MainWindow::newIdentity
void newIdentity()
Definition: MainWindow.cpp:1668
MainWindow::showBandwidthTab
void showBandwidthTab()
Definition: MainWindow.cpp:1869
MainWindow::MainWindow
MainWindow()
Definition: MainWindow.cpp:105
MainWindow::Unset
@ Unset
Definition: MainWindow.h:196
UpdateProgressDialog
Definition: UpdateProgressDialog.h:19
MainWindow::Stopping
@ Stopping
Definition: MainWindow.h:197
MainWindow::tryHashed
bool tryHashed()
Definition: MainWindow.cpp:1389
MainWindow::_torControl
TorControl * _torControl
Definition: MainWindow.h:257
MainWindow::circuitEstablished
void circuitEstablished()
Definition: MainWindow.cpp:1188
MainWindow::_previousSocksPort
QString _previousSocksPort
Definition: MainWindow.h:311
MainWindow::warnDangerousPort
void warnDangerousPort(quint16 port, bool rejected)
Definition: MainWindow.cpp:1216
VidaliaTab
Definition: VidaliaTab.h:23
MainWindow::trayIconActivated
void trayIconActivated(QSystemTrayIcon::ActivationReason reason)
Definition: MainWindow.cpp:336
MainWindow::_isVidaliaRunningTor
bool _isVidaliaRunningTor
Definition: MainWindow.h:255
MainWindow::showDebugDialog
void showDebugDialog()
Definition: MainWindow.cpp:1907
TorControl.h
MainWindow::createConnections
void createConnections()
Definition: MainWindow.cpp:378
MainWindow::_dummy
QAction * _dummy
Definition: MainWindow.h:296
UPNPControl::UPNPError
UPNPError
Definition: UPNPControl.h:32
MainWindow::_engine
PluginEngine * _engine
Definition: MainWindow.h:305
MainWindow::disconnected
void disconnected()
Definition: MainWindow.cpp:1644
MainWindow::_previousControlPort
QString _previousControlPort
Definition: MainWindow.h:310
MainWindow::aboutToQuit
void aboutToQuit()
Definition: MainWindow.cpp:543
MainWindow::showHelpDialog
void showHelpDialog()
MainWindow::restart
void restart()
Definition: MainWindow.cpp:1593
MainWindow::toString
QString toString(TorStatus status)
Definition: MainWindow.cpp:1573
MainWindow::_trayIcon
QSystemTrayIcon _trayIcon
Definition: MainWindow.h:265
MainWindow::bootstrapStatusChanged
void bootstrapStatusChanged(const BootstrapStatus &bs)
Definition: MainWindow.cpp:1106
MainWindow::_statusTab
StatusTab _statusTab
Definition: MainWindow.h:300
MainWindow::createGUI
void createGUI()
Definition: MainWindow.cpp:146
MainWindow::_messageLog
MessageLog * _messageLog
Definition: MainWindow.h:301
PluginEngine.h
MainWindow::addTab
void addTab(VidaliaTab *tab)
Definition: MainWindow.cpp:1787
MainWindow::_actionShowControlPanel
QAction * _actionShowControlPanel
Definition: MainWindow.h:280
NetViewer.h
MainWindow::showConfigDialog
void showConfigDialog(ConfigDialog::Page page=ConfigDialog::General)
Definition: MainWindow.cpp:1658
MainWindow::dangerousTorVersion
void dangerousTorVersion(tc::TorVersionStatus reason, const QString &version, const QStringList &recommended)
Definition: MainWindow.cpp:1055
MainWindow::_actionReloadConfig
QAction * _actionReloadConfig
Definition: MainWindow.h:283
MainWindow::_actionNetworkMap
QAction * _actionNetworkMap
Definition: MainWindow.h:286
MainWindow::_actionRestartTor
QAction * _actionRestartTor
Definition: MainWindow.h:282
MainWindow::ui
Ui::MainWindow ui
Definition: MainWindow.h:298
MainWindow::_actionExit
QAction * _actionExit
Definition: MainWindow.h:292
MainWindow::clockSkewed
void clockSkewed(int skew, const QString &source)
Definition: MainWindow.cpp:273
MainWindow::stop
bool stop()
Definition: MainWindow.cpp:759
tc::TorVersionStatus
TorVersionStatus
Definition: tcglobal.h:86
MainWindow::handleAttachedClose
void handleAttachedClose()
Definition: MainWindow.cpp:1756
UpdateProgressDialog.h
MainWindow::start
void start()
Definition: MainWindow.cpp:564
MainWindow::disconnect
void disconnect()
Definition: MainWindow.cpp:1637
MainWindow::close
void close()
Definition: MainWindow.cpp:469
MainWindow::Authenticating
@ Authenticating
Definition: MainWindow.h:201
MainWindow::startFailed
void startFailed(QString errmsg)
Definition: MainWindow.cpp:853
MainWindow::connectFailed
void connectFailed(QString errmsg)
Definition: MainWindow.cpp:928
ProtocolInfo
Definition: ProtocolInfo.h:22
MainWindow::enableNewIdentity
void enableNewIdentity()
Definition: MainWindow.cpp:1701
MainWindow::stopped
void stopped(int errorCode, QProcess::ExitStatus exitStatus)
Definition: MainWindow.cpp:823
MainWindow::_actionStartStopTor
QAction * _actionStartStopTor
Definition: MainWindow.h:281
MainWindow::connected
void connected()
Definition: MainWindow.cpp:892
HelperProcess.h
MainWindow::Started
@ Started
Definition: MainWindow.h:200
tc::error
DebugMessage error(const QString &fmt)
Definition: tcglobal.cpp:40
MainWindow::TorStatus
TorStatus
Definition: MainWindow.h:195
MainWindow::delTab
void delTab(int index=-1)
Definition: MainWindow.cpp:1837
config.h
NetViewer
Definition: NetViewer.h:41
MainWindow::_actionConfigure
QAction * _actionConfigure
Definition: MainWindow.h:289
MainWindow::retranslateUi
virtual void retranslateUi()
Definition: MainWindow.cpp:343
UPNPControl.h
MainWindow::showAboutDialog
void showAboutDialog()
Definition: MainWindow.cpp:1876
MainWindow::_actionAbout
QAction * _actionAbout
Definition: MainWindow.h:291
MainWindow::authenticated
void authenticated()
Definition: MainWindow.cpp:953
MainWindow::_actionStatus
QAction * _actionStatus
Definition: MainWindow.h:285
MainWindow::_useSavedPassword
bool _useSavedPassword
Definition: MainWindow.h:263
MainWindow::Authenticated
@ Authenticated
Definition: MainWindow.h:202
MainWindow::createMenuBar
void createMenuBar()
Definition: MainWindow.cpp:185
MainWindow::setStartupProgress
void setStartupProgress(int percentComplete, const QString &description)
Definition: MainWindow.cpp:1628
MainWindow::showStatusTab
void showStatusTab()
Definition: MainWindow.cpp:1857
MainWindow
Definition: MainWindow.h:45
VidaliaWindow.h
MainWindow::_actionDebugDialog
QAction * _actionDebugDialog
Definition: MainWindow.h:293
StatusTab.h
MessageLog
Definition: MessageLog.h:28
MainWindow::createToolBar
void createToolBar()
Definition: MainWindow.cpp:231
MainWindow::authenticate
bool authenticate()
Definition: MainWindow.cpp:1301
UpdateProcess.h
MainWindow::~MainWindow
~MainWindow()
Definition: MainWindow.cpp:138
MainWindow::_netViewer
NetViewer _netViewer
Definition: MainWindow.h:302
MainWindow::createActions
void createActions()
Definition: MainWindow.cpp:165
ConfigDialog.h
MainWindow::attachTab
void attachTab()
Definition: MainWindow.cpp:1720
MainWindow::_actionVidaliaHelp
QAction * _actionVidaliaHelp
Definition: MainWindow.h:290
MainWindow::handleCloseTab
void handleCloseTab(int index)
Definition: MainWindow.cpp:1709
MainWindow::setVisible
virtual void setVisible(bool visible)
Definition: MainWindow.cpp:318
ConfigDialog::Page
Page
Definition: ConfigDialog.h:32