~ubuntu-branches/ubuntu/natty/knemo/natty

« back to all changes in this revision

Viewing changes to src/knemod/interfacestatusdialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-02-22 16:36:22 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20110222163622-d8i62gy1stn7tydv
Tags: 0.7.0-0ubuntu1
* New upstream release.
* Switch to source format 3.0 (quilt).
* Make knemo depend on libqt4-sql-sqlite.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* This file is part of KNemo
2
2
   Copyright (C) 2004, 2006 Percy Leonhardt <percy@eris23.de>
3
 
   Copyright (C) 2009 John Stamp <jstamp@users.sourceforge.net>
 
3
   Copyright (C) 2009, 2010 John Stamp <jstamp@users.sourceforge.net>
4
4
 
5
5
   KNemo is free software; you can redistribute it and/or modify
6
6
   it under the terms of the GNU Library General Public License as
32
32
#include "interface.h"
33
33
#include "interfacestatistics.h"
34
34
#include "interfacestatusdialog.h"
 
35
#include "statisticsmodel.h"
35
36
 
36
37
InterfaceStatusDialog::InterfaceStatusDialog( Interface* interface, QWidget* parent )
37
38
    : KDialog( parent ),
40
41
      mConfig( KGlobal::config() ),
41
42
      mInterface( interface )
