From 5929d59c9c8ac0aec88328431136db125443e5cd Mon Sep 17 00:00:00 2001 From: Nicolas Mailloux Date: Wed, 25 Aug 2021 13:32:33 -0400 Subject: [PATCH] Relocate showToast from settings to MainWindow --- mainwindow.cpp | 4 +++- settings.cpp | 22 ++++++++++------------ settings.h | 4 ++++ settingschooser.cpp | 12 +++++++++++- settingschooser.h | 7 ++++++- 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 7f8835e..134f89c 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -594,8 +594,10 @@ void MainWindow::on_settingsBtn_clicked() ui->settingsBtn->setStyleSheet("background: black"); ui->settingsBtn->setIcon(QIcon(":/resources/settings-inverted.png")); - // Create widget + // Create widget and make necessary connections settingsChooserWindow = new settingsChooser(); + connect(settingsChooserWindow, SIGNAL(showToast(QString)), SLOT(showToast(QString))); + connect(settingsChooserWindow, SIGNAL(closeIndefiniteToast()), SLOT(closeIndefiniteToast())); ui->stackedWidget->insertWidget(2, settingsChooserWindow); global::mainwindow::tabSwitcher::settingsChooserWidgetCreated = true; diff --git a/settings.cpp b/settings.cpp index ab34901..903a859 100644 --- a/settings.cpp +++ b/settings.cpp @@ -327,6 +327,10 @@ settings::settings(QWidget *parent) : } if(global::device::isWifiAble == false) { + ui->checkOtaUpdateLabel->hide(); + ui->checkOtaUpdateBtn->hide(); + ui->checkOtaUpdateLabel->deleteLater(); + ui->checkOtaUpdateBtn->deleteLater(); ui->checkOtaUpdateGridLayout->deleteLater(); } @@ -871,8 +875,8 @@ void settings::openUpdateDialog() { // Show the dialog generalDialogWindow = new generalDialog(this); generalDialogWindow->setAttribute(Qt::WA_DeleteOnClose); - connect(generalDialogWindow, SIGNAL(showToast(QString)), SLOT(showToast(QString))); - connect(generalDialogWindow, SIGNAL(closeIndefiniteToast()), SLOT(closeIndefiniteToast())); + connect(generalDialogWindow, SIGNAL(showToast(QString)), SLOT(showToastNative(QString))); + connect(generalDialogWindow, SIGNAL(closeIndefiniteToast()), SLOT(closeIndefiniteToastNative())); generalDialogWindow->show(); QApplication::processEvents(); } @@ -893,16 +897,10 @@ void settings::openUpdateDialogOTA(bool open) { } } -void settings::showToast(QString messageToDisplay) { - global::toast::message = messageToDisplay; - toastWindow = new toast(this); - toastWindow->setAttribute(Qt::WA_DeleteOnClose); - connect(toastWindow, SIGNAL(showToast(QString)), SLOT(showToast(QString))); - connect(toastWindow, SIGNAL(closeIndefiniteToast()), SLOT(closeIndefiniteToast())); - toastWindow->show(); +void settings::showToastNative(QString messageToDisplay) { + emit showToast(messageToDisplay); } -void settings::closeIndefiniteToast() { - // Warning: use with caution - toastWindow->close(); +void settings::closeIndefiniteToastNative() { + emit closeIndefiniteToast(); } diff --git a/settings.h b/settings.h index 4b8f729..938eafb 100644 --- a/settings.h +++ b/settings.h @@ -59,6 +59,10 @@ private slots: void openUpdateDialog(); void launchOtaUpdater(); void openUpdateDialogOTA(bool open); + void showToastNative(QString messageToDisplay); + void closeIndefiniteToastNative(); + +signals: void showToast(QString messageToDisplay); void closeIndefiniteToast(); diff --git a/settingschooser.cpp b/settingschooser.cpp index ee47b31..f7f7c23 100644 --- a/settingschooser.cpp +++ b/settingschooser.cpp @@ -18,7 +18,7 @@ settingsChooser::settingsChooser(QWidget *parent) : stylesheetFile.close(); // UI tweaks - if(checkconfig("/opt/inkbox_kobox_support") != true) { + if(checkconfig("/opt/inkbox_kobox_support") == false) { ui->koboxSettingsBtn->hide(); ui->line_3->hide(); } @@ -73,6 +73,8 @@ void settingsChooser::on_inkboxSettingsBtn_clicked() { settingsWindow = new settings(); settingsWindow->setAttribute(Qt::WA_DeleteOnClose); + connect(settingsWindow, SIGNAL(showToast(QString)), SLOT(showToastNative(QString))); + connect(settingsWindow, SIGNAL(closeIndefiniteToast()), SLOT(closeIndefiniteToastNative())); settingsWindow->showFullScreen(); } @@ -82,3 +84,11 @@ void settingsChooser::on_koboxSettingsBtn_clicked() koboxSettingsWindow->setAttribute(Qt::WA_DeleteOnClose); koboxSettingsWindow->showFullScreen(); } + +void settingsChooser::showToastNative(QString messageToDisplay) { + emit showToast(messageToDisplay); +} + +void settingsChooser::closeIndefiniteToastNative() { + emit closeIndefiniteToast(); +} diff --git a/settingschooser.h b/settingschooser.h index 583daae..45798cb 100644 --- a/settingschooser.h +++ b/settingschooser.h @@ -25,8 +25,13 @@ public: private slots: void on_inkboxSettingsBtn_clicked(); - void on_koboxSettingsBtn_clicked(); + void showToastNative(QString messageToDisplay); + void closeIndefiniteToastNative(); + +signals: + void showToast(QString messageToDisplay); + void closeIndefiniteToast(); private: Ui::settingsChooser *ui;