Refactoring
This commit is contained in:
parent
13f9764853
commit
5eede71667
21 changed files with 566 additions and 220 deletions
|
@ -2,10 +2,14 @@
|
|||
#include <QMessageBox>
|
||||
#include <QSysInfo>
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
|
||||
#include "communicator.h"
|
||||
|
||||
#include "core/errorstrings.h"
|
||||
#include "core/openvpnconfigurator.h"
|
||||
#include "core/servercontroller.h"
|
||||
|
||||
#include "debug.h"
|
||||
#include "defines.h"
|
||||
#include "mainwindow.h"
|
||||
|
@ -34,6 +38,10 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
ui->stackedWidget_main->setSpeed(200);
|
||||
ui->stackedWidget_main->setAnimation(QEasingCurve::Linear);
|
||||
|
||||
ui->label_new_server_wait_info->setVisible(false);
|
||||
ui->progressBar_new_server_connection->setMinimum(0);
|
||||
ui->progressBar_new_server_connection->setMaximum(300);
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
ui->widget_tittlebar->hide();
|
||||
ui->stackedWidget_main->move(0,0);
|
||||
|
@ -48,6 +56,8 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
goToPage(Page::Initialization);
|
||||
}
|
||||
|
||||
//goToPage(Page::Initialization);
|
||||
|
||||
connect(ui->pushButton_blocked_list, SIGNAL(clicked(bool)), this, SLOT(onPushButtonBlockedListClicked(bool)));
|
||||
connect(ui->pushButton_connect, SIGNAL(toggled(bool)), this, SLOT(onPushButtonConnectToggled(bool)));
|
||||
connect(ui->pushButton_settings, SIGNAL(clicked(bool)), this, SLOT(onPushButtonSettingsClicked(bool)));
|
||||
|
@ -148,28 +158,71 @@ void MainWindow::onPushButtonNewServerConnectWithNewData(bool clicked)
|
|||
ui->lineEdit_new_server_password->text().isEmpty() ) {
|
||||
QMessageBox::warning(this, APPLICATION_NAME, tr("Please fill in all fields"));
|
||||
return;
|
||||
} else {
|
||||
qDebug() << "Start connection with new data";
|
||||
m_settings->setServerName(ui->lineEdit_new_server_ip->text());
|
||||
m_settings->setLogin(ui->lineEdit_new_server_login->text());
|
||||
m_settings->setPassword(ui->lineEdit_new_server_password->text());
|
||||
m_settings->save();
|
||||
|
||||
//goToPage(Page::Vpn);
|
||||
|
||||
if (requestOvpnConfig(m_settings->serverName(), m_settings->login(), m_settings->password())) {
|
||||
goToPage(Page::Vpn);
|
||||
|
||||
ui->pushButton_connect->setDown(true);
|
||||
|
||||
if (!m_vpnConnection->connectToVpn()) {
|
||||
ui->pushButton_connect->setChecked(false);
|
||||
QMessageBox::critical(this, APPLICATION_NAME, m_vpnConnection->lastError());
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << "Start connection with new data";
|
||||
|
||||
ServerCredentials serverCredentials;
|
||||
serverCredentials.hostName = ui->lineEdit_new_server_ip->text();
|
||||
if (serverCredentials.hostName.contains(":")) {
|
||||
serverCredentials.port = serverCredentials.hostName.split(":").at(1).toInt();
|
||||
serverCredentials.hostName = serverCredentials.hostName.split(":").at(0);
|
||||
}
|
||||
serverCredentials.userName = ui->lineEdit_new_server_login->text();
|
||||
serverCredentials.password = ui->lineEdit_new_server_password->text();
|
||||
|
||||
m_settings->setServerCredentials(serverCredentials);
|
||||
m_settings->save();
|
||||
|
||||
ui->page_new_server->setEnabled(false);
|
||||
ui->pushButton_new_server_connect_with_new_data->setVisible(false);
|
||||
ui->label_new_server_wait_info->setVisible(true);
|
||||
|
||||
QTimer timer;
|
||||
connect(&timer, &QTimer::timeout, [&](){
|
||||
ui->progressBar_new_server_connection->setValue(ui->progressBar_new_server_connection->value() + 1);
|
||||
});
|
||||
|
||||
ui->progressBar_new_server_connection->setValue(0);
|
||||
timer.start(1000);
|
||||
|
||||
|
||||
ErrorCode e = ServerController::setupServer(serverCredentials, Protocol::Any);
|
||||
if (e) {
|
||||
ui->page_new_server->setEnabled(true);
|
||||
ui->pushButton_new_server_connect_with_new_data->setVisible(true);
|
||||
ui->label_new_server_wait_info->setVisible(false);
|
||||
|
||||
QMessageBox::warning(this, APPLICATION_NAME,
|
||||
tr("Error occurred while configuring server.") + "\n" +
|
||||
errorString(e) + "\n" +
|
||||
tr("See logs for details."));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// just ui progressbar tweak
|
||||
timer.stop();
|
||||
|
||||
int remaining_val = ui->progressBar_new_server_connection->maximum() - ui->progressBar_new_server_connection->value();
|
||||
|
||||
if (remaining_val > 0) {
|
||||
QTimer timer1;
|
||||
QEventLoop loop1;
|
||||
|
||||
connect(&timer1, &QTimer::timeout, [&](){
|
||||
ui->progressBar_new_server_connection->setValue(ui->progressBar_new_server_connection->value() + 1);
|
||||
if (ui->progressBar_new_server_connection->value() >= ui->progressBar_new_server_connection->maximum()) {
|
||||
loop1.quit();
|
||||
}
|
||||
});
|
||||
|
||||
timer1.start(5);
|
||||
loop1.exec();
|
||||
}
|
||||
|
||||
goToPage(Page::Vpn);
|
||||
ui->pushButton_connect->setChecked(true);
|
||||
}
|
||||
|
||||
void MainWindow::onBytesChanged(quint64 receivedData, quint64 sentData)
|
||||
|
@ -249,9 +302,13 @@ void MainWindow::onConnectionStateChanged(VpnProtocol::ConnectionState state)
|
|||
void MainWindow::onPushButtonConnectToggled(bool checked)
|
||||
{
|
||||
if (checked) {
|
||||
if (!m_vpnConnection->connectToVpn()) {
|
||||
// TODO: Call connectToVpn with restricted server account
|
||||
ServerCredentials credentials = m_settings->serverCredentials();
|
||||
|
||||
ErrorCode errorCode = m_vpnConnection->connectToVpn(credentials);
|
||||
if (errorCode) {
|
||||
ui->pushButton_connect->setChecked(false);
|
||||
QMessageBox::critical(this, APPLICATION_NAME, m_vpnConnection->lastError());
|
||||
QMessageBox::critical(this, APPLICATION_NAME, errorString(errorCode));
|
||||
return;
|
||||
}
|
||||
ui->pushButton_connect->setEnabled(false);
|
||||
|
@ -260,36 +317,6 @@ void MainWindow::onPushButtonConnectToggled(bool checked)
|
|||
}
|
||||
}
|
||||
|
||||
bool MainWindow::requestOvpnConfig(const QString& hostName, const QString& userName, const QString& password, int port, int timeout)
|
||||
{
|
||||
QSsh::SshConnectionParameters sshParams;
|
||||
sshParams.authenticationType = QSsh::SshConnectionParameters::AuthenticationTypePassword;
|
||||
sshParams.host = hostName;
|
||||
sshParams.userName = userName;
|
||||
sshParams.password = password;
|
||||
sshParams.timeout = timeout;
|
||||
sshParams.port = port;
|
||||
sshParams.hostKeyCheckingMode = QSsh::SshHostKeyCheckingMode::SshHostKeyCheckingNone;
|
||||
|
||||
if (!ServerController::setupServer(sshParams, ServerController::OpenVPN)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QString configData = OpenVpnConfigurator::genOpenVpnConfig(sshParams);
|
||||
if (configData.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QFile file(Utils::defaultVpnConfigFileName());
|
||||
if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)){
|
||||
QTextStream stream(&file);
|
||||
stream << configData << endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void MainWindow::on_pushButton_close_clicked()
|
||||
{
|
||||
qApp->exit();
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <QMainWindow>
|
||||
|
||||
#include "framelesswindow.h"
|
||||
#include "vpnprotocol.h"
|
||||
#include "protocols/vpnprotocol.h"
|
||||
|
||||
class Settings;
|
||||
class VpnConnection;
|
||||
|
@ -45,9 +45,6 @@ private slots:
|
|||
|
||||
void on_pushButton_close_clicked();
|
||||
|
||||
protected:
|
||||
bool requestOvpnConfig(const QString& hostName, const QString& userName, const QString& password, int port = 22, int timeout = 30);
|
||||
|
||||
private:
|
||||
void goToPage(Page page);
|
||||
|
||||
|
|
|
@ -653,10 +653,7 @@ color: #333333;</string>
|
|||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QPushButton {
|
||||
font-size: 13pt;
|
||||
font: "Open Sans Semibold";
|
||||
color:rgb(212, 212, 212);
|
||||
|
||||
color:rgb(212, 212, 212);
|
||||
border-radius: 4px;
|
||||
|
||||
font-family: Lato;
|
||||
|
@ -708,8 +705,26 @@ color: #15CDCB;</string>
|
|||
</rect>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">background: #181922;
|
||||
border-radius: 4px;</string>
|
||||
<string notr="true">QProgressBar{
|
||||
color:rgb(212, 212, 212);
|
||||
border-radius: 4px;
|
||||
|
||||
font-family: Lato;
|
||||
font-style: normal;
|
||||
font-weight: normal;
|
||||
font-size: 16px;
|
||||
line-height: 21px;
|
||||
|
||||
background: #100A44;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
QProgressBar::chunk {
|
||||
background: rgba(255, 255, 255, 0.15);
|
||||
border-radius: 4px 0px 0px 4px;
|
||||
|
||||
}
|
||||
</string>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>24</number>
|
||||
|
@ -721,7 +736,7 @@ border-radius: 4px;</string>
|
|||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="format">
|
||||
<string>Connecting...</string>
|
||||
<string>Configuring...</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton_back_from_new_server">
|
||||
|
@ -772,6 +787,25 @@ QPushButton:hover {
|
|||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_new_server_wait_info">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>40</x>
|
||||
<y>490</y>
|
||||
<width>301</width>
|
||||
<height>41</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Please wait, configuring process may take up to 5 minutes</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<zorder>progressBar_new_server_connection</zorder>
|
||||
<zorder>label_2</zorder>
|
||||
<zorder>label_4</zorder>
|
||||
|
@ -784,6 +818,7 @@ QPushButton:hover {
|
|||
<zorder>pushButton</zorder>
|
||||
<zorder>pushButton_back_from_new_server</zorder>
|
||||
<zorder>label_7</zorder>
|
||||
<zorder>label_new_server_wait_info</zorder>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page_amnezia">
|
||||
<property name="styleSheet">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue