diff --git a/DataBaseLMS/CMakeLists.txt b/DataBaseLMS/CMakeLists.txt index 1c0ff5a..84ce26e 100644 --- a/DataBaseLMS/CMakeLists.txt +++ b/DataBaseLMS/CMakeLists.txt @@ -10,6 +10,7 @@ add_library(DataBaseLMS SHARED databaselms_users.cpp databaselms_instructors.cpp databaselms_trainees.cpp + databaselms_Postgresql.cpp databaselms.h interfacedatabaselms.cpp interfacedatabaselms.h diff --git a/DataBaseLMS/databaselms.cpp b/DataBaseLMS/databaselms.cpp index 252f4f9..eb0bf78 100644 --- a/DataBaseLMS/databaselms.cpp +++ b/DataBaseLMS/databaselms.cpp @@ -29,225 +29,6 @@ void DataBaseLMS::slot_LanguageChanged(QString language) QCoreApplication::installTranslator(&qtLanguageTranslator); } -bool DataBaseLMS::checkDriverQPSQLavailable() -{ - return QSqlDatabase::isDriverAvailable("QPSQL"); -} - -bool DataBaseLMS::checkUserLMSexist() -{ - DataBaseSettings dbSett = getDataBaseSettings(); - QSqlDatabase dbCheck = QSqlDatabase::addDatabase("QPSQL"); - - dbCheck.setUserName("postgres"); - dbCheck.setPassword("12345678"); - dbCheck.setHostName(dbSett.dbHostName); - dbCheck.setPort(dbSett.dbPort); - - if (dbCheck.open()) - { - QSqlQuery query = QSqlQuery(dbCheck); - query.prepare("SELECT 1 FROM pg_roles WHERE rolname = :username"); - query.bindValue(":username", dbSett.dbUserName); - - if (query.exec() && query.next()) - { - qDebug() << "Пользователь существует."; - return true; - } - else - { - qDebug() << "Пользователь не существует."; - return false; - } - } - else - { - qDebug() << "Ошибка подключения к PostreSQL."; - return false; - } -} - -bool DataBaseLMS::checkDataBaseLMSexist() -{ - DataBaseSettings dbSett = getDataBaseSettings(); - QSqlDatabase dbCheck = QSqlDatabase::addDatabase("QPSQL"); - - bool flDBexist = false; - - dbCheck.setUserName("postgres"); - dbCheck.setPassword("12345678"); - dbCheck.setHostName(dbSett.dbHostName); - dbCheck.setPort(dbSett.dbPort); - - if (dbCheck.open()) - { - QString queryStr = QString("SELECT datname FROM pg_database"); - QSqlQuery query = QSqlQuery(dbCheck); - - if(queryExec(queryStr, &query)) - { - while (query.next()) - {//Инструктор - QString nameDB = ""; - nameDB = query.value(0).toString(); - if(nameDB == dbSettings.dbName) - { - flDBexist = true; - break; - } - } - } - } - else - { - qDebug() << "Ошибка подключения к PostreSQL."; - return false; - } - return flDBexist; -} - -bool DataBaseLMS::createUser(QString name) -{ - DataBaseSettings dbSett = getDataBaseSettings(); - QSqlDatabase dbCheck = QSqlDatabase::addDatabase("QPSQL"); - - dbCheck.setUserName("postgres"); - dbCheck.setPassword("12345678"); - dbCheck.setHostName(dbSett.dbHostName); - dbCheck.setPort(dbSett.dbPort); - - if (dbCheck.open()) - { - QString queryStr = QString("CREATE USER %1 WITH ENCRYPTED PASSWORD '%2'").arg(dbSett.dbUserName, dbSett.dbPassword); - QSqlQuery query = QSqlQuery(dbCheck); - - if(queryExec(queryStr, &query)) - { - qDebug() << "Пользователь создан."; - return true; - } - else - { - qDebug() << "Пользователь не создан."; - return false; - } - } - else - { - qDebug() << "Ошибка подключения к PostreSQL."; - return false; - } -} - -bool DataBaseLMS::createDB(QString name) -{ - DataBaseSettings dbSett = getDataBaseSettings(); - QSqlDatabase dbCheck = QSqlDatabase::addDatabase("QPSQL"); - - dbCheck.setUserName("postgres"); - dbCheck.setPassword("12345678"); - dbCheck.setHostName(dbSett.dbHostName); - dbCheck.setPort(dbSett.dbPort); - - if (dbCheck.open()) - { - //Создание БД - QString queryStr = QString("CREATE DATABASE %1").arg(dbSett.dbName); - QSqlQuery query = QSqlQuery(dbCheck); - - if(queryExec(queryStr, &query)) - { - qDebug() << "БД создана."; - - //Залитие БД - - QProcess process; - //QString pgRestorePath = "C:\\restoreDB.bat"; // Замените на актуальный путь - QString pgRestorePath = "restoreDB.bat"; // Замените на актуальный путь - - /* - QString dbName = "databaselms2"; - QString user = "postgres"; - QString backupFile = "C:\\DBLMS_EMPTY_30_09_2025.backup"; - - QStringList arguments; - arguments << "-d" << dbName; - arguments << "-U" << user; - arguments << backupFile; - */ - - process.start("cmd /C " + pgRestorePath); - process.waitForFinished(-1); // Ждать бесконечно, пока процесс не завершится - - - //Назначение владельца - QString queryStr = QString("ALTER DATABASE %1 OWNER TO %2").arg(dbSett.dbName, dbSett.dbUserName); - QSqlQuery query = QSqlQuery(dbCheck); - if(queryExec(queryStr, &query)) - { - - } - else - return false; - - - - //return true; - } - else - { - qDebug() << "БД не создана."; - return false; - } - - - - - - } - else - { - qDebug() << "Ошибка подключения к PostreSQL."; - return false; - } - - dbCheck.close(); - - QSqlDatabase dbCheck2 = QSqlDatabase::addDatabase("QPSQL"); - - dbCheck2.setUserName("postgres"); - dbCheck2.setPassword("12345678"); - dbCheck2.setHostName(dbSett.dbHostName); - dbCheck2.setPort(dbSett.dbPort); - dbCheck2.setDatabaseName(dbSett.dbName); - - if (dbCheck2.open()) - { - QString newOwner = dbSett.dbUserName; - - // Получаем список таблиц - QSqlQuery query(dbCheck2); - query.exec("SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname = 'public';"); - - while (query.next()) - { - QString tableName = query.value(0).toString(); - QString alterQuery = QString("ALTER TABLE %1 OWNER TO %2;").arg(tableName).arg(newOwner); - qDebug() << "Executing: " << alterQuery; - dbCheck2.exec(alterQuery); - /* - if (dbCheck2.exec(alterQuery)) - { - qDebug() << "Error changing owner for table " << tableName << ":" << dbCheck2.lastError().text(); - return false; - }*/ - } - } - - return true; -} - bool DataBaseLMS::createConnection() { dbSettings = getDataBaseSettings(); diff --git a/DataBaseLMS/databaselms_Postgresql.cpp b/DataBaseLMS/databaselms_Postgresql.cpp new file mode 100644 index 0000000..7b9c9ea --- /dev/null +++ b/DataBaseLMS/databaselms_Postgresql.cpp @@ -0,0 +1,218 @@ +#include "databaselms.h" + +#include +#include +#include +#include +#include +#include + +bool DataBaseLMS::checkDriverQPSQLavailable() +{ + return QSqlDatabase::isDriverAvailable("QPSQL"); +} + +bool DataBaseLMS::checkUserLMSexist() +{ + DataBaseSettings settings = getDataBaseSettings(); + QSqlDatabase dbCheck = QSqlDatabase::addDatabase("QPSQL"); + + dbCheck.setUserName("postgres"); + dbCheck.setPassword("12345678"); + dbCheck.setHostName(settings.dbHostName); + dbCheck.setPort(settings.dbPort); + + if (dbCheck.open()) + { + QSqlQuery query = QSqlQuery(dbCheck); + query.prepare("SELECT 1 FROM pg_roles WHERE rolname = :username"); + query.bindValue(":username", settings.dbUserName); + + if (query.exec() && query.next()) + { + qDebug() << "The user exists."; + return true; + } + else + { + qDebug() << "The user does not exist."; + return false; + } + } + else + { + qDebug() << "PostgreSQL connection error."; + return false; + } +} + +bool DataBaseLMS::checkDataBaseLMSexist() +{ + DataBaseSettings settings = getDataBaseSettings(); + QSqlDatabase dbCheck = QSqlDatabase::addDatabase("QPSQL"); + + bool flDBexist = false; + + dbCheck.setUserName("postgres"); + dbCheck.setPassword("12345678"); + dbCheck.setHostName(settings.dbHostName); + dbCheck.setPort(settings.dbPort); + + if (dbCheck.open()) + { + QString queryStr = QString("SELECT datname FROM pg_database"); + QSqlQuery query = QSqlQuery(dbCheck); + + if(queryExec(queryStr, &query)) + { + while (query.next()) + { + QString nameDB = ""; + nameDB = query.value(0).toString(); + if(nameDB == dbSettings.dbName) + { + flDBexist = true; + break; + } + } + } + } + else + { + qDebug() << "PostgreSQL connection error."; + return false; + } + return flDBexist; +} + +bool DataBaseLMS::createUser(QString name) +{ + DataBaseSettings settings = getDataBaseSettings(); + QSqlDatabase dbCheck = QSqlDatabase::addDatabase("QPSQL"); + + dbCheck.setUserName("postgres"); + dbCheck.setPassword("12345678"); + dbCheck.setHostName(settings.dbHostName); + dbCheck.setPort(settings.dbPort); + + if (dbCheck.open()) + { + QString queryStr = QString("CREATE USER %1 WITH ENCRYPTED PASSWORD '%2'").arg(settings.dbUserName, settings.dbPassword); + QSqlQuery query = QSqlQuery(dbCheck); + + if(queryExec(queryStr, &query)) + { + qDebug() << "User created."; + return true; + } + else + { + qDebug() << "User not created."; + return false; + } + } + else + { + qDebug() << "PostgreSQL connection error."; + return false; + } +} + +bool DataBaseLMS::createDB(QString name) +{ + DataBaseSettings settings = getDataBaseSettings(); + QSqlDatabase dbCheck = QSqlDatabase::addDatabase("QPSQL"); + + dbCheck.setUserName("postgres"); + dbCheck.setPassword("12345678"); + dbCheck.setHostName(settings.dbHostName); + dbCheck.setPort(settings.dbPort); + + if (dbCheck.open()) + { + //Создание БД + QString queryStr = QString("CREATE DATABASE %1").arg(settings.dbName); + QSqlQuery query = QSqlQuery(dbCheck); + + if(queryExec(queryStr, &query)) + { + qDebug() << "The database has been created."; + + //Залитие БД + + QProcess process; + //QString pgRestorePath = "C:\\restoreDB.bat"; + QString pgRestorePath = "restoreDB.bat"; + + /* + QString dbName = "databaselms2"; + QString user = "postgres"; + QString backupFile = "C:\\DBLMS_EMPTY_30_09_2025.backup"; + + QStringList arguments; + arguments << "-d" << dbName; + arguments << "-U" << user; + arguments << backupFile; + */ + + process.start("cmd /C " + pgRestorePath); + process.waitForFinished(-1); // Ждать бесконечно, пока процесс не завершится + + + //Назначение владельца + QString queryStr = QString("ALTER DATABASE %1 OWNER TO %2").arg(settings.dbName, settings.dbUserName); + QSqlQuery query = QSqlQuery(dbCheck); + if(queryExec(queryStr, &query)) + { + + } + else + return false; + } + else + { + qDebug() << "The database was not created.."; + return false; + } + } + else + { + qDebug() << "PostgreSQL connection error."; + return false; + } + + dbCheck.close(); + + QSqlDatabase dbCheck2 = QSqlDatabase::addDatabase("QPSQL"); + + dbCheck2.setUserName("postgres"); + dbCheck2.setPassword("12345678"); + dbCheck2.setHostName(settings.dbHostName); + dbCheck2.setPort(settings.dbPort); + dbCheck2.setDatabaseName(settings.dbName); + + if (dbCheck2.open()) + { + QString newOwner = settings.dbUserName; + + // Получаем список таблиц + QSqlQuery query(dbCheck2); + query.exec("SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname = 'public';"); + + while (query.next()) + { + QString tableName = query.value(0).toString(); + QString alterQuery = QString("ALTER TABLE %1 OWNER TO %2;").arg(tableName).arg(newOwner); + + dbCheck2.exec(alterQuery); + /* + if (dbCheck2.exec(alterQuery)) + { + qDebug() << "Error changing owner for table " << tableName << ":" << dbCheck2.lastError().text(); + return false; + }*/ + } + } + + return true; +} diff --git a/DataBaseLMS/translations/DataBaseLMS_ru_RU.ts b/DataBaseLMS/translations/DataBaseLMS_ru_RU.ts index 9484832..09f1c10 100644 --- a/DataBaseLMS/translations/DataBaseLMS_ru_RU.ts +++ b/DataBaseLMS/translations/DataBaseLMS_ru_RU.ts @@ -4,22 +4,14 @@ DataBaseLMS - + Attention! Внимание! - + The file could not be opened: Файл не может быть открыт: - - InterfaceDataBaseLMS - - - Connection error - Ошибка подключения - - diff --git a/InstructorsAndTrainees/instructorsandtraineeswidget.cpp b/InstructorsAndTrainees/instructorsandtraineeswidget.cpp index 7f2742d..192d76c 100644 --- a/InstructorsAndTrainees/instructorsandtraineeswidget.cpp +++ b/InstructorsAndTrainees/instructorsandtraineeswidget.cpp @@ -412,10 +412,10 @@ void InstructorsAndTraineesWidget::updateLabelServer() if(connectorToServer->getIsConnected()) { ServerSettings serverSettings = connectorToServer->getServerSettings(); - ui->lblServer->setText(serverSettings.Address + " : " +serverSettings.Port); + ui->lblServer->setText(tr("connected") + " " + serverSettings.Address + " : " +serverSettings.Port); } else - ui->lblServer->setText(tr("none")); + ui->lblServer->setText(tr("not connected")); } void InstructorsAndTraineesWidget::setLanguageInterfase() diff --git a/InstructorsAndTrainees/translations/InstructorsAndTraineesWidget_ru_RU.qm b/InstructorsAndTrainees/translations/InstructorsAndTraineesWidget_ru_RU.qm index ffce4cc..894b4ab 100644 Binary files a/InstructorsAndTrainees/translations/InstructorsAndTraineesWidget_ru_RU.qm and b/InstructorsAndTrainees/translations/InstructorsAndTraineesWidget_ru_RU.qm differ diff --git a/InstructorsAndTrainees/translations/InstructorsAndTraineesWidget_ru_RU.ts b/InstructorsAndTrainees/translations/InstructorsAndTraineesWidget_ru_RU.ts index a69559a..66c446c 100644 --- a/InstructorsAndTrainees/translations/InstructorsAndTraineesWidget_ru_RU.ts +++ b/InstructorsAndTrainees/translations/InstructorsAndTraineesWidget_ru_RU.ts @@ -171,52 +171,52 @@ The status will be set: CommonView - + Name Имя - + Login Логин - + Password Пароль - + Class Класс - + Computer Компьютер - + IP address IP адрес - + Administrator Администратор - + Archived Архивный - + Online В сети - + ID ID @@ -234,7 +234,12 @@ The status will be set: Логин - + + ... + + + + Log in Войти @@ -301,22 +306,28 @@ The status will be set: Пароль - + + + ... + + + + Administrator Администратор - + Archived Архивный - + Logged Залогирован - + Save Сохранить @@ -344,17 +355,36 @@ The status will be set: Пароль - + + + ... + + + + Archived Архивный - + Logged Залогирован - + + Save + Сохранить + + + + DialogNewPassword + + + Dialog + Диалог + + + Save Сохранить @@ -451,76 +481,76 @@ The status will be set: Удалить инструктора - - + + To archive Архивировать - + Edit Редактировать - + Show archive Показать архив - + You cannot delete the Administrator. Нельзя удалить администратора. - + You cannot delete a logged-in instructor. Вы не можете удалить инструктора, вошедшего в систему. - + The deletion will be irrevocable. Delete it anyway? Удаление будет безвозвратным. Всё равно удалить? - + You cannot archive a logged-in instructor. Вы не можете заархивировать инструктора, вошедшего в систему. - + You cannot edit a logged-in instructor. Вы не можете редактировать инструктора, вошедшего в систему. - + From archive Разархивировать - + Unacceptable instructor name has been entered. The changes will not be accepted. Введено неприемлемое имя инструктора. Изменения приняты не будут. - + Unacceptable instructor login has been entered. The changes will not be accepted. Введен неприемлемый логин инструктора. Изменения приняты не будут. - + Unacceptable instructor password has been entered. The changes will not be accepted. Введен неприемлемый пароль инструктора. Изменения приняты не будут. - + An existing instructor or trainee login has been entered. The changes will not be accepted. Введен существующий логин инструктора или обучаемого. @@ -556,8 +586,8 @@ The changes will not be accepted. - - + + To archive Архивировать @@ -572,76 +602,76 @@ The changes will not be accepted. Показать архив - + The group is not empty. It is not possible to delete a non-empty group. Группа не пуста. Невозможно удалить непустую группу. - - + + The deletion will be irrevocable. Delete it anyway? Удаление будет безвозвратным. Всё равно удалить? - + You cannot delete a logged-in trainee. Вы не можете удалить обучаемого, вошедшего в систему. - + You cannot archive a logged-in trainee. Вы не можете заархивировать обучаемого, вошедшего в систему. - + You cannot edit a logged-in trainee. Вы не можете редактировать обучаемого, вошедшего в систему. - + From archive Разархивировать - + Unacceptable group name has been entered. The changes will not be accepted. Введено неприемлемое название группы. Изменения приняты не будут. - + An existing group name has been entered. The changes will not be accepted. Введено существующее название группы. Изменения приняты не будут. - + Unacceptable trainee name has been entered. The changes will not be accepted. Введено неприемлемое имя обучаемого. Изменения приняты не будут. - + Unacceptable trainee login has been entered. The changes will not be accepted. Введен неприемлемый логин обучаемого. Изменения приняты не будут. - + Unacceptable trainee password has been entered. The changes will not be accepted. Был введен неприемлемый пароль обучаемого. Изменения приняты не будут. - + An existing instructor or trainee login has been entered. The changes will not be accepted. Введен существующий логин инструктора или обучаемого. @@ -766,48 +796,57 @@ Delete it anyway? - - + none нет - + The file could not be opened Файл не может быть открыт - + Instructor authorization. Авторизация инструктора. - + Instructor deauthorization Деавторизация инструктора - + Error! Ошибка! - + The server is not available! Сервер недоступен! - + + connected + подключен + + + + not connected + не подключен + + + Server settings have been changed. Please reconnect to the server. Настройки сервера изменены. Выполните переподключение к серверу. - + Instructor authorization Авторизация инструктора - + Invalid login or password! Неправильный логин или пароль! @@ -930,73 +969,73 @@ Delete it anyway? Обучаемый - + Name Имя - + - - + + 0 - + Assigned FIM Назначенные FIM - + Assigned AMM Назначенные AMM - + Last login Последний вход - + Time spent on the simulator Время работы на тренажере - + Last exit Последний выход - + Chat Чат - + Tasks Задачи - + AMM - - + + List Перечень - - + + Attached Назначенные - + FIM @@ -1108,12 +1147,12 @@ Delete it anyway? TraineesView - + yes да - + no нет diff --git a/ServerLMS/dialogcheckdb.cpp b/ServerLMS/dialogcheckdb.cpp index 4c639cf..f28a834 100644 --- a/ServerLMS/dialogcheckdb.cpp +++ b/ServerLMS/dialogcheckdb.cpp @@ -13,6 +13,8 @@ DialogCheckDB::DialogCheckDB(ProviderDBLMS* providerDBLMS, QWidget *parent) : { ui->setupUi(this); + ui->btnRepare->setObjectName("btnRepare"); + ui->btnRepare->setEnabled(false); check(); diff --git a/ServerLMS/dialogcheckdb.ui b/ServerLMS/dialogcheckdb.ui index 1bc6b07..e8fe577 100644 --- a/ServerLMS/dialogcheckdb.ui +++ b/ServerLMS/dialogcheckdb.ui @@ -28,7 +28,7 @@ - 150 + 170 0 @@ -44,6 +44,19 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -86,7 +99,7 @@ - 150 + 170 0 @@ -102,6 +115,19 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -144,7 +170,7 @@ - 150 + 170 0 @@ -160,6 +186,19 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -190,21 +229,21 @@ + + + + Qt::Vertical + + + + 20 + 40 + + + + - - - - - 32 - 32 - - - - ... - - - diff --git a/ServerLMS/dialogsettingstray.cpp b/ServerLMS/dialogsettingstray.cpp index ba3d775..bee4fc0 100644 --- a/ServerLMS/dialogsettingstray.cpp +++ b/ServerLMS/dialogsettingstray.cpp @@ -14,6 +14,7 @@ DialogSettingsTray::DialogSettingsTray(ProviderDBLMS* providerDBLMS, QWidget *pa ui->setupUi(this); ui->btnSave->setObjectName("btnSave"); + ui->btnCheckDB->setObjectName("btnCheckDB"); /* Создаем строку для регулярного выражения */ QString ipRange = "(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])"; @@ -54,6 +55,7 @@ DialogSettingsTray::DialogSettingsTray(ProviderDBLMS* providerDBLMS, QWidget *pa } ui->btnSave->setEnabled(false); + ui->btnCheckDB->setEnabled(true); flSettingsServerChanged = false; } @@ -179,6 +181,8 @@ void DialogSettingsTray::on_btnSave_clicked() saveSettings(); + ui->btnCheckDB->setEnabled(true); + this->accept(); } @@ -202,30 +206,35 @@ void DialogSettingsTray::on_DialogSettingsTray_accepted() void DialogSettingsTray::on_editNameDB_textChanged(const QString &arg1) { ui->btnSave->setEnabled(true); + ui->btnCheckDB->setEnabled(false); flSettingsServerChanged = true; } void DialogSettingsTray::on_editHostName_textChanged(const QString &arg1) { ui->btnSave->setEnabled(true); + ui->btnCheckDB->setEnabled(false); flSettingsServerChanged = true; } void DialogSettingsTray::on_editPort_textChanged(const QString &arg1) { ui->btnSave->setEnabled(true); + ui->btnCheckDB->setEnabled(false); flSettingsServerChanged = true; } void DialogSettingsTray::on_editUserName_textChanged(const QString &arg1) { ui->btnSave->setEnabled(true); + ui->btnCheckDB->setEnabled(false); flSettingsServerChanged = true; } void DialogSettingsTray::on_editPassword_textChanged(const QString &arg1) { ui->btnSave->setEnabled(true); + ui->btnCheckDB->setEnabled(false); flSettingsServerChanged = true; } diff --git a/ServerLMS/dialogsettingstray.ui b/ServerLMS/dialogsettingstray.ui index e970c9d..d7968ff 100644 --- a/ServerLMS/dialogsettingstray.ui +++ b/ServerLMS/dialogsettingstray.ui @@ -181,6 +181,19 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -190,7 +203,7 @@ - Check DB + Check diff --git a/ServerLMS/multithreadserver.cpp b/ServerLMS/multithreadserver.cpp index e37b639..5fa5b78 100644 --- a/ServerLMS/multithreadserver.cpp +++ b/ServerLMS/multithreadserver.cpp @@ -9,7 +9,7 @@ MultiThreadServer::MultiThreadServer(ServerLMSWidget *widget,UpdateController *u updateController(updateController), dataParser(dataParser), stateServer(stoped), - stateBlockAutorization(unblocked) + stateBlockAutorization(blocked) { clientsMap = new QMap; } diff --git a/ServerLMS/multithreadserver.h b/ServerLMS/multithreadserver.h index f748395..3636478 100644 --- a/ServerLMS/multithreadserver.h +++ b/ServerLMS/multithreadserver.h @@ -33,6 +33,10 @@ public: { return stateBlockAutorization; } + EStateServer getStateServer() + { + return stateServer; + } signals: void sigInitClient(int descriptor, ServerLMSWidget *serverWidget, UpdateController *updateController, DataParser *dataParser); diff --git a/ServerLMS/serverlmswidget.cpp b/ServerLMS/serverlmswidget.cpp index d5dd3a3..8021d97 100644 --- a/ServerLMS/serverlmswidget.cpp +++ b/ServerLMS/serverlmswidget.cpp @@ -40,7 +40,7 @@ ServerLMSWidget::ServerLMSWidget(QWidget *parent) : updateMyStyleSheet(); - setLanguageInterfase(); + setLanguageInterfase(); } ServerLMSWidget::~ServerLMSWidget() @@ -49,7 +49,6 @@ ServerLMSWidget::~ServerLMSWidget() { server->stopServer(); - //updateThread->exit(); updateThread->quit(); updateThread->wait(); delete updateThread; @@ -64,7 +63,6 @@ ServerLMSWidget::~ServerLMSWidget() delete mutex; - //loggerThread->exit(); loggerThread->quit(); loggerThread->wait(); delete loggerThread; @@ -82,20 +80,7 @@ void ServerLMSWidget::changeEvent(QEvent *event) { ui->retranslateUi(this); // переведём окно заново - if(providerDBLMS->DBisConnected()) - { - //Настройки БД - DataBaseSettings dbSettings = providerDBLMS->getDBSettings(); - QString strDBsettings = QString("%1 (%2) %3 : %4").arg(dbSettings.dbName, - dbSettings.dbType, - dbSettings.dbHostName, - QString::number(dbSettings.dbPort)); - ui->lblDBsettings->setText(strDBsettings); - } - else - { - ui->lblDBsettings->setText(""); - } + updateStateServer(); } } @@ -161,9 +146,11 @@ void ServerLMSWidget::on_btnStartServer_clicked() ui->btnStartServer->setEnabled(false); ui->btnStopServer->setEnabled(true); - ui->lblOnOff->setPixmap(QPixmap(QStringLiteral(":/resources/icons/switchOn.png"))); slot_BlockAutorization(false); + + emit signal_Tray_ShowMessage(tr("Server is started!")); } + updateStateServer(); } void ServerLMSWidget::on_btnStopServer_clicked() @@ -172,9 +159,11 @@ void ServerLMSWidget::on_btnStopServer_clicked() { ui->btnStopServer->setEnabled(false); ui->btnStartServer->setEnabled(true); - ui->lblOnOff->setPixmap(QPixmap(QStringLiteral(":/resources/icons/switchOff.png"))); slot_BlockAutorization(true); + + emit signal_Tray_ShowMessage(tr("Server is stoped!")); } + updateStateServer(); } void ServerLMSWidget::on_btnSettings_clicked() @@ -200,8 +189,7 @@ void ServerLMSWidget::on_btnSettings_clicked() providerDBLMS->DisConnectionFromDB(); - ui->lblDBsettings->setText(""); - ui->lblDBisConnected->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleGreen.png"))); + updateStateServer(); QMessageBox::warning(this, tr("Warning!"), tr("Database settings have been changed.\nThe server will be restarted.")); @@ -313,19 +301,19 @@ void ServerLMSWidget::startInitialization() ui->btnStartServer->setEnabled(true); flStartInitialization = true; + + updateStateServer(); } void ServerLMSWidget::tryConnectionToDB() { if(! providerDBLMS->ConnectionToDB()) { - ui->lblDBsettings->setText(""); - ui->lblDBisConnected->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleGray.png"))); - ui->btnStopServer->setEnabled(false); - ui->btnStartServer->setEnabled(false); - //QMessageBox::critical(this, tr("Error!"), tr("Database connection error!")); - emit signal_Tray_ShowMessage(tr("Database connection error!"), QSystemTrayIcon::Critical); + + emit signal_Menu_ShowWindow(); + + QMessageBox::critical(this, tr("Error!"), tr("Database connection error!")); } else { @@ -337,11 +325,60 @@ void ServerLMSWidget::tryConnectionToDB() dbSettings.dbType, dbSettings.dbHostName, QString::number(dbSettings.dbPort)); - ui->lblDBsettings->setText(strDBsettings); - ui->lblDBisConnected->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleGreen.png"))); emit signal_Tray_ShowMessage(tr("Database connection OK!") + "\n" + strDBsettings); on_btnStartServer_clicked(); } + + updateStateServer(); +} + +void ServerLMSWidget::updateStateServer() +{ + if(server) + { + if(server->getStateServer() == EStateServer::started) + { + ui->lblOnOffText->setText(tr("started")); + ui->lblOnOff->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleGreen.png"))); + } + else + { + ui->lblOnOffText->setText(tr("stoped")); + ui->lblOnOff->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleGray.png"))); + } + + if(server->getStateBlockAutorization() == EStateBlockAutorization::unblocked) + { + ui->lblBlockAuth->setPixmap(QPixmap(QStringLiteral(":/resources/icons/open.png"))); + } + else + { + ui->lblBlockAuth->setPixmap(QPixmap(QStringLiteral(":/resources/icons/lock.png"))); + } + } + + if(providerDBLMS) + { + if(providerDBLMS->DBisConnected()) + { + //Настройки БД + DataBaseSettings dbSettings = providerDBLMS->getDBSettings(); + QString strDBsettings = tr("connected") + QString(" [%1 (%2) %3 : %4]").arg(dbSettings.dbName, + dbSettings.dbType, + dbSettings.dbHostName, + QString::number(dbSettings.dbPort)); + ui->lblDBsettings->setText(strDBsettings); + ui->lblDBisConnected->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleGreen.png"))); + } + else + { + ui->lblDBsettings->setText(tr("not connected")); + ui->lblDBisConnected->setPixmap(QPixmap(QStringLiteral(":/resources/icons/circleGray.png"))); + + ui->btnStopServer->setEnabled(false); + ui->btnStartServer->setEnabled(false); + } + } } diff --git a/ServerLMS/serverlmswidget.h b/ServerLMS/serverlmswidget.h index d7b2bf6..f4f91fa 100644 --- a/ServerLMS/serverlmswidget.h +++ b/ServerLMS/serverlmswidget.h @@ -68,6 +68,9 @@ signals: //сигнал вывода сообщения из трея void signal_Tray_ShowMessage(QString textMsg, QSystemTrayIcon::MessageIcon iconMsg = QSystemTrayIcon::Information); + void signal_Menu_ShowWindow(); + void signal_Menu_HideWindow(); + void sigRecognize(); void sigCalculateFullHash(); void sigUpdateController(CommonClientHandler* commonClientHandler,DataParser *dataParser,AssetsManager *assetManager); @@ -121,6 +124,8 @@ private: void tryConnectionToDB(); + void updateStateServer(); + private: Ui::ServerLMSWidget *ui; diff --git a/ServerLMS/serverlmswidget.ui b/ServerLMS/serverlmswidget.ui index a807a59..3ae845c 100644 --- a/ServerLMS/serverlmswidget.ui +++ b/ServerLMS/serverlmswidget.ui @@ -6,7 +6,7 @@ 0 0 - 800 + 1000 600 @@ -23,7 +23,7 @@ - + @@ -106,25 +106,6 @@ - - - - - 40 - 40 - - - - - - - :/resources/icons/switchOff.png - - - true - - - @@ -222,79 +203,11 @@ - + - - - - 32 - 32 - - - - - 32 - 32 - - - - - - - :/resources/icons/circleGray.png - - - - - - - - 0 - 0 - - - - Data base: - - - - - - - ... - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - + - - - Authorization - - - - - - - - 0 - 0 - - + 32 @@ -311,13 +224,140 @@ - :/resources/icons/open.png + :/resources/icons/circleGray.png true + + + + Server: + + + + + + + + 150 + 0 + + + + + 100 + 16777215 + + + + ... + + + + + + + + + + + + 32 + 32 + + + + + 32 + 32 + + + + + + + :/resources/icons/circleGray.png + + + + + + + + 0 + 0 + + + + Data base: + + + + + + + ... + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Authorization + + + + + + + + 0 + 0 + + + + + 32 + 32 + + + + + 32 + 32 + + + + + + + :/resources/icons/open.png + + + true + + + + + diff --git a/ServerLMS/translations/ServerLMS_ru_RU.qm b/ServerLMS/translations/ServerLMS_ru_RU.qm index 93ec933..a9de524 100644 Binary files a/ServerLMS/translations/ServerLMS_ru_RU.qm and b/ServerLMS/translations/ServerLMS_ru_RU.qm differ diff --git a/ServerLMS/translations/ServerLMS_ru_RU.ts b/ServerLMS/translations/ServerLMS_ru_RU.ts index b3f2909..5950c1d 100644 --- a/ServerLMS/translations/ServerLMS_ru_RU.ts +++ b/ServerLMS/translations/ServerLMS_ru_RU.ts @@ -9,6 +9,86 @@ ООО Константа-Дизайн + + DialogCheckDB + + + + Database + База данных + + + + Driver PostgreSQL + Драйвер PostgreSQL + + + + + + + ... + + + + + User + Пользователь + + + + Repare + Восстановить + + + + Installed + Установлен + + + + Not installed + Не установлен + + + + + Exist + Существует + + + + + Not exist + Не существует + + + + Warning! + Внимание! + + + + Install PostgreSQL. + Установите PostgreSQL. + + + + + Error! + Ошибка! + + + + Failed to create user! + Ошибка создания пользователя! + + + + Failed to create Database! + Ошибка создания Базы данных! + + DialogSettingsTray @@ -57,7 +137,12 @@ Пароль - + + Check DB + Проверить БД + + + Save Сохранить @@ -70,32 +155,38 @@ Форма - + Logger Логгер - + Clients Клиенты - + Settings Настройки - + + Server: + Сервер: + + + Data base: База данных: - + + ... - + Authorization Авторизация @@ -110,32 +201,68 @@ Остановить - - + + Server is started! + Сервер запущен! + + + + Server is stoped! + Сервер остановлен! + + + + Warning! Внимание! - + Database settings have been changed. The server will be restarted. Настройки Базы Данных были изменены. Сервер будет перезапущен. - + The file could not be opened Файл не может быть открыт - + + + Database connection error! + Ошибка подключения Базы данных! + + + Error! Ошибка! - - Database connection error - Ошибка подключения к Базе Данных + + Database connection OK! + База данных подключена! + + + + started + запущен + + + + stoped + остановлен + + + + connected + подключена + + + + not connected + не подключена diff --git a/TrayServerLMS/mainwindow.cpp b/TrayServerLMS/mainwindow.cpp index 418e7d2..2213fae 100644 --- a/TrayServerLMS/mainwindow.cpp +++ b/TrayServerLMS/mainwindow.cpp @@ -52,9 +52,6 @@ MainWindow::MainWindow(QWidget *parent) : connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(slot_Activated(QSystemTrayIcon::ActivationReason))); - slot_Tray_ShowMessage(tr("Starting the server...")); - - serverLMSWidget = new ServerLMSWidget(this); ui->verticalLayout_Main->addWidget(serverLMSWidget); @@ -62,14 +59,17 @@ MainWindow::MainWindow(QWidget *parent) : connect(serverLMSWidget, &ServerLMSWidget::signal_LanguageChanged, this, &MainWindow::slot_LanguageChanged); connect(serverLMSWidget, &ServerLMSWidget::signal_Tray_ShowMessage, this, &MainWindow::slot_Tray_ShowMessage); - serverLMSWidget->start(); + connect(serverLMSWidget, &ServerLMSWidget::signal_Menu_ShowWindow, this, &MainWindow::slot_Menu_ShowWindow); + connect(serverLMSWidget, &ServerLMSWidget::signal_Menu_HideWindow, this, &MainWindow::slot_Menu_HideWindow); qtLanguageTranslator.load(QString("translations/TrayServerLMS_") + serverLMSWidget->getLanguage(), "."); qApp->installTranslator(&qtLanguageTranslator); - errorCheck(); + slot_Tray_ShowMessage(tr("Starting the server...")); - slot_Menu_HideWindow(); + serverLMSWidget->start(); + + errorCheck(); } /* Метод, который обрабатывает событие закрытия окна приложения diff --git a/TrayServerLMS/mainwindow.h b/TrayServerLMS/mainwindow.h index 6a79339..4bf6026 100644 --- a/TrayServerLMS/mainwindow.h +++ b/TrayServerLMS/mainwindow.h @@ -53,7 +53,6 @@ public slots: //Слот вывода сообщения из трея void slot_Tray_ShowMessage(QString textMsg, QSystemTrayIcon::MessageIcon iconMsg = QSystemTrayIcon::Information); - signals: //сигнал об изменении языка интерфейса void signal_LanguageChanged(QString language); diff --git a/TrayServerLMS/translations/TrayServerLMS_ru_RU.qm b/TrayServerLMS/translations/TrayServerLMS_ru_RU.qm index 7ccf127..b1be266 100644 Binary files a/TrayServerLMS/translations/TrayServerLMS_ru_RU.qm and b/TrayServerLMS/translations/TrayServerLMS_ru_RU.qm differ diff --git a/TrayServerLMS/translations/TrayServerLMS_ru_RU.ts b/TrayServerLMS/translations/TrayServerLMS_ru_RU.ts index decb696..162aa42 100644 --- a/TrayServerLMS/translations/TrayServerLMS_ru_RU.ts +++ b/TrayServerLMS/translations/TrayServerLMS_ru_RU.ts @@ -9,47 +9,58 @@ Сервер Системы управления обучением (СУО) - - Language - Язык - - - - + + + Server LMS Сервер СУО - + + Expand window Развернуть окно - + + Minimize window Свернуть окно - + + Exit Выход - + + Starting the server... + Запуск сервера... + + + + Error! + Ошибка! + + + No Client files found! Файлы Клиента не найдены! - + * check Application for the presence of a folder with a build * check SharedData for a folder with the base version and the name base * проверьте Application на наличие папки со сборкой * проверьте SharedData на наличие папки с базовой версией и именем base - - The application is minimized to the tray. To maximize the application window, click the application icon in the tray. - Приложение свернуто в трей. Чтобы развернуть окно приложения, щелкните по иконке приложения в трее. + + The application is minimized to the tray. +To maximize the application window, click the application icon in the tray. + Приложение свёрнуто в область уведомлений. +Чтобы развернуть окно приложения, нажмите на значок приложения в области уведомлений.