1/* This file is part of the KDE libraries
2 Copyright (C) 1999 Waldo Bastian (bastian@kde.org)
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; version 2
7 of the License.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20//krazy:excludeall=dpointer
21
22#ifndef KMESSAGEBOX_H
23#define KMESSAGEBOX_H
24
25#include <QtGui/QMessageBox>
26
27#include <kguiitem.h>
28#include <kstandardguiitem.h>
29
30class QWidget;
31class QStringList;
32class KConfig;
33class KDialog;
34
35 /**
36 * Easy message dialog box.
37 *
38 * Provides convenience functions for some i18n'ed standard dialogs,
39 * as well as audible notification via @ref KNotification
40 *
41 * The text in message boxes is wrapped automatically. The text may either
42 * be plaintext or richtext. If the text is plaintext, a newline-character
43 * may be used to indicate the end of a paragraph.
44 *
45 * @port4 Where applicable, the static functions now take an additional
46 * argument to specify the cancel button. Since a default argument is
47 * provided, this will affect your code only, if you specified
48 * dontAskAgainName and/or options. In those cases, adding an additional
49 * parameter KStandardGuiItem::cancel() leads to the old behavior. The
50 * following functions are affected (omitting function arguments in the
51 * list): questionYesNoCancel(), questionYesNoCancelWId(),
52 * warningContinueCancel(), warningContinueCancelWId(),
53 * warningContinueCancelList(), warningContinueCancelListWId(),
54 * warningYesNoCancel(), warningYesNoCancelWId(),
55 * warningYesNoCancelList(), warningYesNoCancelListWId(), messageBox(),
56 * messageBoxWId().
57 *
58 * \image html kmessagebox.png "KDE Message Box (using questionYesNo())"
59 *
60 * @author Waldo Bastian (bastian@kde.org)
61 */
62class KDEUI_EXPORT KMessageBox
63{
64public:
65 /**
66 * Button types.
67 **/
68 enum ButtonCode
69 {
70 Ok = 1,
71 Cancel = 2,
72 Yes = 3,
73 No = 4,
74 Continue = 5
75 };
76
77 enum DialogType
78 {
79 QuestionYesNo = 1,
80 WarningYesNo = 2,
81 WarningContinueCancel = 3,
82 WarningYesNoCancel = 4,
83 Information = 5,
84 // Reserved for: SSLMessageBox = 6
85 Sorry = 7,
86 Error = 8,
87 QuestionYesNoCancel = 9
88 };
89
90 enum Option
91 {
92 Notify = 1, ///< Emit a KNotify event
93 AllowLink = 2, ///< The message may contain links.
94 Dangerous = 4, ///< The action to be confirmed by the dialog is a potentially destructive one. The default button will be set to Cancel or No, depending on which is available.
95 PlainCaption = 8, ///< Do not use KApplication::makeStdCaption()
96 NoExec = 16, ///< Do not call exec() in createKMessageBox()
97 WindowModal = 32 ///< The window is to be modal relative to its parent. By default, it is application modal.
98 };
99
100 Q_DECLARE_FLAGS(Options,Option)
101
102 /**
103 * Display a simple "question" dialog.
104 *
105 * @param parent Parent widget.
106 * @param text Message string.
107 * @param caption Message box title. The application name is added to
108 * the title. The default title is i18n("Question").
109 * @param buttonYes The text for the first button.
110 * The default is KStandardGuiItem::yes().
111 * @param buttonNo The text for the second button.
112 * The default is KStandardGuiItem::no().
113 * @param dontAskAgainName If provided, a checkbox is added with which
114 * further confirmation can be turned off.
115 * The string is used to lookup and store the setting
116 * in the applications config file.
117 * The setting is stored in the "Notification Messages" group.
118 * If @p dontAskAgainName starts with a ':' then the setting
119 * is stored in the global config file.
120 * @param options see Option
121 *
122 * @return 'Yes' is returned if the Yes-button is pressed. 'No' is returned
123 * if the No-button is pressed.
124 *
125 * To be used for questions like "Do you have a printer?"
126 *
127 * The default button is "Yes". Pressing "Esc" selects "No".
128 */
129
130 static int questionYesNo(QWidget *parent,
131 const QString &text,
132 const QString &caption = QString(),
133 const KGuiItem &buttonYes = KStandardGuiItem::yes(),
134 const KGuiItem &buttonNo = KStandardGuiItem::no(),
135 const QString &dontAskAgainName = QString(),
136 Options options = Notify);
137 /**
138 * This function accepts the window id of the parent window, instead
139 * of QWidget*. It should be used only when necessary.
140 */
141 static int questionYesNoWId(WId parent_id,
142 const QString &text,
143 const QString &caption = QString(),
144 const KGuiItem &buttonYes = KStandardGuiItem::yes(),
145 const KGuiItem &buttonNo = KStandardGuiItem::no(),
146 const QString &dontAskAgainName = QString(),
147 Options options = Notify);
148 /**
149 * Display a simple "question" dialog.
150 *
151 * @param parent Parent widget.
152 * @param text Message string.
153 * @param caption Message box title. The application name is added to
154 * the title. The default title is i18n("Question").
155 * @param buttonYes The text for the first button.
156 * The default is KStandardGuiItem::yes().
157 * @param buttonNo The text for the second button.
158 * The default is KStandardGuiItem::no().
159 * @param buttonCancel The text for the third button.
160 * The default is KStandardGuiItem::cancel().
161 * @param dontAskAgainName If provided, a checkbox is added with which
162 * further confirmation can be turned off.
163 * The string is used to lookup and store the setting
164 * in the applications config file.
165 * The setting is stored in the "Notification Messages" group.
166 * If @p dontAskAgainName starts with a ':' then the setting
167 * is stored in the global config file.
168 * @param options see Options
169 *
170 * @return 'Yes' is returned if the Yes-button is pressed. 'No' is returned
171 * if the No-button is pressed.
172 *
173 * To be used for questions like "Do you want to discard the message or save it for later?",
174 *
175 * The default button is "Yes". Pressing "Esc" selects "Cancel".
176 */
177
178 static int questionYesNoCancel(QWidget *parent,
179 const QString &text,
180 const QString &caption = QString(),
181 const KGuiItem &buttonYes = KStandardGuiItem::yes(),
182 const KGuiItem &buttonNo = KStandardGuiItem::no(),
183 const KGuiItem &buttonCancel = KStandardGuiItem::cancel(),
184 const QString &dontAskAgainName = QString(),
185 Options options = Notify);
186
187 /**
188 * This function accepts the window id of the parent window, instead
189 * of QWidget*. It should be used only when necessary.
190 */
191 static int questionYesNoCancelWId(WId parent_id,
192 const QString &text,
193 const QString &caption = QString(),
194 const KGuiItem &buttonYes = KStandardGuiItem::yes(),
195 const KGuiItem &buttonNo = KStandardGuiItem::no(),
196 const KGuiItem &buttonCancel = KStandardGuiItem::cancel(),
197 const QString &dontAskAgainName = QString(),
198 Options options = Notify);
199
200 /**
201 * Display a "question" dialog with a listbox to show information to the user
202 *
203 * @param parent Parent widget.
204 * @param text Message string.
205 * @param strlist List of strings to be written in the listbox. If the list is
206 * empty, it doesn't show any listbox, working as questionYesNo.
207 * @param caption Message box title. The application name is added to
208 * the title. The default title is i18n("Question").
209 * @param buttonYes The text for the first button.
210 * The default is KStandardGuiItem::yes().
211 * @param buttonNo The text for the second button.
212 * The default is KStandardGuiItem::no().
213 * @param dontAskAgainName If provided, a checkbox is added with which
214 * further confirmation can be turned off.
215 * The string is used to lookup and store the setting
216 * in the applications config file.
217 * The setting is stored in the "Notification Messages" group.
218 * If @p dontAskAgainName starts with a ':' then the setting
219 * is stored in the global config file.
220 * @param options see Options
221 *
222 * @return 'Yes' is returned if the Yes-button is pressed. 'No' is returned
223 * if the No-button is pressed.
224 *
225 * To be used for questions like "Do you really want to delete these files?"
226 * And show the user exactly which files are going to be deleted in case
227 * he presses "Yes"
228 *
229 * The default button is "Yes". Pressing "Esc" selects "No".
230 */
231
232 static int questionYesNoList(QWidget *parent,
233 const QString &text,
234 const QStringList &strlist,
235 const QString &caption = QString(),
236 const KGuiItem &buttonYes = KStandardGuiItem::yes(),
237 const KGuiItem &buttonNo = KStandardGuiItem::no(),
238 const QString &dontAskAgainName = QString(),
239 Options options = Notify);
240
241 /**
242 * This function accepts the window id of the parent window, instead
243 * of QWidget*. It should be used only when necessary.
244 */
245 static int questionYesNoListWId(WId parent_id,
246 const QString &text,
247 const QStringList &strlist,
248 const QString &caption = QString(),
249 const KGuiItem &buttonYes = KStandardGuiItem::yes(),
250 const KGuiItem &buttonNo = KStandardGuiItem::no(),
251 const QString &dontAskAgainName = QString(),
252 Options options = Notify);
253
254 /**
255 * Display a "warning" dialog.
256 *
257 * @param parent Parent widget.
258 * @param text Message string.
259 * @param caption Message box title. The application name is added to
260 * the title. The default title is i18n("Warning").
261 * @param buttonYes The text for the first button.
262 * The default is KStandardGuiItem::yes().
263 * @param buttonNo The text for the second button.
264 * The default is KStandardGuiItem::no().
265 * @param dontAskAgainName If provided, a checkbox is added with which
266 * further confirmation can be turned off.
267 * The string is used to lookup and store the setting
268 * in the applications config file.
269 * The setting is stored in the "Notification Messages" group.
270 * If @p dontAskAgainName starts with a ':' then the setting
271 * is stored in the global config file.
272 * @param options see Options
273 *
274 * @return @p Yes is returned if the Yes-button is pressed. @p No is returned
275 * if the No-button is pressed.
276 *
277 * To be used for questions "Shall I update your configuration?"
278 * The text should explain the implication of both options.
279 *
280 * The default button is "No". Pressing "Esc" selects "No".
281 */
282 static int warningYesNo(QWidget *parent,
283 const QString &text,
284 const QString &caption = QString(),
285 const KGuiItem &buttonYes = KStandardGuiItem::yes(),
286 const KGuiItem &buttonNo = KStandardGuiItem::no(),
287 const QString &dontAskAgainName = QString(),
288 Options options = Options(Notify | Dangerous));
289
290 /**
291 * This function accepts the window id of the parent window, instead
292 * of QWidget*. It should be used only when necessary.
293 */
294 static int warningYesNoWId(WId parent_id,
295 const QString &text,
296 const QString &caption = QString(),
297 const KGuiItem &buttonYes = KStandardGuiItem::yes(),
298 const KGuiItem &buttonNo = KStandardGuiItem::no(),
299 const QString &dontAskAgainName = QString(),
300 Options options = Options(Notify | Dangerous));
301
302 /**
303 * Display a "warning" dialog with a listbox to show information to the user
304 *
305 * @param parent Parent widget.
306 * @param text Message string.
307 * @param strlist List of strings to be written in the listbox. If the list is
308 * empty, it doesn't show any listbox, working as questionYesNo.
309 * @param caption Message box title. The application name is added to
310 * the title. The default title is i18n("Question").
311 * @param buttonYes The text for the first button.
312 * The default is KStandardGuiItem::yes().
313 * @param buttonNo The text for the second button.
314 * The default is KStandardGuiItem::no().
315 * @param dontAskAgainName If provided, a checkbox is added with which
316 * further confirmation can be turned off.
317 * The string is used to lookup and store the setting
318 * in the applications config file.
319 * The setting is stored in the "Notification Messages" group.
320 * If @p dontAskAgainName starts with a ':' then the setting
321 * is stored in the global config file.
322 * @param options see Options
323 *
324 * @return 'Yes' is returned if the Yes-button is pressed. 'No' is returned
325 * if the No-button is pressed.
326 *
327 * To be used for questions like "Do you really want to delete these files?"
328 * And show the user exactly which files are going to be deleted in case
329 * he presses "Yes"
330 *
331 * The default button is "No". Pressing "Esc" selects "No".
332 */
333
334 static int warningYesNoList(QWidget *parent,
335 const QString &text,
336 const QStringList &strlist,
337 const QString &caption = QString(),
338 const KGuiItem &buttonYes = KStandardGuiItem::yes(),
339 const KGuiItem &buttonNo = KStandardGuiItem::no(),
340 const QString &dontAskAgainName = QString(),
341 Options options = Options(Notify | Dangerous));
342
343 /**
344 * This function accepts the window id of the parent window, instead
345 * of QWidget*. It should be used only when necessary.
346 */
347 static int warningYesNoListWId(WId parent_id,
348 const QString &text,
349 const QStringList &strlist,
350 const QString &caption = QString(),
351 const KGuiItem &buttonYes = KStandardGuiItem::yes(),
352 const KGuiItem &buttonNo = KStandardGuiItem::no(),
353 const QString &dontAskAgainName = QString(),
354 Options options = Options(Notify | Dangerous));
355
356 /**
357 * Display a "warning" dialog.
358 *
359 * @param parent Parent widget.
360 * @param text Message string.
361 * @param caption Message box title. The application name is added to
362 * the title. The default title is i18n("Warning").
363 * @param buttonContinue The text for the first button.
364 * The default is KStandardGuiItem::cont().
365 * @param buttonCancel The text for the second button.
366 * The default is KStandardGuiItem::cancel().
367 * @param dontAskAgainName If provided, a checkbox is added with which
368 * further confirmation can be turned off.
369 * The string is used to lookup and store the setting
370 * in the applications config file.
371 * The setting is stored in the "Notification Messages" group.
372 * If @p dontAskAgainName starts with a ':' then the setting
373 * is stored in the global config file.
374 * @param options see Options
375 *
376 * @return @p Continue is returned if the Continue-button is pressed.
377 * @p Cancel is returned if the Cancel-button is pressed.
378 *
379 * To be used for questions like "You are about to Print. Are you sure?"
380 * the continueButton should then be labeled "Print".
381 *
382 * The default button is buttonContinue. Pressing "Esc" selects "Cancel".
383 */
384 static int warningContinueCancel(QWidget *parent,
385 const QString &text,
386 const QString &caption = QString(),
387 const KGuiItem &buttonContinue = KStandardGuiItem::cont(),
388 const KGuiItem &buttonCancel = KStandardGuiItem::cancel(),
389 const QString &dontAskAgainName = QString(),
390 Options options = Notify);
391
392 /**
393 * This function accepts the window id of the parent window, instead
394 * of QWidget*. It should be used only when necessary.
395 */
396 static int warningContinueCancelWId(WId parent_id,
397 const QString &text,
398 const QString &caption = QString(),
399 const KGuiItem &buttonContinue = KStandardGuiItem::cont(),
400 const KGuiItem &buttonCancel = KStandardGuiItem::cancel(),
401 const QString &dontAskAgainName = QString(),
402 Options options = Notify);
403
404 /**
405 * Display a "warning" dialog with a listbox to show information to the user.
406 *
407 * @param parent Parent widget.
408 * @param text Message string.
409 * @param strlist List of strings to be written in the listbox. If the
410 * list is empty, it doesn't show any listbox, working
411 * as warningContinueCancel.
412 * @param caption Message box title. The application name is added to
413 * the title. The default title is i18n("Warning").
414 * @param buttonContinue The text for the first button.
415 * The default is KStandardGuiItem::cont().
416 * @param buttonCancel The text for the second button.
417 * The default is KStandardGuiItem::cancel().
418 * @param dontAskAgainName If provided, a checkbox is added with which
419 * further confirmation can be turned off.
420 * The string is used to lookup and store the setting
421 * in the applications config file.
422 * The setting is stored in the "Notification Messages" group.
423 * If @p dontAskAgainName starts with a ':' then the setting
424 * is stored in the global config file.
425 *
426 * @param options see Options
427 *
428 * @return @p Continue is returned if the Continue-button is pressed.
429 * @p Cancel is returned if the Cancel-button is pressed.
430 *
431 * To be used for questions like "You are about to Print. Are you sure?"
432 * the continueButton should then be labeled "Print".
433 *
434 * The default button is buttonContinue. Pressing "Esc" selects "Cancel".
435 */
436 static int warningContinueCancelList(QWidget *parent,
437 const QString &text,
438 const QStringList &strlist,
439 const QString &caption = QString(),
440 const KGuiItem &buttonContinue = KStandardGuiItem::cont(),
441 const KGuiItem &buttonCancel = KStandardGuiItem::cancel(),
442 const QString &dontAskAgainName = QString(),
443 Options options = Notify);
444
445 /**
446 * This function accepts the window id of the parent window, instead
447 * of QWidget*. It should be used only when necessary.
448 */
449 static int warningContinueCancelListWId(WId parent_id,
450 const QString &text,
451 const QStringList &strlist,
452 const QString &caption = QString(),
453 const KGuiItem &buttonContinue = KStandardGuiItem::cont(),
454 const KGuiItem &buttonCancel = KStandardGuiItem::cancel(),
455 const QString &dontAskAgainName = QString(),
456 Options options = Notify);
457
458 /**
459 * Display a Yes/No/Cancel "warning" dialog.
460 *
461 * @param parent Parent widget.
462 * @param text Message string.
463 * @param caption Message box title. The application name is added to
464 * the title. The default title is i18n("Warning").
465 * @param buttonYes The text for the first button.
466 * The default is KStandardGuiItem::yes().
467 * @param buttonNo The text for the second button.
468 * The default is KStandardGuiItem::no().
469 * @param buttonCancel The text for the third button.
470 * The default is KStandardGuiItem::cancel().
471 * @param dontAskAgainName If provided, a checkbox is added with which
472 * further questions can be turned off. If turned off
473 * all questions will be automatically answered with the
474 * last answer (either Yes or No).
475 * The string is used to lookup and store the setting
476 * in the applications config file.
477 * The setting is stored in the "Notification Messages" group.
478 * If @p dontAskAgainName starts with a ':' then the setting
479 * is stored in the global config file.
480 * @param options see Options
481 *
482 * @return @p Yes is returned if the Yes-button is pressed. @p No is returned
483 * if the No-button is pressed. @p Cancel is retunred if the Cancel-
484 * button is pressed.
485 *
486 * To be used for questions "Do you want to save your changes?"
487 * The text should explain the implication of choosing 'No'.
488 *
489 * The default button is "Yes". Pressing "Esc" selects "Cancel"
490 */
491
492 static int warningYesNoCancel(QWidget *parent,
493 const QString &text,
494 const QString &caption = QString(),
495 const KGuiItem &buttonYes = KStandardGuiItem::yes(),
496 const KGuiItem &buttonNo = KStandardGuiItem::no(),
497 const KGuiItem &buttonCancel = KStandardGuiItem::cancel(),
498 const QString &dontAskAgainName = QString(),
499 Options options = Notify);
500
501 /**
502 * This function accepts the window id of the parent window, instead
503 * of QWidget*. It should be used only when necessary.
504 */
505 static int warningYesNoCancelWId(WId parent_id,
506 const QString &text,
507 const QString &caption = QString(),
508 const KGuiItem &buttonYes = KStandardGuiItem::yes(),
509 const KGuiItem &buttonNo = KStandardGuiItem::no(),
510 const KGuiItem &buttonCancel = KStandardGuiItem::cancel(),
511 const QString &dontAskAgainName = QString(),
512 Options options = Notify);
513
514 /**
515 * Display a Yes/No/Cancel "warning" dialog with a listbox to show information
516 * to the user.
517 *
518 * @param parent Parent widget.
519 * @param text Message string.
520 * @param strlist List of strings to be written in the listbox. If the
521 * list is empty, it doesn't show any listbox, working
522 * as warningYesNoCancel.
523 * @param caption Message box title. The application name is added to
524 * the title. The default title is i18n("Warning").
525 * @param buttonYes The text for the first button.
526 * The default is KStandardGuiItem::yes().
527 * @param buttonNo The text for the second button.
528 * The default is KStandardGuiItem::no().
529 * @param buttonCancel The text for the third button.
530 * The default is KStandardGuiItem::cancel().
531 * @param dontAskAgainName If provided, a checkbox is added with which
532 * further questions can be turned off. If turned off
533 * all questions will be automatically answered with the
534 * last answer (either Yes or No).
535 * The string is used to lookup and store the setting
536 * in the applications config file.
537 * The setting is stored in the "Notification Messages" group.
538 * If @p dontAskAgainName starts with a ':' then the setting
539 * is stored in the global config file.
540 * @param options see Options
541 *
542 * @return @p Yes is returned if the Yes-button is pressed. @p No is returned
543 * if the No-button is pressed. @p Cancel is retunred if the Cancel-
544 * button is pressed.
545 *
546 * To be used for questions "Do you want to save your changes?"
547 * The text should explain the implication of choosing 'No'.
548 *
549 * The default button is "Yes". Pressing "Esc" selects "Cancel"
550 */
551 static int warningYesNoCancelList(QWidget *parent,
552 const QString &text,
553 const QStringList &strlist,
554 const QString &caption = QString(),
555 const KGuiItem &buttonYes = KStandardGuiItem::yes(),
556 const KGuiItem &buttonNo = KStandardGuiItem::no(),
557 const KGuiItem &buttonCancel = KStandardGuiItem::cancel(),
558 const QString &dontAskAgainName = QString(),
559 Options options = Notify);
560
561 /**
562 * This function accepts the window id of the parent window, instead
563 * of QWidget*. It should be used only when necessary.
564 */
565 static int warningYesNoCancelListWId(WId parent_id,
566 const QString &text,
567 const QStringList &strlist,
568 const QString &caption = QString(),
569 const KGuiItem &buttonYes = KStandardGuiItem::yes(),
570 const KGuiItem &buttonNo = KStandardGuiItem::no(),
571 const KGuiItem &buttonCancel = KStandardGuiItem::cancel(),
572 const QString &dontAskAgainName = QString(),
573 Options options = Notify);
574
575 /**
576 * Display an "Error" dialog.
577 *
578 * @param parent Parent widget.
579 * @param text Message string.
580 * @param caption Message box title. The application name is added to
581 * the title. The default title is i18n("Error").
582 * @param options see Options
583 *
584 * Your program messed up and now it's time to inform the user.
585 * To be used for important things like "Sorry, I deleted your hard disk."
586 *
587 * If your program detects the action specified by the user is somehow
588 * not allowed, this should never be reported with error(). Use sorry()
589 * instead to explain to the user that this action is not allowed.
590 *
591 * The default button is "&OK". Pressing "Esc" selects the OK-button.
592 *
593 * NOTE: The OK button will always have the i18n'ed text '&OK'.
594 */
595
596 static void error(QWidget *parent,
597 const QString &text,
598 const QString &caption = QString(),
599 Options options = Notify);
600
601 /**
602 * This function accepts the window id of the parent window, instead
603 * of QWidget*. It should be used only when necessary.
604 */
605 static void errorWId(WId parent_id,
606 const QString &text,
607 const QString &caption = QString(),
608 Options options = Notify);
609
610 /**
611 * Display an "Error" dialog with a listbox.
612 *
613 * @param parent Parent widget.
614 * @param text Message string.
615 * @param strlist List of strings to be written in the listbox. If the
616 * list is empty, it doesn't show any listbox, working
617 * as error().
618 * @param caption Message box title. The application name is added to
619 * the title. The default title is i18n("Error").
620 * @param options see Options
621 *
622 * Your program messed up and now it's time to inform the user.
623 * To be used for important things like "Sorry, I deleted your hard disk."
624 *
625 * If your program detects the action specified by the user is somehow
626 * not allowed, this should never be reported with error(). Use sorry()
627 * instead to explain to the user that this action is not allowed.
628 *
629 * The default button is "&OK". Pressing "Esc" selects the OK-button.
630 *
631 * NOTE: The OK button will always have the i18n'ed text '&OK'.
632 */
633
634 static void errorList(QWidget *parent,
635 const QString &text,
636 const QStringList &strlist,
637 const QString &caption = QString(),
638 Options options = Notify);
639
640 /**
641 * This function accepts the window id of the parent window, instead
642 * of QWidget*. It should be used only when necessary.
643 */
644
645 static void errorListWId(WId parent_id,
646 const QString &text,
647 const QStringList &strlist,
648 const QString &caption = QString(),
649 Options options = Notify);
650
651 /**
652 * Displays an "Error" dialog with a "Details >>" button.
653 *
654 * @param parent Parent widget.
655 * @param text Message string.
656 * @param details Detailed message string.
657 * @param caption Message box title. The application name is added to
658 * the title. The default title is i18n("Error").
659 * @param options see Options
660 *
661 * Your program messed up and now it's time to inform the user.
662 * To be used for important things like "Sorry, I deleted your hard disk."
663 *
664 * The @p details message can contain additional information about
665 * the problem and can be shown on request to advanced/interested users.
666 *
667 * If your program detects the action specified by the user is somehow
668 * not allowed, this should never be reported with error(). Use sorry()
669 * instead to explain to the user that this action is not allowed.
670 *
671 * The default button is "&OK". Pressing "Esc" selects the OK-button.
672 *
673 * NOTE: The OK button will always have the i18n'ed text '&OK'.
674 */
675 static void detailedError(QWidget *parent,
676 const QString &text,
677 const QString &details,
678 const QString &caption = QString(),
679 Options options = Notify);
680
681 /**
682 * This function accepts the window id of the parent window, instead
683 * of QWidget*. It should be used only when necessary.
684 */
685 static void detailedErrorWId(WId parent_id,
686 const QString &text,
687 const QString &details,
688 const QString &caption = QString(),
689 Options options = Notify);
690
691 /**
692 * Like detailedError
693 *
694 * This function will return immediately, the messagebox will be shown
695 * once the application enters an event loop and no other messagebox
696 * is being shown.
697 *
698 * Note that if the parent gets deleted, the messagebox will not be
699 * shown.
700 */
701 static void queuedDetailedError( QWidget *parent,
702 const QString &text,
703 const QString &details,
704 const QString &caption = QString());
705
706 /**
707 * This function accepts the window id of the parent window, instead
708 * of QWidget*. It should be used only when necessary.
709 */
710 static void queuedDetailedErrorWId( WId parent_id,
711 const QString &text,
712 const QString &details,
713 const QString &caption = QString());
714
715 /**
716 * Display an "Sorry" dialog.
717 *
718 * @param parent Parent widget.
719 * @param text Message string.
720 * @param caption Message box title. The application name is added to
721 * the title. The default title is i18n("Sorry").
722 * @param options see OptionsType
723 *
724 * Either your program messed up and asks for understanding
725 * or your user did something stupid.
726 *
727 * To be used for small problems like
728 * "Sorry, I can't find the file you specified."
729 *
730 * The default button is "&OK". Pressing "Esc" selects the OK-button.
731 *
732 * NOTE: The ok button will always have the i18n'ed text '&OK'.
733 */
734
735 static void sorry(QWidget *parent,
736 const QString &text,
737 const QString &caption = QString(),
738 Options options = Notify);
739
740 /**
741 * This function accepts the window id of the parent window, instead
742 * of QWidget*. It should be used only when necessary.
743 */
744 static void sorryWId(WId parent_id,
745 const QString &text,
746 const QString &caption = QString(),
747 Options options = Notify);
748
749 /**
750 * Displays a "Sorry" dialog with a "Details >>" button.
751 *
752 * @param parent Parent widget.
753 * @param text Message string.
754 * @param details Detailed message string.
755 * @param caption Message box title. The application name is added to
756 * the title. The default title is i18n("Sorry").
757 * @param options see Options
758 *
759 * Either your program messed up and asks for understanding
760 * or your user did something stupid.
761 *
762 * To be used for small problems like
763 * "Sorry, I can't find the file you specified."
764 *
765 * And then @p details can contain something like
766 * "foobar.txt was not found in any of
767 * the following directories:
768 * /usr/bin,/usr/local/bin,/usr/sbin"
769 *
770 * The default button is "&OK". Pressing "Esc" selects the OK-button.
771 *
772 * NOTE: The ok button will always have the i18n'ed text '&OK'.
773 */
774
775 static void detailedSorry(QWidget *parent,
776 const QString &text,
777 const QString &details,
778 const QString &caption = QString(),
779 Options options = Notify);
780
781 /**
782 * This function accepts the window id of the parent window, instead
783 * of QWidget*. It should be used only when necessary.
784 */
785 static void detailedSorryWId(WId parent_id,
786 const QString &text,
787 const QString &details,
788 const QString &caption = QString(),
789 Options options = Notify);
790
791 /**
792 * Display an "Information" dialog.
793 *
794 * @param parent Parent widget.
795 * @param text Message string.
796 * @param caption Message box title. The application name is added to
797 * the title. The default title is i18n("Information").
798 * @param dontShowAgainName If provided, a checkbox is added with which
799 * further notifications can be turned off.
800 * The string is used to lookup and store the setting
801 * in the applications config file.
802 * The setting is stored in the "Notification Messages" group.
803 * @param options see Options
804 *
805 *
806 * Your program wants to tell the user something.
807 * To be used for things like:
808 * "Your bookmarks have been rearranged."
809 *
810 * The default button is "&OK". Pressing "Esc" selects the OK-button.
811 *
812 * NOTE: The OK button will always have the i18n'ed text '&OK'.
813 */
814
815 static void information(QWidget *parent,
816 const QString &text,
817 const QString &caption = QString(),
818 const QString &dontShowAgainName = QString(),
819 Options options = Notify);
820
821 /**
822 * This function accepts the window id of the parent window, instead
823 * of QWidget*. It should be used only when necessary.
824 */
825 static void informationWId(WId parent_id,
826 const QString &text,
827 const QString &caption = QString(),
828 const QString &dontShowAgainName = QString(),
829 Options options = Notify);
830
831 /**
832 * Display an "Information" dialog with a listbox.
833 *
834 * @param parent Parent widget.
835 * @param text Message string.
836 * @param strlist List of strings to be written in the listbox. If the
837 * list is empty, it doesn't show any listbox, working
838 * as information.
839 * @param caption Message box title. The application name is added to
840 * the title. The default title is i18n("Information").
841 * @param dontShowAgainName If provided, a checkbox is added with which
842 * further notifications can be turned off.
843 * The string is used to lookup and store the setting
844 * in the applications config file.
845 * The setting is stored in the "Notification Messages" group.
846 * @param options see Options
847 *
848 *
849 * Your program wants to tell the user something.
850 * To be used for things like:
851 * "The following bookmarks have been rearranged:"
852 *
853 * The default button is "&OK". Pressing "Esc" selects the OK-button.
854 *
855 * NOTE: The OK button will always have the i18n'ed text '&OK'.
856 */
857
858 static void informationList(QWidget *parent,
859 const QString &text,
860 const QStringList & strlist,
861 const QString &caption = QString(),
862 const QString &dontShowAgainName = QString(),
863 Options options = Notify);
864
865 /**
866 * This function accepts the window id of the parent window, instead
867 * of QWidget*. It should be used only when necessary.
868 */
869 static void informationListWId(WId parent_id,
870 const QString &text,
871 const QStringList & strlist,
872 const QString &caption = QString(),
873 const QString &dontShowAgainName = QString(),
874 Options options = Notify);
875
876 /**
877 * Enable all messages which have been turned off with the
878 * @p dontShowAgainName feature.
879 */
880 static void enableAllMessages();
881
882 /**
883 * Re-enable a specific @p dontShowAgainName messages that had
884 * previously been turned off.
885 * @see saveDontShowAgainYesNo()
886 * @see saveDontShowAgainContinue()
887 */
888 static void enableMessage(const QString &dontShowAgainName);
889
890 /**
891 * Display an "About" dialog.
892 *
893 * @param parent Parent widget.
894 * @param text Message string.
895 * @param caption Message box title. The application name is added to
896 * the title. The default title is i18n("About \<appname\>").
897 * @param options see Options
898 *
899 *
900 * Your program wants to show some general information about the application
901 * like the authors's names and email addresses.
902 *
903 * The default button is "&OK".
904 *
905 * NOTE: The ok button will always have the i18n'ed text '&OK'.
906 */
907 static void about(QWidget *parent,
908 const QString& text,
909 const QString& caption = QString(),
910 Options options = Notify);
911
912 /**
913 * Alternate method to show a messagebox:
914 *
915 * @param parent Parent widget.
916 * @param type type of message box: QuestionYesNo, WarningYesNo, WarningContinueCancel...
917 * @param text Message string.
918 * @param caption Message box title.
919 * @param buttonYes The text for the first button.
920 * The default is KStandardGuiItem::yes().
921 * @param buttonNo The text for the second button.
922 * The default is KStandardGuiItem::no().
923 * @param buttonCancel The text for the third button.
924 * The default is KStandardGuiItem::cancel().
925 * @param dontShowAskAgainName If provided, a checkbox is added with which
926 * further questions/information can be turned off. If turned off
927 * all questions will be automatically answered with the
928 * last answer (either Yes or No), if the message box needs an answer.
929 * The string is used to lookup and store the setting
930 * in the applications config file.
931 * @param options see Options
932 * Note: for ContinueCancel, buttonYes is the continue button and buttonNo is unused.
933 * and for Information, none is used.
934 * @return a button code, as defined in KMessageBox.
935 */
936
937 static int messageBox( QWidget *parent, DialogType type, const QString &text,
938 const QString &caption = QString(),
939 const KGuiItem &buttonYes = KStandardGuiItem::yes(),
940 const KGuiItem &buttonNo = KStandardGuiItem::no(),
941 const KGuiItem &buttonCancel = KStandardGuiItem::cancel(),
942 const QString &dontShowAskAgainName = QString(),
943 Options options = Notify);
944
945 /**
946 * This function accepts the window id of the parent window, instead
947 * of QWidget*. It should be used only when necessary.
948 */
949 static int messageBoxWId( WId parent_id, DialogType type, const QString &text,
950 const QString &caption = QString(),
951 const KGuiItem &buttonYes = KStandardGuiItem::yes(),
952 const KGuiItem &buttonNo = KStandardGuiItem::no(),
953 const KGuiItem &buttonCancel = KStandardGuiItem::cancel(),
954 const QString &dontShowAskAgainName = QString(),
955 Options options = Notify);
956
957 /**
958 * Like messageBox
959 *
960 * Only for message boxes of type Information, Sorry or Error.
961 *
962 * This function will return immediately, the messagebox will be shown
963 * once the application enters an event loop and no other messagebox
964 * is being shown.
965 *
966 * Note that if the parent gets deleted, the messagebox will not be
967 * shown.
968 */
969 static void queuedMessageBox( QWidget *parent,
970 DialogType type, const QString &text,
971 const QString &caption,
972 Options options );
973
974 /**
975 * This function accepts the window id of the parent window, instead
976 * of QWidget*. It should be used only when necessary.
977 */
978 static void queuedMessageBoxWId( WId parent_id,
979 DialogType type, const QString &text,
980 const QString &caption,
981 Options options );
982
983 /**
984 * @overload
985 *
986 * This is an overloaded member function, provided for convenience.
987 * It behaves essentially like the above function.
988 */
989 static void queuedMessageBox( QWidget *parent,
990 DialogType type, const QString &text,
991 const QString &caption = QString() );
992
993 /**
994 * This function accepts the window id of the parent window, instead
995 * of QWidget*. It should be used only when necessary.
996 */
997 static void queuedMessageBoxWId( WId parent_id,
998 DialogType type, const QString &text,
999 const QString &caption = QString() );
1000
1001 /**
1002 * @return true if the corresponding yes/no message box should be shown.
1003 * @param dontShowAgainName the name that identify the message box. If
1004 * empty, true is always returned.
1005 * @param result is set to the result (Yes or No) that was chosen the last
1006 * time the message box was shown. Only meaningful, if the message box
1007 * should not be shown.
1008 */
1009 static bool shouldBeShownYesNo(const QString &dontShowAgainName,
1010 ButtonCode &result);
1011 /**
1012 * @return true if the corresponding continue/cancel message box should be
1013 * shown.
1014 * @param dontShowAgainName the name that identify the message box. If
1015 * empty, true is always returned.
1016 */
1017 static bool shouldBeShownContinue(const QString &dontShowAgainName);
1018
1019 /**
1020 * Save the fact that the yes/no message box should not be shown again.
1021 * @param dontShowAgainName the name that identify the message box. If
1022 * empty, this method does nothing.
1023 * @param result the value (Yes or No) that should be used as the result
1024 * for the message box.
1025 */
1026 static void saveDontShowAgainYesNo(const QString &dontShowAgainName,
1027 ButtonCode result);
1028
1029 /**
1030 * Save the fact that the continue/cancel message box should not be shown
1031 * again.
1032 * @param dontShowAgainName the name that identify the message box. If
1033 * empty, this method does nothing.
1034 */
1035 static void saveDontShowAgainContinue(const QString &dontShowAgainName);
1036
1037 /**
1038 * Use @p cfg for all settings related to the dontShowAgainName feature.
1039 * If @p cfg is 0 (default) KGlobal::config() will be used.
1040 */
1041 static void setDontShowAskAgainConfig(KConfig* cfg);
1042
1043 /**
1044 * Create content and layout of a standard dialog
1045 *
1046 * @param dialog The parent dialog base
1047 * @param icon Which predefined icon the message box shall show.
1048 * @param text Message string.
1049 * @param strlist List of strings to be written in the listbox.
1050 * If the list is empty, it doesn't show any listbox
1051 * @param ask The text of the checkbox. If empty none will be shown.
1052 * @param checkboxReturn The result of the checkbox. If it's initially
1053 * true then the checkbox will be checked by default.
1054 * May be 0.
1055 * @param options see Options
1056 * @param details Detailed message string.
1057 * @return A KDialog button code, not a KMessageBox button code,
1058 * based on the buttonmask given to the constructor of the
1059 * @p dialog (ie. will return KDialog::Yes [256] instead of
1060 * KMessageBox::Yes [3]). Will return KMessageBox::Cancel
1061 * if the message box is queued for display instead of
1062 * exec()ed immediately or if the option NoExec is set.
1063 * @note Unless NoExec is used,
1064 * the @p dialog that is passed in is deleted by this
1065 * function. Do not delete it yourself.
1066 */
1067 static int createKMessageBox(KDialog *dialog, QMessageBox::Icon icon, //krazy:exclude=qclasses
1068 const QString &text, const QStringList &strlist,
1069 const QString &ask, bool *checkboxReturn,
1070 Options options, const QString &details=QString());
1071
1072 /**
1073 * Create content and layout of a standard dialog
1074 *
1075 * @param dialog The parent dialog base
1076 * @param icon A QPixmap containing the icon to be displayed in the
1077 * dialog next to the text.
1078 * @param text Message string.
1079 * @param strlist List of strings to be written in the listbox.
1080 * If the list is empty, it doesn't show any listbox
1081 * @param ask The text of the checkbox. If empty none will be shown.
1082 * @param checkboxReturn The result of the checkbox. If it's initially
1083 * true then the checkbox will be checked by default.
1084 * May be 0.
1085 * @param options see Options
1086 * @param details Detailed message string.
1087 * @param notifyType The type of notification to send when this message
1088 * is presentend.
1089 * @return A KDialog button code, not a KMessageBox button code,
1090 * based on the buttonmask given to the constructor of the
1091 * @p dialog (ie. will return KDialog::Yes [256] instead of
1092 * KMessageBox::Yes [3]). Will return KMessageBox::Cancel
1093 * if the message box is queued for display instead of
1094 * exec()ed immediately or if the option NoExec is set.
1095 * @note Unless NoExec is used,
1096 * the @p dialog that is passed in is deleted by this
1097 * function. Do not delete it yourself.
1098 */
1099 static int createKMessageBox(KDialog *dialog, const QIcon &icon,
1100 const QString &text, const QStringList &strlist,
1101 const QString &ask, bool *checkboxReturn,
1102 Options options, const QString &details=QString(),
1103 QMessageBox::Icon notifyType=QMessageBox::Information); //krazy:exclude=qclasses
1104};
1105
1106Q_DECLARE_OPERATORS_FOR_FLAGS(KMessageBox::Options)
1107
1108
1109#endif
1110