22 #include <QtCore/QPointer>
23 #include <QtGui/QCheckBox>
24 #include <QtGui/QGroupBox>
25 #include <QtGui/QLabel>
26 #include <QtGui/QLayout>
27 #include <QtGui/QListWidget>
28 #include <QtGui/QScrollArea>
29 #include <QtGui/QScrollBar>
30 #include <QtGui/QTextDocumentFragment>
35 #include <kdialogqueue_p.h>
50 #define I18N_FILTER_BUTTON_YES(src, dst) \
52 dst.setText( i18nc( "@action:button filter-yes", "%1", src.text() ) );
56 #define I18N_FILTER_BUTTON_NO(src, dst) \
58 dst.setText( i18nc( "@action:button filter-no", "%1", src.text() ) );
62 #define I18N_FILTER_BUTTON_CONTINUE(src, dst) \
64 dst.setText( i18nc( "@action:button filter-continue", "%1", src.text() ) );
68 #define I18N_FILTER_BUTTON_CANCEL(src, dst) \
70 dst.setText( i18nc( "@action:button filter-cancel", "%1", src.text() ) );
74 #define I18N_POST_BUTTON_FILTER \
75 i18nc( "@action:button post-filter", "." );
86 case QMessageBox::NoIcon:
89 case QMessageBox::Information:
90 icon_name =
"dialog-information";
92 case QMessageBox::Warning:
93 icon_name =
"dialog-warning";
95 case QMessageBox::Critical:
96 icon_name =
"dialog-error";
105 return QMessageBox::standardIcon(icon);
113 QMessageBox::Icon icon,
119 case QMessageBox::Warning:
120 messageType =
"messageWarning";
122 case QMessageBox::Critical:
123 messageType =
"messageCritical";
125 case QMessageBox::Question:
126 messageType =
"messageQuestion";
129 messageType =
"messageInformation";
133 if ( !strlist.isEmpty() ) {
134 for ( QStringList::ConstIterator it = strlist.begin(); it != strlist.end(); ++it ) {
135 message +=
'\n' + *it;
139 if ( !message.isEmpty() ) {
148 dialog->setWindowModality( Qt::WindowModal );
150 dialog->setModal(
true );
155 const QString &ask,
bool *checkboxReturn,
156 Options options,
const QString &details)
159 ask, checkboxReturn, options, details, icon);
165 const QString &ask,
bool *checkboxReturn, Options options,
166 const QString &details, QMessageBox::Icon notifyType)
169 QVBoxLayout *mainLayout =
new QVBoxLayout(mainWidget);
171 mainLayout->setMargin(0);
173 QHBoxLayout *hLayout =
new QHBoxLayout();
174 hLayout->setMargin(0);
175 hLayout->setSpacing(-1);
176 mainLayout->addLayout(hLayout,5);
180 if (!icon.isNull()) {
182 option.initFrom(mainWidget);
183 iconLabel->setPixmap(icon.pixmap(mainWidget->style()->pixelMetric(QStyle::PM_MessageBoxIconSize, &option, mainWidget)));
186 QVBoxLayout *iconLayout =
new QVBoxLayout();
187 iconLayout->addStretch(1);
188 iconLayout->addWidget(iconLabel);
189 iconLayout->addStretch(5);
191 hLayout->addLayout(iconLayout,0);
196 Qt::TextInteractionFlags flags = Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard;
197 if (options & KMessageBox::AllowLink) {
198 flags |= Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard;
200 messageLabel->setTextInteractionFlags(flags);
203 bool usingSqueezedTextLabel =
false;
204 if (messageLabel->sizeHint().width() > desktop.width() * 0.5) {
206 messageLabel->setWordWrap(
true);
208 usingSqueezedTextLabel = messageLabel->sizeHint().width() > desktop.width() * 0.85;
209 if (usingSqueezedTextLabel)
213 messageLabel->setOpenExternalLinks(options & KMessageBox::AllowLink);
214 messageLabel->setTextInteractionFlags(flags);
218 QPalette messagePal(messageLabel->palette());
219 messagePal.setColor(QPalette::Window, Qt::transparent);
220 messageLabel->setPalette(messagePal);
223 bool usingScrollArea=desktop.height() / 3 < messageLabel->sizeHint().height();
226 QScrollArea* messageScrollArea =
new QScrollArea(mainWidget);
227 messageScrollArea->setWidget(messageLabel);
228 messageScrollArea->setFrameShape(QFrame::NoFrame);
229 messageScrollArea->setWidgetResizable(
true);
230 QPalette scrollPal(messageScrollArea->palette());
231 scrollPal.setColor(QPalette::Window, Qt::transparent);
232 messageScrollArea->viewport()->setPalette(scrollPal);
233 hLayout->addWidget(messageScrollArea,5);
236 hLayout->addWidget(messageLabel,5);
239 const bool usingListWidget=!strlist.isEmpty();
240 if (usingListWidget) {
242 messageLabel->setWordWrap(
true);
244 listWidget->addItems(strlist);
246 QStyleOptionViewItem styleOption;
247 styleOption.initFrom(listWidget);
248 QFontMetrics fm(styleOption.font);
249 int w = listWidget->width();
250 Q_FOREACH(
const QString &str, strlist) {
251 w = qMax(w, fm.width(str));
253 const int borderWidth = listWidget->width() - listWidget->viewport()->width() + listWidget->verticalScrollBar()->height();
255 if (w > desktop.width() * 0.85) {
256 w = qRound(desktop.width() * 0.85);
258 listWidget->setMinimumWidth(w);
260 mainLayout->addWidget(listWidget,usingScrollArea?10:50);
261 listWidget->setSelectionMode(QListWidget::NoSelection);
262 messageLabel->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Minimum);
264 else if (!usingScrollArea)
265 mainLayout->addStretch(15);
268 QPointer<QCheckBox> checkbox = 0;
269 if (!ask.isEmpty()) {
270 checkbox =
new QCheckBox(ask, mainWidget);
271 mainLayout->addWidget(checkbox);
272 if (checkboxReturn) {
273 checkbox->setChecked(*checkboxReturn);
277 if (!details.isEmpty()) {
279 QVBoxLayout *detailsLayout =
new QVBoxLayout(detailsGroup);
280 if (details.length() < 512) {
282 detailsLabel->setOpenExternalLinks(options & KMessageBox::AllowLink);
283 Qt::TextInteractionFlags flags = Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard;
284 if ( options & KMessageBox::AllowLink )
285 flags |= Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard;;
286 detailsLabel->setTextInteractionFlags(flags);
287 detailsLabel->setWordWrap(
true);
288 detailsLayout->addWidget(detailsLabel,50);
292 detailTextEdit->setMinimumHeight(detailTextEdit->fontMetrics().lineSpacing() * 11);
293 detailsLayout->addWidget(detailTextEdit,50);
295 if (!usingListWidget)
296 mainLayout->setStretchFactor(hLayout,10);
301 if (!usingListWidget && !usingScrollArea && !usingSqueezedTextLabel && details.isEmpty())
303 else if (!details.isEmpty() && dialog->minimumHeight()<iconLabel->sizeHint().height()*2)
305 if (!usingScrollArea)
306 dialog->setMinimumSize(300,qMax(150,qMax(iconLabel->sizeHint().height(),messageLabel->sizeHint().height())));
308 dialog->setMinimumSize(300,qMax(150,iconLabel->sizeHint().height()));
324 #ifndef Q_WS_WIN // FIXME problems with KNotify on Windows
326 sendNotification(text, strlist, notifyType, dialog->topLevelWidget()->winId());
330 if (KMessageBox_queue) {
331 KDialogQueue::queueDialog(dialog);
342 QPointer<KDialog> guardedDialog = dialog;
344 const int result = guardedDialog->exec();
345 if (checkbox && checkboxReturn) {
346 *checkboxReturn = checkbox->isChecked();
349 delete (
KDialog *) guardedDialog;
357 const QString &dontAskAgainName,
361 buttonYes, buttonNo, dontAskAgainName, options);
368 const QString &dontAskAgainName,
372 buttonYes, buttonNo, dontAskAgainName, options);
378 if ( dontShowAgainName.isEmpty() ) {
383 if (dontAsk ==
"yes" || dontAsk ==
"true") {
387 if (dontAsk ==
"no" || dontAsk ==
"false") {
396 if ( dontShowAgainName.isEmpty() ) {
400 return cg.
readEntry(dontShowAgainName,
true);
406 if ( dontShowAgainName.isEmpty() ) {
410 if (dontShowAgainName[0] ==
':') {
420 if ( dontShowAgainName.isEmpty() ) {
424 if (dontShowAgainName[0] ==
':') {
428 cg.
writeEntry( dontShowAgainName,
false, flags );
434 KMessageBox_againConfig = cfg;
442 const QString &dontAskAgainName,
446 caption, buttonYes, buttonNo, dontAskAgainName, options );
454 const QString &dontAskAgainName,
468 dialog->
setCaption( caption.isEmpty() ?
i18n(
"Question") : caption );
470 dialog->setObjectName(
"questionYesNo" );
479 if ( parent == NULL && parent_id ) {
483 bool checkboxResult =
false;
484 const int result =
createKMessageBox(dialog, QMessageBox::Information, text, strlist,
485 dontAskAgainName.isEmpty() ?
QString() :
i18n(
"Do not ask again"),
486 &checkboxResult, options);
489 if (checkboxResult) {
501 const QString &dontAskAgainName,
504 return questionYesNoCancelWId( parent ? parent->effectiveWinId() : 0, text, caption, buttonYes, buttonNo, buttonCancel,
505 dontAskAgainName, options );
514 const QString &dontAskAgainName,
529 dialog->
setCaption( caption.isEmpty() ?
i18n(
"Question") : caption );
531 dialog->setObjectName(
"questionYesNoCancel" );
540 if ( parent == NULL && parent_id ) {
544 bool checkboxResult =
false;
547 dontAskAgainName.isEmpty() ?
QString() :
i18n(
"Do not ask again"),
548 &checkboxResult, options);
558 if (checkboxResult) {
568 const QString &dontAskAgainName,
572 buttonYes, buttonNo, dontAskAgainName, options);
579 const QString &dontAskAgainName,
583 buttonYes, buttonNo, dontAskAgainName, options);
591 const QString &dontAskAgainName,
595 buttonYes, buttonNo, dontAskAgainName, options );
603 const QString &dontAskAgainName,
617 dialog->
setCaption( caption.isEmpty() ?
i18n(
"Warning") : caption );
619 dialog->setObjectName(
"warningYesNoList" );
628 if ( parent == NULL && parent_id ) {
632 bool checkboxResult =
false;
633 const int result =
createKMessageBox(dialog, QMessageBox::Warning, text, strlist,
634 dontAskAgainName.isEmpty() ?
QString() :
i18n(
"Do not ask again"),
635 &checkboxResult, options);
638 if (checkboxResult) {
649 const QString &dontAskAgainName,
653 buttonContinue, buttonCancel, dontAskAgainName, options);
661 const QString &dontAskAgainName,
665 buttonContinue, buttonCancel, dontAskAgainName, options);
673 const QString &dontAskAgainName,
677 caption, buttonContinue, buttonCancel, dontAskAgainName, options );
685 const QString &dontAskAgainName,
697 dialog->
setCaption( caption.isEmpty() ?
i18n(
"Warning") : caption );
699 dialog->setObjectName(
"warningYesNo" );
708 if ( parent == NULL && parent_id ) {
712 bool checkboxResult =
false;
713 const int result =
createKMessageBox(dialog, QMessageBox::Warning, text, strlist,
714 dontAskAgainName.isEmpty() ?
QString() :
i18n(
"Do not ask again"),
715 &checkboxResult, options);
720 if (checkboxResult) {
731 const QString &dontAskAgainName,
735 buttonYes, buttonNo, buttonCancel, dontAskAgainName, options);
743 const QString &dontAskAgainName,
747 buttonYes, buttonNo, buttonCancel, dontAskAgainName, options);
756 const QString &dontAskAgainName,
760 caption, buttonYes, buttonNo, buttonCancel, dontAskAgainName, options );
769 const QString &dontAskAgainName,
784 dialog->
setCaption( caption.isEmpty() ?
i18n(
"Warning") : caption );
786 dialog->setObjectName(
"warningYesNoCancel" );
795 if ( parent == NULL && parent_id ) {
799 bool checkboxResult =
false;
800 const int result =
createKMessageBox(dialog, QMessageBox::Warning, text, strlist,
801 dontAskAgainName.isEmpty() ?
QString() :
i18n(
"Do not ask again"),
802 &checkboxResult, options);
812 if (checkboxResult) {
819 const QString &caption, Options options)
825 const QString &caption, Options options)
831 const QString &caption, Options options)
833 return errorListWId( parent ? parent->effectiveWinId() : 0, text, strlist, caption, options );
837 const QString &caption, Options options)
841 dialog->
setCaption( caption.isEmpty() ?
i18n(
"Error") : caption );
843 dialog->setObjectName(
"error" );
850 if ( parent == NULL && parent_id ) {
860 const QString &caption, Options options)
862 return detailedErrorWId( parent ? parent->effectiveWinId() : 0, text, details, caption, options );
867 const QString &caption, Options options)
871 dialog->
setCaption( caption.isEmpty() ?
i18n(
"Error") : caption );
873 dialog->setObjectName(
"error" );
880 if ( parent == NULL && parent_id ) {
898 KMessageBox_queue =
true;
900 KMessageBox_queue =
false;
905 const QString &caption, Options options)
907 return sorryWId( parent ? parent->effectiveWinId() : 0, text, caption, options );
911 const QString &caption, Options options)
915 dialog->
setCaption( caption.isEmpty() ?
i18n(
"Sorry") : caption );
917 dialog->setObjectName(
"sorry" );
924 if ( parent == NULL && parent_id ) {
933 const QString &caption, Options options)
935 return detailedSorryWId( parent ? parent->effectiveWinId() : 0, text, details, caption, options );
940 const QString &caption, Options options)
944 dialog->
setCaption( caption.isEmpty() ?
i18n(
"Sorry") : caption );
946 dialog->setObjectName(
"sorry" );
953 if ( parent == NULL && parent_id ) {
961 const QString &caption,
const QString &dontShowAgainName, Options options)
967 const QString &caption,
const QString &dontShowAgainName, Options options)
973 const QString &caption,
const QString &dontShowAgainName, Options options)
975 return informationListWId( parent ? parent->effectiveWinId() : 0, text, strlist, caption,
976 dontShowAgainName, options );
980 const QString &caption,
const QString &dontShowAgainName, Options options)
988 dialog->
setCaption( caption.isEmpty() ?
i18n(
"Information") : caption );
990 dialog->setObjectName(
"information" );
997 if ( parent == NULL && parent_id ) {
1001 bool checkboxResult =
false;
1004 dontShowAgainName.isEmpty() ?
QString() :
i18n(
"Do not show this message again"),
1005 &checkboxResult, options);
1007 if (checkboxResult) {
1015 if (!config->
hasGroup(
"Notification Messages")) {
1023 const configMap map = cg.
entryMap();
1025 configMap::ConstIterator it;
1026 for (it = map.begin(); it != map.end(); ++it) {
1034 if (!config->
hasGroup(
"Notification Messages")) {
1045 const QString &caption, Options options)
1048 if (_caption.isEmpty()) {
1055 dialog->setObjectName(
"about" );
1059 if (qApp->windowIcon().isNull()) {
1060 QPixmap ret = QMessageBox::standardIcon(QMessageBox::Information);
1061 dialog->setWindowIcon(ret);
1071 const QString &dontShowAskAgainName, Options options )
1073 return messageBoxWId( parent ? parent->effectiveWinId() : 0, type, text, caption,
1074 buttonYes, buttonNo, buttonCancel, dontShowAskAgainName, options );
1080 const QString &dontShow, Options options )
1085 text, caption, buttonYes, buttonNo, dontShow, options );
1088 text, caption, buttonYes, buttonNo, buttonCancel, dontShow, options );
1091 text, caption, buttonYes, buttonNo, dontShow, options );
1094 text, caption,
KGuiItem(buttonYes.
text()), buttonCancel, dontShow, options );
1097 text, caption, buttonYes, buttonNo, buttonCancel, dontShow, options );
1100 text, caption, dontShow, options );
1116 return queuedMessageBoxWId( parent ? parent->effectiveWinId() : 0, type, text, caption, options );
1121 KMessageBox_queue =
true;
1124 KMessageBox_queue =
false;
1134 KMessageBox_queue =
true;
1136 KMessageBox_queue =
false;