Vidalia
0.2.21
Main Page
Namespaces
Classes
Files
File List
File Members
src
vidalia
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 "
HelperProcess.h
"
24
#include "
AboutDialog.h
"
25
#include "
MessageLog.h
"
26
#include "
BandwidthGraph.h
"
27
#include "
ConfigDialog.h
"
28
#include "
HelpBrowser.h
"
29
#include "
NetViewer.h
"
30
31
#include "
TorControl.h
"
32
33
#if defined(USE_AUTOUPDATE)
34
#include "
UpdateProcess.h
"
35
#include "
UpdateProgressDialog.h
"
36
#endif
37
#if defined(USE_MINIUPNPC)
38
#include "
UPNPControl.h
"
39
#endif
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
/** Displays the help browser and displays the most recently viewed help
68
* topic. */
69
void
showHelpDialog
();
70
/** Called when a child window requests the given help <b>topic</b>. */
71
void
showHelpDialog
(
const
QString &topic);
72
/** Called when the user selects "Start" from the menu. */
73
void
start
();
74
/** Called when the user changes a setting that needs Tor restarting */
75
void
restart
();
76
/** Called when the Tor process fails to start. */
77
void
startFailed
(QString errmsg);
78
/** Called when the Tor process has successfully started. */
79
void
started
();
80
/** Called when the user selects "Stop" form the menu. */
81
bool
stop
();
82
/** Called when the Tor process has exited, either expectedly or not. */
83
void
stopped
(
int
errorCode, QProcess::ExitStatus exitStatus);
84
/** Called when the control socket has connected to Tor. */
85
void
connected
();
86
/** Called when the control connection fails. */
87
void
connectFailed
(QString errmsg);
88
/** Called when Vidalia wants to disconnect from a Tor it did not start. */
89
void
disconnect
();
90
/** Called when the control socket has been disconnected. */
91
void
disconnected
();
92
/** Called when Vidalia has successfully authenticated to Tor. */
93
void
authenticated
();
94
/** Called when Vidalia fails to authenticate to Tor. The failure reason is
95
* specified in <b>errmsg</b>. */
96
void
authenticationFailed
(QString errmsg);
97
/** Re-enables the 'New Identity' button after a delay from the previous time
98
* 'New Identity' was used. */
99
void
enableNewIdentity
();
100
/** Called when the user selects the "New Identity" action from the menu. */
101
void
newIdentity
();
102
/** Called when the user exits Vidalia. */
103
void
close
();
104
/** Called when the application has started and the main event loop is
105
* running. */
106
void
running
();
107
/** Terminate the Tor process if it is being run under Vidalia, disconnect
108
* all TorControl signals, and exit Vidalia. */
109
void
aboutToQuit
();
110
/** Creates and displays Vidalia's About dialog. */
111
void
showAboutDialog
();
112
/** Creates and displays the Configuration dialog with the current page set
113
* to <b>page</b>. */
114
void
showConfigDialog
(
ConfigDialog::Page
page =
ConfigDialog::General
);
115
/** Displays the Configuration dialog, set to the Server page. */
116
void
showServerConfigDialog
();
117
/** Called when the "show on startup" checkbox is toggled. */
118
void
toggleShowOnStartup
(
bool
checked);
119
/** Called when the web browser or IM client have stopped */
120
void
onSubprocessFinished
(
int
exitCode, QProcess::ExitStatus exitStatus);
121
/** Called periodically to check if the browser is running. If it is not,
122
* exit Vidalia cleanly */
123
void
onCheckForBrowser
();
124
/** Called web the web browser failed to start */
125
void
onBrowserFailed
(QString errmsg);
126
/** Called web the IM client failed to start */
127
void
onIMFailed
(QString errmsg);
128
/** Called when the proxy server fails to start */
129
void
onProxyFailed
(QString errmsg);
130
131
/** Called when Tor has successfully established a circuit. */
132
void
circuitEstablished
();
133
/** Called when Tor thinks the user has tried to connect to a port that
134
* typically is used for unencrypted applications. Warns the user and allows
135
* them to ignore future warnings on <b>port</b>. */
136
void
warnDangerousPort
(quint16 port,
bool
rejected);
137
/** Called when Tor's bootstrapping status changes. <b>bse</b> represents
138
* Tor's current estimate of its bootstrapping progress. */
139
void
bootstrapStatusChanged
(
const
BootstrapStatus
&bs);
140
/** Called when Tor thinks its version is old or unrecommended, and displays
141
* a message notifying the user. */
142
void
dangerousTorVersion
(
tc::TorVersionStatus
reason,
143
const
QString &version,
144
const
QStringList &recommended);
145
146
/** Called when torControl emits logMessage() */
147
void
log
(
tc::Severity
type,
const
QString &message);
148
/** Toggles the color for the Message Log button */
149
void
warnButton
();
150
151
#if defined(USE_AUTOUPDATE)
152
/** Called when the user clicks the 'Check Now' button in the General
153
* settings page. */
154
void
checkForUpdatesWithUi();
155
/** Called when the update interval timer expires, notifying Vidalia that
156
* we should check for updates again. */
157
void
checkForUpdates(
bool
showProgress =
false
);
158
/** Called when the check for software updates fails. */
159
void
checkForUpdatesFailed(
const
QString &errmsg);
160
/** Called when there is an update available for installation. */
161
void
updatesAvailable(
UpdateProcess::BundleInfo
bi,
162
const
PackageList
&packageList);
163
/** Stops Tor (if necessary), installs any available for <b>bi</b>, and
164
* restarts Tor (if necessary). */
165
void
installUpdates(
UpdateProcess::BundleInfo
bi);
166
/** Called when all <b>numUpdates</b> software updates have been installed
167
* successfully. */
168
void
updatesInstalled(
int
numUpdates);
169
/** Called when an update fails to install. <b>errmsg</b> contains details
170
* about the failure. */
171
void
installUpdatesFailed(
const
QString &errmsg);
172
#endif
173
174
#if defined(USE_MINIUPNPC)
175
/** Called when a UPnP error occurs. */
176
void
upnpError(
UPNPControl::UPNPError
error
);
177
#endif
178
179
private
:
180
enum
TorStatus
{
181
Unset
,
/**< Tor's status has not yet been set. */
182
Stopping
,
/**< Tor is in the process of shutting down. */
183
Stopped
,
/**< Tor is not running. */
184
Starting
,
/**< Tor is in the process of starting. */
185
Started
,
/**< Tor is currently running. */
186
Authenticating
,
/**< Vidalia is authenticating to Tor. */
187
Authenticated
,
/**< Vidalia has authenticated to Tor. */
188
CircuitEstablished
/**< Tor has built a circuit. */
189
};
190
/** Create the actions on the tray menu or menubar */
191
void
createActions
();
192
/** Creates a tray icon with a context menu and adds it to the system
193
* notification area. On Mac, we also set up an application menubar. */
194
void
createTrayIcon
();
195
/** Create the tray popup menu and it's submenus */
196
QMenu*
createTrayMenu
();
197
/** Creates a default menubar on Mac */
198
void
createMenuBar
();
199
/** Sets the current tray or dock icon image to <b>iconFile</b>. */
200
void
setTrayIcon
(
const
QString &iconFile);
201
/** Updates the UI to reflect Tor's current <b>status</b>. Returns the
202
* previously set TorStatus value. */
203
TorStatus
updateTorStatus
(
TorStatus
status);
204
/** Start a web browser when given the directory containing the executable and profile */
205
void
launchBrowserFromDirectory
();
206
/** Starts the web browser, if appropriately configured */
207
void
startSubprocesses
();
208
/** Starts the proxy server, if appropriately configured */
209
void
startProxy
();
210
/** Converts a TorStatus enum value to a string for debug logging purposes. */
211
QString
toString
(
TorStatus
status);
212
/** Authenticates Vidalia to Tor's control port. */
213
bool
authenticate
();
214
/** Searches for and attempts to load the control authentication cookie.
215
* This assumes the cookie is named 'control_auth_cookie'. If
216
* <b>cookiePath</b> is empty, this method will search some default locations
217
* depending on the current platform. <b>cookiePath</b> can point to either
218
* a cookie file or a directory containing the cookie file. */
219
QByteArray
loadControlCookie
(QString cookiePath = QString());
220
/** Checks the status of the current version of Tor to see if it's old,
221
* unrecommended, or obsolete. */
222
void
checkTorVersion
();
223
/** Alerts the user that their current Tor version is either obsolete or
224
* no longer recommended. If Vidalia was built with auto-update support,
225
* they will be given the option to check for available updates. */
226
void
displayTorVersionWarning
();
227
/** Sets the visibility of the startup status description and progress bar
228
* to <b>visible</b>. */
229
void
setStartupProgressVisible
(
bool
visible);
230
/** Sets the progress bar completion value to <b>progressValue</b> and sets
231
* the status text to <b>description</b>. */
232
void
setStartupProgress
(
int
percentComplete,
const
QString &description);
233
/** Adds the needed variables to the environment that the browser will
234
* need */
235
QStringList
updateBrowserEnv
();
236
237
/** The current status of Tor. */
238
TorStatus
_status
;
239
/** Used to determine if the Tor process exiting was intentional or not */
240
bool
_isIntentionalExit
;
241
/** Tracks whether we started a delayed server shutdown. */
242
bool
_delayedShutdownStarted
;
243
/** Set to true if Vidalia started its own Tor process. */
244
bool
_isVidaliaRunningTor
;
245
/** A MessageLog object which handles logging Tor messages */
246
MessageLog
*
_messageLog
;
247
/** A BandwidthGraph object which handles monitoring Tor bandwidth usage */
248
BandwidthGraph
*
_bandwidthGraph
;
249
/** A NetViewer object which displays the Tor network graphically */
250
NetViewer
*
_netViewer
;
251
/** A ConfigDialog object which lets the user configure Tor and Vidalia */
252
ConfigDialog
*
_configDialog
;
253
/** A TorControl object that handles communication with Tor */
254
TorControl
*
_torControl
;
255
/** A HelperProcess object that manages the web browser */
256
HelperProcess
*
_browserProcess
;
257
/** A HelperProcess object that manages the IM client */
258
HelperProcess
*
_imProcess
;
259
/** A HelperProcess object that manages the proxy server */
260
HelperProcess
*
_proxyProcess
;
261
/** Remembers the control password between when we start Tor with a hash of
262
* the password and when we need to provide the password itself. */
263
QString
_controlPassword
;
264
/** Set to true if we should use the control password saved in TorSettings
265
* when authenticating to Tor. */
266
bool
_useSavedPassword
;
267
/** The Vidalia icon that sits in the tray. */
268
QSystemTrayIcon
_trayIcon
;
269
270
#if defined(USE_AUTOUPDATE)
271
/** Timer used to remind us to check for software updates. */
272
QTimer _updateTimer;
273
/** The auto-update process used to check for and download updates. */
274
UpdateProcess
_updateProcess;
275
/** Dialog instance that is be used to show the progress of the auto-update
276
* executable. */
277
UpdateProgressDialog
_updateProgressDialog;
278
/** Set to true if Vidalia should restart Tor after a software upgrade. */
279
bool
_restartTorAfterUpgrade;
280
#endif
281
/** The menubar (Mac OS X only). */
282
QMenuBar *
_menuBar
;
283
284
/** Defines the actions for the tray menu */
285
QAction*
_actionShowControlPanel
;
286
QAction*
_actionStartStopTor
;
287
QAction*
_actionShowConfig
;
288
QAction*
_actionShowAbout
;
289
QAction*
_actionExit
;
290
QAction*
_actionShowBandwidth
;
291
QAction*
_actionShowMessageLog
;
292
QAction*
_actionShowHelp
;
293
QAction*
_actionShowNetworkMap
;
294
QAction*
_actionNewIdentity
;
295
296
quint16
_autoControlPort
;
297
298
/** Timer and bool used to flash buttons with a different color */
299
QTimer *
_warnTimer
;
300
bool
_flashToggle
;
301
302
Ui::MainWindow
ui
;
/**< Qt Designer generated object. */
303
};
304
305
#endif
306
307
Generated on Thu Dec 6 2012 04:33:17 for Vidalia by
1.8.2