Added new display window for monitor bandwidth rates with peers.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5242 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2012-06-21 23:24:53 +00:00
parent 48a1c66c60
commit 7501d92882
6 changed files with 418 additions and 0 deletions

View File

@ -392,6 +392,7 @@ HEADERS += rshare.h \
gui/connect/ConnectFriendWizard.h \
gui/groups/CreateGroup.h \
gui/dht/DhtWindow.h \
gui/bwctrl/BwCtrlWindow.h \
gui/GetStartedDialog.h
@ -493,6 +494,7 @@ FORMS += gui/StartDialog.ui \
gui/common/RsCollectionDialog.ui \
gui/style/StyleDialog.ui \
gui/dht/DhtWindow.ui \
gui/bwctrl/BwCtrlWindow.ui \
gui/GetStartedDialog.ui
SOURCES += main.cpp \
@ -672,6 +674,7 @@ SOURCES += main.cpp \
gui/connect/ConnectFriendWizard.cpp \
gui/groups/CreateGroup.cpp \
gui/dht/DhtWindow.cpp \
gui/bwctrl/BwCtrlWindow.cpp \
gui/GetStartedDialog.cpp
RESOURCES += gui/images.qrc lang/lang.qrc gui/help/content/content.qrc

View File

@ -99,14 +99,20 @@
/****
*
* #define USE_DHTWINDOW 1
* #define USE_BWCTRLWINDOW 1
*
****/
#define USE_DHTWINDOW 1
#define USE_BWCTRLWINDOW 1
#ifdef USE_DHTWINDOW
#include "dht/DhtWindow.h"
#endif
#ifdef USE_BWCTRLWINDOW
#include "bwctrl/BwCtrlWindow.h"
#endif
#define FONT QFont("Arial", 9)
/* Images for toolbar icons */
@ -441,6 +447,9 @@ void MainWindow::createTrayIcon()
#ifdef USE_DHTWINDOW
trayMenu->addAction(QIcon(IMAGE_DHT), tr("DHT Details"), this, SLOT(showDhtWindow()));
#endif
#ifdef USE_BWCTRLWINDOW
trayMenu->addAction(QIcon(IMAGE_DHT), tr("Bandwidth Details"), this, SLOT(showBwCtrlWindow()));
#endif
#ifdef UNFINISHED
trayMenu->addAction(QIcon(IMAGE_UNFINISHED), tr("Applications"), this, SLOT(showApplWindow()));
@ -1206,6 +1215,15 @@ void MainWindow::showDhtWindow()
}
/** Shows Bandwitch Control window */
void MainWindow::showBwCtrlWindow()
{
#ifdef USE_BWCTRLWINDOW
BwCtrlWindow::showYourself();
#endif
}
/** Shows Application window */
#ifdef UNFINISHED
void MainWindow::showApplWindow()

View File

@ -181,6 +181,7 @@ private slots:
void addFriend();
void showMessengerWindow();
void showDhtWindow();
void showBwCtrlWindow();
#ifdef UNFINISHED
void showApplWindow();

View File

