summaryrefslogtreecommitdiffstats
path: root/workspace/LogReceiver/ndgui.cpp
blob: 629a8fbd914f5f9ffdc1c1035c18be3ef497aadb (plain) (blame)
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
86
87
88
89
90
91
92
93
94
95
#include "ndgui.h"

ndgui::ndgui(QWidget *parent)
    : QWidget(parent)
{
	ui.setupUi(this);

	connect(&logReceiver, SIGNAL(addNewInterface(QString, int)), this, SLOT(addNewInterface(QString, int)));
    connect(&logReceiver, SIGNAL(changeProgressBarValue(int , int )), this, SLOT(handleProgress(int, int)));

    buildGui();

    logReceiver.initAndRun("/var/tmp/qt_c_socket_custom");


	setWindowTitle(tr("NetD"));
}

ndgui::~ndgui()
{

}

void ndgui::buildGui() {

	ndStatusLabel = new QLabel(tr("test"));
	ndStatusLabel->setSizePolicy(QSizePolicy::Expanding,
	                                    QSizePolicy::Expanding);
	ndStatusLabel->setAlignment(Qt::AlignCenter);
	ndStatusLabel->setMinimumSize(100, 20);

	// create interface group box
	createInterfaceGroupBox();



    mainLayout = new QVBoxLayout;
    mainLayout->addWidget(ndStatusLabel);
    mainLayout->addWidget(interfaceGroupBox);

    setLayout(mainLayout);
}

void ndgui::createInterfaceGroupBox(){
    interfaceGroupBox = new QGroupBox(tr("Interfaces"));

    interfaceGroupBoxLayout = new QVBoxLayout;
    /* add interfaces via addInterfacesToGroupBox()*/

    interfaceGroupBox->setLayout(interfaceGroupBoxLayout);
}

void ndgui::addNewInterface(QString ifName, int index) {
	QHBoxLayout *hBoxLayout = new QHBoxLayout;
	QLabel *label = new QLabel(ifName);
	QProgressBar *pBar = new QProgressBar(this);
	pBar->setRange(1, 100);
	pBar->setMaximumSize(200, 20);

	progressBars.insert(index, pBar);

	hBoxLayout->addWidget(label, Qt::AlignLeft);
	hBoxLayout->addWidget(pBar, Qt::AlignRight);

	interfaceGroupBoxLayout->addLayout(hBoxLayout, 2);
}
/*
void ndgui::addInterfacesToGroupBox(QList<QNetworkInterface> &interfaces) {
	foreach(QNetworkInterface nI, interfaces){
		int index = indexToIfaceNameMap.value(nI.humanReadableName());
		QHBoxLayout *hBoxLayout = new QHBoxLayout;
	    QLabel *label = new QLabel(nI.humanReadableName());
	    QProgressBar *pBar = new QProgressBar(this);
	    pBar->setRange(1,100);
	    pBar->setMaximumSize(200,20);

	    progressBars.insert(index,pBar);

	    hBoxLayout->addWidget(label, Qt::AlignLeft);
	    hBoxLayout->addWidget(pBar, Qt::AlignRight);

	    interfaceGroupBoxLayout->addLayout(hBoxLayout,2);
	}
}
*/
void ndgui::handleProgress(int iFaceIndex, int newValue) {
	qDebug() << "<[---]> SLOT handleProgress activated with: " << iFaceIndex << newValue;
		QProgressBar * pBar = progressBars.value(iFaceIndex);
		if(newValue >= pBar->value()) {
	        pBar->setValue(newValue);
		}
		else {
		    qDebug() << "Error: new value is smaller than the old value!";
		}
}