~ubuntu-branches/ubuntu/precise/networkmanagement/precise

« back to all changes in this revision

Viewing changes to applet/interfacedetailswidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-10-23 14:00:13 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20111023140013-e38hdzybcg6zndrk
Tags: 0.9~svngit.nm09.20111023.ff842e-0ubuntu1
* New upstream snapshot.
* Drop all patches, merged upstream.
* Add kubuntu_add_subdirectory_po.diff to build the translations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
#include "interfaceitem.h"
60
60
#include "nm-device-interface.h"
61
61
#include "nm-ip4-config-interface.h"
 
62
#include "../libs/internals/settings/802-11-wireless.h"
62
63
 
63
64
class InterfaceDetails
64
65
{
71
72
        QString mac;
72
73
        QString driver;
73
74
        QString activeAccessPoint;
 
75
        uint wifiChannelFrequency;
 
76
        int wifiChannel;
 
77
        int wifiBand;
74
78
 
75
79
        /* ModemManager */
76
80
        Solid::Control::ModemGsmNetworkInterface::RegistrationInfoType registrationInfo;
203
207
{
204
208
    delete details;
205
209
    details = new InterfaceDetails();
 
210
    Solid::Control::ModemNetworkInterfaceNm09 *giface = qobject_cast<Solid::Control::ModemNetworkInterfaceNm09*>(m_iface);
 
211
    if (giface) {
 
212
        giface->setModemCardIface(0);
 
213
        giface->setModemNetworkIface(0);
 
214
    }
206
215
    getDetails();
207
216
    showDetails();
208
217
}
227
236
    Solid::Control::WirelessNetworkInterfaceNm09 *wiface = qobject_cast<Solid::Control::WirelessNetworkInterfaceNm09*>(m_iface);
228
237
    if (wiface) {
229
238
        details->activeAccessPoint = wiface->activeAccessPoint();
 
239
        Solid::Control::AccessPointNm09 *ap = wiface->findAccessPoint(details->activeAccessPoint);
 
240
        if (ap) {
 
241
            details->wifiChannelFrequency = ap->frequency();
 
242
            QPair<int, int> bandAndChannel = UiUtils::findBandAndChannel(details->wifiChannelFrequency);
 
243
            details->wifiBand = bandAndChannel.first;
 
244
            details->wifiChannel = bandAndChannel.second;
 
245
        } else {
 
246
            details->wifiChannelFrequency = 0;
 
247
            details->wifiBand = Knm::WirelessSetting::EnumBand::bg;
 
248
            details->wifiChannel = -1;
 
249
        }
230
250
    } else {
231
251
        details->activeAccessPoint = QString();
232
252
    }
296
316
            if (ap) {
297
317
                info += QString(format).arg(i18nc("interface details", "Access Point (SSID)"), ap->ssid());
298
318
                info += QString(format).arg(i18nc("interface details", "Access Point (MAC)"), ap->hardwareAddress());
 
319
 
 
320
                if (details->wifiChannelFrequency != ap->frequency()) {
 
321
                    details->wifiChannelFrequency = ap->frequency();
 
322
                    QPair<int, int> bandAndChannel = UiUtils::findBandAndChannel(details->wifiChannelFrequency);
 
323
                    details->wifiBand = bandAndChannel.first;
 
324
                    details->wifiChannel = bandAndChannel.second;
 
325
                }
 
326
                info += QString(format).arg(i18nc("@item:intable wireless band", "Band"), UiUtils::wirelessBandToString(details->wifiBand));
 
327
                info += QString(format).arg(i18nc("@item:intable wireless channel", "Channel"), QString("%1 (%2 MHz)").arg(details->wifiChannel).arg(details->wifiChannelFrequency));
299
328
            }
300
329
        }
301
330
 
424
453
    //kDebug() << s;
425
454
    //m_traffic->setText(s);
426
455
 
427
 
    double _r = m_rx.toDouble();
428
 
    double _t = m_tx.toDouble();
 
456
    double _r;
 
457
    double _t;
 
458
    QString r, t;
 
459
 
 
460
    if (m_speedUnit == KNetworkManagerServicePrefs::KBits_s) {
 
461
        _r = m_rx.toInt() << 3;
 
462
        _t = m_tx.toInt() << 3;
 
463
 
 
464
        if (_r < 1000) {
 
465
            m_rxUnit = i18n("KBit/s");
 
466
        } else if (_r < 1000000) {
 
467
            m_rxUnit = i18n("MBit/s");
 
468
            _r /= 1000;
 
469
            _t /= 1000;
 
470
        } else {
 
471
            m_rxUnit = i18n("GBit/s");
 
472
            _r /= 1000000;
 
473
            _t /= 1000000;
 
474
        }
 
475
 
 
476
        m_txUnit = m_rxUnit;
 
477
        r = QString("%1 %2").arg(QString::number(_r, 'f', 0), m_rxUnit);
 
478
        t = QString("%1 %2").arg(QString::number(_t, 'f', 0), m_txUnit);
 
479
    } else {
 
480
        _r = m_rx.toDouble();
 
481
        _t = m_tx.toDouble();
 
482
 
 
483
        r = KGlobal::locale()->formatByteSize(_r*1024);
 
484
        r.append("/s");
 
485
        t = KGlobal::locale()->formatByteSize(_t*1024);
 
486
        t.append("/s");
 
487
    }
 
488
 
429
489
    QList<double> v;
430
490
    v << _r << _t;
431
491
    m_trafficPlotter->addSample(v);
432
492
    m_trafficPlotter->setUnit(m_rxUnit);
433
493
    //m_trafficPlotter->setTitle(i18nc("traffic, e.g. n KB/s / m KB/s", "%1 %2 %3 %4", m_rx, m_rxUnit, m_tx, m_txUnit));
434
494
 
435
 
    QString r = KGlobal::locale()->formatByteSize(_r*1024);
436
 
    r.append("/s");
437
 
    QString t = KGlobal::locale()->formatByteSize(_t*1024);
438
 
    t.append("/s");
439
495
    QString s = i18nc("traffic, e.g. n KB/s\n m KB/s", "%1 %2", r, t);
440
496
    m_trafficPlotter->setTitle(s);
441
497
 
515
571
 
516
572
void InterfaceDetailsWidget::setInterface(Solid::Control::NetworkInterfaceNm09* iface, bool disconnectOld)
517
573
{
 
574
    m_speedUnit = KNetworkManagerServicePrefs::self()->networkSpeedUnit();
 
575
 
518
576
    if (m_iface == iface) {
519
577
        return;
520
578
    }