Port away from deprecated KMessageBox Yes/No

GIT_SILENT
This commit is contained in:
Friedrich W. H. Kossebau 2022-09-30 19:56:52 +02:00 committed by Méven Car
parent a509bd7629
commit 5be69f0dab
5 changed files with 64 additions and 0 deletions

View file

@ -70,6 +70,7 @@
#include <KWindowSystem> #include <KWindowSystem>
#include <KXMLGUIFactory> #include <KXMLGUIFactory>
#include <kwidgetsaddons_version.h>
#include <kio_version.h> #include <kio_version.h>
#include <QApplication> #include <QApplication>
@ -1177,11 +1178,19 @@ void DolphinMainWindow::openTerminalHere()
if (urls.count() > 5) { if (urls.count() > 5) {
QString question = i18np("Are you sure you want to open 1 terminal window?", QString question = i18np("Are you sure you want to open 1 terminal window?",
"Are you sure you want to open %1 terminal windows?", urls.count()); "Are you sure you want to open %1 terminal windows?", urls.count());
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
const int answer = KMessageBox::warningTwoActions(this, question, {},
#else
const int answer = KMessageBox::warningYesNo(this, question, {}, const int answer = KMessageBox::warningYesNo(this, question, {},
#endif
KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls.count()), KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls.count()),
QStringLiteral("utilities-terminal")), QStringLiteral("utilities-terminal")),
KStandardGuiItem::cancel()); KStandardGuiItem::cancel());
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
if (answer != KMessageBox::PrimaryAction) {
#else
if (answer != KMessageBox::Yes) { if (answer != KMessageBox::Yes) {
#endif
return; return;
} }
} }

View file

