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 3276 2008-11-03 00:08:59Z 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 
00114 #if defined(USE_MINIUPNPC)
00115   /** Called when a UPnP error occurs. */
00116   void upnpError(UPNPControl::UPNPError error);
00117 #endif
00118 
00119 private:
00120   enum TorStatus {
00121     Unset,      /**< Tor's status has not yet been set. */
00122     Stopping,   /**< Tor is in the process of shutting down. */
00123     Stopped,    /**< Tor is not running. */
00124     Starting,   /**< Tor is in the process of starting. */
00125     Started,    /**< Tor is currently running. */
00126     Authenticating, /**< Vidalia is authenticating to Tor. */
00127     Authenticated,  /**< Vidalia has authenticated to Tor. */
00128     CircuitEstablished /**< Tor has built a circuit. */
00129   };
00130   /** Create the actions on the tray menu or menubar */
00131   void createActions();
00132   /** Creates a tray icon with a context menu and adds it to the system
00133    * notification area. On Mac, we also set up an application menubar. */
00134   void createTrayIcon();
00135   /** Create the tray popup menu and it's submenus */
00136   QMenu* createTrayMenu();
00137   /** Creates a default menubar on Mac */
00138   void createMenuBar();
00139   /** Updates the UI to reflect Tor's current <b>status</b>. Returns the
00140    * previously set TorStatus value. */
00141   TorStatus updateTorStatus(TorStatus status);
00142   /** Starts the web browser, if appropriately configured */
00143   void startSubprocesses();
00144   /** Starts the proxy server, if appropriately configured */
00145   void startProxy();
00146   /** Converts a TorStatus enum value to a string for debug logging purposes. */
00147   QString toString(TorStatus status);
00148   /** Authenticates Vidalia to Tor's control port. */
00149   bool authenticate();
00150   /** Searches for and attempts to load the control authentication cookie.
00151    * This assumes the cookie is named 'control_auth_cookie'. If
00152    * <b>cookiePath</b> is empty, this method will search some default locations
00153    * depending on the current platform. <b>cookiePath</b> can point to either
00154    * a cookie file or a directory containing the cookie file. */
00155   QByteArray loadControlCookie(QString cookiePath = QString());
00156   /** Called when Tor has successfully established a circuit. */
00157   void circuitEstablished();
00158   /** Checks the status of the current version of Tor to see if it's old,
00159    * unrecommended, or obsolete. */
00160   void checkTorVersion();
00161   /** Called when Tor thinks its version is old or unrecommended, and displays
00162    * a message notifying the user. */
00163   void dangerousTorVersion();
00164   /** Called when Tor's bootstrapping status changes. <b>bse</b> represents
00165    * Tor's current estimate of its bootstrapping progress. */
00166   void bootstrapStatusChanged(const BootstrapStatus &bs);
00167   /** Sets the visibility of the startup status description and progress bar
00168    * to <b>visible</b>. */
00169   void setStartupProgressVisible(bool visible);
00170   /** Sets the progress bar completion value to <b>progressValue</b> and sets
00171    * the status text to <b>description</b>. */
00172   void setStartupProgress(int percentComplete, const QString &description);
00173 
00174   /** The current status of Tor. */
00175   TorStatus _status;
00176   /** Used to determine if the Tor process exiting was intentional or not */
00177   bool _isIntentionalExit;
00178   /** Tracks whether we started a delayed server shutdown. */
00179   bool _delayedShutdownStarted;
00180   /** Set to true if Vidalia started its own Tor process. */
00181   bool _isVidaliaRunningTor;
00182   /** A MessageLog object which handles logging Tor messages */
00183   MessageLog* _messageLog;
00184   /** A BandwidthGraph object which handles monitoring Tor bandwidth usage */
00185   BandwidthGraph* _bandwidthGraph;
00186   /** A NetViewer object which displays the Tor network graphically */
00187   NetViewer* _netViewer;
00188   /** A ConfigDialog object which lets the user configure Tor and Vidalia */
00189   ConfigDialog* _configDialog;
00190   /** A TorControl object that handles communication with Tor */
00191   TorControl* _torControl;
00192   /** A HelperProcess object that manages the web browser */
00193   HelperProcess* _browserProcess;
00194   /** A HelperProcess object that manages the IM client */
00195   HelperProcess* _imProcess;
00196   /** A HelperProcess object that manages the proxy server */
00197   HelperProcess* _proxyProcess;
00198   /** Remembers the control password between when we start Tor with a hash of
00199    * the password and when we need to provide the password itself. */
00200   QString _controlPassword;
00201   /** Set to true if we should use the control password saved in TorSettings
00202    * when authenticating to Tor. */
00203   bool _useSavedPassword;
00204   /** The Vidalia icon that sits in the tray. */
00205   TrayIcon _trayIcon;
00206  
00207   /** Defines the actions for the tray menu */
00208   QAction* _controlPanelAct;
00209   QAction* _startStopAct;
00210   QAction* _configAct;
00211   QAction* _aboutAct;
00212   QAction* _exitAct;
00213   QAction* _bandwidthAct;
00214   QAction* _messageAct;
00215   QAction* _helpAct;
00216   QAction* _networkAct;
00217   QAction* _newIdentityAct;
00218 
00219   Ui::MainWindow ui; /**< Qt Designer generated object. */
00220 };
00221 
00222 #endif
00223 
00224 

Generated on Wed Nov 26 21:03:58 2008 for Vidalia by  doxygen 1.5.6