00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "kalarm.h"
00022 #include <kconfig.h>
00023 #include "messagebox.h"
00024
00025
00026 KConfig* MessageBox::mConfig = 0;
00027 QMap<QString, KMessageBox::ButtonCode> MessageBox::mContinueDefaults;
00028
00029
00030
00031
00032
00033
00034 void MessageBox::setContinueDefault(const QString& dontAskAgainName, ButtonCode defaultButton)
00035 {
00036 mContinueDefaults[dontAskAgainName] = (defaultButton == Cancel ? Cancel : Continue);
00037 }
00038
00039
00040
00041
00042
00043 KMessageBox::ButtonCode MessageBox::getContinueDefault(const QString& dontAskAgainName)
00044 {
00045 ButtonCode defaultButton = Continue;
00046 if (!dontAskAgainName.isEmpty())
00047 {
00048 QMap<QString, ButtonCode>::ConstIterator it = mContinueDefaults.find(dontAskAgainName);
00049 if (it != mContinueDefaults.end())
00050 defaultButton = it.data();
00051 }
00052 return defaultButton;
00053 }
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 int MessageBox::warningContinueCancel(QWidget* parent, const QString& text, const QString& caption,
00064 const KGuiItem& buttonContinue, const QString& dontAskAgainName)
00065 {
00066 ButtonCode defaultButton = getContinueDefault(dontAskAgainName);
00067 return warningContinueCancel(parent, defaultButton, text, caption, buttonContinue, dontAskAgainName);
00068 }
00069
00070
00071
00072
00073
00074
00075 int MessageBox::warningContinueCancel(QWidget* parent, ButtonCode defaultButton, const QString& text,
00076 const QString& caption, const KGuiItem& buttonContinue,
00077 const QString& dontAskAgainName)
00078 {
00079 setContinueDefault(dontAskAgainName, defaultButton);
00080 if (defaultButton != Cancel)
00081 return KMessageBox::warningContinueCancel(parent, text, caption, buttonContinue, dontAskAgainName);
00082
00083
00084 if (!dontAskAgainName.isEmpty())
00085 {
00086 ButtonCode b;
00087 if (!shouldBeShownYesNo(dontAskAgainName, b)
00088 && b != KMessageBox::Yes)
00089 {
00090
00091
00092 saveDontShowAgain(dontAskAgainName, true, false);
00093 }
00094 }
00095 return warningYesNo(parent, text, caption, buttonContinue, KStdGuiItem::cancel(), dontAskAgainName);
00096 }
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 bool MessageBox::setDefaultShouldBeShownContinue(const QString& dontShowAgainName, bool defaultShow)
00107 {
00108 if (dontShowAgainName.isEmpty())
00109 return false;
00110
00111 KConfig* config = mConfig ? mConfig : KGlobal::config();
00112 config->setGroup(QString::fromLatin1("Notification Messages"));
00113 if (config->hasKey(dontShowAgainName))
00114 return false;
00115
00116
00117 saveDontShowAgainContinue(dontShowAgainName, !defaultShow);
00118 return true;
00119 }
00120
00121
00122
00123
00124
00125
00126
00127 bool MessageBox::shouldBeShownContinue(const QString& dontShowAgainName)
00128 {
00129 if (getContinueDefault(dontShowAgainName) != Cancel)
00130 return KMessageBox::shouldBeShownContinue(dontShowAgainName);
00131
00132 ButtonCode b;
00133 return shouldBeShownYesNo(dontShowAgainName, b);
00134 }
00135
00136
00137
00138
00139
00140
00141
00142 void MessageBox::saveDontShowAgainYesNo(const QString& dontShowAgainName, bool dontShow, ButtonCode result)
00143 {
00144 saveDontShowAgain(dontShowAgainName, true, dontShow, (result == Yes ? "yes" : "no"));
00145 }
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 void MessageBox::saveDontShowAgainContinue(const QString& dontShowAgainName, bool dontShow)
00156 {
00157 if (getContinueDefault(dontShowAgainName) == Cancel)
00158 saveDontShowAgainYesNo(dontShowAgainName, dontShow, Yes);
00159 else
00160 saveDontShowAgain(dontShowAgainName, false, dontShow);
00161 }
00162
00163
00164
00165
00166 void MessageBox::saveDontShowAgain(const QString& dontShowAgainName, bool yesno, bool dontShow, const char* yesnoResult)
00167 {
00168 if (dontShowAgainName.isEmpty())
00169 return;
00170 KConfig* config = mConfig ? mConfig : KGlobal::config();
00171 config->setGroup(QString::fromLatin1("Notification Messages"));
00172 bool global = (dontShowAgainName[0] == ':');
00173 if (yesno)
00174 config->writeEntry(dontShowAgainName, QString::fromLatin1(dontShow ? yesnoResult : ""), true, global);
00175 else
00176 config->writeEntry(dontShowAgainName, !dontShow, true, global);
00177 config->sync();
00178 }