Commit a4e0292e authored by David Jarvie's avatar David Jarvie

Use standard functionality of KMessageBox

KMessageBox already provides the option for Cancel to be the default
button, so use it.
parent e756d85f
......@@ -700,18 +700,19 @@ bool KAlarmApp::quitIf(int exitCode, bool force)
void KAlarmApp::doQuit(QWidget* parent)
{
kDebug();
if (KAMessageBox::warningContinueCancel(parent, KMessageBox::Cancel,
if (KAMessageBox::warningCancelContinue(parent,
i18nc("@info", "Quitting will disable alarms (once any alarm message windows are closed)."),
QString(), KStandardGuiItem::quit(), Preferences::QUIT_WARN
) != KMessageBox::Yes)
QString(), KStandardGuiItem::quit(),
KStandardGuiItem::cancel(), Preferences::QUIT_WARN
) != KMessageBox::Continue)
return;
if (!KAlarm::checkRtcWakeConfig(true).isEmpty())
{
// A wake-on-suspend alarm is set
if (KAMessageBox::warningContinueCancel(parent, KMessageBox::Cancel,
if (KAMessageBox::warningCancelContinue(parent,
i18nc("@info", "Quitting will cancel the scheduled Wake from Suspend."),
QString(), KStandardGuiItem::quit()
) != KMessageBox::Yes)
) != KMessageBox::Continue)
return;
mCancelRtcWake = true;
}
......
/*
* messagebox.cpp - enhanced KMessageBox class
* Program: kalarm
* Copyright © 2004,2005,2007,2008,2011 by David Jarvie <djarvie@kde.org>
* Copyright © 2004,2005,2007,2008,2011,2014 by David Jarvie <djarvie@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -55,34 +55,6 @@ KMessageBox::ButtonCode KAMessageBox::getContinueDefault(const QString& dontAskA
return defaultButton;
}
/******************************************************************************
* Continue/cancel message box with the option as to which button is the default.
* If 'dontAskAgainName' is specified, the message box will only be suppressed
* if the user chose Continue last time.
*/
int KAMessageBox::warningContinueCancel(QWidget* parent, ButtonCode defaultButton, const QString& text,
const QString& caption, const KGuiItem& buttonContinue,
const QString& dontAskAgainName)
{
setContinueDefault(dontAskAgainName, defaultButton);
if (defaultButton != Cancel)
return KMessageBox::warningContinueCancel(parent, text, caption, buttonContinue, KStandardGuiItem::cancel(), dontAskAgainName);
// Cancel is the default button, so we have to use KMessageBox::warningYesNo()
if (!dontAskAgainName.isEmpty())
{
ButtonCode b;
if (!shouldBeShownYesNo(dontAskAgainName, b)
&& b != KMessageBox::Yes)
{
// Notification has been suppressed, but No (alias Cancel) is the default,
// so unsuppress notification.
saveDontShowAgain(dontAskAgainName, true, false);
}
}
return warningYesNo(parent, text, caption, buttonContinue, KStandardGuiItem::cancel(), dontAskAgainName);
}
/******************************************************************************
* If there is no current setting for whether a non-yes/no message box should be
* shown, set it to 'defaultShow'.
......
/*
* messagebox.h - enhanced KMessageBox class
* Program: kalarm
* Copyright © 2004,2007,2011 by David Jarvie <djarvie@kde.org>
* Copyright © 2004,2007,2011,2014 by David Jarvie <djarvie@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -59,19 +59,6 @@ class KAMessageBox : public KMessageBox
* @param defaultButton The default button for the message box. Valid values are Continue or Cancel.
*/
static void setContinueDefault(const QString& dontAskAgainName, ButtonCode defaultButton);
/** Displays a Continue/Cancel message box with the option as to which button is the default.
* @param parent Parent widget
* @param defaultButton The default button for the message box. Valid values are Continue or Cancel.
* @param text Message string
* @param caption Caption (window title) of the message box
* @param buttonContinue The text for the first button (default = "Continue")
* @param dontAskAgainName If specified, the message box will only be suppressed
* if the user chose Continue last time.
*/
static int warningContinueCancel(QWidget* parent, ButtonCode defaultButton, const QString& text,
const QString& caption = QString(),
const KGuiItem& buttonContinue = KStandardGuiItem::cont(),
const QString& dontAskAgainName = QString());
/** If there is no current setting for whether a non-Yes/No message box should be
* shown, sets it to @p defaultShow.
* If a Continue/Cancel message box has Cancel as the default button, either
......@@ -105,13 +92,15 @@ class KAMessageBox : public KMessageBox
/** Same as KMessageBox::detailedError() except that it defaults to window-modal,
* not application-modal. */
static void detailedError(QWidget* parent, const QString& text, const QString& details,
const QString& caption = QString(), Options options = Options(Notify|WindowModal))
const QString& caption = QString(),
Options options = Options(Notify|WindowModal))
{ KMessageBox::detailedError(parent, text, details, caption, options); }
/** Same as KMessageBox::detailedSorry() except that it defaults to window-modal,
* not application-modal. */
static void detailedSorry(QWidget* parent, const QString& text, const QString& details,
const QString& caption = QString(), Options options = Options(Notify|WindowModal))
const QString& caption = QString(),
Options options = Options(Notify|WindowModal))
{ KMessageBox::detailedSorry(parent, text, details, caption, options); }
/** Same as KMessageBox::error() except that it defaults to window-modal,
......@@ -123,7 +112,8 @@ class KAMessageBox : public KMessageBox
/** Same as KMessageBox::information() except that it defaults to window-modal,
* not application-modal. */
static void information(QWidget* parent, const QString& text, const QString& caption = QString(),
const QString& dontShowAgainName = QString(), Options options = Options(Notify|WindowModal))
const QString& dontShowAgainName = QString(),
Options options = Options(Notify|WindowModal))
{ KMessageBox::information(parent, text, caption, dontShowAgainName, options); }
/** Same as KMessageBox::sorry() except that it defaults to window-modal,
......@@ -137,7 +127,8 @@ class KAMessageBox : public KMessageBox
static int questionYesNo(QWidget* parent, const QString& text, const QString& caption = QString(),
const KGuiItem& buttonYes = KStandardGuiItem::yes(),
const KGuiItem& buttonNo = KStandardGuiItem::no(),
const QString& dontAskAgainName = QString(), Options options = Options(Notify|WindowModal))
const QString& dontAskAgainName = QString(),
Options options = Options(Notify|WindowModal))
{ return KMessageBox::questionYesNo(parent, text, caption, buttonYes, buttonNo, dontAskAgainName, options); }
/** Same as KMessageBox::questionYesNoCancel() except that it defaults
......@@ -146,15 +137,36 @@ class KAMessageBox : public KMessageBox
const KGuiItem& buttonYes = KStandardGuiItem::yes(),
const KGuiItem& buttonNo = KStandardGuiItem::no(),
const KGuiItem &buttonCancel = KStandardGuiItem::cancel(),
const QString& dontAskAgainName = QString(), Options options = Options(Notify|WindowModal))
const QString& dontAskAgainName = QString(),
Options options = Options(Notify|WindowModal))
{ return KMessageBox::questionYesNoCancel(parent, text, caption, buttonYes, buttonNo, buttonCancel, dontAskAgainName, options); }
/** Same as KMessageBox::warningContinueCancel() except that it defaults to window-modal,
* not application-modal. */
/** Same as KMessageBox::warningContinueCancel() except that the
* default button is Cancel, and it defaults to window-modal, not
* application-modal.
* @param parent Parent widget
* @param defaultButton The default button for the message box. Valid values are Continue or Cancel.
* @param text Message string
* @param caption Caption (window title) of the message box
* @param buttonContinue The text for the first button (default = "Continue")
* @param buttonCancel The text for the second button (default = "Cancel")
* @param dontAskAgainName If specified, the message box will only be suppressed
* if the user chose Continue last time.
*/
static int warningCancelContinue(QWidget* parent, const QString& text, const QString& caption = QString(),
const KGuiItem& buttonContinue = KStandardGuiItem::cont(),
const KGuiItem& buttonCancel = KStandardGuiItem::cancel(),
const QString& dontAskAgainName = QString(),
Options options = Options(Notify|WindowModal))
{ return KMessageBox::warningContinueCancel(parent, text, caption, buttonContinue, buttonCancel, dontAskAgainName, Options(options|Dangerous)); }
/** Same as KMessageBox::warningContinueCancel() except that it
* defaults to window-modal, not application-modal. */
static int warningContinueCancel(QWidget* parent, const QString& text, const QString& caption = QString(),
const KGuiItem& buttonContinue = KStandardGuiItem::cont(),
const KGuiItem& buttonCancel = KStandardGuiItem::cancel(),
const QString& dontAskAgainName = QString(), Options options = Options(Notify|WindowModal))
const QString& dontAskAgainName = QString(),
Options options = Options(Notify|WindowModal))
{ return KMessageBox::warningContinueCancel(parent, text, caption, buttonContinue, buttonCancel, dontAskAgainName, options); }
/** Same as KMessageBox::warningYesNo() except that it defaults to window-modal,
......@@ -162,7 +174,8 @@ class KAMessageBox : public KMessageBox
static int warningYesNo(QWidget* parent, const QString& text, const QString& caption = QString(),
const KGuiItem& buttonYes = KStandardGuiItem::yes(),
const KGuiItem& buttonNo = KStandardGuiItem::no(),
const QString& dontAskAgainName = QString(), Options options = Options(Notify|Dangerous|WindowModal))
const QString& dontAskAgainName = QString(),
Options options = Options(Notify|Dangerous|WindowModal))
{ return KMessageBox::warningYesNo(parent, text, caption, buttonYes, buttonNo, dontAskAgainName, options); }
/** Shortcut to represent Options(Notify | WindowModal). */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment