summaryrefslogtreecommitdiffstats
path: root/src/knemod/interfacestatisticsdialog.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-17 01:06:58 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-17 01:06:58 +0000
commitccceabd36ed168eefd785fb4fb720a577482fec1 (patch)
tree643927e0ff83170395fa3be8f50c69dae48be1ca /src/knemod/interfacestatisticsdialog.cpp
downloadknemo-ccceabd36ed168eefd785fb4fb720a577482fec1.tar.gz
knemo-ccceabd36ed168eefd785fb4fb720a577482fec1.zip
Added KDE3 version of knemo
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/knemo@1091560 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/knemod/interfacestatisticsdialog.cpp')
-rw-r--r--src/knemod/interfacestatisticsdialog.cpp139
1 files changed, 139 insertions, 0 deletions
diff --git a/src/knemod/interfacestatisticsdialog.cpp b/src/knemod/interfacestatisticsdialog.cpp
new file mode 100644
index 0000000..55ee49a
--- /dev/null
+++ b/src/knemod/interfacestatisticsdialog.cpp
@@ -0,0 +1,139 @@
+/* This file is part of KNemo
+ Copyright (C) 2006 Percy Leonhardt <percy@eris23.de>
+
+ KNemo is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of
+ the License, or (at your option) any later version.
+
+ KNemo 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 Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <qtable.h>
+#include <qdatetime.h>
+#include <qpushbutton.h>
+
+#include <klocale.h>
+#include <kio/global.h>
+#include <kiconloader.h>
+#include <kcalendarsystem.h>
+
+#include "data.h"
+#include "interface.h"
+#include "interfacestatistics.h"
+#include "interfacestatisticsdialog.h"
+
+/*
+ * I assume that the last entry in each table is also the current. This will fail
+ * if we walk back in time, so better not play with the system date...
+ */
+
+InterfaceStatisticsDialog::InterfaceStatisticsDialog( Interface* interface, QWidget* parent, const char* name )
+ : InterfaceStatisticsDlg( parent, name ),
+ mInterface( interface )
+{
+ setIcon( SmallIcon( "knemo" ) );
+ setCaption( interface->getName() + " " + i18n( "Statistics" ) );
+
+ connect( buttonClearDaily, SIGNAL( clicked() ), SIGNAL( clearDailyStatisticsClicked() ) );
+ connect( buttonClearMonthly, SIGNAL( clicked() ), SIGNAL( clearMonthlyStatisticsClicked() ) );
+ connect( buttonClearYearly, SIGNAL( clicked() ), SIGNAL( clearYearlyStatisticsClicked() ) );
+}
+
+InterfaceStatisticsDialog::~InterfaceStatisticsDialog()
+{
+}
+
+void InterfaceStatisticsDialog::updateDays()
+{
+ QPtrList<StatisticEntry> dayStatistics = mInterface->getStatistics()->getDayStatistics();
+ StatisticEntry* iterator = dayStatistics.first();
+ tableDaily->setNumRows( dayStatistics.count() );
+ int row = 0;
+ while ( iterator )
+ {
+ QDate date( iterator->year, iterator->month, iterator->day );
+ tableDaily->verticalHeader()->setLabel( row, KGlobal::locale()->formatDate( date, true ) );
+ tableDaily->setText( row, 0, KIO::convertSize( iterator->txBytes ) );
+ tableDaily->setText( row, 1, KIO::convertSize( iterator->rxBytes ) );
+ tableDaily->setText( row, 2, KIO::convertSize( iterator->rxBytes + iterator->txBytes ) );
+ row++;
+ iterator = dayStatistics.next();
+ }
+
+ tableDaily->setCurrentCell( row - 1, 2 );
+ tableDaily->ensureCellVisible( row - 1, 2 );
+}
+
+void InterfaceStatisticsDialog::updateMonths()
+{
+ QPtrList<StatisticEntry> monthStatistics = mInterface->getStatistics()->getMonthStatistics();
+ StatisticEntry* iterator = monthStatistics.first();
+ tableMonthly->setNumRows( monthStatistics.count() );
+ int row = 0;
+ while ( iterator )
+ {
+ const KCalendarSystem* calendar = KGlobal::locale()->calendar();
+ QString monthName = calendar->monthName( iterator->month, iterator->year ) + " " + QString::number( iterator->year );
+ tableMonthly->verticalHeader()->setLabel( row, monthName );
+ tableMonthly->setText( row, 0, KIO::convertSize( iterator->txBytes ) );
+ tableMonthly->setText( row, 1, KIO::convertSize( iterator->rxBytes ) );
+ tableMonthly->setText( row, 2, KIO::convertSize( iterator->rxBytes + iterator->txBytes ) );
+ row++;
+ iterator = monthStatistics.next();
+ }
+
+ tableMonthly->setCurrentCell( row - 1, 2 );
+ tableMonthly->ensureCellVisible( row - 1, 2 );
+}
+
+void InterfaceStatisticsDialog::updateYears()
+{
+ QPtrList<StatisticEntry> yearStatistics = mInterface->getStatistics()->getYearStatistics();
+ StatisticEntry* iterator = yearStatistics.first();
+ tableYearly->setNumRows( yearStatistics.count() );
+ int row = 0;
+ while ( iterator )
+ {
+ tableYearly->verticalHeader()->setLabel( row, QString::number( iterator->year ) );
+ tableYearly->setText( row, 0, KIO::convertSize( iterator->txBytes ) );
+ tableYearly->setText( row, 1, KIO::convertSize( iterator->rxBytes ) );
+ tableYearly->setText( row, 2, KIO::convertSize( iterator->rxBytes + iterator->txBytes ) );
+ row++;
+ iterator = yearStatistics.next();
+ }
+
+ tableYearly->setCurrentCell( row - 1, 2 );
+ tableYearly->ensureCellVisible( row - 1, 2 );
+}
+
+void InterfaceStatisticsDialog::updateCurrentEntry()
+{
+ int lastRow = tableDaily->numRows() - 1;
+ const StatisticEntry* currentEntry = mInterface->getStatistics()->getCurrentDay();
+ tableDaily->setText( lastRow, 0, KIO::convertSize( currentEntry->txBytes ) );
+ tableDaily->setText( lastRow, 1, KIO::convertSize( currentEntry->rxBytes ) );
+ tableDaily->setText( lastRow, 2, KIO::convertSize( currentEntry->rxBytes + currentEntry->txBytes ) );
+
+ lastRow = tableMonthly->numRows() - 1;
+ currentEntry = mInterface->getStatistics()->getCurrentMonth();
+ tableMonthly->setText( lastRow, 0, KIO::convertSize( currentEntry->txBytes ) );
+ tableMonthly->setText( lastRow, 1, KIO::convertSize( currentEntry->rxBytes ) );
+ tableMonthly->setText( lastRow, 2, KIO::convertSize( currentEntry->rxBytes + currentEntry->txBytes ) );
+
+ lastRow = tableYearly->numRows() - 1;
+ currentEntry = mInterface->getStatistics()->getCurrentYear();
+ tableYearly->setText( lastRow, 0, KIO::convertSize( currentEntry->txBytes ) );
+ tableYearly->setText( lastRow, 1, KIO::convertSize( currentEntry->rxBytes ) );
+ tableYearly->setText( lastRow, 2, KIO::convertSize( currentEntry->rxBytes + currentEntry->txBytes ) );
+}
+
+#include "interfacestatisticsdialog.moc"