From a3df3951dcb0b1cb9e95941bcfb28f4f65c4afc3 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Fri, 30 Apr 2021 20:56:53 +0300 Subject: [PATCH] replace QMessageBoxes with KMessageBoxes --- app/settings/detailsdialog/detailshandler.cpp | 15 +++--- app/settings/detailsdialog/detailshandler.h | 5 +- app/settings/generic/genericdialog.cpp | 41 +++------------ app/settings/generic/genericdialog.h | 3 +- .../settingsdialog/settingsdialog.cpp | 11 ++-- app/settings/viewsdialog/viewshandler.cpp | 50 ++++++++----------- app/settings/viewsdialog/viewshandler.h | 7 ++- 7 files changed, 53 insertions(+), 79 deletions(-) diff --git a/app/settings/detailsdialog/detailshandler.cpp b/app/settings/detailsdialog/detailshandler.cpp index ed814c04e..dfc124c14 100644 --- a/app/settings/detailsdialog/detailshandler.cpp +++ b/app/settings/detailsdialog/detailshandler.cpp @@ -36,7 +36,6 @@ #include #include #include -#include // KDE #include @@ -259,16 +258,16 @@ void DetailsHandler::onCurrentLayoutIndexChanged(int row) if (m_lastConfirmedLayoutIndex != row) { if (hasChangedData()) { //new layout was chosen but there are changes - int result = saveChangesConfirmation(); + KMessageBox::ButtonCode result = saveChangesConfirmation(); - if (result == QMessageBox::Apply) { + if (result == KMessageBox::Yes) { switchtonewlayout = true; m_lastConfirmedLayoutIndex = row; save(); - } else if (result == QMessageBox::Discard) { + } else if (result == KMessageBox::No) { switchtonewlayout = true; m_lastConfirmedLayoutIndex = row; - } else if (result == QMessageBox::Cancel) { + } else if (result == KMessageBox::Cancel) { //do nothing } } else { //new layout was chosen and there are no changes @@ -408,16 +407,16 @@ void DetailsHandler::updateWindowTitle() m_dialog->setWindowTitle(i18nc(" Details","%0 Details").arg(m_ui->layoutsCmb->currentText())); } -int DetailsHandler::saveChangesConfirmation() +KMessageBox::ButtonCode DetailsHandler::saveChangesConfirmation() { if (hasChangedData()) { QString layoutName = c_data.name; - QString saveChangesText = i18n("The settings of %0 layout have changed. Do you want to apply the changes or discard them?").arg(layoutName); + QString saveChangesText = i18n("The settings of %0 layout have changed.
Do you want to apply the changes or discard them?").arg(layoutName); return m_dialog->saveChangesConfirmation(saveChangesText); } - return QMessageBox::Cancel; + return KMessageBox::Cancel; } } diff --git a/app/settings/detailsdialog/detailshandler.h b/app/settings/detailsdialog/detailshandler.h index 028aa6342..0ce206af0 100644 --- a/app/settings/detailsdialog/detailshandler.h +++ b/app/settings/detailsdialog/detailshandler.h @@ -30,6 +30,9 @@ #include #include +// KDE +#include + namespace Ui { class DetailsDialog; } @@ -106,7 +109,7 @@ private: void loadLayout(const Latte::Data::Layout &data); - int saveChangesConfirmation(); + KMessageBox::ButtonCode saveChangesConfirmation(); private: Dialog::DetailsDialog *m_dialog{nullptr}; diff --git a/app/settings/generic/genericdialog.cpp b/app/settings/generic/genericdialog.cpp index da31ecfaf..a6db92c1d 100644 --- a/app/settings/generic/genericdialog.cpp +++ b/app/settings/generic/genericdialog.cpp @@ -29,6 +29,7 @@ // KDE #include +#include static const int ERRORINTERVAL = 4000; static const int INFORMATIONINTERVAL = 3000; @@ -64,41 +65,15 @@ KMessageWidget *GenericDialog::initMessageWidget() return messagewidget; } -int GenericDialog::saveChangesConfirmation(const QString &text, QString applyBtnText, QMessageBox::StandardButton defaultButton) +KMessageBox::ButtonCode GenericDialog::saveChangesConfirmation(const QString &text) { - auto msg = new QMessageBox(this); - msg->setIcon(QMessageBox::Warning); - msg->setWindowTitle(i18n("Apply Settings")); - msg->setAttribute(Qt::WA_DeleteOnClose, true); - - if (text.isEmpty()) { - msg->setText(i18n("The settings have changed. Do you want to apply the changes or discard them?")); - } else { - msg->setText(text); - } - - if (applyBtnText.isEmpty()) { - msg->setStandardButtons(QMessageBox::Apply | QMessageBox::Discard | QMessageBox::Cancel); - msg->setDefaultButton(defaultButton == QMessageBox::NoButton ? QMessageBox::Apply : defaultButton); - return msg->exec(); - } else { - msg->setStandardButtons(QMessageBox::Discard | QMessageBox::Cancel); - QPushButton *applyCustomBtn = new QPushButton(msg); - applyCustomBtn->setText(applyBtnText); - applyCustomBtn->setIcon(QIcon::fromTheme("dialog-yes")); - msg->addButton(applyCustomBtn, QMessageBox::ApplyRole); - msg->setDefaultButton(defaultButton == QMessageBox::NoButton ? QMessageBox::Apply : defaultButton); - - if (defaultButton == QMessageBox::NoButton || defaultButton == QMessageBox::Apply) { - msg->setDefaultButton(applyCustomBtn); - } else { - msg->setDefaultButton(defaultButton); - } + QString dialogtext = text.isEmpty() ? i18n("The settings have changed.
Do you want to apply the changes or discard them?") : text; - int result = msg->exec(); - - return (msg->clickedButton() == applyCustomBtn ? QMessageBox::Apply : result); - } + return KMessageBox::warningYesNoCancel(this, + dialogtext, + i18n("Apply Settings"), + KStandardGuiItem::apply(), + KStandardGuiItem::discard()); } void GenericDialog::showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const bool &isPersistent, QList actions) diff --git a/app/settings/generic/genericdialog.h b/app/settings/generic/genericdialog.h index c21a1f672..e8a7ae67c 100644 --- a/app/settings/generic/genericdialog.h +++ b/app/settings/generic/genericdialog.h @@ -30,6 +30,7 @@ #include // KDE +#include #include namespace Latte { @@ -47,7 +48,7 @@ public: void showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const bool &isPersistent = false, QList actions = QList()); void hideInlineMessage(); - int saveChangesConfirmation(const QString &text, QString applyBtnText = "", QMessageBox::StandardButton defaultButton = QMessageBox::NoButton); + KMessageBox::ButtonCode saveChangesConfirmation(const QString &text); private slots: KMessageWidget *initMessageWidget(); diff --git a/app/settings/settingsdialog/settingsdialog.cpp b/app/settings/settingsdialog/settingsdialog.cpp index fca101256..7f2a45325 100644 --- a/app/settings/settingsdialog/settingsdialog.cpp +++ b/app/settings/settingsdialog/settingsdialog.cpp @@ -43,9 +43,10 @@ #include // KDE -#include #include +#include #include +#include namespace Latte { @@ -475,13 +476,13 @@ bool SettingsDialog::saveChanges() || (m_acceptedPage == PreferencesPage && m_tabPreferencesHandler->hasChangedData())) { QString tabName = m_ui->tabWidget->tabBar()->tabText(m_acceptedPage).remove("&"); - QString saveChangesText = i18n("The settings of %0 tab have changed. Do you want to apply the changes or discard them?").arg(tabName); + QString saveChangesText = i18n("The settings of %0 tab have changed.
Do you want to apply the changes or discard them?").arg(tabName); - int result = saveChangesConfirmation(saveChangesText); + KMessageBox::ButtonCode result = saveChangesConfirmation(saveChangesText); - if (result == QMessageBox::Apply) { + if (result == KMessageBox::Yes) { save(); - } else if (result == QMessageBox::Discard) { + } else if (result == KMessageBox::No) { reset(); } else { return false; diff --git a/app/settings/viewsdialog/viewshandler.cpp b/app/settings/viewsdialog/viewshandler.cpp index 9c600d179..747433056 100644 --- a/app/settings/viewsdialog/viewshandler.cpp +++ b/app/settings/viewsdialog/viewshandler.cpp @@ -39,11 +39,9 @@ #include "../../templates/templatesmanager.h" #include "../../tools/commontools.h" -// Qt -#include - -//! KDE +// KDE #include +#include #include namespace Latte { @@ -235,7 +233,7 @@ void ViewsHandler::resetDefaults() void ViewsHandler::save() { - if (removalConfirmation(m_viewsController->viewsForRemovalCount()) == QMessageBox::Yes) { + if (removalConfirmation(m_viewsController->viewsForRemovalCount()) == KMessageBox::Yes) { m_viewsController->save(); } } @@ -273,23 +271,23 @@ void ViewsHandler::onCurrentLayoutIndexChanged(int row) if (m_lastConfirmedLayoutIndex != row) { if (hasChangedData()) { //new layout was chosen but there are changes - int result = saveChangesConfirmation(); + KMessageBox::ButtonCode result = saveChangesConfirmation(); - if (result == QMessageBox::Apply) { + if (result == KMessageBox::Yes) { int removalviews = m_viewsController->viewsForRemovalCount(); - int removalresponse = removalConfirmation(removalviews); + KMessageBox::ButtonCode removalresponse = removalConfirmation(removalviews); - if ( removalresponse == QMessageBox::Yes) { + if (removalresponse == KMessageBox::Yes) { switchtonewlayout = true; m_lastConfirmedLayoutIndex = row; m_viewsController->save(); } else { //do nothing } - } else if (result == QMessageBox::Discard) { + } else if (result == KMessageBox::No) { switchtonewlayout = true; m_lastConfirmedLayoutIndex = row; - } else if (result == QMessageBox::Cancel) { + } else if (result == KMessageBox::Cancel) { //do nothing } } else { //new layout was chosen and there are no changes @@ -314,43 +312,37 @@ void ViewsHandler::updateWindowTitle() m_dialog->setWindowTitle(i18nc(" Docks/Panels","%0 Docks/Panels").arg(m_ui->layoutsCmb->currentText())); } -int ViewsHandler::removalConfirmation(const int &viewsCount) +KMessageBox::ButtonCode ViewsHandler::removalConfirmation(const int &viewsCount) { if (viewsCount<=0) { - return QMessageBox::Yes; + return KMessageBox::Yes; } if (hasChangedData()) { - QString removalTxt = i18n("You are going to remove 1 dock or panel completely from your layout.

