mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-27 19:45:43 +03:00
Рефакт Администрирование БД 3
This commit is contained in:
@@ -26,7 +26,7 @@
|
|||||||
<string>Settings</string>
|
<string>Settings</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowIcon">
|
<property name="windowIcon">
|
||||||
<iconset>
|
<iconset resource="InstructorsAndTrainees.qrc">
|
||||||
<normaloff>:/resources/icons/lms.png</normaloff>:/resources/icons/lms.png</iconset>
|
<normaloff>:/resources/icons/lms.png</normaloff>:/resources/icons/lms.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeGripEnabled">
|
<property name="sizeGripEnabled">
|
||||||
@@ -76,6 +76,16 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="Line" name="line">
|
||||||
|
<property name="lineWidth">
|
||||||
|
<number>2</number>
|
||||||
|
</property>
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="groupBox_Server">
|
<widget class="QGroupBox" name="groupBox_Server">
|
||||||
<property name="font">
|
<property name="font">
|
||||||
@@ -232,7 +242,7 @@
|
|||||||
<string>Save</string>
|
<string>Save</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset>
|
<iconset resource="InstructorsAndTrainees.qrc">
|
||||||
<normaloff>:/resources/icons/circleGreen.png</normaloff>:/resources/icons/circleGreen.png</iconset>
|
<normaloff>:/resources/icons/circleGreen.png</normaloff>:/resources/icons/circleGreen.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="iconSize">
|
<property name="iconSize">
|
||||||
@@ -291,7 +301,7 @@
|
|||||||
<string>Version</string>
|
<string>Version</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset>
|
<iconset resource="InstructorsAndTrainees.qrc">
|
||||||
<normaloff>:/resources/icons/updateVersion.png</normaloff>:/resources/icons/updateVersion.png</iconset>
|
<normaloff>:/resources/icons/updateVersion.png</normaloff>:/resources/icons/updateVersion.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="iconSize">
|
<property name="iconSize">
|
||||||
@@ -323,7 +333,7 @@
|
|||||||
<string>Style</string>
|
<string>Style</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset>
|
<iconset resource="InstructorsAndTrainees.qrc">
|
||||||
<normaloff>:/resources/icons/style.png</normaloff>:/resources/icons/style.png</iconset>
|
<normaloff>:/resources/icons/style.png</normaloff>:/resources/icons/style.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="iconSize">
|
<property name="iconSize">
|
||||||
@@ -359,6 +369,8 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources>
|
||||||
|
<include location="InstructorsAndTrainees.qrc"/>
|
||||||
|
</resources>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ void DialogCheckDB::on_btnRepare_clicked()
|
|||||||
if(!resDriver)
|
if(!resDriver)
|
||||||
{
|
{
|
||||||
QMessageBox::critical(this, tr("Error!"), tr("Install PostgreSQL."));
|
QMessageBox::critical(this, tr("Error!"), tr("Install PostgreSQL."));
|
||||||
|
this->reject();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,8 +89,9 @@ void DialogCheckDB::on_btnRepare_clicked()
|
|||||||
{
|
{
|
||||||
if(!providerDBLMS->createUser())
|
if(!providerDBLMS->createUser())
|
||||||
{
|
{
|
||||||
QMessageBox::critical(this, tr("Error!"), tr("Failed to create user!"));
|
|
||||||
check();
|
check();
|
||||||
|
QMessageBox::critical(this, tr("Error!"), tr("Failed to create user!"));
|
||||||
|
this->reject();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,8 +100,9 @@ void DialogCheckDB::on_btnRepare_clicked()
|
|||||||
{
|
{
|
||||||
if(!providerDBLMS->createDB())
|
if(!providerDBLMS->createDB())
|
||||||
{
|
{
|
||||||
QMessageBox::critical(this, tr("Error!"), tr("Failed to create Database!"));
|
|
||||||
check();
|
check();
|
||||||
|
QMessageBox::critical(this, tr("Error!"), tr("Failed to create Database!"));
|
||||||
|
this->reject();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>400</width>
|
<width>400</width>
|
||||||
<height>300</height>
|
<height>250</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@@ -45,7 +45,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="horizontalSpacer_1">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
@@ -229,6 +229,9 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_Result"/>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ DialogSettingsTray::DialogSettingsTray(ProviderDBLMS* providerDBLMS, QWidget *pa
|
|||||||
/* Устанавливаем Валидатор на QLineEdit */
|
/* Устанавливаем Валидатор на QLineEdit */
|
||||||
ui->editHostName->setValidator(ipValidator);
|
ui->editHostName->setValidator(ipValidator);
|
||||||
|
|
||||||
settings = new ServerDBSettings;
|
settings = new ServerDBSettings();
|
||||||
|
|
||||||
//Задаём два пункта с текстом локалей в комбобоксе
|
//Задаём два пункта с текстом локалей в комбобоксе
|
||||||
ui->cmbLanguage->addItems(QStringList() << "English" << "Русский");
|
ui->cmbLanguage->addItems(QStringList() << "English" << "Русский");
|
||||||
@@ -50,7 +50,17 @@ DialogSettingsTray::DialogSettingsTray(ProviderDBLMS* providerDBLMS, QWidget *pa
|
|||||||
ui->cmbLanguage->setCurrentText("Русский");
|
ui->cmbLanguage->setCurrentText("Русский");
|
||||||
|
|
||||||
ui->editNameDB->setText(settings->NameDB);
|
ui->editNameDB->setText(settings->NameDB);
|
||||||
|
|
||||||
|
if(settings->HostName == "localhost")
|
||||||
|
{
|
||||||
|
ui->checkLocalhost->setChecked(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ui->checkLocalhost->setChecked(false);
|
||||||
|
}
|
||||||
ui->editHostName->setText(settings->HostName);
|
ui->editHostName->setText(settings->HostName);
|
||||||
|
|
||||||
ui->editPort->setText(settings->Port);
|
ui->editPort->setText(settings->Port);
|
||||||
ui->editUserName->setText(settings->UserName);
|
ui->editUserName->setText(settings->UserName);
|
||||||
ui->editPassword->setText(settings->Password);
|
ui->editPassword->setText(settings->Password);
|
||||||
@@ -240,6 +250,20 @@ void DialogSettingsTray::on_editPassword_textChanged(const QString &arg1)
|
|||||||
flSettingsServerChanged = true;
|
flSettingsServerChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DialogSettingsTray::on_checkLocalhost_stateChanged(int arg1)
|
||||||
|
{
|
||||||
|
if(arg1)
|
||||||
|
{
|
||||||
|
ui->editHostName->setText("localhost");
|
||||||
|
ui->editHostName->setEnabled(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ui->editHostName->setText("0.0.0.0");
|
||||||
|
ui->editHostName->setEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DialogSettingsTray::on_btnCheckDB_clicked()
|
void DialogSettingsTray::on_btnCheckDB_clicked()
|
||||||
{
|
{
|
||||||
//Проверяем, установлен ли PostgreSQL
|
//Проверяем, установлен ли PostgreSQL
|
||||||
@@ -249,7 +273,7 @@ void DialogSettingsTray::on_btnCheckDB_clicked()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Запрос Логина и Пароля Суперюзера PostgreSQL (postgres)
|
//Запрос Логина и Пароля Суперюзера PostgreSQL (postgres)
|
||||||
QString UserNamePostgres;
|
QString UserNamePostgres;
|
||||||
QString PasswordPostgres;
|
QString PasswordPostgres;
|
||||||
|
|
||||||
@@ -296,7 +320,17 @@ void DialogSettingsTray::on_btnCheckDB_clicked()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QMessageBox::critical(this, tr("Error!"), tr("The superuser login or password is incorrect!"));
|
if(settings->HostName == "localhost")
|
||||||
|
QMessageBox::critical(this, tr("Error!"), tr("Error connecting to PostgreSQL!") + "\n\n" +
|
||||||
|
tr("Possible reasons:") + "\n" +
|
||||||
|
tr("*superuser PostgreSQL login or password is incorrect;") + "\n" +
|
||||||
|
tr("*Port is incorrect."));
|
||||||
|
else
|
||||||
|
QMessageBox::critical(this, tr("Error!"), tr("Error connecting to PostgreSQL!") + "\n\n" +
|
||||||
|
tr("Possible reasons:") + "\n" +
|
||||||
|
tr("*superuser PostgreSQL login or password is incorrect;") + "\n" +
|
||||||
|
tr("*Port is incorrect;") + "\n" +
|
||||||
|
tr("*file 'pg_hba.conf' does not contain an entry for the IP address:") + settings->HostName + ".");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ private slots:
|
|||||||
|
|
||||||
void on_btnCheckDB_clicked();
|
void on_btnCheckDB_clicked();
|
||||||
|
|
||||||
|
void on_checkLocalhost_stateChanged(int arg1);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool saveSettings();
|
bool saveSettings();
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>400</width>
|
<width>450</width>
|
||||||
<height>427</height>
|
<height>400</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@@ -51,38 +51,24 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="Line" name="line">
|
||||||
|
<property name="lineWidth">
|
||||||
|
<number>2</number>
|
||||||
|
</property>
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="groupBox_DB">
|
<widget class="QGroupBox" name="groupBox_DB">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Data Base</string>
|
<string>Database</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_3">
|
<layout class="QGridLayout" name="gridLayout_3">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_DB">
|
<layout class="QVBoxLayout" name="verticalLayout_DB">
|
||||||
<item>
|
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_NameDB">
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="label_NameDB">
|
|
||||||
<property name="text">
|
|
||||||
<string>DB name</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QLineEdit" name="editNameDB">
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>170</width>
|
|
||||||
<height>16777215</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_HostName">
|
<layout class="QHBoxLayout" name="horizontalLayout_HostName">
|
||||||
<item>
|
<item>
|
||||||
@@ -92,6 +78,26 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_3">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="checkLocalhost">
|
||||||
|
<property name="text">
|
||||||
|
<string>Localhost</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="editHostName">
|
<widget class="QLineEdit" name="editHostName">
|
||||||
<property name="maximumSize">
|
<property name="maximumSize">
|
||||||
@@ -131,6 +137,33 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_NameDB">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_NameDB">
|
||||||
|
<property name="text">
|
||||||
|
<string>Database name</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="editNameDB">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>170</width>
|
||||||
|
<height>16777215</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_UserName">
|
<layout class="QHBoxLayout" name="horizontalLayout_UserName">
|
||||||
<item>
|
<item>
|
||||||
@@ -142,6 +175,9 @@
|
|||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="editUserName">
|
<widget class="QLineEdit" name="editUserName">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="maximumSize">
|
<property name="maximumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>170</width>
|
<width>170</width>
|
||||||
@@ -160,12 +196,15 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_Password">
|
<widget class="QLabel" name="label_Password">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Password</string>
|
<string>User password</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="editPassword">
|
<widget class="QLineEdit" name="editPassword">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="maximumSize">
|
<property name="maximumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>170</width>
|
<width>170</width>
|
||||||
|
|||||||
@@ -110,6 +110,8 @@ void ServerLMSWidget::slot_AddMessageToLog(QString message)
|
|||||||
void ServerLMSWidget::start()
|
void ServerLMSWidget::start()
|
||||||
{
|
{
|
||||||
startInitialization();
|
startInitialization();
|
||||||
|
if(hasError() == 100)
|
||||||
|
return;
|
||||||
tryConnectionToDB();
|
tryConnectionToDB();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +174,7 @@ void ServerLMSWidget::on_btnSettings_clicked()
|
|||||||
dlg.setWindowFlags(dlg.windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
dlg.setWindowFlags(dlg.windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||||
|
|
||||||
connect(&dlg, &DialogSettingsTray::signal_LanguageChanged, this, &ServerLMSWidget::slot_LanguageChanged);
|
connect(&dlg, &DialogSettingsTray::signal_LanguageChanged, this, &ServerLMSWidget::slot_LanguageChanged);
|
||||||
//connect(&dlg, &DialogSettingsTray::signal_UpdateStyleSheet, this, &InstructorsAndTraineesWidget::slot_UpdateStyleSheet);
|
//connect(&dlg, &DialogSettingsTray::signal_UpdateStyleSheet, this, &ServerLMSWidget::slot_UpdateStyleSheet);
|
||||||
|
|
||||||
|
|
||||||
switch( dlg.exec() )
|
switch( dlg.exec() )
|
||||||
|
|||||||
@@ -9,48 +9,16 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
ui(new Ui::MainWindow),
|
ui(new Ui::MainWindow),
|
||||||
serverLMSWidget(nullptr),
|
serverLMSWidget(nullptr),
|
||||||
trayIcon(nullptr),
|
trayIcon(nullptr),
|
||||||
menu(nullptr),
|
trayMenu(nullptr),
|
||||||
action_ShowWindow(nullptr),
|
action_ShowWindow(nullptr),
|
||||||
action_HideWindow(nullptr),
|
action_HideWindow(nullptr),
|
||||||
action_Exit(nullptr)
|
action_Exit(nullptr)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
/* Инициализируем иконку трея, устанавливаем иконку,
|
//Скрываем ненужные элементы окна
|
||||||
* а также задаем всплывающую подсказку
|
ui->menubar->setVisible(false);
|
||||||
* */
|
ui->statusbar->setVisible(false);
|
||||||
trayIcon = new QSystemTrayIcon(this);
|
|
||||||
//trayIcon->setIcon(this->style()->standardIcon(QStyle::SP_ComputerIcon));
|
|
||||||
trayIcon->setIcon(QPixmap(":/resources/database-management.png"));
|
|
||||||
trayIcon->setToolTip(tr("Server LMS"));
|
|
||||||
|
|
||||||
/* После чего создаем контекстное меню*/
|
|
||||||
menu = new QMenu(this);
|
|
||||||
action_ShowWindow = new QAction(tr("Expand window"), this);
|
|
||||||
action_HideWindow = new QAction(tr("Minimize window"), this);
|
|
||||||
action_Exit = new QAction(tr("Exit"), this);
|
|
||||||
|
|
||||||
/* подключаем сигналы нажатий на пункты меню к соответсвующим слотам.
|
|
||||||
* */
|
|
||||||
connect(action_ShowWindow, SIGNAL(triggered()), this, SLOT(slot_Menu_ShowWindow()));
|
|
||||||
connect(action_HideWindow, SIGNAL(triggered()), this, SLOT(slot_Menu_HideWindow()));
|
|
||||||
connect(action_Exit, SIGNAL(triggered()), this, SLOT(slot_Menu_Exit()));
|
|
||||||
|
|
||||||
menu->addAction(action_ShowWindow);
|
|
||||||
menu->addAction(action_HideWindow);
|
|
||||||
menu->addAction(action_Exit);
|
|
||||||
|
|
||||||
/* Устанавливаем контекстное меню на иконку
|
|
||||||
* и показываем иконку приложения в трее
|
|
||||||
* */
|
|
||||||
trayIcon->setContextMenu(menu);
|
|
||||||
trayIcon->show();
|
|
||||||
|
|
||||||
/* Также подключаем сигнал нажатия на иконку к обработчику
|
|
||||||
* данного нажатия
|
|
||||||
* */
|
|
||||||
connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
|
|
||||||
this, SLOT(slot_Activated(QSystemTrayIcon::ActivationReason)));
|
|
||||||
|
|
||||||
serverLMSWidget = new ServerLMSWidget(this);
|
serverLMSWidget = new ServerLMSWidget(this);
|
||||||
|
|
||||||
@@ -59,17 +27,61 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
connect(serverLMSWidget, &ServerLMSWidget::signal_LanguageChanged, this, &MainWindow::slot_LanguageChanged);
|
connect(serverLMSWidget, &ServerLMSWidget::signal_LanguageChanged, this, &MainWindow::slot_LanguageChanged);
|
||||||
connect(serverLMSWidget, &ServerLMSWidget::signal_Tray_ShowMessage, this, &MainWindow::slot_Tray_ShowMessage);
|
connect(serverLMSWidget, &ServerLMSWidget::signal_Tray_ShowMessage, this, &MainWindow::slot_Tray_ShowMessage);
|
||||||
|
|
||||||
connect(serverLMSWidget, &ServerLMSWidget::signal_Menu_ShowWindow, this, &MainWindow::slot_Menu_ShowWindow);
|
connect(serverLMSWidget, &ServerLMSWidget::signal_Menu_ShowWindow, this, &MainWindow::slot_TrayMenu_ShowWindow);
|
||||||
connect(serverLMSWidget, &ServerLMSWidget::signal_Menu_HideWindow, this, &MainWindow::slot_Menu_HideWindow);
|
connect(serverLMSWidget, &ServerLMSWidget::signal_Menu_HideWindow, this, &MainWindow::slot_TrayMenu_HideWindow);
|
||||||
|
|
||||||
qtLanguageTranslator.load(QString("translations/TrayServerLMS_") + serverLMSWidget->getLanguage(), ".");
|
qtLanguageTranslator.load(QString("translations/TrayServerLMS_") + serverLMSWidget->getLanguage(), ".");
|
||||||
qApp->installTranslator(&qtLanguageTranslator);
|
qApp->installTranslator(&qtLanguageTranslator);
|
||||||
|
|
||||||
|
/* Инициализируем иконку трея, устанавливаем иконку,
|
||||||
|
* а также задаем всплывающую подсказку
|
||||||
|
* */
|
||||||
|
trayIcon = new QSystemTrayIcon(this);
|
||||||
|
//trayIcon->setIcon(this->style()->standardIcon(QStyle::SP_ComputerIcon));
|
||||||
|
trayIcon->setIcon(QPixmap(":/resources/database-management.png"));
|
||||||
|
|
||||||
|
/* После чего создаем контекстное меню для иконки трея*/
|
||||||
|
trayMenu = new QMenu(this);
|
||||||
|
action_ShowWindow = new QAction(this);
|
||||||
|
action_HideWindow = new QAction(this);
|
||||||
|
action_Exit = new QAction(this);
|
||||||
|
|
||||||
|
/* подключаем сигналы нажатий на пункты меню к соответсвующим слотам.
|
||||||
|
* */
|
||||||
|
connect(action_ShowWindow, &QAction::triggered, this, &MainWindow::slot_TrayMenu_ShowWindow);
|
||||||
|
connect(action_HideWindow, &QAction::triggered, this, &MainWindow::slot_TrayMenu_HideWindow);
|
||||||
|
connect(action_Exit, &QAction::triggered, this, &MainWindow::slot_TrayMenu_Exit);
|
||||||
|
|
||||||
|
trayMenu->addAction(action_ShowWindow);
|
||||||
|
trayMenu->addAction(action_HideWindow);
|
||||||
|
trayMenu->addAction(action_Exit);
|
||||||
|
|
||||||
|
updateTrayTitles();
|
||||||
|
|
||||||
|
/* Устанавливаем контекстное меню на иконку
|
||||||
|
* и показываем иконку приложения в трее
|
||||||
|
* */
|
||||||
|
trayIcon->setContextMenu(trayMenu);
|
||||||
|
trayIcon->show();
|
||||||
|
|
||||||
slot_Tray_ShowMessage(tr("Starting the server..."));
|
slot_Tray_ShowMessage(tr("Starting the server..."));
|
||||||
|
|
||||||
serverLMSWidget->start();
|
serverLMSWidget->start();
|
||||||
|
|
||||||
errorCheck();
|
errorCheck();
|
||||||
|
|
||||||
|
QTimer::singleShot(1000,this,&MainWindow::slot_Connect);
|
||||||
|
}
|
||||||
|
|
||||||
|
MainWindow::~MainWindow()
|
||||||
|
{
|
||||||
|
delete serverLMSWidget;
|
||||||
|
delete trayIcon;
|
||||||
|
delete trayMenu;
|
||||||
|
delete action_ShowWindow;
|
||||||
|
delete action_HideWindow;
|
||||||
|
delete action_Exit;
|
||||||
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Метод, который обрабатывает событие закрытия окна приложения
|
/* Метод, который обрабатывает событие закрытия окна приложения
|
||||||
@@ -77,64 +89,15 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
void MainWindow::closeEvent(QCloseEvent * event)
|
void MainWindow::closeEvent(QCloseEvent * event)
|
||||||
{
|
{
|
||||||
/* Если окно видимо, то завершение приложения
|
/* Если окно видимо, то завершение приложения
|
||||||
* игнорируется, а окно просто скрывается, что сопровождается
|
* игнорируется, а окно просто скрывается
|
||||||
* соответствующим всплывающим сообщением
|
|
||||||
*/
|
*/
|
||||||
if(this->isVisible())
|
if(this->isVisible())
|
||||||
{
|
{
|
||||||
event->ignore();
|
event->ignore();
|
||||||
slot_Menu_HideWindow();
|
slot_TrayMenu_HideWindow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Метод, который обрабатывает нажатие на иконку приложения в трее
|
|
||||||
* */
|
|
||||||
void MainWindow::slot_Activated(QSystemTrayIcon::ActivationReason reason)
|
|
||||||
{
|
|
||||||
switch (reason){
|
|
||||||
case QSystemTrayIcon::Trigger:
|
|
||||||
/* если окно видимо, то оно скрывается,
|
|
||||||
* и наоборот, если скрыто, то разворачивается на экран
|
|
||||||
* */
|
|
||||||
if(!this->isVisible())
|
|
||||||
{
|
|
||||||
slot_Menu_ShowWindow();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
slot_Menu_HideWindow();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::slot_MessageClicked()
|
|
||||||
{
|
|
||||||
if(!this->isVisible())
|
|
||||||
{
|
|
||||||
slot_Menu_ShowWindow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::exit()
|
|
||||||
{
|
|
||||||
QApplication::exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
|
||||||
{
|
|
||||||
delete serverLMSWidget;
|
|
||||||
delete trayIcon;
|
|
||||||
delete menu;
|
|
||||||
delete action_ShowWindow;
|
|
||||||
delete action_HideWindow;
|
|
||||||
delete action_Exit;
|
|
||||||
delete ui;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::changeEvent(QEvent *event)
|
void MainWindow::changeEvent(QEvent *event)
|
||||||
{
|
{
|
||||||
// В случае получения события изменения языка приложения
|
// В случае получения события изменения языка приложения
|
||||||
@@ -142,56 +105,67 @@ void MainWindow::changeEvent(QEvent *event)
|
|||||||
{// переведём окно заново
|
{// переведём окно заново
|
||||||
ui->retranslateUi(this);
|
ui->retranslateUi(this);
|
||||||
|
|
||||||
trayIcon->setToolTip(tr("Server LMS"));
|
//и все, что связано с треем
|
||||||
action_ShowWindow->setText(tr("Expand window"));
|
updateTrayTitles();
|
||||||
action_HideWindow->setText(tr("Minimize window"));
|
|
||||||
action_Exit->setText(tr("Exit"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::errorCheck()
|
/* Метод, который обрабатывает нажатие на иконку приложения в трее
|
||||||
|
* */
|
||||||
|
void MainWindow::slot_TrayIconActivated(QSystemTrayIcon::ActivationReason reason)
|
||||||
{
|
{
|
||||||
if(serverLMSWidget->hasError() == 100)
|
switch (reason){
|
||||||
|
case QSystemTrayIcon::Trigger:
|
||||||
|
/* если окно видимо, то оно скрывается,
|
||||||
|
* и наоборот, если скрыто, то разворачивается на экран
|
||||||
|
* */
|
||||||
|
if(!this->isVisible())
|
||||||
{
|
{
|
||||||
slot_Menu_ShowWindow();
|
slot_TrayMenu_ShowWindow();
|
||||||
|
|
||||||
QMessageBox msgBox;
|
|
||||||
|
|
||||||
msgBox.setWindowTitle(tr("Error!"));
|
|
||||||
msgBox.setIcon(QMessageBox::Critical);
|
|
||||||
msgBox.setText(tr("No Client files found!"));
|
|
||||||
msgBox.setInformativeText(tr("* check Application for the presence of a folder with a build \n"
|
|
||||||
"* check SharedData for a folder with the base version and the name base"));
|
|
||||||
msgBox.setStandardButtons(QMessageBox::Close);
|
|
||||||
msgBox.show();
|
|
||||||
int ret = msgBox.exec();
|
|
||||||
|
|
||||||
if (ret == QMessageBox::Close)
|
|
||||||
{
|
|
||||||
//выключение с задержкой, так как eventLoop инициализируется позже
|
|
||||||
QTimer::singleShot(1000,this,&MainWindow::slot_Menu_Exit);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
slot_TrayMenu_HideWindow();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::slot_Menu_ShowWindow()
|
/* Метод, который обрабатывает нажатие на сообщение из трея
|
||||||
|
* */
|
||||||
|
void MainWindow::slot_TrayMessageClicked()
|
||||||
{
|
{
|
||||||
|
if(!this->isVisible())
|
||||||
|
{
|
||||||
|
slot_TrayMenu_ShowWindow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::slot_TrayMenu_ShowWindow()
|
||||||
|
{
|
||||||
|
//TODO под вопросом?
|
||||||
|
if(!serverLMSWidget->isEnabledTo(this))
|
||||||
|
return;
|
||||||
this->show();
|
this->show();
|
||||||
action_ShowWindow->setEnabled(false);
|
action_ShowWindow->setEnabled(false);
|
||||||
action_HideWindow->setEnabled(true);
|
action_HideWindow->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::slot_Menu_HideWindow()
|
void MainWindow::slot_TrayMenu_HideWindow()
|
||||||
{
|
{
|
||||||
this->hide();
|
this->hide();
|
||||||
action_ShowWindow->setEnabled(true);
|
action_ShowWindow->setEnabled(true);
|
||||||
action_HideWindow->setEnabled(false);
|
action_HideWindow->setEnabled(false);
|
||||||
|
|
||||||
|
/*
|
||||||
slot_Tray_ShowMessage(tr("The application is minimized to the tray.\n"
|
slot_Tray_ShowMessage(tr("The application is minimized to the tray.\n"
|
||||||
"To maximize the application window, click the application icon in the tray."));
|
"To maximize the application window, click the application icon in the tray."));
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::slot_Menu_Exit()
|
void MainWindow::slot_TrayMenu_Exit()
|
||||||
{
|
{
|
||||||
this->hide();
|
this->hide();
|
||||||
this->close();
|
this->close();
|
||||||
@@ -205,8 +179,58 @@ void MainWindow::slot_Tray_ShowMessage(QString textMsg, QSystemTrayIcon::Message
|
|||||||
icon, 100);
|
icon, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::slot_Connect()
|
||||||
|
{
|
||||||
|
/* Также подключаем сигнал нажатия на иконку к обработчику
|
||||||
|
* данного нажатия
|
||||||
|
* */
|
||||||
|
connect(trayIcon, &QSystemTrayIcon::activated, this, &MainWindow::slot_TrayIconActivated);
|
||||||
|
/* Также подключаем сигнал нажатия на всплывающее сообщение к обработчику
|
||||||
|
* данного нажатия
|
||||||
|
* */
|
||||||
|
connect(trayIcon, &QSystemTrayIcon::messageClicked, this, &MainWindow::slot_TrayMessageClicked);
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::slot_LanguageChanged(QString language)
|
void MainWindow::slot_LanguageChanged(QString language)
|
||||||
{
|
{
|
||||||
qtLanguageTranslator.load(QString(QStringLiteral("translations/TrayServerLMS_")) + language, QStringLiteral("."));
|
qtLanguageTranslator.load(QString(QStringLiteral("translations/TrayServerLMS_")) + language, QStringLiteral("."));
|
||||||
qApp->installTranslator(&qtLanguageTranslator);
|
qApp->installTranslator(&qtLanguageTranslator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::exit()
|
||||||
|
{
|
||||||
|
QApplication::exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::errorCheck()
|
||||||
|
{
|
||||||
|
if(serverLMSWidget->hasError() == 100)
|
||||||
|
{
|
||||||
|
slot_TrayMenu_ShowWindow();
|
||||||
|
|
||||||
|
QMessageBox msgBox(this);
|
||||||
|
|
||||||
|
msgBox.setWindowTitle(tr("Error!"));
|
||||||
|
msgBox.setIcon(QMessageBox::Critical);
|
||||||
|
msgBox.setText(tr("No Client files found!"));
|
||||||
|
msgBox.setInformativeText(tr("* check Application for the presence of a folder with a build \n"
|
||||||
|
"* check SharedData for a folder with the base version and the name base"));
|
||||||
|
msgBox.setStandardButtons(QMessageBox::Close);
|
||||||
|
msgBox.show();
|
||||||
|
int ret = msgBox.exec();
|
||||||
|
|
||||||
|
if (ret == QMessageBox::Close)
|
||||||
|
{
|
||||||
|
//выключение с задержкой, так как eventLoop инициализируется позже
|
||||||
|
QTimer::singleShot(1000,this,&MainWindow::slot_TrayMenu_Exit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::updateTrayTitles()
|
||||||
|
{
|
||||||
|
trayIcon->setToolTip(tr("Server LMS"));
|
||||||
|
action_ShowWindow->setText(tr("Expand window"));
|
||||||
|
action_HideWindow->setText(tr("Minimize window"));
|
||||||
|
action_Exit->setText(tr("Exit"));
|
||||||
|
}
|
||||||
|
|||||||
@@ -41,25 +41,23 @@ public slots:
|
|||||||
void slot_LanguageChanged(QString language);
|
void slot_LanguageChanged(QString language);
|
||||||
|
|
||||||
//Слот нажатия на иконку приложения в трее
|
//Слот нажатия на иконку приложения в трее
|
||||||
void slot_Activated(QSystemTrayIcon::ActivationReason reason);
|
void slot_TrayIconActivated(QSystemTrayIcon::ActivationReason reason);
|
||||||
//Слот нажатия на сообщение
|
//Слот нажатия на сообщение
|
||||||
void slot_MessageClicked();
|
void slot_TrayMessageClicked();
|
||||||
|
|
||||||
//Слоты нажатия на пункты меню
|
//Слоты нажатия на пункты меню
|
||||||
void slot_Menu_ShowWindow();
|
void slot_TrayMenu_ShowWindow();
|
||||||
void slot_Menu_HideWindow();
|
void slot_TrayMenu_HideWindow();
|
||||||
void slot_Menu_Exit();
|
void slot_TrayMenu_Exit();
|
||||||
|
|
||||||
//Слот вывода сообщения из трея
|
//Слот вывода сообщения из трея
|
||||||
void slot_Tray_ShowMessage(QString textMsg, QSystemTrayIcon::MessageIcon iconMsg = QSystemTrayIcon::Information);
|
void slot_Tray_ShowMessage(QString textMsg, QSystemTrayIcon::MessageIcon iconMsg = QSystemTrayIcon::Information);
|
||||||
|
|
||||||
signals:
|
void slot_Connect();
|
||||||
//сигнал об изменении языка интерфейса
|
|
||||||
void signal_LanguageChanged(QString language);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void exit();
|
void exit();
|
||||||
void errorCheck();
|
void errorCheck();
|
||||||
|
void updateTrayTitles();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
@@ -68,7 +66,7 @@ private:
|
|||||||
|
|
||||||
//Трей
|
//Трей
|
||||||
QSystemTrayIcon* trayIcon;
|
QSystemTrayIcon* trayIcon;
|
||||||
QMenu * menu;
|
QMenu * trayMenu;
|
||||||
QAction * action_ShowWindow;
|
QAction * action_ShowWindow;
|
||||||
QAction * action_HideWindow;
|
QAction * action_HideWindow;
|
||||||
QAction * action_Exit;
|
QAction * action_Exit;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>1198</width>
|
<width>1200</width>
|
||||||
<height>800</height>
|
<height>800</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@@ -35,16 +35,23 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenuBar" name="menubar">
|
<widget class="QMenuBar" name="menubar">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>1198</width>
|
<width>1200</width>
|
||||||
<height>21</height>
|
<height>21</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QStatusBar" name="statusbar"/>
|
<widget class="QStatusBar" name="statusbar">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="TrayServerLMS.qrc"/>
|
<include location="TrayServerLMS.qrc"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user