KNemo – network interfaces monitor for systray
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

140 lines
5.8 KiB

  1. /* This file is part of KNemo
  2. Copyright (C) 2006 Percy Leonhardt <percy@eris23.de>
  3. KNemo is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU Library General Public License as
  5. published by the Free Software Foundation; either version 2 of
  6. the License, or (at your option) any later version.
  7. KNemo is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public License
  12. along with this library; see the file COPYING.LIB. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  14. Boston, MA 02110-1301, USA.
  15. */
  16. #include <tqtable.h>
  17. #include <tqdatetime.h>
  18. #include <tqpushbutton.h>
  19. #include <tdelocale.h>
  20. #include <tdeio/global.h>
  21. #include <kiconloader.h>
  22. #include <kcalendarsystem.h>
  23. #include "data.h"
  24. #include "interface.h"
  25. #include "interfacestatistics.h"
  26. #include "interfacestatisticsdialog.h"
  27. /*
  28. * I assume that the last entry in each table is also the current. This will fail
  29. * if we walk back in time, so better not play with the system date...
  30. */
  31. InterfaceStatisticsDialog::InterfaceStatisticsDialog( Interface* interface, TQWidget* parent, const char* name )
  32. : InterfaceStatisticsDlg( parent, name ),
  33. mInterface( interface )
  34. {
  35. setIcon( SmallIcon( "knemo" ) );
  36. setCaption( interface->getName() + " " + i18n( "Statistics" ) );
  37. connect( buttonClearDaily, TQT_SIGNAL( clicked() ), TQT_SIGNAL( clearDailyStatisticsClicked() ) );
  38. connect( buttonClearMonthly, TQT_SIGNAL( clicked() ), TQT_SIGNAL( clearMonthlyStatisticsClicked() ) );
  39. connect( buttonClearYearly, TQT_SIGNAL( clicked() ), TQT_SIGNAL( clearYearlyStatisticsClicked() ) );
  40. }
  41. InterfaceStatisticsDialog::~InterfaceStatisticsDialog()
  42. {
  43. }
  44. void InterfaceStatisticsDialog::updateDays()
  45. {
  46. TQPtrList<StatisticEntry> dayStatistics = mInterface->getStatistics()->getDayStatistics();
  47. StatisticEntry* iterator = dayStatistics.first();
  48. tableDaily->setNumRows( dayStatistics.count() );
  49. int row = 0;
  50. while ( iterator )
  51. {
  52. TQDate date( iterator->year, iterator->month, iterator->day );
  53. tableDaily->verticalHeader()->setLabel( row, TDEGlobal::locale()->formatDate( date, true ) );
  54. tableDaily->setText( row, 0, TDEIO::convertSize( iterator->txBytes ) );
  55. tableDaily->setText( row, 1, TDEIO::convertSize( iterator->rxBytes ) );
  56. tableDaily->setText( row, 2, TDEIO::convertSize( iterator->rxBytes + iterator->txBytes ) );
  57. row++;
  58. iterator = dayStatistics.next();
  59. }
  60. tableDaily->setCurrentCell( row - 1, 2 );
  61. tableDaily->ensureCellVisible( row - 1, 2 );
  62. }
  63. void InterfaceStatisticsDialog::updateMonths()
  64. {
  65. TQPtrList<StatisticEntry> monthStatistics = mInterface->getStatistics()->getMonthStatistics();
  66. StatisticEntry* iterator = monthStatistics.first();
  67. tableMonthly->setNumRows( monthStatistics.count() );
  68. int row = 0;
  69. while ( iterator )
  70. {
  71. const KCalendarSystem* calendar = TDEGlobal::locale()->calendar();
  72. TQString monthName = calendar->monthName( iterator->month, iterator->year ) + " " + TQString::number( iterator->year );
  73. tableMonthly->verticalHeader()->setLabel( row, monthName );
  74. tableMonthly->setText( row, 0, TDEIO::convertSize( iterator->txBytes ) );
  75. tableMonthly->setText( row, 1, TDEIO::convertSize( iterator->rxBytes ) );
  76. tableMonthly->setText( row, 2, TDEIO::convertSize( iterator->rxBytes + iterator->txBytes ) );
  77. row++;
  78. iterator = monthStatistics.next();
  79. }
  80. tableMonthly->setCurrentCell( row - 1, 2 );
  81. tableMonthly->ensureCellVisible( row - 1, 2 );
  82. }
  83. void InterfaceStatisticsDialog::updateYears()
  84. {
  85. TQPtrList<StatisticEntry> yearStatistics = mInterface->getStatistics()->getYearStatistics();
  86. StatisticEntry* iterator = yearStatistics.first();
  87. tableYearly->setNumRows( yearStatistics.count() );
  88. int row = 0;
  89. while ( iterator )
  90. {
  91. tableYearly->verticalHeader()->setLabel( row, TQString::number( iterator->year ) );
  92. tableYearly->setText( row, 0, TDEIO::convertSize( iterator->txBytes ) );
  93. tableYearly->setText( row, 1, TDEIO::convertSize( iterator->rxBytes ) );
  94. tableYearly->setText( row, 2, TDEIO::convertSize( iterator->rxBytes + iterator->txBytes ) );
  95. row++;
  96. iterator = yearStatistics.next();
  97. }
  98. tableYearly->setCurrentCell( row - 1, 2 );
  99. tableYearly->ensureCellVisible( row - 1, 2 );
  100. }
  101. void InterfaceStatisticsDialog::updateCurrentEntry()
  102. {
  103. int lastRow = tableDaily->numRows() - 1;
  104. const StatisticEntry* currentEntry = mInterface->getStatistics()->getCurrentDay();
  105. tableDaily->setText( lastRow, 0, TDEIO::convertSize( currentEntry->txBytes ) );
  106. tableDaily->setText( lastRow, 1, TDEIO::convertSize( currentEntry->rxBytes ) );
  107. tableDaily->setText( lastRow, 2, TDEIO::convertSize( currentEntry->rxBytes + currentEntry->txBytes ) );
  108. lastRow = tableMonthly->numRows() - 1;
  109. currentEntry = mInterface->getStatistics()->getCurrentMonth();
  110. tableMonthly->setText( lastRow, 0, TDEIO::convertSize( currentEntry->txBytes ) );
  111. tableMonthly->setText( lastRow, 1, TDEIO::convertSize( currentEntry->rxBytes ) );
  112. tableMonthly->setText( lastRow, 2, TDEIO::convertSize( currentEntry->rxBytes + currentEntry->txBytes ) );
  113. lastRow = tableYearly->numRows() - 1;
  114. currentEntry = mInterface->getStatistics()->getCurrentYear();
  115. tableYearly->setText( lastRow, 0, TDEIO::convertSize( currentEntry->txBytes ) );
  116. tableYearly->setText( lastRow, 1, TDEIO::convertSize( currentEntry->rxBytes ) );
  117. tableYearly->setText( lastRow, 2, TDEIO::convertSize( currentEntry->rxBytes + currentEntry->txBytes ) );
  118. }
  119. #include "interfacestatisticsdialog.moc"