Would you like to continue?"); + QString removalTxt = i18n("You are going to remove 1 dock or panel completely from your layout.
Would you like to continue?"); if (viewsCount > 1) { - removalTxt = i18n ("You are going to remove %0 docks and panels completely from your layout.

Would you like to continue?").arg(viewsCount); + removalTxt = i18n ("You are going to remove %0 docks and panels completely from your layout.
Would you like to continue?").arg(viewsCount); } - auto msg = new QMessageBox(m_dialog); - msg->setIcon(QMessageBox::Warning); - msg->setWindowTitle(i18n("Approve Removal")); - msg->setText(removalTxt); - msg->setStandardButtons(QMessageBox::Yes | QMessageBox::No); - msg->setDefaultButton(QMessageBox::No); - msg->setAttribute(Qt::WA_DeleteOnClose, true); - - return msg->exec(); + return KMessageBox::warningYesNo(m_dialog, + removalTxt, + i18n("Approve Removal")); } - return QMessageBox::Yes; + return KMessageBox::Yes; } -int ViewsHandler::saveChangesConfirmation() +KMessageBox::ButtonCode ViewsHandler::saveChangesConfirmation() { if (hasChangedData()) { QString layoutName = o_data.name; - QString saveChangesText = i18n("The settings of %0 layout have changed. Do you want to apply the changes now or discard them?").arg(layoutName); + QString saveChangesText = i18n("The settings of %0 layout have changed.
Do you want to apply the changes now or discard them?").arg(layoutName); - return m_dialog->saveChangesConfirmation(saveChangesText, i18n("Apply Now")); + return m_dialog->saveChangesConfirmation(saveChangesText); } - return QMessageBox::Cancel; + return KMessageBox::Cancel; } } diff --git a/app/settings/viewsdialog/viewshandler.h b/app/settings/viewsdialog/viewshandler.h index c37755265..433e642b6 100644 --- a/app/settings/viewsdialog/viewshandler.h +++ b/app/settings/viewsdialog/viewshandler.h @@ -32,6 +32,9 @@ #include #include +// KDE +#include + namespace Ui { class ViewsDialog; } @@ -101,8 +104,8 @@ private: void loadLayout(const Latte::Data::Layout &data); - int saveChangesConfirmation(); - int removalConfirmation(const int &count); + KMessageBox::ButtonCode saveChangesConfirmation(); + KMessageBox::ButtonCode removalConfirmation(const int &count); private: Dialog::ViewsDialog *m_dialog{nullptr};