summaryrefslogtreecommitdiff
path: root/src/traffic_window.cpp
blob: 7296db5a2035badc2b3cced944df1c100e4a0236 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/***************************************************************************
                             traffic_window.cpp
                             -------------------
    begin                : Thu Jul 04 2002
    copyright            : (C) 2002 - 2012 by Roland Riegel
    email                : feedback@roland-riegel.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "device.h"
#include "setting.h"
#include "settingstore.h"
#include "traffic_window.h"

using namespace std;

TrafficWindow::TrafficWindow()
    : Window(), m_curDev(0)
{
}

TrafficWindow::~TrafficWindow()
{
}

void TrafficWindow::processKey(int key)
{
    switch(key)
    {
        case KEY_RIGHT:
        case KEY_DOWN:
        case KEY_NPAGE:
        case KEY_ENTER:
        case '\n':
        case '\t':
        case '\015':
            m_curDev += showMultipleDevices() ? getHeight() / 9 : 1;
            break;
        case KEY_LEFT:
        case KEY_UP:
        case KEY_PPAGE:
            m_curDev -= showMultipleDevices() ? getHeight() / 9 : 1;
            break;
    }
}

void TrafficWindow::printTraffic(const vector<Device*>& devices)
{
    if((unsigned int) m_curDev >= devices.size() || m_curDev < 0)
        m_curDev = 0;

    // print data of the current device(s)
    if(!showMultipleDevices())
    {
        devices[m_curDev]->print(*this);
    }
    else
    {
        if((unsigned int) getHeight() / 9 >= devices.size())
            m_curDev = 0;

        int i = m_curDev;
        while(getHeight() - getY() >= 9)
        {
            devices[i++]->print(*this);

            if((unsigned int) i >= devices.size())
                break;
        }
    }
}

bool TrafficWindow::showMultipleDevices()
{
    return SettingStore::get("MultipleDevices");
}