summaryrefslogtreecommitdiffstats
path: root/kalarm/lib/messagebox.h
blob: 5baccca0addaf771cca6c35ce7e79258b4c83e83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
 *  messagebox.h  -  enhanced KMessageBox class
 *  Program:  kalarm
 *  Copyright (C) 2004 by David Jarvie <[email protected]>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifndef MESSAGEBOX_H
#define MESSAGEBOX_H

#include <kstdguiitem.h>
#include <tdemessagebox.h>


/**
 *  @short Enhanced KMessageBox.
 *
 *  The MessageBox class provides an extension to KMessageBox, including the option for
 *  Continue/Cancel message boxes to have a default button of Cancel.
 *
 *  @author David Jarvie <[email protected]>
 */
class MessageBox : public KMessageBox
{
	public:
		/** MessageBox types.
		 *  @li CONT_CANCEL_DEF_CONT - Continue/Cancel, with Continue as the default button.
		 *  @li CONT_CANCEL_DEF_CANCEL - Continue/Cancel, with Cancel as the default button.
		 *  @li YES_NO_DEF_NO - Yes/No, with No as the default button.
		 */
		enum AskType {      // MessageBox types
			CONT_CANCEL_DEF_CONT,    // Continue/Cancel, with default = Continue
			CONT_CANCEL_DEF_CANCEL,  // Continue/Cancel, with default = Cancel
			YES_NO_DEF_NO            // Yes/No, with default = No
		};
		/** Gets the default button for the Continue/Cancel message box with the specified
		 * "don't ask again" name.
		 *  @param dontAskAgainName The identifier controlling whether the message box is suppressed.
		 */
		static ButtonCode getContinueDefault(const TQString& dontAskAgainName);
		/** Sets the default button for the Continue/Cancel message box with the specified
		 * "don't ask again" name.
		 *  @param dontAskAgainName The identifier controlling whether the message box is suppressed.
		 *  @param defaultButton The default button for the message box. Valid values are Continue or Cancel.
		 */
		static void setContinueDefault(const TQString& dontAskAgainName, ButtonCode defaultButton);
		/** Displays a Continue/Cancel message box with the option as to which button is the default.
		 *  @param parent Parent widget
		 *  @param defaultButton The default button for the message box. Valid values are Continue or Cancel.
		 *  @param text Message string
		 *  @param caption Caption (window title) of the message box
		 *  @param buttonContinue The text for the first button (default = i18n("Continue"))
		 *  @param dontAskAgainName If specified, the message box will only be suppressed
		 *    if the user chose Continue last time.
		 */
		static int  warningContinueCancel(TQWidget* parent, ButtonCode defaultButton, const TQString& text,
		                                  const TQString& caption = TQString(),
		                                  const KGuiItem& buttonContinue = KStdGuiItem::cont(),
		                                  const TQString& dontAskAgainName = TQString());
		/** Displays a Continue/Cancel message box.
		 *  @param parent Parent widget
		 *  @param text Message string
		 *  @param caption Caption (window title) of the message box
		 *  @param buttonContinue The text for the first button (default = i18n("Continue"))
		 *  @param dontAskAgainName If specified, (1) The message box will only be suppressed
		 *    if the user chose Continue last time, and (2) The default button is that last set
		 *    with either setContinueDefault() or warningContinueCancel() for the same
		 *    @p dontAskAgainName value. If neither method has been used to set a default button,
		 *    Continue is the default.
		 */
		static int  warningContinueCancel(TQWidget* parent, const TQString& text, const TQString& caption = TQString(),
		                                  const KGuiItem& buttonContinue = KStdGuiItem::cont(),
		                                  const TQString& dontAskAgainName = TQString());
		/** If there is no current setting for whether a non-Yes/No message box should be
		 *  shown, sets it to @p defaultShow.
		 *  If a Continue/Cancel message box has Cancel as the default button, either
		 *  setContinueDefault() or warningContinueCancel() must have been called
		 *  previously to set this for the specified @p dontShowAgainName value.
		 *  @return true if @p defaultShow was written.
		 */
		static bool setDefaultShouldBeShownContinue(const TQString& dontShowAgainName, bool defaultShow);
		/** Returns whether a non-Yes/No message box should be shown.
		 *  If the message box has Cancel as the default button, either setContinueDefault()
		 *  or warningContinueCancel() must have been called previously to set this for the
		 *  specified @p dontShowAgainName value.
		 *  @param dontShowAgainName The identifier controlling whether the message box is suppressed.
		 */
		static bool shouldBeShownContinue(const TQString& dontShowAgainName);
		/** Stores whether the Yes/No message box should or should not be shown again.
		 *  @param dontShowAgainName The identifier controlling whether the message box is suppressed.
		 *  @param dontShow If true, the message box will be suppressed and will return @p result.
		 *  @param result The button code to return if the message box is suppressed.
		 */
		static void saveDontShowAgainYesNo(const TQString& dontShowAgainName, bool dontShow = true, ButtonCode result = No);
		/** Stores whether a non-Yes/No message box should or should not be shown again.
		 *  If the message box has Cancel as the default button, either setContinueDefault()
		 *  or warningContinueCancel() must have been called previously to set this for the
		 *  specified @p dontShowAgainName value.
		 *  @param dontShowAgainName The identifier controlling whether the message box is suppressed.
		 *  @param dontShow If true, the message box will be suppressed and will return Continue.
		 */
		static void saveDontShowAgainContinue(const TQString& dontShowAgainName, bool dontShow = true);
		/** Sets the TDEConfig object to be used by the MessageBox class. */
		static void setDontShowAskAgainConfig(TDEConfig* cfg)    { mConfig = cfg; }

	private:
		static void saveDontShowAgain(const TQString& dontShowAgainName, bool yesno, bool dontShow, const char* yesnoResult = 0);
		static TDEConfig*                  mConfig;
		static TQMap<TQString, ButtonCode> mContinueDefaults;
};

#endif