summaryrefslogtreecommitdiffstats
path: root/plugins/stats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/stats')
-rw-r--r--plugins/stats/ChartDrawer.cc473
-rw-r--r--plugins/stats/ChartDrawer.h281
-rw-r--r--plugins/stats/ChartDrawerData.cc100
-rw-r--r--plugins/stats/ChartDrawerData.h123
-rw-r--r--plugins/stats/Makefile.am18
-rw-r--r--plugins/stats/PeerMonitor.cc187
-rw-r--r--plugins/stats/PeerMonitor.h123
-rw-r--r--plugins/stats/StatsCon.cc113
-rw-r--r--plugins/stats/StatsCon.h94
-rw-r--r--plugins/stats/StatsPluginPrefs.cc88
-rw-r--r--plugins/stats/StatsPluginPrefs.h66
-rw-r--r--plugins/stats/StatsPluginPrefsPage.cc29
-rw-r--r--plugins/stats/StatsPluginPrefsPage.h44
-rw-r--r--plugins/stats/StatsSpd.cc138
-rw-r--r--plugins/stats/StatsSpd.h113
-rw-r--r--plugins/stats/ktstatsplugin.desktop24
-rw-r--r--plugins/stats/ktstatsplugin.kcfg60
-rw-r--r--plugins/stats/sprefwgt.ui517
-rw-r--r--plugins/stats/statsconwgt.ui48
-rw-r--r--plugins/stats/statsplugin.cc321
-rw-r--r--plugins/stats/statsplugin.h153
-rw-r--r--plugins/stats/statspluginsettings.kcfgc7
-rw-r--r--plugins/stats/statsspdwgt.ui56
23 files changed, 3176 insertions, 0 deletions
diff --git a/plugins/stats/ChartDrawer.cc b/plugins/stats/ChartDrawer.cc
new file mode 100644
index 0000000..75142e6
--- /dev/null
+++ b/plugins/stats/ChartDrawer.cc
@@ -0,0 +1,473 @@
+/***************************************************************************
+ * Copyright © 2007 by Krzysztof Kundzicz *
+ * athantor@gmail.com *
+ * *
+ * 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., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#include "ChartDrawer.h"
+
+#ifdef USE_SOLARIS
+#include <ieeefp.h>
+int isinf(double x) { return !finite(x) && x==x; }
+#endif
+
+
+namespace kt {
+
+ChartDrawer::ChartDrawer(QWidget *p, wgtsize_t x_max, wgtsize_t y_max, bool autom, const QString & uname) : QWidget(p), mXMax(x_max), mYMax(y_max), mAutoMax(autom),
+ mUnitName(uname), mMMode(MaxModeExact)
+{
+ setBackgroundColor("white");
+}
+
+ChartDrawer::~ChartDrawer()
+{
+ QToolTip::remove(this);
+}
+
+ChartDrawer::wgtsize_t ChartDrawer::GetXMax() const
+{
+ return mXMax;
+}
+
+ChartDrawer::wgtsize_t ChartDrawer::GetYMax() const
+{
+ return mYMax;
+}
+
+void ChartDrawer::SetXMax(const wgtsize_t x)
+{
+ mXMax = x;
+
+ for(size_t i = 0; i < mEls.size(); i++)
+ {
+ mEls[i].pmVals -> resize(x, 0.0);
+ }
+}
+
+void ChartDrawer::SetYMax(const wgtsize_t y)
+{
+ mYMax = y;
+}
+
+inline ChartDrawer::wgtsize_t ChartDrawer::GetYScale() const
+{
+ return height() / 8;
+}
+
+
+inline ChartDrawer::wgtunit_t ChartDrawer::TrY(const ChartDrawer::wgtunit_t y) const
+{
+ return height() - y;
+}
+
+void ChartDrawer::paintEvent ( QPaintEvent *)
+{
+ QPainter pnt( this );
+
+ DrawScale(pnt);
+ DrawFrame(pnt);
+ DrawChart(pnt);
+
+}
+
+inline ChartDrawer::wgtunit_t ChartDrawer::height() const
+{
+ return QWidget::height() - 15;
+}
+
+inline ChartDrawer::wgtunit_t ChartDrawer::width() const
+{
+ return QWidget::width() - 65;
+}
+
+void ChartDrawer::DrawFrame(QPainter & rPnt )
+{
+ QPen op = rPnt.pen();
+ rPnt.setPen(QPen("#000", 3));
+
+ rPnt.drawLine(0, TrY(0), width()+3, TrY(0));
+ rPnt.drawLine(width()+1, TrY(0), width()+1, TrY(QWidget::height()));
+
+ QFont oldf(rPnt.font());
+ QFont newf(oldf);
+ newf.setWeight(QFont::Bold);
+ newf.setPointSize(10);
+ newf.setUnderline(1);
+
+ rPnt.setFont(newf);
+ rPnt.drawText(width() + 30, TrY(-7), mUnitName);
+ rPnt.setFont(oldf);
+
+ rPnt.setPen(op);
+}
+
+void ChartDrawer::DrawScale(QPainter & rPnt )
+{
+
+ if(!mYMax)
+ {
+ return;
+ }
+
+ QPen op = rPnt.pen();
+ QPen ep("#eee", 1, Qt::DashLine);
+ QPen lp("#666", 2, Qt::DotLine);
+ QPen tp("#000");
+
+ rPnt.setPen(ep);
+
+ for(wgtsize_t i = 1; i < width(); i += 10)
+ {
+ rPnt.drawLine(i, TrY(0), i, TrY(height()));
+ }
+
+ for(wgtsize_t i = 0; i < height(); i += 10)
+ {
+ rPnt.drawLine(0, TrY(i), width(), TrY(i));
+ }
+
+ rPnt.setPen(lp);
+ rPnt.drawLine(0, TrY(height() - 10), width(), TrY(height() - 10));
+ rPnt.setPen(tp);
+ rPnt.drawText(width() + 4, TrY(height() - 10) + 4, QString::number (mYMax));
+
+ for(wgtsize_t i = 0; i < height() - 15 ; i += GetYScale())
+ {
+ rPnt.setPen(lp);
+ rPnt.drawLine(0, TrY(i), width(), TrY(i));
+ rPnt.setPen(tp);
+ rPnt.drawText(width() + 4, TrY(i) + 4, QString::number ( (mYMax / 8.0 ) * ( i / static_cast<double>(GetYScale() )), 'f', 1 ) );
+ }
+
+ rPnt.setPen(op);
+}
+
+void ChartDrawer::DrawChart(QPainter & rPnt)
+{
+
+ QPen op = rPnt.pen();
+
+ uint32_t skip_max = 0;
+
+ for(size_t i = 0; i < mEls.size(); i++)
+ {
+ rPnt.setPen( *mEls[i].GetPen() );
+
+ for(size_t j = 1; j < mEls[i].pmVals -> size() - 1; j++)
+ {
+ rPnt.drawLine(
+ FindXScreenCoords(j-1),
+ TrY(FindYScreenCoords(mEls[i].pmVals -> at(j-1))),
+ FindXScreenCoords(j),
+ TrY(FindYScreenCoords(mEls[i].pmVals -> at(j)))
+ );
+ }
+//
+ rPnt.drawLine(
+ FindXScreenCoords(mEls[i].pmVals -> size() - 2),
+ TrY(FindYScreenCoords(mEls[i].pmVals -> at(mEls[i].pmVals -> size() - 2))),
+ width(),
+ TrY(FindYScreenCoords(mEls[i].pmVals -> at(mEls[i].pmVals -> size() - 1)))
+ );
+
+ // --------------------
+ // Line on top
+ // ------------
+ QPen myop(rPnt.pen());
+ QPen topl(myop);
+ topl.setStyle(Qt::DotLine);
+ rPnt.setPen(topl);
+ rPnt.drawLine(0, TrY(FindYScreenCoords(mEls[i].pmVals -> at(mEls[i].pmVals -> size() - 1))), width(), TrY(FindYScreenCoords(mEls[i].pmVals -> at(mEls[i].pmVals -> size() - 1))) );
+ rPnt.setPen(myop);
+
+ QFont oldf(rPnt.font());
+ QFont newf(oldf);
+ newf.setWeight(QFont::Bold);
+ newf.setPointSize(8);
+
+ rPnt.setFont(newf);
+ rPnt.drawText(5 + (i * 50), TrY(FindYScreenCoords(mEls[i].pmVals -> at(mEls[i].pmVals -> size() - 1))) + 11, QString::number (mEls[i].pmVals -> at(mEls[i].pmVals -> size() - 1), 'f', 2 ) );
+
+
+ //------------------
+ // max
+ //------------------
+
+ if(mMarkMax[i])
+ {
+ rPnt.setPen(topl);
+ std::pair<double, size_t> max = mEls[i] . Max();
+
+ rPnt.drawLine(
+ FindXScreenCoords(max.second), TrY(0), FindXScreenCoords(max.second), TrY(height())
+ );
+
+ rPnt.setPen(myop);
+
+ rPnt.setFont(newf);
+ QString maxv(QString::number (max.first, 'f', 2));
+
+ if(FindXScreenCoords(max.second) < 35)
+ {
+ rPnt.drawText(FindXScreenCoords(max.second) + 5, TrY(height() - (10 * (i - skip_max)) ) + 10, maxv ) ;
+ } else {
+ rPnt.drawText(FindXScreenCoords(max.second) - 35 , TrY(height() - (10 * (i - skip_max)) ) + 10, maxv ) ;
+ }
+ } else {
+ skip_max++;
+ }
+
+ rPnt.setFont(oldf);
+ rPnt.setPen(op);
+ }
+
+ rPnt.setPen(op);
+}
+
+inline ChartDrawer::wgtunit_t ChartDrawer::FindXScreenCoords(const double x) const
+{
+ return static_cast<wgtunit_t>((width() / static_cast<double>(mXMax)) * x) ;
+}
+
+inline ChartDrawer::wgtunit_t ChartDrawer::FindYScreenCoords(const double y) const
+{
+ return static_cast<wgtunit_t>(((height()) / static_cast<double>(mYMax)) * y) ;
+}
+
+void ChartDrawer::EnableAutoMax(bool a)
+{
+ mAutoMax = a;
+}
+
+void ChartDrawer::AddValue(const size_t idx, const double val, bool u )
+{
+
+ if( idx >= mEls.size() )
+ {
+ return;
+ }
+
+ ChartDrawerData::val_t::iterator it = mEls[idx].pmVals -> begin();
+
+ while(it != mEls[idx] .pmVals -> end() )
+ {
+ *it = *(it + 1);
+ it++;
+ }
+
+#ifdef USE_SOLARIS
+ if(isnand(val) || (isinf(val)))
+#else
+ if(std::isnan(val) || (std::isinf(val)))
+#endif
+ {
+ *(mEls[idx].pmVals -> end() -1) = 0.0;
+ } else {
+ *(mEls[idx].pmVals -> end() -1) = val;
+ }
+
+ if(mAutoMax)
+ {
+ if( (mMMode == MaxModeTop) && (val > mYMax) )
+ {
+ mYMax = static_cast<wgtsize_t>(val) + 3;
+
+ } else if(mMMode == MaxModeExact) {
+ FindSetMax();
+ }
+ }
+
+ if(u)
+ {
+ update();
+ }
+
+}
+
+void ChartDrawer::AddValues(ChartDrawerData Cdd, const bool max)
+{
+ if(Cdd.pmVals -> size() != mXMax)
+ {
+ Cdd.pmVals -> resize(mXMax, 0.0);
+ }
+
+ mEls.push_back(Cdd);
+ mMarkMax.push_back(max);
+
+ MakeLegendTooltip();
+}
+
+void ChartDrawer::AddValues(ChartDrawerData Cdd, const size_t idx, const bool max)
+{
+ if(Cdd.pmVals -> size() != mXMax)
+ {
+ Cdd.pmVals -> resize(mXMax, 0.0);
+ }
+
+ if(idx >= mEls.size())
+ {
+ mEls.push_back(Cdd);
+ } else {
+ mEls.insert(mEls.begin() + idx, Cdd);
+ }
+
+ if(idx >= mMarkMax.size())
+ {
+ mMarkMax.push_back(max);
+ } else {
+ mMarkMax.insert(mMarkMax.begin() + idx, max);
+ }
+
+ MakeLegendTooltip();
+}
+
+void ChartDrawer::AddValuesCnt(const QString & rN, const bool max)
+{
+ mEls.push_back(ChartDrawerData(mXMax, rN));
+ mMarkMax.push_back(max);
+
+ MakeLegendTooltip();
+}
+
+void ChartDrawer::AddValuesCnt(const QPen & rP, const QString & rN, const bool max)
+{
+ mEls.push_back(ChartDrawerData(rP, mXMax, rN));
+ mMarkMax.push_back(max);
+
+ MakeLegendTooltip();
+}
+
+void ChartDrawer::SetUnitName(const QString & rN)
+{
+ mUnitName = rN;
+}
+
+QString ChartDrawer::GetUnitName() const
+{
+ return mUnitName;
+}
+
+void ChartDrawer::mouseDoubleClickEvent ( QMouseEvent * evt )
+{
+ FindSetMax();
+
+ emit DoubleClicked(evt);
+}
+
+void ChartDrawer::EnableMaxDrawAt(const size_t at, const bool e)
+{
+ if(at >= mMarkMax.size())
+ {
+ return;
+ }
+
+ mMarkMax[at] = e;
+}
+
+void ChartDrawer::RemoveValuesCnt(const size_t idx)
+{
+ if(idx >= mEls.size())
+ {
+ return;
+ }
+
+ mEls.erase(mEls.begin() + idx);
+
+ if(idx <= mMarkMax.size())
+ {
+ mMarkMax.erase(mMarkMax.begin() + idx);
+ }
+
+ MakeLegendTooltip();
+
+}
+
+void ChartDrawer::Zero(const size_t idx)
+{
+ if(idx >= mEls.size())
+ {
+ return;
+ }
+
+ std::fill(mEls[idx].pmVals -> begin(), mEls[idx].pmVals -> end(), 0.0);
+
+ if(mAutoMax)
+ {
+ mYMax = 1;
+ }
+}
+
+void ChartDrawer::MakeLegendTooltip()
+{
+ QToolTip::remove(this);
+
+ QString helpstr(QString("<b>%1:</b><br><br>").arg(i18n("Legend")));
+ QMimeSourceFactory* factory = QMimeSourceFactory::defaultFactory();
+ std::vector<QImage> img;
+
+ for(size_t i = 0; i < mEls.size(); i++)
+ {
+ img.push_back(QImage(16,16, 32));
+ img[i].fill(mEls[i].GetPen() -> color().pixel());
+
+ for(uint8_t px = 0; px < 16; px++)
+ {
+ img[i].setPixel(px, 0, 0); //t
+ img[i].setPixel(0, px, 0); //l
+ img[i].setPixel(px, 15, 0); //b
+ img[i].setPixel(15, px, 0); //r
+ }
+
+ factory->setImage(mEls[i].GetName().replace(' ', '_') + "-" + QString::number(i), img[i]);
+ helpstr += QString("<img src='%1'>&nbsp;&nbsp;-&nbsp;&nbsp;%2<br>").arg(mEls[i].GetName().replace(" ", "_") + "-" + QString::number(i)).arg( mEls[i].GetName() );
+ }
+
+ QToolTip::add(this, helpstr);
+}
+
+void ChartDrawer::FindSetMax()
+{
+ wgtsize_t mymax = 1;
+
+ for(val_t::const_iterator it = mEls.begin(); it != mEls.end(); ++it)
+ {
+ for(ChartDrawerData::val_t::const_iterator subit = it -> pmVals -> begin(); subit != it -> pmVals -> end(); ++subit)
+ {
+ if ( (*subit) > mymax )
+ {
+ mymax = static_cast<wgtsize_t>(*subit) + 3;
+ }
+ }
+ }
+
+ mYMax = mymax;
+}
+
+void ChartDrawer::SetMaxMode(const MaxMode mm)
+{
+ mMMode = mm;
+}
+
+ChartDrawer::MaxMode ChartDrawer::GetMaxMode() const
+{
+ return mMMode;
+}
+
+} //NS end
+
+#include "ChartDrawer.moc"
diff --git a/plugins/stats/ChartDrawer.h b/plugins/stats/ChartDrawer.h
new file mode 100644
index 0000000..741240e
--- /dev/null
+++ b/plugins/stats/ChartDrawer.h
@@ -0,0 +1,281 @@
+/***************************************************************************
+ * Copyright © 2007 by Krzysztof Kundzicz *
+ * athantor@gmail.com *
+ * *
+ * 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., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#ifndef CHARTDRAWER_H_
+#define CHARTDRAWER_H_
+
+#include <qwidget.h>
+#include <qpainter.h>
+#include <qstring.h>
+#include <qtooltip.h>
+#include <qmime.h>
+#include <qimage.h>
+
+#include <klocale.h>
+
+#include <vector>
+#include <cmath>
+#include <algorithm> //fill
+
+#include "ChartDrawerData.h"
+
+namespace kt {
+
+/**
+\brief Widget for drawing line charts
+\author Krzysztof Kundzicz <athantor@gmail.com>
+*/
+class ChartDrawer : public QWidget
+{
+ Q_OBJECT
+
+ public:
+ ///Type used as widget size unit
+ typedef uint32_t wgtsize_t;
+ ///Type used as unit in chart
+ typedef int64_t wgtunit_t;
+ /**
+ \brief Type used for data storing
+ \sa ChartDrawerData
+ */
+ typedef std::vector<ChartDrawerData> val_t;
+ ///Determines max mode
+ enum MaxMode { MaxModeTop, MaxModeExact };
+
+ private:
+ ///Maximum X value
+ wgtsize_t mXMax;
+ ///Maximum Y value
+ wgtsize_t mYMax;
+ ///Auto maximum setting
+ bool mAutoMax;
+ ///Chart data
+ val_t mEls;
+ ///Name of the chart unit
+ QString mUnitName;
+ ///Mark max
+ std::vector<bool> mMarkMax;
+ ///Max mode
+ MaxMode mMMode;
+
+ ///Paint event handler
+ void paintEvent ( QPaintEvent * );
+ /**
+ \brief Draws chart's frame
+ \param rPnt Painter on which things will be drawn
+ */
+ void DrawFrame(QPainter &rPnt);
+ /**
+ \brief Draws chart's scale
+ \param rPnt Painter on which things will be drawn
+ */
+ void DrawScale(QPainter &rPnt);
+ /**
+ \brief Draws chart
+ \param rPnt Painter on which things will be drawn
+ */
+ void DrawChart(QPainter &rPnt);
+
+ /**
+ \brief Gets distance between two values on OY
+ \return Distance
+ */
+ inline wgtsize_t GetYScale() const;
+
+ /**
+ \brief Translates widget Y coord to cartesian
+ \param y Coord
+ \return Coord
+ */
+ inline wgtunit_t TrY(const wgtunit_t y) const;
+ /**
+ \brief Returns charts height
+ \return Height
+
+ Return only height of the chart's inside the frame — not the whole widget's
+ */
+ inline wgtunit_t height() const;
+ /**
+ \brief Returns charts width
+ \return Width
+
+ Return only width of the chart's inside the frame — not the whole widget's
+ */
+ inline wgtunit_t width() const;
+
+ /**
+ \brief Finds screen X coord on the widget
+ \param x Coord
+ \return Screen coord
+ \warning Thera are rounding errors
+ */
+ inline wgtunit_t FindXScreenCoords(const double x) const;
+ /**
+ \brief Finds screen Y coord on the widget
+ \param y Coord
+ \return Screen coord
+ \warning Thera are rounding errors
+ */
+ inline wgtunit_t FindYScreenCoords(const double y) const;
+
+ ///Sets tooltip with legend
+ void MakeLegendTooltip();
+
+ public:
+ /**
+ \brief Widget's constructor
+ \param p Parent
+ \param x_max Maximum X size
+ \param y_max Maximum Y size
+ \param autom Whether athomagically set the maximum Y size
+ \param uname Unit name
+ */
+ ChartDrawer(QWidget *p = 0, wgtsize_t x_max = 2, wgtsize_t y_max = 1, bool autom = true, const QString & uname = "KB/s");
+ ~ChartDrawer();
+
+ /**
+ \brief Gets maximum X
+ \return Maximum X
+ */
+ wgtsize_t GetXMax() const;
+ /**
+ \brief Gets maximum Y
+ \return Maximum Y
+ */
+ wgtsize_t GetYMax() const;
+
+ /**
+ \brief Sets the units name
+ \param rN Name
+
+ \note It'l be drawn on the chart
+ */
+ void SetUnitName(const QString & rN);
+
+ /**
+ \brief Gets unit name
+ \return name
+ */
+ QString GetUnitName() const;
+ /**
+ \brief Doubleclick handler
+ \param evt Mouse event
+ */
+ void mouseDoubleClickEvent ( QMouseEvent * evt );
+
+ /**
+ \brief Gets mode of OY axis maximum drawing
+ \return mode
+ */
+ MaxMode GetMaxMode() const;
+
+
+ public slots:
+ /**
+ \brief Adds value to given dataset
+ \param idx Dataset index
+ \param val Value to add
+ \param update Whether update widget after adding
+ */
+ void AddValue(const size_t idx, const double val, bool update = true);
+ /**
+ \brief Adds dataset
+ \param Cdd Dataset
+ \param max Whether mark maximum of this dataset
+ */
+ void AddValues(ChartDrawerData Cdd, const bool max = true);
+ /**
+ \brief Adds dataset
+ \param Cdd Dataset
+ \param idx Where
+ \param max Whether mark maximum of this dataset
+ */
+ void AddValues(ChartDrawerData Cdd, const size_t idx, const bool max = true);
+ /**
+ \brief Adds empty dataset
+ \param rN Set's data name
+ \param max Whether mark maximum of this dataset
+ */
+ void AddValuesCnt(const QString & rN, const bool max = true);
+ /**
+ \brief Adds empty dataset
+ \param rP Pen that will be used to drawing
+ \param rN Dataset name
+ \param max Whether mark maximum of this dataset
+ */
+ void AddValuesCnt(const QPen & rP, const QString & rN, const bool max = true );
+
+ /**
+ \brief Removes dataset
+ \param idx Dataset index
+ */
+ void RemoveValuesCnt(const size_t idx);
+ /**
+ \brief Zeroes values
+ \param idx Dataset index
+ */
+ void Zero(const size_t idx);
+
+ ///Finds and sets maximum
+ void FindSetMax();
+
+ /**
+ \brief Toggles marking of the maximum Y value on given dataset
+ \param at dataset
+ \param e Toggle?
+ */
+ void EnableMaxDrawAt(const size_t, const bool);
+ /**
+ \brief Toggles automatic max Y scale settin
+ \param a Toggle?
+ */
+ void EnableAutoMax(bool a);
+
+ /**
+ \brief Sets maximum X
+ \param x X size
+ */
+ void SetXMax(const wgtsize_t x);
+ /**
+ \brief Sets maximum Y
+ \param y Y size
+ */
+ void SetYMax(const wgtsize_t x);
+
+ /**
+ \brief Sets mode of max of OY axis
+ \param mm Mode
+ */
+ void SetMaxMode(const MaxMode mm);
+
+
+ signals:
+ /**
+ \brief Emited when widget is doubleclicked
+ \param evt Mouse event
+ */
+ void DoubleClicked(QMouseEvent * evt);
+
+};
+
+}
+
+#endif
+
diff --git a/plugins/stats/ChartDrawerData.cc b/plugins/stats/ChartDrawerData.cc
new file mode 100644
index 0000000..9a49a95
--- /dev/null
+++ b/plugins/stats/ChartDrawerData.cc
@@ -0,0 +1,100 @@
+/***************************************************************************
+ * Copyright © 2007 by Krzysztof Kundzicz *
+ * athantor@gmail.com *
+ * *
+ * 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., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#include "ChartDrawerData.h"
+
+namespace kt {
+
+ChartDrawerData::ChartDrawerData(const QString & rN) : pmQp(new QPen("#000", 1, Qt::SolidLine)), pmVals(new val_t(2, 0.0)), mName(rN)
+{
+}
+
+ChartDrawerData::ChartDrawerData(const size_t s, const QString & rN) : pmQp(new QPen("#000", 1, Qt::SolidLine)), pmVals(new val_t(s, 0.0)), mName(rN)
+{
+}
+
+ChartDrawerData::ChartDrawerData(const QPen & rQp, const QString & rN) : pmQp(new QPen(rQp)), pmVals(new val_t(2, 0.0)), mName(rN)
+{
+}
+
+ChartDrawerData::ChartDrawerData(const QPen & rQp, const size_t s, const QString & rN) : pmQp(new QPen(rQp)), pmVals(new val_t(s, 0.0)), mName(rN)
+{
+}
+
+ChartDrawerData::ChartDrawerData(const ChartDrawerData & rS)
+{
+ pmQp = new QPen(*rS.pmQp);
+ pmVals = new val_t(*rS.pmVals);
+ mName = rS.mName;
+}
+
+ChartDrawerData::~ChartDrawerData()
+{
+ delete pmQp;
+ delete pmVals;
+}
+
+const ChartDrawerData::val_t * ChartDrawerData::GetVals() const
+{
+ return pmVals;
+}
+
+const QPen * ChartDrawerData::GetPen() const
+{
+ return pmQp;
+}
+
+void ChartDrawerData::SetPen(const QPen & rQp)
+{
+ delete pmQp;
+ pmQp = new QPen(rQp);
+}
+
+std::pair<double, size_t> ChartDrawerData::Max() const
+{
+
+ double max = 0.0;
+ size_t cpos = 0;
+ size_t maxpos = 0;
+
+ for(val_t::iterator it = pmVals -> begin(); it != pmVals -> end(); it++)
+ {
+ if(max <= *it)
+ {
+ max = *it;
+ maxpos = cpos;
+ }
+
+ cpos++;
+ }
+
+ return std::make_pair(max, maxpos);
+}
+
+QString ChartDrawerData::GetName() const
+{
+ return mName;
+}
+void ChartDrawerData::SetName( const QString & rN )
+{
+ mName = rN;
+}
+
+} // NS end
diff --git a/plugins/stats/ChartDrawerData.h b/plugins/stats/ChartDrawerData.h
new file mode 100644
index 0000000..561e76a
--- /dev/null
+++ b/plugins/stats/ChartDrawerData.h
@@ -0,0 +1,123 @@
+/***************************************************************************
+ * Copyright © 2007 by Krzysztof Kundzicz *
+ * athantor@gmail.com *
+ * *
+ * 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., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#ifndef CHARTDRAWERDATA_H_
+#define CHARTDRAWERDATA_H_
+
+#include <qpen.h>
+#include <vector>
+#include <map>
+
+namespace kt {
+
+class ChartDrawer;
+
+/**
+\brief Container for data used by ChartDrawer
+\author Krzysztof Kundzicz <athantor@gmail.com>
+*/
+class ChartDrawerData
+{
+ friend class ChartDrawer;
+
+ public:
+ ///Type for stroring values
+ typedef std::vector<double> val_t;
+
+ private:
+ ///Pen used for drawing
+ QPen * pmQp;
+ ///Values
+ val_t * pmVals;
+ ///Name of set
+ QString mName;
+
+ public:
+ /**
+ \brief Constructor
+ \param rN Name
+ */
+ ChartDrawerData(const QString & rN);
+ /**
+ \brief Copy constructor
+ \param rS Source
+ */
+ ChartDrawerData(const ChartDrawerData &);
+ /**
+ \brief Constructor
+ \param s Size
+ \param rN Name
+ */
+ ChartDrawerData(const size_t s, const QString & rN);
+ /**
+ \brief Constructor
+ \param rQp Pen used for drawing
+ \param rN Name
+ */
+ ChartDrawerData(const QPen & rQp, const QString & rN);
+ /**
+ \brief Constructor
+ \param rQp Pen used for drawing
+ \param s Size
+ \param rN Name
+ */
+ ChartDrawerData(const QPen & rQp, const size_t s, const QString & rN);
+
+ ///Destructor
+ ~ChartDrawerData();
+
+ /**
+ \brief Gets values
+ \return Pointer to values container
+ */
+ const val_t * GetVals() const;
+ /**
+ \brief Gets pen
+ \return Pointer pen
+ */
+ const QPen * GetPen() const;
+ /**
+ \brief Gets name
+ \return Name
+ */
+ QString GetName() const;
+
+ /**
+ \brief Sets pen
+ \param rQp Pen
+ */
+ void SetPen(const QPen & rQp);
+ /**
+ \brief Sets name
+ \param rN Name
+ */
+ void SetName( const QString & rN );
+
+ /**
+ \brief Finds maximum value
+ \return Pair with value and position
+ */
+ std::pair<double, size_t> Max() const;
+
+};
+
+}
+
+#endif
diff --git a/plugins/stats/Makefile.am b/plugins/stats/Makefile.am
new file mode 100644
index 0000000..e04f417
--- /dev/null
+++ b/plugins/stats/Makefile.am
@@ -0,0 +1,18 @@
+INCLUDES = -I$(top_builddir)/libktorrent -I$(top_builddir)/ktorrent/libktorrent \
+ -I$(srcdir)/../../libktorrent $(all_includes)
+
+METASOURCES = AUTO
+
+kde_module_LTLIBRARIES = ktstatsplugin.la
+
+ktstatsplugin_la_LDFLAGS = -module $(KDE_PLUGIN) $(LIB_KDECORE) $(LIB_KDEUI) $(LIB_KPARTS) $(all_libraries)
+ktstatsplugin_la_SOURCES = ChartDrawerData.cc ChartDrawer.cc statsspdwgt.ui statsconwgt.ui StatsSpd.cc StatsCon.cc sprefwgt.ui statspluginsettings.kcfgc \
+ StatsPluginPrefsPage.cc StatsPluginPrefs.cc statsplugin.cc
+
+ktstatsplugin_la_LIBADD = $(LIB_QT) ../../libktorrent/libktorrent.la
+
+noinst_HEADERS = ChartDrawerData.h ChartDrawer.h StatsSpd.h StatsCon.h StatsPluginPrefsPage.h StatsPluginPrefs.h statsplugin.h
+
+kde_services_DATA = ktstatsplugin.desktop
+kde_kcfg_DATA = ktstatsplugin.kcfg
+KDE_CXXFLAGS = $(USE_EXCEPTIONS) $(USE_RTTI)
diff --git a/plugins/stats/PeerMonitor.cc b/plugins/stats/PeerMonitor.cc
new file mode 100644
index 0000000..a4cf449
--- /dev/null
+++ b/plugins/stats/PeerMonitor.cc
@@ -0,0 +1,187 @@
+/***************************************************************************
+ * Copyright © 2007 by Krzysztof Kundzicz *
+ * athantor@gmail.com *
+ * *
+ * 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., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#include "PeerMonitor.h"
+
+namespace kt {
+
+PeerMonitor::PeerMonitor(kt::TorrentInterface * pTi, std::map<bt::SHA1Hash, PeerMonitor *> * pM) : kt::MonitorInterface(), QObject(), pmTorIface(pTi), pmPeerMMgr(pM)
+{
+
+}
+
+PeerMonitor::~PeerMonitor()
+{
+}
+
+void PeerMonitor::peerAdded (kt::PeerInterface *peer)
+{
+ QMutexLocker lock(&mtx);
+
+ mPeers.push_back( peer );
+}
+
+void PeerMonitor::peerRemoved (kt::PeerInterface *peer)
+{
+
+ QMutexLocker lock(&mtx);
+
+ data_t::iterator it = std::find(mPeers.begin(), mPeers.end(), peer);
+
+ if(it != mPeers.end())
+ {
+ mPeers.erase(it);
+ // *it = 0;
+ }
+
+}
+
+void PeerMonitor::downloadStarted (kt::ChunkDownloadInterface *)
+{
+
+}
+
+void PeerMonitor::downloadRemoved (kt::ChunkDownloadInterface *)
+{
+
+}
+
+void PeerMonitor::stopped ()
+{
+ QMutexLocker lock(&mtx);
+
+ std::fill(mPeers.begin(), mPeers.end(), static_cast<PeerInterface*>( 0 ) );
+// mPeers.clear();
+}
+
+void PeerMonitor::destroyed ()
+{
+ if(pmPeerMMgr -> find(pmTorIface -> getInfoHash()) != pmPeerMMgr -> end() )
+ {
+ pmTorIface -> setMonitor(0);
+ pmPeerMMgr -> erase(pmTorIface -> getInfoHash());
+ delete this;
+ }
+
+}
+
+double PeerMonitor::LeechersUpSpeed()
+{
+ QMutexLocker lock(&mtx);
+
+ double spd = 0.0;
+
+ //without it'll segfault/SIGABRT on stop as in meantime the iterator from
+ // mPeers will be invalidated
+
+ for( data_t::const_iterator it = mPeers.begin(); it != mPeers.end(); it++)
+ {
+ if((it != mPeers.end()) && *it && ( (*it) -> getStats().perc_of_file < 100.0) )
+ {
+ spd += (*it) -> getStats().download_rate;
+ }
+ }
+
+ return spd;
+}
+
+double PeerMonitor::LeechersDownSpeed()
+{
+ QMutexLocker lock(&mtx);
+
+ double spd = 0.0;
+
+
+ for( data_t::const_iterator it = mPeers.begin(); it != mPeers.end(); it++)
+ {
+ if((it != mPeers.end()) && *it && ( (*it) -> getStats().perc_of_file < 100.0) )
+ {
+ spd += (*it) -> getStats().upload_rate;
+ }
+ }
+
+ return spd;
+
+}
+
+double PeerMonitor::SeedersUpSpeed()
+{
+ QMutexLocker lock(&mtx);
+
+ double spd = 0.0;
+
+
+ for( data_t::const_iterator it = mPeers.begin(); it != mPeers.end(); it++)
+ {
+ if((it != mPeers.end()) && *it && ( (*it) -> getStats().perc_of_file == 100.0) )
+ {
+ spd += (*it) -> getStats().download_rate;
+ }
+
+ }
+
+ return spd;
+
+}
+
+uint64_t PeerMonitor::GetLeechers()
+{
+ QMutexLocker lock(&mtx);
+
+ uint64_t l = 0;
+
+
+ for( data_t::const_iterator it = mPeers.begin(); it != mPeers.end(); it++)
+ {
+ if((it != mPeers.end()) && *it && ( (*it) -> getStats().perc_of_file != 100.0) )
+ {
+ l++;
+ }
+
+ }
+
+ return l;
+}
+
+uint64_t PeerMonitor::GetSeeders()
+{
+ QMutexLocker lock(&mtx);
+
+ uint64_t s = 0;
+
+
+ for( data_t::const_iterator it = mPeers.begin(); it != mPeers.end(); it++)
+ {
+ if((it != mPeers.end()) && *it && ( (*it) -> getStats().perc_of_file == 100) )
+ {
+ s++;
+ }
+
+ }
+
+ return s;
+}
+
+kt::TorrentInterface * PeerMonitor::GetTorIface() const
+{
+ return pmTorIface;
+}
+
+} //NS end
diff --git a/plugins/stats/PeerMonitor.h b/plugins/stats/PeerMonitor.h
new file mode 100644
index 0000000..d1ef4fc
--- /dev/null
+++ b/plugins/stats/PeerMonitor.h
@@ -0,0 +1,123 @@
+/***************************************************************************
+ * Copyright © 2007 by Krzysztof Kundzicz *
+ * athantor@gmail.com *
+ * *
+ * 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., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#ifndef PEERMONITOR_H_
+#define PEERMONITOR_H_
+
+#include <qmutex.h>
+
+#include <interfaces/monitorinterface.h>
+#include <interfaces/peerinterface.h>
+#include <interfaces/torrentinterface.h>
+#include <util/sha1hash.h>
+
+#include <map>
+#include <list>
+#include <algorithm>
+
+namespace kt {
+
+/**
+\brief Monitors peers
+\author Krzysztof Kundzicz <athantor@gmail.com>
+
+Used for peers statistics
+
+\warning Don't use it, as There Can Be Only One™ and the infowidgetplugin relays on it
+*/
+
+class PeerMonitor : public MonitorInterface, public QObject
+{
+ public:
+ ///Type of conteiner of pointers to peers
+ typedef std::list<PeerInterface *> data_t;
+
+ private:
+ /**
+ \brief Mutex
+
+ Used for locking conteiner with pointers to peers
+ */
+ QMutex mtx;
+ ///Container with pointers to peers
+ data_t mPeers;
+ ///Monitored torrent
+ TorrentInterface * pmTorIface;
+ /**
+ \brief Pointer to PeerMonitor „manager”
+
+ \li \c Key: Monitored torrent hash
+ \li \c Value \c type: Pointer to peer monitor
+ */
+ std::map<bt::SHA1Hash, PeerMonitor *> *pmPeerMMgr;
+
+ public:
+ /**
+ \brief Constructor
+ \param pTi Pointer to monitored torrent
+ \param pM Pointer to PeerMonitor „manager”
+ */
+ PeerMonitor(TorrentInterface * pTi, std::map<bt::SHA1Hash, PeerMonitor *> * pM);
+ virtual ~PeerMonitor();
+
+ virtual void peerAdded (PeerInterface *peer);
+ virtual void peerRemoved (PeerInterface *peer);
+ virtual void downloadStarted (ChunkDownloadInterface *cd);
+ virtual void downloadRemoved (ChunkDownloadInterface *cd);
+ virtual void stopped();
+ virtual void destroyed () ;
+
+ /**
+ \brief Gets speed @ which leechers are uploading to us
+ \return Speed
+ */
+ double LeechersUpSpeed() ;
+ /**
+ \brief Gets speed @ which leechers are downloading from us
+ \return Speed
+ */
+ double LeechersDownSpeed();
+ /**
+ \brief Gets speed @ which seeders are uploading to us
+ \return Speed
+ */
+ double SeedersUpSpeed() ;
+ /**
+ \brief Gets leechers count to which we are connected
+ \return Count
+ */
+ uint64_t GetLeechers() ;
+ /**
+ \brief Gets seeders count to which we are connected
+ \return Count
+ */
+ uint64_t GetSeeders() ;
+
+ /**
+ \brief Gets pointer to monitored torrent
+ \return Pointer to monitored torrent
+ */
+ TorrentInterface * GetTorIface() const;
+
+};
+
+}
+
+#endif
diff --git a/plugins/stats/StatsCon.cc b/plugins/stats/StatsCon.cc
new file mode 100644
index 0000000..069ba75
--- /dev/null
+++ b/plugins/stats/StatsCon.cc
@@ -0,0 +1,113 @@
+/***************************************************************************
+ * Copyright © 2007 by Krzysztof Kundzicz *
+ * athantor@gmail.com *
+ * *
+ * 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., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#include "StatsCon.h"
+
+namespace kt {
+
+StatsCon::StatsCon(QWidget * p) : StatsConWgt(p), pmPeersConCht(new ChartDrawer(PeersConGbw, StatsPluginSettings::connectionsMeasurements())),
+ pmDHTCht(new ChartDrawer(DHTGbw, StatsPluginSettings::dHTMeasurements()))
+{
+ PeersConGbw->setColumnLayout(0, Qt::Vertical );
+ PeersConGbw->layout()->setSpacing( 6 );
+ PeersConGbw->layout()->setMargin( 11 );
+
+ pmPeersConLay = new QVBoxLayout(PeersConGbw -> layout());
+
+ DHTGbw->setColumnLayout(0, Qt::Vertical );
+ DHTGbw->layout()->setSpacing( 6 );
+ DHTGbw->layout()->setMargin( 11 );
+
+ pmDHTLay = new QVBoxLayout(DHTGbw -> layout());
+
+ //-------------
+
+ pmPeersConLay -> addWidget(pmPeersConCht);
+ pmDHTLay -> addWidget(pmDHTCht);
+
+ //-----------
+
+ pmPeersConCht -> SetUnitName("n");
+
+ pmPeersConCht -> AddValuesCnt(QPen("#f00"), i18n("Leechers connected"));
+ pmPeersConCht -> AddValuesCnt(QPen("#900"), i18n("Leechers in swarms"));
+ pmPeersConCht -> AddValuesCnt(QPen("#00f"), i18n("Seeders connected"));
+ pmPeersConCht -> AddValuesCnt(QPen("#009"), i18n("Seeders in swarms"));
+ pmPeersConCht -> AddValuesCnt(QPen("#0a0"), i18n("Average connected leechers per torrent"));
+ pmPeersConCht -> AddValuesCnt(QPen("#060"), i18n("Average connected seeders per torrent"));
+ pmPeersConCht -> AddValuesCnt(QPen("#099"), i18n("Average connected leechers per running torrent"));
+ pmPeersConCht -> AddValuesCnt(QPen("#055"), i18n("Average connected seeders per running torrent"));
+
+
+ pmDHTCht -> SetUnitName("n");
+
+ pmDHTCht -> AddValuesCnt(QPen("#f00"), i18n("Nodes"));
+ pmDHTCht -> AddValuesCnt(QPen("#00f"), i18n("Tasks"));
+}
+
+StatsCon::~StatsCon()
+{
+ delete pmPeersConCht;
+ delete pmDHTCht;
+
+ delete pmPeersConLay;
+ delete pmDHTLay;
+}
+
+void StatsCon::AddPeersConVal(const size_t idx, const double val)
+{
+ pmPeersConCht -> AddValue(idx, val , false );
+}
+
+void StatsCon::AddDHTVal(const size_t idx, const double val)
+{
+ pmDHTCht -> AddValue(idx, val, false);
+}
+
+void StatsCon::UpdateCharts()
+{
+ pmPeersConCht -> update();
+ pmDHTCht -> update();
+}
+
+void StatsCon::ZeroPeersConn(const size_t idx)
+{
+ pmPeersConCht -> Zero(idx);
+}
+
+void StatsCon::ChangeConnMsmtCnt(const size_t cnt)
+{
+ pmPeersConCht -> SetXMax(cnt);
+}
+
+void StatsCon::ChangeDHTMsmtCnt(const size_t cnt)
+{
+ pmDHTCht -> SetXMax(cnt);
+}
+
+void StatsCon::ChangeChartsMaxMode(const ChartDrawer::MaxMode mm)
+{
+ pmPeersConCht -> SetMaxMode(mm);
+ pmDHTCht -> SetMaxMode(mm);
+}
+
+} //NS
+
+#include "StatsCon.moc"
diff --git a/plugins/stats/StatsCon.h b/plugins/stats/StatsCon.h
new file mode 100644
index 0000000..9d60048
--- /dev/null
+++ b/plugins/stats/StatsCon.h
@@ -0,0 +1,94 @@
+/***************************************************************************
+ * Copyright © 2007 by Krzysztof Kundzicz *
+ * athantor@gmail.com *
+ * *
+ * 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., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#ifndef STATSCON_H_
+#define STATSCON_H_
+
+#include <qwidget.h>
+#include <qlayout.h>
+#include <qtabwidget.h>
+#include <qgroupbox.h>
+
+#include "statspluginsettings.h"
+#include "statsconwgt.h"
+#include "ChartDrawer.h"
+
+namespace kt {
+
+class StatsCon : public StatsConWgt
+{
+ Q_OBJECT
+ private:
+ ///Layout of peers connections
+ QVBoxLayout * pmPeersConLay;
+ ///Layout of DHT stats
+ QVBoxLayout * pmDHTLay;
+
+ ///Chart widget of peers connted
+ ChartDrawer * pmPeersConCht;
+ ///Chart widget of DHT
+ ChartDrawer * pmDHTCht;
+
+ public:
+ StatsCon(QWidget * p = 0);
+ virtual ~StatsCon();
+ /**
+ \brief Adds value to peers connections chart
+ \param idx Dataset index
+ \param val Value
+ */
+ void AddPeersConVal(const size_t idx, const double val);
+ /**
+ \brief Adds value to DHT chart
+ \param idx Dataset index
+ \param val Value
+ */
+ void AddDHTVal(const size_t idx, const double val);
+
+ /**
+ \brief Zeroes data on given idx @ peers connections chart
+ \param idx Dataset index
+ */
+ void ZeroPeersConn(const size_t idx);
+
+ /**
+ \brief Changes connections chart's measurments count
+ \param cnt Measurements
+ */
+ void ChangeConnMsmtCnt(const size_t cnt);
+ /**
+ \brief Changes DHT chart's measurments count
+ \param cnt Measurements
+ */
+ void ChangeDHTMsmtCnt(const size_t cnt);
+ /**
+ \brief Changes charts OY axis maximum mode
+ \param mm Mode
+ */
+ void ChangeChartsMaxMode(const ChartDrawer::MaxMode mm);
+ public slots:
+ ///Updates charts
+ void UpdateCharts();
+
+};
+
+} // NS
+
+#endif
diff --git a/plugins/stats/StatsPluginPrefs.cc b/plugins/stats/StatsPluginPrefs.cc
new file mode 100644
index 0000000..07cfa23
--- /dev/null
+++ b/plugins/stats/StatsPluginPrefs.cc
@@ -0,0 +1,88 @@
+/***************************************************************************
+ * Copyright © 2007 by Krzysztof Kundzicz *
+ * athantor@gmail.com *
+ * *
+ * 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., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#include "StatsPluginPrefs.h"
+
+namespace kt {
+
+StatsPluginPrefs::StatsPluginPrefs() : PrefPageInterface(i18n("Statistics"), i18n("Statistics options"), KGlobal::iconLoader()->loadIcon("ktimemon",KIcon::NoGroup)), pmUi(0)
+{
+}
+
+StatsPluginPrefs::~StatsPluginPrefs()
+{
+}
+
+bool StatsPluginPrefs::apply ()
+{
+ StatsPluginSettings::setUpdateChartsEveryGuiUpdates(pmUi -> GuiUpdatesSbw -> value());
+ StatsPluginSettings::setGatherDataEveryMs(pmUi -> DataIvalSbw -> value());
+ StatsPluginSettings::setPeersSpeedDataIval(pmUi -> PeersSpdUpdIvalSbw -> value());
+
+ StatsPluginSettings::setPeersSpeed(pmUi -> PeersSpdCbw -> isChecked());
+ StatsPluginSettings::setDrawSeedersInSwarms(pmUi -> ConnSdrInSwaCbw -> isChecked());
+ StatsPluginSettings::setDrawLeechersInSwarms(pmUi -> ConnLchInSwaCbw -> isChecked());
+
+ StatsPluginSettings::setDownloadMeasurements(pmUi -> DownloadMrmtSbw -> value());
+ StatsPluginSettings::setPeersSpeedMeasurements(pmUi -> PeersSpdMrmtSbw -> value());
+ StatsPluginSettings::setUploadMeasurements(pmUi -> UploadMrmtSbw -> value());
+ StatsPluginSettings::setConnectionsMeasurements(pmUi -> ConnsMrmtSbw -> value());
+ StatsPluginSettings::setDHTMeasurements(pmUi -> DHTMrmtSbw -> value());
+ StatsPluginSettings::setMaxSpdMode(pmUi -> MaxSpdModeCbw -> currentItem());
+
+ StatsPluginSettings::writeConfig();
+
+ emit Applied();
+
+ return true;
+}
+
+void StatsPluginPrefs::createWidget (QWidget *parent)
+{
+ pmUi = new StatsPluginPrefsPage(parent);
+}
+
+void StatsPluginPrefs::updateData ()
+{
+ pmUi -> GuiUpdatesSbw -> setValue(StatsPluginSettings::updateChartsEveryGuiUpdates());
+ pmUi -> DataIvalSbw -> setValue(StatsPluginSettings::gatherDataEveryMs());
+ pmUi -> PeersSpdUpdIvalSbw -> setValue(StatsPluginSettings::peersSpeedDataIval());
+
+ pmUi -> PeersSpdCbw -> setChecked(StatsPluginSettings::peersSpeed());
+ pmUi -> ConnSdrInSwaCbw -> setChecked(StatsPluginSettings::drawSeedersInSwarms());
+ pmUi -> ConnLchInSwaCbw -> setChecked(StatsPluginSettings::drawLeechersInSwarms());
+
+ pmUi -> DownloadMrmtSbw -> setValue(StatsPluginSettings::downloadMeasurements());
+ pmUi -> PeersSpdMrmtSbw -> setValue(StatsPluginSettings::peersSpeedMeasurements());
+ pmUi -> UploadMrmtSbw -> setValue(StatsPluginSettings::uploadMeasurements());
+ pmUi -> ConnsMrmtSbw -> setValue(StatsPluginSettings::connectionsMeasurements());
+ pmUi -> DHTMrmtSbw -> setValue(StatsPluginSettings::dHTMeasurements());
+ pmUi -> MaxSpdModeCbw -> setCurrentItem(StatsPluginSettings::maxSpdMode());
+}
+
+void StatsPluginPrefs::deleteWidget ()
+{
+ delete pmUi;
+}
+
+
+} //NS end
+
+#include "StatsPluginPrefs.moc"
diff --git a/plugins/stats/StatsPluginPrefs.h b/plugins/stats/StatsPluginPrefs.h
new file mode 100644
index 0000000..6d563ec
--- /dev/null
+++ b/plugins/stats/StatsPluginPrefs.h
@@ -0,0 +1,66 @@
+/***************************************************************************
+ * Copyright © 2007 by Krzysztof Kundzicz *
+ * athantor@gmail.com *
+ * *
+ * 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., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#ifndef STATSPLUGINPREFS_H_
+#define STATSPLUGINPREFS_H_
+
+#include <qspinbox.h>
+#include <qcheckbox.h>
+#include <qcombobox.h>
+
+#include <klocale.h>
+#include <kglobal.h>
+#include <kiconloader.h>
+
+#include <interfaces/prefpageinterface.h>
+
+#include "StatsPluginPrefsPage.h"
+#include "statspluginsettings.h"
+
+namespace kt {
+
+/**
+\brief Prefs page
+\author Krzysztof Kundzicz <athantor@gmail.com>
+*/
+class StatsPluginPrefs : public QObject, public PrefPageInterface
+{
+ Q_OBJECT
+
+ private:
+ ///Widget
+ StatsPluginPrefsPage *pmUi;
+ public:
+ ///Constructor
+ StatsPluginPrefs();
+ ///Destructor
+ virtual ~StatsPluginPrefs();
+
+ virtual bool apply ();
+ virtual void createWidget (QWidget *parent);
+ virtual void updateData ();
+ virtual void deleteWidget ();
+ signals:
+ void Applied();
+};
+
+}
+
+#endif
diff --git a/plugins/stats/StatsPluginPrefsPage.cc b/plugins/stats/StatsPluginPrefsPage.cc
new file mode 100644
index 0000000..1278127
--- /dev/null
+++ b/plugins/stats/StatsPluginPrefsPage.cc
@@ -0,0 +1,29 @@
+/***************************************************************************
+ * Copyright © 2007 by Krzysztof Kundzicz *
+ * athantor@gmail.com *
+ * *
+ * 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., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#include "StatsPluginPrefsPage.h"
+
+namespace kt {
+
+StatsPluginPrefsPage::StatsPluginPrefsPage(QWidget *p) : sprefwgt(p)
+{
+}
+
+}// NS END
diff --git a/plugins/stats/StatsPluginPrefsPage.h b/plugins/stats/StatsPluginPrefsPage.h
new file mode 100644
index 0000000..59bd9f1
--- /dev/null
+++ b/plugins/stats/StatsPluginPrefsPage.h
@@ -0,0 +1,44 @@
+/***************************************************************************
+ * Copyright © 2007 by Krzysztof Kundzicz *
+ * athantor@gmail.com *
+ * *
+ * 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., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#ifndef STATSPLUGINPREFSPAGE_H_
+#define STATSPLUGINPREFSPAGE_H_
+
+#include "sprefwgt.h"
+
+namespace kt {
+
+/**
+\brief Prefs widget
+\author Krzysztof Kundzicz <athantor@gmail.com>
+*/
+class StatsPluginPrefsPage : public sprefwgt
+{
+ public:
+ /**
+ \brief Constructor
+ \param p Parent
+ */
+ StatsPluginPrefsPage(QWidget * p = 0);
+};
+
+}
+
+#endif
diff --git a/plugins/stats/StatsSpd.cc b/plugins/stats/StatsSpd.cc
new file mode 100644
index 0000000..e4f9d53
--- /dev/null
+++ b/plugins/stats/StatsSpd.cc
@@ -0,0 +1,138 @@
+/***************************************************************************
+ * Copyright © 2007 by Krzysztof Kundzicz *
+ * athantor@gmail.com *
+ * *
+ * 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., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#include "StatsSpd.h"
+
+namespace kt {
+
+StatsSpd::StatsSpd(QWidget *p) : StatsSpdWgt(p),
+ pmDownCht(new ChartDrawer(DownSpeedGbw, StatsPluginSettings::downloadMeasurements())),
+ pmPeersSpdCht(new ChartDrawer(PeersSpdGbw, StatsPluginSettings::peersSpeedMeasurements())),
+ pmUpCht(new ChartDrawer(UpSpeedGbw, StatsPluginSettings::uploadMeasurements()))
+{
+
+ DownSpeedGbw->setColumnLayout(0, Qt::Vertical );
+ DownSpeedGbw->layout()->setSpacing( 6 );
+ DownSpeedGbw->layout()->setMargin( 11 );
+
+ pmDSpdLay = new QVBoxLayout(DownSpeedGbw -> layout());
+
+ UpSpeedGbw->setColumnLayout(0, Qt::Vertical );
+ UpSpeedGbw->layout()->setSpacing( 6 );
+ UpSpeedGbw->layout()->setMargin( 11 );
+
+ pmUSpdLay = new QVBoxLayout(UpSpeedGbw -> layout());
+
+ PeersSpdGbw->setColumnLayout(0, Qt::Vertical );
+ PeersSpdGbw->layout()->setSpacing( 6 );
+ PeersSpdGbw->layout()->setMargin( 11 );
+
+ pmPeersSpdLay = new QVBoxLayout(PeersSpdGbw -> layout());
+
+ //-----------------
+
+ pmUSpdLay -> addWidget(pmUpCht);
+ pmDSpdLay -> addWidget(pmDownCht);
+ pmPeersSpdLay -> addWidget(pmPeersSpdCht);
+
+ // ----------------
+
+ pmUpCht -> AddValuesCnt(QPen("#f00"), i18n("Current"));
+ pmDownCht -> AddValuesCnt(QPen("#f00"), i18n("Current"));
+
+ pmUpCht -> AddValuesCnt(QPen("#00f"), i18n("Average"));
+ pmDownCht -> AddValuesCnt(QPen("#00f"), i18n("Average"));
+
+ pmUpCht -> AddValuesCnt(i18n("Limit"), 0);
+ pmDownCht -> AddValuesCnt(i18n("Limit"), 0);
+
+// pmUpCht -> AddValuesCnt(QPen("#f0f"), i18n("Current torrent"));
+// pmDownCht -> AddValuesCnt(QPen("#f0f"), i18n("Current torrent"));
+//
+
+
+ pmPeersSpdCht -> AddValuesCnt(QPen("#090"), i18n("Average from leecher"));
+ pmPeersSpdCht -> AddValuesCnt(QPen("#f00"), i18n("Average to leecher"));
+ pmPeersSpdCht -> AddValuesCnt(QPen("#00f"), i18n("Average from seeder"));
+ pmPeersSpdCht -> AddValuesCnt(QPen("magenta"), i18n("From leechers"));
+ pmPeersSpdCht -> AddValuesCnt(QPen("orange"), i18n("From seeders"));
+
+}
+
+StatsSpd::~StatsSpd()
+{
+ delete pmUpCht;
+ delete pmDownCht;
+ delete pmPeersSpdCht;
+
+ delete pmUSpdLay;
+ delete pmDSpdLay;
+ delete pmPeersSpdLay;
+
+}
+
+void StatsSpd::AddUpSpdVal(const size_t idx, const double val)
+{
+ pmUpCht -> AddValue(idx, val, false);
+}
+
+void StatsSpd::AddDownSpdVal(const size_t idx, const double val)
+{
+ pmDownCht -> AddValue(idx, val , false);
+}
+
+void StatsSpd::AddPeersSpdVal(const size_t idx, const double val)
+{
+ pmPeersSpdCht -> AddValue(idx, val , false);
+}
+
+void StatsSpd::UpdateCharts()
+{
+ pmUpCht -> update();
+ pmDownCht -> update();
+ pmPeersSpdCht -> update();
+}
+
+void StatsSpd::ChangeDownMsmtCnt(const size_t cnt)
+{
+ pmDownCht -> SetXMax(cnt);
+}
+
+void StatsSpd::ChangePrsSpdMsmtCnt(const size_t cnt)
+{
+ pmPeersSpdCht -> SetXMax(cnt);
+}
+
+void StatsSpd::ChangeUpMsmtCnt(const size_t cnt)
+{
+ pmUpCht -> SetXMax(cnt);
+}
+
+void StatsSpd::ChangeChartsMaxMode(const ChartDrawer::MaxMode mm)
+{
+ pmUpCht -> SetMaxMode(mm);
+ pmDownCht -> SetMaxMode(mm);
+ pmPeersSpdCht -> SetMaxMode(mm);
+}
+
+
+} //NS end
+
+#include "StatsSpd.moc"
diff --git a/plugins/stats/StatsSpd.h b/plugins/stats/StatsSpd.h
new file mode 100644
index 0000000..7ba8d43
--- /dev/null
+++ b/plugins/stats/StatsSpd.h
@@ -0,0 +1,113 @@
+/***************************************************************************
+ * Copyright © 2007 by Krzysztof Kundzicz *
+ * athantor@gmail.com *
+ * *
+ * 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., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#ifndef STATSSPD_H_
+#define STATSSPD_H_
+
+#include <qwidget.h>
+#include <qlayout.h>
+#include <qtabwidget.h>
+#include <qgroupbox.h>
+
+#include "statspluginsettings.h"
+#include "statsspdwgt.h"
+#include "ChartDrawer.h"
+
+namespace kt {
+
+/**
+\brief Main widget of stats plugin
+\author Krzysztof Kundzicz <athantor@gmail.com>
+*/
+class StatsSpd : public StatsSpdWgt
+{
+ Q_OBJECT
+
+ private:
+ ///Layout of upload speed
+ QVBoxLayout * pmUSpdLay;
+ ///Layout of down speed
+ QVBoxLayout * pmDSpdLay;
+ ///Layout of peers speed
+ QVBoxLayout * pmPeersSpdLay;
+
+ ///Chart widget of download speed
+ ChartDrawer * pmDownCht;
+ ///Chart widget of peers speed
+ ChartDrawer * pmPeersSpdCht;
+ ///Chart widget of upload speed
+ ChartDrawer * pmUpCht;
+
+ public:
+ /**
+ \brief Constructor
+ \param p Parent
+ */
+ StatsSpd(QWidget *p = 0);
+ ///Destructor
+ virtual ~StatsSpd();
+
+ /**
+ \brief Adds value to upload speed chart
+ \param idx Dataset index
+ \param val Value
+ **/
+ void AddUpSpdVal(const size_t idx, const double val);
+ /**
+ \brief Adds value to download speed chart
+ \param idx Dataset index
+ \param val Value
+ **/
+ void AddDownSpdVal(const size_t idx, const double val);
+ /**
+ \brief Adds value to peers speed chart
+ \param idx Dataset index
+ \param val Value
+ **/
+ void AddPeersSpdVal(const size_t idx, const double val);
+ /**
+ \brief Changes download chart's measurments count
+ \param cnt Measurements
+ */
+ void ChangeDownMsmtCnt(const size_t cnt);
+ /**
+ \brief Changes peers speed chart's measurments count
+ \param cnt Measurements
+ */
+ void ChangePrsSpdMsmtCnt(const size_t cnt);
+ /**
+ \brief Changes upload chart's measurments count
+ \param cnt Measurements
+ */
+ void ChangeUpMsmtCnt(const size_t cnt);
+ /**
+ \brief Changes charts OY axis maximum mode
+ \param mm Mode
+ */
+ void ChangeChartsMaxMode(const ChartDrawer::MaxMode mm);
+
+ public slots:
+ ///Updates charts
+ void UpdateCharts();
+};
+
+}
+
+#endif
diff --git a/plugins/stats/ktstatsplugin.desktop b/plugins/stats/ktstatsplugin.desktop
new file mode 100644
index 0000000..79e620f
--- /dev/null
+++ b/plugins/stats/ktstatsplugin.desktop
@@ -0,0 +1,24 @@
+[Desktop Entry]
+Type=Service
+Name=StatsPlugin
+Name[bg]=Приставка за статистика
+Name[de]=Statistik-Modul
+Name[es]=Complemento de estadísticas
+Name[et]=Statistikaplugin
+Name[it]=Plugin statistiche
+Name[nds]=Statistik-Moduul
+Name[nl]=Statistiekenplugin
+Name[pl]=Wtyczka statystyk
+Name[pt]='Plugin' de Estatísticas
+Name[pt_BR]=Plugin de Estatísticas
+Name[sr]=Прикључак за статистику
+Name[sr@Latn]=Priključak za statistiku
+Name[sv]=Statistikinsticksprogram
+Name[tr]=Arama Eklentisi
+Name[uk]=Втулок статистики
+Name[xx]=xxStatsPluginxx
+Name[zh_CN]=统计插件
+Comment=
+Comment[xx]=xxxx
+ServiceTypes=KTorrent/Plugin
+X-KDE-Library=ktstatsplugin
diff --git a/plugins/stats/ktstatsplugin.kcfg b/plugins/stats/ktstatsplugin.kcfg
new file mode 100644
index 0000000..43c5dd4
--- /dev/null
+++ b/plugins/stats/ktstatsplugin.kcfg
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
+ http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
+
+ <kcfgfile name="ktinfowidgetpluginrc"/>
+ <group name="general">
+ <entry name="UpdateChartsEveryGuiUpdates" type="UInt">
+ <label>Update charts every</label>
+ <default>4</default>
+ </entry>
+ <entry name="GatherDataEveryMs" type="UInt">
+ <label>Gather data every</label>
+ <default>1000</default>
+ </entry>
+ <entry name="PeersSpeed" type="Bool">
+ <label>Toggle peers speed charts</label>
+ <default>true</default>
+ </entry>
+ <entry name="PeersSpeedDataIval" type="UInt">
+ <label>Interval between getting data about peers speed</label>
+ <default>4</default>
+ </entry>
+ <entry name="DrawLeechersInSwarms" type="Bool">
+ <label>Toggle drawing of leechers in swarms</label>
+ <default>false</default>
+ </entry>
+ <entry name="DrawSeedersInSwarms" type="Bool">
+ <label>Toggle drawing of seeders in swarms</label>
+ <default>false</default>
+ </entry>
+
+ <entry name="DownloadMeasurements" type="UInt">
+ <label>Download mesurments count</label>
+ <default>256</default>
+ </entry>
+ <entry name="PeersSpeedMeasurements" type="UInt">
+ <label>Peers speed mesurments count</label>
+ <default>256</default>
+ </entry>
+ <entry name="UploadMeasurements" type="UInt">
+ <label>Upload mesurments count</label>
+ <default>256</default>
+ </entry>
+ <entry name="ConnectionsMeasurements" type="UInt">
+ <label>Connections mesurments count</label>
+ <default>512</default>
+ </entry>
+ <entry name="DHTMeasurements" type="UInt">
+ <label>DHT mesurments count</label>
+ <default>512</default>
+ </entry>
+
+ <entry name="MaxSpdMode" type="UInt">
+ <label>OY axis max mode</label>
+ <default>1</default>
+ </entry>
+ </group>
+</kcfg>
diff --git a/plugins/stats/sprefwgt.ui b/plugins/stats/sprefwgt.ui
new file mode 100644
index 0000000..7b6674a
--- /dev/null
+++ b/plugins/stats/sprefwgt.ui
@@ -0,0 +1,517 @@
+<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
+<class>sprefwgt</class>
+<widget class="QWidget">
+ <property name="name">
+ <cstring>sprefwgt</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>600</width>
+ <height>480</height>
+ </rect>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <property name="spacing">
+ <number>0</number>
+ </property>
+ <widget class="QGroupBox">
+ <property name="name">
+ <cstring>groupBox1</cstring>
+ </property>
+ <property name="title">
+ <string>Update</string>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLayoutWidget">
+ <property name="name">
+ <cstring>layout2</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>textLabel1</cstring>
+ </property>
+ <property name="text">
+ <string>Update charts every</string>
+ </property>
+ <property name="buddy" stdset="0">
+ <cstring>GuiUpdatesSbw</cstring>
+ </property>
+ </widget>
+ <widget class="QSpinBox">
+ <property name="name">
+ <cstring>GuiUpdatesSbw</cstring>
+ </property>
+ <property name="maxValue">
+ <number>429496729</number>
+ </property>
+ <property name="minValue">
+ <number>1</number>
+ </property>
+ <property name="value">
+ <number>4</number>
+ </property>
+ </widget>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>textLabel2</cstring>
+ </property>
+ <property name="text">
+ <string>GUI updates</string>
+ </property>
+ <property name="buddy" stdset="0">
+ <cstring>GuiUpdatesSbw</cstring>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ <widget class="QLayoutWidget">
+ <property name="name">
+ <cstring>layout4</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>textLabel3</cstring>
+ </property>
+ <property name="text">
+ <string>Gather data every</string>
+ </property>
+ <property name="buddy" stdset="0">
+ <cstring>spinBox2</cstring>
+ </property>
+ </widget>
+ <widget class="QSpinBox">
+ <property name="name">
+ <cstring>DataIvalSbw</cstring>
+ </property>
+ <property name="maxValue">
+ <number>999999999</number>
+ </property>
+ <property name="minValue">
+ <number>1</number>
+ </property>
+ <property name="lineStep">
+ <number>250</number>
+ </property>
+ <property name="value">
+ <number>1000</number>
+ </property>
+ </widget>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>textLabel4</cstring>
+ </property>
+ <property name="text">
+ <string>miliseconds</string>
+ </property>
+ <property name="buddy" stdset="0">
+ <cstring>spinBox2</cstring>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ </vbox>
+ </widget>
+ <widget class="QGroupBox">
+ <property name="name">
+ <cstring>groupBox5</cstring>
+ </property>
+ <property name="title">
+ <string>Maximum</string>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLayoutWidget">
+ <property name="name">
+ <cstring>layout11</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>textLabel1_4</cstring>
+ </property>
+ <property name="text">
+ <string>Maximum speed scale mode:</string>
+ </property>
+ </widget>
+ <widget class="QComboBox">
+ <item>
+ <property name="text">
+ <string>Top</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Exact</string>
+ </property>
+ </item>
+ <property name="name">
+ <cstring>MaxSpdModeCbw</cstring>
+ </property>
+ <property name="currentItem">
+ <number>1</number>
+ </property>
+ <property name="toolTip" stdset="0">
+ <string>See 'What's this' for more help</string>
+ </property>
+ <property name="whatsThis" stdset="0">
+ <string>Set maximum value on OY scale as:
+- Top: Globally achieved maximum speed
+- Exact: Maximum achieved speed visible on chart</string>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ </vbox>
+ </widget>
+ <widget class="QGroupBox">
+ <property name="name">
+ <cstring>groupBox3</cstring>
+ </property>
+ <property name="title">
+ <string>Peers speed</string>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLayoutWidget">
+ <property name="name">
+ <cstring>layout3</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QCheckBox">
+ <property name="name">
+ <cstring>PeersSpdCbw</cstring>
+ </property>
+ <property name="text">
+ <string>Peers speed:</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>textLabel1_2</cstring>
+ </property>
+ <property name="text">
+ <string>update every</string>
+ </property>
+ </widget>
+ <widget class="QSpinBox">
+ <property name="name">
+ <cstring>PeersSpdUpdIvalSbw</cstring>
+ </property>
+ <property name="maxValue">
+ <number>999999999</number>
+ </property>
+ <property name="minValue">
+ <number>1</number>
+ </property>
+ <property name="value">
+ <number>4</number>
+ </property>
+ </widget>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>textLabel2_2</cstring>
+ </property>
+ <property name="text">
+ <string>chart data updates</string>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>textLabel3_2</cstring>
+ </property>
+ <property name="text">
+ <string>Gathering data about many connected peers can be CPU consuming.</string>
+ </property>
+ <property name="alignment">
+ <set>WordBreak|AlignVCenter</set>
+ </property>
+ </widget>
+ </vbox>
+ </widget>
+ <widget class="QGroupBox">
+ <property name="name">
+ <cstring>groupBox11</cstring>
+ </property>
+ <property name="title">
+ <string>Peers connections</string>
+ </property>
+ <property name="toolTip" stdset="0">
+ <string>Large values can obscure charts of connected peers</string>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLayoutWidget">
+ <property name="name">
+ <cstring>layout7</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QCheckBox">
+ <property name="name">
+ <cstring>ConnSdrInSwaCbw</cstring>
+ </property>
+ <property name="text">
+ <string>Show seeders in swarms</string>
+ </property>
+ </widget>
+ <widget class="QCheckBox">
+ <property name="name">
+ <cstring>ConnLchInSwaCbw</cstring>
+ </property>
+ <property name="text">
+ <string>Show leechers in swarms</string>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ </vbox>
+ </widget>
+ <widget class="QGroupBox">
+ <property name="name">
+ <cstring>groupBox8</cstring>
+ </property>
+ <property name="title">
+ <string>Measurements count</string>
+ </property>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLayoutWidget" row="0" column="0">
+ <property name="name">
+ <cstring>layout5</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>textLabel1_3</cstring>
+ </property>
+ <property name="text">
+ <string>Download</string>
+ </property>
+ </widget>
+ <widget class="QSpinBox">
+ <property name="name">
+ <cstring>DownloadMrmtSbw</cstring>
+ </property>
+ <property name="maxValue">
+ <number>999999999</number>
+ </property>
+ <property name="minValue">
+ <number>1</number>
+ </property>
+ <property name="value">
+ <number>256</number>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ <widget class="QLayoutWidget" row="1" column="0">
+ <property name="name">
+ <cstring>layout5_2</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>textLabel1_3_2</cstring>
+ </property>
+ <property name="text">
+ <string>Peers speed</string>
+ </property>
+ </widget>
+ <widget class="QSpinBox">
+ <property name="name">
+ <cstring>PeersSpdMrmtSbw</cstring>
+ </property>
+ <property name="maxValue">
+ <number>999999999</number>
+ </property>
+ <property name="minValue">
+ <number>1</number>
+ </property>
+ <property name="value">
+ <number>256</number>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ <widget class="QLayoutWidget" row="2" column="0">
+ <property name="name">
+ <cstring>layout5_3</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>textLabel1_3_3</cstring>
+ </property>
+ <property name="text">
+ <string>Upload</string>
+ </property>
+ </widget>
+ <widget class="QSpinBox">
+ <property name="name">
+ <cstring>UploadMrmtSbw</cstring>
+ </property>
+ <property name="maxValue">
+ <number>999999999</number>
+ </property>
+ <property name="minValue">
+ <number>1</number>
+ </property>
+ <property name="value">
+ <number>256</number>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ <widget class="QLayoutWidget" row="0" column="1">
+ <property name="name">
+ <cstring>layout5_5</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>textLabel1_3_5</cstring>
+ </property>
+ <property name="text">
+ <string>Connections</string>
+ </property>
+ </widget>
+ <widget class="QSpinBox">
+ <property name="name">
+ <cstring>ConnsMrmtSbw</cstring>
+ </property>
+ <property name="maxValue">
+ <number>999999999</number>
+ </property>
+ <property name="minValue">
+ <number>1</number>
+ </property>
+ <property name="value">
+ <number>512</number>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ <widget class="QLayoutWidget" row="1" column="1">
+ <property name="name">
+ <cstring>layout5_4</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>textLabel1_3_4</cstring>
+ </property>
+ <property name="text">
+ <string>DHT</string>
+ </property>
+ </widget>
+ <widget class="QSpinBox">
+ <property name="name">
+ <cstring>DHTMrmtSbw</cstring>
+ </property>
+ <property name="maxValue">
+ <number>999999999</number>
+ </property>
+ <property name="minValue">
+ <number>1</number>
+ </property>
+ <property name="value">
+ <number>512</number>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ </grid>
+ </widget>
+ <spacer>
+ <property name="name">
+ <cstring>spacer3</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Vertical</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Expanding</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </vbox>
+</widget>
+<connections>
+ <connection>
+ <sender>PeersSpdCbw</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>textLabel2_2</receiver>
+ <slot>setEnabled(bool)</slot>
+ </connection>
+ <connection>
+ <sender>PeersSpdCbw</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>PeersSpdUpdIvalSbw</receiver>
+ <slot>setEnabled(bool)</slot>
+ </connection>
+ <connection>
+ <sender>PeersSpdCbw</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>textLabel1_2</receiver>
+ <slot>setEnabled(bool)</slot>
+ </connection>
+</connections>
+<layoutdefaults spacing="6" margin="11"/>
+</UI>
diff --git a/plugins/stats/statsconwgt.ui b/plugins/stats/statsconwgt.ui
new file mode 100644
index 0000000..07753dc
--- /dev/null
+++ b/plugins/stats/statsconwgt.ui
@@ -0,0 +1,48 @@
+<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
+<class>StatsConWgt</class>
+<widget class="QWidget">
+ <property name="name">
+ <cstring>StatsConWgt</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>600</width>
+ <height>480</height>
+ </rect>
+ </property>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLayoutWidget" row="0" column="0">
+ <property name="name">
+ <cstring>layout3</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QGroupBox">
+ <property name="name">
+ <cstring>PeersConGbw</cstring>
+ </property>
+ <property name="title">
+ <string>Peers</string>
+ </property>
+ </widget>
+ <widget class="QGroupBox">
+ <property name="name">
+ <cstring>DHTGbw</cstring>
+ </property>
+ <property name="title">
+ <string>DHT</string>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ </grid>
+</widget>
+<layoutdefaults spacing="6" margin="11"/>
+</UI>
diff --git a/plugins/stats/statsplugin.cc b/plugins/stats/statsplugin.cc
new file mode 100644
index 0000000..d3d1b03
--- /dev/null
+++ b/plugins/stats/statsplugin.cc
@@ -0,0 +1,321 @@
+/***************************************************************************
+ * Copyright © 2007 by Krzysztof Kundzicz *
+ * athantor@gmail.com *
+ * *
+ * 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., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#include "statsplugin.h"
+
+K_EXPORT_COMPONENT_FACTORY(ktstatsplugin, KGenericFactory<kt::StatsPlugin>("ktstatsplugin"))
+
+namespace kt
+{
+
+StatsPlugin::StatsPlugin(QObject* parent, const char* qt_name, const QStringList& args):
+ Plugin(parent, qt_name, args, "Statistics", i18n("Statistics"),"Krzysztof Kundzicz", "athantor@gmail.com", i18n("Shows transfers statistics"),"ktimemon"), pmUiSpd(0), pmUiCon(0), pmPrefsUi(0), pmUpdTmr(0)
+{
+ mUpAvg = std::make_pair(0.0, 0.0);
+ mDownAvg = std::make_pair(0.0, 0.0);
+ mLeechAvg = std::make_pair(0, 0);
+ mRunningLeechAvg = std::make_pair(0, 0);
+ mSeedAvg = std::make_pair(0, 0);
+ mRunningSeedAvg = std::make_pair(0, 0);
+}
+
+StatsPlugin::~StatsPlugin()
+{
+}
+
+void StatsPlugin::load()
+{
+
+ mUpdCtr = 1;
+ mPeerSpdUpdCtr = 1;
+
+ pmUiSpd = new StatsSpd(dynamic_cast<QWidget *>(parent()));
+ pmUiCon = new StatsCon(dynamic_cast<QWidget *>(parent()));
+ pmPrefsUi = new StatsPluginPrefs();
+ pmUpdTmr = new QTimer(this);
+
+ connect(pmUpdTmr, SIGNAL(timeout () ), this, SLOT(UpdateData()));
+ connect(pmPrefsUi, SIGNAL(Applied()), this, SLOT(RestartTimer()));
+ connect(pmPrefsUi, SIGNAL(Applied()), this, SLOT(TogglePeersSpdCht()));
+ connect(pmPrefsUi, SIGNAL(Applied()), this, SLOT(ToggleLchInSwmDrawing()));
+ connect(pmPrefsUi, SIGNAL(Applied()), this, SLOT(ToggleSdrInSwmDrawing()));
+ connect(pmPrefsUi, SIGNAL(Applied()), this, SLOT(ChangeMsmtsCounts()));
+ connect(pmPrefsUi, SIGNAL(Applied()), this, SLOT(ChangeMaxMode()));
+
+ TogglePeersSpdCht();
+ ChangeMaxMode();
+
+ pmUpdTmr -> start(StatsPluginSettings::gatherDataEveryMs());
+
+ getGUI() -> addToolWidget(pmUiSpd,"ktimemon" ,i18n("Speed statistics"), GUIInterface::DOCK_BOTTOM);
+ getGUI() -> addToolWidget(pmUiCon,"ktimemon" ,i18n("Connection statistics"), GUIInterface::DOCK_BOTTOM);
+ getGUI() -> addPrefPage (pmPrefsUi);
+
+}
+
+void StatsPlugin::unload()
+{
+ getGUI() -> removeToolWidget(pmUiSpd);
+ getGUI() -> removeToolWidget(pmUiCon);
+ getGUI() -> removePrefPage(pmPrefsUi);
+
+ disconnect(pmUpdTmr, SIGNAL(timeout()), this, SLOT(UpdateData()));
+ disconnect(pmPrefsUi, SIGNAL(Applied()), this, SLOT(RestartTimer()));
+ disconnect(pmPrefsUi, SIGNAL(Applied()), this, SLOT(TogglePeersSpdCht()));
+ disconnect(pmPrefsUi, SIGNAL(Applied()), this, SLOT(ToggleLchInSwmDrawing()));
+ disconnect(pmPrefsUi, SIGNAL(Applied()), this, SLOT(ToggleSdrInSwmDrawing()));
+ disconnect(pmPrefsUi, SIGNAL(Applied()), this, SLOT(ChangeMsmtsCounts()));
+ disconnect(pmPrefsUi, SIGNAL(Applied()), this, SLOT(ChangeMaxMode()));
+
+ delete pmUiSpd;
+ delete pmUiCon;
+ delete pmPrefsUi;
+ delete pmUpdTmr;
+}
+
+bool StatsPlugin::versionCheck(const QString& rVer) const
+{
+ return rVer == KT_VERSION_MACRO;
+}
+
+void StatsPlugin::guiUpdate()
+{
+ if(mUpdCtr >= StatsPluginSettings::updateChartsEveryGuiUpdates())
+ {
+ pmUiSpd -> UpdateCharts();
+ pmUiCon -> UpdateCharts();
+ mUpdCtr = 1;
+
+ } else {
+ mUpdCtr++;
+ }
+}
+
+void StatsPlugin::UpdateData()
+{
+ uint32_t lcon = 0;
+ uint32_t lswa = 0;
+ uint32_t scon = 0;
+ uint32_t sswa = 0;
+ uint32_t rlcon = 0;
+ uint32_t rlswa = 0;
+ uint32_t rscon = 0;
+ uint32_t rsswa = 0;
+
+ uint32_t ld = 0;
+ uint32_t lu = 0;
+ uint32_t sd = 0;
+
+ //---------------------------------------
+
+ mDownAvg.first += getCore() -> getStats() . download_speed;
+ mDownAvg.second++;
+
+ mUpAvg.first += getCore() -> getStats() . upload_speed;
+ mUpAvg.second++;
+
+ pmUiSpd -> AddDownSpdVal(0, getCore() -> getStats() . download_speed / 1024.0);
+ pmUiSpd -> AddUpSpdVal(0, getCore() -> getStats() . upload_speed / 1024.0);
+
+ pmUiSpd -> AddDownSpdVal(1, (mDownAvg.first / mDownAvg.second) / 1024.0 );
+ pmUiSpd -> AddUpSpdVal(1, (mUpAvg.first / mUpAvg.second) / 1024.0 );
+
+ pmUiSpd -> AddDownSpdVal(2, getCore() -> getMaxDownloadSpeed () );
+ pmUiSpd -> AddUpSpdVal(2, getCore() -> getMaxUploadSpeed ());
+
+// if(getGUI()-> getCurrentTorrent())
+// {
+// pmUi -> AddDownSpdVal(3, getGUI()-> getCurrentTorrent() -> getStats() . download_rate / 1024.0);
+// pmUi -> AddUpSpdVal(3, getGUI()-> getCurrentTorrent() -> getStats() . upload_rate / 1024.0);
+// } else {
+// pmUi -> AddDownSpdVal(3, 0.0);
+// pmUi -> AddUpSpdVal(3, 0.0);
+// }
+
+ // ------
+
+ bt::QueueManager::iterator tor = getCore() -> getQueueManager () -> begin();
+
+ while(tor != getCore() -> getQueueManager () -> end())
+ {
+ lcon += (*tor) -> getStats().leechers_connected_to;
+ lswa += (*tor) -> getStats().leechers_total;
+ scon += (*tor) -> getStats().seeders_connected_to;
+ sswa += (*tor) -> getStats().seeders_total;
+
+ mLeechAvg.first += lcon;
+ mLeechAvg.second += lswa;
+ mSeedAvg.first += scon;
+ mSeedAvg.second += sswa;
+
+ if(StatsPluginSettings::peersSpeed() && ( mPeerSpdUpdCtr >= StatsPluginSettings::peersSpeedDataIval() ) )
+ {
+ bt::TorrentControl * tc = dynamic_cast<bt::TorrentControl *>( *tor );
+ const bt::PeerManager * pm = tc->getPeerMgr();
+ if(tc && pm)
+ {
+ for(bt::PeerManager::CItr it = pm -> beginPeerList(); it != pm -> endPeerList (); ++it)
+ {
+ if(it && (*it) )
+ {
+ if(!(*it) -> isSeeder())
+ {
+ ld += (*it) -> getDownloadRate();
+ lu += (*it) -> getUploadRate();
+ } else {
+ sd += (*it) -> getDownloadRate();
+ }
+ }
+ }
+ }
+ }
+
+
+ if( (*tor) -> getStats().started)
+ {
+
+ rlcon += (*tor) -> getStats().leechers_connected_to;
+ rlswa += (*tor) -> getStats().leechers_total;
+ rscon += (*tor) -> getStats().seeders_connected_to;
+ rsswa += (*tor) -> getStats().seeders_total;
+
+ mRunningLeechAvg.first += rlcon;
+ mRunningLeechAvg.second += rlswa;
+ mRunningSeedAvg.first += rscon;
+ mRunningSeedAvg.second += rsswa;
+ }
+
+ tor++;
+ }
+
+ // ------
+
+ if(StatsPluginSettings::peersSpeed() )
+ {
+ if( mPeerSpdUpdCtr >= StatsPluginSettings::peersSpeedDataIval() )
+ {
+ pmUiSpd -> AddPeersSpdVal(0, (ld / (lcon * 1.0)) / 1024.0);
+ pmUiSpd -> AddPeersSpdVal(1, (lu / (lcon * 1.0)) / 1024.0);
+ pmUiSpd -> AddPeersSpdVal(2, (sd / (lswa * 1.0)) / 1024.0);
+ pmUiSpd -> AddPeersSpdVal(3, ld / 1024.0);
+ pmUiSpd -> AddPeersSpdVal(4, sd / 1024.0);
+
+ mPeerSpdUpdCtr = 1;
+ } else {
+ mPeerSpdUpdCtr++;
+ }
+ }
+
+ pmUiCon -> AddPeersConVal(0, lcon);
+ if(StatsPluginSettings::drawLeechersInSwarms())
+ {
+ pmUiCon -> AddPeersConVal(1, lswa);
+ }
+ pmUiCon -> AddPeersConVal(2, scon);
+ if(StatsPluginSettings::drawSeedersInSwarms())
+ {
+ pmUiCon -> AddPeersConVal(3, sswa);
+ }
+
+ double cnt = getCore() -> getQueueManager() -> count() * 1.0;
+ double rcnt = getCore() -> getQueueManager() -> getNumRunning() * 1.0;
+
+ pmUiCon -> AddPeersConVal(4, lcon / cnt );
+ pmUiCon -> AddPeersConVal(5, scon / cnt );
+ pmUiCon -> AddPeersConVal(6, lcon / rcnt);
+ pmUiCon -> AddPeersConVal(7, scon / rcnt );
+
+ // -----
+
+ if( bt::Globals::instance().getDHT().isRunning() )
+ {
+ pmUiCon -> AddDHTVal(0, bt::Globals::instance().getDHT(). getStats().num_peers);
+ pmUiCon -> AddDHTVal(1, bt::Globals::instance().getDHT(). getStats().num_tasks);
+ }
+}
+
+void StatsPlugin::RestartTimer()
+{
+ if( (!pmUpdTmr) || (!pmUpdTmr -> isActive()))
+ {
+ return;
+ }
+
+ pmUpdTmr -> stop();
+ pmUpdTmr -> start(StatsPluginSettings::gatherDataEveryMs());
+}
+
+void StatsPlugin::TogglePeersSpdCht()
+{
+ if(StatsPluginSettings::peersSpeed())
+ {
+ if(pmUiSpd -> PeersSpdGbw -> isHidden())
+ {
+ pmUiSpd -> PeersSpdGbw -> setHidden(false);
+ }
+ } else {
+ if(!pmUiSpd -> PeersSpdGbw -> isHidden())
+ {
+ pmUiSpd -> PeersSpdGbw -> setHidden(true);
+ }
+ }
+}
+
+void StatsPlugin::ToggleLchInSwmDrawing()
+{
+ if(!StatsPluginSettings::drawLeechersInSwarms())
+ {
+ pmUiCon -> ZeroPeersConn(1);
+ }
+}
+
+void StatsPlugin::ToggleSdrInSwmDrawing()
+{
+ if(!StatsPluginSettings::drawSeedersInSwarms())
+ {
+ pmUiCon -> ZeroPeersConn(3);
+ }
+}
+
+void StatsPlugin::ChangeMsmtsCounts()
+{
+ pmUiSpd -> ChangeDownMsmtCnt(StatsPluginSettings::downloadMeasurements());
+ pmUiSpd -> ChangePrsSpdMsmtCnt(StatsPluginSettings::peersSpeedMeasurements());
+ pmUiSpd -> ChangeUpMsmtCnt(StatsPluginSettings::uploadMeasurements());
+ pmUiCon -> ChangeConnMsmtCnt(StatsPluginSettings::connectionsMeasurements());
+ pmUiCon -> ChangeDHTMsmtCnt(StatsPluginSettings::dHTMeasurements());
+}
+
+void StatsPlugin::ChangeMaxMode()
+{
+ if(StatsPluginSettings::maxSpdMode() == 0)
+ {
+ pmUiSpd -> ChangeChartsMaxMode(ChartDrawer::MaxModeTop);
+ pmUiCon -> ChangeChartsMaxMode(ChartDrawer::MaxModeTop);
+
+ } else if (StatsPluginSettings::maxSpdMode() == 1) {
+ pmUiSpd -> ChangeChartsMaxMode(ChartDrawer::MaxModeExact);
+ pmUiCon -> ChangeChartsMaxMode(ChartDrawer::MaxModeExact);
+ }
+}
+
+} // NS end
+
+#include "statsplugin.moc"
diff --git a/plugins/stats/statsplugin.h b/plugins/stats/statsplugin.h
new file mode 100644
index 0000000..14f1fcd
--- /dev/null
+++ b/plugins/stats/statsplugin.h
@@ -0,0 +1,153 @@
+/***************************************************************************
+ * Copyright © 2007 by Krzysztof Kundzicz *
+ * athantor@gmail.com *
+ * *
+ * 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., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#ifndef StatsPlugin_H_
+#define StatsPlugin_H_
+
+#include <kgenericfactory.h>
+
+#include <qwidget.h>
+#include <qtimer.h>
+
+#include <interfaces/plugin.h>
+#include <interfaces/guiinterface.h>
+#include <interfaces/coreinterface.h>
+#include <torrent/globals.h>
+#include <kademlia/dhtbase.h>
+#include <torrent/queuemanager.h>
+#include <torrent/torrentcontrol.h>
+#include <torrent/peermanager.h>
+#include <torrent/peer.h>
+
+#include "StatsSpd.h"
+#include "StatsCon.h"
+#include "StatsPluginPrefs.h"
+#include "statspluginsettings.h"
+#include <map> // std::pair
+
+namespace kt {
+
+/**
+\brief Statistics plugin
+\author Krzysztof Kundzicz <athantor@gmail.com>
+\version 200705191548
+*/
+class StatsPlugin : public Plugin
+{
+ Q_OBJECT
+
+ private:
+ ///Speed UI of the plugin
+ StatsSpd * pmUiSpd;
+ ///Connections UI of the plugin
+ StatsCon * pmUiCon;
+ ///UI of the pref page
+ StatsPluginPrefs * pmPrefsUi;
+ /**
+ \brief Average upload speed data
+
+ \li \c first: Total speed
+ \li \c second: Measurements count
+ */
+ std::pair<long double, long double> mUpAvg;
+ /**
+ \brief Average download speed data
+
+ \li \c first: Total speed
+ \li \c second: Measurements count
+ */
+ std::pair<long double, long double> mDownAvg;
+ /**
+ \brief Leechers stats
+
+ \li \c first: connected
+ \li \c second: swarm
+ */
+ std::pair<uint32_t, uint32_t> mLeechAvg;
+ /**
+ \brief Leechers stats on running torrents
+
+ \li \c first: connected
+ \li \c second: swarm
+ */
+ std::pair<uint32_t, uint32_t> mRunningLeechAvg;
+ /**
+ \brief Seeders stats
+
+ \li \c first: connected
+ \li \c second: swarm
+ */
+ std::pair<uint32_t, uint32_t> mSeedAvg;
+ /**
+ \brief Seeders stats on running torrents
+
+ \li \c first: connected
+ \li \c second: swarm
+ */
+ std::pair<uint32_t, uint32_t> mRunningSeedAvg;
+
+ ///Data update timer
+ QTimer * pmUpdTmr;
+
+ ///Update ctr
+ uint32_t mUpdCtr;
+ uint32_t mPeerSpdUpdCtr;
+
+ private slots:
+ ///Updates stat data
+ void UpdateData();
+ /**
+ \brief Restarts timer
+
+ Restarts timer when the interval of data gathering has been changed
+ */
+ void RestartTimer();
+ ///Toggles peers speed chart
+ void TogglePeersSpdCht();
+ ///Toggles drawing of total leechers in swarms
+ void ToggleLchInSwmDrawing();
+ ///Toggles drawing of total seeders in swarms
+ void ToggleSdrInSwmDrawing();
+ ///Changes measurements counts
+ void ChangeMsmtsCounts();
+ ///Changes OY max mode
+ void ChangeMaxMode();
+
+ public:
+ /**
+ \brief Constructor
+ \param parent Parent
+ \param qt_name
+ \param args
+ */
+ StatsPlugin(QObject* parent, const char* qt_name, const QStringList& args);
+ ///Destructor
+ virtual ~StatsPlugin();
+
+ virtual void load();
+ virtual void unload();
+ virtual bool versionCheck(const QString&) const;
+ virtual void guiUpdate();
+};
+
+}
+
+#endif
+
diff --git a/plugins/stats/statspluginsettings.kcfgc b/plugins/stats/statspluginsettings.kcfgc
new file mode 100644
index 0000000..d809d30
--- /dev/null
+++ b/plugins/stats/statspluginsettings.kcfgc
@@ -0,0 +1,7 @@
+# Code generation options for kconfig_compiler
+File=ktstatsplugin.kcfg
+ClassName=StatsPluginSettings
+Namespace=kt
+Singleton=true
+Mutators=true
+# will create the necessary code for setting those variables
diff --git a/plugins/stats/statsspdwgt.ui b/plugins/stats/statsspdwgt.ui
new file mode 100644
index 0000000..162bf9c
--- /dev/null
+++ b/plugins/stats/statsspdwgt.ui
@@ -0,0 +1,56 @@
+<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
+<class>StatsSpdWgt</class>
+<widget class="QWidget">
+ <property name="name">
+ <cstring>StatsSpdWgt</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>600</width>
+ <height>480</height>
+ </rect>
+ </property>
+ <grid>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLayoutWidget" row="0" column="0">
+ <property name="name">
+ <cstring>layout5</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QGroupBox">
+ <property name="name">
+ <cstring>DownSpeedGbw</cstring>
+ </property>
+ <property name="title">
+ <string>Download</string>
+ </property>
+ </widget>
+ <widget class="QGroupBox">
+ <property name="name">
+ <cstring>PeersSpdGbw</cstring>
+ </property>
+ <property name="title">
+ <string>Peers</string>
+ </property>
+ </widget>
+ <widget class="QGroupBox">
+ <property name="name">
+ <cstring>UpSpeedGbw</cstring>
+ </property>
+ <property name="title">
+ <string>Upload</string>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ </grid>
+</widget>
+<layoutdefaults spacing="6" margin="11"/>
+</UI>