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