mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJClient.git
synced 2026-03-28 05:25:39 +03:00
323 lines
8.9 KiB
C++
323 lines
8.9 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
|
|
#include <QTimer>
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
, ui(new Ui::MainWindow)
|
|
{
|
|
ui->setupUi(this);
|
|
Initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::Initialize()
|
|
{
|
|
|
|
ui->settingsWidget->hide();
|
|
ui->notificationLabel->hide();
|
|
ui->loadingProgressBar->hide();
|
|
ui->updateButton->hide();
|
|
ui->connectButton->hide();
|
|
ui->startButton->setEnabled(false);
|
|
ui->debugText->hide();
|
|
ui->displayGroupWidget->hide();
|
|
ui->autostartCheckBox->hide();
|
|
|
|
updateControllerThread = new QThread;
|
|
connectionThread = new QThread;
|
|
|
|
client = new TCPClient;
|
|
client->moveToThread(connectionThread);
|
|
|
|
dataParser = new DataParser;
|
|
|
|
updateController = new UpdateController(dataParser);
|
|
updateController->moveToThread(updateControllerThread);
|
|
|
|
recognizeSystem = new RecognizeSystem;
|
|
screenChecker = new ScreenChecker(dataParser,ui->displayWidget);
|
|
externalExecuter = new ExternalExecuter;
|
|
|
|
timer = new QTimer;
|
|
connect(timer,&QTimer::timeout,this,&MainWindow::disableNotify);
|
|
|
|
connect(recognizeSystem,&RecognizeSystem::UpdateBytesAvailable,this,&MainWindow::UpdateProgress);
|
|
connect(recognizeSystem,&RecognizeSystem::LoadComplete,this,&MainWindow::LoadComplete);
|
|
connect(recognizeSystem,&RecognizeSystem::onNeedUpdate,this,&MainWindow::SetNeedUpdate);
|
|
connect(recognizeSystem,&RecognizeSystem::onSendDebugLog,this,&MainWindow::DebugLog);
|
|
connect(recognizeSystem,&RecognizeSystem::SockedDisabled,this,&MainWindow::LostConnection);
|
|
connect(recognizeSystem,&RecognizeSystem::SaveLoginData,this,&MainWindow::CheckLoginResult);
|
|
connect(recognizeSystem,&RecognizeSystem::SocketWaitForReadyRead,client,&TCPClient::WaitRead,Qt::AutoConnection);
|
|
|
|
connect(client,&TCPClient::signalGetXmlAnswer,dataParser,&DataParser::slotGetXmlAnswer);
|
|
|
|
connectionThread->start();
|
|
updateControllerThread->start();
|
|
|
|
updateControllerThread->setPriority(QThread::LowPriority);
|
|
connectionThread->setPriority(QThread::HighestPriority);
|
|
|
|
connect(client,&TCPClient::onSendDebugLog,this,&MainWindow::DebugLog,Qt::AutoConnection);
|
|
|
|
connect(this,&MainWindow::onInitializeClient,client,&TCPClient::Initialize,Qt::AutoConnection);
|
|
connect(this,&MainWindow::onSetConnect,client,&TCPClient::SetConnect,Qt::AutoConnection);
|
|
connect(this,&MainWindow::onSendMessage,client,&TCPClient::MessageEntered,Qt::AutoConnection);
|
|
connect(this,&MainWindow::SendClientAuthorization,client,&TCPClient::SendClientAutorization,Qt::AutoConnection);
|
|
connect(client,&TCPClient::ConnectionState,this,&MainWindow::onConnectionState);
|
|
|
|
connect(this,&MainWindow::onCalculateHash,updateController,&UpdateController::CalculateHash);
|
|
|
|
emit onCalculateHash();
|
|
emit onInitializeClient(recognizeSystem,externalExecuter);
|
|
|
|
recognizeSystem->Initialize(updateController,dataParser);
|
|
|
|
screenChecker->Check();
|
|
ui->updateButton->setEnabled(false);
|
|
ui->startButton->setEnabled(false);
|
|
|
|
maxBytesAvailable = 0;
|
|
globalValue = 0;
|
|
|
|
ui->loadingProgressBar->setValue(0);
|
|
|
|
loadStaticData();
|
|
emit onSetConnect(dataParser->GetServerSettings());
|
|
|
|
CheckAppAvailable();
|
|
|
|
}
|
|
|
|
void MainWindow::UpdateProgress(qint64 size,quint64 sended)
|
|
{
|
|
float currentValue = 100.00 / (maxBytesAvailable / size);
|
|
globalValue += currentValue;
|
|
|
|
ui->loadingProgressBar->setValue(globalValue);
|
|
}
|
|
|
|
void MainWindow::LoadComplete()
|
|
{
|
|
ui->loadingProgressBar->setValue(100);
|
|
ui->updateButton->setEnabled(false);
|
|
externalExecuter->FindApp();
|
|
ui->startButton->setEnabled(true);
|
|
autoStart();
|
|
ui->inlineTextDebug->setText(tr("Обновление завершено..."));
|
|
}
|
|
|
|
void MainWindow::SetNeedUpdate(bool flag,quint64 size, quint64 fileCount)
|
|
{
|
|
maxBytesAvailable = 0;
|
|
QString availableSizeText;
|
|
|
|
if (flag){
|
|
QString result = tr("Доступно обновление: ") + Tools::convertFileSize(size);
|
|
result += tr("Количество файлов: ") + QString::number(fileCount);
|
|
ui->inlineTextDebug->setText(result);
|
|
maxBytesAvailable = size;
|
|
}
|
|
else
|
|
{
|
|
ui->inlineTextDebug->setText(tr("Установлена последняя версия"));
|
|
autoStart();
|
|
}
|
|
|
|
ui->updateButton->setEnabled(flag);
|
|
ui->startButton->setEnabled(!flag);
|
|
ui->loadingProgressBar->setRange(0,100);
|
|
}
|
|
|
|
void MainWindow::LostConnection()
|
|
{
|
|
ui->loadingProgressBar->setValue(0);
|
|
}
|
|
|
|
void MainWindow::CheckLoginResult(ServerAuthorization *serverAuth)
|
|
{
|
|
if (serverAuth->Result){
|
|
emit onSendMessage("check");
|
|
|
|
ui->inlineTextDebug->setText(tr("Проверка обновлений..."));
|
|
|
|
ui->loadingProgressBar->show();
|
|
ui->updateButton->show();
|
|
ui->displayGroupWidget->show();
|
|
ui->autostartCheckBox->show();
|
|
|
|
dataParser->CreateAuthData(serverAuth);
|
|
ui->loginWidget->hide();
|
|
|
|
}
|
|
else {
|
|
ui->notificationLabel->setText(tr("Неверный логин/пароль"));
|
|
timer->setInterval(3000);
|
|
timer->start();
|
|
|
|
QPalette palette = ui->notificationLabel->palette();
|
|
palette.setColor(ui->notificationLabel->foregroundRole(), Qt::red);
|
|
|
|
ui->notificationLabel->setPalette(palette);
|
|
ui->notificationLabel->show();
|
|
}
|
|
|
|
}
|
|
|
|
void MainWindow::CheckAppAvailable()
|
|
{
|
|
bool isAvailable = externalExecuter->FindApp();
|
|
ui->startButton->setEnabled(isAvailable);
|
|
}
|
|
|
|
void MainWindow::checkLanguage(QString language)
|
|
{
|
|
if (language == "RUS")
|
|
{
|
|
translator.load("QtLanguage_ru_RU",".");
|
|
}
|
|
else if(language == "ENG")
|
|
{
|
|
translator.load("QtLanguage_eng_EN",".");
|
|
}
|
|
|
|
qApp->installTranslator(&translator);
|
|
ui->retranslateUi(this);
|
|
}
|
|
|
|
void MainWindow::autoStart()
|
|
{
|
|
if(ui->autostartCheckBox->isChecked()){
|
|
on_startButton_clicked();
|
|
}
|
|
}
|
|
|
|
void MainWindow::loadStaticData()
|
|
{
|
|
ServerSettings *currentSettings = dataParser->GetServerSettings();
|
|
|
|
ui->serverInputField->setText(currentSettings->Address);
|
|
ui->portInputField->setText(currentSettings->Port);
|
|
ui->languageComboBox->setCurrentText(currentSettings->Language);
|
|
ui->autostartCheckBox->setChecked(currentSettings->isAutoStart);
|
|
|
|
checkLanguage(currentSettings->Language);
|
|
}
|
|
|
|
|
|
void MainWindow::on_loginButton_clicked()
|
|
{
|
|
QString username = ui->loginInputField->text();
|
|
QString password = ui->passwordInputField->text();
|
|
|
|
ClientAutorization *autorization = new ClientAutorization;
|
|
autorization->Login = username;
|
|
autorization->Password = password;
|
|
|
|
dataParser->CreateAuthMessage(autorization);
|
|
emit SendClientAuthorization();
|
|
}
|
|
|
|
void MainWindow::on_updateButton_clicked()
|
|
{
|
|
emit onSendMessage("update");
|
|
ui->updateButton->hide();
|
|
ui->loadingProgressBar->setValue(0);
|
|
}
|
|
|
|
void MainWindow::on_startButton_clicked()
|
|
{
|
|
client->SendUnityConnect();
|
|
externalExecuter->CallApp();
|
|
}
|
|
|
|
|
|
void MainWindow::on_saveServerButton_clicked()
|
|
{
|
|
ui->settingsWidget->hide();
|
|
ui->loginWidget->show();
|
|
|
|
QString server = ui->serverInputField->text();
|
|
QString port = ui->portInputField->text();
|
|
|
|
dataParser->CreateServerSettings(server,port);
|
|
|
|
emit onSetConnect(dataParser->GetServerSettings());
|
|
}
|
|
|
|
void MainWindow::on_settingsButton_clicked()
|
|
{
|
|
ui->settingsWidget->show();
|
|
ui->loginWidget->hide();
|
|
}
|
|
|
|
void MainWindow::disableNotify()
|
|
{
|
|
ui->notificationLabel->hide();
|
|
|
|
QPalette palette = ui->notificationLabel->palette();
|
|
palette.setColor(ui->notificationLabel->foregroundRole(), Qt::black);
|
|
|
|
ui->notificationLabel->setPalette(palette);
|
|
timer->stop();
|
|
}
|
|
|
|
void MainWindow::onConnectionState(bool flag)
|
|
{
|
|
ui->notificationLabel->show();
|
|
QPalette palette = ui->notificationLabel->palette();
|
|
|
|
if(flag)
|
|
{
|
|
palette.setColor(ui->notificationLabel->foregroundRole(),Qt::green);
|
|
ui->notificationLabel->setText(tr("Соединение установлено"));
|
|
ui->connectButton->hide();
|
|
}
|
|
else
|
|
{
|
|
palette.setColor(ui->notificationLabel->foregroundRole(),Qt::red);
|
|
ui->notificationLabel->setText(tr("Соединение отсутсвует"));
|
|
ui->connectButton->show();
|
|
}
|
|
|
|
ui->notificationLabel->setPalette(palette);
|
|
timer->start(3000);
|
|
}
|
|
|
|
void MainWindow::DebugLog(QString message)
|
|
{
|
|
ui->debugText->append(message);
|
|
}
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
connectionThread->quit();
|
|
connectionThread->wait();
|
|
|
|
updateControllerThread->quit();
|
|
updateControllerThread->wait();
|
|
|
|
client->sendDisable();
|
|
|
|
delete connectionThread;
|
|
delete updateControllerThread;
|
|
delete ui;
|
|
}
|
|
|
|
void MainWindow::on_connectButton_clicked()
|
|
{
|
|
emit onSetConnect(dataParser->GetServerSettings());
|
|
}
|
|
|
|
void MainWindow::on_languageComboBox_activated(const QString &arg1)
|
|
{
|
|
qDebug() << arg1;
|
|
dataParser->saveClientSettrings(arg1,ui->autostartCheckBox->isChecked());
|
|
checkLanguage(arg1);
|
|
ui->retranslateUi(this);
|
|
}
|