MainWindow.h

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

Generated on 31 Mar 2010 for Vidalia by  doxygen 1.6.1