Vidalia
0.2.17
|
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.torproject.org/projects/vidalia.html. No part of Vidalia, 00007 ** including this file, may be copied, modified, propagated, or distributed 00008 ** except according to the terms described in the LICENSE file. 00009 */ 00010 00011 /* 00012 ** \file MainWindow.h 00013 ** \brief Main window. Creates tray menu and child windows 00014 */ 00015 00016 #ifndef _MAINWINDOW_H 00017 #define _MAINWINDOW_H 00018 00019 #include "config.h" 00020 #include "ui_MainWindow.h" 00021 00022 #include "VidaliaWindow.h" 00023 #include "HelperProcess.h" 00024 #include "AboutDialog.h" 00025 #include "MessageLog.h" 00026 #include "BandwidthGraph.h" 00027 #include "ConfigDialog.h" 00028 #include "HelpBrowser.h" 00029 #include "NetViewer.h" 00030 00031 #include "TorControl.h" 00032 00033 #if defined(USE_AUTOUPDATE) 00034 #include "UpdateProcess.h" 00035 #include "UpdateProgressDialog.h" 00036 #endif 00037 #if defined(USE_MINIUPNPC) 00038 #include "UPNPControl.h" 00039 #endif 00040 00041 #include <QMainWindow> 00042 #include <QTimer> 00043 #include <QSystemTrayIcon> 00044 00045 class MainWindow : public VidaliaWindow 00046 { 00047 Q_OBJECT 00048 00049 public: 00050 /** Default constructor */ 00051 MainWindow(); 00052 /** Destructor. */ 00053 ~MainWindow(); 00054 00055 public slots: 00056 /** Shows or hides this window. **/ 00057 virtual void setVisible(bool visible); 00058 00059 protected: 00060 /** Called when the user changes the UI translation. */ 00061 virtual void retranslateUi(); 00062 00063 private slots: 00064 /** Respond to a double-click on the tray icon by opening the Control Panel 00065 * window. */ 00066 void trayIconActivated(QSystemTrayIcon::ActivationReason reason); 00067 /** Displays the help browser and displays the most recently viewed help 00068 * topic. */ 00069 void showHelpDialog(); 00070 /** Called when a child window requests the given help <b>topic</b>. */ 00071 void showHelpDialog(const QString &topic); 00072 /** Called when the user selects "Start" from the menu. */ 00073 void start(); 00074 /** Called when the user changes a setting that needs Tor restarting */ 00075 void restart(); 00076 /** Called when the Tor process fails to start. */ 00077 void startFailed(QString errmsg); 00078 /** Called when the Tor process has successfully started. */ 00079 void started(); 00080 /** Called when the user selects "Stop" form the menu. */ 00081 bool stop(); 00082 /** Called when the Tor process has exited, either expectedly or not. */ 00083 void stopped(int errorCode, QProcess::ExitStatus exitStatus); 00084 /** Called when the control socket has connected to Tor. */ 00085 void connected(); 00086 /** Called when the control connection fails. */ 00087 void connectFailed(QString errmsg); 00088 /** Called when Vidalia wants to disconnect from a Tor it did not start. */ 00089 void disconnect(); 00090 /** Called when the control socket has been disconnected. */ 00091 void disconnected(); 00092 /** Called when Vidalia has successfully authenticated to Tor. */ 00093 void authenticated(); 00094 /** Called when Vidalia fails to authenticate to Tor. The failure reason is 00095 * specified in <b>errmsg</b>. */ 00096 void authenticationFailed(QString errmsg); 00097 /** Re-enables the 'New Identity' button after a delay from the previous time 00098 * 'New Identity' was used. */ 00099 void enableNewIdentity(); 00100 /** Called when the user selects the "New Identity" action from the menu. */ 00101 void newIdentity(); 00102 /** Called when the user exits Vidalia. */ 00103 void close(); 00104 /** Called when the application has started and the main event loop is 00105 * running. */ 00106 void running(); 00107 /** Terminate the Tor process if it is being run under Vidalia, disconnect 00108 * all TorControl signals, and exit Vidalia. */ 00109 void aboutToQuit(); 00110 /** Creates and displays Vidalia's About dialog. */ 00111 void showAboutDialog(); 00112 /** Creates and displays the Configuration dialog with the current page set 00113 * to <b>page</b>. */ 00114 void showConfigDialog(ConfigDialog::Page page = ConfigDialog::General); 00115 /** Displays the Configuration dialog, set to the Server page. */ 00116 void showServerConfigDialog(); 00117 /** Called when the "show on startup" checkbox is toggled. */ 00118 void toggleShowOnStartup(bool checked); 00119 /** Called when the web browser or IM client have stopped */ 00120 void onSubprocessFinished(int exitCode, QProcess::ExitStatus exitStatus); 00121 /** Called periodically to check if the browser is running. If it is not, 00122 * exit Vidalia cleanly */ 00123 void onCheckForBrowser(); 00124 /** Called web the web browser failed to start */ 00125 void onBrowserFailed(QString errmsg); 00126 /** Called web the IM client failed to start */ 00127 void onIMFailed(QString errmsg); 00128 /** Called when the proxy server fails to start */ 00129 void onProxyFailed(QString errmsg); 00130 00131 /** Called when Tor has successfully established a circuit. */ 00132 void circuitEstablished(); 00133 /** Called when Tor thinks the user has tried to connect to a port that 00134 * typically is used for unencrypted applications. Warns the user and allows 00135 * them to ignore future warnings on <b>port</b>. */ 00136 void warnDangerousPort(quint16 port, bool rejected); 00137 /** Called when Tor's bootstrapping status changes. <b>bse</b> represents 00138 * Tor's current estimate of its bootstrapping progress. */ 00139 void bootstrapStatusChanged(const BootstrapStatus &bs); 00140 /** Called when Tor thinks its version is old or unrecommended, and displays 00141 * a message notifying the user. */ 00142 void dangerousTorVersion(tc::TorVersionStatus reason, 00143 const QString &version, 00144 const QStringList &recommended); 00145 00146 #if defined(USE_AUTOUPDATE) 00147 /** Called when the user clicks the 'Check Now' button in the General 00148 * settings page. */ 00149 void checkForUpdatesWithUi(); 00150 /** Called when the update interval timer expires, notifying Vidalia that 00151 * we should check for updates again. */ 00152 void checkForUpdates(bool showProgress = false); 00153 /** Called when the check for software updates fails. */ 00154 void checkForUpdatesFailed(const QString &errmsg); 00155 /** Called when there is an update available for installation. */ 00156 void updatesAvailable(UpdateProcess::BundleInfo bi, 00157 const PackageList &packageList); 00158 /** Stops Tor (if necessary), installs any available for <b>bi</b>, and 00159 * restarts Tor (if necessary). */ 00160 void installUpdates(UpdateProcess::BundleInfo bi); 00161 /** Called when all <b>numUpdates</b> software updates have been installed 00162 * successfully. */ 00163 void updatesInstalled(int numUpdates); 00164 /** Called when an update fails to install. <b>errmsg</b> contains details 00165 * about the failure. */ 00166 void installUpdatesFailed(const QString &errmsg); 00167 #endif 00168 00169 #if defined(USE_MINIUPNPC) 00170 /** Called when a UPnP error occurs. */ 00171 void upnpError(UPNPControl::UPNPError error); 00172 #endif 00173 00174 private: 00175 enum TorStatus { 00176 Unset, /**< Tor's status has not yet been set. */ 00177 Stopping, /**< Tor is in the process of shutting down. */ 00178 Stopped, /**< Tor is not running. */ 00179 Starting, /**< Tor is in the process of starting. */ 00180 Started, /**< Tor is currently running. */ 00181 Authenticating, /**< Vidalia is authenticating to Tor. */ 00182 Authenticated, /**< Vidalia has authenticated to Tor. */ 00183 CircuitEstablished /**< Tor has built a circuit. */ 00184 }; 00185 /** Create the actions on the tray menu or menubar */ 00186 void createActions(); 00187 /** Creates a tray icon with a context menu and adds it to the system 00188 * notification area. On Mac, we also set up an application menubar. */ 00189 void createTrayIcon(); 00190 /** Create the tray popup menu and it's submenus */ 00191 QMenu* createTrayMenu(); 00192 /** Creates a default menubar on Mac */ 00193 void createMenuBar(); 00194 /** Sets the current tray or dock icon image to <b>iconFile</b>. */ 00195 void setTrayIcon(const QString &iconFile); 00196 /** Updates the UI to reflect Tor's current <b>status</b>. Returns the 00197 * previously set TorStatus value. */ 00198 TorStatus updateTorStatus(TorStatus status); 00199 /** Start a web browser when given the directory containing the executable and profile */ 00200 void launchBrowserFromDirectory(); 00201 /** Starts the web browser, if appropriately configured */ 00202 void startSubprocesses(); 00203 /** Starts the proxy server, if appropriately configured */ 00204 void startProxy(); 00205 /** Converts a TorStatus enum value to a string for debug logging purposes. */ 00206 QString toString(TorStatus status); 00207 /** Authenticates Vidalia to Tor's control port. */ 00208 bool authenticate(); 00209 /** Searches for and attempts to load the control authentication cookie. 00210 * This assumes the cookie is named 'control_auth_cookie'. If 00211 * <b>cookiePath</b> is empty, this method will search some default locations 00212 * depending on the current platform. <b>cookiePath</b> can point to either 00213 * a cookie file or a directory containing the cookie file. */ 00214 QByteArray loadControlCookie(QString cookiePath = QString()); 00215 /** Checks the status of the current version of Tor to see if it's old, 00216 * unrecommended, or obsolete. */ 00217 void checkTorVersion(); 00218 /** Alerts the user that their current Tor version is either obsolete or 00219 * no longer recommended. If Vidalia was built with auto-update support, 00220 * they will be given the option to check for available updates. */ 00221 void displayTorVersionWarning(); 00222 /** Sets the visibility of the startup status description and progress bar 00223 * to <b>visible</b>. */ 00224 void setStartupProgressVisible(bool visible); 00225 /** Sets the progress bar completion value to <b>progressValue</b> and sets 00226 * the status text to <b>description</b>. */ 00227 void setStartupProgress(int percentComplete, const QString &description); 00228 /** Adds the needed variables to the environment that the browser will 00229 * need */ 00230 QStringList updateBrowserEnv(); 00231 00232 /** The current status of Tor. */ 00233 TorStatus _status; 00234 /** Used to determine if the Tor process exiting was intentional or not */ 00235 bool _isIntentionalExit; 00236 /** Tracks whether we started a delayed server shutdown. */ 00237 bool _delayedShutdownStarted; 00238 /** Set to true if Vidalia started its own Tor process. */ 00239 bool _isVidaliaRunningTor; 00240 /** A MessageLog object which handles logging Tor messages */ 00241 MessageLog* _messageLog; 00242 /** A BandwidthGraph object which handles monitoring Tor bandwidth usage */ 00243 BandwidthGraph* _bandwidthGraph; 00244 /** A NetViewer object which displays the Tor network graphically */ 00245 NetViewer* _netViewer; 00246 /** A ConfigDialog object which lets the user configure Tor and Vidalia */ 00247 ConfigDialog* _configDialog; 00248 /** A TorControl object that handles communication with Tor */ 00249 TorControl* _torControl; 00250 /** A HelperProcess object that manages the web browser */ 00251 HelperProcess* _browserProcess; 00252 /** A HelperProcess object that manages the IM client */ 00253 HelperProcess* _imProcess; 00254 /** A HelperProcess object that manages the proxy server */ 00255 HelperProcess* _proxyProcess; 00256 /** Remembers the control password between when we start Tor with a hash of 00257 * the password and when we need to provide the password itself. */ 00258 QString _controlPassword; 00259 /** Set to true if we should use the control password saved in TorSettings 00260 * when authenticating to Tor. */ 00261 bool _useSavedPassword; 00262 /** The Vidalia icon that sits in the tray. */ 00263 QSystemTrayIcon _trayIcon; 00264 00265 #if defined(USE_AUTOUPDATE) 00266 /** Timer used to remind us to check for software updates. */ 00267 QTimer _updateTimer; 00268 /** The auto-update process used to check for and download updates. */ 00269 UpdateProcess _updateProcess; 00270 /** Dialog instance that is be used to show the progress of the auto-update 00271 * executable. */ 00272 UpdateProgressDialog _updateProgressDialog; 00273 /** Set to true if Vidalia should restart Tor after a software upgrade. */ 00274 bool _restartTorAfterUpgrade; 00275 #endif 00276 /** The menubar (Mac OS X only). */ 00277 QMenuBar *_menuBar; 00278 00279 /** Defines the actions for the tray menu */ 00280 QAction* _actionShowControlPanel; 00281 QAction* _actionStartStopTor; 00282 QAction* _actionShowConfig; 00283 QAction* _actionShowAbout; 00284 QAction* _actionExit; 00285 QAction* _actionShowBandwidth; 00286 QAction* _actionShowMessageLog; 00287 QAction* _actionShowHelp; 00288 QAction* _actionShowNetworkMap; 00289 QAction* _actionNewIdentity; 00290 00291 quint16 _autoControlPort; 00292 00293 Ui::MainWindow ui; /**< Qt Designer generated object. */ 00294 }; 00295 00296 #endif 00297 00298