~ubuntu-branches/ubuntu/saucy/knemo/saucy

« back to all changes in this revision

Viewing changes to src/knemod/interfaceplotterdialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2010-06-15 18:58:30 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20100615185830-2zeqn9vpn3jjx6gd
Tags: 0.6.3-1
* New upstream release 
  - Fixes (LP: #559683, LP: #248294)
  - save changes to traffic threshold setting
  - add option to report traffic rate in bit/s
  - update the signal plotter from KDE SC 4.4 branch; a few minor plotter
    config options were dropped as a result
  - on startup sync recent traffic statistics with vnstat if it's available;
    this should help KNemo account for traffic between sessions
  - fix possible hang when text icon theme uses fixed fonts

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
*/
23
23
 
24
24
#include <QMenu>
 
25
#include <QMouseEvent>
25
26
#include <KApplication>
26
27
 
 
28
#include "global.h"
27
29
#include "interfaceplotterdialog.h"
28
30
#include "utils.h"
29
31
#include "signalplotter.h"
35
37
static const char plot_minimumValue[] = "MinimumValue";
36
38
static const char plot_maximumValue[] = "MaximumValue";
37
39
static const char plot_labels[] = "Labels";
38
 
static const char plot_bottomBar[] = "BottomBar";
39
40
static const char plot_verticalLines[] = "VerticalLines";
40
41
static const char plot_horizontalLines[] = "HorizontalLines";
41
42
static const char plot_showIncoming[] = "ShowIncoming";
42
43
static const char plot_showOutgoing[] = "ShowOutgoing";
43
44
static const char plot_automaticDetection[] = "AutomaticDetection";
44
45
static const char plot_verticalLinesScroll[] = "VerticalLinesScroll";
45
 
static const char plot_colorVLines[] = "ColorVLines";
46
 
static const char plot_colorHLines[] = "ColorHLines";
47
46
static const char plot_colorIncoming[] = "ColorIncoming";
48
47
static const char plot_colorOutgoing[] = "ColorOutgoing";
49
 
static const char plot_colorBackground[] = "ColorBackground";
50
 
static const char plot_opacity[] = "Opacity";
51
48
 
52
49
class FancyPlotterLabel : public QWidget
53
50
{
79
76
      mConfigDlg( 0 ),
80
77
      mSetPos( true ),
81
78
      mWasShown( false ),
 
79
      mUseBitrate( generalSettings->useBitrate ),
82
80
      mName( name )
83
81
{
84
82
    setCaption( i18n( "%1 Traffic", mName ) );
94
92
    mainWidget()->setLayout( layout );
95
93
    layout->setSpacing(0);
96
94
    mPlotter = new KSignalPlotter( this );
97
 
    mPlotter->setThinFrame( true );
98
95
    mPlotter->setShowAxis( true );
99
96
    int axisTextWidth = fontMetrics().width(i18nc("Largest axis title", "99999 XXXX"));
100
97
    mPlotter->addBeam( Qt::black );
232
229
    mConfigDlg = 0;
233
230
}
234
231
 
 
232
void InterfacePlotterDialog::useBitrate( bool useBits )
 
233
{
 
234
    mUseBitrate = useBits;
 
235
    mPlotter->useBitrate( mUseBitrate );
 
236
    for ( int beamId = 0; beamId < mPlotter->numBeams(); beamId++ )
 
237
    {
 
238
        QString lastValue = formattedRate( mPlotter->lastValue(beamId), mUseBitrate );
 
239
        static_cast<FancyPlotterLabel *>((static_cast<QWidgetItem *>(mLabelLayout->itemAt(beamId)))->widget())->value->setText(lastValue);
 
240
    }
 
241
}
 
242
 
235
243
void InterfacePlotterDialog::updatePlotter( const double incomingBytes, const double outgoingBytes )
236
244
{
237
245
    QList<double> trafficList;
242
250
 
243
251
    for ( int beamId = 0; beamId < mPlotter->numBeams(); beamId++ )
244
252
    {
245
 
        QString lastValue = mPlotter->lastValueAsString(beamId);
 
253
        QString lastValue = formattedRate( mPlotter->lastValue(beamId), mUseBitrate );
246
254
        static_cast<FancyPlotterLabel *>((static_cast<QWidgetItem *>(mLabelLayout->itemAt(beamId)))->widget())->value->setText(lastValue);
247
255
    }
248
256
}
258
266
    mSettings.pixel = clamp<int>(plotterGroup.readEntry( plot_pixel, s.pixel ), 1, 50 );
259
267
    mSettings.distance = clamp<int>(plotterGroup.readEntry( plot_distance, s.distance ), 10, 120 );
260
268
    mSettings.fontSize = clamp<int>(plotterGroup.readEntry( plot_fontSize, s.fontSize ), 5, 24 );
261
 
    mSettings.minimumValue = clamp<int>(plotterGroup.readEntry( plot_minimumValue, s.minimumValue ), 0, 49999 );
262
 
    mSettings.maximumValue = clamp<int>(plotterGroup.readEntry( plot_maximumValue, s.maximumValue ), 0, 50000 );
 
269
    mSettings.minimumValue = clamp<double>(plotterGroup.readEntry( plot_minimumValue, s.minimumValue ), 0.0, 49999.0 );
 
270
    mSettings.maximumValue = clamp<double>(plotterGroup.readEntry( plot_maximumValue, s.maximumValue ), 0.0, 50000.0 );
263
271
    mSettings.labels = plotterGroup.readEntry( plot_labels, s.labels );
264
 
    mSettings.bottomBar = plotterGroup.readEntry( plot_bottomBar, s.bottomBar );
265
272
    mSettings.showIncoming = plotterGroup.readEntry( plot_showIncoming, s.showIncoming );
266
273
    mSettings.showOutgoing = plotterGroup.readEntry( plot_showOutgoing, s.showOutgoing );
267
274
    mSettings.verticalLines = plotterGroup.readEntry( plot_verticalLines, s.verticalLines );
268
275
    mSettings.horizontalLines = plotterGroup.readEntry( plot_horizontalLines, s.horizontalLines );
269
276
    mSettings.automaticDetection = plotterGroup.readEntry( plot_automaticDetection, s.automaticDetection );
270
277
    mSettings.verticalLinesScroll = plotterGroup.readEntry( plot_verticalLinesScroll, s.verticalLinesScroll );
271
 
    mSettings.colorVLines = plotterGroup.readEntry( plot_colorVLines, s.colorVLines );
272
 
    mSettings.colorHLines = plotterGroup.readEntry( plot_colorHLines, s.colorHLines );
273
278
    mSettings.colorIncoming = plotterGroup.readEntry( plot_colorIncoming, s.colorIncoming );
274
279
    mSettings.colorOutgoing = plotterGroup.readEntry( plot_colorOutgoing, s.colorOutgoing );
275
 
    mSettings.colorBackground = plotterGroup.readEntry( plot_colorBackground, s.colorBackground );
276
 
    mSettings.opacity = clamp<int>(plotterGroup.readEntry( plot_opacity, s.opacity ), 0, 100 );
277
280
    configChanged();
278
281
}
279
282
 
290
293
    plotterGroup.writeEntry( plot_minimumValue, mSettings.minimumValue );
291
294
    plotterGroup.writeEntry( plot_maximumValue, mSettings.maximumValue );
292
295
    plotterGroup.writeEntry( plot_labels, mSettings.labels );
293
 
    plotterGroup.writeEntry( plot_bottomBar, mSettings.bottomBar );
294
296
    plotterGroup.writeEntry( plot_verticalLines, mSettings.verticalLines );
295
297
    plotterGroup.writeEntry( plot_horizontalLines, mSettings.horizontalLines );
296
298
    plotterGroup.writeEntry( plot_showIncoming, mSettings.showIncoming );
297
299
    plotterGroup.writeEntry( plot_showOutgoing, mSettings.showOutgoing );
298
300
    plotterGroup.writeEntry( plot_automaticDetection, mSettings.automaticDetection );
299
301
    plotterGroup.writeEntry( plot_verticalLinesScroll, mSettings.verticalLinesScroll );
300
 
    plotterGroup.writeEntry( plot_colorVLines, mSettings.colorVLines );
301
 
    plotterGroup.writeEntry( plot_colorHLines, mSettings.colorHLines );
302
302
    plotterGroup.writeEntry( plot_colorIncoming, mSettings.colorIncoming );
303
303
    plotterGroup.writeEntry( plot_colorOutgoing, mSettings.colorOutgoing );
304
 
    plotterGroup.writeEntry( plot_colorBackground, mSettings.colorBackground );
305
 
    plotterGroup.writeEntry( plot_opacity, mSettings.opacity );
306
304
    config->sync();
307
305
    configChanged();
308
306
}
309
307
 
