-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidget.cpp
83 lines (69 loc) · 2.88 KB
/
widget.cpp
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
#include "widget.h"
Widget::Widget(QWidget *parent, int argc, char** argv) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
Network* network = new Network();
bool ok = true;
QString text;
if(argc > 1) {
text = argv[1];
} else {
QString devList = network->getInterfaceList();
text = QInputDialog::getText(this, tr("Info"),tr("Interface list:\n"+devList.toUtf8()+"\n\nInput target interface:"), QLineEdit::Normal, network->getFirstInterface(), &ok); // wlp0s20f3
}
if(!ok) {
parent->close();
}
loadUI();
connect(network, SIGNAL(signalGUI(QVariant)), this, SLOT(addData(const QVariant&)));
network->startCapture(text);
}
Widget::~Widget()
{
delete ui;
}
void Widget::loadUI() {
ui->tableWidget->setColumnCount(11);
ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableWidget->setHorizontalHeaderLabels(QStringList()
<< "No"
<< "Type"
<< "Source"
<< "Destination"
<< "Protocol"
<< "Source"
<< "Destination"
<< "len"
<< "Source Port"
<< "Destination Port"
<< "Data");
ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
}
void Widget::addData(const QVariant &data) {
QStringList list = data.toStringList();
int index = list[0].toInt()-1;
ui->tableWidget->insertRow(index);
for(int i=0; i<11; i++) {
QTableWidgetItem* item = new QTableWidgetItem(list[i]);
ui->tableWidget->setItem(index, i, item);
}
printList(list);
update();
}
void Widget::printList(QStringList list) {
printf("----------------------------------\n");
printf("Type:%s\n", list[1].toUtf8().constData());
printf("Source:%s\n", list[2].toUtf8().constData());
printf("Destination:%s\n", list[3].toUtf8().constData());
printf("Protocol:%s\n", list[4].toUtf8().constData());
printf("Source:%s\n", list[5].toUtf8().constData());
printf("Destination:%s\n", list[6].toUtf8().constData());
printf("Len:%s\n", list[7].toUtf8().constData());
printf("Source Port:%s\n", list[8].toUtf8().constData());
printf("Destination Port:%s\n", list[9].toUtf8().constData());
printf("Data:%s\n", list[10].toUtf8().constData());
printf("----------------------------------\n\n");
}