2009-08-17 03:00:34 -04:00
|
|
|
#include <iostream>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <rsiface/rsturtle.h>
|
|
|
|
#include "TurtleRouterDialog.h"
|
|
|
|
|
|
|
|
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() ;
|
|
|
|
stl.push_back(QString("Search requests")) ;
|
|
|
|
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() ;
|
|
|
|
stl.push_back(QString("Tunnel requests")) ;
|
|
|
|
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() ;
|
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 ;
|
|
|
|
std::vector<std::vector<std::string> > search_reqs_info ;
|
|
|
|
std::vector<std::vector<std::string> > 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
|
|
|
|
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)
|
|
|
|
while(_f2f_TW->topLevelItem(i)->takeChild(0) != NULL) ;
|
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) ;
|
|
|
|
|
2010-02-26 09:34:46 -05:00
|
|
|
if(parent->text(0) == QString("Unknown hashes"))
|
|
|
|
unknown_hash_found = true ;
|
|
|
|
|
2010-02-21 14:27:13 -05: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]) ;
|
2010-02-20 17:51:24 -05:00
|
|
|
stl.clear() ;
|
|
|
|
stl.push_back(str) ;
|
|
|
|
|
|
|
|
new QTreeWidgetItem(parent,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)
|
|
|
|
{
|
|
|
|
QString str = QString::fromStdString("Request id: "+search_reqs_info[i][0] + "\t from [" + search_reqs_info[i][1] + "]\t " + search_reqs_info[i][2]) ;
|
2009-08-17 03:00:34 -04:00
|
|
|
|
2010-02-20 17:51:24 -05:00
|
|
|
stl.clear() ;
|
|
|
|
stl.push_back(str) ;
|
|
|
|
|
|
|
|
new QTreeWidgetItem(top_level_s_requests,stl) ;
|
|
|
|
}
|
2010-02-23 04:14:35 -05:00
|
|
|
top_level_s_requests->setText(0,"Search requests ("+QString::number(search_reqs_info.size())+")") ;
|
2009-08-17 03:00:34 -04:00
|
|
|
|
2010-02-20 17:51:24 -05:00
|
|
|
for(uint i=0;i<tunnel_reqs_info.size();++i)
|
2009-08-17 03:00:34 -04:00
|
|
|
{
|
2010-02-20 17:51:24 -05:00
|
|
|
QString str = QString::fromStdString("Request id: "+tunnel_reqs_info[i][0] + "\t from [" + tunnel_reqs_info[i][1] + "]\t " + tunnel_reqs_info[i][2]) ;
|
|
|
|
|
|
|
|
stl.clear() ;
|
|
|
|
stl.push_back(str) ;
|
2009-08-17 03:00:34 -04:00
|
|
|
|
2010-02-20 17:51:24 -05:00
|
|
|
new QTreeWidgetItem(top_level_t_requests,stl) ;
|
2009-08-17 03:00:34 -04:00
|
|
|
}
|
2010-02-23 04:14:35 -05:00
|
|
|
top_level_t_requests->setText(0,"tunnel requests ("+QString::number(tunnel_reqs_info.size())+")") ;
|
2009-08-17 03:00:34 -04:00
|
|
|
|
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
|
|
|
|
|
|
|
if(_f2f_TW->topLevelItem(i)->text(0) == "Unknown hashes" && unknown_hash_found)
|
|
|
|
found = true ;
|
|
|
|
|
|
|
|
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)
|
2010-02-20 17:51:24 -05:00
|
|
|
_f2f_TW->takeTopLevelItem(i) ;
|
|
|
|
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.
|
|
|
|
//
|
|
|
|
QList<QTreeWidgetItem*> items = _f2f_TW->findItems((hash=="")?QString("Unknown hashes"):QString::fromStdString(hash),Qt::MatchExactly) ;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-02-20 17:51:24 -05:00
|
|
|
|