310
308
void InterfacePlotterDialog::configChanged()
311
309
{
312
 
    QFont font = mPlotter->axisFont();
313
 
    font.setPointSize( mSettings.fontSize );
314
 
    QFontMetrics fm( font );
 
310
    QFont pfont = mPlotter->font();
 
311
    pfont.setPointSize( mSettings.fontSize );
 
312
    QFontMetrics fm( pfont );
315
313
    int axisTextWidth = fm.width(i18nc("Largest axis title", "99999 XXXX"));
316
314
    mPlotter->setMaxAxisTextWidth( axisTextWidth );
317
 
    mPlotter->setAxisFont( font );
 
315
    mPlotter->setFont( pfont );
 
316
    mPlotter->useBitrate( generalSettings->useBitrate );
318
317
    if ( !mSettings.automaticDetection )
319
318
    {
320
 
        mPlotter->setMinValue( mSettings.minimumValue );
321
 
        mPlotter->setMaxValue( mSettings.maximumValue );
 
319
        mPlotter->setMinimumValue( mSettings.minimumValue );
 
320
        mPlotter->setMaximumValue( mSettings.maximumValue );
322
321
    }
323
322
    mPlotter->setHorizontalScale( mSettings.pixel );
324
323
    mPlotter->setVerticalLinesDistance( mSettings.distance );
327
326
    mPlotter->setShowHorizontalLines( mSettings.horizontalLines );
328
327
    mPlotter->setUseAutoRange( mSettings.automaticDetection );
329
328
    mPlotter->setVerticalLinesScroll( mSettings.verticalLinesScroll );
330
 
    mPlotter->setVerticalLinesColor( mSettings.colorVLines );
331
 
    mPlotter->setHorizontalLinesColor( mSettings.colorHLines );
332
 
    mPlotter->setBackgroundColor( mSettings.colorBackground );
333
 
    mPlotter->setFillOpacity( mSettings.opacity * 255 / 100.0 + 0.5 );
334
329
 
335
330
    // add or remove beams according to user settings
336
331
    int visibleBeams = KSignalPlotter::NONE;
346
341
    mPlotter->setBeamColor( KSignalPlotter::OUTGOING_BEAM, mSettings.colorOutgoing );
347
342
    mPlotter->setVisibleBeams( visibleBeams );
348
343
 
349
 
    if ( mSettings.bottomBar )
350
 
    {
351
 
        if ( visibleBeams & KSignalPlotter::INCOMING_TRAFFIC )
352
 
            mReceivedLabel->show();
353
 
        else
354
 
            mReceivedLabel->hide();
 
344
    if ( visibleBeams & KSignalPlotter::INCOMING_TRAFFIC )
 
345
        mReceivedLabel->show();
 
346
    else
 
347
        mReceivedLabel->hide();
355
348
 
356
 
        if ( visibleBeams & KSignalPlotter::OUTGOING_TRAFFIC )
357
 
            mSentLabel->show();
358
 
        else
359
 
            mSentLabel->hide();
360
 
    }
 
349
    if ( visibleBeams & KSignalPlotter::OUTGOING_TRAFFIC )
 
350
        mSentLabel->show();
 
351
    else
 
352
        mSentLabel->hide();
361
353
}
362
354
 
363
355
#include "interfaceplotterdialog.moc"