Vidalia  0.2.15
NetViewer.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.torproject.org/projects/vidalia.html. No part of Vidalia, 
00007 **  including this file, may be copied, modified, propagated, or distributed 
00008 **  except according to the terms described in the LICENSE file.
00009 */
00010 
00011 /*
00012 ** \file NetViewer.h
00013 ** \brief Displays a map of the Tor network and the user's circuits
00014 */
00015 
00016 #ifndef _NETVIEWER_H
00017 #define _NETVIEWER_H
00018 
00019 #include "config.h"
00020 #include "ui_NetViewer.h"
00021 #include "VidaliaWindow.h"
00022 #include "GeoIpResolver.h"
00023 
00024 #if defined(USE_MARBLE)
00025 #include "TorMapWidget.h"
00026 #else
00027 #include "TorMapImageView.h"
00028 #endif
00029 
00030 #include "TorControl.h"
00031 
00032 #include <QMainWindow>
00033 #include <QStringList>
00034 #include <QEvent>
00035 #include <QTimer>
00036 #include <QHash>
00037 
00038 class QDateTime;
00039 
00040 
00041 class NetViewer : public VidaliaWindow
00042 {
00043   Q_OBJECT
00044 
00045 public:
00046   /** Default constructor */
00047   NetViewer(QWidget* parent = 0);
00048 
00049 public slots:
00050   /** Displays the network map window. */
00051 //  void showWindow();
00052   /** Loads a list of current circuits and streams. */
00053   void loadConnections();
00054   /** Adds <b>circuit</b> to the list and the map */
00055   void addCircuit(const Circuit &circuit);
00056   /** Adds <b>stream</b> to the list of circuits, under the appropriate
00057    * circuit. */
00058   void addStream(const Stream &stream);
00059 
00060   /** Called when a NEWDESC event arrives. Retrieves new router descriptors
00061    * for the router identities given in <b>ids</b> and updates the router list
00062    * and network map.
00063    */
00064   void newDescriptors(const QStringList &ids);
00065 
00066   /** Called when Tor has mapped the address <b>from</b> to the address
00067    * <b>to</b>. <b>expires</b> indicates the time at which when the address
00068    * mapping will no longer be considered valid.
00069    */
00070   void addressMapped(const QString &from, const QString &to,
00071                      const QDateTime &expires);
00072 
00073   /** Clears all known information */
00074   void clear();
00075 
00076 protected:
00077   /** Called when the user changes the UI translation. */
00078   void retranslateUi();
00079 
00080 private slots:
00081   /** Called when the user selects the "Help" action on the toolbar. */
00082   void help();
00083   /** Called when the user selects the "Refresh" action on the toolbar */
00084   void refresh();
00085   /** Called when the user selects a circuit on the circuit list */
00086   void circuitSelected(const Circuit &circuit);
00087   /** Called when the user selects one or more routers in the list. */
00088   void routerSelected(const QList<RouterDescriptor> &routers);
00089   /** Handles when we get connected to Tor network */
00090   void onAuthenticated();
00091   /** Handles when we get disconnected from Tor network */
00092   void onDisconnected();
00093   /** Called when the user selects a router on the network map. Displays a 
00094    * dialog with detailed information for the router specified by
00095    * <b>id</b>.*/
00096   void displayRouterInfo(const QString &id);
00097   /** Called when the user clicks the "Zoom In" button. */
00098   void zoomIn();
00099   /** Called when the user clicks the "Zoom Out" button. */
00100   void zoomOut();
00101   /** Called when the user clicks "Full Screen" or presses Escape on the map.
00102    * Toggles the map between normal and a full screen viewing modes. */
00103   void toggleFullScreen();
00104 
00105 private:
00106   /** */
00107   void setupGeoIpResolver();
00108   /** Retrieves a list of all running routers from Tor and their descriptors,
00109    * and adds them to the RouterListWidget. */
00110   void loadNetworkStatus();
00111   /** Loads a list of address mappings from Tor. */
00112   void loadAddressMap();
00113   /** Adds a router to our list of servers and retrieves geographic location
00114    * information for the server. */
00115   void addRouter(const RouterDescriptor &rd);
00116 
00117   /** TorControl object used to talk to Tor. */
00118   TorControl* _torControl;
00119   /** Timer that fires once an hour to update the router list. */
00120   QTimer _refreshTimer;
00121   /** GeoIpResolver used to geolocate routers by IP address. */
00122   GeoIpResolver _geoip;
00123   /** Stores a list of address mappings from Tor. */
00124   AddressMap _addressMap;
00125  
00126   /** Widget that displays the Tor network map. */
00127 #if defined(USE_MARBLE)
00128   TorMapWidget* _map;
00129 #else
00130   TorMapImageView* _map;
00131 #endif
00132 
00133   /** Qt Designer generated object **/
00134   Ui::NetViewer ui;
00135 };
00136 
00137 #endif
00138