2014-11-13 01:04:59 +02:00
|
|
|
/* This file is part of the KDE libraries
|
|
|
|
Copyright (C) 1999 Waldo Bastian (bastian@kde.org)
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; version 2
|
|
|
|
of the License.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public License
|
|
|
|
along with this library; see the file COPYING.LIB. If not, write to
|
|
|
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "kmessagebox.h"
|
2023-08-09 03:58:14 +03:00
|
|
|
#include "kapplication.h"
|
|
|
|
#include "kconfig.h"
|
|
|
|
#include "kdialog.h"
|
|
|
|
#include "kdialogqueue_p.h"
|
|
|
|
#include "klocale.h"
|
|
|
|
#include "knotification.h"
|
|
|
|
#include "kiconloader.h"
|
|
|
|
#include "kconfiggroup.h"
|
|
|
|
#include "kwindowsystem.h"
|
2023-08-29 08:18:25 +03:00
|
|
|
#include "kpixmapwidget.h"
|
2024-04-30 08:24:48 +03:00
|
|
|
#include "kdebug.h"
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
#include <QtCore/QPointer>
|
2023-08-12 02:02:58 +03:00
|
|
|
#include <QtCore/QDebug>
|
2014-11-13 01:04:59 +02:00
|
|
|
#include <QtGui/QCheckBox>
|
|
|
|
#include <QtGui/QGroupBox>
|
|
|
|
#include <QtGui/QLabel>
|
|
|
|
#include <QtGui/QLayout>
|
|
|
|
#include <QtGui/QListWidget>
|
|
|
|
#include <QtGui/QScrollArea>
|
|
|
|
#include <QtGui/QScrollBar>
|
2024-04-30 03:34:27 +03:00
|
|
|
#include <QtGui/QTextBrowser>
|
2023-08-09 03:58:14 +03:00
|
|
|
#include <QtGui/QDesktopWidget>
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
// Some i18n filters, that standard button texts are piped through
|
|
|
|
// (the new KGuiItem object with filtered text is created from the old one).
|
|
|
|
|
|
|
|
// i18n: Filter for the Yes-button text in standard message dialogs,
|
|
|
|
// after the message caption/text have been translated.
|
|
|
|
#define I18N_FILTER_BUTTON_YES(src, dst) \
|
|
|
|
KGuiItem dst(src); \
|
|
|
|
dst.setText( i18nc( "@action:button filter-yes", "%1", src.text() ) );
|
|
|
|
|
|
|
|
// i18n: Filter for the No-button text in standard message dialogs,
|
|
|
|
// after the message caption/text have been translated.
|
|
|
|
#define I18N_FILTER_BUTTON_NO(src, dst) \
|
|
|
|
KGuiItem dst(src); \
|
|
|
|
dst.setText( i18nc( "@action:button filter-no", "%1", src.text() ) );
|
|
|
|
|
|
|
|
// i18n: Filter for the Continue-button text in standard message dialogs,
|
|
|
|
// after the message caption/text have been translated.
|
|
|
|
#define I18N_FILTER_BUTTON_CONTINUE(src, dst) \
|
|
|
|
KGuiItem dst(src); \
|
|
|
|
dst.setText( i18nc( "@action:button filter-continue", "%1", src.text() ) );
|
|
|
|
|
|
|
|
// i18n: Filter for the Cancel-button text in standard message dialogs,
|
|
|
|
// after the message caption/text have been translated.
|
|
|
|
#define I18N_FILTER_BUTTON_CANCEL(src, dst) \
|
|
|
|
KGuiItem dst(src); \
|
|
|
|
dst.setText( i18nc( "@action:button filter-cancel", "%1", src.text() ) );
|
|
|
|
|
|
|
|
// i18n: Called after the button texts in standard message dialogs
|
|
|
|
// have been filtered by the messages above. Not visible to user.
|
|
|
|
#define I18N_POST_BUTTON_FILTER \
|
|
|
|
i18nc( "@action:button post-filter", "." );
|
|
|
|
|
|
|
|
static bool KMessageBox_queue = false;
|
|
|
|
KConfig* KMessageBox_againConfig = 0;
|
|
|
|
|
|
|
|
|
|
|
|
static QIcon themedMessageBoxIcon(QMessageBox::Icon icon)
|
|
|
|
{
|
|
|
|
QString icon_name;
|
|
|
|
switch (icon) {
|
2024-04-20 20:40:07 +03:00
|
|
|
case QMessageBox::NoIcon: {
|
|
|
|
return QIcon();
|
|
|
|
}
|
|
|
|
case QMessageBox::Information: {
|
|
|
|
icon_name = "dialog-information";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QMessageBox::Warning: {
|
|
|
|
icon_name = "dialog-warning";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QMessageBox::Critical: {
|
|
|
|
icon_name = "dialog-error";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
break;
|
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
2024-04-20 20:40:07 +03:00
|
|
|
QIcon ret = KIconLoader::global()->loadIcon(
|
|
|
|
icon_name, KIconLoader::NoGroup, KIconLoader::SizeHuge, KIconLoader::DefaultState, QStringList(), 0, true
|
|
|
|
);
|
|
|
|
if (ret.isNull()) {
|
|
|
|
return QMessageBox::standardIcon(icon);
|
|
|
|
}
|
|
|
|
return ret;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2024-04-20 20:40:07 +03:00
|
|
|
// create the message for KNotify
|
|
|
|
static void sendNotification(QString message, const QStringList &strlist, QMessageBox::Icon icon,
|
|
|
|
WId parent_id)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2024-04-20 20:40:07 +03:00
|
|
|
if (!strlist.isEmpty() ) {
|
|
|
|
foreach (const QString &it, strlist) {
|
|
|
|
message += '\n' + it;
|
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2024-04-20 20:40:07 +03:00
|
|
|
if (!message.isEmpty()) {
|
|
|
|
QString messageType;
|
|
|
|
switch (icon) {
|
|
|
|
case QMessageBox::Warning: {
|
|
|
|
messageType = QLatin1String("kde/messageWarning");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QMessageBox::Critical: {
|
|
|
|
messageType = QLatin1String("kde/messageCritical");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case QMessageBox::Question: {
|
|
|
|
messageType = QLatin1String("kde/messageQuestion");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
messageType = QLatin1String("kde/messageInformation");
|
|
|
|
break;
|
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2023-08-24 19:53:51 +03:00
|
|
|
KNotification::event(
|
2024-04-20 20:40:07 +03:00
|
|
|
messageType, QString(), message, QString(), QWidget::find(parent_id)
|
2023-08-24 19:53:51 +03:00
|
|
|
);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-20 20:40:07 +03:00
|
|
|
static void applyOptions(KDialog* dialog, KMessageBox::Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2024-04-20 20:40:07 +03:00
|
|
|
if (options & KMessageBox::WindowModal) {
|
|
|
|
dialog->setWindowModality(Qt::WindowModal);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
2024-04-20 20:40:07 +03:00
|
|
|
dialog->setModal(true);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2024-04-20 20:40:07 +03:00
|
|
|
int KMessageBox::createKMessageBox(KDialog *dialog, QMessageBox::Icon icon, const QString &text,
|
|
|
|
const QStringList &strlist, const QString &ask,
|
|
|
|
bool *checkboxReturn, Options options, const QString &details)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2024-04-20 20:40:07 +03:00
|
|
|
return createKMessageBox(
|
|
|
|
dialog, themedMessageBoxIcon(icon), text, strlist,
|
|
|
|
ask, checkboxReturn, options, details, icon
|
|
|
|
);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-20 20:40:07 +03:00
|
|
|
int KMessageBox::createKMessageBox(KDialog *dialog, const QIcon &icon, const QString &text,
|
|
|
|
const QStringList &strlist, const QString &ask,
|
|
|
|
bool *checkboxReturn, Options options, const QString &details,
|
|
|
|
QMessageBox::Icon notifyType)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
QWidget *mainWidget = new QWidget(dialog);
|
|
|
|
QVBoxLayout *mainLayout = new QVBoxLayout(mainWidget);
|
|
|
|
mainLayout->setMargin(0);
|
|
|
|
|
|
|
|
QHBoxLayout *hLayout = new QHBoxLayout();
|
|
|
|
hLayout->setMargin(0);
|
2024-04-30 23:33:24 +03:00
|
|
|
mainLayout->addLayout(hLayout);
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2023-08-29 08:18:25 +03:00
|
|
|
KPixmapWidget *iconWidget = new KPixmapWidget(mainWidget);
|
2014-11-13 01:04:59 +02:00
|
|
|
if (!icon.isNull()) {
|
|
|
|
QStyleOption option;
|
|
|
|
option.initFrom(mainWidget);
|
2024-04-30 08:24:48 +03:00
|
|
|
const int iconSize = mainWidget->style()->pixelMetric(QStyle::PM_MessageBoxIconSize, &option, mainWidget);
|
|
|
|
iconWidget->setPixmap(icon.pixmap(iconSize));
|
|
|
|
iconWidget->setMinimumSize(QSize(iconSize, iconSize));
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
2024-04-30 08:24:48 +03:00
|
|
|
hLayout->addWidget(iconWidget, 0, Qt::AlignTop | Qt::AlignVCenter);
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
QLabel *messageLabel = new QLabel(text, mainWidget);
|
|
|
|
messageLabel->setOpenExternalLinks(options & KMessageBox::AllowLink);
|
|
|
|
Qt::TextInteractionFlags flags = Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard;
|
|
|
|
if (options & KMessageBox::AllowLink) {
|
|
|
|
flags |= Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard;
|
|
|
|
}
|
|
|
|
messageLabel->setTextInteractionFlags(flags);
|
2024-04-30 08:24:48 +03:00
|
|
|
messageLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2024-04-30 23:33:24 +03:00
|
|
|
hLayout->addWidget(messageLabel, 0, Qt::AlignLeft | Qt::AlignVCenter);
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2024-04-30 08:24:48 +03:00
|
|
|
const QRect desktop = QApplication::desktop()->screenGeometry(dialog);
|
2024-04-20 21:37:05 +03:00
|
|
|
const bool usingListWidget = !strlist.isEmpty();
|
2014-11-13 01:04:59 +02:00
|
|
|
if (usingListWidget) {
|
|
|
|
QListWidget *listWidget = new QListWidget(mainWidget);
|
|
|
|
listWidget->addItems(strlist);
|
|
|
|
|
|
|
|
QStyleOptionViewItem styleOption;
|
|
|
|
styleOption.initFrom(listWidget);
|
|
|
|
QFontMetrics fm(styleOption.font);
|
|
|
|
int w = listWidget->width();
|
2024-04-30 21:31:32 +03:00
|
|
|
foreach (const QString &str, strlist) {
|
2014-11-13 01:04:59 +02:00
|
|
|
w = qMax(w, fm.width(str));
|
|
|
|
}
|
|
|
|
const int borderWidth = listWidget->width() - listWidget->viewport()->width() + listWidget->verticalScrollBar()->height();
|
|
|
|
w += borderWidth;
|
|
|
|
if (w > desktop.width() * 0.85) { // limit listWidget size to 85% of screen width
|
|
|
|
w = qRound(desktop.width() * 0.85);
|
|
|
|
}
|
|
|
|
listWidget->setMinimumWidth(w);
|
|
|
|
|
2024-04-30 23:33:24 +03:00
|
|
|
mainLayout->addWidget(listWidget);
|
2014-11-13 01:04:59 +02:00
|
|
|
listWidget->setSelectionMode(QListWidget::NoSelection);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QPointer<QCheckBox> checkbox = 0;
|
|
|
|
if (!ask.isEmpty()) {
|
|
|
|
checkbox = new QCheckBox(ask, mainWidget);
|
|
|
|
mainLayout->addWidget(checkbox);
|
|
|
|
if (checkboxReturn) {
|
|
|
|
checkbox->setChecked(*checkboxReturn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-30 08:24:48 +03:00
|
|
|
QGroupBox *detailsGroup = nullptr;
|
2014-11-13 01:04:59 +02:00
|
|
|
if (!details.isEmpty()) {
|
2024-04-30 08:24:48 +03:00
|
|
|
detailsGroup = new QGroupBox(i18n("Details"));
|
2014-11-13 01:04:59 +02:00
|
|
|
QVBoxLayout *detailsLayout = new QVBoxLayout(detailsGroup);
|
2024-04-30 07:49:07 +03:00
|
|
|
QTextBrowser *detailTextBrowser = new QTextBrowser(detailsGroup);
|
|
|
|
detailTextBrowser->setHtml(details);
|
|
|
|
detailTextBrowser->setReadOnly(true);
|
|
|
|
detailTextBrowser->setMinimumHeight(detailTextBrowser->fontMetrics().lineSpacing() * 11);
|
|
|
|
detailTextBrowser->setOpenExternalLinks(options & KMessageBox::AllowLink);
|
|
|
|
Qt::TextInteractionFlags flags = Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard;
|
2024-04-30 21:31:32 +03:00
|
|
|
if (options & KMessageBox::AllowLink) {
|
2024-04-30 07:49:07 +03:00
|
|
|
flags |= Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard;
|
2024-04-30 21:31:32 +03:00
|
|
|
}
|
2024-04-30 07:49:07 +03:00
|
|
|
detailTextBrowser->setTextInteractionFlags(flags);
|
2024-04-30 23:33:24 +03:00
|
|
|
detailsLayout->addWidget(detailTextBrowser);
|
2014-11-13 01:04:59 +02:00
|
|
|
dialog->setDetailsWidget(detailsGroup);
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog->setMainWidget(mainWidget);
|
2024-04-30 23:33:24 +03:00
|
|
|
// force KDialog to re-layout
|
2024-04-30 08:24:48 +03:00
|
|
|
dialog->adjustSize();
|
2024-04-30 22:44:17 +03:00
|
|
|
QLayout* dialogLayout = dialog->layout();
|
|
|
|
dialogLayout->setSizeConstraint(QLayout::SetFixedSize);
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
if ((options & KMessageBox::Dangerous)) {
|
2024-04-30 08:24:48 +03:00
|
|
|
if (dialog->isButtonEnabled(KDialog::Cancel)) {
|
2014-11-13 01:04:59 +02:00
|
|
|
dialog->setDefaultButton(KDialog::Cancel);
|
2024-04-30 08:24:48 +03:00
|
|
|
} else if (dialog->isButtonEnabled(KDialog::No)) {
|
2014-11-13 01:04:59 +02:00
|
|
|
dialog->setDefaultButton(KDialog::No);
|
2024-04-30 08:24:48 +03:00
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
KDialog::ButtonCode defaultCode = dialog->defaultButton();
|
|
|
|
if (defaultCode != KDialog::NoDefault) {
|
|
|
|
dialog->setButtonFocus(defaultCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((options & KMessageBox::Notify)) {
|
2019-12-17 01:08:55 +00:00
|
|
|
sendNotification(text, strlist, notifyType, dialog->window()->winId());
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (KMessageBox_queue) {
|
|
|
|
KDialogQueue::queueDialog(dialog);
|
|
|
|
return KMessageBox::Cancel; // We have to return something.
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((options & KMessageBox::NoExec)) {
|
|
|
|
return KMessageBox::Cancel; // We have to return something.
|
|
|
|
}
|
|
|
|
|
2023-08-12 02:02:58 +03:00
|
|
|
// raise the dialog in case the parent is minimized (hidden), e.g. status
|
|
|
|
// status notifier item (kget)
|
2024-04-30 22:35:38 +03:00
|
|
|
dialog->show();
|
|
|
|
KWindowSystem::raiseWindow(dialog->winId());
|
|
|
|
KWindowSystem::forceActiveWindow(dialog->winId());
|
2023-08-12 02:02:58 +03:00
|
|
|
|
2024-04-30 22:35:38 +03:00
|
|
|
const int result = dialog->exec();
|
2014-11-13 01:04:59 +02:00
|
|
|
if (checkbox && checkboxReturn) {
|
|
|
|
*checkboxReturn = checkbox->isChecked();
|
|
|
|
}
|
2024-05-02 08:57:44 +03:00
|
|
|
dialog->deleteLater();
|
2014-11-13 01:04:59 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-04-30 22:35:38 +03:00
|
|
|
int KMessageBox::questionYesNo(QWidget *parent, const QString &text, const QString &caption,
|
|
|
|
const KGuiItem &buttonYes, const KGuiItem &buttonNo,
|
|
|
|
const QString &dontAskAgainName, Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2024-04-20 21:37:05 +03:00
|
|
|
return questionYesNoList(
|
|
|
|
parent, text, QStringList(), caption,
|
|
|
|
buttonYes, buttonNo, dontAskAgainName, options
|
|
|
|
);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int KMessageBox::questionYesNoWId(WId parent_id, const QString &text,
|
2024-05-02 08:57:44 +03:00
|
|
|
const QString &caption,
|
|
|
|
const KGuiItem &buttonYes,
|
|
|
|
const KGuiItem &buttonNo,
|
|
|
|
const QString &dontAskAgainName,
|
|
|
|
Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2024-05-02 08:57:44 +03:00
|
|
|
return questionYesNoListWId(
|
|
|
|
parent_id, text, QStringList(), caption,
|
|
|
|
buttonYes, buttonNo, dontAskAgainName, options
|
|
|
|
);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool KMessageBox::shouldBeShownYesNo(const QString &dontShowAgainName,
|
2024-05-02 08:57:44 +03:00
|
|
|
ButtonCode &result)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
if ( dontShowAgainName.isEmpty() ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
KConfigGroup cg( KMessageBox_againConfig ? KMessageBox_againConfig : KGlobal::config().data(), "Notification Messages" );
|
|
|
|
const QString dontAsk = cg.readEntry(dontShowAgainName, QString()).toLower();
|
|
|
|
if (dontAsk == "yes" || dontAsk == "true") {
|
|
|
|
result = Yes;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (dontAsk == "no" || dontAsk == "false") {
|
|
|
|
result = No;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool KMessageBox::shouldBeShownContinue(const QString &dontShowAgainName)
|
|
|
|
{
|
2024-05-02 08:57:44 +03:00
|
|
|
if (dontShowAgainName.isEmpty()) {
|
2014-11-13 01:04:59 +02:00
|
|
|
return true;
|
|
|
|
}
|
2024-05-02 08:57:44 +03:00
|
|
|
KConfigGroup cg(KMessageBox_againConfig ? KMessageBox_againConfig : KGlobal::config().data(), "Notification Messages");
|
2014-11-13 01:04:59 +02:00
|
|
|
return cg.readEntry(dontShowAgainName, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KMessageBox::saveDontShowAgainYesNo(const QString &dontShowAgainName,
|
2024-05-02 08:57:44 +03:00
|
|
|
ButtonCode result)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2024-05-02 08:57:44 +03:00
|
|
|
if (dontShowAgainName.isEmpty()) {
|
2014-11-13 01:04:59 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
KConfigGroup::WriteConfigFlags flags = KConfig::Persistent;
|
|
|
|
if (dontShowAgainName[0] == ':') {
|
|
|
|
flags |= KConfigGroup::Global;
|
|
|
|
}
|
2024-05-02 08:57:44 +03:00
|
|
|
KConfigGroup cg(KMessageBox_againConfig? KMessageBox_againConfig : KGlobal::config().data(), "Notification Messages");
|
|
|
|
cg.writeEntry(dontShowAgainName, result == Yes, flags);
|
2014-11-13 01:04:59 +02:00
|
|
|
cg.sync();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KMessageBox::saveDontShowAgainContinue(const QString &dontShowAgainName)
|
|
|
|
{
|
2024-05-02 08:57:44 +03:00
|
|
|
if (dontShowAgainName.isEmpty() ) {
|
2014-11-13 01:04:59 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
KConfigGroup::WriteConfigFlags flags = KConfigGroup::Persistent;
|
|
|
|
if (dontShowAgainName[0] == ':') {
|
|
|
|
flags |= KConfigGroup::Global;
|
|
|
|
}
|
2024-05-02 08:57:44 +03:00
|
|
|
KConfigGroup cg(KMessageBox_againConfig? KMessageBox_againConfig: KGlobal::config().data(), "Notification Messages");
|
|
|
|
cg.writeEntry(dontShowAgainName, false, flags);
|
2014-11-13 01:04:59 +02:00
|
|
|
cg.sync();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KMessageBox::setDontShowAskAgainConfig(KConfig* cfg)
|
|
|
|
{
|
|
|
|
KMessageBox_againConfig = cfg;
|
|
|
|
}
|
|
|
|
|
|
|
|
int KMessageBox::questionYesNoList(QWidget *parent, const QString &text,
|
2024-05-02 08:57:44 +03:00
|
|
|
const QStringList &strlist,
|
|
|
|
const QString &caption,
|
|
|
|
const KGuiItem &buttonYes,
|
|
|
|
const KGuiItem &buttonNo,
|
|
|
|
const QString &dontAskAgainName,
|
|
|
|
Options options)
|
|
|
|
{
|
|
|
|
// in order to avoid code duplication, convert to WId, it will be converted back
|
|
|
|
return questionYesNoListWId(
|
|
|
|
parent ? parent->effectiveWinId() : 0, text, strlist,
|
|
|
|
caption, buttonYes, buttonNo, dontAskAgainName, options
|
|
|
|
);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int KMessageBox::questionYesNoListWId(WId parent_id, const QString &text,
|
2024-05-02 08:57:44 +03:00
|
|
|
const QStringList &strlist,
|
|
|
|
const QString &caption,
|
|
|
|
const KGuiItem &buttonYes_,
|
|
|
|
const KGuiItem &buttonNo_,
|
|
|
|
const QString &dontAskAgainName,
|
|
|
|
Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
ButtonCode res;
|
2024-05-02 08:57:44 +03:00
|
|
|
if (!shouldBeShownYesNo(dontAskAgainName, res)) {
|
2014-11-13 01:04:59 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
I18N_FILTER_BUTTON_YES(buttonYes_, buttonYes)
|
|
|
|
I18N_FILTER_BUTTON_NO(buttonNo_, buttonNo)
|
|
|
|
I18N_POST_BUTTON_FILTER
|
|
|
|
|
|
|
|
QWidget* parent = QWidget::find( parent_id );
|
|
|
|
KDialog *dialog = new KDialog(parent, Qt::Dialog);
|
2024-04-30 21:45:09 +03:00
|
|
|
dialog->setCaption(caption.isEmpty() ? i18n("Question") : caption);
|
|
|
|
dialog->setButtons(KDialog::Yes | KDialog::No);
|
|
|
|
dialog->setObjectName("questionYesNo");
|
|
|
|
dialog->setButtonGuiItem(KDialog::Yes, buttonYes);
|
|
|
|
dialog->setButtonGuiItem(KDialog::No, buttonNo);
|
|
|
|
dialog->setDefaultButton(KDialog::Yes);
|
|
|
|
dialog->setEscapeButton(KDialog::No);
|
|
|
|
applyOptions(dialog, options);
|
|
|
|
if (options & KMessageBox::PlainCaption) {
|
|
|
|
dialog->setWindowTitle(caption);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
2024-04-30 21:45:09 +03:00
|
|
|
if (parent == NULL && parent_id) {
|
|
|
|
KWindowSystem::setMainWindow(dialog, parent_id);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool checkboxResult = false;
|
2024-04-30 21:45:09 +03:00
|
|
|
const int result = createKMessageBox(
|
|
|
|
dialog, QMessageBox::Information, text, strlist,
|
|
|
|
dontAskAgainName.isEmpty() ? QString() : i18n("Do not ask again"),
|
|
|
|
&checkboxResult, options
|
|
|
|
);
|
2014-11-13 01:04:59 +02:00
|
|
|
res = (result==KDialog::Yes ? Yes : No);
|
|
|
|
|
|
|
|
if (checkboxResult) {
|
|
|
|
saveDontShowAgainYesNo(dontAskAgainName, res);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int KMessageBox::questionYesNoCancel(QWidget *parent,
|
2024-05-02 08:57:44 +03:00
|
|
|
const QString &text,
|
|
|
|
const QString &caption,
|
|
|
|
const KGuiItem &buttonYes,
|
|
|
|
const KGuiItem &buttonNo,
|
|
|
|
const KGuiItem &buttonCancel,
|
|
|
|
const QString &dontAskAgainName,
|
|
|
|
Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2024-05-02 08:57:44 +03:00
|
|
|
return questionYesNoCancelWId(
|
|
|
|
parent ? parent->effectiveWinId() : 0, text, caption, buttonYes, buttonNo, buttonCancel,
|
|
|
|
dontAskAgainName, options
|
|
|
|
);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int KMessageBox::questionYesNoCancelWId(WId parent_id,
|
2024-05-02 08:57:44 +03:00
|
|
|
const QString &text,
|
|
|
|
const QString &caption,
|
|
|
|
const KGuiItem &buttonYes_,
|
|
|
|
const KGuiItem &buttonNo_,
|
|
|
|
const KGuiItem &buttonCancel_,
|
|
|
|
const QString &dontAskAgainName,
|
|
|
|
Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
ButtonCode res;
|
2024-05-02 08:57:44 +03:00
|
|
|
if (!shouldBeShownYesNo(dontAskAgainName, res)) {
|
2014-11-13 01:04:59 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
I18N_FILTER_BUTTON_YES(buttonYes_, buttonYes)
|
|
|
|
I18N_FILTER_BUTTON_NO(buttonNo_, buttonNo)
|
|
|
|
I18N_FILTER_BUTTON_CANCEL(buttonCancel_, buttonCancel)
|
|
|
|
I18N_POST_BUTTON_FILTER
|
|
|
|
|
2024-05-02 08:57:44 +03:00
|
|
|
QWidget* parent = QWidget::find(parent_id);
|
2014-11-13 01:04:59 +02:00
|
|
|
KDialog *dialog= new KDialog(parent, Qt::Dialog);
|
2024-04-30 21:45:09 +03:00
|
|
|
dialog->setCaption(caption.isEmpty() ? i18n("Question") : caption);
|
|
|
|
dialog->setButtons(KDialog::Yes | KDialog::No | KDialog::Cancel);
|
|
|
|
dialog->setObjectName("questionYesNoCancel");
|
|
|
|
dialog->setButtonGuiItem(KDialog::Yes, buttonYes);
|
|
|
|
dialog->setButtonGuiItem(KDialog::No, buttonNo);
|
|
|
|
dialog->setButtonGuiItem(KDialog::Cancel, buttonCancel);
|
|
|
|
dialog->setDefaultButton(KDialog::Yes);
|
|
|
|
applyOptions(dialog, options);
|
|
|
|
if (options & KMessageBox::PlainCaption) {
|
|
|
|
dialog->setWindowTitle(caption);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
2024-04-30 21:45:09 +03:00
|
|
|
if (parent == NULL && parent_id) {
|
|
|
|
KWindowSystem::setMainWindow(dialog, parent_id);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool checkboxResult = false;
|
2024-04-30 21:45:09 +03:00
|
|
|
const int result = createKMessageBox(
|
|
|
|
dialog, QMessageBox::Information,
|
|
|
|
text, QStringList(),
|
|
|
|
dontAskAgainName.isEmpty() ? QString() : i18n("Do not ask again"),
|
|
|
|
&checkboxResult, options
|
|
|
|
);
|
|
|
|
if (result == KDialog::Yes) {
|
2014-11-13 01:04:59 +02:00
|
|
|
res = Yes;
|
|
|
|
} else if ( result == KDialog::No ) {
|
|
|
|
res = No;
|
|
|
|
} else {
|
|
|
|
return Cancel;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (checkboxResult) {
|
|
|
|
saveDontShowAgainYesNo(dontAskAgainName, res);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int KMessageBox::warningYesNo(QWidget *parent, const QString &text,
|
2024-05-02 08:57:44 +03:00
|
|
|
const QString &caption,
|
|
|
|
const KGuiItem &buttonYes,
|
|
|
|
const KGuiItem &buttonNo,
|
|
|
|
const QString &dontAskAgainName,
|
|
|
|
Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2024-05-02 08:57:44 +03:00
|
|
|
return warningYesNoList(
|
|
|
|
parent, text, QStringList(), caption,
|
|
|
|
buttonYes, buttonNo, dontAskAgainName, options
|
|
|
|
);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int KMessageBox::warningYesNoWId(WId parent_id, const QString &text,
|
2024-05-02 08:57:44 +03:00
|
|
|
const QString &caption,
|
|
|
|
const KGuiItem &buttonYes,
|
|
|
|
const KGuiItem &buttonNo,
|
|
|
|
const QString &dontAskAgainName,
|
|
|
|
Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2024-05-02 08:57:44 +03:00
|
|
|
return warningYesNoListWId(
|
|
|
|
parent_id, text, QStringList(), caption,
|
|
|
|
buttonYes, buttonNo, dontAskAgainName, options
|
|
|
|
);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int KMessageBox::warningYesNoList(QWidget *parent, const QString &text,
|
2024-05-02 08:57:44 +03:00
|
|
|
const QStringList &strlist,
|
|
|
|
const QString &caption,
|
|
|
|
const KGuiItem &buttonYes,
|
|
|
|
const KGuiItem &buttonNo,
|
|
|
|
const QString &dontAskAgainName,
|
|
|
|
Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
return warningYesNoListWId( parent ? parent->effectiveWinId() : 0, text, strlist, caption,
|
|
|
|
buttonYes, buttonNo, dontAskAgainName, options );
|
|
|
|
}
|
|
|
|
|
|
|
|
int KMessageBox::warningYesNoListWId(WId parent_id, const QString &text,
|
|
|
|
const QStringList &strlist,
|
|
|
|
const QString &caption,
|
|
|
|
const KGuiItem &buttonYes_,
|
|
|
|
const KGuiItem &buttonNo_,
|
|
|
|
const QString &dontAskAgainName,
|
|
|
|
Options options)
|
|
|
|
{
|
|
|
|
ButtonCode res;
|
2024-05-02 08:57:44 +03:00
|
|
|
if (!shouldBeShownYesNo(dontAskAgainName, res)) {
|
2014-11-13 01:04:59 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
I18N_FILTER_BUTTON_YES(buttonYes_, buttonYes)
|
|
|
|
I18N_FILTER_BUTTON_NO(buttonNo_, buttonNo)
|
|
|
|
I18N_POST_BUTTON_FILTER
|
|
|
|
|
2024-04-30 21:45:09 +03:00
|
|
|
QWidget* parent = QWidget::find(parent_id);
|
2014-11-13 01:04:59 +02:00
|
|
|
KDialog *dialog = new KDialog(parent, Qt::Dialog);
|
2024-04-30 21:45:09 +03:00
|
|
|
dialog->setCaption(caption.isEmpty() ? i18n("Warning") : caption);
|
|
|
|
dialog->setButtons(KDialog::Yes | KDialog::No);
|
|
|
|
dialog->setObjectName("warningYesNoList");
|
|
|
|
dialog->setButtonGuiItem(KDialog::Yes, buttonYes);
|
|
|
|
dialog->setButtonGuiItem(KDialog::No, buttonNo);
|
|
|
|
dialog->setDefaultButton(KDialog::No);
|
|
|
|
dialog->setEscapeButton(KDialog::No);
|
|
|
|
applyOptions(dialog, options);
|
|
|
|
if (options & KMessageBox::PlainCaption) {
|
|
|
|
dialog->setWindowTitle(caption);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
2024-04-30 21:45:09 +03:00
|
|
|
if (parent == NULL && parent_id) {
|
|
|
|
KWindowSystem::setMainWindow(dialog, parent_id);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool checkboxResult = false;
|
2024-04-30 21:45:09 +03:00
|
|
|
const int result = createKMessageBox(
|
|
|
|
dialog, QMessageBox::Warning, text, strlist,
|
|
|
|
dontAskAgainName.isEmpty() ? QString() : i18n("Do not ask again"),
|
|
|
|
&checkboxResult, options
|
|
|
|
);
|
2024-05-02 08:57:44 +03:00
|
|
|
res = (result == KDialog::Yes ? Yes : No);
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
if (checkboxResult) {
|
|
|
|
saveDontShowAgainYesNo(dontAskAgainName, res);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int KMessageBox::warningContinueCancel(QWidget *parent,
|
2024-05-02 08:57:44 +03:00
|
|
|
const QString &text,
|
|
|
|
const QString &caption,
|
|
|
|
const KGuiItem &buttonContinue,
|
|
|
|
const KGuiItem &buttonCancel,
|
|
|
|
const QString &dontAskAgainName,
|
|
|
|
Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2024-05-02 08:57:44 +03:00
|
|
|
return warningContinueCancelList(
|
|
|
|
parent, text, QStringList(), caption,
|
|
|
|
buttonContinue, buttonCancel, dontAskAgainName, options
|
|
|
|
);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int KMessageBox::warningContinueCancelWId(WId parent_id,
|
2024-05-02 08:57:44 +03:00
|
|
|
const QString &text,
|
|
|
|
const QString &caption,
|
|
|
|
const KGuiItem &buttonContinue,
|
|
|
|
const KGuiItem &buttonCancel,
|
|
|
|
const QString &dontAskAgainName,
|
|
|
|
Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2024-05-02 08:57:44 +03:00
|
|
|
return warningContinueCancelListWId(
|
|
|
|
parent_id, text, QStringList(), caption,
|
|
|
|
buttonContinue, buttonCancel, dontAskAgainName, options
|
|
|
|
);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int KMessageBox::warningContinueCancelList(QWidget *parent, const QString &text,
|
2024-05-02 08:57:44 +03:00
|
|
|
const QStringList &strlist,
|
|
|
|
const QString &caption,
|
|
|
|
const KGuiItem &buttonContinue,
|
|
|
|
const KGuiItem &buttonCancel,
|
|
|
|
const QString &dontAskAgainName,
|
|
|
|
Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2024-05-02 08:57:44 +03:00
|
|
|
return warningContinueCancelListWId(
|
|
|
|
parent ? parent->effectiveWinId() : 0, text, strlist,
|
|
|
|
caption, buttonContinue, buttonCancel, dontAskAgainName, options
|
|
|
|
);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int KMessageBox::warningContinueCancelListWId(WId parent_id, const QString &text,
|
2024-05-02 08:57:44 +03:00
|
|
|
const QStringList &strlist,
|
|
|
|
const QString &caption,
|
|
|
|
const KGuiItem &buttonContinue_,
|
|
|
|
const KGuiItem &buttonCancel_,
|
|
|
|
const QString &dontAskAgainName,
|
|
|
|
Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
if ( !shouldBeShownContinue(dontAskAgainName) )
|
|
|
|
return Continue;
|
|
|
|
|
|
|
|
I18N_FILTER_BUTTON_CONTINUE(buttonContinue_, buttonContinue)
|
|
|
|
I18N_FILTER_BUTTON_CANCEL(buttonCancel_, buttonCancel)
|
|
|
|
I18N_POST_BUTTON_FILTER
|
|
|
|
|
2024-04-30 22:35:38 +03:00
|
|
|
QWidget* parent = QWidget::find(parent_id);
|
2014-11-13 01:04:59 +02:00
|
|
|
KDialog *dialog = new KDialog(parent, Qt::Dialog);
|
2024-04-30 22:35:38 +03:00
|
|
|
dialog->setCaption(caption.isEmpty() ? i18n("Warning") : caption);
|
|
|
|
dialog->setButtons(KDialog::Yes | KDialog::No);
|
|
|
|
dialog->setObjectName("warningYesNo");
|
2024-04-30 21:45:09 +03:00
|
|
|
dialog->setButtonGuiItem(KDialog::Yes, buttonContinue);
|
|
|
|
dialog->setButtonGuiItem(KDialog::No, buttonCancel);
|
|
|
|
dialog->setDefaultButton(KDialog::Yes);
|
|
|
|
dialog->setEscapeButton(KDialog::No);
|
|
|
|
applyOptions(dialog, options);
|
|
|
|
if (options & KMessageBox::PlainCaption) {
|
|
|
|
dialog->setWindowTitle(caption);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
2024-04-30 21:45:09 +03:00
|
|
|
if (parent == NULL && parent_id) {
|
|
|
|
KWindowSystem::setMainWindow(dialog, parent_id);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool checkboxResult = false;
|
2024-04-30 21:45:09 +03:00
|
|
|
const int result = createKMessageBox(
|
|
|
|
dialog, QMessageBox::Warning, text, strlist,
|
|
|
|
dontAskAgainName.isEmpty() ? QString() : i18n("Do not ask again"),
|
|
|
|
&checkboxResult, options
|
|
|
|
);
|
|
|
|
if (result != KDialog::Yes) {
|
2014-11-13 01:04:59 +02:00
|
|
|
return Cancel;
|
|
|
|
}
|
|
|
|
if (checkboxResult) {
|
|
|
|
saveDontShowAgainContinue(dontAskAgainName);
|
|
|
|
}
|
|
|
|
return Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
int KMessageBox::warningYesNoCancel(QWidget *parent, const QString &text,
|
|
|
|
const QString &caption,
|
|
|
|
const KGuiItem &buttonYes,
|
|
|
|
const KGuiItem &buttonNo,
|
|
|
|
const KGuiItem &buttonCancel,
|
|
|
|
const QString &dontAskAgainName,
|
|
|
|
Options options)
|
|
|
|
{
|
|
|
|
return warningYesNoCancelList(parent, text, QStringList(), caption,
|
|
|
|
buttonYes, buttonNo, buttonCancel, dontAskAgainName, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
int KMessageBox::warningYesNoCancelWId(WId parent_id, const QString &text,
|
|
|
|
const QString &caption,
|
|
|
|
const KGuiItem &buttonYes,
|
|
|
|
const KGuiItem &buttonNo,
|
|
|
|
const KGuiItem &buttonCancel,
|
|
|
|
const QString &dontAskAgainName,
|
|
|
|
Options options)
|
|
|
|
{
|
|
|
|
return warningYesNoCancelListWId(parent_id, text, QStringList(), caption,
|
|
|
|
buttonYes, buttonNo, buttonCancel, dontAskAgainName, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
int KMessageBox::warningYesNoCancelList(QWidget *parent, const QString &text,
|
|
|
|
const QStringList &strlist,
|
|
|
|
const QString &caption,
|
|
|
|
const KGuiItem &buttonYes,
|
|
|
|
const KGuiItem &buttonNo,
|
|
|
|
const KGuiItem &buttonCancel,
|
|
|
|
const QString &dontAskAgainName,
|
|
|
|
Options options)
|
|
|
|
{
|
|
|
|
return warningYesNoCancelListWId( parent ? parent->effectiveWinId() : 0, text, strlist,
|
|
|
|
caption, buttonYes, buttonNo, buttonCancel, dontAskAgainName, options );
|
|
|
|
}
|
|
|
|
|
|
|
|
int KMessageBox::warningYesNoCancelListWId(WId parent_id, const QString &text,
|
|
|
|
const QStringList &strlist,
|
|
|
|
const QString &caption,
|
|
|
|
const KGuiItem &buttonYes_,
|
|
|
|
const KGuiItem &buttonNo_,
|
|
|
|
const KGuiItem &buttonCancel_,
|
|
|
|
const QString &dontAskAgainName,
|
|
|
|
Options options)
|
|
|
|
{
|
|
|
|
ButtonCode res;
|
|
|
|
if ( !shouldBeShownYesNo(dontAskAgainName, res) ) {
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
I18N_FILTER_BUTTON_YES(buttonYes_, buttonYes)
|
|
|
|
I18N_FILTER_BUTTON_NO(buttonNo_, buttonNo)
|
|
|
|
I18N_FILTER_BUTTON_CANCEL(buttonCancel_, buttonCancel)
|
|
|
|
I18N_POST_BUTTON_FILTER
|
|
|
|
|
|
|
|
QWidget* parent = QWidget::find( parent_id );
|
|
|
|
KDialog *dialog = new KDialog(parent, Qt::Dialog);
|
2024-04-30 21:45:09 +03:00
|
|
|
dialog->setCaption(caption.isEmpty() ? i18n("Warning") : caption);
|
|
|
|
dialog->setButtons(KDialog::Yes | KDialog::No | KDialog::Cancel);
|
2024-04-30 22:35:38 +03:00
|
|
|
dialog->setObjectName("warningYesNoCancel");
|
2024-04-30 21:45:09 +03:00
|
|
|
dialog->setButtonGuiItem(KDialog::Yes, buttonYes);
|
|
|
|
dialog->setButtonGuiItem(KDialog::No, buttonNo);
|
|
|
|
dialog->setButtonGuiItem(KDialog::Cancel, buttonCancel);
|
|
|
|
dialog->setDefaultButton(KDialog::Yes);
|
|
|
|
applyOptions(dialog, options );
|
|
|
|
if (options & KMessageBox::PlainCaption) {
|
|
|
|
dialog->setWindowTitle(caption);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
2024-04-30 21:45:09 +03:00
|
|
|
if (parent == NULL && parent_id) {
|
|
|
|
KWindowSystem::setMainWindow(dialog, parent_id);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool checkboxResult = false;
|
2024-04-30 21:45:09 +03:00
|
|
|
const int result = createKMessageBox(
|
|
|
|
dialog, QMessageBox::Warning, text, strlist,
|
|
|
|
dontAskAgainName.isEmpty() ? QString() : i18n("Do not ask again"),
|
|
|
|
&checkboxResult, options
|
|
|
|
);
|
|
|
|
if (result == KDialog::Yes) {
|
2014-11-13 01:04:59 +02:00
|
|
|
res = Yes;
|
|
|
|
} else if ( result == KDialog::No ) {
|
|
|
|
res = No;
|
|
|
|
} else {
|
|
|
|
return Cancel;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (checkboxResult) {
|
|
|
|
saveDontShowAgainYesNo(dontAskAgainName, res);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2024-04-30 21:45:09 +03:00
|
|
|
void KMessageBox::error(QWidget *parent, const QString &text, const QString &caption,
|
|
|
|
Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
return errorListWId( parent ? parent->effectiveWinId() : 0, text, QStringList(), caption, options );
|
|
|
|
}
|
|
|
|
|
2024-04-30 21:45:09 +03:00
|
|
|
void KMessageBox::errorWId(WId parent_id, const QString &text, const QString &caption,
|
|
|
|
Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2024-04-30 21:45:09 +03:00
|
|
|
errorListWId(parent_id, text, QStringList(), caption, options);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void KMessageBox::errorList(QWidget *parent, const QString &text, const QStringList &strlist,
|
2024-04-30 21:45:09 +03:00
|
|
|
const QString &caption, Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2024-04-30 21:45:09 +03:00
|
|
|
return errorListWId(parent ? parent->effectiveWinId() : 0, text, strlist, caption, options);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void KMessageBox::errorListWId(WId parent_id, const QString &text, const QStringList &strlist,
|
2024-04-30 21:45:09 +03:00
|
|
|
const QString &caption, Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2024-04-30 21:45:09 +03:00
|
|
|
QWidget* parent = QWidget::find(parent_id);
|
2014-11-13 01:04:59 +02:00
|
|
|
KDialog *dialog = new KDialog(parent, Qt::Dialog);
|
2024-04-30 21:45:09 +03:00
|
|
|
dialog->setCaption(caption.isEmpty() ? i18n("Error") : caption);
|
|
|
|
dialog->setButtons(KDialog::Ok);
|
|
|
|
dialog->setObjectName("error");
|
|
|
|
dialog->setDefaultButton(KDialog::Ok);
|
|
|
|
dialog->setEscapeButton(KDialog::Ok);
|
|
|
|
applyOptions(dialog, options);
|
|
|
|
if (options & KMessageBox::PlainCaption) {
|
|
|
|
dialog->setWindowTitle(caption);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
2024-04-30 21:45:09 +03:00
|
|
|
if (parent == NULL && parent_id) {
|
|
|
|
KWindowSystem::setMainWindow(dialog, parent_id);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
createKMessageBox(dialog, QMessageBox::Critical, text, strlist, QString(), 0, options);
|
|
|
|
}
|
|
|
|
|
2024-04-30 21:45:09 +03:00
|
|
|
void KMessageBox::detailedError(QWidget *parent, const QString &text,
|
|
|
|
const QString &details,
|
|
|
|
const QString &caption, Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
return detailedErrorWId( parent ? parent->effectiveWinId() : 0, text, details, caption, options );
|
|
|
|
}
|
|
|
|
|
|
|
|
void KMessageBox::detailedErrorWId(WId parent_id, const QString &text,
|
2024-04-30 21:45:09 +03:00
|
|
|
const QString &details,
|
|
|
|
const QString &caption, Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2024-04-30 22:35:38 +03:00
|
|
|
QWidget* parent = QWidget::find(parent_id);
|
2014-11-13 01:04:59 +02:00
|
|
|
KDialog *dialog = new KDialog(parent, Qt::Dialog);
|
2024-04-30 21:45:09 +03:00
|
|
|
dialog->setCaption(caption.isEmpty() ? i18n("Error") : caption);
|
|
|
|
dialog->setButtons(KDialog::Ok | KDialog::Details);
|
|
|
|
dialog->setObjectName("error");
|
|
|
|
dialog->setDefaultButton(KDialog::Ok);
|
|
|
|
dialog->setEscapeButton(KDialog::Ok);
|
|
|
|
applyOptions(dialog, options);
|
|
|
|
if (options & KMessageBox::PlainCaption) {
|
|
|
|
dialog->setWindowTitle(caption);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
2024-04-30 21:45:09 +03:00
|
|
|
if (parent == NULL && parent_id) {
|
|
|
|
KWindowSystem::setMainWindow(dialog, parent_id);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
createKMessageBox(dialog, QMessageBox::Critical, text, QStringList(), QString(), 0, options, details);
|
|
|
|
}
|
|
|
|
|
2024-04-30 21:45:09 +03:00
|
|
|
void KMessageBox::queuedDetailedError(QWidget *parent, const QString &text, const QString &details,
|
|
|
|
const QString &caption)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2024-04-30 21:45:09 +03:00
|
|
|
return queuedDetailedErrorWId(parent ? parent->effectiveWinId() : 0, text, details, caption);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void KMessageBox::queuedDetailedErrorWId(WId parent_id, const QString &text,
|
2024-04-30 21:45:09 +03:00
|
|
|
const QString &details, const QString &caption)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
KMessageBox_queue = true;
|
|
|
|
(void) detailedErrorWId(parent_id, text, details, caption);
|
|
|
|
KMessageBox_queue = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-30 21:45:09 +03:00
|
|
|
void KMessageBox::sorry(QWidget *parent, const QString &text, const QString &caption,
|
|
|
|
Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2024-04-30 21:45:09 +03:00
|
|
|
return sorryWId(parent ? parent->effectiveWinId() : 0, text, caption, options);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2024-04-30 21:45:09 +03:00
|
|
|
void KMessageBox::sorryWId(WId parent_id, const QString &text, const QString &caption,
|
|
|
|
Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2024-04-30 21:45:09 +03:00
|
|
|
QWidget* parent = QWidget::find(parent_id);
|
2014-11-13 01:04:59 +02:00
|
|
|
KDialog *dialog = new KDialog(parent, Qt::Dialog);
|
2024-04-30 21:45:09 +03:00
|
|
|
dialog->setCaption(caption.isEmpty() ? i18n("Sorry") : caption);
|
|
|
|
dialog->setButtons(KDialog::Ok);
|
|
|
|
dialog->setObjectName("sorry");
|
|
|
|
dialog->setDefaultButton(KDialog::Ok);
|
|
|
|
dialog->setEscapeButton(KDialog::Ok);
|
|
|
|
applyOptions(dialog, options);
|
|
|
|
if (options & KMessageBox::PlainCaption) {
|
|
|
|
dialog->setWindowTitle(caption);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
2024-04-30 21:45:09 +03:00
|
|
|
if (parent == NULL && parent_id) {
|
|
|
|
KWindowSystem::setMainWindow(dialog, parent_id);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
createKMessageBox(dialog, QMessageBox::Warning, text, QStringList(), QString(), 0, options);
|
|
|
|
}
|
|
|
|
|
2024-04-30 21:45:09 +03:00
|
|
|
void KMessageBox::detailedSorry(QWidget *parent, const QString &text, const QString &details,
|
|
|
|
const QString &caption, Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2024-04-30 21:45:09 +03:00
|
|
|
return detailedSorryWId(parent ? parent->effectiveWinId() : 0, text, details, caption, options);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2024-04-30 21:45:09 +03:00
|
|
|
void KMessageBox::detailedSorryWId(WId parent_id, const QString &text, const QString &details,
|
|
|
|
const QString &caption, Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
QWidget* parent = QWidget::find( parent_id );
|
|
|
|
KDialog *dialog = new KDialog(parent, Qt::Dialog);
|
2024-04-30 21:45:09 +03:00
|
|
|
dialog->setCaption(caption.isEmpty() ? i18n("Sorry") : caption);
|
|
|
|
dialog->setButtons(KDialog::Ok | KDialog::Details);
|
|
|
|
dialog->setObjectName("sorry");
|
|
|
|
dialog->setDefaultButton(KDialog::Ok);
|
|
|
|
dialog->setEscapeButton(KDialog::Ok);
|
|
|
|
applyOptions(dialog, options);
|
|
|
|
if (options & KMessageBox::PlainCaption) {
|
|
|
|
dialog->setWindowTitle(caption);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
2024-04-30 21:45:09 +03:00
|
|
|
if (parent == NULL && parent_id) {
|
|
|
|
KWindowSystem::setMainWindow(dialog, parent_id);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
createKMessageBox(dialog, QMessageBox::Warning, text, QStringList(), QString(), 0, options, details);
|
|
|
|
}
|
|
|
|
|
2024-04-30 21:45:09 +03:00
|
|
|
void KMessageBox::information(QWidget *parent,const QString &text, const QString &caption,
|
|
|
|
const QString &dontShowAgainName, Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
informationList(parent, text, QStringList(), caption, dontShowAgainName, options);
|
|
|
|
}
|
|
|
|
|
2024-04-30 21:45:09 +03:00
|
|
|
void KMessageBox::informationWId(WId parent_id,const QString &text, const QString &caption,
|
|
|
|
const QString &dontShowAgainName, Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
informationListWId(parent_id, text, QStringList(), caption, dontShowAgainName, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KMessageBox::informationList(QWidget *parent,const QString &text, const QStringList & strlist,
|
2024-04-30 21:45:09 +03:00
|
|
|
const QString &caption, const QString &dontShowAgainName, Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2024-04-30 21:45:09 +03:00
|
|
|
return informationListWId(
|
|
|
|
parent ? parent->effectiveWinId() : 0, text, strlist, caption,
|
|
|
|
dontShowAgainName, options
|
|
|
|
);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2024-04-30 21:45:09 +03:00
|
|
|
void KMessageBox::informationListWId(WId parent_id,const QString &text, const QStringList &strlist,
|
2024-04-20 19:17:23 +03:00
|
|
|
const QString &caption, const QString &dontShowAgainName, Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2024-04-20 19:17:23 +03:00
|
|
|
if (!shouldBeShownContinue(dontShowAgainName)) {
|
2014-11-13 01:04:59 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-04-30 22:35:38 +03:00
|
|
|
QWidget* parent = QWidget::find(parent_id);
|
2014-11-13 01:04:59 +02:00
|
|
|
KDialog *dialog = new KDialog(parent, Qt::Dialog);
|
2024-04-20 19:17:23 +03:00
|
|
|
dialog->setCaption(caption.isEmpty() ? i18n("Information") : caption);
|
|
|
|
dialog->setButtons(KDialog::Ok);
|
|
|
|
dialog->setObjectName("information");
|
|
|
|
dialog->setDefaultButton(KDialog::Ok);
|
|
|
|
dialog->setEscapeButton(KDialog::Ok);
|
2024-04-30 21:45:09 +03:00
|
|
|
applyOptions(dialog, options);
|
2024-04-20 19:17:23 +03:00
|
|
|
if (options & KMessageBox::PlainCaption) {
|
|
|
|
dialog->setWindowTitle(caption);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
2024-04-20 19:17:23 +03:00
|
|
|
if (!parent && parent_id) {
|
|
|
|
KWindowSystem::setMainWindow(dialog, parent_id);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool checkboxResult = false;
|
|
|
|
|
2024-04-20 19:17:23 +03:00
|
|
|
createKMessageBox(
|
|
|
|
dialog, QMessageBox::Information, text, strlist,
|
|
|
|
dontShowAgainName.isEmpty() ? QString() : i18n("Do not show this message again"),
|
|
|
|
&checkboxResult, options
|
|
|
|
);
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
if (checkboxResult) {
|
|
|
|
saveDontShowAgainContinue(dontShowAgainName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KMessageBox::enableAllMessages()
|
|
|
|
{
|
|
|
|
KConfig *config = KMessageBox_againConfig ? KMessageBox_againConfig : KGlobal::config().data();
|
|
|
|
if (!config->hasGroup("Notification Messages")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
KConfigGroup cg(config, "Notification Messages" );
|
|
|
|
|
|
|
|
typedef QMap<QString, QString> configMap;
|
|
|
|
|
|
|
|
const configMap map = cg.entryMap();
|
|
|
|
|
|
|
|
configMap::ConstIterator it;
|
|
|
|
for (it = map.begin(); it != map.end(); ++it) {
|
|
|
|
cg.deleteEntry( it.key() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KMessageBox::enableMessage(const QString &dontShowAgainName)
|
|
|
|
{
|
2024-04-20 19:17:23 +03:00
|
|
|
KConfig *config = KMessageBox_againConfig ? KMessageBox_againConfig : KGlobal::config().data();
|
|
|
|
if (!config->hasGroup("Notification Messages")) {
|
|
|
|
return;
|
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2024-04-20 19:17:23 +03:00
|
|
|
KConfigGroup cg(config, "Notification Messages");
|
|
|
|
cg.deleteEntry(dontShowAgainName);
|
|
|
|
config->sync();
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2024-04-30 21:45:09 +03:00
|
|
|
void KMessageBox::about(QWidget *parent, const QString &text, const QString &caption,
|
|
|
|
Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
QString _caption = caption;
|
|
|
|
if (_caption.isEmpty()) {
|
|
|
|
_caption = i18n("About %1", KGlobal::caption());
|
|
|
|
}
|
|
|
|
|
|
|
|
KDialog *dialog = new KDialog(parent, Qt::Dialog);
|
2024-04-30 21:45:09 +03:00
|
|
|
dialog->setCaption(caption);
|
|
|
|
dialog->setButtons(KDialog::Ok);
|
|
|
|
dialog->setObjectName("about");
|
|
|
|
applyOptions(dialog, options);
|
|
|
|
dialog->setDefaultButton(KDialog::Ok);
|
|
|
|
dialog->setEscapeButton(KDialog::Ok);
|
2014-11-13 01:04:59 +02:00
|
|
|
if (qApp->windowIcon().isNull()) {
|
|
|
|
QPixmap ret = QMessageBox::standardIcon(QMessageBox::Information);
|
|
|
|
dialog->setWindowIcon(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
createKMessageBox(dialog, qApp->windowIcon(), text, QStringList(), QString(), 0, options);
|
|
|
|
}
|
|
|
|
|
2024-04-20 19:17:23 +03:00
|
|
|
int KMessageBox::messageBox(QWidget *parent, DialogType type, const QString &text,
|
|
|
|
const QString &caption, const KGuiItem &buttonYes,
|
|
|
|
const KGuiItem &buttonNo, const KGuiItem &buttonCancel,
|
|
|
|
const QString &dontShowAskAgainName, Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2024-04-20 19:17:23 +03:00
|
|
|
return messageBoxWId(
|
|
|
|
parent ? parent->effectiveWinId() : 0, type, text, caption,
|
|
|
|
buttonYes, buttonNo, buttonCancel, dontShowAskAgainName, options
|
|
|
|
);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2024-04-20 19:17:23 +03:00
|
|
|
int KMessageBox::messageBoxWId(WId parent_id, DialogType type, const QString &text,
|
|
|
|
const QString &caption, const KGuiItem &buttonYes,
|
|
|
|
const KGuiItem &buttonNo, const KGuiItem &buttonCancel,
|
|
|
|
const QString &dontShow, Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
switch (type) {
|
2024-04-20 19:17:23 +03:00
|
|
|
case QuestionYesNo: {
|
|
|
|
return KMessageBox::questionYesNoWId(
|
|
|
|
parent_id,
|
|
|
|
text, caption, buttonYes, buttonNo, dontShow, options
|
|
|
|
);
|
|
|
|
}
|
|
|
|
case QuestionYesNoCancel: {
|
|
|
|
return KMessageBox::questionYesNoCancelWId(
|
|
|
|
parent_id,
|
|
|
|
text, caption, buttonYes, buttonNo, buttonCancel, dontShow, options
|
|
|
|
);
|
|
|
|
}
|
|
|
|
case WarningYesNo: {
|
|
|
|
return KMessageBox::warningYesNoWId(
|
|
|
|
parent_id,
|
|
|
|
text, caption, buttonYes, buttonNo, dontShow, options
|
|
|
|
);
|
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
case WarningContinueCancel:
|
2024-04-20 19:17:23 +03:00
|
|
|
return KMessageBox::warningContinueCancelWId(
|
|
|
|
parent_id,
|
|
|
|
text, caption, KGuiItem(buttonYes.text()), buttonCancel, dontShow, options
|
|
|
|
);
|
2014-11-13 01:04:59 +02:00
|
|
|
case WarningYesNoCancel:
|
2024-04-20 19:17:23 +03:00
|
|
|
return KMessageBox::warningYesNoCancelWId(
|
|
|
|
parent_id,
|
|
|
|
text, caption, buttonYes, buttonNo, buttonCancel, dontShow, options
|
|
|
|
);
|
2014-11-13 01:04:59 +02:00
|
|
|
case Information:
|
2024-04-20 19:17:23 +03:00
|
|
|
KMessageBox::informationWId(parent_id, text, caption, dontShow, options);
|
2014-11-13 01:04:59 +02:00
|
|
|
return KMessageBox::Ok;
|
|
|
|
|
|
|
|
case Error:
|
2024-04-20 19:17:23 +03:00
|
|
|
KMessageBox::errorWId(parent_id, text, caption, options);
|
2014-11-13 01:04:59 +02:00
|
|
|
return KMessageBox::Ok;
|
|
|
|
|
|
|
|
case Sorry:
|
2024-04-20 19:17:23 +03:00
|
|
|
KMessageBox::sorryWId(parent_id, text, caption, options);
|
2014-11-13 01:04:59 +02:00
|
|
|
return KMessageBox::Ok;
|
|
|
|
}
|
|
|
|
return KMessageBox::Cancel;
|
|
|
|
}
|
|
|
|
|
2024-04-20 19:17:23 +03:00
|
|
|
void KMessageBox::queuedMessageBox(QWidget *parent, DialogType type, const QString &text,
|
|
|
|
const QString &caption, Options options)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2024-04-20 19:17:23 +03:00
|
|
|
return queuedMessageBoxWId(parent ? parent->effectiveWinId() : 0, type, text, caption, options);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2024-04-20 19:17:23 +03:00
|
|
|
void KMessageBox::queuedMessageBoxWId(WId parent_id, DialogType type, const QString &text,
|
|
|
|
const QString &caption, Options options )
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
KMessageBox_queue = true;
|
2024-04-20 19:17:23 +03:00
|
|
|
(void) messageBoxWId(
|
|
|
|
parent_id,
|
|
|
|
type, text, caption, KStandardGuiItem::yes(),
|
|
|
|
KStandardGuiItem::no(), KStandardGuiItem::cancel(), QString(), options
|
|
|
|
);
|
2014-11-13 01:04:59 +02:00
|
|
|
KMessageBox_queue = false;
|
|
|
|
}
|
|
|
|
|
2024-04-20 19:17:23 +03:00
|
|
|
void KMessageBox::queuedMessageBox(QWidget *parent, DialogType type, const QString &text,
|
|
|
|
const QString &caption)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2024-04-20 19:17:23 +03:00
|
|
|
return queuedMessageBoxWId( parent ? parent->effectiveWinId() : 0, type, text, caption);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2024-04-20 19:17:23 +03:00
|
|
|
void KMessageBox::queuedMessageBoxWId(WId parent_id, DialogType type, const QString &text,
|
|
|
|
const QString &caption)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
|
|
|
KMessageBox_queue = true;
|
|
|
|
(void) messageBoxWId(parent_id, type, text, caption);
|
|
|
|
KMessageBox_queue = false;
|
|
|
|
}
|