diff --git a/retroshare-gui/src/gui/RttStatistics.cpp b/retroshare-gui/src/gui/RttStatistics.cpp index 9e36dc52f..148922bff 100644 --- a/retroshare-gui/src/gui/RttStatistics.cpp +++ b/retroshare-gui/src/gui/RttStatistics.cpp @@ -80,6 +80,10 @@ class RttPlot oy+=2+2*celly ; painter->drawRect(ox, oy, PLOT_WIDTH, PLOT_HEIGHT); + + /* We want antialiased lines and text */ + painter->setRenderHint(QPainter::Antialiasing); + painter->setRenderHint(QPainter::TextAntialiasing); if(mInfo.empty()) return ; diff --git a/retroshare-gui/src/gui/dht/DhtWindow.cpp b/retroshare-gui/src/gui/dht/DhtWindow.cpp index 6353ca920..82ad43b12 100644 --- a/retroshare-gui/src/gui/dht/DhtWindow.cpp +++ b/retroshare-gui/src/gui/dht/DhtWindow.cpp @@ -73,6 +73,7 @@ void DhtWindow::updateDisplay() updateNetPeers(); updateDhtPeers(); updateRelays(); + getDHTStatus(); RsAutoUpdatePage::unlockAllEvents() ; } @@ -663,4 +664,42 @@ void DhtWindow::updateDhtPeers() } +void DhtWindow::getDHTStatus() +{ + + RsConfigNetStatus config; + rsConfig->getConfigNetStatus(config); + + if (!(config.DHTActive)) + { + // GRAY. + } + else + { + if (config.netDhtOk) + { +#define MIN_RS_NET_SIZE 10 + // YELLOW or GREEN. + if (config.netDhtRsNetSize < MIN_RS_NET_SIZE) + { + updateGraph(config.netDhtRsNetSize,config.netDhtNetSize); + } + else + { + updateGraph(config.netDhtRsNetSize,config.netDhtNetSize); + } + } + else + { + // RED - some issue. + + } + } +} + +/** Adds new data to the graph. */ +void DhtWindow::updateGraph(qreal rsDHT, qreal allDHT) +{ + ui.frmGraph->addPoints(rsDHT, allDHT); +} diff --git a/retroshare-gui/src/gui/dht/DhtWindow.h b/retroshare-gui/src/gui/dht/DhtWindow.h index 6f9feca82..8a6c819a8 100644 --- a/retroshare-gui/src/gui/dht/DhtWindow.h +++ b/retroshare-gui/src/gui/dht/DhtWindow.h @@ -37,10 +37,13 @@ public: void updateNetPeers(); void updateDhtPeers(); void updateRelays(); + void getDHTStatus(); public slots: virtual void updateDisplay() ; + void updateGraph(qreal rsDHT, qreal allDHT); + protected: //void changeEvent(QEvent *e); diff --git a/retroshare-gui/src/gui/dht/DhtWindow.ui b/retroshare-gui/src/gui/dht/DhtWindow.ui index 88ff851ea..d2f7d9135 100644 --- a/retroshare-gui/src/gui/dht/DhtWindow.ui +++ b/retroshare-gui/src/gui/dht/DhtWindow.ui @@ -7,655 +7,701 @@ 0 0 694 - 478 + 603 DHT - - - - - - - + + + + + 0 + + + + DHT + + + + + + + + + + + 75 + true + + + + Net Status: + + + + + + + Qt::LeftToRight + + + Net Status + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + + + + + 75 + true + + + + Network Mode: + + + + + + + Network Mode + + + + + + + + + + + + 75 + true + + + + Nat Type: + + + + + + + Nat Type + + + + + + + + + + + + 75 + true + + + + Nat Hole: + + + + + + + Nat Hole + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + + 75 + true + + + + Connect Mode: + + + + + + + + 0 + 0 + + + + Qt::LeftToRight + + + Connect Options + + + + + + + + + + + + 75 + true + + + + Peer Address: + + + + + + + + 0 + 0 + + + + Peer Address + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + 75 true - - Net Status: + + DHT + + + + + + + + 75 + true + + + + Unreachable: + + + + + + + + 50 + false + + + + + + + + + + + + + + + + 75 + true + + + + Online: + + + + + + + + 50 + false + + + + + + + + + + + + + + + + 75 + true + + + + Offline: + + + + + + + + 50 + false + + + + + + + + + + + + + + + + 75 + true + + + + Peers: + + + + + + + + 50 + false + + + + + + + + + + - - - - Qt::LeftToRight - - - Net Status - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - - - + + 75 true - - Network Mode: + + Connections + + + + + + + + 75 + true + + + + Disconnected: + + + + + + + + 50 + false + + + + + + + + + + + + + + + + 75 + true + + + + Direct: + + + + + + + + 50 + false + + + + + + + + + + + + + + + + 75 + true + + + + Proxy: + + + + + + + + 50 + false + + + + + + + + + + + + + + + + 75 + true + + + + Relay: + + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + - - - - Network Mode - - - - - - - - - - - - 75 - true - - - - Nat Type: - - - - - - - Nat Type - - - - - - - - - - - - 75 - true - - - - Nat Hole: - - - - - - - Nat Hole - - - - - + + - Qt::Horizontal + Qt::Vertical - - - 40 - 20 - - - - - - - - - - - - - - - - - 75 - true - - - - Connect Mode: - - - - - - - - 0 - 0 - - - - Qt::LeftToRight - - - Connect Options - - - - - - - - - - - - 75 - true - - - - Peer Address: - - - - - - - - 0 - 0 - - - - Peer Address - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - 75 - true - - - - DHT - - - - - - - - - 75 - true - - - - Unreachable: + + + true + + + Name + + + + + PeerId + + + + + DHT Status + + + + + ConnectLogic + + + + + Connect Status + + + + + Connect Mode + + + + + Request Status + + + + + Cb Status + + + + + RsId + + - - - - - - 50 - false - - - - - + + + + + + DHT Details + + + + + + + true + + + + Bucket + + + + + IP:Port + + + + + Key + + + + + Status Flags + + + + + Found + + + + + Last Sent + + + + + Last Recv + + + + + + + + true + + + + Relay Mode + + + + + Source + + + + + Proxy + + + + + Destination + + + + + Class + + + + + Age + + + + + Last Sent + + + + + Bandwidth + + + + + - - - - - - - - - - 75 - true - - - - Online: - - - - - - - - 50 - false - - - - - - - - - - - - - - - - 75 - true - - - - Offline: - - - - - - - - 50 - false - - - - - - - - - - - - - - - - 75 - true - - - - Peers: - - - - - - - - 50 - false - - - - - - - - - - - - - - - - - 75 - true - - - - Connections - - - - - - - - - 75 - true - - - - Disconnected: - - - - - - - - 50 - false - - - - - - - - - - - - - - - - 75 - true - - - - Direct: - - - - - - - - 50 - false - - - - - - - - - - - - - - - - 75 - true - - - - Proxy: - - - - - - - - 50 - false - - - - - - - - - - - - - - - - 75 - true - - - - Relay: - - - - - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - Qt::Vertical - - - - - 0 - - - - - true - - - - Name - - - - - PeerId - - - - - DHT Status - - - - - ConnectLogic - - - - - Connect Status - - - - - Connect Mode - - - - - Request Status - - - - - Cb Status - - - - - RsId - - - - - - - - DHT Details + + + DHT Graph + + + + + + + 120 + 80 + - - - - - - true + + + 10 + + + + Qt::NoContextMenu + + + QFrame::Box + + + QFrame::Plain - - - Bucket - - - - - IP:Port - - - - - Key - - - - - Status Flags - - - - - Found - - - - - Last Sent - - - - - Last Recv - - - - - true - - - - Relay Mode - - - - - Source - - - - - Proxy - - - - - Destination - - - - - Class - - - - - Age - - - - - Last Sent - - - - - Bandwidth - - - + + + DhtGraph + QFrame +
gui/dhtgraph.h
+ 1 +
+
diff --git a/retroshare-gui/src/gui/dhtgraph.cpp b/retroshare-gui/src/gui/dhtgraph.cpp new file mode 100644 index 000000000..69a0678be --- /dev/null +++ b/retroshare-gui/src/gui/dhtgraph.cpp @@ -0,0 +1,298 @@ +/**************************************************************** + * This file is distributed under the following license: + * + * Copyright (C) 2014 RetroShare Team + * Copyright (c) 2006-2007, crypton + * Copyright (c) 2006, Matt Edman, Justin Hipple + * + * 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 + +#include "dhtgraph.h" + + +/** Default contructor */ +DhtGraph::DhtGraph(QWidget *parent) +: QFrame(parent) +{ + /* Create Graph Frame related objects */ + _allDHT = new QList(); + _rsDHT = new QList(); + _painter = new QPainter(); + _graphStyle = AreaGraph; + + /* Initialize graph values */ + _allDHT->prepend(0); + _rsDHT->prepend(0); + _maxPoints = getNumPoints(); + _showRSDHT = true; + _showALLDHT = false; + _maxValue = MINUSER_SCALE; +} + +/** Default destructor */ +DhtGraph::~DhtGraph() +{ + delete _painter; + delete _allDHT; + delete _rsDHT; +} + +/** Gets the width of the desktop, which is the maximum number of points + * we can plot in the graph. */ +int +DhtGraph::getNumPoints() +{ + QDesktopWidget *desktop = QApplication::desktop(); + int width = desktop->width(); + return width; +} + +/** Adds new data points to the graph. */ +void +DhtGraph::addPoints(qreal rsdht, qreal alldht) +{ + /* If maximum number of points plotted, remove oldest */ + if (_rsDHT->size() == _maxPoints) { + _rsDHT->removeLast(); + //_allDHT->removeLast(); + } + + /* Add the points to their respective lists */ + //_allDHT->prepend(alldht); + _rsDHT->prepend(rsdht); + + + /* Check for a new maximum value */ + //if (alldht > _maxValue) _maxValue = alldht; + if (rsdht > _maxValue) _maxValue = rsdht; + + this->update(); +} + +/** Clears the graph. */ +void +DhtGraph::resetGraph() +{ + _allDHT->clear(); + _rsDHT->clear(); + _allDHT->prepend(0); + _rsDHT->prepend(0); + _maxValue = MINUSER_SCALE; + + this->update(); +} + +/** Toggles display of respective graph lines and counters. */ +void +DhtGraph::setShowCounters(bool showRSDHT, bool showALLDHT) +{ + _showRSDHT = showRSDHT; + _showALLDHT = showALLDHT; + this->update(); +} + +/** Overloads default QWidget::paintEvent. Draws the actual + * bandwidth graph. */ +void +DhtGraph::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event); + + /* Set current graph dimensions */ + _rec = this->frameRect(); + + /* Start the painter */ + _painter->begin(this); + + /* We want antialiased lines and text */ + _painter->setRenderHint(QPainter::Antialiasing); + _painter->setRenderHint(QPainter::TextAntialiasing); + + /* Fill in the background */ + _painter->fillRect(_rec, QBrush(BACK_COLOR)); + _painter->drawRect(_rec); + + /* Paint the scale */ + paintScale(); + /* Plot the rsDHT/allDHT data */ + paintData(); + /* Paint the rsDHT/allDHT totals */ + paintTotals(); + + /* Stop the painter */ + _painter->end(); +} + +/** Paints an integral and an outline of that integral for each data set (rsdht + * and/or alldht) that is to be displayed. The integrals will be drawn first, + * followed by the outlines, since we want the area of overlapping integrals + * to blend, but not the outlines of those integrals. */ +void +DhtGraph::paintData() +{ + QVector rsdhtPoints, alldhtPoints; + + /* Convert the bandwidth data points to graph points */ + rsdhtPoints = pointsFromData(_rsDHT); + alldhtPoints = pointsFromData(_allDHT); + + if (_graphStyle == AreaGraph) { + /* Plot the bandwidth data as area graphs */ + if (_showRSDHT) + paintIntegral(rsdhtPoints, RSDHT_COLOR, 0.6); + if (_showALLDHT) + paintIntegral(alldhtPoints, ALLDHT_COLOR, 0.4); + } + + /* Plot the bandwidth as solid lines. If the graph style is currently an + * area graph, we end up outlining the integrals. */ + if (_showRSDHT) + paintLine(rsdhtPoints, RSDHT_COLOR); + if (_showALLDHT) + paintLine(alldhtPoints, ALLDHT_COLOR); +} + +/** Returns a list of points on the bandwidth graph based on the supplied set + * of rsdht or alldht values. */ +QVector +DhtGraph::pointsFromData(QList* list) +{ + QVector points; + int x = _rec.width(); + int y = _rec.height(); + qreal scale = (y - (y/10)) / _maxValue; + qreal currValue; + + /* Translate all data points to points on the graph frame */ + points << QPointF(x, y); + for (int i = 0; i < list->size(); i++) { + currValue = y - (list->at(i) * scale); + if (x - SCROLL_STEP < SCALE_WIDTH) { + points << QPointF(SCALE_WIDTH, currValue); + break; + } + points << QPointF(x, currValue); + x -= SCROLL_STEP; + } + points << QPointF(SCALE_WIDTH, y); + return points; +} + +/** Plots an integral using the data points in points. The area will be + * filled in using color and an alpha-blending level of alpha + * (default is opaque). */ +void +DhtGraph::paintIntegral(QVector points, QColor color, qreal alpha) +{ + /* Save the current brush, plot the integral, and restore the old brush */ + QBrush oldBrush = _painter->brush(); + color.setAlphaF(alpha); + _painter->setBrush(QBrush(color)); + _painter->drawPolygon(points.data(), points.size()); + _painter->setBrush(oldBrush); +} + +/** Iterates the input list and draws a line on the graph in the appropriate + * color. */ +void +DhtGraph::paintLine(QVector points, QColor color, Qt::PenStyle lineStyle) +{ + /* Save the current brush, plot the line, and restore the old brush */ + QPen oldPen = _painter->pen(); + _painter->setPen(QPen(color, lineStyle)); + _painter->drawPolyline(points.data(), points.size()); + _painter->setPen(oldPen); +} + +/** Paints selected total indicators on the graph. */ +void +DhtGraph::paintTotals() +{ + int x = SCALE_WIDTH + FONT_SIZE, y = 0; + int rowHeight = FONT_SIZE; + +#if !defined(Q_WS_MAC) + /* On Mac, we don't need vertical spacing between the text rows. */ + rowHeight += 5; +#endif + + /* If total received is selected */ + if (_showRSDHT) { + y = rowHeight; + _painter->setPen(RSDHT_COLOR); + _painter->drawText(x, y, + tr("RetroShare users in DHT: ")+ + " ("+tr("%1").arg(_rsDHT->first(), 0, 'f', 0)+")"); + } + + /* If total sent is selected */ + if (_showALLDHT) { + y += rowHeight; + _painter->setPen(ALLDHT_COLOR); + _painter->drawText(x, y, + tr("Total DHT users: ") + + " ("+tr("%1").arg(_allDHT->first(), 0, 'f', 0)+")"); + } +} + +/** Returns a formatted string with the correct size suffix. */ +QString +DhtGraph::totalToStr(qreal total) +{ + /* Determine the correct size suffix */ + if (total < 1024) { + /* Use KB suffix */ + return tr("%1 KB").arg(total, 0, 'f', 2); + } else if (total < 1048576) { + /* Use MB suffix */ + return tr("%1 MB").arg(total/1024.0, 0, 'f', 2); + } else { + /* Use GB suffix */ + return tr("%1 GB").arg(total/1048576.0, 0, 'f', 2); + } +} + +/** Paints the scale on the graph. */ +void +DhtGraph::paintScale() +{ + qreal markStep = _maxValue * .25; + int top = _rec.y(); + int bottom = _rec.height(); + qreal paintStep = (bottom - (bottom/10)) / 4; + + /* Draw the other marks in their correctly scaled locations */ + qreal scale; + qreal pos; + for (int i = 1; i < 5; i++) { + pos = bottom - (i * paintStep); + scale = i * markStep; + _painter->setPen(SCALE_COLOR); + _painter->drawText(QPointF(5, pos+FONT_SIZE), + tr("%1 Users").arg(scale, 0, 'f', 0)); + _painter->setPen(GRID_COLOR); + _painter->drawLine(QPointF(SCALE_WIDTH, pos), + QPointF(_rec.width(), pos)); + } + + /* Draw vertical separator */ + _painter->drawLine(SCALE_WIDTH, top, SCALE_WIDTH, bottom); +} + diff --git a/retroshare-gui/src/gui/dhtgraph.h b/retroshare-gui/src/gui/dhtgraph.h new file mode 100644 index 000000000..80f98b4c4 --- /dev/null +++ b/retroshare-gui/src/gui/dhtgraph.h @@ -0,0 +1,120 @@ +/**************************************************************** + * This file is distributed under the following license: + * + * Copyright (C) 2014 RetroShare Team + * Copyright (c) 2006-2007, crypton + * Copyright (c) 2006, Matt Edman, Justin Hipple + * + * 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. + ****************************************************************/ + + +#ifndef _DhtGraph_H +#define _DhtGraph_H + +#include +#include +#include +#include +#include +#include + +#define HOR_SPC 2 /** Space between data points */ +#define SCALE_WIDTH 75 /** Width of the scale */ +#define MINUSER_SCALE 2000 /** 2000 users is the minimum scale */ +#define SCROLL_STEP 4 /** Horizontal change on graph update */ + +#define BACK_COLOR Qt::white +#define SCALE_COLOR Qt::black +#define GRID_COLOR Qt::black +#define RSDHT_COLOR Qt::magenta +#define ALLDHT_COLOR Qt::yellow + +#define FONT_SIZE 11 + + +class DhtGraph : public QFrame +{ + Q_OBJECT + +public: + /** Bandwidth graph style. */ + enum GraphStyle { + SolidLine = 0, /**< Plot bandwidth as solid lines. */ + AreaGraph /**< Plot bandwidth as alpha blended area graphs. */ + }; + + /** Default Constructor */ + DhtGraph(QWidget *parent = 0); + /** Default Destructor */ + ~DhtGraph(); + + /** Add data points. */ + void addPoints(qreal rsDHT, qreal allDHT); + /** Clears the graph. */ + void resetGraph(); + /** Toggles display of data counters. */ + void setShowCounters(bool showRSDHT, bool showALLDHT); + /** Sets the graph style used to display bandwidth data. */ + void setGraphStyle(GraphStyle style) { _graphStyle = style; } + +protected: + /** Overloaded QWidget::paintEvent() */ + void paintEvent(QPaintEvent *event); + +private: + /** Gets the width of the desktop, the max # of points. */ + int getNumPoints(); + + /** Paints an integral and an outline of that integral for each data set + * (rsdht and/or alldht) that is to be displayed. */ + void paintData(); + /** Paints the rsdht/alldht totals. */ + void paintTotals(); + /** Paints the scale in the graph. */ + void paintScale(); + /** Returns a formatted string representation of total. */ + QString totalToStr(qreal total); + /** Returns a list of points on the bandwidth graph based on the supplied set + * of rsdht or alldht values. */ + QVector pointsFromData(QList* list); + /** Paints a line with the data in points. */ + void paintLine(QVector points, QColor color, + Qt::PenStyle lineStyle = Qt::SolidLine); + /** Paints an integral using the supplied data. */ + void paintIntegral(QVector points, QColor color, qreal alpha = 1.0); + + /** Style with which the bandwidth data will be graphed. */ + GraphStyle _graphStyle; + /** A QPainter object that handles drawing the various graph elements. */ + QPainter* _painter; + /** Holds the RSDHT data points. */ + QList *_rsDHT; + /** Holds the ALLDHT data points. */ + QList *_allDHT; + /** The current dimensions of the graph. */ + QRect _rec; + /** The maximum data value plotted. */ + qreal _maxValue; + /** The maximum number of points to store. */ + int _maxPoints; + + /** Show the respective lines and counters. */ + bool _showRSDHT; + bool _showALLDHT; +}; + +#endif diff --git a/retroshare-gui/src/retroshare-gui.pro b/retroshare-gui/src/retroshare-gui.pro index 300c8616d..22f290df3 100644 --- a/retroshare-gui/src/retroshare-gui.pro +++ b/retroshare-gui/src/retroshare-gui.pro @@ -324,6 +324,7 @@ HEADERS += rshare.h \ gui/NetworkDialog.h \ gui/GenCertDialog.h \ gui/graphframe.h \ + gui/dhtgraph.h \ gui/graphframetunnel.h \ gui/linetypes.h \ gui/mainpagestack.h \ @@ -661,6 +662,7 @@ SOURCES += main.cpp \ gui/GenCertDialog.cpp \ gui/NetworkDialog.cpp \ gui/graphframe.cpp \ + gui/dhtgraph.cpp \ gui/graphframetunnel.cpp \ gui/mainpagestack.cpp \ gui/MainWindow.cpp \