File indexing completed on 2024-05-12 05:46:40
0001 /* This file is part of the KDE libraries 0002 Copyright (C) 1999 Waldo Bastian (bastian@kde.org) 0003 Copyright 2012 David Faure <faure+bluesystems@kde.org> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; version 2 0008 of the License. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #include "kmessagebox.h" 0022 #include "kmessagebox_p.h" 0023 0024 #include <QPointer> 0025 #include <QCheckBox> 0026 #include <QDialog> 0027 #include <QDialogButtonBox> 0028 #include <QLabel> 0029 #include <QLayout> 0030 #include <QListWidget> 0031 #include <QPushButton> 0032 #include <QDesktopWidget> 0033 #include <QScrollArea> 0034 #include <QScrollBar> 0035 #include <QTextBrowser> 0036 #include <QWindow> 0037 0038 #include <qapplication.h> 0039 #if 0 0040 // NOTE waiting for the notification framework plan 0041 #include <knotification.h> 0042 #endif 0043 #include <ksqueezedtextlabel.h> 0044 0045 #include <KCollapsibleGroupBox> 0046 // Some i18n filters, that standard button texts are piped through 0047 // (the new KGuiItem object with filtered text is created from the old one). 0048 0049 // Filter for the Yes-button text in standard message dialogs, 0050 // after the message caption/text have been translated. 0051 #define I18N_FILTER_BUTTON_YES(src, dst) \ 0052 KGuiItem dst(src); \ 0053 dst.setText( QApplication::translate( "KMessageBox", src.text().toUtf8().constData(), "@action:button filter-yes" ) ); 0054 0055 // Filter for the No-button text in standard message dialogs, 0056 // after the message caption/text have been translated. 0057 #define I18N_FILTER_BUTTON_NO(src, dst) \ 0058 KGuiItem dst(src); \ 0059 dst.setText( QApplication::translate( "KMessageBox", src.text().toUtf8().constData(), "@action:button filter-no" ) ); 0060 0061 // Filter for the Continue-button text in standard message dialogs, 0062 // after the message caption/text have been translated. 0063 #define I18N_FILTER_BUTTON_CONTINUE(src, dst) \ 0064 KGuiItem dst(src); \ 0065 dst.setText( QApplication::translate( "KMessageBox", src.text().toUtf8().constData(), "@action:button filter-continue" ) ); 0066 0067 // Filter for the Cancel-button text in standard message dialogs, 0068 // after the message caption/text have been translated. 0069 #define I18N_FILTER_BUTTON_CANCEL(src, dst) \ 0070 KGuiItem dst(src); \ 0071 dst.setText( QApplication::translate( "KMessageBox", src.text().toUtf8().constData(), "@action:button filter-cancel" ) ); 0072 0073 // Called after the button texts in standard message dialogs 0074 // have been filtered by the messages above. Not visible to user. 0075 #define I18N_POST_BUTTON_FILTER \ 0076 QApplication::translate( "KMessageBox", ".", "@action:button post-filter" ); 0077 0078 namespace KMessageBox 0079 { 0080 0081 /* 0082 * this static is used by the createKMessageBox function to enqueue dialogs 0083 * FIXME what should we do about this static? 0084 */ 0085 QDialogButtonBox::StandardButton KWIDGETSADDONS_EXPORT(*KMessageBox_exec_hook)(QDialog *) = nullptr; 0086 0087 static void applyOptions(QDialog *dialog, KMessageBox::Options options) 0088 { 0089 if (options & KMessageBox::WindowModal) { 0090 dialog->setWindowModality(Qt::WindowModal); 0091 } 0092 dialog->setModal(true); 0093 } 0094 0095 // This method has been copied from KWindowSystem to avoid depending on it 0096 static void setMainWindow(QWidget *subWidget, WId mainWindowId) 0097 { 0098 #ifdef Q_OS_OSX 0099 if (!QWidget::find(mainWindowId)) { 0100 return; 0101 } 0102 #endif 0103 // Set the WA_NativeWindow attribute to force the creation of the QWindow. 0104 // Without this QWidget::windowHandle() returns 0. 0105 subWidget->setAttribute(Qt::WA_NativeWindow, true); 0106 QWindow *subWindow = subWidget->windowHandle(); 0107 Q_ASSERT(subWindow); 0108 0109 QWindow *mainWindow = QWindow::fromWinId(mainWindowId); 0110 if (!mainWindow) { 0111 // foreign windows not supported on all platforms 0112 return; 0113 } 0114 // mainWindow is not the child of any object, so make sure it gets deleted at some point 0115 QObject::connect(subWidget, &QObject::destroyed, mainWindow, &QObject::deleteLater); 0116 subWindow->setTransientParent(mainWindow); 0117 } 0118 0119 /** 0120 * Create a QDialog whose parent is a foreign window 0121 */ 0122 static QDialog *createWIdDialog(WId parent_id) 0123 { 0124 QWidget *parent = QWidget::find(parent_id); 0125 QDialog *dialog = new QDialog(parent, Qt::Dialog); 0126 if (!parent && parent_id) { 0127 setMainWindow(dialog, parent_id); 0128 } 0129 return dialog; 0130 } 0131 0132 class DialogButtonsHelper : public QObject 0133 { 0134 Q_OBJECT 0135 public: 0136 DialogButtonsHelper(QDialog *dialog, QDialogButtonBox *buttons) 0137 : QObject(dialog), 0138 m_dialog(dialog), 0139 m_buttons(buttons), 0140 m_details(nullptr) 0141 { 0142 connect(m_buttons, &QDialogButtonBox::clicked, 0143 this, &DialogButtonsHelper::onButtonClicked); 0144 } 0145 0146 void setDetailsWidget(QWidget *widget) 0147 { 0148 m_details = widget; 0149 } 0150 0151 public Q_SLOTS: 0152 void onButtonClicked(QAbstractButton *button) 0153 { 0154 QDialogButtonBox::StandardButton code = m_buttons->standardButton(button); 0155 if (code != QDialogButtonBox::NoButton) { 0156 m_dialog->done(code); 0157 } 0158 } 0159 0160 private: 0161 QDialog *const m_dialog; 0162 QDialogButtonBox *const m_buttons; 0163 QWidget *m_details; 0164 }; 0165 0166 QDialogButtonBox::StandardButton createKMessageBox(QDialog *dialog, QDialogButtonBox *buttons, QMessageBox::Icon icon, 0167 const QString &text, const QStringList &strlist, 0168 const QString &ask, bool *checkboxReturn, 0169 Options options, const QString &details) 0170 { 0171 QIcon tmpIcon; 0172 QStyle *style = dialog ? dialog->style() : QApplication::style(); 0173 switch (icon) { 0174 case QMessageBox::Information: 0175 tmpIcon = style->standardIcon(QStyle::SP_MessageBoxInformation, nullptr, dialog); 0176 break; 0177 case QMessageBox::Warning: 0178 tmpIcon = style->standardIcon(QStyle::SP_MessageBoxWarning, nullptr, dialog); 0179 break; 0180 case QMessageBox::Critical: 0181 tmpIcon = style->standardIcon(QStyle::SP_MessageBoxCritical, nullptr, dialog); 0182 break; 0183 case QMessageBox::Question: 0184 tmpIcon = style->standardIcon(QStyle::SP_MessageBoxQuestion, nullptr, dialog); 0185 break; 0186 default: 0187 break; 0188 } 0189 0190 return createKMessageBox(dialog, buttons, tmpIcon, text, strlist, 0191 ask, checkboxReturn, options, details, icon); 0192 } 0193 0194 QDialogButtonBox::StandardButton createKMessageBox(QDialog *dialog, QDialogButtonBox *buttons, const QIcon &icon, 0195 const QString &text, const QStringList &strlist, 0196 const QString &ask, bool *checkboxReturn, Options options, 0197 const QString &details, QMessageBox::Icon notifyType) 0198 { 0199 DialogButtonsHelper *buttonsHelper = new DialogButtonsHelper(dialog, buttons); 0200 0201 QWidget *mainWidget = new QWidget(dialog); 0202 QVBoxLayout *mainLayout = new QVBoxLayout(mainWidget); 0203 const int spacingHint = mainWidget->style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing); 0204 mainLayout->setSpacing(spacingHint * 2); // provide extra spacing 0205 mainLayout->setContentsMargins(0, 0, 0, 0); 0206 buttons->setParent(dialog); 0207 0208 QHBoxLayout *hLayout = new QHBoxLayout(); 0209 hLayout->setContentsMargins(0, 0, 0, 0); 0210 hLayout->setSpacing(-1); // use default spacing 0211 mainLayout->addLayout(hLayout, 5); 0212 0213 QLabel *iconLabel = new QLabel(mainWidget); 0214 0215 if (!icon.isNull()) { 0216 QStyleOption option; 0217 option.initFrom(mainWidget); 0218 iconLabel->setPixmap(icon.pixmap(mainWidget->style()->pixelMetric(QStyle::PM_MessageBoxIconSize, &option, mainWidget))); 0219 } 0220 0221 QVBoxLayout *iconLayout = new QVBoxLayout(); 0222 iconLayout->addStretch(1); 0223 iconLayout->addWidget(iconLabel); 0224 iconLayout->addStretch(5); 0225 0226 hLayout->addLayout(iconLayout, 0); 0227 hLayout->addSpacing(spacingHint); 0228 0229 QLabel *messageLabel = new QLabel(text, mainWidget); 0230 messageLabel->setOpenExternalLinks(options & KMessageBox::AllowLink); 0231 Qt::TextInteractionFlags flags = Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard; 0232 if (options & KMessageBox::AllowLink) { 0233 flags |= Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard; 0234 } 0235 messageLabel->setTextInteractionFlags(flags); 0236 0237 QRect desktop = QApplication::desktop()->screenGeometry(dialog); 0238 bool usingSqueezedTextLabel = false; 0239 if (messageLabel->sizeHint().width() > desktop.width() * 0.5) { 0240 // enable automatic wrapping of messages which are longer than 50% of screen width 0241 messageLabel->setWordWrap(true); 0242 // use a squeezed label if text is still too wide 0243 usingSqueezedTextLabel = messageLabel->sizeHint().width() > desktop.width() * 0.85; 0244 if (usingSqueezedTextLabel) { 0245 delete messageLabel; 0246 messageLabel = new KSqueezedTextLabel(text, mainWidget); 0247 messageLabel->setOpenExternalLinks(options & KMessageBox::AllowLink); 0248 messageLabel->setTextInteractionFlags(flags); 0249 } 0250 } 0251 0252 QPalette messagePal(messageLabel->palette()); 0253 messagePal.setColor(QPalette::Window, Qt::transparent); 0254 messageLabel->setPalette(messagePal); 0255 0256 bool usingScrollArea = desktop.height() / 3 < messageLabel->sizeHint().height(); 0257 if (usingScrollArea) { 0258 QScrollArea *messageScrollArea = new QScrollArea(mainWidget); 0259 messageScrollArea->setWidget(messageLabel); 0260 messageScrollArea->setFrameShape(QFrame::NoFrame); 0261 messageScrollArea->setWidgetResizable(true); 0262 QPalette scrollPal(messageScrollArea->palette()); 0263 scrollPal.setColor(QPalette::Window, Qt::transparent); 0264 messageScrollArea->viewport()->setPalette(scrollPal); 0265 hLayout->addWidget(messageScrollArea, 5); 0266 } else { 0267 hLayout->addWidget(messageLabel, 5); 0268 } 0269 0270 const bool usingListWidget = !strlist.isEmpty(); 0271 if (usingListWidget) { 0272 // enable automatic wrapping since the listwidget has already a good initial width 0273 messageLabel->setWordWrap(true); 0274 QListWidget *listWidget = new QListWidget(mainWidget); 0275 listWidget->addItems(strlist); 0276 0277 QStyleOptionViewItem styleOption; 0278 styleOption.initFrom(listWidget); 0279 QFontMetrics fm(styleOption.font); 0280 int w = listWidget->width(); 0281 for (const QString &str : strlist) { 0282 w = qMax(w, fm.boundingRect(str).width()); 0283 } 0284 const int borderWidth = listWidget->width() - listWidget->viewport()->width() + listWidget->verticalScrollBar()->height(); 0285 w += borderWidth; 0286 if (w > desktop.width() * 0.85) { // limit listWidget size to 85% of screen width 0287 w = qRound(desktop.width() * 0.85); 0288 } 0289 listWidget->setMinimumWidth(w); 0290 0291 mainLayout->addWidget(listWidget, usingScrollArea ? 10 : 50); 0292 listWidget->setSelectionMode(QListWidget::NoSelection); 0293 messageLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); 0294 } else if (!usingScrollArea) { 0295 mainLayout->addStretch(15); 0296 } 0297 0298 QPointer<QCheckBox> checkbox = nullptr; 0299 if (!ask.isEmpty()) { 0300 checkbox = new QCheckBox(ask, mainWidget); 0301 mainLayout->addWidget(checkbox); 0302 if (checkboxReturn) { 0303 checkbox->setChecked(*checkboxReturn); 0304 } 0305 } 0306 0307 QVBoxLayout *topLayout = new QVBoxLayout; 0308 dialog->setLayout(topLayout); 0309 topLayout->addWidget(mainWidget); 0310 0311 if (!details.isEmpty()) { 0312 QHBoxLayout *detailsHLayout = new QHBoxLayout(); 0313 detailsHLayout->addSpacing(2 * spacingHint + iconLayout->sizeHint().width()); 0314 KCollapsibleGroupBox *detailsGroup = new KCollapsibleGroupBox(); 0315 detailsGroup->setTitle(QApplication::translate("KMessageBox", "Details")); 0316 QVBoxLayout *detailsLayout = new QVBoxLayout(detailsGroup); 0317 if (details.length() < 512) { 0318 QLabel *detailsLabel = new QLabel(details); 0319 detailsLabel->setOpenExternalLinks(options & KMessageBox::AllowLink); 0320 Qt::TextInteractionFlags flags = Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard; 0321 if (options & KMessageBox::AllowLink) { 0322 flags |= Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard; 0323 }; 0324 detailsLabel->setTextInteractionFlags(flags); 0325 detailsLabel->setWordWrap(true); 0326 detailsLabel->setMinimumSize(detailsLabel->sizeHint()); 0327 detailsLayout->addWidget(detailsLabel, 50); 0328 } else { 0329 QTextBrowser *detailTextEdit = new QTextBrowser(); 0330 detailTextEdit->setText(details); 0331 detailTextEdit->setReadOnly(true); 0332 detailTextEdit->setMinimumHeight(detailTextEdit->fontMetrics().lineSpacing() * 11); 0333 detailsLayout->addWidget(detailTextEdit, 50); 0334 } 0335 if (!usingListWidget) { 0336 mainLayout->setStretchFactor(hLayout, 10); 0337 } 0338 detailsHLayout->addWidget(detailsGroup); 0339 topLayout->addLayout(detailsHLayout); 0340 buttonsHelper->setDetailsWidget(detailsGroup); 0341 } 0342 0343 topLayout->addWidget(buttons); 0344 topLayout->setSizeConstraint(QLayout::SetFixedSize); 0345 0346 if (!usingListWidget && !usingScrollArea && !usingSqueezedTextLabel && details.isEmpty()) { 0347 dialog->setFixedSize(dialog->sizeHint() + QSize(10, 10)); 0348 } 0349 0350 if ((options & KMessageBox::Dangerous)) { 0351 QPushButton *cancelButton = buttons->button(QDialogButtonBox::Cancel); 0352 QPushButton *noButton = buttons->button(QDialogButtonBox::No); 0353 0354 if (cancelButton && cancelButton->isEnabled()) { 0355 cancelButton->setDefault(true); 0356 cancelButton->setFocus(); 0357 } else if (noButton && noButton->isEnabled()) { 0358 noButton->setDefault(true); 0359 noButton->setFocus(); 0360 } 0361 } 0362 0363 #ifndef Q_OS_WIN // FIXME problems with KNotify on Windows 0364 if ((options & KMessageBox::Notify)) { 0365 QString message = text; 0366 if (!strlist.isEmpty()) { 0367 message += QLatin1Char('\n') + strlist.join(QLatin1Char('\n')); 0368 } 0369 notifyInterface()->sendNotification(notifyType, message, dialog->topLevelWidget()); 0370 } 0371 #endif 0372 0373 if (KMessageBox_exec_hook) { 0374 return KMessageBox_exec_hook(dialog); 0375 } 0376 0377 if ((options & KMessageBox::NoExec)) { 0378 return QDialogButtonBox::NoButton; // We have to return something. 0379 } 0380 0381 // We use a QPointer because the dialog may get deleted 0382 // during exec() if the parent of the dialog gets deleted. 0383 // In that case the QPointer will reset to 0. 0384 QPointer<QDialog> guardedDialog = dialog; 0385 0386 const QDialogButtonBox::StandardButton result = QDialogButtonBox::StandardButton(guardedDialog->exec()); 0387 if (checkbox && checkboxReturn) { 0388 *checkboxReturn = checkbox->isChecked(); 0389 } 0390 0391 delete guardedDialog; 0392 return result; 0393 } 0394 0395 ButtonCode questionYesNo(QWidget *parent, const QString &text, 0396 const QString &caption, 0397 const KGuiItem &buttonYes, 0398 const KGuiItem &buttonNo, 0399 const QString &dontAskAgainName, 0400 Options options) 0401 { 0402 return questionYesNoList(parent, text, QStringList(), caption, 0403 buttonYes, buttonNo, dontAskAgainName, options); 0404 } 0405 0406 bool shouldBeShownYesNo(const QString &dontShowAgainName, 0407 ButtonCode &result) 0408 { 0409 if (dontShowAgainName.isEmpty()) { 0410 return true; 0411 } 0412 return dontAskAgainInterface()->shouldBeShownYesNo(dontShowAgainName, result); 0413 } 0414 0415 bool shouldBeShownContinue(const QString &dontShowAgainName) 0416 { 0417 if (dontShowAgainName.isEmpty()) { 0418 return true; 0419 } 0420 return dontAskAgainInterface()->shouldBeShownContinue(dontShowAgainName); 0421 } 0422 0423 void saveDontShowAgainYesNo(const QString &dontShowAgainName, 0424 ButtonCode result) 0425 { 0426 if (dontShowAgainName.isEmpty()) { 0427 return; 0428 } 0429 dontAskAgainInterface()->saveDontShowAgainYesNo(dontShowAgainName, result); 0430 } 0431 0432 void saveDontShowAgainContinue(const QString &dontShowAgainName) 0433 { 0434 if (dontShowAgainName.isEmpty()) { 0435 return; 0436 } 0437 dontAskAgainInterface()->saveDontShowAgainContinue(dontShowAgainName); 0438 } 0439 0440 void enableAllMessages() 0441 { 0442 dontAskAgainInterface()->enableAllMessages(); 0443 } 0444 0445 void enableMessage(const QString &dontShowAgainName) 0446 { 0447 dontAskAgainInterface()->enableMessage(dontShowAgainName); 0448 } 0449 0450 void setDontShowAgainConfig(KConfig *cfg) 0451 { 0452 dontAskAgainInterface()->setConfig(cfg); 0453 } 0454 0455 static ButtonCode questionYesNoListInternal(QDialog *dialog, const QString &text, 0456 const QStringList &strlist, 0457 const QString &caption, 0458 const KGuiItem &buttonYes_, 0459 const KGuiItem &buttonNo_, 0460 const QString &dontAskAgainName, 0461 Options options) 0462 { 0463 ButtonCode res; 0464 if (!shouldBeShownYesNo(dontAskAgainName, res)) { 0465 delete dialog; 0466 return res; 0467 } 0468 0469 I18N_FILTER_BUTTON_YES(buttonYes_, buttonYes) 0470 I18N_FILTER_BUTTON_NO(buttonNo_, buttonNo) 0471 I18N_POST_BUTTON_FILTER 0472 0473 dialog->setWindowTitle(caption.isEmpty() ? QApplication::translate("KMessageBox", "Question") : caption); 0474 dialog->setObjectName(QStringLiteral("questionYesNo")); 0475 0476 QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); 0477 buttonBox->setStandardButtons(QDialogButtonBox::Yes | QDialogButtonBox::No); 0478 KGuiItem::assign(buttonBox->button(QDialogButtonBox::Yes), buttonYes); 0479 KGuiItem::assign(buttonBox->button(QDialogButtonBox::No), buttonNo); 0480 0481 applyOptions(dialog, options); 0482 0483 bool checkboxResult = false; 0484 const int result = createKMessageBox(dialog, buttonBox, QMessageBox::Question, text, strlist, 0485 dontAskAgainName.isEmpty() ? QString() : QApplication::translate("KMessageBox", "Do not ask again"), 0486 &checkboxResult, options); 0487 res = (result == QDialogButtonBox::Yes ? Yes : No); 0488 0489 if (checkboxResult) { 0490 saveDontShowAgainYesNo(dontAskAgainName, res); 0491 } 0492 return res; 0493 } 0494 0495 ButtonCode questionYesNoList(QWidget *parent, const QString &text, 0496 const QStringList &strlist, 0497 const QString &caption, 0498 const KGuiItem &buttonYes, 0499 const KGuiItem &buttonNo, 0500 const QString &dontAskAgainName, 0501 Options options) 0502 { 0503 return questionYesNoListInternal(new QDialog(parent), text, strlist, caption, buttonYes, buttonNo, 0504 dontAskAgainName, options); 0505 } 0506 0507 static ButtonCode questionYesNoCancelInternal(QDialog *dialog, 0508 const QString &text, 0509 const QString &caption, 0510 const KGuiItem &buttonYes_, 0511 const KGuiItem &buttonNo_, 0512 const KGuiItem &buttonCancel_, 0513 const QString &dontAskAgainName, 0514 Options options) 0515 { 0516 ButtonCode res; 0517 if (!shouldBeShownYesNo(dontAskAgainName, res)) { 0518 delete dialog; 0519 return res; 0520 } 0521 0522 I18N_FILTER_BUTTON_YES(buttonYes_, buttonYes) 0523 I18N_FILTER_BUTTON_NO(buttonNo_, buttonNo) 0524 I18N_FILTER_BUTTON_CANCEL(buttonCancel_, buttonCancel) 0525 I18N_POST_BUTTON_FILTER 0526 0527 dialog->setWindowTitle(caption.isEmpty() ? QApplication::translate("KMessageBox", "Question") : caption); 0528 dialog->setObjectName(QStringLiteral("questionYesNoCancel")); 0529 0530 QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); 0531 buttonBox->setStandardButtons(QDialogButtonBox::Yes | QDialogButtonBox::No | QDialogButtonBox::Cancel); 0532 KGuiItem::assign(buttonBox->button(QDialogButtonBox::Yes), buttonYes); 0533 KGuiItem::assign(buttonBox->button(QDialogButtonBox::No), buttonNo); 0534 KGuiItem::assign(buttonBox->button(QDialogButtonBox::Cancel), buttonCancel); 0535 0536 applyOptions(dialog, options); 0537 0538 bool checkboxResult = false; 0539 const int result = createKMessageBox(dialog, buttonBox, QMessageBox::Question, 0540 text, QStringList(), 0541 dontAskAgainName.isEmpty() ? QString() : QApplication::translate("KMessageBox", "Do not ask again"), 0542 &checkboxResult, options); 0543 0544 if (result == QDialogButtonBox::Yes) { 0545 res = Yes; 0546 } else if (result == QDialogButtonBox::No) { 0547 res = No; 0548 } else { 0549 return Cancel; 0550 } 0551 0552 if (checkboxResult) { 0553 saveDontShowAgainYesNo(dontAskAgainName, res); 0554 } 0555 return res; 0556 } 0557 0558 ButtonCode questionYesNoCancel(QWidget *parent, 0559 const QString &text, 0560 const QString &caption, 0561 const KGuiItem &buttonYes, 0562 const KGuiItem &buttonNo, 0563 const KGuiItem &buttonCancel, 0564 const QString &dontAskAgainName, 0565 Options options) 0566 { 0567 return questionYesNoCancelInternal(new QDialog(parent), text, caption, buttonYes, buttonNo, buttonCancel, 0568 dontAskAgainName, options); 0569 } 0570 0571 ButtonCode warningYesNo(QWidget *parent, const QString &text, 0572 const QString &caption, 0573 const KGuiItem &buttonYes, 0574 const KGuiItem &buttonNo, 0575 const QString &dontAskAgainName, 0576 Options options) 0577 { 0578 return warningYesNoList(parent, text, QStringList(), caption, 0579 buttonYes, buttonNo, dontAskAgainName, options); 0580 } 0581 0582 static ButtonCode warningYesNoListInternal(QDialog *dialog, const QString &text, 0583 const QStringList &strlist, 0584 const QString &caption, 0585 const KGuiItem &buttonYes_, 0586 const KGuiItem &buttonNo_, 0587 const QString &dontAskAgainName, 0588 Options options) 0589 { 0590 ButtonCode res; 0591 if (!shouldBeShownYesNo(dontAskAgainName, res)) { 0592 delete dialog; 0593 return res; 0594 } 0595 0596 I18N_FILTER_BUTTON_YES(buttonYes_, buttonYes) 0597 I18N_FILTER_BUTTON_NO(buttonNo_, buttonNo) 0598 I18N_POST_BUTTON_FILTER 0599 0600 dialog->setWindowTitle(caption.isEmpty() ? QApplication::translate("KMessageBox", "Warning") : caption); 0601 dialog->setObjectName(QStringLiteral("warningYesNoList")); 0602 0603 QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); 0604 buttonBox->setStandardButtons(QDialogButtonBox::Yes | QDialogButtonBox::No); 0605 KGuiItem::assign(buttonBox->button(QDialogButtonBox::Yes), buttonYes); 0606 KGuiItem::assign(buttonBox->button(QDialogButtonBox::No), buttonNo); 0607 0608 applyOptions(dialog, options); 0609 0610 bool checkboxResult = false; 0611 const int result = createKMessageBox(dialog, buttonBox, QMessageBox::Warning, text, strlist, 0612 dontAskAgainName.isEmpty() ? QString() : QApplication::translate("KMessageBox", "Do not ask again"), 0613 &checkboxResult, options); 0614 res = (result == QDialogButtonBox::Yes ? Yes : No); 0615 0616 if (checkboxResult) { 0617 saveDontShowAgainYesNo(dontAskAgainName, res); 0618 } 0619 return res; 0620 } 0621 0622 ButtonCode warningYesNoList(QWidget *parent, const QString &text, 0623 const QStringList &strlist, 0624 const QString &caption, 0625 const KGuiItem &buttonYes, 0626 const KGuiItem &buttonNo, 0627 const QString &dontAskAgainName, 0628 Options options) 0629 { 0630 return warningYesNoListInternal(new QDialog(parent), text, strlist, caption, buttonYes, buttonNo, 0631 dontAskAgainName, options); 0632 } 0633 0634 ButtonCode warningContinueCancel(QWidget *parent, 0635 const QString &text, 0636 const QString &caption, 0637 const KGuiItem &buttonContinue, 0638 const KGuiItem &buttonCancel, 0639 const QString &dontAskAgainName, 0640 Options options) 0641 { 0642 return warningContinueCancelList(parent, text, QStringList(), caption, 0643 buttonContinue, buttonCancel, dontAskAgainName, options); 0644 } 0645 0646 static ButtonCode warningContinueCancelListInternal(QDialog *dialog, const QString &text, 0647 const QStringList &strlist, 0648 const QString &caption, 0649 const KGuiItem &buttonContinue_, 0650 const KGuiItem &buttonCancel_, 0651 const QString &dontAskAgainName, 0652 Options options, 0653 const QString &details) 0654 { 0655 if (!shouldBeShownContinue(dontAskAgainName)) { 0656 delete dialog; 0657 return Continue; 0658 } 0659 0660 I18N_FILTER_BUTTON_CONTINUE(buttonContinue_, buttonContinue) 0661 I18N_FILTER_BUTTON_CANCEL(buttonCancel_, buttonCancel) 0662 I18N_POST_BUTTON_FILTER 0663 0664 dialog->setWindowTitle(caption.isEmpty() ? QApplication::translate("KMessageBox", "Warning") : caption); 0665 dialog->setObjectName(QStringLiteral("warningYesNo")); 0666 0667 QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); 0668 buttonBox->setStandardButtons(QDialogButtonBox::Yes | QDialogButtonBox::No); 0669 KGuiItem::assign(buttonBox->button(QDialogButtonBox::Yes), buttonContinue); 0670 KGuiItem::assign(buttonBox->button(QDialogButtonBox::No), buttonCancel); 0671 0672 applyOptions(dialog, options); 0673 0674 bool checkboxResult = false; 0675 const int result = createKMessageBox(dialog, buttonBox, QMessageBox::Warning, text, strlist, 0676 dontAskAgainName.isEmpty() ? QString() : QApplication::translate("KMessageBox", "Do not ask again"), 0677 &checkboxResult, options, details); 0678 0679 if (result != QDialogButtonBox::Yes) { 0680 return Cancel; 0681 } 0682 if (checkboxResult) { 0683 saveDontShowAgainContinue(dontAskAgainName); 0684 } 0685 return Continue; 0686 } 0687 0688 ButtonCode warningContinueCancelList(QWidget *parent, const QString &text, 0689 const QStringList &strlist, 0690 const QString &caption, 0691 const KGuiItem &buttonContinue, 0692 const KGuiItem &buttonCancel, 0693 const QString &dontAskAgainName, 0694 Options options) 0695 { 0696 return warningContinueCancelListInternal(new QDialog(parent), text, strlist, caption, buttonContinue, buttonCancel, 0697 dontAskAgainName, options, QString()); 0698 } 0699 0700 0701 ButtonCode warningContinueCancelDetailed(QWidget *parent, 0702 const QString &text, 0703 const QString &caption, 0704 const KGuiItem &buttonContinue, 0705 const KGuiItem &buttonCancel, 0706 const QString &dontAskAgainName, 0707 Options options, 0708 const QString &details) 0709 { 0710 return warningContinueCancelListInternal(new QDialog(parent), text, QStringList(), caption, 0711 buttonContinue, buttonCancel, dontAskAgainName, options, details); 0712 } 0713 0714 ButtonCode warningYesNoCancel(QWidget *parent, const QString &text, 0715 const QString &caption, 0716 const KGuiItem &buttonYes, 0717 const KGuiItem &buttonNo, 0718 const KGuiItem &buttonCancel, 0719 const QString &dontAskAgainName, 0720 Options options) 0721 { 0722 return warningYesNoCancelList(parent, text, QStringList(), caption, 0723 buttonYes, buttonNo, buttonCancel, dontAskAgainName, options); 0724 } 0725 0726 static ButtonCode warningYesNoCancelListInternal(QDialog *dialog, const QString &text, 0727 const QStringList &strlist, 0728 const QString &caption, 0729 const KGuiItem &buttonYes_, 0730 const KGuiItem &buttonNo_, 0731 const KGuiItem &buttonCancel_, 0732 const QString &dontAskAgainName, 0733 Options options) 0734 { 0735 ButtonCode res; 0736 if (!shouldBeShownYesNo(dontAskAgainName, res)) { 0737 delete dialog; 0738 return res; 0739 } 0740 0741 I18N_FILTER_BUTTON_YES(buttonYes_, buttonYes) 0742 I18N_FILTER_BUTTON_NO(buttonNo_, buttonNo) 0743 I18N_FILTER_BUTTON_CANCEL(buttonCancel_, buttonCancel) 0744 I18N_POST_BUTTON_FILTER 0745 0746 dialog->setWindowTitle(caption.isEmpty() ? QApplication::translate("KMessageBox", "Warning") : caption); 0747 dialog->setObjectName(QStringLiteral("warningYesNoCancel")); 0748 0749 QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); 0750 buttonBox->setStandardButtons(QDialogButtonBox::Yes | QDialogButtonBox::No | QDialogButtonBox::Cancel); 0751 KGuiItem::assign(buttonBox->button(QDialogButtonBox::Yes), buttonYes); 0752 KGuiItem::assign(buttonBox->button(QDialogButtonBox::No), buttonNo); 0753 KGuiItem::assign(buttonBox->button(QDialogButtonBox::Cancel), buttonCancel); 0754 0755 applyOptions(dialog, options); 0756 0757 bool checkboxResult = false; 0758 const int result = createKMessageBox(dialog, buttonBox, QMessageBox::Warning, text, strlist, 0759 dontAskAgainName.isEmpty() ? QString() : QApplication::translate("KMessageBox", "Do not ask again"), 0760 &checkboxResult, options); 0761 0762 if (result == QDialogButtonBox::Yes) { 0763 res = Yes; 0764 } else if (result == QDialogButtonBox::No) { 0765 res = No; 0766 } else { 0767 return Cancel; 0768 } 0769 0770 if (checkboxResult) { 0771 saveDontShowAgainYesNo(dontAskAgainName, res); 0772 } 0773 return res; 0774 } 0775 0776 ButtonCode warningYesNoCancelList(QWidget *parent, const QString &text, 0777 const QStringList &strlist, 0778 const QString &caption, 0779 const KGuiItem &buttonYes, 0780 const KGuiItem &buttonNo, 0781 const KGuiItem &buttonCancel, 0782 const QString &dontAskAgainName, 0783 Options options) 0784 { 0785 return warningYesNoCancelListInternal(new QDialog(parent), text, strlist, caption, buttonYes, buttonNo, buttonCancel, 0786 dontAskAgainName, options); 0787 } 0788 0789 void error(QWidget *parent, const QString &text, 0790 const QString &caption, Options options) 0791 { 0792 errorList(parent, text, QStringList(), caption, options); 0793 } 0794 0795 static void errorListInternal(QDialog *dialog, const QString &text, const QStringList &strlist, 0796 const QString &caption, Options options) 0797 { 0798 dialog->setWindowTitle(caption.isEmpty() ? QApplication::translate("KMessageBox", "Error") : caption); 0799 dialog->setObjectName(QStringLiteral("error")); 0800 0801 QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); 0802 buttonBox->setStandardButtons(QDialogButtonBox::Ok); 0803 0804 applyOptions(dialog, options); 0805 0806 createKMessageBox(dialog, buttonBox, QMessageBox::Critical, text, strlist, QString(), nullptr, options); 0807 } 0808 0809 void errorList(QWidget *parent, const QString &text, const QStringList &strlist, 0810 const QString &caption, Options options) 0811 { 0812 errorListInternal(new QDialog(parent), text, strlist, caption, options); 0813 } 0814 0815 static void detailedErrorInternal(QDialog *dialog, const QString &text, 0816 const QString &details, 0817 const QString &caption, Options options) 0818 { 0819 dialog->setWindowTitle(caption.isEmpty() ? QApplication::translate("KMessageBox", "Error") : caption); 0820 dialog->setObjectName(QStringLiteral("error")); 0821 0822 QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); 0823 buttonBox->addButton(QDialogButtonBox::Ok); 0824 buttonBox->button(QDialogButtonBox::Ok)->setFocus(); 0825 0826 applyOptions(dialog, options); 0827 0828 createKMessageBox(dialog, buttonBox, QMessageBox::Critical, text, QStringList(), QString(), nullptr, options, details); 0829 } 0830 0831 void detailedError(QWidget *parent, const QString &text, 0832 const QString &details, 0833 const QString &caption, Options options) 0834 { 0835 detailedErrorInternal(new QDialog(parent), text, details, caption, options); 0836 } 0837 0838 static void sorryInternal(QDialog *dialog, const QString &text, 0839 const QString &caption, 0840 const KGuiItem &buttonOk_, 0841 Options options) 0842 { 0843 I18N_FILTER_BUTTON_YES(buttonOk_, buttonOk) 0844 I18N_POST_BUTTON_FILTER 0845 0846 dialog->setWindowTitle(caption.isEmpty() ? QApplication::translate("KMessageBox", "Sorry") : caption); 0847 dialog->setObjectName(QStringLiteral("sorry")); 0848 0849 QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); 0850 buttonBox->setStandardButtons(QDialogButtonBox::Ok); 0851 KGuiItem::assign(buttonBox->button(QDialogButtonBox::Ok), buttonOk); 0852 0853 applyOptions(dialog, options); 0854 0855 createKMessageBox(dialog, buttonBox, QMessageBox::Warning, text, QStringList(), QString(), nullptr, options); 0856 } 0857 0858 void sorry(QWidget *parent, const QString &text, 0859 const QString &caption, Options options) 0860 { 0861 sorryInternal(new QDialog(parent), text, caption, KStandardGuiItem::ok(), options); 0862 } 0863 0864 void sorry(QWidget *parent, const QString &text, 0865 const QString &caption, const KGuiItem &item, Options options) 0866 { 0867 sorryInternal(new QDialog(parent), text, caption, item, options); 0868 } 0869 0870 static void detailedSorryInternal(QDialog *dialog, const QString &text, 0871 const QString &details, 0872 const QString &caption, 0873 const KGuiItem &buttonOk_, 0874 Options options) 0875 { 0876 I18N_FILTER_BUTTON_YES(buttonOk_, buttonOk) 0877 I18N_POST_BUTTON_FILTER 0878 0879 dialog->setWindowTitle(caption.isEmpty() ? QApplication::translate("KMessageBox", "Sorry") : caption); 0880 dialog->setObjectName(QStringLiteral("sorry")); 0881 0882 QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); 0883 buttonBox->addButton(QDialogButtonBox::Ok); 0884 buttonBox->button(QDialogButtonBox::Ok)->setFocus(); 0885 KGuiItem::assign(buttonBox->button(QDialogButtonBox::Ok), buttonOk); 0886 0887 applyOptions(dialog, options); 0888 0889 createKMessageBox(dialog, buttonBox, QMessageBox::Warning, text, QStringList(), QString(), nullptr, options, details); 0890 } 0891 0892 void detailedSorry(QWidget *parent, const QString &text, 0893 const QString &details, 0894 const QString &caption, Options options) 0895 { 0896 detailedSorryInternal(new QDialog(parent), text, details, caption, KStandardGuiItem::ok(), options); 0897 } 0898 0899 void detailedSorry(QWidget *parent, const QString &text, 0900 const QString &details, 0901 const QString &caption, 0902 const KGuiItem &buttonOk, 0903 Options options) 0904 { 0905 detailedSorryInternal(new QDialog(parent), text, details, caption, buttonOk, options); 0906 } 0907 0908 void information(QWidget *parent, const QString &text, 0909 const QString &caption, const QString &dontShowAgainName, Options options) 0910 { 0911 informationList(parent, text, QStringList(), caption, dontShowAgainName, options); 0912 } 0913 0914 static void informationListInternal(QDialog *dialog, const QString &text, const QStringList &strlist, 0915 const QString &caption, const QString &dontShowAgainName, Options options) 0916 { 0917 if (!shouldBeShownContinue(dontShowAgainName)) { 0918 delete dialog; 0919 return; 0920 } 0921 0922 dialog->setWindowTitle(caption.isEmpty() ? QApplication::translate("KMessageBox", "Information") : caption); 0923 dialog->setObjectName(QStringLiteral("information")); 0924 0925 QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); 0926 buttonBox->setStandardButtons(QDialogButtonBox::Ok); 0927 0928 applyOptions(dialog, options); 0929 0930 bool checkboxResult = false; 0931 0932 createKMessageBox(dialog, buttonBox, QMessageBox::Information, text, strlist, 0933 dontShowAgainName.isEmpty() ? QString() : QApplication::translate("KMessageBox", "Do not show this message again"), 0934 &checkboxResult, options); 0935 0936 if (checkboxResult) { 0937 saveDontShowAgainContinue(dontShowAgainName); 0938 } 0939 } 0940 0941 void informationList(QWidget *parent, const QString &text, const QStringList &strlist, 0942 const QString &caption, const QString &dontShowAgainName, Options options) 0943 { 0944 informationListInternal(new QDialog(parent), text, strlist, caption, dontShowAgainName, options); 0945 } 0946 0947 void about(QWidget *parent, const QString &text, 0948 const QString &caption, Options options) 0949 { 0950 QDialog *dialog = new QDialog(parent, Qt::Dialog); 0951 if (!caption.isEmpty()) { 0952 dialog->setWindowTitle(caption); 0953 } 0954 dialog->setObjectName(QStringLiteral("about")); 0955 0956 QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); 0957 buttonBox->setStandardButtons(QDialogButtonBox::Ok); 0958 0959 applyOptions(dialog, options); 0960 0961 if (qApp->windowIcon().isNull()) { 0962 QPixmap ret = QMessageBox::standardIcon(QMessageBox::Information); 0963 dialog->setWindowIcon(ret); 0964 } 0965 0966 createKMessageBox(dialog, buttonBox, qApp->windowIcon(), text, QStringList(), QString(), nullptr, options); 0967 } 0968 0969 static ButtonCode messageBoxInternal(QDialog *dialog, DialogType type, const QString &text, 0970 const QString &caption, const KGuiItem &buttonYes, 0971 const KGuiItem &buttonNo, const KGuiItem &buttonCancel, 0972 const QString &dontShow, Options options) 0973 { 0974 switch (type) { 0975 case QuestionYesNo: 0976 return questionYesNoListInternal(dialog, text, QStringList(), caption, 0977 buttonYes, buttonNo, dontShow, options); 0978 case QuestionYesNoCancel: 0979 return questionYesNoCancelInternal(dialog, text, caption, 0980 buttonYes, buttonNo, buttonCancel, dontShow, options); 0981 case WarningYesNo: 0982 return warningYesNoListInternal(dialog, text, QStringList(), caption, 0983 buttonYes, buttonNo, dontShow, options); 0984 case WarningContinueCancel: 0985 return warningContinueCancelListInternal(dialog, text, QStringList(), caption, 0986 KGuiItem(buttonYes.text()), buttonCancel, dontShow, options, QString()); 0987 case WarningYesNoCancel: 0988 return warningYesNoCancelListInternal(dialog, text, QStringList(), caption, 0989 buttonYes, buttonNo, buttonCancel, dontShow, options); 0990 case Information: 0991 informationListInternal(dialog, text, QStringList(), caption, dontShow, options); 0992 return KMessageBox::Ok; 0993 0994 case Error: 0995 errorListInternal(dialog, text, QStringList(), caption, options); 0996 return KMessageBox::Ok; 0997 0998 case Sorry: 0999 sorryInternal(dialog, text, caption, KStandardGuiItem::ok(), options); 1000 return KMessageBox::Ok; 1001 } 1002 return KMessageBox::Cancel; 1003 } 1004 1005 ButtonCode messageBox(QWidget *parent, DialogType type, const QString &text, 1006 const QString &caption, const KGuiItem &buttonYes, 1007 const KGuiItem &buttonNo, const KGuiItem &buttonCancel, 1008 const QString &dontShow, Options options) 1009 { 1010 return messageBoxInternal(new QDialog(parent), type, text, caption, 1011 buttonYes, buttonNo, buttonCancel, dontShow, options); 1012 } 1013 1014 ButtonCode questionYesNoWId(WId parent_id, const QString &text, 1015 const QString &caption, 1016 const KGuiItem &buttonYes, 1017 const KGuiItem &buttonNo, 1018 const QString &dontAskAgainName, 1019 Options options) 1020 { 1021 return questionYesNoListWId(parent_id, text, QStringList(), caption, 1022 buttonYes, buttonNo, dontAskAgainName, options); 1023 } 1024 1025 ButtonCode questionYesNoListWId(WId parent_id, const QString &text, 1026 const QStringList &strlist, 1027 const QString &caption, 1028 const KGuiItem &buttonYes, 1029 const KGuiItem &buttonNo, 1030 const QString &dontAskAgainName, 1031 Options options) 1032 { 1033 return questionYesNoListInternal(createWIdDialog(parent_id), text, strlist, caption, buttonYes, buttonNo, 1034 dontAskAgainName, options); 1035 } 1036 1037 ButtonCode questionYesNoCancelWId(WId parent_id, 1038 const QString &text, 1039 const QString &caption, 1040 const KGuiItem &buttonYes, 1041 const KGuiItem &buttonNo, 1042 const KGuiItem &buttonCancel, 1043 const QString &dontAskAgainName, 1044 Options options) 1045 { 1046 return questionYesNoCancelInternal(createWIdDialog(parent_id), text, caption, buttonYes, buttonNo, buttonCancel, 1047 dontAskAgainName, options); 1048 } 1049 1050 ButtonCode warningYesNoWId(WId parent_id, const QString &text, 1051 const QString &caption, 1052 const KGuiItem &buttonYes, 1053 const KGuiItem &buttonNo, 1054 const QString &dontAskAgainName, 1055 Options options) 1056 { 1057 return warningYesNoListWId(parent_id, text, QStringList(), caption, 1058 buttonYes, buttonNo, dontAskAgainName, options); 1059 } 1060 1061 ButtonCode warningYesNoListWId(WId parent_id, const QString &text, 1062 const QStringList &strlist, 1063 const QString &caption, 1064 const KGuiItem &buttonYes, 1065 const KGuiItem &buttonNo, 1066 const QString &dontAskAgainName, 1067 Options options) 1068 { 1069 return warningYesNoListInternal(createWIdDialog(parent_id), text, strlist, caption, buttonYes, buttonNo, 1070 dontAskAgainName, options); 1071 } 1072 1073 ButtonCode warningContinueCancelWId(WId parent_id, 1074 const QString &text, 1075 const QString &caption, 1076 const KGuiItem &buttonContinue, 1077 const KGuiItem &buttonCancel, 1078 const QString &dontAskAgainName, 1079 Options options) 1080 { 1081 return warningContinueCancelListWId(parent_id, text, QStringList(), caption, 1082 buttonContinue, buttonCancel, dontAskAgainName, options); 1083 } 1084 1085 ButtonCode warningContinueCancelListWId(WId parent_id, const QString &text, 1086 const QStringList &strlist, 1087 const QString &caption, 1088 const KGuiItem &buttonContinue, 1089 const KGuiItem &buttonCancel, 1090 const QString &dontAskAgainName, 1091 Options options) 1092 { 1093 return warningContinueCancelListInternal(createWIdDialog(parent_id), text, strlist, caption, buttonContinue, buttonCancel, 1094 dontAskAgainName, options, QString()); 1095 } 1096 1097 ButtonCode warningYesNoCancelWId(WId parent_id, const QString &text, 1098 const QString &caption, 1099 const KGuiItem &buttonYes, 1100 const KGuiItem &buttonNo, 1101 const KGuiItem &buttonCancel, 1102 const QString &dontAskAgainName, 1103 Options options) 1104 { 1105 return warningYesNoCancelListWId(parent_id, text, QStringList(), caption, 1106 buttonYes, buttonNo, buttonCancel, dontAskAgainName, options); 1107 } 1108 1109 ButtonCode warningYesNoCancelListWId(WId parent_id, const QString &text, 1110 const QStringList &strlist, 1111 const QString &caption, 1112 const KGuiItem &buttonYes, 1113 const KGuiItem &buttonNo, 1114 const KGuiItem &buttonCancel, 1115 const QString &dontAskAgainName, 1116 Options options) 1117 { 1118 return warningYesNoCancelList(createWIdDialog(parent_id), text, strlist, caption, buttonYes, buttonNo, buttonCancel, 1119 dontAskAgainName, options); 1120 } 1121 1122 void errorWId(WId parent_id, const QString &text, 1123 const QString &caption, Options options) 1124 { 1125 errorListWId(parent_id, text, QStringList(), caption, options); 1126 } 1127 1128 void errorListWId(WId parent_id, const QString &text, const QStringList &strlist, 1129 const QString &caption, Options options) 1130 { 1131 errorListInternal(createWIdDialog(parent_id), text, strlist, caption, options); 1132 } 1133 1134 void detailedErrorWId(WId parent_id, const QString &text, 1135 const QString &details, 1136 const QString &caption, Options options) 1137 { 1138 detailedErrorInternal(createWIdDialog(parent_id), text, details, caption, options); 1139 } 1140 1141 void sorryWId(WId parent_id, const QString &text, 1142 const QString &caption, Options options) 1143 { 1144 QWidget *parent = QWidget::find(parent_id); 1145 QDialog *dialog = new QDialog(parent, Qt::Dialog); 1146 dialog->setWindowTitle(caption.isEmpty() ? QApplication::translate("KMessageBox", "Sorry") : caption); 1147 dialog->setObjectName(QStringLiteral("sorry")); 1148 1149 QDialogButtonBox *buttonBox = new QDialogButtonBox(dialog); 1150 buttonBox->setStandardButtons(QDialogButtonBox::Ok); 1151 1152 applyOptions(dialog, options); 1153 if (parent == nullptr && parent_id) { 1154 setMainWindow(dialog, parent_id); 1155 } 1156 1157 createKMessageBox(dialog, buttonBox, QMessageBox::Warning, text, QStringList(), QString(), nullptr, options); 1158 } 1159 1160 void detailedSorryWId(WId parent_id, const QString &text, 1161 const QString &details, 1162 const QString &caption, Options options) 1163 { 1164 detailedSorryInternal(createWIdDialog(parent_id), text, details, caption, KStandardGuiItem::ok(), options); 1165 } 1166 1167 void detailedSorryWId(WId parent_id, const QString &text, 1168 const QString &details, 1169 const QString &caption, 1170 const KGuiItem &buttonOk, 1171 Options options) 1172 { 1173 detailedSorryInternal(createWIdDialog(parent_id), text, details, caption, buttonOk, options); 1174 } 1175 1176 void informationWId(WId parent_id, const QString &text, 1177 const QString &caption, const QString &dontShowAgainName, Options options) 1178 { 1179 informationListWId(parent_id, text, QStringList(), caption, dontShowAgainName, options); 1180 } 1181 1182 void informationListWId(WId parent_id, const QString &text, const QStringList &strlist, 1183 const QString &caption, const QString &dontShowAgainName, Options options) 1184 { 1185 informationListInternal(createWIdDialog(parent_id), text, strlist, caption, dontShowAgainName, options); 1186 } 1187 1188 ButtonCode messageBoxWId(WId parent_id, DialogType type, const QString &text, 1189 const QString &caption, const KGuiItem &buttonYes, 1190 const KGuiItem &buttonNo, const KGuiItem &buttonCancel, 1191 const QString &dontShow, Options options) 1192 { 1193 return messageBoxInternal(createWIdDialog(parent_id), type, text, caption, 1194 buttonYes, buttonNo, buttonCancel, dontShow, options); 1195 } 1196 1197 } // namespace 1198 1199 #include "kmessagebox.moc"