@ -0,0 +1,221 @@
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2012 Robert Fernie
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include "BwCtrlWindow.h"
#include "ui_BwCtrlWindow.h"
#include <QTimer>
#include <QDateTime>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <time.h>
#include "retroshare-gui/RsAutoUpdatePage.h"
#include "retroshare/rsconfig.h"
#include "retroshare/rspeers.h"
/********************************************** STATIC WINDOW *************************************/
BwCtrlWindow * BwCtrlWindow::mInstance = NULL;
void BwCtrlWindow::showYourself()
{
if (mInstance == NULL) {
mInstance = new BwCtrlWindow();
}
mInstance->show();
mInstance->activateWindow();
}
BwCtrlWindow* BwCtrlWindow::getInstance()
{
return mInstance;
}
void BwCtrlWindow::releaseInstance()
{
if (mInstance) {
delete mInstance;
}
}
/********************************************** STATIC WINDOW *************************************/
BwCtrlWindow::BwCtrlWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::BwCtrlWindow)
{
ui->setupUi(this);
setAttribute ( Qt::WA_DeleteOnClose, true );
// tick for gui update.
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(1000);
}
BwCtrlWindow::~BwCtrlWindow()
{
delete ui;
mInstance = NULL;
}
void BwCtrlWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void BwCtrlWindow::update()
{
if (!isVisible())
{
#ifdef DEBUG_BWCTRLWINDOW
//std::cerr << "BwCtrlWindow::update() !Visible" << std::endl;
#endif
return;
}
/* do nothing if locked, or not visible */
if (RsAutoUpdatePage::eventsLocked() == true)
{
#ifdef DEBUG_BWCTRLWINDOW
std::cerr << "BwCtrlWindow::update() events Are Locked" << std::endl;
#endif
return;
}
if (!rsConfig)
{
#ifdef DEBUG_BWCTRLWINDOW
std::cerr << "BwCtrlWindow::update rsConfig NOT Set" << std::endl;
#endif
return;
}
RsAutoUpdatePage::lockAllEvents();
//std::cerr << "BwCtrlWindow::update()" << std::endl;
updateBandwidth();
RsAutoUpdatePage::unlockAllEvents() ;
}
void BwCtrlWindow::updateBandwidth()
{
QTreeWidget *peerTreeWidget = ui->bwTreeWidget;
#define PTW_COL_RSNAME 0
#define PTW_COL_PEERID 1
#define PTW_COL_IN_RATE 2
#define PTW_COL_IN_MAX 3
#define PTW_COL_IN_ALLOC 4
#define PTW_COL_IN_ALLOC_SENT 5
#define PTW_COL_OUT_RATE 6
#define PTW_COL_OUT_MAX 7
#define PTW_COL_OUT_ALLOC 8
#define PTW_COL_OUT_ALLOC_SENT 9
peerTreeWidget->clear();
RsConfigDataRates totalRates;
std::map<std::string, RsConfigDataRates> rateMap;
std::map<std::string, RsConfigDataRates>::iterator it;
rsConfig->getTotalBandwidthRates(totalRates);
rsConfig->getAllBandwidthRates(rateMap);
/* insert */
QTreeWidgetItem *item = new QTreeWidgetItem();
peerTreeWidget->addTopLevelItem(item);
/* do Totals */
item -> setData(PTW_COL_PEERID, Qt::DisplayRole, QString("TOTALS"));
item -> setData(PTW_COL_RSNAME, Qt::DisplayRole, QString("Totals"));
item -> setData(PTW_COL_IN_RATE, Qt::DisplayRole, QString::number(totalRates.mRateIn));
item -> setData(PTW_COL_IN_MAX, Qt::DisplayRole, QString::number(totalRates.mRateMaxIn));
item -> setData(PTW_COL_IN_ALLOC, Qt::DisplayRole, QString("N/A"));
item -> setData(PTW_COL_IN_ALLOC_SENT, Qt::DisplayRole, QString("N/A"));
item -> setData(PTW_COL_OUT_RATE, Qt::DisplayRole, QString::number(totalRates.mRateOut));
item -> setData(PTW_COL_OUT_MAX, Qt::DisplayRole, QString::number(totalRates.mRateMaxOut));
item -> setData(PTW_COL_OUT_ALLOC, Qt::DisplayRole, QString("N/A"));
item -> setData(PTW_COL_OUT_ALLOC_SENT, Qt::DisplayRole, QString("N/A"));
time_t now = time(NULL);
for(it = rateMap.begin(); it != rateMap.end(); it++)
{
/* find the entry */
QTreeWidgetItem *peer_item = NULL;
#if 0
QString qpeerid = QString::fromStdString(*it);
int itemCount = peerTreeWidget->topLevelItemCount();
for (int nIndex = 0; nIndex < itemCount; nIndex++)
{
QTreeWidgetItem *tmp_item = peerTreeWidget->topLevelItem(nIndex);
if (tmp_item->data(PTW_COL_PEERID, Qt::DisplayRole).toString() == qpeerid)
{
peer_item = tmp_item;
break;
}
}
#endif
if (!peer_item)
{
/* insert */
peer_item = new QTreeWidgetItem();
peerTreeWidget->addTopLevelItem(peer_item);
}
std::string name = rsPeers->getPeerName(it->first);
peer_item -> setData(PTW_COL_PEERID, Qt::DisplayRole, QString::fromStdString(it->first));
peer_item -> setData(PTW_COL_RSNAME, Qt::DisplayRole, QString::fromStdString(name));
peer_item -> setData(PTW_COL_IN_RATE, Qt::DisplayRole, QString::number(it->second.mRateIn));
peer_item -> setData(PTW_COL_IN_MAX, Qt::DisplayRole, QString::number(it->second.mRateMaxIn));
peer_item -> setData(PTW_COL_IN_ALLOC, Qt::DisplayRole, QString::number(it->second.mAllocIn));
peer_item -> setData(PTW_COL_IN_ALLOC_SENT, Qt::DisplayRole, QString::number(now - it->second.mAllocTs));
peer_item -> setData(PTW_COL_OUT_RATE, Qt::DisplayRole, QString::number(it->second.mRateOut));
peer_item -> setData(PTW_COL_OUT_MAX, Qt::DisplayRole, QString::number(it->second.mRateMaxOut));
peer_item -> setData(PTW_COL_OUT_ALLOC, Qt::DisplayRole, QString::number(it->second.mAllowedOut));
peer_item -> setData(PTW_COL_OUT_ALLOC_SENT, Qt::DisplayRole, QString::number(now - it->second.mAllowedTs));
}
}

