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

Generated on Sat Aug 16 17:31:48 2008 for Vidalia by  doxygen 1.5.6