improved display of tunnel info

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2381 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-02-20 22:51:24 +00:00
parent c7895aa0e2
commit 7625238724
3 changed files with 77 additions and 157 deletions

View file

@ -5,56 +5,27 @@
#include <rsiface/rsturtle.h> #include <rsiface/rsturtle.h>
#include "TurtleRouterDialog.h" #include "TurtleRouterDialog.h"
TurtleRouterDialog *TurtleRouterDialog::_instance = NULL ;
TurtleRouterDialog::TurtleRouterDialog(QWidget *parent) TurtleRouterDialog::TurtleRouterDialog(QWidget *parent)
: RsAutoUpdatePage(2000,parent) : RsAutoUpdatePage(2000,parent)
{ {
setupUi(this) ; setupUi(this) ;
connect( _hashes_TW, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showCtxMenu(const QPoint&)));
_hashes_TW->setToolTip(tr("As a helper, you can manually remove hashes\nfrom there. Warning: doing so on currently\nactive transfers will block the transfer process.")) ; // Init the basic setup.
} //
QStringList stl ;
int n=0 ;
void TurtleRouterDialog::showCtxMenu(const QPoint& point) stl.clear() ;
{ stl.push_back(QString("Search requests")) ;
if(_hashes_TW->currentItem() == NULL) top_level_s_requests = new QTreeWidgetItem(_f2f_TW,stl) ;
return ; _f2f_TW->insertTopLevelItem(n++,top_level_s_requests) ;
std::cerr << "execing context menu" << std::endl ; stl.clear() ;
// create context menus. stl.push_back(QString("Tunnel requests")) ;
QMenu contextMnu( this ); top_level_t_requests = new QTreeWidgetItem(_f2f_TW,stl) ;
QAction *removeHashAction = new QAction(QIcon(":/images/delete.png"), tr("Stop handling this hash"), this); _f2f_TW->insertTopLevelItem(n++,top_level_t_requests) ;
connect(removeHashAction , SIGNAL(triggered()), this, SLOT(removeFileHash()));
contextMnu.addAction(removeHashAction);
QMouseEvent *mevent = new QMouseEvent(QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier ) ; top_level_hashes.clear() ;
contextMnu.exec( mevent->globalPos() );
}
void TurtleRouterDialog::showUp()
{
if(_instance == NULL)
_instance = new TurtleRouterDialog ;
_instance->show() ;
_instance->update() ;
}
void TurtleRouterDialog::removeFileHash()
{
QTableWidgetItem *item = _hashes_TW->currentItem();
std::cout << "in remove hash " << std::endl ;
if(item == NULL)
return ;
std::cout << "item->row = " << item->row() << std::endl ;
std::string hash = _hashes_TW->item(item->row(),0)->text().toStdString() ;
std::cout << "remove ing hash: " << hash << std::endl ;
rsTurtle->stopMonitoringFileTunnels(hash) ;
} }
void TurtleRouterDialog::updateDisplay() void TurtleRouterDialog::updateDisplay()
@ -70,35 +41,70 @@ void TurtleRouterDialog::updateDisplay()
// now display this in the QTableWidgets // now display this in the QTableWidgets
fillTable( _hashes_TW, hashes_info) ; QStringList stl ;
fillTable( _tunnels_TW, tunnels_info) ;
std::vector<std::vector<std::string> >& reqs(search_reqs_info) ; // remove all children of top level objects
for(int i=0;i<_f2f_TW->topLevelItemCount();++i)
while(_f2f_TW->topLevelItem(i)->takeChild(0) != NULL) ;
for(uint i=0;i<search_reqs_info.size();++i) search_reqs_info[i].push_back("Search request") ; // check that an entry exist for all hashes
for(uint i=0;i<tunnel_reqs_info.size();++i) for(uint i=0;i<tunnels_info.size();++i)
{ {
tunnel_reqs_info[i].push_back("Tunnel request") ; const std::string& hash(tunnels_info[i][3]) ;
reqs.push_back(tunnel_reqs_info[i]) ;
QTreeWidgetItem *parent = findParentHashItem(hash) ;
QString str = QString::fromStdString("Tunnel id: "+tunnels_info[i][0] + "\t from [" + tunnels_info[i][2] + "] to [" + tunnels_info[i][1] + "]\t\t last transfer: " + tunnels_info[i][4]) ;
stl.clear() ;
stl.push_back(str) ;
new QTreeWidgetItem(parent,stl) ;
} }
fillTable( _reqs_TW, reqs) ; 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]) ;
void TurtleRouterDialog::fillTable(QTableWidget *table,const std::vector<std::vector<std::string> >& data) stl.clear() ;
stl.push_back(str) ;
new QTreeWidgetItem(top_level_s_requests,stl) ;
}
for(uint i=0;i<tunnel_reqs_info.size();++i)
{
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) ;
new QTreeWidgetItem(top_level_t_requests,stl) ;
}
for(int i=2;i<_f2f_TW->topLevelItemCount();)
if(_f2f_TW->topLevelItem(i)->childCount() == 0)
_f2f_TW->takeTopLevelItem(i) ;
else
++i ;
}
QTreeWidgetItem *TurtleRouterDialog::findParentHashItem(const std::string& hash)
{ {
table->clearContents() ; // 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) ;
for(uint i=0;i<data.size();++i) if(items.empty())
{ {
if(table->rowCount() <= i) QStringList stl ;
table->insertRow(i) ; stl.push_back((hash=="")?QString("Unknown hashes"):QString::fromStdString(hash)) ;
QTreeWidgetItem *item = new QTreeWidgetItem(_f2f_TW,stl) ;
_f2f_TW->insertTopLevelItem(0,item) ;
for(uint j=0;j<data[i].size();++j) return item ;
table->setItem(i,j,new QTableWidgetItem(QString::fromStdString(data[i][j].empty()?"Unknown":data[i][j]))) ;
} }
else
for(uint i=data.size();i<table->rowCount();) return items.front() ;
table->removeRow(i) ;
} }

