diff --git a/src/kmessagebox.h b/src/kmessagebox.h --- a/src/kmessagebox.h +++ b/src/kmessagebox.h @@ -572,13 +572,41 @@ * The default button is "&OK". Pressing "Esc" selects the OK-button. * * NOTE: The ok button will always have the i18n'ed text '&OK'. + * See the overload with a KGuiItem argument to change that. */ - KWIDGETSADDONS_EXPORT void sorry(QWidget *parent, const QString &text, const QString &caption = QString(), Options options = Notify); +/** + * Display a "Sorry" dialog. + * + * @param parent Parent widget. + * @param text Message string. + * @param caption Message box title. The application name is added to + * the title. The default title is i18n("Sorry"). + * @param buttonOk The text for the only button. + * The default is KStandardGuiItem::ok(). + * @param options see OptionsType + * + * Either your program messed up and asks for understanding + * or your user did something stupid. + * + * To be used for small problems like + * "Sorry, I can't find the file you specified." + * + * The default button is "&OK". Pressing "Esc" selects the OK-button. + * + * There is only one button, therefore it's the default button, and pressing "Esc" selects it as well. + * @since 5.63 + */ +KWIDGETSADDONS_EXPORT void sorry(QWidget *parent, + const QString &text, + const QString &caption /*= QString()*/, + const KGuiItem &buttonOk /*= KStandardGuiItem::ok()*/, + Options options = Notify); // TODO KF6 merge with previous overload + /** * Displays a "Sorry" dialog with a "Details >>" button. * @@ -603,14 +631,49 @@ * The default button is "&OK". Pressing "Esc" selects the OK-button. * * NOTE: The ok button will always have the i18n'ed text '&OK'. + * See the overload with a KGuiItem argument to change that. */ KWIDGETSADDONS_EXPORT void detailedSorry(QWidget *parent, const QString &text, const QString &details, const QString &caption = QString(), Options options = Notify); +/** + * Displays a "Sorry" dialog with a "Details >>" button. + * + * @param parent Parent widget. + * @param text Message string. + * @param details Detailed message string. + * @param caption Message box title. The application name is added to + * the title. The default title is i18n("Sorry"). + * @param buttonOk The text for the only button. + * The default is KStandardGuiItem::ok(). + * @param options see Options + * + * Either your program messed up and asks for understanding + * or your user did something stupid. + * + * To be used for small problems like + * "Sorry, I can't find the file you specified." + * + * And then @p details can contain something like + * "foobar.txt was not found in any of + * the following directories: + * /usr/bin,/usr/local/bin,/usr/sbin" + * + * There is only one button, therefore it's the default button, and pressing "Esc" selects it as well. + * @since 5.63 + */ + +KWIDGETSADDONS_EXPORT void detailedSorry(QWidget *parent, + const QString &text, + const QString &details, + const QString &caption /* = QString() */, + const KGuiItem &buttonOk /*= KStandardGuiItem::ok()*/, + Options options = Notify); // TODO KF6: merge with previous overload + /** * Display an "Information" dialog. * @@ -893,7 +956,7 @@ */ KWIDGETSADDONS_EXPORT ButtonCode questionYesNoCancelWId(WId parent_id, const QString &text, - const QString &caption = QString(), + const QString &caption = QString(), const KGuiItem &buttonYes = KStandardGuiItem::yes(), const KGuiItem &buttonNo = KStandardGuiItem::no(), const KGuiItem &buttonCancel = KStandardGuiItem::cancel(), @@ -1028,6 +1091,17 @@ const QString &caption = QString(), Options options = Notify); +/** + * This function accepts the window id of the parent window, instead + * of QWidget*. It should be used only when necessary. + * @since 5.63 + */ +KWIDGETSADDONS_EXPORT void sorryWId(WId parent_id, + const QString &text, + const QString &caption /*= QString()*/, + const KGuiItem &buttonOk /*= KStandardGuiItem::ok()*/, + Options options = Notify); // TODO KF6 merge with previous overload + /** * This function accepts the window id of the parent window, instead * of QWidget*. It should be used only when necessary. @@ -1038,6 +1112,18 @@ const QString &caption = QString(), Options options = Notify); +/** + * This function accepts the window id of the parent window, instead + * of QWidget*. It should be used only when necessary. + * @since 5.63 + */ +KWIDGETSADDONS_EXPORT void detailedSorryWId(WId parent_id, + const QString &text, + const QString &details, + const QString &caption /*= QString()*/, + const KGuiItem &buttonOk /*= KStandardGuiItem::ok()*/, + Options options = Notify); // TODO KF6 merge with previous overload + /** * This function accepts the window id of the parent window, instead * of QWidget*. It should be used only when necessary. diff --git a/src/kmessagebox.cpp b/src/kmessagebox.cpp --- a/src/kmessagebox.cpp +++ b/src/kmessagebox.cpp @@ -836,13 +836,19 @@ } static void sorryInternal(QDialog *dialog, const QString &text, - const QString &caption, Options options) + const QString &caption, + const KGuiItem &buttonOk_, + Options options) { + I18N_FILTER_BUTTON_YES(buttonOk_, buttonOk) + I18N_POST_BUTTON_FILTER + dialog->setWindowTitle(caption.isEmpty() ? QApplication::translate("KMessageBox", "Sorry") : caption); dialog->setObjectName(QStringLiteral("sorry")); QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); buttonBox->setStandardButtons(QDialogButtonBox::Ok); + KGuiItem::assign(buttonBox->button(QDialogButtonBox::Ok), buttonOk); applyOptions(dialog, options); @@ -852,19 +858,31 @@ void sorry(QWidget *parent, const QString &text, const QString &caption, Options options) { - sorryInternal(new QDialog(parent), text, caption, options); + sorryInternal(new QDialog(parent), text, caption, KStandardGuiItem::ok(), options); +} + +void sorry(QWidget *parent, const QString &text, + const QString &caption, const KGuiItem &item, Options options) +{ + sorryInternal(new QDialog(parent), text, caption, item, options); } static void detailedSorryInternal(QDialog *dialog, const QString &text, const QString &details, - const QString &caption, Options options) + const QString &caption, + const KGuiItem &buttonOk_, + Options options) { + I18N_FILTER_BUTTON_YES(buttonOk_, buttonOk) + I18N_POST_BUTTON_FILTER + dialog->setWindowTitle(caption.isEmpty() ? QApplication::translate("KMessageBox", "Sorry") : caption); dialog->setObjectName(QStringLiteral("sorry")); QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); buttonBox->addButton(QDialogButtonBox::Ok); buttonBox->button(QDialogButtonBox::Ok)->setFocus(); + KGuiItem::assign(buttonBox->button(QDialogButtonBox::Ok), buttonOk); applyOptions(dialog, options); @@ -875,7 +893,16 @@ const QString &details, const QString &caption, Options options) { - detailedSorryInternal(new QDialog(parent), text, details, caption, options); + detailedSorryInternal(new QDialog(parent), text, details, caption, KStandardGuiItem::ok(), options); +} + +void detailedSorry(QWidget *parent, const QString &text, + const QString &details, + const QString &caption, + const KGuiItem &buttonOk, + Options options) +{ + detailedSorryInternal(new QDialog(parent), text, details, caption, buttonOk, options); } void information(QWidget *parent, const QString &text, @@ -969,7 +996,7 @@ return KMessageBox::Ok; case Sorry: - sorryInternal(dialog, text, caption, options); + sorryInternal(dialog, text, caption, KStandardGuiItem::ok(), options); return KMessageBox::Ok; } return KMessageBox::Cancel; @@ -1134,7 +1161,16 @@ const QString &details, const QString &caption, Options options) { - detailedSorryInternal(createWIdDialog(parent_id), text, details, caption, options); + detailedSorryInternal(createWIdDialog(parent_id), text, details, caption, KStandardGuiItem::ok(), options); +} + +void detailedSorryWId(WId parent_id, const QString &text, + const QString &details, + const QString &caption, + const KGuiItem &buttonOk, + Options options) +{ + detailedSorryInternal(createWIdDialog(parent_id), text, details, caption, buttonOk, options); } void informationWId(WId parent_id, const QString &text, diff --git a/tests/kmessageboxtest.cpp b/tests/kmessageboxtest.cpp --- a/tests/kmessageboxtest.cpp +++ b/tests/kmessageboxtest.cpp @@ -149,12 +149,12 @@ case 13: i = KMessageBox::Ok; - KMessageBox::sorry(nullptr, QStringLiteral("Sorry, Your harddisk appears to be empty.")); + KMessageBox::sorry(nullptr, QStringLiteral("Sorry, Your harddisk appears to be empty."), QString(), KGuiItem(QStringLiteral("Abort"))); break; case 14: i = KMessageBox::Ok; - KMessageBox::detailedSorry(nullptr, QStringLiteral("Sorry, Your harddisk appears to be empty."), QStringLiteral("We don't know more yet."), QStringLiteral("Oops")); + KMessageBox::detailedSorry(nullptr, QStringLiteral("Sorry, Your harddisk appears to be empty."), QStringLiteral("We don't know more yet."), QStringLiteral("Oops"), KGuiItem(QStringLiteral("Abort"))); break; case 15: