2015-07-12 00:04:18 -04:00
|
|
|
#include <QComboBox>
|
2015-07-12 23:04:36 -04:00
|
|
|
#include <QTimer>
|
2015-07-12 00:04:18 -04:00
|
|
|
|
2015-07-12 23:04:36 -04:00
|
|
|
#include "retroshare/rspeers.h"
|
2015-07-17 16:13:31 -04:00
|
|
|
#include "retroshare/rsservicecontrol.h"
|
2015-07-12 23:04:36 -04:00
|
|
|
#include "retroshare-gui/RsAutoUpdatePage.h"
|
2015-07-12 00:04:18 -04:00
|
|
|
#include "BandwidthStatsWidget.h"
|
|
|
|
|
|
|
|
BandwidthStatsWidget::BandwidthStatsWidget(QWidget *parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
{
|
|
|
|
ui.setupUi(this) ;
|
|
|
|
|
2015-07-12 23:04:36 -04:00
|
|
|
// now add one button per service
|
|
|
|
|
|
|
|
ui.friend_CB->addItem(tr("Sum")) ;
|
|
|
|
ui.friend_CB->addItem(tr("All")) ;
|
|
|
|
|
|
|
|
ui.service_CB->addItem(tr("Sum")) ;
|
|
|
|
ui.service_CB->addItem(tr("All")) ;
|
|
|
|
|
|
|
|
ui.unit_CB->addItem(tr("KB/s")) ;
|
|
|
|
ui.unit_CB->addItem(tr("Count")) ;
|
2016-01-16 11:30:15 -05:00
|
|
|
|
|
|
|
ui.logScale_CB->setChecked(true) ;
|
2015-07-12 23:04:36 -04:00
|
|
|
|
2017-03-04 15:08:10 -05:00
|
|
|
ui.bwgraph_BW->setSelector(BWGraphSource::SELECTOR_TYPE_FRIEND,BWGraphSource::GRAPH_TYPE_SUM) ;
|
|
|
|
ui.bwgraph_BW->setSelector(BWGraphSource::SELECTOR_TYPE_SERVICE,BWGraphSource::GRAPH_TYPE_SUM) ;
|
|
|
|
ui.bwgraph_BW->setUnit(BWGraphSource::UNIT_KILOBYTES) ;
|
2015-07-15 15:29:41 -04:00
|
|
|
|
2017-04-20 14:54:51 -04:00
|
|
|
ui.bwgraph_BW->resetFlags(RSGraphWidget::RSGRAPH_FLAGS_LEGEND_CUMULATED) ;
|
|
|
|
|
|
|
|
updateUnitSelection(0);
|
|
|
|
|
2015-07-12 23:04:36 -04:00
|
|
|
// Setup connections
|
|
|
|
|
2017-04-20 14:54:51 -04:00
|
|
|
QObject::connect(ui.friend_CB ,SIGNAL(currentIndexChanged(int )),this, SLOT( updateFriendSelection(int ))) ;
|
|
|
|
QObject::connect(ui.updn_CB ,SIGNAL(currentIndexChanged(int )),this, SLOT( updateUpDownSelection(int ))) ;
|
|
|
|
QObject::connect(ui.unit_CB ,SIGNAL(currentIndexChanged(int )),this, SLOT( updateUnitSelection(int ))) ;
|
|
|
|
QObject::connect(ui.service_CB ,SIGNAL(currentIndexChanged(int )),this, SLOT(updateServiceSelection(int ))) ;
|
|
|
|
QObject::connect(ui.legend_CB ,SIGNAL(currentIndexChanged(int )),this, SLOT( updateLegendType(int ))) ;
|
|
|
|
QObject::connect(ui.logScale_CB,SIGNAL( toggled(bool)),this, SLOT( toggleLogScale(bool))) ;
|
2015-07-12 23:04:36 -04:00
|
|
|
|
|
|
|
// setup one timer for auto-update
|
|
|
|
|
|
|
|
mTimer = new QTimer(this) ;
|
|
|
|
connect(mTimer, SIGNAL(timeout()), this, SLOT(updateComboBoxes())) ;
|
|
|
|
mTimer->setSingleShot(false) ;
|
|
|
|
mTimer->start(2000) ;
|
|
|
|
}
|
|
|
|
|
2016-01-16 11:30:15 -05:00
|
|
|
void BandwidthStatsWidget::toggleLogScale(bool b)
|
|
|
|
{
|
|
|
|
if(b)
|
|
|
|
ui.bwgraph_BW->setFlags(RSGraphWidget::RSGRAPH_FLAGS_LOG_SCALE_Y) ;
|
|
|
|
else
|
|
|
|
ui.bwgraph_BW->resetFlags(RSGraphWidget::RSGRAPH_FLAGS_LOG_SCALE_Y) ;
|
|
|
|
}
|
2015-07-12 23:04:36 -04:00
|
|
|
void BandwidthStatsWidget::updateComboBoxes()
|
|
|
|
{
|
|
|
|
if(!isVisible())
|
|
|
|
return ;
|
|
|
|
|
|
|
|
if(RsAutoUpdatePage::eventsLocked())
|
|
|
|
return ;
|
|
|
|
|
|
|
|
// Setup button/combobox info
|
|
|
|
|
2016-06-05 11:05:52 -04:00
|
|
|
int indx = 2 ;
|
2015-07-17 16:13:31 -04:00
|
|
|
//RsPeerDetails details ;
|
2015-07-12 23:04:36 -04:00
|
|
|
RsPeerId current_friend_id(ui.friend_CB->itemData(ui.friend_CB->currentIndex()).toString().toStdString()) ;
|
|
|
|
|
2015-07-17 16:13:31 -04:00
|
|
|
for(std::map<RsPeerId,std::string>::const_iterator it(ui.bwgraph_BW->visibleFriends().begin());it!=ui.bwgraph_BW->visibleFriends().end();++it)
|
2015-07-12 23:04:36 -04:00
|
|
|
{
|
2015-07-17 16:13:31 -04:00
|
|
|
if( it->first.toStdString() != ui.friend_CB->itemData(indx).toString().toStdString())
|
2015-07-12 23:04:36 -04:00
|
|
|
{
|
2015-07-17 16:13:31 -04:00
|
|
|
std::cerr << " friends: " << it->first << " not in combo at place " << indx << ". Adding it." << std::endl;
|
2015-07-12 23:04:36 -04:00
|
|
|
|
2015-07-17 16:13:31 -04:00
|
|
|
QString name = QString::fromUtf8(it->second.c_str()) ;
|
2015-07-12 23:04:36 -04:00
|
|
|
QVariant data ;
|
|
|
|
|
2015-07-17 16:13:31 -04:00
|
|
|
//if(rsPeers->getPeerDetails(*it,details))
|
|
|
|
//{
|
|
|
|
// name = QString::fromUtf8(details.name.c_str())+" ("+QString::fromUtf8(details.location.c_str())+")" ;
|
|
|
|
data = QVariant(QString::fromStdString( (it->first).toStdString())) ;
|
|
|
|
//}
|
2015-07-12 23:04:36 -04:00
|
|
|
|
|
|
|
if(ui.friend_CB->count() <= indx)
|
|
|
|
ui.friend_CB->addItem(name,data) ;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui.friend_CB->setItemText(indx,name) ;
|
|
|
|
ui.friend_CB->setItemData(indx,data) ;
|
|
|
|
}
|
|
|
|
|
2015-07-17 16:13:31 -04:00
|
|
|
if(current_friend_id == it->first && ui.friend_CB->currentIndex() != indx)
|
2015-07-12 23:04:36 -04:00
|
|
|
ui.friend_CB->setCurrentIndex(indx) ;
|
|
|
|
}
|
|
|
|
++indx ;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(ui.friend_CB->count() > indx)
|
|
|
|
{
|
|
|
|
std::cerr << " friends: removing item " << ui.friend_CB->count()-1 << " currently " << ui.friend_CB->count() << " items" << std::endl;
|
|
|
|
ui.friend_CB->removeItem(ui.friend_CB->count()-1) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
// now one entry per service
|
|
|
|
|
2015-07-17 16:13:31 -04:00
|
|
|
RsPeerServiceInfo service_info_map ;
|
|
|
|
rsServiceControl->getOwnServices(service_info_map) ;
|
|
|
|
|
2015-07-12 23:04:36 -04:00
|
|
|
indx = 2 ;
|
|
|
|
uint16_t current_service_id = ui.service_CB->itemData(ui.service_CB->currentIndex()).toInt() ;
|
|
|
|
|
|
|
|
for(std::set<uint16_t>::const_iterator it(ui.bwgraph_BW->visibleServices().begin());it!=ui.bwgraph_BW->visibleServices().end();++it)
|
|
|
|
{
|
|
|
|
if(*it != ui.service_CB->itemData(indx).toInt())
|
|
|
|
{
|
2015-07-17 16:13:31 -04:00
|
|
|
QString sname = QString::fromUtf8(service_info_map.mServiceList[ ((*it)<<8) + 0x02000000].mServiceName.c_str()) ;
|
2015-07-12 23:04:36 -04:00
|
|
|
|
|
|
|
if(ui.service_CB->count() <= indx)
|
2015-07-17 16:13:31 -04:00
|
|
|
ui.service_CB->addItem(sname + " (0x"+QString::number(*it,16)+")",QVariant(*it)) ;
|
2015-07-12 23:04:36 -04:00
|
|
|
else
|
|
|
|
{
|
2015-07-17 16:13:31 -04:00
|
|
|
ui.service_CB->setItemText(indx,sname + " (0x"+QString::number(*it,16)+")") ;
|
2015-07-12 23:04:36 -04:00
|
|
|
ui.service_CB->setItemData(indx,QVariant(*it)) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(current_service_id == *it && ui.service_CB->currentIndex() != indx)
|
|
|
|
ui.service_CB->setCurrentIndex(indx) ;
|
|
|
|
|
|
|
|
}
|
|
|
|
++indx ;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(ui.service_CB->count() > indx)
|
|
|
|
{
|
|
|
|
std::cerr << " services: removing item " << ui.service_CB->count()-1 << std::endl;
|
|
|
|
ui.service_CB->removeItem(ui.service_CB->count()-1) ;
|
|
|
|
}
|
2015-07-12 00:04:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void BandwidthStatsWidget::updateFriendSelection(int n)
|
|
|
|
{
|
|
|
|
if(n == 0)
|
2017-03-04 15:08:10 -05:00
|
|
|
ui.bwgraph_BW->setSelector(BWGraphSource::SELECTOR_TYPE_FRIEND,BWGraphSource::GRAPH_TYPE_SUM) ;
|
2015-07-12 00:04:18 -04:00
|
|
|
else if(n == 1)
|
|
|
|
{
|
|
|
|
// 1 means all. So make sure the other combo is not set on ALL. If so, switch it to sum.
|
|
|
|
|
|
|
|
if(ui.service_CB->currentIndex() == 1)
|
|
|
|
ui.service_CB->setCurrentIndex(0) ;
|
|
|
|
|
2017-03-04 15:08:10 -05:00
|
|
|
ui.bwgraph_BW->setSelector(BWGraphSource::SELECTOR_TYPE_FRIEND,BWGraphSource::GRAPH_TYPE_ALL) ;
|
2015-07-12 00:04:18 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int ci = ui.friend_CB->currentIndex() ;
|
|
|
|
|
2017-03-04 15:08:10 -05:00
|
|
|
ui.bwgraph_BW->setSelector(BWGraphSource::SELECTOR_TYPE_FRIEND,BWGraphSource::GRAPH_TYPE_SINGLE,ui.friend_CB->itemData(ci,Qt::UserRole).toString().toStdString()) ;
|
2015-07-12 00:04:18 -04:00
|
|
|
}
|
|
|
|
}
|
2017-04-20 14:54:51 -04:00
|
|
|
void BandwidthStatsWidget::updateLegendType(int n)
|
|
|
|
{
|
|
|
|
if(n==0)
|
|
|
|
ui.bwgraph_BW->resetFlags(RSGraphWidget::RSGRAPH_FLAGS_LEGEND_CUMULATED) ;
|
|
|
|
else
|
|
|
|
ui.bwgraph_BW->setFlags(RSGraphWidget::RSGRAPH_FLAGS_LEGEND_CUMULATED) ;
|
|
|
|
}
|
2015-07-12 00:04:18 -04:00
|
|
|
void BandwidthStatsWidget::updateServiceSelection(int n)
|
|
|
|
{
|
|
|
|
if(n == 0)
|
2017-03-04 15:08:10 -05:00
|
|
|
ui.bwgraph_BW->setSelector(BWGraphSource::SELECTOR_TYPE_SERVICE,BWGraphSource::GRAPH_TYPE_SUM) ;
|
2015-07-12 00:04:18 -04:00
|
|
|
else if(n == 1)
|
|
|
|
{
|
|
|
|
// 1 means all. So make sure the other combo is not set on ALL. If so, switch it to sum.
|
|
|
|
|
|
|
|
if(ui.friend_CB->currentIndex() == 1)
|
|
|
|
ui.friend_CB->setCurrentIndex(0) ;
|
|
|
|
|
2017-03-04 15:08:10 -05:00
|
|
|
ui.bwgraph_BW->setSelector(BWGraphSource::SELECTOR_TYPE_SERVICE,BWGraphSource::GRAPH_TYPE_ALL) ;
|
2015-07-12 00:04:18 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int ci = ui.service_CB->currentIndex() ;
|
|
|
|
|
2017-03-04 15:08:10 -05:00
|
|
|
ui.bwgraph_BW->setSelector(BWGraphSource::SELECTOR_TYPE_SERVICE,BWGraphSource::GRAPH_TYPE_SINGLE,ui.service_CB->itemData(ci,Qt::UserRole).toString().toStdString()) ;
|
2015-07-12 00:04:18 -04:00
|
|
|
}
|
|
|
|
}
|
2015-07-12 23:04:36 -04:00
|
|
|
|
|
|
|
void BandwidthStatsWidget::updateUpDownSelection(int n)
|
|
|
|
{
|
|
|
|
if(n==0)
|
2017-03-04 15:08:10 -05:00
|
|
|
ui.bwgraph_BW->setDirection(BWGraphSource::DIRECTION_UP) ;
|
2015-07-12 23:04:36 -04:00
|
|
|
else
|
2017-03-04 15:08:10 -05:00
|
|
|
ui.bwgraph_BW->setDirection(BWGraphSource::DIRECTION_DOWN) ;
|
2015-07-12 23:04:36 -04:00
|
|
|
}
|
|
|
|
void BandwidthStatsWidget::updateUnitSelection(int n)
|
|
|
|
{
|
|
|
|
if(n==0)
|
2017-04-20 14:54:51 -04:00
|
|
|
{
|
2017-03-04 15:08:10 -05:00
|
|
|
ui.bwgraph_BW->setUnit(BWGraphSource::UNIT_KILOBYTES) ;
|
2017-04-20 14:54:51 -04:00
|
|
|
ui.legend_CB->setItemText(1,tr("Average"));
|
|
|
|
}
|
2015-07-12 23:04:36 -04:00
|
|
|
else
|
2017-04-20 14:54:51 -04:00
|
|
|
{
|
2017-03-04 15:08:10 -05:00
|
|
|
ui.bwgraph_BW->setUnit(BWGraphSource::UNIT_COUNT) ;
|
2017-04-20 14:54:51 -04:00
|
|
|
ui.legend_CB->setItemText(1,tr("Total"));
|
|
|
|
}
|
2015-07-12 23:04:36 -04:00
|
|
|
}
|