• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kalarm/lib

messagebox.cpp

Go to the documentation of this file.
00001 /*
00002  *  messagebox.cpp  -  enhanced KMessageBox class
00003  *  Program:  kalarm
00004  *  Copyright © 2004,2005,2007 by David Jarvie <software@astrojar.org.uk>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #include "kalarm.h"   //krazy:exclude=includes (kalarm.h must be first)
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 * Set the default button for continue/cancel message boxes with the specified
00034 * 'dontAskAgainName'.
00035 */
00036 void MessageBox::setContinueDefault(const QString& dontAskAgainName, ButtonCode defaultButton)
00037 {
00038     mContinueDefaults[dontAskAgainName] = (defaultButton == Cancel ? Cancel : Continue);
00039 }
00040 
00041 /******************************************************************************
00042 * Get the default button for continue/cancel message boxes with the specified
00043 * 'dontAskAgainName'.
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 * Continue/cancel message box.
00059 * If 'dontAskAgainName' is specified:
00060 *   1) The message box will only be suppressed if the user chose Continue last time.
00061 *   2) The default button is that last set with either setContinueDefault() or
00062 *      warningContinueCancel() for that 'dontAskAgainName' value. If neither method
00063 *      has set a default button, Continue is the default.
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 * Continue/cancel message box with the option as to which button is the default.
00074 * If 'dontAskAgainName' is specified, the message box will only be suppressed
00075 * if the user chose Continue last time.
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     // Cancel is the default button, so we have to use KMessageBox::warningYesNo()
00086     if (!dontAskAgainName.isEmpty())
00087     {
00088         ButtonCode b;
00089         if (!shouldBeShownYesNo(dontAskAgainName, b)
00090         &&  b != KMessageBox::Yes)
00091         {
00092             // Notification has been suppressed, but No (alias Cancel) is the default,
00093             // so unsuppress notification.
00094             saveDontShowAgain(dontAskAgainName, true, false);
00095         }
00096     }
00097     return warningYesNo(parent, text, caption, buttonContinue, KStandardGuiItem::cancel(), dontAskAgainName);
00098 }
00099 
00100 /******************************************************************************
00101 * If there is no current setting for whether a non-yes/no message box should be
00102 * shown, set it to 'defaultShow'.
00103 * If a continue/cancel message box has Cancel as the default button, either
00104 * setContinueDefault() or warningContinueCancel() must have been called
00105 * previously to set this for this 'dontShowAgainName' value.
00106 * Reply = true if 'defaultShow' was written.
00107 */
00108 bool MessageBox::setDefaultShouldBeShownContinue(const QString& dontShowAgainName, bool defaultShow)
00109 {
00110     if (dontShowAgainName.isEmpty())
00111         return false;
00112     // First check whether there is an existing setting
00113     KConfigGroup config(KGlobal::config(), "Notification Messages");
00114     if (config.hasKey(dontShowAgainName))
00115         return false;
00116 
00117     // There is no current setting, so write one
00118     saveDontShowAgainContinue(dontShowAgainName, !defaultShow);
00119     return true;
00120 }
00121 
00122 /******************************************************************************
00123 * Return whether a non-yes/no message box should be shown.
00124 * If the message box has Cancel as the default button, either setContinueDefault()
00125 * or warningContinueCancel() must have been called previously to set this for this
00126 * 'dontShowAgainName' value.
00127 */
00128 bool MessageBox::shouldBeShownContinue(const QString& dontShowAgainName)
00129 {
00130     if (getContinueDefault(dontShowAgainName) != Cancel)
00131         return KMessageBox::shouldBeShownContinue(dontShowAgainName);
00132     // Cancel is the default button, so we have to use a yes/no message box
00133     ButtonCode b;
00134     return shouldBeShownYesNo(dontShowAgainName, b);
00135 }
00136 
00137 
00138 /******************************************************************************
00139 * Save whether the yes/no message box should not be shown again.
00140 * If 'dontShow' is true, the message box will be suppressed and it will return
00141 * 'result'.
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 * Save whether a non-yes/no message box should not be shown again.
00150 * If 'dontShow' is true, the message box will be suppressed and it will return
00151 * Continue.
00152 * If the message box has Cancel as the default button, either setContinueDefault()
00153 * or warningContinueCancel() must have been called previously to set this for this
00154 * 'dontShowAgainName' value.
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 * Save whether the message box should not be shown again.
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 }

kalarm/lib

Skip menu "kalarm/lib"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal