This repository has been archived by the owner on Feb 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
tftpapp.cpp
executable file
·94 lines (84 loc) · 2.32 KB
/
tftpapp.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
#include "tftpapp.h"
#include "ui_tftpapp.h"
TFTPApp::TFTPApp(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::TFTPApp)
{
ui->setupUi(this);
qRegisterMetaType<rqCode>("rqCode");
server = NULL;
client = NULL;
}
TFTPApp::~TFTPApp()
{
delete ui;
// if(server != NULL){
// delete server;
// }
// if(client != NULL){
// delete client;
// }
}
void TFTPApp::on_pbStartStopServer_pressed()
{
if(server != NULL){
if(server->isRunning()){
server->stop();
server = NULL;
ui->pbStartStopServer->setText("Iniciar");
}
}else{
server = new TFTPServer(ui->leServerIP->text(),
(qint16)ui->spServerPort->value(), this);
try{
server->start();
ui->pbStartStopServer->setText("Detener");
}catch(int e){
QMessageBox::information(this, "Error! =(", "Error al iniciar el servidor. \nVea el Log para más información.");
server = NULL;
}
}
}
void TFTPApp::on_pbPut_pressed()
{
// toggleClientButtons(false);
if(client == NULL){
client = new TFTPClient(ui->leIPHost->text(), (qint16)ui->spPort->value(),
ui->leFileName->text(),this);
// connect(client, SIGNAL(workerDone()), this, SLOT(workerDone()));
}else{
client->setReqInfo(ui->leIPHost->text(), (qint16)ui->spPort->value(),
ui->leFileName->text());
}
// connect(client, SIGNAL(workerDone(bool)), this, SLOT(workerDone()));
client->putFile();
}
void TFTPApp::on_pbGet_pressed()
{
// toggleClientButtons(false);
if(client == NULL){
client = new TFTPClient(ui->leIPHost->text(), (qint16)ui->spPort->value(),
ui->leFileName->text(), this);
}else{
client->setReqInfo(ui->leIPHost->text(), (qint16)ui->spPort->value(),
ui->leFileName->text());
}
client->getFile();
}
void TFTPApp::on_pbStopClient_pressed()
{
if(client != NULL){
client->stopTransfer();
}
// toggleClientButtons(true);
}
void TFTPApp::toggleClientButtons(bool val)
{
ui->pbGet->setEnabled(val);
ui->pbPut->setEnabled(val);
ui->pbStopClient->setEnabled(!val);
}
void TFTPApp::workerDone()
{
toggleClientButtons(true);
}