@ -24,6 +24,7 @@
#include <kio_version.h> #include <kio_version.h>
#include <kiocore_export.h> #include <kiocore_export.h>
#include <kservice_export.h> #include <kservice_export.h>
#include <kwidgetsaddons_version.h>
#include <QtGlobal> #include <QtGlobal>
#include <KNSWidgets/Button> #include <KNSWidgets/Button>
@ -199,14 +200,22 @@ void ContextMenuSettingsPage::applySettings()
VersionControlSettings::self()->save(); VersionControlSettings::self()->save();
if (!laterSelected) { if (!laterSelected) {
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
KMessageBox::ButtonCode promptRestart = KMessageBox::questionTwoActions(window(),
#else
KMessageBox::ButtonCode promptRestart = KMessageBox::questionYesNo(window(), KMessageBox::ButtonCode promptRestart = KMessageBox::questionYesNo(window(),
#endif
i18nc("@info", "Dolphin must be restarted to apply the " i18nc("@info", "Dolphin must be restarted to apply the "
"updated version control system settings."), "updated version control system settings."),
i18nc("@info", "Restart now?"), i18nc("@info", "Restart now?"),
KGuiItem(QApplication::translate("KStandardGuiItem", "&Restart"), QStringLiteral("dialog-restart")), KGuiItem(QApplication::translate("KStandardGuiItem", "&Restart"), QStringLiteral("dialog-restart")),
KGuiItem(QApplication::translate("KStandardGuiItem", "&Later"), QStringLiteral("dialog-later")) KGuiItem(QApplication::translate("KStandardGuiItem", "&Later"), QStringLiteral("dialog-later"))
); );
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
if (promptRestart == KMessageBox::ButtonCode::PrimaryAction) {
#else
if (promptRestart == KMessageBox::ButtonCode::Yes) { if (promptRestart == KMessageBox::ButtonCode::Yes) {
#endif
Dolphin::openNewWindow(); Dolphin::openNewWindow();
qApp->quit(); qApp->quit();
} else { } else {

View file

@ -25,6 +25,8 @@
#include <KWindowConfig> #include <KWindowConfig>
#include <KMessageBox> #include <KMessageBox>
#include <kwidgetsaddons_version.h>
#include <QCloseEvent> #include <QCloseEvent>
#include <QPushButton> #include <QPushButton>
@ -179,17 +181,29 @@ void DolphinSettingsDialog::closeEvent(QCloseEvent* event)
return; return;
} }
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
const auto response = KMessageBox::warningTwoActionsCancel(this,
#else
const auto response = KMessageBox::warningYesNoCancel(this, const auto response = KMessageBox::warningYesNoCancel(this,
#endif
i18n("You have unsaved changes. Do you want to apply the changes or discard them?"), i18n("You have unsaved changes. Do you want to apply the changes or discard them?"),
i18n("Warning"), i18n("Warning"),
KStandardGuiItem::save(), KStandardGuiItem::save(),
KStandardGuiItem::discard(), KStandardGuiItem::discard(),
KStandardGuiItem::cancel()); KStandardGuiItem::cancel());
switch (response) { switch (response) {
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
case KMessageBox::PrimaryAction:
#else
case KMessageBox::Yes: case KMessageBox::Yes:
#endif
applySettings(); applySettings();
Q_FALLTHROUGH(); Q_FALLTHROUGH();
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
case KMessageBox::SecondaryAction:
#else
case KMessageBox::No: case KMessageBox::No:
#endif
event->accept(); event->accept();
break; break;
case KMessageBox::Cancel: case KMessageBox::Cancel:

View file

@ -18,6 +18,8 @@
#include <KMessageBox> #include <KMessageBox>
#include <KWindowConfig> #include <KWindowConfig>
#include <kwidgetsaddons_version.h>
#if HAVE_BALOO #if HAVE_BALOO
#include <Baloo/IndexerConfig> #include <Baloo/IndexerConfig>
#endif #endif
@ -347,9 +349,15 @@ void ViewPropertiesDialog::applyViewProperties()
const bool applyToSubFolders = m_applyToSubFolders && m_applyToSubFolders->isChecked(); const bool applyToSubFolders = m_applyToSubFolders && m_applyToSubFolders->isChecked();
if (applyToSubFolders) { if (applyToSubFolders) {
const QString text(i18nc("@info", "The view properties of all sub-folders will be changed. Do you want to continue?")); const QString text(i18nc("@info", "The view properties of all sub-folders will be changed. Do you want to continue?"));
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
if (KMessageBox::questionTwoActions(this, text, {},
KStandardGuiItem::cont(),
KStandardGuiItem::cancel()) == KMessageBox::SecondaryAction) {
#else
if (KMessageBox::questionYesNo(this, text, {}, if (KMessageBox::questionYesNo(this, text, {},
KStandardGuiItem::cont(), KStandardGuiItem::cont(),
KStandardGuiItem::cancel()) == KMessageBox::No) { KStandardGuiItem::cancel()) == KMessageBox::No) {
#endif
return; return;
} }
@ -381,9 +389,15 @@ void ViewPropertiesDialog::applyViewProperties()
if (applyToAllFolders) { if (applyToAllFolders) {
const QString text(i18nc("@info", "The view properties of all folders will be changed. Do you want to continue?")); const QString text(i18nc("@info", "The view properties of all folders will be changed. Do you want to continue?"));
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
if (KMessageBox::questionTwoActions(this, text, {},
KStandardGuiItem::cont(),
KStandardGuiItem::cancel()) == KMessageBox::SecondaryAction) {
#else
if (KMessageBox::questionYesNo(this, text, {}, if (KMessageBox::questionYesNo(this, text, {},
KStandardGuiItem::cont(), KStandardGuiItem::cont(),
KStandardGuiItem::cancel()) == KMessageBox::No) { KStandardGuiItem::cancel()) == KMessageBox::No) {
#endif
return; return;
} }

View file

@ -47,6 +47,8 @@
#include <KProtocolManager> #include <KProtocolManager>
#include <KUrlMimeData> #include <KUrlMimeData>
#include <kwidgetsaddons_version.h>
#include <QAbstractItemView> #include <QAbstractItemView>
#include <QActionGroup> #include <QActionGroup>
#include <QApplication> #include <QApplication>
@ -1017,11 +1019,19 @@ void DolphinView::slotItemsActivated(const KItemSet &indexes)
if (indexes.count() > 5) { if (indexes.count() > 5) {
QString question = i18np("Are you sure you want to open 1 item?", "Are you sure you want to open %1 items?", indexes.count()); QString question = i18np("Are you sure you want to open 1 item?", "Are you sure you want to open %1 items?", indexes.count());
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
const int answer = KMessageBox::warningTwoActions(this, question, {},
#else
const int answer = KMessageBox::warningYesNo(this, question, {}, const int answer = KMessageBox::warningYesNo(this, question, {},
#endif
KGuiItem(i18ncp("@action:button", "Open %1 Item", "Open %1 Items", indexes.count()), KGuiItem(i18ncp("@action:button", "Open %1 Item", "Open %1 Items", indexes.count()),
QStringLiteral("document-open")), QStringLiteral("document-open")),
KStandardGuiItem::cancel()); KStandardGuiItem::cancel());
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
if (answer != KMessageBox::PrimaryAction) {
#else
if (answer != KMessageBox::Yes) { if (answer != KMessageBox::Yes) {
#endif
return; return;
} }
} }
@ -1879,7 +1889,11 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray& role, con
KGuiItem yesGuiItem(KStandardGuiItem::yes()); KGuiItem yesGuiItem(KStandardGuiItem::yes());
yesGuiItem.setText(i18nc("@action:button", "Rename and Hide")); yesGuiItem.setText(i18nc("@action:button", "Rename and Hide"));
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
const auto code = KMessageBox::questionTwoActions(this,
#else
const auto code = KMessageBox::questionYesNo(this, const auto code = KMessageBox::questionYesNo(this,
#endif
oldItem.isFile() ? i18n("Adding a dot to the beginning of this file's name will hide it from view.\n" oldItem.isFile() ? i18n("Adding a dot to the beginning of this file's name will hide it from view.\n"
"Do you still want to rename it?") "Do you still want to rename it?")
: i18n("Adding a dot to the beginning of this folder's name will hide it from view.\n" : i18n("Adding a dot to the beginning of this folder's name will hide it from view.\n"
@ -1890,7 +1904,11 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray& role, con
QStringLiteral("ConfirmHide") QStringLiteral("ConfirmHide")
); );
#if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
if (code == KMessageBox::SecondaryAction) {
#else
if (code == KMessageBox::No) { if (code == KMessageBox::No) {
#endif
return; return;
} }
} }