~ubuntu-branches/ubuntu/precise/knemo/precise

« back to all changes in this revision

Viewing changes to src/knemod/interfaceicon.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, 2005 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
104
104
        outHist.append( 0 );
105
105
    }
106
106
 
107
 
    inMaxRate = mInterface->getSettings().inMaxRate;
108
 
    outMaxRate = mInterface->getSettings().outMaxRate;
 
107
    inMaxRate = mInterface->settings().inMaxRate;
 
108
    outMaxRate = mInterface->settings().outMaxRate;
109
109
 
110
110
    updateTrayStatus();
111
111
 
112
112
    if ( mTray != 0L )
113
113
    {
114
114
        updateMenu();
115
 
        if ( mInterface->getSettings().iconTheme == TEXT_THEME )
 
115
        if ( mInterface->settings().iconTheme == TEXT_THEME )
116
116
             updateIconText( true );
117
 
        else if ( mInterface->getSettings().iconTheme == NETLOAD_THEME )
 
117
        else if ( mInterface->settings().iconTheme == NETLOAD_THEME )
118
118
             updateBars( true );
119
119
    }
120
120
}
121
121
 
122
122
void InterfaceIcon::updateIconImage( int status )
123
123
{
124
 
    if ( mTray == 0L || mInterface->getSettings().iconTheme == TEXT_THEME )
 
124
    if ( mTray == 0L || mInterface->settings().iconTheme == TEXT_THEME )
125
125
        return;
126
126
 
127
127
    QString iconName;
128
 
    if ( mInterface->getSettings().iconTheme == SYSTEM_THEME )
 
128
    if ( mInterface->settings().iconTheme == SYSTEM_THEME )
129
129
        iconName = "network-";
130
130
    else
131
 
        iconName = "knemo-" + mInterface->getSettings().iconTheme + "-";
 
131
        iconName = "knemo-" + mInterface->settings().iconTheme + "-";
132
132
 
133
133
    // Now set the correct icon depending on the status of the interface.
134
134
    if ( ( status & KNemoIface::RxTraffic ) &&
175
175
    rate = histcalculate / histSize;
176
176
 
177
177
    /* update maximum */
178
 
    if ( !mInterface->getSettings().barScale )
 
178
    if ( !mInterface->settings().barScale )
179
179
    {
180
180
        QList<unsigned long>sortedMax( hist );
181
181
        qSort( sortedMax );
201
201
 
202
202
QColor InterfaceIcon::calcColor( QList<unsigned long>& hist, const QColor& low, const QColor& high, int hival )
203
203
{
204
 
    const BackendData * data = mInterface->getData();
 
204
    const BackendData * data = mInterface->backendData();
205
205
 
206
206
    if ( data->status & KNemoIface::Connected )
207
207
    {
208
 
        if ( ! mInterface->getSettings().dynamicColor )
 
208
        if ( ! mInterface->settings().dynamicColor )
209
209
            return low;
210
210
    }
211
211
    else if ( data->status & KNemoIface::Available )
212
 
        return mInterface->getSettings().colorDisabled;
 
212
        return mInterface->settings().colorDisabled;
213
213
    else if ( data->status & KNemoIface::Unavailable )
214
 
        return mInterface->getSettings().colorUnavailable;
 
214
        return mInterface->settings().colorUnavailable;
215
215
 
216
216
    unsigned long histcalculate = 0;
217
217
    unsigned long rate = 0;
218
 
    if ( mInterface->getSettings().iconTheme == NETLOAD_THEME )
 
218
    if ( mInterface->settings().iconTheme == NETLOAD_THEME )
219
219
    {
220
220
        foreach( unsigned long j, hist )
221
221
        {
248
248
void InterfaceIcon::updateBars( bool doUpdate )
249
249
{
250
250
    // Has color changed?
251
 
    QColor rxColor = calcColor( inHist, mInterface->getSettings().colorIncoming, mInterface->getSettings().colorIncomingMax, mInterface->getSettings().inMaxRate );
252
 
    QColor txColor = calcColor( outHist, mInterface->getSettings().colorOutgoing, mInterface->getSettings().colorOutgoingMax, mInterface->getSettings().outMaxRate );
 
251
    QColor rxColor = calcColor( inHist, mInterface->settings().colorIncoming, mInterface->settings().colorIncomingMax, mInterface->settings().inMaxRate );
 
252
    QColor txColor = calcColor( outHist, mInterface->settings().colorOutgoing, mInterface->settings().colorOutgoingMax, mInterface->settings().outMaxRate );
253
253
    if ( rxColor != colorIncoming )
254
254
    {
255
255
        doUpdate = true;
297
297
    QPainter p( &barIcon );
298
298
    p.setOpacity( 1.0 );
299
299
 
300
 
    QColor topColor = mInterface->getSettings().colorUnavailable;
301
 
    QColor topColorD = mInterface->getSettings().colorUnavailable.darker();
 
300
    const BackendData * data = mInterface->backendData();
 
301
    QColor topColor;
 
302
    if ( data->status & KNemoIface::Connected )
 
303
    {
 
304
        topColor = mInterface->settings().colorBackground;
 
305
    }
 
306
    else if ( data->status & KNemoIface::Available )
 
307
    {
 
308
        topColor = mInterface->settings().colorDisabled;
 
309
    }
 
310
    else
 
311
    {
 
312
        topColor = mInterface->settings().colorUnavailable;
 
313
    }
 
314
    QColor topColorD = topColor.darker();
302
315
    topColor.setAlpha( 128 );
303
316
    topColorD.setAlpha( 128 );
304
317
    topInGrad.setColorAt(0, topColorD);
372
385
void InterfaceIcon::updateIconText( bool doUpdate )
373
386
{
374
387
    // Has color changed?
375
 
    QColor rxColor = calcColor( inHist, mInterface->getSettings().colorIncoming, mInterface->getSettings().colorIncomingMax, mInterface->getSettings().inMaxRate );
376
 
    QColor txColor = calcColor( outHist, mInterface->getSettings().colorOutgoing, mInterface->getSettings().colorOutgoingMax, mInterface->getSettings().outMaxRate );
 
388
    QColor rxColor = calcColor( inHist, mInterface->settings().colorIncoming, mInterface->settings().colorIncomingMax, mInterface->settings().inMaxRate );
 
389
    QColor txColor = calcColor( outHist, mInterface->settings().colorOutgoing, mInterface->settings().colorOutgoingMax, mInterface->settings().outMaxRate );
377
390
    if ( rxColor != colorIncoming )
378
391
    {
379
392
        doUpdate = true;
386
399
    }
387
400
 
388
401
    // Has text changed?
389
 
    QString byteText = compactTrayText( mInterface->getRxRate() );
 
402
    QString byteText = compactTrayText( mInterface->rxRate() );
390
403
    if ( byteText != textIncoming )
391
404
    {
392
405
        doUpdate = true;
393
406
        textIncoming = byteText;
394
407
    }
395
 
    byteText = compactTrayText( mInterface->getTxRate() );
 
408
    byteText = compactTrayText( mInterface->txRate() );
396
409
    if ( byteText != textOutgoing )
397
410
    {
398
411
        doUpdate = true;
413
426
    KColorScheme scheme(QPalette::Active, KColorScheme::View);
414
427
 
415
428
    // rxFont and txFont should be the same size per poll period
416
 
    QFont rxFont = setIconFont( textIncoming, mInterface->getSettings().iconFont, iconWidth );
417
 
    QFont txFont = setIconFont( textOutgoing, mInterface->getSettings().iconFont, iconWidth );
 
429
    QFont rxFont = setIconFont( textIncoming, mInterface->settings().iconFont, iconWidth );
 
430
    QFont txFont = setIconFont( textOutgoing, mInterface->settings().iconFont, iconWidth );
418
431
    if ( rxFont.pointSizeF() > txFont.pointSizeF() )
419
432
        rxFont.setPointSizeF( txFont.pointSizeF() );
420
433
 
436
449
{
437
450
    if ( mTray == 0L )
438
451
        return;
439
 
    inHist.prepend( mInterface->getRxRate() );
440
 
    outHist.prepend( mInterface->getTxRate() );
 
452
    inHist.prepend( mInterface->rxRate() );
 
453
    outHist.prepend( mInterface->txRate() );
441
454
    while ( inHist.count() > histSize )
442
455
    {
443
456
        inHist.removeLast();
445
458
    }
446
459
 
447
460
 
448
 
    if ( mInterface->getSettings().iconTheme == TEXT_THEME )
 
461
    if ( mInterface->settings().iconTheme == TEXT_THEME )
449
462
        updateIconText();
450
 
    else if ( mInterface->getSettings().iconTheme == NETLOAD_THEME )
 
463
    else if ( mInterface->settings().iconTheme == NETLOAD_THEME )
451
464
        updateBars();
452
465
    mTray->updateToolTip();
453
466
}
461
474
        menu->removeAction( action );
462
475
    commandActions->clear();
463
476
 
464
 
    InterfaceSettings& settings = mInterface->getSettings();
 
477
    InterfaceSettings& settings = mInterface->settings();
465
478
 
466
479
    // If the user wants custom commands, add them.
467
480
    if ( settings.commands.size() > 0 )
487
500
 
488
501
void InterfaceIcon::updateTrayStatus()
489
502
{
490
 
    const QString ifaceName( mInterface->getName() );
491
 
    const BackendData * data = mInterface->getData();
 
503
    const QString ifaceName( mInterface->ifaceName() );
 
504
    const BackendData * data = mInterface->backendData();
492
505
    int currentStatus = data->status;
493
 
    bool hideWhenUnavailable = mInterface->getSettings().hideWhenUnavailable;
494
 
    bool hideWhenDisconnected = mInterface->getSettings().hideWhenDisconnected;
 
506
    bool hideWhenUnavailable = mInterface->settings().hideWhenUnavailable;
 
507
    bool hideWhenDisconnected = mInterface->settings().hideWhenDisconnected;
495
508
 
496
 
    QString title = mInterface->getSettings().alias;
 
509
    QString title = mInterface->settings().alias;
497
510
    if ( title.isEmpty() )
498
511
        title = ifaceName;
499
512
 
535
548
        connect( menu, SIGNAL( triggered( QAction * ) ),
536
549
                 this, SLOT( menuTriggered( QAction * ) ) );
537
550
 
538
 
        if ( mInterface->getSettings().iconTheme == TEXT_THEME )
 
551
        if ( mInterface->settings().iconTheme == TEXT_THEME )
539
552
            updateIconText();
540
 
        else if ( mInterface->getSettings().iconTheme == NETLOAD_THEME )
 
553
        else if ( mInterface->settings().iconTheme == NETLOAD_THEME )
541
554
            updateBars();
542
555
        else
543
 
            updateIconImage( mInterface->getState() );
 
556
            updateIconImage( mInterface->ifaceState() );
544
557
        updateMenu();
545
558
#ifndef HAVE_KSTATUSNOTIFIERITEM
546
559
        mTray->show();
548
561
    }
549
562
    else if ( mTray != 0L )
550
563
    {
551
 
        if ( mInterface->getSettings().iconTheme != TEXT_THEME &&
552
 
             mInterface->getSettings().iconTheme != NETLOAD_THEME )
553
 
            updateIconImage( mInterface->getState() );
 
564
        if ( mInterface->settings().iconTheme != TEXT_THEME &&
 
565
             mInterface->settings().iconTheme != NETLOAD_THEME )
 
566
            updateIconImage( mInterface->ifaceState() );
554
567
    }
555
568
}
556
569
 
557
570
void InterfaceIcon::showConfigDialog()
558
571
{
559
 
    KNemoDaemon::sSelectedInterface = mInterface->getName();
 
572
    KNemoDaemon::sSelectedInterface = mInterface->ifaceName();
560
573
 
561
574
    KProcess process;
562
575
    process << "kcmshell4" << "kcm_knemo";