-
Notifications
You must be signed in to change notification settings - Fork 0
/
v2ui.cpp
97 lines (79 loc) · 2.14 KB
/
v2ui.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "v2ui.h"
#include "./ui_v2ui.h"
#include <QMenuBar>
#include <getserverdialog.h>
#include <QDebug>
#include <QJsonDocument>
#include <v2server.h>
#include <handler.h>
#include <QStringList>
#include <QMap>
v2Ui::v2Ui(QWidget *parent)
: QWidget(parent)
, ui(new Ui::v2Ui)
{
ui->setupUi(this);
handler = new Handler(new QObject ,this);
dialog = new getServerDialog(this);
connect(handler , &Handler::serverAdded , this , &v2Ui::serverAdded);
ui->deleteServerButton->setEnabled(false);
}
v2Ui::~v2Ui()
{
delete ui;
}
void v2Ui::setV2rayOutput(QString str)
{
ui->v2rayOutput->append(str);
}
void v2Ui::on_pushButton_clicked()
{
dialog->exec();
QString jsonString = dialog->jsonString;
QJsonDocument * doc = new QJsonDocument(QJsonDocument::fromJson(jsonString.toUtf8()));
v2Server * serverToBeAdded = new v2Server(this, doc);
handler->addServer(serverToBeAdded);
//tmp to be updated (having a list of servers with the ability to choose active server)
handler->setActiveServer(serverToBeAdded);
}
void v2Ui::serverAdded(v2Server *)
{
updateList();
}
void v2Ui::on_connectButton_clicked()
{
handler->connectToServer(handler->activeServer);
}
void v2Ui::updateList()
{
QStringList list;
foreach(v2Server* server , handler->serverList){
listMap[server->serverIP + ":" + server->serverPort] = server;
list.append(server->serverIP + ":" + server->serverPort);
}
ui->listWidget->clear();
ui->listWidget->addItems(list);
}
void v2Ui::on_pushButton_2_clicked()
{
handler->disconnect();
}
void v2Ui::on_listWidget_doubleClicked(const QModelIndex &index)
{
v2Server * tempServer = listMap[index.data(Qt::DisplayRole).toString()];
handler->activeServer = tempServer;
if(handler->isConnected){
handler->disconnect();
handler->connectToServer(handler->activeServer);
}
}
void v2Ui::on_listWidget_clicked(const QModelIndex &index)
{
ui->deleteServerButton->setEnabled(true);
selectedServer = listMap[index.data().toString()];
}
void v2Ui::on_deleteServerButton_clicked()
{
handler->removeServer(selectedServer);
updateList();
}