2009-08-17 03:00:34 -04:00
|
|
|
#include <iostream>
|
|
|
|
#include <QTimer>
|
2011-05-23 17:45:25 -04:00
|
|
|
#include <QObject>
|
2010-08-06 05:40:23 -04:00
|
|
|
#include <retroshare/rsturtle.h>
|
2011-05-23 17:45:25 -04:00
|
|
|
#include <retroshare/rspeers.h>
|
2009-08-17 03:00:34 -04:00
|
|
|
#include "TurtleRouterDialog.h"
|
2011-05-23 17:45:25 -04:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QStylePainter>
|
2009-08-17 03:00:34 -04:00
|
|
|
|
2011-03-02 09:31:03 -05:00
|
|
|
static const int MAX_TUNNEL_REQUESTS_DISPLAY = 10 ;
|
|
|
|
|
2011-05-23 17:45:25 -04:00
|
|
|
class TRHistogram
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TRHistogram(const std::vector<TurtleRequestDisplayInfo >& info) :_infos(info) {}
|
|
|
|
|
|
|
|
QColor colorScale(float f)
|
|
|
|
{
|
2011-05-28 18:25:42 -04:00
|
|
|
if(f == 0)
|
2011-05-28 18:29:06 -04:00
|
|
|
return QColor::fromHsv(0,0,192) ;
|
2011-05-28 18:25:42 -04:00
|
|
|
else
|
|
|
|
return QColor::fromHsv((int)((1.0-f)*280),200,255) ;
|
2011-05-23 17:45:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void draw(QPainter *painter,int& ox,int& oy,const QString& title)
|
|
|
|
{
|
|
|
|
static const int MaxTime = 61 ;
|
2011-05-26 18:11:06 -04:00
|
|
|
static const int MaxDepth = 8 ;
|
|
|
|
static const int cellx = 7 ;
|
|
|
|
static const int celly = 12 ;
|
2011-05-23 17:45:25 -04:00
|
|
|
|
|
|
|
int save_ox = ox ;
|
|
|
|
painter->setPen(QColor::fromRgb(0,0,0)) ;
|
|
|
|
painter->drawText(2+ox,celly+oy,title) ;
|
|
|
|
oy+=2+2*celly ;
|
|
|
|
|
|
|
|
if(_infos.empty())
|
|
|
|
return ;
|
|
|
|
|
|
|
|
ox += 10 ;
|
|
|
|
std::map<std::string,std::vector<int> > hits ;
|
2011-05-26 18:11:06 -04:00
|
|
|
std::map<std::string,std::vector<int> > depths ;
|
2011-05-23 17:45:25 -04:00
|
|
|
std::map<std::string,std::vector<int> >::iterator it ;
|
|
|
|
|
|
|
|
int max_hits = 1;
|
2011-05-26 18:11:06 -04:00
|
|
|
int max_depth = 1;
|
|
|
|
|
2011-05-23 17:45:25 -04:00
|
|
|
for(uint32_t i=0;i<_infos.size();++i)
|
|
|
|
{
|
|
|
|
std::vector<int>& h(hits[_infos[i].source_peer_id]) ;
|
2011-05-26 18:11:06 -04:00
|
|
|
std::vector<int>& g(depths[_infos[i].source_peer_id]) ;
|
2011-05-23 17:45:25 -04:00
|
|
|
|
|
|
|
if(h.size() <= _infos[i].age)
|
|
|
|
h.resize(MaxTime,0) ;
|
|
|
|
|
2011-05-26 18:11:06 -04:00
|
|
|
if(g.empty())
|
|
|
|
g.resize(MaxDepth,0) ;
|
|
|
|
|
2011-05-23 17:45:25 -04:00
|
|
|
if(_infos[i].age < h.size())
|
|
|
|
{
|
|
|
|
h[_infos[i].age]++ ;
|
|
|
|
if(h[_infos[i].age] > max_hits)
|
|
|
|
max_hits = h[_infos[i].age] ;
|
|
|
|
}
|
2011-05-26 18:11:06 -04:00
|
|
|
if(_infos[i].depth < g.size())
|
|
|
|
{
|
|
|
|
g[_infos[i].depth]++ ;
|
|
|
|
|
|
|
|
if(g[_infos[i].depth] > max_depth)
|
|
|
|
max_depth = g[_infos[i].depth] ;
|
|
|
|
}
|
2011-05-23 17:45:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int p=0 ;
|
|
|
|
|
2011-05-26 18:11:06 -04:00
|
|
|
for(it=depths.begin();it!=depths.end();++it,++p)
|
|
|
|
for(int i=0;i<MaxDepth;++i)
|
|
|
|
painter->fillRect(ox+MaxTime*cellx+20+i*cellx,oy+p*celly,cellx,celly,colorScale(it->second[i]/(float)max_depth)) ;
|
|
|
|
|
|
|
|
painter->setPen(QColor::fromRgb(0,0,0)) ;
|
|
|
|
painter->drawRect(ox+MaxTime*cellx+20,oy,MaxDepth*cellx,p*celly) ;
|
|
|
|
|
|
|
|
for(int i=0;i<MaxTime;i+=5)
|
|
|
|
painter->drawText(ox+i*cellx,oy+(p+1)*celly+4,QString::number(i)) ;
|
|
|
|
|
|
|
|
p=0 ;
|
2011-05-23 17:45:25 -04:00
|
|
|
for(it=hits.begin();it!=hits.end();++it,++p)
|
|
|
|
{
|
|
|
|
int total = 0 ;
|
|
|
|
|
|
|
|
for(int i=0;i<MaxTime;++i)
|
|
|
|
{
|
|
|
|
painter->fillRect(ox+i*cellx,oy+p*celly,cellx,celly,colorScale(it->second[i]/(float)max_hits)) ;
|
|
|
|
total += it->second[i] ;
|
|
|
|
}
|
|
|
|
|
|
|
|
painter->setPen(QColor::fromRgb(0,0,0)) ;
|
2011-05-26 18:11:06 -04:00
|
|
|
painter->drawText(ox+MaxDepth*cellx+30+(MaxTime+1)*cellx,oy+(p+1)*celly,TurtleRouterDialog::getPeerName(it->first)) ;
|
2011-05-28 18:25:42 -04:00
|
|
|
painter->drawText(ox+MaxDepth*cellx+30+(MaxTime+1)*cellx+120,oy+(p+1)*celly,"("+QString::number(total)+")") ;
|
2011-05-23 17:45:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
painter->drawRect(ox,oy,MaxTime*cellx,p*celly) ;
|
|
|
|
|
|
|
|
for(int i=0;i<MaxTime;i+=5)
|
|
|
|
painter->drawText(ox+i*cellx,oy+(p+1)*celly+4,QString::number(i)) ;
|
2011-05-26 18:11:06 -04:00
|
|
|
for(int i=0;i<MaxDepth;i++)
|
|
|
|
painter->drawText(ox+MaxTime*cellx+20+i*cellx,oy+(p+1)*celly+4,QString::number(i)) ;
|
2011-05-23 17:45:25 -04:00
|
|
|
|
|
|
|
oy += (p+1)*celly+4 ;
|
|
|
|
|
|
|
|
painter->drawText(ox,oy+celly,QObject::tr("(Age in seconds)"));
|
2011-05-26 18:11:06 -04:00
|
|
|
painter->drawText(ox+MaxTime*cellx+20,oy+celly,QObject::tr("(Depth)"));
|
2011-05-23 17:45:25 -04:00
|
|
|
oy += 3*celly ;
|
|
|
|
|
|
|
|
// now, draw a scale
|
|
|
|
|
|
|
|
for(int i=0;i<=10;++i)
|
|
|
|
{
|
2011-05-26 18:11:06 -04:00
|
|
|
painter->fillRect(ox+i*(cellx+20),oy,cellx,celly,colorScale(i/10.0f)) ;
|
2011-05-23 17:45:25 -04:00
|
|
|
painter->setPen(QColor::fromRgb(0,0,0)) ;
|
2011-05-26 18:11:06 -04:00
|
|
|
painter->drawRect(ox+i*(cellx+20),oy,cellx,celly) ;
|
|
|
|
painter->drawText(ox+i*(cellx+20)+cellx+4,oy+celly,QString::number((int)(max_hits*i/10.0))) ;
|
2011-05-23 17:45:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
oy += celly*2 ;
|
|
|
|
|
|
|
|
ox = save_ox ;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const std::vector<TurtleRequestDisplayInfo>& _infos ;
|
|
|
|
};
|
|
|
|
|
2009-08-17 03:00:34 -04:00
|
|
|
TurtleRouterDialog::TurtleRouterDialog(QWidget *parent)
|
2010-02-14 04:06:37 -05:00
|
|
|
: RsAutoUpdatePage(2000,parent)
|
2009-08-17 03:00:34 -04:00
|
|
|
{
|
|
|
|
setupUi(this) ;
|
2010-02-14 04:06:37 -05:00
|
|
|
|
2010-02-20 17:51:24 -05:00
|
|
|
// Init the basic setup.
|
|
|
|
//
|
|
|
|
QStringList stl ;
|
|
|
|
int n=0 ;
|
2009-08-17 03:00:34 -04:00
|
|
|
|
2010-02-20 17:51:24 -05:00
|
|
|
stl.clear() ;
|
2010-04-03 14:29:25 -04:00
|
|
|
stl.push_back(tr("Search requests")) ;
|
2010-02-20 17:51:24 -05:00
|
|
|
top_level_s_requests = new QTreeWidgetItem(_f2f_TW,stl) ;
|
|
|
|
_f2f_TW->insertTopLevelItem(n++,top_level_s_requests) ;
|
2009-08-17 03:00:34 -04:00
|
|
|
|
2010-02-20 17:51:24 -05:00
|
|
|
stl.clear() ;
|
2010-04-03 14:29:25 -04:00
|
|
|
stl.push_back(tr("Tunnel requests")) ;
|
2010-02-20 17:51:24 -05:00
|
|
|
top_level_t_requests = new QTreeWidgetItem(_f2f_TW,stl) ;
|
|
|
|
_f2f_TW->insertTopLevelItem(n++,top_level_t_requests) ;
|
2009-08-17 03:00:34 -04:00
|
|
|
|
2010-02-20 17:51:24 -05:00
|
|
|
top_level_hashes.clear() ;
|
2011-05-23 17:45:25 -04:00
|
|
|
|
2011-05-28 18:25:42 -04:00
|
|
|
_tunnel_statistics_F->setWidget( _tst_CW = new TurtleRouterStatisticsWidget() ) ;
|
|
|
|
_tunnel_statistics_F->setWidgetResizable(true);
|
|
|
|
_tunnel_statistics_F->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
_tunnel_statistics_F->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
|
|
|
_tunnel_statistics_F->viewport()->setBackgroundRole(QPalette::NoRole);
|
|
|
|
_tunnel_statistics_F->setFrameStyle(QFrame::NoFrame);
|
|
|
|
_tunnel_statistics_F->setFocusPolicy(Qt::NoFocus);
|
2009-08-17 03:00:34 -04:00
|
|
|
}
|
|
|
|
|
2010-02-14 04:06:37 -05:00
|
|
|
void TurtleRouterDialog::updateDisplay()
|
2009-08-17 03:00:34 -04:00
|
|
|
{
|
2010-02-14 04:06:37 -05:00
|
|
|
std::vector<std::vector<std::string> > hashes_info ;
|
|
|
|
std::vector<std::vector<std::string> > tunnels_info ;
|
2011-05-23 17:45:25 -04:00
|
|
|
std::vector<TurtleRequestDisplayInfo > search_reqs_info ;
|
|
|
|
std::vector<TurtleRequestDisplayInfo > tunnel_reqs_info ;
|
2009-08-17 03:00:34 -04:00
|
|
|
|
2010-02-14 04:06:37 -05:00
|
|
|
rsTurtle->getInfo(hashes_info,tunnels_info,search_reqs_info,tunnel_reqs_info) ;
|
2009-08-17 03:00:34 -04:00
|
|
|
|
2011-05-23 17:45:25 -04:00
|
|
|
updateTunnelRequests(hashes_info,tunnels_info,search_reqs_info,tunnel_reqs_info) ;
|
|
|
|
_tst_CW->updateTunnelStatistics(hashes_info,tunnels_info,search_reqs_info,tunnel_reqs_info) ;
|
2011-05-28 18:25:42 -04:00
|
|
|
_tst_CW->update();
|
2011-05-23 17:45:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
QString TurtleRouterDialog::getPeerName(const std::string& peer_id)
|
|
|
|
{
|
|
|
|
static std::map<std::string, QString> names ;
|
|
|
|
|
|
|
|
std::map<std::string,QString>::const_iterator it = names.find(peer_id) ;
|
|
|
|
|
|
|
|
if( it != names.end())
|
|
|
|
return it->second ;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RsPeerDetails detail ;
|
|
|
|
if(!rsPeers->getPeerDetails(peer_id,detail))
|
|
|
|
return "unknown peer";
|
|
|
|
|
|
|
|
return (names[peer_id] = QString::fromStdString(detail.name)) ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TurtleRouterDialog::updateTunnelRequests( const std::vector<std::vector<std::string> >& hashes_info,
|
|
|
|
const std::vector<std::vector<std::string> >& tunnels_info,
|
|
|
|
const std::vector<TurtleRequestDisplayInfo >& search_reqs_info,
|
|
|
|
const std::vector<TurtleRequestDisplayInfo >& tunnel_reqs_info)
|
|
|
|
{
|
2010-02-14 04:06:37 -05:00
|
|
|
// now display this in the QTableWidgets
|
2009-08-17 03:00:34 -04:00
|
|
|
|
2010-02-20 17:51:24 -05:00
|
|
|
QStringList stl ;
|
2010-02-14 05:53:57 -05:00
|
|
|
|
2010-02-20 17:51:24 -05:00
|
|
|
// remove all children of top level objects
|
|
|
|
for(int i=0;i<_f2f_TW->topLevelItemCount();++i)
|
2011-03-02 09:31:03 -05:00
|
|
|
{
|
|
|
|
QTreeWidgetItem *taken ;
|
|
|
|
while( (taken = _f2f_TW->topLevelItem(i)->takeChild(0)) != NULL)
|
|
|
|
delete taken ;
|
|
|
|
}
|
2010-02-14 05:53:57 -05:00
|
|
|
|
2010-02-23 04:14:35 -05:00
|
|
|
for(uint i=0;i<hashes_info.size();++i)
|
|
|
|
findParentHashItem(hashes_info[i][0]) ;
|
|
|
|
|
2010-02-26 09:34:46 -05:00
|
|
|
bool unknown_hash_found = false ;
|
|
|
|
|
2010-02-20 17:51:24 -05:00
|
|
|
// check that an entry exist for all hashes
|
|
|
|
for(uint i=0;i<tunnels_info.size();++i)
|
2010-02-14 05:53:57 -05:00
|
|
|
{
|
2010-02-20 17:51:24 -05:00
|
|
|
const std::string& hash(tunnels_info[i][3]) ;
|
|
|
|
|
|
|
|
QTreeWidgetItem *parent = findParentHashItem(hash) ;
|
|
|
|
|
2011-03-02 09:31:03 -05:00
|
|
|
if(parent->text(0).left(14) == QString("Unknown hashes"))
|
2010-02-26 09:34:46 -05:00
|
|
|
unknown_hash_found = true ;
|
|
|
|
|
2010-06-19 08:11:44 -04:00
|
|
|
QString str = QString::fromStdString( "Tunnel id: " + tunnels_info[i][0] + "\t [" + tunnels_info[i][2] + "] --> [" + tunnels_info[i][1] + "]\t\t last transfer: " + tunnels_info[i][4] + "\t Speed: " + tunnels_info[i][5] ) ;
|
2010-02-20 17:51:24 -05:00
|
|
|
stl.clear() ;
|
|
|
|
stl.push_back(str) ;
|
|
|
|
|
2011-03-02 09:31:03 -05:00
|
|
|
parent->addChild(new QTreeWidgetItem(stl)) ;
|
2010-02-14 05:53:57 -05:00
|
|
|
}
|
|
|
|
|
2010-02-20 17:51:24 -05:00
|
|
|
for(uint i=0;i<search_reqs_info.size();++i)
|
|
|
|
{
|
2011-05-23 17:45:25 -04:00
|
|
|
QString str = "Request id: " + QString::number(search_reqs_info[i].request_id,16) + "\t from [" + getPeerName(search_reqs_info[i].source_peer_id) + "]\t " + QString::number(search_reqs_info[i].age)+" secs ago" ;
|
2009-08-17 03:00:34 -04:00
|
|
|
|
2010-02-20 17:51:24 -05:00
|
|
|
stl.clear() ;
|
|
|
|
stl.push_back(str) ;
|
|
|
|
|
2011-03-02 09:31:03 -05:00
|
|
|
top_level_s_requests->addChild(new QTreeWidgetItem(stl)) ;
|
2010-02-20 17:51:24 -05:00
|
|
|
}
|
2010-04-03 14:29:25 -04:00
|
|
|
top_level_s_requests->setText(0, tr("Search requests") + "(" + QString::number(search_reqs_info.size()) + ")" ) ;
|
2009-08-17 03:00:34 -04:00
|
|
|
|
2011-05-23 17:45:25 -04:00
|
|
|
for(uint i=0;i<tunnel_reqs_info.size();++i)
|
|
|
|
if(i+MAX_TUNNEL_REQUESTS_DISPLAY >= tunnel_reqs_info.size() || i < MAX_TUNNEL_REQUESTS_DISPLAY)
|
2011-03-02 09:31:03 -05:00
|
|
|
{
|
2011-05-23 17:45:25 -04:00
|
|
|
QString str = "Request id: " + QString::number(tunnel_reqs_info[i].request_id,16) + "\t from [" + getPeerName(tunnel_reqs_info[i].source_peer_id) + "]\t " + QString::number(tunnel_reqs_info[i].age)+" secs ago" ;
|
2011-03-02 09:31:03 -05:00
|
|
|
|
|
|
|
stl.clear() ;
|
|
|
|
stl.push_back(str) ;
|
|
|
|
|
|
|
|
top_level_t_requests->addChild(new QTreeWidgetItem(stl)) ;
|
|
|
|
}
|
|
|
|
else if(i == MAX_TUNNEL_REQUESTS_DISPLAY)
|
|
|
|
{
|
|
|
|
stl.clear() ;
|
|
|
|
stl.push_back(QString("...")) ;
|
|
|
|
top_level_t_requests->addChild(new QTreeWidgetItem(stl)) ;
|
|
|
|
|
|
|
|
}
|
2009-08-17 03:00:34 -04:00
|
|
|
|
2010-04-03 14:29:25 -04:00
|
|
|
top_level_t_requests->setText(0, tr("Tunnel requests") + "("+QString::number(tunnel_reqs_info.size()) + ")") ;
|
2009-08-17 03:00:34 -04:00
|
|
|
|
2011-03-02 09:31:03 -05:00
|
|
|
QTreeWidgetItem *unknown_hashs_item = findParentHashItem("") ;
|
|
|
|
unknown_hashs_item->setText(0,QString("Unknown hashes (") + QString::number(unknown_hashs_item->childCount())+QString(")")) ;
|
|
|
|
|
2010-02-23 04:14:35 -05:00
|
|
|
// Ok, this is a N2 search, but there are very few elements in the list.
|
2010-02-20 17:51:24 -05:00
|
|
|
for(int i=2;i<_f2f_TW->topLevelItemCount();)
|
2010-02-23 04:14:35 -05:00
|
|
|
{
|
|
|
|
bool found = false ;
|
2010-02-26 09:34:46 -05:00
|
|
|
|
2011-03-02 09:31:03 -05:00
|
|
|
if(_f2f_TW->topLevelItem(i)->text(0).left(14) == "Unknown hashes" && unknown_hash_found)
|
2010-02-26 09:34:46 -05:00
|
|
|
found = true ;
|
|
|
|
|
2010-02-27 15:19:31 -05:00
|
|
|
if(_f2f_TW->topLevelItem(i)->childCount() > 0) // this saves uploading hashes
|
|
|
|
found = true ;
|
|
|
|
|
2010-02-26 09:34:46 -05:00
|
|
|
for(uint j=0;j<hashes_info.size() && !found;++j)
|
2010-02-23 04:14:35 -05:00
|
|
|
if(_f2f_TW->topLevelItem(i)->text(0).toStdString() == hashes_info[j][0])
|
|
|
|
found=true ;
|
|
|
|
|
|
|
|
if(!found)
|
2011-03-02 09:31:03 -05:00
|
|
|
delete _f2f_TW->takeTopLevelItem(i) ;
|
2010-02-20 17:51:24 -05:00
|
|
|
else
|
|
|
|
++i ;
|
2010-02-23 04:14:35 -05:00
|
|
|
}
|
2010-02-20 17:51:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
QTreeWidgetItem *TurtleRouterDialog::findParentHashItem(const std::string& hash)
|
|
|
|
{
|
|
|
|
// look for the hash, and insert a new element if necessary.
|
|
|
|
//
|
2011-03-02 09:31:03 -05:00
|
|
|
QList<QTreeWidgetItem*> items = _f2f_TW->findItems((hash=="")?QString("Unknown hashes"):QString::fromStdString(hash),Qt::MatchStartsWith) ;
|
2010-02-20 17:51:24 -05:00
|
|
|
|
|
|
|
if(items.empty())
|
|
|
|
{
|
|
|
|
QStringList stl ;
|
|
|
|
stl.push_back((hash=="")?QString("Unknown hashes"):QString::fromStdString(hash)) ;
|
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem(_f2f_TW,stl) ;
|
|
|
|
_f2f_TW->insertTopLevelItem(0,item) ;
|
|
|
|
|
|
|
|
return item ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return items.front() ;
|
2009-08-17 03:00:34 -04:00
|
|
|
}
|
|
|
|
|
2011-05-23 17:45:25 -04:00
|
|
|
TurtleRouterStatisticsWidget::TurtleRouterStatisticsWidget(QWidget *parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
{
|
|
|
|
maxWidth = 200 ;
|
2011-05-28 18:25:42 -04:00
|
|
|
maxHeight = 0 ;
|
2011-05-23 17:45:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TurtleRouterStatisticsWidget::updateTunnelStatistics(const std::vector<std::vector<std::string> >& hashes_info,
|
|
|
|
const std::vector<std::vector<std::string> >& tunnels_info,
|
|
|
|
const std::vector<TurtleRequestDisplayInfo >& search_reqs_info,
|
|
|
|
const std::vector<TurtleRequestDisplayInfo >& tunnel_reqs_info)
|
|
|
|
|
|
|
|
{
|
2011-05-28 18:25:42 -04:00
|
|
|
static const int cellx = 6 ;
|
|
|
|
static const int celly = 10+4 ;
|
|
|
|
|
2011-05-23 17:45:25 -04:00
|
|
|
QPixmap tmppixmap(maxWidth, maxHeight);
|
|
|
|
tmppixmap.fill(this, 0, 0);
|
2011-05-28 18:25:42 -04:00
|
|
|
setFixedHeight(maxHeight);
|
2011-05-23 17:45:25 -04:00
|
|
|
|
|
|
|
QPainter painter(&tmppixmap);
|
|
|
|
painter.initFrom(this);
|
|
|
|
|
2011-05-28 18:25:42 -04:00
|
|
|
maxHeight = 500 ;
|
|
|
|
|
2011-05-23 17:45:25 -04:00
|
|
|
// std::cerr << "Drawing into pixmap of size " << maxWidth << "x" << maxHeight << std::endl;
|
|
|
|
// draw...
|
|
|
|
int ox=5,oy=5 ;
|
2011-05-28 18:25:42 -04:00
|
|
|
|
|
|
|
TRHistogram(search_reqs_info).draw(&painter,ox,oy,QObject::tr("Search requests repartition:")) ;
|
|
|
|
|
|
|
|
painter.setPen(QColor::fromRgb(70,70,70)) ;
|
|
|
|
painter.drawLine(0,oy,maxWidth,oy) ;
|
|
|
|
oy += celly ;
|
|
|
|
|
|
|
|
TRHistogram(tunnel_reqs_info).draw(&painter,ox,oy,QObject::tr("Tunnel requests repartition:")) ;
|
2011-05-23 17:45:25 -04:00
|
|
|
|
2011-05-26 18:11:06 -04:00
|
|
|
// now give information about turtle traffic.
|
|
|
|
//
|
|
|
|
TurtleTrafficStatisticsInfo info ;
|
|
|
|
rsTurtle->getTrafficStatistics(info) ;
|
|
|
|
|
2011-05-28 18:25:42 -04:00
|
|
|
painter.setPen(QColor::fromRgb(70,70,70)) ;
|
|
|
|
painter.drawLine(0,oy,maxWidth,oy) ;
|
|
|
|
oy += celly ;
|
2011-05-26 18:11:06 -04:00
|
|
|
|
|
|
|
painter.drawText(ox,oy+celly,tr("Turtle router traffic:")) ; oy += celly*2 ;
|
|
|
|
painter.drawText(ox+2*cellx,oy+celly,tr("Tunnel requests Up")+"\t: " + speedString(info.tr_up_Bps) ) ; oy += celly ;
|
|
|
|
painter.drawText(ox+2*cellx,oy+celly,tr("Tunnel requests Dn")+"\t: " + speedString(info.tr_dn_Bps) ) ; oy += celly ;
|
|
|
|
painter.drawText(ox+2*cellx,oy+celly,tr("Incoming file data")+"\t: " + speedString(info.data_dn_Bps) ) ; oy += celly ;
|
|
|
|
painter.drawText(ox+2*cellx,oy+celly,tr("Outgoing file data")+"\t: " + speedString(info.data_up_Bps) ) ; oy += celly ;
|
|
|
|
painter.drawText(ox+2*cellx,oy+celly,tr("Forwarded data ")+"\t: " + speedString(info.unknown_updn_Bps) ) ; oy += celly ;
|
|
|
|
|
2011-05-23 17:45:25 -04:00
|
|
|
// update the pixmap
|
2011-05-26 18:11:06 -04:00
|
|
|
//
|
2011-05-23 17:45:25 -04:00
|
|
|
pixmap = tmppixmap;
|
2011-05-28 18:25:42 -04:00
|
|
|
maxHeight = oy ;
|
2011-05-23 17:45:25 -04:00
|
|
|
}
|
|
|
|
|
2011-05-26 18:11:06 -04:00
|
|
|
QString TurtleRouterStatisticsWidget::speedString(float f)
|
|
|
|
{
|
|
|
|
if(f < 1.0f)
|
|
|
|
return QString("0 B/s") ;
|
|
|
|
if(f < 1024.0f)
|
|
|
|
return QString::number((int)f)+" B/s" ;
|
|
|
|
|
|
|
|
return QString::number(f/1024.0,'f',2) + " KB/s";
|
|
|
|
}
|
|
|
|
|
2011-05-23 17:45:25 -04:00
|
|
|
void TurtleRouterStatisticsWidget::paintEvent(QPaintEvent *event)
|
|
|
|
{
|
|
|
|
QStylePainter(this).drawPixmap(0, 0, pixmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TurtleRouterStatisticsWidget::resizeEvent(QResizeEvent *event)
|
|
|
|
{
|
|
|
|
QRect TaskGraphRect = geometry();
|
2011-05-28 18:25:42 -04:00
|
|
|
maxWidth = TaskGraphRect.width();
|
|
|
|
maxHeight = TaskGraphRect.height() ;
|
2011-05-23 17:45:25 -04:00
|
|
|
|
|
|
|
QWidget::resizeEvent(event);
|
2011-05-28 18:25:42 -04:00
|
|
|
update();
|
2011-05-23 17:45:25 -04:00
|
|
|
}
|
|
|
|
|
2010-02-20 17:51:24 -05:00
|
|
|
|