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>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset>
|
||||
<iconset resource="InstructorsAndTrainees.qrc">
|
||||
<normaloff>:/resources/icons/lms.png</normaloff>:/resources/icons/lms.png</iconset>
|
||||
</property>
|
||||
<property name="sizeGripEnabled">
|
||||
@@ -76,6 +76,16 @@
|
||||
</item>
|
||||
</layout>
|
||||
</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>
|
||||
<widget class="QGroupBox" name="groupBox_Server">
|
||||
<property name="font">
|
||||
@@ -232,7 +242,7 @@
|
||||
<string>Save</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<iconset resource="InstructorsAndTrainees.qrc">
|
||||
<normaloff>:/resources/icons/circleGreen.png</normaloff>:/resources/icons/circleGreen.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
@@ -291,7 +301,7 @@
|
||||
<string>Version</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<iconset resource="InstructorsAndTrainees.qrc">
|
||||
<normaloff>:/resources/icons/updateVersion.png</normaloff>:/resources/icons/updateVersion.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
@@ -323,7 +333,7 @@
|
||||
<string>Style</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset>
|
||||
<iconset resource="InstructorsAndTrainees.qrc">
|
||||
<normaloff>:/resources/icons/style.png</normaloff>:/resources/icons/style.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
@@ -359,6 +369,8 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<resources>
|
||||
<include location="InstructorsAndTrainees.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
||||
@@ -81,6 +81,7 @@ void DialogCheckDB::on_btnRepare_clicked()
|
||||
if(!resDriver)
|
||||
{
|
||||
QMessageBox::critical(this, tr("Error!"), tr("Install PostgreSQL."));
|
||||
this->reject();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -88,8 +89,9 @@ void DialogCheckDB::on_btnRepare_clicked()
|
||||
{
|
||||
if(!providerDBLMS->createUser())
|
||||
{
|
||||
QMessageBox::critical(this, tr("Error!"), tr("Failed to create user!"));
|
||||
check();
|
||||
QMessageBox::critical(this, tr("Error!"), tr("Failed to create user!"));
|
||||
this->reject();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -98,8 +100,9 @@ void DialogCheckDB::on_btnRepare_clicked()
|
||||
{
|
||||
if(!providerDBLMS->createDB())
|
||||
{
|
||||
QMessageBox::critical(this, tr("Error!"), tr("Failed to create Database!"));
|
||||
check();
|
||||
QMessageBox::critical(this, tr("Error!"), tr("Failed to create Database!"));
|
||||
this->reject();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
<height>250</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -45,7 +45,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<spacer name="horizontalSpacer_1">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
@@ -229,6 +229,9 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_Result"/>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
|
||||
@@ -34,7 +34,7 @@ DialogSettingsTray::DialogSettingsTray(ProviderDBLMS* providerDBLMS, QWidget *pa
|
||||
/* Устанавливаем Валидатор на QLineEdit */
|
||||
ui->editHostName->setValidator(ipValidator);
|
||||
|
||||
settings = new ServerDBSettings;
|
||||
settings = new ServerDBSettings();
|
||||
|
||||
//Задаём два пункта с текстом локалей в комбобоксе
|
||||
ui->cmbLanguage->addItems(QStringList() << "English" << "Русский");
|
||||
@@ -50,7 +50,17 @@ DialogSettingsTray::DialogSettingsTray(ProviderDBLMS* providerDBLMS, QWidget *pa
|
||||
ui->cmbLanguage->setCurrentText("Русский");
|
||||
|
||||
ui->editNameDB->setText(settings->NameDB);
|
||||
|
||||
if(settings->HostName == "localhost")
|
||||
{
|
||||
ui->checkLocalhost->setChecked(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->checkLocalhost->setChecked(false);
|
||||
}
|
||||
ui->editHostName->setText(settings->HostName);
|
||||
|
||||
ui->editPort->setText(settings->Port);
|
||||
ui->editUserName->setText(settings->UserName);
|
||||
ui->editPassword->setText(settings->Password);
|
||||
@@ -240,6 +250,20 @@ void DialogSettingsTray::on_editPassword_textChanged(const QString &arg1)
|
||||
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()
|
||||
{
|
||||
//Проверяем, установлен ли PostgreSQL
|
||||
@@ -249,7 +273,7 @@ void DialogSettingsTray::on_btnCheckDB_clicked()
|
||||
return;
|
||||
}
|
||||
|
||||
//TODO Запрос Логина и Пароля Суперюзера PostgreSQL (postgres)
|
||||
//Запрос Логина и Пароля Суперюзера PostgreSQL (postgres)
|
||||
QString UserNamePostgres;
|
||||
QString PasswordPostgres;
|
||||
|
||||
@@ -296,7 +320,17 @@ void DialogSettingsTray::on_btnCheckDB_clicked()
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,8 @@ private slots:
|
||||
|
||||
void on_btnCheckDB_clicked();
|
||||
|
||||
void on_checkLocalhost_stateChanged(int arg1);
|
||||
|
||||
private:
|
||||
bool saveSettings();
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>427</height>
|
||||
<width>450</width>
|
||||
<height>400</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -51,38 +51,24 @@
|
||||
</item>
|
||||
</layout>
|
||||
</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>
|
||||
<widget class="QGroupBox" name="groupBox_DB">
|
||||
<property name="title">
|
||||
<string>Data Base</string>
|
||||
<string>Database</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="0">
|
||||
<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>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_HostName">
|
||||
<item>
|
||||
@@ -92,6 +78,26 @@
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
<widget class="QLineEdit" name="editHostName">
|
||||
<property name="maximumSize">
|
||||
@@ -131,6 +137,33 @@
|
||||
</item>
|
||||
</layout>
|
||||
</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>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_UserName">
|
||||
<item>
|
||||
@@ -142,6 +175,9 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="editUserName">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>170</width>
|
||||
@@ -160,12 +196,15 @@
|
||||
<item>
|
||||
<widget class="QLabel" name="label_Password">
|
||||
<property name="text">
|
||||
<string>Password</string>
|
||||
<string>User password</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="editPassword">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>170</width>
|
||||
|
||||
@@ -110,6 +110,8 @@ void ServerLMSWidget::slot_AddMessageToLog(QString message)
|
||||
void ServerLMSWidget::start()
|
||||
{
|
||||
startInitialization();
|
||||
if(hasError() == 100)
|
||||
return;
|
||||
tryConnectionToDB();
|
||||
}
|
||||
|
||||
@@ -172,7 +174,7 @@ void ServerLMSWidget::on_btnSettings_clicked()
|
||||
dlg.setWindowFlags(dlg.windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
|
||||
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() )
|
||||
|
||||
@@ -9,48 +9,16 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
ui(new Ui::MainWindow),
|
||||
serverLMSWidget(nullptr),
|
||||
trayIcon(nullptr),
|
||||
menu(nullptr),
|
||||
trayMenu(nullptr),
|
||||
action_ShowWindow(nullptr),
|
||||
action_HideWindow(nullptr),
|
||||
action_Exit(nullptr)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
/* Инициализируем иконку трея, устанавливаем иконку,
|
||||
* а также задаем всплывающую подсказку
|
||||
* */
|
||||
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)));
|
||||
//Скрываем ненужные элементы окна
|
||||
ui->menubar->setVisible(false);
|
||||
ui->statusbar->setVisible(false);
|
||||
|
||||
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_Tray_ShowMessage, this, &MainWindow::slot_Tray_ShowMessage);
|
||||
|
||||
connect(serverLMSWidget, &ServerLMSWidget::signal_Menu_ShowWindow, this, &MainWindow::slot_Menu_ShowWindow);
|
||||
connect(serverLMSWidget, &ServerLMSWidget::signal_Menu_HideWindow, this, &MainWindow::slot_Menu_HideWindow);
|
||||
connect(serverLMSWidget, &ServerLMSWidget::signal_Menu_ShowWindow, this, &MainWindow::slot_TrayMenu_ShowWindow);
|
||||
connect(serverLMSWidget, &ServerLMSWidget::signal_Menu_HideWindow, this, &MainWindow::slot_TrayMenu_HideWindow);
|
||||
|
||||
qtLanguageTranslator.load(QString("translations/TrayServerLMS_") + serverLMSWidget->getLanguage(), ".");
|
||||
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..."));
|
||||
|
||||
serverLMSWidget->start();
|
||||
|
||||
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)
|
||||
{
|
||||
/* Если окно видимо, то завершение приложения
|
||||
* игнорируется, а окно просто скрывается, что сопровождается
|
||||
* соответствующим всплывающим сообщением
|
||||
* игнорируется, а окно просто скрывается
|
||||
*/
|
||||
if(this->isVisible())
|
||||
{
|
||||
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)
|
||||
{
|
||||
// В случае получения события изменения языка приложения
|
||||
@@ -142,56 +105,67 @@ void MainWindow::changeEvent(QEvent *event)
|
||||
{// переведём окно заново
|
||||
ui->retranslateUi(this);
|
||||
|
||||
trayIcon->setToolTip(tr("Server LMS"));
|
||||
action_ShowWindow->setText(tr("Expand window"));
|
||||
action_HideWindow->setText(tr("Minimize window"));
|
||||
action_Exit->setText(tr("Exit"));
|
||||
//и все, что связано с треем
|
||||
updateTrayTitles();
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
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);
|
||||
slot_TrayMenu_ShowWindow();
|
||||
}
|
||||
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();
|
||||
action_ShowWindow->setEnabled(false);
|
||||
action_HideWindow->setEnabled(true);
|
||||
}
|
||||
|
||||
void MainWindow::slot_Menu_HideWindow()
|
||||
void MainWindow::slot_TrayMenu_HideWindow()
|
||||
{
|
||||
this->hide();
|
||||
action_ShowWindow->setEnabled(true);
|
||||
action_HideWindow->setEnabled(false);
|
||||
|
||||
/*
|
||||
slot_Tray_ShowMessage(tr("The application is minimized to the tray.\n"
|
||||
"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->close();
|
||||
@@ -205,8 +179,58 @@ void MainWindow::slot_Tray_ShowMessage(QString textMsg, QSystemTrayIcon::Message
|
||||
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)
|
||||
{
|
||||
qtLanguageTranslator.load(QString(QStringLiteral("translations/TrayServerLMS_")) + language, QStringLiteral("."));
|
||||
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_Activated(QSystemTrayIcon::ActivationReason reason);
|
||||
void slot_TrayIconActivated(QSystemTrayIcon::ActivationReason reason);
|
||||
//Слот нажатия на сообщение
|
||||
void slot_MessageClicked();
|
||||
void slot_TrayMessageClicked();
|
||||
|
||||
//Слоты нажатия на пункты меню
|
||||
void slot_Menu_ShowWindow();
|
||||
void slot_Menu_HideWindow();
|
||||
void slot_Menu_Exit();
|
||||
void slot_TrayMenu_ShowWindow();
|
||||
void slot_TrayMenu_HideWindow();
|
||||
void slot_TrayMenu_Exit();
|
||||
|
||||
//Слот вывода сообщения из трея
|
||||
void slot_Tray_ShowMessage(QString textMsg, QSystemTrayIcon::MessageIcon iconMsg = QSystemTrayIcon::Information);
|
||||
|
||||
signals:
|
||||
//сигнал об изменении языка интерфейса
|
||||
void signal_LanguageChanged(QString language);
|
||||
|
||||
void slot_Connect();
|
||||
private:
|
||||
void exit();
|
||||
void errorCheck();
|
||||
void updateTrayTitles();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
@@ -68,7 +66,7 @@ private:
|
||||
|
||||
//Трей
|
||||
QSystemTrayIcon* trayIcon;
|
||||
QMenu * menu;
|
||||
QMenu * trayMenu;
|
||||
QAction * action_ShowWindow;
|
||||
QAction * action_HideWindow;
|
||||
QAction * action_Exit;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1198</width>
|
||||
<width>1200</width>
|
||||
<height>800</height>
|
||||
</rect>
|
||||
</property>
|
||||
@@ -35,16 +35,23 @@
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1198</width>
|
||||
<width>1200</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
<widget class="QStatusBar" name="statusbar">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="TrayServerLMS.qrc"/>
|
||||
|
||||
Reference in New Issue
Block a user