mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
Settings DB
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include <QMessageBox>
|
||||
#include <QProcess>
|
||||
#include <QFile>
|
||||
#include <QResizeEvent>
|
||||
#include "specialmessagebox.h"
|
||||
#include "dialogcheckdb.h"
|
||||
#include "ui_dialogcheckdb.h"
|
||||
@@ -8,33 +9,78 @@
|
||||
DialogCheckDB::DialogCheckDB(ProviderDBLMS* providerDBLMS, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::DialogCheckDB),
|
||||
providerDBLMS(providerDBLMS),
|
||||
resDriver(false),
|
||||
resUser(false),
|
||||
resDB(false)
|
||||
waitAnimationWidget(nullptr),
|
||||
providerDBLMS(providerDBLMS)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
connect(this, &DialogCheckDB::signal_CheckDB, providerDBLMS, &ProviderDBLMS::slot_CheckDB);
|
||||
connect(providerDBLMS, &ProviderDBLMS::signal_CheckDBResult, this, &DialogCheckDB::slot_CheckDBResult);
|
||||
|
||||
connect(this, &DialogCheckDB::signal_RepareDB, providerDBLMS, &ProviderDBLMS::slot_RepareDB);
|
||||
connect(providerDBLMS, &ProviderDBLMS::signal_RepareDBResult, this, &DialogCheckDB::slot_RepareDBResult);
|
||||
|
||||
|
||||
waitAnimationWidget = new WaitAnimationWidget;
|
||||
QMovie *movie = new QMovie(":/resources/icons/762.gif");
|
||||
waitAnimationWidget->setParent(this);
|
||||
waitAnimationWidget->initialize(movie,this);
|
||||
|
||||
ui->btnRepare->setObjectName("btnRepare");
|
||||
|
||||
ui->btnRepare->setEnabled(false);
|
||||
|
||||
check();
|
||||
ui->btnRepare->setEnabled(false);
|
||||
}
|
||||
|
||||
DialogCheckDB::~DialogCheckDB()
|
||||
{
|
||||
if(waitAnimationWidget)
|
||||
{
|
||||
waitAnimationWidget->hideWithStop();
|
||||
delete waitAnimationWidget;
|
||||
}
|
||||
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void DialogCheckDB::initialize()
|
||||
{
|
||||
check();
|
||||
}
|
||||
|
||||
void DialogCheckDB::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QSize size = event->size();
|
||||
waitAnimationWidget->resize(size);
|
||||
}
|
||||
|
||||
void DialogCheckDB::check()
|
||||
{
|
||||
resDriver = false;
|
||||
resUser = false;
|
||||
resDB = false;
|
||||
waitAnimationWidget->showWithPlay();
|
||||
|
||||
resDriver = providerDBLMS->checkDriverQPSQLavailable();
|
||||
if(resDriver)
|
||||
emit signal_CheckDB();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void DialogCheckDB::on_btnRepare_clicked()
|
||||
{
|
||||
waitAnimationWidget->showWithPlay();
|
||||
|
||||
if(!checkResult.resDriver)
|
||||
{
|
||||
SpecMsgBox::CriticalClose(this, tr("Install PostgreSQL."));
|
||||
this->reject();
|
||||
return;
|
||||
}
|
||||
|
||||
emit signal_RepareDB(checkResult);
|
||||
}
|
||||
|
||||
void DialogCheckDB::slot_CheckDBResult(CheckResult result)
|
||||
{
|
||||
checkResult = result;
|
||||
|
||||
if(result.resDriver)
|
||||
{
|
||||
ui->lblDriverRes->setText(tr("Installed"));
|
||||
ui->lblDriverResIco->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleGreen.png")));
|
||||
@@ -45,8 +91,7 @@ void DialogCheckDB::check()
|
||||
ui->lblDriverResIco->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleRed.png")));
|
||||
}
|
||||
|
||||
resUser = providerDBLMS->checkUserLMSexist();
|
||||
if(resUser)
|
||||
if(result.resUser)
|
||||
{
|
||||
ui->lblUserRes->setText(tr("Exist"));
|
||||
ui->lblUserResIco->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleGreen.png")));
|
||||
@@ -57,8 +102,7 @@ void DialogCheckDB::check()
|
||||
ui->lblUserResIco->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleRed.png")));
|
||||
}
|
||||
|
||||
resDB = providerDBLMS->checkDataBaseLMSexist();
|
||||
if(resDB)
|
||||
if(result.resDB)
|
||||
{
|
||||
ui->lblDBRes->setText(tr("Exist"));
|
||||
ui->lblDBResIco->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleGreen.png")));
|
||||
@@ -69,48 +113,39 @@ void DialogCheckDB::check()
|
||||
ui->lblDBResIco->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleRed.png")));
|
||||
}
|
||||
|
||||
if(!resDriver || !resUser || !resDB)
|
||||
if(!result.resDriver || !result.resUser || !result.resDB)
|
||||
{
|
||||
ui->btnRepare->setEnabled(true);
|
||||
}
|
||||
else
|
||||
ui->btnRepare->setEnabled(false);
|
||||
|
||||
waitAnimationWidget->hideWithStop();
|
||||
}
|
||||
|
||||
void DialogCheckDB::on_btnRepare_clicked()
|
||||
void DialogCheckDB::slot_RepareDBResult(CheckResult result)
|
||||
{
|
||||
if(!resDriver)
|
||||
checkResult = result;
|
||||
|
||||
if(!checkResult.resUser)
|
||||
{
|
||||
SpecMsgBox::CriticalClose(this, tr("Install PostgreSQL."));
|
||||
slot_CheckDBResult(checkResult);
|
||||
SpecMsgBox::CriticalClose(this, tr("Failed to create user!"));
|
||||
this->reject();
|
||||
return;
|
||||
}
|
||||
|
||||
if(!resUser)
|
||||
if(!checkResult.resDB)
|
||||
{
|
||||
if(!providerDBLMS->createUser())
|
||||
{
|
||||
check();
|
||||
SpecMsgBox::CriticalClose(this, tr("Failed to create user!"));
|
||||
this->reject();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(!resDB)
|
||||
{
|
||||
if(!providerDBLMS->createDB())
|
||||
{
|
||||
check();
|
||||
SpecMsgBox::CriticalClose(this, tr("Failed to create Database!"));
|
||||
this->reject();
|
||||
return;
|
||||
}
|
||||
slot_CheckDBResult(checkResult);
|
||||
SpecMsgBox::CriticalClose(this, tr("Failed to create Database!"));
|
||||
this->reject();
|
||||
return;
|
||||
}
|
||||
|
||||
check();
|
||||
|
||||
if(resDriver && resUser && resDB)
|
||||
if(checkResult.resDriver && checkResult.resUser && checkResult.resDB)
|
||||
{
|
||||
SpecMsgBox::InfoOk(this, tr("The database has been successfully restored!"));
|
||||
this->accept();
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <QDialog>
|
||||
#include "providerdblms.h"
|
||||
#include "waitanimationwidget.h"
|
||||
|
||||
namespace Ui {
|
||||
class DialogCheckDB;
|
||||
@@ -16,9 +17,22 @@ public:
|
||||
explicit DialogCheckDB(ProviderDBLMS* providerDBLMS, QWidget *parent = nullptr);
|
||||
~DialogCheckDB();
|
||||
|
||||
void initialize();
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
|
||||
private slots:
|
||||
void on_btnRepare_clicked();
|
||||
|
||||
signals:
|
||||
void signal_CheckDB();
|
||||
void signal_RepareDB(CheckResult result);
|
||||
|
||||
public slots:
|
||||
void slot_CheckDBResult(CheckResult result);
|
||||
void slot_RepareDBResult(CheckResult result);
|
||||
|
||||
private:
|
||||
void check();
|
||||
void prepareRestoreDBscript();
|
||||
@@ -26,11 +40,11 @@ private:
|
||||
private:
|
||||
Ui::DialogCheckDB *ui;
|
||||
|
||||
WaitAnimationWidget *waitAnimationWidget;
|
||||
|
||||
ProviderDBLMS* providerDBLMS;
|
||||
|
||||
bool resDriver;
|
||||
bool resUser;
|
||||
bool resDB;
|
||||
CheckResult checkResult;
|
||||
};
|
||||
|
||||
#endif // DIALOGCHECKDB_H
|
||||
|
||||
@@ -24,7 +24,13 @@ DialogSettingsTray::DialogSettingsTray(ProviderDBLMS* providerDBLMS, QWidget *pa
|
||||
#ifndef PROJECT_TYPE_DEBUG
|
||||
ui->checkLocalhost->setEnabled(false);
|
||||
ui->btnUpdateDocs->setVisible(false);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef PROJECT_TYPE_DEBUG
|
||||
ui->editNameDB->setEnabled(true);
|
||||
ui->editUserName->setEnabled(true);
|
||||
ui->editPassword->setEnabled(true);
|
||||
#endif
|
||||
|
||||
/* Создаем строку для регулярного выражения */
|
||||
QString ipRange = "(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])";
|
||||
@@ -298,7 +304,7 @@ void DialogSettingsTray::on_checkLocalhost_stateChanged(int arg1)
|
||||
void DialogSettingsTray::on_btnCheckDB_clicked()
|
||||
{
|
||||
//Проверяем, установлен ли PostgreSQL
|
||||
if(!providerDBLMS->checkDriverQPSQLavailable())
|
||||
if(!ProviderDBLMS::checkDriverQPSQLavailable())
|
||||
{
|
||||
SpecMsgBox::CriticalClose(this, tr("Driver PostgreSQL is not installed!"));
|
||||
return;
|
||||
@@ -332,10 +338,11 @@ void DialogSettingsTray::on_btnCheckDB_clicked()
|
||||
return;
|
||||
}
|
||||
|
||||
if(providerDBLMS->setUserPasswordPostgres(UserNamePostgres, PasswordPostgres))
|
||||
if(ProviderDBLMS::setUserPasswordPostgres(UserNamePostgres, PasswordPostgres))
|
||||
{
|
||||
DialogCheckDB dlgCheckDB(providerDBLMS, this);
|
||||
dlgCheckDB.setWindowFlags(dlgCheckDB.windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
dlgCheckDB.initialize();
|
||||
|
||||
switch( dlgCheckDB.exec() )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user