20 #include <tqcheckbox.h>
21 #include <tqguardedptr.h>
24 #include <tqlineedit.h>
25 #include <tqmessagebox.h>
26 #include <tqstringlist.h>
28 #include <tqvgroupbox.h>
29 #include <tqstylesheet.h>
30 #include <tqsimplerichtext.h>
31 #include <tqpushbutton.h>
34 #include <tdeapplication.h>
35 #include <tdeconfig.h>
37 #include <kdialogbase.h>
39 #include <tdelistbox.h>
41 #include <tdemessagebox.h>
42 #include <knotifyclient.h>
43 #include <kstdguiitem.h>
44 #include <kactivelabel.h>
45 #include <kiconloader.h>
46 #include <tdeglobalsettings.h>
61 static bool KMessageBox_queue =
false;
63 static TQPixmap themedMessageBoxIcon(TQMessageBox::Icon icon)
69 case TQMessageBox::NoIcon:
72 case TQMessageBox::Information:
73 icon_name =
"messagebox_info";
75 case TQMessageBox::Warning:
76 icon_name =
"messagebox_warning";
78 case TQMessageBox::Critical:
79 icon_name =
"messagebox_critical";
88 return TQMessageBox::standardIcon(icon);
93 static void sendNotification( TQString message,
94 const TQStringList& strlist,
95 TQMessageBox::Icon icon,
102 case TQMessageBox::Warning:
103 messageType =
"messageWarning";
105 case TQMessageBox::Critical:
106 messageType =
"messageCritical";
108 case TQMessageBox::Question:
109 messageType =
"messageQuestion";
112 messageType =
"messageInformation";
116 if ( !strlist.isEmpty() )
118 for ( TQStringList::ConstIterator it = strlist.begin(); it != strlist.end(); ++it )
119 message +=
"\n" + *it;
122 if ( !message.isEmpty() )
126 static TQString qrichtextify(
const TQString& text )
128 if ( text.isEmpty() || text[0] ==
'<' )
131 TQStringList lines = TQStringList::split(
'\n', text);
132 for(TQStringList::Iterator it = lines.begin(); it != lines.end(); ++it)
134 *it = TQStyleSheet::convertFromPlainText( *it, TQStyleSheetItem::WhiteSpaceNormal );
137 return lines.join(TQString::null);
141 const TQString &text,
const TQStringList &strlist,
142 const TQString &ask,
bool *checkboxReturn,
143 int options,
const TQString &details)
146 ask, checkboxReturn, options, details, icon);
150 const TQString &text,
const TQStringList &strlist,
151 const TQString &ask,
bool *checkboxReturn,
int options,
152 const TQString &details, TQMessageBox::Icon notifyType)
154 TQVBox *topcontents =
new TQVBox (dialog);
158 TQWidget *contents =
new TQWidget(topcontents);
159 TQHBoxLayout * lay =
new TQHBoxLayout(contents);
162 TQLabel *label1 =
new TQLabel( contents);
165 label1->setPixmap(icon);
167 lay->addWidget( label1, 0, Qt::AlignCenter );
170 TQString qt_text = qrichtextify( text );
176 TQSimpleRichText rt(qt_text, dialog->font());
179 pref_width = d.width() / 3;
180 rt.setWidth(pref_width);
181 int used_width = rt.widthUsed();
182 pref_height = rt.height();
183 if (3*pref_height > 2*d.height())
186 pref_width = d.width() / 2;
187 rt.setWidth(pref_width);
188 used_width = rt.widthUsed();
189 pref_height = rt.height();
191 if (used_width <= pref_width)
195 int new_width = (used_width * 9) / 10;
196 rt.setWidth(new_width);
197 int new_height = rt.height();
198 if (new_height > pref_height)
200 used_width = rt.widthUsed();
201 if (used_width > new_width)
204 pref_width = used_width;
208 if (used_width > (pref_width *2))
209 pref_width = pref_width *2;
211 pref_width = used_width;
217 TQObject::disconnect(label2, TQT_SIGNAL(linkClicked(
const TQString &)),
218 label2, TQT_SLOT(openLink(
const TQString &)));
223 label2->setFixedSize(TQSize(pref_width+10, pref_height));
224 lay->addWidget( label2 );
228 if (!strlist.isEmpty())
231 listbox->insertStringList( strlist );
232 listbox->setSelectionMode( TQListBox::NoSelection );
233 topcontents->setStretchFactor(listbox, 1);
236 TQGuardedPtr<TQCheckBox> checkbox = 0;
239 checkbox =
new TQCheckBox(ask, topcontents);
241 checkbox->setChecked(*checkboxReturn);
244 if (!details.isEmpty())
246 TQVGroupBox *detailsGroup =
new TQVGroupBox( i18n(
"Details"), dialog);
247 if ( details.length() < 512 ) {
250 label3->setMinimumSize(label3->sizeHint());
251 if (!(options & KMessageBox::AllowLink))
253 TQObject::disconnect(label3, TQT_SIGNAL(linkClicked(
const TQString &)),
254 label3, TQT_SLOT(openLink(
const TQString &)));
257 TQTextEdit* te =
new TQTextEdit(details, TQString::null, detailsGroup);
258 te->setReadOnly(
true );
259 te->setMinimumHeight( te->fontMetrics().lineSpacing() * 11 );
283 for(
unsigned int i = 0;
284 i <
sizeof( buttons )/
sizeof( buttons[ 0 ] );
286 if( TQPushButton* btn = dialog->
actionButton( buttons[ i ] ))
287 if( btn->isDefault())
291 sendNotification( text, strlist, notifyType, dialog->topLevelWidget()->winId());
293 if (KMessageBox_queue)
295 KDialogQueue::queueDialog(dialog);
296 return KMessageBox::Cancel;
301 return KMessageBox::Cancel;
307 TQGuardedPtr<KDialogBase> guardedDialog = dialog;
309 int result = guardedDialog->exec();
310 if (checkbox && checkboxReturn)
311 *checkboxReturn = checkbox->isChecked();
318 const TQString &caption,
321 const TQString &dontAskAgainName,
325 buttonYes, buttonNo, dontAskAgainName, options);
330 const TQString &caption,
333 const TQString &dontAskAgainName,
337 buttonYes, buttonNo, dontAskAgainName, options);
344 if ( dontShowAgainName.isEmpty() )
return true;
345 TQString grpNotifMsgs = TQString::fromLatin1(
"Notification Messages");
348 TQString dontAsk = config->
readEntry(dontShowAgainName).lower();
349 if (dontAsk ==
"yes") {
353 if (dontAsk ==
"no") {
363 if ( dontShowAgainName.isEmpty() )
return true;
364 TQString grpNotifMsgs = TQString::fromLatin1(
"Notification Messages");
374 if ( dontShowAgainName.isEmpty() )
return;
375 TQString grpNotifMsgs = TQString::fromLatin1(
"Notification Messages");
378 config->
writeEntry( dontShowAgainName, result==Yes ?
"yes" :
"no",
true, (dontShowAgainName[0] ==
':'));
385 if ( dontShowAgainName.isEmpty() )
return;
386 TQString grpNotifMsgs = TQString::fromLatin1(
"Notification Messages");
389 config->
writeEntry( dontShowAgainName,
false,
true, (dontShowAgainName[0] ==
':'));
393 TDEConfig* KMessageBox::againConfig = NULL;
402 const TQStringList &strlist,
403 const TQString &caption,
406 const TQString &dontAskAgainName,
410 caption, buttonYes, buttonNo, dontAskAgainName, options );
415 const TQStringList &strlist,
416 const TQString &caption,
419 const TQString &dontAskAgainName,
426 TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id ));
428 caption.isEmpty() ? i18n(
"Question") : caption,
431 parent,
"questionYesNo",
true,
true,
432 buttonYes, buttonNo);
436 if( parent == NULL && parent_id )
437 XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id );
440 bool checkboxResult =
false;
442 dontAskAgainName.isEmpty() ? TQString::null : i18n(
"Do not ask again"),
443 &checkboxResult, options);
444 res = (result==KDialogBase::Yes ? Yes : No);
453 const TQString &text,
454 const TQString &caption,
457 const TQString &dontAskAgainName,
461 dontAskAgainName, options );
466 const TQString &text,
467 const TQString &caption,
470 const TQString &dontAskAgainName,
477 TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id ));
479 caption.isEmpty() ? i18n(
"Question") : caption,
482 parent,
"questionYesNoCancel",
true,
true,
483 buttonYes, buttonNo);
487 if( parent == NULL && parent_id )
488 XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id );
491 bool checkboxResult =
false;
493 text, TQStringList(),
494 dontAskAgainName.isEmpty() ? TQString::null : i18n(
"Do not ask again"),
495 &checkboxResult, options);
496 if ( result==KDialogBase::Cancel )
return Cancel;
497 res = (result==KDialogBase::Yes ? Yes : No);
506 const TQString &caption,
509 const TQString &dontAskAgainName,
513 buttonYes, buttonNo, dontAskAgainName, options);
518 const TQString &caption,
521 const TQString &dontAskAgainName,
525 buttonYes, buttonNo, dontAskAgainName, options);
530 const TQStringList &strlist,
531 const TQString &caption,
534 const TQString &dontAskAgainName,
538 buttonYes, buttonNo, dontAskAgainName, options );
543 const TQStringList &strlist,
544 const TQString &caption,
547 const TQString &dontAskAgainName,
559 TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id ));
561 caption.isEmpty() ? i18n(
"Warning") : caption,
564 parent,
"warningYesNoList",
true,
true,
565 buttonYes, buttonNo);
569 if( parent == NULL && parent_id )
570 XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id );
573 bool checkboxResult =
false;
575 dontAskAgainName.isEmpty() ? TQString::null : i18n(
"Do not ask again"),
576 &checkboxResult, options);
586 const TQString &text,
587 const TQString &caption,
589 const TQString &dontAskAgainName,
593 buttonContinue, dontAskAgainName, options);
598 const TQString &text,
599 const TQString &caption,
601 const TQString &dontAskAgainName,
605 buttonContinue, dontAskAgainName, options);
610 const TQStringList &strlist,
611 const TQString &caption,
613 const TQString &dontAskAgainName,
617 caption, buttonContinue, dontAskAgainName, options );
622 const TQStringList &strlist,
623 const TQString &caption,
625 const TQString &dontAskAgainName,
631 TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id ));
633 caption.isEmpty() ? i18n(
"Warning") : caption,
636 parent,
"warningYesNo",
true,
true,
637 buttonContinue, KStdGuiItem::cancel() );
641 if( parent == NULL && parent_id )
642 XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id );
645 bool checkboxResult =
false;
647 dontAskAgainName.isEmpty() ? TQString::null : i18n(
"Do not ask again"),
648 &checkboxResult, options);
650 if ( result==KDialogBase::No )
659 const TQString &caption,
662 const TQString &dontAskAgainName,
666 buttonYes, buttonNo, dontAskAgainName, options);
671 const TQString &caption,
674 const TQString &dontAskAgainName,
678 buttonYes, buttonNo, dontAskAgainName, options);
683 const TQStringList &strlist,
684 const TQString &caption,
687 const TQString &dontAskAgainName,
691 caption, buttonYes, buttonNo, dontAskAgainName, options );
696 const TQStringList &strlist,
697 const TQString &caption,
700 const TQString &dontAskAgainName,
707 TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id ));
709 caption.isEmpty() ? i18n(
"Warning") : caption,
712 parent,
"warningYesNoCancel",
true,
true,
713 buttonYes, buttonNo);
717 if( parent == NULL && parent_id )
718 XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id );
721 bool checkboxResult =
false;
723 dontAskAgainName.isEmpty() ? TQString::null : i18n(
"Do not ask again"),
724 &checkboxResult, options);
725 if ( result==KDialogBase::Cancel )
return Cancel;
726 res = (result==KDialogBase::Yes ? Yes : No);
735 const TQString &caption,
int options)
737 return errorListWId( parent ? parent->winId() : 0, text, TQStringList(), caption, options );
742 const TQString &caption,
int options)
744 errorListWId( parent_id, text, TQStringList(), caption, options );
749 const TQString &caption,
int options)
751 return errorListWId( parent ? parent->winId() : 0, text, strlist, caption, options );
756 const TQString &caption,
int options)
758 TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id ));
760 caption.isEmpty() ? i18n(
"Error") : caption,
762 KDialogBase::Yes, KDialogBase::Yes,
763 parent,
"error",
true,
true,
768 if( parent == NULL && parent_id )
769 XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id );
772 createKMessageBox(dialog, TQMessageBox::Critical, text, strlist, TQString::null, 0, options);
777 const TQString &details,
778 const TQString &caption,
int options)
780 return detailedErrorWId( parent ? parent->winId() : 0, text, details, caption, options );
785 const TQString &details,
786 const TQString &caption,
int options)
788 TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id ));
790 caption.isEmpty() ? i18n(
"Error") : caption,
793 parent,
"error",
true,
true,
798 if( parent == NULL && parent_id )
799 XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id );
802 createKMessageBox(dialog, TQMessageBox::Critical, text, TQStringList(), TQString::null, 0, options, details);
807 const TQString &details,
808 const TQString &caption)
815 const TQString &details,
816 const TQString &caption)
818 KMessageBox_queue =
true;
820 KMessageBox_queue =
false;
826 const TQString &caption,
int options)
828 return sorryWId( parent ? parent->winId() : 0, text, caption, options );
833 const TQString &caption,
int options)
835 TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id ));
837 caption.isEmpty() ? i18n(
"Sorry") : caption,
839 KDialogBase::Yes, KDialogBase::Yes,
840 parent,
"sorry",
true,
true,
845 if( parent == NULL && parent_id )
846 XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id );
849 createKMessageBox(dialog, TQMessageBox::Warning, text, TQStringList(), TQString::null, 0, options);
854 const TQString &details,
855 const TQString &caption,
int options)
857 return detailedSorryWId( parent ? parent->winId() : 0, text, details, caption, options );
862 const TQString &details,
863 const TQString &caption,
int options)
865 TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id ));
867 caption.isEmpty() ? i18n(
"Sorry") : caption,
870 parent,
"sorry",
true,
true,
875 if( parent == NULL && parent_id )
876 XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id );
879 createKMessageBox(dialog, TQMessageBox::Warning, text, TQStringList(), TQString::null, 0, options, details);
884 const TQString &caption,
const TQString &dontShowAgainName,
int options)
886 informationList(parent, text, TQStringList(), caption, dontShowAgainName, options);
891 const TQString &caption,
const TQString &dontShowAgainName,
int options)
893 informationListWId(parent_id, text, TQStringList(), caption, dontShowAgainName, options);
898 const TQString &caption,
const TQString &dontShowAgainName,
int options)
901 dontShowAgainName, options );
906 const TQString &caption,
const TQString &dontShowAgainName,
int options)
911 TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id ));
913 caption.isEmpty() ? i18n(
"Information") : caption,
915 KDialogBase::Yes, KDialogBase::Yes,
916 parent,
"information",
true,
true,
921 if( parent == NULL && parent_id )
922 XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id );
925 bool checkboxResult =
false;
928 dontShowAgainName.isEmpty() ? TQString::null : i18n(
"Do not show this message again"),
929 &checkboxResult, options);
939 TQString grpNotifMsgs = TQString::fromLatin1(
"Notification Messages");
940 if (!config->
hasGroup(grpNotifMsgs))
945 typedef TQMap<TQString, TQString> configMap;
947 configMap map = config->
entryMap(grpNotifMsgs);
949 configMap::Iterator it;
950 for (it = map.begin(); it != map.end(); ++it)
959 TQString grpNotifMsgs = TQString::fromLatin1(
"Notification Messages");
960 if (!config->
hasGroup(grpNotifMsgs))
971 const TQString &caption,
int options)
973 TQString _caption = caption;
974 if (_caption.isEmpty())
975 _caption = i18n(
"About %1").arg(kapp->caption());
981 parent,
"about",
true,
true,
986 ret = TQMessageBox::standardIcon(TQMessageBox::Information);
987 dialog->setIcon(ret);
989 createKMessageBox(dialog, ret, text, TQStringList(), TQString::null, 0, options);
995 const TQString &caption,
const KGuiItem &buttonYes,
996 const KGuiItem &buttonNo,
const TQString &dontShowAskAgainName,
999 return messageBoxWId( parent ? parent->winId() : 0, type, text, caption,
1000 buttonYes, buttonNo, dontShowAskAgainName, options );
1004 const TQString &caption,
const KGuiItem &buttonYes,
1005 const KGuiItem &buttonNo,
int options )
1007 return messageBoxWId( parent ? parent->winId() : 0, type, text, caption,
1008 buttonYes, buttonNo, TQString::null, options );
1012 const TQString &caption,
const KGuiItem &buttonYes,
1013 const KGuiItem &buttonNo,
const TQString &dontShow,
1019 text, caption, buttonYes, buttonNo, dontShow, options );
1020 case QuestionYesNoCancel:
1022 text, caption, buttonYes, buttonNo, dontShow, options );
1025 text, caption, buttonYes, buttonNo, dontShow, options );
1026 case WarningContinueCancel:
1028 text, caption, buttonYes.text(), dontShow, options );
1029 case WarningYesNoCancel:
1031 text, caption, buttonYes, buttonNo, dontShow, options );
1034 text, caption, dontShow, options );
1035 return KMessageBox::Ok;
1039 return KMessageBox::Ok;
1043 return KMessageBox::Ok;
1045 return KMessageBox::Cancel;
1055 KMessageBox_queue =
true;
1056 (void)
messageBoxWId(parent_id, type, text, caption, KStdGuiItem::yes(),
1057 KStdGuiItem::no(), TQString::null, options);
1058 KMessageBox_queue =
false;
1068 KMessageBox_queue =
true;
1070 KMessageBox_queue =
false;