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