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"
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
46{
47 Q_OBJECT
48
49public:
50 /** Default constructor */
51 MainWindow();
52 /** Destructor. */
54
55public slots:
56 /** Shows or hides this window. **/
57 virtual void setVisible(bool visible);
58
59protected:
60 /** Called when the user changes the UI translation. */
61 virtual void retranslateUi();
62
63private 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. */
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
194private:
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 */
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
QList< PackageInfo > PackageList
Definition: PackageInfo.h:93
void sighup()
void enableNewIdentity()
QStringList _tabMap
Definition: MainWindow.h:306
void authenticated()
Definition: MainWindow.cpp:953
void restart()
NetViewer _netViewer
Definition: MainWindow.h:302
void started()
Definition: MainWindow.cpp:689
bool _isIntentionalExit
Definition: MainWindow.h:251
void createMenuBar()
Definition: MainWindow.cpp:185
QAction * _actionReloadConfig
Definition: MainWindow.h:283
void showHelpDialog()
virtual void retranslateUi()
Definition: MainWindow.cpp:343
void clockSkewed(int skew, const QString &source)
Definition: MainWindow.cpp:273
QAction * _actionExit
Definition: MainWindow.h:292
void bootstrapStatusChanged(const BootstrapStatus &bs)
bool stop()
Definition: MainWindow.cpp:759
BandwidthGraph * _graph
Definition: MainWindow.h:303
QMenu _reattachMenu
Definition: MainWindow.h:295
void showNetViewerTab()
QString toString(TorStatus status)
void aboutToQuit()
Definition: MainWindow.cpp:543
void running()
Definition: MainWindow.cpp:489
void showDebugDialog()
void handleCloseTab(int index)
@ Authenticating
Definition: MainWindow.h:201
@ CircuitEstablished
Definition: MainWindow.h:203
void connectFailed(QString errmsg)
Definition: MainWindow.cpp:928
void start()
Definition: MainWindow.cpp:564
void showBandwidthTab()
void stopped(int errorCode, QProcess::ExitStatus exitStatus)
Definition: MainWindow.cpp:823
void createActions()
Definition: MainWindow.cpp:165
void showAboutDialog()
void trayIconActivated(QSystemTrayIcon::ActivationReason reason)
Definition: MainWindow.cpp:336
void close()
Definition: MainWindow.cpp:469
QAction * _actionShowControlPanel
Definition: MainWindow.h:280
QString _previousSocksPort
Definition: MainWindow.h:311
bool _startedWithPrevious
Definition: MainWindow.h:309
void checkTorVersion()
QString _controlPassword
Definition: MainWindow.h:260
void setStartupProgress(int percentComplete, const QString &description)
bool tryCookie(const ProtocolInfo &pi)
QMenu * createTrayMenu()
Definition: MainWindow.cpp:245
void startFailed(QString errmsg)
Definition: MainWindow.cpp:853
QAction * _actionDebugDialog
Definition: MainWindow.h:293
TorControl * _torControl
Definition: MainWindow.h:257
void attachTab()
QByteArray loadControlCookie(QString cookiePath=QString())
QAction * _actionBandwidthGraph
Definition: MainWindow.h:288
bool _useSavedPassword
Definition: MainWindow.h:263
void dangerousTorVersion(tc::TorVersionStatus reason, const QString &version, const QStringList &recommended)
bool _delayedShutdownStarted
Definition: MainWindow.h:253
QAction * _actionStatus
Definition: MainWindow.h:285
QAction * _actionVidaliaHelp
Definition: MainWindow.h:290
bool authenticate()
virtual void setVisible(bool visible)
Definition: MainWindow.cpp:318
void disconnected()
void circuitEstablished()
QStringList _detachedTabMap
Definition: MainWindow.h:307
QAction * _actionNewIdentity
Definition: MainWindow.h:284
QAction * _actionAbout
Definition: MainWindow.h:291
QAction * _actionConfigure
Definition: MainWindow.h:289
void warnDangerousPort(quint16 port, bool rejected)
void createTrayIcon()
Definition: MainWindow.cpp:295
QAction * _actionMessageLog
Definition: MainWindow.h:287
void connected()
Definition: MainWindow.cpp:892
void displayTorVersionWarning()
QAction * _actionStartStopTor
Definition: MainWindow.h:281
StatusTab _statusTab
Definition: MainWindow.h:300
void disconnect()
QString _previousControlPort
Definition: MainWindow.h:310
TorStatus updateTorStatus(TorStatus status)
void showMessageLogTab()
void createGUI()
Definition: MainWindow.cpp:146
void newIdentity()
QAction * _actionNetworkMap
Definition: MainWindow.h:286
void showConfigDialog(ConfigDialog::Page page=ConfigDialog::General)
void setStartupProgressVisible(bool visible)
PluginEngine * _engine
Definition: MainWindow.h:305
bool tryHashed()
QAction * _actionRestartTor
Definition: MainWindow.h:282
void detachTab()
void addTab(VidaliaTab *tab)
TorStatus _status
Definition: MainWindow.h:249
void showStatusTab()
void createToolBar()
Definition: MainWindow.cpp:231
void authenticationFailed(QString errmsg)
QSystemTrayIcon _trayIcon
Definition: MainWindow.h:265
void setTrayIcon(const QString &iconFile)
QAction * _dummy
Definition: MainWindow.h:296
void handleAttachedClose()
void delTab(int index=-1)
void createConnections()
Definition: MainWindow.cpp:378
Ui::MainWindow ui
Definition: MainWindow.h:298
bool _isVidaliaRunningTor
Definition: MainWindow.h:255
MessageLog * _messageLog
Definition: MainWindow.h:301
TorVersionStatus
Definition: tcglobal.h:86
DebugMessage error(const QString &fmt)
Definition: tcglobal.cpp:40