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 3742 2009-04-29 20:13:52Z edmanm $
00014 ** \brief Main (hidden) window. Creates tray menu and child windows
00015 */
00016 
00017 #ifndef _MAINWINDOW_H
00018 #define _MAINWINDOW_H
00019 
00020 #include <QMainWindow>
00021 #include <torcontrol.h>
00022 #include <bootstrapstatusevent.h>
00023 
00024 #include "vidaliawindow.h"
00025 #include "tray/trayicon.h"
00026 #include "about/aboutdialog.h"
00027 #include "log/messagelog.h"
00028 #include "bwgraph/bwgraph.h"
00029 #include "config/configdialog.h"
00030 #include "help/browser/helpbrowser.h"
00031 #include "network/netviewer.h"
00032 #include "ui_mainwindow.h"
00033 #include "helperprocess.h"
00034 #include "config.h"
00035 
00036 #if defined(USE_MINIUPNPC)
00037 #include "config/upnpcontrol.h"
00038 #endif
00039 
00040 class MainWindow : public VidaliaWindow
00041 {
00042   Q_OBJECT
00043 
00044 public:
00045   /** Default constructor */
00046   MainWindow();
00047   /** Destructor. */
00048   ~MainWindow();
00049 
00050 public slots:
00051   /** Shows or hides this window. **/
00052   virtual void setVisible(bool visible);
00053 
00054 protected:
00055   /** Catches and processes Tor client status events. */
00056   virtual void customEvent(QEvent *event);
00057 
00058 private slots:
00059   /** Displays the help browser and displays the most recently viewed help
00060    * topic. */
00061   void showHelpDialog();
00062   /** Called when a child window requests the given help <b>topic</b>. */
00063   void showHelpDialog(const QString &topic);
00064   /** Called when the user selects "Start" from the menu. */
00065   void start();
00066   /** Called when the Tor process fails to start. */
00067   void startFailed(QString errmsg);
00068   /** Called when the Tor process has successfully started. */
00069   void started();
00070   /** Called when the user selects "Stop" form the menu. */
00071   bool stop();
00072   /** Called when the Tor process has exited, either expectedly or not. */
00073   void stopped(int errorCode, QProcess::ExitStatus exitStatus);
00074   /** Called when the control socket has connected to Tor. */
00075   void connected();
00076   /** Called when the control connection fails. */
00077   void connectFailed(QString errmsg);
00078   /** Called when Vidalia wants to disconnect from a Tor it did not start. */
00079   void disconnect();
00080   /** Called when the control socket has been disconnected. */
00081   void disconnected();
00082   /** Called when Vidalia has successfully authenticated to Tor. */
00083   void authenticated();
00084   /** Called when Vidalia fails to authenticate to Tor. The failure reason is
00085    * specified in <b>errmsg</b>. */
00086   void authenticationFailed(QString errmsg);
00087   /** Re-enables the 'New Identity' button after a delay from the previous time
00088    * 'New Identity' was used. */
00089   void enableNewIdentity();
00090   /** Called when the user selects the "New Identity" action from the menu. */
00091   void newIdentity();
00092   /** Called when the user exits Vidalia. */
00093   void close();
00094   /** Called when the application has started and the main event loop is
00095    * running. */
00096   void running();
00097   /** Terminate the Tor process if it is being run under Vidalia, disconnect
00098    * all TorControl signals, and exit Vidalia. */
00099   void shutdown();
00100   /** Creates and displays Vidalia's About dialog. */
00101   void showAboutDialog();
00102   /** Creates and displays the Configuration dialog with the current page set
00103    * to <b>page</b>. */
00104   void showConfigDialog(ConfigDialog::Page page = ConfigDialog::General);
00105   /** Displays the Configuration dialog, set to the Server page. */
00106   void showServerConfigDialog();
00107   /** Called when the "show on startup" checkbox is toggled. */
00108   void toggleShowOnStartup(bool checked);
00109   /** Called when the web browser or IM client have stopped */
00110   void onSubprocessFinished(int exitCode, QProcess::ExitStatus exitStatus);
00111   /** Called periodically to check if the browser is running. If it is not,
00112    * exit Vidalia cleanly */
00113   void onCheckForBrowser();
00114   /** Called web the web browser failed to start */
00115   void onBrowserFailed(QString errmsg);
00116   /** Called web the IM client failed to start */
00117   void onIMFailed(QString errmsg);
00118   /** Called when the proxy server fails to start */
00119   void onProxyFailed(QString errmsg);
00120 
00121 #if defined(USE_MINIUPNPC)
00122   /** Called when a UPnP error occurs. */
00123   void upnpError(UPNPControl::UPNPError error);
00124 #endif
00125 
00126 private:
00127   enum TorStatus {
00128     Unset,      /**< Tor's status has not yet been set. */
00129     Stopping,   /**< Tor is in the process of shutting down. */
00130     Stopped,    /**< Tor is not running. */
00131     Starting,   /**< Tor is in the process of starting. */
00132     Started,    /**< Tor is currently running. */
00133     Authenticating, /**< Vidalia is authenticating to Tor. */
00134     Authenticated,  /**< Vidalia has authenticated to Tor. */
00135     CircuitEstablished /**< Tor has built a circuit. */
00136   };
00137   /** Create the actions on the tray menu or menubar */
00138   void createActions();
00139   /** Creates a tray icon with a context menu and adds it to the system
00140    * notification area. On Mac, we also set up an application menubar. */
00141   void createTrayIcon();
00142   /** Create the tray popup menu and it's submenus */
00143   QMenu* createTrayMenu();
00144   /** Creates a default menubar on Mac */
00145   void createMenuBar();
00146   /** Updates the UI to reflect Tor's current <b>status</b>. Returns the
00147    * previously set TorStatus value. */
00148   TorStatus updateTorStatus(TorStatus status);
00149   /** Start a web browser when given the directory containing the executable and profile */
00150   void launchBrowserFromDirectory();
00151   /** Starts the web browser, if appropriately configured */
00152   void startSubprocesses();
00153   /** Starts the proxy server, if appropriately configured */
00154   void startProxy();
00155   /** Converts a TorStatus enum value to a string for debug logging purposes. */
00156   QString toString(TorStatus status);
00157   /** Authenticates Vidalia to Tor's control port. */
00158   bool authenticate();
00159   /** Searches for and attempts to load the control authentication cookie.
00160    * This assumes the cookie is named 'control_auth_cookie'. If
00161    * <b>cookiePath</b> is empty, this method will search some default locations
00162    * depending on the current platform. <b>cookiePath</b> can point to either
00163    * a cookie file or a directory containing the cookie file. */
00164   QByteArray loadControlCookie(QString cookiePath = QString());
00165   /** Called when Tor has successfully established a circuit. */
00166   void circuitEstablished();
00167   /** Checks the status of the current version of Tor to see if it's old,
00168    * unrecommended, or obsolete. */
00169   void checkTorVersion();
00170   /** Called when Tor thinks its version is old or unrecommended, and displays
00171    * a message notifying the user. */
00172   void dangerousTorVersion();
00173   /** Called when Tor's bootstrapping status changes. <b>bse</b> represents
00174    * Tor's current estimate of its bootstrapping progress. */
00175   void bootstrapStatusChanged(const BootstrapStatus &bs);
00176   /** Sets the visibility of the startup status description and progress bar
00177    * to <b>visible</b>. */
00178   void setStartupProgressVisible(bool visible);
00179   /** Sets the progress bar completion value to <b>progressValue</b> and sets
00180    * the status text to <b>description</b>. */
00181   void setStartupProgress(int percentComplete, const QString &description);
00182 
00183   /** The current status of Tor. */
00184   TorStatus _status;
00185   /** Used to determine if the Tor process exiting was intentional or not */
00186   bool _isIntentionalExit;
00187   /** Tracks whether we started a delayed server shutdown. */
00188   bool _delayedShutdownStarted;
00189   /** Set to true if Vidalia started its own Tor process. */
00190   bool _isVidaliaRunningTor;
00191   /** A MessageLog object which handles logging Tor messages */
00192   MessageLog* _messageLog;
00193   /** A BandwidthGraph object which handles monitoring Tor bandwidth usage */
00194   BandwidthGraph* _bandwidthGraph;
00195   /** A NetViewer object which displays the Tor network graphically */
00196   NetViewer* _netViewer;
00197   /** A ConfigDialog object which lets the user configure Tor and Vidalia */
00198   ConfigDialog* _configDialog;
00199   /** A TorControl object that handles communication with Tor */
00200   TorControl* _torControl;
00201   /** A HelperProcess object that manages the web browser */
00202   HelperProcess* _browserProcess;
00203   /** A HelperProcess object that manages the IM client */
00204   HelperProcess* _imProcess;
00205   /** A HelperProcess object that manages the proxy server */
00206   HelperProcess* _proxyProcess;
00207   /** Remembers the control password between when we start Tor with a hash of
00208    * the password and when we need to provide the password itself. */
00209   QString _controlPassword;
00210   /** Set to true if we should use the control password saved in TorSettings
00211    * when authenticating to Tor. */
00212   bool _useSavedPassword;
00213   /** The Vidalia icon that sits in the tray. */
00214   TrayIcon _trayIcon;
00215  
00216   /** Defines the actions for the tray menu */
00217   QAction* _controlPanelAct;
00218   QAction* _startStopAct;
00219   QAction* _configAct;
00220   QAction* _aboutAct;
00221   QAction* _exitAct;
00222   QAction* _bandwidthAct;
00223   QAction* _messageAct;
00224   QAction* _helpAct;
00225   QAction* _networkAct;
00226   QAction* _newIdentityAct;
00227 
00228   Ui::MainWindow ui; /**< Qt Designer generated object. */
00229 };
00230 
00231 #endif
00232 
00233 

Generated on Tue Jul 7 17:00:56 2009 for Vidalia by  doxygen 1.4.7