replace QMessageBoxes with KMessageBoxes

work/spdx
Michail Vourlakos 4 years ago
parent 7f11e50ecb
commit a3df3951dc

@ -36,7 +36,6 @@
#include <QColorDialog>
#include <QFileDialog>
#include <QIcon>
#include <QMessageBox>
// KDE
#include <KIconDialog>
@ -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("<layout name> 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 <b>%0</b> layout have changed. Do you want to apply the changes or discard them?").arg(layoutName);
QString saveChangesText = i18n("The settings of <b>%0</b> layout have changed.<br/>Do you want to apply the changes or discard them?").arg(layoutName);
return m_dialog->saveChangesConfirmation(saveChangesText);
}
return QMessageBox::Cancel;
return KMessageBox::Cancel;
}
}

@ -30,6 +30,9 @@
#include <QButtonGroup>
#include <QSortFilterProxyModel>
// KDE
#include <KMessageBox>
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};

@ -29,6 +29,7 @@
// KDE
#include <KLocalizedString>
#include <KStandardGuiItem>
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.<br/>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<QAction *> actions)

@ -30,6 +30,7 @@
#include <QWidget>
// KDE
#include <KMessageBox>
#include <KMessageWidget>
namespace Latte {
@ -47,7 +48,7 @@ public:
void showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const bool &isPersistent = false, QList<QAction *> actions = QList<QAction *>());
void hideInlineMessage();
int saveChangesConfirmation(const QString &text, QString applyBtnText = "", QMessageBox::StandardButton defaultButton = QMessageBox::NoButton);
KMessageBox::ButtonCode saveChangesConfirmation(const QString &text);
private slots:
KMessageWidget *initMessageWidget();

@ -43,9 +43,10 @@
#include <QMimeData>
// KDE
#include <KIO/OpenFileManagerWindowJob>
#include <KLocalizedString>
#include <KMessageBox>
#include <KWindowSystem>
#include <KIO/OpenFileManagerWindowJob>
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 <b>%0</b> tab have changed. Do you want to apply the changes or discard them?").arg(tabName);
QString saveChangesText = i18n("The settings of <b>%0</b> tab have changed.<br/>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;

@ -39,11 +39,9 @@
#include "../../templates/templatesmanager.h"
#include "../../tools/commontools.h"
// Qt
#include <QMessageBox>
//! KDE
// KDE
#include <KLocalizedString>
#include <KStandardGuiItem>
#include <KIO/OpenFileManagerWindowJob>
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("<layout name> 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 <b>remove 1</b> dock or panel completely from your layout.<br/><br/> Would you like to continue?");
QString removalTxt = i18n("You are going to <b>remove 1</b> dock or panel completely from your layout.<br/>Would you like to continue?");
if (viewsCount > 1) {
removalTxt = i18n ("You are going to <b>remove %0</b> docks and panels completely from your layout.<br/><br/> Would you like to continue?").arg(viewsCount);
removalTxt = i18n ("You are going to <b>remove %0</b> docks and panels completely from your layout.<br/>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 <b>%0</b> layout have changed. Do you want to apply the changes now or discard them?").arg(layoutName);
QString saveChangesText = i18n("The settings of <b>%0</b> layout have changed.<br/>Do you want to apply the changes <b>now</b> or discard them?").arg(layoutName);
return m_dialog->saveChangesConfirmation(saveChangesText, i18n("Apply Now"));
return m_dialog->saveChangesConfirmation(saveChangesText);
}
return QMessageBox::Cancel;
return KMessageBox::Cancel;
}
}

@ -32,6 +32,9 @@
#include <QMenu>
#include <QSortFilterProxyModel>
// KDE
#include <KMessageBox>
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};

Loading…
Cancel
Save