-
Notifications
You must be signed in to change notification settings - Fork 1
/
mainwindow.cpp
executable file
·100 lines (84 loc) · 2.73 KB
/
mainwindow.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
98
99
100
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
if (!QSqlDatabase::drivers().contains("QMYSQL"))
{
QMessageBox::critical(
this,
"Unable to load database",
"This application needs the QMYSQL driver"
);
this->close();
}
else
{
ui->stackedWidget->setCurrentIndex(0);
ui->lineEdit_hostname->setText("127.0.0.1");
ui->lineEdit_dbname->setText("serverDB");
ui->lineEdit_port->setText("3306");
ui->lineEdit_username->setText("root");
ui->lineEdit_password->setText("mypass");
ui->lineEdit_password->setEchoMode(QLineEdit::Password);
ui->lineEdit_docspath->setText("Select folder");
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_logindb_clicked()
{
int indexWindow = ui->stackedWidget->currentIndex();
QString username = ui->lineEdit_username->text();
QString password = ui->lineEdit_password->text();
QString hostname = ui->lineEdit_hostname->text();
QString dbname = ui->lineEdit_dbname->text();
QString port = ui->lineEdit_port->text();
QSqlError err = initDb(hostname,dbname,port,username,password);
if (err.type() != QSqlError::NoError)
{
QMessageBox::critical(this,"dbError",err.text());
}
else
{
//Db disponibile
QMessageBox::information(this, "Login","ok");
ui->stackedWidget->setCurrentIndex(++indexWindow);
}
}
void MainWindow::on_pushButton_startServer_clicked()
{
if(m_tcpServer.listen(QHostAddress::Any,ui->portNumber->value()))
{
qDebug() << this << "server started!";
setStarted(true);
}
else
{
qCritical() << m_tcpServer.errorString();
QMessageBox::critical(this,"Server error","Try to change port");
setStarted(false);
}
}
void MainWindow::setStarted(bool started)
{
ui->pushButton_startServer->setEnabled(!started);
ui->pushButton_stopServer->setEnabled(started);
}
void MainWindow::on_pushButton_stopServer_clicked()
{
m_tcpServer.close();
setStarted(false);
}
void MainWindow::on_pushButton_selectDocsPath_clicked()
{
QString dir = QFileDialog::getExistingDirectory(this, tr("Select Documents Directory"),
"",
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks);
ui->lineEdit_docspath->setText(dir);
setDocumentsDirectory(dir);
}