mainwindow.h

Go to the documentation of this file.
00001 /****************************************************************
00002  *  Vidalia is distributed under the following license:
00003  *
00004  *  Copyright (C) 2006,  Matt Edman, Justin Hipple
00005  *
00006  *  This program is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU General Public License
00008  *  as published by the Free Software Foundation; either version 2
00009  *  of the License, or (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  *  Boston, MA  02110-1301, USA.
00020  ****************************************************************/
00021 
00022 /**
00023  * \file mainwindow.h
00024  * \version $Id: mainwindow.h 1866 2007-08-24 23:16:35Z edmanm $
00025  * \brief Main (hidden) window. Creates tray menu and child windows
00026  */
00027 
00028 #ifndef _MAINWINDOW_H
00029 #define _MAINWINDOW_H
00030 
00031 #include <QMainWindow>
00032 
00033 #include <control/torcontrol.h>
00034 
00035 /* QSystemTrayIcon appeared in Qt 4.2, but we need a bugfix to it on Mac 
00036  * that won't appear until Qt 4.2.2. */
00037 #if QT_VERSION >= 0x040200 && !defined(Q_WS_MAC)
00038 #define USE_QSYSTEMTRAYICON  1
00039 #include <QSystemTrayIcon>
00040 #else
00041 #undef USE_QSYSTEMTRAYICON
00042 #include "tray/trayicon.h"
00043 #endif
00044 
00045 #include "common/vidaliawindow.h"
00046 #include "about/aboutdialog.h"
00047 #include "log/messagelog.h"
00048 #include "bwgraph/bwgraph.h"
00049 #include "config/configdialog.h"
00050 #include "help/browser/helpbrowser.h"
00051 #include "network/netviewer.h"
00052 #include "ui_mainwindow.h"
00053 
00054 
00055 class MainWindow : public VidaliaWindow
00056 {
00057   Q_OBJECT
00058 
00059 public:
00060   /** Default constructor */
00061   MainWindow();
00062   /** Destructor. */
00063   ~MainWindow();
00064 
00065 private slots:
00066   /** Called when the user selects "Start" from the menu. */
00067   void start();
00068   /** Called when the Tor process fails to start. */
00069   void startFailed(QString errmsg);
00070   /** Called when the Tor process has successfully started. */
00071   void started();
00072   /** Called when the user selects "Stop" form the menu. */
00073   bool stop();
00074   /** Called when the Tor process has exited, either expectedly or not. */
00075   void stopped(int errorCode, QProcess::ExitStatus exitStatus);
00076   /** Called when the control socket has connected to Tor. */
00077   void connected();
00078   /** Called when the control connection fails. */
00079   void connectFailed(QString errmsg);
00080   /** Called when Vidalia wants to disconnect from a Tor it did not start. */
00081   void disconnect();
00082   /** Called when the control socket has been disconnected. */
00083   void disconnected();
00084   /** Called when Vidalia has successfully authenticated to Tor. */
00085   void authenticated();
00086   /** Called when Vidalia fails to authenticate to Tor. The failure reason is
00087    * specified in <b>errmsg</b>. */
00088   void authenticationFailed(QString errmsg);
00089   /** Re-enables the 'New Identity' button after a delay from the previous time
00090    * 'New Identity' was used. */
00091   void enableNewIdentity();
00092   /** Called when the user selects the "New Identity" action from the menu. */
00093   void newIdentity();
00094   /** Called when the user exits Vidalia. */
00095   void close();
00096   /** Terminate the Tor process if it is being run under Vidalia, disconnect
00097    * all TorControl signals, and exit Vidalia. */
00098   void shutdown();
00099   /** Creates and displays Vidalia's About dialog. */
00100   void showAboutDialog();
00101   /** Creates and displays the Configuration dialog with the current page set
00102    * to <b>page</b>. */
00103   void showConfigDialog(ConfigDialog::Page page = ConfigDialog::General);
00104   /** Displays the Configuration dialog, set to the Server page. */
00105   void showServerConfigDialog();
00106   /** Called when the "show on startup" checkbox is toggled. */
00107   void toggleShowOnStartup(bool checked);
00108   
00109 #if defined(USE_QSYSTEMTRAYICON)
00110   /** Displays the main window if <b>reason</b> is DoubleClick. */
00111   void trayActivated(QSystemTrayIcon::ActivationReason reason);
00112 #endif
00113 
00114 private:
00115   enum TorStatus {
00116     Unset,      /**< Tor's status has not yet been set. */
00117     Stopping,   /**< Tor is in the process of shutting down. */
00118     Stopped,    /**< Tor is not running. */
00119     Starting,   /**< Tor is in the process of starting. */
00120     Started,    /**< Tor is currently running. */
00121     Connecting, /**< Vidalia is connecting to Tor. */
00122     Connected,  /**< Vidalia is connected to Tor. */
00123     Disconnecting,  /**< Vidalia is disconnecting from Tor. */
00124     Disconnected,   /**< Vidalia is disconnected from Tor. */
00125     Authenticating, /**< Vidalia is authenticating to Tor. */
00126     Authenticated   /**< Vidalia has authenticated to Tor. */
00127   };
00128   /** Create the actions on the tray menu or menubar */
00129   void createActions();
00130   /** Creates a tray icon with a context menu and adds it to the system
00131    * notification area. On Mac, we also set up an application menubar. */
00132   void createTrayIcon();
00133   /** Create the tray popup menu and it's submenus */
00134   QMenu* createTrayMenu();
00135   /** Creates a default menubar on Mac */
00136   void createMenuBar();
00137   /** Returns true if we're running on a platform with tray icon support. */
00138   bool isTrayIconSupported();
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   /** Converts a TorStatus enum value to a string for debug logging purposes. */
00143   QString toString(TorStatus status);
00144   /** Authenticates Vidalia to Tor's control port. */
00145   bool authenticate();
00146   /** Searches for and attempts to load the control authentication cookie.
00147    * This assumes the cookie is named 'control_auth_cookie'. If
00148    * <b>cookiePath</b> is empty, this method will search some default locations
00149    * depending on the current platform. <b>cookiePath</b> can point to either
00150    * a cookie file or a directory containing the cookie file. */
00151   QByteArray loadControlCookie(QString cookiePath = QString());
00152 
00153   /** The current status of Tor. */
00154   TorStatus _status;
00155   /** Used to determine if the Tor process exiting was intentional or not */
00156   bool _isIntentionalExit;
00157   /** Tracks whether we started a delayed server shutdown. */
00158   bool _delayedShutdownStarted;
00159   /** Set to true if Vidalia started its own Tor process. */
00160   bool _isVidaliaRunningTor;
00161   /** A MessageLog object which handles logging Tor messages */
00162   MessageLog* _messageLog;
00163   /** A BandwidthGraph object which handles monitoring Tor bandwidth usage */
00164   BandwidthGraph* _bandwidthGraph;
00165   /** A NetViewer object which displays the Tor network graphically */
00166   NetViewer* _netViewer;
00167   /** A TorControl object that handles communication with Tor */
00168   TorControl* _torControl;
00169 
00170 #if defined(USE_QSYSTEMTRAYICON)
00171   QSystemTrayIcon _trayIcon; /**< The Vidalia icon that sits in the tray.
00172                                   (post-Qt 4.2) */
00173 #else
00174   TrayIcon _trayIcon; /**< The Vidalia icon that sits in the tray. (pre-Qt 4.2) */
00175 #endif
00176   
00177   /** Defines the actions for the tray menu */
00178   QAction* _controlPanelAct;
00179   QAction* _startStopAct;
00180   QAction* _configAct;
00181   QAction* _aboutAct;
00182   QAction* _exitAct;
00183   QAction* _bandwidthAct;
00184   QAction* _messageAct;
00185   QAction* _helpAct;
00186   QAction* _networkAct;
00187   QAction* _newIdentityAct;
00188 
00189   Ui::MainWindow ui; /**< Qt Designer generated object. */
00190 };
00191 
00192 #endif
00193 

Generated on Wed Sep 5 15:49:27 2007 for Vidalia by  doxygen 1.5.3