Sophie

Sophie

distrib > Mandriva > 2010.2 > i586 > media > contrib-backports > by-pkgid > 9601c7beb4ff23e834bfa171795ed560 > files > 331

vidalia-0.2.9-1mdv2010.1.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Vidalia: TorMapWidget.cpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.3 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="dir_b47abd1aad201a152869566145babb61.html">src</a>&nbsp;&raquo;&nbsp;<a class="el" href="dir_695ba8f8357372e02d38c40b3c6dbe81.html">vidalia</a>&nbsp;&raquo;&nbsp;<a class="el" href="dir_3776330d706700e272fa8df738fecea6.html">network</a>
  </div>
</div>
<div class="contents">
<h1>TorMapWidget.cpp</h1><a href="_tor_map_widget_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment">**  This file is part of Vidalia, and is subject to the license terms in the</span>
<a name="l00003"></a>00003 <span class="comment">**  LICENSE file, found in the top level directory of this distribution. If you</span>
<a name="l00004"></a>00004 <span class="comment">**  did not receive the LICENSE file with this file, you may obtain it from the</span>
<a name="l00005"></a>00005 <span class="comment">**  Vidalia source package distributed by the Vidalia Project at</span>
<a name="l00006"></a>00006 <span class="comment">**  http://www.vidalia-project.net/. No part of Vidalia, including this file,</span>
<a name="l00007"></a>00007 <span class="comment">**  may be copied, modified, propagated, or distributed except according to the</span>
<a name="l00008"></a>00008 <span class="comment">**  terms described in the LICENSE file.</span>
<a name="l00009"></a>00009 <span class="comment">*/</span>
<a name="l00010"></a>00010 
<a name="l00011"></a>00011 <span class="comment">/*</span>
<a name="l00012"></a>00012 <span class="comment">** \file TorMapWidget.cpp</span>
<a name="l00013"></a>00013 <span class="comment">** \version $Id: TorMapWidget.cpp 4020 2009-08-09 19:10:45Z edmanm $</span>
<a name="l00014"></a>00014 <span class="comment">** \brief Displays Tor servers and circuits on a map of the world</span>
<a name="l00015"></a>00015 <span class="comment">*/</span>
<a name="l00016"></a>00016 
<a name="l00017"></a>00017 <span class="preprocessor">#include &quot;<a class="code" href="_tor_map_widget_8h.html">TorMapWidget.h</a>&quot;</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &quot;<a class="code" href="_tor_map_widget_input_handler_8h.html">TorMapWidgetInputHandler.h</a>&quot;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#include &quot;<a class="code" href="_tor_map_widget_popup_menu_8h.html">TorMapWidgetPopupMenu.h</a>&quot;</span>
<a name="l00020"></a>00020 <span class="preprocessor">#include &quot;<a class="code" href="_vidalia_8h.html">Vidalia.h</a>&quot;</span>
<a name="l00021"></a>00021 
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;MarbleModel.h&gt;</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include &lt;HttpDownloadManager.h&gt;</span>
<a name="l00024"></a>00024 
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;QStringList&gt;</span>
<a name="l00026"></a>00026 
<a name="l00027"></a>00027 <span class="keyword">using namespace </span>Marble;
<a name="l00028"></a>00028 <span class="comment"></span>
<a name="l00029"></a>00029 <span class="comment">/** QPens to use for drawing different map elements */</span>
<a name="l00030"></a><a class="code" href="_tor_map_widget_8cpp.html#aa1220bcce74390150be7253b74d2a64d">00030</a> <span class="preprocessor">#define CIRCUIT_NORMAL_PEN      QPen(Qt::blue,  2.0)</span>
<a name="l00031"></a><a class="code" href="_tor_map_widget_8cpp.html#a1bfd4bbb034e09ab8e6307a865ef8ee3">00031</a> <span class="preprocessor"></span><span class="preprocessor">#define CIRCUIT_SELECTED_PEN    QPen(Qt::green, 3.0)</span>
<a name="l00032"></a>00032 <span class="preprocessor"></span>
<a name="l00033"></a>00033 <span class="comment"></span>
<a name="l00034"></a>00034 <span class="comment">/** Default constructor */</span>
<a name="l00035"></a><a class="code" href="class_tor_map_widget.html#ae88980e6de02700663a16992745057e6">00035</a> <a class="code" href="class_tor_map_widget.html#ae88980e6de02700663a16992745057e6">TorMapWidget::TorMapWidget</a>(QWidget *parent)
<a name="l00036"></a>00036   : MarbleWidget(parent)
<a name="l00037"></a>00037 {
<a name="l00038"></a>00038   setMapThemeId(<span class="stringliteral">&quot;earth/srtm/srtm.dgml&quot;</span>);
<a name="l00039"></a>00039   setShowScaleBar(<span class="keyword">false</span>);
<a name="l00040"></a>00040   setShowCrosshairs(<span class="keyword">false</span>);
<a name="l00041"></a>00041   setAnimationsEnabled(<span class="keyword">true</span>);
<a name="l00042"></a>00042   setCursor(Qt::OpenHandCursor);
<a name="l00043"></a>00043 
<a name="l00044"></a>00044   model()-&gt;downloadManager()-&gt;setDownloadEnabled(<span class="keyword">false</span>);
<a name="l00045"></a>00045 
<a name="l00046"></a>00046   <a class="code" href="class_tor_map_widget_input_handler.html">TorMapWidgetInputHandler</a> *handler = <span class="keyword">new</span> <a class="code" href="class_tor_map_widget_input_handler.html">TorMapWidgetInputHandler</a>();
<a name="l00047"></a>00047   <a class="code" href="class_tor_map_widget_popup_menu.html">TorMapWidgetPopupMenu</a> *popupMenu  = <span class="keyword">new</span> <a class="code" href="class_tor_map_widget_popup_menu.html">TorMapWidgetPopupMenu</a>(<span class="keyword">this</span>);
<a name="l00048"></a>00048 
<a name="l00049"></a>00049   connect(handler, SIGNAL(featureClicked(QPoint,Qt::MouseButton)),
<a name="l00050"></a>00050           popupMenu, SLOT(featureClicked(QPoint,Qt::MouseButton)));
<a name="l00051"></a>00051   connect(popupMenu, SIGNAL(<a class="code" href="class_tor_map_widget.html#a48cc137b41ad8c0b04eea56f795c40fc">displayRouterInfo</a>(QString)),
<a name="l00052"></a>00052           <span class="keyword">this</span>, SIGNAL(<a class="code" href="class_tor_map_widget.html#a48cc137b41ad8c0b04eea56f795c40fc">displayRouterInfo</a>(QString)));
<a name="l00053"></a>00053 
<a name="l00054"></a>00054   <span class="comment">/* We can&#39;t call setInputHandler() until MarbleWidget has called its</span>
<a name="l00055"></a>00055 <span class="comment">   * internal _q_initGui() method, which doesn&#39;t happen until a</span>
<a name="l00056"></a>00056 <span class="comment">   * QTimer::singleShot(0, this, SLOT(_q_initGui())) timer set in its</span>
<a name="l00057"></a>00057 <span class="comment">   * constructor times out. So force that event to process now. */</span> 
<a name="l00058"></a>00058   <a class="code" href="_vidalia_8h.html#aef0a1c1e9430e6b86892ae28b1577294">vApp</a>-&gt;processEvents(QEventLoop::ExcludeUserInputEvents
<a name="l00059"></a>00059                         | QEventLoop::ExcludeSocketNotifiers);
<a name="l00060"></a>00060 
<a name="l00061"></a>00061   setInputHandler(handler);
<a name="l00062"></a>00062 }
<a name="l00063"></a>00063 <span class="comment"></span>
<a name="l00064"></a>00064 <span class="comment">/** Destructor */</span>
<a name="l00065"></a><a class="code" href="class_tor_map_widget.html#acfbbc2f4e4dd8c9decd055beed8c30f0">00065</a> <a class="code" href="class_tor_map_widget.html#acfbbc2f4e4dd8c9decd055beed8c30f0">TorMapWidget::~TorMapWidget</a>()
<a name="l00066"></a>00066 {
<a name="l00067"></a>00067   <a class="code" href="class_tor_map_widget.html#a97c3379161e17c8baa80711c42dd711b">clear</a>();
<a name="l00068"></a>00068 }
<a name="l00069"></a>00069 <span class="comment"></span>
<a name="l00070"></a>00070 <span class="comment">/** Adds a router to the map. */</span>
<a name="l00071"></a>00071 <span class="keywordtype">void</span>
<a name="l00072"></a><a class="code" href="class_tor_map_widget.html#aada860f4c3eaade56dd8506dd689dd06">00072</a> <a class="code" href="class_tor_map_widget.html#aada860f4c3eaade56dd8506dd689dd06">TorMapWidget::addRouter</a>(<span class="keyword">const</span> <a class="code" href="class_router_descriptor.html">RouterDescriptor</a> &amp;desc, <span class="keyword">const</span> <a class="code" href="class_geo_ip.html">GeoIp</a> &amp;geoip)
<a name="l00073"></a>00073 {
<a name="l00074"></a>00074   QString kml;
<a name="l00075"></a>00075   qreal lon = geoip.<a class="code" href="class_geo_ip.html#af2313a1436e88c21528423d7807c763c">longitude</a>();
<a name="l00076"></a>00076   qreal lat = geoip.<a class="code" href="class_geo_ip.html#adb5de17f48460151e1fb336239f97e4d">latitude</a>();
<a name="l00077"></a>00077   quint64 bw;
<a name="l00078"></a>00078   
<a name="l00079"></a>00079   bw = qMin(desc.<a class="code" href="class_router_descriptor.html#ac41cf8a37672d7bb0ad380104babfc7e">averageBandwidth</a>(), desc.<a class="code" href="class_router_descriptor.html#a7b2ae9944df4c0ca891aade00d1abff2">burstBandwidth</a>());
<a name="l00080"></a>00080   bw = qMin(bw, desc.<a class="code" href="class_router_descriptor.html#af8440bef161b61da8cb70e391d1e00c7">observedBandwidth</a>());
<a name="l00081"></a>00081 
<a name="l00082"></a>00082   kml.append(<span class="stringliteral">&quot;&lt;?xml version=\&quot;1.0\&quot; encoding=\&quot;UTF-8\&quot;?&gt;&quot;</span>
<a name="l00083"></a>00083              <span class="stringliteral">&quot;&lt;kml xmlns=\&quot;http://earth.google.com/kml/2.0\&quot;&gt;&quot;</span>
<a name="l00084"></a>00084              <span class="stringliteral">&quot;&lt;Document&gt;&quot;</span>
<a name="l00085"></a>00085              <span class="stringliteral">&quot;  &lt;Style id=\&quot;normalPlacemark\&quot;&gt;&quot;</span>
<a name="l00086"></a>00086              <span class="stringliteral">&quot;    &lt;IconStyle&gt;&lt;Icon&gt;&lt;href&gt;:/images/icons/placemark-relay.png&lt;/href&gt;&lt;/Icon&gt;&lt;/IconStyle&gt;&quot;</span>
<a name="l00087"></a>00087              <span class="stringliteral">&quot;  &lt;/Style&gt;&quot;</span>
<a name="l00088"></a>00088              );
<a name="l00089"></a>00089 
<a name="l00090"></a>00090   kml.append(<span class="stringliteral">&quot;&lt;Placemark&gt;&quot;</span>);
<a name="l00091"></a>00091   kml.append(<span class="stringliteral">&quot;&lt;styleUrl&gt;#normalPlacemark&lt;/styleUrl&gt;&quot;</span>);
<a name="l00092"></a>00092   kml.append(QString(<span class="stringliteral">&quot;&lt;name&gt;%1&lt;/name&gt;&quot;</span>).arg(desc.<a class="code" href="class_router_descriptor.html#abba7b090e12112fab38e63654bfe8929">name</a>()));
<a name="l00093"></a>00093   kml.append(QString(<span class="stringliteral">&quot;&lt;description&gt;%1&lt;/description&gt;&quot;</span>).arg(desc.<a class="code" href="class_router_descriptor.html#afd43d25061bd0e5461bb6e27d680498b">id</a>()));
<a name="l00094"></a>00094   kml.append(QString(<span class="stringliteral">&quot;&lt;role&gt;1&lt;/role&gt;&quot;</span>));
<a name="l00095"></a>00095   kml.append(QString(<span class="stringliteral">&quot;&lt;address&gt;%1&lt;/address&gt;&quot;</span>).arg(geoip.<a class="code" href="class_geo_ip.html#a821197ccf11820d24544f39b6e01296f">toString</a>()));
<a name="l00096"></a>00096   kml.append(QString(<span class="stringliteral">&quot;&lt;CountryNameCode&gt;%1&lt;/CountryNameCode&gt;&quot;</span>).arg(geoip.<a class="code" href="class_geo_ip.html#a44cbaa4bd1ced6dea5233ed3cf417679">country</a>()));
<a name="l00097"></a>00097   kml.append(QString(<span class="stringliteral">&quot;&lt;pop&gt;%1&lt;/pop&gt;&quot;</span>).arg(10 * bw));
<a name="l00098"></a>00098   kml.append(QString(<span class="stringliteral">&quot;&lt;Point&gt;&quot;</span>
<a name="l00099"></a>00099                      <span class="stringliteral">&quot;  &lt;coordinates&gt;%1,%2&lt;/coordinates&gt;&quot;</span>
<a name="l00100"></a>00100                      <span class="stringliteral">&quot;&lt;/Point&gt;&quot;</span>).arg(lon).arg(lat));
<a name="l00101"></a>00101   kml.append(<span class="stringliteral">&quot;&lt;/Placemark&gt;&quot;</span>);
<a name="l00102"></a>00102   kml.append(<span class="stringliteral">&quot;&lt;/Document&gt;&lt;/kml&gt;&quot;</span>);
<a name="l00103"></a>00103 
<a name="l00104"></a>00104   QString <span class="keywordtype">id</span> = desc.<a class="code" href="class_router_descriptor.html#afd43d25061bd0e5461bb6e27d680498b">id</a>();
<a name="l00105"></a>00105   addPlacemarkData(kml, <span class="keywordtype">id</span>);
<a name="l00106"></a>00106   <a class="code" href="class_tor_map_widget.html#a89e87119356e6e4877455225839c983d">_routers</a>.insert(<span class="keywordtype">id</span>, GeoDataCoordinates(lon, lat, 0.0,
<a name="l00107"></a>00107                                          GeoDataCoordinates::Degree));
<a name="l00108"></a>00108 }
<a name="l00109"></a>00109 <span class="comment"></span>
<a name="l00110"></a>00110 <span class="comment">/** Adds a circuit to the map using the given ordered list of router IDs. */</span>
<a name="l00111"></a>00111 <span class="keywordtype">void</span>
<a name="l00112"></a><a class="code" href="class_tor_map_widget.html#ab889dd195fdbe57f2c7b96c2765ed27f">00112</a> <a class="code" href="class_tor_map_widget.html#ab889dd195fdbe57f2c7b96c2765ed27f">TorMapWidget::addCircuit</a>(<span class="keyword">const</span> <a class="code" href="_circuit_8h.html#a8b7b0182a6d1ff0aab7ab31df9c3f83d">CircuitId</a> &amp;circid, <span class="keyword">const</span> QStringList &amp;path)
<a name="l00113"></a>00113 {
<a name="l00114"></a>00114   <span class="comment">/* XXX: Is it better to do KML LineString-based circuit drawing here,</span>
<a name="l00115"></a>00115 <span class="comment">   *      instead of going with a QPainter-based approach? I gave it a brief</span>
<a name="l00116"></a>00116 <span class="comment">   *      try once but failed. It might be worth looking into harder if we</span>
<a name="l00117"></a>00117 <span class="comment">   *      want to make circuits selectable on the map too.</span>
<a name="l00118"></a>00118 <span class="comment">   */</span>
<a name="l00119"></a>00119 
<a name="l00120"></a>00120   <span class="comment">/* It doesn&#39;t make sense to draw a path of length less than two */</span>
<a name="l00121"></a>00121   <span class="keywordflow">if</span> (path.size() &lt; 2)
<a name="l00122"></a>00122     <span class="keywordflow">return</span>;
<a name="l00123"></a>00123 
<a name="l00124"></a>00124   <span class="keywordflow">if</span> (<a class="code" href="class_tor_map_widget.html#a6bf2c2627536dcaedb1757d441cd7a9e">_circuits</a>.contains(circid)) {
<a name="l00125"></a>00125     <span class="comment">/* Extend an existing path */</span>
<a name="l00126"></a>00126     <a class="code" href="_tor_map_widget_8h.html#ac8a268c0787bf5eb3f0f442ebd5d0fdd">CircuitGeoPath</a> *geoPath = <a class="code" href="class_tor_map_widget.html#a6bf2c2627536dcaedb1757d441cd7a9e">_circuits</a>.value(circid);
<a name="l00127"></a>00127 
<a name="l00128"></a>00128     QString router = path.at(path.size()-1);
<a name="l00129"></a>00129     <span class="keywordflow">if</span> (<a class="code" href="class_tor_map_widget.html#a89e87119356e6e4877455225839c983d">_routers</a>.contains(router))
<a name="l00130"></a>00130       geoPath-&gt;first.append(<a class="code" href="class_tor_map_widget.html#a89e87119356e6e4877455225839c983d">_routers</a>.value(router));
<a name="l00131"></a>00131   } <span class="keywordflow">else</span> {
<a name="l00132"></a>00132     <span class="comment">/* Construct a new path */</span>
<a name="l00133"></a>00133     <a class="code" href="_tor_map_widget_8h.html#ac8a268c0787bf5eb3f0f442ebd5d0fdd">CircuitGeoPath</a> *geoPath = <span class="keyword">new</span> <a class="code" href="_tor_map_widget_8h.html#ac8a268c0787bf5eb3f0f442ebd5d0fdd">CircuitGeoPath</a>();
<a name="l00134"></a>00134     geoPath-&gt;second = <span class="keyword">false</span>; <span class="comment">/* initially unselected */</span>
<a name="l00135"></a>00135 
<a name="l00136"></a>00136     <span class="keywordflow">foreach</span> (QString router, path) {
<a name="l00137"></a>00137       <span class="keywordflow">if</span> (<a class="code" href="class_tor_map_widget.html#a89e87119356e6e4877455225839c983d">_routers</a>.contains(router))
<a name="l00138"></a>00138         geoPath-&gt;first.append(<a class="code" href="class_tor_map_widget.html#a89e87119356e6e4877455225839c983d">_routers</a>.value(router));
<a name="l00139"></a>00139     }
<a name="l00140"></a>00140     geoPath-&gt;first.setTessellationFlags(Tessellate | RespectLatitudeCircle);
<a name="l00141"></a>00141     <a class="code" href="class_tor_map_widget.html#a6bf2c2627536dcaedb1757d441cd7a9e">_circuits</a>.insert(circid, geoPath);
<a name="l00142"></a>00142   }
<a name="l00143"></a>00143 
<a name="l00144"></a>00144   repaint();
<a name="l00145"></a>00145 }
<a name="l00146"></a>00146 <span class="comment"></span>
<a name="l00147"></a>00147 <span class="comment">/** Removes a circuit from the map. */</span>
<a name="l00148"></a>00148 <span class="keywordtype">void</span>
<a name="l00149"></a><a class="code" href="class_tor_map_widget.html#a03ca0d16d9e507fc798dea7fa6632529">00149</a> <a class="code" href="class_tor_map_widget.html#a03ca0d16d9e507fc798dea7fa6632529">TorMapWidget::removeCircuit</a>(<span class="keyword">const</span> <a class="code" href="_circuit_8h.html#a8b7b0182a6d1ff0aab7ab31df9c3f83d">CircuitId</a> &amp;circid)
<a name="l00150"></a>00150 {
<a name="l00151"></a>00151   <a class="code" href="_tor_map_widget_8h.html#ac8a268c0787bf5eb3f0f442ebd5d0fdd">CircuitGeoPath</a> *path = <a class="code" href="class_tor_map_widget.html#a6bf2c2627536dcaedb1757d441cd7a9e">_circuits</a>.take(circid);
<a name="l00152"></a>00152   <span class="keywordflow">if</span> (path)
<a name="l00153"></a>00153     <span class="keyword">delete</span> path;
<a name="l00154"></a>00154 
<a name="l00155"></a>00155   repaint();
<a name="l00156"></a>00156 }
<a name="l00157"></a>00157 <span class="comment"></span>
<a name="l00158"></a>00158 <span class="comment">/** Selects and highlights the router on the map. */</span>
<a name="l00159"></a>00159 <span class="keywordtype">void</span>
<a name="l00160"></a><a class="code" href="class_tor_map_widget.html#a9bc838ff315f9853e883f7e009a3ecee">00160</a> <a class="code" href="class_tor_map_widget.html#a9bc838ff315f9853e883f7e009a3ecee">TorMapWidget::selectRouter</a>(<span class="keyword">const</span> QString &amp;<span class="keywordtype">id</span>)
<a name="l00161"></a>00161 {
<a name="l00162"></a>00162 <span class="preprocessor">#if 0</span>
<a name="l00163"></a>00163 <span class="preprocessor"></span>  <span class="keywordflow">if</span> (<a class="code" href="class_tor_map_widget.html#a89e87119356e6e4877455225839c983d">_routers</a>.contains(<span class="keywordtype">id</span>)) {
<a name="l00164"></a>00164     QPair&lt;QPointF, bool&gt; *routerPair = <a class="code" href="class_tor_map_widget.html#a89e87119356e6e4877455225839c983d">_routers</a>.value(<span class="keywordtype">id</span>);
<a name="l00165"></a>00165     routerPair-&gt;second = <span class="keyword">true</span>;
<a name="l00166"></a>00166   }
<a name="l00167"></a>00167   repaint();
<a name="l00168"></a>00168 <span class="preprocessor">#endif</span>
<a name="l00169"></a>00169 <span class="preprocessor"></span>}
<a name="l00170"></a>00170 <span class="comment"></span>
<a name="l00171"></a>00171 <span class="comment">/** Selects and highlights the circuit with the id &lt;b&gt;circid&lt;/b&gt; </span>
<a name="l00172"></a>00172 <span class="comment"> * on the map. */</span>
<a name="l00173"></a>00173 <span class="keywordtype">void</span>
<a name="l00174"></a><a class="code" href="class_tor_map_widget.html#a250b6c8ec86957c35fefaeb61552eca6">00174</a> <a class="code" href="class_tor_map_widget.html#a250b6c8ec86957c35fefaeb61552eca6">TorMapWidget::selectCircuit</a>(<span class="keyword">const</span> <a class="code" href="_circuit_8h.html#a8b7b0182a6d1ff0aab7ab31df9c3f83d">CircuitId</a> &amp;circid)
<a name="l00175"></a>00175 {
<a name="l00176"></a>00176   <span class="keywordflow">if</span> (<a class="code" href="class_tor_map_widget.html#a6bf2c2627536dcaedb1757d441cd7a9e">_circuits</a>.contains(circid)) {
<a name="l00177"></a>00177     <a class="code" href="_tor_map_widget_8h.html#ac8a268c0787bf5eb3f0f442ebd5d0fdd">CircuitGeoPath</a> *path = <a class="code" href="class_tor_map_widget.html#a6bf2c2627536dcaedb1757d441cd7a9e">_circuits</a>.value(circid);
<a name="l00178"></a>00178     path-&gt;second = <span class="keyword">true</span>;
<a name="l00179"></a>00179   }
<a name="l00180"></a>00180 
<a name="l00181"></a>00181   repaint();
<a name="l00182"></a>00182 }
<a name="l00183"></a>00183 <span class="comment"></span>
<a name="l00184"></a>00184 <span class="comment">/** Deselects any highlighted routers or circuits */</span>
<a name="l00185"></a>00185 <span class="keywordtype">void</span>
<a name="l00186"></a><a class="code" href="class_tor_map_widget.html#a74ecf3f5185ccfa3489709a5cb1c6bcc">00186</a> <a class="code" href="class_tor_map_widget.html#a74ecf3f5185ccfa3489709a5cb1c6bcc">TorMapWidget::deselectAll</a>()
<a name="l00187"></a>00187 {
<a name="l00188"></a>00188 <span class="preprocessor">#if 0</span>
<a name="l00189"></a>00189 <span class="preprocessor"></span>  <span class="comment">/* Deselect all router points */</span>
<a name="l00190"></a>00190   <span class="keywordflow">foreach</span> (QString router, <a class="code" href="class_tor_map_widget.html#a89e87119356e6e4877455225839c983d">_routers</a>.keys()) {
<a name="l00191"></a>00191     QPair&lt;QPointF,bool&gt; *routerPair = <a class="code" href="class_tor_map_widget.html#a89e87119356e6e4877455225839c983d">_routers</a>.value(router);
<a name="l00192"></a>00192     routerPair-&gt;second = <span class="keyword">false</span>;
<a name="l00193"></a>00193   }
<a name="l00194"></a>00194 <span class="preprocessor">#endif</span>
<a name="l00195"></a>00195 <span class="preprocessor"></span>  <span class="comment">/* Deselect all circuit paths */</span>
<a name="l00196"></a>00196   <span class="keywordflow">foreach</span> (<a class="code" href="_tor_map_widget_8h.html#ac8a268c0787bf5eb3f0f442ebd5d0fdd">CircuitGeoPath</a> *path, <a class="code" href="class_tor_map_widget.html#a6bf2c2627536dcaedb1757d441cd7a9e">_circuits</a>.values()) {
<a name="l00197"></a>00197     path-&gt;second = <span class="keyword">false</span>;
<a name="l00198"></a>00198   }
<a name="l00199"></a>00199 
<a name="l00200"></a>00200   repaint();
<a name="l00201"></a>00201 }
<a name="l00202"></a>00202 <span class="comment"></span>
<a name="l00203"></a>00203 <span class="comment">/** Clears the list of routers and removes all the data on the map */</span>
<a name="l00204"></a>00204 <span class="keywordtype">void</span>
<a name="l00205"></a><a class="code" href="class_tor_map_widget.html#a97c3379161e17c8baa80711c42dd711b">00205</a> <a class="code" href="class_tor_map_widget.html#a97c3379161e17c8baa80711c42dd711b">TorMapWidget::clear</a>()
<a name="l00206"></a>00206 {
<a name="l00207"></a>00207   <span class="keywordflow">foreach</span> (QString <span class="keywordtype">id</span>, <a class="code" href="class_tor_map_widget.html#a89e87119356e6e4877455225839c983d">_routers</a>.keys()) {
<a name="l00208"></a>00208     removePlacemarkKey(<span class="keywordtype">id</span>);
<a name="l00209"></a>00209   }
<a name="l00210"></a>00210 
<a name="l00211"></a>00211   <span class="keywordflow">foreach</span> (<a class="code" href="_circuit_8h.html#a8b7b0182a6d1ff0aab7ab31df9c3f83d">CircuitId</a> circid, <a class="code" href="class_tor_map_widget.html#a6bf2c2627536dcaedb1757d441cd7a9e">_circuits</a>.keys()) {
<a name="l00212"></a>00212     <a class="code" href="_tor_map_widget_8h.html#ac8a268c0787bf5eb3f0f442ebd5d0fdd">CircuitGeoPath</a> *path = <a class="code" href="class_tor_map_widget.html#a6bf2c2627536dcaedb1757d441cd7a9e">_circuits</a>.take(circid);
<a name="l00213"></a>00213     <span class="keyword">delete</span> path;
<a name="l00214"></a>00214   }
<a name="l00215"></a>00215 
<a name="l00216"></a>00216   repaint();
<a name="l00217"></a>00217 }
<a name="l00218"></a>00218  <span class="comment"></span>
<a name="l00219"></a>00219 <span class="comment">/** Zooms the map to fit entirely within the constraints of the current</span>
<a name="l00220"></a>00220 <span class="comment"> * viewport size. */</span>
<a name="l00221"></a>00221 <span class="keywordtype">void</span>
<a name="l00222"></a><a class="code" href="class_tor_map_widget.html#a1e51aaaf31297768061cff75e09394e8">00222</a> <a class="code" href="class_tor_map_widget.html#a1e51aaaf31297768061cff75e09394e8">TorMapWidget::zoomToFit</a>()
<a name="l00223"></a>00223 {
<a name="l00224"></a>00224   <span class="keywordtype">int</span> width  = size().width();
<a name="l00225"></a>00225   <span class="keywordtype">int</span> height = size().height();
<a name="l00226"></a>00226 
<a name="l00227"></a>00227   setRadius(qMin(width, height) / 2);
<a name="l00228"></a>00228 
<a name="l00229"></a>00229   <span class="comment">/* XXX: Calling setRadius() seems to cause Marble to no longer draw the</span>
<a name="l00230"></a>00230 <span class="comment">   *      atmosphere. So, re-enable it. */</span>
<a name="l00231"></a>00231   setShowAtmosphere(<span class="keyword">true</span>);
<a name="l00232"></a>00232 }
<a name="l00233"></a>00233 <span class="comment"></span>
<a name="l00234"></a>00234 <span class="comment">/** Zoom to the circuit on the map with the given &lt;b&gt;circid&lt;/b&gt;. */</span>
<a name="l00235"></a>00235 <span class="keywordtype">void</span>
<a name="l00236"></a><a class="code" href="class_tor_map_widget.html#a7fbe61582e1f26cadf1459fae0d43905">00236</a> <a class="code" href="class_tor_map_widget.html#a7fbe61582e1f26cadf1459fae0d43905">TorMapWidget::zoomToCircuit</a>(<span class="keyword">const</span> <a class="code" href="_circuit_8h.html#a8b7b0182a6d1ff0aab7ab31df9c3f83d">CircuitId</a> &amp;circid)
<a name="l00237"></a>00237 {
<a name="l00238"></a>00238 <span class="preprocessor">#if 0</span>
<a name="l00239"></a>00239 <span class="preprocessor"></span>  <span class="keywordflow">if</span> (<a class="code" href="class_tor_map_widget.html#a6bf2c2627536dcaedb1757d441cd7a9e">_circuits</a>.contains(circid)) {
<a name="l00240"></a>00240     QPair&lt;QPainterPath*,bool&gt; *pair = <a class="code" href="class_tor_map_widget.html#a6bf2c2627536dcaedb1757d441cd7a9e">_circuits</a>.value(circid);
<a name="l00241"></a>00241     QRectF rect = ((QPainterPath *)pair-&gt;first)-&gt;boundingRect();
<a name="l00242"></a>00242     <span class="keywordflow">if</span> (!rect.isNull()) {
<a name="l00243"></a>00243       <span class="keywordtype">float</span> zoomLevel = 1.0 - qMax(rect.height()/float(<a class="code" href="_tor_map_image_view_8cpp.html#a529d5ebb449edf31d9835d13f4fb9f89">MAP_HEIGHT</a>),
<a name="l00244"></a>00244                                    rect.width()/float(<a class="code" href="_tor_map_image_view_8cpp.html#aa037a6d6a4f04d51c7ec1c9ee9054e76">MAP_WIDTH</a>));
<a name="l00245"></a>00245 
<a name="l00246"></a>00246       zoom(rect.center().toPoint(), zoomLevel+0.2);
<a name="l00247"></a>00247     }
<a name="l00248"></a>00248   }
<a name="l00249"></a>00249 <span class="preprocessor">#endif</span>
<a name="l00250"></a>00250 <span class="preprocessor"></span>}
<a name="l00251"></a>00251 <span class="comment"></span>
<a name="l00252"></a>00252 <span class="comment">/** Zooms in on the router with the given &lt;b&gt;id&lt;/b&gt;. */</span>
<a name="l00253"></a>00253 <span class="keywordtype">void</span>
<a name="l00254"></a><a class="code" href="class_tor_map_widget.html#a24682cb4e5d49f7b801b54a5b8935dc6">00254</a> <a class="code" href="class_tor_map_widget.html#a24682cb4e5d49f7b801b54a5b8935dc6">TorMapWidget::zoomToRouter</a>(<span class="keyword">const</span> QString &amp;<span class="keywordtype">id</span>)
<a name="l00255"></a>00255 {
<a name="l00256"></a>00256   <span class="keywordflow">if</span> (<a class="code" href="class_tor_map_widget.html#a89e87119356e6e4877455225839c983d">_routers</a>.contains(<span class="keywordtype">id</span>)) {
<a name="l00257"></a>00257     qreal lon, lat;
<a name="l00258"></a>00258     GeoDataCoordinates coords = <a class="code" href="class_tor_map_widget.html#a89e87119356e6e4877455225839c983d">_routers</a>.value(<span class="keywordtype">id</span>);
<a name="l00259"></a>00259     coords.geoCoordinates(lon, lat, GeoDataPoint::Degree);
<a name="l00260"></a>00260 
<a name="l00261"></a>00261     zoomView(maximumZoom());
<a name="l00262"></a>00262     centerOn(lon, lat, <span class="keyword">true</span>);
<a name="l00263"></a>00263   }
<a name="l00264"></a>00264 }
<a name="l00265"></a>00265 <span class="comment"></span>
<a name="l00266"></a>00266 <span class="comment">/** Paints the current circuits and streams on the image. */</span>
<a name="l00267"></a>00267 <span class="keywordtype">void</span>
<a name="l00268"></a>00268 <a class="code" href="class_tor_map_widget.html#a738b1ad07dfaaa20c5fe5d6583ddcef9">TorMapWidget::customPaint</a>(GeoPainter *painter)
<a name="l00269"></a>00269 {
<a name="l00270"></a>00270   <span class="keywordtype">bool</span> selected = <span class="keyword">false</span>;
<a name="l00271"></a>00271 
<a name="l00272"></a>00272   painter-&gt;autoMapQuality();
<a name="l00273"></a>00273   painter-&gt;setPen(<a class="code" href="_tor_map_widget_8cpp.html#aa1220bcce74390150be7253b74d2a64d">CIRCUIT_NORMAL_PEN</a>);
<a name="l00274"></a>00274 
<a name="l00275"></a>00275   <span class="keywordflow">foreach</span> (<a class="code" href="_tor_map_widget_8h.html#ac8a268c0787bf5eb3f0f442ebd5d0fdd">CircuitGeoPath</a> *path, <a class="code" href="class_tor_map_widget.html#a6bf2c2627536dcaedb1757d441cd7a9e">_circuits</a>.values()) {
<a name="l00276"></a>00276     <span class="keywordflow">if</span> (! path-&gt;second &amp;&amp; selected) {
<a name="l00277"></a>00277       painter-&gt;setPen(<a class="code" href="_tor_map_widget_8cpp.html#aa1220bcce74390150be7253b74d2a64d">CIRCUIT_NORMAL_PEN</a>);
<a name="l00278"></a>00278       selected = <span class="keyword">false</span>;
<a name="l00279"></a>00279     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (path-&gt;second &amp;&amp; ! selected) {
<a name="l00280"></a>00280       painter-&gt;setPen(<a class="code" href="_tor_map_widget_8cpp.html#a1bfd4bbb034e09ab8e6307a865ef8ee3">CIRCUIT_SELECTED_PEN</a>);
<a name="l00281"></a>00281       selected = <span class="keyword">true</span>;
<a name="l00282"></a>00282     }
<a name="l00283"></a>00283     painter-&gt;drawPolyline(path-&gt;first);
<a name="l00284"></a>00284   }
<a name="l00285"></a>00285 }
<a name="l00286"></a>00286 
</pre></div></div>
<hr class="footer"/><address style="text-align: right;"><small>Generated on Mon Aug 30 22:58:55 2010 for Vidalia by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
</body>
</html>