View file

@ -6,22 +6,16 @@
class TurtleRouterDialog: public RsAutoUpdatePage, public Ui::TurtleRouterDialogForm class TurtleRouterDialog: public RsAutoUpdatePage, public Ui::TurtleRouterDialogForm
{ {
Q_OBJECT
public: public:
TurtleRouterDialog(QWidget *parent = NULL) ; TurtleRouterDialog(QWidget *parent = NULL) ;
static void showUp() ;
/** Default Constructor */ /** Default Constructor */
protected slots:
void showCtxMenu(const QPoint&) ;
void removeFileHash() ;
private: private:
void fillTable(QTableWidget *table,const std::vector<std::vector<std::string> >&) ;
QTimer *_timer ;
virtual void updateDisplay() ; virtual void updateDisplay() ;
QTreeWidgetItem *findParentHashItem(const std::string& hash) ;
static TurtleRouterDialog *_instance ; std::map<std::string,QTreeWidgetItem*> top_level_hashes ;
QTreeWidgetItem *top_level_unknown_hashes ;
QTreeWidgetItem *top_level_s_requests ;
QTreeWidgetItem *top_level_t_requests ;
} ; } ;

View file

@ -19,93 +19,13 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QTableWidget" name="_hashes_TW"> <widget class="QTreeWidget" name="_f2f_TW">
<property name="contextMenuPolicy"> <property name="headerHidden">
<enum>Qt::CustomContextMenu</enum> <bool>true</bool>
</property> </property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<column> <column>
<property name="text"> <property name="text">
<string>Handled file hash</string> <string>F2F router information</string>
</property>
</column>
<column>
<property name="text">
<string>File Name</string>
</property>
</column>
<column>
<property name="text">
<string>Active tunnels</string>
</property>
</column>
<column>
<property name="text">
<string>Last tunnel request</string>
</property>
</column>
</widget>
</item>
<item>
<widget class="QTableWidget" name="_tunnels_TW">
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<column>
<property name="text">
<string>Current Tunnel id</string>
</property>
</column>
<column>
<property name="text">
<string>Source</string>
</property>
</column>
<column>
<property name="text">
<string>Destination</string>
</property>
</column>
<column>
<property name="text">
<string>Hash</string>
</property>
</column>
<column>
<property name="text">
<string>Last transfer</string>
</property>
</column>
</widget>
</item>
<item>
<widget class="QTableWidget" name="_reqs_TW">
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<column>
<property name="text">
<string>Request id</string>
</property>
</column>
<column>
<property name="text">
<string>Origin</string>
</property>
</column>
<column>
<property name="text">
<string>Age</string>
</property>
</column>
<column>
<property name="text">
<string>Type</string>
</property> </property>
</column> </column>
</widget> </widget>