Sophie

Sophie

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

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: RouterDescriptorView.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>RouterDescriptorView.cpp</h1><a href="_router_descriptor_view_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 RouterDescriptorView.cpp</span>
<a name="l00013"></a>00013 <span class="comment">** \version $Id: RouterDescriptorView.cpp 3770 2009-05-14 02:41:24Z edmanm $</span>
<a name="l00014"></a>00014 <span class="comment">** \brief Formats and displays a router descriptor as HTML</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="_router_descriptor_view_8h.html">RouterDescriptorView.h</a>&quot;</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &quot;<a class="code" href="_vidalia_8h.html">Vidalia.h</a>&quot;</span>
<a name="l00019"></a>00019 
<a name="l00020"></a>00020 <span class="preprocessor">#include &quot;<a class="code" href="html_8h.html">html.h</a>&quot;</span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &quot;<a class="code" href="stringutil_8h.html">stringutil.h</a>&quot;</span>
<a name="l00022"></a>00022 
<a name="l00023"></a>00023 <span class="preprocessor">#include &lt;QMenu&gt;</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;QIcon&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;QTextCursor&gt;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;QClipboard&gt;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;QShortcut&gt;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &lt;QTextDocumentFragment&gt;</span>
<a name="l00029"></a>00029 
<a name="l00030"></a><a class="code" href="_router_descriptor_view_8cpp.html#af77dfade97935a39bfdb7b2944d9d99d">00030</a> <span class="preprocessor">#define IMG_COPY      &quot;:/images/22x22/edit-copy.png&quot;</span>
<a name="l00031"></a>00031 <span class="preprocessor"></span>
<a name="l00032"></a>00032 <span class="comment"></span>
<a name="l00033"></a>00033 <span class="comment">/** Default constructor. */</span>
<a name="l00034"></a><a class="code" href="class_router_descriptor_view.html#a36313f7b51a3725b4ae41be9ada6a54c">00034</a> <a class="code" href="class_router_descriptor_view.html#a36313f7b51a3725b4ae41be9ada6a54c">RouterDescriptorView::RouterDescriptorView</a>(QWidget *parent)
<a name="l00035"></a>00035 : QTextEdit(parent)
<a name="l00036"></a>00036 {
<a name="l00037"></a>00037   <span class="comment">/* Steal QTextEdit&#39;s default &quot;Copy&quot; shortcut, since we want to do some</span>
<a name="l00038"></a>00038 <span class="comment">   * tweaking of the selected text before putting it on the clipboard. */</span>
<a name="l00039"></a>00039   QShortcut *shortcut = <span class="keyword">new</span> QShortcut(QKeySequence::Copy, <span class="keyword">this</span>,
<a name="l00040"></a>00040                                       SLOT(<a class="code" href="class_router_descriptor_view.html#a770be7bb7238121e043f19edb3a1d48d">copySelectedText</a>()));
<a name="l00041"></a>00041   Q_UNUSED(shortcut);
<a name="l00042"></a>00042 }
<a name="l00043"></a>00043 <span class="comment"></span>
<a name="l00044"></a>00044 <span class="comment">/** Displays a context menu for the user when they right-click on the</span>
<a name="l00045"></a>00045 <span class="comment"> * widget. */</span>
<a name="l00046"></a>00046 <span class="keywordtype">void</span>
<a name="l00047"></a><a class="code" href="class_router_descriptor_view.html#a81ff3b19ccad82ac9ae86f40f459ad5d">00047</a> <a class="code" href="class_router_descriptor_view.html#a81ff3b19ccad82ac9ae86f40f459ad5d">RouterDescriptorView::contextMenuEvent</a>(QContextMenuEvent *event)
<a name="l00048"></a>00048 {
<a name="l00049"></a>00049   QMenu *menu = <span class="keyword">new</span> QMenu();
<a name="l00050"></a>00050 
<a name="l00051"></a>00051   QAction *copyAction = <span class="keyword">new</span> QAction(QIcon(<a class="code" href="_network_page_8cpp.html#af77dfade97935a39bfdb7b2944d9d99d">IMG_COPY</a>), tr(<span class="stringliteral">&quot;Copy&quot;</span>), menu);
<a name="l00052"></a>00052   copyAction-&gt;setShortcut(QKeySequence::Copy);
<a name="l00053"></a>00053   connect(copyAction, SIGNAL(triggered()), <span class="keyword">this</span>, SLOT(<a class="code" href="class_router_descriptor_view.html#a770be7bb7238121e043f19edb3a1d48d">copySelectedText</a>()));
<a name="l00054"></a>00054 
<a name="l00055"></a>00055   <span class="keywordflow">if</span> (textCursor().selectedText().isEmpty())
<a name="l00056"></a>00056     copyAction-&gt;setEnabled(<span class="keyword">false</span>);
<a name="l00057"></a>00057 
<a name="l00058"></a>00058   menu-&gt;addAction(copyAction);
<a name="l00059"></a>00059   menu-&gt;exec(event-&gt;globalPos());
<a name="l00060"></a>00060   <span class="keyword">delete</span> menu;
<a name="l00061"></a>00061 }
<a name="l00062"></a>00062 <span class="comment"></span>
<a name="l00063"></a>00063 <span class="comment">/** Copies any selected text to the clipboard. */</span>
<a name="l00064"></a>00064 <span class="keywordtype">void</span>
<a name="l00065"></a><a class="code" href="class_router_descriptor_view.html#a770be7bb7238121e043f19edb3a1d48d">00065</a> <a class="code" href="class_router_descriptor_view.html#a770be7bb7238121e043f19edb3a1d48d">RouterDescriptorView::copySelectedText</a>()
<a name="l00066"></a>00066 { 
<a name="l00067"></a>00067   QString selectedText = textCursor().selection().toPlainText();
<a name="l00068"></a>00068   selectedText.replace(<span class="stringliteral">&quot;:\n&quot;</span>, <span class="stringliteral">&quot;: &quot;</span>);
<a name="l00069"></a>00069   <a class="code" href="_vidalia_8h.html#aef0a1c1e9430e6b86892ae28b1577294">vApp</a>-&gt;clipboard()-&gt;setText(selectedText);
<a name="l00070"></a>00070 }
<a name="l00071"></a>00071 <span class="comment"></span>
<a name="l00072"></a>00072 <span class="comment">/** Adjusts the displayed uptime to include time since the router&#39;s descriptor</span>
<a name="l00073"></a>00073 <span class="comment"> * was last published. */</span>
<a name="l00074"></a>00074 quint64
<a name="l00075"></a><a class="code" href="class_router_descriptor_view.html#a8bd409c017e9b40fa9c91e9be3d096b9">00075</a> <a class="code" href="class_router_descriptor_view.html#a8bd409c017e9b40fa9c91e9be3d096b9">RouterDescriptorView::adjustUptime</a>(quint64 uptime, QDateTime published)
<a name="l00076"></a>00076 {
<a name="l00077"></a>00077   QDateTime now = QDateTime::currentDateTime().toUTC();
<a name="l00078"></a>00078   
<a name="l00079"></a>00079   <span class="keywordflow">if</span> (now &lt; published) {
<a name="l00080"></a>00080     <span class="keywordflow">return</span> uptime;
<a name="l00081"></a>00081   }
<a name="l00082"></a>00082   <span class="keywordflow">return</span> (uptime + (now.toTime_t() - published.toTime_t()));
<a name="l00083"></a>00083 }
<a name="l00084"></a>00084 <span class="comment"></span>
<a name="l00085"></a>00085 <span class="comment">/** Displays all router descriptors in the given list. */</span>
<a name="l00086"></a>00086 <span class="keywordtype">void</span>
<a name="l00087"></a><a class="code" href="class_router_descriptor_view.html#ae44d3e20d725c187b7f0de320ec6dc1c">00087</a> <a class="code" href="class_router_descriptor_view.html#a43bf58dd45c29e01cbe23b8e36c84545">RouterDescriptorView::display</a>(QList&lt;RouterDescriptor&gt; rdlist)
<a name="l00088"></a>00088 {
<a name="l00089"></a>00089   <a class="code" href="class_router_descriptor.html">RouterDescriptor</a> rd;
<a name="l00090"></a>00090   QString html = <span class="stringliteral">&quot;&lt;html&gt;&lt;body&gt;&quot;</span>;
<a name="l00091"></a>00091   
<a name="l00092"></a>00092   <span class="keywordflow">for</span> (<span class="keywordtype">int</span> r = 0; r &lt; rdlist.size(); r++) { 
<a name="l00093"></a>00093     rd = rdlist.at(r);
<a name="l00094"></a>00094     <span class="keywordflow">if</span> (rd.<a class="code" href="class_router_descriptor.html#af2f3f41df02ac7c60c5184dc80eeb52f">isEmpty</a>())
<a name="l00095"></a>00095       <span class="keywordflow">continue</span>;
<a name="l00096"></a>00096     
<a name="l00097"></a>00097     <span class="comment">/* Router name and status */</span>
<a name="l00098"></a>00098     html.append(<a class="code" href="html_8cpp.html#a6859bd9e7f8c6a4ec0150749bac76c1d">p</a>(<a class="code" href="html_8cpp.html#ae81b348b93d155129c2e91ced96c1898">b</a>(rd.<a class="code" href="class_router_descriptor.html#abba7b090e12112fab38e63654bfe8929">name</a>()) + <span class="stringliteral">&quot; (&quot;</span> + <a class="code" href="html_8cpp.html#a4a5dba6492ea149585950c59c210ff47">i</a>(rd.<a class="code" href="class_router_descriptor.html#adbfdce4fc446fa7d79052c532e7c387c">status</a>()) + <span class="stringliteral">&quot;)&quot;</span>));
<a name="l00099"></a>00099 
<a name="l00100"></a>00100     <span class="comment">/* IP and platform */</span>
<a name="l00101"></a>00101     html.append(<span class="stringliteral">&quot;&lt;table&gt;&quot;</span>);
<a name="l00102"></a>00102     
<a name="l00103"></a>00103     <span class="comment">/* If we have location information, show that first. */</span>
<a name="l00104"></a>00104     <span class="keywordflow">if</span> (!rd.<a class="code" href="class_router_descriptor.html#ac28db726f2266bb6d0cf40c185e2e09f">location</a>().isEmpty()) {
<a name="l00105"></a>00105       html.append(<a class="code" href="html_8cpp.html#ab9eb4c1f8720cf228c6eacb50a25809d">trow</a>(<a class="code" href="html_8cpp.html#ac02b8a5659a07000307f63f2992821c0">tcol</a>(<a class="code" href="html_8cpp.html#ae81b348b93d155129c2e91ced96c1898">b</a>(tr(<span class="stringliteral">&quot;Location:&quot;</span>))) + <a class="code" href="html_8cpp.html#ac02b8a5659a07000307f63f2992821c0">tcol</a>(rd.<a class="code" href="class_router_descriptor.html#ac28db726f2266bb6d0cf40c185e2e09f">location</a>())));
<a name="l00106"></a>00106     }
<a name="l00107"></a>00107     
<a name="l00108"></a>00108     <span class="comment">/* Add the IP address and router platform information */</span>
<a name="l00109"></a>00109     html.append(<a class="code" href="html_8cpp.html#ab9eb4c1f8720cf228c6eacb50a25809d">trow</a>(<a class="code" href="html_8cpp.html#ac02b8a5659a07000307f63f2992821c0">tcol</a>(<a class="code" href="html_8cpp.html#ae81b348b93d155129c2e91ced96c1898">b</a>(tr(<span class="stringliteral">&quot;IP Address:&quot;</span>))) + <a class="code" href="html_8cpp.html#ac02b8a5659a07000307f63f2992821c0">tcol</a>(rd.<a class="code" href="class_router_descriptor.html#a0ff20382ab48433fecdb03758819c8ed">ip</a>().toString())));
<a name="l00110"></a>00110     html.append(<a class="code" href="html_8cpp.html#ab9eb4c1f8720cf228c6eacb50a25809d">trow</a>(<a class="code" href="html_8cpp.html#ac02b8a5659a07000307f63f2992821c0">tcol</a>(<a class="code" href="html_8cpp.html#ae81b348b93d155129c2e91ced96c1898">b</a>(tr(<span class="stringliteral">&quot;Platform:&quot;</span>)))   + <a class="code" href="html_8cpp.html#ac02b8a5659a07000307f63f2992821c0">tcol</a>(rd.<a class="code" href="class_router_descriptor.html#afe0a179b9eef0a8c603916e8ac18eab5">platform</a>())));
<a name="l00111"></a>00111 
<a name="l00112"></a>00112     <span class="comment">/* If the router is online, then show the uptime and bandwidth stats. */</span>
<a name="l00113"></a>00113     <span class="keywordflow">if</span> (!rd.<a class="code" href="class_router_descriptor.html#a84295b2e93684a11b9c6f41d24552936">offline</a>()) {
<a name="l00114"></a>00114       html.append(<a class="code" href="html_8cpp.html#ab9eb4c1f8720cf228c6eacb50a25809d">trow</a>(<a class="code" href="html_8cpp.html#ac02b8a5659a07000307f63f2992821c0">tcol</a>(<a class="code" href="html_8cpp.html#ae81b348b93d155129c2e91ced96c1898">b</a>(tr(<span class="stringliteral">&quot;Bandwidth:&quot;</span>)))  + 
<a name="l00115"></a>00115                        <a class="code" href="html_8cpp.html#ac02b8a5659a07000307f63f2992821c0">tcol</a>(<a class="code" href="stringutil_8cpp.html#a2be37f42e0b68ec6af355f453c80f1df">string_format_bandwidth</a>(rd.<a class="code" href="class_router_descriptor.html#af8440bef161b61da8cb70e391d1e00c7">observedBandwidth</a>()))));
<a name="l00116"></a>00116       html.append(<a class="code" href="html_8cpp.html#ab9eb4c1f8720cf228c6eacb50a25809d">trow</a>(<a class="code" href="html_8cpp.html#ac02b8a5659a07000307f63f2992821c0">tcol</a>(<a class="code" href="html_8cpp.html#ae81b348b93d155129c2e91ced96c1898">b</a>(tr(<span class="stringliteral">&quot;Uptime:&quot;</span>)))   + 
<a name="l00117"></a>00117                        <a class="code" href="html_8cpp.html#ac02b8a5659a07000307f63f2992821c0">tcol</a>(<a class="code" href="stringutil_8cpp.html#adc62dcb23eb63ad2cc3373689091aee3">string_format_uptime</a>(
<a name="l00118"></a>00118                               <a class="code" href="class_router_descriptor_view.html#a8bd409c017e9b40fa9c91e9be3d096b9">adjustUptime</a>(rd.<a class="code" href="class_router_descriptor.html#ad20789cc87451278fd0bf25476c33865">uptime</a>(), rd.<a class="code" href="class_router_descriptor.html#aeed974e75b31ab7f29bac890ad43d75e">published</a>())))));
<a name="l00119"></a>00119     }
<a name="l00120"></a>00120 
<a name="l00121"></a>00121     <span class="comment">/* Date the router was published */</span>
<a name="l00122"></a>00122     html.append(<a class="code" href="html_8cpp.html#ab9eb4c1f8720cf228c6eacb50a25809d">trow</a>(<a class="code" href="html_8cpp.html#ac02b8a5659a07000307f63f2992821c0">tcol</a>(<a class="code" href="html_8cpp.html#ae81b348b93d155129c2e91ced96c1898">b</a>(tr(<span class="stringliteral">&quot;Last Updated:&quot;</span>)))  +
<a name="l00123"></a>00123                      <a class="code" href="html_8cpp.html#ac02b8a5659a07000307f63f2992821c0">tcol</a>(<a class="code" href="stringutil_8cpp.html#a457c2b0b9a0e212819ab340227117440">string_format_datetime</a>(rd.<a class="code" href="class_router_descriptor.html#aeed974e75b31ab7f29bac890ad43d75e">published</a>()) + <span class="stringliteral">&quot; GMT&quot;</span>)));
<a name="l00124"></a>00124 
<a name="l00125"></a>00125     html.append(<span class="stringliteral">&quot;&lt;/table&gt;&quot;</span>);
<a name="l00126"></a>00126 
<a name="l00127"></a>00127     <span class="comment">/* If there are multiple descriptors, and this isn&#39;t is the last one </span>
<a name="l00128"></a>00128 <span class="comment">     * then separate them with a short horizontal line. */</span>
<a name="l00129"></a>00129     <span class="keywordflow">if</span> (r+1 != rdlist.size()) {
<a name="l00130"></a>00130       html.append(<span class="stringliteral">&quot;&lt;center&gt;&lt;hr width=\&quot;50%\&quot;/&gt;&lt;/center&gt;&quot;</span>);
<a name="l00131"></a>00131     }
<a name="l00132"></a>00132   }
<a name="l00133"></a>00133   html.append(<span class="stringliteral">&quot;&lt;/body&gt;&lt;/html&gt;&quot;</span>);
<a name="l00134"></a>00134   setHtml(html); 
<a name="l00135"></a>00135 }
<a name="l00136"></a>00136 <span class="comment"></span>
<a name="l00137"></a>00137 <span class="comment">/** Displays the given router descriptor. */</span>
<a name="l00138"></a>00138 <span class="keywordtype">void</span>
<a name="l00139"></a><a class="code" href="class_router_descriptor_view.html#a43bf58dd45c29e01cbe23b8e36c84545">00139</a> <a class="code" href="class_router_descriptor_view.html#a43bf58dd45c29e01cbe23b8e36c84545">RouterDescriptorView::display</a>(<a class="code" href="class_router_descriptor.html">RouterDescriptor</a> rd)
<a name="l00140"></a>00140 {
<a name="l00141"></a>00141   <a class="code" href="class_router_descriptor_view.html#a43bf58dd45c29e01cbe23b8e36c84545">display</a>(QList&lt;RouterDescriptor&gt;() &lt;&lt; rd);
<a name="l00142"></a>00142 }
<a name="l00143"></a>00143 
</pre></div></div>
<hr class="footer"/><address style="text-align: right;"><small>Generated on Mon Aug 30 22:58:54 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>