42
43
{
43
 
    setCaption( i18n( "%1 Interface Status", interface->getName() ) );
 
44
    setCaption( i18nc( "interface name", "%1 Interface Status", interface->ifaceName() ) );
44
45
    setButtons( Close );
45
46
 
46
47
    ui.setupUi( mainWidget() );
 
48
    configChanged();
47
49
 
48
50
    // FreeBSD doesn't have these
49
51
#ifndef __linux__
56
58
    connect( ui.comboBoxIP, SIGNAL( currentIndexChanged(int) ), this, SLOT( updateDialog() ) );
57
59
 
58
60
    updateDialog();
59
 
    const BackendData * data = mInterface->getData();
 
61
    const BackendData * data = mInterface->backendData();
60
62
    if ( !data )
61
63
        return;
62
64
    if ( !data->isWireless )
68
70
 
69
71
    // Restore window size and position.
70
72
    KConfig *config = mConfig.data();
71
 
    KConfigGroup interfaceGroup( config, confg_interface + mInterface->getName() );
 
73
    KConfigGroup interfaceGroup( config, confg_interface + mInterface->ifaceName() );
72
74
    if ( interfaceGroup.hasKey( conf_statusPos ) )
73
75
    {
74
76
        QPoint p = interfaceGroup.readEntry( conf_statusPos, QPoint() );
92
94
    if ( mWasShown )
93
95
    {
94
96
        KConfig *config = mConfig.data();
95
 
        KConfigGroup interfaceGroup( config, confg_interface + mInterface->getName() );
 
97
        KConfigGroup interfaceGroup( config, confg_interface + mInterface->ifaceName() );
96
98
        interfaceGroup.writeEntry( conf_statusPos, pos() );
97
99
        interfaceGroup.writeEntry( conf_statusSize, size() );
98
100
        config->sync();
126
128
    if ( isHidden() )
127
129
        return;
128
130
 
129
 
    const BackendData* data = mInterface->getData();
 
131
    const BackendData* data = mInterface->backendData();
130
132
    if ( !data )
131
133
        return;
132
 
    InterfaceSettings& settings = mInterface->getSettings();
 
134
    InterfaceSettings& settings = mInterface->settings();
133
135
 
134
136
    // connection tab
135
 
    ui.textLabelInterface->setText( mInterface->getName() );
 
137
    ui.textLabelInterface->setText( mInterface->ifaceName() );
136
138
    ui.textLabelAlias->setText( settings.alias );
137
 
    ui.textLabelUptime->setText( mInterface->getUptimeString() );
 
139
    ui.textLabelUptime->setText( mInterface->uptimeString() );
138
140
 
139
141
    if ( data->status & KNemoIface::Connected )
140
142
        ui.textLabelStatus->setText( i18n( "Connected" ) );
145
147
    else
146
148
        ui.textLabelStatus->setText( i18n( "Unavailable" ) );
147
149
 
148
 
    ui.groupBoxStatistics->setEnabled( mInterface->getSettings().activateStatistics );
 
150
    ui.groupBoxStatistics->setEnabled( mInterface->settings().activateStatistics );
149
151
 
150
152
    if ( data->status & KNemoIface::Available )
151
153
    {
190
192
    ui.textLabelPacketsReceived->setText( QString::number( data->rxPackets ) );
191
193
    ui.textLabelBytesSend->setText( data->txString );
192
194
    ui.textLabelBytesReceived->setText( data->rxString );
193
 
    ui.textLabelSpeedSend->setText( mInterface->getTxRateStr() );
194
 
    ui.textLabelSpeedReceived->setText( mInterface->getRxRateStr() );
 
195
    ui.textLabelSpeedSend->setText( mInterface->txRateStr() );
 
196
    ui.textLabelSpeedReceived->setText( mInterface->rxRateStr() );
195
197
}
196
198
 
197
199
void InterfaceStatusDialog::doConnected( const BackendData *data )
264
266
        switch ( addrData.scope )
265
267
        {
266
268
            case RT_SCOPE_UNIVERSE:
267
 
                scope = i18n( "global" );
 
269
                scope = i18nc( "ipv6 address scope", "global" );
268
270
                break;
269
271
            case RT_SCOPE_SITE:
270
 
                scope = i18n( "site" );
 
272
                scope = i18nc( "ipv6 address scope", "site" );
271
273
                break;
272
274
            case RT_SCOPE_LINK:
273
 
                scope = i18n( "link" );
 
275
                scope = i18nc( "ipv6 address scope", "link" );
274
276
                break;
275
277
            case RT_SCOPE_HOST:
276
 
                scope = i18n( "host" );
 
278
                scope = i18nc( "ipv6 address scope", "host" );
277
279
                break;
278
280
            case RT_SCOPE_NOWHERE:
279
 
                scope = i18n( "none" );
 
281
                scope = i18nc( "ipv6 address scope", "none" );
280
282
                break;
281
283
        }
282
284
        scope += addrData.ipv6Flags;
360
362
    ui.textLabelSpeedReceived->setText( QString::null );
361
363
}
362
364
 
 
365
void InterfaceStatusDialog::configChanged()
 
366
{
 
367
    bool billText = false;
 
368
    if ( mInterface->settings().activateStatistics )
 
369
    {
 
370
        foreach ( StatsRule rule, mInterface->settings().statsRules )
 
371
        {
 
372
            if ( rule.periodCount != 1 ||
 
373
                 rule.periodUnits != KNemoStats::Month ||
 
374
                 mInterface->ifaceStatistics()->calendar()->day( rule.startDate ) != 1 )
 
375
            {
 
376
                billText = true;
 
377
            }
 
378
        }
 
379
    }
 
380
 
 
381
    ui.textLabelBill->setVisible( billText );
 
382
    ui.textLabelBillSent->setVisible( billText );
 
383
    ui.textLabelBillReceived->setVisible( billText );
 
384
    ui.textLabelBillTotal->setVisible( billText );
 
385
}
 
386
 
363
387
void InterfaceStatusDialog::statisticsChanged()
364
388
{
365
 
    InterfaceStatistics *stat = mInterface->getStatistics();
 
389
    InterfaceStatistics *stat = mInterface->ifaceStatistics();
366
390
    if ( stat == 0 )
367
391
        return;
368
392
 
369
 
    StatisticsModel * statistics = stat->getStatistics( StatisticsModel::Day );
 
393
    StatisticsModel * statistics = stat->getStatistics( KNemoStats::Day );
370
394
    ui.textLabelTodaySent->setText( statistics->txText() );
371
395
    ui.textLabelTodayReceived->setText( statistics->rxText() );
372
396
    ui.textLabelTodayTotal->setText( statistics->totalText() );
373
397
 
374
 
    statistics = stat->getStatistics( StatisticsModel::Month );
 
398
    statistics = stat->getStatistics( KNemoStats::Month );
375
399
    ui.textLabelMonthSent->setText( statistics->txText() );
376
400
    ui.textLabelMonthReceived->setText( statistics->rxText() );
377
401
    ui.textLabelMonthTotal->setText( statistics->totalText() );
378
402
 
379
 
    statistics = stat->getStatistics( StatisticsModel::Year );
 
403
    statistics = stat->getStatistics( KNemoStats::BillPeriod );
 
404
    ui.textLabelBillSent->setText( statistics->txText() );
 
405
    ui.textLabelBillReceived->setText( statistics->rxText() );
 
406
    ui.textLabelBillTotal->setText( statistics->totalText() );
 
407
 
 
408
    statistics = stat->getStatistics( KNemoStats::Year );
380
409
    ui.textLabelYearSent->setText( statistics->txText() );
381
410
    ui.textLabelYearReceived->setText( statistics->rxText() );
382
411
    ui.textLabelYearTotal->setText( statistics->totalText() );