-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
65 lines (62 loc) · 1.7 KB
/
main.cpp
File metadata and controls
65 lines (62 loc) · 1.7 KB
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
//cmake -S . -B .
//make
#include <QApplication>
#include <QWidget>
#include <QPushButton>
#include <QLabel>
#include <QLineEdit>
#include <QVBoxLayout>
#include <QMessageBox>
#include <QFileInfo>
#include <QDir>
#include "main.h"
#include "httpserver.h"
class Window: public QWidget
{
public:
Window(QHostAddress& address, int port): QWidget(nullptr)
{
QPushButton* exitButton = new QPushButton("exit");
connect(exitButton, &QPushButton::clicked, this, &Window::close);
QVBoxLayout* layout = new QVBoxLayout;
layout->addWidget(exitButton);
setLayout(layout);
resize(300, 200);
Server* server = new Server(this);
if (!server->listen(address, port)) {
QMessageBox::critical(this, "", "!tcpServer->listen()");
return;
}
connect(server, &Server::newConnection, server, &Server::newClient);
QLineEdit* addressLine = new QLineEdit("http://" + address.toString() + ":" + QString::number(port) + "/");
QLabel* info = new QLabel();
layout->insertWidget(0, info);
layout->insertWidget(0, addressLine);
connect(server, &Server::clientPercentChanged, [info](int newValue){
if (newValue == 0)
info->setText("");
else
info->setText(QString::number(newValue) + "%");
});
}
};
int main(int argc, char** argv)
{
if (argc != 3)
return 0;
QByteArray arg(argv[1]);
QString arg1(arg);
QHostAddress address;
if (!address.setAddress(arg1))
return 0;
arg.clear();
arg.append(argv[2]);
QString arg2(arg);
int port = arg2.toInt();
QApplication app(argc, argv);
if (!QFileInfo::exists(CURRENT_PATH + FILES_DIR))
QDir(CURRENT_PATH).mkdir(FILES_DIR);
Window window(address, port);
window.show();
return app.exec();
}