View File

@ -0,0 +1,59 @@
#ifndef RSBWCTRL_WINDOW_H
#define RSBWCTRL_WINDOW_H
/****************************************************************
* RetroShare is distributed under the following license:
*
* Copyright (C) 2012 Robert Fernie
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <QMainWindow>
namespace Ui {
class BwCtrlWindow;
}
class BwCtrlWindow : public QMainWindow {
Q_OBJECT
public:
static void showYourself ();
static BwCtrlWindow* getInstance();
static void releaseInstance();
BwCtrlWindow(QWidget *parent = 0);
~BwCtrlWindow();
void updateBandwidth();
public slots:
void update();
protected:
void changeEvent(QEvent *e);
private:
Ui::BwCtrlWindow *ui;
static BwCtrlWindow *mInstance;
};
#endif // RSBWCTRL_WINDOW_H

View File

@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BwCtrlWindow</class>
<widget class="QMainWindow" name="BwCtrlWindow">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>927</width>
<height>777</height>
</rect>
</property>
<property name="windowTitle">
<string>Bandwidth Control WIndow</string>
</property>
<property name="windowIcon">
<iconset resource="../images.qrc">
<normaloff>:/images/dht16.png</normaloff>:/images/dht16.png</iconset>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="bwSummaryLabel">
<property name="text">
<string>BandWidth Measurements</string>
</property>
</widget>
</item>
<item>
<widget class="QTreeWidget" name="bwTreeWidget">
<property name="sortingEnabled">
<bool>true</bool>
</property>
<column>
<property name="text">
<string>ID</string>
</property>
</column>
<column>
<property name="text">
<string>Name</string>
</property>
</column>
<column>
<property name="text">
<string>In (KB/s)</string>
</property>
</column>
<column>
<property name="text">
<string>InMax (KB/s)</string>
</property>
</column>
<column>
<property name="text">
<string>InAllocated (KB/s)</string>
</property>
</column>
<column>
<property name="text">
<string>Allocated Sent</string>
</property>
</column>
<column>
<property name="text">
<string>Out (KB/s)</string>
</property>
</column>
<column>
<property name="text">
<string>OutMax (KB/s)</string>
</property>
</column>
<column>
<property name="text">
<string>OutAllowed (KB/s)</string>
</property>
</column>
<column>
<property name="text">
<string>Allowed Recvd</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>927</width>
<height>23</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>
<include location="../images.qrc"/>
</resources>
<connections/>
</ui>