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

kalarm/lib

  • sources
  • kde-4.12
  • kdepim
  • kalarm
  • lib
messagebox.cpp
Go to the documentation of this file.
1 /*
2  * messagebox.cpp - enhanced KMessageBox class
3  * Program: kalarm
4  * Copyright © 2004,2005,2007,2008,2011 by David Jarvie <djarvie@kde.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #include "kalarm.h" //krazy:exclude=includes (kalarm.h must be first)
22 #include "messagebox.h"
23 
24 #include <kconfiggroup.h>
25 #include <ksharedconfig.h>
26 #include <kglobal.h>
27 
28 
29 QMap<QString, KMessageBox::ButtonCode> KAMessageBox::mContinueDefaults;
30 
31 const KAMessageBox::Options KAMessageBox::NoAppModal = KMessageBox::Options(KMessageBox::Notify | KAMessageBox::WindowModal);
32 
33 /******************************************************************************
34 * Set the default button for continue/cancel message boxes with the specified
35 * 'dontAskAgainName'.
36 */
37 void KAMessageBox::setContinueDefault(const QString& dontAskAgainName, ButtonCode defaultButton)
38 {
39  mContinueDefaults[dontAskAgainName] = (defaultButton == Cancel ? Cancel : Continue);
40 }
41 
42 /******************************************************************************
43 * Get the default button for continue/cancel message boxes with the specified
44 * 'dontAskAgainName'.
45 */
46 KMessageBox::ButtonCode KAMessageBox::getContinueDefault(const QString& dontAskAgainName)
47 {
48  ButtonCode defaultButton = Continue;
49  if (!dontAskAgainName.isEmpty())
50  {
51  QMap<QString, ButtonCode>::ConstIterator it = mContinueDefaults.constFind(dontAskAgainName);
52  if (it != mContinueDefaults.constEnd())
53  defaultButton = it.value();
54  }
55  return defaultButton;
56 }
57 
58 /******************************************************************************
59 * Continue/cancel message box with the option as to which button is the default.
60 * If 'dontAskAgainName' is specified, the message box will only be suppressed
61 * if the user chose Continue last time.
62 */
63 int KAMessageBox::warningContinueCancel(QWidget* parent, ButtonCode defaultButton, const QString& text,
64  const QString& caption, const KGuiItem& buttonContinue,
65  const QString& dontAskAgainName)
66 {
67  setContinueDefault(dontAskAgainName, defaultButton);
68  if (defaultButton != Cancel)
69  return KMessageBox::warningContinueCancel(parent, text, caption, buttonContinue, KStandardGuiItem::cancel(), dontAskAgainName);
70 
71  // Cancel is the default button, so we have to use KMessageBox::warningYesNo()
72  if (!dontAskAgainName.isEmpty())
73  {
74  ButtonCode b;
75  if (!shouldBeShownYesNo(dontAskAgainName, b)
76  && b != KMessageBox::Yes)
77  {
78  // Notification has been suppressed, but No (alias Cancel) is the default,
79  // so unsuppress notification.
80  saveDontShowAgain(dontAskAgainName, true, false);
81  }
82  }
83  return warningYesNo(parent, text, caption, buttonContinue, KStandardGuiItem::cancel(), dontAskAgainName);
84 }
85 
86 /******************************************************************************
87 * If there is no current setting for whether a non-yes/no message box should be
88 * shown, set it to 'defaultShow'.
89 * If a continue/cancel message box has Cancel as the default button, either
90 * setContinueDefault() or warningContinueCancel() must have been called
91 * previously to set this for this 'dontShowAgainName' value.
92 * Reply = true if 'defaultShow' was written.
93 */
94 bool KAMessageBox::setDefaultShouldBeShownContinue(const QString& dontShowAgainName, bool defaultShow)
95 {
96  if (dontShowAgainName.isEmpty())
97  return false;
98  // First check whether there is an existing setting
99  KConfigGroup config(KGlobal::config(), "Notification Messages");
100  if (config.hasKey(dontShowAgainName))
101  return false;
102 
103  // There is no current setting, so write one
104  saveDontShowAgainContinue(dontShowAgainName, !defaultShow);
105  return true;
106 }
107 
108 /******************************************************************************
109 * Return whether a non-yes/no message box should be shown.
110 * If the message box has Cancel as the default button, either setContinueDefault()
111 * or warningContinueCancel() must have been called previously to set this for this
112 * 'dontShowAgainName' value.
113 */
114 bool KAMessageBox::shouldBeShownContinue(const QString& dontShowAgainName)
115 {
116  if (getContinueDefault(dontShowAgainName) != Cancel)
117  return KMessageBox::shouldBeShownContinue(dontShowAgainName);
118  // Cancel is the default button, so we have to use a yes/no message box
119  ButtonCode b;
120  return shouldBeShownYesNo(dontShowAgainName, b);
121 }
122 
123 
124 /******************************************************************************
125 * Save whether the yes/no message box should not be shown again.
126 * If 'dontShow' is true, the message box will be suppressed and it will return
127 * 'result'.
128 */
129 void KAMessageBox::saveDontShowAgainYesNo(const QString& dontShowAgainName, bool dontShow, ButtonCode result)
130 {
131  saveDontShowAgain(dontShowAgainName, true, dontShow, (result == Yes ? "yes" : "no"));
132 }
133 
134 /******************************************************************************
135 * Save whether a non-yes/no message box should not be shown again.
136 * If 'dontShow' is true, the message box will be suppressed and it will return
137 * Continue.
138 * If the message box has Cancel as the default button, either setContinueDefault()
139 * or warningContinueCancel() must have been called previously to set this for this
140 * 'dontShowAgainName' value.
141 */
142 void KAMessageBox::saveDontShowAgainContinue(const QString& dontShowAgainName, bool dontShow)
143 {
144  if (getContinueDefault(dontShowAgainName) == Cancel)
145  saveDontShowAgainYesNo(dontShowAgainName, dontShow, Yes);
146  else
147  saveDontShowAgain(dontShowAgainName, false, dontShow);
148 }
149 
150 /******************************************************************************
151 * Save whether the message box should not be shown again.
152 */
153 void KAMessageBox::saveDontShowAgain(const QString& dontShowAgainName, bool yesno, bool dontShow, const char* yesnoResult)
154 {
155  if (dontShowAgainName.isEmpty())
156  return;
157  KConfigGroup config(KGlobal::config(), "Notification Messages");
158  KConfig::WriteConfigFlags flags = (dontShowAgainName[0] == QLatin1Char(':')) ? KConfig::Global | KConfig::Persistent : KConfig::Persistent;
159  if (yesno)
160  config.writeEntry(dontShowAgainName, QString::fromLatin1(dontShow ? yesnoResult : ""), flags);
161  else
162  config.writeEntry(dontShowAgainName, !dontShow, flags);
163  config.sync();
164 }
165 
166 // vim: et sw=4:
KAMessageBox::WindowModal
static const Option WindowModal
Definition: messagebox.h:172
text
virtual QByteArray text(quint32 serialNumber) const =0
QWidget
KAMessageBox::getContinueDefault
static ButtonCode getContinueDefault(const QString &dontAskAgainName)
Gets the default button for the Continue/Cancel message box with the specified "don't ask again" name...
Definition: messagebox.cpp:46
messagebox.h
KAMessageBox::setContinueDefault
static void setContinueDefault(const QString &dontAskAgainName, ButtonCode defaultButton)
Sets the default button for the Continue/Cancel message box with the specified "don't ask again" name...
Definition: messagebox.cpp:37
KAMessageBox::shouldBeShownContinue
static bool shouldBeShownContinue(const QString &dontShowAgainName)
Returns whether a non-Yes/No message box should be shown.
Definition: messagebox.cpp:114
KAMessageBox::warningContinueCancel
static int warningContinueCancel(QWidget *parent, ButtonCode defaultButton, const QString &text, const QString &caption=QString(), const KGuiItem &buttonContinue=KStandardGuiItem::cont(), const QString &dontAskAgainName=QString())
Displays a Continue/Cancel message box with the option as to which button is the default.
Definition: messagebox.cpp:63
KAMessageBox::warningYesNo
static int warningYesNo(QWidget *parent, const QString &text, const QString &caption=QString(), const KGuiItem &buttonYes=KStandardGuiItem::yes(), const KGuiItem &buttonNo=KStandardGuiItem::no(), const QString &dontAskAgainName=QString(), Options options=Options(Notify|Dangerous|WindowModal))
Same as KMessageBox::warningYesNo() except that it defaults to window-modal, not application-modal.
Definition: messagebox.h:162
KAMessageBox::saveDontShowAgainYesNo
static void saveDontShowAgainYesNo(const QString &dontShowAgainName, bool dontShow=true, ButtonCode result=No)
Stores whether the Yes/No message box should or should not be shown again.
Definition: messagebox.cpp:129
KAMessageBox::saveDontShowAgainContinue
static void saveDontShowAgainContinue(const QString &dontShowAgainName, bool dontShow=true)
Stores whether a non-Yes/No message box should or should not be shown again.
Definition: messagebox.cpp:142
KAMessageBox::setDefaultShouldBeShownContinue
static bool setDefaultShouldBeShownContinue(const QString &dontShowAgainName, bool defaultShow)
If there is no current setting for whether a non-Yes/No message box should be shown, sets it to defaultShow.
Definition: messagebox.cpp:94
KAMessageBox::NoAppModal
static const Options NoAppModal
Shortcut to represent Options(Notify | WindowModal).
Definition: messagebox.h:169
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:59:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalarm/lib

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

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal