-
Notifications
You must be signed in to change notification settings - Fork 0
/
NetworkConfig.cpp
68 lines (53 loc) · 1.48 KB
/
NetworkConfig.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
#include "NetworkConfig.h"
#include "Incoming.h"
NetworkConfig::NetworkConfig(Outgoing *outgoing)
{
out = outgoing;
setWindowTitle("Configure remote ponds");
QGridLayout *layout2 = new QGridLayout(); //main widget
QPushButton *ok = new QPushButton("Ok");
connect(ok, SIGNAL(clicked()), this, SLOT(save()));
QPushButton *add = new QPushButton("Add");
connect(add, SIGNAL(clicked()), this, SLOT(add()));
QPushButton *remove = new QPushButton("Remove");
connect(remove, SIGNAL(clicked()), this, SLOT(remove()));
host = new QLineEdit();
port = new QSpinBox();
port->setMaximum(65554);
port->setValue(PORT);
list = new QListWidget(this);
layout2->addWidget(host,0,0);
layout2->addWidget(port,0,1);
layout2->addWidget(add,0,2);
layout2->addWidget(list,1,0,1,3);
for(int i = 0; i < out->size(); i++){
addPond(i);
}
layout2->addWidget(remove,2,2);
layout2->addWidget(ok,3,2);
setLayout(layout2);
}
NetworkConfig::~NetworkConfig()
{
}
void NetworkConfig::addPond(int index){
struct s_host tmpHost = out->getHost(index);
list->addItem(tmpHost.name +" : " + QString::number(tmpHost.port));
}
void NetworkConfig::add(){
if(!host->text().isEmpty()){
out->addHost(host->text() , port->value());
addPond(out->size() - 1);
}
}
void NetworkConfig::remove(){
QList<QListWidgetItem *> items = list->selectedItems();
if(items.size()){
int row = list->row(items.at(0));
out->deleteHost(row);
delete list->takeItem(row);
}
}
void NetworkConfig::save(){
accept();
}