• 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.14
  • 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,2014 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 * If there is no current setting for whether a non-yes/no message box should be
60 * shown, set it to 'defaultShow'.
61 * If a continue/cancel message box has Cancel as the default button, either
62 * setContinueDefault() or warningContinueCancel() must have been called
63 * previously to set this for this 'dontShowAgainName' value.
64 * Reply = true if 'defaultShow' was written.
65 */
66 bool KAMessageBox::setDefaultShouldBeShownContinue(const QString& dontShowAgainName, bool defaultShow)
67 {
68  if (dontShowAgainName.isEmpty())
69  return false;
70  // First check whether there is an existing setting
71  KConfigGroup config(KGlobal::config(), "Notification Messages");
72  if (config.hasKey(dontShowAgainName))
73  return false;
74 
75  // There is no current setting, so write one
76  saveDontShowAgainContinue(dontShowAgainName, !defaultShow);
77  return true;
78 }
79 
80 /******************************************************************************
81 * Return whether a non-yes/no message box should be shown.
82 * If the message box has Cancel as the default button, either setContinueDefault()
83 * or warningContinueCancel() must have been called previously to set this for this
84 * 'dontShowAgainName' value.
85 */
86 bool KAMessageBox::shouldBeShownContinue(const QString& dontShowAgainName)
87 {
88  if (getContinueDefault(dontShowAgainName) != Cancel)
89  return KMessageBox::shouldBeShownContinue(dontShowAgainName);
90  // Cancel is the default button, so we have to use a yes/no message box
91  ButtonCode b;
92  return shouldBeShownYesNo(dontShowAgainName, b);
93 }
94 
95 
96 /******************************************************************************
97 * Save whether the yes/no message box should not be shown again.
98 * If 'dontShow' is true, the message box will be suppressed and it will return
99 * 'result'.
100 */
101 void KAMessageBox::saveDontShowAgainYesNo(const QString& dontShowAgainName, bool dontShow, ButtonCode result)
102 {
103  saveDontShowAgain(dontShowAgainName, true, dontShow, (result == Yes ? "yes" : "no"));
104 }
105 
106 /******************************************************************************
107 * Save whether a non-yes/no message box should not be shown again.
108 * If 'dontShow' is true, the message box will be suppressed and it will return
109 * Continue.
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 void KAMessageBox::saveDontShowAgainContinue(const QString& dontShowAgainName, bool dontShow)
115 {
116  if (getContinueDefault(dontShowAgainName) == Cancel)
117  saveDontShowAgainYesNo(dontShowAgainName, dontShow, Yes);
118  else
119  saveDontShowAgain(dontShowAgainName, false, dontShow);
120 }
121 
122 /******************************************************************************
123 * Save whether the message box should not be shown again.
124 */
125 void KAMessageBox::saveDontShowAgain(const QString& dontShowAgainName, bool yesno, bool dontShow, const char* yesnoResult)
126 {
127  if (dontShowAgainName.isEmpty())
128  return;
129  KConfigGroup config(KGlobal::config(), "Notification Messages");
130  KConfig::WriteConfigFlags flags = (dontShowAgainName[0] == QLatin1Char(':')) ? KConfig::Global | KConfig::Persistent : KConfig::Persistent;
131  if (yesno)
132  config.writeEntry(dontShowAgainName, QString::fromLatin1(dontShow ? yesnoResult : ""), flags);
133  else
134  config.writeEntry(dontShowAgainName, !dontShow, flags);
135  config.sync();
136 }
137 
138 // vim: et sw=4:
KAMessageBox::WindowModal
static const Option WindowModal
Definition: messagebox.h:184
QMap
QMap::constFind
const_iterator constFind(const Key &key) const
QString::isEmpty
bool isEmpty() const
QMap::constEnd
const_iterator constEnd() const
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
QString
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
QLatin1Char
KAMessageBox::shouldBeShownContinue
static bool shouldBeShownContinue(const QString &dontShowAgainName)
Returns whether a non-Yes/No message box should be shown.
Definition: messagebox.cpp:86
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:101
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:114
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:66
QString::fromLatin1
QString fromLatin1(const char *str, int size)
KAMessageBox::NoAppModal
static const Options NoAppModal
Shortcut to represent Options(Notify | WindowModal).
Definition: messagebox.h:181
QMap::value
const T value(const Key &key) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:35:02 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
  • pimprint

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