diff --git a/src/kcm/configdialog.cpp b/src/kcm/configdialog.cpp index c2028f8..027a4e3 100644 --- a/src/kcm/configdialog.cpp +++ b/src/kcm/configdialog.cpp @@ -1,1812 +1,1813 @@ /* This file is part of KNemo Copyright (C) 2004, 2006 Percy Leonhardt Copyright (C) 2009, 2010 John Stamp 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 #include #include #include #include #include +#include #include #include #include #include #include #include #include #include "ui_configdlg.h" #include "config-knemo.h" #include "configdialog.h" #include "statsconfig.h" #include "warnconfig.h" #include "themeconfig.h" #include "utils.h" #include #include #include #include #ifdef __linux__ #include #include #include #endif K_PLUGIN_FACTORY(KNemoFactory, registerPlugin("knemo");) K_EXPORT_PLUGIN(KNemoFactory("kcm_knemo")) Q_DECLARE_METATYPE( KNemoTheme ) Q_DECLARE_METATYPE( StatsRule ) Q_DECLARE_METATYPE( WarnRule ) static bool themesLessThan( const KNemoTheme& s1, const KNemoTheme& s2 ) { if ( s1.name < s2.name ) return true; else return false; } static QString periodText( int c, int u ) { QString units; switch ( u ) { case KNemoStats::Hour: units = i18np( "%1 hour", "%1 hours", c ); break; case KNemoStats::Day: units = i18np( "%1 day", "%1 days", c ); break; case KNemoStats::Week: units = i18np( "%1 week", "%1 weeks", c ); break; case KNemoStats::Month: units = i18np( "%1 month", "%1 months", c ); break; case KNemoStats::BillPeriod: units = i18np( "%1 billing period", "%1 billing periods", c ); break; case KNemoStats::Year: units = i18np( "%1 year", "%1 years", c ); break; default: units = i18n( "Invalid period" ); ;; } return units; } void StatsRuleModel::setCalendar( const KCalendarSystem *cal ) { mCalendar = cal; } QString StatsRuleModel::dateText( const StatsRule &s ) { QString dateStr = mCalendar->formatDate( s.startDate, KLocale::LongDate ); if ( !mCalendar->isValid( s.startDate ) ) dateStr = i18n( "Invalid Date" ); return dateStr; } QList StatsRuleModel::getRules() { QList statsRules; for ( int i = 0; i < rowCount(); ++i ) { statsRules << item( i, 0 )->data( Qt::UserRole ).value(); } return statsRules; } QModelIndex StatsRuleModel::addRule( const StatsRule &s ) { QList items; QStandardItem *item = new QStandardItem( dateText( s ) ); QVariant v; v.setValue( s ); item->setData( v, Qt::UserRole ); item->setData( s.startDate, Qt::UserRole + 1 ); items << item; item = new QStandardItem( periodText( s.periodCount, s.periodUnits ) ); items << item; appendRow( items ); return indexFromItem (items[0] ); } void StatsRuleModel::modifyRule( const QModelIndex &index, const StatsRule &s ) { QVariant v; v.setValue( s ); item( index.row(), 0 )->setData( v, Qt::UserRole ); item( index.row(), 0 )->setData( s.startDate, Qt::UserRole + 1 ); item( index.row(), 0 )->setData( dateText( s ), Qt::DisplayRole ); item( index.row(), 1 )->setData( periodText( s.periodCount, s.periodUnits ), Qt::DisplayRole ); } QString WarnModel::ruleText( const WarnRule &warn ) { QString warnText; quint64 siz = warn.threshold * pow( 1024, warn.trafficUnits ); switch ( warn.trafficDirection ) { case KNemoStats::TrafficIn: if ( warn.trafficType == KNemoStats::Peak ) warnText = i18n( "peak incoming traffic > %1" ).arg( KIO::convertSize( siz ) ); else if ( warn.trafficType == KNemoStats::Offpeak ) warnText = i18n( "off-peak incoming traffic > %1" ).arg( KIO::convertSize( siz ) ); else warnText = i18n( "incoming traffic > %1" ).arg( KIO::convertSize( siz ) ); break; case KNemoStats::TrafficOut: if ( warn.trafficType == KNemoStats::Peak ) warnText = i18n( "peak outgoing traffic > %1" ).arg( KIO::convertSize( siz ) ); else if ( warn.trafficType == KNemoStats::Offpeak ) warnText = i18n( "off-peak outgoing traffic > %1" ).arg( KIO::convertSize( siz ) ); else warnText = i18n( "outgoing traffic > %1" ).arg( KIO::convertSize( siz ) ); break; case KNemoStats::TrafficTotal: if ( warn.trafficType == KNemoStats::Peak ) warnText = i18n( "peak incoming and outgoing traffic > %1" ).arg( KIO::convertSize( siz ) ); else if ( warn.trafficType == KNemoStats::Offpeak ) warnText = i18n( "off-peak incoming and outgoing traffic > %1" ).arg( KIO::convertSize( siz ) ); else warnText = i18n( "incoming and outgoing traffic > %1" ).arg( KIO::convertSize( siz ) ); } return warnText; } QList WarnModel::getRules() { QList warnRules; for ( int i = 0; i < rowCount(); ++i ) { warnRules << item( i, 0 )->data( Qt::UserRole ).value(); } return warnRules; } QModelIndex WarnModel::addWarn( const WarnRule &warn ) { QList items; QStandardItem *item = new QStandardItem( ruleText( warn ) ); QVariant v; v.setValue( warn ); item->setData( v, Qt::UserRole ); items << item; item = new QStandardItem( periodText( warn.periodCount, warn.periodUnits ) ); items << item; appendRow( items ); return indexFromItem( items[0] ); } void WarnModel::modifyWarn( const QModelIndex &index, const WarnRule &warn ) { QVariant v; v.setValue( warn ); item( index.row(), 0 )->setData( v, Qt::UserRole ); item( index.row(), 0 )->setData( ruleText( warn ), Qt::DisplayRole ); item( index.row(), 1 )->setData( periodText( warn.periodCount, warn.periodUnits ), Qt::DisplayRole ); } ConfigDialog::ConfigDialog( QWidget *parent, const QVariantList &args ) : KCModule( parent, args ), mLock( false ), mDlg( new Ui::ConfigDlg() ), mCalendar( 0 ) { mConfig = KSharedConfig::openConfig( "knemorc" ); setupToolTipMap(); QWidget *main = new QWidget( this ); QVBoxLayout* top = new QVBoxLayout( this ); mDlg->setupUi( main ); top->addWidget( main ); statsModel = new StatsRuleModel( this ); QStringList l; l << i18n( "Start Date" ) << i18n( "Period" ); statsModel->setHorizontalHeaderLabels( l ); QSortFilterProxyModel *proxy = new QSortFilterProxyModel( mDlg->statsView ); proxy->setSourceModel( statsModel ); proxy->setSortRole( Qt::UserRole + 1 ); mDlg->statsView->setModel( proxy ); mDlg->statsView->sortByColumn( 0, Qt::AscendingOrder ); warnModel = new WarnModel( this ); l.clear(); l << i18n( "Alert" ) << i18n( "Period" ); warnModel->setHorizontalHeaderLabels( l ); mDlg->warnView->setModel( warnModel ); QList themes = findThemes(); qSort( themes.begin(), themes.end(), themesLessThan ); foreach ( KNemoTheme theme, themes ) mDlg->comboBoxIconTheme->addItem( theme.name, QVariant::fromValue( theme ) ); // We want these hardcoded and at the bottom of the list KNemoTheme systemTheme; systemTheme.name = i18n( "System Theme" ); systemTheme.comment = i18n( "Use the current icon theme's network status icons" ); systemTheme.internalName = SYSTEM_THEME; KNemoTheme textTheme; textTheme.name = i18n( "Text" ); textTheme.comment = i18n( "KNemo theme that shows the upload/download speed as text" ); textTheme.internalName = TEXT_THEME; KNemoTheme netloadTheme; netloadTheme.name = i18n( "Netload" ); netloadTheme.comment = i18n( "KNemo theme that shows the upload/download speed as bar graphs" ); netloadTheme.internalName = NETLOAD_THEME; // Leave this out for now. Looks like none of the KDE icon themes provide // status/network-* icons. //mDlg->comboBoxIconTheme->addItem( systemTheme.name, QVariant::fromValue( systemTheme ) ); mDlg->comboBoxIconTheme->addItem( netloadTheme.name, QVariant::fromValue( netloadTheme ) ); mDlg->comboBoxIconTheme->addItem( textTheme.name, QVariant::fromValue( textTheme ) ); InterfaceSettings s; int index = findIndexFromName( s.iconTheme ); if ( index < 0 ) index = findIndexFromName( TEXT_THEME ); mDlg->comboBoxIconTheme->setCurrentIndex( index ); for ( size_t i = 0; i < sizeof(pollIntervals)/sizeof(double); i++ ) mDlg->comboBoxPoll->addItem( i18n( "%1 sec", pollIntervals[i] ), pollIntervals[i] ); mDlg->pushButtonNew->setIcon( QIcon::fromTheme( "list-add" ) ); mDlg->pushButtonAll->setIcon( QIcon::fromTheme( "document-new" ) ); mDlg->pushButtonDelete->setIcon( QIcon::fromTheme( "list-remove" ) ); mDlg->pushButtonAddCommand->setIcon( QIcon::fromTheme( "list-add" ) ); mDlg->pushButtonRemoveCommand->setIcon( QIcon::fromTheme( "list-remove" ) ); mDlg->pushButtonUp->setIcon( QIcon::fromTheme( "arrow-up" ) ); mDlg->pushButtonDown->setIcon( QIcon::fromTheme( "arrow-down" ) ); mDlg->pushButtonAddToolTip->setIcon( QIcon::fromTheme( "arrow-right" ) ); mDlg->pushButtonRemoveToolTip->setIcon( QIcon::fromTheme( "arrow-left" ) ); mDlg->themeColorBox->setEnabled( false ); //mDlg->listViewCommands->setSorting( -1 ); setButtons( KCModule::Default | KCModule::Apply ); connect( mDlg->checkBoxStartKNemo, SIGNAL( toggled( bool ) ), this, SLOT( checkBoxStartKNemoToggled( bool ) ) ); // Interface connect( mDlg->listBoxInterfaces, SIGNAL( currentRowChanged( int ) ), this, SLOT( interfaceSelected( int ) ) ); connect( mDlg->pushButtonNew, SIGNAL( clicked() ), this, SLOT( buttonNewSelected() ) ); connect( mDlg->pushButtonAll, SIGNAL( clicked() ), this, SLOT( buttonAllSelected() ) ); connect( mDlg->pushButtonDelete, SIGNAL( clicked() ), this, SLOT( buttonDeleteSelected() ) ); connect( mDlg->lineEditAlias, SIGNAL( textChanged( const QString& ) ), this, SLOT( aliasChanged( const QString& ) ) ); // Interface - Icon Appearance connect( mDlg->comboHiding, SIGNAL( activated( int ) ), this, SLOT( comboHidingChanged( int ) ) ); connect( mDlg->comboBoxIconTheme, SIGNAL( activated( int ) ), this, SLOT( iconThemeChanged( int ) ) ); connect( mDlg->colorIncoming, SIGNAL( changed( const QColor& ) ), this, SLOT( colorButtonChanged() ) ); connect( mDlg->colorOutgoing, SIGNAL( changed( const QColor& ) ), this, SLOT( colorButtonChanged() ) ); connect( mDlg->colorDisabled, SIGNAL( changed( const QColor& ) ), this, SLOT( colorButtonChanged() ) ); connect( mDlg->colorUnavailable, SIGNAL( changed( const QColor& ) ), this, SLOT( colorButtonChanged() ) ); connect( mDlg->iconFont, SIGNAL( currentFontChanged( const QFont& ) ), this, SLOT( iconFontChanged( const QFont& ) ) ); connect( mDlg->advancedButton, SIGNAL( clicked() ), this, SLOT( advancedButtonClicked() ) ); // Interface - Statistics connect( mDlg->checkBoxStatistics, SIGNAL( toggled( bool ) ), this, SLOT( checkBoxStatisticsToggled ( bool ) ) ); connect( mDlg->addStats, SIGNAL( clicked() ), this, SLOT( addStatsClicked() ) ); connect( mDlg->modifyStats, SIGNAL( clicked() ), this, SLOT( modifyStatsClicked() ) ); connect( mDlg->removeStats, SIGNAL( clicked() ), this, SLOT( removeStatsClicked() ) ); connect( mDlg->addWarn, SIGNAL( clicked() ), this, SLOT( addWarnClicked() ) ); connect( mDlg->modifyWarn, SIGNAL( clicked() ), this, SLOT( modifyWarnClicked() ) ); connect( mDlg->removeWarn, SIGNAL( clicked() ), this, SLOT( removeWarnClicked() ) ); // Interface - Context Menu connect( mDlg->listViewCommands, SIGNAL( currentItemChanged( QTreeWidgetItem*, QTreeWidgetItem* ) ), this, SLOT( listViewCommandsSelectionChanged( QTreeWidgetItem*, QTreeWidgetItem* ) ) ); connect( mDlg->listViewCommands, SIGNAL( itemChanged( QTreeWidgetItem*, int ) ), this, SLOT( listViewCommandsChanged( QTreeWidgetItem*, int ) ) ); connect( mDlg->pushButtonAddCommand, SIGNAL( clicked() ), this, SLOT( buttonAddCommandSelected() ) ); connect( mDlg->pushButtonRemoveCommand, SIGNAL( clicked() ), this, SLOT( buttonRemoveCommandSelected() ) ); connect( mDlg->pushButtonUp, SIGNAL( clicked() ), this, SLOT( buttonCommandUpSelected() ) ); connect( mDlg->pushButtonDown, SIGNAL( clicked() ), this, SLOT( buttonCommandDownSelected() ) ); // ToolTip connect( mDlg->pushButtonAddToolTip, SIGNAL( clicked() ), this, SLOT( buttonAddToolTipSelected() ) ); connect( mDlg->pushButtonRemoveToolTip, SIGNAL( clicked() ), this, SLOT( buttonRemoveToolTipSelected() ) ); // General connect( mDlg->pushButtonNotifications, SIGNAL( clicked() ), this, SLOT( buttonNotificationsSelected() ) ); connect( mDlg->comboBoxPoll, SIGNAL( currentIndexChanged( int ) ), this, SLOT( changed() ) ); connect( mDlg->numInputSaveInterval, SIGNAL( valueChanged( int ) ), this, SLOT( changed() ) ); connect( mDlg->useBitrate, SIGNAL( toggled( bool ) ), this, SLOT( changed() ) ); } ConfigDialog::~ConfigDialog() { delete mDlg; } void ConfigDialog::load() { mSettingsMap.clear(); mDlg->listBoxInterfaces->clear(); KConfig *config = mConfig.data(); KConfigGroup generalGroup( config, confg_general ); bool startKNemo = generalGroup.readEntry( conf_autoStart, true ); mDlg->checkBoxStartKNemo->setChecked( startKNemo ); GeneralSettings g; double pollVal = clamp(generalGroup.readEntry( conf_pollInterval, g.pollInterval ), 0.1, 2.0 ); pollVal = validatePoll( pollVal ); int index = mDlg->comboBoxPoll->findData( pollVal ); if ( index >= 0 ) mDlg->comboBoxPoll->setCurrentIndex( index ); mDlg->numInputSaveInterval->setValue( clamp(generalGroup.readEntry( conf_saveInterval, g.saveInterval ), 0, 300 ) ); mDlg->useBitrate->setChecked( generalGroup.readEntry( conf_useBitrate, g.useBitrate ) ); mDlg->lineEditStatisticsDir->setUrl( generalGroup.readEntry( conf_statisticsDir, g.statisticsDir ) ); mToolTipContent = generalGroup.readEntry( conf_toolTipContent, g.toolTipContent ); QStringList list = generalGroup.readEntry( conf_interfaces, QStringList() ); // Get defaults from the struct InterfaceSettings s; foreach ( QString interface, list ) { QString group( confg_interface ); group += interface; InterfaceSettings* settings = new InterfaceSettings(); if ( config->hasGroup( group ) ) { KConfigGroup interfaceGroup( config, group ); settings->alias = interfaceGroup.readEntry( conf_alias ).trimmed(); settings->hideWhenDisconnected = interfaceGroup.readEntry( conf_hideWhenNotAvail, s.hideWhenDisconnected ); settings->hideWhenUnavailable = interfaceGroup.readEntry( conf_hideWhenNotExist, s.hideWhenUnavailable ); settings->trafficThreshold = clamp(interfaceGroup.readEntry( conf_trafficThreshold, s.trafficThreshold ), 0, 1000 ); settings->iconTheme = interfaceGroup.readEntry( conf_iconTheme, s.iconTheme ); settings->colorIncoming = interfaceGroup.readEntry( conf_colorIncoming, s.colorIncoming ); settings->colorOutgoing = interfaceGroup.readEntry( conf_colorOutgoing, s.colorOutgoing ); KColorScheme scheme(QPalette::Active, KColorScheme::View); settings->colorDisabled = interfaceGroup.readEntry( conf_colorDisabled, scheme.foreground( KColorScheme::InactiveText ).color() ); settings->colorUnavailable = interfaceGroup.readEntry( conf_colorUnavailable, scheme.foreground( KColorScheme::InactiveText ).color() ); settings->colorBackground = scheme.foreground( KColorScheme::InactiveText ).color(); settings->iconFont = interfaceGroup.readEntry( conf_iconFont, s.iconFont ); settings->dynamicColor = interfaceGroup.readEntry( conf_dynamicColor, s.dynamicColor ); settings->colorIncomingMax = interfaceGroup.readEntry( conf_colorIncomingMax, s.colorIncomingMax ); settings->colorOutgoingMax = interfaceGroup.readEntry( conf_colorOutgoingMax, s.colorOutgoingMax ); settings->barScale = interfaceGroup.readEntry( conf_barScale, s.barScale ); settings->inMaxRate = interfaceGroup.readEntry( conf_inMaxRate, s.inMaxRate ); settings->outMaxRate = interfaceGroup.readEntry( conf_outMaxRate, s.outMaxRate ); if ( interfaceGroup.hasKey( conf_calendar ) ) { QString oldSetting = interfaceGroup.readEntry( conf_calendar ); // FIXME //settings->calendarSystem = KCalendarSystem::calendarSystem( oldSetting ); interfaceGroup.writeEntry( conf_calendarSystem, static_cast(settings->calendarSystem) ); interfaceGroup.deleteEntry( conf_calendar ); config->sync(); } else settings->calendarSystem = static_cast(interfaceGroup.readEntry( conf_calendarSystem, static_cast(KLocale::QDateCalendar) )); settings->activateStatistics = interfaceGroup.readEntry( conf_activateStatistics, s.activateStatistics ); int statsRuleCount = interfaceGroup.readEntry( conf_statsRules, 0 ); for ( int i = 0; i < statsRuleCount; ++i ) { group = QString( "%1%2 #%3" ).arg( confg_statsRule ).arg( interface ).arg( i ); if ( config->hasGroup( group ) ) { KConfigGroup statsGroup( config, group ); StatsRule stats; stats.startDate = statsGroup.readEntry( conf_statsStartDate, QDate() ); stats.periodUnits = clamp(statsGroup.readEntry( conf_statsPeriodUnits, stats.periodUnits ), KNemoStats::Day, KNemoStats::Year ); stats.periodCount = clamp(statsGroup.readEntry( conf_statsPeriodCount, stats.periodCount ), 1, 1000 ); stats.logOffpeak = statsGroup.readEntry( conf_logOffpeak,stats.logOffpeak ); stats.offpeakStartTime = QTime::fromString( statsGroup.readEntry( conf_offpeakStartTime, stats.offpeakStartTime.toString( Qt::ISODate ) ), Qt::ISODate ); stats.offpeakEndTime = QTime::fromString( statsGroup.readEntry( conf_offpeakEndTime, stats.offpeakEndTime.toString( Qt::ISODate ) ), Qt::ISODate ); stats.weekendIsOffpeak = statsGroup.readEntry( conf_weekendIsOffpeak, stats.weekendIsOffpeak ); stats.weekendDayStart = statsGroup.readEntry( conf_weekendDayStart, stats.weekendDayStart ); stats.weekendDayEnd = statsGroup.readEntry( conf_weekendDayEnd, stats.weekendDayEnd ); stats.weekendTimeStart = QTime::fromString( statsGroup.readEntry( conf_weekendTimeStart, stats.weekendTimeStart.toString( Qt::ISODate ) ), Qt::ISODate ); stats.weekendTimeEnd = QTime::fromString( statsGroup.readEntry( conf_weekendTimeEnd, stats.weekendTimeEnd.toString( Qt::ISODate ) ), Qt::ISODate ); settings->statsRules << stats; } } int warnRuleCount = interfaceGroup.readEntry( conf_warnRules, 0 ); for ( int i = 0; i < warnRuleCount; ++i ) { group = QString( "%1%2 #%3" ).arg( confg_warnRule ).arg( interface ).arg( i ); if ( config->hasGroup( group ) ) { KConfigGroup warnGroup( config, group ); WarnRule warn; warn.periodUnits = clamp(warnGroup.readEntry( conf_warnPeriodUnits, warn.periodUnits ), KNemoStats::Hour, KNemoStats::Year ); warn.periodCount = clamp(warnGroup.readEntry( conf_warnPeriodCount, warn.periodCount ), 1, 1000 ); warn.trafficType = clamp(warnGroup.readEntry( conf_warnTrafficType, warn.trafficType ), KNemoStats::Peak, KNemoStats::PeakOffpeak ); warn.trafficDirection = clamp(warnGroup.readEntry( conf_warnTrafficDirection, warn.trafficDirection ), KNemoStats::TrafficIn, KNemoStats::TrafficTotal ); warn.trafficUnits = clamp(warnGroup.readEntry( conf_warnTrafficUnits, warn.trafficUnits ), KNemoStats::UnitB, KNemoStats::UnitG ); warn.threshold = clamp(warnGroup.readEntry( conf_warnThreshold, warn.threshold ), 0.0, 9999.0 ); warn.customText = warnGroup.readEntry( conf_warnCustomText, warn.customText ).trimmed(); settings->warnRules << warn; } } int numCommands = interfaceGroup.readEntry( conf_numCommands, s.numCommands ); for ( int i = 0; i < numCommands; i++ ) { QString entry; InterfaceCommand cmd; entry = QString( "%1%2" ).arg( conf_runAsRoot ).arg( i + 1 ); cmd.runAsRoot = interfaceGroup.readEntry( entry, false ); entry = QString( "%1%2" ).arg( conf_command ).arg( i + 1 ); cmd.command = interfaceGroup.readEntry( entry ); entry = QString( "%1%2" ).arg( conf_menuText ).arg( i + 1 ); cmd.menuText = interfaceGroup.readEntry( entry ); settings->commands.append( cmd ); } } mSettingsMap.insert( interface, settings ); mDlg->listBoxInterfaces->addItem( interface ); mDlg->pushButtonDelete->setEnabled( true ); mDlg->ifaceTab->setEnabled( true ); } // These things need to be here so that 'Reset' from the control // center is handled correctly. setupToolTipTab(); // In case the user opened the control center via the context menu // this call to the daemon will deliver the interface the menu // belongs to. This way we can preselect the appropriate entry in the list. QString selectedInterface = QString::null; QDBusMessage reply = QDBusInterface("org.kde.knemo", "/knemo", "org.kde.knemo").call("getSelectedInterface"); if ( reply.arguments().count() ) { selectedInterface = reply.arguments().first().toString(); } if ( selectedInterface != QString::null ) { // Try to preselect the interface. int i; for ( i = 0; i < mDlg->listBoxInterfaces->count(); i++ ) { if ( mDlg->listBoxInterfaces->item( i )->text() == selectedInterface ) { // Found it. mDlg->listBoxInterfaces->setCurrentRow( i ); break; } } if ( i == mDlg->listBoxInterfaces->count() ) { // Not found. Select first entry in list. mDlg->listBoxInterfaces->setCurrentRow( 0 ); } } else if ( mDlg->listBoxInterfaces->count() ) { // No interface from KNemo. Select first entry in list. mDlg->listBoxInterfaces->setCurrentRow( 0 ); } } void ConfigDialog::save() { KConfig *config = mConfig.data(); QStringList list; // Remove interfaces from the config that were deleted during this session foreach ( QString delIface, mDeletedIfaces ) { if ( !mSettingsMap.contains( delIface ) ) { config->deleteGroup( confg_interface + delIface ); config->deleteGroup( confg_plotter + delIface ); } } QStringList groupList = config->groupList(); foreach ( QString tempDel, groupList ) { if ( tempDel.contains( confg_statsRule ) || tempDel.contains( confg_warnRule ) ) config->deleteGroup( tempDel ); } foreach ( QString it, mSettingsMap.keys() ) { list.append( it ); InterfaceSettings* settings = mSettingsMap.value( it ); KConfigGroup interfaceGroup( config, confg_interface + it ); // Preserve settings set by the app before delete QPoint plotterPos = interfaceGroup.readEntry( conf_plotterPos, QPoint() ); QSize plotterSize = interfaceGroup.readEntry( conf_plotterSize, QSize() ); QPoint statisticsPos = interfaceGroup.readEntry( conf_statisticsPos, QPoint() ); QSize statisticsSize = interfaceGroup.readEntry( conf_statisticsSize, QSize() ); QPoint statusPos = interfaceGroup.readEntry( conf_statusPos, QPoint() ); QSize statusSize = interfaceGroup.readEntry( conf_statusSize, QSize() ); QByteArray hourState = interfaceGroup.readEntry( conf_hourState, QByteArray() ); QByteArray dayState = interfaceGroup.readEntry( conf_dayState, QByteArray() ); QByteArray weekState = interfaceGroup.readEntry( conf_weekState, QByteArray() ); QByteArray monthState = interfaceGroup.readEntry( conf_monthState, QByteArray() ); QByteArray billingState = interfaceGroup.readEntry( conf_billingState, QByteArray() ); QByteArray yearState = interfaceGroup.readEntry( conf_yearState, QByteArray() ); // Make sure we don't get crufty commands left over interfaceGroup.deleteGroup(); if ( !plotterPos.isNull() ) interfaceGroup.writeEntry( conf_plotterPos, plotterPos ); if ( !plotterSize.isEmpty() ) interfaceGroup.writeEntry( conf_plotterSize, plotterSize ); if ( !statisticsPos.isNull() ) interfaceGroup.writeEntry( conf_statisticsPos, statisticsPos ); if ( !statisticsSize.isEmpty() ) interfaceGroup.writeEntry( conf_statisticsSize, statisticsSize ); if ( !statusPos.isNull() ) interfaceGroup.writeEntry( conf_statusPos, statusPos ); if ( !statusSize.isEmpty() ) interfaceGroup.writeEntry( conf_statusSize, statusSize ); if ( !settings->alias.trimmed().isEmpty() ) interfaceGroup.writeEntry( conf_alias, settings->alias ); if ( !hourState.isNull() ) interfaceGroup.writeEntry( conf_hourState, hourState ); if ( !dayState.isNull() ) interfaceGroup.writeEntry( conf_dayState, dayState ); if ( !weekState.isNull() ) interfaceGroup.writeEntry( conf_weekState, weekState ); if ( !monthState.isNull() ) interfaceGroup.writeEntry( conf_monthState, monthState ); if ( !billingState.isNull() ) interfaceGroup.writeEntry( conf_billingState, billingState ); if ( !yearState.isNull() ) interfaceGroup.writeEntry( conf_yearState, yearState ); interfaceGroup.writeEntry( conf_hideWhenNotAvail, settings->hideWhenDisconnected ); interfaceGroup.writeEntry( conf_hideWhenNotExist, settings->hideWhenUnavailable ); interfaceGroup.writeEntry( conf_trafficThreshold, settings->trafficThreshold ); interfaceGroup.writeEntry( conf_iconTheme, settings->iconTheme ); if ( settings->iconTheme == TEXT_THEME || settings->iconTheme == NETLOAD_THEME ) { interfaceGroup.writeEntry( conf_colorIncoming, settings->colorIncoming ); interfaceGroup.writeEntry( conf_colorOutgoing, settings->colorOutgoing ); interfaceGroup.writeEntry( conf_colorDisabled, settings->colorDisabled ); interfaceGroup.writeEntry( conf_colorUnavailable, settings->colorUnavailable ); interfaceGroup.writeEntry( conf_dynamicColor, settings->dynamicColor ); if ( settings->dynamicColor ) { interfaceGroup.writeEntry( conf_colorIncomingMax, settings->colorIncomingMax ); interfaceGroup.writeEntry( conf_colorOutgoingMax, settings->colorOutgoingMax ); } if ( settings->iconTheme == NETLOAD_THEME ) { interfaceGroup.writeEntry( conf_barScale, settings->barScale ); } if ( settings->iconTheme == TEXT_THEME && settings->iconFont != QFontDatabase::systemFont( QFontDatabase::GeneralFont ) ) { interfaceGroup.writeEntry( conf_iconFont, settings->iconFont ); } if ( settings->dynamicColor || ( settings->iconTheme == NETLOAD_THEME && settings->barScale ) ) { interfaceGroup.writeEntry( conf_inMaxRate, settings->inMaxRate ); interfaceGroup.writeEntry( conf_outMaxRate, settings->outMaxRate ); } } interfaceGroup.writeEntry( conf_activateStatistics, settings->activateStatistics ); interfaceGroup.writeEntry( conf_calendarSystem, static_cast(settings->calendarSystem) ); interfaceGroup.writeEntry( conf_statsRules, settings->statsRules.count() ); for ( int i = 0; i < settings->statsRules.count(); i++ ) { QString group = QString( "%1%2 #%3" ).arg( confg_statsRule ).arg( it ).arg( i ); KConfigGroup statsGroup( config, group ); statsGroup.writeEntry( conf_statsStartDate, settings->statsRules[i].startDate ); statsGroup.writeEntry( conf_statsPeriodUnits, settings->statsRules[i].periodUnits ); statsGroup.writeEntry( conf_statsPeriodCount, settings->statsRules[i].periodCount ); statsGroup.writeEntry( conf_logOffpeak, settings->statsRules[i].logOffpeak ); if ( settings->statsRules[i].logOffpeak ) { statsGroup.writeEntry( conf_offpeakStartTime, settings->statsRules[i].offpeakStartTime.toString( Qt::ISODate ) ); statsGroup.writeEntry( conf_offpeakEndTime, settings->statsRules[i].offpeakEndTime.toString( Qt::ISODate ) ); statsGroup.writeEntry( conf_weekendIsOffpeak, settings->statsRules[i].weekendIsOffpeak ); if ( settings->statsRules[i].weekendIsOffpeak ) { statsGroup.writeEntry( conf_weekendDayStart, settings->statsRules[i].weekendDayStart ); statsGroup.writeEntry( conf_weekendDayEnd, settings->statsRules[i].weekendDayEnd ); statsGroup.writeEntry( conf_weekendTimeStart, settings->statsRules[i].weekendTimeStart.toString( Qt::ISODate ) ); statsGroup.writeEntry( conf_weekendTimeEnd, settings->statsRules[i].weekendTimeEnd.toString( Qt::ISODate ) ); } } } interfaceGroup.writeEntry( conf_warnRules, settings->warnRules.count() ); for ( int i = 0; i < settings->warnRules.count(); i++ ) { QString group = QString( "%1%2 #%3" ).arg( confg_warnRule ).arg( it ).arg( i ); KConfigGroup warnGroup( config, group ); if ( settings->statsRules.count() == 0 && settings->warnRules[i].periodUnits == KNemoStats::BillPeriod ) { warnGroup.writeEntry( conf_warnPeriodUnits, static_cast(KNemoStats::Month) ); } else { warnGroup.writeEntry( conf_warnPeriodUnits, settings->warnRules[i].periodUnits ); } warnGroup.writeEntry( conf_warnPeriodCount, settings->warnRules[i].periodCount ); warnGroup.writeEntry( conf_warnTrafficType, settings->warnRules[i].trafficType ); warnGroup.writeEntry( conf_warnTrafficDirection, settings->warnRules[i].trafficDirection ); warnGroup.writeEntry( conf_warnTrafficUnits, settings->warnRules[i].trafficUnits ); warnGroup.writeEntry( conf_warnThreshold, settings->warnRules[i].threshold ); warnGroup.writeEntry( conf_warnCustomText, settings->warnRules[i].customText.trimmed() ); } interfaceGroup.writeEntry( conf_numCommands, settings->commands.size() ); for ( int i = 0; i < settings->commands.size(); i++ ) { QString entry; entry = QString( "%1%2" ).arg( conf_runAsRoot ).arg( i + 1 ); interfaceGroup.writeEntry( entry, settings->commands[i].runAsRoot ); entry = QString( "%1%2" ).arg( conf_command ).arg( i + 1 ); interfaceGroup.writeEntry( entry, settings->commands[i].command ); entry = QString( "%1%2" ).arg( conf_menuText ).arg( i + 1 ); interfaceGroup.writeEntry( entry, settings->commands[i].menuText ); } } KConfigGroup generalGroup( config, confg_general ); generalGroup.writeEntry( conf_firstStart, false ); generalGroup.writeEntry( conf_autoStart, mDlg->checkBoxStartKNemo->isChecked() ); generalGroup.writeEntry( conf_pollInterval, mDlg->comboBoxPoll->itemData( mDlg->comboBoxPoll->currentIndex() ).value() ); generalGroup.writeEntry( conf_saveInterval, mDlg->numInputSaveInterval->value() ); generalGroup.writeEntry( conf_useBitrate, mDlg->useBitrate->isChecked() ); generalGroup.writeEntry( conf_statisticsDir, mDlg->lineEditStatisticsDir->url().url() ); generalGroup.writeEntry( conf_toolTipContent, mToolTipContent ); generalGroup.writeEntry( conf_interfaces, list ); config->sync(); QDBusMessage reply = QDBusInterface("org.kde.knemo", "/knemo", "org.kde.knemo").call("reparseConfiguration"); } void ConfigDialog::defaults() { // Set these values before we check for default interfaces mSettingsMap.clear(); mDlg->listBoxInterfaces->clear(); mDlg->pushButtonDelete->setEnabled( false ); InterfaceSettings emptySettings; updateControls( &emptySettings ); // Default interface void *cache = NULL; #ifdef __linux__ struct nl_sock *rtsock = nl_socket_alloc(); int c = nl_connect(rtsock, NETLINK_ROUTE); if ( c >= 0 ) { rtnl_route_alloc_cache( rtsock, AF_UNSPEC, NL_AUTO_PROVIDE, reinterpret_cast(&cache) ); } #endif QString interface = getDefaultRoute( AF_INET, NULL, cache ); if ( interface.isEmpty() ) interface = getDefaultRoute( AF_INET6, NULL, cache ); #ifdef __linux__ nl_cache_free( static_cast(cache) ); nl_close( rtsock ); nl_socket_free( rtsock ); #endif if ( interface.isEmpty() ) { mDlg->aliasLabel->setEnabled( false ); mDlg->lineEditAlias->setEnabled( false ); mDlg->ifaceTab->setEnabled( false ); mDlg->pixmapError->clear(); mDlg->pixmapDisconnected->clear(); mDlg->pixmapConnected->clear(); mDlg->pixmapIncoming->clear(); mDlg->pixmapOutgoing->clear(); mDlg->pixmapTraffic->clear(); } else { InterfaceSettings* settings = new InterfaceSettings(); KColorScheme scheme(QPalette::Active, KColorScheme::View); settings->colorDisabled = scheme.foreground( KColorScheme::InactiveText ).color(); settings->colorUnavailable = scheme.foreground( KColorScheme::InactiveText ).color(); settings->colorBackground = scheme.foreground( KColorScheme::InactiveText ).color(); settings->iconFont = QFontDatabase::systemFont( QFontDatabase::GeneralFont ); mSettingsMap.insert( interface, settings ); mDlg->listBoxInterfaces->addItem( interface ); mDlg->listBoxInterfaces->setCurrentRow( 0 ); mDlg->pushButtonDelete->setEnabled( true ); mDlg->aliasLabel->setEnabled( true ); mDlg->lineEditAlias->setEnabled( true ); mDlg->ifaceTab->setEnabled( true ); } // Default general settings GeneralSettings g; int index = mDlg->comboBoxPoll->findData( g.pollInterval ); if ( index >= 0 ) mDlg->comboBoxPoll->setCurrentIndex( index ); mDlg->numInputSaveInterval->setValue( g.saveInterval ); mDlg->useBitrate->setChecked( g.useBitrate ); mDlg->lineEditStatisticsDir->setUrl( g.statisticsDir ); // Default tool tips mToolTipContent = g.toolTipContent; setupToolTipTab(); changed( true ); } void ConfigDialog::checkBoxStartKNemoToggled( bool on ) { if ( on ) { KConfig *config = mConfig.data(); KConfigGroup generalGroup( config, confg_general ); if ( generalGroup.readEntry( conf_firstStart, true ) ) { // Populate the dialog with some default values if the user starts // KNemo for the very first time. defaults(); } } if (!mLock) changed( true ); } /****************************************** * * * Interface tab * * * ******************************************/ InterfaceSettings * ConfigDialog::getItemSettings() { if ( !mDlg->listBoxInterfaces->currentItem() ) return NULL; QListWidgetItem* selected = mDlg->listBoxInterfaces->currentItem(); return mSettingsMap[selected->text()]; } QString ConfigDialog::findNameFromIndex( int index ) { KNemoTheme theme = mDlg->comboBoxIconTheme->itemData( index ).value(); return theme.internalName; } int ConfigDialog::findIndexFromName( const QString& internalName ) { for( int i = 0; i < mDlg->comboBoxIconTheme->count(); i++ ) { KNemoTheme theme = mDlg->comboBoxIconTheme->itemData( i ).value(); if ( theme.internalName == internalName ) return i; } return -1; } void ConfigDialog::updateWarnText( int oldCount ) { // If the billing periods go away, the warn period will change to months // This only changes the text displayed in the model, so it can change // back if a billing period reappears. if ( ! statsModel->rowCount() ) { QList warnRules = warnModel->getRules(); for ( int i = 0; i < warnRules.count(); ++i ) { if ( warnRules[i].periodUnits == KNemoStats::BillPeriod ) { warnModel->item( i, 1 )->setData( periodText( warnRules[i].periodCount, KNemoStats::Month ), Qt::DisplayRole ); } } } else if ( oldCount == 0 ) { QList warnRules = warnModel->getRules(); for ( int i = 0; i < warnRules.count(); ++i ) { if ( warnRules[i].periodUnits == KNemoStats::BillPeriod ) warnModel->item( i, 1 )->setData( periodText( warnRules[i].periodCount, warnRules[i].periodUnits ), Qt::DisplayRole ); } } } void ConfigDialog::updateControls( InterfaceSettings *settings ) { mLock = true; mDlg->lineEditAlias->setText( settings->alias ); int index = findIndexFromName( settings->iconTheme ); if ( index < 0 ) index = findIndexFromName( TEXT_THEME ); mDlg->comboBoxIconTheme->setCurrentIndex( index ); mDlg->colorIncoming->setColor( settings->colorIncoming ); mDlg->colorOutgoing->setColor( settings->colorOutgoing ); mDlg->colorDisabled->setColor( settings->colorDisabled ); mDlg->colorUnavailable->setColor( settings->colorUnavailable ); mDlg->iconFont->setCurrentFont( settings->iconFont ); iconThemeChanged( index ); if ( settings->hideWhenDisconnected ) index = 1; else if ( settings->hideWhenUnavailable ) index = 2; else index = 0; mDlg->comboHiding->setCurrentIndex( index ); comboHidingChanged( index ); mDlg->checkBoxStatistics->setChecked( settings->activateStatistics ); if ( !mCalendar || mCalendar->calendarSystem() != settings->calendarSystem ) mCalendar = KCalendarSystem::create( settings->calendarSystem ); statsModel->removeRows(0, statsModel->rowCount() ); statsModel->setCalendar( mCalendar ); foreach( StatsRule s, settings->statsRules ) { statsModel->addRule( s ); } if ( statsModel->rowCount() ) { QSortFilterProxyModel* proxy = static_cast(mDlg->statsView->model()); QModelIndex index = statsModel->indexFromItem( statsModel->item( 0, 0 ) ); mDlg->statsView->setCurrentIndex( proxy->mapFromSource( index ) ); } mDlg->modifyStats->setEnabled( statsModel->rowCount() ); mDlg->removeStats->setEnabled( statsModel->rowCount() ); warnModel->removeRows(0, warnModel->rowCount() ); foreach( WarnRule warn, settings->warnRules ) { warnModel->addWarn( warn ); } updateWarnText( statsModel->rowCount() ); mDlg->modifyWarn->setEnabled( warnModel->rowCount() ); mDlg->removeWarn->setEnabled( warnModel->rowCount() ); if ( warnModel->rowCount() ) { mDlg->warnView->setCurrentIndex( warnModel->indexFromItem ( warnModel->item( 0, 0 ) ) ); } mDlg->listViewCommands->clear(); QListitems; foreach ( InterfaceCommand command, settings->commands ) { QTreeWidgetItem* item = new QTreeWidgetItem(); enum Qt::CheckState checkState = Qt::Unchecked; if ( command.runAsRoot ) checkState = Qt::Checked; item->setCheckState( 0, checkState ); item->setFlags( item->flags() | Qt::ItemIsEditable ); item->setText( 1, command.menuText ); item->setText( 2, command.command ); items << item; } if ( items.count() > 0 ) { mDlg->listViewCommands->addTopLevelItems( items ); mDlg->listViewCommands->setCurrentItem( items[0] ); mDlg->pushButtonRemoveCommand->setEnabled( true ); setUpDownButtons( items[0] ); } else { mDlg->pushButtonRemoveCommand->setEnabled( false ); setUpDownButtons( NULL ); } mLock = false; } void ConfigDialog::interfaceSelected( int row ) { if ( row < 0 ) return; QString interface = mDlg->listBoxInterfaces->item( row )->text(); InterfaceSettings* settings = mSettingsMap[interface]; mDlg->ifaceTab->setEnabled( true ); mDlg->aliasLabel->setEnabled( true ); mDlg->lineEditAlias->setEnabled( true ); updateControls( settings ); } void ConfigDialog::buttonNewSelected() { bool ok = false; QString ifname = QInputDialog::getText( this, i18n( "Add new interface" ), i18n( "Please enter the name of the interface to be monitored.\nIt should be something like 'eth1', 'wlan2' or 'ppp0'." ), QLineEdit::Normal, QString::null, &ok ); if ( ok ) { QListWidgetItem *item = new QListWidgetItem( ifname ); mDlg->listBoxInterfaces->addItem( item ); InterfaceSettings *settings = new InterfaceSettings(); KColorScheme scheme(QPalette::Active, KColorScheme::View); settings->colorDisabled = scheme.foreground( KColorScheme::InactiveText ).color(); settings->colorUnavailable = scheme.foreground( KColorScheme::InactiveText ).color(); settings->colorBackground = scheme.foreground( KColorScheme::InactiveText ).color(); settings->iconFont = QFontDatabase::systemFont( QFontDatabase::GeneralFont ); mSettingsMap.insert( ifname, settings ); mDlg->listBoxInterfaces->setCurrentRow( mDlg->listBoxInterfaces->row( item ) ); mDlg->pushButtonDelete->setEnabled( true ); changed( true ); } } void ConfigDialog::buttonAllSelected() { QStringList ifaces; #ifdef __linux__ nl_cache * linkCache = NULL; nl_sock *rtsock = nl_socket_alloc(); int c = nl_connect(rtsock, NETLINK_ROUTE); if ( c >= 0 ) { rtnl_link_alloc_cache( rtsock, AF_UNSPEC, &linkCache ); struct rtnl_link * rtlink; for ( rtlink = reinterpret_cast(nl_cache_get_first( linkCache )); rtlink != NULL; rtlink = reinterpret_cast(nl_cache_get_next( reinterpret_cast(rtlink) )) ) { QString ifname( rtnl_link_get_name( rtlink ) ); ifaces << ifname; } } nl_cache_free( linkCache ); nl_close( rtsock ); nl_socket_free( rtsock ); #else struct ifaddrs *ifaddr; struct ifaddrs *ifa; getifaddrs( &ifaddr ); for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { QString ifname( ifa->ifa_name ); ifaces << ifname; } freeifaddrs( ifaddr ); #endif ifaces.removeAll( "lo" ); ifaces.removeAll( "lo0" ); const KColorScheme scheme(QPalette::Active, KColorScheme::View); foreach ( QString ifname, ifaces ) { if ( mSettingsMap.contains( ifname ) ) continue; InterfaceSettings* settings = new InterfaceSettings(); settings->colorDisabled = scheme.foreground( KColorScheme::InactiveText ).color(); settings->colorUnavailable = scheme.foreground( KColorScheme::InactiveText ).color(); settings->colorBackground = scheme.foreground( KColorScheme::InactiveText ).color(); settings->iconFont = QFontDatabase::systemFont( QFontDatabase::GeneralFont ); mSettingsMap.insert( ifname, settings ); mDlg->listBoxInterfaces->addItem( ifname ); } if ( mDlg->listBoxInterfaces->count() > 0 ) { mDlg->listBoxInterfaces->setCurrentRow( 0 ); mDlg->pushButtonDelete->setEnabled( true ); mDlg->ifaceTab->setEnabled( true ); QString iface = mDlg->listBoxInterfaces->item( 0 )->text(); } changed( true ); } void ConfigDialog::buttonDeleteSelected() { if ( !mDlg->listBoxInterfaces->currentItem() ) return; QListWidgetItem* selected = mDlg->listBoxInterfaces->currentItem(); // To prevent bloat when we save if ( !mDeletedIfaces.contains( selected->text() ) ) mDeletedIfaces << selected->text(); mSettingsMap.remove( selected->text() ); QListWidgetItem *taken = mDlg->listBoxInterfaces->takeItem( mDlg->listBoxInterfaces->row( selected ) ); delete taken; if ( mDlg->listBoxInterfaces->count() < 1 ) { InterfaceSettings emptySettings; updateControls( &emptySettings ); mDlg->pushButtonDelete->setEnabled( false ); mDlg->aliasLabel->setEnabled( false ); mDlg->lineEditAlias->setEnabled( false ); mDlg->ifaceTab->setEnabled( false ); mDlg->pixmapError->clear(); mDlg->pixmapDisconnected->clear(); mDlg->pixmapConnected->clear(); mDlg->pixmapIncoming->clear(); mDlg->pixmapOutgoing->clear(); mDlg->pixmapTraffic->clear(); } changed( true ); } void ConfigDialog::aliasChanged( const QString& text ) { InterfaceSettings* settings = getItemSettings(); if ( !settings ) return; settings->alias = text; if (!mLock) changed( true ); } /****************************************** * * * Interface tab - Icon Appearance * * * ******************************************/ QPixmap ConfigDialog::textIcon( QString incomingText, QString outgoingText, int status ) { QPixmap sampleIcon( 22, 22 ); sampleIcon.fill( Qt::transparent ); QRect topRect( 0, 0, 22, 11 ); QRect bottomRect( 0, 11, 22, 11 ); QPainter p( &sampleIcon ); p.setBrush( Qt::NoBrush ); p.setOpacity( 1.0 ); QFont rxFont = setIconFont( incomingText, mDlg->iconFont->currentFont(), 22 ); QFont txFont = setIconFont( outgoingText, mDlg->iconFont->currentFont(), 22 ); if ( rxFont.pointSizeF() > txFont.pointSizeF() ) rxFont.setPointSizeF( txFont.pointSizeF() ); p.setFont( rxFont ); if ( status >= KNemoIface::Connected ) p.setPen( mDlg->colorIncoming->color() ); else if ( status == KNemoIface::Available ) p.setPen( mDlg->colorDisabled->color() ); else p.setPen( mDlg->colorUnavailable->color() ); p.drawText( topRect, Qt::AlignCenter | Qt::AlignRight, incomingText ); p.setFont( rxFont ); if ( status >= KNemoIface::Connected ) p.setPen( mDlg->colorOutgoing->color() ); p.drawText( bottomRect, Qt::AlignCenter | Qt::AlignRight, outgoingText ); return sampleIcon; } QPixmap ConfigDialog::barIcon( int status ) { int barIncoming = 0; int barOutgoing = 0; QPixmap barIcon( 22, 22 ); barIcon.fill( Qt::transparent ); QPainter p( &barIcon ); QLinearGradient inGrad( 12, 0, 19, 0 ); QLinearGradient topInGrad( 12, 0, 19, 0 ); QLinearGradient outGrad( 3, 0, 10, 0 ); QLinearGradient topOutGrad( 3, 0, 10, 0 ); QColor topColor = getItemSettings()->colorBackground; QColor topColorD = getItemSettings()->colorBackground.darker(); topColor.setAlpha( 128 ); topColorD.setAlpha( 128 ); topInGrad.setColorAt(0, topColorD); topInGrad.setColorAt(1, topColor ); topOutGrad.setColorAt(0, topColorD); topOutGrad.setColorAt(1, topColor ); if ( status & KNemoIface::Connected ) { inGrad.setColorAt(0, mDlg->colorIncoming->color() ); inGrad.setColorAt(1, mDlg->colorIncoming->color().darker() ); outGrad.setColorAt(0, mDlg->colorOutgoing->color() ); outGrad.setColorAt(1, mDlg->colorOutgoing->color().darker() ); } else if ( status & KNemoIface::Available ) { inGrad.setColorAt(0, mDlg->colorDisabled->color()); inGrad.setColorAt(1, mDlg->colorDisabled->color().darker() ); outGrad.setColorAt(0, mDlg->colorDisabled->color() ); outGrad.setColorAt(1, mDlg->colorDisabled->color().darker() ); } else { inGrad.setColorAt(0, mDlg->colorUnavailable->color() ); inGrad.setColorAt(1, mDlg->colorUnavailable->color().darker() ); outGrad.setColorAt(0, mDlg->colorUnavailable->color() ); outGrad.setColorAt(1, mDlg->colorUnavailable->color().darker() ); } if ( status & KNemoIface::Available || status & KNemoIface::Unavailable ) { barIncoming = 22; barOutgoing = 22; } if ( status & KNemoIface::RxTraffic ) barIncoming = 17; if ( status & KNemoIface::TxTraffic ) barOutgoing = 17; int top = 22 - barOutgoing; QRect topLeftRect( 3, 0, 7, top ); QRect leftRect( 3, top, 7, 22 ); top = 22 - barIncoming; QRect topRightRect( 12, 0, 7, top ); QRect rightRect( 12, top, 7, 22 ); QBrush brush( inGrad ); p.setBrush( brush ); p.fillRect( rightRect, inGrad ); brush = QBrush( topInGrad ); p.fillRect( topRightRect, topInGrad ); brush = QBrush( outGrad ); p.fillRect( leftRect, outGrad ); brush = QBrush( topOutGrad ); p.fillRect( topLeftRect, topOutGrad ); return barIcon; } void ConfigDialog::comboHidingChanged( int val ) { InterfaceSettings* settings = getItemSettings(); if ( !settings ) return; switch ( val ) { case 0: settings->hideWhenDisconnected = false; settings->hideWhenUnavailable = false; break; case 1: settings->hideWhenDisconnected = true; settings->hideWhenUnavailable = true; break; case 2: settings->hideWhenDisconnected = false; settings->hideWhenUnavailable = true; break; } if (!mLock) changed( true ); } void ConfigDialog::iconThemeChanged( int set ) { InterfaceSettings* settings = getItemSettings(); if ( !settings ) return; KNemoTheme curTheme = mDlg->comboBoxIconTheme->itemData( mDlg->comboBoxIconTheme->currentIndex() ).value(); if ( curTheme.internalName != TEXT_THEME ) { mDlg->iconFontLabel->setEnabled( false ); mDlg->iconFont->setEnabled( false ); } if ( curTheme.internalName == TEXT_THEME || curTheme.internalName == NETLOAD_THEME ) { if ( curTheme.internalName == TEXT_THEME ) { settings->iconTheme = TEXT_THEME; mDlg->pixmapError->setPixmap( textIcon( "0.0K", "0.0K", KNemoIface::Unavailable ) ); mDlg->pixmapDisconnected->setPixmap( textIcon( "0.0K", "0.0K", KNemoIface::Available ) ); mDlg->pixmapConnected->setPixmap( textIcon( "0.0K", "0.0K", KNemoIface::Connected ) ); mDlg->pixmapIncoming->setPixmap( textIcon( "123K", "0.0K", KNemoIface::Connected ) ); mDlg->pixmapOutgoing->setPixmap( textIcon( "0.0K", "12K", KNemoIface::Connected ) ); mDlg->pixmapTraffic->setPixmap( textIcon( "123K", "12K", KNemoIface::Connected ) ); mDlg->iconFontLabel->setEnabled( true ); mDlg->iconFont->setEnabled( true ); } else { settings->iconTheme = NETLOAD_THEME; mDlg->pixmapError->setPixmap( barIcon( KNemoIface::Unavailable ) ); mDlg->pixmapDisconnected->setPixmap( barIcon( KNemoIface::Available ) ); mDlg->pixmapConnected->setPixmap( barIcon( KNemoIface::Connected ) ); mDlg->pixmapIncoming->setPixmap( barIcon( KNemoIface::Connected | KNemoIface::RxTraffic ) ); mDlg->pixmapOutgoing->setPixmap( barIcon( KNemoIface::Connected | KNemoIface::TxTraffic ) ); mDlg->pixmapTraffic->setPixmap( barIcon( KNemoIface::Connected | KNemoIface::RxTraffic | KNemoIface::TxTraffic ) ); } mDlg->themeColorBox->setEnabled( true ); } else { settings->iconTheme = findNameFromIndex( set ); QString iconName; if ( settings->iconTheme == SYSTEM_THEME ) iconName = "network-"; else iconName = "knemo-" + settings->iconTheme + "-"; mDlg->pixmapError->setPixmap( QIcon::fromTheme( iconName + ICON_ERROR ).pixmap( 22 ) ); mDlg->pixmapDisconnected->setPixmap( QIcon::fromTheme( iconName + ICON_OFFLINE ).pixmap( 22 ) ); mDlg->pixmapConnected->setPixmap( QIcon::fromTheme( iconName + ICON_IDLE ).pixmap( 22 ) ); mDlg->pixmapIncoming->setPixmap( QIcon::fromTheme( iconName + ICON_RX ).pixmap( 22 ) ); mDlg->pixmapOutgoing->setPixmap( QIcon::fromTheme( iconName + ICON_TX ).pixmap( 22 ) ); mDlg->pixmapTraffic->setPixmap( QIcon::fromTheme( iconName + ICON_RX_TX ).pixmap( 22 ) ); mDlg->themeColorBox->setEnabled( false ); } if (!mLock) changed( true ); } void ConfigDialog::colorButtonChanged() { InterfaceSettings* settings = getItemSettings(); if ( !settings ) return; if ( mDlg->colorIncoming->color().isValid() ) settings->colorIncoming = mDlg->colorIncoming->color(); if ( mDlg->colorOutgoing->color().isValid() ) settings->colorOutgoing = mDlg->colorOutgoing->color(); if ( mDlg->colorDisabled->color().isValid() ) settings->colorDisabled = mDlg->colorDisabled->color(); if ( mDlg->colorUnavailable->color().isValid() ) settings->colorUnavailable = mDlg->colorUnavailable->color(); KNemoTheme curTheme = mDlg->comboBoxIconTheme->itemData( mDlg->comboBoxIconTheme->currentIndex() ).value(); if ( curTheme.internalName == TEXT_THEME || curTheme.internalName == NETLOAD_THEME ) iconThemeChanged( mDlg->comboBoxIconTheme->currentIndex() ); if ( !mLock) changed( true ); } void ConfigDialog::iconFontChanged( const QFont &font ) { InterfaceSettings* settings = getItemSettings(); if ( !settings ) return; if ( font != settings->iconFont ) { settings->iconFont = font; iconThemeChanged( mDlg->comboBoxIconTheme->currentIndex() ); } if ( !mLock ) changed( true ); } void ConfigDialog::advancedButtonClicked() { InterfaceSettings* settings = getItemSettings(); if ( !settings ) return; ThemeConfig dlg( *settings ); if ( dlg.exec() ) { InterfaceSettings s = dlg.settings(); settings->trafficThreshold = s.trafficThreshold; settings->dynamicColor = s.dynamicColor; settings->colorIncomingMax = s.colorIncomingMax; settings->colorOutgoingMax = s.colorOutgoingMax; settings->barScale = s.barScale; settings->inMaxRate = s.inMaxRate; settings->outMaxRate = s.outMaxRate; changed( true ); } } void ConfigDialog::addStatsClicked() { InterfaceSettings* settings = getItemSettings(); if ( !settings ) return; StatsRule rule; int oldRuleCount = statsModel->rowCount(); StatsConfig dlg( settings, mCalendar, rule, true ); if ( dlg.exec() ) { rule = dlg.settings(); QSortFilterProxyModel* proxy = static_cast(mDlg->statsView->model()); QModelIndex index = statsModel->addRule( rule ); mDlg->statsView->setCurrentIndex( proxy->mapFromSource( index ) ); settings->statsRules = statsModel->getRules(); mDlg->modifyStats->setEnabled( true ); mDlg->removeStats->setEnabled( true ); updateWarnText( oldRuleCount ); changed( true ); } } void ConfigDialog::modifyStatsClicked() { InterfaceSettings* settings = getItemSettings(); if ( !settings || mDlg->statsView->model()->rowCount() < 1 ) return; QModelIndex index = mDlg->statsView->selectionModel()->currentIndex(); if ( !index.isValid() ) return; QSortFilterProxyModel* proxy = static_cast(mDlg->statsView->model()); index = proxy->mapToSource( index ); StatsRule s = statsModel->item( index.row(), 0 )->data( Qt::UserRole ).value(); StatsConfig dlg( settings, mCalendar, s, false ); if ( dlg.exec() ) { s = dlg.settings(); statsModel->modifyRule( index, s ); settings->statsRules = statsModel->getRules(); changed( true ); } } void ConfigDialog::removeStatsClicked() { InterfaceSettings* settings = getItemSettings(); if ( !settings || mDlg->statsView->model()->rowCount() < 1 ) return; QModelIndex index = mDlg->statsView->selectionModel()->currentIndex(); if ( !index.isValid() ) return; QSortFilterProxyModel* proxy = static_cast(mDlg->statsView->model()); index = proxy->mapToSource( index ); statsModel->removeRow( index.row() ); settings->statsRules = statsModel->getRules(); mDlg->modifyStats->setEnabled( statsModel->rowCount() ); mDlg->removeStats->setEnabled( statsModel->rowCount() ); updateWarnText( statsModel->rowCount() ); changed( true ); } void ConfigDialog::addWarnClicked() { InterfaceSettings* settings = getItemSettings(); if ( !settings ) return; WarnRule warn; WarnConfig dlg( settings, warn, true ); if ( dlg.exec() ) { warn = dlg.settings(); QModelIndex index = warnModel->addWarn( warn ); mDlg->warnView->setCurrentIndex( index ); settings->warnRules = warnModel->getRules(); changed( true ); mDlg->modifyWarn->setEnabled( true ); mDlg->removeWarn->setEnabled( true ); } } void ConfigDialog::modifyWarnClicked() { InterfaceSettings* settings = getItemSettings(); if ( !settings || mDlg->warnView->model()->rowCount() < 1 ) return; const QModelIndex index = mDlg->warnView->selectionModel()->currentIndex(); if ( !index.isValid() ) return; WarnRule warn = mDlg->warnView->model()->data( index.sibling( index.row(), 0 ), Qt::UserRole ).value(); WarnConfig dlg( settings, warn, false ); if ( dlg.exec() ) { warn = dlg.settings(); warnModel->modifyWarn( index, warn ); settings->warnRules = warnModel->getRules(); changed( true ); } } void ConfigDialog::removeWarnClicked() { InterfaceSettings* settings = getItemSettings(); if ( !settings || mDlg->warnView->model()->rowCount() < 1 ) return; const QModelIndex index = mDlg->warnView->selectionModel()->currentIndex(); if ( !index.isValid() ) return; warnModel->removeRow( index.row() ); settings->warnRules = warnModel->getRules(); mDlg->modifyWarn->setEnabled( warnModel->rowCount() ); mDlg->removeWarn->setEnabled( warnModel->rowCount() ); changed( true ); } /****************************************** * * * Interface tab - Statistics * * * ******************************************/ void ConfigDialog::checkBoxStatisticsToggled( bool on ) { InterfaceSettings* settings = getItemSettings(); if ( !settings ) return; settings->activateStatistics = on; if (!mLock) changed( true ); } /****************************************** * * * Interface tab - Context Menu * * * ******************************************/ void ConfigDialog::buttonAddCommandSelected() { InterfaceSettings* settings = getItemSettings(); if ( !settings ) return; InterfaceCommand cmd; cmd.runAsRoot = false; cmd.menuText = QString(); cmd.command = QString(); settings->commands.append( cmd ); QTreeWidgetItem* item = new QTreeWidgetItem(); item->setCheckState( 0, Qt::Unchecked ); item->setFlags( item->flags() | Qt::ItemIsEditable ); mDlg->listViewCommands->addTopLevelItem( item ); mDlg->listViewCommands->setCurrentItem( item ); if (!mLock) changed( true ); } void ConfigDialog::buttonRemoveCommandSelected() { InterfaceSettings* settings = getItemSettings(); if ( !settings ) return; if ( !mDlg->listViewCommands->currentItem() ) return; QTreeWidgetItem *item = mDlg->listViewCommands->currentItem(); int index = mDlg->listViewCommands->indexOfTopLevelItem( item ); mDlg->listViewCommands->takeTopLevelItem( index ); delete item; QList cmds; QTreeWidgetItemIterator i( mDlg->listViewCommands ); while ( QTreeWidgetItem * item = *i ) { InterfaceCommand cmd; cmd.runAsRoot = item->checkState( 0 ); cmd.menuText = item->text( 1 ); cmd.command = item->text( 2 ); cmds.append( cmd ); ++i; } settings->commands = cmds; if (!mLock) changed( true ); } void ConfigDialog::setUpDownButtons( QTreeWidgetItem* item ) { if ( !item ) { mDlg->pushButtonUp->setEnabled( false ); mDlg->pushButtonDown->setEnabled( false ); return; } if (mDlg->listViewCommands->indexOfTopLevelItem( item ) == 0 ) mDlg->pushButtonUp->setEnabled( false ); else mDlg->pushButtonUp->setEnabled( true ); if (mDlg->listViewCommands->indexOfTopLevelItem( item ) == mDlg->listViewCommands->topLevelItemCount() - 1 ) mDlg->pushButtonDown->setEnabled( false ); else mDlg->pushButtonDown->setEnabled( true ); } void ConfigDialog::buttonCommandUpSelected() { InterfaceSettings* settings = getItemSettings(); if ( !settings ) return; if ( !mDlg->listViewCommands->currentItem() ) return; QTreeWidgetItem* item = mDlg->listViewCommands->currentItem(); int index = mDlg->listViewCommands->indexOfTopLevelItem( item ); if ( index == 0 ) return; mDlg->listViewCommands->takeTopLevelItem( index ); mDlg->listViewCommands->insertTopLevelItem( index - 1, item ); mDlg->listViewCommands->setCurrentItem( item ); setUpDownButtons( item ); QList cmds; QTreeWidgetItemIterator i( mDlg->listViewCommands ); while ( QTreeWidgetItem * item = *i ) { InterfaceCommand cmd; cmd.runAsRoot = item->checkState( 0 ); cmd.menuText = item->text( 1 ); cmd.command = item->text( 2 ); cmds.append( cmd ); ++i; } settings->commands = cmds; if (!mLock) changed( true ); } void ConfigDialog::buttonCommandDownSelected() { InterfaceSettings* settings = getItemSettings(); if ( !settings ) return; if ( !mDlg->listViewCommands->currentItem() ) return; QTreeWidgetItem* item = mDlg->listViewCommands->currentItem(); int index = mDlg->listViewCommands->indexOfTopLevelItem( item ); if ( index == mDlg->listViewCommands->topLevelItemCount() - 1 ) return; mDlg->listViewCommands->takeTopLevelItem( index ); mDlg->listViewCommands->insertTopLevelItem( index + 1, item ); mDlg->listViewCommands->setCurrentItem( item ); setUpDownButtons( item ); QList cmds; QTreeWidgetItemIterator i( mDlg->listViewCommands ); while ( QTreeWidgetItem * item = *i ) { InterfaceCommand cmd; cmd.runAsRoot = item->checkState( 0 ); cmd.menuText = item->text( 1 ); cmd.command = item->text( 2 ); cmds.append( cmd ); ++i; } settings->commands = cmds; if (!mLock) changed( true ); } void ConfigDialog::listViewCommandsSelectionChanged( QTreeWidgetItem* item, QTreeWidgetItem* ) { mDlg->pushButtonRemoveCommand->setEnabled( item != NULL ); setUpDownButtons( item ); } void ConfigDialog::listViewCommandsChanged( QTreeWidgetItem* item, int column ) { InterfaceSettings* settings = getItemSettings(); if ( !settings ) return; int row = mDlg->listViewCommands->indexOfTopLevelItem( item ); InterfaceCommand& cmd = settings->commands[row]; switch ( column ) { case 0: cmd.runAsRoot = item->checkState( 0 ); break; case 1: cmd.menuText = item->text( 1 ); break; case 2: cmd.command = item->text( 2 ); } if (!mLock) changed( true ); } /****************************************** * * * ToolTip tab * * * ******************************************/ void ConfigDialog::setupToolTipMap() { // Cannot make this data static as the i18n macro doesn't seem // to work when called to early i.e. before setting the catalogue. mToolTips.insert( INTERFACE, i18n( "Interface" ) ); mToolTips.insert( STATUS, i18n( "Status" ) ); mToolTips.insert( UPTIME, i18n( "Connection Time" ) ); mToolTips.insert( IP_ADDRESS, i18n( "IP Address" ) ); mToolTips.insert( SCOPE, i18n( "Scope & Flags" ) ); mToolTips.insert( HW_ADDRESS, i18n( "MAC Address" ) ); mToolTips.insert( BCAST_ADDRESS, i18n( "Broadcast Address" ) ); mToolTips.insert( GATEWAY, i18n( "Default Gateway" ) ); mToolTips.insert( PTP_ADDRESS, i18n( "PtP Address" ) ); mToolTips.insert( RX_PACKETS, i18n( "Packets Received" ) ); mToolTips.insert( TX_PACKETS, i18n( "Packets Sent" ) ); mToolTips.insert( RX_BYTES, i18n( "Bytes Received" ) ); mToolTips.insert( TX_BYTES, i18n( "Bytes Sent" ) ); mToolTips.insert( DOWNLOAD_SPEED, i18n( "Download Speed" ) ); mToolTips.insert( UPLOAD_SPEED, i18n( "Upload Speed" ) ); mToolTips.insert( ESSID, i18n( "ESSID" ) ); mToolTips.insert( MODE, i18n( "Mode" ) ); mToolTips.insert( FREQUENCY, i18n( "Frequency" ) ); mToolTips.insert( BIT_RATE, i18n( "Bit Rate" ) ); mToolTips.insert( ACCESS_POINT, i18n( "Access Point" ) ); mToolTips.insert( LINK_QUALITY, i18n( "Link Quality" ) ); #ifndef __linux__ mToolTips.insert( NICK_NAME, i18n( "Nickname" ) ); #endif mToolTips.insert( ENCRYPTION, i18n( "Encryption" ) ); } void ConfigDialog::setupToolTipTab() { mDlg->listBoxDisplay->clear(); mDlg->listBoxAvailable->clear(); foreach ( QString tip, mToolTips ) { if ( mToolTipContent & mToolTips.key( tip ) ) mDlg->listBoxDisplay->addItem( tip ); else mDlg->listBoxAvailable->addItem( tip ); } if ( mDlg->listBoxDisplay->count() > 0 ) mDlg->listBoxDisplay->item( 0 )->setSelected( true ); if ( mDlg->listBoxAvailable->count() > 0 ) mDlg->listBoxAvailable->item( 0 )->setSelected( true ); mDlg->pushButtonRemoveToolTip->setEnabled( (mDlg->listBoxDisplay->count() > 0) ); mDlg->pushButtonAddToolTip->setEnabled( (mDlg->listBoxAvailable->count() > 0) ); } void ConfigDialog::moveTips( QListWidget *from, QListWidget* to ) { QList selectedItems = from->selectedItems(); foreach ( QListWidgetItem *selected, selectedItems ) { quint32 key = mToolTips.key( selected->text() ); int newIndex = -1; int count = to->count(); for ( int i = 0; i < count; i++ ) { QListWidgetItem *item = to->item( i ); if ( mToolTips.key( item->text() ) > key ) { newIndex = i; break; } } if ( newIndex < 0 ) newIndex = count; selected->setSelected( false ); from->takeItem( from->row( selected ) ); to->insertItem( newIndex, selected ); mDlg->pushButtonAddToolTip->setEnabled( (mDlg->listBoxAvailable->count() > 0) ); mDlg->pushButtonRemoveToolTip->setEnabled( (mDlg->listBoxDisplay->count() > 0) ); changed( true ); } mToolTipContent = 0; for ( int i = 0; i < mDlg->listBoxDisplay->count(); i++ ) mToolTipContent += mToolTips.key( mDlg->listBoxDisplay->item( i )->text() ); } void ConfigDialog::buttonAddToolTipSelected() { // Support extended selection if ( mDlg->listBoxAvailable->count() == 0 ) return; moveTips( mDlg->listBoxAvailable, mDlg->listBoxDisplay ); } void ConfigDialog::buttonRemoveToolTipSelected() { // Support extended selection if ( mDlg->listBoxDisplay->count() == 0 ) return; moveTips( mDlg->listBoxDisplay, mDlg->listBoxAvailable ); } /****************************************** * * * General tab * * * ******************************************/ void ConfigDialog::buttonNotificationsSelected() { KNotifyConfigWidget::configure( this, "knemo" ); } #include "configdialog.moc" diff --git a/src/kcm/configdlg.ui b/src/kcm/configdlg.ui index 8f95112..55edc51 100644 --- a/src/kcm/configdlg.ui +++ b/src/kcm/configdlg.ui @@ -1,1116 +1,1098 @@ ConfigDlg - + + 0 + + + 0 + + + 0 + + 0 Start KNemo automatically when you login 0 Interfaces This lists the interfaces that you wish to monitor. Please use the names understood by <i>ifconfig</i> ('eth0', 'wlan0', 'ppp0', etc.), or click "Add all interfaces" below to include all of the interfaces currently found on your system. true Add a new interface Add all interfaces false Delete the selected interface Qt::Vertical 0 0 false Alias: false false You can enter an alias for the interface. KNemo will use it to differentiate interfaces when it displays tooltips, dialogs, etc. false 0 0 0 Icon Appearance Icon hiding: Do not hide Hide when disconnected Hide when unavailable Icon theme: false Unavailable false Disconnected false Connected false Incoming traffic false Outgoing traffic false Incoming and outgoing traffic false Theme Settings Incoming traffic: Outgoing traffic: Disconnected: Unavailable: false Icon Font: - + Qt::Horizontal QSizePolicy::Expanding 0 0 Advanced... Qt::Vertical 0 0 Statistics Activate statistics false Custom Billing Periods Log traffic statistics according to customized rules. When a custom billing period ends, it will automatically start a new billing period with the same rules. false false Add a new entry Add... Modify... Remove the selected entry Remove Qt::Vertical QSizePolicy::Expanding 0 0 false Traffic Notifications When interface traffic exceeds the limit set by a rule, KNemo will emit a notification. The notification will appear once per period. false false Add a new entry Add... Modify... Remove the selected entry Remove Qt::Vertical QSizePolicy::Expanding 0 0 Qt::Vertical 0 0 Context Menu In this area you can add the custom entries for your context menu: <ol><li>push the <b>Add</b> button to add a new entry in the list;</li><li>edit the entry by double clicking in the <b>Menu text</b> and <b>Command</b> columns.</li></ol>If you need to execute the command as root user check the corresponding <b>Root</b> check box. false false 3 Root Menu text Command Add a new entry Remove the selected entry Qt::Vertical QSizePolicy::Expanding 0 0 Move the selected entry up Move the selected entry down ToolTip 0 0 Available: false QAbstractItemView::ExtendedSelection Qt::Vertical QSizePolicy::Expanding 0 0 Qt::Horizontal QSizePolicy::Fixed 5 20 Add the selected entry to the tray icon's tooltip Remove the selected entry from the tray icon's tooltip Qt::Horizontal QSizePolicy::Fixed 5 20 Qt::Vertical QSizePolicy::Expanding 0 0 0 0 Active: false QAbstractItemView::ExtendedSelection Wireless specific information will only appear in the tooltips of wireless devices true General Notifications Configure Notifications... Update interval Update interface information every false Set how often KNemo polls interfaces for information. A lower value will speed up reaction to changes, but it will also increase CPU load. Qt::Horizontal QSizePolicy::Expanding 0 0 Report traffic rate in bit/s Statistics Autosave interval: false - + Save interface statistics every <i>n</i> seconds. If 0, KNemo will only save statistics when it closes. - - 60 + + At shutdown + + + sec 0 300 - - sec - - - At shutdown + + 60 Qt::Horizontal QSizePolicy::Expanding 0 0 Statistics directory: false KNemo will log interface statistics in this directory. Qt::Vertical QSizePolicy::Expanding 0 0 - - KFontComboBox - KComboBox -
kfontcombobox.h
-
KColorButton QPushButton
kcolorbutton.h
- - KComboBox - QComboBox -
kcombobox.h
-
KUrlRequester QFrame
kurlrequester.h
-
- - KIntNumInput - QWidget -
knuminput.h
+ 1
checkBoxStartKNemo tabWidgetConfiguration listBoxInterfaces pushButtonNew pushButtonAll pushButtonDelete lineEditAlias ifaceTab comboHiding comboBoxIconTheme colorIncoming colorOutgoing colorDisabled colorUnavailable iconFont advancedButton checkBoxStatistics statsView addStats modifyStats removeStats warnView addWarn modifyWarn removeWarn listViewCommands pushButtonAddCommand pushButtonRemoveCommand pushButtonUp pushButtonDown listBoxAvailable pushButtonAddToolTip pushButtonRemoveToolTip listBoxDisplay pushButtonNotifications comboBoxPoll useBitrate numInputSaveInterval lineEditStatisticsDir - - knuminput.h - knuminput.h - knuminput.h - knuminput.h - knuminput.h - knuminput.h - knuminput.h - knuminput.h - knuminput.h - knuminput.h - knuminput.h - checkBoxStatistics toggled(bool) groupBox setEnabled(bool) 429 148 496 437 checkBoxStatistics toggled(bool) groupBox_2 setEnabled(bool) 431 146 426 162
diff --git a/src/kcm/statscfg.ui b/src/kcm/statscfg.ui index 84b6bef..55b1ccb 100644 --- a/src/kcm/statscfg.ui +++ b/src/kcm/statscfg.ui @@ -1,451 +1,462 @@ StatsCfg - + + 0 + + + 0 + + + 0 + + 0 0 Billing Period Rules Qt::Horizontal QSizePolicy::Fixed 20 0 Start date: - + <p>By default, this shows the start date of the current month or billing period. If you change the date, KNemo will recalculate billing periods from that date forward. Any billing periods before that date will remain unmodified.</p><p>If you set an erroneous date, just select an earlier good billing date, and KNemo will repair it.</p> Qt::Horizontal QSizePolicy::Fixed 20 0 Billing period length: - + 1 1000 Qt::Vertical 0 0 Off-Peak Rules Log off-peak traffic Qt::Horizontal QSizePolicy::Fixed 20 0 false Off-peak start time: false h:00 AP Qt::Horizontal QSizePolicy::Fixed 20 0 false Off-peak end time: false h:00 AP Qt::Horizontal QSizePolicy::Fixed 20 0 false Weekends count as off-peak Qt::Horizontal QSizePolicy::Fixed 40 0 false Weekend starts: false false h:00 AP Qt::Horizontal QSizePolicy::Fixed 40 0 false Weekend ends: false false h:00 AP Qt::Vertical 0 0 Qt::Vertical 0 0 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::RestoreDefaults + + + - - KIntSpinBox - QSpinBox -
knuminput.h
-
DateEditWidget - QComboBox + QWidget
dateeditwidget.h
logOffpeak toggled(bool) label_4 setEnabled(bool) 106 55 106 77 logOffpeak toggled(bool) startTime setEnabled(bool) 251 54 259 78 logOffpeak toggled(bool) label_6 setEnabled(bool) 154 49 123 117 logOffpeak toggled(bool) stopTime setEnabled(bool) 204 48 235 123 logOffpeak toggled(bool) doWeekend setEnabled(bool) 71 47 63 156
diff --git a/src/kcm/statsconfig.cpp b/src/kcm/statsconfig.cpp index 8f62076..f71656f 100644 --- a/src/kcm/statsconfig.cpp +++ b/src/kcm/statsconfig.cpp @@ -1,145 +1,146 @@ /* This file is part of KNemo Copyright (C) 2010 John Stamp 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 "statsconfig.h" +#include #include #include #include -StatsConfig::StatsConfig( const InterfaceSettings * settings, const KCalendarSystem *calendar, const StatsRule &rule, bool addRule ) : KDialog(), +StatsConfig::StatsConfig( const InterfaceSettings * settings, const KCalendarSystem *calendar, const StatsRule &rule, bool addRule ) : QDialog(), mSettings( settings ), mCal( calendar ), mAddRule( addRule ) { // Do this for the sake of KDateEdit KGlobal::locale()->setCalendarSystem( mCal->calendarSystem() ); - mDlg.setupUi( mainWidget() ); - setButtons( KDialog::Default | KDialog::Ok | KDialog::Cancel ); + mDlg.setupUi( this ); for ( int i = 1; i <= mCal->daysInWeek( QDate::currentDate() ); ++i ) { mDlg.weekendStartDay->addItem( mCal->weekDayName( i ) ); mDlg.weekendStopDay->addItem( mCal->weekDayName( i ) ); } mDlg.periodUnits->addItem( i18n( "Days" ), KNemoStats::Day ); mDlg.periodUnits->addItem( i18n( "Weeks" ), KNemoStats::Week ); mDlg.periodUnits->addItem( i18n( "Months" ), KNemoStats::Month ); //mDlg.periodUnits->addItem( i18n( "Years" ), KNemoStats::Year ); - connect( this, SIGNAL( defaultClicked() ), SLOT( setDefaults() ) ); + connect( mDlg.buttonBox, SIGNAL( accepted() ), SLOT( accept() ) ); + connect( mDlg.buttonBox, SIGNAL( rejected() ), SLOT( reject() ) ); + connect( mDlg.buttonBox, SIGNAL( clicked( QAbstractButton* ) ), SLOT( setDefaults( QAbstractButton* ) ) ); connect( mDlg.logOffpeak, SIGNAL( toggled( bool ) ), SLOT( enableItems() ) ); connect( mDlg.doWeekend, SIGNAL( toggled( bool ) ), SLOT( enableItems() ) ); QDate dt = rule.startDate; if ( !dt.isValid() ) dt = QDate::currentDate().addDays( 1 - mCal->day( QDate::currentDate() ) ); mDlg.startDate->setDate( dt ); setControls( rule ); } void StatsConfig::setControls( const StatsRule &s ) { mDlg.periodCount->setValue( s.periodCount ); int index = mDlg.periodUnits->findData( s.periodUnits ); mDlg.periodUnits->setCurrentIndex( index ); mDlg.logOffpeak->setChecked( s.logOffpeak ); mDlg.startTime->setTime( s.offpeakStartTime ); mDlg.stopTime->setTime( s.offpeakEndTime ); mDlg.doWeekend->setChecked( s.weekendIsOffpeak ); mDlg.weekendStartDay->setCurrentIndex( s.weekendDayStart - 1 ); mDlg.weekendStopDay->setCurrentIndex( s.weekendDayEnd - 1 ); mDlg.weekendStartTime->setTime( s.weekendTimeStart ); mDlg.weekendStopTime->setTime( s.weekendTimeEnd ); } -void StatsConfig::setDefaults() +void StatsConfig::setDefaults( QAbstractButton* button ) { - StatsRule s; - mDlg.startDate->setDate( QDate::currentDate().addDays( 1 - mCal->day( QDate::currentDate() ) ) ); - setControls( s ); + if (static_cast(button) == mDlg.buttonBox->button(QDialogButtonBox::RestoreDefaults) ) { + StatsRule s; + mDlg.startDate->setDate( QDate::currentDate().addDays( 1 - mCal->day( QDate::currentDate() ) ) ); + setControls( s ); + } } StatsRule StatsConfig::settings() { StatsRule rule; rule.startDate = mDlg.startDate->date(); rule.periodUnits = mDlg.periodUnits->itemData( mDlg.periodUnits->currentIndex() ).toInt(); rule.periodCount = mDlg.periodCount->value(); rule.logOffpeak = mDlg.logOffpeak->isChecked(); rule.offpeakStartTime = mDlg.startTime->time(); rule.offpeakEndTime = mDlg.stopTime->time(); rule.weekendIsOffpeak = mDlg.doWeekend->isChecked(); rule.weekendDayStart = mDlg.weekendStartDay->currentIndex() + 1; rule.weekendDayEnd = mDlg.weekendStopDay->currentIndex() + 1; rule.weekendTimeStart = mDlg.weekendStartTime->time(); rule.weekendTimeEnd = mDlg.weekendStopTime->time(); return rule; } void StatsConfig::enableItems() { bool enabledItems; if ( mDlg.logOffpeak->isChecked() && mDlg.doWeekend->isChecked() ) { enabledItems = true; } else { enabledItems = false; } mDlg.label_9->setEnabled( enabledItems ); mDlg.label_10->setEnabled( enabledItems ); mDlg.weekendStartDay->setEnabled( enabledItems ); mDlg.weekendStopDay->setEnabled( enabledItems ); mDlg.weekendStartTime->setEnabled( enabledItems ); mDlg.weekendStopTime->setEnabled( enabledItems ); } -void StatsConfig::slotButtonClicked( int button ) +void StatsConfig::accept() { - if ( mAddRule && ( (button == Ok) || (button == Apply) ) ) + bool duplicateEntry = false; + StatsRule testRule = settings(); + QList statsRules = mSettings->statsRules; + foreach ( StatsRule rule, statsRules ) { - bool duplicateEntry = false; - StatsRule testRule = settings(); - QList statsRules = mSettings->statsRules; - foreach ( StatsRule rule, statsRules ) + if ( rule == testRule ) { - if ( rule == testRule ) - { - duplicateEntry = true; - break; - } + duplicateEntry = true; + break; } - if ( duplicateEntry ) - KMessageBox::sorry( 0, - i18n( "Another rule already starts on %1. " - "Please choose another date.", - mCal->formatDate( mDlg.startDate->date(), KLocale::LongDate ) ) - ); - else - KDialog::slotButtonClicked( button ); } - else - KDialog::slotButtonClicked( button ); + if ( duplicateEntry ) + { + KMessageBox::sorry( 0, + i18n( "Another rule already starts on %1. " + "Please choose another date.", + mCal->formatDate( mDlg.startDate->date(), KLocale::LongDate ) ) + ); + } else { + QDialog::accept(); + } } #include "statsconfig.moc" diff --git a/src/kcm/statsconfig.h b/src/kcm/statsconfig.h index 12177f5..8559ac0 100644 --- a/src/kcm/statsconfig.h +++ b/src/kcm/statsconfig.h @@ -1,46 +1,45 @@ /* This file is part of KNemo Copyright (C) 2010 John Stamp 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. */ #ifndef STATSCONFIG_H #define STATSCONFIG_H -#include +#include #include "data.h" #include "ui_statscfg.h" -class StatsConfig : public KDialog +class StatsConfig : public QDialog { Q_OBJECT public: StatsConfig( const InterfaceSettings *settings, const KCalendarSystem *calendar, const StatsRule &rule, bool addRule = true ); StatsRule settings(); private: Ui::StatsCfg mDlg; const InterfaceSettings *mSettings; const KCalendarSystem *mCal; bool mAddRule; void setControls( const StatsRule &s ); private slots: - void setDefaults(); + void setDefaults( QAbstractButton* ); void enableItems(); -protected: - virtual void slotButtonClicked( int button ); + void accept(); }; #endif diff --git a/src/kcm/themecfg.ui b/src/kcm/themecfg.ui index 731e16c..4273912 100644 --- a/src/kcm/themecfg.ui +++ b/src/kcm/themecfg.ui @@ -1,280 +1,282 @@ ThemeCfg 0 Traffic Traffic activity threshold: - + If you are on a network with a lot of low-level traffic, you can increase this value so the tray icon does not constantly report activity. packets/sec 1000 Traffic Rate Visualization If checked, the transmit and receive colors will change according to the traffic rate. As the traffic rate increases, the color will change from the default color, to the max rate color. Change color according to max visual rate If this is checked, the Netload bar graphs will use a constant scale based on the maximum rates below. If unchecked, the bar graphs will change scale according to recent traffic rates. Always scale bar graphs to max visual rate false Max Visual Rate Incoming traffic: - + <p>The maximum incoming rate for this connection.</p><p>This does <b>not</b> affect the actual traffic rate, only how KNemo displays it.</p> KiB/sec 1 1048576 4 false Color: false Outgoing traffic: - + <p>The maximum outgoing rate for this connection.</p><p>This does <b>not</b> affect the actual traffic rate, only how KNemo displays it.</p> KiB/sec 1 1048576 4 false Color: false Qt::Vertical 0 0 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::RestoreDefaults + + + KColorButton QPushButton
kcolorbutton.h
- - KIntSpinBox - QSpinBox -
knuminput.h
-
spinBoxTrafficThreshold checkBarScale checkDynColor rxMaxRate colorIncomingMax txMaxRate colorOutgoingMax checkDynColor toggled(bool) label setEnabled(bool) 175 172 204 201 checkDynColor toggled(bool) label_2 setEnabled(bool) 136 172 206 231 checkDynColor toggled(bool) colorIncomingMax setEnabled(bool) 319 172 335 201 checkDynColor toggled(bool) colorOutgoingMax setEnabled(bool) 305 172 335 231
diff --git a/src/kcm/themeconfig.cpp b/src/kcm/themeconfig.cpp index d96fe2e..3842042 100644 --- a/src/kcm/themeconfig.cpp +++ b/src/kcm/themeconfig.cpp @@ -1,92 +1,95 @@ /* This file is part of KNemo Copyright (C) 2009, 2010 John Stamp 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 "themeconfig.h" -ThemeConfig::ThemeConfig( const InterfaceSettings s ) : KDialog(), +ThemeConfig::ThemeConfig( const InterfaceSettings s ) : QDialog(), mSettings( s ) { - mDlg.setupUi( mainWidget() ); - setButtons( KDialog::Default | KDialog::Ok | KDialog::Cancel ); + mDlg.setupUi( this ); if ( mSettings.iconTheme != NETLOAD_THEME ) mDlg.checkBarScale->hide(); if ( mSettings.iconTheme != NETLOAD_THEME && mSettings.iconTheme != TEXT_THEME ) { mDlg.rateGroup->hide(); mDlg.maxRateGroup->hide(); } mDlg.spinBoxTrafficThreshold->setValue( mSettings.trafficThreshold ); mDlg.txMaxRate->setValue( mSettings.outMaxRate ); mDlg.rxMaxRate->setValue( mSettings.inMaxRate ); mDlg.checkBarScale->setChecked( mSettings.barScale ); mDlg.checkDynColor->setChecked( mSettings.dynamicColor ); mDlg.colorIncomingMax->setColor( mSettings.colorIncomingMax ); mDlg.colorOutgoingMax->setColor( mSettings.colorOutgoingMax ); updateRateGroup(); - connect( this, SIGNAL( defaultClicked() ), SLOT( setDefaults() ) ); + connect( mDlg.buttonBox, SIGNAL( accepted() ), SLOT( accept() ) ); + connect( mDlg.buttonBox, SIGNAL( rejected() ), SLOT( reject() ) ); + connect( mDlg.buttonBox, SIGNAL( clicked( QAbstractButton* ) ), SLOT( setDefaults( QAbstractButton* ) ) ); connect( mDlg.checkBarScale, SIGNAL( toggled( bool ) ), SLOT( updateRateGroup() ) ); connect( mDlg.checkDynColor, SIGNAL( toggled( bool ) ), SLOT( updateRateGroup() ) ); } -void ThemeConfig::setDefaults() +void ThemeConfig::setDefaults( QAbstractButton* button ) { - InterfaceSettings s; + if (static_cast(button) == mDlg.buttonBox->button(QDialogButtonBox::RestoreDefaults) ) { + InterfaceSettings s; - mDlg.spinBoxTrafficThreshold->setValue( s.trafficThreshold ); + mDlg.spinBoxTrafficThreshold->setValue( s.trafficThreshold ); - mDlg.txMaxRate->setValue( s.outMaxRate ); - mDlg.rxMaxRate->setValue( s.inMaxRate ); + mDlg.txMaxRate->setValue( s.outMaxRate ); + mDlg.rxMaxRate->setValue( s.inMaxRate ); - mDlg.checkBarScale->setChecked( s.barScale ); - mDlg.checkDynColor->setChecked( s.dynamicColor ); - mDlg.colorIncomingMax->setColor( s.colorIncomingMax ); - mDlg.colorOutgoingMax->setColor( s.colorOutgoingMax ); + mDlg.checkBarScale->setChecked( s.barScale ); + mDlg.checkDynColor->setChecked( s.dynamicColor ); + mDlg.colorIncomingMax->setColor( s.colorIncomingMax ); + mDlg.colorOutgoingMax->setColor( s.colorOutgoingMax ); + } } void ThemeConfig::updateRateGroup() { if ( mDlg.checkBarScale->isChecked() || mDlg.checkDynColor->isChecked() ) mDlg.maxRateGroup->setEnabled( true ); else mDlg.maxRateGroup->setEnabled( false ); } InterfaceSettings ThemeConfig::settings() { mSettings.trafficThreshold = mDlg.spinBoxTrafficThreshold->value(); mSettings.outMaxRate = mDlg.txMaxRate->value(); mSettings.inMaxRate = mDlg.rxMaxRate->value(); mSettings.barScale = mDlg.checkBarScale->isChecked(); mSettings.dynamicColor = mDlg.checkDynColor->isChecked(); mSettings.colorIncomingMax = mDlg.colorIncomingMax->color(); mSettings.colorOutgoingMax = mDlg.colorOutgoingMax->color(); return mSettings; } #include "themeconfig.moc" diff --git a/src/kcm/themeconfig.h b/src/kcm/themeconfig.h index 651038e..ff74da9 100644 --- a/src/kcm/themeconfig.h +++ b/src/kcm/themeconfig.h @@ -1,41 +1,41 @@ /* This file is part of KNemo Copyright (C) 2009, 2010 John Stamp 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. */ #ifndef THEMECONFIG_H #define THEMECONFIG_H -#include +#include #include "data.h" #include "ui_themecfg.h" -class ThemeConfig : public KDialog +class ThemeConfig : public QDialog { Q_OBJECT public: ThemeConfig( const InterfaceSettings s ); InterfaceSettings settings(); private slots: - void setDefaults(); + void setDefaults( QAbstractButton* ); void updateRateGroup(); private: Ui::ThemeCfg mDlg; InterfaceSettings mSettings; }; #endif diff --git a/src/kcm/warncfg.ui b/src/kcm/warncfg.ui index 1a97bde..7feb09e 100644 --- a/src/kcm/warncfg.ui +++ b/src/kcm/warncfg.ui @@ -1,290 +1,283 @@ WarnCfg - + + 0 + + + 0 + + + 0 + + 0 Notification Rules Traffic type: Peak Offpeak Peak and offpeak Traffic direction: Incoming Outgoing Incoming and outgoing 0 0 Notify when traffic exceeds: within: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter Qt::Horizontal 0 0 - - - - 0 - 0 - - + When traffic for a month or billing period exceeds this limit, KNemo will emit a notification. The notification will appear once per session. + + 1 + 0.100000000000000 + + 9999.000000000000000 + 0.100000000000000 - - - - - 1 - 0 0 -1 - + 1 1000 0 0 Notification Text Custom notification text - + false false + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::RestoreDefaults + + + - - - KDoubleNumInput - QWidget -
knuminput.h
-
- - KIntSpinBox - QSpinBox -
knuminput.h
-
- - KTextEdit - QTextEdit -
ktextedit.h
-
-
trafficType trafficDirection threshold trafficUnits periodCount periodUnits customTextCheck customTextEdit customTextCheck toggled(bool) legend setEnabled(bool) 201 246 241 350 customTextCheck toggled(bool) customTextEdit setEnabled(bool) 140 247 151 286
diff --git a/src/kcm/warnconfig.cpp b/src/kcm/warnconfig.cpp index 9b53a3b..7e59635 100644 --- a/src/kcm/warnconfig.cpp +++ b/src/kcm/warnconfig.cpp @@ -1,140 +1,139 @@ /* This file is part of KNemo Copyright (C) 2010 John Stamp 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 #include "warnconfig.h" +#include #include WarnConfig::WarnConfig( const InterfaceSettings *settings, const WarnRule &warn, bool addRule ) - : KDialog(), + : QDialog(), mSettings( settings ), mAddRule( addRule ) { - mDlg.setupUi( mainWidget() ); - setButtons( KDialog::Default | KDialog::Ok | KDialog::Cancel ); + mDlg.setupUi( this ); QList statsRules = settings->statsRules; bool offpeakTracking = false; foreach( StatsRule stats, statsRules ) { if ( stats.logOffpeak ) { offpeakTracking = true; break; } } if ( !offpeakTracking ) { mDlg.trafficTypeLabel->hide(); mDlg.trafficType->hide(); } mDlg.trafficUnits->addItem( i18n( "KiB" ), KNemoStats::UnitK ); mDlg.trafficUnits->addItem( i18n( "MiB" ), KNemoStats::UnitM ); mDlg.trafficUnits->addItem( i18n( "GiB" ), KNemoStats::UnitG ); mDlg.periodUnits->addItem( i18n( "Hours" ), KNemoStats::Hour ); mDlg.periodUnits->addItem( i18n( "Days" ), KNemoStats::Day ); mDlg.periodUnits->addItem( i18n( "Weeks" ), KNemoStats::Week ); mDlg.periodUnits->addItem( i18n( "Months" ), KNemoStats::Month ); if ( settings->statsRules.count() ) mDlg.periodUnits->addItem( i18n( "Billing Periods" ), KNemoStats::BillPeriod ); //mDlg.periodUnits->addItem( i18n( "Years" ), KNemoStats::Year ); mDlg.legend->setText( i18n( "%i = interface, %a = interface alias,
" "%t = traffic threshold, %c = current traffic" ) ); - connect( this, SIGNAL( defaultClicked() ), SLOT( setDefaults() ) ); + connect( mDlg.buttonBox, SIGNAL( accepted() ), SLOT( accept() ) ); + connect( mDlg.buttonBox, SIGNAL( rejected() ), SLOT( reject() ) ); + connect( mDlg.buttonBox, SIGNAL( clicked( QAbstractButton* ) ), SLOT( setDefaults( QAbstractButton* ) ) ); connect( mDlg.threshold, SIGNAL( valueChanged( double ) ), this, SLOT( thresholdChanged( double ) ) ); setControls( warn ); } void WarnConfig::setControls( const WarnRule &warn ) { mDlg.trafficType->setCurrentIndex( warn.trafficType ); mDlg.trafficDirection->setCurrentIndex( warn.trafficDirection ); mDlg.threshold->setValue( warn.threshold ); int index = mDlg.trafficUnits->findData( warn.trafficUnits ); mDlg.trafficUnits->setCurrentIndex( index ); mDlg.periodCount->setValue( warn.periodCount ); index = mDlg.periodUnits->findData( warn.periodUnits ); if ( index < 0 ) { index = mDlg.periodUnits->findData( KNemoStats::Month ); } mDlg.periodUnits->setCurrentIndex( index ); mDlg.customTextEdit->setPlainText( warn.customText ); mDlg.customTextCheck->setChecked( !warn.customText.trimmed().isEmpty() ); } WarnRule WarnConfig::settings() { WarnRule warn; warn.trafficType = mDlg.trafficType->currentIndex(); warn.trafficDirection = mDlg.trafficDirection->currentIndex(); warn.threshold = mDlg.threshold->value(); warn.trafficUnits = mDlg.trafficUnits->itemData( mDlg.trafficUnits->currentIndex() ).toInt(); warn.periodCount = mDlg.periodCount->value(); warn.periodUnits = mDlg.periodUnits->itemData( mDlg.periodUnits->currentIndex() ).toInt(); if ( mDlg.customTextCheck->isChecked() ) warn.customText = mDlg.customTextEdit->toPlainText().trimmed(); else warn.customText = QString(); return warn; } void WarnConfig::thresholdChanged( double val ) { double test = round(val*10.0)/10.0; if ( val != test ) mDlg.threshold->setValue( test ); } -void WarnConfig::setDefaults() +void WarnConfig::setDefaults(QAbstractButton* button) { - WarnRule warn; - setControls( warn ); + if (static_cast(button) == mDlg.buttonBox->button(QDialogButtonBox::RestoreDefaults) ) { + WarnRule warn; + setControls( warn ); + } } -void WarnConfig::slotButtonClicked( int button ) +void WarnConfig::accept() { WarnRule testRule = settings(); - if ( mAddRule && ( (button == Ok) || (button == Apply) ) ) + bool duplicateEntry = false; + QList warnRules = mSettings->warnRules; + foreach ( WarnRule rule, warnRules ) { - bool duplicateEntry = false; - QList warnRules = mSettings->warnRules; - foreach ( WarnRule rule, warnRules ) + if ( rule == testRule ) { - if ( rule == testRule ) - { - duplicateEntry = true; - break; - } + duplicateEntry = true; + break; } - if ( duplicateEntry ) - KMessageBox::sorry( 0, i18n( "This traffic notification rule already exists." ) ); - else - KDialog::slotButtonClicked( button ); } + if ( duplicateEntry ) + KMessageBox::sorry( 0, i18n( "This traffic notification rule already exists." ) ); else - KDialog::slotButtonClicked( button ); + QDialog::accept(); } #include "warnconfig.moc" diff --git a/src/kcm/warnconfig.h b/src/kcm/warnconfig.h index 8c3e185..ca63718 100644 --- a/src/kcm/warnconfig.h +++ b/src/kcm/warnconfig.h @@ -1,45 +1,44 @@ /* This file is part of KNemo Copyright (C) 2010 John Stamp 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. */ #ifndef WARNCONFIG_H #define WARNCONFIG_H -#include +#include #include "data.h" #include "ui_warncfg.h" -class WarnConfig : public KDialog +class WarnConfig : public QDialog { Q_OBJECT public: WarnConfig( const InterfaceSettings *settings, const WarnRule &warn, bool addRule = true ); WarnRule settings(); private: Ui::WarnCfg mDlg; const InterfaceSettings *mSettings; bool mAddRule; void setControls( const WarnRule &warn ); private slots: - void setDefaults(); + void accept(); + void setDefaults(QAbstractButton* button); void thresholdChanged( double ); -protected: - virtual void slotButtonClicked( int button ); }; #endif diff --git a/src/knemod/interfaceplotterdialog.cpp b/src/knemod/interfaceplotterdialog.cpp index 67ad557..3f134ba 100644 --- a/src/knemod/interfaceplotterdialog.cpp +++ b/src/knemod/interfaceplotterdialog.cpp @@ -1,522 +1,523 @@ /* This file is part of KNemo Copyright (C) 2004, 2006 Percy Leonhardt Copyright (C) 2009, 2010 John Stamp Portions adapted from FancyPlotter.cpp in KSysGuard Copyright (c) 1999 - 2002 Chris Schlaeger 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 #include #include #include "global.h" #include "interfaceplotterdialog.h" #include "utils.h" #include #include "plotterconfigdialog.h" #include static const char plot_pixel[] = "Pixel"; static const char plot_distance[] = "Distance"; static const char plot_fontSize[] = "FontSize"; static const char plot_minimumValue[] = "MinimumValue"; static const char plot_maximumValue[] = "MaximumValue"; static const char plot_labels[] = "Labels"; static const char plot_verticalLines[] = "VerticalLines"; static const char plot_horizontalLines[] = "HorizontalLines"; static const char plot_showIncoming[] = "ShowIncoming"; static const char plot_showOutgoing[] = "ShowOutgoing"; static const char plot_automaticDetection[] = "AutomaticDetection"; static const char plot_verticalLinesScroll[] = "VerticalLinesScroll"; static const char plot_colorIncoming[] = "ColorIncoming"; static const char plot_colorOutgoing[] = "ColorOutgoing"; class FancyPlotterLabel : public QLabel { public: FancyPlotterLabel(QWidget *parent) : QLabel(parent) { setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); longHeadingWidth = 0; shortHeadingWidth = 0; textMargin = 0; setLayoutDirection(Qt::LeftToRight); //We do this because we organise the strings ourselves.. is this going to muck it up though for RTL languages? } ~FancyPlotterLabel() { } void setLabel(const QString &name, const QColor &color) { labelName = name; if(indicatorSymbol.isNull()) { if(fontMetrics().inFont(QChar(0x25CF))) indicatorSymbol = QChar(0x25CF); else indicatorSymbol = '#'; } changeLabel(color); } void setValueText(const QString &value) { //value can have multiple strings, separated with the 0x9c character valueText = value.split(QChar(0x9c)); resizeEvent(NULL); update(); } virtual void resizeEvent( QResizeEvent * ) { QFontMetrics fm = fontMetrics(); if(valueText.isEmpty()) { if(longHeadingWidth < width()) setText(longHeadingText); else setText(shortHeadingText); return; } QString value = valueText.first(); int textWidth = fm.boundingRect(value).width(); if(textWidth + longHeadingWidth < width()) setBothText(longHeadingText, value); else if(textWidth + shortHeadingWidth < width()) setBothText(shortHeadingText, value); else { int valueTextCount = valueText.count(); int i; for(i = 1; i < valueTextCount; ++i) { textWidth = fm.boundingRect(valueText.at(i)).width(); if(textWidth + shortHeadingWidth <= width()) { break; } } if(i < valueTextCount) setBothText(shortHeadingText, valueText.at(i)); else setText(noHeadingText + valueText.last()); //This just sets the color of the text } } void changeLabel(const QColor &_color) { color = _color; if ( qApp->layoutDirection() == Qt::RightToLeft ) longHeadingText = QString(": ") + labelName + " " + indicatorSymbol + ""; else longHeadingText = QString("" + indicatorSymbol + " " + labelName + " :"; shortHeadingText = QString("" + indicatorSymbol + ""; noHeadingText = QString(""; textMargin = fontMetrics().width('x') + margin()*2 + frameWidth()*2; longHeadingWidth = fontMetrics().boundingRect(labelName + " :" + indicatorSymbol + " x").width() + textMargin; shortHeadingWidth = fontMetrics().boundingRect(indicatorSymbol).width() + textMargin; setMinimumWidth(shortHeadingWidth); update(); } private: void setBothText(const QString &heading, const QString & value) { if(QApplication::layoutDirection() == Qt::LeftToRight) setText(heading + ' ' + value); else setText("" + value + ' ' + heading); } int textMargin; QString longHeadingText; QString shortHeadingText; QString noHeadingText; int longHeadingWidth; int shortHeadingWidth; QList valueText; QString labelName; QColor color; static QChar indicatorSymbol; }; QChar FancyPlotterLabel::indicatorSymbol; InterfacePlotterDialog::InterfacePlotterDialog( QString name ) : KDialog(), mConfig( KSharedConfig::openConfig() ), mConfigDlg( 0 ), mLabelsWidget( NULL ), mSetPos( true ), mWasShown( false ), mUseBitrate( generalSettings->useBitrate ), mMultiplier( 1024 ), mOutgoingVisible( false ), mIncomingVisible( false ), mName( name ) { setCaption( i18nc( "interface name", "%1 Traffic", mName ) ); setButtons( None ); setContextMenuPolicy( Qt::DefaultContextMenu ); mByteUnits << ki18n( "%1 B/s" ) << ki18n( "%1 KiB/s" ) << ki18n( "%1 MiB/s" ) << ki18n( "%1 GiB/s" ); mBitUnits << ki18n( "%1 bit/s" ) << ki18n( "%1 kbit/s" ) << ki18n( "%1 Mbit/s" ) << ki18n( "%1 Gbit/s" ); mIndicatorSymbol = '#'; QFontMetrics fm(font()); if (fm.inFont(QChar(0x25CF))) mIndicatorSymbol = QChar(0x25CF); QBoxLayout *layout = new QVBoxLayout(this); layout->setContentsMargins(0,0,0,0); layout->setSpacing(0); mainWidget()->setLayout( layout ); mPlotter = new KSignalPlotter( this ); int axisTextWidth = fontMetrics().width(i18nc("Largest axis title", "99999 XXXX")); mPlotter->setMaxAxisTextWidth( axisTextWidth ); mPlotter->setShowAxis( true ); mPlotter->setUseAutoRange( true ); layout->addWidget(mPlotter); /* Create a set of labels underneath the graph. */ mLabelsWidget = new QWidget; layout->addWidget(mLabelsWidget); QBoxLayout *outerLabelLayout = new QHBoxLayout(mLabelsWidget); outerLabelLayout->setSpacing(0); outerLabelLayout->setContentsMargins(0,0,0,0); /* create a spacer to fill up the space up to the start of the graph */ outerLabelLayout->addItem(new QSpacerItem(axisTextWidth + 10, 0, QSizePolicy::Preferred)); mLabelLayout = new QHBoxLayout; outerLabelLayout->addLayout(mLabelLayout); mReceivedLabel = new FancyPlotterLabel( this ); mSentLabel = new FancyPlotterLabel( this ); mLabelLayout->addWidget( mSentLabel ); mLabelLayout->addWidget( mReceivedLabel ); // Restore window size and position. KConfig *config = mConfig.data(); KConfigGroup interfaceGroup( config, confg_interface + mName ); if ( interfaceGroup.hasKey( conf_plotterPos ) ) { QPoint p = interfaceGroup.readEntry( conf_plotterPos, QPoint() ); // See comment in event() mSetPos = false; move( p ); } if ( interfaceGroup.hasKey( conf_plotterSize ) ) { QSize s = interfaceGroup.readEntry( conf_plotterSize, QSize() ); // A little hack so the plotter's data isn't chopped off the first time // the dialog appears mPlotter->resize( s ); resize( s ); } else { // HACK mPlotter->resize( 500, 350 ); // Improve the chance that we have a decent sized dialog // the first time it's shown resize( 500, 350 ); } connect( mPlotter, SIGNAL(axisScaleChanged()), this, SLOT(setPlotterUnits()) ); loadConfig(); } InterfacePlotterDialog::~InterfacePlotterDialog() { if ( mWasShown ) { // If the dialog was never shown, then the position // will be wrong KConfig *config = mConfig.data(); KConfigGroup interfaceGroup( config, confg_interface + mName ); interfaceGroup.writeEntry( conf_plotterSize, size() ); interfaceGroup.writeEntry( conf_plotterPos, pos() ); config->sync(); } } bool InterfacePlotterDialog::event( QEvent *e ) { /* If we do not explicitly call size() and move() at least once then * hiding and showing the dialog will cause it to forget its previous * size and position. */ switch ( e->type() ) { case QEvent::Move: if ( mSetPos && !pos().isNull() ) { mSetPos = false; move( pos() ); } break; case QEvent::Show: mWasShown = true; break; case QEvent::MouseButtonPress: { QMouseEvent *m = static_cast(e); if ( m->button() == Qt::RightButton ) { showContextMenu( m->pos() ); return true; } } default: ;; } return KDialog::event( e ); } void InterfacePlotterDialog::resizeEvent( QResizeEvent* ) { bool showLabels = true;; if( mainWidget()->height() <= mLabelsWidget->sizeHint().height() + mPlotter->minimumHeight() ) showLabels = false; mLabelsWidget->setVisible(showLabels); } void InterfacePlotterDialog::showContextMenu( const QPoint &pos ) { QMenu pm; QAction *action = 0; action = pm.addAction( i18n( "&Properties" ) ); action->setData( 1 ); action = pm.exec( mapToGlobal(pos) ); if ( action ) { switch ( action->data().toInt() ) { case 1: configPlotter(); break; } } } void InterfacePlotterDialog::configPlotter() { if ( mConfigDlg ) return; mConfigDlg = new PlotterConfigDialog( this, mName, &mSettings ); connect( mConfigDlg, SIGNAL( finished() ), this, SLOT( configFinished() ) ); connect( mConfigDlg, SIGNAL( saved() ), this, SLOT( saveConfig() ) ); mConfigDlg->show(); } void InterfacePlotterDialog::configFinished() { - mConfigDlg->delayedDestruct(); + // FIXME + // mConfigDlg->delayedDestruct(); mConfigDlg = 0; } void InterfacePlotterDialog::setPlotterUnits() { // Prevent this being called recursively disconnect( mPlotter, SIGNAL(axisScaleChanged()), this, SLOT(setPlotterUnits()) ); qreal value = mPlotter->currentMaximumRangeValue(); int units = 0; if (value >= pow( mMultiplier, 3)*0.7) //If it's over 0.7GiB, then set the scale to gigabytes { units = 3; } else if (value > pow(mMultiplier,2)) { units = 2; } else if (value > mMultiplier) { units = 1; } mPlotter->setScaleDownBy( pow(mMultiplier, units ) ); if ( mUseBitrate ) mPlotter->setUnit( mBitUnits[units] ); else mPlotter->setUnit( mByteUnits[units] ); // reconnect connect( mPlotter, SIGNAL(axisScaleChanged()), this, SLOT(setPlotterUnits()) ); } void InterfacePlotterDialog::useBitrate( bool useBits ) { // Have to wipe the plotters if we change units if ( mUseBitrate != useBits ) { int nb = mPlotter->numBeams(); for ( int i = 0; i < nb; i++ ) { mPlotter->removeBeam(0); } mOutgoingVisible = false; mIncomingVisible = false; } mUseBitrate = useBits; if ( mUseBitrate ) mMultiplier = 1000; else mMultiplier = 1024; addBeams(); for ( int beamId = 0; beamId < mPlotter->numBeams(); beamId++ ) { QString lastValue = formattedRate( mPlotter->lastValue(beamId), mUseBitrate ); static_cast((static_cast(mLabelLayout->itemAt(beamId)))->widget())->setText(lastValue); } setPlotterUnits(); } void InterfacePlotterDialog::updatePlotter( const double incomingBytes, const double outgoingBytes ) { QList trafficList; if ( mOutgoingVisible ) trafficList.append( outgoingBytes ); if ( mIncomingVisible ) trafficList.append( incomingBytes ); mPlotter->addSample( trafficList ); for ( int beamId = 0; beamId < mPlotter->numBeams(); beamId++ ) { QString lastValue = formattedRate( mPlotter->lastValue(beamId), mUseBitrate ); static_cast((static_cast(mLabelLayout->itemAt(beamId)))->widget())->setValueText(lastValue); } } void InterfacePlotterDialog::loadConfig() { KSharedConfigPtr config = KSharedConfig::openConfig(); // Set the plotter widgets QString group = confg_plotter + mName; // Plotter PlotterSettings s; KConfigGroup plotterGroup( config, group ); mSettings.pixel = clamp(plotterGroup.readEntry( plot_pixel, s.pixel ), 1, 50 ); mSettings.distance = clamp(plotterGroup.readEntry( plot_distance, s.distance ), 10, 120 ); mSettings.fontSize = clamp(plotterGroup.readEntry( plot_fontSize, s.fontSize ), 5, 24 ); mSettings.minimumValue = clamp(plotterGroup.readEntry( plot_minimumValue, s.minimumValue ), 0.0, pow(1024.0, 3) - 1 ); mSettings.maximumValue = clamp(plotterGroup.readEntry( plot_maximumValue, s.maximumValue ), 0.0, pow(1024.0, 3) ); mSettings.labels = plotterGroup.readEntry( plot_labels, s.labels ); mSettings.showIncoming = plotterGroup.readEntry( plot_showIncoming, s.showIncoming ); mSettings.showOutgoing = plotterGroup.readEntry( plot_showOutgoing, s.showOutgoing ); mSettings.verticalLines = plotterGroup.readEntry( plot_verticalLines, s.verticalLines ); mSettings.horizontalLines = plotterGroup.readEntry( plot_horizontalLines, s.horizontalLines ); mSettings.automaticDetection = plotterGroup.readEntry( plot_automaticDetection, s.automaticDetection ); mSettings.verticalLinesScroll = plotterGroup.readEntry( plot_verticalLinesScroll, s.verticalLinesScroll ); mSettings.colorIncoming = plotterGroup.readEntry( plot_colorIncoming, s.colorIncoming ); mSettings.colorOutgoing = plotterGroup.readEntry( plot_colorOutgoing, s.colorOutgoing ); configChanged(); } void InterfacePlotterDialog::saveConfig() { KSharedConfigPtr config = KSharedConfig::openConfig(); // Set the plotter widgets QString group = confg_plotter + mName; // Plotter KConfigGroup plotterGroup( config, group ); plotterGroup.writeEntry( plot_pixel, mSettings.pixel ); plotterGroup.writeEntry( plot_distance, mSettings.distance ); plotterGroup.writeEntry( plot_fontSize, mSettings.fontSize ); plotterGroup.writeEntry( plot_minimumValue, mSettings.minimumValue ); plotterGroup.writeEntry( plot_maximumValue, mSettings.maximumValue ); plotterGroup.writeEntry( plot_labels, mSettings.labels ); plotterGroup.writeEntry( plot_verticalLines, mSettings.verticalLines ); plotterGroup.writeEntry( plot_horizontalLines, mSettings.horizontalLines ); plotterGroup.writeEntry( plot_showIncoming, mSettings.showIncoming ); plotterGroup.writeEntry( plot_showOutgoing, mSettings.showOutgoing ); plotterGroup.writeEntry( plot_automaticDetection, mSettings.automaticDetection ); plotterGroup.writeEntry( plot_verticalLinesScroll, mSettings.verticalLinesScroll ); plotterGroup.writeEntry( plot_colorIncoming, mSettings.colorIncoming ); plotterGroup.writeEntry( plot_colorOutgoing, mSettings.colorOutgoing ); config->sync(); configChanged(); } void InterfacePlotterDialog::configChanged() { QFont pfont = mPlotter->font(); pfont.setPointSize( mSettings.fontSize ); QFontMetrics fm( pfont ); int axisTextWidth = fm.width(i18nc("Largest axis title", "99999 XXXX")); mPlotter->setMaxAxisTextWidth( axisTextWidth ); mPlotter->setFont( pfont ); if ( !mSettings.automaticDetection ) { mPlotter->setMinimumValue( mSettings.minimumValue * mMultiplier ); mPlotter->setMaximumValue( mSettings.maximumValue * mMultiplier ); } else { // Don't want the disabled settings to be used as hints mPlotter->setMinimumValue( 0 ); mPlotter->setMaximumValue( 1 ); } mPlotter->setHorizontalScale( mSettings.pixel ); mPlotter->setVerticalLinesDistance( mSettings.distance ); mPlotter->setShowAxis( mSettings.labels ); mPlotter->setShowVerticalLines( mSettings.verticalLines ); mPlotter->setShowHorizontalLines( mSettings.horizontalLines ); mPlotter->setUseAutoRange( mSettings.automaticDetection ); mPlotter->setVerticalLinesScroll( mSettings.verticalLinesScroll ); mSentLabel->setLabel( i18nc( "network traffic", "Sending" ), mSettings.colorOutgoing); mReceivedLabel->setLabel( i18nc( "network traffic", "Receiving" ), mSettings.colorIncoming); addBeams(); } void InterfacePlotterDialog::addBeams() { if ( mSettings.showOutgoing ) { if ( !mOutgoingVisible ) { mPlotter->addBeam( mSettings.colorOutgoing ); mSentLabel->show(); mOutgoingVisible = true; if ( mIncomingVisible ) { QList newOrder; newOrder << 1 << 0; mPlotter->reorderBeams( newOrder ); } } } else if ( mOutgoingVisible == true ) { mPlotter->removeBeam( 0 ); mSentLabel->hide(); mOutgoingVisible = false; } if ( mSettings.showIncoming ) { if ( !mIncomingVisible ) { mPlotter->addBeam( mSettings.colorIncoming ); mReceivedLabel->show(); mIncomingVisible = true; } } else if ( mIncomingVisible == true ) { mPlotter->removeBeam( mPlotter->numBeams() - 1 ); mReceivedLabel->hide(); mIncomingVisible = false; } } #include "interfaceplotterdialog.moc" diff --git a/src/knemod/interfacestatisticsdialog.cpp b/src/knemod/interfacestatisticsdialog.cpp index aa6e354..fcde99b 100644 --- a/src/knemod/interfacestatisticsdialog.cpp +++ b/src/knemod/interfacestatisticsdialog.cpp @@ -1,212 +1,217 @@ /* This file is part of KNemo Copyright (C) 2006 Percy Leonhardt Copyright (C) 2009, 2010 John Stamp 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 #include #include +#include +#include +#include #include #include "data.h" #include "interface.h" #include "interfacestatistics.h" #include "interfacestatisticsdialog.h" #include "statisticsmodel.h" InterfaceStatisticsDialog::InterfaceStatisticsDialog( Interface* interface, QWidget* parent ) - : KDialog( parent ), + : QDialog( parent ), mWasShown( false ), mSetPos( true ), mConfig( KSharedConfig::openConfig() ), mInterface( interface ) { - setCaption( i18n( "%1 Statistics", interface->ifaceName() ) ); - setButtons( Reset | Close ); + setWindowTitle( i18n( "%1 Statistics", interface->ifaceName() ) ); - ui.setupUi( mainWidget() ); + ui.setupUi( this ); mBillingWidget = new QWidget(); QVBoxLayout *bl = new QVBoxLayout( mBillingWidget ); mBillingView = new StatisticsView( mBillingWidget ); mBillingView->setEditTriggers( QAbstractItemView::NoEditTriggers ); mBillingView->setSortingEnabled( true ); mBillingView->horizontalHeader()->setStretchLastSection( true ); mBillingView->verticalHeader()->setVisible( false ); bl->addWidget( mBillingView ); mStateKeys.insert( ui.tableHourly, conf_hourState ); mStateKeys.insert( ui.tableDaily, conf_dayState ); mStateKeys.insert( ui.tableWeekly, conf_weekState ); mStateKeys.insert( ui.tableMonthly, conf_monthState ); mStateKeys.insert( ui.tableYearly, conf_yearState ); mStateKeys.insert( mBillingView, conf_billingState ); configChanged(); KConfig *config = mConfig.data(); KConfigGroup interfaceGroup( config, confg_interface + mInterface->ifaceName() ); InterfaceStatistics *stat = mInterface->ifaceStatistics(); setupTable( &interfaceGroup, ui.tableHourly, stat->getStatistics( KNemoStats::Hour ) ); setupTable( &interfaceGroup, ui.tableDaily, stat->getStatistics( KNemoStats::Day ) ); setupTable( &interfaceGroup, ui.tableWeekly, stat->getStatistics( KNemoStats::Week ) ); setupTable( &interfaceGroup, ui.tableMonthly, stat->getStatistics( KNemoStats::Month ) ); setupTable( &interfaceGroup, ui.tableYearly, stat->getStatistics( KNemoStats::Year ) ); setupTable( &interfaceGroup, mBillingView, stat->getStatistics( KNemoStats::BillPeriod ) ); - connect( this, SIGNAL( resetClicked() ), SLOT( confirmReset() ) ); + connect( ui.buttonBox, SIGNAL( rejected() ), SLOT( reject() ) ); + connect( ui.buttonBox, SIGNAL( clicked( QAbstractButton* ) ), SLOT( confirmReset( QAbstractButton* ) ) ); if ( interfaceGroup.hasKey( conf_statisticsPos ) ) { QPoint p = interfaceGroup.readEntry( conf_statisticsPos, QPoint() ); // See comment in event() mSetPos = false; move( p ); } if ( interfaceGroup.hasKey( conf_statisticsSize ) ) { QSize s = interfaceGroup.readEntry( conf_statisticsSize, QSize() ); resize( s ); } else { // Improve the chance that we have a decent sized dialog // the first time it's shown resize( 600, 450 ); } } InterfaceStatisticsDialog::~InterfaceStatisticsDialog() { if ( mWasShown ) { KConfig *config = mConfig.data(); KConfigGroup interfaceGroup( config, confg_interface + mInterface->ifaceName() ); interfaceGroup.writeEntry( conf_statisticsPos, pos() ); interfaceGroup.writeEntry( conf_statisticsSize, size() ); QHashIterator i( mStateKeys ); while ( i.hasNext() ) { i.next(); interfaceGroup.writeEntry( i.value(), i.key()->horizontalHeader()->saveState() ); } config->sync(); } } void InterfaceStatisticsDialog::configChanged() { bool billingTab = false; bool logOffpeak = false; KCalendarSystem *cal = mInterface->ifaceStatistics()->calendar(); foreach ( StatsRule rule, mInterface->settings().statsRules ) { if ( rule.periodCount != 1 || rule.periodUnits != KNemoStats::Month || cal->day( rule.startDate ) != 1 ) { billingTab = true; } if ( rule.logOffpeak ) logOffpeak = true; } ui.tableHourly->haveOffpeak( logOffpeak ); ui.tableDaily->haveOffpeak( logOffpeak ); ui.tableWeekly->haveOffpeak( logOffpeak ); ui.tableMonthly->haveOffpeak( logOffpeak ); ui.tableYearly->haveOffpeak( logOffpeak ); mBillingView->haveOffpeak( logOffpeak ); if ( billingTab && ui.tabWidget->count() < 6 ) { ui.tabWidget->insertTab( 4, mBillingWidget, i18n( "Billing Periods" ) ); } else if ( !billingTab && ui.tabWidget->count() > 5 ) ui.tabWidget->removeTab( 4 ); } void InterfaceStatisticsDialog::setupTable( KConfigGroup* group, QTableView *view, StatisticsModel *model ) { QSortFilterProxyModel *proxy = new QSortFilterProxyModel( view ); proxy->setSourceModel( model ); proxy->setSortRole( StatisticsModel::DataRole ); view->setModel( proxy ); view->sortByColumn( 0, Qt::AscendingOrder ); QModelIndex sourceIndex = proxy->sourceModel()->index( proxy->rowCount() - 1, 0 ); view->selectionModel()->setCurrentIndex( proxy->mapFromSource( sourceIndex ), QItemSelectionModel::NoUpdate ); connect( model, SIGNAL( itemChanged( QStandardItem * ) ), view->viewport(), SLOT( update() ) ); connect( proxy, SIGNAL( rowsInserted( const QModelIndex&, int, int ) ), this, SLOT( setCurrentSel() ) ); QByteArray state = group->readEntry( mStateKeys.value( view ), QByteArray() ); if ( state.isNull() ) view->resizeColumnsToContents(); else view->horizontalHeader()->restoreState( state ); proxy->setDynamicSortFilter( true ); } bool InterfaceStatisticsDialog::event( QEvent *e ) { /* If we do not explicitly call size() and move() at least once then * hiding and showing the dialog will cause it to forget its previous * size and position. */ if ( e->type() == QEvent::Move ) { if ( mSetPos && !pos().isNull() ) { mSetPos = false; move( pos() ); } } if ( e->type() == QEvent::Show && !mWasShown ) { mWasShown = true; // Set this here! For some reason the QTableView in the first tab // will become ridiculously wide if we set this earlier. ui.tableHourly->horizontalHeader()->setStretchLastSection( true ); } - return KDialog::event( e ); + return QDialog::event( e ); } -void InterfaceStatisticsDialog::confirmReset() +void InterfaceStatisticsDialog::confirmReset( QAbstractButton* button) { - if ( KMessageBox::questionYesNo( this, i18n( "Do you want to reset all statistics?" ) ) == KMessageBox::Yes ) - emit clearStatistics(); + if (static_cast(button) == ui.buttonBox->button(QDialogButtonBox::Reset) ) { + if ( KMessageBox::questionYesNo( this, i18n( "Do you want to reset all statistics?" ) ) == KMessageBox::Yes ) + emit clearStatistics(); + } } void InterfaceStatisticsDialog::setCurrentSel() { QSortFilterProxyModel *proxy = static_cast( sender() ); QTableView *tv = static_cast( sender()->parent() ); QModelIndex sourceIndex = proxy->sourceModel()->index( proxy->rowCount() - 1, 0 ); tv->selectionModel()->setCurrentIndex( proxy->mapFromSource( sourceIndex ), QItemSelectionModel::NoUpdate ); } #include "interfacestatisticsdialog.moc" diff --git a/src/knemod/interfacestatisticsdialog.h b/src/knemod/interfacestatisticsdialog.h index becd500..58b5718 100644 --- a/src/knemod/interfacestatisticsdialog.h +++ b/src/knemod/interfacestatisticsdialog.h @@ -1,81 +1,81 @@ /* This file is part of KNemo Copyright (C) 2006 Percy Leonhardt Copyright (C) 2009, 2010 John Stamp 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. */ #ifndef INTERFACESTATISTICSDIALOG_H #define INTERFACESTATISTICSDIALOG_H -#include +#include #include "ui_interfacestatisticsdlg.h" class StatisticsModel; class Interface; /** * This class shows the statistics dialog. It contains the tables for the * different statistics. * * @short Statistics dialog * @author Percy Leonhardt */ -class InterfaceStatisticsDialog : public KDialog +class InterfaceStatisticsDialog : public QDialog { Q_OBJECT public: /** * Default Constructor */ InterfaceStatisticsDialog( Interface* interface, QWidget* parent = 0L ); /** * Default Destructor */ virtual ~InterfaceStatisticsDialog(); void configChanged(); signals: void clearStatistics(); public slots: - void confirmReset(); + void confirmReset(QAbstractButton* button); protected: bool event( QEvent *e ); private: void setupTable( KConfigGroup* group, QTableView * view, StatisticsModel* model ); Ui::InterfaceStatisticsDlg ui; bool mWasShown; bool mSetPos; QWidget *mBillingWidget; StatisticsView *mBillingView; - KSharedConfigPtr mConfig; + KSharedConfig::Ptr mConfig; Interface* mInterface; QHash mStateKeys; private slots: void setCurrentSel(); }; #endif // INTERFACESTATISTICSDIALOG_H diff --git a/src/knemod/interfacestatisticsdlg.ui b/src/knemod/interfacestatisticsdlg.ui index a1672f4..3f9cfe1 100644 --- a/src/knemod/interfacestatisticsdlg.ui +++ b/src/knemod/interfacestatisticsdlg.ui @@ -1,155 +1,163 @@ InterfaceStatisticsDlg - - - 0 - 0 - 442 - 345 - - - + + 0 + + + 0 + + + 0 + + 0 0 24 Hours QAbstractItemView::NoEditTriggers true false Days QAbstractItemView::NoEditTriggers true true false Weeks QAbstractItemView::NoEditTriggers true true false Months QAbstractItemView::NoEditTriggers true true false Years QAbstractItemView::NoEditTriggers true true false + + + + QDialogButtonBox::Close|QDialogButtonBox::Reset + + + StatisticsView QTableView
statisticsview.h
tabWidget tableHourly tableDaily tableWeekly tableMonthly tableYearly
diff --git a/src/knemod/interfacestatusdialog.cpp b/src/knemod/interfacestatusdialog.cpp index ca82b14..defb4d3 100644 --- a/src/knemod/interfacestatusdialog.cpp +++ b/src/knemod/interfacestatusdialog.cpp @@ -1,414 +1,413 @@ /* This file is part of KNemo Copyright (C) 2004, 2006 Percy Leonhardt Copyright (C) 2009, 2010 John Stamp 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 #include #include #include -#include +#include #ifdef __linux__ #include #endif #include "global.h" #include "interface.h" #include "interfacestatistics.h" #include "interfacestatusdialog.h" #include "statisticsmodel.h" InterfaceStatusDialog::InterfaceStatusDialog( Interface* interface, QWidget* parent ) - : KDialog( parent ), + : QDialog( parent ), mWasShown( false ), mSetPos( true ), mConfig( KSharedConfig::openConfig() ), mInterface( interface ) { - setCaption( i18nc( "interface name", "%1 Interface Status", interface->ifaceName() ) ); - setButtons( None ); + setWindowTitle( i18nc( "interface name", "%1 Interface Status", interface->ifaceName() ) ); - ui.setupUi( mainWidget() ); + ui.setupUi( this ); configChanged(); // FreeBSD doesn't have these #ifndef __linux__ ui.addrLabel->hide(); ui.textLabelAddrLabel->hide(); ui.textLabelNickNameL->hide(); ui.textLabelNickName->hide(); #endif connect( ui.comboBoxIP, SIGNAL( currentIndexChanged(int) ), this, SLOT( updateDialog() ) ); updateDialog(); const BackendData * data = mInterface->backendData(); if ( !data ) return; if ( !data->isWireless ) { QWidget* wirelessTab = ui.tabWidget->widget( 2 ); ui.tabWidget->removeTab( 2 ); delete wirelessTab; } // Restore window size and position. KConfig *config = mConfig.data(); KConfigGroup interfaceGroup( config, confg_interface + mInterface->ifaceName() ); if ( interfaceGroup.hasKey( conf_statusPos ) ) { QPoint p = interfaceGroup.readEntry( conf_statusPos, QPoint() ); // See comment in event() mSetPos = false; move( p ); } if ( interfaceGroup.hasKey( conf_statusSize ) ) { QSize s = interfaceGroup.readEntry( conf_statusSize, QSize() ); resize( s ); } else resize( sizeHint() ); statisticsChanged(); } InterfaceStatusDialog::~InterfaceStatusDialog() { if ( mWasShown ) { KConfig *config = mConfig.data(); KConfigGroup interfaceGroup( config, confg_interface + mInterface->ifaceName() ); interfaceGroup.writeEntry( conf_statusPos, pos() ); interfaceGroup.writeEntry( conf_statusSize, size() ); config->sync(); } } bool InterfaceStatusDialog::event( QEvent *e ) { /* If we do not explicitly call size() and move() at least once then * hiding and showing the dialog will cause it to forget its previous * size and position. */ if ( e->type() == QEvent::Move ) { if ( mSetPos && !pos().isNull() ) { mSetPos = false; move( pos() ); } } else if ( e->type() == QEvent::Show ) { mWasShown = true; updateDialog(); } - return KDialog::event( e ); + return QDialog::event( e ); } void InterfaceStatusDialog::updateDialog() { if ( isHidden() ) return; const BackendData* data = mInterface->backendData(); if ( !data ) return; InterfaceSettings& settings = mInterface->settings(); // connection tab ui.textLabelInterface->setText( mInterface->ifaceName() ); ui.textLabelAlias->setText( settings.alias ); ui.textLabelUptime->setText( mInterface->uptimeString() ); if ( data->status & KNemoIface::Connected ) ui.textLabelStatus->setText( i18n( "Connected" ) ); else if ( data->status & KNemoIface::Up ) ui.textLabelStatus->setText( i18n( "Disconnected" ) ); else if ( data->status & KNemoIface::Available ) ui.textLabelStatus->setText( i18n( "Down" ) ); else ui.textLabelStatus->setText( i18n( "Unavailable" ) ); ui.groupBoxStatistics->setEnabled( mInterface->settings().activateStatistics ); if ( data->status & KNemoIface::Available ) { doAvailable( data ); if ( data->status & KNemoIface::Up ) { doUp( data ); if ( data->status & KNemoIface::Connected ) doConnected( data ); } } if ( data->status < KNemoIface::Connected ) { doDisconnected( data ); if ( data->status < KNemoIface::Up ) { doDown(); if ( data->status < KNemoIface::Available ) doUnavailable(); } } } void InterfaceStatusDialog::doAvailable( const BackendData* data ) { if ( data->interfaceType == KNemoIface::Ethernet ) { ui.macText->setText( data->hwAddress ); ui.macLabel->show(); ui.macText->show(); } else { ui.gatewayLabel->hide(); ui.gatewayText->hide(); ui.macLabel->hide(); ui.macText->hide(); } ui.textLabelPacketsSend->setText( QString::number( data->txPackets ) ); ui.textLabelPacketsReceived->setText( QString::number( data->rxPackets ) ); ui.textLabelBytesSend->setText( data->txString ); ui.textLabelBytesReceived->setText( data->rxString ); ui.textLabelSpeedSend->setText( mInterface->txRateStr() ); ui.textLabelSpeedReceived->setText( mInterface->rxRateStr() ); } void InterfaceStatusDialog::doConnected( const BackendData *data ) { ui.groupBoxCurrentConnection->setEnabled( true ); if ( data->isWireless ) { // wireless tab ui.textLabelESSID->setText( data->essid ); ui.textLabelAccessPoint->setText( data->accessPoint ); ui.textLabelNickName->setText( data->nickName ); ui.textLabelMode->setText( data->mode ); ui.textLabelFreqChannel->setText( data->frequency + " [" + data->channel + "]" ); ui.textLabelBitRate->setText( data->bitRate ); ui.textLabelLinkQuality->setText( data->linkQuality ); if ( data->isEncrypted == true ) { ui.textLabelEncryption->setText( i18n( "active" ) ); } else { ui.textLabelEncryption->setText( i18n( "off" ) ); } } } void InterfaceStatusDialog::doUp( const BackendData *data ) { // ip tab // Simpler to just clear and re-insert items in the combo box. // But then if we're selecting, the highlighted item would get // cleared each poll period. int i = 0; QStringList keys = data->addrData.keys(); while ( i < ui.comboBoxIP->count() ) { if ( keys.contains( ui.comboBoxIP->itemText( i ) ) ) i++; else ui.comboBoxIP->removeItem( i ); } QFont f = QFontDatabase::systemFont( QFontDatabase::GeneralFont ); QFontMetrics fm( f ); int w = 0; int keyCounter = 0; foreach( QString key, keys ) { // Combo box preserves order in map if ( ui.comboBoxIP->findText( key ) < 0 ) ui.comboBoxIP->insertItem( keyCounter, key ); keyCounter++; if ( fm.width( key ) > w ) w = fm.width( key ); } ui.comboBoxIP->setMinimumWidth( w + 35 ); AddrData addrData = data->addrData.value( ui.comboBoxIP->currentText() ); #ifdef __linux__ if ( addrData.label.isEmpty() ) ui.textLabelAddrLabel->clear(); else ui.textLabelAddrLabel->setText( addrData.label ); #endif if ( ui.comboBoxIP->count() > 0 ) { QString scope; switch ( addrData.scope ) { case RT_SCOPE_UNIVERSE: scope = i18nc( "ipv6 address scope", "global" ); break; case RT_SCOPE_SITE: scope = i18nc( "ipv6 address scope", "site" ); break; case RT_SCOPE_LINK: scope = i18nc( "ipv6 address scope", "link" ); break; case RT_SCOPE_HOST: scope = i18nc( "ipv6 address scope", "host" ); break; case RT_SCOPE_NOWHERE: scope = i18nc( "ipv6 address scope", "none" ); break; } scope += addrData.ipv6Flags; ui.textLabelScope->setText( scope ); if ( data->interfaceType == KNemoIface::Ethernet ) { if ( addrData.scope != RT_SCOPE_HOST ) { if ( addrData.afType == AF_INET ) ui.gatewayText->setText( data->ip4DefaultGateway ); else ui.gatewayText->setText( data->ip6DefaultGateway ); ui.gatewayLabel->show(); ui.gatewayText->show(); } else { ui.gatewayLabel->hide(); ui.gatewayText->hide(); } } ui.broadcastLabel->setText( i18n( "Broadcast Address:" ) ); if ( addrData.scope != RT_SCOPE_HOST ) { ui.broadcastText->setText( addrData.broadcastAddress ); if ( addrData.hasPeer ) ui.broadcastLabel->setText( i18n( "PtP Address:" ) ); ui.broadcastLabel->show(); ui.broadcastText->show(); } else { ui.broadcastLabel->hide(); ui.broadcastText->hide(); } } ui.groupBoxIP->setEnabled( (ui.comboBoxIP->count() > 0) ); // traffic tab } void InterfaceStatusDialog::doDisconnected( const BackendData *data ) { ui.groupBoxCurrentConnection->setEnabled( false ); if ( data->isWireless ) { ui.textLabelESSID->setText( QString::null ); ui.textLabelAccessPoint->setText( QString::null ); ui.textLabelNickName->setText( QString::null ); ui.textLabelMode->setText( QString::null ); ui.textLabelFreqChannel->setText( QString::null ); ui.textLabelBitRate->setText( QString::null ); ui.textLabelLinkQuality->setText( QString::null ); ui.textLabelEncryption->setText( QString::null ); } } void InterfaceStatusDialog::doDown() { // clear IP group ui.groupBoxIP->setEnabled( false ); ui.comboBoxIP->clear(); ui.textLabelAddrLabel->setText( QString::null ); ui.textLabelScope->setText( QString::null ); ui.broadcastText->setText( QString::null ); ui.gatewayText->setText( QString::null ); } void InterfaceStatusDialog::doUnavailable() { ui.macText->setText( QString::null ); // clear current connection group ui.textLabelPacketsSend->setText( QString::null ); ui.textLabelPacketsReceived->setText( QString::null ); ui.textLabelBytesSend->setText( QString::null ); ui.textLabelBytesReceived->setText( QString::null ); ui.textLabelSpeedSend->setText( QString::null ); ui.textLabelSpeedReceived->setText( QString::null ); } void InterfaceStatusDialog::configChanged() { bool billText = false; if ( mInterface->settings().activateStatistics ) { foreach ( StatsRule rule, mInterface->settings().statsRules ) { if ( rule.periodCount != 1 || rule.periodUnits != KNemoStats::Month || mInterface->ifaceStatistics()->calendar()->day( rule.startDate ) != 1 ) { billText = true; } } } ui.textLabelBill->setVisible( billText ); ui.textLabelBillSent->setVisible( billText ); ui.textLabelBillReceived->setVisible( billText ); ui.textLabelBillTotal->setVisible( billText ); } void InterfaceStatusDialog::statisticsChanged() { InterfaceStatistics *stat = mInterface->ifaceStatistics(); if ( stat == 0 ) return; StatisticsModel * statistics = stat->getStatistics( KNemoStats::Day ); ui.textLabelTodaySent->setText( statistics->txText() ); ui.textLabelTodayReceived->setText( statistics->rxText() ); ui.textLabelTodayTotal->setText( statistics->totalText() ); statistics = stat->getStatistics( KNemoStats::Month ); ui.textLabelMonthSent->setText( statistics->txText() ); ui.textLabelMonthReceived->setText( statistics->rxText() ); ui.textLabelMonthTotal->setText( statistics->totalText() ); statistics = stat->getStatistics( KNemoStats::BillPeriod ); ui.textLabelBillSent->setText( statistics->txText() ); ui.textLabelBillReceived->setText( statistics->rxText() ); ui.textLabelBillTotal->setText( statistics->totalText() ); statistics = stat->getStatistics( KNemoStats::Year ); ui.textLabelYearSent->setText( statistics->txText() ); ui.textLabelYearReceived->setText( statistics->rxText() ); ui.textLabelYearTotal->setText( statistics->totalText() ); } #include "interfacestatusdialog.moc" diff --git a/src/knemod/interfacestatusdialog.h b/src/knemod/interfacestatusdialog.h index 7642edb..31b8f40 100644 --- a/src/knemod/interfacestatusdialog.h +++ b/src/knemod/interfacestatusdialog.h @@ -1,81 +1,81 @@ /* This file is part of KNemo Copyright (C) 2004, 2006 Percy Leonhardt Copyright (C) 2009, 2010 John Stamp 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. */ #ifndef INTERFACESTATUSDIALOG_H #define INTERFACESTATUSDIALOG_H -#include +#include #include "ui_interfacestatusdlg.h" class Interface; /** * This class serves as the main window for KNemo. It handles the * menus, toolbars, and status bars. * * @short Main window class * @author Percy Leonhardt */ -class InterfaceStatusDialog : public KDialog +class InterfaceStatusDialog : public QDialog { Q_OBJECT public: /** * Default Constructor */ InterfaceStatusDialog( Interface* interface, QWidget* parent = 0L ); /** * Default Destructor */ virtual ~InterfaceStatusDialog(); public slots: /** * Update the statistics tab when data changed */ void statisticsChanged(); void updateDialog(); void configChanged(); protected: bool event( QEvent *e ); private: void doAvailable( const BackendData* data ); void doConnected( const BackendData *data ); void doUp( const BackendData *data ); void doDisconnected( const BackendData *data ); void doDown(); void doUnavailable(); Ui::InterfaceStatusDlg ui; bool mWasShown; bool mSetPos; - KSharedConfigPtr mConfig; + KSharedConfig::Ptr mConfig; Interface* mInterface; }; #endif // INTERFACESTATUSDIALOG_H diff --git a/src/knemod/interfacestatusdlg.ui b/src/knemod/interfacestatusdlg.ui index 66095df..3431941 100644 --- a/src/knemod/interfacestatusdlg.ui +++ b/src/knemod/interfacestatusdlg.ui @@ -1,829 +1,838 @@ InterfaceStatusDlg - + + 0 + + + 0 + + + 0 + + 0 0 Connection Qt::Vertical QSizePolicy::Expanding 0 0 false IP Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false IP Address/prefix: false Address Label: false Scope & Flags: false Broadcast Address: false Default Gateway: false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Interface: false Alias: false Status: false Connection Time: false MAC Address: false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Traffic false Interface Traffic Received Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Sent Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Packets: false Bytes: Qt::AlignTop false Speed: Qt::AlignTop false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false false Statistics Today: false This year: Qt::AlignTop false Received Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Total Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false This month: Qt::AlignTop false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Sent Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false This bill period: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Qt::Vertical QSizePolicy::Expanding 0 0 Wireless Connected to: false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Access point: false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Bit Rate: false Frequency [Channel]: false Mode: false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Nickname: false Qt::Vertical QSizePolicy::Expanding 0 0 Link Quality: false Encryption: false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter false diff --git a/src/knemod/plotterconfigdialog.cpp b/src/knemod/plotterconfigdialog.cpp index 7b009d2..6ed150f 100644 --- a/src/knemod/plotterconfigdialog.cpp +++ b/src/knemod/plotterconfigdialog.cpp @@ -1,150 +1,158 @@ /* This file is part of KNemo Copyright (C) 2009, 2010 John Stamp 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 "plotterconfigdialog.h" #include "global.h" #include -PlotterConfigDialog::PlotterConfigDialog( QWidget * parent, const QString& iface, PlotterSettings* settings ) : KDialog( parent ), +PlotterConfigDialog::PlotterConfigDialog( QWidget * parent, const QString& iface, PlotterSettings* settings ) : QDialog( parent ), mName( iface ), mSettings( settings ) { - setButtons( Ok | Apply | Default | Close ); - ui.setupUi( mainWidget() ); QString suffix; if ( generalSettings->useBitrate ) { suffix = i18n( " kbit/s" ); } else { suffix = i18n( " KiB/s" ); } + ui.setupUi( this ); ui.spinBoxMinValue->setSuffix( suffix ); ui.spinBoxMaxValue->setSuffix( suffix ); load(); - enableButtonApply( false ); + ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false); //enableButtonDefault( true ); - connect( this, SIGNAL( defaultClicked() ), SLOT( defaults() ) ); - connect( this, SIGNAL( applyClicked() ), SLOT( save() ) ); - connect( this, SIGNAL( okClicked() ), SLOT( save() ) ); + connect( ui.buttonBox, SIGNAL( accepted() ), SLOT( save() ) ); + connect( ui.buttonBox, SIGNAL( clicked( QAbstractButton* ) ), SLOT( defaults( QAbstractButton* ) ) ); // connect the plotter widgets connect( ui.checkBoxLabels, SIGNAL( toggled( bool ) ), this, SLOT( changed() ) ); connect( ui.checkBoxVLines, SIGNAL( toggled( bool ) ), this, SLOT( changed() ) ); connect( ui.checkBoxHLines, SIGNAL( toggled( bool ) ), this, SLOT( changed() ) ); connect( ui.checkBoxIncoming, SIGNAL( toggled( bool ) ), this, SLOT( changed() ) ); connect( ui.checkBoxOutgoing, SIGNAL( toggled( bool ) ), this, SLOT( changed() ) ); connect( ui.checkBoxVLinesScroll, SIGNAL( toggled( bool ) ), this, SLOT( changed() ) ); connect( ui.checkBoxAutoDetection, SIGNAL( toggled( bool ) ), this, SLOT( changed() ) ); connect( ui.spinBoxPixel, SIGNAL( valueChanged( int ) ), this, SLOT( changed() ) ); connect( ui.spinBoxDistance, SIGNAL( valueChanged( int ) ), this, SLOT( changed() ) ); connect( ui.spinBoxFontSize, SIGNAL( valueChanged( int ) ), this, SLOT( changed() ) ); connect( ui.spinBoxMinValue, SIGNAL( valueChanged( double ) ), this, SLOT( changed() ) ); connect( ui.spinBoxMaxValue, SIGNAL( valueChanged( double ) ), this, SLOT( changed() ) ); connect( ui.kColorButtonIncoming, SIGNAL( changed( const QColor& ) ), this, SLOT( changed() ) ); connect( ui.kColorButtonOutgoing, SIGNAL( changed( const QColor& ) ), this, SLOT( changed() ) ); } PlotterConfigDialog::~PlotterConfigDialog() { } void PlotterConfigDialog::load() { ui.spinBoxPixel->setValue( mSettings->pixel ); ui.spinBoxDistance->setValue( mSettings->distance ); ui.spinBoxFontSize->setValue( mSettings->fontSize ); ui.spinBoxMinValue->setValue( mSettings->minimumValue ); ui.spinBoxMaxValue->setValue( mSettings->maximumValue ); ui.checkBoxLabels->setChecked( mSettings->labels ); ui.checkBoxVLines->setChecked( mSettings->verticalLines ); ui.checkBoxHLines->setChecked( mSettings->horizontalLines ); ui.checkBoxIncoming->setChecked( mSettings->showIncoming ); ui.checkBoxOutgoing->setChecked( mSettings->showOutgoing ); ui.checkBoxAutoDetection->setChecked( !mSettings->automaticDetection ); ui.checkBoxVLinesScroll->setChecked( mSettings->verticalLinesScroll ); ui.kColorButtonIncoming->setColor( mSettings->colorIncoming ); ui.kColorButtonOutgoing->setColor( mSettings->colorOutgoing ); } void PlotterConfigDialog::save() { mSettings->pixel = ui.spinBoxPixel->value(); mSettings->distance = ui.spinBoxDistance->value(); mSettings->fontSize = ui.spinBoxFontSize->value(); mSettings->minimumValue = ui.spinBoxMinValue->value(); mSettings->maximumValue = ui.spinBoxMaxValue->value(); mSettings->labels = ui.checkBoxLabels->isChecked(); mSettings->verticalLines = ui.checkBoxVLines->isChecked(); mSettings->horizontalLines = ui.checkBoxHLines->isChecked(); mSettings->showIncoming = ui.checkBoxIncoming->isChecked(); mSettings->showOutgoing = ui.checkBoxOutgoing->isChecked(); mSettings->automaticDetection = !ui.checkBoxAutoDetection->isChecked(); mSettings->verticalLinesScroll = ui.checkBoxVLinesScroll->isChecked(); mSettings->colorIncoming = ui.kColorButtonIncoming->color(); mSettings->colorOutgoing = ui.kColorButtonOutgoing->color(); + ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false); emit saved(); } -void PlotterConfigDialog::defaults() +void PlotterConfigDialog::defaults( QAbstractButton* button ) { - enableButtonApply( true ); - PlotterSettings s; - // Default plotter settings - ui.spinBoxPixel->setValue( s.pixel ); - ui.spinBoxDistance->setValue( s.distance ); - ui.spinBoxFontSize->setValue( s.fontSize ); - ui.spinBoxMinValue->setValue( s.minimumValue ); - ui.spinBoxMaxValue->setValue( s.maximumValue ); - ui.checkBoxLabels->setChecked( s.labels ); - ui.checkBoxVLines->setChecked( s.verticalLines ); - ui.checkBoxHLines->setChecked( s.horizontalLines ); - ui.checkBoxIncoming->setChecked( s.showIncoming ); - ui.checkBoxOutgoing->setChecked( s.showOutgoing ); - ui.checkBoxAutoDetection->setChecked( !s.automaticDetection ); - ui.checkBoxVLinesScroll->setChecked( s.verticalLinesScroll ); - ui.kColorButtonIncoming->setColor( s.colorIncoming ); - ui.kColorButtonOutgoing->setColor( s.colorOutgoing ); + if (static_cast(button) == ui.buttonBox->button(QDialogButtonBox::RestoreDefaults) ) { + ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(true); + PlotterSettings s; + // Default plotter settings + ui.spinBoxPixel->setValue( s.pixel ); + ui.spinBoxDistance->setValue( s.distance ); + ui.spinBoxFontSize->setValue( s.fontSize ); + ui.spinBoxMinValue->setValue( s.minimumValue ); + ui.spinBoxMaxValue->setValue( s.maximumValue ); + ui.checkBoxLabels->setChecked( s.labels ); + ui.checkBoxVLines->setChecked( s.verticalLines ); + ui.checkBoxHLines->setChecked( s.horizontalLines ); + ui.checkBoxIncoming->setChecked( s.showIncoming ); + ui.checkBoxOutgoing->setChecked( s.showOutgoing ); + ui.checkBoxAutoDetection->setChecked( !s.automaticDetection ); + ui.checkBoxVLinesScroll->setChecked( s.verticalLinesScroll ); + ui.kColorButtonIncoming->setColor( s.colorIncoming ); + ui.kColorButtonOutgoing->setColor( s.colorOutgoing ); + } else if (static_cast(button) == ui.buttonBox->button(QDialogButtonBox::Ok) ) { + QDialog::accept(); + } else if (static_cast(button) == ui.buttonBox->button(QDialogButtonBox::Apply) ) { + save(); + } else if (static_cast(button) == ui.buttonBox->button(QDialogButtonBox::Cancel) ) { + QDialog::reject(); + } + } void PlotterConfigDialog::changed() { - enableButtonApply( true ); + ui.buttonBox->button(QDialogButtonBox::Apply)->setEnabled(true); } #include "plotterconfigdialog.moc" diff --git a/src/knemod/plotterconfigdialog.h b/src/knemod/plotterconfigdialog.h index da1b9bf..53cd7c5 100644 --- a/src/knemod/plotterconfigdialog.h +++ b/src/knemod/plotterconfigdialog.h @@ -1,83 +1,83 @@ /* This file is part of KNemo Copyright (C) 2009, 2010 John Stamp 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. */ #ifndef PLOTTERCONFIGDIALOG_H #define PLOTTERCONFIGDIALOG_H -#include +#include #include #include "ui_plotterconfigdlg.h" struct PlotterSettings { PlotterSettings() : pixel( 6 ), distance( 30 ), fontSize( 8 ), minimumValue( 0.0 ), maximumValue( 20.0 ), labels( true ), showIncoming( true ), showOutgoing( true ), verticalLines( false ), horizontalLines( true ), automaticDetection( true ), verticalLinesScroll( false ), colorIncoming( 0x1889FF ), colorOutgoing( 0xFF7F08 ) {} int pixel; int distance; int fontSize; double minimumValue; double maximumValue; bool labels; bool showIncoming; bool showOutgoing; bool verticalLines; bool horizontalLines; bool automaticDetection; bool verticalLinesScroll; QColor colorIncoming; QColor colorOutgoing; }; -class PlotterConfigDialog : public KDialog +class PlotterConfigDialog : public QDialog { Q_OBJECT public: PlotterConfigDialog( QWidget *parent, const QString& iface, PlotterSettings* settings ); virtual ~PlotterConfigDialog(); signals: void saved(); private slots: void changed(); - void defaults(); + void defaults(QAbstractButton*); void save(); private: void load(); Ui::Form ui; QString mName; PlotterSettings *mSettings; }; #endif diff --git a/src/knemod/plotterconfigdlg.ui b/src/knemod/plotterconfigdlg.ui index 7ae6945..169dd87 100644 --- a/src/knemod/plotterconfigdlg.ui +++ b/src/knemod/plotterconfigdlg.ui @@ -1,575 +1,551 @@ Form - + + 0 + + + 0 + + + 0 + + 0 0 Scales Vertical Scale Specify graph range: false Minimum value: false spinBoxMinValue - + false 49999.000000000000000 10.000000000000000 - - 49999 - false Maximum value: false spinBoxMaxValue - + false + + 1.000000000000000 + 50000.000000000000000 10.000000000000000 - - 50000 - - - 1 - Horizontal Scale Pixels per time period: false - + 1 50 6 - - 50 - - - 1 - Qt::Horizontal 0 0 Qt::Vertical 0 0 Grid Lines Vertical lines Qt::Horizontal 0 0 false Distance: false spinBoxDistance - + false 10 120 30 - - 120 - - - 10 - false Vertical lines scroll Horizontal lines Text Show axis labels Font size: false spinBoxFontSize - - - - 0 - 0 - - + 8 - - 0 - - - 0 - Qt::Vertical 0 0 Sensors Show incoming traffic false Show outgoing traffic false Qt::Vertical 0 0 + + + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::RestoreDefaults + + + - - KDoubleNumInput - QWidget -
knuminput.h
-
KColorButton QPushButton
kcolorbutton.h
- - KIntSpinBox - QSpinBox -
knuminput.h
-
tabWidget_2 checkBoxAutoDetection spinBoxMinValue spinBoxMaxValue spinBoxPixel checkBoxVLines spinBoxDistance checkBoxVLinesScroll checkBoxHLines checkBoxLabels spinBoxFontSize checkBoxIncoming kColorButtonIncoming checkBoxOutgoing kColorButtonOutgoing checkBoxAutoDetection toggled(bool) spinBoxMinValue setEnabled(bool) - 168 - 98 + 207 + 81 - 235 - 132 + 197 + 111 checkBoxAutoDetection toggled(bool) spinBoxMaxValue setEnabled(bool) - 299 - 98 + 289 + 80 - 457 - 132 + 441 + 107 checkBoxVLines toggled(bool) spinBoxDistance setEnabled(bool) - 59 - 102 + 109 + 67 - 456 - 106 + 109 + 67 checkBoxVLines toggled(bool) checkBoxVLinesScroll setEnabled(bool) - 59 - 102 + 103 + 67 - 94 - 118 + 109 + 67 checkBoxAutoDetection toggled(bool) textLabel9_3 setEnabled(bool) - 132 - 98 + 111 + 78 - 130 - 132 + 94 + 106 checkBoxAutoDetection toggled(bool) textLabel9_2_2 setEnabled(bool) - 303 - 98 + 316 + 93 - 354 - 132 + 343 + 123 checkBoxVLines toggled(bool) textLabel1_2_2 setEnabled(bool) - 59 - 102 + 103 + 67 - 387 - 106 + 109 + 67 checkBoxIncoming toggled(bool) kColorButtonIncoming setEnabled(bool) 64 62 - 340 - 63 + 109 + 67 checkBoxOutgoing toggled(bool) kColorButtonOutgoing setEnabled(bool) - 64 - 92 + 66 + 74 - 340 - 93 + 109 + 74