mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJClient.git
synced 2026-03-28 05:25:39 +03:00
feat: display Update size and notification
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
@@ -8,6 +10,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
Initialize();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -19,12 +22,13 @@ void MainWindow::Initialize()
|
||||
ui->notificationLabel->hide();
|
||||
ui->loadingProgressBar->hide();
|
||||
ui->updateButton->hide();
|
||||
ui->connectButton->hide();
|
||||
ui->startButton->setEnabled(false);
|
||||
ui->debugText->hide();
|
||||
|
||||
updateControllerThread = new QThread;
|
||||
connectionThread = new QThread;
|
||||
|
||||
|
||||
client = new TCPClient;
|
||||
client->moveToThread(connectionThread);
|
||||
|
||||
@@ -37,6 +41,9 @@ void MainWindow::Initialize()
|
||||
screenChecker = new ScreenChecker;
|
||||
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);
|
||||
@@ -54,9 +61,10 @@ void MainWindow::Initialize()
|
||||
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::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);
|
||||
|
||||
@@ -66,11 +74,11 @@ void MainWindow::Initialize()
|
||||
recognizeSystem->Initialize(updateController,dataParser);
|
||||
|
||||
screenChecker->Check();
|
||||
ui->disblayCount->setText(screenChecker->getScreenCount());
|
||||
ui->updateButton->setEnabled(false);
|
||||
ui->startButton->setEnabled(false);
|
||||
|
||||
maxBytesAvailable = 0;
|
||||
globalValue = 0;
|
||||
ui->loadingProgressBar->setValue(0);
|
||||
|
||||
emit onSetConnect(dataParser->GetServerSettings());
|
||||
@@ -80,11 +88,10 @@ void MainWindow::Initialize()
|
||||
|
||||
void MainWindow::UpdateProgress(qint64 size,quint64 sended)
|
||||
{
|
||||
float currentValue = 100.00 / (maxBytesAvailable / size);
|
||||
globalValue += currentValue;
|
||||
|
||||
ui->loadingProgressBar->setMaximum(size);
|
||||
ui->loadingProgressBar->setMinimum(0);
|
||||
|
||||
ui->loadingProgressBar->setValue(sended);
|
||||
ui->loadingProgressBar->setValue(globalValue);
|
||||
}
|
||||
|
||||
void MainWindow::LoadComplete()
|
||||
@@ -95,29 +102,49 @@ void MainWindow::LoadComplete()
|
||||
ui->startButton->setEnabled(true);
|
||||
}
|
||||
|
||||
void MainWindow::SetNeedUpdate(bool flag)
|
||||
void MainWindow::SetNeedUpdate(bool flag,quint64 size)
|
||||
{
|
||||
maxBytesAvailable = 0;
|
||||
if(flag){
|
||||
quint64 megaByte = size / (1024 * 1024);
|
||||
QString result = "Доступно обновление: " + QString::number(megaByte) + " мегабайт";
|
||||
ui->inlineTextDebug->setText(result);
|
||||
maxBytesAvailable = size;
|
||||
}else{
|
||||
ui->inlineTextDebug->setText("Установлена последняя версия");
|
||||
}
|
||||
|
||||
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("Проверка обновлений...");
|
||||
ui->loadingProgressBar->show();
|
||||
ui->updateButton->show();
|
||||
dataParser->CreateAuthData(serverAuth);
|
||||
ui->loginWidget->hide();
|
||||
|
||||
}
|
||||
else {
|
||||
ui->notificationLabel->setText("Неверный логин/пароль");
|
||||
timer->setInterval(3000);
|
||||
timer->start();
|
||||
|
||||
QPalette palette = ui->notificationLabel->palette();
|
||||
palette.setColor(ui->notificationLabel->foregroundRole(), Qt::red);
|
||||
|
||||
ui->notificationLabel->setPalette(palette);
|
||||
ui->notificationLabel->show();
|
||||
}
|
||||
|
||||
@@ -179,6 +206,39 @@ void MainWindow::on_settingsButton_clicked()
|
||||
ui->portInputField->setText(currentSettings->Port);
|
||||
}
|
||||
|
||||
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("Соединение установлено");
|
||||
ui->connectButton->hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
palette.setColor(ui->notificationLabel->foregroundRole(),Qt::red);
|
||||
ui->notificationLabel->setText("Соединение отсутсвует");
|
||||
ui->connectButton->show();
|
||||
}
|
||||
|
||||
ui->notificationLabel->setPalette(palette);
|
||||
timer->start(3000);
|
||||
}
|
||||
|
||||
void MainWindow::DebugLog(QString message)
|
||||
{
|
||||
ui->debugText->append(message);
|
||||
@@ -198,3 +258,7 @@ MainWindow::~MainWindow()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MainWindow::on_connectButton_clicked()
|
||||
{
|
||||
emit onSetConnect(dataParser->GetServerSettings());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user